<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="权限功能表查询">


	<query id="CoreDeliveryReview.GetDeliveryMaxPk" desc="获取当前合同行向下，最大交货行编号。">
		<![CDATA[ 
		SELECT MAX(ORD_LN_DLY_PK) FROM SLM_ORDER_LINE_DELIVERY WHERE ORD_LN_PK=?
		]]>
	</query>


	<query id="CoreDeliveryReview.doQuery" desc="">
		<![CDATA[ 
SELECT (CASE
         WHEN (SELECT COUNT(*)
                 FROM SLM_ORD_DESIGN_STS_PL_PC S,
                      SLM_ORD_DESIGN_MSC       T,
                      SLM_ORDER_LINE_DELIVERY  R
                WHERE S.ORD_LN_DLY_PK = R.ORD_LN_DLY_PK
                  AND A.ORD_PK = R.ORD_PK
                  AND R.VALIDFLAG = '1'
                  AND S.PRDCYC_MEET != 'S'
                  AND T.DESGIN_KEY = S.DESGIN_KEY
                  AND T.VALIDFLAG = '1'
                  AND S.VALIDFLAG = '1') > 0 THEN
          '0'
         WHEN (SELECT COUNT(*)
                 FROM SLM_ORD_DESIGN_STS_PL_PC S,
                      SLM_ORD_DESIGN_MSC       T,
                      SLM_ORDER_LINE_DELIVERY  R
                WHERE S.ORD_LN_DLY_PK = R.ORD_LN_DLY_PK
                  AND A.ORD_PK = R.ORD_PK
                  AND R.VALIDFLAG = '1'
                  AND S.PRDCYC_MEET != 'S'
                  AND T.DESGIN_KEY = S.DESGIN_KEY
                  AND T.VALIDFLAG = '1'
                  AND S.VALIDFLAG = '1') <= 0 AND
              (SELECT COUNT(*)
                 FROM SLM_ORD_DESIGN_STS_PL_PC S,
                      SLM_ORD_DESIGN_MSC       T,
                      SLM_ORDER_LINE_DELIVERY  R
                WHERE S.ORD_LN_DLY_PK = R.ORD_LN_DLY_PK
                  AND A.ORD_PK = R.ORD_PK
                  AND R.VALIDFLAG = '1'
                  AND T.DESGIN_KEY = S.DESGIN_KEY
                  AND T.VALIDFLAG = '1'
                  AND S.VALIDFLAG = '1') > 0 THEN
          '1'
         WHEN (SELECT COUNT(*)
                 FROM SLM_ORD_DESIGN_STS_PL_PC S,
                      SLM_ORD_DESIGN_MSC       T,
                      SLM_ORDER_LINE_DELIVERY  R
                WHERE S.ORD_LN_DLY_PK = R.ORD_LN_DLY_PK
                  AND A.ORD_PK = R.ORD_PK
                  AND R.VALIDFLAG = '1'
                  AND S.PRDCYC_MEET != 'S'
                  AND T.DESGIN_KEY = S.DESGIN_KEY
                  AND T.VALIDFLAG = '1'
                  AND S.VALIDFLAG = '1') <= 0 AND
              (SELECT COUNT(*)
                 FROM SLM_ORD_DESIGN_STS_PL_PC S,
                      SLM_ORD_DESIGN_MSC       T,
                      SLM_ORDER_LINE_DELIVERY  R
                WHERE S.ORD_LN_DLY_PK = R.ORD_LN_DLY_PK
                  AND A.ORD_PK = R.ORD_PK
                  AND R.VALIDFLAG = '1'
                  AND T.DESGIN_KEY = S.DESGIN_KEY
                  AND T.VALIDFLAG = '1'
                  AND S.VALIDFLAG = '1') <= 0 THEN
          '2'
         ELSE
          '1'
       END) ISDELIVERYD,
       ORD_PK,
       MANAG_NO,
       ORDER_NO,
       CUSTM_ORDER_NO,
       ORDER_TYP,
       ORDER_TYP_DESC,
       PROTCL_NO,
       CUSTOMER_NO,
       CUSTOMER_NM,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = SUPPLY_UNIT) SUPPLY_UNIT_NM,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = PRICE_FL) PRICE_FL_NM,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = CURRENCY) CURRENCY_NM,
       STLMT_UNIT_NO,
       STLMT_UNIT_NM,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = FST_DRAWEE_UNIT) FST_DRAWEE_UNIT_NM,
       LEGAL_PSN,
       AGENT,
       ADDRESS,
       ZIP_CODE,
       BANK,
       ACCOUNT,
       TAX_ID,
       PHONE,
       FAX,
       ORDER_WGT,
       ORDER_MNY_TAX,
       ORDER_MNY_NTAX,
       MNY_ASK_DESC,
       SIGN_PERSON,
       TO_CHAR(SIGN_DATE, 'YYYY-MM-DD') SIGN_DATE,
       TO_CHAR(ORDER_BDATE, 'YYYY-MM-DD') ORDER_BDATE,
       TO_CHAR(ORDER_EDATE, 'YYYY-MM-DD') ORDER_EDATE,
       ORDER_SCAN_NO,
       CUSTOMER_MODEL_FL,
       ORDER_MODEL_NO,
       SALE_ORG,
       SALE_ORG_DESC,
       SALE_AREA_NO,
       SALE_AREA_DESC,
       MEMO,
       ORDER_STS,
      -- ORDER_STS_DESC || DECODE(TH_EXAMINE_STATUS,'1','(计划审批通过)','2','(部门领导审批通过)','') ORDER_STS_DESC,
	 CASE
		WHEN SUPPLY_UNIT = '120504' and ORDER_STS >= 12020210 and ORDER_STS < 12020212 THEN
			ORDER_STS_DESC --|| DECODE(TH_EXAMINE_STATUS,'1','(待部门领导审批)','2','(待分管领导审批)','(待计划审批)')
		ELSE
			ORDER_STS_DESC
	END ORDER_STS_DESC,
       APPROVAL_MAN,
       APPROVAL_TIME,
       VALIDFLAG,
       CREATE_NAME,
       TO_CHAR(CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
       UPDATE_NAME,
       UPDATE_TIME,
       DELETE_NAME,
       DELETE_TIME,
       ORDER_YEAR,
       EFFECT_TIME,
       EFFECT_MAN,
       CLOSE_TIME,
       CLOSE_MAN,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = MNY_ASK_TYP) MNY_ASK_TYP_NM,
       SIGN_ADDRESS,
       SUPPLY_UNIT,
       PRICE_FL,
       CURRENCY,
       FST_DRAWEE_UNIT,
       MNY_ASK_TYP,
       NVL(ORDER_MODEL_DESC, ' ') ORDER_MODEL_DESC,
       CREATE_DEPT,
       MARKET_SYS,
       MARKET_SYS_DESC,
       ABRVITION,
       (SELECT REVIEW_F_RS FROM SLM_ORDER_REVIEW_ITEM_LIST B WHERE B.LIST_PK_VAL LIKE A.ORD_PK || '%' AND B.REVIEW_ITM = 'D' AND B.IS_CURT_REVIEW = '1' AND ROWNUM = 1) REVIEW_F_RS
  FROM SLM_ORDER_HEAD A
 WHERE ORDER_STS IN (?, ?, ?)
   AND LOWER(ORDER_NO) || '&' LIKE '%' || LOWER(?) || '%'
   AND (CASE
         WHEN (SELECT COUNT(*)
                 FROM SLM_ORD_DESIGN_STS_PL_PC S,
                      SLM_ORD_DESIGN_MSC       T,
                      SLM_ORDER_LINE_DELIVERY  R
                WHERE S.ORD_LN_DLY_PK = R.ORD_LN_DLY_PK
                  AND A.ORD_PK = R.ORD_PK
                  AND R.VALIDFLAG = '1'
                  AND S.PRDCYC_MEET != 'S'
                  AND T.DESGIN_KEY = S.DESGIN_KEY
                  AND T.VALIDFLAG = '1'
                  AND S.VALIDFLAG = '1') > 0 THEN
          '0'
         WHEN (SELECT COUNT(*)
                 FROM SLM_ORD_DESIGN_STS_PL_PC S,
                      SLM_ORD_DESIGN_MSC       T,
                      SLM_ORDER_LINE_DELIVERY  R
                WHERE S.ORD_LN_DLY_PK = R.ORD_LN_DLY_PK
                  AND A.ORD_PK = R.ORD_PK
                  AND R.VALIDFLAG = '1'
                  AND S.PRDCYC_MEET != 'S'
                  AND T.DESGIN_KEY = S.DESGIN_KEY
                  AND T.VALIDFLAG = '1'
                  AND S.VALIDFLAG = '1') <= 0 AND
              (SELECT COUNT(*)
                 FROM SLM_ORD_DESIGN_STS_PL_PC S,
                      SLM_ORD_DESIGN_MSC       T,
                      SLM_ORDER_LINE_DELIVERY  R
                WHERE S.ORD_LN_DLY_PK = R.ORD_LN_DLY_PK
                  AND A.ORD_PK = R.ORD_PK
                  AND R.VALIDFLAG = '1'
                  AND T.DESGIN_KEY = S.DESGIN_KEY
                  AND T.VALIDFLAG = '1'
                  AND S.VALIDFLAG = '1') > 0 THEN
          '1'
         WHEN (SELECT COUNT(*)
                 FROM SLM_ORD_DESIGN_STS_PL_PC S,
                      SLM_ORD_DESIGN_MSC       T,
                      SLM_ORDER_LINE_DELIVERY  R
                WHERE S.ORD_LN_DLY_PK = R.ORD_LN_DLY_PK
                  AND A.ORD_PK = R.ORD_PK
                  AND R.VALIDFLAG = '1'
                  AND S.PRDCYC_MEET != 'S'
                  AND T.DESGIN_KEY = S.DESGIN_KEY
                  AND T.VALIDFLAG = '1'
                  AND S.VALIDFLAG = '1') <= 0 AND
              (SELECT COUNT(*)
                 FROM SLM_ORD_DESIGN_STS_PL_PC S,
                      SLM_ORD_DESIGN_MSC       T,
                      SLM_ORDER_LINE_DELIVERY  R
                WHERE S.ORD_LN_DLY_PK = R.ORD_LN_DLY_PK
                  AND A.ORD_PK = R.ORD_PK
                  AND R.VALIDFLAG = '1'
                  AND T.DESGIN_KEY = S.DESGIN_KEY
                  AND T.VALIDFLAG = '1'
                  AND S.VALIDFLAG = '1') <= 0 THEN
          '2'
         ELSE
          '1'
       END) IN ('1', ?, '2')
   AND CREATE_TIME >= TO_DATE(?, 'YYYY-MM-DD HH24:mi:ss')
   AND CREATE_TIME <= TO_DATE(?, 'YYYY-MM-DD HH24:mi:ss')
   AND VALIDFLAG IN (1, ?)
   AND ORDER_TYP != '120102'

			  
		]]>
	</query>

	<query id="CoreDeliveryReview.doQueryMpsUpdate" desc="mps调整界面查询合同头信息">
		<![CDATA[ 
SELECT 
       ORD_PK,
       MANAG_NO,
       ORDER_NO,
       CUSTM_ORDER_NO,
       ORDER_TYP,
       ORDER_TYP_DESC,
       PROTCL_NO,
       CUSTOMER_NO,
       CUSTOMER_NM,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = SUPPLY_UNIT) SUPPLY_UNIT_NM,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = PRICE_FL) PRICE_FL_NM,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = CURRENCY) CURRENCY_NM,
       STLMT_UNIT_NO,
       STLMT_UNIT_NM,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = FST_DRAWEE_UNIT) FST_DRAWEE_UNIT_NM,
       LEGAL_PSN,
       AGENT,
       ADDRESS,
       ZIP_CODE,
       BANK,
       ACCOUNT,
       TAX_ID,
       PHONE,
       FAX,
       ORDER_WGT,
       ORDER_MNY_TAX,
       ORDER_MNY_NTAX,
       MNY_ASK_DESC,
       SIGN_PERSON,
       TO_CHAR(SIGN_DATE, 'YYYY-MM-DD') SIGN_DATE,
       TO_CHAR(ORDER_BDATE, 'YYYY-MM-DD') ORDER_BDATE,
       TO_CHAR(ORDER_EDATE, 'YYYY-MM-DD') ORDER_EDATE,
       ORDER_SCAN_NO,
       CUSTOMER_MODEL_FL,
       ORDER_MODEL_NO,
       SALE_ORG,
       SALE_ORG_DESC,
       SALE_AREA_NO,
       SALE_AREA_DESC,
       MEMO,
       ORDER_STS,
       ORDER_STS_DESC,
       APPROVAL_MAN,
       APPROVAL_TIME,
       VALIDFLAG,
       CREATE_NAME,
       TO_CHAR(CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
       UPDATE_NAME,
       UPDATE_TIME,
       DELETE_NAME,
       DELETE_TIME,
       ORDER_YEAR,
       EFFECT_TIME,
       EFFECT_MAN,
       CLOSE_TIME,
       CLOSE_MAN,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = MNY_ASK_TYP) MNY_ASK_TYP_NM,
       SIGN_ADDRESS,
       SUPPLY_UNIT,
       PRICE_FL,
       CURRENCY,
       FST_DRAWEE_UNIT,
       MNY_ASK_TYP,
       NVL(ORDER_MODEL_DESC, ' ') ORDER_MODEL_DESC,
       CREATE_DEPT,
       MARKET_SYS,
       MARKET_SYS_DESC,
       ABRVITION
  FROM SLM_ORDER_HEAD A
 WHERE (ORDER_STS >= '12020210' or ORDER_STS='12020202')
   AND LOWER(ORDER_NO) || '&' LIKE '%' || LOWER(?) || '%'
   AND CREATE_TIME >= TO_DATE(?, 'YYYY-MM-DD HH24:mi:ss')
   AND CREATE_TIME <= TO_DATE(?, 'YYYY-MM-DD HH24:mi:ss')
   AND VALIDFLAG ='1'
   AND ORDER_TYP != '120102'

			  
		]]>
	</query>
	
	<query id="CoreDeliveryReview.GetOrderLineForMpsUpdate" desc="根据合同头号，获取合同行信息。">
		<![CDATA[ 
			   SELECT ORD_PK,
			       ORD_LN_PK,
			       ORDER_SEQ,
			       CUST_ALPHA_NO,
			       PSC,
			       PSC_DESC,
			       MSC,
			       MSC_DESC,
			       PRODUCCODE,
			       PRODUCNAME,
			       STD_CODE,
			       STD_NAME,
			       STEELCODE,
			       STEELNAME,
			       ORDER_SPEC_CODE,
			       ORDER_SPEC_DESC,
			       SPEC_CODE,
			       SPEC_NAME,
			       DIMATER,
			       HEIGHT,
			       MODEL_CODE,
			       MODEL_DESC,
			       LEN_NO,
			       LEN_DESC,
			       LEN_UNIT,
			       ORDER_QTY,
			       ORDER_UNIT,
			       ORD_ENSU_TOTL_LEN,
			       ROUND(PRDCT_WGT,3) PRDCT_WGT,
			       MPS_NO,
			       MPS_NO_INPUT,
			       DECODE(T.MPS_NO_FILE ,NULL,'无MPS文本','最近上传的MPS文本'||' '||T.MPS_NO_FILE) MPS_NO_FILE ,
			       T.MPS_NO_FILE MPS_FILE,
			       DECODE(MPS_FL,'1','TRUE','FALSE') MPS_FL,
			       DELVRY_RANGE_TPE,
			       DELVRY_RANGE_MIN,
			       DELVRY_RANGE_MAX,
			          '(-'
			     || TO_CHAR (DELVRY_RANGE_MIN)
			     || DECODE (DELVRY_RANGE_TPE, '%', '%', ORDER_UNIT)
			     || ','
			     || TO_CHAR (DELVRY_RANGE_MAX)
			     || DECODE (DELVRY_RANGE_TPE, '%', '%', ORDER_UNIT)
			     || ')' DELVRY_RANGE,
			       FINAL_USER,
			       FINAL_USER_DESC,
			       TO_CHAR (DELVRY_EDATE, 'YYYY-MM-DD') DELVRY_EDATE
			  FROM SLM_ORDER_LINE T
			 WHERE ORD_PK = ?
			 and (T.ORDER_LN_STATUS >= '12020210' or T.ORDER_LN_STATUS='12020202')  AND VALIDFLAG = '1'
		]]>
	</query>

	<query id="CoreDeliveryReview.GetOrderLine" desc="根据合同头号，获取合同行信息。">
		<![CDATA[ 
			   SELECT ORD_PK,
			       ORD_LN_PK,
			       ORDER_SEQ,
			       CUST_ALPHA_NO,
			       PSC,
			       PSC_DESC,
			       MSC,
			       MSC_DESC,
			       PRODUCCODE,
			       PRODUCNAME,
			       STD_CODE,
			       STD_NAME,
			       STEELCODE,
			       STEELNAME,
			       ORDER_SPEC_CODE,
			       ORDER_SPEC_DESC,
			       SPEC_CODE,
			       SPEC_NAME,
			       DIMATER,
			       HEIGHT,
			       MODEL_CODE,
			       MODEL_DESC,
			       LEN_NO,
			       LEN_DESC,
			       LEN_UNIT,
			       ORDER_QTY,
			       ORDER_UNIT,
			       ORD_ENSU_TOTL_LEN,
			       ROUND(PRDCT_WGT,3) PRDCT_WGT,
			       MPS_NO,
			       MPS_NO_INPUT,
			       DECODE(MPS_FL,'1','TRUE','FALSE') MPS_FL,
			       DELVRY_RANGE_TPE,
			       DELVRY_RANGE_MIN,
			       DELVRY_RANGE_MAX,
			          '(-'
			     || TO_CHAR (DELVRY_RANGE_MIN)
			     || DECODE (DELVRY_RANGE_TPE, '%', '%', ORDER_UNIT)
			     || ','
			     || TO_CHAR (DELVRY_RANGE_MAX)
			     || DECODE (DELVRY_RANGE_TPE, '%', '%', ORDER_UNIT)
			     || ')' DELVRY_RANGE,
			       FINAL_USER,
			       FINAL_USER_DESC,
			       TO_CHAR (DELVRY_EDATE, 'YYYY-MM-DD') DELVRY_EDATE
			  FROM SLM_ORDER_LINE T
			 WHERE ORD_PK = ?  AND VALIDFLAG = '1'
		]]>
	</query>


	<query id="CoreDeliveryReview.GetOrderLineDelivery" desc="根据合同头号，获取交货行信息。">
		<![CDATA[ 
			   SELECT DECODE(D.PRDCYC_MEET, 'W', '等待', 'S', '满足', 'F', '不满足','等待') PRDCYC_MEET,
			   	   A.ORD_PK,
			       A.ORD_LN_PK,
			       A.ORDER_SEQ,
			       B.ORD_LN_DLY_PK,
			       B.DELIVERY_NO,
			       TO_CHAR (B.DELVRY_EDATE, 'YYYY-MM-DD') DELVRY_EDATE,
			       B.DELVRY_QTY,
			       B.ORDER_UNIT,
			       B.WGT_ESTMT,
			       B.RECEIV_NO,
			       B.RECEIV_NM,
			       B.VALIDFLAG,
			       C.DESGIN_KEY,
			       C.MSC_PLINE,
			       TO_CHAR (C.RCMD_DELVRY_EDATE, 'YYYY-MM-DD') RCMD_DELVRY_EDATE,
			       ROUND(C.PRD_CYC,4) PRD_CYC,
			       ROUND(C.PRD_CYC_BTCH,4) PRD_CYC_BTCH,
			       C.N_MATERIAL_FL,
			       C.CYC_EDIT
			  FROM SLM_ORDER_LINE           A,
			       SLM_ORDER_LINE_DELIVERY  B,
			       SLM_ORD_DESIGN_MSC_PL_PC C,
			       SLM_ORD_DESIGN_STS_PL_PC D,
			       SLM_ORD_DESIGN_MSC       E
			 WHERE A.ORD_PK = ?
		 AND B.ORD_LN_PK = A.ORD_LN_PK 
         AND B.ORD_LN_DLY_PK = C.ORD_LN_DLY_PK(+)
         AND C.ORD_LN_DLY_PK = D.ORD_LN_DLY_PK(+)
         AND A.ORD_LN_PK = E.ORD_LN_PK
         AND E.VALIDFLAG = '1'
         AND E.DESGIN_KEY = C.DESGIN_KEY
         AND C.DESGIN_KEY = D.DESGIN_KEY(+)
         AND B.VALIDFLAG = '1'
         AND A.VALIDFLAG = '1'
         
		]]>
	</query>


	<query id="CoreDeliveryReview.doDelete" desc="删除交货行信息。">
		<![CDATA[ 
		DELETE 
	    FROM SLM_ORDER_LINE_DELIVERY T
	    WHERE ORD_LN_DLY_PK=?  
			   
		]]>
	</query>

	<query id="CoreDeliveryReview.SelectDelete" desc="查询删除交货行信息。">
		<![CDATA[ 
		SELECT COUNT(1)
	    FROM SLM_ORDER_LINE_DELIVERY T
	    WHERE ORD_LN_PK=?  
			   
		]]>
	</query>


	<query id="CoreDeliveryReview.doUpdate" desc="修改交货行信息">
		<![CDATA[ 
			 UPDATE SLM_ORDER_LINE_DELIVERY
			    SET DELVRY_EDATE = TO_DATE(?,'YYYY-MM-DD'), DELVRY_QTY = ?, WGT_ESTMT = ?
			  WHERE ORD_LN_DLY_PK = ?
		]]>
	</query>



	<query id="CoreDeliveryReview.doAdd" desc="新增交货行信息">
		<![CDATA[ 
			 INSERT INTO SLM_ORDER_LINE_DELIVERY
				  (ORD_PK,
				   ORD_LN_PK,
				   ORD_LN_DLY_PK,
				   DELIVERY_NO,
				   DELVRY_EDATE,
				   DELVRY_QTY,
				   ORDER_UNIT,
				   WGT_ESTMT,
				   RECEIV_NO,
				   RECEIV_NM
				   )
				VALUES
				  (?, ?, (SELECT  ? ||LPAD(TO_NUMBER(NVL(MAX(SUBSTR(ORD_LN_DLY_PK,36,3)), '0')) + 1, 3, '0')
                          FROM SLM_ORDER_LINE_DELIVERY  WHERE ORD_LN_PK = ?)
				  ,(SELECT  LPAD(TO_NUMBER(NVL(MAX(SUBSTR(ORD_LN_DLY_PK,36,3)), '0')) + 1, 3, '0')
                          FROM SLM_ORDER_LINE_DELIVERY  WHERE ORD_LN_PK = ?), TO_DATE(?,'YYYY-MM-DD'), ?, ?, ?, ?, ?)
		]]>
	</query>

	<query id="CoreDeliveryReview.doUpdateHeadSts" desc="修改合同头状态">
		<![CDATA[ 
			 UPDATE SLM_ORDER_HEAD 
			 SET ORDER_STS=?,
			 ORDER_STS_DESC=? 
			 WHERE ORD_PK=?
		]]>
	</query>

	<query id="CoreDeliveryReview.doUpdateLnStatus" desc="修改合同行状态">
		<![CDATA[ 
			 UPDATE SLM_ORDER_LINE 
			 SET ORDER_LN_STATUS=? 
			 WHERE ORD_PK=?
		]]>
	</query>

	<query id="CoreDeliveryReview.doUpdateDelStatus" desc="修改交货行状态">
		<![CDATA[ 
			 UPDATE SLM_ORDER_LINE_DELIVERY 
			 SET DELIVERY_STATUS=? 
			 WHERE ORD_PK=?
		]]>
	</query>

	<query id="CoreDeliveryReview.SelectMSCPLPCLST" desc="修改交货行状态">
		<![CDATA[ 
			  SELECT
    T.PROCESS_CODE,
    T.PROCESS_DESC,
    T.REVIEW_ASK,
    TO_CHAR(T.LST_PRD_DATE,'YYYY-MM-DD') LST_PRD_DATE,
    DECODE(T2.PRDCYC_MEET, 'W', '等待', 'F', '不满足', 'S', '满足', '') PRDCYC_MEET

    FROM SLM_ORD_DESIGN_MSC_PL_PC_LST T, 
       SLM_ORD_DESIGN_STS_PL_PC_LST T2
    WHERE T.ORD_LN_DLY_PK = T2.ORD_LN_DLY_PK
   AND T.ORD_LN_DLY_PK = ?
   AND T.PROCESS_CODE = T2.PROCESS_CDOE
   AND T.DESGIN_KEY = T2.DESGIN_KEY	
   ORDER BY PROCESS_CODE 
		]]>
	</query>

	<query id="CoreDeliveryReview.SELECTWELLCODE" desc="修改交货行状态">
		<![CDATA[ 
			 
    SELECT WELL_CODE, WELL_NAME
    FROM SLM_ORD_DESIGN_MSC_PL_GX_PRL T
    WHERE T.DESGIN_KEY = ?
    AND T.PROCESS_CODE = ?
			 
		]]>
	</query>

	<query id="CoreDeliveryReview.GETWELLDETAIL" desc="修改交货行状态">
		<![CDATA[ 
	SELECT R.*,
       NVL(Q.USE_WGT, '0') USE_WGT,
       NVL(Q.USE_MONTH, ?) USE_MONTH,
       (R.MONTH - NVL(Q.USE_WGT, '0')) MONTHREMAIN
    FROM (SELECT T.WELL_CODE,
               T.WELL_NAME,
               DECODE(?,
                      '1',
                      T.MONTH_1,
                      '2',
                      T.MONTH_2,
                      '3',
                      T.MONTH_3,
                      '4',
                      T.MONTH_4,
                      '5',
                      T.MONTH_5,
                      '6',
                      T.MONTH_6,
                      '7',
                      T.MONTH_7,
                      '8',
                      T.MONTH_8,
                      '9',
                      T.MONTH_9,
                      '10',
                      T.MONTH_10,
                      '11',
                      T.MONTH_11,
                      '12',
                      T.MONTH_12,
                      '') MONTH
          FROM COM_BASE_WELL_MONTH T
         WHERE T.YEAR = ?
           AND T.WELL_CODE = ?) R,
       
       (SELECT NVL(S.USE_MONTH, ?) USE_MONTH,
                NVL(SUM(S.USE_WGT), '0') USE_WGT,
               WELL_CODE
          FROM SLM_WELL_USE_LIST S
         WHERE S.WELL_CODE = ?
           AND S.USE_MONTH = ?
           --AND S.SALE_ORG  = ?
           AND S.WELL_YEAR = ?
           GROUP BY USE_MONTH,WELL_CODE) Q
    WHERE R.WELL_CODE = Q.WELL_CODE(+)

   	]]>
	</query>

	<query id="CoreDeliveryReview.GetOrderLineInfo" desc="获取合同行信息">
		<![CDATA[ 
	 SELECT ORD_PK,
       ORD_LN_PK,
       ORDER_SEQ,
       CUST_ALPHA_NO,
       PSC,
       PSC_DESC,
       MSC,
       MSC_DESC,
       MSC_STYLE,
       USE_CODE,
       USE_DESC,
       PRD_CLS,
       PRODUCCODE,
       PRODUCNAME,
       STD_CODE,
       STD_NAME,
       STEELCODE,
       STEELNAME,
       STD_STYLE,
       STD_STYLE_DESC,
       ORDER_SPEC_CODE,
       ORDER_SPEC_DESC,
       SPEC_CODE,
       SPEC_NAME,
       DIMATER,
       HEIGHT,
       MODEL_CODE,
       MODEL_DESC,
       LEN_NO,
       LEN_DESC,
       LEN_UNIT,
       LEN_MIN,
       LEN_MAX,
       SHRT_LEN_RATO,
       SHORTEST,
       LONG_LEN_RATO,
       LONGEST,
       SHRT_STOVE,
       AVG_LEN_MIN,
       DIFRNC_LEN_MAX,
       SIGL_LEN,
       ORDER_UNIT,
       ORDER_QTY,
       ORD_ENSU_TOTL_LEN,
       PRDCT_WGT,
       DELVRY_RANGE_TPE,
       DELVRY_RANGE_MIN,
       DELVRY_RANGE_MAX,
       FINAL_USER,
       FINAL_USER_DESC,
       OUTS_BILLET_FL,
       OUTS_STL_PIPE_FL,
       ASSEL_FL,
       PRODUCER_FL,
       PRDCR_NO,
       PRDCR_DESC,
       MPS_FL,
       MPS_NO,
       MPS_DESC,
       DELVRY_BDATE,
       DELVRY_EDATE,
       DELVRY_DESC,
       TRANS_DESC,
       ADD_ASK_NO,
       ORDER_ADD_DESC,
       ORDER_SPECIAL_FL,
       ORDER_SPECIAL_HEAD,
       ORDER_SPECIAL_PATH,
       ORDER_SPECIAL_DESC,
       ZBS,
       ORDER_PRICE,
       TRANS_PRICE,
       TEST_ID,
       TEST_PRICE,
       OUT_PRICE,
       BALNCE_PRICE,
       BE_ORDER_LN_STATUS,
       BE_OBJ_STS_OP,
       ORDER_LN_STATUS,
       OBJ_STS_OP,
       MEMO,
       VALIDFLAG,
       CREATE_NAME,
       CREATE_TIME,
       UPDATE_NAME,
       UPDATE_TIME,
       DELETE_NAME,
       DELETE_TIME,
       ORD_LN_PK_OLD
  FROM SLM_ORDER_LINE T
  WHERE T.ORD_PK = ?
   AND T.VALIDFLAG = '1'
	 
		]]>
	</query>

	<query id="CoreDeliveryReview.GetOrderLineDeliveryInfo" desc="查询交货行信息">
		<![CDATA[ 
		 SELECT ORD_PK,
       ORD_LN_PK,
       ORD_LN_DLY_PK,
       DELIVERY_NO,
       DELVRY_BDATE,
       DELVRY_EDATE,
       DELVRY_QTY,
       ORDER_UNIT,
       WGT_ESTMT,
       ENSU_TOTL_LEN,
       RECEIV_NO,
       RECEIV_NM,
       DELVRY_ADDR,
       AGENCY_FL,
       RECEIV_ADDR,
       TRANSIT_PLAN,
       TRANSIT_MNY,
       BE_DELIVERY_STATUS,
       BE_OBJ_STS_OP,
       DELIVERY_STATUS,
       OBJ_STS_OP,
       VALIDFLAG,
       CREATE_NAME,
       CREATE_TIME,
       UPDATE_NAME,
       UPDATE_TIME,
       DELETE_NAME,
       DELETE_TIME
  FROM SLM_ORDER_LINE_DELIVERY T
 WHERE T.ORD_PK = ?
   AND T.ORD_LN_PK = ?
   AND T.VALIDFLAG = '1'
		 	 
 
		]]>
	</query>

	<query id="CoreDeliveryReview.GetWellUse" desc="产能井耗用">
        <![CDATA[ 
       SELECT         
       NVL(SUM(USE_WGT), '0') USE_WGT
   FROM SLM_WELL_USE_LIST T
   WHERE T.WELL_CODE = ?
   AND T.WELL_YEAR = TO_NUMBER(?)
   AND T.USE_MONTH = TO_NUMBER(?)
         ]]>
	</query>
	
	<query id="CoreDeliveryReview.GetWellUseSaleOrg" desc="产能井耗用">
        <![CDATA[ 
       SELECT         
       NVL(SUM(USE_WGT), '0') USE_WGT
   FROM SLM_WELL_USE_LIST T
   WHERE T.WELL_CODE = ?
   AND T.WELL_YEAR = TO_NUMBER(?)
   AND T.USE_MONTH = TO_NUMBER(?)
   AND T.SALE_ORG  = ?
         ]]>
	</query>

	<query id="CoreDeliveryReview.GetWellFree" desc="产能井耗用">
        <![CDATA[ 
       SELECT         
       NVL(SUM(USE_WGT), '0') USE_WGT
  FROM SLM_WELL_USE_LIST T
  WHERE T.WELL_CODE = ?
  AND T.WELL_YEAR = TO_NUMBER(?)
  AND T.USE_MONTH = TO_NUMBER(?)
  AND T.SALE_ORG  = ?
  AND T.USE_TYPE  = '释放'

         ]]>
	</query>

	<query id="CoreDeliveryReview.InsertWellUseList" desc="插入产能井">
        <![CDATA[ 
   			INSERT INTO SLM_WELL_USE_LIST
  (WELL_CODE,
   WELL_NAME,
   WELL_YEAR,
   USE_MONTH,
   USE_CODE,
   SALE_ORG,
   SALE_ORG_DESC,
   ORD_LN_DLY_PK,
   USE_OBJ,
   USE_TYPE,
   USE_WGT,
   CREATE_NAME,
   CREATE_TIME)
   VALUES
  (?,
   (SELECT WELL_NAME FROM COM_BASE_WELL WHERE WELL_CODE = ?),
   ?,
   ?,
   (SELECT SUBSTR(?, 3, 2) || LPAD(?, 2, '0') ||
           LPAD(TO_NUMBER(NVL(SUBSTR(MAX(USE_CODE), 5, 6), 0)) + 1, 6, '0')
      FROM SLM_WELL_USE_LIST
     WHERE WELL_CODE = ?
       AND WELL_YEAR = ?
       AND USE_MONTH = ?),
   ?,
   ?,
   ?,
   ?,
   ?,
   TO_NUMBER(?),?,SYSDATE)
   			
         ]]>
	</query>

	<query id="CoreDeliveryReview.DeleteWellUse" desc="产能井耗用">
        <![CDATA[ 
       DELETE        
       FROM SLM_WELL_USE_LIST T
       WHERE T.WELL_CODE = ?      
       AND T.USE_OBJ   = '0'
       AND T.USE_TYPE  = '消耗'

         ]]>
	</query>

	<query id="CoreDeliveryReview.FreeWellUse" desc="产能井耗用">
        <![CDATA[ 
      UPDATE SLM_WELL_USE_LIST
      SET USE_WGT = -USE_WGT, USE_TYPE = '释放'
      WHERE WELL_CODE = ?
      AND ORD_LN_DLY_PK = ?
      AND USE_WGT > 0
	  AND USE_TYPE = '消耗'

         ]]>
	</query>

	<query id="CoreDeliveryReview.GetOrderLineDeliveryStatus" desc="根据合同头号，获取交货行信息。">
		<![CDATA[ 
			   SELECT DECODE(D.PRDCYC_MEET, 'W', '等待', 'S', '满足', 'F', '不满足','等待') PRDCYC_MEET,
			   	   A.ORD_PK
			      
			  FROM SLM_ORDER_LINE           A,
			       SLM_ORDER_LINE_DELIVERY  B,
			       SLM_ORD_DESIGN_MSC_PL_PC C,
			       SLM_ORD_DESIGN_STS_PL_PC D
			 WHERE A.ORD_PK = ?
			   AND A.ORD_LN_PK = B.ORD_LN_PK
			   AND A.ORD_PK    = B.ORD_PK
			   AND B.ORD_LN_DLY_PK = C.ORD_LN_DLY_PK(+)
			   AND B.ORD_LN_DLY_PK = D.ORD_LN_DLY_PK 
			   AND C.DESGIN_KEY  = D.DESGIN_KEY(+)
			   AND B.VALIDFLAG = '1'
			   AND A.VALIDFLAG = '1'
			   
		]]>
	</query>

	<query id="CoreDeliveryReview.SetOrderLineDlyEtime" desc="根据合同头号，获取交货行信息。">
		<![CDATA[ 
			  UPDATE SLM_ORDER_LINE T
     SET T.DELVRY_EDATE = TO_DATE(?,'YYYY-MM-DD'),
     	 T.DELVRY_DESC = ?
     WHERE T.ORD_LN_PK = ?
     AND T.VALIDFLAG = '1'
			  
			   
		]]>
	</query>

	<query id="CoreDeliveryReview.getMpsFlag" desc="根据合同头号，获取交货行信息。">
		<![CDATA[ 
			 
      SELECT TO_CHAR(WM_Concat(T.MPS_FL)) MPS_FL
    FROM SLM_ORDER_LINE T
   WHERE T.ORD_PK = ?
     AND T.VALIDFLAG = '1'

		]]>
	</query>

	<query id="CoreDeliveryReview.getLineMpsComplete" desc="根据合同头号，获取交货行信息。">
		<![CDATA[ 
		 SELECT  1
        FROM SLM_ORDER_LINE T
        WHERE T.ORD_PK = ?
        AND T.VALIDFLAG = '1'
        AND T.MPS_FL = '1'
        AND (TRIM(T.MPS_NO_INPUT) IS NULL OR TRIM(T.MPS_NO_FILE) IS NULL)
        
		]]>
	</query>
	
	<query id="CoreDeliveryReview.getOrdStatus" desc="根据合同头号，获取交货行信息。">
		<![CDATA[ 
		SELECT  T.ORDER_STS
        FROM SLM_ORDER_HEAD T
        WHERE T.ORD_PK = ?
        AND T.VALIDFLAG = '1'
        
		]]>
	</query>


	<query id="CoreDeliveryReview.updateThExamineStatus" desc="修改天淮评审状态">
		<![CDATA[
			update SLM_ORDER_HEAD set TH_EXAMINE_STATUS = {0}
			where TH_EXAMINE_STATUS = {1} and ORD_PK = {2} and VALIDFLAG = '1'
		]]>
	</query>
</queryMap>