<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="接箍合同组订单">

	<query id="CorePlnJgOrdToDd.queryJgOrdNo" desc="查询所有未处理完成接箍和同">
		<![CDATA[
			SELECT T.JG_ORDERNO FROM PLN_ORDER_JG T WHERE T.PRO_PLAN_ID IS NULL
		]]>
	</query>

	<query id="CorePlnJgOrdToDd.queryJgGxMNo" desc="查询工序订单订单号">
		<![CDATA[
			SELECT T.PRO_PLAN_ID FROM PLN_GX_JG_M T WHERE T.PLANSTATUS = '0'
		]]>
	</query>

	<query id="CorePlnJgOrdToDd.queryJgOrd" 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.PRDCR_NO,
			       DECODE(T.PRDCR_NO, NULL, '否', '是') IF_MONITOR_JG,
			       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,
			       C.BASENAME 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,
			       NVL(M.CUST_ALPHA_NO, '/') CUST_ALPHA_NO,
			       DECODE(M.CUST_ALPHA_NO, NULL, '/', M.ORDER_SPECIAL_DESC) ORDER_SPECIAL_DESC,
			       NVL(M.ALPHA_CODE, '/') ALPHA_CODE,
			       AP.ALPHA_NAME,
			       (SELECT TO_CHAR(WM_CONCAT(PR.STATION_CODE || ',' || PR.PDEPT_NO || ',' ||
			                                 PR.PDEPT_NO2 || ',' || PR.PDEPT_NO3))
			          FROM (SELECT P1.PRDCR_NO,
			                       P1.STATION_CODE,
			                       P1.PDEPT_NO,
			                       P1.PDEPT_NO2,
			                       P1.PDEPT_NO3
			                  FROM SLM_ORDER_LINE_PRDCR_LST P1, SLM_ORDER_LINE_PRDCR P
			                 WHERE P1.PRDCR_NO = P.PRDCR_NO
			                   AND P1.PRDCR_INDEX = P.PRDCR_INDEX
			                   AND P1.PRDCR_PRC_FL = '1'
			                   AND P.CODE_JG IS NOT NULL
			                 ORDER BY P1.STATION_CODE ASC) PR
			         WHERE PR.PRDCR_NO = T.PRDCR_NO) PRD_STATION_DEPT,
			       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 CF
			    ON CF.ORD_LN_PK = T1.ORD_LN_PK
			   AND CF.VALIDFLAG = '1'
			  LEFT JOIN CRAFT_ORD_DESIGN_MSC_JG M
			    ON M.DESGIN_KEY = CF.DESGIN_KEY
			   AND M.KEY_JG = T.KEY_JG
			  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
			  LEFT JOIN COM_BASE_STD_ALPHA AP
			    ON AP.ALPHA_CODE = M.ALPHA_CODE
			 WHERE T.PRO_PLAN_ID IS NULL
			   AND T.JG_ORDERNO LIKE '%' || NLS_UPPER(?) || '%'
		]]>
	</query>

	<query id="CorePlnJgOrdToDd.queryJgGxM" desc="查询接箍工序订单">
		<![CDATA[
			SELECT T.PRO_PLAN_ID,
			       T.PLINE_CODE,
			       T.PLINE_NAME,
			       T.PLAN_SEQ_NO,
			       T.MONITORDEMAND,
			       DECODE(T.IF_MONITOR_JG, '1', '是', '否') IF_MONITOR_JG,
			       T.PRDCR_NO,
			       T.CODE_JG,
			       T.STEELCODE,
			       T.STEELNAME,
			       T.OUTDIAMETER,
			       T.WALLTHICK,
			       T.AIMLENGTH,
			       T.SINGLEWEIGHT,
			       T.SPEC_JG,
			       T.SPEC_JG_DESC,
			       T.MODEL_CODE,
			       T.MODEL_DESC,
			       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = T.STYLE_JG) STYLE_JG,
			       H.BASENAME STYLE_JG_DESC,
			       T.DIAMETER,
			       T.CHECK_J_VAL,
			       T.ALL_CODE_BL,
			       T.CODE_JG_BL,
			       T.BL_WL_ID,
			       T.BL_WL_DESC,
			       T.MIN_D,
			       T.MIN_H,
			       T.BL_MIN_D_OUT,
			       T.BL_MAX_D_IN,
			       T.AIMLENGTH_BL,
			       T.DIAMETER_PL,
			       T.HEIGHT_PL,
			       T.LENGTH_MIN,
			       T.LENGTH_MAX,
			       T.TAPER,
			       T.ALPHA_NAME,
			       A.STD_NAME,
			       A.STD_STYLE_DESC,
			       (SELECT REPLACE(WM_CONCAT(A.STEELCODE_JG_DESC), ',', ';')
			          FROM COM_MSC_JG_R_STEEL N
			         WHERE N.STEELCODE = A.STEELCODE_JG) REP_STEELNAME,
			       A.MIN_D_JG,
			       A.MAX_D_JG,
			       A.PRODUCCODE_JG,
			       C.BASENAME PRODUCCODE_JG_DESC,
			       A.STEELCODE_JG,
			       D.STEELNAME STEELCODE_JG_DESC,
			       A.PRODUCCODE,
			       G.PRODUCNAME,
			       A.DIAMETER_JG,
			       A.LENGTH_JG,
			       A.HEIGHT_JG,
			       A.WEIGHT_JG,
			       A.MIN_H_CP,
			       A.MAX_H_CP,
			       A.MIN_D_CP,
			       A.MAX_D_CP,
			       A.ALPHA,
			       T.PLAN_NUM,
			       T.BL_NUM,
			       T.BL_WEIGHT,
			       T.ZYPLAN_NUM,
			       T.PRODUCED_NUM,
			       T.CUST_ALPHA_NO,
			       T.ORDER_SPECIAL_DESC,
			       T.ALPHA_CODE,
			       DECODE(T.PLANSTATUS,
			              '0',
			              '计划',
			              '1',
			              '下发',
			              '2',
			              '生产中',
			              '3',
			              '生产完成',
			              '4',
			              '取消') 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,
			       NVL(T.MATCHNUM, 0) MATCHNUM,
			       DECODE(T.IFBUYPLAN, '1', '是', '否') IFBUYPLAN,
			       T.BUYPLANID,
			       NVL(T.BUYPLANNUM, 0) BUYPLANNUM,
			       NVL(T.JGWT_BLREQ, 0) JGWT_BLREQ
			  FROM PLN_GX_JG_M T
			  LEFT JOIN COM_MSC_JG A
			    ON T.CODE_JG = A.CODE_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_PRODUCT G
			    ON G.PRODUCCODE = A.PRODUCCODE
			  LEFT JOIN COM_BASE_INFO H
			    ON H.BASECODE = A.STYLE_JG
			 WHERE T.PRO_PLAN_ID LIKE '%' || NLS_UPPER(?) || '%'
			   AND T.PLANSTATUS < '3'
		]]>
	</query>

	<query id="CorePlnJgOrdToDd.queryJgGxProp" desc="查询接箍工序订单明细属性">
		<![CDATA[
			SELECT T.PRO_PLAN_ID,
			       T.JG_GROUP_ID,
			       T.SPEC_JG_DESC,
			       T.CODE_JG_BL,
			       T.STEELCODE,
			       T.STEELNAME,
			       T.GRADECODE,
			       T.GRADENAME,
			       T.MIN_D,
			       T.MIN_H,
			       T.AIMLENGTH_BL,
			       T.AIM_CUT_LEN,
			       T.LENGTH_MIN,
			       T.LENGTH_MAX,
			       T.TAPER,
			       T.MODEL_CODE,
			       T.MODEL_DESC,
			       (SELECT B.BASENAME
			          FROM COM_BASE_INFO B
			         WHERE B.BASECODE = T.DEMAND_DETECTION) DEMAND_DETECTION,
			       (SELECT B.BASENAME
			          FROM COM_BASE_INFO B
			         WHERE B.BASECODE = T.DEMAND_BONDERIZING) DEMAND_BONDERIZING,
			       (SELECT B.BASENAME
			          FROM COM_BASE_INFO B
			         WHERE B.BASECODE = T.DEMAND_COPPER) DEMAND_COPPER,
			       (SELECT B.BASENAME
			          FROM COM_BASE_INFO B
			         WHERE B.BASECODE = T.DEMAND_BLAST) DEMAND_BLAST,
			       T.GROUP_NUM,
			       T.SINGLE_CUT_NUN,
			       T.GROUP_BL_NUM,
			       T.GROUP_BL_WT,
			       T.MATCHNUM_JG,
			       T.MATCHWT_BL,
			       T.MATCHNUM_BL,
			       T.BATCHED_WT,
			       T.BATCHED_NUM,
			       T.PRODUCED_NUM,
			       DECODE(T.GROUP_STATUS,
			              '0',
			              '计划',
			              '1',
			              '下发',
			              '2',
			              '工单制定中',
			              '3',
			              '工单制定完成',
			              '4',
			              '生产中',
			              '5',
			              '生产完成',
			              '6',
			              '取消') GROUP_STATUS
			  FROM PLN_GX_JG_PROP T
			 WHERE T.PRO_PLAN_ID = ?
		]]>
	</query>

	<query id="CorePlnJgOrdToDd.queryGxJgOrd" desc="查询接箍订单下的合同">
		<![CDATA[
			SELECT T.JG_ORDERNO,
			       T.ORDER_NO,
			       T.ORDER_SEQ,
			       T.DELIVERY_NO,
			       T.PRO_PLAN_ID,
			       T.JG_GROUP_ID,
			       T.ORD_LN_DLY_PK,
			       T.BUYER_ID,
			       T.BUYER_NAME,
			       TO_CHAR(T.DELVRY_EDATE, 'YYYY-MM-DD') DELVRY_EDATE,
			       T.ORDERCONTACT,
			       T.PRDCR_NO,
			       DECODE(T.PRDCR_NO, NULL, '否', '是') IF_MONITOR_JG,
			       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,
			       C.BASENAME 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,
			       NVL(M.CUST_ALPHA_NO, '/') CUST_ALPHA_NO,
			       DECODE(M.CUST_ALPHA_NO, NULL, '/', M.ORDER_SPECIAL_DESC) ORDER_SPECIAL_DESC,
			       NVL(M.ALPHA_CODE, '/') ALPHA_CODE,
			       AP.ALPHA_NAME,
			       (SELECT TO_CHAR(WM_CONCAT(PR.STATION_CODE || ',' || PR.PDEPT_NO || ',' ||
			                                 PR.PDEPT_NO2 || ',' || PR.PDEPT_NO3))
			          FROM (SELECT P1.PRDCR_NO,
			                       P1.STATION_CODE,
			                       P1.PDEPT_NO,
			                       P1.PDEPT_NO2,
			                       P1.PDEPT_NO3
			                  FROM SLM_ORDER_LINE_PRDCR_LST P1, SLM_ORDER_LINE_PRDCR P
			                 WHERE P1.PRDCR_NO = P.PRDCR_NO
			                   AND P1.PRDCR_INDEX = P.PRDCR_INDEX
			                   AND P1.PRDCR_PRC_FL = '1'
			                   AND P.CODE_JG IS NOT NULL
			                 ORDER BY P1.STATION_CODE ASC) PR
			         WHERE PR.PRDCR_NO = T.PRDCR_NO) PRD_STATION_DEPT,
			       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 CF
			    ON CF.ORD_LN_PK = T1.ORD_LN_PK
			   AND CF.VALIDFLAG = '1'
			  LEFT JOIN CRAFT_ORD_DESIGN_MSC_JG M
			    ON M.DESGIN_KEY = CF.DESGIN_KEY
			   AND M.KEY_JG = T.KEY_JG
			  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
			  LEFT JOIN COM_BASE_STD_ALPHA AP
			    ON AP.ALPHA_CODE = M.ALPHA_CODE
			 WHERE T.PRO_PLAN_ID = ?
		]]>
	</query>

	<query id="CorePlnJgOrdToDd.getGxJgMOrdNo" desc="获取新的接箍订单号">
		<![CDATA[
			SELECT ('JGDD_' || TO_CHAR(SYSDATE, 'YYYYMMDD') ||
			       LPAD(NVL(MAX(TO_NUMBER(SUBSTR(T.PRO_PLAN_ID, 14)) + 1), '1'),
			             4,
			             '0')) AS PLAN_ID
			  FROM PLN_GX_JG_M T
			 WHERE SUBSTR(T.PRO_PLAN_ID, 6, 8) = TO_CHAR(SYSDATE, 'YYYYMMDD')
		]]>
	</query>

	<query id="CorePlnJgOrdToDd.queryJgOrdDemand" desc="查询接箍合同四项">
		<![CDATA[
			SELECT T.DEMAND_DETECTION,
			       T.DEMAND_BONDERIZING,
			       T.DEMAND_COPPER,
			       T.DEMAND_BLAST
			  FROM PLN_ORDER_JG T
		]]>
	</query>

	<query id="CorePlnJgOrdToDd.queryJgOrdStatus" desc="查询接箍合同">
		<![CDATA[
			SELECT T.PRO_PLAN_ID,
			       T.ORDERNUM,
			       T.CODE_JG,
			       T.JGORDERSTATUS,
			       T.DEMAND_DETECTION,
			       T.DEMAND_BONDERIZING,
			       T.DEMAND_COPPER,
			       T.DEMAND_BLAST,
			       M.CODE_JG_BL
			  FROM PLN_ORDER_JG T
			  LEFT JOIN PLN_GX_JG_M M
			    ON M.PRO_PLAN_ID = T.PRO_PLAN_ID
			 WHERE T.JG_ORDERNO = ?
		]]>
	</query>

	<query id="CorePlnJgOrdToDd.queryJgPrdCr" desc="查询监制">
		<![CDATA[
			SELECT T.PRDCR_NO,
       T.CODE_JG,
       T.CODE_BL,
       (SELECT B.BASENAME
          FROM COM_BASE_INFO B
         WHERE B.BASECODE = T.PRDCR_DESC) PRDCR_DESC
  FROM SLM_ORDER_LINE_PRDCR T, SLM_ORD_DESIGN_MSC_JG T2
 WHERE T.PRDCR_NO = ?
   AND T.CODE_JG = T2.KEY_JG
   AND T2.CODE_JG =?

		]]>
	</query>

	<query id="CorePlnJgOrdToDd.addGxJgM" desc="新增接箍工序订单">
		<![CDATA[
			INSERT INTO PLN_GX_JG_M
				  (PRO_PLAN_ID,
				   PLINE_CODE,
				   PLINE_NAME,
				   PLAN_SEQ_NO,
				   MONITORDEMAND,
				   IF_MONITOR_JG,
				   PRDCR_NO,
				   CODE_JG,
				   STEELCODE,
				   STEELNAME,
				   OUTDIAMETER,
				   WALLTHICK,
				   AIMLENGTH,
				   SINGLEWEIGHT,
				   SPEC_JG,
				   SPEC_JG_DESC,
				   MODEL_CODE,
				   MODEL_DESC,
				   STYLE_JG,
				   DIAMETER,
				   CHECK_J_VAL,
				   ALL_CODE_BL,
				   CODE_JG_BL,
				   BL_WL_ID,
				   BL_WL_DESC,
				   MIN_D,
				   MIN_H,
				   BL_MIN_D_OUT,
				   BL_MAX_D_IN,
				   AIMLENGTH_BL,
				   DIAMETER_PL,
				   HEIGHT_PL,
				   LENGTH_MIN,
				   LENGTH_MAX,
				   TAPER,
				   PLAN_NUM,
				   BL_NUM,
				   BL_WEIGHT,
				   ZYPLAN_NUM,
				   PRODUCED_NUM,
				   PLANSTATUS,
				   CREATE_NAME,
				   CREATE_TIME,
				   CUST_ALPHA_NO,
				   ORDER_SPECIAL_DESC,
				   ALPHA_CODE,
				   ALPHA_NAME)
				  SELECT '#PRO_PLAN_ID#',
				  		 '#PLINE_CODE#',
				  		 '#PLINE_NAME#',
				         NULL,
				         '#MONITORDEMAND#',
				         '#IF_MONITOR_JG#',
				         '#PRDCR_NO#',
				         T.CODE_JG,
				         T.STEELCODE_JG,
				         T.STEELCODE_JG_DESC,
				         T.DIAMETER_JG,
				         T.HEIGHT_JG,
				         T.LENGTH_JG,
				         T.WEIGHT_JG,
				         T.SPEC_JG,
				         T.SPEC_JG_DESC,
				         T.MODEL_CODE,
				         T.MODEL_DESC,
				         T.STYLE_JG,
				         T.DIAMETER,
				         T.CHECK_J_VAL,
				         '#ALL_CODE_BL#',
				         '#CODE_JG_BL#',
				         '#BL_WL_ID#',
				         '#BL_WL_DESC#',
				         T.MIN_D,
				         T.MIN_H,
				         T.MIN_D_CP,
				         T.MAX_D_CP,
				         NULL,
				         T.DIAMETER_PL,
				         T.HEIGHT_PL,
				         T.LENGTH_MIN,
				         T.LENGTH_MAX,
				         T.TAPER,
				         '#PLAN_NUM#',
				         NULL,
				         NULL,
				         '0',
				         '0',
				         '0',
				         '#CREATE_NAME#',
				         SYSDATE,
				         '#CUST_ALPHA_NO#',
				         '#ORDER_SPECIAL_DESC#',
				         '#ALPHA_CODE#',
				         '#ALPHA_NAME#'
				    FROM COM_MSC_JG T
				   WHERE T.CODE_JG = '#CODE_JG#'
		]]>
	</query>

	<query id="CorePlnJgOrdToDd.addGxJgProp" desc="新增接箍工序订单属性">
		<![CDATA[
			INSERT INTO PLN_GX_JG_PROP
				  (PRO_PLAN_ID,
				   JG_GROUP_ID,
				   SPEC_JG_DESC,
				   CODE_JG_BL,
				   STEELCODE,
				   STEELNAME,
				   GRADECODE,
				   GRADENAME,
				   MIN_D,
				   MIN_H,
				   AIMLENGTH_BL,
				   AIM_CUT_LEN,
				   LENGTH_MIN,
				   LENGTH_MAX,
				   TAPER,
				   MODEL_CODE,
				   MODEL_DESC,
				   DEMAND_DETECTION,
				   DEMAND_BONDERIZING,
				   DEMAND_COPPER,
				   DEMAND_BLAST,
				   GROUP_NUM,
				   SINGLE_CUT_NUN,
				   GROUP_BL_NUM,
				   GROUP_BL_WT,
				   PRODUCED_NUM,
				   GROUP_STATUS)
				  SELECT '#PRO_PLAN_ID#',
				         '#JG_GROUP_ID#',
				         T.SPEC_JG_DESC,
				         '#CODE_JG_BL#',
				         T.STEELCODE_JG,
				         T.STEELCODE_JG_DESC,
				         '#GRADECODE#',
				         '#GRADENAME#',
				         T.MIN_D,
				         T.MIN_H,
				         '#AIMLENGTH_BL#',
				         T.LENGTH_JG,
				         T.LENGTH_MIN,
				         T.LENGTH_MAX,
				         T.TAPER,
				         T.MODEL_CODE,
				         T.MODEL_DESC,
				         '#DEMAND_DETECTION#',
				         '#DEMAND_BONDERIZING#',
				         '#DEMAND_COPPER#',
				         '#DEMAND_BLAST#',
				         '#GROUP_NUM#',
				         '#SINGLE_CUT_NUN#',
				         '#GROUP_BL_NUM#',
				         '#GROUP_BL_WT#',
				         '0',
				         '0'
				    FROM COM_MSC_JG T
				   WHERE T.CODE_JG = ?
		]]>
	</query>

	<query id="CorePlnJgOrdToDd.updatePlnJgOrd" desc="更新接箍合同状态，回写订单号">
		 <![CDATA[
		 	UPDATE PLN_ORDER_JG T
			   SET T.PRO_PLAN_ID = ?, T.JGORDERSTATUS = ?, T.JG_GROUP_ID = ?
			 WHERE T.JG_ORDERNO = ?
		 ]]>
	</query>

	<query id="CorePlnJgOrdToDd.selectJgOrdPropdeal" desc="查询接箍合同适合的订单属性">
		 <![CDATA[
		 	SELECT T1.JG_GROUP_ID,
			       T1.CODE_JG_BL,
			       T1.GROUP_NUM,
			       T1.GROUP_BL_NUM,
			       T1.GROUP_BL_WT
			  FROM PLN_ORDER_JG T, PLN_GX_JG_PROP T1
			 WHERE (T.DEMAND_DETECTION = T1.DEMAND_DETECTION OR
			       (T.DEMAND_DETECTION IS NULL AND T1.DEMAND_DETECTION IS NULL))
			   AND (T.DEMAND_BONDERIZING = T1.DEMAND_BONDERIZING OR
			       (T.DEMAND_BONDERIZING IS NULL AND T1.DEMAND_BONDERIZING IS NULL))
			   AND (T.DEMAND_COPPER = T1.DEMAND_COPPER OR
			       (T.DEMAND_COPPER IS NULL AND T1.DEMAND_COPPER IS NULL))
			   AND (T.DEMAND_BLAST = T1.DEMAND_BLAST OR
			       (T.DEMAND_BLAST IS NULL AND T1.DEMAND_BLAST IS NULL))
			   AND T.JG_ORDERNO = ?
			   AND T1.PRO_PLAN_ID = ?
		 ]]>
	</query>

	<query id="CorePlnJgOrdToDd.updateGxJgMNum" desc="更新接箍订单接箍个数">
		 <![CDATA[
		 	UPDATE PLN_GX_JG_M T
			   SET T.PLAN_NUM = T.PLAN_NUM + ?
			 WHERE T.PRO_PLAN_ID = ?
		 ]]>
	</query>

	<query id="CorePlnJgOrdToDd.updateGxJgPropNum" desc="更新接箍订单属性分组接箍个数">
		 <![CDATA[
		 	UPDATE PLN_GX_JG_PROP T
			   SET T.GROUP_NUM = T.GROUP_NUM + ?,
			   	   T.GROUP_BL_NUM = T.GROUP_BL_NUM + ?,
			   	   T.GROUP_BL_WT  = T.GROUP_BL_WT + ?
			 WHERE T.PRO_PLAN_ID = ?
			   AND T.JG_GROUP_ID = ?
		 ]]>
	</query>

	<query id="CorePlnJgOrdToDd.getGxJgPropId" desc="生产加工订单分组组号">
		 <![CDATA[
		 	SELECT LPAD(NVL((MAX(TO_NUMBER(T.JG_GROUP_ID)) + 1), 1), 2, '0') GROUP_ID
			  FROM PLN_GX_JG_PROP T
			 WHERE T.PRO_PLAN_ID = ?
		 ]]>
	</query>

	<query id="CorePlnJgOrdToDd.deleteGxJgM" desc="删除生产订单">
		<![CDATA[
			DELETE FROM PLN_GX_JG_M T WHERE T.PRO_PLAN_ID = ?
		]]>
	</query>
	<query id="CorePlnJgOrdToDd.deleteGxJgC" desc="删除生产订单从表">
		<![CDATA[
			DELETE FROM PLN_GX_JG_C T WHERE T.PRO_PLAN_ID = ?
		]]>
	</query>
	<query id="CorePlnJgOrdToDd.deleteGxJgPropByDd" desc="删除生产订单属性分组">
		<![CDATA[
			DELETE FROM PLN_GX_JG_PROP T WHERE T.PRO_PLAN_ID = ?
		]]>
	</query>

	<query id="CorePlnJgOrdToDd.deleteGxJgProp" desc="删除生产订单属性分组">
		<![CDATA[
			DELETE FROM PLN_GX_JG_PROP T WHERE T.PRO_PLAN_ID = ? AND T.JG_GROUP_ID = ?
		]]>
	</query>

	<query id="CorePlnJgOrdToDd.selectGxJgOrd" desc="查询订单接箍明细">
		<![CDATA[
			SELECT T.ORDERNUM,
			       T.JG_GROUP_ID,
			       T.PRO_PLAN_ID,
			       T.JGORDERSTATUS,
			       P.CODE_JG_BL,
			       P.GROUP_NUM,
			       P.GROUP_BL_NUM,
			       P.GROUP_BL_WT
			  FROM PLN_ORDER_JG T
			  LEFT JOIN PLN_GX_JG_PROP P
			    ON P.PRO_PLAN_ID = T.PRO_PLAN_ID
			   AND P.JG_GROUP_ID = T.JG_GROUP_ID
			 WHERE T.JG_ORDERNO = ?
		]]>
	</query>

	<query id="CorePlnJgOrdToDd.selectGxJgProp" desc="查询订单分组">
		<![CDATA[
			SELECT T.GROUP_NUM, T1.PLAN_NUM, T1.PLANSTATUS
			  FROM PLN_GX_JG_PROP T, PLN_GX_JG_M T1
			 WHERE T1.PRO_PLAN_ID = T.PRO_PLAN_ID
			   AND T.PRO_PLAN_ID = ?
			   AND T.JG_GROUP_ID = ?
		]]>
	</query>



	<query id="CorePlnJgOrdToDd.selectPrdStation" desc="查询监制工序点单位">
		<![CDATA[
			SELECT P1.PRDCR_NO,
			       P.CODE_JG,
			       P.CODE_BL,
			       P1.STATION_CODE,
			       P1.PDEPT_NO,
			       P1.PDEPT_NO2,
			       P1.PDEPT_NO3
			  FROM SLM_ORDER_LINE_PRDCR_LST P1, SLM_ORDER_LINE_PRDCR P
			 WHERE P1.PRDCR_NO = P.PRDCR_NO
			   AND P1.PRDCR_INDEX = P.PRDCR_INDEX
			   AND P1.PRDCR_PRC_FL = '1'
			   AND P.CODE_JG IS NOT NULL
			   AND P.PRDCR_NO = ?
			 ORDER BY P1.STATION_CODE ASC
		]]>
	</query>


	<query id="CorePlnJgOrdToDd.queryMatJg" desc="查询监制工序点单位">
		<![CDATA[
			SELECT T1.KEP_NO,
			       T1.MAT_NO,
			       T1.JUDGE_STOVE_NO,
			       T1.BATCH_NO,
			       T1.RESULT_NO,
			       T1.ZY_PLAN_ID,
			       T1.PRO_PLAN_ID,
			       T1.STORAGE_NO,
			       T1.LOCATION_NO,
			       T1.STORAGE_ATTR,
			       T1.STORAGE_ATTR_NAME,
			       T1.STORAGE_TYPE_NO,
			       T1.STORAGE_TYPE_NAME,
			       T1.MANAGEMENT_NO,
			       T1.MANAGEMENT_NAME,
			       T.PLINE_CODE,
			       T.PLINE_NAME,
			       T.CODE_JG,
			       T.GRADECODE,
			       T.GRADENAME,
			       T.STEELCODE,
			       T.STEELNAME,
			       T.MODEL_CODE,
			       T.MODEL_DESC,
			       T.OUTDIAMETER,
			       T.WALLTHICK,
			       T.SPEC_JG,
			       T.SPEC_JG_DESC,
			       T.STYLE_JG,
			       T.DIAMETER,
			       T.CHECK_J_VAL,
			       T.AIMLENGTH,
			       T.SINGLEWEIGHT,
			       T.MACH_NO,
			       T.MACH_NM,
			       T.PRO_NUM,
			       T.PRO_WT,
			       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,
			       T.CUST_ALPHA_NO,
			       T.ORDER_SPECIAL_DESC,
			       T.ALPHA_CODE,
			       A.ALPHA_NAME,
			       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
			  FROM COUPLING_MAT_M T
			  LEFT JOIN COM_BASE_STD_ALPHA A
			    ON A.ALPHA_CODE = T.ALPHA_CODE, COUPLING_MAT_BUTTRESS T1
			 WHERE T1.MAT_NO = T.MAT_NO
			   AND T.CODE_JG = ?
			   AND T.CUST_ALPHA_NO = ?
			   AND T.ALPHA_CODE = ?
		]]>
	</query>

	<query id="CorePlnJgOrdToDd.selectJgRBl" desc="查询接箍对应备料">
		<![CDATA[
SELECT V.PSC_BL
  FROM CRAFT_ORD_DESIGN_MSC_JG_BL V
 WHERE V.DESGIN_KEY =
       (SELECT Z.DESGIN_KEY
          FROM CRAFT_ORD_DESIGN Z
         WHERE Z.ORD_LN_PK =
               (SELECT SUBSTR(T.ORD_LN_DLY_PK, 1, 35)
                  FROM PLN_ORDER_JG T
                 WHERE T.JG_ORDERNO =?)
           AND Z.CRAFT_SEQ =
               (SELECT MAX(X.CRAFT_SEQ)
                  FROM PLN_SALEORD_PROC X
                 WHERE X.PLANSTATUS = '1'
                   AND X.ORD_LN_DLY_PK =
                       (SELECT T.ORD_LN_DLY_PK
                          FROM PLN_ORDER_JG T
                         WHERE T.JG_ORDERNO = ?)))
   AND V.CODE_JG =
       (SELECT T.KEY_JG
          FROM PLN_ORDER_JG T
         WHERE T.JG_ORDERNO = ?)

		]]>
	</query>

	<query id="CorePlnJgOrdToDd.selectJgMaterialPl" desc="查询接箍投入产出产线能力">
		<![CDATA[
		SELECT T.PLINE_CODE,
       T.PLINE_NAME,
       T.IN_MATERIAL_NO,
       T.IN_MATERIAL_DESC,
       T.OUT_MATERIAL_NO,
       T.OUT_MATERIAL_DESC,
       NVL(T.WASTE_RATE, 0) WASTE_RATE
  FROM SLM_BASE_MATERIAL_H_PL T
 WHERE (T.DISABLE_FL != '1' OR T.DISABLE_FL IS NULL)
   AND T.IN_MATERIAL_NO = (SELECT T2.MATERIAL_NO
                             FROM CRAFT_ORD_DESIGN   TD,
                                  CRAFT_ORD_LINE_BOM T1,
                                  SLM_ORD_DESIGN_BOM T2
                            WHERE TD.DESGIN_KEY = T1.DESGIN_KEY
                              AND T1.BOM = T2.BOM
                              AND TD.ORD_LN_PK = ?
                              and td.VALIDFLAG<>'0'
                            GROUP BY T2.MATERIAL_NO)
   AND T.OUT_MATERIAL_NO = ?
		]]>
	</query>

	<query id="CorePlnJgOrdToDd.selectComMscJg" desc="查询接箍基础表">
		<![CDATA[
			SELECT T.LENGTH_JG FROM COM_MSC_JG T WHERE T.CODE_JG = ?
		]]>
	</query>

	<query id="CorePlnJgOrdToDd.selectComMscBl" desc="查询备料码基础表">
		<![CDATA[
			SELECT T.MIN_L,
			       T.MAX_L,
			       ((T.MIN_L + T.MAX_L) * 1000 / 2) AIM_LEN,
			       T.MIN_D,
			       T.MIN_H
			  FROM COM_MSC_BL T
			 WHERE T.PSC_BL = ?
		]]>
	</query>
	<query id="CorePlnJgOrdToDd.addGxJgC" desc="新增接箍订单从表">
		<![CDATA[
		insert INTO PLN_GX_JG_C(PRO_PLAN_ID, CODE_JG_BL, CREATE_NAME, CREATE_TIME) VALUES(?, ?, '#CREATE_NAME#', SYSDATE)
		]]>
	</query>
	<query id="CorePlnJgOrdToDd.queryJgGxMInfo" desc="查询接箍工序订单记录">
		<![CDATA[
			SELECT T.PRO_PLAN_ID,t.PLANSTATUS,nvl(MATCHNUM,0) MATCHNUM,nvl(BUYPLANNUM,0) BUYPLANNUM,nvl(JGWT_BLREQ,0) JGWT_BLREQ FROM PLN_GX_JG_M T WHERE T.PRO_PLAN_ID = ?
		]]>
	</query>


	<query id="CorePlnJgOrdToDd.addPlnGxJGProps" desc="新增接箍排产订单">
		<![CDATA[
          INSERT INTO PLN_GX_JG_PROP_S
  (PRO_PLAN_ID,
   JG_GROUP_ID,
   GX_PLAN_NO,
   PLINE_CODE,
   PLINE_NAME,
   GX_PRO_SEQ,
   CODE_JG,
   SPEC_JG_DESC,
   CODE_JG_BL,
   STEELCODE,
   STEELNAME,
   GRADECODE,
   GRADENAME,
   BL_WL_ID,
   BL_WL_DESC,
   MIN_D,
   MIN_H,
   AIMLENGTH_BL,
   AIM_CUT_LEN,
   LENGTH_MIN,
   LENGTH_MAX,
   TAPER,
   MODEL_CODE,
   MODEL_DESC,
   DEMAND_DETECTION,
   DEMAND_BONDERIZING,
   DEMAND_COPPER,
   DEMAND_BLAST,
   GROUP_NUM_S,
   SINGLE_CUT_NUN,
   GROUP_BL_NUM_S,
   GROUP_BL_WT_S,
   IS_PLAN_OK,
   MATCHNUM_JG,
   PRO_MONTH,
   PLAN_USETIME,
   PLAN_TIME_B,
   PLAN_TIME_E,
   MATCHWT_BL,
   MATCHNUM_BL,
   BATCHED_WT,
   BATCHED_NUM,
   BATCHED_NUM_OUT,
   REAL_BATCHED_WT,
   REAL_BATCHED_NUM,
   PRODUCED_NUM,
   EXE_STATUS,
   IS_REPAIR_PLN,
   REPAIR_TYPE,
   IS_STOVE_ISSUED,
   ISSUED_TIME,
   ISSUED_MAN,
   LAST_UNDOWN_TIME,
   LAST_UNDOWN_MAN,
   PROCESSING_COST,
   TOTAL_COST,
   IF_MONITOR_JG,
   PRDCR_NO,
   CREATE_TIME,
   IF_STOVE_ISSUED,
   STOVE_ISSUED_TIME,
   STOVE_ISSUED_MAN)
VALUES
  ('#PRO_PLAN_ID#',
   '#JG_GROUP_ID#',
   '#GX_PLAN_NO#',
   '#PLINE_CODE#',
   '#PLINE_NAME#',
   '#GX_PRO_SEQ#',
   '#CODE_JG#',
   '#SPEC_JG_DESC#',
   '#CODE_JG_BL#',
   '#STEELCODE#',
   '#STEELNAME#',
   '#GRADECODE#',
   '#GRADENAME#',
   '#BL_WL_ID#',
   '#BL_WL_DESC#',
   '#MIN_D#',
   '#MIN_H#',
   '#AIMLENGTH_BL#',
   '#AIM_CUT_LEN#',
   '#LENGTH_MIN#',
   '#LENGTH_MAX#',
   '#TAPER#',
   '#MODEL_CODE#',
   '#MODEL_DESC#',
   '#DEMAND_DETECTION#',
   '#DEMAND_BONDERIZING#',
   '#DEMAND_COPPER#',
   '#DEMAND_BLAST#',
   '#GROUP_NUM_S#',
   '#SINGLE_CUT_NUN#',
   '#GROUP_BL_NUM_S#',
   '#GROUP_BL_WT_S#',
   '#IS_PLAN_OK#',
   '#MATCHNUM_JG#',
   '#PRO_MONTH#',
   '#PLAN_USETIME#',
   TO_DATE('#PLAN_TIME_B#', 'YYYY-MM-DD HH24:MI:SS'),
   TO_DATE('#PLAN_TIME_E#', 'YYYY-MM-DD HH24:MI:SS'),
   '#MATCHWT_BL#',
   '#MATCHNUM_BL#',
   '#BATCHED_WT#',
   '#BATCHED_NUM#',
   '#BATCHED_NUM_OUT#',
   '#REAL_BATCHED_WT#',
   '#REAL_BATCHED_NUM#',
   '#PRODUCED_NUM#',
   '#EXE_STATUS#',
   '#IS_REPAIR_PLN#',
   '#REPAIR_TYPE#',
   '#IS_STOVE_ISSUED#',
   NULL,
   '#ISSUED_MAN#',
   NULL,
   '#LAST_UNDOWN_MAN#',
   '#PROCESSING_COST#',
   '#TOTAL_COST#',
   '#IF_MONITOR_JG#',
   '#PRDCR_NO#',
   SYSDATE,
   '#IF_STOVE_ISSUED#',
   NULL,
   '#STOVE_ISSUED_MAN#')
		]]>
	</query>

</queryMap>