<?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.PmPdSlabInfoMapper">


    <sql id = "BaseSql">
    PPSI.SLAB_INFO_ID,
    PPSI.SLAB_NO,
    PPSI.WHOLE_BACKLOG_SEQ,
    PPSI.WHOLE_BACKLOG_CODE,
    PPSI.NEXT_WHOLE_BACKLOG_SEQ,
    PPSI.NEXT_WHOLE_BACKLOG_CODE,
    PPSI.OU_BACKLOG_SEQ,
    PPSI.OU_BACKLOG_CODE,
    PPSI.PONO,
    PPSI.MAT_STATUS,
    PPSI.SLAB_FLAG,
    PPSI.OU_STATUS_HP,
    PPSI.AUTO_MANUAL_FLAG,
    PPSI.OU_BEGIN_TIME,
    PPSI.OU_END_TIME,
    PPSI.OU_PROGRAM,
    PPSI.OU_RESP,
    PPSI.STOCK_CODE,
    PPSI.SG_SIGN,
    PPSI.ST_NO,
    PPSI.PREC_ST_NO,
    PPSI.DECI_ST_NO,
    PPSI.FIN_ST_NO,
    PPSI.PSC,
    PPSI.APN,
    PPSI.MSC,
    PPSI.MSC_LINE_NO,
    PPSI.OLD_PSC,
    PPSI.OLD_APN,
    PPSI.OLD_MSC,
    PPSI.OLD_MSC_LINE,
    PPSI.CAN_ASSIGN_FLAG,
    PPSI.REMAIN_CAUSE_CODE,
    PPSI.COMPLEX_DECIDE_CODE,
    PPSI.MAT_ACT_THICK,
    PPSI.MAT_ACT_WIDTH,
    PPSI.MAT_ACT_LEN,
    PPSI.MAT_ACT_WT,
    PPSI.MAT_THEORY_WT,
    PPSI.SLAB_PLACE_CODE,
    PPSI.BD_FLAG,
    PPSI.CC_TYPE,
    PPSI.OU_RESP_AUTO,
    PPSI.OU_TIME_AUTO,
    PPSI.OU_AUTO_FLAG,
    PPSI.OU_MEMO1,
    PPSI.OU_MEMO2,
    PPSI.OU_MEMO3,
    PPSI.OU_MEMO4,
    PPSI.OU_MEMO5,
    PPSI.OU_MEMO6,
    PPSI.OU_MEMO7,
    PPSI.OU_MEMO8,
    PPSI.OU_MEMO9,
    PPSI.OU_MEMO10,
    PPSI.INGOT_TYPE,
    PPSI.TENANT_ID,
    PPSI.ATTRIBUTE1,
    PPSI.ATTRIBUTE2,
    PPSI.ATTRIBUTE3,
    PPSI.ATTRIBUTE4,
    PPSI.ATTRIBUTE5,
    PPSI.creation_date,    PPSI.created_by,    PPSI.last_updated_by,    PPSI.last_update_date,    PPSI.object_version_number
    </sql>

    <select id = "selectList" resultType = "com.xisc.pm.domain.entity.PmPdSlabInfo">
        select
        <include refid = "BaseSql"/>
        from PM_PD_SLAB_INFO PPSI
        <where>
            <if test="slabInfoId !=null">
                and PPSI.SLAB_INFO_ID = #{slabInfoId,jdbcType = INTEGER}
            </if>
            <if test="slabNo !=null">
                and PPSI.SLAB_NO = #{slabNo,jdbcType = VARCHAR}
            </if>
            <if test="wholeBacklogSeq !=null">
                and PPSI.WHOLE_BACKLOG_SEQ = #{wholeBacklogSeq,jdbcType = INTEGER}
            </if>
            <if test="wholeBacklogCode !=null">
                and PPSI.WHOLE_BACKLOG_CODE = #{wholeBacklogCode,jdbcType = VARCHAR}
            </if>
            <if test="nextWholeBacklogSeq !=null">
                and PPSI.NEXT_WHOLE_BACKLOG_SEQ = #{nextWholeBacklogSeq,jdbcType = INTEGER}
            </if>
            <if test="nextWholeBacklogCode !=null">
                and PPSI.NEXT_WHOLE_BACKLOG_CODE = #{nextWholeBacklogCode,jdbcType = VARCHAR}
            </if>
            <if test="ouBacklogSeq !=null">
                and PPSI.OU_BACKLOG_SEQ = #{ouBacklogSeq,jdbcType = INTEGER}
            </if>
            <if test="ouBacklogCode !=null">
                and PPSI.OU_BACKLOG_CODE = #{ouBacklogCode,jdbcType = VARCHAR}
            </if>
            <if test="pono !=null">
                and PPSI.PONO = #{pono,jdbcType = VARCHAR}
            </if>
            <if test="matStatus !=null">
                and PPSI.MAT_STATUS = #{matStatus,jdbcType = VARCHAR}
            </if>
            <if test="slabFlag !=null">
                and PPSI.SLAB_FLAG = #{slabFlag,jdbcType = VARCHAR}
            </if>
            <if test="ouStatusHp !=null">
                and PPSI.OU_STATUS_HP = #{ouStatusHp,jdbcType = VARCHAR}
            </if>
            <if test="autoManualFlag !=null">
                and PPSI.AUTO_MANUAL_FLAG = #{autoManualFlag,jdbcType = VARCHAR}
            </if>
            <if test="ouBeginTime !=null">
                and PPSI.OU_BEGIN_TIME = #{ouBeginTime,jdbcType = VARCHAR}
            </if>
            <if test="ouEndTime !=null">
                and PPSI.OU_END_TIME = #{ouEndTime,jdbcType = VARCHAR}
            </if>
            <if test="ouProgram !=null">
                and PPSI.OU_PROGRAM = #{ouProgram,jdbcType = VARCHAR}
            </if>
            <if test="ouResp !=null">
                and PPSI.OU_RESP = #{ouResp,jdbcType = VARCHAR}
            </if>
            <if test="stockCode !=null">
                and PPSI.STOCK_CODE = #{stockCode,jdbcType = VARCHAR}
            </if>
            <if test="sgSign !=null">
                and PPSI.SG_SIGN = #{sgSign,jdbcType = VARCHAR}
            </if>
            <if test="stNo !=null">
                and PPSI.ST_NO = #{stNo,jdbcType = VARCHAR}
            </if>
            <if test="precStNo !=null">
                and PPSI.PREC_ST_NO = #{precStNo,jdbcType = VARCHAR}
            </if>
            <if test="deciStNo !=null">
                and PPSI.DECI_ST_NO = #{deciStNo,jdbcType = VARCHAR}
            </if>
            <if test="finStNo !=null">
                and PPSI.FIN_ST_NO = #{finStNo,jdbcType = VARCHAR}
            </if>
            <if test="psc !=null">
                and PPSI.PSC = #{psc,jdbcType = VARCHAR}
            </if>
            <if test="apn !=null">
                and PPSI.APN = #{apn,jdbcType = VARCHAR}
            </if>
            <if test="msc !=null">
                and PPSI.MSC = #{msc,jdbcType = VARCHAR}
            </if>
            <if test="mscLineNo !=null">
                and PPSI.MSC_LINE_NO = #{mscLineNo,jdbcType = VARCHAR}
            </if>
            <if test="oldPsc !=null">
                and PPSI.OLD_PSC = #{oldPsc,jdbcType = VARCHAR}
            </if>
            <if test="oldApn !=null">
                and PPSI.OLD_APN = #{oldApn,jdbcType = VARCHAR}
            </if>
            <if test="oldMsc !=null">
                and PPSI.OLD_MSC = #{oldMsc,jdbcType = VARCHAR}
            </if>
            <if test="oldMscLine !=null">
                and PPSI.OLD_MSC_LINE = #{oldMscLine,jdbcType = VARCHAR}
            </if>
            <if test="canAssignFlag !=null">
                and PPSI.CAN_ASSIGN_FLAG = #{canAssignFlag,jdbcType = VARCHAR}
            </if>
            <if test="remainCauseCode !=null">
                and PPSI.REMAIN_CAUSE_CODE = #{remainCauseCode,jdbcType = VARCHAR}
            </if>
            <if test="complexDecideCode !=null">
                and PPSI.COMPLEX_DECIDE_CODE = #{complexDecideCode,jdbcType = VARCHAR}
            </if>
            <if test="matActThick !=null">
                and PPSI.MAT_ACT_THICK = #{matActThick,jdbcType = INTEGER}
            </if>
            <if test="matActWidth !=null">
                and PPSI.MAT_ACT_WIDTH = #{matActWidth,jdbcType = INTEGER}
            </if>
            <if test="matActLen !=null">
                and PPSI.MAT_ACT_LEN = #{matActLen,jdbcType = INTEGER}
            </if>
            <if test="matActWt !=null">
                and PPSI.MAT_ACT_WT = #{matActWt,jdbcType = INTEGER}
            </if>
            <if test="matTheoryWt !=null">
                and PPSI.MAT_THEORY_WT = #{matTheoryWt,jdbcType = INTEGER}
            </if>
            <if test="slabPlaceCode !=null">
                and PPSI.SLAB_PLACE_CODE = #{slabPlaceCode,jdbcType = VARCHAR}
            </if>
            <if test="bdFlag !=null">
                and PPSI.BD_FLAG = #{bdFlag,jdbcType = VARCHAR}
            </if>
            <if test="ccType !=null">
                and PPSI.CC_TYPE = #{ccType,jdbcType = VARCHAR}
            </if>
            <if test="ouRespAuto !=null">
                and PPSI.OU_RESP_AUTO = #{ouRespAuto,jdbcType = VARCHAR}
            </if>
            <if test="ouTimeAuto !=null">
                and PPSI.OU_TIME_AUTO = #{ouTimeAuto,jdbcType = VARCHAR}
            </if>
            <if test="ouAutoFlag !=null">
                and PPSI.OU_AUTO_FLAG = #{ouAutoFlag,jdbcType = VARCHAR}
            </if>
            <if test="ouMemo1 !=null">
                and PPSI.OU_MEMO1 = #{ouMemo1,jdbcType = VARCHAR}
            </if>
            <if test="ouMemo2 !=null">
                and PPSI.OU_MEMO2 = #{ouMemo2,jdbcType = VARCHAR}
            </if>
            <if test="ouMemo3 !=null">
                and PPSI.OU_MEMO3 = #{ouMemo3,jdbcType = VARCHAR}
            </if>
            <if test="ouMemo4 !=null">
                and PPSI.OU_MEMO4 = #{ouMemo4,jdbcType = VARCHAR}
            </if>
            <if test="ouMemo5 !=null">
                and PPSI.OU_MEMO5 = #{ouMemo5,jdbcType = VARCHAR}
            </if>
            <if test="ouMemo6 !=null">
                and PPSI.OU_MEMO6 = #{ouMemo6,jdbcType = INTEGER}
            </if>
            <if test="ouMemo7 !=null">
                and PPSI.OU_MEMO7 = #{ouMemo7,jdbcType = INTEGER}
            </if>
            <if test="ouMemo8 !=null">
                and PPSI.OU_MEMO8 = #{ouMemo8,jdbcType = INTEGER}
            </if>
            <if test="ouMemo9 !=null">
                and PPSI.OU_MEMO9 = #{ouMemo9,jdbcType = INTEGER}
            </if>
            <if test="ouMemo10 !=null">
                and PPSI.OU_MEMO10 = #{ouMemo10,jdbcType = INTEGER}
            </if>
            <if test="ingotType !=null">
                and PPSI.INGOT_TYPE = #{ingotType,jdbcType = VARCHAR}
            </if>
            <if test="tenantId !=null">
                and PPSI.TENANT_ID = #{tenantId,jdbcType = INTEGER}
            </if>
            <if test="attribute1 !=null">
                and PPSI.ATTRIBUTE1 = #{attribute1,jdbcType = VARCHAR}
            </if>
            <if test="attribute2 !=null">
                and PPSI.ATTRIBUTE2 = #{attribute2,jdbcType = VARCHAR}
            </if>
            <if test="attribute3 !=null">
                and PPSI.ATTRIBUTE3 = #{attribute3,jdbcType = VARCHAR}
            </if>
            <if test="attribute4 !=null">
                and PPSI.ATTRIBUTE4 = #{attribute4,jdbcType = VARCHAR}
            </if>
            <if test="attribute5 !=null">
                and PPSI.ATTRIBUTE5 = #{attribute5,jdbcType = VARCHAR}
            </if>
        </where>
    </select>
    <select id="selectListByPono" resultType="com.xisc.pm.domain.entity.PmCmdSlab">
        SELECT *
        FROM PM_CMD_SLAB PCS
        WHERE PCS.pono >= #{ponoLowerLimit} AND PCS.pono  &lt;= #{ponoUpperLimit}
    </select>
    <select id="selectWholeBacklogNo" resultType="java.lang.String">
        select whole_backlog_no from CT_DET where ORDER_NO = #{orderNoAxis}
    </select>
    <select id="selectMesOrderMain" resultType="com.xisc.pm.domain.vo.QdToPoOrderVO1">
        select ORDER_TYPE_CODE, EXPORT_FLAG, FIN_CUST_CODE, PSC, APN, MSC, SG_STD, SG_SIGN from QD_TO_PO_ORDER where ORDER_NO = #{orderNoAxis}
    </select>
    <select id="selectQdRolllingList" resultType="com.xisc.pm.domain.vo.QdToLineupResultRollingVO">
        select
            *
        from
            QD_TO_LINEUP_RESULT_ROLLING
        where
        MSC_LINE_NO = #{mscLineNo}
        and ORDER_NO in
        <foreach collection="orderNoList" item="orderNo" open="(" close=")" separator="," >
            #{orderNo}
        </foreach>
    </select>
    <select id="selectQdHeatList" resultType="com.xisc.pm.domain.vo.QdToLineupResultHeatVO">
        select
            ORDER_NO,
            MSC_LINE_NO,
            LOAD_FUR_TEMP,
            HEAT_TEMP,
            FIRST_THICK,
            FIRST_BG_TEMP,
            FIRST_END_TEMP
        from
            QD_TO_LINEUP_RESULT_HEAT
        where
        MSC_LINE_NO = #{mscLineNo}
        AND to_number(SLAB_THK_MIN)  <![CDATA[ <=  ]]> #{moldThick}
        AND to_number(SLAB_THK_MAX)  <![CDATA[ >= ]]>  #{moldThick}
        and ORDER_NO in
        <foreach collection="orderNoList" item="orderNo" open="(" close=")" separator="," >
            #{orderNo}
        </foreach>
    </select>
    <select id="selectReultHeatTreat" resultType="com.xisc.pm.domain.vo.QdToLineupResultHeattreatVO">
        select
   			*
        from
        QD_TO_LINEUP_RESULT_HEATTREAT
        where
        MSC_LINE_NO = #{mscLineNo}
        and ORDER_NO in
        <foreach collection="orderNoList" item="orderNo" open="(" close=")" separator="," >
            #{orderNo}
        </foreach>
    </select>
    <select id="selectMmplate" resultType="com.xisc.pm.domain.vo.MmPlateVO">
        select
            MAT_ACT_WID,
            MAT_ACT_LEN,
            COMPLEX_DECIDE_CODE,
            OLD_COMPLEX_DECIDE_CODE
        from
            MM_PLATE
        where MAT_NO = #{tmpSlabNo} AND REC_STS = '2'
    </select>
    <select id="selectMmHtmrslt" resultType="java.lang.Long">
        select count(*) from MM_HTMRSLT where MAT_NO = #{tmpSlabNo}
    </select>
    <select id="selectPmContMscTech" resultType="java.lang.Integer">
        select count(*) from PM_CONT_MSC_TECH
                        where
                            MSC_LINE_NO = #{mscLineNo}
                          and
                            ORDER_NO = #{orderNo}
                          and whole_backlog like '%PA%'
    </select>
    <select id="selectUltCheckCode" resultType="java.lang.String">
        select
            ULT_CHECK_CODE
        from
            QD_TO_LINEUP_RESULT_SIZING
        where
            ORDER_NO = #{orderNo}
        and MSC_LINE_NO = #{mscLineNo}
    </select>
    <select id="selectUltPdCodeList" resultType="java.lang.String">
        select
            ULT_PD_CODE
        from
            QD_TO_LINEUP_RESULT_SIZING
        where
            ORDER_NO = #{orderNo}
          and MSC_LINE_NO = #{mscLineNo}
    </select>
    <select id="selectShotFlag" resultType="java.lang.String">
        select SHOT_FLAG from QD_TO_PO_ORDER where ORDER_NO = #{orderNo}
    </select>
    <select id="selectMmUstRslt" resultType="java.lang.String">
        select
            UST_VALUE_LAST
        from
            MM_UST_RSLT
        where
            PLATE_NO = #{tmpSlabNo}
    </select>
    <select id="selectOrgOrderNo" resultType="java.lang.String">
        select ORDER_NO from MM_SLAB where SLAB_NO = #{slabNo}
    </select>
    <select id="selectUltCode0" resultType="java.lang.String">
        select ULT_CODE from QD_TO_LINEUP_RESULT_SIZING where ORDER_NO = #{orgOrderNo}
    </select>
    <select id="selectUltCode1" resultType="java.lang.String">
        select ULT_CODE from QD_TO_LINEUP_RESULT_SIZING where ORDER_NO = #{orderNo} and MSC_LINE_NO = #{mscLineNo}
    </select>

    <select id="selectPlatePonoList" resultType="com.xisc.pm.domain.vo.MmPlateVO">
        SELECT
            mp.MAT_NO,
            ms.PONO
        FROM
            MM_PLATE mp
                JOIN MM_SLAB ms ON mp.SLAB_NO = ms.SLAB_NO and mp.TENANT_ID = ms.TENANT_ID
        <where>
            <if test="tenantId !=null">
                and mp.TENANT_ID = #{tenantId}
            </if>
            <if test="ponoSlabNoList != null and ponoSlabNoList.size() > 0">
                and mp.MAT_NO in
                <foreach collection="ponoSlabNoList" item="ponoSlabNo" open="(" close=")" separator="," >
                    #{ponoSlabNo}
                </foreach>
            </if>
        </where>
    </select>

    <select id="selectQdToPoOrderByOrderList" resultType="com.xisc.pm.domain.vo.QdToPoOrderVO">
        SELECT
            qtpo.IS_UT,
            qtpo.SHOT_FLAG,
            qtpo.ORDER_NO,
            qtpo.ULT_DETECT_STD1,
            qtpo.ULT_DETECT_STD2,
            qtpo.ULT_DETECT_STD3
        FROM
            QD_TO_PO_ORDER qtpo
        <where>
            <if test="tenantId !=null">
                and qtpo.TENANT_ID = #{tenantId}
            </if>
            <if test="orderNoList != null and orderNoList.size() > 0">
                and qtpo.ORDER_NO in
                <foreach collection="orderNoList" item="orderNo" open="(" close=")" separator="," >
                    #{orderNo}
                </foreach>
            </if>
        </where>
    </select>
    
    <select id="selectUtCheckCodeByOrderNo" resultType="com.xisc.pm.domain.vo.QdToLineupResultUTVO">
        SELECT
        qtlru.ORDER_NO,
        qtlru.UT_CHECK_CODE,
        qtlru.UT_PD_CODE
        FROM
        QD_TO_LINEUP_RESULT_UT qtlru
        <where>
            <if test="tenantId !=null">
                and qtlru.TENANT_ID = #{tenantId}
            </if>
            <if test="orderNoList != null and orderNoList.size() > 0">
                and qtlru.ORDER_NO in
                <foreach collection="orderNoList" item="orderNo" open="(" close=")" separator="," >
                    #{orderNo}
                </foreach>
            </if>
        </where>
    </select>
</mapper>

