|
@@ -0,0 +1,197 @@
|
|
|
+<?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.fs.aiChat.mapper.InterestAiChatSessionMapper">
|
|
|
+
|
|
|
+ <resultMap type="InterestAiSession" id="getSessionListByUserIdResultMap">
|
|
|
+ <result property="sessionId" column="session_id" />
|
|
|
+ <result property="roleId" column="role_id" />
|
|
|
+ <result property="roleName" column="role_name" />
|
|
|
+ <result property="welcomeMessage" column="welcome_message" />
|
|
|
+ <result property="textDescription" column="text_description" />
|
|
|
+ <result property="lastCreateTime" column="lastCreateTime" />
|
|
|
+ <result property="lastContent" column="lastContent" />
|
|
|
+ <result property="roleAvatar" column="roleAvatar" />
|
|
|
+ <result property="roleTag" column="role_tag" />
|
|
|
+ </resultMap>
|
|
|
+
|
|
|
+ <select id="getSessionListByUserId" resultMap="getSessionListByUserIdResultMap">
|
|
|
+ select temp.role_id,
|
|
|
+ temp.role_name,
|
|
|
+ temp.role_tag,
|
|
|
+ temp.roleAvatar as roleAvatar,
|
|
|
+ temp.welcome_message,
|
|
|
+ temp.text_description,
|
|
|
+ temp.lastContent,
|
|
|
+ temp.lastCreateTime,
|
|
|
+ temp.session_id
|
|
|
+ from (select t1.role_id,
|
|
|
+ t1.role_name,
|
|
|
+ t1.role_tag,
|
|
|
+ t1.avatar as roleAvatar,
|
|
|
+ t1.welcome_message,
|
|
|
+ t1.text_description,
|
|
|
+ (select content
|
|
|
+ from (select ROW_NUMBER() over (PARTITION by session_id ORDER BY create_time desc) rowNum, content, session_id, create_time
|
|
|
+ from fs_interest_ai_msg
|
|
|
+ where session_id = t3.session_id
|
|
|
+ and send_type = 2) temp
|
|
|
+ where temp.rowNum = 1) as lastContent
|
|
|
+ ,
|
|
|
+ (select max(create_time)
|
|
|
+ from fs_interest_ai_msg
|
|
|
+ where session_id = t3.session_id and send_type = 2) as lastCreateTime,
|
|
|
+ t3.session_id
|
|
|
+ from fs_interest_ai_role t1
|
|
|
+ left join fs_interest_ai_session t3 on t3.role_id = t1.role_id and t3.user_id = #{userId} ) temp
|
|
|
+ order by temp.lastCreateTime desc
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <resultMap type="SessionRoleInfo" id="getSessionRoleInfoBySessionIdResultMap" >
|
|
|
+ <result property="roleId" column="role_id" />
|
|
|
+ <result property="roleName" column="role_name" />
|
|
|
+ <result property="roleTag" column="role_tag" />
|
|
|
+ <result property="appKey" column="app_key" />
|
|
|
+ <result property="avatar" column="avatar" />
|
|
|
+ <result property="welcomeMessage" column="welcome_message" />
|
|
|
+ <result property="imageUrl" column="image_url" />
|
|
|
+ <result property="createTime" column="create_time" />
|
|
|
+ <result property="updateTime" column="update_time" />
|
|
|
+ <result property="textDescription" column="text_description" />
|
|
|
+ <result property="title" column="title" />
|
|
|
+ <result property="wordList" column="wordList" />
|
|
|
+ <result property="isRecommend" column="is_recommend" />
|
|
|
+ <result property="recommendImgUrl" column="recommend_img_url" />
|
|
|
+ <result property="sessionId" column="session_id" />
|
|
|
+
|
|
|
+ </resultMap>
|
|
|
+
|
|
|
+ <select id="getSessionRoleInfoByRoleId" resultMap="getSessionRoleInfoBySessionIdResultMap">
|
|
|
+ select t1.role_id,
|
|
|
+ t1.role_name,
|
|
|
+ t1.role_tag,
|
|
|
+ t1.app_key,
|
|
|
+ t1.avatar,
|
|
|
+ t1.welcome_message,
|
|
|
+ t1.image_url,
|
|
|
+ t1.create_time,
|
|
|
+ t1.update_time,
|
|
|
+ t1.text_description,
|
|
|
+ t1.title,
|
|
|
+ (select GROUP_CONCAT(t3.content order by t3.sort SEPARATOR "||") from fs_interest_ai_role_words t3 where t3.role_id = t1.role_id) as wordList
|
|
|
+ from fs_interest_ai_role t1
|
|
|
+ where t1.role_id = #{roleId}
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <select id="getRecommendRoleList" resultMap="getSessionRoleInfoBySessionIdResultMap">
|
|
|
+ select t1.role_id,
|
|
|
+ t1.role_name,
|
|
|
+ t1.is_recommend,
|
|
|
+ t1.recommend_img_url,
|
|
|
+ (select max(session_id) from fs_interest_ai_session t2 where t2.user_id = #{userId} and t2.role_id = t1.role_id) as session_id
|
|
|
+ from fs_interest_ai_role t1
|
|
|
+ where t1.is_recommend = 1
|
|
|
+ order by t1.update_time desc,t1.create_time desc
|
|
|
+ </select>
|
|
|
+ <resultMap type="FsInterestAiRole" id="FsInterestAiRoleResult">
|
|
|
+ <result property="roleId" column="role_id" />
|
|
|
+ <result property="roleName" column="role_name" />
|
|
|
+ <result property="roleTag" column="role_tag" />
|
|
|
+ <result property="appKey" column="app_key" />
|
|
|
+ <result property="avatar" column="avatar" />
|
|
|
+ <result property="welcomeMessage" column="welcome_message" />
|
|
|
+ <result property="createTime" column="create_time" />
|
|
|
+ <result property="updateTime" column="update_time" />
|
|
|
+ <result property="imageUrl" column="image_url" />
|
|
|
+ <result property="textDescription" column="text_description" />
|
|
|
+ <result property="title" column="title" />
|
|
|
+ <result property="isRecommend" column="is_recommend" />
|
|
|
+ <result property="recommendImgUrl" column="recommend_img_url" />
|
|
|
+ </resultMap>
|
|
|
+
|
|
|
+ <sql id="selectFsInterestAiRoleVo">
|
|
|
+ select role_id, role_name, role_tag, app_key, avatar, welcome_message, create_time, update_time, image_url,text_description,title,is_recommend,recommend_img_url from fs_interest_ai_role
|
|
|
+ </sql>
|
|
|
+
|
|
|
+ <select id="selectFsInterestAiRoleByRoleId" parameterType="Long" resultMap="FsInterestAiRoleResult">
|
|
|
+ <include refid="selectFsInterestAiRoleVo"/>
|
|
|
+ where role_id = #{roleId}
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <select id="getSessionChatList" resultType="InterestAiChatMsg">
|
|
|
+ select t1.msg_id,
|
|
|
+ t1.session_id,
|
|
|
+ t1.user_id,
|
|
|
+ t1.role_id,
|
|
|
+ t1.role_name,
|
|
|
+ t1.send_type,
|
|
|
+ t1.content,
|
|
|
+ t1.create_time,
|
|
|
+ t1.nick_name,
|
|
|
+ t1.avatar,
|
|
|
+ t3.avatar as role_avatar
|
|
|
+ from fs_interest_ai_session t2
|
|
|
+ inner join fs_interest_ai_msg t1 on t1.session_id = t2.session_id
|
|
|
+ inner join fs_interest_ai_role t3 on t3.role_id = t2.role_id
|
|
|
+ where t2.session_id = #{sessionId}
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <insert id="insertFsInterestAiSession" parameterType="FsInterestAiSession" useGeneratedKeys="true" keyProperty="sessionId">
|
|
|
+ insert into fs_interest_ai_session
|
|
|
+ <trim prefix="(" suffix=")" suffixOverrides=",">
|
|
|
+ <if test="chatId != null">chat_id,</if>
|
|
|
+ <if test="userId != null">user_id,</if>
|
|
|
+ <if test="roleId != null">role_id,</if>
|
|
|
+ <if test="roleName != null">role_name,</if>
|
|
|
+ <if test="status != null">status,</if>
|
|
|
+ <if test="nickName != null">nick_name,</if>
|
|
|
+ <if test="avatar != null">avatar,</if>
|
|
|
+ <if test="createTime != null">create_time,</if>
|
|
|
+ <if test="updateTime != null">update_time,</if>
|
|
|
+ </trim>
|
|
|
+ <trim prefix="values (" suffix=")" suffixOverrides=",">
|
|
|
+ <if test="chatId != null">#{chatId},</if>
|
|
|
+ <if test="userId != null">#{userId},</if>
|
|
|
+ <if test="roleId != null">#{roleId},</if>
|
|
|
+ <if test="roleName != null">#{roleName},</if>
|
|
|
+ <if test="status != null">#{status},</if>
|
|
|
+ <if test="nickName != null">#{nickName},</if>
|
|
|
+ <if test="avatar != null">#{avatar},</if>
|
|
|
+ <if test="createTime != null">#{createTime},</if>
|
|
|
+ <if test="updateTime != null">#{updateTime},</if>
|
|
|
+ </trim>
|
|
|
+ </insert>
|
|
|
+
|
|
|
+ <insert id="insertFsInterestAiMsg" parameterType="FsInterestAiMsg" useGeneratedKeys="true" keyProperty="msgId">
|
|
|
+ insert into fs_interest_ai_msg
|
|
|
+ <trim prefix="(" suffix=")" suffixOverrides=",">
|
|
|
+ <if test="sessionId != null">session_id,</if>
|
|
|
+ <if test="userId != null">user_id,</if>
|
|
|
+ <if test="content != null">content,</if>
|
|
|
+ <if test="sendType != null">send_type,</if>
|
|
|
+ <if test="roleId != null">role_id,</if>
|
|
|
+ <if test="roleName != null">role_name,</if>
|
|
|
+ <if test="createTime != null">create_time,</if>
|
|
|
+ <if test="nickName != null">nick_name,</if>
|
|
|
+ <if test="avatar != null">avatar,</if>
|
|
|
+ <if test="promptTokens != null">prompt_tokens,</if>
|
|
|
+ <if test="completionTokens != null">completion_tokens,</if>
|
|
|
+ <if test="totalTokens != null">total_tokens,</if>
|
|
|
+ </trim>
|
|
|
+ <trim prefix="values (" suffix=")" suffixOverrides=",">
|
|
|
+ <if test="sessionId != null">#{sessionId},</if>
|
|
|
+ <if test="userId != null">#{userId},</if>
|
|
|
+ <if test="content != null">#{content},</if>
|
|
|
+ <if test="sendType != null">#{sendType},</if>
|
|
|
+ <if test="roleId != null">#{roleId},</if>
|
|
|
+ <if test="roleName != null">#{roleName},</if>
|
|
|
+ <if test="createTime != null">#{createTime},</if>
|
|
|
+ <if test="nickName != null">#{nickName},</if>
|
|
|
+ <if test="avatar != null">#{avatar},</if>
|
|
|
+ <if test="promptTokens != null">#{promptTokens},</if>
|
|
|
+ <if test="completionTokens != null">#{completionTokens},</if>
|
|
|
+ <if test="totalTokens != null">#{totalTokens},</if>
|
|
|
+ </trim>
|
|
|
+ </insert>
|
|
|
+</mapper>
|