<?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.aicall.mapper.CcLlmKbMapper">
    
    <resultMap type="CcLlmKb" id="CcLlmKbResult">
        <result property="id"    column="id"    />
        <result property="title"    column="title"    />
        <result property="content"    column="content"    />
        <result property="catId"    column="cat_id"    />
    </resultMap>

    <sql id="selectCcLlmKbVo">
        select id, title, content, cat_id from cc_llm_kb
    </sql>

    <select id="selectCcLlmKbList" parameterType="CcLlmKb" resultMap="CcLlmKbResult">
        <include refid="selectCcLlmKbVo"/>
        <where>  
            <if test="title != null  and title != ''"> and title = #{title}</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="catId != null "> and cat_id = #{catId}</if>
        </where>
    </select>
    
    <select id="selectCcLlmKbById" parameterType="Long" resultMap="CcLlmKbResult">
        <include refid="selectCcLlmKbVo"/>
        where id = #{id}
    </select>

    <insert id="insertCcLlmKb" parameterType="CcLlmKb">
        insert into cc_llm_kb
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="title != null and title != ''">title,</if>
            <if test="content != null and content != ''">content,</if>
            <if test="catId != null">cat_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="title != null and title != ''">#{title},</if>
            <if test="content != null and content != ''">#{content},</if>
            <if test="catId != null">#{catId},</if>
         </trim>
    </insert>

    <update id="updateCcLlmKb" parameterType="CcLlmKb">
        update cc_llm_kb
        <trim prefix="SET" suffixOverrides=",">
            <if test="title != null and title != ''">title = #{title},</if>
            <if test="content != null and content != ''">content = #{content},</if>
            <if test="catId != null">cat_id = #{catId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCcLlmKbById" parameterType="Long">
        delete from cc_llm_kb where id = #{id}
    </delete>

    <delete id="deleteCcLlmKbByIds" parameterType="String">
        delete from cc_llm_kb where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <select id="selectCountByCatId" parameterType="Long">
        select count(1) from cc_llm_kb where cat_id = #{catId}
    </select>


    <delete id="deleteCcLlmKbByCatId" parameterType="Long">
        delete from cc_llm_kb where cat_id = #{catId}
    </delete>

    <!-- 批量插入 -->
    <insert id="insertBatch" parameterType="java.util.List">
        INSERT INTO cc_llm_kb
        (title, content, cat_id)
        VALUES
        <foreach collection="list" item="e" separator=",">
            (#{e.title},
            #{e.content},
            #{e.catId})
        </foreach>
    </insert>

</mapper>