<?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.xisc.pm.infra.mapper.PmCmdSmallPltTraMapper">


    <sql id = "BaseSql">
        PCSPT.TRA_ID,
        PCSPT.OPERATION_TYPE,
        PCSPT.OPERATION_USER,
        PCSPT.OPERATION_TIME,
        PCSPT.PM_CMD_SMALL_PLT_ID,
        PCSPT.PONO_SLAB_NO,
        PCSPT.TMP_SLAB_NO,
        PCSPT.SMALL_PLATE_DIV_NO,
        PCSPT.ORDER_NO,
        PCSPT.ORDER_SEQ_NO,
        PCSPT.SLAB_NO,
        PCSPT.PLATE_NO,
        PCSPT.PICK_MODE_WID_DIR,
        PCSPT.PICK_MODE_LEN_DIR,
        PCSPT.ORDER_THICK,
        PCSPT.ORDER_WIDTH,
        PCSPT.ORDER_LEN,
        PCSPT.ORDER_LEN_MIN,
        PCSPT.ORDER_LEN_MAX,
        PCSPT.SMALL_PLATE_THICK,
        PCSPT.SMALL_PLATE_WIDTH,
        PCSPT.SMALL_PLATE_LEN,
        PCSPT.SAMPLE_LEN_GIVE,
        PCSPT.SAMPLE_WIDTH_GIVE,
        PCSPT.SAMPLE_GIVE_SHP,
        PCSPT.SAMPLE_HEAD_LEN_FREE,
        PCSPT.SAMPLE_TAIL_LEN_FREE,
        PCSPT.SAMPLE_HEAD_LEN_PLATE,
        PCSPT.SAMPLE_TAIL_LEN_PLATE,
        PCSPT.SAMPLE_HEAD_LEN_MB,
        PCSPT.SAMPLE_TAIL_LEN_MB,
        PCSPT.MSC_LINE_NO,
        PCSPT.TENANT_ID,
        PCSPT.ATTRIBUTE1,
        PCSPT.ATTRIBUTE2,
        PCSPT.ATTRIBUTE3,
        PCSPT.ATTRIBUTE4,
        PCSPT.ATTRIBUTE5,
        PCSPT.creation_date,        PCSPT.created_by,        PCSPT.last_updated_by,        PCSPT.last_update_date,        PCSPT.object_version_number
    </sql>

    <select id = "selectList" resultType = "com.xisc.pm.domain.entity.PmCmdSmallPltTra">
        select
        <include refid = "BaseSql"/>
        from PM_CMD_SMALL_PLT_TRA PCSPT
        <where>
            <if test="traId !=null">
                and PCSPT.TRA_ID = #{traId,jdbcType = INTEGER}
            </if>
            <if test="operationType !=null">
                and PCSPT.OPERATION_TYPE = #{operationType,jdbcType = VARCHAR}
            </if>
            <if test="operationUser !=null">
                and PCSPT.OPERATION_USER = #{operationUser,jdbcType = VARCHAR}
            </if>
            <if test="operationTime !=null">
                and PCSPT.OPERATION_TIME = #{operationTime,jdbcType = OTHER}
            </if>
            <if test="pmCmdSmallPltId !=null">
                and PCSPT.PM_CMD_SMALL_PLT_ID = #{pmCmdSmallPltId,jdbcType = INTEGER}
            </if>
            <if test="ponoSlabNo !=null">
                and PCSPT.PONO_SLAB_NO = #{ponoSlabNo,jdbcType = VARCHAR}
            </if>
            <if test="tmpSlabNo !=null">
                and PCSPT.TMP_SLAB_NO = #{tmpSlabNo,jdbcType = VARCHAR}
            </if>
            <if test="smallPlateDivNo !=null">
                and PCSPT.SMALL_PLATE_DIV_NO = #{smallPlateDivNo,jdbcType = VARCHAR}
            </if>
            <if test="orderNo !=null">
                and PCSPT.ORDER_NO = #{orderNo,jdbcType = VARCHAR}
            </if>
            <if test="orderSeqNo !=null">
                and PCSPT.ORDER_SEQ_NO = #{orderSeqNo,jdbcType = INTEGER}
            </if>
            <if test="slabNo !=null">
                and PCSPT.SLAB_NO = #{slabNo,jdbcType = VARCHAR}
            </if>
            <if test="plateNo !=null">
                and PCSPT.PLATE_NO = #{plateNo,jdbcType = VARCHAR}
            </if>
            <if test="pickModeWidDir !=null">
                and PCSPT.PICK_MODE_WID_DIR = #{pickModeWidDir,jdbcType = INTEGER}
            </if>
            <if test="pickModeLenDir !=null">
                and PCSPT.PICK_MODE_LEN_DIR = #{pickModeLenDir,jdbcType = INTEGER}
            </if>
            <if test="orderThick !=null">
                and PCSPT.ORDER_THICK = #{orderThick,jdbcType = INTEGER}
            </if>
            <if test="orderWidth !=null">
                and PCSPT.ORDER_WIDTH = #{orderWidth,jdbcType = INTEGER}
            </if>
            <if test="orderLen !=null">
                and PCSPT.ORDER_LEN = #{orderLen,jdbcType = INTEGER}
            </if>
            <if test="orderLenMin !=null">
                and PCSPT.ORDER_LEN_MIN = #{orderLenMin,jdbcType = INTEGER}
            </if>
            <if test="orderLenMax !=null">
                and PCSPT.ORDER_LEN_MAX = #{orderLenMax,jdbcType = INTEGER}
            </if>
            <if test="smallPlateThick !=null">
                and PCSPT.SMALL_PLATE_THICK = #{smallPlateThick,jdbcType = INTEGER}
            </if>
            <if test="smallPlateWidth !=null">
                and PCSPT.SMALL_PLATE_WIDTH = #{smallPlateWidth,jdbcType = INTEGER}
            </if>
            <if test="smallPlateLen !=null">
                and PCSPT.SMALL_PLATE_LEN = #{smallPlateLen,jdbcType = INTEGER}
            </if>
            <if test="sampleLenGive !=null">
                and PCSPT.SAMPLE_LEN_GIVE = #{sampleLenGive,jdbcType = INTEGER}
            </if>
            <if test="sampleWidthGive !=null">
                and PCSPT.SAMPLE_WIDTH_GIVE = #{sampleWidthGive,jdbcType = INTEGER}
            </if>
            <if test="sampleGiveShp !=null">
                and PCSPT.SAMPLE_GIVE_SHP = #{sampleGiveShp,jdbcType = VARCHAR}
            </if>
            <if test="sampleHeadLenFree !=null">
                and PCSPT.SAMPLE_HEAD_LEN_FREE = #{sampleHeadLenFree,jdbcType = INTEGER}
            </if>
            <if test="sampleTailLenFree !=null">
                and PCSPT.SAMPLE_TAIL_LEN_FREE = #{sampleTailLenFree,jdbcType = INTEGER}
            </if>
            <if test="sampleHeadLenPlate !=null">
                and PCSPT.SAMPLE_HEAD_LEN_PLATE = #{sampleHeadLenPlate,jdbcType = INTEGER}
            </if>
            <if test="sampleTailLenPlate !=null">
                and PCSPT.SAMPLE_TAIL_LEN_PLATE = #{sampleTailLenPlate,jdbcType = INTEGER}
            </if>
            <if test="sampleHeadLenMb !=null">
                and PCSPT.SAMPLE_HEAD_LEN_MB = #{sampleHeadLenMb,jdbcType = INTEGER}
            </if>
            <if test="sampleTailLenMb !=null">
                and PCSPT.SAMPLE_TAIL_LEN_MB = #{sampleTailLenMb,jdbcType = INTEGER}
            </if>
            <if test="mscLineNo !=null">
                and PCSPT.MSC_LINE_NO = #{mscLineNo,jdbcType = VARCHAR}
            </if>
            <if test="tenantId !=null">
                and PCSPT.TENANT_ID = #{tenantId,jdbcType = INTEGER}
            </if>
            <if test="attribute1 !=null">
                and PCSPT.ATTRIBUTE1 = #{attribute1,jdbcType = VARCHAR}
            </if>
            <if test="attribute2 !=null">
                and PCSPT.ATTRIBUTE2 = #{attribute2,jdbcType = VARCHAR}
            </if>
            <if test="attribute3 !=null">
                and PCSPT.ATTRIBUTE3 = #{attribute3,jdbcType = VARCHAR}
            </if>
            <if test="attribute4 !=null">
                and PCSPT.ATTRIBUTE4 = #{attribute4,jdbcType = VARCHAR}
            </if>
            <if test="attribute5 !=null">
                and PCSPT.ATTRIBUTE5 = #{attribute5,jdbcType = VARCHAR}
            </if>
        </where>
    </select>

    <select id="selectByPonoSlabList" resultType = "com.xisc.pm.domain.entity.PmCmdSmallPltTra">
        select
        <include refid="BaseSql"/>
        from (
        select
        <include refid="BaseSql"/>,
        ROW_NUMBER() OVER (PARTITION BY PCSPT.PONO_SLAB_NO ORDER BY PCSPT.creation_date DESC) as rn
        from PM_CMD_SMALL_PLT_TRA PCSPT
        <where>
            <if test="ponoSlabList != null and ponoSlabList.size() > 0">
                and PCSPT.PONO_SLAB_NO in
                <foreach collection="ponoSlabList" item="ponoSlab" index="index" open="(" close=")" separator=",">
                    #{ponoSlab}
                </foreach>
            </if>
            <if test="tenantId != null">
                and PCSPT.TENANT_ID = #{tenantId}
            </if>
        </where>
        ) PCSPT
        where PCSPT.rn = 1
    </select>
</mapper>

