parent
63ffb1bb2a
commit
9cc5739e58
@ -0,0 +1,87 @@
|
||||
<?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.unilife.mapper.AiChatSessionMapper">
|
||||
|
||||
<!-- 结果映射 -->
|
||||
<resultMap id="AiChatSessionResultMap" type="com.unilife.model.entity.AiChatSession">
|
||||
<id column="id" property="id"/>
|
||||
<result column="user_id" property="userId"/>
|
||||
<result column="title" property="title"/>
|
||||
<result column="created_at" property="createdAt"/>
|
||||
<result column="updated_at" property="updatedAt"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 插入会话 -->
|
||||
<insert id="insert" parameterType="com.unilife.model.entity.AiChatSession">
|
||||
INSERT INTO ai_chat_sessions (
|
||||
id, user_id, title, created_at, updated_at
|
||||
) VALUES (
|
||||
#{id}, #{userId}, #{title}, #{createdAt}, #{updatedAt}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<!-- 根据ID查询会话 -->
|
||||
<select id="selectById" resultMap="AiChatSessionResultMap">
|
||||
SELECT id, user_id, title, created_at, updated_at
|
||||
FROM ai_chat_sessions
|
||||
WHERE id = #{id}
|
||||
</select>
|
||||
|
||||
<!-- 根据用户ID分页查询会话列表 -->
|
||||
<select id="selectByUserId" resultMap="AiChatSessionResultMap">
|
||||
SELECT id, user_id, title, created_at, updated_at
|
||||
FROM ai_chat_sessions
|
||||
WHERE user_id = #{userId}
|
||||
ORDER BY updated_at DESC
|
||||
LIMIT #{offset}, #{limit}
|
||||
</select>
|
||||
|
||||
<!-- 查询匿名会话列表 -->
|
||||
<select id="selectAnonymousSessions" resultMap="AiChatSessionResultMap">
|
||||
SELECT id, user_id, title, created_at, updated_at
|
||||
FROM ai_chat_sessions
|
||||
WHERE user_id IS NULL
|
||||
ORDER BY updated_at DESC
|
||||
LIMIT #{offset}, #{limit}
|
||||
</select>
|
||||
|
||||
<!-- 统计用户会话总数 -->
|
||||
<select id="countByUserId" resultType="long">
|
||||
SELECT COUNT(*)
|
||||
FROM ai_chat_sessions
|
||||
WHERE user_id = #{userId}
|
||||
</select>
|
||||
|
||||
<!-- 统计匿名会话总数 -->
|
||||
<select id="countAnonymousSessions" resultType="long">
|
||||
SELECT COUNT(*)
|
||||
FROM ai_chat_sessions
|
||||
WHERE user_id IS NULL
|
||||
</select>
|
||||
|
||||
<!-- 更新会话标题 -->
|
||||
<update id="updateTitle">
|
||||
UPDATE ai_chat_sessions
|
||||
SET title = #{title}, updated_at = CURRENT_TIMESTAMP
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<!-- 更新会话的最后消息时间和消息数量(简化方案中保留方法但不使用) -->
|
||||
<update id="updateMessageInfo">
|
||||
UPDATE ai_chat_sessions
|
||||
SET updated_at = CURRENT_TIMESTAMP
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<!-- 删除会话 -->
|
||||
<delete id="deleteById">
|
||||
DELETE FROM ai_chat_sessions WHERE id = #{id}
|
||||
</delete>
|
||||
|
||||
<!-- 批量删除过期会话 -->
|
||||
<delete id="deleteExpiredSessions">
|
||||
DELETE FROM ai_chat_sessions
|
||||
WHERE updated_at < #{expireTime}
|
||||
</delete>
|
||||
|
||||
</mapper>
|
Loading…
Reference in new issue