<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="工序合同 处理">
	<query id="CorePrcOrder.queryBLbyReqBlId" desc="通过备料需求编号查询备料需求">
		<![CDATA[
			SELECT * FROM PLN_PORDER_BL_REQ T WHERE T.REQ_BL_ID = ?
		]]>
	</query>
	
	<query id="CorePrcOrder.querySaleStatus" desc="查询销售合同状态">
		<![CDATA[
			SELECT *
			  FROM PLN_SALEORDER T
			 WHERE T.ORD_LN_DLY_PK = ?
		]]>
	</query>
	
	<query id="CorePrcOrder.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,
			       CIC,
			       PIC,
			       SIC,
			       DIC,
			       WIC,
			       GIC
			  FROM SLM_ORD_DESIGN_MSC_PL_PRC T
			 WHERE T.DESGIN_KEY = ?
			   AND T.MSC_PLINE = ?
			 ORDER BY T.BACKLOG_SEQ ASC
		]]>
	</query>
	
	<query id="CorePrcOrder.queryOrderPrdcr" desc="查询合同信息_合同行_监制明细">
		<![CDATA[
			SELECT *
			  FROM SLM_ORDER_LINE_PRDCR_LST T
			 WHERE T.PRDCR_NO = ?
			 WHERE T.PRDCR_PRC_FL = '1'
		]]>
	</query>

	<query id="CorePrcOrder.querySaleOrderBom" desc="查询销售合同可选BOM">
		<![CDATA[
			SELECT T1.DESGIN_KEY, T.*,
               (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
		     FROM SLM_ORD_DESIGN_BOM T,
		          (SELECT * FROM SLM_ORD_LINE_BOM A WHERE A.DESGIN_KEY = ?) T1
		    WHERE T.BOM = T1.BOM
		      AND T.MSC_PLINE = ?
		      AND T.MATERIAL_NO = ?
		]]>
	</query>
	
	<query id="CorePrcOrder.getDesignBomInf" desc="查询bom主表">
			<![CDATA[
				SELECT T.MATERIAL_NO,
				       T.MATERIAL_DESC,
				       T.BOM,
				       T.BOM_TYP,
				       T.MSC_PLINE,
				       T.WHOLE_BACKLOG,
				       T.WHOLE_BACKLOG_DESC,
				       T.MSC,
				       T.MSC_DESC,
				       T.GRADECODE,
				       T.GRADENAME,
				       T.SPEC_CODE_C,
				       T.SPEC_NAME_C,
				       T.SPEC_CODE_R,
				       T.SPEC_NAME_R,
				       T.SPEC_CODE_D,
				       T.SPEC_NAME_D,
				       T.SPEC_CODE_Z,
				       T.SPEC_NAME_Z,
				       T.A_IN_MATERIAL_NO,
				       T.A_IN_MATERIAL_DESC,
				       T.A_OUT_MATERIAL_NO,
				       T.A_OUT_MATERIAL_DESC,
				       T.B_IN_MATERIAL_NO,
				       T.B_IN_MATERIAL_DESC,
				       T.B_OUT_MATERIAL_NO,
				       T.B_OUT_MATERIAL_DESC,
				       T.C_IN_MATERIAL_NO,
				       T.C_IN_MATERIAL_DESC,
				       T.C_OUT_MATERIAL_NO,
				       T.C_OUT_MATERIAL_DESC,
				       T.D_IN_MATERIAL_NO,
				       T.D_IN_MATERIAL_DESC,
				       T.D_OUT_MATERIAL_NO,
				       T.D_OUT_MATERIAL_DESC,
				       T.E_IN_MATERIAL_NO,
				       T.E_IN_MATERIAL_DESC,
				       T.E_OUT_MATERIAL_NO,
				       T.E_OUT_MATERIAL_DESC,
				       T.F_IN_MATERIAL_NO,
				       T.F_IN_MATERIAL_DESC,
				       T.F_OUT_MATERIAL_NO,
				       T.F_OUT_MATERIAL_DESC,
				       T.J_IN_MATERIAL_NO,
				       T.J_IN_MATERIAL_DESC,
				       T.J_OUT_MATERIAL_NO,
				       T.J_OUT_MATERIAL_DESC,
			       (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
				  FROM SLM_ORD_DESIGN_BOM T
				 WHERE T.BOM = ?
			]]>
		</query>
	
	<query id="CorePrcOrder.queryZgGetrate" desc="查询扎管成材率">
		<![CDATA[
			SELECT * FROM SLM_BASE_MATERIAL_D_PL T WHERE 
			T.IN_MATERIAL_NO=? AND T.OUT_MATERIAL_NO=? ORDER BY T.PRD_RATE DESC
		]]>
	</query>
	
	<query id="CorePrcOrder.queryBjGetrate" desc="查询镦拔阔成材率">
		<![CDATA[
			SELECT * FROM SLM_BASE_MATERIAL_E_PL T WHERE 
			T.IN_MATERIAL_NO=? AND T.OUT_MATERIAL_NO=? ORDER BY T.PRD_RATE DESC
		]]>
	</query>
	
	<query id="CorePrcOrder.queryRclGetrate" desc="查询热处理成材率">
		<![CDATA[
			SELECT * FROM SLM_BASE_MATERIAL_F_PL T WHERE 
			T.IN_MATERIAL_NO=? AND T.OUT_MATERIAL_NO=? ORDER BY T.PRD_RATE DESC
		]]>
	</query>
	
	<query id="CorePrcOrder.queryJgxGetrate" desc="查询加工线成材率">
		<![CDATA[
			SELECT * FROM SLM_BASE_MATERIAL_I_PL T WHERE 
			T.IN_MATERIAL_NO=? AND T.OUT_MATERIAL_NO=? ORDER BY T.PRD_RATE DESC
		]]>
	</query>
	
	<query id="CorePrcOrder.addSlaeZgPrc" desc="新建合同下发的轧管合同">
		<![CDATA[
			INSERT INTO PLN_ORDER_ZG
				  (PRO_ORDER_NO,
				   ORDER_SOURCE,
				   ORDER_NO,
				   ORDER_SEQ,
				   DELIVERY_NO,
				   REQ_BL_ID,
				   PROCESS_SEQ,
				   STEELCODE,
				   STEELNAME,
				   OUTDIAMETER,
				   WALLTHICK,
				   LENGTHMAX,
				   LENGTHMIN,
				   OUTWL_ID,
				   INWL_GP,
				   GETRATE,
				   ORDERWEIGHT,
				   ORDERNUM,
				   PROD_END_DATE,
				   ORDERSTATUS,
				   INDEX_SEQ,
				   ISENDGX,
				   NEXT_GX,
				   IF_MONITOR_ZG,
				   PRDCR_NO,
				   CREATE_NAME,
				   CREATE_TIME)
				VALUES
				  ((SELECT ('ZG_' || TO_CHAR(SYSDATE, 'YY') || TO_CHAR(SYSDATE, 'MM') ||
				       TO_CHAR(SYSDATE, 'DD') || LPAD(DECODE(MAX(SUBSTR(T.PRO_ORDER_NO, 10) + 1),
				                                              '',
				                                              '000001',
				                                              MAX(SUBSTR(T.PRO_ORDER_NO, 10) + 1)),
				                                       6,
				                                       '0')) PRO_ORDER_NO
				  FROM PLN_ORDER_ZG T),
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   TO_DATE(?, 'YYYY/MM/DD'),
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   SYSDATE)
		]]>
	</query>
	
	<query id="CorePrcOrder.DelSaleProZg" desc="删除销售扎管工序合同">
		<![CDATA[
			DELETE FROM PLN_ORDER_ZG T WHERE 
			T.ORDER_SOURCE='销售合同' AND T.ORDER_NO=? AND T.ORDER_SEQ=? AND T.DELIVERY_NO=?
		]]>
	</query>
	
	<query id="CorePrcOrder.DelBlProZg" desc="删除备料扎管工序合同">
		<![CDATA[
			DELETE FROM PLN_ORDER_ZG T WHERE 
			T.ORDER_SOURCE='备料需求' AND T.REQ_BL_ID=?
		]]>
	</query>
	
	<query id="CorePrcOrder.addSlaeBjPrc" desc="新建合同下发的镦拔扩合同">
		<![CDATA[
			INSERT INTO PLN_ORDER_BJ
				  (PRO_ORDER_NO,
				   ORDER_SOURCE,
				   ORDER_NO,
				   ORDER_SEQ,
				   DELIVERY_NO,
				   REQ_BL_ID,
				   PROCESS_SEQ,
				   STEELCODE,
				   STEELNAME,
				   OUTDIAMETER,
				   WALLTHICK,
				   LENGTHMAX,
				   LENGTHMIN,
				   OUTWL_ID,
				   INWL_ID,
				   OUTDIAMETER_IN,
				   WALLTHICK_IN,
				   GETRATE,
				   ORDERWEIGHT,
				   ORDERNUM,
				   PROD_END_DATE,
				   ORDERSTATUS,
				   INDEX_SEQ,
				   ISBEGINGX,
				   PREVIOUS_GX,
				   ISENDGX,
				   NEXT_GX,
				   IF_MONITOR_BJ,
				   PRDCR_NO,
				   CREATE_NAME,
				   CREATE_TIME)
				VALUES
				  ((SELECT ('BJ_' || TO_CHAR(SYSDATE, 'YY') || TO_CHAR(SYSDATE, 'MM') ||
								       TO_CHAR(SYSDATE, 'DD') || LPAD(DECODE(MAX(SUBSTR(T.PRO_ORDER_NO, 10) + 1),
								                                              '',
								                                              '000001',
								                                              MAX(SUBSTR(T.PRO_ORDER_NO, 10) + 1)),
								                                       6,
								                                       '0')) PRO_ORDER_NO
								  FROM PLN_ORDER_BJ T),
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   TO_DATE(?,'YYYY-MM-DD'),
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   SYSDATE)
		]]>
	</query>
	
	<query id="CorePrcOrder.DelSaleProBj" desc="删除销售变径工序合同">
		<![CDATA[
			DELETE FROM PLN_ORDER_BJ T WHERE 
			T.ORDER_SOURCE='销售合同' AND T.ORDER_NO=? AND T.ORDER_SEQ=? AND T.DELIVERY_NO=?
		]]>
	</query>
	
	<query id="CorePrcOrder.DelBlProBj" desc="删除备料变径工序合同">
		<![CDATA[
			DELETE FROM PLN_ORDER_BJ T WHERE 
			T.ORDER_SOURCE='备料需求' AND T.REQ_BL_ID=?
		]]>
	</query>
	
	<query id="CorePrcOrder.addSlaeRclPrc" desc="新建合同下发的热处理合同">
		<![CDATA[
			INSERT INTO PLN_ORDER_RCL
				  (PRO_ORDER_NO,
				   ORDER_SOURCE,
				   ORDER_NO,
				   ORDER_SEQ,
				   DELIVERY_NO,
				   REQ_BL_ID,
				   PROCESS_SEQ,
				   STEELCODE,
				   STEELNAME,
				   OUTDIAMETER,
				   WALLTHICK,
				   LENGTHMAX,
				   LENGTHMIN,
				   GETRATE,
				   INWL_ID,
				   OUTWL_ID,
				   ORDERWEIGHT,
				   ORDERNUM,
				   PROD_END_DATE,
				   ORDERSTATUS,
				   INDEX_SEQ,
				   ISBEGINGX,
				   PREVIOUS_GX,
				   ISENDGX,
				   NEXT_GX,
				   IF_MONITOR_RCL,
				   PRDCR_NO,
				   CREATE_NAME,
				   CREATE_TIME)
				VALUES
				  ((SELECT ('RCL_' || TO_CHAR(SYSDATE, 'YY') || TO_CHAR(SYSDATE, 'MM') ||
								       TO_CHAR(SYSDATE, 'DD') || LPAD(DECODE(MAX(SUBSTR(T.PRO_ORDER_NO, 11) + 1),
								                                              '',
								                                              '000001',
								                                              MAX(SUBSTR(T.PRO_ORDER_NO, 11) + 1)),
								                                       6,
								                                       '0')) PRO_ORDER_NO
								  FROM PLN_ORDER_RCL T),
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   TO_DATE(?,'YYYY-MM-DD'),
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   SYSDATE)
		]]>
	</query>
	
	<query id="CorePrcOrder.DelSaleProRcl" desc="删除销售热处理工序合同">
		<![CDATA[
			DELETE FROM PLN_ORDER_RCL T WHERE 
			T.ORDER_SOURCE='销售合同' AND T.ORDER_NO=? AND T.ORDER_SEQ=? AND T.DELIVERY_NO=?
		]]>
	</query>
	
	<query id="CorePrcOrder.DelBlProRcl" desc="删除备料热处理工序合同">
		<![CDATA[
			DELETE FROM PLN_ORDER_RCL T WHERE 
			T.ORDER_SOURCE='备料需求' AND T.REQ_BL_ID=?
		]]>
	</query>
	
	<query id="CorePrcOrder.addSlaeJgxPrc" desc="新建合同下发的管加工合同">
		<![CDATA[
			INSERT INTO PLN_ORDER_JGX
				  (PRO_ORDER_NO,
				   ORDER_SOURCE,
				   ORDER_NO,
				   ORDER_SEQ,
				   DELIVERY_NO,
				   PROCESS_SEQ,
				   STEELCODE,
				   STEELNAME,
				   OUTDIAMETER,
				   WALLTHICK,
				   LENGTHMAX,
				   LENGTHMIN,
				   LENGTHDISC,
				   MODEL_CODE,
				   GETRATE,
				   INWL_ID,
				   OUTWL_ID,
				   ORDERWEIGHT,
				   ORDERNUM,
				   PROD_END_DATE,
				   ORDERSTATUS,
				   INDEX_SEQ,
				   ISBEGINGX,
				   PREVIOUS_GX,
				   ISENDGX,
				   NEXT_GX,
				   IF_MONITOR_JGX,
				   PRDCR_NO,
				   CREATE_NAME,
				   CREATE_TIME)
				VALUES
				  ((SELECT ('JGX_' || TO_CHAR(SYSDATE, 'YY') || TO_CHAR(SYSDATE, 'MM') ||
								       TO_CHAR(SYSDATE, 'DD') || LPAD(DECODE(MAX(SUBSTR(T.PRO_ORDER_NO, 11) + 1),
								                                              '',
								                                              '000001',
								                                              MAX(SUBSTR(T.PRO_ORDER_NO, 11) + 1)),
								                                       6,
								                                       '0')) PRO_ORDER_NO
								  FROM PLN_ORDER_JGX T),
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   TO_DATE(?,'YYYY-MM-DD'),
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   SYSDATE)
		]]>
	</query>
	
	<query id="CorePrcOrder.DelSaleProJgx" desc="删除销售加工线工序合同">
		<![CDATA[
			DELETE FROM PLN_ORDER_JGX T WHERE 
			T.ORDER_SOURCE='销售合同' AND T.ORDER_NO=? AND T.ORDER_SEQ=? AND T.DELIVERY_NO=?
		]]>
	</query>
	
	<query id="CorePrcOrder.DelBlProJgx" desc="删除备料加工线工序合同">
		<![CDATA[
			DELETE FROM PLN_ORDER_JGX T WHERE 
			T.ORDER_SOURCE='备料需求' AND T.REQ_BL_ID=?
		]]>
	</query>
	
	<query id="CorePrcOrder.addSlaeGpPrc" desc="合同下发管坯需求">
		<![CDATA[
			INSERT INTO PLN_REQINF_GP
				  (GPREQ_ID,
				   ISENDGX,
				   ORDER_SOURCE,
				   ORDER_NO,
				   ORDER_SEQ,
				   DELIVERY_NO,
				   BUYER_ID,
				   BUYER_NAME,
				   PSC,
				   MSC,
				   STEELCODE,
				   STEELNAME,
				   GRADECODE,
				   DIAMETER_GP,
				   LENGTH_GP,
				   MATERIAL_NO,
				   MATERIAL_NAME,
				   IF_MONITOR_LG,
				   PRDCR_NO,
				   WEIGHT_GP_ONE,
				   GP_WEIGHT,
				   GP_NUM,
				   REQ_DONESTATUS)
				VALUES
				  ((SELECT ('GP_' || TO_CHAR(SYSDATE, 'YY') || TO_CHAR(SYSDATE, 'MM') ||
				          TO_CHAR(SYSDATE, 'DD') || LPAD(DECODE(MAX(SUBSTR(T.GPREQ_ID, 10) + 1),
				                                                 '',
				                                                 '000001',
				                                                 MAX(SUBSTR(T.GPREQ_ID, 10) + 1)),
				                                          6,
				                                          '0')) GPREQ_ID
				     FROM PLN_REQINF_GP T),
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?,
				   ?)
		]]>
	</query>
	
	<query id="CorePrcOrder.DelSaleGpReq" desc="删除销售合同形成的管坯需求">
		<![CDATA[
			DELETE FROM PLN_REQINF_GP T WHERE 
			T.ORDER_SOURCE='销售合同' AND T.ORDER_NO=? AND T.ORDER_SEQ=? AND T.DELIVERY_NO=?
		]]>
	</query>
</queryMap>