<?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.FastGptDatasetMapper">
    
    <resultMap type="FastGptDataset" id="FastGptDatasetResult">
        <result property="datasetId"    column="dataset_id"    />
        <result property="parentId"    column="parentId"    />
        <result property="type"    column="type"    />
        <result property="name"    column="name"    />
        <result property="intro"    column="intro"    />
        <result property="avatar"    column="avatar"    />
        <result property="vectorModel"    column="vectorModel"    />
        <result property="agentModel"    column="agentModel"    />
        <result property="permission"    column="permission"    />
        <result property="canWrite"    column="canWrite"    />
        <result property="isOwner"    column="isOwner"    />
        <result property="updateTime"    column="updateTime"    />
        <result property="createTime"    column="createTime"    />
        <result property="companyId"    column="company_id"    />
    </resultMap>

    <sql id="selectFastGptDatasetVo">
        select dataset_id, parentId, type, name, intro, avatar, vectorModel, agentModel, permission, canWrite, isOwner, updateTime, createTime, company_id from fastgpt_dataset
    </sql>

    <select id="selectFastGptDatasetList" parameterType="FastGptDataset" resultMap="FastGptDatasetResult">
        <include refid="selectFastGptDatasetVo"/>
        <where>  
            <if test="parentId != null  and parentId != ''"> and parentId = #{parentId}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="intro != null  and intro != ''"> and intro = #{intro}</if>
            <if test="avatar != null  and avatar != ''"> and avatar = #{avatar}</if>
            <if test="vectorModel != null  and vectorModel != ''"> and vectorModel = #{vectorModel}</if>
            <if test="agentModel != null  and agentModel != ''"> and agentModel = #{agentModel}</if>
            <if test="permission != null  and permission != ''"> and permission = #{permission}</if>
            <if test="canWrite != null "> and canWrite = #{canWrite}</if>
            <if test="isOwner != null "> and isOwner = #{isOwner}</if>
            <if test="updateTime != null "> and updateTime = #{updateTime}</if>
            <if test="createTime != null "> and createTime = #{createTime}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
        </where>
    </select>
    
    <select id="selectFastGptDatasetByDatasetId" parameterType="String" resultMap="FastGptDatasetResult">
        <include refid="selectFastGptDatasetVo"/>
        where dataset_id = #{datasetId}
    </select>
        
    <insert id="insertFastGptDataset" parameterType="FastGptDataset">
        insert into fastgpt_dataset
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="datasetId != null">dataset_id,</if>
            <if test="parentId != null">parentId,</if>
            <if test="type != null">type,</if>
            <if test="name != null">name,</if>
            <if test="intro != null">intro,</if>
            <if test="avatar != null">avatar,</if>
            <if test="vectorModel != null">vectorModel,</if>
            <if test="agentModel != null">agentModel,</if>
            <if test="permission != null">permission,</if>
            <if test="canWrite != null">canWrite,</if>
            <if test="isOwner != null">isOwner,</if>
            <if test="updateTime != null">updateTime,</if>
            <if test="createTime != null">createTime,</if>
            <if test="companyId != null">company_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="datasetId != null">#{datasetId},</if>
            <if test="parentId != null">#{parentId},</if>
            <if test="type != null">#{type},</if>
            <if test="name != null">#{name},</if>
            <if test="intro != null">#{intro},</if>
            <if test="avatar != null">#{avatar},</if>
            <if test="vectorModel != null">#{vectorModel},</if>
            <if test="agentModel != null">#{agentModel},</if>
            <if test="permission != null">#{permission},</if>
            <if test="canWrite != null">#{canWrite},</if>
            <if test="isOwner != null">#{isOwner},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="companyId != null">#{companyId},</if>
         </trim>
    </insert>

    <insert id="insertOrUpdateFastGptDataset" parameterType="FastGptDataset">
        insert into fastgpt_dataset
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="datasetId != null">dataset_id,</if>
            <if test="parentId != null">parentId,</if>
            <if test="type != null">type,</if>
            <if test="name != null">name,</if>
            <if test="intro != null">intro,</if>
            <if test="avatar != null">avatar,</if>
            <if test="vectorModel != null">vectorModel,</if>
            <if test="agentModel != null">agentModel,</if>
            <if test="permission != null">permission,</if>
            <if test="canWrite != null">canWrite,</if>
            <if test="isOwner != null">isOwner,</if>
            <if test="updateTime != null">updateTime,</if>
            <if test="createTime != null">createTime,</if>
            <if test="companyId != null">company_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="datasetId != null">#{datasetId},</if>
            <if test="parentId != null">#{parentId},</if>
            <if test="type != null">#{type},</if>
            <if test="name != null">#{name},</if>
            <if test="intro != null">#{intro},</if>
            <if test="avatar != null">#{avatar},</if>
            <if test="vectorModel != null">#{vectorModel},</if>
            <if test="agentModel != null">#{agentModel},</if>
            <if test="permission != null">#{permission},</if>
            <if test="canWrite != null">#{canWrite},</if>
            <if test="isOwner != null">#{isOwner},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="companyId != null">#{companyId},</if>
        </trim>
        on duplicate key update
        <trim suffixOverrides=",">
            <if test="parentId != null">parentId = #{parentId},</if>
            <if test="type != null">type = #{type},</if>
            <if test="name != null">name = #{name},</if>
            <if test="intro != null">intro = #{intro},</if>
            <if test="avatar != null">avatar = #{avatar},</if>
            <if test="vectorModel != null">vectorModel = #{vectorModel},</if>
            <if test="agentModel != null">agentModel = #{agentModel},</if>
            <if test="permission != null">permission = #{permission},</if>
            <if test="canWrite != null">canWrite = #{canWrite},</if>
            <if test="isOwner != null">isOwner = #{isOwner},</if>
            <if test="updateTime != null">updateTime = #{updateTime},</if>
            <if test="createTime != null">createTime = #{createTime},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
        </trim>
    </insert>


    <update id="updateFastGptDataset" parameterType="FastGptDataset">
        update fastgpt_dataset
        <trim prefix="SET" suffixOverrides=",">
            <if test="parentId != null">parentId = #{parentId},</if>
            <if test="type != null">type = #{type},</if>
            <if test="name != null">name = #{name},</if>
            <if test="intro != null">intro = #{intro},</if>
            <if test="avatar != null">avatar = #{avatar},</if>
            <if test="vectorModel != null">vectorModel = #{vectorModel},</if>
            <if test="agentModel != null">agentModel = #{agentModel},</if>
            <if test="permission != null">permission = #{permission},</if>
            <if test="canWrite != null">canWrite = #{canWrite},</if>
            <if test="isOwner != null">isOwner = #{isOwner},</if>
            <if test="updateTime != null">updateTime = #{updateTime},</if>
            <if test="createTime != null">createTime = #{createTime},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
        </trim>
        where dataset_id = #{datasetId}
    </update>

    <delete id="deleteFastGptDatasetByDatasetId" parameterType="String">
        delete from fastgpt_dataset where dataset_id = #{datasetId}
    </delete>

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