<?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.ruoyi.llm.mapper.CmcChatMapper">
    
    <resultMap type="CmcChat" id="CmcChatResult">
        <result property="chatId"    column="chat_id"    />
        <result property="topicId"    column="topic_id"    />
        <result property="userId"    column="user_id"    />
        <result property="input"    column="input"    />
        <result property="inputTime"    column="input_time"    />
        <result property="output"    column="output"    />
        <result property="outputTime"    column="output_time"    />
    </resultMap>

    <sql id="selectCmcChatVo">
        select chat_id, topic_id, user_id, input, input_time, output, output_time from cmc_chat
    </sql>

    <select id="selectCmcChatList" parameterType="CmcChat" resultMap="CmcChatResult">
        <include refid="selectCmcChatVo"/>
        <where>  
            <if test="topicId != null  and topicId != ''"> and topic_id = #{topicId}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="input != null  and input != ''"> and input = #{input}</if>
            <if test="inputTime != null "> and input_time = #{inputTime}</if>
            <if test="output != null  and output != ''"> and output = #{output}</if>
            <if test="outputTime != null "> and output_time = #{outputTime}</if>
        </where>
    </select>
    
    <select id="selectCmcChatByChatId" parameterType="String" resultMap="CmcChatResult">
        <include refid="selectCmcChatVo"/>
        where chat_id = #{chatId}
    </select>

    <insert id="insertCmcChat" parameterType="CmcChat">
        insert into cmc_chat
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="chatId != null">chat_id,</if>
            <if test="topicId != null">topic_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="input != null">input,</if>
            <if test="inputTime != null">input_time,</if>
            <if test="output != null">output,</if>
            <if test="outputTime != null">output_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="chatId != null">#{chatId},</if>
            <if test="topicId != null">#{topicId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="input != null">#{input},</if>
            <if test="inputTime != null">#{inputTime},</if>
            <if test="output != null">#{output},</if>
            <if test="outputTime != null">#{outputTime},</if>
         </trim>
    </insert>

    <update id="updateCmcChat" parameterType="CmcChat">
        update cmc_chat
        <trim prefix="SET" suffixOverrides=",">
            <if test="topicId != null">topic_id = #{topicId},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="input != null">input = #{input},</if>
            <if test="inputTime != null">input_time = #{inputTime},</if>
            <if test="output != null">output = #{output},</if>
            <if test="outputTime != null">output_time = #{outputTime},</if>
        </trim>
        where chat_id = #{chatId}
    </update>

    <delete id="deleteCmcChatByChatId" parameterType="String">
        delete from cmc_chat where chat_id = #{chatId}
    </delete>

    <delete id="deleteCmcChatByChatIds" parameterType="String">
        delete from cmc_chat where chat_id in 
        <foreach item="chatId" collection="array" open="(" separator="," close=")">
            #{chatId}
        </foreach>
    </delete>
</mapper>