<?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.DatasetVersionMapper">
    <resultMap id="BaseResultMap" type="com.yice.webadmin.app.model.DatasetVersion">
        <id column="version_id" jdbcType="BIGINT" property="versionId"/>
        <result column="dataset_version" jdbcType="TINYINT" property="datasetVersion"/>
        <result column="input_status" jdbcType="TINYINT" property="inputStatus"/>
        <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="dataset_id" jdbcType="BIGINT" property="datasetId"/>
        <result column="output_status" jdbcType="TINYINT" property="outputStatus"/>
        <result column="clean_status" jdbcType="TINYINT" property="cleanStatus"/>
        <result column="enhance_status" jdbcType="TINYINT" property="enhanceStatus"/>
        <result column="release_status" jdbcType="TINYINT" property="releaseStatus"/>
        <result column="mark_progress" jdbcType="TINYINT" property="markProgress"/>
        <result column="data_volume" jdbcType="BIGINT" property="dataVolume"/>
        <result column="dimension_type" jdbcType="TINYINT" property="dimensionType"/>
        <result column="template" jdbcType="TINYINT" property="template"/>
        <result column="is_inherit" jdbcType="TINYINT" property="isInherit"/>
        <result column="his_version" jdbcType="TINYINT" property="hisVersion"/>
        <result column="file_url" jdbcType="VARCHAR" property="fileUrl"/>
        <result column="version_name" jdbcType="VARCHAR" property="versionName"/>
    </resultMap>

    <insert id="insertList">
        INSERT INTO lmp_dataset_version
        (version_id,
        dataset_version,
        input_status,
        create_user_id,
        create_time,
        update_user_id,
        update_time,
        dataset_id,
        output_status,
        clean_status,
        enhance_status,
        release_status,
        mark_progress,
        data_volume,
        dimension_type,
        template,
        is_inherit,
        his_version,
        version_name)
        VALUES
        <foreach collection="list" index="index" item="item" separator=",">
            (#{item.versionId},
            #{item.datasetVersion},
            #{item.inputStatus},
            #{item.createUserId},
            #{item.createTime},
            #{item.updateUserId},
            #{item.updateTime},
            #{item.datasetId},
            #{item.outputStatus},
            #{item.cleanStatus},
            #{item.enhanceStatus},
            #{item.releaseStatus},
            #{item.markProgress},
            #{item.dataVolume},
            #{item.dimensionType},
            #{item.template},
            #{item.isInherit},
            #{item.hisVersion},
            #{item.versionName}
            )
        </foreach>
    </insert>

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

    <!-- 这里仅包含调用接口输入的主表过滤条件 -->
    <sql id="inputFilterRef">
        <if test="datasetVersionFilter != null">
            <if test="datasetVersionFilter.datasetVersion != null and datasetVersionFilter.datasetVersion != ''">
                AND lmp_dataset_version.dataset_version = #{datasetVersionFilter.datasetVersion}
            </if>
            <if test="datasetVersionFilter.datasetId != null">
                AND lmp_dataset_version.dataset_id = #{datasetVersionFilter.datasetId}
            </if>
        </if>
    </sql>

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

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