<?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.CmcTopicMapper">
    
    <resultMap type="CmcTopic" id="CmcTopicResult">
        <result property="topicId"    column="topic_id"    />
        <result property="topic"    column="topic"    />
        <result property="agentId"    column="agent_id"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectCmcTopicVo">
        select topic_id, topic, agent_id, create_time from cmc_topic
    </sql>

    <select id="selectCmcTopicList" parameterType="CmcTopic" resultMap="CmcTopicResult">
        <include refid="selectCmcTopicVo"/>
        <where>  
            <if test="topic != null  and topic != ''"> and topic = #{topic}</if>
            <if test="agentId != null "> and agent_id = #{agentId}</if>
        </where>
        order by create_time desc
    </select>
    
    <select id="selectCmcTopicByTopicId" parameterType="String" resultMap="CmcTopicResult">
        <include refid="selectCmcTopicVo"/>
        where topic_id = #{topicId}
    </select>

    <insert id="insertCmcTopic" parameterType="CmcTopic">
        insert into cmc_topic
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="topicId != null">topic_id,</if>
            <if test="topic != null">topic,</if>
            <if test="agentId != null">agent_id,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="topicId != null">#{topicId},</if>
            <if test="topic != null">#{topic},</if>
            <if test="agentId != null">#{agentId},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateCmcTopic" parameterType="CmcTopic">
        update cmc_topic
        <trim prefix="SET" suffixOverrides=",">
            <if test="topic != null">topic = #{topic},</if>
            <if test="agentId != null">agent_id = #{agentId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where topic_id = #{topicId}
    </update>

    <delete id="deleteCmcTopicByTopicId" parameterType="String">
        delete from cmc_topic where topic_id = #{topicId}
    </delete>

    <delete id="deleteCmcTopicByTopicIds" parameterType="String">
        delete from cmc_topic where topic_id in 
        <foreach item="topicId" collection="array" open="(" separator="," close=")">
            #{topicId}
        </foreach>
    </delete>
</mapper>