<?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.FastGptCollentionDataMapper">
    
    <resultMap type="FastGptCollentionData" id="FastGptCollentionDataResult">
        <result property="id"    column="id"    />
        <result property="collectionId"    column="collectionId"    />
        <result property="question"    column="question"    />
        <result property="answer"    column="answer"    />
        <result property="indexes"    column="indexes"    />
        <result property="datasetId"    column="datasetId"    />
        <result property="chunkIndex"    column="chunkIndex"    />
        <result property="companyId"    column="company_id"    />
    </resultMap>

    <sql id="selectFastGptCollentionDataVo">
        select id, collectionId, question, answer, indexes,datasetId,chunkIndex,company_id  from fastgpt_collention_data
    </sql>

    <select id="selectFastGptCollentionDataList" parameterType="FastGptCollentionData" resultMap="FastGptCollentionDataResult">
        <include refid="selectFastGptCollentionDataVo"/>
        <where>  
            <if test="collectionId != null  and collectionId != ''"> and collectionId = #{collectionId}</if>
            <if test="question != null  and question != ''"> and question like concat('%', #{question}, '%')</if>
            <if test="answer != null  and answer != ''"> and answer like concat('%', #{answer}, '%')</if>
            <if test="indexes != null  and indexes != ''"> and indexes = #{indexes}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
        </where>
    </select>
    
    <select id="selectFastGptCollentionDataById" parameterType="String" resultMap="FastGptCollentionDataResult">
        <include refid="selectFastGptCollentionDataVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertFastGptCollentionData" parameterType="FastGptCollentionData">
        insert into fastgpt_collention_data
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="collectionId != null">collectionId,</if>
            <if test="question != null">question,</if>
            <if test="answer != null">answer,</if>
            <if test="indexes != null">indexes,</if>
            <if test="datasetId != null">datasetId,</if>
            <if test="chunkIndex != null">chunkIndex,</if>
            <if test="companyId != null">company_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="collectionId != null">#{collectionId},</if>
            <if test="question != null">#{question},</if>
            <if test="answer != null">#{answer},</if>
            <if test="indexes != null">#{indexes},</if>
            <if test="datasetId != null">#{datasetId},</if>
            <if test="chunkIndex != null">#{chunkIndex},</if>
            <if test="companyId != null">#{companyId},</if>
         </trim>
    </insert>

    <insert id="insertOrUpdateFastGptCollentionData" parameterType="FastGptCollentionData">
        insert into fastgpt_collention_data
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="collectionId != null">collectionId,</if>
            <if test="question != null">question,</if>
            <if test="answer != null">answer,</if>
            <if test="indexes != null">indexes,</if>
            <if test="datasetId != null">datasetId,</if>
            <if test="chunkIndex != null">chunkIndex,</if>
            <if test="companyId != null">company_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="collectionId != null">#{collectionId},</if>
            <if test="question != null">#{question},</if>
            <if test="answer != null">#{answer},</if>
            <if test="indexes != null">#{indexes},</if>
            <if test="datasetId != null">#{datasetId},</if>
            <if test="chunkIndex != null">#{chunkIndex},</if>
            <if test="companyId != null">#{companyId},</if>
        </trim>
        on duplicate key update
        <trim suffixOverrides=",">
            <if test="collectionId != null">collectionId = #{collectionId},</if>
            <if test="question != null">question = #{question},</if>
            <if test="answer != null">answer = #{answer},</if>
            <if test="indexes != null">indexes = #{indexes},</if>
            <if test="datasetId != null">datasetId = #{datasetId},</if>
            <if test="chunkIndex != null">chunkIndex = #{chunkIndex},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
        </trim>
    </insert>

    <update id="updateFastGptCollentionData" parameterType="FastGptCollentionData">
        update fastgpt_collention_data
        <trim prefix="SET" suffixOverrides=",">
            <if test="collectionId != null">collectionId = #{collectionId},</if>
            <if test="question != null">question = #{question},</if>
            <if test="answer != null">answer = #{answer},</if>
            <if test="indexes != null">indexes = #{indexes},</if>
            <if test="datasetId != null">datasetId = #{datasetId},</if>
            <if test="chunkIndex != null">chunkIndex = #{chunkIndex},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteFastGptCollentionDataById" parameterType="String">
        delete from fastgpt_collention_data where id = #{id}
    </delete>

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