<?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.fs.fastGpt.mapper.FastGptCollectionMapper">
    
    <resultMap type="FastGptCollection" id="FastGptCollectionResult">
        <result property="collectionId"    column="collection_id"    />
        <result property="type"    column="type"    />
        <result property="datasetId"    column="datasetId"    />
        <result property="parentId"    column="parentId"    />
        <result property="name"    column="name"    />
        <result property="collectionType"    column="collection_type"    />
        <result property="metadata"    column="metadata"    />
        <result property="text"    column="text"    />
        <result property="trainingType"    column="trainingType"    />
        <result property="chunkSize"    column="chunkSize"    />
        <result property="chunkSplitter"    column="chunkSplitter"    />
        <result property="qaPrompt"    column="qaPrompt"    />
        <result property="link"    column="link"    />
        <result property="fileUrl"    column="fileUrl"    />
        <result property="fileName"    column="fileName"    />
        <result property="updateTime"    column="updateTime"    />
        <result property="createTime"    column="createTime"    />
        <result property="forbid"    column="forbid"    />
        <result property="companyId"    column="company_id"    />
        <result property="dataAmount"    column="data_amount"    />
    </resultMap>

    <sql id="selectFastGptCollectionVo">
        select collection_id, type, datasetId, parentId, name, collection_type, metadata, text, trainingType, chunkSize, chunkSplitter, qaPrompt, link, fileUrl,fileName, updateTime, createTime, forbid, company_id,data_amount from fastgpt_collection
    </sql>

    <select id="selectFastGptCollectionList" parameterType="FastGptCollection" resultMap="FastGptCollectionResult">
        <include refid="selectFastGptCollectionVo"/>
        <where>  
            <if test="type != null "> and `type` = #{type}</if>
            <if test="datasetId != null  and datasetId != ''"> and datasetId = #{datasetId}</if>
            <if test="parentId != null  and parentId != ''"> and parentId = #{parentId}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="collectionType != null  and collectionType != ''"> and collection_type = #{collectionType}</if>
            <if test="metadata != null  and metadata != ''"> and metadata = #{metadata}</if>
            <if test="text != null  and text != ''"> and text = #{text}</if>
            <if test="trainingType != null  and trainingType != ''"> and trainingType = #{trainingType}</if>
            <if test="chunkSplitter != null  and chunkSplitter != ''"> and chunkSplitter = #{chunkSplitter}</if>
            <if test="qaPrompt != null  and qaPrompt != ''"> and qaPrompt = #{qaPrompt}</if>
            <if test="updateTime != null "> and updateTime = #{updateTime}</if>
            <if test="fileName != null "> and fileName = #{fileName}</if>
            <if test="createTime != null "> and createTime = #{createTime}</if>
            <if test="forbid != null "> and forbid = #{forbid}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="dataAmount != null "> and data_amount = #{dataAmount}</if>
        </where>
        order by createTime desc
    </select>
    
    <select id="selectFastGptCollectionByCollectionId" parameterType="String" resultMap="FastGptCollectionResult">
        <include refid="selectFastGptCollectionVo"/>
        where collection_id = #{collectionId}
    </select>
        
    <insert id="insertFastGptCollection" parameterType="FastGptCollection">
        insert into fastgpt_collection
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="collectionId != null">collection_id,</if>
            <if test="type != null">`type`,</if>
            <if test="datasetId != null">datasetId,</if>
            <if test="parentId != null">parentId,</if>
            <if test="name != null">`name`,</if>
            <if test="collectionType != null">collection_type,</if>
            <if test="metadata != null">metadata,</if>
            <if test="text != null">text,</if>
            <if test="trainingType != null">trainingType,</if>
            <if test="chunkSize != null">chunkSize,</if>
            <if test="chunkSplitter != null">chunkSplitter,</if>
            <if test="qaPrompt != null">qaPrompt,</if>
            <if test="link != null">link,</if>
            <if test="fileUrl != null">fileUrl,</if>
            <if test="fileName != null">fileName,</if>
            <if test="updateTime != null">updateTime,</if>
            <if test="createTime != null">createTime,</if>
            <if test="forbid != null">forbid,</if>
            <if test="companyId != null">company_id,</if>
            <if test="dataAmount != null">data_amount,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="collectionId != null">#{collectionId},</if>
            <if test="type != null">#{type},</if>
            <if test="datasetId != null">#{datasetId},</if>
            <if test="parentId != null">#{parentId},</if>
            <if test="name != null">#{name},</if>
            <if test="collectionType != null">#{collectionType},</if>
            <if test="metadata != null">#{metadata},</if>
            <if test="text != null">#{text},</if>
            <if test="trainingType != null">#{trainingType},</if>
            <if test="chunkSize != null">#{chunkSize},</if>
            <if test="chunkSplitter != null">#{chunkSplitter},</if>
            <if test="qaPrompt != null">#{qaPrompt},</if>
            <if test="link != null">#{link},</if>
            <if test="fileUrl != null">#{fileUrl},</if>
            <if test="fileName != null">#{fileName},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="forbid != null">#{forbid},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="dataAmount != null">#{dataAmount},</if>
         </trim>
    </insert>


    <insert id="insertOrUpdateFastGptCollection" parameterType="FastGptCollection">
        insert into fastgpt_collection
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="collectionId != null">collection_id,</if>
            <if test="type != null">`type`,</if>
            <if test="datasetId != null">datasetId,</if>
            <if test="parentId != null">parentId,</if>
            <if test="name != null">`name`,</if>
            <if test="collectionType != null">collection_type,</if>
            <if test="metadata != null">metadata,</if>
            <if test="text != null">text,</if>
            <if test="trainingType != null">trainingType,</if>
            <if test="chunkSize != null">chunkSize,</if>
            <if test="chunkSplitter != null">chunkSplitter,</if>
            <if test="qaPrompt != null">qaPrompt,</if>
            <if test="link != null">link,</if>
            <if test="fileUrl != null">fileUrl,</if>
            <if test="fileName != null">fileName,</if>
            <if test="updateTime != null">updateTime,</if>
            <if test="createTime != null">createTime,</if>
            <if test="forbid != null">forbid,</if>
            <if test="companyId != null">company_id,</if>
            <if test="dataAmount != null">data_amount,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="collectionId != null">#{collectionId},</if>
            <if test="type != null">#{type},</if>
            <if test="datasetId != null">#{datasetId},</if>
            <if test="parentId != null">#{parentId},</if>
            <if test="name != null">#{name},</if>
            <if test="collectionType != null">#{collectionType},</if>
            <if test="metadata != null">#{metadata},</if>
            <if test="text != null">#{text},</if>
            <if test="trainingType != null">#{trainingType},</if>
            <if test="chunkSize != null">#{chunkSize},</if>
            <if test="chunkSplitter != null">#{chunkSplitter},</if>
            <if test="qaPrompt != null">#{qaPrompt},</if>
            <if test="link != null">#{link},</if>
            <if test="fileUrl != null">#{fileUrl},</if>
            <if test="fileName != null">#{fileName},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="forbid != null">#{forbid},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="dataAmount != null">#{dataAmount},</if>
        </trim>
        on duplicate key update
        <trim suffixOverrides=",">
            <if test="type != null">type = #{type},</if>
            <if test="datasetId != null">datasetId = #{datasetId},</if>
            <if test="parentId != null">parentId = #{parentId},</if>
            <if test="name != null">`name` = #{name},</if>
            <if test="collectionType != null">collection_type = #{collectionType},</if>
            <if test="metadata != null">metadata = #{metadata},</if>
            <if test="text != null">text = #{text},</if>
            <if test="trainingType != null">trainingType = #{trainingType},</if>
            <if test="chunkSize != null">chunkSize = #{chunkSize},</if>
            <if test="chunkSplitter != null">chunkSplitter = #{chunkSplitter},</if>
            <if test="qaPrompt != null">qaPrompt = #{qaPrompt},</if>
            <if test="link != null">link = #{link},</if>
            <if test="fileUrl != null">fileUrl = #{fileUrl},</if>
            <if test="fileName != null">fileName = #{fileName},</if>
            <if test="updateTime != null">updateTime = #{updateTime},</if>
            <if test="createTime != null">createTime = #{createTime},</if>
            <if test="forbid != null">forbid = #{forbid},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="dataAmount != null">data_amount = #{dataAmount},</if>
        </trim>
    </insert>


    <update id="updateFastGptCollection" parameterType="FastGptCollection">
        update fastgpt_collection
        <trim prefix="SET" suffixOverrides=",">
            <if test="type != null">type = #{type},</if>
            <if test="datasetId != null">datasetId = #{datasetId},</if>
            <if test="parentId != null">parentId = #{parentId},</if>
            <if test="name != null">`name` = #{name},</if>
            <if test="collectionType != null">collection_type = #{collectionType},</if>
            <if test="metadata != null">metadata = #{metadata},</if>
            <if test="text != null">text = #{text},</if>
            <if test="trainingType != null">trainingType = #{trainingType},</if>
            <if test="chunkSize != null">chunkSize = #{chunkSize},</if>
            <if test="chunkSplitter != null">chunkSplitter = #{chunkSplitter},</if>
            <if test="qaPrompt != null">qaPrompt = #{qaPrompt},</if>
            <if test="link != null">link = #{link},</if>
            <if test="fileUrl != null">fileUrl = #{fileUrl},</if>
            <if test="fileName != null">fileName = #{fileName},</if>
            <if test="updateTime != null">updateTime = #{updateTime},</if>
            <if test="createTime != null">createTime = #{createTime},</if>
            <if test="forbid != null">forbid = #{forbid},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="dataAmount != null">data_amount = #{dataAmount},</if>
        </trim>
        where collection_id = #{collectionId}
    </update>

    <delete id="deleteFastGptCollectionByCollectionId" parameterType="String">
        delete from fastgpt_collection where collection_id = #{collectionId}
    </delete>

    <delete id="deleteFastGptCollectionByCollectionIds" parameterType="String">
        delete from fastgpt_collection where collection_id in 
        <foreach item="collectionId" collection="array" open="(" separator="," close=")">
            #{collectionId}
        </foreach>
    </delete>
</mapper>