<?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.yice.webadmin.app.dao.PromptOptimizeBatchMapper">
    <resultMap id="BaseResultMap" type="com.yice.webadmin.app.model.PromptOptimizeBatch">
        <id column="batch_task_id" jdbcType="BIGINT" property="batchTaskId"/>
        <result column="task_name" jdbcType="VARCHAR" property="taskName"/>
        <result column="task_describe" jdbcType="VARCHAR" property="taskDescribe"/>
        <result column="source_dataset_id" jdbcType="BIGINT" property="sourceDatasetId"/>
        <result column="source_dataset_name" jdbcType="VARCHAR" property="sourceDatasetName"/>
        <result column="source_dataset_version" jdbcType="BIGINT" property="sourceDatasetVersion"/>
        <result column="dest_dataset_id" jdbcType="BIGINT" property="destDatasetId"/>
        <result column="dest_dataset_name" jdbcType="VARCHAR" property="destDatasetName"/>
        <result column="dest_dataset_version" jdbcType="BIGINT" property="destDatasetVersion"/>
        <result column="quality_qptimality" jdbcType="TINYINT" property="qualityQptimality"/>
        <result column="shorten_prompt" jdbcType="TINYINT" property="shortenPrompt"/>
        <result column="epoch" jdbcType="TINYINT" property="epoch"/>
        <result column="chain" jdbcType="TINYINT" property="chain"/>
        <result column="task_status" jdbcType="TINYINT" property="taskStatus"/>
        <result column="create_user_id" jdbcType="BIGINT" property="createUserId"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="update_user_id" jdbcType="BIGINT" property="updateUserId"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
        <result column="success_count" jdbcType="BIGINT" property="successCount"/>
        <result column="fail_count" jdbcType="BIGINT" property="failCount"/>
        <result column="finish_time" jdbcType="TIMESTAMP" property="finishTime"/>
    </resultMap>

    <insert id="insertList">
        INSERT INTO lmp_prompt_optimize_batch
        (batch_task_id,
        task_name,
        task_describe,
        source_dataset_id,
        source_dataset_name,
        source_dataset_version,
        dest_dataset_id,
        dest_dataset_name,
        dest_dataset_version,
        quality_qptimality,
        shorten_prompt,
        epoch,
        chain,
        task_status,
        create_user_id,
        create_time,
        update_user_id,
        update_time,
        success_count,
        fail_count,
        finish_time)
        VALUES
        <foreach collection="list" index="index" item="item" separator=",">
            (#{item.batchTaskId},
            #{item.taskName},
            #{item.taskDescribe},
            #{item.sourceDatasetId},
            #{item.sourceDatasetName},
            #{item.sourceDatasetVersion},
            #{item.destDatasetId},
            #{item.destDatasetName},
            #{item.destDatasetVersion},
            #{item.qualityQptimality},
            #{item.shortenPrompt},
            #{item.epoch},
            #{item.chain},
            #{item.taskStatus},
            #{item.createUserId},
            #{item.createTime},
            #{item.updateUserId},
            #{item.updateTime},
            #{item.successCount},
            #{item.failCount},
            #{item.finishTime})
        </foreach>
    </insert>

    <!-- 如果有逻辑删除字段过滤，请写到这里 -->
    <sql id="filterRef">
        <!-- 这里必须加上全包名，否则当filterRef被其他Mapper.xml包含引用的时候，就会调用Mapper.xml中的该SQL片段 -->
        <include refid="com.yice.webadmin.app.dao.PromptOptimizeBatchMapper.inputFilterRef"/>
    </sql>

    <!-- 这里仅包含调用接口输入的主表过滤条件 -->
    <sql id="inputFilterRef">
        <if test="promptOptimizeBatchFilter != null">
            <if test="promptOptimizeBatchFilter.searchString != null and promptOptimizeBatchFilter.searchString != ''">
                <bind name="safePromptOptimizeBatchSearchString"
                      value="'%' + promptOptimizeBatchFilter.searchString + '%'"/>
                AND IFNULL(lmp_prompt_optimize_batch.task_name,'') LIKE #{safePromptOptimizeBatchSearchString}
            </if>
        </if>
    </sql>

    <select id="getPromptOptimizeBatchList" resultMap="BaseResultMap"
            parameterType="com.yice.webadmin.app.model.PromptOptimizeBatch">
        SELECT * FROM lmp_prompt_optimize_batch
        <where>
            <include refid="filterRef"/>
        </where>
        <if test="orderBy != null and orderBy != ''">
            ORDER BY ${orderBy}
        </if>
    </select>
</mapper>
