<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="热处理工序合同">
	
	<query id="CorePlnProcOrdRcl.queryPlnRclOrd" desc="查询产线基础信息">
		<![CDATA[
			SELECT T.PRO_ORDER_NO,
			       T3.GX_PLAN_NO,
			       T.PLAN_GROUP_ID,
			       T.ORDER_SOURCE,
			       T1.ORD_LN_PK,
			       T2.CRAFT_SEQ,
			       T.ORD_LN_DLY_PK,
			       T.PLN_DIVIDE_ID,
			       T.ORDER_NO,
			       T.ORDER_SEQ,
			       (T1.ORDER_NO || '/' || T1.ORDER_SEQ) ORDER_NO_SEQ,
			       T.DELIVERY_NO,
			       T.REQ_BL_ID,
			       T.INDEX_SEQ,
			       T.BOM,
			       T.BACKLOG_SEQ,
			       T.STEELCODE,
			       T.STEELNAME,
			       T.OUTDIAMETER,
			       T.WALLTHICK,
			       T.AIMWALLTHICK,
			       T.LENGTHMAX,
			       T.LENGTHMIN,
			       T.AIMLENGTH,
			       (T.GETRATE * 100) GETRATE,
			       T.INWL_ID,
			       T.OUTWL_ID,
			       M.IN_MATERIAL_DESC INWL_DESC,
			       M.OUT_MATERIAL_DESC OUTWL_DESC,
			       (SELECT B.BASENAME
			          FROM COM_BASE_INFO B
			         WHERE B.BASECODE = T.GROUP_RCL) GROUP_RCL,
			       T.PLINE_CODE_MAY,
			       T.PLINE_NAME_MAY,
			       T3.WEIGTH_S,
			       T3.NUM_S,
			       T.MATCH_WT,
			       T.MATCH_NUM,
			       DECODE(T.IFBUYPLAN, '0', '无', '1', '有') IFBUYPLAN,
			       T.BUYPLANID,
			       T.BUYPLAN_WT,
			       T.REQ_PROD_WT,
			       T.REQ_PROD_NUM,
			       TO_CHAR(T.PROD_END_DATE, 'YYYY-MM-DD HH24:MI:SS') PROD_END_DATE,
			       DECODE(T3.EXE_STATUS,
			              '0',
			              '计划',
			              '1',
			              '生产中',
			              '2',
			              '生产完成',
			              '异常') EXE_STATUS,
			       DECODE(T.IS_PLANED, '0', '否', '1', '是') IS_PLANED,
			       T.PRO_PLAN_ID,
			       T.FINISHWEIGHT,
			       DECODE(T.ISENDGX, '0', '否', '1', '是') ISENDGX,
			       T.NEXT_GX,
			       DECODE(T.IS_EXTRA_ORD, '0', '否', '1', '是') IS_EXTRA_ORD,
			       DECODE(T.IF_MONITOR_RCL, '0', '否', '1', '是') IF_MONITOR_RCL,
			       T.PRDCR_NO,
			       T.CRAFT_FILE_NO,
			       T.CRAFT_FILE_MAN,
			       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,
			       T3.PLINE_CODE,
			       T3.PLINE_NAME
			  FROM PLN_ORDER_RCL T
			  LEFT JOIN SLM_BASE_MATERIAL_F M
			    ON M.IN_MATERIAL_NO = T.INWL_ID
			   AND M.OUT_MATERIAL_NO = T.OUTWL_ID
			  LEFT JOIN PLN_SALEORD T1
			    ON T1.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
			  LEFT JOIN PLN_SALEORD_PROC T2
			    ON T2.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
			   AND T2.PLN_DIVIDE_ID = T.PLN_DIVIDE_ID, PLN_ORDER_RCL_S T3
			 WHERE T3.PRO_ORDER_NO = T.PRO_ORDER_NO
			   AND NVL(T1.ROLL_MONTH, '1') = NVL(?, NVL(T1.ROLL_MONTH, '1'))
			   AND (T1.ORDER_NO || '/' || T1.ORDER_SEQ) LIKE '%' || NLS_UPPER(?) || '%'
			   AND (T3.IS_REPAIR_PLN IS NULL OR T3.IS_REPAIR_PLN != '1')
		]]>
	</query>

	<query id="CorePlnProcOrdRcl.queryBaseProcess" desc="查询工序基础表">
		<![CDATA[
			SELECT T.PROCESS_CODE, T.PROCESS_DESC
			  FROM COM_BASE_PROCESS T
			 WHERE T.VALIDFLAG = '1'
		]]>
	</query>
	
	<query id="CorePlnProcOrdRcl.queryPineBase" desc="查询产线基础信息">
		<![CDATA[
			SELECT T.PLINE_CODE, T.PLINE_NAME
			  FROM COM_BASE_PLINE T
			 WHERE T.PROCESS_CODE = ?
			   AND T.VALIDFLAG = '1'
		]]>
	</query>
	
	<query id="CorePlnProcOrdRcl.queryRclProcPine" desc="查询热处理工序可用产线">
		<![CDATA[
			SELECT T.PLINE_CODE, T.PLINE_NAME
			  FROM COM_BASE_PLINE T, PLN_ORDER_RCL T1
			  LEFT JOIN PLN_SALEORD T2
			    ON T2.ORD_LN_DLY_PK = T1.ORD_LN_DLY_PK, SLM_BASE_MATERIAL_F_PL B,
			 (SELECT M.ORD_LN_PK,
			               M.CRAFT_SEQ,
			               M1.MSC_PLINE,
			               M1.PROCESS_CODE,
			               M1.PLINE_CODE
			          FROM CRAFT_ORD_DESIGN M, CRAFT_ORD_DESIGN_MSC_PL_GX_PRL M1
			         WHERE M1.DESGIN_KEY = M.DESGIN_KEY
			           AND M1.PROCESS_CODE = 'F') E
			 WHERE T1.GROUP_RCL = T.GROUP_PLAN
			   AND B.IN_MATERIAL_NO = T1.INWL_ID
			   AND B.OUT_MATERIAL_NO = T1.OUTWL_ID
			   AND T.PLINE_CODE = B.PLINE_CODE
			   AND E.PLINE_CODE = B.PLINE_CODE
			   AND E.ORD_LN_PK = T2.ORD_LN_PK
			   AND E.CRAFT_SEQ = T1.CRAFT_SEQ
			   AND E.MSC_PLINE = T1.INDEX_SEQ
			   AND T1.PRO_ORDER_NO = ?
			 ORDER BY B.WASTE_RATE ASC
		]]>
	</query>
	
	<query id="CorePlnProcOrdRcl.queryRclProcMaterialPine" desc="查询热处理工序可用产线">
		<![CDATA[
			SELECT B.PLINE_CODE, B.PLINE_NAME
			   FROM PLN_ORDER_RCL T, SLM_BASE_MATERIAL_F_PL B
			  WHERE B.IN_MATERIAL_NO = T.INWL_ID
			    AND B.OUT_MATERIAL_NO = T.OUTWL_ID
			    AND T.PRO_ORDER_NO = ?
			  ORDER BY B.WASTE_RATE ASC
		]]>
	</query>
	
	<query id="CorePlnProcOrdRcl.queryProcOrderNo" desc="查询工序产线">
		<![CDATA[
			SELECT T1.EXE_STATUS,
			       T.GROUP_RCL,
			       T1.PLINE_CODE,
			       T1.PLINE_NAME,
			       T1.GX_PLAN_NO,
			       (SELECT B.GROUP_PLAN
			          FROM COM_BASE_PLINE B
			         WHERE B.PLINE_CODE = T1.PLINE_CODE) PLINE_GROUP
			  FROM PLN_ORDER_RCL T, PLN_ORDER_RCL_S T1
			 WHERE T1.PRO_ORDER_NO = T.PRO_ORDER_NO
			   AND T1.PRO_ORDER_NO = ?
		]]>
	</query>
	
	<query id="CorePlnProcOrdRcl.queryProcOrdStatus" desc="查询热处理工序状态">
		<![CDATA[
			SELECT T1.EXE_STATUS,
			       T.GROUP_RCL,
			       T1.PLINE_CODE,
			       T1.PLINE_NAME,
			       (SELECT B.BASENAME
			          FROM COM_BASE_INFO B
			         WHERE B.BASECODE = T.GROUP_RCL) GROUP_PLAN
			  FROM PLN_ORDER_RCL T, PLN_ORDER_RCL_S T1
			 WHERE T1.PRO_ORDER_NO = T.PRO_ORDER_NO
			   AND T1.PRO_ORDER_NO = ?
			   AND T1.GX_PLAN_NO = ?
		]]>
	</query>
	
	<query id="CorePlnProcOrdRcl.updateRclOrdPline" desc="修改热处理产线">
		<![CDATA[
			UPDATE PLN_ORDER_RCL T
			   SET T.PLINE_CODE = ?,
			       T.PLINE_NAME =
			       (SELECT B.PLINE_NAME
			          FROM COM_BASE_PLINE B
			         WHERE B.PLINE_CODE = ?)
			 WHERE T.PRO_ORDER_NO = ?
		]]>
	</query>
	
	
	
	<query id="CorePlnProcOrdRcl.updateGroupJgxOrd" desc="修改管加工分组">
		<![CDATA[
			UPDATE PLN_ORDER_RCL T
	         SET T.GROUP_RCL =
	             (SELECT B.GROUP_PLAN FROM COM_BASE_PLINE B WHERE B.PLINE_CODE = ?)
	       WHERE T.PRO_ORDER_NO = ?
		]]>
	</query>
	
	<query id="CorePlnProcOrdRcl.updateGroupPlnOrdProc" desc="修改排产加工分组">
		<![CDATA[
			UPDATE PLN_SALEORD_PROC T
			   SET T.GROUP_RCL =
			       (SELECT B.GROUP_PLAN FROM COM_BASE_PLINE B WHERE B.PLINE_CODE = ?)
			 WHERE T.ORD_LN_DLY_PK =
			       (SELECT M.ORD_LN_DLY_PK FROM PLN_ORDER_JGX M WHERE M.PRO_ORDER_NO = ?)
			   AND T.PLN_DIVIDE_ID =
			       (SELECT M.PLN_DIVIDE_ID FROM PLN_ORDER_JGX M WHERE M.PRO_ORDER_NO = ?)
		]]>
	</query>
</queryMap>