<?xml version="1.0" encoding="UTF-8"?>
	<queryMap desc="合同状态导入设置">
		<query id="CoreOrderStatusSet.getBaseInfSort" desc="获取基础信息表">
			<![CDATA[
				SELECT T.BASECODE, T.BASENAME
				  FROM COM_BASE_INFO T
				 WHERE T.SORTCODE = ?
				   AND T.VALIDFLAG = '1'
			]]>
		</query>
	
		<query id="CoreOrderStatusSet.queryOrderSetLog" desc="查询导入日志">
			<![CDATA[
				SELECT T.ROLL_MONTH,
				       T.ORDER_NO_SEQ,
				       T.ORD_LN_DLY_PK,
				       T.IMP_TIME,
				       DECODE(T.IF_SET_MONTH,'0','否','1','是') IF_SET_MONTH,
				       T.NUM_SET_STATUS,
				       DECODE(T.END_STATUS,
			              '1',
			              '已接收',
			              '2',
			              '已下发',
			              '4',
			              '生产完成',
			              '5',
			              '缴库完成') END_STATUS,
	                    T.PRODUCE_SORT,
	                    DECODE(T.IF_SET_PRODUCE_SORT,'0','否','1','是') IF_SET_PRODUCE_SORT,
	                    T.ORDERFROM,
	                    DECODE(T.IF_SET_ORDERFROM,'0','否','1','是') IF_SET_ORDERFROM
				  FROM PLN_SALEORDER_SET T
				 WHERE T.ORDER_NO_SEQ LIKE '%' || ? || '%'
				   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="CoreOrderStatusSet.setOrderStatus" desc="设置合同状态">
			<![CDATA[
				UPDATE PLN_SALEORDER T
				   SET T.PORDERSTATUS = ?
				 WHERE T.ORDER_NO = ?
				   AND T.ORDER_SEQ = ?
			]]>
		</query>
		
		<query id="CoreOrderStatusSet.setDeliveryStatus" desc="设置合同状态">
			<![CDATA[
				UPDATE SLM_ORDER_LINE_DELIVERY T
				   SET T.DELIVERY_STATUS = ?
				 WHERE T.ORD_LN_PK = (SELECT MAX(B.ORD_LN_PK)
				                        FROM PLN_SALEORDER B
				                       WHERE B.ORDER_NO = ?
				                         AND B.ORDER_SEQ = ?)
			]]>
		</query>
		
		<query id="CoreOrderStatusSet.setOrderStatusByPk" desc="设置合同状态">
			<![CDATA[
				UPDATE PLN_SALEORDER T
				   SET T.PORDERSTATUS = ?
				 WHERE T.ORD_LN_DLY_PK = ?
			]]>
		</query>
		
		<query id="CoreOrderStatusSet.setDeliveryStatusByPk" desc="设置合同状态">
			<![CDATA[
				UPDATE SLM_ORDER_LINE_DELIVERY T SET T.DELIVERY_STATUS = ? WHERE T.ORD_LN_DLY_PK = ?
			]]>
		</query>
		
		<query id="CoreOrderStatusSet.setProSort" desc="设置合同生产分类">
			<![CDATA[
				UPDATE PLN_SALEORDER T
				   SET T.PRODUCE_SORT = NVL(?, T.PRODUCE_SORT)
				 WHERE T.ORDER_NO = ?
				   AND T.ORDER_SEQ = ?
			]]>
		</query>
		
		<query id="CoreOrderStatusSet.setProSortByPk" desc="设置合同生产分类">
			<![CDATA[
				UPDATE PLN_SALEORDER T
				   SET T.PRODUCE_SORT = NVL(?, T.PRODUCE_SORT)
				 WHERE T.ORD_LN_DLY_PK = ?
			]]>
		</query>
		
		<query id="CoreOrderStatusSet.setOrderfrom" desc="设置合同来源">
			<![CDATA[
				UPDATE PLN_SALEORDER T
				   SET T.ORDERFROM = NVL(?, T.ORDERFROM)
				 WHERE T.ORDER_NO = ?
				   AND T.ORDER_SEQ = ?
			]]>
		</query>
		
		<query id="CoreOrderStatusSet.setOrderfromByPk" desc="设置合同来源">
			<![CDATA[
				UPDATE PLN_SALEORDER T
				   SET T.ORDERFROM = NVL(?, T.ORDERFROM)
				 WHERE T.ORD_LN_DLY_PK = ?
			]]>
		</query>
		
		<query id="CoreOrderStatusSet.setOrderStatusMonth" desc="设置合同轧制月份">
			<![CDATA[
				UPDATE PLN_SALEORDER T
				   SET T.ROLL_MONTH = NVL(?, T.ROLL_MONTH)
				 WHERE T.ORDER_NO = ?
				   AND T.ORDER_SEQ = ?
			]]>
		</query>
		
		<query id="CoreOrderStatusSet.setOrderStatusMonthByPk" desc="设置合同轧制月份">
			<![CDATA[
				UPDATE PLN_SALEORDER T
				   SET T.ROLL_MONTH = NVL(?, T.ROLL_MONTH)
				 WHERE T.ORD_LN_DLY_PK = ?
			]]>
		</query>
		
		<query id="CoreOrderStatusSet.insertOrderSetlog" desc="导入日志">
			<![CDATA[
				 INSERT INTO PLN_SALEORDER_SET
				   (ROLL_MONTH,
				    ORDER_NO_SEQ,
				    ORD_LN_DLY_PK,
				    IF_SET_MONTH,
				    NUM_SET_STATUS,
				    ORDERFROM,
				    PRODUCE_SORT)
				 VALUES
				   ('#ROLL_MONTH#',
				    '#ORDER_NO_SEQ#',
				    '#ORD_LN_DLY_PK#',
				    '#IF_SET_MONTH#',
				    '0',
				    DECODE('#ORDERFROM#',
				           '国内贸易部',
				           '100101',
				           '国际贸易部',
				           '100102',
				           '钢贸公司',
				           '100103'),
				    '#PRODUCE_SORT#')
			]]>
		</query>
		
		<query id="CoreOrderStatusSet.updateOrderSetlogMonth" desc="更新日志轧制月份">
			<![CDATA[
				UPDATE PLN_SALEORDER_SET T
				   SET T.IF_SET_MONTH   = ?
				 WHERE T.ORDER_NO_SEQ = ?
				   AND DECODE(?, NULL, '1', T.ORD_LN_DLY_PK) = DECODE(?, NULL, '1', ?)
			]]>
		</query>
		
		<query id="CoreOrderStatusSet.updateOrderSetlogProSort" desc="更新日志生产分类">
			<![CDATA[
				UPDATE PLN_SALEORDER_SET T
				   SET T.IF_SET_PRODUCE_SORT   = ?
				 WHERE T.ORDER_NO_SEQ = ?
				   AND DECODE(?, NULL, '1', T.ORD_LN_DLY_PK) = DECODE(?, NULL, '1', ?)
			]]>
		</query>
		
		<query id="CoreOrderStatusSet.updateOrderSetlogOrderfrom" desc="更新日志合同来源">
			<![CDATA[
				UPDATE PLN_SALEORDER_SET T
				   SET T.IF_SET_ORDERFROM   = ?
				 WHERE T.ORDER_NO_SEQ = ?
				   AND DECODE(?, NULL, '1', T.ORD_LN_DLY_PK) = DECODE(?, NULL, '1', ?)
			]]>
		</query>
		
		<query id="CoreOrderStatusSet.updateOrderSetlog" desc="更新日志状态">
			<![CDATA[
				UPDATE PLN_SALEORDER_SET T
				   SET T.END_STATUS     = ?,
				       T.NUM_SET_STATUS = T.NUM_SET_STATUS + 1
				 WHERE T.ORDER_NO_SEQ = ?
				   AND DECODE(?, NULL, '1', T.ORD_LN_DLY_PK) = DECODE(?, NULL, '1', ?)
			]]>
		</query>
		
		<query id="CoreOrderStatusSet.deleteOrderStatus" desc="删除日志">
			<![CDATA[
				DELETE FROM PLN_SALEORDER_SET T
				 WHERE T.ORDER_NO_SEQ = ?
				   AND DECODE(?, NULL, '1', T.ORD_LN_DLY_PK) = DECODE(?, NULL, '1', ?)
			]]>
		</query>
	</queryMap>
	