<?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.TuningRunMapper">
    <resultMap id="BaseResultMap" type="com.yice.webadmin.app.model.TuningRun">
        <id column="run_id" jdbcType="BIGINT" property="runId"/>
        <result column="task_id" jdbcType="BIGINT" property="taskId"/>
        <result column="run_status" jdbcType="TINYINT" property="runStatus"/>
        <result column="run_version" jdbcType="TINYINT" property="runVersion"/>
        <result column="run_name" jdbcType="VARCHAR" property="runName"/>
        <result column="model_id" jdbcType="BIGINT" property="modelId"/>
        <result column="model_version_id" jdbcType="BIGINT" property="modelVersionId"/>
        <result column="run_time" jdbcType="BIGINT" property="runTime"/>
        <result column="dataset_version_id" jdbcType="BIGINT" property="datasetVersionId"/>
        <result column="split_ratio" jdbcType="TINYINT" property="splitRatio"/>
        <result column="train_mode" jdbcType="VARCHAR" property="trainMode"/>
        <result column="train_method" jdbcType="VARCHAR" property="trainMethod"/>
        <result column="configuration" jdbcType="LONGVARCHAR" property="configuration"/>
        <result column="publish_status" jdbcType="TINYINT" property="publishStatus"/>
        <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"/>
    </resultMap>

    <insert id="insertList">
        INSERT INTO lmp_tuning_run
        (run_id,
        task_id,
        run_status,
        run_version,
        run_name,
        model_id,
        model_version_id,
        run_time,
        dataset_version_id,
        split_ratio,
        train_mode,
        train_method,
        configuration,
        publish_status,
        create_user_id,
        create_time,
        update_user_id,
        update_time)
        VALUES
        <foreach collection="list" index="index" item="item" separator=",">
            (#{item.runId},
            #{item.taskId},
            #{item.runStatus},
            #{item.runVersion},
            #{item.runName},
            #{item.modelId},
            #{item.modelVersionId},
            #{item.runTime},
            #{item.datasetVersionId},
            #{item.splitRatio},
            #{item.trainMode},
            #{item.trainMethod},
            #{item.configuration},
            #{item.publishStatus},
            #{item.createUserId},
            #{item.createTime},
            #{item.updateUserId},
            #{item.updateTime})
        </foreach>
    </insert>

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

    <!-- 这里仅包含调用接口输入的主表过滤条件 -->
    <sql id="inputFilterRef">
        <if test="tuningRunFilter != null">
            <if test="tuningRunFilter.runId != null">
                AND lmp_tuning_run.run_id = #{tuningRunFilter.runId}
            </if>
            <if test="tuningRunFilter.taskId != null">
                AND lmp_tuning_run.task_id = #{tuningRunFilter.taskId}
            </if>
        </if>
    </sql>

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