You've already forked FrameTour-BE
- 新增小程序人脸聊天控制器 AppChatController,支持会话创建、消息收发、历史查询及会话关闭 - 集成智谱 GLM 模型客户端 GlmClient,支持流式文本生成与回调 - 新增聊天会话与消息实体类及 MyBatis 映射,实现数据持久化 - 提供 FaceChatService 接口及实现,封装聊天业务逻辑包括同步/流式消息发送 - 引入 zai-sdk 依赖以支持调用智谱 AI 大模型能力 - 支持基于人脸 ID 的唯一会话管理与用户权限校验 - 消息记录包含角色、内容、追踪 ID 及延迟信息,便于调试与分析
This commit is contained in:
43
src/main/resources/mapper/FaceChatConversationMapper.xml
Normal file
43
src/main/resources/mapper/FaceChatConversationMapper.xml
Normal file
@@ -0,0 +1,43 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ycwl.basic.mapper.FaceChatConversationMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.ycwl.basic.model.mobile.chat.entity.FaceChatConversationEntity">
|
||||
<id column="id" property="id"/>
|
||||
<result column="face_id" property="faceId"/>
|
||||
<result column="member_id" property="memberId"/>
|
||||
<result column="status" property="status"/>
|
||||
<result column="model" property="model"/>
|
||||
<result column="created_at" property="createdAt"/>
|
||||
<result column="updated_at" property="updatedAt"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="findByFaceId" resultMap="BaseResultMap">
|
||||
select id, face_id, member_id, status, model, created_at, updated_at
|
||||
from face_chat_conversation
|
||||
where face_id = #{faceId}
|
||||
limit 1
|
||||
</select>
|
||||
|
||||
<select id="getById" resultMap="BaseResultMap">
|
||||
select id, face_id, member_id, status, model, created_at, updated_at
|
||||
from face_chat_conversation
|
||||
where id = #{id}
|
||||
limit 1
|
||||
</select>
|
||||
|
||||
<insert id="insert">
|
||||
insert into face_chat_conversation
|
||||
(id, face_id, member_id, status, model, created_at, updated_at)
|
||||
values
|
||||
(#{id}, #{faceId}, #{memberId}, #{status}, #{model}, now(), now())
|
||||
</insert>
|
||||
|
||||
<update id="updateStatus">
|
||||
update face_chat_conversation
|
||||
set status = #{status}, updated_at = now()
|
||||
where id = #{id}
|
||||
</update>
|
||||
</mapper>
|
||||
55
src/main/resources/mapper/FaceChatMessageMapper.xml
Normal file
55
src/main/resources/mapper/FaceChatMessageMapper.xml
Normal file
@@ -0,0 +1,55 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ycwl.basic.mapper.FaceChatMessageMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.ycwl.basic.model.mobile.chat.entity.FaceChatMessageEntity">
|
||||
<id column="id" property="id"/>
|
||||
<result column="conversation_id" property="conversationId"/>
|
||||
<result column="face_id" property="faceId"/>
|
||||
<result column="seq" property="seq"/>
|
||||
<result column="role" property="role"/>
|
||||
<result column="content" property="content"/>
|
||||
<result column="trace_id" property="traceId"/>
|
||||
<result column="latency_ms" property="latencyMs"/>
|
||||
<result column="created_at" property="createdAt"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="maxSeqForUpdate" resultType="java.lang.Integer">
|
||||
select ifnull(max(seq), 0)
|
||||
from face_chat_message
|
||||
where conversation_id = #{conversationId}
|
||||
for update
|
||||
</select>
|
||||
|
||||
<insert id="insert">
|
||||
insert into face_chat_message
|
||||
(id, conversation_id, face_id, seq, role, content, trace_id, latency_ms, created_at)
|
||||
values
|
||||
(#{id}, #{conversationId}, #{faceId}, #{seq}, #{role}, #{content}, #{traceId}, #{latencyMs}, now())
|
||||
</insert>
|
||||
|
||||
<select id="listByConversation" resultMap="BaseResultMap">
|
||||
select id, conversation_id, face_id, seq, role, content, trace_id, latency_ms, created_at
|
||||
from face_chat_message
|
||||
where conversation_id = #{conversationId}
|
||||
<if test="cursor != null">
|
||||
and seq > #{cursor}
|
||||
</if>
|
||||
order by seq asc
|
||||
<if test="limit != null">
|
||||
limit #{limit}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="listRecentByConversation" resultMap="BaseResultMap">
|
||||
select id, conversation_id, face_id, seq, role, content, trace_id, latency_ms, created_at
|
||||
from face_chat_message
|
||||
where conversation_id = #{conversationId}
|
||||
order by seq desc
|
||||
<if test="limit != null">
|
||||
limit #{limit}
|
||||
</if>
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user