<?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.fastGpt.mapper.FastGptChatSessionMapper">

    <resultMap type="FastGptChatSession" id="FastGptChatSessionResult">
        <result property="sessionId"    column="session_id"    />
        <result property="chatId"    column="chat_id"    />
        <result property="userId"    column="user_id"    />
        <result property="kfId"    column="kf_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="status"    column="status"    />
        <result property="companyId"    column="company_id"    />
        <result property="isLook"    column="is_look"    />
        <result property="userType"    column="user_type"    />
        <result property="nickName"    column="nick_name"    />
        <result property="avatar"    column="avatar"    />
        <result property="isArtificial"    column="is_artificial"    />
        <result property="remindTime"    column="remind_time"    />
        <result property="remindStatus"    column="remind_status"    />
        <result property="remindCount"    column="remind_count"    />
        <result property="qwExtId"    column="qw_ext_id"    />
        <result property="qwUserId"    column="qw_user_id"    />
        <result property="lastTime"    column="last_time"    />
        <result property="isReply"    column="is_reply"    />
    </resultMap>

    <sql id="selectFastGptChatSessionVo">
        select session_id,remind_time,is_reply,last_time,remind_status,remind_count,qw_ext_id,qw_user_id,chat_id,is_artificial, user_id, kf_id, create_time, update_time, status, company_id, is_look, user_type, nick_name, avatar from fastgpt_chat_session
    </sql>

    <select id="selectFastGptChatSessionList" parameterType="FastGptChatSession" resultMap="FastGptChatSessionResult">
        <include refid="selectFastGptChatSessionVo"/>
        <where>
            <if test="chatId != null  and chatId != ''"> and chat_id = #{chatId}</if>
            <if test="userId != null  and userId != ''"> and user_id = #{userId}</if>
            <if test="kfId != null  and kfId != ''"> and kf_id = #{kfId}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="isLook != null "> and is_look = #{isLook}</if>
            <if test="userType != null "> and user_type = #{userType}</if>
            <if test="nickName != null  and nickName != ''"> and nick_name like concat('%', #{nickName}, '%')</if>
            <if test="avatar != null  and avatar != ''"> and avatar = #{avatar}</if>
        </where>
    </select>

    <select id="selectFastGptChatSessionBySessionId" parameterType="Long" resultMap="FastGptChatSessionResult">
        <include refid="selectFastGptChatSessionVo"/>
        where session_id = #{sessionId}
    </select>

    <insert id="insertFastGptChatSession" parameterType="FastGptChatSession" useGeneratedKeys="true" keyProperty="sessionId">
        insert into fastgpt_chat_session
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="sessionId != null">session_id,</if>
            <if test="chatId != null">chat_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="kfId != null">kf_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="status != null">status,</if>
            <if test="companyId != null">company_id,</if>
            <if test="isLook != null">is_look,</if>
            <if test="userType != null">user_type,</if>
            <if test="nickName != null">nick_name,</if>
            <if test="avatar != null">avatar,</if>
            <if test="isArtificial != null">is_artificial,</if>
            <if test="remindTime != null">remind_time,</if>
            <if test="remindStatus != null">remind_status,</if>
            <if test="remindCount != null">remind_count,</if>
            <if test="qwExtId != null">qw_ext_id,</if>
            <if test="qwUserId != null">qw_user_id,</if>
            <if test="lastTime != null">last_time,</if>
            <if test="isReply != null">is_reply,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="sessionId != null">#{sessionId},</if>
            <if test="chatId != null">#{chatId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="kfId != null">#{kfId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="status != null">#{status},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="isLook != null">#{isLook},</if>
            <if test="userType != null">#{userType},</if>
            <if test="nickName != null">#{nickName},</if>
            <if test="avatar != null">#{avatar},</if>
            <if test="isArtificial != null">#{isArtificial},</if>
            <if test="remindTime != null">#{remindTime},</if>
            <if test="remindStatus != null">#{remindStatus},</if>
            <if test="remindCount != null">#{remindCount},</if>
            <if test="qwExtId != null">#{qwExtId},</if>
            <if test="qwUserId != null">#{qwUserId},</if>
            <if test="lastTime != null">#{lastTime},</if>
            <if test="isReply != null">#{isReply},</if>
         </trim>
    </insert>

    <update id="updateFastGptChatSession" parameterType="FastGptChatSession">
        update fastgpt_chat_session
        <trim prefix="SET" suffixOverrides=",">
            <if test="chatId != null">chat_id = #{chatId},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="kfId != null">kf_id = #{kfId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="status != null">status = #{status},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="isLook != null">is_look = #{isLook},</if>
            <if test="userType != null">user_type = #{userType},</if>
            <if test="nickName != null">nick_name = #{nickName},</if>
            <if test="avatar != null">avatar = #{avatar},</if>
            <if test="isArtificial != null">is_artificial = #{isArtificial},</if>
            <if test="remindTime != null">remind_time = #{remindTime},</if>
            <if test="remindStatus != null">remind_status = #{remindStatus},</if>
            <if test="remindCount != null">remind_count = #{remindCount},</if>
            <if test="qwExtId != null">qw_ext_id = #{qwExtId},</if>
            <if test="qwUserId != null">qw_user_id = #{qwUserId},</if>
            <if test="lastTime != null">last_time = #{lastTime},</if>
            <if test="isReply != null">is_reply = #{isReply},</if>
        </trim>
        where session_id = #{sessionId}
    </update>

    <delete id="deleteFastGptChatSessionBySessionId" parameterType="Long">
        delete from fastgpt_chat_session where session_id = #{sessionId}
    </delete>

    <delete id="deleteFastGptChatSessionBySessionIds" parameterType="String">
        delete from fastgpt_chat_session where session_id in
        <foreach item="sessionId" collection="array" open="(" separator="," close=")">
            #{sessionId}
        </foreach>
    </delete>
</mapper>
