<?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.CmcDocumentMapper">
    
    <resultMap type="CmcDocument" id="CmcDocumentResult">
        <result property="documentId"    column="document_id"    />
        <result property="chatId"    column="chat_id"    />
        <result property="path"    column="path"    />
    </resultMap>

    <sql id="selectCmcDocumentVo">
        select document_id, chat_id, path from cmc_document
    </sql>

    <select id="selectCmcDocumentList" parameterType="CmcDocument" resultMap="CmcDocumentResult">
        <include refid="selectCmcDocumentVo"/>
        <where>  
            <if test="chatId != null  and chatId != ''"> and chat_id = #{chatId}</if>
            <if test="path != null  and path != ''"> and path = #{path}</if>
        </where>
    </select>
    
    <select id="selectCmcDocumentByDocumentId" parameterType="String" resultMap="CmcDocumentResult">
        <include refid="selectCmcDocumentVo"/>
        where document_id = #{documentId}
    </select>

    <insert id="insertCmcDocument" parameterType="CmcDocument">
        insert into cmc_document
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="documentId != null">document_id,</if>
            <if test="chatId != null">chat_id,</if>
            <if test="path != null">path,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="documentId != null">#{documentId},</if>
            <if test="chatId != null">#{chatId},</if>
            <if test="path != null">#{path},</if>
         </trim>
    </insert>

    <update id="updateCmcDocument" parameterType="CmcDocument">
        update cmc_document
        <trim prefix="SET" suffixOverrides=",">
            <if test="chatId != null">chat_id = #{chatId},</if>
            <if test="path != null">path = #{path},</if>
        </trim>
        where document_id = #{documentId}
    </update>

    <delete id="deleteCmcDocumentByDocumentId" parameterType="String">
        delete from cmc_document where document_id = #{documentId}
    </delete>

    <delete id="deleteCmcDocumentByDocumentIds" parameterType="String">
        delete from cmc_document where document_id in 
        <foreach item="documentId" collection="array" open="(" separator="," close=")">
            #{documentId}
        </foreach>
    </delete>
</mapper>