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

	<select id="orderFilterList"
		resultType="com.xisc.pm.api.dto.PmProContFilterResposeDTO">
		select
			ppcpa.DELIVY_DATE,
			ppc.ORDER_NO,
			ppcpa.GIVE_SAMPLE_CODE,
			ppcpa.ORDER_UNIT_AIM_WT as UNIT_WT_AIM,
			ppcpa.ORDER_UNIT_AIM_WT,
			ppcpa.ORDER_THICK,
			ppcpa.ORDER_WIDTH,
			ppcpa.ORDER_LEN as LEN_AIM,
			ppcpa.ORDER_QTY,
			ppcpa.SG_SIGN,
			ppcpa.PROJECT_CODE,
			pcmt.ROLL_MODE,
			pcmt.ST_NO,
			pcmt.ROLL_DIRECT_CODE,
			pcmt.AD_TYPE_CODE,
			ppcpa.CONSIGN_CUST_CNAME,
			ppcpa.DELIVY_PLACE_NAME,
			ppcpa.DELIVY_NUM_TOL_PLUS,
			ppcpa.DELIVY_NUM_TOL_MINUS,
			pcmt.CTRL_ROLL_CODE,
		    pcmt.CTRL_ROLL_CODE1,
		    pcmt.CTRL_ROLL_CODE34,
			pcmt.RF_PATH,
			ppc.PD_TOT_QTY,
			ppcpa.URG_ORDER_FLAG,
			ppcpa.TWO_ROLL_FLAG,
			ppcpa.WIDTH_MAX,
			ppcpa.WIDTH_MIN,
			ppcpa.ORDER_MAX_LEN,
			ppcpa.ORDER_MIN_LEN,
			ppcpa.PROD_DENSITY,
			pcmt.HEAT_TREAT_MODE,
			pcmt.WHOLE_HEAT_TREATMENT_TYPE,
			pcmt.ULT_CODE,
			pcmt.HEAD_CUT,
			pcmt.TAIL_CUT,
			ppcpa.ORDER_NO_ERP,
			ppcpa.SPECIAL_PRINT,
			ppcpa.WIDTH_ADDV,
			ppcpa.CHECK_METHOD_CODE,
		    ppcpa.ACCP_AUTH_CODE,
			ppcpa.WT_METHOD_CODE,
			ppcpa.HULL_SECTION_NO,
			ppcpa.SECTION_MANAGE,
			ppcpa.NEED_LECQUERING,
			ppcpa.FIN_CUST_CODE,
			pcmt.KEEP_TEMP_AIM,
			pcmt.ULT_DETECT_METHOD_CODE,
			pcmt.CUT_MODE_CODE,
			pcmt.MULTI_PLATE_FLAG,
			pcmt.COOL_CODE,
			pcmt.ULT_STG_CODE,
			pcmt.AD_MODE_CODE,
			pcmt.WHOLE_BACKLOG_CODE,
			pcmt.HOT_SEND_DIV,
			pcmt.HOT_CHARGE_FLAG,
			ppcpa.PROD_SIDE_MARK,
			ppcpa.SAMPLE_MODE_CODE,
			ppcpa.THICK_TOL_MIN,
			ppcpa.THICK_TOL_MAX,
			ppcpa.TRIM_CODE,
			ppcpa.BACKLOG_T_MARK,
			ppcpa.BACKLOG_Q_MARK,
			ppcpa.BACKLOG_A_MARK,
			ppcpa.BACKLOG_N_MARK,
			ppcpa.PICK_PATTERN_CODE,
			ppcpa.SAMPLE_LEN_HEAD,
			ppcpa.SAMPLE_LEN_TAIL,
			ppcpa.PROD_CODE_HP,
			ppcpa.PLANER_FLAG,
			ppcpa.ORDER_TYPE_CODE,
			
			ppc.PRO_CONT_ID,
			ppc.PD_HOLD_FLAG,
			ppc.PD_LACK_QTY,
			pcmt.FUR_TYPE,
			pcmt.COMPRESS_MIN,
			pcmt.MSC_LINE_NO,
		    pcmt.SLAB_PLACE_CODE,
		    pcmt.SLAB_THK_MIN,
		    pcmt.SLAB_THK_MAX,
			ppc.ON_PD_FLAG,
			ppc.PD_PROGRAM,
			ppc.PD_PLANNER,
			ppc.STEEL_PLAN_DATE,
			ppc.STEEL_LATEST_DATE,
			ppc.PD_OVER_DEVO_QTY as pdOverDevoQtyHistory,
		    nvl(ppc.PD_OVER_DEVO_QTY, 0) + nvl(ppc.PD_LACK_QTY, 0) as assemblyBoardNum,
			ptpo.ERP_UT_SPEC1,
			ptpo.ERP_UT_SPEC2,
			ptpo.ERP_UT_SPEC3,
		    qtlrs.MACRO_SMP_FLAG
		from PM_PRO_CONT ppc
		<if test="joinCtMainFlag != null and joinCtMainFlag == 1">
			left join CT_MAIN cm on cm.ORDER_NO = ppc.ORDER_NO
		</if>
		left join PM_PRO_CONT_PROD_ATTR ppcpa on ppcpa.PRO_CONT_ID = ppc.PRO_CONT_ID
		left join PM_CONT_MSC_TECH pcmt on pcmt.ORDER_NO = ppc.ORDER_NO
		INNER JOIN QD_TO_PO_ORDER ptpo on ptpo.ORDER_NO = ppc.ORDER_NO
		left join QD_TO_LINEUP_RESULT_SLABPHY qtlrs on qtlrs.ORDER_NO = ppc.ORDER_NO
		where 
		ppc.TENANT_ID = #{tenantId}
		
		<if test="joinCtMainFlag != null and joinCtMainFlag == 1">
			and cm.ORDER_STATUS <![CDATA[ >= ]]> '40'
			and cm.ORDER_STATUS <![CDATA[ <= ]]> '66'
		</if>
		
		<if test="stNo != null and stNo != ''">
			<if test="stReplFlag != null and stReplFlag == 0">
				and pcmt.ST_NO = #{stNo}
			</if>
			<if test="stReplFlag != null and stReplFlag == 1">
				and (pcmt.ST_NO = #{stNo} or EXISTS (select 1 from QE_TJ_BETTER_TO_WORSE phs where phs.BETTER_ST_NO = #{stNo} and phs.ENABLED_FLAG = 1 and phs.WORSE_ST_NO = pcmt.ST_NO))
			</if>
		</if>
		<if test="sgSign != null and sgSign != ''">
			<bind name="sgSignLike" value="'%' + sgSign + '%'"/>
			and ppcpa.SG_SIGN like #{sgSignLike}
		</if>
		<if test="orderThickFrom != null">
			and ppcpa.ORDER_THICK >= #{orderThickFrom}
		</if>
		<if test="orderThickTo != null">
			and ppcpa.ORDER_THICK <![CDATA[ <= ]]> #{orderThickTo}
		</if>
		<if test="orderWidthFrom != null">
			and ppcpa.ORDER_WIDTH >= #{orderWidthFrom}
		</if>
		<if test="orderWidthTo != null">
			and ppcpa.ORDER_WIDTH <![CDATA[ <= ]]> #{orderWidthTo}
		</if>
		<if test="orderLenFrom != null">
			and ppcpa.ORDER_LEN >= #{orderLenFrom}
		</if>
		<if test="orderLenTo != null">
			and ppcpa.ORDER_LEN <![CDATA[ <= ]]> #{orderLenTo}
		</if>
		<if test="delivyDateFrom != null">
            AND ppcpa.DELIVY_DATE <![CDATA[ >= ]]> #{delivyDateFrom}
        </if>
        <if test="delivyDateTo != null">
            AND ppcpa.DELIVY_DATE <![CDATA[ <= ]]> #{delivyDateTo}
        </if>
        <if test="mscLineNo != null and mscLineNo != ''">
			and pcmt.MSC_LINE_NO = #{mscLineNo}
		</if>
        <if test="xzFlag != null and xzFlag != ''">
            AND ppcpa.XZ_FLAG <![CDATA[ <= ]]> #{xzFlag}
        </if>
        <if test="orderNoList != null and orderNoList.size() != 0">
            and ppc.ORDER_NO in
            <foreach collection="orderNoList" index="index" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="matDesignKind != null and matDesignKind != 'FHB'.toString()">
        	<if test="queryQfh != null and queryQfh == '1'.toString()">
        		and ppcpa.ORDER_TYPE_CODE IN ('QFH', 'ZSF', 'NSF')
        	</if>
        	<if test="queryQfh != null and queryQfh == '0'.toString()">
        		and ppcpa.ORDER_TYPE_CODE NOT IN ('QFH', 'QDH', 'ZSF', 'NSF', 'QBP', 'QLP', 'NBP')
        	</if>
        </if>
		<if test="matDesignKind != null and matDesignKind == 'C'.toString()">
			and ppcpa.INGOT_ROLL = '0'
		</if>
        order by ppc.ORDER_NO asc 

	</select>
	
	<select id="queryByOrderNoList" resultType="com.xisc.pm.domain.entity.PmProCont">
		SELECT 	DISTINCT
					ppc.PRO_CONT_ID
                    ,ppc.ORDER_NO
                    ,ppc.PD_HOLD_FLAG
                    ,ppc.HOLD_MAKER
                    ,ppc.HOLD_TIME
                    ,ppc.REL_MAKER
                    ,ppc.REL_TIME
                    ,ppc.PD_REL_MAKER
                    ,ppc.PD_REL_TIME
                    ,ppc.ON_PD_FLAG
                    ,ppc.PD_BEGIN_TIME
                    ,ppc.PD_END_TIME
                    ,ppc.PD_PROGRAM
                    ,ppc.PD_PLANNER
                    ,ppc.PD_TOT_WT
                    ,ppc.PD_TOT_QTY
                    ,ppc.PD_OVER_DEVO_WT
                    ,ppc.PD_OVER_DEVO_QTY
                    ,ppc.PD_OVER_DEVO_CAUSE
                    ,ppc.PD_LACK_QTY
                    ,ppc.PD_LACK_WT
                    ,ppc.PD_PLAN_DATE
                    ,ppc.PD_LATEST_DATE
                    ,ppc.STEEL_PLAN_DATE
                    ,ppc.STEEL_LATEST_DATE
                    ,ppc.TENANT_ID
                    ,ppc.OBJECT_VERSION_NUMBER
                    ,ppc.CREATION_DATE
                    ,ppc.CREATED_BY
                    ,ppc.LAST_UPDATED_BY
                    ,ppc.LAST_UPDATE_DATE
                    ,ppc.ATTRIBUTE1
                    ,ppc.ATTRIBUTE2
                    ,ppc.ATTRIBUTE3
                    ,ppc.ATTRIBUTE4
                    ,ppc.ATTRIBUTE5
		from PM_PRO_CONT ppc
		<if test="request.joinCtMainFlag != null and request.joinCtMainFlag == 1">
			left join CT_MAIN cm on cm.ORDER_NO = ppc.ORDER_NO
			left join CT_DET cd on cm.ORDER_NO = cd.ORDER_NO and cd.WHOLE_BACKLOG_CODE = '13'
		</if>
		left join PM_PRO_CONT_PROD_ATTR ppcpa on ppcpa.PRO_CONT_ID = ppc.PRO_CONT_ID
		left join PM_CONT_MSC_TECH pcmt on pcmt.ORDER_NO = ppc.ORDER_NO
		WHERE ppc.TENANT_ID = #{request.tenantId}
		<if test="request.joinCtMainFlag != null and request.joinCtMainFlag == 1">
			and cm.ORDER_STATUS <![CDATA[ >= ]]> '40'
			and cm.ORDER_STATUS <![CDATA[ <= ]]> '66'
		</if>
		<if test="orderNoList != null and orderNoList.size() != 0">
            and ppc.ORDER_NO in
            <foreach collection="orderNoList" index="index" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="request.isOnPdFlag != null and request.isOnPdFlag == '1'.toString()">
        	and ppc.ON_PD_FLAG = '1' 
        </if>
        <if test="request.isOnPdFlag != null and request.isOnPdFlag == '0'.toString()">
        	and ppc.ON_PD_FLAG = '0'
        </if>
        <if test="request.isOrderHoldFlag != null and request.isOrderHoldFlag == '1'.toString()">
        	and ppc.PD_HOLD_FLAG = '1' 
        </if>
        <if test="request.isOrderHoldFlag != null and request.isOrderHoldFlag == '0'.toString()">
        	and ppc.PD_HOLD_FLAG = '0'
        </if>
        <if test="request.joinCtMainFlag != null and request.joinCtMainFlag == 1">
	        <if test="request.isPdLackFlag != null and request.isPdLackFlag == '1'.toString()">
	        	and cd.STOCK_NUM > 0
	        </if>
	        <if test="request.isPdLackFlag != null and request.isPdLackFlag == '0'.toString()">
	        	and cd.STOCK_NUM <![CDATA[ <= ]]> 0
	        </if>
	    </if>
        <if test="request.sgSign != null and request.sgSign != ''">
        	<bind name="sgSignLike" value="'%' + request.sgSign + '%'"/>
			and ppcpa.SG_SIGN like #{sgSignLike}
		</if>
		<if test="request.stNo != null and request.stNo != ''">
			<bind name="stNoLike" value="'%' + request.stNo + '%'"/>
			and pcmt.ST_NO like #{stNoLike}
		</if>
		<if test="request.delivyDateFrom != null">
			and ppcpa.DELIVY_DATE <![CDATA[ >= ]]> #{request.delivyDateFrom}
		</if>
		<if test="request.delivyDateTo != null">
			and ppcpa.DELIVY_DATE <![CDATA[ <= ]]> #{request.delivyDateTo}
		</if>
		<if test="request.orderThickFrom != null">
			and ppcpa.ORDER_THICK <![CDATA[ >= ]]> #{request.orderThickFrom}
		</if>
		<if test="request.orderThickTo != null">
			and ppcpa.ORDER_THICK <![CDATA[ <= ]]> #{request.orderThickTo}
		</if>
		<if test="request.orderWidthFrom != null">
			and ppcpa.ORDER_WIDTH <![CDATA[ >= ]]> #{request.orderWidthFrom}
		</if>
		<if test="request.orderWidthTo != null">
			and ppcpa.ORDER_WIDTH <![CDATA[ <= ]]> #{request.orderWidthTo}
		</if>
		<if test="request.orderLenFrom != null">
			and ppcpa.ORDER_LEN <![CDATA[ >= ]]> #{request.orderLenFrom}
		</if>
		<if test="request.orderLenTo != null">
			and ppcpa.ORDER_LEN <![CDATA[ <= ]]> #{request.orderLenTo}
		</if>
		<if test="request.orderNoFrom != null and request.orderNoFrom != ''">
			and ppcpa.ORDER_NO <![CDATA[ >= ]]> #{request.orderNoFrom}
		</if>
		<if test="request.orderNoTo != null and request.orderNoTo != ''">
			and ppcpa.ORDER_NO <![CDATA[ <= ]]> #{request.orderNoTo}
		</if>
		<if test="request.hullSectionFrom != null and request.hullSectionFrom != ''">
			and ppcpa.HULL_SECTION_NO <![CDATA[ >= ]]> #{request.hullSectionFrom}
		</if>
		<if test="request.hullSectionTo != null and request.hullSectionTo != ''">
			and ppcpa.HULL_SECTION_NO <![CDATA[ <= ]]> #{request.hullSectionTo}
		</if>
		<if test="request.prodCodeHp != null and request.prodCodeHp != ''">
			and ppcpa.PROD_CODE_HP = #{request.prodCodeHp}
		</if>
		<if test="request.orderNoErp != null and request.orderNoErp != ''">
			<bind name="orderNoErpLike" value="'%' + request.orderNoErp + '%'"/>
			and ppcpa.ORDER_NO_ERP like #{orderNoErpLike}
		</if>
		<if test="request.orderTypeCodeEx != null and request.orderTypeCodeEx != ''">
			and ppcpa.ORDER_TYPE_CODE <![CDATA[ != ]]> #{request.orderTypeCodeEx}
		</if>
		<if test="request.delivyPlaceName != null and request.delivyPlaceName != ''">
			<bind name="delivyPlaceNameLike" value="'%' + request.delivyPlaceName + '%'"/>
			and ppcpa.DELIVY_PLACE_NAME like #{delivyPlaceNameLike}
		</if>
		<if test="request.adTypeCode != null and request.adTypeCode != ''">
			and pcmt.AD_TYPE_CODE = #{request.adTypeCode}
		</if>
		<if test="request.mscLineNo != null and request.mscLineNo != ''">
			and EXISTS (select 1 from PM_CONT_MSC_TECH pcmt where pcmt.ORDER_NO = ppc.ORDER_NO and pcmt.MSC_LINE_NO = #{request.mscLineNo})
		</if>
		order by ppc.ORDER_NO ASC
		
	</select>
	
	<select id="selectProContSimpleList" resultType="com.xisc.pm.api.dto.PmProContSimpleDTO">
		select 
			DISTINCT
			ppcpa.ORDER_THICK,
			ppcpa.ORDER_WIDTH,
			ppcpa.ORDER_LEN as LEN_AIM,
			ppc.PD_LACK_QTY,
			ppc.ORDER_NO,
			ppcpa.SG_SIGN
		from PM_PRO_CONT ppc
		left join PM_PRO_CONT_PROD_ATTR ppcpa on ppcpa.PRO_CONT_ID = ppc.PRO_CONT_ID
		left join PM_CONT_MSC_TECH pcmt on pcmt.ORDER_NO = ppc.ORDER_NO
		left join CT_MAIN cm on cm.ORDER_NO = ppc.ORDER_NO
		where 
		ppc.TENANT_ID = #{tenantId}
		and cm.ORDER_STATUS <![CDATA[ >= ]]> '40'
		and cm.ORDER_STATUS <![CDATA[ < ]]> '67'
		<if test="stNo != null and stNo != ''">
			AND ppc.PD_LACK_QTY > 0
			AND pcmt.ST_NO = #{stNo}
		</if>
		<if test="orderNo != null and orderNo != ''">
			<bind name="orderNoLike" value="'%'+ orderNo + '%' "/>
			and ppc.ORDER_NO like #{orderNoLike}
		</if>
		
	</select>
	
	<select id="selectAutoBoardContList" resultType="com.xisc.pm.app.service.autoboard.dto.PmContBoardParam">
		SELECT 
			ppc.ORDER_NO as orderNo, 
			pcmt.MSC_LINE_NO as mscLineNoStr,
			cd.STOCK_NUM AS pdLockQty ,
			ppcpa.ORDER_LEN as smallPlateLen ,
			ppcpa.ORDER_THICK as orderThick,
			ppcpa.ORDER_WIDTH as orderWid,
			ppcpa.ORDER_UNIT_AIM_WT as orderUnitAim,
			pcmt.ST_NO as stNo, 
			ppcpa.DELIVY_DATE as delivyDate ,
			ppcpa.CONSIGN_CUST_CNAME as orderCustCname,
			ppcpa.DELIVY_PLACE_NAME as delivyPlace,
			ppcpa.ORDER_NO_ERP as erpOrderNo,
			cm.ORD_REM_NUM as contractAllowance,
			pcmt.CUT_MODE_CODE as cutModeCode,
			<!-- pcmt.MULTI_PLATE_FLAG as multiPlateFlag, -->
			ppcpa.SAMPLE_MODE_CODE as sampleModeCode,
			ppcpa.THICK_TOL_MIN as thickTolMin,
			ppcpa.THICK_TOL_MAX as thickTolMax,
			ppcpa.TRIM_CODE as trimCode,
			ppcpa.BACKLOG_T_MARK as backlogQMark,
			ppcpa.BACKLOG_Q_MARK as backlogTMark,
			ppcpa.BACKLOG_A_MARK as backlogAMark,
			ppcpa.BACKLOG_N_MARK as backlogNMark,
			ppcpa.PICK_PATTERN_CODE as pickPatternCode,
			ppcpa.SAMPLE_LEN_HEAD as sampleLenHead,
			ppcpa.SAMPLE_LEN_TAIL as sampleLenTail,
			pcmt.WHOLE_HEAT_TREATMENT_TYPE as wholeHeatTreatmentType,
			pcmt.HEAD_CUT as headCut ,
			pcmt.TAIL_CUT as tailCut ,
			pcmt.SLAB_THK_MIN as slabThkMin ,
			pcmt.SLAB_THK_MAX as slabThkMax ,
			ppcpa.WIDTH_ADDV as widthAddv,
			ppcpa.SG_SIGN as sgSign ,
			pcmt.ROLL_MODE as rollMode,
			ppcpa.PROD_DENSITY as prodDensity,
			pcmt.ROLL_DIRECT_CODE as rollDirectCode,
			ppcpa.PROD_SIDE_MARK as prodSideMark,
			qtpo.THK_TOL_TYPE as thkTolType,
			pscb.ST_CODE AS stCode,
			ppcpa.PLANER_FLAG as planerFlag,
			pcmt.AD_TYPE_CODE adTypeCode,
			qtwp.WITNESS_PRO_NO AS witnessProNo,
			qtpo.AXIAL_ROLL_MARK as axialRollMark,
			case WHEN papcl.LOCK_QTY > 0 then papcl.LOCK_QTY else  0 end as LOCK_QTY
		from PM_PRO_CONT ppc
		left join PM_PRO_CONT_PROD_ATTR ppcpa on ppcpa.ORDER_NO = ppc.ORDER_NO
		left join PM_CONT_MSC_TECH pcmt on pcmt.ORDER_NO = ppc.ORDER_NO
		left join CT_MAIN cm on cm.ORDER_NO = ppc.ORDER_NO
		left join CT_DET cd on cd.ORDER_NO = cm.ORDER_NO and cd.WHOLE_BACKLOG_CODE = '13'
		left join PM_AUTO_PD_CONT_LOCK papcl on papcl.ORDER_NO = ppc.ORDER_NO
		left join QD_TO_PO_ORDER qtpo on qtpo.ORDER_NO = ppc.ORDER_NO
		left join PM_ST_CODE_BT pscb on pscb.ROLL_LINE_NO = SUBSTR(PCMT.MSC_LINE_NO, 3, 2) and pscb.ST_NO = pcmt.ST_NO
		left join QE_TJ_WITNESS_PRO_ORDER qtwp on qtwp.ORDER_NO = ppc.ORDER_NO
		where 
		ppc.TENANT_ID = #{tenantId}
		AND cd.STOCK_NUM > 0
		and ppc.PD_HOLD_FLAG = 0
		and ppcpa.INGOT_ROLL = '0'
		and cm.ORDER_STATUS <![CDATA[ >= ]]> '40'
		and cm.ORDER_STATUS <![CDATA[ < ]]> '67'
		and ppcpa.ORDER_TYPE_CODE <![CDATA[ != ]]> 'QFH'
		<if test="policyGroup.mscLineNoList != null and policyGroup.mscLineNoList.size() > 0">
			and pcmt.MSC_LINE_NO in 
			<foreach collection="policyGroup.mscLineNoList" item="mscLineNo" open="(" close=")" separator="," >
				#{mscLineNo}
			</foreach>
		</if>
		<if test="policyGroup.contractNumList != null and policyGroup.contractNumList.size() > 0">
			and cm.CONTRACT_NUM in 
			<foreach collection="policyGroup.contractNumList" item="contractNum" open="(" close=")" separator="," >
				#{contractNum}
			</foreach>
		</if>
		<if test="policyGroup.stNoList != null and policyGroup.stNoList.size() > 0">
			and pcmt.ST_NO in 
			<foreach collection="policyGroup.stNoList" item="stNoValue" open="(" close=")" separator="," >
				#{stNoValue}
			</foreach>
		</if>
		<if test="policyGroup.delivyDateFrom != null">
            AND ppcpa.DELIVY_DATE <![CDATA[ >= ]]> #{policyGroup.delivyDateFrom}
        </if>
        <if test="policyGroup.delivyDateTo != null">
            AND ppcpa.DELIVY_DATE <![CDATA[ <= ]]> #{policyGroup.delivyDateTo}
        </if>
	</select>
	
	<!-- <select id="selectAutoBoardContList" resultType="com.xisc.pm.app.service.autoboard.dto.PmContBoardParam">
		SELECT 
			ppc.ORDER_NO as orderNo, 
			LISTAGG(pcmt.MSC_LINE_NO , ',') WITHIN GROUP (ORDER BY pcmt.MSC_LINE_NO) as mscLineNoStr,
			max(ppc.PD_LACK_QTY) AS pdLockQty ,
			max(ppcpa.ORDER_LEN) as smallPlateLen ,
			max(ppcpa.ORDER_THICK) as orderThick,
			max(ppcpa.ORDER_WIDTH) as orderWid,
			max(ppcpa.ORDER_UNIT_AIM_WT) as orderUnitAim,
			max(pcmt.ST_NO) as stNo, 
			max(ppcpa.DELIVY_DATE) as delivyDate ,
			max(ppcpa.CONSIGN_CUST_CNAME) as orderCustCname,
			max(ppcpa.DELIVY_PLACE_NAME) as delivyPlace,
			max(ppcpa.ORDER_NO_ERP) as erpOrderNo,
			max(cm.ORD_REM_NUM) as contractAllowance,
			max(pcmt.CUT_MODE_CODE) as cutModeCode,
			max(pcmt.MULTI_PLATE_FLAG) as multiPlateFlag,
			max(ppcpa.SAMPLE_MODE_CODE) as sampleModeCode,
			max(ppcpa.THICK_TOL_MIN) as thickTolMin,
			max(ppcpa.THICK_TOL_MAX) as thickTolMax,
			max(ppcpa.TRIM_CODE) as trimCode,
			max(ppcpa.BACKLOG_T_MARK) as backlogQMark,
			max(ppcpa.BACKLOG_Q_MARK) as backlogTMark,
			max(ppcpa.BACKLOG_A_MARK) as backlogAMark,
			max(ppcpa.BACKLOG_N_MARK) as backlogNMark,
			max(ppcpa.PICK_PATTERN_CODE) as pickPatternCode,
			max(ppcpa.SAMPLE_LEN_HEAD) as sampleLenHead,
			max(ppcpa.SAMPLE_LEN_TAIL) as sampleLenTail,
			max(pcmt.WHOLE_HEAT_TREATMENT_TYPE) as wholeHeatTreatmentType,
			max(pcmt.HEAD_CUT) as headCut ,
			max(pcmt.TAIL_CUT) as tailCut ,
			max(ppcpa.WIDTH_ADDV) as widthAddv,
			max(ppcpa.SG_SIGN) as sgSign ,
			max(pcmt.ROLL_MODE) as rollMode,
			max(ppcpa.PROD_DENSITY) as prodDensity,
			max(pcmt.ROLL_DIRECT_CODE) as rollDirectCode,
			max(ppcpa.PROD_SIDE_MARK) as prodSideMark,
			max(qtpo.THK_TOL_TYPE) as thkTolType,
			MAX(pscb.ST_CODE) AS stCode,
			max(ppcpa.PLANER_FLAG) as planerFlag,
			max(pcmt.AD_TYPE_CODE) adTypeCode,
			max(qtwp.WITNESS_PRO_NO) AS witnessProNo
		from PM_PRO_CONT ppc
		left join PM_PRO_CONT_PROD_ATTR ppcpa on ppcpa.ORDER_NO = ppc.ORDER_NO
		left join PM_CONT_MSC_TECH pcmt on pcmt.ORDER_NO = ppc.ORDER_NO
		left join CT_MAIN cm on cm.ORDER_NO = ppc.ORDER_NO
		left join QD_TO_PO_ORDER qtpo on qtpo.ORDER_NO = ppc.ORDER_NO
		left join PM_ST_CODE_BT pscb on pscb.ROLL_LINE_NO = SUBSTR(PCMT.MSC_LINE_NO, 3, 2) and pscb.ST_NO = pcmt.ST_NO
		left join QE_TJ_WITNESS_PRO_ORDER qtwp on qtwp.ORDER_NO = ppc.ORDER_NO
		where 
		ppc.TENANT_ID = 1
		AND ppc.PD_LACK_QTY > 0
		and ppcpa.INGOT_ROLL = '0'
		and cm.ORDER_STATUS <![CDATA[ >= ]]> '40'
		and cm.ORDER_STATUS <![CDATA[ < ]]> '67'
		<if test="policyGroup.mscLineNoList != null and policyGroup.mscLineNoList.size() > 0">
			and pcmt.MSC_LINE_NO in 
			<foreach collection="policyGroup.mscLineNoList" item="mscLineNo" open="(" close=")" separator="," >
				#{mscLineNo}
			</foreach>
		</if>
		<if test="policyGroup.stNoList != null and policyGroup.stNoList.size() > 0">
			pcmt.ST_NO in 
			<foreach collection="policyGroup.stNoList" item="stNoValue" open="(" close=")" separator="," >
				#{stNoValue}
			</foreach>
		</if>
		<if test="policyGroup.delivyDateFrom != null">
            AND ppcpa.DELIVY_DATE <![CDATA[ >= ]]> #{policyGroup.delivyDateFrom}
        </if>
        <if test="policyGroup.delivyDateTo != null">
            AND ppcpa.DELIVY_DATE <![CDATA[ <= ]]> #{policyGroup.delivyDateTo}
        </if>
		GROUP BY ppc.ORDER_NO
	</select> -->

	<select id="selectSlabPlaceCode" resultType="com.xisc.pm.domain.vo.QdToLineupResultSteelVO">
		SELECT
			qtlrs.ORDER_NO,
			qtlrs.MSC_LINE_NO,
			qtlrs.SLAB_PLACE_CODE
		FROM
			QD_TO_LINEUP_RESULT_STEEL qtlrs
		<where>
			<if test="tenantId != null">
				AND qtlrs.TENANT_ID = #{tenantId}
			</if>
			<if test="orderNoList != null and orderNoList.size()>0">
				and  (qtlrs.ORDER_NO in
				<foreach collection="orderNoList" item="orderNo" open="(" close=")" separator="," index="index">
					<if test="(index % 999) == 998"> NULL ) OR qtlrs.ORDER_NO in (</if> #{orderNo}
				</foreach>)
			</if>
			<if test="mscLineNoList != null and mscLineNoList.size()>0">
				and  (qtlrs.MSC_LINE_NO in
				<foreach collection="mscLineNoList" item="mscLineNo" open="(" close=")" separator="," index="index">
					<if test="(index % 999) == 998"> NULL ) OR qtlrs.MSC_LINE_NO in (</if> #{mscLineNo}
				</foreach>)
			</if>
		</where>
	</select>

	<select id="queryOrderRemNumByOrderNoList" resultType="com.xisc.pm.domain.vo.CtMainVO">
		SELECT
			sum(NVL(cm.ORD_REM_NUM, 0)) AS contractNum,
		    sum(NVL(cm.SHIP_END_NUM, 0)) AS shipEndNum,
			SUBSTR( cm.ORDER_NO, 1, 8 ) as contractOrder
		FROM
			CT_MAIN cm
		<where>
			<if test="orderNoList != null and orderNoList.size()>0">
				and  (cm.ORDER_NO in
				<foreach collection="orderNoList" item="orderNo" open="(" close=")" separator="," index="index">
					<if test="(index % 999) == 998"> NULL ) OR cm.ORDER_NO in (</if> #{orderNo}
				</foreach>)
			</if>
			<if test="tenantId != null">
				AND cm.TENANT_ID = #{tenantId}
			</if>
		</where>
		GROUP BY
			SUBSTR( cm.ORDER_NO, 1, 8 )
	</select>
</mapper>