<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="合同接箍短节处理">

	<query id="CorePlnOrdJgDjDeal.querySaleOrder" desc="查询销售提报合同">
		<![CDATA[
			SELECT T.ORD_PK,
			       T.ORD_LN_PK,
			       T.ORD_LN_DLY_PK,
			       T.ORDER_NO,
			       T.ORDER_SEQ,
			       T.DELIVERY_NO,
			       (T.ORDER_NO || '/' || T.ORDER_SEQ) ORDER_NO_SEQ,
			       (SELECT A.PRODUC_DESC
			          FROM COM_BASE_PRODUCT A
			         WHERE A.PRODUCCODE = T.PRODUCCODE
			           AND A.VALIDFLAG = '1') PRD_CLS,
			       T.PRODUCCODE,
			       T.PRODUCNAME,
			       T.STD_CODE,
			       T.STD_NAME,
			       T.STEELCODE,
			       T.STEELNAME,
			       T.SPEC_CODE,
			       T.SPEC_NAME,
			       T.ORDERNUM,
			       T.OUTDIAMETER,
			       T.WALLTHICK,
			       T.LEN_UNIT,
			       T.LENGTHMAX,
			       T.LENGTHMIN,
			       T.LENGTHDISC,
			       T.MODEL_CODE,
			       T.MODEL_DESC,
			       T.ORDER_UNIT,
			       T.ORDER_QTY,
			       T.ORDERWEIGHT,
			       DECODE(T.ORDER_UNIT, '米', '吨', '英尺', '吨', T.ORDER_UNIT) ORDERWEIGHTUNIT,
			       DECODE(T.TOTLENGTH, 0, '', T.TOTLENGTH) TOTLENGTH,
			       T.TOTLENGTH_UNIT,
			       T.DELVRY_RANGE_TPE,
			       T.DELVRY_RANGE_MIN,
			       T.DELVRY_RANGE_MAX,
			       '(-' || TO_CHAR(ABS(T.DELVRY_RANGE_MIN)) ||
			       DECODE(T.DELVRY_RANGE_TPE, '%', '%', '') || ',' ||
			       TO_CHAR(T.DELVRY_RANGE_MAX) ||
			       DECODE(T.DELVRY_RANGE_TPE, '%', '%', '') || ')' DELVRY_RANGE,
			       T.BUYER_ID,
			       (SELECT A.ABRVITION
			          FROM SLM_BASE_CUSTOMER A
			         WHERE A.CUSTOMER_NO = T.BUYER_ID) BUYER_NAME,
			       T.ORDER_SPECIAL_DESC,
			       T.ADD_ASK_NO,
			       T.ORDER_ADD_DESC,
			       (SELECT A.BASENAME
			          FROM COM_BASE_INFO A
			         WHERE A.BASECODE = T.ORDERFROM) ORDERFROM,
			       T.FINAL_USER,
			       NVL((SELECT A.ABRVITION
			             FROM SLM_BASE_CUSTOMER A
			            WHERE A.CUSTOMER_NO = DECODE(T.FINAL_USER,
			                                         NULL,
			                                         T.BUYER_ID,
			                                         '/',
			                                         T.BUYER_ID,
			                                         T.FINAL_USER)),
			           DECODE(T.FINAL_USER_DESC,
			                  NULL,
			                  T.BUYER_NAME,
			                  '/',
			                  T.BUYER_NAME,
			                  T.FINAL_USER_DESC)) FINAL_USER_DESC,
			       TO_CHAR(T.DELVRY_EDATE, 'YYYY-MM-DD') DELVRY_EDATE,
			       T.ORDERCONTACT,
			       (SELECT A.BASENAME
			          FROM COM_BASE_INFO A
			         WHERE A.BASECODE = T.MONITORDEMAND) MONITORDEMAND,
			       T.SPECSTANDARD,
			       DECODE(T.PORDERSTATUS,
			              '0',
			              '待接收',
			              '1',
			              '已接收',
			              '2',
			              '已下发',
			              '3',
			              '生产中',
			              '4',
			              '生产完成',
			              '5',
			              '缴库完成') PORDERSTATUS,
			       T.PSC,
			       T.MSC,
			       T.CODE_JG,
			       T.CODE_DJ_BL,
			       T.PLANWEIGHT,
			       T.PAYDOWNWEIGHT,
			       T.CREATE_NAME,
			       TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
			       T.UPDATE_NAME,
			       TO_CHAR(T.UPDATE_TIME, 'YYYY-MM-DD HH24:MI:SS') UPDATE_TIME,
			       T.ENDGXNAME,
			       T.MERGETYPE,
			       DECODE(T.JZ_FILE_IF_ALL, '1', '是', '0', '否') JZ_FILE_IF_ALL,
			       T.PRDCR_NO,
			       T.ROLL_MONTH,
			       T.MATERIAL_NO,
			       T.MATERIAL_DESC,
			       NVL(T.BL_GROUP_NUM,
			           (SELECT MIN(A.GROUP_NUM)
			              FROM CRAFT_ORD_DESIGN_MSC_BL A
			             WHERE A.DESGIN_KEY = T1.DESGIN_KEY)) BL_GROUP_NUM,
			       T.SHRT_LEN_RATO,
			       T.SHORTEST,
			       T.LONG_LEN_RATO,
			       T.LONGEST,
			       T.SHRT_STOVE,
			       T.AVG_LEN_MIN,
			       T.DIFRNC_LEN_MAX,
			       T.SIGL_LEN,
			       T.ENDLEN_SPECSTD,
			       T.STATION_NO,
			       NVL(T.STATION_NM,
			           (SELECT A.STATION_NM
			              FROM SLM_BASE_STATION A
			             WHERE A.STATION_NO = T.STATION_NO)) STATION_NM,
			       T.PRODUCE_SORT,
			       T.USE_CODE,
			       T.USE_DESC,
			       DECODE(T.TOTLENGTH_M, 0, '', T.TOTLENGTH_M) TOTLENGTH_M,
			       (SELECT A.BASENAME
			          FROM COM_BASE_INFO A
			         WHERE A.BASECODE = NVL(TRIM(T.OUTS_BILLET_FL), '121802')) OUTS_BILLET_FL,
			       T.PIPE_PROPERTY,
			       T.LEN_TOEND_MIN,
			       T.LEN_TOEND_MAX,
			       T.LENGTH_JG,
			       T.WEIGH_TYPE,
			       T.TRANSIT_TYP,
			       T.ACCEPT_NO,
			       (SELECT A.BASENAME
			          FROM COM_BASE_INFO A
			         WHERE A.BASECODE = T.OUTS_STL_PIPE_FL) OUTS_STL_PIPE_FL,
			       DECODE(T.JGORD_IS_OK, '0', '否', '1', '是', '2', '/') JGORD_IS_OK,
			       DECODE(T.JGL_REQ_IS_OK, '0', '否', '1', '是', '2', '/') JGL_REQ_IS_OK,
			       DECODE(T.DJBL_REQ_IS_OK, '0', '否', '1', '是', '2', '/') DJBL_REQ_IS_OK,
			       DECODE(T.IF_SALE_FREEZE, '1', '是', '0', '否') IF_SALE_FREEZE,
			       T.ASK_TYPE_STATUS,
			       T.STD_STYLE_DESC,
			       NVL(T.ROLL_WELL_MONTH, T.ROLL_MONTH) ROLL_WELL_MONTH,
			       T.WEIGHT_PER_M,
			       T.PAYDOWN_NUM,
			       T.PAYDOWN_WT_MIN,
			       T.PAYDOWN_WT_MAX,
			       (SELECT SUM(B.REQWEIGHT)
			          FROM PLN_SALEORDER_R_NUM B
			         WHERE B.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK) REQ_QTYSUM,
			       (SELECT SUM(B.CONFIRM_WT)
			          FROM PLN_SALEORDER_R_NUM B
			         WHERE B.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK) CONFIRM_WT_SUM,
			       T.HEIGHT_ORD_MIN,
			       T.HEIGHT_ORD_MAX,
			       T1.DESGIN_KEY,
			       M.UNIT_DESC_PROCESS UNIT_DESC,
			       F.DEPARTNAME,
			       T2.DESIGN_STS
			  FROM PLN_SALEORD T
			  LEFT JOIN CRAFT_ORD_DESIGN T1
			    ON T1.ORD_LN_PK = T.ORD_LN_PK
			   AND T1.VALIDFLAG = '1'
			 LEFT JOIN (SELECT DECODE(K.DESIGN_STS,
			                           'W',
			                           '等待',
			                           'S',
			                           '通过',
			                           'F',
			                           '失败') DESIGN_STS,
			                    H.ORD_LN_PK
			               FROM SLM_ORDER_LINE H, CRAFT_ORD_DESIGN M
			               LEFT JOIN CRAFT_ORD_DESIGN_STS_TKLG K
			                 ON K.DESGIN_KEY = M.DESGIN_KEY
			                AND K.VALIDFLAG = '1'
			              WHERE M.CRAFT_SEQ =
			                    (SELECT MAX(CRAFT_SEQ)
			                       FROM CRAFT_ORD_DESIGN
			                      WHERE ORD_LN_PK = M.ORD_LN_PK)
			                AND H.VALIDFLAG <> '0'
			                AND M.ORD_LN_PK = H.ORD_LN_PK
			                AND M.VALIDFLAG <> '0') T2
			    ON T2.ORD_LN_PK = T.ORD_LN_PK
			  LEFT JOIN COM_MSC M
			  LEFT JOIN CORE_APP_DEPARTMENT E
			    ON E.DEPARTID = M.UNIT_CODE_PROCESS
			  LEFT JOIN CORE_APP_DEPARTMENT F
			    ON F.DEPARTID = E.PID ON T.MSC = M.MSC
			 WHERE NVL(T1.CRAFT_SEQ, 1) = NVL((SELECT MAX(M.CRAFT_SEQ)
			                                    FROM CRAFT_ORD_DESIGN M
			                                   WHERE M.ORD_LN_PK = T.ORD_LN_PK
			                                     AND M.VALIDFLAG = '1'),
			                                  1)
			   --AND NVL(T.ROLL_MONTH, '1') LIKE '%' || NVL(?, '1') || '%'
			   --AND NVL(T.ACCEPT_NO, '1') LIKE '%' || NVL(NLS_UPPER(?), '1') || '%'
			   AND (T.ORDER_NO || '/' || T.ORDER_SEQ) LIKE '%' || NLS_UPPER(?) || '%'
			   AND T.PORDERSTATUS LIKE '%' || ? || '%'
			   AND DECODE(?, '1', T.JGORD_IS_OK, 1) != DECODE(?, '1', '2', 2)
			   AND DECODE(?, '1', T.DJBL_REQ_IS_OK, 1) != DECODE(?, '1', '2', 2)
			   AND (T.JGORD_IS_OK != '2' OR T.DJBL_REQ_IS_OK != '2')
			   AND T.PORDERSTATUS != '0'
			   AND T.ORDER_TYPE = '1'
			   --AND (T.PORDERSTATUS != '5' OR
			        --TO_DATE(T.ROLL_MONTH, 'YYYY-MM') =
			        --TO_DATE(TO_CHAR(SYSDATE, 'YYYY-MM'), 'YYYY-MM'))
		]]>
	</query>

	<query id="CorePlnOrdJgDjDeal.queryDjBlNeed" desc="查询短节备料需求">
		<![CDATA[
			SELECT T.REQ_BL_ID,
			       T.BLTYPE,
			       T.ORDER_NO,
			       T.ORDER_SEQ,
			       T.DELIVERY_NO,
			       T.ORD_LN_DLY_PK,
			       T.JG_ORDERNO,
			       T.STEELCODE,
			       T.STEELNAME,
			       T.OUTDIAMETER,
			       T.WALLTHICK,
			       T.AIMWALLTHICK,
			       T.LENGTHMAX,
			       T.LENGTHMIN,
			       T.AIMLENGTH,
			       T.CODE_DJ_BL,
			       T.CODE_JG_BL,
			       T.SINGLEWEIGHT,
			       T.JGBL_REQ_WEIGHT,
			       T.JGBL_REQ_NUM,
			       T.MATCHWEIGHT,
			       T.MATCHNUM,
			       DECODE(T.PLANSTATUS, '0', '待处理', '1', '已确认', '2', '已下发') PLANSTATUS,
			       T.CREATE_NAME,
			       TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
			       T.UPDATE_NAME,
			       TO_CHAR(T.UPDATE_TIME, 'YYYY-MM-DD HH24:MI:SS') UPDATE_TIME,
			       T.STD_CODE,
			       T.STD_NAME,
			       T.MSC,
			       DECODE(T.SPEC_SAME_SALE, '1', '相同', '0', '不同') SPEC_SAME_SALE
			  FROM PLN_PORDER_BL_REQ T, PLN_SALEORD T1
			 WHERE T.BLTYPE = '短节备料'
			   AND T.ORDER_NO = T1.ORDER_NO
			   AND T.ORDER_SEQ = T1.ORDER_SEQ
			   AND T.DELIVERY_NO = T1.DELIVERY_NO
			   AND (T1.JGORD_IS_OK != '2' OR T1.DJBL_REQ_IS_OK != '2')
			   AND T1.PORDERSTATUS != '0'

		]]>
	</query>
	<query id="CorePlnOrdJgDjDeal.selectDjBl" desc="查询短节备料需求状态">
		<![CDATA[
		SELECT T.PLANSTATUS FROM PLN_PORDER_BL_REQ T WHERE T.REQ_BL_ID=?
		]]>
	</query>
		<query id="CorePlnOrdJgDjDeal.DoUpdateDjBl" desc="修改短节备料需求">
		<![CDATA[
 UPDATE PLN_PORDER_BL_REQ
    SET AIMWALLTHICK    = ?,
        LENGTHMAX       = ?,
        LENGTHMIN       = ?,
        AIMLENGTH       = ?,
        JGBL_REQ_NUM    = ?,
        SINGLEWEIGHT    = ?,
        JGBL_REQ_WEIGHT = ?,
        UPDATE_NAME     = ?,
        UPDATE_TIME     =TO_DATE(?,'yyyy-MM-dd HH24:mi:ss')
  WHERE REQ_BL_ID = ?
		]]>
	</query>
	<query id="CorePlnOrdJgDjDeal.queryJgOrder" desc="查询接箍和同">
		<![CDATA[
			SELECT T.JG_ORDERNO,
			       T.ORDER_NO,
			       T.ORDER_SEQ,
			       T.DELIVERY_NO,
			       T.ORD_LN_DLY_PK,
			       T.BUYER_ID,
			       T.BUYER_NAME,
			       TO_CHAR(T.DELVRY_EDATE, 'YYYY-MM-DD') DELVRY_EDATE,
			       T.ORDERCONTACT,
			       T.MONITORDEMAND,
			       T.PSC,
			       T.INDEX_SEQ,
			       T.ORDERWEIGHT,
			       T.ORDERNUM,
			       T.CREATE_NAME,
			       TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
			       T.UPDATE_NAME,
			       TO_CHAR(T.UPDATE_TIME, 'YYYY-MM-DD HH24:MI:SS') UPDATE_TIME,
			       DECODE(T.JGORDERSTATUS,
			              '0',
			              '待处理',
			              '1',
			              '已组订单',
			              '2',
			              '已完成') JGORDERSTATUS,
			       T.GROUP_JGX,
			       A.STD_NAME,
			       A.STD_STYLE_DESC,
			       A.CHECK_J_VAL,
			       (SELECT REPLACE(WM_CONCAT(A.STEELCODE_JG_DESC), ',', ';')
			          FROM COM_MSC_JG_R_STEEL N
			         WHERE N.STEELCODE = A.STEELCODE_JG) REP_STEELNAME,
			       A.TAPER,
			       A.MIN_D_JG,
			       A.MAX_D_JG,
			       T.CODE_JG,
			       A.SPEC_JG,
			       A.PRODUCCODE_JG,
			       A.STEELCODE_JG,
			       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = A.STYLE_JG) STYLE_JG,
			       A.PRODUCCODE,
			       A.MODEL_CODE,
			       A.DIAMETER_JG,
			       A.LENGTH_JG,
			       A.HEIGHT_JG,
			       A.WEIGHT_JG,
			       A.MIN_D,
			       A.MIN_H,
			       A.DIAMETER_PL,
			       A.HEIGHT_PL,
			       A.LENGTH_MIN,
			       A.LENGTH_MAX,
			       A.MIN_H_CP,
			       A.MAX_H_CP,
			       A.MIN_D_CP,
			       A.MAX_D_CP,
			       A.DIAMETER,
			       A.ALPHA,
			       B.SPEC_NAME SPEC_JG_DESC,
			       A.PRODUCCODE_JG_DESC,
			       D.STEELNAME STEELCODE_JG_DESC,
			       F.MODEL_DESC,
			       G.PRODUCNAME,
			       H.BASENAME STYLE_JG_DESC,
			       NVL((SELECT F.BASENAME
			             FROM COM_BASE_INFO F
			            WHERE F.BASECODE = T.DEMAND_DETECTION),
			           T.DEMAND_DETECTION) DEMAND_DETECTION,
			       NVL((SELECT F.BASENAME
			             FROM COM_BASE_INFO F
			            WHERE F.BASECODE = T.DEMAND_BONDERIZING),
			           T.DEMAND_BONDERIZING) DEMAND_BONDERIZING,
			       NVL((SELECT F.BASENAME
			             FROM COM_BASE_INFO F
			            WHERE F.BASECODE = T.DEMAND_COPPER),
			           T.DEMAND_COPPER) DEMAND_COPPER,
			       NVL((SELECT F.BASENAME
			             FROM COM_BASE_INFO F
			            WHERE F.BASECODE = T.DEMAND_BLAST),
			           T.DEMAND_BLAST) DEMAND_BLAST,
			       M.CUST_ALPHA_NO,
			       M.ORDER_SPECIAL_DESC,
			       M.ALPHA_CODE,
			       AP.ALPHA_NAME,
			       T.MSC,
			       T.KEY_JG
			  FROM PLN_ORDER_JG T
			  LEFT JOIN PLN_SALEORD T1
			    ON T1.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
			  LEFT JOIN COM_MSC_JG A
			    ON T.CODE_JG = A.CODE_JG
			  LEFT JOIN CRAFT_ORD_DESIGN M1
			    ON M1.VALIDFLAG = '1'
			   AND M1.ORD_LN_PK = T1.ORD_LN_PK
			  LEFT JOIN CRAFT_ORD_DESIGN_MSC_JG M
			    ON M.KEY_JG = T.KEY_JG
			   AND M.DESGIN_KEY = M1.DESGIN_KEY
			  LEFT JOIN COM_BASE_STD_ALPHA AP
			    ON AP.ALPHA_CODE = M.ALPHA_CODE
			  LEFT JOIN COM_BASE_SPEC B
			    ON B.SPEC_CODE = A.SPEC_JG
			  LEFT JOIN COM_BASE_INFO C
			    ON C.BASECODE = A.PRODUCCODE_JG
			  LEFT JOIN COM_BASE_STEEL D
			    ON D.STEELCODE = A.STEELCODE_JG
			  LEFT JOIN COM_BASE_MODEL F
			    ON F.MODEL_CODE = A.MODEL_CODE
			  LEFT JOIN COM_BASE_PRODUCT G
			    ON G.PRODUCCODE = A.PRODUCCODE
			  LEFT JOIN COM_BASE_INFO H
			    ON H.BASECODE = A.STYLE_JG
			 WHERE NVL(T1.ROLL_MONTH, '1') LIKE '%' || NVL(?, '1') || '%'
			   AND NVL(T1.ACCEPT_NO, '1') LIKE '%' || NVL(NLS_UPPER(?), '1') || '%'
			   AND (T.ORDER_NO || '/' || T.ORDER_SEQ) LIKE '%' || NLS_UPPER(?) || '%'
			   AND T1.PORDERSTATUS LIKE '%' || ? || '%'
			   AND DECODE(?, '1', T1.JGORD_IS_OK, 1) != DECODE(?, '1', '2', 2)
			   AND DECODE(?, '1', T1.DJBL_REQ_IS_OK, 1) != DECODE(?, '1', '2', 2)
			   AND (T1.JGORD_IS_OK != '2' OR T1.DJBL_REQ_IS_OK != '2')
			   AND T1.PORDERSTATUS != '0'
			  -- AND (T1.PORDERSTATUS != '5' OR
			       -- TO_DATE(T1.ROLL_MONTH, 'YYYY-MM') =
			        --TO_DATE(TO_CHAR(SYSDATE, 'YYYY-MM'), 'YYYY-MM'))
		]]>
	</query>

	<query id="CorePlnOrdJgDjDeal.querySaleStatus" desc="查询销售合同状态">
		<![CDATA[
			SELECT T1.DESGIN_KEY,
			       T.PORDERSTATUS,
			       T.JGORD_IS_OK,
			       T.JGL_REQ_IS_OK,
			       T.DJBL_REQ_IS_OK,
			       T.ORDERNUM,
			       T.ORDER_NO,
			       T.ORDER_SEQ,
			       T.DELIVERY_NO,
			       NVL(T.DELVRY_RANGE_MAX,0) DELVRY_RANGE_MAX
			  FROM PLN_SALEORD T
			  LEFT JOIN CRAFT_ORD_DESIGN T1
			    ON T1.ORD_LN_PK = T.ORD_LN_PK
			   AND T1.VALIDFLAG = '1'
			 WHERE T.ORD_LN_DLY_PK = ?
		]]>
	</query>
	
	<query id="CorePlnOrdJgDjDeal.selectBlReqStatusByPk" desc="查询备料需求">
		<![CDATA[
			SELECT T.ORDER_NO,
			       T.ORDER_SEQ,
			       T.DELIVERY_NO,
			       T.REQ_BL_ID,
			       T.PLANSTATUS
			  FROM PLN_PORDER_BL_REQ T
			 WHERE T.ORD_LN_DLY_PK = ?
		]]>
	</query>

	<query id="CorePlnOrdJgDjDeal.queryCrfatDesgin" desc="查询工艺设计">
		<![CDATA[
			SELECT M.DESGIN_KEY,
			       T.ORDER_NO,
			       T.ORDER_SEQ,
			       T.DELIVERY_NO,
			       T.ORDERNUM,
			       T.PRDCR_NO,
			       NVL(T.DELVRY_RANGE_MAX,0) DELVRY_RANGE_MAX
			  FROM PLN_SALEORD T
			  LEFT JOIN CRAFT_ORD_DESIGN M
			    ON M.ORD_LN_PK = T.ORD_LN_PK
			   AND M.VALIDFLAG = '1'
			 WHERE T.ORD_LN_DLY_PK = ?
			 ORDER BY M.CRAFT_SEQ DESC
		]]>
	</query>
	
	<query id="CorePlnOrdJgDjDeal.queryPrdcrLst" desc="查询接箍加工监制">
		<![CDATA[
			SELECT NVL((SELECT B.BASENAME
			             FROM COM_BASE_INFO B
			            WHERE B.BASECODE = T1.PRDCR_PRC_DESC),
			           T1.PRDCR_PRC_DESC) PRDCR_PRC_DESC
			  FROM SLM_ORDER_LINE_PRDCR T, SLM_ORDER_LINE_PRDCR_LST T1
			 WHERE T.PRDCR_NO = T1.PRDCR_NO
			   AND T.PRDCR_INDEX = T1.PRDCR_INDEX
			   AND T.PRDCR_NO = ?
			   AND T.CODE_JG = ?
		]]>
	</query>
	
	<query id="CorePlnOrdJgDjDeal.queryJgOrdSerialNum" desc="查询接箍合同流水号">
		<![CDATA[
			SELECT T.JG_ORDERNO
			  FROM PLN_ORDER_JG T
			 WHERE T.ORDER_NO = ?
			   AND T.ORDER_SEQ = ?
			   AND T.DELIVERY_NO = ?
		]]>
	</query>
	
	<query id="CorePlnOrdJgDjDeal.queryCrfatMscJg" desc="查询接箍码信息">
		<![CDATA[
			SELECT T1.CODE_JG,
			       T.DEMAND_DETECTION,
			       T.DEMAND_BONDERIZING,
			       T.DEMAND_COPPER,
			       T.DEMAND_BLAST,
			       T.KEY_JG,
			       T1.WEIGHT_JG
			  FROM CRAFT_ORD_DESIGN_MSC_JG T, COM_MSC_JG T1
			 WHERE T.CODE_JG = T1.CODE_JG
			   AND T1.VALIDFLAG = '1'
			   AND T.DESGIN_KEY = ?
		]]>
	</query>
	
	<query id="CorePlnOrdJgDjDeal.addJgOrd" desc="新增接箍合同">
		<![CDATA[
			INSERT INTO PLN_ORDER_JG
				  (JG_ORDERNO,
				   ORDER_NO,
				   ORDER_SEQ,
				   DELIVERY_NO,
				   BUYER_ID,
				   BUYER_NAME,
				   DELVRY_EDATE,
				   ORDERCONTACT,
				   MONITORDEMAND,
				   IF_MONITOR_JG,
				   PRDCR_NO,
				   PSC,
				   MSC,
				   CODE_JG,
				   STEELCODE,
				   STEELNAME,
				   OUTDIAMETER,
				   WALLTHICK,
				   MODEL_CODE,
				   MODEL_DESC,
				   AIMLENGTH,
				   SINGLEWEIGHT,
				   ORDERWEIGHT,
				   ORDERNUM,
				   CREATE_NAME,
				   CREATE_TIME,
				   ORD_LN_DLY_PK,
				   DEMAND_DETECTION,
				   DEMAND_BONDERIZING,
				   DEMAND_COPPER,
				   DEMAND_BLAST,
				   KEY_JG,
				   SPEC_JG,
				   SPEC_JG_DESC,
				   FINAL_USER,FINAL_USER_DESC,
				   IF_JG_SALEORD)
				  SELECT '#JG_ORDERNO#',
				         T2.ORDER_NO,
				         T2.ORDER_SEQ,
				         T2.DELIVERY_NO,
				         T2.BUYER_ID,
				         T2.BUYER_NAME,
				         T2.DELVRY_EDATE,
				         T2.ORDERCONTACT,
				         '#MONITORDEMAND#',
				         '#IF_MONITOR_JG#',
				         '#PRDCR_NO#',
				         T2.PSC,
				         T2.MSC,
				         T1.CODE_JG,
				         T1.STEELCODE_JG,
				         T1.STEELCODE_JG_DESC,
				         T1.DIAMETER_JG,
				         T1.HEIGHT_JG,
				         T1.MODEL_CODE,
				         T1.MODEL_DESC,
				         T1.LENGTH_JG,
				         T1.WEIGHT_JG,
				         '#ORDERWEIGHT#',
				         '#ORDERNUM#',
				         '#CREATE_NAME#',
				         SYSDATE,
				         T2.ORD_LN_DLY_PK,
				         '#DEMAND_DETECTION#',
				         '#DEMAND_BONDERIZING#',
				         '#DEMAND_COPPER#',
				         '#DEMAND_BLAST#',
				         '#KEY_JG#',
				         T1.SPEC_JG,
				         T1.SPEC_JG_DESC,
				         T2.FINAL_USER,T2.FINAL_USER_DESC,
				         decode(T2.PRODUCCODE,'S000012',1,0)
				    FROM COM_MSC_JG T1, PLN_SALEORD T2
				   WHERE T1.CODE_JG = '#CODE_JG#'
				     AND T2.ORD_LN_DLY_PK = '#ORD_LN_DLY_PK#'
		]]>
	</query>
	
	<query id="CorePlnOrdJgDjDeal.queryRelbyPlnOrd" desc="根据交货合同查询接箍及备料关系">
		<![CDATA[
			SELECT T1.JG_ORDERNO
			  FROM  PLN_ORDER_JG T1
			 WHERE length(T1.PRO_PLAN_ID) > 1
			   AND T1.ORD_LN_DLY_PK = ?
		]]>
	</query>
	
	<query id="CorePlnOrdJgDjDeal.updateJgSaleorder" desc="更新交货行接箍是否制定合同">
		<![CDATA[
			UPDATE PLN_SALEORD T
			   SET T.JGORD_IS_OK = ?,
       			   T.JGL_REQ_IS_OK = ?
			 WHERE T.ORD_LN_DLY_PK = ?
		]]>
	</query>
	
	
	<query id="CorePlnOrdJgDjDeal.RollbackJg" desc="撤销原来形成的接箍合同">
		<![CDATA[
			DELETE FROM PLN_ORDER_JG T WHERE T.ORD_LN_DLY_PK = ?
		]]>
	</query>
	
	
	
	
	
	<query id="CorePlnOrdJgDjDeal.SavePretreatBL" desc="保存销售合同短节备料信息">
		<![CDATA[
			INSERT INTO PLN_PORDER_BL_REQ
				  (REQ_BL_ID,
				   BLTYPE,
				   ORDER_NO,
				   ORDER_SEQ,
				   DELIVERY_NO,
				   ORD_LN_DLY_PK,
				   PRDCR_NO,
				   STEELCODE,
				   STEELNAME,
				   OUTDIAMETER,
				   WALLTHICK,
				   AIMWALLTHICK,
				   LENGTHMAX,
				   LENGTHMIN,
				   CODE_DJ_BL,
				   CODE_JG_BL,
				   STD_CODE,
				   STD_NAME,
				   MSC,
				   PSC,
				   SINGLEWEIGHT,
				   JGBL_REQ_WEIGHT,
				   JGBL_REQ_NUM,
				   MATCHWEIGHT,
				   MATCHNUM,
				   PLANSTATUS,
				   CREATE_NAME,
				   CREATE_TIME,
				   SPEC_SAME_SALE)
				  SELECT (SELECT ('ZZBY-D' || TO_CHAR(SYSDATE, 'YYMMDD') || '/' ||
				                 LPAD(NVL(MAX(TO_NUMBER(SUBSTR(T.REQ_BL_ID, 14)) + 1), '1'),
				                       3,
				                       '0'))
				            FROM PLN_PORDER_BL_REQ T
				           WHERE SUBSTR(T.REQ_BL_ID, 0, 12) =
				                 'ZZBY-D' || TO_CHAR(SYSDATE, 'YYMMDD')),
				         '#BLTYPE#',
				         '#ORDER_NO#',
				         '#ORDER_SEQ#',
				         '#DELIVERY_NO#',
				         '#ORD_LN_DLY_PK#',
				         (select PRDCR_NO from PLN_SALEORD where ORD_LN_DLY_PK='#ORD_LN_DLY_PK#'),
				         T1.STEELCODE,
				         T1.STEELNAME,
				         T1.MIN_D,
				         T1.MIN_H,
				         T1.MIN_H,
				         T1.MAX_L,
				         '#LENGTHMIN#',
				         '#CODE_DJ_BL#',
				         '#CODE_JG_BL#',
				         T1.STD_CODE,
				         T1.STD_NAME,
				         '#MSC#',
				         '#PSC#',
				         '#SINGLEWEIGHT#',
				         '#JGBL_REQ_WEIGHT#',
				         '#JGBL_REQ_NUM#',
				         '0',
				         '0',
				         '0',
				         '#CREATE_NAME#',
				         SYSDATE,
				         '#SPEC_SAME_SALE#'
				    FROM COM_MSC_BL T1
				   WHERE T1.PSC_BL = '#CODE_DJ_BL#'
		]]>
	</query>
	
	<query id="CorePlnOrdJgDjDeal.updateDjSaleorder" desc="更新销售合同">
		<![CDATA[
			UPDATE PLN_SALEORD T
			   SET T.DJBL_REQ_IS_OK = ?
			 WHERE T.ORD_LN_DLY_PK = ?
		]]>
	</query>
	
	<query id="CorePlnOrdJgDjDeal.updateDjBlGroup" desc="更新短节备料组">
		<![CDATA[
			UPDATE PLN_SALEORD T SET T.BL_GROUP_NUM = ? WHERE T.ORD_LN_DLY_PK = ?
		]]>
	</query>
	
	<query id="CorePlnOrdJgDjDeal.RollbackDj" desc="撤销原来形成的短节需求">
		<![CDATA[
			DELETE FROM PLN_PORDER_BL_REQ T WHERE T.REQ_BL_ID = ?
		]]>
	</query>
	
	<query id="CorePlnOrdJgDjDeal.queryPlnBlReqStatus" desc="查询备料信息">
		<![CDATA[
			SELECT T.REQ_BL_ID,
			       T.BLTYPE,
			       T.ORDER_NO,
			       T.ORDER_SEQ,
			       T.DELIVERY_NO,
			       T.STEELCODE,
			       T.STEELNAME,
			       T.OUTDIAMETER,
			       T.WALLTHICK,
			       T.AIMWALLTHICK,
			       T.LENGTHMAX,
			       T.LENGTHMIN,
			       T.AIMLENGTH,
			       T.CODE_DJ_BL,
			       T.GETRATE_DJ,
			       T.CODE_JG_BL,
			       T.STD_CODE,
			       T.STD_NAME,
			       T.MSC,
			       T.SINGLEWEIGHT,
			       T.JGBL_REQ_WEIGHT,
			       T.JGBL_REQ_NUM,
			       T.MATCHWEIGHT,
			       T.MATCHNUM,
			       T.PLANSTATUS,
			       T.JGCUTPLAN_WT,
			       T.JGCUTPLAN_NUM,
			       T.CREATE_NAME,
			       TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
			       T.UPDATE_NAME,
			       TO_CHAR(T.UPDATE_TIME, 'YYYY-MM-DD HH24:MI:SS') UPDATE_TIME,
			       T.SPEC_SAME_SALE,
			       ORD_LN_DLY_PK
			  FROM PLN_PORDER_BL_REQ T
			 WHERE T.REQ_BL_ID = ?
		]]>
	</query>
	
	<query id="CorePlnOrdJgDjDeal.selectPlnBlReqPscMsc" desc="获取备料产品码冶金规范码">
		<![CDATA[
			SELECT P.PSC,
			       M.MSC,
			       P.PSC_DESC,
			       P.STD_STYLE,
			       B.STD_STYLE,
			       T.REQ_BL_ID,
			       T.CODE_DJ_BL,
			       M1.UNIT_CODE_PROCESS,
			       M1.UNIT_DESC_PROCESS,
			       F.DEPARTID,
			       F.DEPARTNAME
			  FROM PLN_PORDER_BL_REQ T
			  LEFT JOIN COM_MSC_BL B
			    ON B.PSC_BL = 
			       DECODE(TRIM(T.BLTYPE), '接箍料', T.CODE_JG_BL, T.CODE_DJ_BL)
			  LEFT JOIN COM_PSC P
			    ON P.PRODUCCODE = B.PRODUCCODE
			   AND P.STD_CODE = B.STD_CODE
			   AND P.STEELCODE = B.STEELCODE
			   AND NVL(P.STD_STYLE, '1') = NVL(B.STD_STYLE, '1')
			   AND P.VALIDFLAG = '1'
			  LEFT JOIN COM_PSC_R_MSC M
			    ON M.PSC = P.PSC
			   AND M.USE_CODE = B.USE_CODE
			   AND M.VALIDFLAG = '1'
			  LEFT JOIN COM_MSC M1
			    ON M.MSC = M1.MSC
			  LEFT JOIN CORE_APP_DEPARTMENT E
			    ON E.DEPARTID = M1.UNIT_CODE_PROCESS
			  LEFT JOIN CORE_APP_DEPARTMENT F
			    ON F.DEPARTID = E.PID
			 WHERE T.REQ_BL_ID = ?
		]]>
	</query>
	
	<query id="CorePlnOrdJgDjDeal.selectBlCraftDesgin" desc="查询备料码评审">
		<![CDATA[
			SELECT T.DESGIN_KEY,
			       T.VALIDFLAG,
			       M1.CRAFT_NAME,
			       T.CRAFT_SEQ,
			       T.CRAFT_NO,
			       T.CRAFT_NO_V
			  FROM CRAFT_ORD_DESIGN T
			  LEFT JOIN CRAFT_ORD_DESIGN_APPOINT M1
			    ON M1.ORD_LN_PK = T.ORD_LN_PK
			  LEFT JOIN CRAFT_ORD_DESIGN_STS_TKLG K
			    ON K.DESGIN_KEY = T.DESGIN_KEY
			   AND K.VALIDFLAG = '1'
			 WHERE T.DESGIN_KEY IS NOT NULL
			   AND K.DESIGN_STS = 'S'
			   AND T.ORD_LN_PK = ?
		]]>
	</query>
	
	<query id="CorePlnOrdJgDjDeal.queryBlDesginPl" desc="查询质量设计制程">
		<![CDATA[		
         SELECT T.MSC_PLINE,
                T.WHOLE_BACKLOG,
                T.WHOLE_BACKLOG_DESC,
                (SELECT LISTAGG(C.GRADENAME, ',') WITHIN GROUP(ORDER BY C.PRIORITY ASC, C.GRADECODE)
                   FROM (SELECT DISTINCT B.GRADENAME, B.GRADECODE, B.PRIORITY
                           FROM CRAFT_ORD_DESIGN_MSC_PL_GZ B,
                                CRAFT_ORD_DESIGN_MSC_PL    B1
                          WHERE B.DESGIN_KEY = B1.DESGIN_KEY
                            AND B.MSC_PLINE = B1.MSC_PLINE
                            AND B.PRIORITY<'100'
                            AND B1.DESGIN_KEY =?
                          ORDER BY B.PRIORITY ASC, B.GRADECODE ASC) C) GRADENAME
           FROM CRAFT_ORD_DESIGN_MSC_PL T
          WHERE T.DESGIN_KEY = ?
            AND T.VALIDFLAG = '1'
		]]>
	</query>
	
	<query id="CorePlnOrdJgDjDeal.queryMscplPrc" desc="销售合同查询制程工序">
		<![CDATA[
			SELECT DESGIN_KEY,
	              MSC_PLINE,
	              WHOLE_BACKLOG,
	              WHOLE_BACKLOG_DESC,
	              BACKLOG_SEQ,
	              PROCESS_CODE,
	              PROCESS_DESC,
	              PROCESS_SEQ,
	              PROCESS_CODE_C,
	              PROCESS_DESC_C,
	              MINUTE_PRODUCT,
	              MINUTE_PRODUCT_OUT,
	              MINUTE_WAITE,
	              MINUTE_WAITE_OUT,
	              BATCH_WAITE,
	              BATCH_WAITE_OUT,
	              SIC
	         FROM CRAFT_ORD_DESIGN_MSC_PL_PRC T
	       WHERE T.DESGIN_KEY = ?
	         AND T.MSC_PLINE = ?
	       ORDER BY T.BACKLOG_SEQ ASC
		]]>
	</query>
	
	<query id="CorePlnOrdJgDjDeal.selectDesginBom" desc="销售合同查询制程工序">
		<![CDATA[
			SELECT C.PRIORITY, W.*
  FROM (SELECT T.BOM,
               T.MSC,
               T.MSC_PLINE,
               T.MATERIAL_NO,
               T.MATERIAL_DESC,
               T.WHOLE_BACKLOG,
               T.WHOLE_BACKLOG_DESC,
               T.GRADECODE,
               T.GRADENAME,
               T.A_OUT_MATERIAL_NO,
               T.B_OUT_MATERIAL_NO,
               T.C_OUT_MATERIAL_NO,
               T.D_IN_MATERIAL_NO,
               T.D_OUT_MATERIAL_NO,
               T.E_IN_MATERIAL_NO,
               T.E_IN_MATERIAL_DESC,
               T.E_OUT_MATERIAL_NO,
               T.E_OUT_MATERIAL_DESC,
               (SELECT TO_CHAR(WM_CONCAT(B.PLINE_NAME))
                  FROM SLM_BASE_MATERIAL_D_PL B
                 WHERE B.IN_MATERIAL_NO = T.D_IN_MATERIAL_NO
                   AND B.OUT_MATERIAL_NO = T.D_OUT_MATERIAL_NO
                   AND (B.DISABLE_FL != '1' OR B.DISABLE_FL IS NULL)) D_PLINE,
               (SELECT B.DIMATER
                  FROM COM_BASE_SPEC B
                 WHERE B.SPEC_CODE = T.SPEC_CODE_R) DIMATER,
               (SELECT B.HEIGHT
                  FROM COM_BASE_SPEC B
                 WHERE B.SPEC_CODE = T.SPEC_CODE_R) HEIGHT,
               B.DESGIN_KEY
          FROM SLM_ORD_DESIGN_BOM T, CRAFT_ORD_LINE_BOM B
         WHERE T.BOM = B.BOM
           AND B.DESGIN_KEY = ? AND T.MSC_PLINE=? AND T.MSC=?) W,
       CRAFT_ORD_DESIGN_MSC_PL_GZ C
 WHERE W.DESGIN_KEY = C.DESGIN_KEY(+)
   AND W.MSC_PLINE = C.MSC_PLINE(+)
   AND W.GRADECODE = C.GRADECODE(+)
   AND C.PRIORITY<'100'
 ORDER BY C.PRIORITY ASC, W.GRADECODE ASC
		]]>
	</query>
	
	<query id="CorePlnOrdJgDjDeal.addBlReqOrderPrc" desc="备料确认到排产">
		<![CDATA[
			INSERT INTO PLN_SALEORD_PROC
				  (ORD_LN_DLY_PK,
				   PLN_DIVIDE_ID,
				   ORDER_SOURCE,
				   ORDER_NO,
				   ORDER_SEQ,
				   DELIVERY_NO,
				   PSC,
				   CRAFT_FILE_NO,
				   CRAFT_FILE_MAN,
				   MSC,
				   INDEX_SEQ,
				   PROCESS_SEQ,
				   BOM,
				   GRADECODE_ALL,
				   GRADECODE,
				   G_IS_OK,
				   GROUP_JGX,
				   F_IS_OK,
				   GROUP_RCL,
				   GROUP_ROLL_ALL,
				   GROUP_ROLL,
				   BJ_TYPE,
				   E_IN_MATERIAL_NO,
				   E_IN_MATERIAL_DESC,
				   DIMATER_YLG,
				   HEIGHT_YLG,
				   MATERIAL_NO,
				   MATERIAL_DESC,
				   STUFF_PROPERTY,
				   GRADECODE_IS_OK,
				   D_IS_OK,
				   E_IS_OK,
				   WEIGHT_PER_M,
				   PLAN_WT_D,
				   PLAN_NUM_D,
				   PLAN_TOT_LEN_D,
				   PLAN_WT_BEGIN,
				   PLAN_NUM_BEGIN,
				   PLANSTATUS,
				   IF_ALLOW_ISSUE,
				   HEIGHT_NK_MIN,
				   HEIGHT_NK_MAX,
				   ORDER_QTY_D,
				   ORDER_UNIT,
				   AIM_LEN_ROLL,
				   AIM_LEN_END,
				   PLAN_P_MAIN,
				   TOT_LEN_ONE_P,
				   CUT_NUM_P,
				   CRAFT_SEQ,
				   CRAFT_NO_V,
				   AIM_WALLTHICK,
				   ROLL_LENGTH,
				   CRAFT_RENEW_ST,
				   CRAFT_NO_NEW,
				   CRAFT_NO_V_NEW,
				   GROUP_ROLL_NAME,
				   PLAN_IS_OK,
				   ABC,
				   ROLL_MONTH,
				   PRDCRPRO,
				   LEN_ROLL_MAX,
				   LEN_ROLL_MIN,AIM_OUTDIAMETER,FEED_RATE,COEFFICIENT,COEFFICIENT_MIN,PLAN_P_MAIN_MIN,AIM_WT_END,WEIGHT_KZ_M,PROC_DESC_C_RCL)
				  SELECT T.REQ_BL_ID,
				         '01',
				         '备料需求',
				         T.REQ_BL_ID,
				         '',
				         '',
				         '#PSC#',
				         '#CRAFT_FILE_NO#',
				         '#CRAFT_FILE_MAN#',
				         '#MSC#',
				         '#INDEX_SEQ#',
				         '#PROCESS_SEQ#',
				         '#BOM#',
				         '#GRADECODE_ALL#',
				         '#GRADECODE#',
				         '#G_IS_OK#',
				         '#GROUP_JGX#',
				         '#F_IS_OK#',
				         '#GROUP_RCL#',
				         '#GROUP_ROLL_ALL#',
				         '#GROUP_ROLL#',
				         '#BJ_TYPE#',
				         '#E_IN_MATERIAL_NO#',
				         '#E_IN_MATERIAL_DESC#',
				         '#DIMATER_YLG#',
				         '#HEIGHT_YLG#',
				         '#MATERIAL_NO#',
				         '#MATERIAL_DESC#',
				         '#STUFF_PROPERTY#',
				         '0',
				         '#D_IS_OK#',
				         '#E_IS_OK#',
				         '#WEIGHT_PER_M#',
				         '#PLAN_WT_D#',
				         '#PLAN_NUM_D#',
				         '#PLAN_TOT_LEN_D#',
				         '#PLAN_WT_BEGIN#',
				         '#PLAN_NUM_BEGIN#',
				         '1',
				         '0',
				         '#HEIGHT_NK_MIN#',
				         '#HEIGHT_NK_MAX#',
				         T.JGBL_REQ_WEIGHT,
				         '吨',
				         '#AIM_LEN_ROLL#',
				         '#AIM_LEN_END#',
				         '#PLAN_P_MAIN#',
				         '#TOT_LEN_ONE_P#',
				         '#CUT_NUM_P#',
				         '#CRAFT_SEQ#',
				         '#CRAFT_NO_V#',
				         '#AIM_WALLTHICK#',
				         '#ROLL_LENGTH#',
				         '#CRAFT_RENEW_ST#',
				         '#CRAFT_NO_NEW#',
				         '#CRAFT_NO_V_NEW#',
				         '#GROUP_ROLL_NAME#',
				         '0',
				         '#ABC#',
				         TO_CHAR(SYSDATE, 'YYYY-MM'),
				         '#PRDCRPRO#',
				         '#LEN_ROLL_MAX#',
				         '#LEN_ROLL_MIN#','#AIM_OUTDIAMETER#','#FEED_RATE#','#COEFFICIENT#',
				         '#COEFFICIENT_MIN#','#PLAN_P_MAIN_MIN#','#AIM_WT_END#','#WEIGHT_KZ_M#','#PROC_DESC_C_RCL#'
				    FROM PLN_PORDER_BL_REQ T
				   WHERE T.REQ_BL_ID = ?
		]]>
	</query>
	
	<query id="CorePlnOrdJgDjDeal.updateBlReqInfo" desc="更新备料需求信息">
		<![CDATA[
			UPDATE PLN_PORDER_BL_REQ T
			   SET T.JGBL_REQ_NUM = '#JGBL_REQ_NUM#',
			       T.PLANSTATUS   = '#PLANSTATUS#',
			       T.AIMWALLTHICK = '#AIMWALLTHICK#',
			       T.AIMLENGTH    = '#AIMLENGTH#'
			 WHERE T.REQ_BL_ID = '#REQ_BL_ID#'
		]]>
	</query>
	
	<query id="CorePlnOrdJgDjDeal.deleteBlSaleOrd" desc="删除备料交货行记录">
		<![CDATA[
			DELETE FROM PLN_SALEORD T WHERE T.ORD_LN_DLY_PK = ?
		]]>
	</query>
	
	<query id="CorePlnOrdJgDjDeal.deleteBlPlnProc" desc="删除备料排产记录">
		<![CDATA[
			DELETE FROM PLN_SALEORD_PROC T WHERE T.ORD_LN_DLY_PK = ?
		]]>
	</query>
	
	<query id="CorePlnOrdJgDjDeal.selectBlBomMaterial" desc="查询备料信息">
		<![CDATA[
			SELECT B.PSC_BL,
			       B.STEELCODE,
			       B.STEELNAME,
			       S.SPEC_CODE,
			       S.SPEC_NAME,
			       B.STD_STYLE,
			       B.STD_STYLE_DESC,
			       B.MIN_D          DIMATER,
			       B.MIN_H          HEIGHT,
			       B.MODEL_CODE,
			       B.MODEL_DESC,
			       B.PRODUCCODE,
			       B.PRODUCNAME,
			       M.MSC,
			       M.MSC_DESC,
			       P.PSC,
			       P.PSC_DESC
			  FROM COM_MSC_BL B
			  LEFT JOIN COM_PSC P
			    ON P.PRODUCCODE = B.PRODUCCODE
			   AND P.STD_CODE = B.STD_CODE
			   AND P.STEELCODE = B.STEELCODE
			   AND NVL(P.STD_STYLE, '1') = NVL(B.STD_STYLE, '1')
			   AND P.VALIDFLAG = '1'
			  LEFT JOIN COM_BASE_SPEC S
			    ON S.DIMATER = B.MIN_D
			   AND S.HEIGHT = B.MIN_H
			   AND S.MSC_STYLE = 'A'
			   AND S.VALIDFLAG = '1'
			  LEFT JOIN COM_PSC_R_MSC M
			    ON M.PSC = P.PSC
			   AND M.USE_CODE = B.USE_CODE
			   AND M.VALIDFLAG = '1'
			 WHERE B.PSC_BL = ?
		]]>
	</query>
	
	
	
		
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	<query id="CorePlnOrdJgDjDeal.queryBlList" desc="查询备料清单表">
		<![CDATA[
			SELECT T.PSC_BL,
			       T.PRODUCCODE,
			       T.PRODUCNAME,
			       T.STD_CODE,
			       T.STD_NAME,
			       T.STEELCODE,
			       T.STEELNAME,
			       T.STD_STYLE,
			       T.STD_STYLE_DESC,
			       T.MODEL_CODE,
			       T.MODEL_DESC,
			       T.MIN_D,
			       T.MIN_H,
			       T.USE_CODE,
			       T.USE_DESC,
			       T.MIN_L,
			       T.MAX_L,
			       T.MEMO
			  FROM COM_MSC_BL T
			 WHERE T.PSC_BL = ?
			   AND T.VALIDFLAG = '1'
		]]>
	</query>
	
	<query id="CorePlnOrdJgDjDeal.queryDesginBlList" desc="查询备料清单表">
		<![CDATA[
			SELECT M.GROUP_NUM,
			       T.PSC_BL,
			       T.PRODUCCODE,
			       T.PRODUCNAME,
			       T.STD_CODE,
			       T.STD_NAME,
			       T.STEELCODE,
			       T.STEELNAME,
			       T.STD_STYLE,
			       T.STD_STYLE_DESC,
			       T.MODEL_CODE,
			       T.MODEL_DESC,
			       T.MIN_D,
			       T.MIN_H,
			       T.USE_CODE,
			       T.USE_DESC,
			       T.MIN_L,
			       T.MAX_L,
			       T.MEMO
			  FROM COM_MSC_BL T, CRAFT_ORD_DESIGN_MSC_BL M
			 WHERE T.PSC_BL = M.PSC_BL
			   AND T.VALIDFLAG = '1'
			   AND M.DESGIN_KEY = ?
		]]>
	</query>
	
	<query id="CorePlnOrdJgDjDeal.queryblPsc" desc="查询产品码">
		<![CDATA[
			SELECT T.PSC
			  FROM COM_PSC T
			 WHERE T.PRODUCCODE = ?
			   AND T.STD_CODE = ?
			   AND T.STEELCODE = ?
			   AND DECODE(?, '', 1, T.STD_STYLE) = DECODE(?, '', 1, ?)
			   AND T.VALIDFLAG = '1'
		]]>
	</query>
	
	<query id="CorePlnOrdJgDjDeal.queryPscForMsc" desc="根据产品码查找对应冶金规范码">
		<![CDATA[
			SELECT T.MSC
			  FROM COM_PSC_R_MSC T
			 WHERE T.PSC = ?
			   AND T.VALIDFLAG = '1'
		]]>
	</query>
	
	<query id="CorePlnOrdJgDjDeal.queryBlCodeByGp" desc="根据DESGIN_KEY与备料组查询短节备料码">
		<![CDATA[
		 	SELECT T.PSC_BL
			  FROM CRAFT_ORD_DESIGN_MSC_BL T
			 WHERE T.DESGIN_KEY = ?
			   AND T.GROUP_NUM = ?
		]]>
	</query>
	
	<query id="CorePlnOrdJgDjDeal.queryBlCode" desc="根据DESGIN_KEY查询短节备料码">
		<![CDATA[
			SELECT T.GROUP_NUM, T.PSC_BL
			  FROM CRAFT_ORD_DESIGN_MSC_BL T
			 WHERE T.DESGIN_KEY = ?
		]]>
	</query>
	
	<query id="CorePlnOrdJgDjDeal.queryBlGroup" desc="查询质量设计下所有备料组">
		<![CDATA[
			SELECT DISTINCT T.GROUP_NUM,
			       T1.ORDERNUM,
			       T1.LENGTHDISC,
			       T1.STEELCODE,
			       T1.STEELNAME,
			       T1.OUTDIAMETER,
			       T1.WALLTHICK,
			       T1.LENGTHMAX
			  FROM CRAFT_ORD_DESIGN_MSC_BL T, PLN_SALEORD T1
			 WHERE T.DESGIN_KEY = ?
			   AND T1.ORD_LN_DLY_PK = ?
		]]>
	</query>
	
	<query id="CorePlnOrdJgDjDeal.querySaleByPrimary" desc="通过合同号查询销售合同内容">
		<![CDATA[
			SELECT T.ORDER_NO,
			       T.ORDER_SEQ,
			       T.DELIVERY_NO,
			       T.DJBL_REQ_IS_OK,
			       T.PORDERSTATUS,
			       T.ORD_LN_DLY_PK,
			       T.OUTDIAMETER,
			       T.WALLTHICK,
			       T.STEELCODE
			  FROM PLN_SALEORD T
			 WHERE T.ORD_LN_DLY_PK = ?
		]]>
	</query>
	
	<query id="CorePlnOrdJgDjDeal.getAcceptNum" desc="接收版本号">
		<![CDATA[
			SELECT 'L' || TO_CHAR(SYSDATE, 'YYYYMMDD') ||
			               LPAD(NVL(MAX(TO_NUMBER(SUBSTR(T.ACCEPT_NO, 10)) + 1), '1'),
			                    2,
			                    '0') ACCEPTNO
			          FROM PLN_SALEORD T
			         WHERE SUBSTR(T.ACCEPT_NO, 0, 9) =
			               ('X' || TO_CHAR(SYSDATE, 'YYYYMMDD'))
		]]>
	</query>
	
	<query id="CorePlnOrdJgDjDeal.getCraftStdSic" desc="获取工艺交付标准公差索引号">
		<![CDATA[
			SELECT B.SIC FROM CRAFT_ORD_DESIGN_STD B WHERE B.DESGIN_KEY = ?
		]]>
	</query>
	
	<query id="CorePlnOrdJgDjDeal.getSpecBaseCode" desc="获取外径壁厚对应的规格代码">
		<![CDATA[
			SELECT T.SPEC_CODE, T.SPEC_NAME
			  FROM COM_BASE_SPEC T
			 WHERE T.MSC_STYLE = 'A'
			   AND T.VALIDFLAG = '1'
			   AND TO_NUMBER(T.DIMATER) = ?
			   AND TO_NUMBER(T.HEIGHT) = ?
		]]>
	</query>
	
	<query id="CorePlnOrdJgDjDeal.addPlnSaleOrdBl" desc="新增备料交货行到提报表">
		<![CDATA[
			INSERT INTO PLN_SALEORD
				  (ORD_PK,
				   ORD_LN_PK,
				   ORD_LN_DLY_PK,
				   ORDER_NO,
				   ORDER_SEQ,
				   DELIVERY_NO,
				   PRD_CLS,
				   PRODUCCODE,
				   PRODUCNAME,
				   STD_CODE,
				   STD_NAME,
				   STEELCODE,
				   STEELNAME,
				   SPEC_CODE,
				   SPEC_NAME,
				   OUTDIAMETER,
				   WALLTHICK,
				   LEN_UNIT,
				   LENGTHMAX,
				   LENGTHMIN,
				   LENGTHDISC,
				   MODEL_CODE,
				   MODEL_DESC,
				   ORDER_UNIT,
				   ORDER_QTY,
				   ORDERWEIGHT,
				   ORDERNUM,
				   TOTLENGTH,
				   TOTLENGTH_UNIT,
				   DELVRY_RANGE_TPE,
				   DELVRY_RANGE_MIN,
				   DELVRY_RANGE_MAX,
				   ORDERFROM,
				   MONITORDEMAND,
				   SPECSTANDARD,
				   PORDERSTATUS,
				   PSC,
				   MSC,
				   PLANWEIGHT,
				   PAYDOWNWEIGHT,
				   PAYDOWN_NUM,
				   CREATE_NAME,
				   CREATE_TIME,
				   UPDATE_NAME,
				   UPDATE_TIME,
				   ENDGXNAME,
				   MERGETYPE,
				   PRDCR_NO,
				   ROLL_MONTH,
				   ROLL_WELL_MONTH,
				   MATERIAL_NO,
				   MATERIAL_DESC,
				   PRODUCE_SORT,
				   USE_CODE,
				   USE_DESC,
				   WEIGHT_PER_M,
				   TOTLENGTH_M,
				   OUTS_BILLET_FL,
				   OUTS_STL_PIPE_FL,
				   PIPE_PROPERTY,
				   LEN_TOEND_MIN,
				   LEN_TOEND_MAX,
				   CRAFT_SEQ,
				   CRAFT_NO_V,
				   CRAFT_FILE_NO,
				   CRAFT_FILE_MAN,
				   WEIGH_TYPE,
				   TRANSIT_TYP,
				   ACCEPT_NO,
				   JGORD_IS_OK,
				   JGL_REQ_IS_OK,
				   DJBL_REQ_IS_OK,
				   STD_STYLE_DESC,
				   HEIGHT_ORD_MIN,
				   HEIGHT_ORD_MAX,
				   PAYDOWN_WT_MIN,
				   PAYDOWN_WT_MAX,
				   ORDER_TYPE,
				   BUYER_ID,BUYER_NAME,FINAL_USER,FINAL_USER_DESC,JZ_FILE_IF_ALL,SUPPLY_UNIT_CODE,SUPPLY_UNIT)
				  SELECT B.PSC_BL,
				         B.PSC_BL,
				         '#ORD_LN_DLY_PK#',
				         '#ORDER_NO#',
				         '#ORDER_SEQ#',
				         '#DELIVERY_NO#',
				         (SELECT P.PRODUC_STYLE
				            FROM COM_BASE_PRODUCT P
				           WHERE P.PRODUCCODE = B.PRODUCCODE
				             AND P.VALIDFLAG = '1'),
				         B.PRODUCCODE,
				         B.PRODUCNAME,
				         B.STD_CODE,
				         B.STD_NAME,
				         B.STEELCODE,
				         B.STEELNAME,
				         '#SPEC_CODE#',
				         '#SPEC_NAME#',
				         B.MIN_D,
				         B.MIN_H,
				         '米',
				         '#LENGTHMAX#',
				         '#LENGTHMIN#',
				          '#LENGTHMIN#' || '-' || '#LENGTHMAX#' || '米',
				         B.MODEL_CODE,
				         B.MODEL_DESC,
				         '吨',
				         '#ORDER_QTY#',
				         '#ORDERWEIGHT#',
				         '#ORDERNUM#',
				         '0',
				         '米',
				         '%',
				         '5',
				         '5',
				         '备料需求',
				         '#MONITORDEMAND#',
				         '#SPECSTANDARD#',
				         '1',
				         '#PSC#',
				         '#MSC#',
				         '#PLANWEIGHT#',
				         '0',
				         '0',
				         '#CREATE_NAME#',
				         SYSDATE,
				         '#UPDATE_NAME#',
				         SYSDATE,
				         '#ENDGXNAME#',
				         '0',
				         '#PRDCR_NO#',
				         TO_CHAR(SYSDATE, 'YYYY-MM'),
				         TO_CHAR(SYSDATE, 'YYYY-MM'),
				         '#MATERIAL_NO#',
				         '#MATERIAL_DESC#',
				         '#PRODUCE_SORT#',
				         B.USE_CODE,
				         B.USE_DESC,
				         '#WEIGHT_PER_M#',
				         '0',
				         B.OUTS_BILLET_FL,
				         B.OUTS_STL_PIPE_FL,
				         '#PIPE_PROPERTY#',
				         '#LEN_TOEND_MIN#',
				         '#LEN_TOEND_MAX#',
				         '#CRAFT_SEQ#',
				         '#CRAFT_NO_V#',
				         '#CRAFT_FILE_NO#',
				         '#CRAFT_FILE_MAN#',
				         '#WEIGH_TYPE#',
				         '#TRANSIT_TYP#',
				         '#ACCEPT_NO#',
				         '2',
				         '2',
				         '2',
				         B.STD_STYLE_DESC,
				         '#HEIGHT_ORD_MIN#',
				         '#HEIGHT_ORD_MAX#',
				         '#PAYDOWN_WT_MIN#',
				         '#PAYDOWN_WT_MAX#',
				         '2',
				         '#BUYER_ID#','#BUYER_NAME#','#FINAL_USER#','#FINAL_USER_DESC#','#JZ_FILE_IF_ALL#','120501','天津钢管制造有限公司'
				    FROM COM_MSC_BL B
				   WHERE B.PSC_BL = ?
		]]>
	</query>
	<query id="CorePlnOrdJgDjDeal.selectOutBillFi" desc="获取是否外购">
		<![CDATA[
SELECT DECODE(T.OUTS_BILLET_FL,'121801','1','121802','0') OUTS_BILLET_FL
  FROM COM_MSC_BL T
 WHERE T.PSC_BL = ?
   AND T.VALIDFLAG = '1'	
			]]>
	</query>
	
	
	
	
</queryMap>