<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="工序生产完毕">

	<query id="CoreProcessFinish.selectPlnProcOrd" desc="查询交货行排产合同">
		<![CDATA[
			SELECT T.ORD_LN_DLY_PK,
       T.PLN_DIVIDE_ID,
       T.PLANSTATUS,
       T1.PRO_ORDER_NO JGX_ORD,
       T2.PRO_ORDER_NO RCL_ORD,
       T3.PRO_ORDER_NO DBK_ORD,
       T4.PRO_ORDER_NO ZG_ORD,
       T6.PRO_PLAN_ID  JG_ORD
  FROM PLN_SALEORD_PROC T
  LEFT JOIN PLN_ORDER_JGX T1
    ON T1.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
   AND T1.PLN_DIVIDE_ID = T.PLN_DIVIDE_ID
  LEFT JOIN PLN_ORDER_RCL T2
    ON T2.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
   AND T2.PLN_DIVIDE_ID = T.PLN_DIVIDE_ID
  LEFT JOIN PLN_ORDER_DBK T3
    ON T3.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
   AND T3.PLN_DIVIDE_ID = T.PLN_DIVIDE_ID
  LEFT JOIN PLN_ORDER_ZG T4
    ON T4.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
   AND T4.PLN_DIVIDE_ID = T.PLN_DIVIDE_ID
   LEFT JOIN (SELECT T5.PRO_PLAN_ID, T5.ORD_LN_DLY_PK, T5.PLN_DIVIDE_ID
          FROM PLN_GX_JG_PROP_S T5
         GROUP BY T5.PRO_PLAN_ID,T5.ORD_LN_DLY_PK, T5.PLN_DIVIDE_ID) T6
    ON T6.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
   AND T6.PLN_DIVIDE_ID = T.PLN_DIVIDE_ID
			 WHERE T.ORD_LN_DLY_PK = ?
		]]>
	</query>
	<query id="CoreProcessFinish.selectJgProcMId" desc="查询接箍订单">
		<![CDATA[
SELECT MIN(T.PRO_PLAN_ID) PRO_PLAN_ID, MIN(T.EXE_STATUS) EXE_STATUS
  FROM PLN_GX_JG_PROP_S T
 WHERE T.ORD_LN_DLY_PK = ?
   AND T.PLN_DIVIDE_ID = ?
		]]>
	</query>
	<query id="CoreProcessFinish.selectJgxProcMId" desc="查询加工订单">
		<![CDATA[
			SELECT T.PRO_PLAN_ID, T.ORDERSTATUS
			  FROM PLN_ORDER_JGX T
			 WHERE T.ORD_LN_DLY_PK = ?
			   AND T.PLN_DIVIDE_ID = ?
		]]>
	</query>

	<query id="CoreProcessFinish.selectRclProcMId" desc="查询热处理订单">
		<![CDATA[
			SELECT T.PRO_PLAN_ID, T.ORDERSTATUS
			  FROM PLN_ORDER_RCL T
			 WHERE T.ORD_LN_DLY_PK = ?
			   AND T.PLN_DIVIDE_ID = ?
		]]>
	</query>

	<query id="CoreProcessFinish.selectDbkProcMId" desc="查询镦拔扩订单">
		<![CDATA[
			SELECT T.PRO_PLAN_ID, T.ORDERSTATUS
			  FROM PLN_ORDER_DBK T
			 WHERE T.ORD_LN_DLY_PK = ?
			   AND T.PLN_DIVIDE_ID = ?
		]]>
	</query>

	<query id="CoreProcessFinish.selectZgProcMId" desc="查询轧管订单">
		<![CDATA[
			SELECT T.PRO_PLAN_ID, T.ORDERSTATUS
			  FROM PLN_ORDER_ZG T
			 WHERE T.ORD_LN_DLY_PK = ?
			   AND T.PLN_DIVIDE_ID = ?
			   AND T.PRO_ORDER_NO=?
		]]>
	</query>

	<query id="CoreProcessFinish.processJgxFinish" desc="更新加工工序合同">
		<![CDATA[
			UPDATE PLN_ORDER_JGX
			   SET ORDERSTATUS = ?
			 WHERE ORD_LN_DLY_PK = ?
			   AND PLN_DIVIDE_ID = ?
			   AND ORDERSTATUS < 4
		]]>
	</query>

	<query id="CoreProcessFinish.processRclFinish" desc="更新热处理工序合同">
		<![CDATA[
			UPDATE PLN_ORDER_RCL
			   SET ORDERSTATUS = ?
			 WHERE ORD_LN_DLY_PK = ?
			   AND PLN_DIVIDE_ID = ?
			   AND ORDERSTATUS < 4
		]]>
	</query>

	<query id="CoreProcessFinish.processDbkFinish" desc="更新镦拔扩工序合同">
		<![CDATA[
			UPDATE PLN_ORDER_DBK
			   SET ORDERSTATUS = ?
			 WHERE ORD_LN_DLY_PK = ?
			   AND PLN_DIVIDE_ID = ?
			   AND ORDERSTATUS < 4
		]]>
	</query>

	<query id="CoreProcessFinish.processZgFinish" desc="更新轧管工序合同">
		<![CDATA[
			UPDATE PLN_ORDER_ZG
			   SET ORDERSTATUS = ?
			 WHERE ORD_LN_DLY_PK = ?
			   AND PLN_DIVIDE_ID = ?
			   AND ORDERSTATUS < 4
		]]>
	</query>


	<query id="CoreProcessFinish.selectJgxMProcessNum" desc="查询加工订单是否完成">
		<![CDATA[
			SELECT COUNT(*) NUM_ORD
			  FROM PLN_ORDER_JGX T, PLN_GX_JGX_M M
			 WHERE M.PRO_PLAN_ID = T.PRO_PLAN_ID
			   AND M.PRO_PLAN_ID = ?
			   AND T.ORDERSTATUS < 4
		]]>
	</query>

	<query id="CoreProcessFinish.selectRclMProcessNum" desc="查询热处理订单是否完成">
		<![CDATA[
			SELECT COUNT(*) NUM_ORD
			  FROM PLN_ORDER_RCL T, PLN_GX_RCL_M M
			 WHERE M.PRO_PLAN_ID = T.PRO_PLAN_ID
			   AND M.PRO_PLAN_ID = ?
			   AND T.ORDERSTATUS < 4
		]]>
	</query>

	<query id="CoreProcessFinish.selectDbkMProcessNum" desc="查询镦拔扩订单是否完成">
		<![CDATA[
			SELECT COUNT(*) NUM_ORD
			  FROM PLN_ORDER_DBK T, PLN_GX_DBK_M M
			 WHERE M.PRO_PLAN_ID = T.PRO_PLAN_ID
			   AND M.PRO_PLAN_ID = ?
			   AND T.ORDERSTATUS < 4
		]]>
	</query>

	<query id="CoreProcessFinish.selectZgMProcessNum" desc="查询轧管订单是否完成">
		<![CDATA[
			SELECT COUNT(*) NUM_ORD
			  FROM PLN_ORDER_ZG T, PLN_GX_ZG_M M
			 WHERE M.PRO_PLAN_ID = T.PRO_PLAN_ID
			   AND M.PRO_PLAN_ID = ?
			   AND T.ORDERSTATUS < 4
		]]>
	</query>

	<query id="CoreProcessFinish.updateJgxMStatus" desc="设置加工订单生产完毕">
		<![CDATA[
			UPDATE PLN_GX_JGX_M T
			   SET T.PLANSTATUS = '3'
			 WHERE T.PRO_PLAN_ID = ?
		]]>
	</query>

	<query id="CoreProcessFinish.updateRclMStatus" desc="设置加工订单生产完毕">
		<![CDATA[
			UPDATE PLN_GX_RCL_M T
			   SET T.PLANSTATUS = '3'
			 WHERE T.PRO_PLAN_ID = ?
		]]>
	</query>

	<query id="CoreProcessFinish.updateDbkMStatus" desc="设置加工订单生产完毕">
		<![CDATA[
			UPDATE PLN_GX_DBK_M T
			   SET T.PLANSTATUS = '3'
			 WHERE T.PRO_PLAN_ID = ?
		]]>
	</query>

	<query id="CoreProcessFinish.updateZgMStatus" desc="设置加工订单生产完毕">
		<![CDATA[
			UPDATE PLN_GX_ZG_M T
			   SET T.PLANSTATUS = '3'
			 WHERE T.PRO_PLAN_ID = ?
		]]>
	</query>
<query id="CoreProcessFinish.updateJgMSGxStatus" desc="设置接箍排产生产完毕">
		<![CDATA[
			UPDATE PLN_GX_JG_PROP_S T
			   SET T.EXE_STATUS = '3', T.GX_PRO_SEQ = '-1'
			 WHERE T.PRO_PLAN_ID = ?
			   AND T.GX_PLAN_NO = ?
		]]>
	</query>
	<query id="CoreProcessFinish.updateJgxMSGxStatus" desc="设置加工订单排产生产完毕">
		<![CDATA[
			UPDATE PLN_ORDER_JGX_S T
			   SET T.EXE_STATUS = '3', T.GX_PRO_SEQ = '-1'
			 WHERE T.PRO_PLAN_ID = ?
			   AND T.GX_PLAN_NO = ?
		]]>
	</query>

	<query id="CoreProcessFinish.updateRclMSGxStatus" desc="设置热处理订单排产生产完毕">
		<![CDATA[
			UPDATE PLN_ORDER_RCL_S T
			   SET T.EXE_STATUS = '3', T.GX_PRO_SEQ = '-1'
			 WHERE T.PRO_PLAN_ID = ?
			   AND T.GX_PLAN_NO = ?
		]]>
	</query>

	<query id="CoreProcessFinish.updateDbkMSGxStatus" desc="设置镦拔扩订单排产生产完毕">
		<![CDATA[
			UPDATE PLN_ORDER_DBK_S T
			   SET T.EXE_STATUS = '3', T.GX_PRO_SEQ = '-1'
			 WHERE T.PRO_PLAN_ID = ?
			   AND T.GX_PLAN_NO = ?
		]]>
	</query>
	<query id="CoreProcessFinish.updateZgZyBatch" desc="强制生产完成轧管订单排产轧批号">
		<![CDATA[
			UPDATE PLN_ORDER_ZG_S T
			   SET T.ZY_BATCH_ID='',
			       T.ZY_BATCH_ID1= ?
			 WHERE T.PRO_PLAN_ID = ?
			   AND T.GX_PLAN_NO = ?
		]]>
	</query>
	<query id="CoreProcessFinish.updateZgMSGxStatus" desc="设置轧管订单排产生产完毕">
		<![CDATA[
			UPDATE PLN_ORDER_ZG_S T
			   SET T.EXE_STATUS = '3', T.GX_PRO_SEQ = '-1',T.ZY_BATCH_ID=?
			 WHERE T.PRO_PLAN_ID = ?
			   AND T.GX_PLAN_NO = ?
		]]>
	</query>
<query id="CoreProcessFinish.selectOrderJgS" desc="查询接箍工序">
		<![CDATA[
	    SELECT TO_NUMBER(T.GX_PRO_SEQ) GX_PRO_SEQ,
           T.PLINE_CODE,
           T.PLINE_NAME,
           TO_CHAR(T.PLAN_TIME_B, 'YYYY-MM-DD HH24:MI:SS') PLAN_TIME_B,
           T.GX_PLAN_NO,
           T.EXE_STATUS
      FROM PLN_GX_JG_PROP_S T
     WHERE T.PRO_PLAN_ID = ?
		]]>
	</query>
	<query id="CoreProcessFinish.selectOrderJgxS" desc="查询管加工耗时工序">
		<![CDATA[
			 SELECT TO_NUMBER(T.GX_PRO_SEQ) GX_PRO_SEQ,
			       T.PLINE_CODE,
			       T.PLINE_NAME,
			       TO_CHAR(T.PLAN_TIME_B,'YYYY-MM-DD HH24:MI:SS') PLAN_TIME_B,
			       T.GX_PLAN_NO,
			       T.EXE_STATUS
			  FROM PLN_ORDER_JGX_S T
			 WHERE T.PRO_PLAN_ID = ?
		]]>
	</query>

	<query id="CoreProcessFinish.selectOrderRclS" desc="查询热处理耗时工序">
		<![CDATA[
			 SELECT TO_NUMBER(T.GX_PRO_SEQ) GX_PRO_SEQ,
			       T.PLINE_CODE,
			       T.PLINE_NAME,
			       TO_CHAR(T.PLAN_TIME_B,'YYYY-MM-DD HH24:MI:SS') PLAN_TIME_B,
			       T.GX_PLAN_NO,
			       T.EXE_STATUS
			  FROM PLN_ORDER_RCL_S T
			 WHERE T.PRO_PLAN_ID = ?
		]]>
	</query>

	<query id="CoreProcessFinish.selectOrderDbkS" desc="查询镦拔扩耗时工序">
		<![CDATA[
			 SELECT TO_NUMBER(T.GX_PRO_SEQ) GX_PRO_SEQ,
			       T.PLINE_CODE,
			       T.PLINE_NAME,
			       TO_CHAR(T.PLAN_TIME_B,'YYYY-MM-DD HH24:MI:SS') PLAN_TIME_B,
			       T.GX_PLAN_NO,
			       T.EXE_STATUS
			  FROM PLN_ORDER_DBK_S T
			 WHERE T.PRO_PLAN_ID = ?
		]]>
	</query>

	<query id="CoreProcessFinish.selectOrderZgS" desc="查询轧管耗时工序">
		<![CDATA[
			SELECT TO_NUMBER(T.GX_PRO_SEQ) GX_PRO_SEQ,
			       T.PLINE_CODE,
			       T.PLINE_NAME,
			       TO_CHAR(T.PLAN_TIME_B,'YYYY-MM-DD HH24:MI:SS') PLAN_TIME_B,
			       T.GX_PLAN_NO,
			       T.EXE_STATUS,
			       T.ZY_BATCH_ID,
			       NVL(T.IF_STOVE_ISSUED,0) IF_STOVE_ISSUED
			  FROM PLN_ORDER_ZG_S T
			 WHERE T.PRO_PLAN_ID = ?
		]]>
	</query>
<query id="CoreProcessFinish.selectOrdJgSPline" desc="分产线查询接箍排产">
		<![CDATA[
			SELECT T.PRO_PLAN_ID,
			       T.GX_PLAN_NO,
			       T.GX_PRO_SEQ,
			       T.PLINE_CODE,
			       T.PLINE_NAME
			  FROM PLN_GX_JG_PROP_S T
			 WHERE T.PLINE_CODE = ? 
		]]>
	</query>
	
	<query id="CoreProcessFinish.selectOrdJgxSPline" desc="分产线查询加工线排产">
		<![CDATA[
			SELECT T.PRO_PLAN_ID,
			       T.GX_PLAN_NO,
			       T.GX_PRO_SEQ,
			       T.PLINE_CODE,
			       T.PLINE_NAME
			  FROM PLN_ORDER_JGX_S T
			 WHERE T.PLINE_CODE = ? 
		]]>
	</query>
<query id="CoreProcessFinish.updateOrdJgSStatus" desc="更新接箍排产状态">
		<![CDATA[
			UPDATE PLN_GX_JG_PROP_S T
			   SET T.EXE_STATUS = ?
			 WHERE T.PRO_PLAN_ID = ?
			   AND T.GX_PLAN_NO = ?
		]]>
	</query>
	<query id="CoreProcessFinish.updateOrdJgxSStatus" desc="更新加工排产状态">
		<![CDATA[
			UPDATE PLN_ORDER_JGX_S T
			   SET T.EXE_STATUS = ?
			 WHERE T.PRO_PLAN_ID = ?
			   AND T.GX_PLAN_NO = ?
		]]>
	</query>

	<query id="CoreProcessFinish.selectOrdRclsPline" desc="分产线查询热处理排产">
		<![CDATA[
			SELECT T.PRO_PLAN_ID,
			       T.GX_PLAN_NO,
			       T.GX_PRO_SEQ,
			       T.PLINE_CODE,
			       T.PLINE_NAME
			  FROM PLN_ORDER_RCL_S T
			 WHERE T.PLINE_CODE = ? 
		]]>
	</query>

	<query id="CoreProcessFinish.updateOrdRclsStatus" desc="更新热处理排产状态">
		<![CDATA[
			UPDATE PLN_ORDER_RCL_S T
			   SET T.EXE_STATUS = ?
			 WHERE T.PRO_PLAN_ID = ?
			   AND T.GX_PLAN_NO = ?
		]]>
	</query>

	<query id="CoreProcessFinish.selectOrdDbksPline" desc="分产线查询热处理排产">
		<![CDATA[
			SELECT T.PRO_PLAN_ID,
			       T.GX_PLAN_NO,
			       T.GX_PRO_SEQ,
			       T.PLINE_CODE,
			       T.PLINE_NAME
			  FROM PLN_ORDER_DBK_S T
			 WHERE T.PLINE_CODE = ? 
		]]>
	</query>

	<query id="CoreProcessFinish.updateOrdDbksStatus" desc="更新热处理排产状态">
		<![CDATA[
			UPDATE PLN_ORDER_DBK_S T
			   SET T.EXE_STATUS = ?
			 WHERE T.PRO_PLAN_ID = ?
			   AND T.GX_PLAN_NO = ?
		]]>
	</query>

	<query id="CoreProcessFinish.selectOrdZgsPline" desc="分产线查询热处理排产">
		<![CDATA[
			SELECT T.PRO_PLAN_ID,
			       T.GX_PLAN_NO,
			       T.GX_PRO_SEQ,
			       T.PLINE_CODE,
			       T.PLINE_NAME
			  FROM PLN_ORDER_ZG_S T
			 WHERE T.PLINE_CODE = ? 
		]]>
	</query>

	<query id="CoreProcessFinish.updateOrdZgsStatus" desc="更新热处理排产状态">
		<![CDATA[
			UPDATE PLN_ORDER_ZG_S T
			   SET T.EXE_STATUS = ?
			 WHERE T.PRO_PLAN_ID = ?
			   AND T.GX_PLAN_NO = ?
		]]>
	</query>



</queryMap>