<?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.CmcAgentMapper">
    
    <resultMap type="CmcAgent" id="CmcAgentResult">
        <result property="agentId"    column="agent_id"    />
        <result property="agentName"    column="agent_name"    />
        <result property="description"    column="description"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectCmcAgentVo">
        select agent_id, agent_name, description, create_by, create_time from cmc_agent
    </sql>

    <select id="selectCmcAgentList" parameterType="CmcAgent" resultMap="CmcAgentResult">
        <include refid="selectCmcAgentVo"/>
        <where>  
            <if test="agentName != null  and agentName != ''"> and agent_name like concat('%', #{agentName}, '%')</if>
            <if test="description != null  and description != ''"> and description = #{description}</if>
        </where>
    </select>
    
    <select id="selectCmcAgentByAgentId" parameterType="Integer" resultMap="CmcAgentResult">
        <include refid="selectCmcAgentVo"/>
        where agent_id = #{agentId}
    </select>

    <insert id="insertCmcAgent" parameterType="CmcAgent" useGeneratedKeys="true" keyProperty="agentId">
        insert into cmc_agent
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="agentName != null">agent_name,</if>
            <if test="description != null">description,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="agentName != null">#{agentName},</if>
            <if test="description != null">#{description},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateCmcAgent" parameterType="CmcAgent">
        update cmc_agent
        <trim prefix="SET" suffixOverrides=",">
            <if test="agentName != null">agent_name = #{agentName},</if>
            <if test="description != null">description = #{description},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where agent_id = #{agentId}
    </update>

    <delete id="deleteCmcAgentByAgentId" parameterType="Integer">
        delete from cmc_agent where agent_id = #{agentId}
    </delete>

    <delete id="deleteCmcAgentByAgentIds" parameterType="String">
        delete from cmc_agent where agent_id in 
        <foreach item="agentId" collection="array" open="(" separator="," close=")">
            #{agentId}
        </foreach>
    </delete>
</mapper>