<?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.ModelTaskMapper">
    <resultMap id="BaseResultMap" type="com.yice.webadmin.app.model.ModelTask">
        <id column="task_id" jdbcType="BIGINT" property="taskId"/>
        <result column="model_id" jdbcType="BIGINT" property="modelId"/>
        <result column="version_id" jdbcType="BIGINT" property="versionId"/>
        <result column="version_name" jdbcType="VARCHAR" property="versionName"/>
        <result column="task_type" jdbcType="TINYINT" property="taskType"/>
        <result column="task_status" jdbcType="TINYINT" property="taskStatus"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="complete_time" jdbcType="TIMESTAMP" property="completeTime"/>
        <result column="create_user_id" jdbcType="BIGINT" property="createUserId"/>
        <result column="update_user_id" jdbcType="BIGINT" property="updateUserId"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
        <result column="model_version" jdbcType="TINYINT" property="modelVersion"/>
    </resultMap>

    <insert id="insertList">
        INSERT INTO lmp_model_task
        (task_id,
        model_id,
        version_id,
        version_name,
        task_type,
        task_status,
        create_time,
        complete_time,
        create_user_id,
        update_user_id,
        update_time,
        model_version)
        VALUES
        <foreach collection="list" index="index" item="item" separator=",">
            (#{item.taskId},
            #{item.modelId},
            #{item.versionId},
            #{item.versionName},
            #{item.taskType},
            #{item.taskStatus},
            #{item.createTime},
            #{item.completeTime},
            #{item.createUserId},
            #{item.updateUserId},
            #{item.updateTime},
            #{item.modelVersion})
        </foreach>
    </insert>

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

    <!-- 这里仅包含调用接口输入的主表过滤条件 -->
    <sql id="inputFilterRef">
        <if test="modelTaskFilter != null">
            <if test="modelTaskFilter.modelId != null">
                AND lmp_model_task.model_id = #{modelTaskFilter.modelId}
            </if>
            <if test="modelTaskFilter.versionId != null">
                AND lmp_model_task.version_id = #{modelTaskFilter.versionId}
            </if>
        </if>
    </sql>

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

    <!-- 支持基于一对一或者一对多从表字段过滤的SQL_ID -->
    <select id="getModelTaskListEx" resultMap="BaseResultMap">
        SELECT
        lmp_model_task.*
        FROM
        lmp_model_task
        LEFT JOIN
        lmp_model_estimate ON lmp_model_task.task_id = lmp_model_estimate.task_id
        LEFT JOIN
        lmp_model_compress ON lmp_model_task.task_id = lmp_model_compress.task_id
        <where>
            <include refid="filterRef"/>
            <include refid="com.yice.webadmin.app.dao.ModelEstimateMapper.inputFilterRef"/>
            <include refid="com.yice.webadmin.app.dao.ModelCompressMapper.inputFilterRef"/>
        </where>
        <if test="orderBy != null and orderBy != ''">
            ORDER BY ${orderBy}
        </if>
    </select>
</mapper>
