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


    <sql id = "BaseSql">
    PSPI.SLAB_POOL_IN_ID,
    PSPI.VIRTUAL_SLAB_NO,
    PSPI.MAIN_BACKLOG_CODE,
    PSPI.MSC_LINE_NO,
    PSPI.USER_ID,
    PSPI.WHOLE_BACKLOG_CODE,
    PSPI.ORDER_NO,
    PSPI.ST_NO,
    PSPI.STEEL_PLAN_DATE,
    PSPI.ROLL_PLAN_DATE,
    PSPI.ESTA_STATUS,
    PSPI.SLAB_DEST,
    PSPI.NOM_SLAB_THICK,
    PSPI.NOM_SLAB_WIDTH,
    PSPI.NOM_SLAB_LEN,
    PSPI.SLAB_MAX_NOM_LEN,
    PSPI.SLAB_MIN_NOM_LEN,
    PSPI.CC_TYPE,
    PSPI.NOM_SLAB_WT,
    PSPI.SLAB_MAX_NOM_WT,
    PSPI.SLAB_MIN_NOM_WT,
    PSPI.SLAB_PLACE_CODE,
    PSPI.NOM_ROLL_WIDTH,
    PSPI.NOM_ROLL_THICK,
    PSPI.WHOLE_BACKLOG,
    PSPI.URG_ORDER_FLAG,
    PSPI.IG_MAT_DESIGN_KIND,
    PSPI.INGOT_TYPE,
    PSPI.ORDER_TYPE_CODE,
    PSPI.ORDER_DELAY_FLAG,
    PSPI.SG_SIGN,
    PSPI.NOM_HOT_SEND_FLAG,
    PSPI.DELIVY_DATE,
    PSPI.CONSIGN_CUST_CNAME,
    PSPI.DELIVY_PLACE_NAME,
    PSPI.ORDER_HOT_CHARGE_FLAG,
    PSPI.PRESS_USE_CODE,
    PSPI.RF_PATH,
    PSPI.SG_CODE,
    PSPI.TENANT_ID,
    PSPI.ATTRIBUTE1,
    PSPI.ATTRIBUTE2,
    PSPI.ATTRIBUTE3,
    PSPI.ATTRIBUTE4,
    PSPI.ATTRIBUTE5,
    PSPI.creation_date,    PSPI.created_by,    PSPI.last_updated_by,    PSPI.last_update_date,    PSPI.object_version_number
    </sql>

    <select id = "selectList" resultType = "com.xisc.pm.domain.entity.PmSlabPoolIn">
        select
        <include refid = "BaseSql"/>
        from PM_SLAB_POOL_IN PSPI
        <where>
            <if test="slabPoolInId !=null">
                and PSPI.SLAB_POOL_IN_ID = #{slabPoolInId,jdbcType = INTEGER}
            </if>
            <if test="virtualSlabNo !=null">
                and PSPI.VIRTUAL_SLAB_NO = #{virtualSlabNo,jdbcType = VARCHAR}
            </if>
            <if test="mainBacklogCode !=null">
                and PSPI.MAIN_BACKLOG_CODE = #{mainBacklogCode,jdbcType = VARCHAR}
            </if>
            <if test="mscLineNo !=null">
                and PSPI.MSC_LINE_NO = #{mscLineNo,jdbcType = VARCHAR}
            </if>
            <if test="userId !=null">
                and PSPI.USER_ID = #{userId,jdbcType = VARCHAR}
            </if>
            <if test="wholeBacklogCode !=null">
                and PSPI.WHOLE_BACKLOG_CODE = #{wholeBacklogCode,jdbcType = VARCHAR}
            </if>
            <if test="orderNo !=null">
                and PSPI.ORDER_NO = #{orderNo,jdbcType = VARCHAR}
            </if>
            <if test="stNo !=null">
                and PSPI.ST_NO = #{stNo,jdbcType = VARCHAR}
            </if>
            <if test="steelPlanDate !=null">
                and PSPI.STEEL_PLAN_DATE = #{steelPlanDate,jdbcType = OTHER}
            </if>
            <if test="rollPlanDate !=null">
                and PSPI.ROLL_PLAN_DATE = #{rollPlanDate,jdbcType = OTHER}
            </if>
            <if test="estaStatus !=null">
                and PSPI.ESTA_STATUS = #{estaStatus,jdbcType = VARCHAR}
            </if>
            <if test="slabDest !=null">
                and PSPI.SLAB_DEST = #{slabDest,jdbcType = VARCHAR}
            </if>
            <if test="nomSlabThick !=null">
                and PSPI.NOM_SLAB_THICK = #{nomSlabThick,jdbcType = INTEGER}
            </if>
            <if test="nomSlabWidth !=null">
                and PSPI.NOM_SLAB_WIDTH = #{nomSlabWidth,jdbcType = INTEGER}
            </if>
            <if test="nomSlabLen !=null">
                and PSPI.NOM_SLAB_LEN = #{nomSlabLen,jdbcType = INTEGER}
            </if>
            <if test="slabMaxNomLen !=null">
                and PSPI.SLAB_MAX_NOM_LEN = #{slabMaxNomLen,jdbcType = INTEGER}
            </if>
            <if test="slabMinNomLen !=null">
                and PSPI.SLAB_MIN_NOM_LEN = #{slabMinNomLen,jdbcType = INTEGER}
            </if>
            <if test="ccType !=null">
                and PSPI.CC_TYPE = #{ccType,jdbcType = VARCHAR}
            </if>
            <if test="nomSlabWt !=null">
                and PSPI.NOM_SLAB_WT = #{nomSlabWt,jdbcType = INTEGER}
            </if>
            <if test="slabMaxNomWt !=null">
                and PSPI.SLAB_MAX_NOM_WT = #{slabMaxNomWt,jdbcType = INTEGER}
            </if>
            <if test="slabMinNomWt !=null">
                and PSPI.SLAB_MIN_NOM_WT = #{slabMinNomWt,jdbcType = INTEGER}
            </if>
            <if test="slabPlaceCode !=null">
                and PSPI.SLAB_PLACE_CODE = #{slabPlaceCode,jdbcType = VARCHAR}
            </if>
            <if test="nomRollWidth !=null">
                and PSPI.NOM_ROLL_WIDTH = #{nomRollWidth,jdbcType = INTEGER}
            </if>
            <if test="nomRollThick !=null">
                and PSPI.NOM_ROLL_THICK = #{nomRollThick,jdbcType = INTEGER}
            </if>
            <if test="wholeBacklog !=null">
                and PSPI.WHOLE_BACKLOG = #{wholeBacklog,jdbcType = VARCHAR}
            </if>
            <if test="urgOrderFlag !=null">
                and PSPI.URG_ORDER_FLAG = #{urgOrderFlag,jdbcType = VARCHAR}
            </if>
            <if test="igMatDesignKind !=null">
                and PSPI.IG_MAT_DESIGN_KIND = #{igMatDesignKind,jdbcType = VARCHAR}
            </if>
            <if test="ingotType !=null">
                and PSPI.INGOT_TYPE = #{ingotType,jdbcType = VARCHAR}
            </if>
            <if test="orderTypeCode !=null">
                and PSPI.ORDER_TYPE_CODE = #{orderTypeCode,jdbcType = VARCHAR}
            </if>
            <if test="orderDelayFlag !=null">
                and PSPI.ORDER_DELAY_FLAG = #{orderDelayFlag,jdbcType = VARCHAR}
            </if>
            <if test="sgSign !=null">
                and PSPI.SG_SIGN = #{sgSign,jdbcType = VARCHAR}
            </if>
            <if test="nomHotSendFlag !=null">
                and PSPI.NOM_HOT_SEND_FLAG = #{nomHotSendFlag,jdbcType = VARCHAR}
            </if>
            <if test="delivyDate !=null">
                and PSPI.DELIVY_DATE = #{delivyDate,jdbcType = OTHER}
            </if>
            <if test="consignCustCname !=null">
                and PSPI.CONSIGN_CUST_CNAME = #{consignCustCname,jdbcType = VARCHAR}
            </if>
            <if test="delivyPlaceName !=null">
                and PSPI.DELIVY_PLACE_NAME = #{delivyPlaceName,jdbcType = VARCHAR}
            </if>
            <if test="orderHotChargeFlag !=null">
                and PSPI.ORDER_HOT_CHARGE_FLAG = #{orderHotChargeFlag,jdbcType = VARCHAR}
            </if>
            <if test="pressUseCode !=null">
                and PSPI.PRESS_USE_CODE = #{pressUseCode,jdbcType = VARCHAR}
            </if>
            <if test="rfPath !=null">
                and PSPI.RF_PATH = #{rfPath,jdbcType = VARCHAR}
            </if>
            <if test="sgCode !=null">
                and PSPI.SG_CODE = #{sgCode,jdbcType = VARCHAR}
            </if>
            <if test="tenantId !=null">
                and PSPI.TENANT_ID = #{tenantId,jdbcType = INTEGER}
            </if>
            <if test="attribute1 !=null">
                and PSPI.ATTRIBUTE1 = #{attribute1,jdbcType = VARCHAR}
            </if>
            <if test="attribute2 !=null">
                and PSPI.ATTRIBUTE2 = #{attribute2,jdbcType = VARCHAR}
            </if>
            <if test="attribute3 !=null">
                and PSPI.ATTRIBUTE3 = #{attribute3,jdbcType = VARCHAR}
            </if>
            <if test="attribute4 !=null">
                and PSPI.ATTRIBUTE4 = #{attribute4,jdbcType = VARCHAR}
            </if>
            <if test="attribute5 !=null">
                and PSPI.ATTRIBUTE5 = #{attribute5,jdbcType = VARCHAR}
            </if>
        </where>
    </select>

    <select id="selectListByQdToPoOrder" resultType="com.xisc.pm.domain.vo.QdToPoOrderVO">
        SELECT
            qtpo.ORDER_NO,
            qtpo.HULL_SECTION_NO,
            qtpo.GIVE_SAMPLE_FLAG,
            qtpo.SECTION_MANAGE,
            qtpo.ORDER_THICK,
            qtpo.ORDER_WIDTH,
            qtpo.CONSIGN_CUST_CNAME
        FROM
            QD_TO_PO_ORDER qtpo
        <where>
            <if test="tenantId !=null">
                and qtpo.TENANT_ID = #{tenantId}
            </if>
            <if test="newOrderNoList != null and newOrderNoList.size() > 0">
                and qtpo.ORDER_NO in
                <foreach collection="newOrderNoList" index="index" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="hullSectionNoFrom !=null">
                and qtpo.HULL_SECTION_NO <![CDATA[ >= ]]>  #{hullSectionNoFrom}
            </if>
            <if test="hullSectionNoTo !=null">
                and qtpo.HULL_SECTION_NO <![CDATA[ <= ]]>  #{hullSectionNoTo}
            </if>
        </where>
    </select>

    <select id="selectByQdToLineupResultSizing" resultType="com.xisc.pm.domain.vo.QdToLineupResultSizingVO">
        SELECT
            qtlrs.ORDER_NO,
            qtlrs.ULT_CODE
        FROM
            QD_TO_LINEUP_RESULT_SIZING qtlrs
        <where>
            <if test="tenantId !=null">
                and qtlrs.TENANT_ID = #{tenantId}
            </if>
            <if test="newOrderNoList != null and newOrderNoList.size() != 0">
                and qtlrs.ORDER_NO in
                <foreach collection="newOrderNoList" index="index" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
        </where>
    </select>

    <select id="selectByQdToPoLineComb" resultType="com.xisc.pm.domain.vo.QdToPoLineCombVO">
        SELECT
            qtplc.MSC_LINE_NO,
            qtplc.WHOLE_BACKLOG,
            qtplc.ORDER_NO
        FROM
            QD_TO_PO_LINE_COMB qtplc
        <where>
            <if test="tenantId !=null">
                and qtplc.TENANT_ID = #{tenantId}
            </if>
            <if test="orderNoList != null and orderNoList.size() > 0">
                and qtplc.ORDER_NO in
                <foreach collection="orderNoList" index="index" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
        </where>
    </select>

    <select id="selectRemByCtMain" resultType="com.xisc.pm.domain.vo.CtMainVO">
        SELECT
            cm.ORDER_NO,
            cm.ORD_REM_WGT,
            cm.ORD_REM_NUM
        FROM
            CT_MAIN cm
        <where>
            <if test="orderNoRangeList !=null and orderNoRangeList.size() > 0">
                <foreach collection="orderNoRangeList" index="index" item="item" open="(" close=")"  separator="or">
                    cm.ORDER_NO BETWEEN #{item.orderNoFrom} and  #{item.orderNoTo}
                </foreach>
            </if>
            <if test="tenantId !=null">
                and cm.TENANT_ID = #{tenantId}
            </if>
        </where>
    </select>

    <select id="queryQeTjBetterToWorse" resultType="com.xisc.pm.domain.vo.QeTjBetterToWorseVO">
        SELECT
            qtbtw.BTW_ID,
            qtbtw.MAIN_BACKLOG_CODE,
            qtbtw.BETTER_ST_NO,
            qtbtw.WORSE_ST_NO,
            qtbtw.BETTER_TO_WORSE_SEQ,
            qtbtw.REMARK,
            qtbtw.TENANT_ID
        FROM
            QE_TJ_BETTER_TO_WORSE qtbtw
        WHERE
              qtbtw.ENABLED_FLAG = '1'
          AND qtbtw.BETTER_ST_NO = #{outSgNo}
          AND qtbtw.TENANT_ID = #{tenantId}
    </select>
    
    <select id="queryQeTjBetterByWorseStNo" resultType="com.xisc.pm.domain.vo.QeTjBetterToWorseVO">
        SELECT
            qtbtw.BTW_ID,
            qtbtw.MAIN_BACKLOG_CODE,
            qtbtw.BETTER_ST_NO,
            qtbtw.WORSE_ST_NO,
            qtbtw.BETTER_TO_WORSE_SEQ,
            qtbtw.REMARK,
            qtbtw.TENANT_ID
        FROM
            QE_TJ_BETTER_TO_WORSE qtbtw
        WHERE
              qtbtw.ENABLED_FLAG = '1'
          AND qtbtw.BETTER_ST_NO = #{stNo}
          AND qtbtw.TENANT_ID = #{tenantId}
          ORDER BY qtbtw.BETTER_TO_WORSE_SEQ asc
    </select>

    <select id="selectCtMainByOrderNoList" resultType="com.xisc.pm.domain.vo.CtMainVO">
        select
        cm.ORDER_NO,
        cm.OVER_DEVO_NUM_TOTAL
        FROM
        CT_MAIN cm
        <where>
            <if test="tenantId !=null">
                and cm.TENANT_ID = #{tenantId}
            </if>
            <if test="orderNoList != null and orderNoList.size()>0">
                and cm.ORDER_NO in
                <foreach collection="orderNoList" item="orderNo" open="(" close=")" separator=",">
                    #{orderNo}
                </foreach>
            </if>
        </where>
    </select>
</mapper>

