<?xml version="1.0" encoding="UTF-8"?>
	<queryMap desc="合同状态导入设置">
	
		<query id="CoreOrdStatusSet.queryOrderSetLog" desc="查询导入日志">
			<![CDATA[
				SELECT T.ROLL_MONTH,
				       (M.ORDER_NO || '/' || M.ORDER_SEQ) ORDER_NO_SEQ,
				       M.DELIVERY_NO,
				       T.ORD_LN_DLY_PK,
				       T.PLN_DIVIDE_ID,
				       T.IMP_TIME,
				       DECODE(T.IF_SET_MONTH, '0', '否', '1', '是') IF_SET_MONTH,
				       T.NUM_SET_STATUS,
				       T.CHECK_MOTH,
				       DECODE(T.END_STATUS,
				              '1',
				              '已接收',
				              '2',
				              '已下发',
				              '3',
				              '生产中',
				              '4',
				              '生产完成',
				              '5',
				              '缴库完成') END_STATUS,
				       N.ROLL_MONTH ROLL_MONTH_NOW,
				       M.PRODUCNAME,
				       M.SPEC_NAME,
				       M.LENGTHDISC,
				       DECODE(N.PLANSTATUS,
				              '1',
				              '已接收',
				              '2',
				              '已下发',
				              '3',
				              '生产中',
				              '4',
				              '生产完成',
				              '5',
				              '缴库完成') PLANSTATUS,
				       T.PRIORITY,
				       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = T.PRIORITY) PRIORITY_NAME,
				       T.PRIORITY_MEMO
				  FROM PLN_SALEORD_SET T
				  LEFT JOIN PLN_SALEORD M
				    ON M.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
				  LEFT JOIN PLN_SALEORD_PROC N
				    ON N.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
				   AND N.PLN_DIVIDE_ID = T.PLN_DIVIDE_ID
				 WHERE (M.ORDER_NO || '/' || M.ORDER_SEQ) LIKE '%' || NLS_UPPER(?) || '%'
				   AND DECODE(?, NULL, '1', T.IF_SET_MONTH) = NVL(?, '1')
				   AND DECODE(?, NULL, '1', T.NUM_SET_STATUS) = NVL(?, '1')
				   AND TO_DATE(TO_CHAR(T.IMP_TIME, 'YYYY-MM-DD'), 'YYYY-MM-DD') BETWEEN
				       TO_DATE(?, 'YYYY-MM-DD') AND TO_DATE(?, 'YYYY-MM-DD')
			]]>
		</query>
		
		<query id="CoreOrdStatusSet.queryPlnOrdStatus" desc="查询排产交货行状态">
			<![CDATA[
				SELECT T.PLANSTATUS, T1.ORD_LN_PK,T.ORDER_SOURCE
				  FROM PLN_SALEORD_PROC T, PLN_SALEORD T1
				 WHERE T1.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
				   AND T.ORD_LN_DLY_PK = ?
			]]>
		</query>
		
		<query id="CoreOrdStatusSet.setOrdProcStatusByPk" desc="更新拆分合同状态">
		<![CDATA[
			UPDATE PLN_SALEORD_PROC T
			   SET T.PLANSTATUS     = ?,
			       T.ISSUED_MAN = ?,
			       T.ISSUED_TIME = SYSDATE,
			       T.DELETE_NAME     = ?,
			       T.DELETE_TIME    = TO_DATE(?,'YYYY-MM-DD HH24:MI:SS')
			 WHERE T.ORD_LN_DLY_PK = ?
			   AND T.PLN_DIVIDE_ID = NVL(?, T.PLN_DIVIDE_ID)
			]]>
		</query>
		
		<query id="CoreOrdStatusSet.setOrderStatusByPk" desc="设置合同状态">
			<![CDATA[
				UPDATE PLN_SALEORD T
				   SET T.PORDERSTATUS = ?
				 WHERE T.ORD_LN_DLY_PK = ?
			]]>
		</query>
		
		<query id="CoreOrdStatusSet.setDeliveryStatusByPk" desc="设置销售交货行合同状态">
			<![CDATA[
				UPDATE SLM_ORDER_LINE_DELIVERY T SET T.DELIVERY_STATUS = ? WHERE T.ORD_LN_DLY_PK = ?
			]]>
		</query>
		
		<query id="CoreOrdStatusSet.queryRollWellMonth" desc="查询产能井月份">
			<![CDATA[
				SELECT T.ROLL_WELL_MONTH, T1.ORDER_SOURCE
				  FROM PLN_SALEORD T, PLN_SALEORD_PROC T1
				 WHERE T.ORD_LN_DLY_PK = T1.ORD_LN_DLY_PK
				   AND T1.ORD_LN_DLY_PK = ?
				   AND T1.PLN_DIVIDE_ID = ?
			]]>
		</query>
		
		<query id="CoreOrdStatusSet.setOrderStatusMonthByPk" desc="设置合同轧制月份">
			<![CDATA[
				UPDATE PLN_SALEORD T
				   SET T.ROLL_MONTH = NVL(?, T.ROLL_MONTH)
				 WHERE T.ORD_LN_DLY_PK = ?
			]]>
		</query>
		
		<query id="CoreOrdStatusSet.setOrderStatusMonthByPkProc" desc="设置合同轧制月份">
			<![CDATA[
				UPDATE PLN_SALEORD_PROC T
				   SET T.ROLL_MONTH = NVL(?, T.ROLL_MONTH)
				 WHERE T.ORD_LN_DLY_PK = ?
				   AND T.PLN_DIVIDE_ID = ?
			]]>
		</query>
	<query id = "CoreOrderStatusSet.updateOrderCheckMoth" desc = "同步考核月份">
		UPDATE PLN_SALEORD_PROC T
		SET T.CHECK_MOTH = '#CHECK_MOTH#'
		WHERE T.ORD_LN_DLY_PK = '#ORD_LN_DLY_PK#'
		AND T.PLN_DIVIDE_ID = '#PLN_DIVIDE_ID#'
	</query>
		<query id="CoreOrdStatusSet.updatePlnZgLenGpSin" desc="更新轧管排产单倍坯长">
			<![CDATA[
			UPDATE PLN_ORDER_ZG_S T
   SET T.LEN_GP_SINGLE = '#LEN_GP_SINGLE#'
 WHERE T.PRO_PLAN_ID = '#PRO_PLAN_ID#'
   AND T.GX_PLAN_NO = '#GX_PLAN_NO#'
			
			]]>
		</query>	
		<query id="CoreOrdStatusSet.insertOrderSetlog" desc="导入日志">
			<![CDATA[
				INSERT INTO PLN_SALEORD_SET
				  (ROLL_MONTH, ORD_LN_DLY_PK, PLN_DIVIDE_ID,CHECK_MOTH,PRIORITY,PRIORITY_MEMO)
				VALUES
				  ('#ROLL_MONTH#', '#ORD_LN_DLY_PK#', '#PLN_DIVIDE_ID#','#CHECK_MOTH#','#PRIORITY#','#PRIORITY_MEMO#')
			]]>
		</query>
		
		<query id="CoreOrdStatusSet.updateOrderSetlogMonth" desc="更新日志轧制月份">
			<![CDATA[
				UPDATE PLN_SALEORD_SET T
				   SET T.IF_SET_MONTH   = ?
				 WHERE T.ORD_LN_DLY_PK = ?
				   AND DECODE(?, NULL, 1, T.PLN_DIVIDE_ID) = NVL(?, 1)
			]]>
		</query>
		
		<query id="CoreOrdStatusSet.updateOrderSetlog" desc="更新日志状态">
			<![CDATA[
				UPDATE PLN_SALEORD_SET T
				   SET T.END_STATUS = ?, T.NUM_SET_STATUS = T.NUM_SET_STATUS + 1
				 WHERE T.ORD_LN_DLY_PK = ?
				   AND DECODE(?, NULL, 1, T.PLN_DIVIDE_ID) = NVL(?, 1)
			]]>
		</query>
		
		<query id="CoreOrdStatusSet.deleteOrderStatus" desc="删除日志">
			<![CDATA[
				DELETE FROM PLN_SALEORD_SET T
				 WHERE T.ORD_LN_DLY_PK = ?
				   AND DECODE(?, NULL, 1, T.PLN_DIVIDE_ID) = NVL(?, 1)
			]]>
		</query>
	
		<query id="CoreOrdStatusSet.setOrdLineStatus" desc="修改销售合同行表状态">
			<![CDATA[
				UPDATE SLM_ORDER_LINE T SET T.ORDER_LN_STATUS = ? WHERE T.ORD_LN_PK = ?
			]]>
		</query>
		
		<query id="CoreOrdStatusSet.getNumDeliveryByLine" desc="查询和同行的交货行数目">
			<![CDATA[
				SELECT COUNT(T.DELIVERY_STATUS) DELIVERY_NUM
				  FROM SLM_ORDER_LINE_DELIVERY T
				 WHERE T.ORD_LN_PK = ?
				   AND SUBSTR(T.DELIVERY_STATUS, 0, 6) != '120210'
				   AND T.VALIDFLAG = '1'
			]]>
		</query>
	</queryMap>
	