<?xml version="1.0" encoding="UTF-8"?>
	<queryMap desc="合同补量申请">
		<query id="CoreReqRequest.getOrdRNum" desc="查询合同补量申请">
			<![CDATA[
				SELECT T.R_NUM_ID,
				       T.ORD_LN_DLY_PK,
				       T.ORDER_NO,
				       T.ORDER_SEQ,
				       T.DELIVERY_NO,
				       T.PRODUCCODE,
				       T.PRODUCNAME,
				       T.STD_CODE,
				       T.STD_NAME,
				       T.STEELCODE,
				       T.STEELNAME,
				       T.SPEC_CODE,
				       T.SPEC_NAME,
				       T.MODEL_CODE,
				       T.MODEL_DESC,
				       T.OUTDIAMETER,
				       T.WALLTHICK,
				       T.LENGTHDISC,
				       T.ORDER_UNIT,
				       T.REQWEIGHT,
				       T.CONFIRM_WT,
				       DECODE(T.ORDER_UNIT, '米', '吨', '英尺', '吨', T.ORDER_UNIT) REQ_WEIGHT_UNIT,
				       T.REP_QTY,
				       T.REP_REASON,
				       T.REQ_NAME,
				       TO_CHAR(T.REQ_TIME, 'YYYY-MM-DD HH24:MI:SS') REQ_TIME,
				       T.PLAN_DEAL_NAME,
				       TO_CHAR(T.PLAN_DEAL_TIME, 'YYYY-MM-DD HH24:MI:SS') PLAN_DEAL_TIME
				  FROM PLN_SALEORDER_R_NUM T
				 WHERE T.ORD_LN_DLY_PK = ?
			]]>
		</query>
		
		<query id="CoreReqRequest.getOrdRNumbyid" desc="查询合同补量申请">
			<![CDATA[
			SELECT T.R_NUM_ID,
			       T.ORD_LN_DLY_PK,
			       T.ORDER_NO,
			       T.ORDER_SEQ,
			       T.DELIVERY_NO,
			       T.ORDER_UNIT,
			       T.REP_QTY,
			       T.REQWEIGHT
			  FROM PLN_SALEORDER_R_NUM T
			 WHERE T.R_NUM_ID = ?
			]]>
		</query>
		
		<query id="CoreReqRequest.getReqOrder" desc="查询补量合同">
			<![CDATA[
				SELECT (SELECT A.PLINE_NAME
				          FROM COM_BASE_PLINE A
				         WHERE A.PLINE_CODE = T.GROUP_ROLL
				           AND A.VALIDFLAG = '1') GROUP_ROLL,
				       (SELECT A.PRODUC_JX
				          FROM COM_BASE_PRODUCT A
				         WHERE A.PRODUCCODE = T.PRODUCCODE) PRODUC_JX,
				       (DECODE(T.STD_STYLE_DESC || ' ', ' ', '', T.STD_STYLE_DESC || ' ') ||
				       T.STEELNAME) STEELNAME,
				       T.OUTDIAMETER,
				       T.WALLTHICK,
				       T.LENGTHDISC,
				       T.MODEL_DESC,
				       T2.REQWEIGHT,
				       DECODE(T2.CONFIRM_WT,NULL,T2.REQWEIGHT,T2.CONFIRM_WT) CONFIRM_WT,
				       DECODE(T.ORDER_UNIT,
				              '个',
				              '支',
				              '米',
				              '吨',
				              '英尺',
				              '吨',
				              T.ORDER_UNIT) DW,
				       DECODE(T.ORDER_UNIT, '米', '吨', '英尺', '吨', T.ORDER_UNIT) REQ_WEIGHT_UNIT,
				       T.STD_NAME,
				       T.ORDER_NO || '/' || T.ORDER_SEQ ORDER_SEQNO,
				       NVL((SELECT A.ABRVITION
				             FROM SLM_BASE_CUSTOMER A
				            WHERE A.CUSTOMER_NO = DECODE(T.FINAL_USER,
				                                         NULL,
				                                         T.BUYER_ID,
				                                         '/',
				                                         T.BUYER_ID,
				                                         T.FINAL_USER)),
				           DECODE(T.FINAL_USER_DESC,
				                  NULL,
				                  T.BUYER_NAME,
				                  '/',
				                  T.BUYER_NAME,
				                  T.FINAL_USER_DESC)) FINAL_USER,
				       DECODE(T.ORDER_SPECIAL_DESC, NULL, '普通', '特殊') ORDER_TYPE,
				       T.ORDER_ADD_DESC,
				       T.ASK_TYPE_STATUS,
				       (SELECT MAX(A.BASENAME)
				          FROM COM_BASE_INFO A
				         WHERE A.BASECODE = T.ORDERFROM
				            OR A.BASENAME = T.ORDERFROM) ORDERFROM,
				       T.PROCESS_SEQ,
				       T.PRODUCE_SORT,
				       TO_CHAR(T.DELVRY_RANGE_MAX / 100, 'FM9999990.00') DELVRY_RANGE_MAX,
				       ('-' || TO_CHAR(abs(T.DELVRY_RANGE_MIN) / 100, 'FM9999990.00')) DELVRY_RANGE_MIN,
				       (TO_CHAR(T.DELVRY_RANGE_MAX, 'FM9999990.00') ||
				       DECODE(T.DELVRY_RANGE_TPE, '%', '%', '')) RANGE_MAX,
				       ('-' || TO_CHAR(abs(T.DELVRY_RANGE_MIN), 'FM9999990.00') ||
				       DECODE(T.DELVRY_RANGE_TPE, '%', '%', '')) RANGE_MIN,
				       TO_CHAR(T.DELVRY_EDATE, 'YYYY-MM-DD') DELVRY_EDATE,
				       T.ORDERCONTACT,
				       (DECODE(T.TRANSIT_TYP || ' ', ' ', '', T.TRANSIT_TYP || ' ') ||
				       DECODE(T.STATION_NM,
				               NULL,
				               (SELECT A.STATION_NM
				                  FROM SLM_BASE_STATION A
				                 WHERE A.STATION_NO = T.STATION_NO),
				               T.STATION_NM)) STATION_NM,
				       T.PLAN_QTY,
				       (SELECT MAX(A.BASENAME)
				          FROM COM_BASE_INFO A
				         WHERE A.BASECODE = T.PRD_CLS
				            OR A.BASENAME = T.PRD_CLS) PRD_CLS,
				       T.ROLL_MONTH,
				       (SELECT MAX(A.BASENAME)
				          FROM COM_BASE_INFO A
				         WHERE A.BASECODE = DECODE(TRIM(T.OUTS_BILLET_FL),
				                                   NULL,
				                                   '121802',
				                                   T.OUTS_BILLET_FL)) OUTS_BILLET_FL,
				       T.STUFF_PROPERTY,
				       T.SPEC_NAME,
				       T.PACKTYPE,
				       (SELECT A.BASENAME
				          FROM COM_BASE_INFO A
				         WHERE A.BASECODE = T.MONITORDEMAND) MONITORDEMAND,
				       (TO_CHAR(T.LENGTHMIN, 'FM9999999990.00') || '-' ||
				       TO_CHAR(T.LENGTHMAX, 'FM9999999990.00') || 'M') TECHNICALLEN,
				       T.ORDER_SPECIAL_DESC,
				       T2.REP_QTY,
				       T2.ORDER_UNIT,
				       T.SHRT_STOVE,
				       T.SIGL_LEN,
				       T.ENDLEN_SPECSTD,
				       T.GRADECODE_ALL,
				       T1.CRAFT_FILE_NO,
				       T1.CRAFT_FILE_MAN,
				       T1.STD_LG_NO,
				       T1.STD_ZG_NO,
				       T1.STD_GJG_NO,
				       T1.HEIGHT_NK_MIN,
				       T1.HEIGHT_NK_MAX,
				       TO_CHAR(T.LEN_TOEND_MIN, 'FM99990.00') LEN_TOEND_MIN,
				       TO_CHAR(T.LEN_TOEND_MAX, 'FM99990.00') LEN_TOEND_MAX,
				       T1.CRAFT_PATH,
				       T1.RCL_INFO,
				       T1.VERSION_NO,
				       T1.VERSION_DESC,
				       '销售合同' ORDERCONTRACT,
				       DECODE(T.PORDERSTATUS,
				              '0',
				              '待接收',
				              '1',
				              '已接收',
				              '2',
				              '已下发',
				              '3',
				              '生产中',
				              '4',
				              '生产完成',
				              '5',
				              '缴库完成',
				              '6',
				              '发运完毕',
				              '7',
				              '结算完毕',
				              '8',
				              '合同关闭') PORDERSTATUS,
				       T.DELIVERY_NO,
				       DECODE(T.JGORD_IS_OK, '0', '否', '1', '是', '2', '/') JGORD_IS_OK,
				       DECODE(T.DJBL_REQ_IS_OK, '0', '否', '1', '是', '2', '/') DJBL_REQ_IS_OK,
				       T2.ORD_LN_DLY_PK,
				       T2.REQ_NAME,
				       TO_CHAR(T2.REQ_TIME, 'YYYY-MM-DD HH24:MI:SS') REQ_TIME,
				       T2.PLAN_DEAL_NAME,
				       TO_CHAR(T2.PLAN_DEAL_TIME, 'YYYY-MM-DD HH24:MI:SS') PLAN_DEAL_TIME,
				       T2.R_NUM_ID
				  FROM PLN_SALEORDER_R_NUM T2, PLN_SALEORDER T, PLN_ORD_CRAFT_FILE T1
				 WHERE T.ORD_LN_DLY_PK(+) = T2.ORD_LN_DLY_PK
				   AND T1.ORDER_NO(+) = T.ORDER_NO
				   AND T1.ORDER_SEQ(+) = T.ORDER_SEQ
				   AND T1.CRAFT_FILE_NO(+) = T.CRAFT_FILE_NO
				   AND (T.ORDER_NO || '/' || T.ORDER_SEQ) LIKE '%' || ? || '%'
				   AND TO_DATE(TO_CHAR(T2.REQ_TIME, 'YYYY-MM-DD'), 'YYYY-MM-DD') BETWEEN
				       TO_DATE(?, 'YYYY/MM/DD') AND TO_DATE(?, 'YYYY/MM/DD')
				   AND T.PORDERSTATUS != '0'
			]]>
		</query>
		
		<query id="CoreReqRequest.addOrderRNum" desc="新增合同补量申请">
			<![CDATA[
				 INSERT INTO PLN_SALEORDER_R_NUM
					  (R_NUM_ID,
					   ORD_LN_DLY_PK,
					   ORDER_NO,
					   ORDER_SEQ,
					   DELIVERY_NO,
					   PRODUCCODE,
					   PRODUCNAME,
					   STD_CODE,
					   STD_NAME,
					   STEELCODE,
					   STEELNAME,
					   SPEC_CODE,
					   SPEC_NAME,
					   MODEL_CODE,
					   MODEL_DESC,
					   OUTDIAMETER,
					   WALLTHICK,
					   LENGTHDISC,
					   ORDER_UNIT,
					   REP_QTY,
					   REQWEIGHT,
					   REP_REASON,
					   REQ_NAME,
					   REQ_TIME)
					VALUES
					  ((SELECT 'REQ' || TO_CHAR(SYSDATE, 'YY') || TO_CHAR(SYSDATE, 'MM') ||
					          TO_CHAR(SYSDATE, 'DD') || LPAD(DECODE((MAX(SUBSTR(T.R_NUM_ID, 10)) + 1),
					                                                '',
					                                                '0001',
					                                                (MAX(SUBSTR(T.R_NUM_ID, 10)) + 1)),
					                                         4,
					                                         '0')
					     FROM PLN_SALEORDER_R_NUM T),
					   '#ORD_LN_DLY_PK#',
					   '#ORDER_NO#',
					   '#ORDER_SEQ#',
					   '#DELIVERY_NO#',
					   '#PRODUCCODE#',
					   '#PRODUCNAME#',
					   '#STD_CODE#',
					   '#STD_NAME#',
					   '#STEELCODE#',
					   '#STEELNAME#',
					   '#SPEC_CODE#',
					   '#SPEC_NAME#',
					   '#MODEL_CODE#',
					   '#MODEL_DESC#',
					   '#OUTDIAMETER#',
					   '#WALLTHICK#',
					   '#LENGTHDISC#',
					   '#ORDER_UNIT#',
					   '#REP_QTY#',
					   '#REQWEIGHT#',
					   '#REP_REASON#',
					   '#REQ_NAME#',
					   SYSDATE)
			]]>
		</query>
		
		<query id="CoreReqRequest.deleteOrderRNum" desc="删除合同补量申请">
			<![CDATA[
				DELETE FROM PLN_SALEORDER_R_NUM T WHERE T.R_NUM_ID = ?
			]]>
		</query>
		
		<query id="CoreReqRequest.doModify" desc="修改合同补量申请">
			<![CDATA[
				UPDATE PLN_SALEORDER_R_NUM T
				   SET T.REP_QTY    = '#REP_QTY#',
				       T.REP_REASON = '#REP_REASON#',
				       T.REQWEIGHT  = '#REQWEIGHT#'
				 WHERE T.R_NUM_ID = '#R_NUM_ID#'
			]]>
		</query>
		
		<query id="CoreReqRequest.confirmOrderRNum" desc="合同补量申请确认">
			<![CDATA[
				UPDATE PLN_SALEORDER_R_NUM T
				   SET T.CONFIRM_WT     = '#CONFIRM_WT#',
				       T.PLAN_DEAL_NAME = '#PLAN_DEAL_NAME#',
				       T.PLAN_DEAL_TIME = SYSDATE
				 WHERE T.R_NUM_ID = '#R_NUM_ID#'
			]]>
		</query>
		
	</queryMap>