<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="合同产能井调整">
<query id="CoreWellAdjust.getWellUse" desc="查询产能井占用情况">
	<![CDATA[
SELECT T.WELL_CODE,
       T.WELL_NAME,
       T.WELL_YEAR,
       (SELECT NVL(SUM(A1.MONTH_1), 0)
          FROM COM_BASE_WELL_MONTH A1
         WHERE A1.YEAR = T.WELL_YEAR
           AND A1.WELL_CODE = T.WELL_CODE) well_Wgt1,
       (SELECT NVL(SUM(A1.USE_WGT), 0)
          FROM SLM_WELL_USE_LIST A1
         WHERE A1.WELL_YEAR = T.WELL_YEAR
           AND A1.WELL_CODE = T.WELL_CODE
           AND A1.USE_MONTH = '1') use_Wgt1,
       (SELECT NVL(SUM(A1.MONTH_2), 0)
          FROM COM_BASE_WELL_MONTH A1
         WHERE A1.YEAR = T.WELL_YEAR
           AND A1.WELL_CODE = T.WELL_CODE) well_Wgt2,
       (SELECT NVL(SUM(A1.USE_WGT), 0)
          FROM SLM_WELL_USE_LIST A1
         WHERE A1.WELL_YEAR = T.WELL_YEAR
           AND A1.WELL_CODE = T.WELL_CODE
           AND A1.USE_MONTH = '2') use_Wgt2,
       (SELECT NVL(SUM(A1.MONTH_3), 0)
          FROM COM_BASE_WELL_MONTH A1
         WHERE A1.YEAR = T.WELL_YEAR
           AND A1.WELL_CODE = T.WELL_CODE) well_Wgt3,
       (SELECT NVL(SUM(A1.USE_WGT), 0)
          FROM SLM_WELL_USE_LIST A1
         WHERE A1.WELL_YEAR = T.WELL_YEAR
           AND A1.WELL_CODE = T.WELL_CODE
           AND A1.USE_MONTH = '3') use_Wgt3,
       (SELECT NVL(SUM(A1.MONTH_4), 0)
          FROM COM_BASE_WELL_MONTH A1
         WHERE A1.YEAR = T.WELL_YEAR
           AND A1.WELL_CODE = T.WELL_CODE) well_Wgt4,
       (SELECT NVL(SUM(A1.USE_WGT), 0)
          FROM SLM_WELL_USE_LIST A1
         WHERE A1.WELL_YEAR = T.WELL_YEAR
           AND A1.WELL_CODE = T.WELL_CODE
           AND A1.USE_MONTH = '4') use_Wgt4,
       (SELECT NVL(SUM(A1.MONTH_5), 0)
          FROM COM_BASE_WELL_MONTH A1
         WHERE A1.YEAR = T.WELL_YEAR
           AND A1.WELL_CODE = T.WELL_CODE) well_Wgt5,
       (SELECT NVL(SUM(A1.USE_WGT), 0)
          FROM SLM_WELL_USE_LIST A1
         WHERE A1.WELL_YEAR = T.WELL_YEAR
           AND A1.WELL_CODE = T.WELL_CODE
           AND A1.USE_MONTH = '5') use_Wgt5,
       (SELECT NVL(SUM(A1.MONTH_6), 0)
          FROM COM_BASE_WELL_MONTH A1
         WHERE A1.YEAR = T.WELL_YEAR
           AND A1.WELL_CODE = T.WELL_CODE) well_Wgt6,
       (SELECT NVL(SUM(A1.USE_WGT), 0)
          FROM SLM_WELL_USE_LIST A1
         WHERE A1.WELL_YEAR = T.WELL_YEAR
           AND A1.WELL_CODE = T.WELL_CODE
           AND A1.USE_MONTH = '6') use_Wgt6,
       (SELECT NVL(SUM(A1.MONTH_7), 0)
          FROM COM_BASE_WELL_MONTH A1
         WHERE A1.YEAR = T.WELL_YEAR
           AND A1.WELL_CODE = T.WELL_CODE) well_Wgt7,
       (SELECT NVL(SUM(A1.USE_WGT), 0)
          FROM SLM_WELL_USE_LIST A1
         WHERE A1.WELL_YEAR = T.WELL_YEAR
           AND A1.WELL_CODE = T.WELL_CODE
           AND A1.USE_MONTH = '7') use_Wgt7,
       (SELECT NVL(SUM(A1.MONTH_8), 0)
          FROM COM_BASE_WELL_MONTH A1
         WHERE A1.YEAR = T.WELL_YEAR
           AND A1.WELL_CODE = T.WELL_CODE) well_Wgt8,
       (SELECT NVL(SUM(A1.USE_WGT), 0)
          FROM SLM_WELL_USE_LIST A1
         WHERE A1.WELL_YEAR = T.WELL_YEAR
           AND A1.WELL_CODE = T.WELL_CODE
           AND A1.USE_MONTH = '8') use_Wgt8,
       (SELECT NVL(SUM(A1.MONTH_9), 0)
          FROM COM_BASE_WELL_MONTH A1
         WHERE A1.YEAR = T.WELL_YEAR
           AND A1.WELL_CODE = T.WELL_CODE) well_Wgt9,
       (SELECT NVL(SUM(A1.USE_WGT), 0)
          FROM SLM_WELL_USE_LIST A1
         WHERE A1.WELL_YEAR = T.WELL_YEAR
           AND A1.WELL_CODE = T.WELL_CODE
           AND A1.USE_MONTH = '9') use_Wgt9,
       (SELECT NVL(SUM(A1.MONTH_10), 0)
          FROM COM_BASE_WELL_MONTH A1
         WHERE A1.YEAR = T.WELL_YEAR
           AND A1.WELL_CODE = T.WELL_CODE) well_Wgt10,
       (SELECT NVL(SUM(A1.USE_WGT), 0)
          FROM SLM_WELL_USE_LIST A1
         WHERE A1.WELL_YEAR = T.WELL_YEAR
           AND A1.WELL_CODE = T.WELL_CODE
           AND A1.USE_MONTH = '10') use_Wgt10,
       (SELECT NVL(SUM(A1.MONTH_11), 0)
          FROM COM_BASE_WELL_MONTH A1
         WHERE A1.YEAR = T.WELL_YEAR
           AND A1.WELL_CODE = T.WELL_CODE) well_Wgt11,
       (SELECT NVL(SUM(A1.USE_WGT), 0)
          FROM SLM_WELL_USE_LIST A1
         WHERE A1.WELL_YEAR = T.WELL_YEAR
           AND A1.WELL_CODE = T.WELL_CODE
           AND A1.USE_MONTH = '11') use_Wgt11,
       (SELECT NVL(SUM(A1.MONTH_12), 0)
          FROM COM_BASE_WELL_MONTH A1
         WHERE A1.YEAR = T.WELL_YEAR
           AND A1.WELL_CODE = T.WELL_CODE) well_Wgt12,
       (SELECT NVL(SUM(A1.USE_WGT), 0)
          FROM SLM_WELL_USE_LIST A1
         WHERE A1.WELL_YEAR = T.WELL_YEAR
           AND A1.WELL_CODE = T.WELL_CODE
           AND A1.USE_MONTH = '12') use_Wgt12
  FROM SLM_WELL_USE_LIST T
 WHERE T.WELL_YEAR = ?
   AND T.USE_TYPE = '消耗'
   AND T.CREATE_TIME = (SELECT MAX(F.CREATE_TIME)
                          FROM SLM_WELL_USE_LIST F
                         WHERE F.WELL_CODE = T.WELL_CODE
                           AND F.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
                           AND F.USE_TYPE = '消耗')
 GROUP BY T.WELL_CODE, T.WELL_NAME, T.WELL_YEAR		
	]]>
	</query>    
    
    
    <query id="CoreWellAdjust.getWellOrder" desc="查询产能井合同">
	<![CDATA[
SELECT A.ORD_PK,
       B.ORD_LN_PK,
       C.ORD_LN_DLY_PK,
       (A.ORDER_NO || '/' || B.ORDER_SEQ) MANAG_NO,
       A.ORDER_NO,
       A.ORDER_TYP,
       A.ORDER_TYP_DESC,
       A.CUSTOMER_NO,
       A.CUSTOMER_NM,
       A.ABRVITION,
       A.SALE_ORG,
       A.SALE_ORG_DESC,
       A.SALE_AREA_NO,
       A.SALE_AREA_DESC,
       A.ORDER_STS,
       A.ORDER_STS_DESC,
       A.CREATE_NAME,
       A.CREATE_TIME,
       B.ORDER_SEQ,
       B.CUST_ALPHA_NO,
       B.PSC,
       B.PSC_DESC,
       B.MSC,
       B.MSC_DESC,
       DECODE(B.MSC_STYLE,
              'A',
              '钢管(管坯)',
              'B',
              '钢管+接箍',
              'C',
              '短节+附件',
              'D',
              '接箍',
              'E',
              '双工短节') MSC_STYLE,
       B.USE_CODE,
       B.USE_DESC,
       B.PRD_CLS,
       B.PRODUCCODE,
       B.PRODUCNAME,
       B.STD_CODE,
       B.STD_NAME,
       B.STEELCODE,
       B.STEELNAME,
       B.STD_STYLE,
       B.STD_STYLE_DESC,
       B.SPEC_CODE,
       B.SPEC_NAME,
       B.DIMATER,
       B.HEIGHT,
       B.MODEL_CODE,
       B.MODEL_DESC,
       B.LEN_MIN,
       B.LEN_MAX,
       B.LEN_UNIT,
       C.DELVRY_QTY,
       C.ORDER_UNIT,
       C.WGT_ESTMT,
       '(-' || TO_CHAR(B.DELVRY_RANGE_MIN) ||
       DECODE(B.DELVRY_RANGE_TPE, '%', '%', '') || ',+' ||
       TO_CHAR(B.DELVRY_RANGE_MAX) ||
       DECODE(B.DELVRY_RANGE_TPE, '%', '%', '') || ')' DELVRY_RANGE,
       B.FINAL_USER,
       B.FINAL_USER_DESC,
       (SELECT BASENAME
          FROM COM_BASE_INFO E
         WHERE E.BASECODE = B.OUTS_BILLET_FL) OUTS_BILLET_FL,
       (SELECT BASENAME
          FROM COM_BASE_INFO E
         WHERE E.BASECODE = B.OUTS_STL_PIPE_FL) OUTS_STL_PIPE_FL,
       B.ASSEL_FL,
       B.PRODUCER_FL,
       B.PRDCR_NO,
       B.PRDCR_DESC,
       B.MPS_FL,
       B.MPS_NO,
       B.MPS_DESC,
       B.ADD_ASK_NO,
       B.ORDER_ADD_DESC,
       B.ORDER_SPECIAL_FL,
       B.ORDER_SPECIAL_HEAD,
       B.ORDER_SPECIAL_DESC,
       (SELECT BASENAME
          FROM COM_BASE_INFO E
         WHERE E.BASECODE = B.ORDER_LN_STATUS) ORDER_LN_STATUS,
       B.CUST_ALPHA_NO2,
       B.AW,
       C.DELIVERY_NO,
       C.DELVRY_EDATE,
       C.ENSU_TOTL_LEN,
       (SELECT BASENAME
          FROM COM_BASE_INFO E
         WHERE E.BASECODE = C.DELIVERY_STATUS) DELIVERY_STATUS,
       D.USE_CODE WELL_USE_CODE
  FROM SLM_ORDER_HEAD          A,
       SLM_ORDER_LINE          B,
       SLM_ORDER_LINE_DELIVERY C,
       SLM_WELL_USE_LIST       D
 WHERE A.ORD_PK = B.ORD_PK(+)
   AND B.ORD_LN_PK = C.ORD_LN_PK(+)
   AND A.VALIDFLAG = '1'
   AND B.VALIDFLAG = '1'
   AND C.VALIDFLAG = '1'
   AND D.ORD_LN_DLY_PK = C.ORD_LN_DLY_PK
   AND D.WELL_YEAR = ?
   AND D.USE_MONTH = ?
   AND D.WELL_CODE = ?
   AND D.USE_TYPE = '消耗'
   AND D.CREATE_TIME = (SELECT MAX(F.CREATE_TIME)
                          FROM SLM_WELL_USE_LIST F
                         WHERE F.WELL_CODE = D.WELL_CODE
                           AND F.ORD_LN_DLY_PK = D.ORD_LN_DLY_PK
                           AND F.USE_TYPE = '消耗')
	]]>
	</query>   
	
	 <query id="CoreWellAdjust.getOrder" desc="获取合同信息">
	<![CDATA[
	SELECT A.ORD_PK,
               B.ORD_LN_PK,
               C.ORD_LN_DLY_PK,
               (A.ORDER_NO || '/' || B.ORDER_SEQ) MANAG_NO,
               A.ORDER_NO,
               A.ORDER_TYP,
               A.ORDER_TYP_DESC,
               A.CUSTOMER_NO,
               A.CUSTOMER_NM,
               A.ABRVITION,
               A.SALE_ORG,
               A.SALE_ORG_DESC,
               A.SALE_AREA_NO,
               A.SALE_AREA_DESC,
               A.ORDER_STS,
               A.ORDER_STS_DESC,
               A.CREATE_NAME,
               A.CREATE_TIME,
               B.ORDER_SEQ,
               B.CUST_ALPHA_NO,
               B.PSC,
               B.PSC_DESC,
               B.MSC,
               B.MSC_DESC,
               B.MSC_STYLE,
               B.USE_CODE,
               B.USE_DESC,
               B.PRD_CLS,
               B.PRODUCCODE,
               B.PRODUCNAME,
               B.STD_CODE,
               B.STD_NAME,
               B.STEELCODE,
               B.STEELNAME,
               B.STD_STYLE,
               B.STD_STYLE_DESC,
               B.SPEC_CODE,
               B.SPEC_NAME,
               B.DIMATER,
               B.HEIGHT,
               B.MODEL_CODE,
               B.MODEL_DESC,
               B.LEN_MIN,
               B.LEN_MAX,
               B.LEN_UNIT,               
               C.DELVRY_QTY,
               C.ORDER_UNIT,
               C.WGT_ESTMT,
               '(-' || TO_CHAR(B.DELVRY_RANGE_MIN) ||
               DECODE(B.DELVRY_RANGE_TPE, '%', '%', '') || ',+' ||
               TO_CHAR(B.DELVRY_RANGE_MAX) ||
               DECODE(B.DELVRY_RANGE_TPE, '%', '%', '') || ')' DELVRY_RANGE,
               B.FINAL_USER,
               B.FINAL_USER_DESC,
               B.OUTS_BILLET_FL,
               B.OUTS_STL_PIPE_FL,
               B.ASSEL_FL,
               B.PRODUCER_FL,
               B.PRDCR_NO,
               B.PRDCR_DESC,
               B.MPS_FL,
               B.MPS_NO,
               B.MPS_DESC,
               B.ADD_ASK_NO,
               B.ORDER_ADD_DESC,
               B.ORDER_SPECIAL_FL,
               B.ORDER_SPECIAL_HEAD,
               B.ORDER_SPECIAL_DESC,
               B.ORDER_LN_STATUS,
               B.CUST_ALPHA_NO2,
               B.AW,
               C.DELIVERY_NO,
               C.DELVRY_EDATE,
               C.ENSU_TOTL_LEN,
               C.DELIVERY_STATUS
          FROM SLM_ORDER_HEAD A, SLM_ORDER_LINE B, SLM_ORDER_LINE_DELIVERY C
         WHERE A.ORD_PK = B.ORD_PK(+)
           AND B.ORD_LN_PK = C.ORD_LN_PK(+)
           AND A.VALIDFLAG = '1'
           AND B.VALIDFLAG = '1'
           AND C.VALIDFLAG = '1'
		   AND ORD_LN_DLY_PK = ?
	]]>
	</query>   
	
	 <query id="CoreWellAdjust.getProcessCode" desc="通过产能井号获取工序号">
	<![CDATA[
		SELECT T.PROCESS_CDOE FROM COM_BASE_WELL T WHERE T.WELL_CODE =? 
	]]>
	</query>   
	
	 <query id="CoreWellAdjust.getDesignKey" desc="获取DESIGNkey和制程号">
	<![CDATA[
		SELECT A.DESGIN_KEY,B.MSC_PLINE FROM SLM_ORD_DESIGN_MSC A,SLM_ORD_DESIGN_MSC_PL B
      WHERE A.DESGIN_KEY = B.DESGIN_KEY(+)
         AND A.ORD_LN_PK = ?
         AND A.VALIDFLAG ='1'
	]]>
	</query> 
	
	<query id="CoreWellAdjust.getDesignPline" desc="获取工序下产线">
	<![CDATA[
		SELECT 
		        PLINE_CODE,PLINE_NAME,
		        WELL_CODE,WELL_NAME		       
		        FROM SLM_ORD_DESIGN_MSC_PL_GX_PRL
				WHERE 
		        DESGIN_KEY=? 
		        AND MSC_PLINE=?
				AND PROCESS_CODE=?
	]]>
	</query> 
	
	<query id="CoreWellAdjust.getPlineWell" desc="通过产线获取对应的产能井代码">
	<![CDATA[
		SELECT T.WELL_CODE,T.WELL_NAME,T.PLINE_CODE,T.PLINE_NAME FROM COM_MSC_PLINE_R_SPEC T WHERE T.VALIDFLAG = '1' #Condition# 
	]]>
	</query> 
	
	<query id="CoreWellAdjust.setUseWell" desc="更新产能井号">
	<![CDATA[
		UPDATE SLM_WELL_USE_LIST T 
		   SET T.WELL_CODE = ?
		       T.WELL_NAME = ?
		WHERE T.ORD_LN_DLY_PK = ?
		AND   T.WELL_CODE = ?
		AND   T.WELL_YEAR = ?
		AND   T.USE_MONTH = ?
	]]>
	</query> 
	
		<query id="CoreWellAdjust.getBaseWell" desc="获取产能井基本信息">
	<![CDATA[
		SELECT T.WELL_CODE, T.WELL_NAME
  FROM COM_BASE_WELL T
 WHERE T.VALIDFLAG = ?
   AND T.PROCESS_CDOE =
       (SELECT A.PROCESS_CDOE FROM COM_BASE_WELL A WHERE A.WELL_CODE = ?)
	]]>
	</query> 
	
	<query id="CoreWellAdjust.getBom" desc="从BOM清单中获取相关信息">
	<![CDATA[
		SELECT T.MATERIAL_NO,
		       T.MATERIAL_DESC,
		       T.BOM,
		       T.BOM_TYP,
		       T.MSC_PLINE,
		       T.WHOLE_BACKLOG,
		       T.WHOLE_BACKLOG_DESC,
		       T.MSC,
		       T.MSC_DESC,
		       T.GRADECODE,
		       T.GRADENAME,
		       T.SPEC_CODE_C,
		       T.SPEC_NAME_C,
		       T.SPEC_CODE_R,
		       T.SPEC_NAME_R,
		       T.SPEC_CODE_D,
		       T.SPEC_NAME_D,
		       T.SPEC_CODE_Z,
		       T.SPEC_NAME_Z,
		       T.A_IN_MATERIAL_NO,
		       T.A_IN_MATERIAL_DESC,
		       T.A_OUT_MATERIAL_NO,
		       T.A_OUT_MATERIAL_DESC,
		       T.B_IN_MATERIAL_NO,
		       T.B_IN_MATERIAL_DESC,
		       T.B_OUT_MATERIAL_NO,
		       T.B_OUT_MATERIAL_DESC,
		       T.C_IN_MATERIAL_NO,
		       T.C_IN_MATERIAL_DESC,
		       T.C_OUT_MATERIAL_NO,
		       T.C_OUT_MATERIAL_DESC,
		       T.D_IN_MATERIAL_NO,
		       T.D_IN_MATERIAL_DESC,
		       T.D_OUT_MATERIAL_NO,
		       T.D_OUT_MATERIAL_DESC,
		       T.E_IN_MATERIAL_NO,
		       T.E_IN_MATERIAL_DESC,
		       T.E_OUT_MATERIAL_NO,
		       T.E_OUT_MATERIAL_DESC,
		       T.F_IN_MATERIAL_NO,
		       T.F_IN_MATERIAL_DESC,
		       T.F_OUT_MATERIAL_NO,
		       T.F_OUT_MATERIAL_DESC,
		       T.J_IN_MATERIAL_NO,
		       T.J_IN_MATERIAL_DESC,
		       T.J_OUT_MATERIAL_NO,
		       T.J_OUT_MATERIAL_DESC,
		       T.I_IN_MATERIAL_NO,
		       T.I_IN_MATERIAL_DESC,
		       T.I_OUT_MATERIAL_NO,
		       T.I_OUT_MATERIAL_DESC,
		       T.PROCESS_CODE_CS,
		       TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME
		  FROM SLM_ORD_DESIGN_BOM T
		 WHERE T.BOM IN
		       (SELECT T3.BOM
		          FROM SLM_ORDER_LINE T1, SLM_ORD_DESIGN_MSC T2, SLM_ORD_LINE_BOM T3
		         WHERE T1.ORD_LN_PK = T2.ORD_LN_PK
		           AND T2.DESGIN_KEY = T3.DESGIN_KEY(+)
		           AND T2.VALIDFLAG = '1'
		           AND T1.ORD_LN_PK = ?) 
		  AND T.MSC_PLINE = ?
	]]>
	</query> 
	
		<query id="CoreWellAdjust.getDH" desc="获取外径、壁厚">
	<![CDATA[
		SELECT T.DIMATER,T.HEIGHT FROM COM_BASE_SPEC T WHERE T.SPEC_CODE = ?
	]]>
	</query> 
	
	<query id="CoreWellAdjust.save" desc="调整指定产能井、年、月">
	<![CDATA[
UPDATE SLM_WELL_USE_LIST T
    SET T.USE_CODE=(SELECT SUBSTR({5}, 3, 2) || LPAD({6}, 2, '0') ||
           LPAD(TO_NUMBER(NVL(SUBSTR(MAX(USE_CODE), 5, 6), 0)) + 1, 6, '0'),
        T.WELL_YEAR = {5},
        T.USE_MONTH = {6}
  WHERE T.WELL_CODE = {0}
    AND T.WELL_YEAR = {1}
    AND T.USE_MONTH = {2}
    AND T.USE_CODE = {3}
    AND T.ORD_LN_DLY_PK = {4}
	]]>
	</query>
	
	<query id="CoreWellAdjust.GetProcessByWellCode" desc="通过产能井代码获取工序">
	<![CDATA[
SELECT T.PROCESS_CDOE VALUE FROM COM_BASE_WELL T WHERE T.WELL_CODE = {0}
	]]>
	</query>
	
	<query id="CoreWellAdjust.GetNewWellCodeA" desc="获取炼钢工序新的产能井">
	<![CDATA[
SELECT DISTINCT A.WELL_CODE, A.WELL_NAME
  FROM COM_MSC_PLINE_R_SPEC         A,
       SLM_ORDER_LINE               B,
       SLM_ORD_DESIGN_MSC_PL_GX_PRL C,
       SLM_ORD_DESIGN_STS_TKLG      D,
       SLM_ORD_DESIGN_MSC_PL        F
 WHERE A.VALIDFLAG = '1'
   AND C.PLINE_CODE = A.PLINE_CODE
   AND C.PROCESS_CODE = 'A'
   AND (A.PROCESS_CDOE_C IS NULL OR EXISTS
        (SELECT 1
           FROM SLM_ORD_DESIGN_MSC_PL_PRC E
          WHERE E.DESGIN_KEY = D.DESGIN_KEY
            AND E.PROCESS_CODE_C = A.PROCESS_CDOE_C))
   AND B.ORD_LN_PK = {0}
   AND D.ORD_LN_PK = B.ORD_LN_PK
   AND D.VALIDFLAG = '1'
   AND C.DESGIN_KEY = D.DESGIN_KEY
   AND F.DESGIN_KEY = D.DESGIN_KEY
   AND F.MSC_PLINE = (SELECT MIN(G.MSC_PLINE)
                        FROM SLM_ORD_DESIGN_MSC_PL G
                       WHERE G.DESGIN_KEY = D.DESGIN_KEY)
	]]>
	</query>
	
	<query id="CoreWellAdjust.GetNewWellCodeB" desc="获取铸造工序新的产能井">
	<![CDATA[
SELECT DISTINCT A.WELL_CODE, A.WELL_NAME, A.INDEX_SEQ
  FROM COM_MSC_PLINE_R_SPEC         A,
       SLM_ORDER_LINE               B,
       SLM_ORD_DESIGN_MSC_PL_GX_PRL C,
       SLM_ORD_DESIGN_STS_TKLG      D,
       SLM_ORD_DESIGN_MSC_PL        F,
       SLM_ORD_DESIGN_MSC_BILT_C    H
 WHERE A.SPEC_CODE = H.C_SPEC_CODE
   AND H.DESGIN_KEY = D.DESGIN_KEY
   AND H.MSC_PLINE = F.MSC_PLINE
   AND A.VALIDFLAG = '1'
   AND C.PLINE_CODE = A.PLINE_CODE
   AND C.PROCESS_CODE = 'B'
   AND (A.PROCESS_CDOE_C IS NULL OR EXISTS
        (SELECT 1
           FROM SLM_ORD_DESIGN_MSC_PL_PRC E
          WHERE E.DESGIN_KEY = D.DESGIN_KEY
            AND E.PROCESS_CODE_C = A.PROCESS_CDOE_C))
   AND B.ORD_LN_PK = {0}
   AND D.ORD_LN_PK = B.ORD_LN_PK
   AND D.VALIDFLAG = '1'
   AND C.DESGIN_KEY = D.DESGIN_KEY
   AND F.DESGIN_KEY = D.DESGIN_KEY
   AND F.MSC_PLINE = (SELECT MIN(G.MSC_PLINE)
                        FROM SLM_ORD_DESIGN_MSC_PL G
                       WHERE G.DESGIN_KEY = D.DESGIN_KEY)
	]]>
	</query>
	
	<query id="CoreWellAdjust.GetNewWellCodeC" desc="获取锻造工序新的产能井">
	<![CDATA[
SELECT DISTINCT A.WELL_CODE, A.WELL_NAME, A.INDEX_SEQ
  FROM COM_MSC_PLINE_R_SPEC         A,
       SLM_ORDER_LINE               B,
       SLM_ORD_DESIGN_MSC_PL_GX_PRL C,
       SLM_ORD_DESIGN_STS_TKLG      D,
       SLM_ORD_DESIGN_MSC_PL        F,
       SLM_ORD_DESIGN_MSC_BILT      H
 WHERE A.SPEC_CODE = H.B_SPEC_CODE
   AND H.DESGIN_KEY = D.DESGIN_KEY
   AND H.MSC_PLINE = F.MSC_PLINE
   AND A.VALIDFLAG = '1'
   AND C.PLINE_CODE = A.PLINE_CODE
   AND C.PROCESS_CODE = 'C'
   AND (A.PROCESS_CDOE_C IS NULL OR EXISTS
        (SELECT 1
           FROM SLM_ORD_DESIGN_MSC_PL_PRC E
          WHERE E.DESGIN_KEY = D.DESGIN_KEY
            AND E.PROCESS_CODE_C = A.PROCESS_CDOE_C))
   AND B.ORD_LN_PK = {0}
   AND D.ORD_LN_PK = B.ORD_LN_PK
   AND D.VALIDFLAG = '1'
   AND C.DESGIN_KEY = D.DESGIN_KEY
   AND F.DESGIN_KEY = D.DESGIN_KEY
   AND F.MSC_PLINE = (SELECT MIN(G.MSC_PLINE)
                        FROM SLM_ORD_DESIGN_MSC_PL G
                       WHERE G.DESGIN_KEY = D.DESGIN_KEY)
	]]>
	</query>
	
	<query id="CoreWellAdjust.GetNewWellCodeD" desc="获取轧管工序新的产能井">
	<![CDATA[
SELECT DISTINCT A.WELL_CODE, A.WELL_NAME, A.INDEX_SEQ
  FROM COM_MSC_PLINE_R_SPEC         A,
       SLM_ORDER_LINE               B,
       SLM_ORD_DESIGN_MSC_PL_GX_PRL C,
       SLM_ORD_DESIGN_STS_TKLG      D,
       SLM_ORD_DESIGN_MSC_PL        F,
       SLM_ORD_DESIGN_MSC_GZ_GG     H
 WHERE COMPARE_VALUE(H.DIMATER, '>=', A.MIN_D) = 1
   AND COMPARE_VALUE(H.DIMATER, '<=', A.MAX_D) = 1
   AND COMPARE_VALUE(H.HEIGHT, '>=', A.MIN_H) = 1
   AND COMPARE_VALUE(H.HEIGHT, '<=', A.MAX_H) = 1
   AND H.DESGIN_KEY = D.DESGIN_KEY
   AND H.MSC_PLINE = F.MSC_PLINE
   AND A.VALIDFLAG = '1'
   AND C.PLINE_CODE = A.PLINE_CODE
   AND C.PROCESS_CODE = 'D'
   AND (A.PROCESS_CDOE_C IS NULL OR EXISTS
        (SELECT 1
           FROM SLM_ORD_DESIGN_MSC_PL_PRC E
          WHERE E.DESGIN_KEY = D.DESGIN_KEY
            AND E.PROCESS_CODE_C = A.PROCESS_CDOE_C))
   AND B.ORD_LN_PK = {0}
   AND D.ORD_LN_PK = B.ORD_LN_PK
   AND D.VALIDFLAG = '1'
   AND C.DESGIN_KEY = D.DESGIN_KEY
   AND F.DESGIN_KEY = D.DESGIN_KEY
   AND F.MSC_PLINE = (SELECT MIN(G.MSC_PLINE)
                        FROM SLM_ORD_DESIGN_MSC_PL G
                       WHERE G.DESGIN_KEY = D.DESGIN_KEY)
	]]>
	</query>
	
	<query id="CoreWellAdjust.GetNewWellCodeE" desc="获取镦拔扩工序新的产能井">
	<![CDATA[
SELECT DISTINCT A.WELL_CODE, A.WELL_NAME, A.INDEX_SEQ
  FROM COM_MSC_PLINE_R_SPEC         A,
       SLM_ORDER_LINE               B,
       SLM_ORD_DESIGN_MSC_PL_GX_PRL C,
       SLM_ORD_DESIGN_STS_TKLG      D,
       SLM_ORD_DESIGN_MSC_PL        F
 WHERE COMPARE_VALUE(B.DIMATER, '>=', A.MIN_D) = 1
   AND COMPARE_VALUE(B.DIMATER, '<=', A.MAX_D) = 1
   AND COMPARE_VALUE(B.HEIGHT, '>=', A.MIN_H) = 1
   AND COMPARE_VALUE(B.HEIGHT, '<=', A.MAX_H) = 1
   AND A.VALIDFLAG = '1'
   AND C.PLINE_CODE = A.PLINE_CODE
   AND C.PROCESS_CODE = 'E'
   AND (A.PROCESS_CDOE_C IS NULL OR EXISTS
        (SELECT 1
           FROM SLM_ORD_DESIGN_MSC_PL_PRC E
          WHERE E.DESGIN_KEY = D.DESGIN_KEY
            AND E.PROCESS_CODE_C = A.PROCESS_CDOE_C))
   AND B.ORD_LN_PK = {0}
   AND D.ORD_LN_PK = B.ORD_LN_PK
   AND D.VALIDFLAG = '1'
   AND C.DESGIN_KEY = D.DESGIN_KEY
   AND F.DESGIN_KEY = D.DESGIN_KEY
   AND F.MSC_PLINE = (SELECT MIN(G.MSC_PLINE)
                        FROM SLM_ORD_DESIGN_MSC_PL G
                       WHERE G.DESGIN_KEY = D.DESGIN_KEY)
	]]>
	</query>
	
	<query id="CoreWellAdjust.GetNewWellCodeF" desc="获取热处理扩工序新的产能井">
	<![CDATA[
SELECT DISTINCT A.WELL_CODE, A.WELL_NAME, A.INDEX_SEQ
  FROM COM_MSC_PLINE_R_SPEC         A,
       SLM_ORDER_LINE               B,
       SLM_ORD_DESIGN_MSC_PL_GX_PRL C,
       SLM_ORD_DESIGN_STS_TKLG      D,
       SLM_ORD_DESIGN_MSC_PL        F
 WHERE COMPARE_VALUE(B.DIMATER, '>=', A.MIN_D) = 1
   AND COMPARE_VALUE(B.DIMATER, '<=', A.MAX_D) = 1
   AND COMPARE_VALUE(B.HEIGHT, '>=', A.MIN_H) = 1
   AND COMPARE_VALUE(B.HEIGHT, '<=', A.MAX_H) = 1
   AND A.VALIDFLAG = '1'
   AND C.PLINE_CODE = A.PLINE_CODE
   AND C.PROCESS_CODE = 'F'
   AND (A.PROCESS_CDOE_C IS NULL OR EXISTS
        (SELECT 1
           FROM SLM_ORD_DESIGN_MSC_PL_PRC E
          WHERE E.DESGIN_KEY = D.DESGIN_KEY
            AND E.PROCESS_CODE_C = A.PROCESS_CDOE_C))
   AND B.ORD_LN_PK = {0}
   AND D.ORD_LN_PK = B.ORD_LN_PK
   AND D.VALIDFLAG = '1'
   AND C.DESGIN_KEY = D.DESGIN_KEY
   AND F.DESGIN_KEY = D.DESGIN_KEY
   AND F.MSC_PLINE = (SELECT MIN(G.MSC_PLINE)
                        FROM SLM_ORD_DESIGN_MSC_PL G
                       WHERE G.DESGIN_KEY = D.DESGIN_KEY)
	]]>
	</query>
	
	<query id="CoreWellAdjust.GetNewWellCodeG" desc="获取加工工序新的产能井">
	<![CDATA[
SELECT DISTINCT A.WELL_CODE, A.WELL_NAME, A.INDEX_SEQ
  FROM COM_MSC_PLINE_R_SPEC         A,
       SLM_ORDER_LINE               B,
       SLM_ORD_DESIGN_MSC_PL_GX_PRL C,
       SLM_ORD_DESIGN_STS_TKLG      D,
       SLM_ORD_DESIGN_MSC_PL        F
 WHERE COMPARE_VALUE(B.DIMATER, '>=', A.MIN_D) = 1
   AND COMPARE_VALUE(B.DIMATER, '<=', A.MAX_D) = 1
   AND COMPARE_VALUE(B.HEIGHT, '>=', A.MIN_H) = 1
   AND COMPARE_VALUE(B.HEIGHT, '<=', A.MAX_H) = 1
   AND (A.MODEL_CODE IS NULL OR INSTR(A.MODEL_CODE, B.MODEL_CODE) > 0)
   AND A.VALIDFLAG = '1'
   AND C.PLINE_CODE = A.PLINE_CODE
   AND C.PROCESS_CODE = 'G'
   AND (A.PROCESS_CDOE_C IS NULL OR EXISTS
        (SELECT 1
           FROM SLM_ORD_DESIGN_MSC_PL_PRC E
          WHERE E.DESGIN_KEY = D.DESGIN_KEY
            AND E.PROCESS_CODE_C = A.PROCESS_CDOE_C))
   AND B.ORD_LN_PK = {0}
   AND D.ORD_LN_PK = B.ORD_LN_PK
   AND D.VALIDFLAG = '1'
   AND C.DESGIN_KEY = D.DESGIN_KEY
   AND F.DESGIN_KEY = D.DESGIN_KEY
   AND F.MSC_PLINE = (SELECT MIN(G.MSC_PLINE)
                        FROM SLM_ORD_DESIGN_MSC_PL G
                       WHERE G.DESGIN_KEY = D.DESGIN_KEY)
	]]>
	</query>
	
	<query id="CoreWellAdjust.GetNewWellCodeH" desc="获取接箍加工工序新的产能井">
	<![CDATA[
SELECT DISTINCT A.WELL_CODE, A.WELL_NAME, A.INDEX_SEQ
  FROM COM_MSC_PLINE_R_SPEC         A,
       SLM_ORDER_LINE               B,
       SLM_ORD_DESIGN_MSC_PL_GX_PRL C,
       SLM_ORD_DESIGN_STS_TKLG      D,
       SLM_ORD_DESIGN_MSC_PL        F
 WHERE (NOT EXISTS (SELECT 1
                      FROM com_msc_jg_r_spec H
                     WHERE H.CODE_JG = TO_CHAR(A.INDEX_SEQ)
                       AND H.VALIDFLAG = '1') OR EXISTS
        (SELECT 1
           FROM com_msc_jg_r_spec H
          WHERE H.CODE_JG = TO_CHAR(A.INDEX_SEQ)
            AND H.VALIDFLAG = '1'
            AND H.SPEC_CODE = B.SPEC_CODE))
   AND (A.MODEL_CODE IS NULL OR INSTR(A.MODEL_CODE, B.MODEL_CODE) > 0)
   AND A.VALIDFLAG = '1'
   AND C.PLINE_CODE = A.PLINE_CODE
   AND C.PROCESS_CODE = 'H'
   AND B.ORD_LN_PK = {0}
   AND D.ORD_LN_PK = B.ORD_LN_PK
   AND D.VALIDFLAG = '1'
   AND C.DESGIN_KEY = D.DESGIN_KEY
   AND F.DESGIN_KEY = D.DESGIN_KEY
   AND F.MSC_PLINE = (SELECT MIN(G.MSC_PLINE)
                        FROM SLM_ORD_DESIGN_MSC_PL G
                       WHERE G.DESGIN_KEY = D.DESGIN_KEY)
	]]>
	</query>
	
	<query id="CoreWellAdjust.UpdateWell" desc="修改产能井">
	<![CDATA[
UPDATE SLM_WELL_USE_LIST T
   SET T.WELL_CODE = {0}, T.WELL_NAME = {1}, T.USE_CODE = {2}
 WHERE T.WELL_CODE = {3}
   AND T.USE_TYPE = '消耗'
   AND T.CREATE_TIME = (SELECT MAX(A.CREATE_TIME)
                          FROM SLM_WELL_USE_LIST A
                         WHERE A.WELL_CODE = T.WELL_CODE
                           AND A.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
                           AND T.USE_TYPE = '消耗')
   AND EXISTS (SELECT 1
          FROM SLM_ORDER_LINE_DELIVERY A
         WHERE A.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
           AND A.ORD_LN_PK = {4})
	]]>
	</query>
	
	<query id="CoreWellAdjust.getMaxUseCode" desc="获取当前月的最大编号">
	<![CDATA[
SELECT SUBSTR(EXTRACT(YEAR FROM SYSDATE), 3, 2) ||
       LPAD(EXTRACT(MONTH FROM SYSDATE), 2, '0') ||
       LPAD(NVL(SUBSTR(MAX(T.USE_CODE), 5, 6), 0) + 1, 6, '0') VALUE
  FROM SLM_WELL_USE_LIST T
 WHERE T.USE_CODE LIKE SUBSTR(EXTRACT(YEAR FROM SYSDATE), 3, 2) ||
       LPAD(EXTRACT(MONTH FROM SYSDATE), 2, '0') || '%'
	]]>
	</query>
	
	<query id="CoreWellAdjust.getSYSDATE" desc="获取系统时间">
	<![CDATA[
SELECT TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS') FROM DUAL
	]]>
	</query>
	
	<query id="CoreWellAdjust.getWellUseWgt" desc="查询某个月产能井的耗用情况">
	<![CDATA[
SELECT NVL(SUM(T.USE_WGT), 0) USE_WGT
  FROM SLM_WELL_USE_LIST T
 WHERE T.WELL_CODE = {0}
   AND T.WELL_YEAR = {1}
   AND T.USE_MONTH = {2}
	]]>
	</query>
	
	<query id="CoreWellAdjust.getWellUseWgtByDlyPk" desc="通过交货行获取产能井的耗用情况">
	<![CDATA[
SELECT *
  FROM SLM_WELL_USE_LIST T
 WHERE T.WELL_CODE = {0}
   AND T.WELL_YEAR = {1}
   AND T.USE_MONTH = {2}
   AND T.USE_CODE = {3}
   AND T.ORD_LN_DLY_PK = {4}
	]]>
	</query>
	
	<query id="CoreWellAdjust.getWellByProcess" desc="通过工序获取产能">
	<![CDATA[
SELECT *
  FROM SLM_WELL_USE_LIST T
 WHERE T.ORD_LN_DLY_PK = {0}
   AND EXISTS
 (SELECT 1
          FROM Com_Base_Well A
         WHERE A.WELL_CODE = T.WELL_CODE
           AND A.PROCESS_CDOE = {1})
   AND T.USE_TYPE = '消耗'
   AND T.CREATE_TIME = (SELECT MAX(B.CREATE_TIME)
                          FROM SLM_WELL_USE_LIST B
                         WHERE B.WELL_CODE = T.WELL_CODE
                           AND B.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
                           AND B.USE_TYPE = '消耗')
	]]>
	</query>
	
	<query id="CoreWellAdjust.getWellAbility" desc="获取产能井的产能">
	<![CDATA[
SELECT CASE {2}
      WHEN '1' THEN
        T.MONTH_1
      WHEN '2' THEN
        T.MONTH_2
      WHEN '3' THEN
        T.MONTH_3
      WHEN '4' THEN
        T.MONTH_4
      WHEN '5' THEN
        T.MONTH_5
      WHEN '6' THEN
        T.MONTH_6
      WHEN '7' THEN
        T.MONTH_7
      WHEN '8' THEN
        T.MONTH_8
      WHEN '9' THEN
        T.MONTH_9
      WHEN '10' THEN
        T.MONTH_10
      WHEN '11' THEN
         T.MONTH_11
      WHEN '12' THEN
         T.MONTH_12
      ELSE
         0
      END VALUE
 FROM COM_BASE_WELL_MONTH T
  WHERE T.WELL_CODE = {0}
AND T.YEAR = {1}
	]]>
	</query>
	
	<query id="CoreWellAdjust.UpdatePlPcList" desc="更新生产周期">
	<![CDATA[
UPDATE SLM_ORD_DESIGN_MSC_PL_PC_LST T
   SET T.REVIEW_ASK = TO_CHAR(add_months(TO_DATE(T.REVIEW_ASK, 'YYYY-MM-DD'),
                                         months_between(to_date({2},
                                                                'YYYYMM'),
                                                        TO_DATE({3},
                                                                'YYYYMM'))),
                              'YYYY-MM-DD')
 WHERE T.ORD_LN_DLY_PK = {0}
   AND T.DESGIN_KEY = (SELECT A.DESGIN_KEY
                         FROM SLM_ORD_DESIGN_STS_TKLG A
                        WHERE A.ORD_LN_PK = {1}
                          AND A.VALIDFLAG = '1')

	]]>
	</query>
</queryMap>
