<?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.DatasetDetailMapper">
    <resultMap id="BaseResultMap" type="com.yice.webadmin.app.model.DatasetDetail">
        <id column="detail_id" jdbcType="BIGINT" property="detailId"/>
        <result column="dataset_id" jdbcType="BIGINT" property="datasetId"/>
        <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="version_id" jdbcType="BIGINT" property="versionId"/>
        <result column="dataset_value" jdbcType="LONGVARCHAR" property="datasetValue"/>
        <result column="serial_number" jdbcType="BIGINT" property="serialNumber"/>
    </resultMap>

    <insert id="insertList">
        INSERT INTO lmp_dataset_detail
        (detail_id,
        dataset_id,
        create_user_id,
        create_time,
        update_user_id,
        update_time,
        version_id,
        dataset_value,
        serial_number)
        VALUES
        <foreach collection="list" index="index" item="item" separator=",">
            (#{item.detailId},
            #{item.datasetId},
            #{item.createUserId},
            #{item.createTime},
            #{item.updateUserId},
            #{item.updateTime},
            #{item.versionId},
            #{item.datasetValue},
            #{item.serialNumber})
        </foreach>
    </insert>

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

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

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