<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="外购坯查询等业务操作    ">
	<query id="BuyGpDAL.getBUY_BASE_CUSTOMERALL" desc="获取供应商数据">
	<![CDATA[
        SELECT  a.customer_no,a.customer_nm,a.region_no,b.wet_d,b.wet_dg,b.wet_dgf
         FROM BUY_BASE_CUSTOMER a
        LEFT JOIN BUY_BASE_REQ b
        ON a.Customer_No = b.customer_no
		]]>
	</query>

	<query id="BuyGpDAL.getPLN_REQINF_GP" desc="获取外购坯需求数据 ">
	<![CDATA[
       SELECT ta.*,tb.GP_SYWEIGHT
		FROM
		(
		SELECT MATERIAL_NAME,CIC,GRADENAME,DIAMETER_GP,LEN_GP_SINGLE,
		       COUNT(*) AS CT,SUM(GP_WEIGHT) AS GP_WEIGHT,CEIL(SUM(GP_WEIGHT)/60) * 60 AS GSWEIGHT
		        FROM PLN_REQINF_GP 
		        WHERE BUYPLANID is  null
		       GROUP BY MATERIAL_NAME,CIC,GRADENAME,DIAMETER_GP,LEN_GP_SINGLE
		) ta
		LEFT JOIN       
		(      
		 SELECT a.material_name,a.cic,a.len_gp_single,sum(a.gp_syweight) as GP_SYWEIGHT  FROM  BUY_GP_REQ a
		 WHERE REC_STATUS ='2'
		 GROUP BY a.material_name,a.cic,a.len_gp_single
		) tb
		ON ta.MATERIAL_NAME = tb.material_name
		AND ta.CIC = tb.cic
		AND ta.LEN_GP_SINGLE = tb.len_gp_single
		]]>
	</query>
	<query id="BuyGpDAL.getPLN_REQINF_GP_DETAILS" desc="获取外购坯需求数据 详细数据">
	<![CDATA[
       SELECT MATERIAL_NAME,CIC,GRADENAME,DIAMETER_GP,LEN_GP_SINGLE,
       ORDER_NO,ORDER_SEQ,DELIVERY_NO,WEIGHT_GP_ONE,GP_WEIGHT,GP_NUM,GPREQ_ID
       FROM PLN_REQINF_GP
       WHERE BUYPLANID is  null
		]]>
	</query>
	<query id="BuyGpDAL.getBUY_GP_REQ" desc="获取管坯采购需求清单">
	<![CDATA[
       SELECT GPBUYPLANID,CIC,CASE REC_TYPE WHEN '0' THEN '正常' WHEN '1' THEN '预排' WHEN '2' THEN '利计划' ELSE '' END AS REC_TYPE,
              GPREQ_ID,ORD_SQE_PK,CASE GPTYPE WHEN '0' THEN '轧坯' WHEN '1' THEN '铸坯' WHEN '2' THEN '锻坯' ELSE ''  END AS GPTYPE,MATERIAL_NO,
              MATERIAL_NAME,GRADENAME,DIAMETER,LEN_GP_SINGLE,LENGTH,
              WEIGHT_ONE,GP_NUM,GP_WEIGHT,OLD_GP_NUM,OLD_GP_WEIGHT,
              WEIGHT_ASS,NUM_TOT,WEIGHT_TOT,ROLL_MONTH,GET_ENDTIME,
              CASE REC_STATUS WHEN '0' THEN '编制' WHEN '1' THEN '生效' WHEN '2' THEN '提报' ELSE '' END AS REC_STATUS
              
              FROM BUY_GP_REQ
              WHERE 1=1 
              ORDER BY CREATE_TIME DESC
       
		]]>
	</query>
	<query id="BuyGpDAL.getBUY_GP_REQ1" desc="获取管坯采购需求清单新">
	<![CDATA[
    SELECT  GPREQ_ID,CIC,CASE REC_TYPE WHEN '0' THEN '正常' WHEN '1' THEN '预排' ELSE NULL END AS REC_TYPE,
              CASE a.GPTYPE WHEN '0' THEN '轧坯'  WHEN '1' THEN '铸坯' WHEN '2' THEN '锻坯' ELSE ''  END AS GPTYPE,a.MATERIAL_NO,
              a.MATERIAL_NAME,a.GRADENAME,a.LEN_GP_SINGLE,
              CASE REQ_STATUS WHEN '0' THEN '编制' WHEN '1' THEN '生效' WHEN '2' THEN '提报' 
              WHEN '3' THEN '执行' WHEN '4' THEN '交齐'
              ELSE '' END AS REC_STATUS
              ,GP_WEIGHT,DIAMETER_GP,CASE WHEN REQ_STATUS='0' THEN NULL ELSE ISSUED_TIME END AS ISSUED_TIME,b.CREATE_TIME,
              GP_SYWEIGHT,supply_unit_code,supply_unit,decode(type_flag,'0','否','1','是','2','定销订购') type_flag,
              a.GPREQ_VERSION,LENGTH_GP,CUT_NUM_GP
              FROM PLN_REQINF_GP a,BUY_GP_ORDER b
              WHERE  a.gpreq_id = b.gpbuyplanid(+) 
              AND IFBUYPLAN =1  AND REQ_DONESTATUS >0 
		]]>
	</query>
	<query id="BuyGpDAL.updateGpreqVersion" desc="更新管理需求版本号">
		<![CDATA[
		UPDATE PLN_REQINF_GP SET GPREQ_VERSION = ? WHERE gpreq_id = ?
		]]>
	</query>


	<query id="BuyGpDAL.getBUY_GP_REQ_XS" desc="获取管坯采购需求清单(供销售)">
	<![CDATA[
       SELECT GPBUYPLANID,CIC,CASE REC_TYPE WHEN '0' THEN '正常' WHEN '1' THEN '预排' WHEN '2' THEN '利计划' ELSE '' END AS REC_TYPE,
              GPREQ_ID,ORD_SQE_PK,CASE GPTYPE WHEN '0' THEN '轧坯'  WHEN '1' THEN '铸坯' WHEN '2' THEN '锻坯' ELSE ''  END AS GPTYPE,MATERIAL_NO,
              MATERIAL_NAME,GRADENAME,DIAMETER,LEN_GP_SINGLE,LENGTH,
              WEIGHT_ONE,GP_NUM,GP_WEIGHT,OLD_GP_NUM,OLD_GP_WEIGHT,
              WEIGHT_ASS,NUM_TOT,WEIGHT_TOT,ROLL_MONTH,GET_ENDTIME,
              CASE REC_STATUS WHEN '0' THEN '编制' WHEN '1' THEN '生效' WHEN '2' THEN '提报' ELSE '' END AS REC_STATUS,
              NULL AS BC 
              FROM BUY_GP_REQ
              WHERE 1=1 AND REC_STATUS=1
              ORDER BY CREATE_TIME DESC
		]]>
	</query>
	<query id="BuyGpDAL.getBUY_GP_REQ_XS1" desc="获取管坯采购需求清单(供销售)(新)">
	<![CDATA[
           SELECT  GPREQ_ID,CIC,CASE REC_TYPE WHEN '0' THEN '正常' WHEN '1' THEN '预排' ELSE NULL END AS REC_TYPE,
              CASE GPTYPE WHEN '0' THEN '轧坯'  WHEN '1' THEN '铸坯' WHEN '2' THEN '锻坯' ELSE ''  END AS GPTYPE,MATERIAL_NO,
              MATERIAL_NAME,GRADENAME,LEN_GP_SINGLE,
              CASE REQ_STATUS WHEN '0' THEN '编制' WHEN '1' THEN '生效' WHEN '2' THEN '提报' ELSE '' END AS REC_STATUS
              ,GP_WEIGHT,
              NULL AS BC,DIAMETER_GP,ISSUED_TIME,SUPPLY_UNIT_CODE,SUPPLY_UNIT,DECODE(TYPE_FLAG,'0','否','1','是','2','定销订购') TYPE_FLAG
              FROM PLN_REQINF_GP
              WHERE IFBUYPLAN =1  AND REQ_DONESTATUS >0 AND REQ_STATUS = 1 
              AND  SUPPLY_UNIT_CODE='120501'
      ORDER BY GPREQ_ID DESC 
		]]>
	</query>
	<query id="BuyGpDAL.getBUY_GP_REQ_XS1TH" desc="获取管坯采购需求清单(供销售)(新)">
	<![CDATA[
           SELECT GPREQ_ID,
       CIC,
       CASE REC_TYPE
         WHEN '0' THEN
          '正常'
         WHEN '1' THEN
          '预排'
         ELSE
          NULL
       END AS REC_TYPE,
       CASE GPTYPE
         WHEN '0' THEN
          '轧坯'
         WHEN '1' THEN
          '铸坯'
         WHEN '2' THEN
          '锻坯'
         ELSE
          ''
       END AS GPTYPE,
       MATERIAL_NO,
       MATERIAL_NAME,
       GRADENAME,
       LEN_GP_SINGLE,
       CASE
         WHEN EXAMINE_STATUS = '2' THEN
          CASE REQ_STATUS
            WHEN '0' THEN
             '编制'
            WHEN '1' THEN
             '生效'
            WHEN '2' THEN
             '提报'
            ELSE
             ''
          END
         ELSE
          '编制'
       END AS REC_STATUS,
       GP_WEIGHT,
       CUT_NUM_GP AS BC,
       DIAMETER_GP,
       ISSUED_TIME,
       SUPPLY_UNIT_CODE,
       SUPPLY_UNIT,
       DECODE(TYPE_FLAG, '0', '否', '1', '是', '2', '定销订购') TYPE_FLAG,
       DECODE(EXAMINE_STATUS,
              '0',
              '未审批',
              '1',
              '工艺审批',
              '2',
              '副总审批') EXAMINE_STATUS,
       EXAMINE_TIME,GPREQ_VERSION
  FROM PLN_REQINF_GP
 WHERE IFBUYPLAN = 1
   AND REQ_DONESTATUS > 0
   AND REQ_STATUS = 1
   AND SUPPLY_UNIT_CODE = '120504'
   AND TYPE_FLAG = '0'
 ORDER BY GPREQ_ID DESC

		]]>
	</query>
	<query id="BuyGpDAL.getBUY_GP_REQ_XS1THSJX" desc="获取管坯采购需求清单(供销售)(新双经销)">
	<![CDATA[
           SELECT GPREQ_ID,
       CIC,
       CASE REC_TYPE
         WHEN '0' THEN
          '正常'
         WHEN '1' THEN
          '预排'
         ELSE
          NULL
       END AS REC_TYPE,
       CASE GPTYPE
         WHEN '0' THEN
          '轧坯'
         WHEN '1' THEN
          '铸坯'
         WHEN '2' THEN
          '锻坯'
         ELSE
          ''
       END AS GPTYPE,
       MATERIAL_NO,
       MATERIAL_NAME,
       GRADENAME,
       LEN_GP_SINGLE,
       CASE
         WHEN EXAMINE_STATUS = '2' THEN
          CASE REQ_STATUS
            WHEN '0' THEN
             '编制'
            WHEN '1' THEN
             '生效'
            WHEN '2' THEN
             '提报'
            ELSE
             ''
          END
         ELSE
          '编制'
       END AS REC_STATUS,
       GP_WEIGHT,
       NULL AS BC,
       DIAMETER_GP,
       ISSUED_TIME,
       SUPPLY_UNIT_CODE,
       SUPPLY_UNIT,
       DECODE(TYPE_FLAG, '0', '否', '1', '是', '2', '定销订购') TYPE_FLAG,
       DECODE(EXAMINE_STATUS,
              '0',
              '未审批',
              '1',
              '工艺审批',
              '2',
              '副总审批') EXAMINE_STATUS,
       EXAMINE_TIME,GPREQ_VERSION
  FROM PLN_REQINF_GP
 WHERE IFBUYPLAN = 1
   AND REQ_DONESTATUS > 0
   AND REQ_STATUS = 1
   AND SUPPLY_UNIT_CODE = '120504'
   AND TYPE_FLAG = '1'
 ORDER BY GPREQ_ID DESC

		]]>
	</query>
	<query id="BuyGpDAL.getBUY_GP_REQ_XS1THSJX1" desc="获取管坯采购需求清单(供销售)(定销订购)">
	<![CDATA[
           SELECT GPREQ_ID,
       CIC,
       CASE REC_TYPE
         WHEN '0' THEN
          '正常'
         WHEN '1' THEN
          '预排'
         ELSE
          NULL
       END AS REC_TYPE,
       CASE GPTYPE
         WHEN '0' THEN
          '轧坯'
         WHEN '1' THEN
          '铸坯'
         WHEN '2' THEN
          '锻坯'
         ELSE
          ''
       END AS GPTYPE,
       MATERIAL_NO,
       MATERIAL_NAME,
       GRADENAME,
       LEN_GP_SINGLE,
       CASE
         WHEN EXAMINE_STATUS = '2' THEN
          CASE REQ_STATUS
            WHEN '0' THEN
             '编制'
            WHEN '1' THEN
             '生效'
            WHEN '2' THEN
             '提报'
            ELSE
             ''
          END
         ELSE
          '编制'
       END AS REC_STATUS,
       GP_WEIGHT,
       NULL AS BC,
       DIAMETER_GP,
       ISSUED_TIME,
       SUPPLY_UNIT_CODE,
       SUPPLY_UNIT,
       DECODE(TYPE_FLAG, '0', '否', '1', '是', '2', '定销订购') TYPE_FLAG,
       DECODE(EXAMINE_STATUS,
              '0',
              '未审批',
              '1',
              '工艺审批',
              '2',
              '副总审批') EXAMINE_STATUS,
       EXAMINE_TIME,GPREQ_VERSION
  FROM PLN_REQINF_GP
 WHERE IFBUYPLAN = 1
   AND REQ_DONESTATUS > 0
   AND REQ_STATUS = 1
   AND SUPPLY_UNIT_CODE = '120504'
   AND TYPE_FLAG = '2'
 ORDER BY GPREQ_ID DESC

		]]>
	</query>
	<query id="BuyGpDAL.getBUY_GP_REQ_XS1THSJX2" desc="获取管坯采购需求清单(供销售)(定销订购)">
	<![CDATA[
           SELECT GPREQ_ID,
       CIC,
       CASE REC_TYPE
         WHEN '0' THEN
          '正常'
         WHEN '1' THEN
          '预排'
         ELSE
          NULL
       END AS REC_TYPE,
       CASE GPTYPE
         WHEN '0' THEN
          '轧坯'
         WHEN '1' THEN
          '铸坯'
         WHEN '2' THEN
          '锻坯'
         ELSE
          ''
       END AS GPTYPE,
       MATERIAL_NO,
       MATERIAL_NAME,
       GRADENAME,
       LEN_GP_SINGLE,
       CASE
         WHEN EXAMINE_STATUS = '2' THEN
          CASE REQ_STATUS
            WHEN '0' THEN
             '编制'
            WHEN '1' THEN
             '生效'
            WHEN '2' THEN
             '提报'
            ELSE
             ''
          END
         ELSE
          '编制'
       END AS REC_STATUS,
       GP_WEIGHT,
       NULL AS BC,
       DIAMETER_GP,
       ISSUED_TIME,
       SUPPLY_UNIT_CODE,
       SUPPLY_UNIT,
       DECODE(TYPE_FLAG, '0', '否', '1', '是', '2', '定销订购', '3', '来料加工') TYPE_FLAG,
       DECODE(EXAMINE_STATUS,
              '0',
              '未审批',
              '1',
              '工艺审批',
              '2',
              '副总审批') EXAMINE_STATUS,
       EXAMINE_TIME,GPREQ_VERSION
  FROM PLN_REQINF_GP
 WHERE IFBUYPLAN = 1
   AND REQ_DONESTATUS > 0
   AND REQ_STATUS = 1
   AND SUPPLY_UNIT_CODE = '120504'
   AND TYPE_FLAG = '3'
 ORDER BY GPREQ_ID DESC

		]]>
	</query>

	<query id="BuyGpDAL.getBUY_GP_REQ_XS1THSJX3" desc="获取管坯采购需求清单(供销售)(库存商备坯)">
		<![CDATA[
           SELECT GPREQ_ID,
       CIC,
       CASE REC_TYPE
         WHEN '0' THEN
          '正常'
         WHEN '1' THEN
          '预排'
         ELSE
          NULL
       END AS REC_TYPE,
       CASE GPTYPE
         WHEN '0' THEN
          '轧坯'
         WHEN '1' THEN
          '铸坯'
         WHEN '2' THEN
          '锻坯'
         ELSE
          ''
       END AS GPTYPE,
       MATERIAL_NO,
       MATERIAL_NAME,
       GRADENAME,
       LEN_GP_SINGLE,
       CASE
         WHEN EXAMINE_STATUS = '2' THEN
          CASE REQ_STATUS
            WHEN '0' THEN
             '编制'
            WHEN '1' THEN
             '生效'
            WHEN '2' THEN
             '提报'
            ELSE
             ''
          END
         ELSE
          '编制'
       END AS REC_STATUS,
       GP_WEIGHT,
       NULL AS BC,
       DIAMETER_GP,
       ISSUED_TIME,
       SUPPLY_UNIT_CODE,
       SUPPLY_UNIT,
       DECODE(TYPE_FLAG, '0', '否', '1', '是', '2', '定销订购', '3', '来料加工', '3', '库存商备坯') TYPE_FLAG,
       DECODE(EXAMINE_STATUS,
              '0',
              '未审批',
              '1',
              '工艺审批',
              '2',
              '副总审批') EXAMINE_STATUS,
       EXAMINE_TIME,GPREQ_VERSION
  FROM PLN_REQINF_GP
 WHERE IFBUYPLAN = 1
   AND REQ_DONESTATUS > 0
   AND REQ_STATUS = 1
   AND SUPPLY_UNIT_CODE = '120504'
   AND TYPE_FLAG = '4'
 ORDER BY GPREQ_ID DESC

		]]>
	</query>
	<query id="BuyGpDAL.getBUY_GP_REQ_SUPPLIER" desc="获取管坯采购需求(选取供应商)">
	<![CDATA[
       SELECT GPBUYPLANID,CASE REC_TYPE WHEN '0' THEN '正常' WHEN '1' THEN '预排' WHEN '2' THEN '利计划' ELSE '' END AS REC_TYPE,
              GPREQ_ID,ORD_SQE_PK,CASE GPTYPE WHEN '0' THEN '轧坯'  WHEN '1' THEN '铸坯' WHEN '2' THEN '锻坯' ELSE ''  END AS GPTYPE,MATERIAL_NO,
              MATERIAL_NAME,GRADENAME,DIAMETER,LEN_GP_SINGLE,LENGTH,
              WEIGHT_ONE,GP_NUM,GP_WEIGHT,OLD_GP_NUM,OLD_GP_WEIGHT,
              WEIGHT_ASS,NUM_TOT,WEIGHT_TOT
              FROM BUY_GP_REQ
              WHERE GPBUYPLANID=?
		]]>
	</query>
	<query id="BuyGpDAL.getBUY_BASE_CUSTOMER" desc="获取管坯采购供货商列表">
	<![CDATA[
       SELECT '全部' AS CUSTOMER_NM,'0' AS CUSTOMER_NO FROM DUAL
       UNION
       SELECT SUPP_SHORT_NAME AS CUSTOMER_NM,SUPP_CODE AS CUSTOMER_NO FROM COM_BASE_SUPP
	   --WHERE SUPP_CODE NOT IN ('00032','00031','00030')
	   WHERE SUPP_TYPE ='0'
		]]>
	</query>
	<query id="BuyGpDAL.getBUY_BASE_CUSTOMERSJX" desc="获取管坯采购供货商列表双经销">
	<![CDATA[
       SELECT SUPP_SHORT_NAME AS CUSTOMER_NM,SUPP_CODE AS CUSTOMER_NO FROM COM_BASE_SUPP
	   --WHERE SUPP_CODE  IN ('00032','00031','00033','00037','00038')
	   WHERE SUPP_TYPE ='1'
		]]>
	</query>
	<query id="BuyGpDAL.getBUY_BASE_CUSTOMERSJX1" desc="获取管坯采购供货商列表定销订购">
	<![CDATA[
       SELECT SUPP_SHORT_NAME AS CUSTOMER_NM,SUPP_CODE AS CUSTOMER_NO FROM COM_BASE_SUPP
	   --WHERE SUPP_CODE  IN ('00030')
	   WHERE SUPP_TYPE ='2'
		]]>
	</query>
	<query id="BuyGpDAL.getBUY_BASE_CUSTOMERSJX2" desc="获取管坯采购供货商列表来料加工">
	<![CDATA[
       SELECT SUPP_SHORT_NAME AS CUSTOMER_NM,SUPP_CODE AS CUSTOMER_NO FROM COM_BASE_SUPP
	   --WHERE SUPP_CODE  IN ('00030')
	   WHERE SUPP_TYPE ='3'
		]]>
	</query>
	<query id="BuyGpDAL.updateBUY_GP_REQ_Status2" desc="提报管坯采购需求（从生效到正式)">
	<![CDATA[
        UPDATE BUY_GP_REQ
        SET REC_STATUS=2
        WHERE REC_STATUS='1'
		]]>
	</query>
	<query id="BuyGpDAL.updateBUY_GP_REQ_Status21" desc="提报管坯采购需求（从生效到正式)新">
	<![CDATA[
        UPDATE PLN_REQINF_GP
        SET REQ_STATUS=2
        WHERE REQ_STATUS='1'
		]]>
	</query>

	<query id="BuyGpDAL.updateBUY_GP_REQ_Status1" desc="提报管坯采购需求（从编制到生效)">
	<![CDATA[
        UPDATE BUY_GP_REQ
        SET REC_STATUS=1
        WHERE REC_STATUS='0' AND gpbuyplanid IN ( #gpbuyplanid# )
		]]>
	</query>
	<query id="BuyGpDAL.updateBUY_GP_REQ_Status0" desc="提报管坯采购需求（从生效到编制)">
	<![CDATA[
        UPDATE BUY_GP_REQ
        SET REC_STATUS=0
        WHERE REC_STATUS='1' AND gpbuyplanid IN ( #gpbuyplanid# )
       
		]]>
	</query>
	<query id="BuyGpDAL.updateBUY_GP_REQ_Status11" desc="提报管坯采购需求（从编制到生效新)">
	<![CDATA[
        UPDATE PLN_REQINF_GP
        SET REQ_STATUS=1,
        ISSUED_TIME = sysdate
        WHERE REQ_STATUS='0' AND GPREQ_ID IN ( #gpbuyplanid# )
		]]>
	</query>
	<query id="BuyGpDAL.updateBUY_GP_REQ_Status01" desc="提报管坯采购需求（从生效到编制新)">
	<![CDATA[
        UPDATE PLN_REQINF_GP
        SET REQ_STATUS=0
        WHERE REQ_STATUS='1' AND GPREQ_ID IN ( #gpbuyplanid# )
       
		]]>
	</query>
	<query id="BuyGpDAL.updateBUY_GP_REQ_JQ" desc="管坯需求是否交齐">
	<![CDATA[
        UPDATE PLN_REQINF_GP
        SET REQ_STATUS=4
        WHERE REQ_STATUS='2' 
        AND IFBUYPLAN =1  
        AND REQ_DONESTATUS >0
        AND GPREQ_ID IN ( #gpbuyplanid# )
		]]>
	</query>
	<query id="BuyGpDAL.updateBUY_GP_REQ_JQ_Cancel" desc="管坯需求（撤销)交齐">
	<![CDATA[
        UPDATE PLN_REQINF_GP
        SET REQ_STATUS=2
        WHERE REQ_STATUS='4' 
        AND IFBUYPLAN =1  
        AND REQ_DONESTATUS >0
        AND GPREQ_ID IN ( #gpbuyplanid# )
		]]>
	</query>
	<query id="BuyGpDAL.getBUY_GP_ORDER" desc="获取采购合同表">
      <![CDATA[    
          SELECT
      ORD_NO_PK,                
      b.ORDER_NO,           
      SUBSTR(TO_CHAR(1000+TO_NUMBER(ORDER_SQE)),-3) AS ORDER_SQE,          
      GPBUYPLANID,          
      CASE b.GPTYPE WHEN '0' THEN '轧坯'  WHEN '1' THEN '铸坯' WHEN '2' THEN '锻坯' ELSE ''  END AS GPTYPE,              
      SUPP_CODE,           
      b.MATERIAL_NAME,        
      (select agreement_desc from COM_BASE_PURCHASE_AGREEMENT
           where agreement_code =STD_CODE) 
       AS STD_CODE,                  
      b.GRADENAME,            
      DIAMETER,             
      b.LEN_GP_SINGLE,        
      LENGTH,              
      WEIGHT_ONE,          
      CAST(FIX_NUM AS INT) FIX_NUM,             
      WEIGHT_NUM,           
      GET_ENDTIME,          
      b.MEMO,                 
      WEIGHT_TOT,
      a.ISSUED_TIME,
      
      b.CREATE_TIME,
      CASE REQ_STATUS 
              WHEN '3' THEN '执行' WHEN '4' THEN '交齐'
              ELSE '' END AS REC_STATUS,
      SUPPLY_UNIT_CODE,SUPPLY_UNIT,DECODE(TYPE_FLAG,'0','否','1','是','2','定销订购') TYPE_FLAG,
      b.ORDER_PRICE
    FROM
      BUY_GP_ORDER b,PLN_REQINF_GP a
      WHERE  a.gpreq_id(+) = b.gpbuyplanid AND a.SUPPLY_UNIT_CODE='120501'
      ]]>
	</query>
	<!-- tzh 24.10.31 Add 加入产销传回来没有坯料需求的合同信息 -->
	<query id="BuyGpDAL.getBUY_GP_ORDERTH" desc="获取采购合同表(天淮)">
      <![CDATA[  
       select * from (  
          SELECT
      ORD_NO_PK,                
      b.ORDER_NO,           
      SUBSTR(TO_CHAR(1000+TO_NUMBER(ORDER_SQE)),-3) AS ORDER_SQE,          
      GPBUYPLANID,          
      CASE b.GPTYPE WHEN '0' THEN '轧坯'  WHEN '1' THEN '铸坯' WHEN '2' THEN '锻坯' ELSE ''  END AS GPTYPE,              
      SUPP_CODE,           
      b.MATERIAL_NAME,        
      (select agreement_desc from COM_BASE_PURCHASE_AGREEMENT
           where agreement_code =STD_CODE) 
       AS STD_CODE,                  
      b.GRADENAME,            
      DIAMETER,             
      b.LEN_GP_SINGLE,        
      LENGTH,              
      WEIGHT_ONE,          
      CAST(FIX_NUM AS INT) FIX_NUM,             
      WEIGHT_NUM,           
      GET_ENDTIME,          
      b.MEMO,                 
      WEIGHT_TOT,
      a.ISSUED_TIME,
      
      b.CREATE_TIME,
      CASE REQ_STATUS 
              WHEN '3' THEN '执行' WHEN '4' THEN '交齐'
              ELSE '' END AS REC_STATUS,
      SUPPLY_UNIT_CODE,SUPPLY_UNIT,DECODE(TYPE_FLAG,'0','否','1','是','2','定销订购') TYPE_FLAG,
      b.ORDER_PRICE
    FROM
      BUY_GP_ORDER b,PLN_REQINF_GP a
      WHERE  a.gpreq_id(+) = b.gpbuyplanid
      AND a.SUPPLY_UNIT_CODE='120504'
      
      
      union all
      
    SELECT 
       ORD_NO_PK,                
      b.ORDER_NO,           
     SUBSTR(TO_CHAR(1000+TO_NUMBER(b.ORDER_SQE)),-3) AS  ORDER_SQE,          
      b.GPBUYPLANID,          
      (CASE b.GPTYPE WHEN '0' THEN '轧坯'  WHEN '1' THEN '铸坯' WHEN '2' THEN '锻坯' ELSE ''  END)  AS GPTYPE,              
       b.SUPP_CODE,           
      b.MATERIAL_NAME,        
      (select  agreement_desc from COM_BASE_PURCHASE_AGREEMENT
           where agreement_code =b.STD_CODE) AS STD_CODE,                  
      b.GRADENAME,            
      b.DIAMETER,             
      b.LEN_GP_SINGLE,        
      b.LENGTH,              
      b.WEIGHT_ONE,          
      CAST(b.FIX_NUM AS INT) FIX_NUM,             
      b.WEIGHT_NUM,           
      b.GET_ENDTIME,          
       null MEMO,                 
      b.WEIGHT_TOT,
       NULL ISSUED_TIME,
      
      b.CREATE_TIME,
      null REC_STATUS,
      null SUPPLY_UNIT_CODE, null SUPPLY_UNIT,
      null TYPE_FLAG,
      b.ORDER_PRICE 
      from  BUY_GP_ORDER b where b.GPBUYPLANID LIKE 'POXQ%'
      )
      
      ]]>
	</query>
	<query id="BuyGpDAL.getGpBuyPlanId" desc="生成外购坯需求计划号">
		SELECT 'W' ||
		TO_CHAR(SYSDATE, 'YYYYMM') ||
		LPAD(NVL(MAX(TO_NUMBER(SUBSTR(T.GPBUYPLANID, 8, 11))) + 1, 1),4,'0')
		VERSION_NO
		FROM BUY_GP_REQ T
		WHERE SUBSTR(T.GPBUYPLANID, 2, 6) =
		TO_CHAR(SYSDATE, 'YYYYMM')
	</query>

	<query id="BuyGpDAL.beforeInsertBUY_GP_REQ" desc="合并管坯采购需求清单表">
	 <![CDATA[
	 BEGIN
       
		UPDATE  BUY_GP_REQ ta
		SET  ta.old_gp_weight = ta.old_gp_weight + (
		     SELECT nvl(GP_WEIGHT,0) FROM
		     (
		     SELECT SUM(GP_WEIGHT) GP_WEIGHT,tb.material_name,tb.cic
		     FROM PLN_REQINF_GP tb
		     WHERE tb.buyplanid IS NULL AND tb.gpreq_id IN (#gpreq_id#)
		     GROUP BY tb.material_name,tb.cic
		     ) tc
		     WHERE  ta.material_name = tc.material_name AND ta.CIC = tc.CIC
		     )
		WHERE ta.gpbuyplanid  IN
		(
		  SELECT GPBUYPLANID FROM
		(
		SELECT MIN(a.GPBUYPLANID) GPBUYPLANID,a.material_name,a.CIC  FROM  BUY_GP_REQ a
		WHERE a.Rec_Type ='0' AND a.rec_status ='0'
		GROUP BY a.material_name,a.CIC 
		) 
		);
		
		UPDATE PLN_REQINF_GP ta
		SET ta.buyplanid =
		(SELECT GPBUYPLANID FROM
		(
		SELECT MIN(a.GPBUYPLANID) GPBUYPLANID,a.material_name,a.CIC  FROM  BUY_GP_REQ a
		WHERE a.Rec_Type ='0' AND a.rec_status ='0'
		GROUP BY a.material_name,a.CIC 
		) tb
		WHERE  ta.material_name = tb.material_name AND ta.CIC = tb.CIC
		)
		WHERE ta.gpreq_id IN (#gpreq_id#);
		END;
	 ]]>
	</query>

	<query id="BuyGpDAL.insertBUY_GP_REQ" desc="插入管坯采购需求清单表">

		INSERT INTO
		BUY_GP_REQ(
		GPBUYPLANID ,
		REC_TYPE ,
		GPREQ_ID ,
		ORD_SQE_PK ,
		GPTYPE ,
		MATERIAL_NO ,
		MATERIAL_NAME ,
		GRADECODE ,
		GRADENAME ,
		DIAMETER ,
		LEN_GP_SINGLE ,
		LENGTH ,
		WEIGHT_ONE ,
		GP_NUM ,
		GP_WEIGHT ,
		OLD_GP_NUM ,
		OLD_GP_WEIGHT ,
		WEIGHT_ASS ,
		NUM_TOT ,
		WEIGHT_TOT ,
		ROLL_MONTH ,
		GET_ENDTIME ,
		REC_STATUS ,
		MEMO ,
		CREATE_NAME ,
		CREATE_TIME ,
		CIC
		)
		SELECT
		?,
		'0',
		a.gpreq_id,
		NULL,
		a.gptype,
		a.material_no,
		a.material_name,
		a.gradecode,
		a.gradename,
		a.diameter_gp,
		a.len_gp_single,
		a.length_gp,
		a.weight_gp_one,
		NULL,
		NULL,
		(select sum(gp_num) from PLN_REQINF_GP WHERE
		gpreq_id in ( #gpreq_id# )),
		a.gp_weight,
		CEIL(a.gp_weight/60) * 60,
		NULL,
		NULL,
		NULL,
		NULL,
		'0',
		NULL,
		NULL,
		SYSDATE,
		CIC
		FROM PLN_REQINF_GP a
		WHERE a.BUYPLANID IS NULL
		AND a.gpreq_id = ?
    </query>
	<query id="BuyGpDAL.insertBUY_GP_REQ_YP" desc="插入管坯采购需求(预排)清单表">

		INSERT INTO
		BUY_GP_REQ(
		GPBUYPLANID ,
		REC_TYPE ,
		GPTYPE ,
		MATERIAL_NAME ,
		GRADENAME ,
		DIAMETER ,
		LEN_GP_SINGLE ,
		OLD_GP_WEIGHT ,
		CREATE_TIME ,
		GRADECODE ,
		CIC ,
		MATERIAL_NO
		)
		SELECT
		?,
		1,
		?,
		?,
		?,
		?,
		?,
		?,
		SYSDATE,
		(SELECT MAX(GRADECODE) FROM
		COM_BASE_GRADE WHERE GRADENAME=?),
		?,
		? || (SELECT MAX(SPEC_CODE) FROM
		COM_BASE_SPEC WHERE SPEC_NAME
		=?)||','||(SELECT MAX(GRADECODE) FROM
		COM_BASE_GRADE WHERE
		GRADENAME=?)
		FROM DUAL    
    </query>
	<query id="BuyGpDAL.updatePLN_REQINF_GP_buyplanid" desc="插入管坯采购需求清单后级联更新外购坯需求数据">
		UPDATE
		PLN_REQINF_GP
		SET BUYPLANID = ?
		WHERE BUYPLANID IS NULL
    </query>
	<query id="BuyGpDAL.deleteBUY_GP_REQ" desc="删除管坯采购需求清单表">
     <![CDATA[
        BEGIN
        
        UPDATE PLN_REQINF_GP
        SET BUYPLANID=NULL
        WHERE BUYPLANID IN (
        SELECT GPBUYPLANID FROM BUY_GP_REQ 
        WHERE REC_STATUS='0' 
        AND GPBUYPLANID IN ( #GPPBUYPLANID# )
        );
        
        DELETE FROM BUY_GP_REQ 
        WHERE REC_STATUS='0' 
        AND GPBUYPLANID IN ( #GPPBUYPLANID# );
        
        END;
		]]>
	</query>
	<query id="BuyGpDAL.insertBUY_GP_ORDER" desc="插入采购合同表">
	 <![CDATA[		
		INSERT INTO BUY_GP_ORDER(
		   ORD_NO_PK,
		   ORD_SQE_PK,
		   ORDER_NO,
		   ORDER_SQE,
		   GPBUYPLANID,
		   GPTYPE,
		   SUPP_CODE,
		   MATERIAL_NO,
		   MATERIAL_NAME,
		   STD_CODE,
		   GRADECODE,
		   GRADENAME,
		   DIAMETER,
		   LEN_GP_SINGLE,
		   LENGTH,
		   WEIGHT_ONE,
		   FIX_NUM,
		   WEIGHT_NUM,
		   GET_ENDTIME,
		   WEIGHT_TOT                                                                        
		)
		    with t
    as
    (
    SELECT e.gpbuyplanid as gpid,
    (SELECT MIN(LEVEL) FROM DUAL   WHERE LEVEL*e.len_gp_single between k.len_min and k.len_max connect by level <10 ) AS bc
     FROM
    (
    SELECT a.gpbuyplanid,a.cic,a.diameter,a.len_gp_single
    FROM  BUY_GP_REQ a
    WHERE a.rec_status ='1'
    ) e
    INNER JOIN
    (
    SELECT c.supp_code,c.supp_name,c.agreement_code,d.std_idx FROM COM_BASE_PURCHASE_PROVIDER c
    INNER JOIN com_base_purchase_std_idx d
    ON c.agreement_code = d.agreement_code
    WHERE c.supp_name =?
    )f
    ON e.cic = f.std_idx
    INNER JOIN
    COM_BASE_PURCHASE_RANGE k
    ON f.supp_code = k.supp_code
    AND e.diameter = to_number(k.spec_name)
    )
		SELECT 
		SYS_GUID(),
		SYS_GUID(),
		NULL,
		NULL,
		GPBUYPLANID,
		GPTYPE,
		?,
		MATERIAL_NO,
		MATERIAL_NAME,
		(SELECT c.agreement_code FROM COM_BASE_PURCHASE_PROVIDER c
		INNER JOIN com_base_purchase_std_idx d
		ON c.agreement_code = d.agreement_code
		WHERE c.supp_name =? AND d.std_idx= a.CIC),
		GRADECODE,
		GRADENAME,
		DIAMETER,
		LEN_GP_SINGLE,
		LEN_GP_SINGLE * BC,
		 WEIGHT_ONE,
		 BC,
		 NULL,
		 NULL,
		 OLD_GP_WEIGHT
		FROM 
		BUY_GP_REQ a
		INNER JOIN t
		ON a.GPBUYPLANID = t.gpid
		WHERE 1=1 AND BC IS NOT NULL
	   ]]>
	</query>
	<query id="BuyGpDAL.insertBUY_GP_ORDER1" desc="插入采购合同表(新)">
	 <![CDATA[		
		INSERT INTO BUY_GP_ORDER(
		   ORD_NO_PK,
		   ORD_SQE_PK,
		   ORDER_NO,
		   ORDER_SQE,
		   GPBUYPLANID,
		   GPTYPE,
		   SUPP_CODE,
		   MATERIAL_NO,
		   MATERIAL_NAME,
		   STD_CODE,
		   GRADECODE,
		   GRADENAME,
		   DIAMETER,
		   LEN_GP_SINGLE,
		   LENGTH,
		   WEIGHT_ONE,
		   FIX_NUM,
		   WEIGHT_NUM,
		   GET_ENDTIME,
		   WEIGHT_TOT，
		   CREATE_TIME                                                                        
		)
		 with t
    as
    (
    SELECT e.gpbuyplanid as gpid,
    (SELECT MIN(LEVEL) FROM DUAL   WHERE LEVEL*e.len_gp_single between k.len_min and k.len_max connect by level <10 ) AS bc
     FROM
    (
    SELECT a.Gpreq_Id AS gpbuyplanid,a.cic,a.diameter_gp,a.len_gp_single
    FROM  PLN_REQINF_GP a
    WHERE a.REQ_STATUS ='1'
    ) e
    INNER JOIN
    (
    SELECT c.supp_code,c.supp_name,c.agreement_code,d.std_idx FROM COM_BASE_PURCHASE_PROVIDER c
    INNER JOIN com_base_purchase_std_idx d
    ON c.agreement_code = d.agreement_code
    WHERE c.supp_name =(SELECT SUPP_NAME FROM COM_BASE_SUPP WHERE SUPP_SHORT_NAME=?)
    )f
    ON e.cic = f.std_idx
    INNER JOIN
    COM_BASE_PURCHASE_RANGE k
    ON f.supp_code = k.supp_code
    AND e.diameter_gp = to_number(k.spec_name)
    )
    SELECT 
    SYS_GUID(),
    SYS_GUID(),
    NULL,
    NULL,
    GPREQ_ID,
    GPTYPE,
    ?,
    MATERIAL_NO,
    MATERIAL_NAME,
    (SELECT max(c.agreement_code) FROM COM_BASE_PURCHASE_PROVIDER c
    INNER JOIN com_base_purchase_std_idx d
    ON c.agreement_code = d.agreement_code
    WHERE c.supp_name =(SELECT SUPP_NAME FROM COM_BASE_SUPP WHERE SUPP_SHORT_NAME=?) AND d.std_idx= a.CIC),
    GRADECODE,
    GRADENAME,
    DIAMETER_GP,
    LEN_GP_SINGLE,
    LEN_GP_SINGLE * BC,
     NULL,
     BC,
     GP_WEIGHT,
     NULL,
    GP_WEIGHT,
    SYSDATE
    FROM 
    PLN_REQINF_GP a
    INNER JOIN (select GPID,BC FROM t GROUP BY GPID,BC) t
    ON a.Gpreq_Id = t.gpid
    WHERE a.REQ_STATUS ='1' AND BC IS NOT NULL
	   ]]>
	</query>
		<query id="BuyGpDAL.insertBUY_GP_ORDER1SJX" desc="插入采购合同表(新)">
	 <![CDATA[		
		INSERT INTO BUY_GP_ORDER(
		   ORD_NO_PK,
		   ORD_SQE_PK,
		   ORDER_NO,
		   ORDER_SQE,
		   GPBUYPLANID,
		   GPTYPE,
		   SUPP_CODE,
		   MATERIAL_NO,
		   MATERIAL_NAME,
		   STD_CODE,
		   GRADECODE,
		   GRADENAME,
		   DIAMETER,
		   LEN_GP_SINGLE,
		   LENGTH,
		   WEIGHT_ONE,
		   FIX_NUM,
		   WEIGHT_NUM,
		   GET_ENDTIME,
		   WEIGHT_TOT，
		   CREATE_TIME                                                                        
		)
		 with t1
    as
    (
    SELECT e.gpbuyplanid as gpid,
    (SELECT MIN(LEVEL) FROM DUAL   WHERE LEVEL*e.len_gp_single between k.len_min and k.len_max connect by level <10 ) AS bc
     FROM
    (
    SELECT a.Gpreq_Id AS gpbuyplanid,a.cic,a.diameter_gp,a.len_gp_single
    FROM  PLN_REQINF_GP a
    WHERE a.REQ_STATUS ='1'
    ) e
    INNER JOIN
    (
    SELECT c.supp_code,c.supp_name,c.agreement_code,d.std_idx FROM COM_BASE_PURCHASE_PROVIDER c
    INNER JOIN com_base_purchase_std_idx d
    ON c.agreement_code = d.agreement_code
    WHERE c.supp_name =(SELECT SUPP_NAME FROM COM_BASE_SUPP WHERE SUPP_SHORT_NAME=?)
    )f
    ON e.cic = f.std_idx
    INNER JOIN
    COM_BASE_PURCHASE_RANGE k
    ON f.supp_code = k.supp_code
    AND e.diameter_gp = to_number(k.spec_name)
    ),
    t as
    (
    SELECT gpid,MAX(BC) bc FROM t1 GROUP BY gpid
    )
    SELECT 
    SYS_GUID(),
    SYS_GUID(),
    NULL,
    NULL,
    GPREQ_ID,
    GPTYPE,
    ?,
    MATERIAL_NO,
    MATERIAL_NAME,
    (SELECT max(c.agreement_code) FROM COM_BASE_PURCHASE_PROVIDER c
    INNER JOIN com_base_purchase_std_idx d
    ON c.agreement_code = d.agreement_code
    WHERE c.supp_name =(SELECT SUPP_NAME FROM COM_BASE_SUPP WHERE SUPP_SHORT_NAME=?) AND d.std_idx= a.CIC),
    GRADECODE,
    GRADENAME,
    DIAMETER_GP,
    LEN_GP_SINGLE,
    LEN_GP_SINGLE ,
     NULL,
     1,
     GP_WEIGHT,
     NULL,
    GP_WEIGHT,
    SYSDATE
    FROM 
    PLN_REQINF_GP a
    LEFT JOIN t
    ON a.Gpreq_Id = t.gpid
    WHERE a.REQ_STATUS ='1' 
	   ]]>
	</query>
	<query id="BuyGpDAL.updateBUY_BASE_CUSTOMER" desc="更新供应商列表">
		UPDATE
		BUY_BASE_CUSTOMER
		SET CUSTOMER_NM=?,REGION_NO=?
		WHERE CUSTOMER_NO=?
	</query>
	<query id="BuyGpDAL.updateBUY_BASE_REQ" desc="更新供应商订货起定量配置表">
		UPDATE BUY_BASE_REQ
		SET WET_D=?,WET_DG=?,WET_DGF=?
		WHERE CUSTOMER_NO=?
    </query>
	<query id="BuyGpDAL.getBUY_GP_REQ_SpecialSupplier_bak" desc="获取选中供应商的特定管坯需求单(备份)">
		SELECT GPBUYPLANID,CIC,CASE REC_TYPE WHEN '0' THEN '正常' WHEN '1' THEN
		'预排' WHEN '2' THEN '利计划' ELSE '' END AS REC_TYPE,
		GPREQ_ID,ORD_SQE_PK,CASE GPTYPE WHEN '0' THEN '轧坯'  WHEN '1' THEN '铸坯' WHEN '2' THEN '锻坯'
		ELSE '' END AS GPTYPE,MATERIAL_NO,
		MATERIAL_NAME,GRADENAME,DIAMETER,LEN_GP_SINGLE,LENGTH,
		WEIGHT_ONE,GP_NUM,GP_WEIGHT,OLD_GP_NUM,OLD_GP_WEIGHT,
		WEIGHT_ASS,NUM_TOT,WEIGHT_TOT,ROLL_MONTH,GET_ENDTIME,
		CASE REC_STATUS
		WHEN '0' THEN '编制' WHEN '1' THEN '生效' WHEN '2' THEN '提报'
		ELSE '' END AS
		REC_STATUS
		FROM BUY_GP_REQ
		WHERE REC_STATUS='1' AND GPBUYPLANID IN
		(
		SELECT e.gpbuyplanid FROM
		(
		SELECT a.gpbuyplanid,a.cic FROM BUY_GP_REQ a
		LEFT
		JOIN PLN_REQINF_GP b
		ON a.gpbuyplanid = b.buyplanid
		GROUP BY
		a.gpbuyplanid,a.cic
		) e
		LEFT JOIN
		(
		SELECT
		c.supp_name,c.agreement_code,d.std_idx FROM COM_BASE_PURCHASE_PROVIDER
		c
		INNER JOIN com_base_purchase_std_idx d
		ON c.agreement_code =
		d.agreement_code
		WHERE c.supp_name =?
		)f
		ON e.cic = f.std_idx
		WHERE
		f.STD_IDX IS NOT NULL
		)
    </query>
	<query id="BuyGpDAL.getBUY_GP_REQ_SpecialSupplier" desc="获取选中供应商的特定管坯需求单">
    <![CDATA[
    with t
    as
    (
    SELECT e.gpbuyplanid as gpid,
    (SELECT MIN(LEVEL) FROM DUAL   WHERE LEVEL*e.len_gp_single between k.len_min and k.len_max connect by level <10 ) AS bc
     FROM
    (
    SELECT a.gpbuyplanid,a.cic,a.diameter,a.len_gp_single
    FROM  BUY_GP_REQ a
    WHERE a.rec_status ='1'
    ) e
    INNER JOIN
    (
    SELECT c.supp_code,c.supp_name,c.agreement_code,d.std_idx FROM COM_BASE_PURCHASE_PROVIDER c
    INNER JOIN com_base_purchase_std_idx d
    ON c.agreement_code = d.agreement_code
    WHERE c.supp_name =(SELECT SUPP_NAME FROM COM_BASE_SUPP WHERE SUPP_SHORT_NAME=?)
    AND d.agreement_code IN (SELECT agreement_code FROM  COM_BASE_PURCHASE_AGREEMENT WHERE validflag ='1')
    )f
    ON e.cic = f.std_idx
    INNER JOIN
    COM_BASE_PURCHASE_RANGE k
    ON f.supp_code = k.supp_code
    AND e.diameter = to_number(k.spec_name)
    )
    SELECT GPBUYPLANID,CIC,CASE REC_TYPE WHEN '0' THEN '正常' WHEN '1' THEN '预排' WHEN '2' THEN '利计划' ELSE '' END AS REC_TYPE,
           GPREQ_ID,ORD_SQE_PK,CASE GPTYPE WHEN '0' THEN '轧坯'  WHEN '1' THEN '铸坯' WHEN '2' THEN '锻坯' ELSE ''  END AS GPTYPE,MATERIAL_NO,
           MATERIAL_NAME,GRADENAME,DIAMETER,LEN_GP_SINGLE,LEN_GP_SINGLE*BC AS LENGTH,
           WEIGHT_ONE,GP_NUM,GP_WEIGHT,OLD_GP_NUM,OLD_GP_WEIGHT,
           WEIGHT_ASS,NUM_TOT,WEIGHT_TOT,ROLL_MONTH,GET_ENDTIME,
           CASE REC_STATUS WHEN '0' THEN '编制' WHEN '1' THEN '生效' WHEN '2' THEN '提报' ELSE '' END AS REC_STATUS,
           BC 
           FROM BUY_GP_REQ  INNER JOIN t
           ON GPBUYPLANID = t.GPID
     WHERE REC_STATUS='1' AND t.BC IS NOT NULL
     
    ]]>
	</query>
	<query id="BuyGpDAL.getBUY_GP_REQ_SpecialSupplier1bak" desc="获取选中供应商的特定管坯需求单(新)">
    <![CDATA[
    with t
    as
    (
    SELECT e.gpbuyplanid as gpid,
    (SELECT MIN(LEVEL) FROM DUAL   WHERE LEVEL*e.len_gp_single between k.len_min and k.len_max connect by level <10 ) AS bc
     FROM
    (
    SELECT a.Gpreq_Id AS gpbuyplanid,a.cic,a.diameter_gp,a.len_gp_single
    FROM  PLN_REQINF_GP a
    WHERE a.REQ_STATUS ='1'
    ) e
    INNER JOIN
    (
    SELECT c.supp_code,c.supp_name,c.agreement_code,d.std_idx FROM COM_BASE_PURCHASE_PROVIDER c
    INNER JOIN com_base_purchase_std_idx d
    ON c.agreement_code = d.agreement_code
    WHERE c.supp_name =(SELECT SUPP_NAME FROM COM_BASE_SUPP WHERE SUPP_SHORT_NAME=?)
    AND d.agreement_code IN (SELECT agreement_code FROM  COM_BASE_PURCHASE_AGREEMENT WHERE validflag ='1')
    )f
    ON e.cic = f.std_idx
    INNER JOIN
    COM_BASE_PURCHASE_RANGE k
    ON f.supp_code = k.supp_code
    AND e.diameter_gp = to_number(k.spec_name)
    )
    SELECT GPREQ_ID,CIC,CASE REC_TYPE WHEN '0' THEN '正常' WHEN '1' THEN '预排' ELSE NULL END AS REC_TYPE,
              CASE GPTYPE WHEN '0' THEN '轧坯'  WHEN '1' THEN '铸坯' WHEN '2' THEN '锻坯' ELSE ''  END AS GPTYPE,MATERIAL_NO,
              MATERIAL_NAME,GRADENAME,LEN_GP_SINGLE,
              CASE REQ_STATUS WHEN '0' THEN '编制' WHEN '1' THEN '生效' WHEN '2' THEN '提报' ELSE '' END AS REC_STATUS
              ,GP_WEIGHT,
           BC,DIAMETER_GP,ISSUED_TIME,SUPPLY_UNIT_CODE,SUPPLY_UNIT,DECODE(TYPE_FLAG,'0','否','1','是','2','定销订购') TYPE_FLAG
           FROM PLN_REQINF_GP  INNER JOIN t
           ON Gpreq_Id = t.GPID
     WHERE REQ_STATUS='1' AND SUPPLY_UNIT_CODE='120501' AND t.BC IS NOT NULL
    ]]>
	</query>
	<query id="BuyGpDAL.getBUY_GP_REQ_SpecialSupplier1" desc="获取选中供应商的特定管坯需求单(新)">
    <![CDATA[
    with t
    as
    (
    SELECT e.gpbuyplanid as gpid,
    (SELECT MIN(LEVEL) FROM DUAL   WHERE LEVEL*e.len_gp_single between k.len_min and k.len_max connect by level <10 ) AS bc
     FROM
    (
    SELECT a.Gpreq_Id AS gpbuyplanid,a.cic,a.diameter_gp,a.len_gp_single
    FROM  PLN_REQINF_GP a
    WHERE a.REQ_STATUS ='1'
    ) e
    INNER JOIN
    (
    SELECT c.supp_code,c.supp_name,c.agreement_code,d.std_idx FROM COM_BASE_PURCHASE_PROVIDER c
    INNER JOIN com_base_purchase_std_idx d
    ON c.agreement_code = d.agreement_code
    WHERE c.supp_name =(SELECT SUPP_NAME FROM COM_BASE_SUPP WHERE SUPP_SHORT_NAME=?)
    AND d.agreement_code IN (SELECT agreement_code FROM  COM_BASE_PURCHASE_AGREEMENT WHERE validflag ='1')
    )f
    ON e.cic = f.std_idx
    INNER JOIN
    COM_BASE_PURCHASE_RANGE k
    ON f.supp_code = k.supp_code
    AND e.diameter_gp = to_number(k.spec_name)
    )
    SELECT GPREQ_ID,CIC,CASE REC_TYPE WHEN '0' THEN '正常' WHEN '1' THEN '预排' ELSE NULL END AS REC_TYPE,
              CASE GPTYPE WHEN '0' THEN '轧坯'  WHEN '1' THEN '铸坯' WHEN '2' THEN '锻坯' ELSE ''  END AS GPTYPE,MATERIAL_NO,
              MATERIAL_NAME,GRADENAME,LEN_GP_SINGLE,
              CASE REQ_STATUS WHEN '0' THEN '编制' WHEN '1' THEN '生效' WHEN '2' THEN '提报' ELSE '' END AS REC_STATUS
              ,GP_WEIGHT,
           BC,DIAMETER_GP,ISSUED_TIME,SUPPLY_UNIT_CODE,SUPPLY_UNIT,DECODE(TYPE_FLAG,'0','否','1','是','2','定销订购') TYPE_FLAG
           FROM PLN_REQINF_GP  INNER JOIN (select GPID,BC FROM t GROUP BY GPID,BC) t
           ON Gpreq_Id = t.GPID
     WHERE REQ_STATUS='1' AND SUPPLY_UNIT_CODE='120501' AND t.BC IS NOT NULL
    ]]>
	</query>
	<query id="BuyGpDAL.getBUY_GP_REQ_SpecialSupplier1TH" desc="获取选中供应商的特定管坯需求单(天淮新)">
    <![CDATA[
    with t as
 (SELECT e.gpbuyplanid as gpid,
         (SELECT MIN(LEVEL)
            FROM DUAL
           WHERE LEVEL * e.len_gp_single between k.len_min and k.len_max
          connect by level < 10) AS bc
    FROM (SELECT a.Gpreq_Id AS gpbuyplanid,
                 a.cic,
                 a.diameter_gp,
                 a.len_gp_single
            FROM PLN_REQINF_GP a
           WHERE a.REQ_STATUS = '1') e
   INNER JOIN (SELECT c.supp_code, c.supp_name, c.agreement_code, d.std_idx
                FROM COM_BASE_PURCHASE_PROVIDER c
               INNER JOIN com_base_purchase_std_idx d
                  ON c.agreement_code = d.agreement_code
               WHERE c.supp_name =
                     (SELECT SUPP_NAME
                        FROM COM_BASE_SUPP
                       WHERE SUPP_SHORT_NAME = ?)
                 AND d.agreement_code IN
                     (SELECT agreement_code
                        FROM COM_BASE_PURCHASE_AGREEMENT
                       WHERE validflag = '1')) f
      ON e.cic = f.std_idx
   INNER JOIN COM_BASE_PURCHASE_RANGE k
      ON f.supp_code = k.supp_code
     AND e.diameter_gp = to_number(k.spec_name))
SELECT GPREQ_ID,
       CIC,
       CASE REC_TYPE
         WHEN '0' THEN
          '正常'
         WHEN '1' THEN
          '预排'
         ELSE
          NULL
       END AS REC_TYPE,
       CASE GPTYPE
         WHEN '0' THEN
          '轧坯'
         WHEN '1' THEN
          '铸坯'
         WHEN '2' THEN
          '锻坯'
         ELSE
          ''
       END AS GPTYPE,
       MATERIAL_NO,
       MATERIAL_NAME,
       GRADENAME,
       LEN_GP_SINGLE,
       CASE
         WHEN EXAMINE_STATUS = '2' THEN
          CASE REQ_STATUS
            WHEN '0' THEN
             '编制'
            WHEN '1' THEN
             '生效'
            WHEN '2' THEN
             '提报'
            ELSE
             ''
          END
         ELSE
          '编制'
       END AS REC_STATUS,
       GP_WEIGHT,
       BC,
       DIAMETER_GP,
       ISSUED_TIME,
       SUPPLY_UNIT_CODE,
       SUPPLY_UNIT,
       DECODE(TYPE_FLAG, '0', '否', '1', '是', '2', '定销订购') TYPE_FLAG,
       DECODE(EXAMINE_STATUS,
              '0',
              '未审批',
              '1',
              '工艺审批',
              '2',
              '副总审批') EXAMINE_STATUS,
       EXAMINE_TIME,GPREQ_VERSION
  FROM PLN_REQINF_GP
 INNER JOIN (select GPID, BC FROM t GROUP BY GPID, BC) t
    ON Gpreq_Id = t.GPID
 WHERE REQ_STATUS = '1'
   AND SUPPLY_UNIT_CODE = '120504'
   AND t.BC IS NOT NULL

    ]]>
	</query>
	<query id="BuyGpDAL.getPiKind" desc="选择坯分类根据实际情况获取数据源">
		SELECT 1 CODE,'铸坯' NAME FROM
		DUAL
		UNION
		SELECT 2 CODE,'锻坯' NAME FROM DUAL
     </query>
	<query id="BuyGpDAL.getCicSteelgrades" desc="选择外购坯钢种及索引码">
		SELECT
		a.CIC,a.GRADENAME STEELGRADES FROM COM_MSC_STD_CIC a
		WHERE a.cic in
		(
		SELECT b.std_idx FROM com_base_purchase_std_idx b
		)
     </query>
	<query id="BuyGpDAL.updateBUY_GP_ORDER" desc="更新采购合同表">
       <![CDATA[
       BEGIN
       UPDATE BUY_GP_ORDER 
       SET 
       MEMO =?,
       ORDER_NO = ?,
       GET_ENDTIME = CASE ? WHEN '2000-01-01' THEN NULL ELSE to_date(?,'YYYY-MM-DD') END,
       FIX_NUM = CASE ? WHEN '0' THEN NULL ELSE ? END,
       WEIGHT_NUM=  CASE ? WHEN '0' THEN NULL ELSE ? END,
       ORDER_SQE=CASE  WHEN ? IS NULL THEN NULL WHEN ORDER_NO !=? THEN NULL ELSE ORDER_SQE END，
       ORDER_PRICE=CASE ? WHEN '0.00' THEN NULL ELSE ? END
       WHERE ORD_NO_PK = ?;
       
        UPDATE BUY_GP_ORDER
        SET LENGTH = FIX_NUM * LEN_GP_SINGLE
        WHERE ORD_NO_PK = ?;
       END;
       ]]>
	</query>
	<query id="BuyGpDAL.updateBUY_GP_ORDER1" desc="更新采购合同表1">
		UPDATE BUY_GP_ORDER
		a
		SET get_endtime=NULL
		WHERE
		get_endtime=TO_DATE('2000-01-01','YYYY-MM-DD')
     </query>
	<query id="BuyGpDAL.updateBUY_GP_ORDER_LINE" desc="更新采购合同行号">
		UPDATE
		BUY_GP_ORDER a
		SET a.order_sqe = (
		WITH t
		as
		(
		SELECT
		RANK() OVER(PARTITION
		BY ORDER_NO ORDER BY rowid)+ (SELECT NVL(MAX(TO_NUMBER(ORDER_SQE)),0)
		FROM BUY_GP_ORDER WHERE ORDER_NO= a.ORDER_NO) AS RN,a.rowid
		FROM
		BUY_GP_ORDER a
		WHERE a.order_no IS NOT NULL AND a.order_sqe IS NULL
		)
		SELECT RN FROM t where a.ROWID=t.ROWID
		)
		WHERE a.order_no IS NOT NULL
		AND a.order_sqe IS NULL 
     </query>
	<query id="BuyGpDAL.deleteBUY_GP_ORDER" desc="删除采购合同">
		DELETE FROM
		BUY_GP_ORDER
		WHERE GPBUYPLANID IN
		(
		SELECT GPBUYPLANID FROM
		BUY_GP_ORDER
		WHERE GPBUYPLANID
		)
      </query>
	<query id="BuyGpDAL.deleteBUY_GP_ORDER1" desc="删除采购合同">
		DELETE FROM
		BUY_GP_ORDER
		WHERE GPBUYPLANID IN
		(
		SELECT GPBUYPLANID FROM
		BUY_GP_ORDER
		WHERE ORD_NO_PK IN ( #ORD_NO_PK# )
		)
      </query>
	<query id="BuyGpDAL.updateBUY_GP_REQ_Status211" desc="提报管坯采购需求（从正式到生效:合同退回用)">
	<![CDATA[
        UPDATE PLN_REQINF_GP
        SET REQ_STATUS=1,
            GP_SYWEIGHT=NULL
        WHERE REQ_STATUS='2' 
        AND GPREQ_ID IN 
        (	
			SELECT GPBUYPLANID  FROM BUY_GP_ORDER 
			WHERE ORD_NO_PK IN ( #ORD_NO_PK# )
		) 
		
		]]>
	</query>
	<query id="BuyGpDAL.deleteBUY_GP_ORDER2" desc="删除采购合同(新2017-08-09)">
		BEGIN
		UPDATE
		PLN_REQINF_GP
		SET REQ_STATUS=1,
		GP_SYWEIGHT=NULL
		WHERE REQ_STATUS='2'
		AND
		GPREQ_ID IN
		(
		SELECT GPBUYPLANID FROM BUY_GP_ORDER
		WHERE ORD_NO_PK IN (
		#ORD_NO_PK# )
		);
		DELETE FROM BUY_GP_ORDER t
		WHERE GPBUYPLANID IN
		(
		SELECT
		GPBUYPLANID FROM
		BUY_GP_ORDER
		WHERE ORD_NO_PK IN ( #ORD_NO_PK# )
		) AND
		EXISTS(SELECT * FROM PLN_REQINF_GP
		WHERE REQ_STATUS=1 AND GPREQ_ID =
		t.GPBUYPLANID);
		END;
      </query>
	<query id="BuyGpDAL.updateBUY_GP_REQ_SYWEIGHT_ORDERWEIGHT" desc="更新采购坯需求表（修改合同后调用）">
	<![CDATA[
         UPDATE BUY_GP_REQ tc
     
	     SET (tc.WEIGHT_TOT,tc.GP_SYWEIGHT) =
	    (SELECT td.ORDERWEIGHT,td.SYWEIGHT FROM 
	    (
	    SELECT ta.GPBUYPLANID,ta.WEIGHT AS ORDERWEIGHT,ta.WEIGHT-tb.GPWEIGHT AS SYWEIGHT
	    FROM
	    (
	    SELECT SUM(WEIGHT_NUM) AS WEIGHT,GPBUYPLANID FROM BUY_GP_ORDER
	    WHERE GPBUYPLANID IN 
	    ( SELECT GPBUYPLANID FROM  BUY_GP_ORDER 
	      WHERE   ORD_NO_PK IN ( #ORD_NO_PK# ) 
	    )
	    GROUP BY GPBUYPLANID
	    ) ta
	    INNER JOIN
	    (
	     SELECT BUYPLANID ,SUM(GP_WEIGHT) AS GPWEIGHT FROM PLN_REQINF_GP 
	     GROUP BY BUYPLANID
	    ) tb
	    ON ta.GPBUYPLANID = tb.BUYPLANID
	    WHERE ta.WEIGHT-tb.GPWEIGHT>0
	    ) td
	    WHERE  tc.GPBUYPLANID = td.GPBUYPLANID
	    )
		]]>
	</query>
	<query id="BuyGpDAL.updateBUY_GP_REQ_SYWEIGHT_ORDERWEIGHT1" desc="更新采购坯需求表（修改合同后调用）">
	<![CDATA[
         UPDATE PLN_REQINF_GP tc
     
	     SET (tc.GP_SYWEIGHT) =
	    (SELECT td.SYWEIGHT FROM 
	    (
	    SELECT ta.GPBUYPLANID,ta.WEIGHT-tb.GPWEIGHT AS SYWEIGHT
	    FROM
	    (
	    SELECT SUM(WEIGHT_NUM) AS WEIGHT,GPBUYPLANID FROM BUY_GP_ORDER
	    WHERE GPBUYPLANID IN 
	    ( SELECT GPBUYPLANID FROM  BUY_GP_ORDER 
	      WHERE   ORD_NO_PK IN ( #ORD_NO_PK# ) 
	    )
	    GROUP BY GPBUYPLANID
	    ) ta
	    INNER JOIN
	    (
	     SELECT GPREQ_ID ,GP_WEIGHT AS GPWEIGHT FROM PLN_REQINF_GP 
	    ) tb
	    ON ta.GPBUYPLANID = GPREQ_ID
	    WHERE ta.WEIGHT-tb.GPWEIGHT>0
	    ) td
	    WHERE  tc.GPREQ_ID = td.GPBUYPLANID
	    )
		]]>
	</query>
	<query id="BuyGpDAL.updateBUY_GP_REQ_SYWEIGHT_ORDERWEIGHT2" desc="更新采购坯需求表（修改合同后调用）">
	<![CDATA[
    UPDATE PLN_REQINF_GP a
		SET a.gp_syweight =
		(
		WITH t
		AS
		(
		SELECT avg(t.gp_weight) gp_weight,t.gpreq_id,nvl(sum(t1.gpreq_weight),avg(t.gp_weight)) gpreq_weight 
		FROM PLN_REQINF_GP t,PLN_ORDER_ZG_S t1
		WHERE  
		t1.gpreq_id in (SELECT GPBUYPLANID FROM  BUY_GP_ORDER WHERE   ORD_NO_PK IN ( #ORD_NO_PK# ) ) and
		1=1
		AND t.req_status in ('2','3','4')
		AND t.gpreq_id = t1.gpreq_id(+)
		GROUP BY t.gpreq_id
		),
		t1
		AS
		(
		SELECT SUM(WEIGHT_NUM) AS WEIGHT_NUM, gpbuyplanid FROM buy_gp_order
		GROUP BY gpbuyplanid
		),
		t2
		AS
		(
		 SELECT t.gpreq_id,t1.WEIGHT_NUM-t.gpreq_weight as sy_weight FROM t,t1
		 WHERE t.gpreq_id = t1.gpbuyplanid(+)
		)
		select t2.sy_weight  from t2 where t2.gpreq_id = a.gpreq_id and t2.sy_weight >0
		)
		where 
		EXISTS (
		WITH t
		AS
		(
		SELECT avg(t.gp_weight) gp_weight,t.gpreq_id,nvl(sum(t1.gpreq_weight),avg(t.gp_weight)) gpreq_weight 
		FROM PLN_REQINF_GP t,PLN_ORDER_ZG_S t1
		WHERE  
		t1.gpreq_id in (SELECT GPBUYPLANID FROM  BUY_GP_ORDER WHERE   ORD_NO_PK IN ( #ORD_NO_PK# ) ) and
		1=1
		AND t.req_status in ('2','3','4')
		AND t.gpreq_id = t1.gpreq_id(+)
		GROUP BY t.gpreq_id
		),
		t1
		AS
		(
		SELECT SUM(WEIGHT_NUM) AS WEIGHT_NUM, gpbuyplanid FROM buy_gp_order
		GROUP BY gpbuyplanid
		),
		t2
		AS
		(
		 SELECT t.gpreq_id,t1.WEIGHT_NUM-t.gpreq_weight as sy_weight FROM t,t1
		 WHERE t.gpreq_id = t1.gpbuyplanid(+)
		)
		select t2.sy_weight  from t2 where t2.gpreq_id = a.gpreq_id and t2.sy_weight >0
		)
		
		and a.ifbuyplan ='1' and  a.req_status in ('2','3','4')
		]]>
	</query>
	<query id="BuyGpDAL.updateBUY_GP_REQ_SYWEIGHT_LYL" desc="利余量">
	<![CDATA[
	BEGIN
	
	UPDATE PLN_REQINF_GP
    SET buyplanid = (
    WITH t
    AS
    (
    SELECT  a.gpreq_id, a.material_name,a.len_gp_single,a.cic,a.gp_weight   FROM  PLN_REQINF_GP a
    WHERE a.buyplanid IS NULL
    AND a.gpreq_id = '#gpreq_id#'
    ),
    t1
    AS
    (
    SELECT b.material_name,b.len_gp_single,b.cic,b.gp_syweight,b.gpbuyplanid FROM BUY_GP_REQ b
    WHERE b.gp_syweight >0
    ),
    t2
    AS
    (
    SELECT ROW_NUMBER() OVER (ORDER BY t1.gp_syweight) AS RN  , t.gpreq_id,t.gp_weight,t1.gp_syweight,t1.gpbuyplanid FROM t 
    LEFT JOIN t1 
    ON t.material_name = t1.material_name
    AND t.len_gp_single= t1.len_gp_single
    AND t.cic = t1.cic
    WHERE t1.gp_syweight >=t.gp_weight
    ),
    t3
    AS
    (
     SELECT * FROM t2 WHERE RN=1
    )
    SELECT gpbuyplanid FROM t3
    )
    WHERE gpreq_id = '#gpreq_id#';
    
   UPDATE BUY_GP_REQ
   SET GP_SYWEIGHT = WEIGHT_TOT -
   (SELECT sum(a.gp_weight) FROM PLN_REQINF_GP a WHERE a.buyplanid = (SELECT buyplanid FROM PLN_REQINF_GP  WHERE gpreq_id = '#gpreq_id#'))
   WHERE  GPBUYPLANID = (SELECT buyplanid FROM PLN_REQINF_GP  WHERE gpreq_id = '#gpreq_id#');
   
   END;
	]]>
	</query>
	<query id="BuyGpDAL.getBUY_GP_ORDERCF1" desc="获取合同 拆分界面数据">
		SELECT
		SUPP_SHORT_NAME AS SUPPLIER FROM COM_BASE_SUPP
		WHERE SUPP_NAME NOT IN
		(
		SELECT SUPP_CODE SUPPLIER FROM
		BUY_GP_ORDER
		WHERE ORD_NO_PK = ?
		)
     </query>
	<query id="BuyGpDAL.getBUY_GP_ORDERCF2" desc="获取合同 拆分界面数据">
		SELECT ORD_NO_PK,
		ORDER_NO,
		ORDER_SQE,
		GPBUYPLANID,
		CASE GPTYPE WHEN '0' THEN '轧坯'  WHEN '1' THEN '铸坯' WHEN '2'
		THEN '锻坯' ELSE '' END AS GPTYPE,
		SUPP_CODE,
		MATERIAL_NAME,
		LENGTH,
		WEIGHT_NUM,
		WEIGHT_TOT,
		LEN_GP_SINGLE
		FROM BUY_GP_ORDER
		WHERE ORD_NO_PK =
		?
     </query>
	<query id="BuyGpDAL.getBUY_GP_ORDERCFSAVE" desc="获取合同 拆分保存数据">
		<![CDATA[
		BEGIN
		
		INSERT INTO BUY_GP_ORDER
		(
		       ord_no_pk,
		       ord_sqe_pk,
		       gpbuyplanid,
		       gptype,
		       supp_code,
		       material_no,
		       material_name,
		       std_code,
		       gradecode,
		       gradename,
		       diameter,
		       len_gp_single,
		       length,
		       weight_one,
		       fix_num,
		       weight_num,
		       get_endtime,
		       ord_status,
		       validflag,
		       create_time,
		       weight_tot
		)
		SELECT sys_guid(),
		       sys_guid(),
		       a.gpbuyplanid,
		       a.gptype,
		       ?       ,
		       a.material_no,
		       a.material_name,
		       a.std_code,
		       a.gradecode,
		       a.gradename,
		       a.diameter,
		       a.len_gp_single,
		       a.length,
		       a.weight_one,
		       a.fix_num,
		       ?        ,
		       a.get_endtime,
		       a.ord_status,
		       a.validflag,
		       sysdate,
		       CASE WHEN ? >=a.Weight_Num THEN a.weight_tot ELSE a.weight_tot * ?/a.Weight_Num  END
		       FROM BUY_GP_ORDER a
		       WHERE a.ord_no_pk = ?;
		       
		       UPDATE BUY_GP_ORDER
    		   SET WEIGHT_NUM = WEIGHT_NUM - ?,
        	   WEIGHT_TOT = WEIGHT_TOT- WEIGHT_TOT * ?/ WEIGHT_NUM
     		   WHERE ORD_NO_PK =?;
     
     		   DELETE FROM BUY_GP_ORDER
 			   WHERE  WEIGHT_NUM <=0 AND ORD_NO_PK =?;
     		   
     		   END;
       ]]>
	</query>
	<query id="BuyGpDAL.Test" desc="测试">
		<![CDATA[
	    SELECT *
		FROM BUY_GP_ORDER 
		WHERE ORD_NO_PK = ?
        ]]>
	</query>
	<query id="BuyGpDAL.QueryOrderByGpreq" desc="通过外购坯合同号查询生产合同">
		<![CDATA[
	      SELECT DECODE(t.EXE_STATUS,
              '0',
              '计划',
              '1',
              '生产中',
              '2',
              '已生产',
              '3',
              '关闭A',
              '')  状态,
       DECODE(t.Order_No,null,null,DECODE(b.gptype,'1','铸坯','2','锻坯','0','轧坯')) 坯分类,
       DECODE(t.Order_No ||'/'||t.Order_Seq,'/',null,t.Order_No ||'/'||t.Order_Seq)   合同号,
       t.Pro_Month 轧制月份,
       t.Pline_Name 产线,
       NVL((SELECT A.ABRVITION
                   FROM SLM_BASE_CUSTOMER A
                  WHERE A.CUSTOMER_NO = DECODE(T4.FINAL_USER,
                                               NULL,
                                               T4.BUYER_ID,
                                               '/',
                                               T4.BUYER_ID,
                                               T4.FINAL_USER)),
                 DECODE(T4.FINAL_USER_DESC,
                        NULL,
                        T4.BUYER_NAME,
                        '/',
                        T4.BUYER_NAME,
                        T4.FINAL_USER_DESC)) 用户,
       TO_NUMBER(t.diameter_gp) 断面,
       t.len_gp_single  单倍坯长,
       t.Gradename 钢种,
       T4.OUTDIAMETER 名义外径,
       T4.WALLTHICK 名义壁厚,
       t.ACTUAL_WEIGHT 需坯量,
       b.issued_time 提报日期,
       b.gpreq_id   管坯需求号,
       t.pro_plan_id||'-'||t.gx_plan_no PLAN_ID,
       (SELECT A.PRODUC_JX
                FROM COM_BASE_PRODUCT A
               WHERE A.PRODUCCODE = T4.PRODUCCODE) 品种
	FROM  PLN_REQINF_GP b,
      PLN_ORDER_ZG_S t,
      PLN_SALEORD T4
    WHERE b.gpreq_id = t.gpreq_id(+)
	AND   t.Ord_Ln_Dly_Pk = T4.ORD_LN_DLY_PK(+)
	AND   b.gpreq_id = ?
        ]]>
	</query>
	<query id="BuyGpDAL.QueryForXsAll" desc="导出数据给销售">
		<![CDATA[
	   SELECT DECODE(t.EXE_STATUS,
              '0',
              '计划',
              '1',
              '生产中',
              '2',
              '已生产',
              '3',
              '关闭A',
              '') 状态,
       DECODE(t.Order_No ||'/'||t.Order_Seq,'/',null,t.Order_No ||'/'||t.Order_Seq)   合同号,
       t.Pro_Month 轧制月份,
       t.pline_name 机组,
       NVL((SELECT A.ABRVITION
                   FROM SLM_BASE_CUSTOMER A
                  WHERE A.CUSTOMER_NO = DECODE(T4.FINAL_USER,
                                               NULL,
                                               T4.BUYER_ID,
                                               '/',
                                               T4.BUYER_ID,
                                               T4.FINAL_USER)),
                 DECODE(T4.FINAL_USER_DESC,
                        NULL,
                        T4.BUYER_NAME,
                        '/',
                        T4.BUYER_NAME,
                        T4.FINAL_USER_DESC)) 用户,
       t.Gradename 钢种,
       T4.OUTDIAMETER 名义外径,
       T4.WALLTHICK 名义壁厚,
       t.Gpreq_Weight 需坯量,
       b.diameter_gp 断面,
       b.gpreq_id  外购坯需求号,
       DECODE(b.rec_type,'0','正常','1','预排','') 外购需求类型,
       DECODE(b.req_status,'1','生效','2','提报','4','交齐','') 外购需求类型,
       b.issued_time 提报日期,
       a.Order_No 采购合同号,
       a.order_sqe 采购合同行号,
       a.supp_code 供货商,
       a.gradename 外购钢种,
       a.weight_num 合同量,
       a.length 长度,
       a.create_time 合同生成日期 
  	FROM  BUY_GP_ORDER a,
      PLN_REQINF_GP b,
      PLN_ORDER_ZG_S t,
      PLN_SALEORD T4
  	WHERE b.gpreq_id = a.gpbuyplanid(+)
  	AND   b.gpreq_id = t.gpreq_id(+) 
  	AND   t.Ord_Ln_Dly_Pk = T4.ORD_LN_DLY_PK(+)
  	AND   b.req_status > 0
  	AND   b.ifbuyplan ='1'
  	AND   b.req_donestatus >0
        ]]>
	</query>
	<query id="BuyGpDAL.UPDATE_CGPREQUIRES_TD" desc="外购坯脱单">
		<![CDATA[
	    BEGIN
		    UPDATE PLN_REQINF_GP b
			SET gp_syweight = nvl(gp_syweight,0)+(
			WITH t
			AS
			(
			SELECT sum(nvl(t.actual_weight,0)) actual_weight,gpreq_id FROM PLN_ORDER_ZG_S t
			WHERE t.gpreq_id = #gpreq_id# AND t.pro_plan_id||'-'||t.gx_plan_no in ( #plan_id# )
			GROUP BY gpreq_id
			)
			SELECT ACTUAL_WEIGHT FROM t WHERE t.gpreq_id = b.gpreq_id
			)
			WHERE req_status = '2'
			AND ifbuyplan=1 
			AND req_donestatus=1;
			AND gpreq_id = #gpreq_id# ;
	
	
			UPDATE PLN_REQINF_GP b
			SET gp_weight = gp_weight-(
			WITH t
			AS
			(
			SELECT sum(nvl(t.actual_weight,0)) actual_weight,gpreq_id FROM PLN_ORDER_ZG_S t
			WHERE t.gpreq_id = #gpreq_id# AND t.pro_plan_id||'-'||t.gx_plan_no in ( #plan_id# )
			GROUP BY gpreq_id
			)
			SELECT ACTUAL_WEIGHT FROM t WHERE t.gpreq_id = b.gpreq_id
			)
			WHERE req_status = '1'
			AND ifbuyplan=1 
			AND req_donestatus=1;
			AND gpreq_id = #gpreq_id# ;
	
			UPDATE PLN_ORDER_ZG_S
			SET GPREQ_ID = NULL,
			GPREQ_IF_OK =0,
			STATE_SINGLE=2
			WHERE pro_plan_id||'-'||gx_plan_no in ( #plan_id# );
			
			DELETE FROM PLN_REQINF_GP WHERE GP_WEIGHT <=0  AND REQ_STATUS IN (0,1) AND ifbuyplan=1 and req_donestatus=1;
        END;
        ]]>
	</query>
	<query id="BuyGpDAL.insertBUY_CGP_DCYB" desc="插入到厂预报">
		<![CDATA[
		INSERT INTO BUY_GP_DCYB
		(
		STOVE_NO,
		DCYB_PK,
		JUDGE_STOVE_NO,
		PLAN_COUNT,
		PLAN_WEIGHT,
		DH_DATE,
		CREATE_TIME,
		CREATE_NAME,
		ORD_NO_PK
		)
		VALUES
		(
		?,
		SYS_GUID(),
		?,
		?,
		?,
		to_date(?,'YYYY-MM-DD'),
		SYSDATE,
		?,
		?
		)
		]]>
	</query>
	<query id="BuyGpDAL.updateBUY_CGP_DCYB" desc="更新到厂预报">
		<![CDATA[
		UPDATE BUY_GP_DCYB
		SET STOVE_NO=?,
		JUDGE_STOVE_NO=?,
		PLAN_COUNT=?,
		PLAN_WEIGHT=?,
		DH_DATE=to_date(?,'YYYY-MM-DD'),
		UPDATE_NAME=?
		WHERE DCYB_PK=?
		]]>
	</query>
	<query id="BuyGpDAL.deleteBUY_CGP_DCYB" desc="删除到厂预报">
		<![CDATA[
        DELETE FROM  BUY_GP_DCYB
        WHERE DCYB_PK=?
		]]>
	</query>
	<query id="BuyGpDAL.getBUY_CGP_DCYB" desc="插入到厂预报">
		<![CDATA[
		SELECT 
		STOVE_NO 炉号,
		JUDGE_STOVE_NO 判定炉号,
		PLAN_COUNT 支数,
		PLAN_WEIGHT 吨数,
		DH_DATE 到货日期,
		DCYB_PK
		FROM BUY_GP_DCYB
		WHERE ORD_NO_PK = ?
		]]>
	</query>
	<query id="BuyGpDAL.get_MAT_GP_M" desc="查询采购坯库存表">
	 <![CDATA[
	 SELECT STOVE_NO 炉号,
	 JUDGE_STOVE_NO 判定炉号,
	 DIMATER 断面,
	 GRADENAME 钢种,
	 FIX_NUM 倍尺,
	 ACT_LEN 长度,
	 CREATE_TIME 日期,
	 SUM(ACT_COUNT) 支数,
	 SUM(ACT_WEIGHT) 重量
	 FROM MAT_GP_M
	 WHERE 1=1 
	 GROUP BY  STOVE_NO,JUDGE_STOVE_NO,DIMATER,GRADENAME,FIX_NUM,ACT_LEN ,CREATE_TIME
	 ]]>
	</query>
		<query id="BuyGpDAL.insert_MAT_GP_M" desc="采购坯入库库存表">
		<![CDATA[
		INSERT INTO MAT_GP_M
		(
		 MAT_NO,       --材料号（坯号）规则---(15)----母料号000
		 PRODUCT_FLAG, --材料类别（8014在制品、成品、商品）
		 MAT_STATUS,   --材料状态（801501在制品阶段、801502成品、801503商品...）
		 STOVE_NO,     --熔炼炉号
		 JUDGE_STOVE_NO, --判定炉号
		 --MAT_ORIGIN_CODE, --材料来源类型代码（1外购、2机组产出等）
		 MATERIAL_NO,     --物料码
		 MATERIAL_NAME,   --物料描叙
		 GRADECODE,       --钢种代码
		 GRADENAME,       --钢种名称
		 STD_CODE,        --标准代码
		 STD_NAME,        --标准名称
		 DIMATER,         --直径或宽度(实际)
		 ACT_LEN,         --坯料长度(实际)
		 FIX_NUM,         --倍尺数(实际)
		 FIX_LEN,         --单倍长度(实际)
		 ACT_COUNT,       --材料支数(实际)
		 ACT_WEIGHT,      --材料实重(实际)
		 ACT_THEORY_WEIGHT, --材料理论重量(实际)
		 BELONG_CODE,       --所属权单位代码
		 BELONG_NAME,       --所属权单位
		 INSTOCK_TIME,      --入库时间(首次)
		 BAL_YEAR_MONTH,    --结算日期（年月）
		 CREATE_NAME,       --创建人
		 CREATE_TIME,        --创建时间
		 --FURNACENO,           --虚拟炉号
		 PLINE_NAME,          --产线名称
		 PLINE_CODE,          --产线代码
		 GPTYPE,             --管坯类型
		 PRO_ORDER_NO,        --采购合同号
		 ORD_PK,              --采购合同号PK值
		 DB_ACT_COUNT,        --单倍坯支数
		 CIC,
		 PIC,
		 SIC,
		 DIC,
		 QCM_STAUS,           --交库状态
		 MAT_ORIGIN_CODE,     --材料类型来源代码
		 MAT_ORIGIN_NAME,     --材料类型来源名称
		 PRO_PLAN_ID,          --铸造订单编号(传采购需求单号) 
		 GPREQ_ID,             --传采购需求单号
		 FURNACENO,            --虚拟炉号
         SEQUENCENO,            --顺序号
         SOURE_NAME,           --材料来源地名称
		 SOURE_CODE,           --材料来源地代码
		 GROUD_NO,              --组号
		 SUPPLY_UNIT_CODE,          --制造商代码
	     SUPPLY_UNIT                --制造商
		)
		    SELECT 
		      '#judge_stove_no#'||
		                       substr((
		           select  TO_NUMBER(REGEXP_REPLACE(nvl(max(mat_no),10000),'[^0-9.]','')) rn from 
		                 mat_gp_m
		           where judge_stove_no ='#judge_stove_no#'
		                 ) +rownum,-3),
		     '801401',
		     '80150101',
		   	 '#stove_no#',
			 '#judge_stove_no#',
		     --'1',
		     (select material_no from buy_gp_order where ord_no_pk='#ord_no_pk#'),
			 (select material_name from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		     (select gradecode from buy_gp_order where ord_no_pk='#ord_no_pk#'),
			 (select gradename from buy_gp_order where ord_no_pk='#ord_no_pk#'),
			 --(select std_code from buy_gp_order where ord_no_pk='#ord_no_pk#'),
			  null,
			  null,
		     (select diameter from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		     --(select len_gp_single * #bc# from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		     #gplength#,
		     #bc#,
		     (select len_gp_single from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		     1,
		     --'#act_weight#',
		     case  when ROWNUM <#count#  then round(#weight#/#count#,3)  else #weight#-round((#weight#/#count#),3)*(#count# - 1) end,
		     null,
		     decode((SELECT  supply_unit_code FROM pln_reqinf_gp WHERE gpreq_id =(SELECT  gpbuyplanid  from buy_gp_order where ord_no_pk='#ord_no_pk#')),
        		 '120501','002001001','120504','002023005',''),
		  	 decode((SELECT  supply_unit_code FROM pln_reqinf_gp WHERE gpreq_id =(SELECT  gpbuyplanid  from buy_gp_order where ord_no_pk='#ord_no_pk#')),
        		 '120501','生产计划部','120504','产品制造部',''),
		     sysdate,
		     --to_char(sysdate,'yyyymm'),
			 decode(sign(sysdate -to_date(to_char(SYSDATE,'yyyy-mm')||'-25'||' 21:00:00','yyyy-MM-dd HH24:mi:ss')),'1',to_char(add_months(trunc(sysdate),1),'yyyymm'),'-1',to_char(SYSDATE,'yyyymm'),'0',to_char(add_months(trunc(sysdate),1),'yyyymm')),
		     '#create_name#',
			 sysdate,
		     --null,
		     (select CASE GPTYPE  WHEN '0' THEN '轧坯(外购)' WHEN '1' THEN '连铸坯(外购)' ELSE '锻坯(外购)' END from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		     (select CASE GPTYPE  WHEN '0' THEN 'C063' WHEN '1' THEN 'C063' ELSE 'C064' END from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		     (select GPTYPE from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		     (select ORDER_NO ||'/'||SUBSTR(TO_CHAR(1000+TO_NUMBER(ORDER_SQE)),-3) from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		     '#ord_no_pk#',
		     #bc#,
		     (
		     SELECT CIC FROM PLN_REQINF_GP WHERE GPREQ_ID =
              (
 				SELECT GPBUYPLANID FROM BUY_GP_ORDER WHERE ORD_NO_PK ='#ord_no_pk#'
			  )
			 ),
			 (
		     SELECT PIC FROM PLN_REQINF_GP WHERE GPREQ_ID =
              (
 				SELECT GPBUYPLANID FROM BUY_GP_ORDER WHERE ORD_NO_PK ='#ord_no_pk#'
			  )
			 ),
			 (
		     SELECT SIC FROM PLN_REQINF_GP WHERE GPREQ_ID =
              (
 				SELECT GPBUYPLANID FROM BUY_GP_ORDER WHERE ORD_NO_PK ='#ord_no_pk#'
			  )
			 ),
			 (
		     SELECT DIC FROM PLN_REQINF_GP WHERE GPREQ_ID =
              (
 				SELECT GPBUYPLANID FROM BUY_GP_ORDER WHERE ORD_NO_PK ='#ord_no_pk#'
			  )
			 ),
			 '00',
			 '801301',
			 '外购',
			 (select gpbuyplanid from buy_gp_order where ord_no_pk='#ord_no_pk#'),
			 (select gpbuyplanid from buy_gp_order where ord_no_pk='#ord_no_pk#'),
			 --'#judge_stove_no#' ||'-'||'#bc#',
			 '#judge_stove_no#' ||'-'||'1',
             1,
             (select SUPP_CODE from buy_gp_order where ord_no_pk='#ord_no_pk#'),
             (SELECT  SUPP_CODE  FROM COM_BASE_SUPP
             WHERE SUPP_SHORT_NAME =(select SUPP_CODE from buy_gp_order where ord_no_pk='#ord_no_pk#')),
             '#bc#',
            (SELECT SUPPLY_UNIT_CODE FROM pln_reqinf_gp WHERE gpreq_id = (SELECT max(gpbuyplanid) from buy_gp_order where ord_no_pk='#ord_no_pk#')),
		  	(SELECT SUPPLY_UNIT FROM pln_reqinf_gp WHERE gpreq_id = (SELECT max(gpbuyplanid) from buy_gp_order where ord_no_pk='#ord_no_pk#'))
		    FROM DUAL CONNECT BY ROWNUM <=#count# 
			]]>
	</query>
	<query id="BuyGpDAL.insert_MAT_GP_M_TH" desc="采购坯入库库存表(天淮)">
		<![CDATA[
		INSERT INTO MAT_GP_M
		(
		 MAT_NO,       --材料号（坯号）规则---(15)----母料号000
		 PRODUCT_FLAG, --材料类别（8014在制品、成品、商品）
		 MAT_STATUS,   --材料状态（801501在制品阶段、801502成品、801503商品...）
		 STOVE_NO,     --熔炼炉号
		 JUDGE_STOVE_NO, --判定炉号
		 --MAT_ORIGIN_CODE, --材料来源类型代码（1外购、2机组产出等）
		 MATERIAL_NO,     --物料码
		 MATERIAL_NAME,   --物料描叙
		 GRADECODE,       --钢种代码
		 GRADENAME,       --钢种名称
		 STD_CODE,        --标准代码
		 STD_NAME,        --标准名称
		 DIMATER,         --直径或宽度(实际)
		 ACT_LEN,         --坯料长度(实际)
		 FIX_NUM,         --倍尺数(实际)
		 FIX_LEN,         --单倍长度(实际)
		 ACT_COUNT,       --材料支数(实际)
		 ACT_WEIGHT,      --材料实重(实际)
		 ACT_THEORY_WEIGHT, --材料理论重量(实际)
		 BELONG_CODE,       --所属权单位代码
		 BELONG_NAME,       --所属权单位
		 INSTOCK_TIME,      --入库时间(首次)
		 BAL_YEAR_MONTH,    --结算日期（年月）
		 CREATE_NAME,       --创建人
		 CREATE_TIME,        --创建时间
		 --FURNACENO,           --虚拟炉号
		 PLINE_NAME,          --产线名称
		 PLINE_CODE,          --产线代码
		 GPTYPE,             --管坯类型
		 PRO_ORDER_NO,        --采购合同号
		 ORD_PK,              --采购合同号PK值
		 DB_ACT_COUNT,        --单倍坯支数
		 CIC,
		 PIC,
		 SIC,
		 DIC,
		 QCM_STAUS,           --交库状态
		 MAT_ORIGIN_CODE,     --材料类型来源代码
		 MAT_ORIGIN_NAME,     --材料类型来源名称
		 PRO_PLAN_ID,          --铸造订单编号(传采购需求单号) 
		 GPREQ_ID,             --传采购需求单号
		 FURNACENO,            --虚拟炉号
         SEQUENCENO,            --顺序号
         SOURE_NAME,           --材料来源地名称
		 SOURE_CODE,           --材料来源地代码
		 GROUD_NO,              --组号
		 SUPPLY_UNIT_CODE,          --制造商代码
	     SUPPLY_UNIT,                --制造商
	     IS_DEALER          --是否双经销
		)
		    SELECT
		     '#judge_stove_no#' ||
			   substr((
			   select  TO_NUMBER(REGEXP_REPLACE(nvl(max(mat_no),10000),'[^0-9.]','')) rn from 
		       	( select mat_no from      YDM_GP_INLIST
		           where STOVE_NO ='#judge_stove_no#' and mat_no like '#judge_stove_no#%'
		           and instock_type_code='800701' and supply_unit_code='120504'
               union all
               select mat_no from mat_gp_m  
               where STOVE_NO ='#judge_stove_no#' and mat_no like '#judge_stove_no#%' and supply_unit_code='120504'
               union all
               select mat_no from mat_gp_m_history  
               where STOVE_NO ='#judge_stove_no#' and mat_no like '#judge_stove_no#%' and supply_unit_code='120504'
               )
	           ) +1-rownum,-3),
		     '801401',
		     '80150101',
		   	 '#stove_no#',
		   	 null,
			 --'#judge_stove_no#',
		     --'1',
		     (select material_no from buy_gp_order where ord_no_pk='#ord_no_pk#'),
			 (select material_name from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		     (select gradecode from buy_gp_order where ord_no_pk='#ord_no_pk#'),
			 (select gradename from buy_gp_order where ord_no_pk='#ord_no_pk#'),
			 --(select std_code from buy_gp_order where ord_no_pk='#ord_no_pk#'),
			  null,
			  null,
		     (select diameter from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		     --(select len_gp_single * #bc# from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		     #gplength#,
		    decode((select len_gp_single*fix_num from buy_gp_order where ord_no_pk='#ord_no_pk#'),#gplength#,#bc#,1),
			decode((select len_gp_single*fix_num from buy_gp_order where ord_no_pk='#ord_no_pk#'),#gplength#,(select len_gp_single from buy_gp_order where ord_no_pk='#ord_no_pk#'),#gplength#),
		     1,
		     --'#act_weight#',
		     case  when ROWNUM <#count#  then round(#weight#/#count#,3)  else #weight#-round((#weight#/#count#),3)*(#count# - 1) end,
		     null,
		     decode((SELECT  supply_unit_code FROM pln_reqinf_gp WHERE gpreq_id =(SELECT  gpbuyplanid  from buy_gp_order where ord_no_pk='#ord_no_pk#')),
        		 '120501','002001001','120504','002023005',''),
		  	 decode((SELECT  supply_unit_code FROM pln_reqinf_gp WHERE gpreq_id =(SELECT  gpbuyplanid  from buy_gp_order where ord_no_pk='#ord_no_pk#')),
        		 '120501','生产计划部','120504','产品制造部',''),
		     sysdate,
		     --to_char(sysdate,'yyyymm'),
			 decode(sign(sysdate -to_date(to_char(SYSDATE,'yyyy-mm')||'-25'||' 21:00:00','yyyy-MM-dd HH24:mi:ss')),'1',to_char(add_months(trunc(sysdate),1),'yyyymm'),'-1',to_char(SYSDATE,'yyyymm'),'0',to_char(add_months(trunc(sysdate),1),'yyyymm')),
		     '#create_name#',
			 sysdate,
		     --null,
		     (select CASE GPTYPE  WHEN '0' THEN '轧坯(外购)' WHEN '1' THEN '连铸坯(外购)' ELSE '锻坯(外购)' END from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		     (select CASE GPTYPE  WHEN '0' THEN 'C063' WHEN '1' THEN 'C063' ELSE 'C064' END from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		     (select GPTYPE from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		     (select ORDER_NO ||'/'||SUBSTR(TO_CHAR(1000+TO_NUMBER(ORDER_SQE)),-3) from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		     '#ord_no_pk#',
		     #bc#,
		     (
		     SELECT CIC FROM PLN_REQINF_GP WHERE GPREQ_ID =
              (
 				SELECT GPBUYPLANID FROM BUY_GP_ORDER WHERE ORD_NO_PK ='#ord_no_pk#'
			  )
			 ),
			 (
		     SELECT PIC FROM PLN_REQINF_GP WHERE GPREQ_ID =
              (
 				SELECT GPBUYPLANID FROM BUY_GP_ORDER WHERE ORD_NO_PK ='#ord_no_pk#'
			  )
			 ),
			 (
		     SELECT SIC FROM PLN_REQINF_GP WHERE GPREQ_ID =
              (
 				SELECT GPBUYPLANID FROM BUY_GP_ORDER WHERE ORD_NO_PK ='#ord_no_pk#'
			  )
			 ),
			 (
		     SELECT DIC FROM PLN_REQINF_GP WHERE GPREQ_ID =
              (
 				SELECT GPBUYPLANID FROM BUY_GP_ORDER WHERE ORD_NO_PK ='#ord_no_pk#'
			  )
			 ),
			 '00',
			 '801301',
			 '外购',
			 (select gpbuyplanid from buy_gp_order where ord_no_pk='#ord_no_pk#'),
			 (select gpbuyplanid from buy_gp_order where ord_no_pk='#ord_no_pk#'),
			 --'#judge_stove_no#' ||'-'||'#bc#',
			 '#judge_stove_no#' ||'-'||'1',
             1,
             (select SUPP_CODE from buy_gp_order where ord_no_pk='#ord_no_pk#'),
             (SELECT  SUPP_CODE  FROM COM_BASE_SUPP
             WHERE SUPP_SHORT_NAME =(select SUPP_CODE from buy_gp_order where ord_no_pk='#ord_no_pk#')),
             '#bc#',
            (SELECT SUPPLY_UNIT_CODE FROM pln_reqinf_gp WHERE gpreq_id = (SELECT max(gpbuyplanid) from buy_gp_order where ord_no_pk='#ord_no_pk#')),
		  	(SELECT SUPPLY_UNIT FROM pln_reqinf_gp WHERE gpreq_id = (SELECT max(gpbuyplanid) from buy_gp_order where ord_no_pk='#ord_no_pk#')),
		  	(SELECT  TYPE_FLAG FROM pln_reqinf_gp WHERE gpreq_id =(SELECT  max(gpbuyplanid)  from buy_gp_order where ord_no_pk='#ord_no_pk#'))
		    FROM DUAL CONNECT BY ROWNUM <=#count# 
			]]>
	</query>
	<query id="BuyGpDAL.insert_YDM_GP_BUTTRESS" desc="采购坯入库位置表">
		<![CDATA[
		INSERT INTO
		YDM_GP_BUTTRESS t
		(
		 MAT_NO,                  --材料号
		 STOVE_NO,                --熔炼炉号
		 JUDGE_STOVE_NO,          --判定炉号
		 STORAGE_NO,              --仓库代码
		 LOCATION_NO,             --库位代码
		 LARY_NO,                 --层号
		 LOC_NO,                  --位置
		 STORAGE_ATTR,            --仓库类型(基础表YDM_BS_STORAGE)
		 STORAGE_ATTR_NAME,       --仓库类型描述(基础表YDM_BS_STORAGE)
		 STORAGE_TYPE_NO,         --库类别代码(基础表YDM_BS_STORAGE)
		 STORAGE_TYPE_NAME,       --库类别代码描述(基础表YDM_BS_STORAGE)
		 CREATE_NAME,             --创建人
		 CREATE_TIME,             --创建时间
		 GROUD_NO,                --组号(判定炉号对应长度分组)写倍尺
		 LOCATION_NAME            --库位名称
		)
		SELECT 
		  '#judge_stove_no#'||
		                   substr((
				   select  TO_NUMBER(REGEXP_REPLACE(nvl(max(mat_no),10000),'[^0-9.]','')) rn from 
			           YDM_GP_BUTTRESS
				   where judge_stove_no ='#judge_stove_no#'
			           ) +rownum,-3),
		  '#stove_no#',
		  '#judge_stove_no#',
		  --'#department_id#',
		  --'#department_id#' || '10101',
		  (select STORAGE_NO from YDM_BS_STORAGE where storage_name = '#storage_name#'),
		  (select LOCATION_NO from ydm_bs_location
		  WHERE STORAGE_NO =
		  (
 			SELECT STORAGE_NO FROM YDM_BS_STORAGE WHERE storage_name ='#storage_name#' 
		  ) and LOCATION_NAME='#location#' ),
		  '#level#',
		  null,
		  (select STORAGE_ATTR from YDM_BS_STORAGE where  storage_name = '#storage_name#'),
		  (select STORAGE_ATTR_NAME from YDM_BS_STORAGE where  storage_name = '#storage_name#'),
		  (select STORAGE_TYPE_NO from YDM_BS_STORAGE where  storage_name = '#storage_name#'),
		  (select STORAGE_TYPE_NAME from YDM_BS_STORAGE where  storage_name = '#storage_name#'),
		  '#create_name#',
		  sysdate,
		  #bc#,
		  '#location#'
		  
		FROM DUAL CONNECT BY ROWNUM <=#count# 
		]]>
	</query>
	<query id="BuyGpDAL.insert_YDM_GP_BUTTRESS_TH" desc="采购坯入库位置表">
		<![CDATA[
		INSERT INTO
		YDM_GP_BUTTRESS t
		(
		 MAT_NO,                  --材料号
		 STOVE_NO,                --熔炼炉号
		 JUDGE_STOVE_NO,          --判定炉号
		 STORAGE_NO,              --仓库代码
		 LOCATION_NO,             --库位代码
		 LARY_NO,                 --层号
		 LOC_NO,                  --位置
		 STORAGE_ATTR,            --仓库类型(基础表YDM_BS_STORAGE)
		 STORAGE_ATTR_NAME,       --仓库类型描述(基础表YDM_BS_STORAGE)
		 STORAGE_TYPE_NO,         --库类别代码(基础表YDM_BS_STORAGE)
		 STORAGE_TYPE_NAME,       --库类别代码描述(基础表YDM_BS_STORAGE)
		 CREATE_NAME,             --创建人
		 CREATE_TIME,             --创建时间
		 GROUD_NO,                --组号(判定炉号对应长度分组)写倍尺
		 LOCATION_NAME            --库位名称
		)
		SELECT 
		   '#judge_stove_no#' ||
				substr((
				select  TO_NUMBER(REGEXP_REPLACE(nvl(max(mat_no),10000),'[^0-9.]','')) rn from 
		       	( select mat_no from      YDM_GP_INLIST
		           where STOVE_NO ='#judge_stove_no#' and mat_no like '#judge_stove_no#%'
		           and instock_type_code='800701' and supply_unit_code='120504'
               union all
               select mat_no from mat_gp_m  
               where STOVE_NO ='#judge_stove_no#' and mat_no like '#judge_stove_no#%' and supply_unit_code='120504'
               union all
               select mat_no from mat_gp_m_history  
               where STOVE_NO ='#judge_stove_no#' and mat_no like '#judge_stove_no#%' and supply_unit_code='120504'
               )
	           ) +1-rownum,-3),
		  '#stove_no#',
		  null,
		  --'#department_id#',
		  --'#department_id#' || '10101',
		  (select STORAGE_NO from YDM_BS_STORAGE where storage_name = '#storage_name#'),
		  (select LOCATION_NO from ydm_bs_location
		  WHERE STORAGE_NO =
		  (
 			SELECT STORAGE_NO FROM YDM_BS_STORAGE WHERE storage_name ='#storage_name#' 
		  ) and LOCATION_NAME='#location#' ),
		  '#level#',
		  null,
		  (select STORAGE_ATTR from YDM_BS_STORAGE where  storage_name = '#storage_name#'),
		  (select STORAGE_ATTR_NAME from YDM_BS_STORAGE where  storage_name = '#storage_name#'),
		  (select STORAGE_TYPE_NO from YDM_BS_STORAGE where  storage_name = '#storage_name#'),
		  (select STORAGE_TYPE_NAME from YDM_BS_STORAGE where  storage_name = '#storage_name#'),
		  '#create_name#',
		  sysdate,
		  #bc#,
		  '#location#'
		  
		FROM DUAL CONNECT BY ROWNUM <=#count# 
		]]>
	</query>
	<query id="BuyGpDAL.get_TH_GP_JUDGE_STOVE_NO" desc="获取天淮采购坯入库当前最大炉号">
		<![CDATA[
		SELECT 'A'||to_char(sysdate,'yymm')|| SUBSTR(10001+(select  to_number(substr(10000+substr(nvl(max(judge_stove_no),10000),-4),-4))  from Ydm_Gp_Inlist
		where judge_stove_no > 'A'||to_char(sysdate,'yymm')||'0000'),2)
		FROM dual
			]]>
	</query>
	<query id="BuyGpDAL.insert_Ydm_Gp_Inlist" desc="采购坯入库实绩表">
		<![CDATA[
	     INSERT INTO Ydm_Gp_Inlist
		(
		 INSTOCK_SQE,     --入库流水号
		 INSTOCK_DOC,     --入库单编号
		 INSTOCK_TYPE_CODE,--入库类型编码
		 INSTOCK_TYPE_NAME,--入库类型名称
		 VEHICLE_NO,       --车牌号
		 MAT_NO,           --材料号
		 PRODUCT_FLAG,     --材料类别
		 MAT_STATUS,       --材料状态
		 STOVE_NO,         --熔炼炉号
		 JUDGE_STOVE_NO,   --判定炉号
		 MAT_ORIGIN_CODE,  --材料来源类型代码（1外购、2机组产出等）
		 MAT_ORIGIN_NAME,  --材料来源类型名称
		 SOURE_CODE,       --材料来源地代码（产线、外委、外购对应的具体项目）
		 SOURE_NAME,       --材料来源地名称
		 ORDER_NO,         --合同号
		 ORD_PK,           --合同主键
		 MATERIAL_NO,      --物料码
		 MATERIAL_NAME,    --物料描述
		 GRADECODE,        --钢种代码
		 GRADENAME,        --钢种名称
		 STD_CODE,         --标准代码
		 STD_NAME,         --标准名称
		 DIMATER,          --直径或宽度（断面）
		 ACT_LEN,          --坯料长度（实际）
		 FIX_NUM,          --倍尺数（实际）
		 FIX_LEN,          --单倍长度（实际）
		 ACT_COUNT,        --材料支数（实际）
		 ACT_WEIGHT,       --材料实重（实际）
		 ACT_THEORY_WEIGHT,--材料理论重量(实际)
		 STORAGE_NO,       --仓库代码
		 LOCATION_NO,      --库位代码
		 LARY_NO,          --层号
		 LOC_NO,           --位置
		 INSTOCK_TIME,     --入库时间
		 IN_BC,            --入库班次
		 IN_BZ,            --入库班组
		 IN_TIME_F,        --首次入库时间
		 STORAGE_ATTR,            --仓库类型(基础表YDM_BS_STORAGE)
		 STORAGE_ATTR_NAME,       --仓库类型描述(基础表YDM_BS_STORAGE)
		 STORAGE_TYPE_NO,         --库类别代码(基础表YDM_BS_STORAGE)
		 STORAGE_TYPE_NAME,       --库类别代码描述(基础表YDM_BS_STORAGE)
		 CREATE_NAME,             --创建人
		 CREATE_TIME,              --创建时间
		 PLINE_NAME,               --产线描述
		 PLINE_CODE,               --产线代码
		 BELONG_CODE,              --所属权单位代码
		 BELONG_NAME,               --所属权单位
		 GROUD_NO ,                --组号
		 JUDGE_STOVE_NO_SEQ,       --判定炉号序号
		 FURNACENO,                 --虚拟炉号
		 SUPPLY_UNIT_CODE,          --制造商代码
		 SUPPLY_UNIT,                --制造商
		 BAL_YEAR_MONTH              --结算日期（年月）
		)
		SELECT
		    'IA'||to_char(sysdate,'yymmdd')|| '#rn#'
		    || SUBSTR(
            1000+ROWNUM+(select  to_number(substr(10000+substr(nvl(max(INSTOCK_SQE),10000),-4),-4))  from 
            Ydm_Gp_Inlist
            --where instock_doc like 'IA'||to_char(sysdate,'yymmdd')|| '%'),-4
            where instock_doc  = 'IA'||to_char(sysdate,'yymmdd')|| '#rn#'),-4
            )
		   /*
		   (
		   WITH t
		   AS
		   (
		   select  substr(10000+substr(nvl(max(instock_doc),10000),-4)+1,-4) rn from 
		   Ydm_Gp_Inlist
		   where instock_doc like 'IA'||to_char(sysdate,'yymmdd')|| '%'
		   )
		   select 'IA'||to_char(sysdate,'yymmdd')|| '#rn#' 
		   || SUBSTR(10000+ROWNUM+
		    (select  to_number(substr(10000+substr(nvl(max(instock_doc),10000),-4)+1,-4))  from 
            Ydm_Gp_Inlist
            where instock_doc like 'IA'||to_char(sysdate,'yymmdd')|| '%')
		   ,-4) */
		   ,
		   (
		   WITH t
		   AS
		   (
		   select  substr(10000+substr(nvl(max(instock_doc),10000),-4)+1,-3) rn from 
		   Ydm_Gp_Inlist
		   where instock_doc like 'IA'||to_char(sysdate,'yymmdd')|| '%'
		   )
		   select 'IA'||to_char(sysdate,'yymmdd')|| '#rn#' from dual
		   ),
		   '800701',
		   '产出入库',
		   '#car_no#',
		   '#judge_stove_no#'||
		   substr((
		   select  TO_NUMBER(REGEXP_REPLACE(nvl(max(mat_no),10000),'[^0-9.]','')) rn from 
	           Ydm_Gp_Inlist
		   where judge_stove_no ='#judge_stove_no#'
	           ) +rownum,-3),
		   '801401',
		   '80150101',
		   '#stove_no#',
		   '#judge_stove_no#',
		   '801301',
		   '外购',
           (SELECT  SUPP_CODE  FROM COM_BASE_SUPP
           WHERE SUPP_SHORT_NAME =(select SUPP_CODE from buy_gp_order where ord_no_pk='#ord_no_pk#')),
           (select SUPP_CODE from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		   (select ORDER_NO || '/' ||           
           SUBSTR(TO_CHAR(1000+TO_NUMBER(ORDER_SQE)),-3) from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		   '#ord_no_pk#',
		  (select material_no from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		  (select material_name from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		  (select gradecode from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		  (select gradename from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		  (select std_code from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		  null,
		  (select diameter from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		  --(select len_gp_single * #bc# from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		  decode((SELECT  supply_unit_code FROM pln_reqinf_gp WHERE gpreq_id =(SELECT  gpbuyplanid  from buy_gp_order where ord_no_pk='#ord_no_pk#')),
        		 '120501',(select len_gp_single * #bc# from buy_gp_order where ord_no_pk='#ord_no_pk#'),'120504','#gplength#',''),
		  #bc#,
		  (select len_gp_single from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		  1,
		  --'#act_weight#',
		  case  when ROWNUM <#count#  then round(#weight#/#count#,3)  else #weight#-round((#weight#/#count#),3)*(#count# - 1) end,
		  null,
		  (select STORAGE_NO from YDM_BS_STORAGE where storage_name = '#storage_name#'),
		  (select LOCATION_NO from ydm_bs_location
		  WHERE STORAGE_NO =
		  (
 			SELECT STORAGE_NO FROM YDM_BS_STORAGE WHERE storage_name ='#storage_name#' 
		  ) and LOCATION_NAME='#location#' ),
		  '#level#',
		  null,
		  sysdate,
		  null,
		  null, 
		  sysdate,
		  (select STORAGE_ATTR from YDM_BS_STORAGE where  storage_name = '#storage_name#'),
		  (select STORAGE_ATTR_NAME from YDM_BS_STORAGE where  storage_name = '#storage_name#'),
		  (select STORAGE_TYPE_NO from YDM_BS_STORAGE where  storage_name = '#storage_name#'),
		  (select STORAGE_TYPE_NAME from YDM_BS_STORAGE where  storage_name = '#storage_name#'),
		  '#create_name#',
		  sysdate,
		   (select CASE GPTYPE  WHEN '0' THEN '轧坯(外购)' WHEN '1' THEN '连铸坯(外购)' ELSE '锻坯(外购)' END from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		     (select CASE GPTYPE  WHEN '0' THEN 'C063' WHEN '1' THEN 'C063' ELSE 'C064' END from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		   decode((SELECT  supply_unit_code FROM pln_reqinf_gp WHERE gpreq_id =(SELECT  gpbuyplanid  from buy_gp_order where ord_no_pk='#ord_no_pk#')),
        		 '120501','002001001','120504','002023005',''),
		  decode((SELECT  supply_unit_code FROM pln_reqinf_gp WHERE gpreq_id =(SELECT  gpbuyplanid  from buy_gp_order where ord_no_pk='#ord_no_pk#')),
        		 '120501','生产计划部','120504','产品制造部',''),
		  '#bc#',
		  '#judge_stove_no#' || '-01',
		  '#judge_stove_no#' ||'-'||'1',
		  (SELECT SUPPLY_UNIT_CODE FROM pln_reqinf_gp WHERE gpreq_id = (SELECT max(gpbuyplanid) from buy_gp_order where ord_no_pk='#ord_no_pk#')),
		  (SELECT SUPPLY_UNIT FROM pln_reqinf_gp WHERE gpreq_id = (SELECT max(gpbuyplanid) from buy_gp_order where ord_no_pk='#ord_no_pk#')),
		  decode(sign(sysdate -to_date(to_char(SYSDATE,'yyyy-mm')||'-25'||' 21:00:00','yyyy-MM-dd HH24:mi:ss')),'1',to_char(add_months(trunc(sysdate),1),'yyyymm'),'-1',to_char(SYSDATE,'yyyymm'),'0',to_char(add_months(trunc(sysdate),1),'yyyymm'))
		FROM DUAL CONNECT BY ROWNUM <= #count# 
		]]>
	</query>
	<query id="BuyGpDAL.insert_Ydm_Gp_Inlist_TH" desc="采购坯入库实绩表(天淮)">
		<![CDATA[
	     INSERT INTO Ydm_Gp_Inlist
		(
		 INSTOCK_SQE,     --入库流水号
		 INSTOCK_DOC,     --入库单编号
		 INSTOCK_TYPE_CODE,--入库类型编码
		 INSTOCK_TYPE_NAME,--入库类型名称
		 VEHICLE_NO,       --车牌号
		 MAT_NO,           --材料号
		 PRODUCT_FLAG,     --材料类别
		 MAT_STATUS,       --材料状态
		 STOVE_NO,         --熔炼炉号
		 JUDGE_STOVE_NO,   --判定炉号
		 MAT_ORIGIN_CODE,  --材料来源类型代码（1外购、2机组产出等）
		 MAT_ORIGIN_NAME,  --材料来源类型名称
		 SOURE_CODE,       --材料来源地代码（产线、外委、外购对应的具体项目）
		 SOURE_NAME,       --材料来源地名称
		 ORDER_NO,         --合同号
		 ORD_PK,           --合同主键
		 MATERIAL_NO,      --物料码
		 MATERIAL_NAME,    --物料描述
		 GRADECODE,        --钢种代码
		 GRADENAME,        --钢种名称
		 STD_CODE,         --标准代码
		 STD_NAME,         --标准名称
		 DIMATER,          --直径或宽度（断面）
		 ACT_LEN,          --坯料长度（实际）
		 FIX_NUM,          --倍尺数（实际）
		 FIX_LEN,          --单倍长度（实际）
		 ACT_COUNT,        --材料支数（实际）
		 ACT_WEIGHT,       --材料实重（实际）
		 ACT_THEORY_WEIGHT,--材料理论重量(实际)
		 STORAGE_NO,       --仓库代码
		 LOCATION_NO,      --库位代码
		 LARY_NO,          --层号
		 LOC_NO,           --位置
		 INSTOCK_TIME,     --入库时间
		 IN_BC,            --入库班次
		 IN_BZ,            --入库班组
		 IN_TIME_F,        --首次入库时间
		 STORAGE_ATTR,            --仓库类型(基础表YDM_BS_STORAGE)
		 STORAGE_ATTR_NAME,       --仓库类型描述(基础表YDM_BS_STORAGE)
		 STORAGE_TYPE_NO,         --库类别代码(基础表YDM_BS_STORAGE)
		 STORAGE_TYPE_NAME,       --库类别代码描述(基础表YDM_BS_STORAGE)
		 CREATE_NAME,             --创建人
		 CREATE_TIME,              --创建时间
		 PLINE_NAME,               --产线描述
		 PLINE_CODE,               --产线代码
		 BELONG_CODE,              --所属权单位代码
		 BELONG_NAME,               --所属权单位
		 GROUD_NO ,                --组号
		 JUDGE_STOVE_NO_SEQ,       --判定炉号序号
		 FURNACENO,                 --虚拟炉号
		 SUPPLY_UNIT_CODE,          --制造商代码
		 SUPPLY_UNIT,                --制造商
		 BAL_YEAR_MONTH              --结算日期（年月）
		)
		SELECT
		    'IA'||to_char(sysdate,'yymmdd')|| '#rn#'
		    || SUBSTR(
            1000+ROWNUM+(select  to_number(substr(10000+substr(nvl(max(INSTOCK_SQE),10000),-4),-4))  from 
            Ydm_Gp_Inlist
            --where instock_doc like 'IA'||to_char(sysdate,'yymmdd')|| '%'),-4
            where INSTOCK_SQE  like 'IA'||to_char(sysdate,'yymmdd')|| '#rn#'||'%'),-4
            )
		   /*
		   (
		   WITH t
		   AS
		   (
		   select  substr(10000+substr(nvl(max(instock_doc),10000),-4)+1,-4) rn from 
		   Ydm_Gp_Inlist
		   where instock_doc like 'IA'||to_char(sysdate,'yymmdd')|| '%'
		   )
		   select 'IA'||to_char(sysdate,'yymmdd')|| '#rn#' 
		   || SUBSTR(10000+ROWNUM+
		    (select  to_number(substr(10000+substr(nvl(max(instock_doc),10000),-4)+1,-4))  from 
            Ydm_Gp_Inlist
            where instock_doc like 'IA'||to_char(sysdate,'yymmdd')|| '%')
		   ,-4) */
		   ,
		   (
		   WITH t
		   AS
		   (
		   select  substr(10000+substr(nvl(max(instock_doc),10000),-4)+1,-3) rn from 
		   Ydm_Gp_Inlist
		   where instock_doc like 'IA'||to_char(sysdate,'yymmdd')|| '%'
		   )
		   select 'IA'||to_char(sysdate,'yymmdd')|| '#rn#' from dual
		   ),
		   '800701',
		   '产出入库',
		   '#car_no#',
		    '#judge_stove_no#' ||
				substr((
		    select  TO_NUMBER(REGEXP_REPLACE(nvl(max(mat_no),10000),'[^0-9.]','')) rn from 
		       	( select mat_no from      YDM_GP_INLIST
		           where STOVE_NO ='#judge_stove_no#' and mat_no like '#judge_stove_no#%'
		           and instock_type_code='800701' and supply_unit_code='120504'
               union all
               select mat_no from mat_gp_m  
               where STOVE_NO ='#judge_stove_no#' and mat_no like '#judge_stove_no#%' and supply_unit_code='120504'
               union all
               select mat_no from mat_gp_m_history  
               where STOVE_NO ='#judge_stove_no#' and mat_no like '#judge_stove_no#%' and supply_unit_code='120504'
               )
	           ) +rownum,-3),
		   '801401',
		   '80150101',
		   '#stove_no#',
		    null,
		   '801301',
		   '外购',
           (SELECT  SUPP_CODE  FROM COM_BASE_SUPP
           WHERE SUPP_SHORT_NAME =(select SUPP_CODE from buy_gp_order where ord_no_pk='#ord_no_pk#')),
           (select SUPP_CODE from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		   (select ORDER_NO || '/' ||           
           SUBSTR(TO_CHAR(1000+TO_NUMBER(ORDER_SQE)),-3) from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		   '#ord_no_pk#',
		  (select material_no from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		  (select material_name from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		  (select gradecode from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		  (select gradename from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		  (select std_code from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		  null,
		  (select diameter from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		  --(select len_gp_single * #bc# from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		  decode((SELECT  supply_unit_code FROM pln_reqinf_gp WHERE gpreq_id =(SELECT  gpbuyplanid  from buy_gp_order where ord_no_pk='#ord_no_pk#')),
        		 '120501',(select len_gp_single * #bc# from buy_gp_order where ord_no_pk='#ord_no_pk#'),'120504','#gplength#',''),
		  decode((select len_gp_single*fix_num from buy_gp_order where ord_no_pk='#ord_no_pk#'),#gplength#,#bc#,1),
		  decode((select len_gp_single*fix_num from buy_gp_order where ord_no_pk='#ord_no_pk#'),#gplength#,(select len_gp_single from buy_gp_order where ord_no_pk='#ord_no_pk#'),#gplength#),
		  1,
		  --'#act_weight#',
		  case  when ROWNUM <#count#  then round(#weight#/#count#,3)  else #weight#-round((#weight#/#count#),3)*(#count# - 1) end,
		  null,
		  (select STORAGE_NO from YDM_BS_STORAGE where storage_name = '#storage_name#'),
		  (select LOCATION_NO from ydm_bs_location
		  WHERE STORAGE_NO =
		  (
 			SELECT STORAGE_NO FROM YDM_BS_STORAGE WHERE storage_name ='#storage_name#' 
		  ) and LOCATION_NAME='#location#' ),
		  '#level#',
		  null,
		  sysdate,
		  null,
		  null, 
		  sysdate,
		  (select STORAGE_ATTR from YDM_BS_STORAGE where  storage_name = '#storage_name#'),
		  (select STORAGE_ATTR_NAME from YDM_BS_STORAGE where  storage_name = '#storage_name#'),
		  (select STORAGE_TYPE_NO from YDM_BS_STORAGE where  storage_name = '#storage_name#'),
		  (select STORAGE_TYPE_NAME from YDM_BS_STORAGE where  storage_name = '#storage_name#'),
		  '#create_name#',
		  sysdate,
		   (select CASE GPTYPE  WHEN '0' THEN '轧坯(外购)' WHEN '1' THEN '连铸坯(外购)' ELSE '锻坯(外购)' END from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		     (select CASE GPTYPE  WHEN '0' THEN 'C063' WHEN '1' THEN 'C063' ELSE 'C064' END from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		   decode((SELECT  supply_unit_code FROM pln_reqinf_gp WHERE gpreq_id =(SELECT  gpbuyplanid  from buy_gp_order where ord_no_pk='#ord_no_pk#')),
        		 '120501','002001001','120504','002023005',''),
		  decode((SELECT  supply_unit_code FROM pln_reqinf_gp WHERE gpreq_id =(SELECT  gpbuyplanid  from buy_gp_order where ord_no_pk='#ord_no_pk#')),
        		 '120501','生产计划部','120504','产品制造部',''),
		  '#bc#',
		  '#judge_stove_no#' || '-01',
		  '#judge_stove_no#' ||'-'||'1',
		  (SELECT SUPPLY_UNIT_CODE FROM pln_reqinf_gp WHERE gpreq_id = (SELECT max(gpbuyplanid) from buy_gp_order where ord_no_pk='#ord_no_pk#')),
		  (SELECT SUPPLY_UNIT FROM pln_reqinf_gp WHERE gpreq_id = (SELECT max(gpbuyplanid) from buy_gp_order where ord_no_pk='#ord_no_pk#')),
		  decode(sign(sysdate -to_date(to_char(SYSDATE,'yyyy-mm')||'-25'||' 21:00:00','yyyy-MM-dd HH24:mi:ss')),'1',to_char(add_months(trunc(sysdate),1),'yyyymm'),'-1',to_char(SYSDATE,'yyyymm'),'0',to_char(add_months(trunc(sysdate),1),'yyyymm'))
		FROM DUAL CONNECT BY ROWNUM <= #count# 
		]]>
	</query>
	<query id="BuyGpDAL.insert_STL_LG_INSTORE_RESULT" desc="插入管坯交库实绩表">
		<![CDATA[   
		  INSERT INTO STL_LG_INSTORE_RESULT
		  (
		    PRO_PLAN_ID,   --铸造订单编号(不空) 外购坯需求单号
			GX_PLAN_NO,    --工序排产序号(不空) 1
			FURNACENO,     --虚拟炉号         （不空)
			STOVE_NO,      --熔炼炉号
			JUDGE_STOVE_NO,--标识炉号
			MATERIAL_NO,   --物料码
			MATERIAL_NAME, --物料描述
			GRADECODE,     --钢种代码
			GRADENAME,     --钢种
			DIAMETER,      --直径
			FIX_NUM,       --倍尺数
			FIX_LEN,       --单倍长度
			LENGTH,        --长度
			ACT_COUNT,     --支数
			WEIGHT,        --重量
			JUDGE_STOVE_NO_SEQ,  --判定炉号（序号）--判定炉号-01
			SEQUENCENO  ,         --顺序号（虚拟炉号） 所有都写1
			NODE_FUR_FLAG        --结炉标识
		  )
		  
		SELECT 
		(select gpbuyplanid from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		1,
		'#judge_stove_no#' ||'-'||'#bc#',
		'#stove_no#',
		'#judge_stove_no#',
		(select material_no from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		(select material_name from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		(select gradecode from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		(select gradename from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		(select diameter from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		#bc#,
		(select len_gp_single from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		--(select len_gp_single * #bc# from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		decode((SELECT  supply_unit_code FROM pln_reqinf_gp WHERE gpreq_id =(SELECT  gpbuyplanid  from buy_gp_order where ord_no_pk='#ord_no_pk#')),
        		 '120501',(select len_gp_single * #bc# from buy_gp_order where ord_no_pk='#ord_no_pk#'),'120504','#gplength#',''),
		#count#,
		#weight#,
		'#judge_stove_no#' || '-01',
		1,
		'#jielu#'
		FROM DUAL
		WHERE NOT EXISTS
		(SELECT * FROM  STL_LG_INSTORE_RESULT 
		 WHERE 
		 PRO_PLAN_ID =(select gpbuyplanid from buy_gp_order where ord_no_pk='#ord_no_pk#')
		 AND JUDGE_STOVE_NO='#judge_stove_no#'
		 AND FIX_NUM =#bc# )
		]]>
	</query>
	<query id="BuyGpDAL.insert_STL_LG_INSTORE_RESULT_TH" desc="插入管坯交库实绩表(天淮)">
		<![CDATA[   
		  INSERT INTO STL_LG_INSTORE_RESULT
		  (
		    PRO_PLAN_ID,   --铸造订单编号(不空) 外购坯需求单号
			GX_PLAN_NO,    --工序排产序号(不空) 1
			FURNACENO,     --虚拟炉号         （不空)
			STOVE_NO,      --熔炼炉号
			JUDGE_STOVE_NO,--标识炉号
			MATERIAL_NO,   --物料码
			MATERIAL_NAME, --物料描述
			GRADECODE,     --钢种代码
			GRADENAME,     --钢种
			DIAMETER,      --直径
			FIX_NUM,       --倍尺数
			FIX_LEN,       --单倍长度
			LENGTH,        --长度
			ACT_COUNT,     --支数
			WEIGHT,        --重量
			JUDGE_STOVE_NO_SEQ,  --判定炉号（序号）--判定炉号-01
			SEQUENCENO  ,         --顺序号（虚拟炉号） 所有都写1
			NODE_FUR_FLAG        --结炉标识
		  )
		  
		SELECT 
		(select gpbuyplanid from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		1,
		'#judge_stove_no#' ||'-'||'#bc#',
		'#stove_no#',
		--'#judge_stove_no#',
		null,
		(select material_no from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		(select material_name from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		(select gradecode from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		(select gradename from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		(select diameter from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		decode((select len_gp_single*fix_num from buy_gp_order where ord_no_pk='#ord_no_pk#'),#gplength#,#bc#,1),
		decode((select len_gp_single*fix_num from buy_gp_order where ord_no_pk='#ord_no_pk#'),#gplength#,(select len_gp_single from buy_gp_order where ord_no_pk='#ord_no_pk#'),#gplength#),
		--(select len_gp_single * #bc# from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		decode((SELECT  supply_unit_code FROM pln_reqinf_gp WHERE gpreq_id =(SELECT  gpbuyplanid  from buy_gp_order where ord_no_pk='#ord_no_pk#')),
        		 '120501',(select len_gp_single * #bc# from buy_gp_order where ord_no_pk='#ord_no_pk#'),'120504','#gplength#',''),
		#count#,
		#weight#,
		'#judge_stove_no#' || '-01',
		1,
		'#jielu#'
		FROM DUAL
		WHERE NOT EXISTS
		(SELECT * FROM  STL_LG_INSTORE_RESULT 
		 WHERE 
		 PRO_PLAN_ID =(select gpbuyplanid from buy_gp_order where ord_no_pk='#ord_no_pk#')
		 AND STOVE_NO='#judge_stove_no#'
		 AND LENGTH =#gplength# )
		]]>
	</query>
	<query id="BuyGpDAL.insert_MAT_GP_M_older20180204" desc="采购坯入库库存表老版本备份">
		<![CDATA[
		INSERT INTO MAT_GP_M
		(
		 MAT_NO,       --材料号（坯号）规则---(15)----母料号000
		 PRODUCT_FLAG, --材料类别（8014在制品、成品、商品）
		 MAT_STATUS,   --材料状态（801501在制品阶段、801502成品、801503商品...）
		 STOVE_NO,     --熔炼炉号
		 JUDGE_STOVE_NO, --判定炉号
		 --MAT_ORIGIN_CODE, --材料来源类型代码（1外购、2机组产出等）
		 MATERIAL_NO,     --物料码
		 MATERIAL_NAME,   --物料描叙
		 GRADECODE,       --钢种代码
		 GRADENAME,       --钢种名称
		 STD_CODE,        --标准代码
		 STD_NAME,        --标准名称
		 DIMATER,         --直径或宽度(实际)
		 ACT_LEN,         --坯料长度(实际)
		 FIX_NUM,         --倍尺数(实际)
		 FIX_LEN,         --单倍长度(实际)
		 ACT_COUNT,       --材料支数(实际)
		 ACT_WEIGHT,      --材料实重(实际)
		 ACT_THEORY_WEIGHT, --材料理论重量(实际)
		 BELONG_CODE,       --所属权单位代码
		 BELONG_NAME,       --所属权单位
		 INSTOCK_TIME,      --入库时间(首次)
		 BAL_YEAR_MONTH,    --结算日期（年月）
		 CREATE_NAME,       --创建人
		 CREATE_TIME,        --创建时间
		 --FURNACENO,           --虚拟炉号
		 PLINE_NAME,          --产线名称
		 PLINE_CODE,          --产线代码
		 GPTYPE,             --管坯类型
		 PRO_ORDER_NO,        --采购合同号
		 ORD_PK,              --采购合同号PK值
		 DB_ACT_COUNT,        --单倍坯支数
		 CIC,
		 PIC,
		 SIC,
		 DIC,
		 QCM_STAUS,           --交库状态
		 MAT_ORIGIN_CODE,     --材料类型来源代码
		 MAT_ORIGIN_NAME,     --材料类型来源名称
		 PRO_PLAN_ID,          --铸造订单编号(传采购需求单号) 
		 GPREQ_ID,             --传采购需求单号
		 FURNACENO,            --虚拟炉号
         SEQUENCENO,            --顺序号
         SOURE_NAME,           --材料来源地名称
		 SOURE_CODE            --材料来源地代码
		)
		    SELECT 
		      '#judge_stove_no#'||
		                       substr((
		           select  nvl(max(mat_no),10000) rn from 
		                 mat_gp_m
		           where judge_stove_no ='#judge_stove_no#'
		                 ) +rownum,-4),
		     '801401',
		     '80150101',
		   	 '#stove_no#',
			 '#judge_stove_no#',
		     --'1',
		     (select material_no from buy_gp_order where ord_no_pk='#ord_no_pk#'),
			 (select material_name from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		     (select gradecode from buy_gp_order where ord_no_pk='#ord_no_pk#'),
			 (select gradename from buy_gp_order where ord_no_pk='#ord_no_pk#'),
			 --(select std_code from buy_gp_order where ord_no_pk='#ord_no_pk#'),
			  null,
			  null,
		     (select diameter from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		     --(select len_gp_single * #bc# from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		     decode((SELECT  supply_unit_code FROM pln_reqinf_gp WHERE gpreq_id =(SELECT  gpbuyplanid  from buy_gp_order where ord_no_pk='#ord_no_pk#')),
        		 '120501',(select len_gp_single * #bc# from buy_gp_order where ord_no_pk='#ord_no_pk#'),'120504','#gplength#',''),
		     #bc#,
		     (select len_gp_single from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		     1,
		     --'#act_weight#',
		     case  when ROWNUM <#count#  then round(#weight#/#count#,3)  else #weight#-round((#weight#/#count#),3)*(#count# - 1) end,
		     null,
		     '002001001',
		     '生产计划部',
		     sysdate,
		     to_char(sysdate,'yyyymm'),
		     '#create_name#',
			 sysdate,
		     --null,
		     (select CASE GPTYPE WHEN '1' THEN '连铸坯(外购)' ELSE '锻坯(外购)' END from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		     (select CASE GPTYPE WHEN '1' THEN 'C063' ELSE 'C064' END from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		     (select GPTYPE from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		     (select ORDER_NO ||'/'||SUBSTR(TO_CHAR(1000+TO_NUMBER(ORDER_SQE)),-3) from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		     '#ord_no_pk#',
		     #bc#,
		     (
		     SELECT CIC FROM PLN_REQINF_GP WHERE GPREQ_ID =
              (
 				SELECT GPBUYPLANID FROM BUY_GP_ORDER WHERE ORD_NO_PK ='#ord_no_pk#'
			  )
			 ),
			 (
		     SELECT PIC FROM PLN_REQINF_GP WHERE GPREQ_ID =
              (
 				SELECT GPBUYPLANID FROM BUY_GP_ORDER WHERE ORD_NO_PK ='#ord_no_pk#'
			  )
			 ),
			 (
		     SELECT SIC FROM PLN_REQINF_GP WHERE GPREQ_ID =
              (
 				SELECT GPBUYPLANID FROM BUY_GP_ORDER WHERE ORD_NO_PK ='#ord_no_pk#'
			  )
			 ),
			 (
		     SELECT DIC FROM PLN_REQINF_GP WHERE GPREQ_ID =
              (
 				SELECT GPBUYPLANID FROM BUY_GP_ORDER WHERE ORD_NO_PK ='#ord_no_pk#'
			  )
			 ),
			 '00',
			 '801301',
			 '外购',
			 (select gpbuyplanid from buy_gp_order where ord_no_pk='#ord_no_pk#'),
			 (select gpbuyplanid from buy_gp_order where ord_no_pk='#ord_no_pk#'),
			 --'#judge_stove_no#' ||'-'||'#bc#',
			 '#judge_stove_no#' ||'-'||'1',
             1,
             (select SUPP_CODE from buy_gp_order where ord_no_pk='#ord_no_pk#'),
             (SELECT  SUPP_CODE  FROM COM_BASE_SUPP
             WHERE SUPP_SHORT_NAME =(select SUPP_CODE from buy_gp_order where ord_no_pk='#ord_no_pk#'))
		    FROM DUAL CONNECT BY ROWNUM <=#count# 
			]]>
	</query>
	<query id="BuyGpDAL.insert_YDM_GP_BUTTRESS_older20180204" desc="采购坯入库位置表老版本备份">
		<![CDATA[
		INSERT INTO
		YDM_GP_BUTTRESS t
		(
		 MAT_NO,                  --材料号
		 STOVE_NO,                --熔炼炉号
		 JUDGE_STOVE_NO,          --判定炉号
		 STORAGE_NO,              --仓库代码
		 LOCATION_NO,             --库位代码
		 LARY_NO,                 --层号
		 LOC_NO,                  --位置
		 STORAGE_ATTR,            --仓库类型(基础表YDM_BS_STORAGE)
		 STORAGE_ATTR_NAME,       --仓库类型描述(基础表YDM_BS_STORAGE)
		 STORAGE_TYPE_NO,         --库类别代码(基础表YDM_BS_STORAGE)
		 STORAGE_TYPE_NAME,       --库类别代码描述(基础表YDM_BS_STORAGE)
		 CREATE_NAME,             --创建人
		 CREATE_TIME,             --创建时间
		 GROUD_NO,                --组号(判定炉号对应长度分组)写倍尺
		 LOCATION_NAME            --库位名称
		)
		SELECT 
		  '#judge_stove_no#'||
		                   substr((
				   select  nvl(max(mat_no),10000) rn from 
			           YDM_GP_BUTTRESS
				   where judge_stove_no ='#judge_stove_no#'
			           ) +rownum,-4),
		  '#stove_no#',
		  '#judge_stove_no#',
		  --'#department_id#',
		  --'#department_id#' || '10101',
		  (select STORAGE_NO from YDM_BS_STORAGE where storage_name = '#storage_name#'),
		  (select LOCATION_NO from ydm_bs_location
		  WHERE STORAGE_NO =
		  (
 			SELECT STORAGE_NO FROM YDM_BS_STORAGE WHERE storage_name ='#storage_name#' 
		  ) and LOCATION_NAME='#location#' ),
		  '#level#',
		  null,
		  (select STORAGE_ATTR from YDM_BS_STORAGE where  storage_name = '#storage_name#'),
		  (select STORAGE_ATTR_NAME from YDM_BS_STORAGE where  storage_name = '#storage_name#'),
		  (select STORAGE_TYPE_NO from YDM_BS_STORAGE where  storage_name = '#storage_name#'),
		  (select STORAGE_TYPE_NAME from YDM_BS_STORAGE where  storage_name = '#storage_name#'),
		  '#create_name#',
		  sysdate,
		  #bc#,
		  '#location#'
		  
		FROM DUAL CONNECT BY ROWNUM <=#count# 
		]]>
	</query>
	<query id="BuyGpDAL.insert_Ydm_Gp_Inlist_older20180204" desc="采购坯入库实绩表历史版本备份">
		<![CDATA[
	     INSERT INTO Ydm_Gp_Inlist
		(
		 INSTOCK_SQE,     --入库流水号
		 INSTOCK_DOC,     --入库单编号
		 INSTOCK_TYPE_CODE,--入库类型编码
		 INSTOCK_TYPE_NAME,--入库类型名称
		 VEHICLE_NO,       --车牌号
		 MAT_NO,           --材料号
		 PRODUCT_FLAG,     --材料类别
		 MAT_STATUS,       --材料状态
		 STOVE_NO,         --熔炼炉号
		 JUDGE_STOVE_NO,   --判定炉号
		 MAT_ORIGIN_CODE,  --材料来源类型代码（1外购、2机组产出等）
		 MAT_ORIGIN_NAME,  --材料来源类型名称
		 SOURE_CODE,       --材料来源地代码（产线、外委、外购对应的具体项目）
		 SOURE_NAME,       --材料来源地名称
		 ORDER_NO,         --合同号
		 ORD_PK,           --合同主键
		 MATERIAL_NO,      --物料码
		 MATERIAL_NAME,    --物料描述
		 GRADECODE,        --钢种代码
		 GRADENAME,        --钢种名称
		 STD_CODE,         --标准代码
		 STD_NAME,         --标准名称
		 DIMATER,          --直径或宽度（断面）
		 ACT_LEN,          --坯料长度（实际）
		 FIX_NUM,          --倍尺数（实际）
		 FIX_LEN,          --单倍长度（实际）
		 ACT_COUNT,        --材料支数（实际）
		 ACT_WEIGHT,       --材料实重（实际）
		 ACT_THEORY_WEIGHT,--材料理论重量(实际)
		 STORAGE_NO,       --仓库代码
		 LOCATION_NO,      --库位代码
		 LARY_NO,          --层号
		 LOC_NO,           --位置
		 INSTOCK_TIME,     --入库时间
		 IN_BC,            --入库班次
		 IN_BZ,            --入库班组
		 IN_TIME_F,        --首次入库时间
		 STORAGE_ATTR,            --仓库类型(基础表YDM_BS_STORAGE)
		 STORAGE_ATTR_NAME,       --仓库类型描述(基础表YDM_BS_STORAGE)
		 STORAGE_TYPE_NO,         --库类别代码(基础表YDM_BS_STORAGE)
		 STORAGE_TYPE_NAME,       --库类别代码描述(基础表YDM_BS_STORAGE)
		 CREATE_NAME,             --创建人
		 CREATE_TIME,              --创建时间
		 PLINE_NAME,               --产线描述
		 PLINE_CODE,               --产线代码
		 BELONG_CODE,              --所属权单位代码
		 BELONG_NAME,               --所属权单位
		 GROUD_NO ,                --组号
		 JUDGE_STOVE_NO_SEQ,       --判定炉号序号
		 FURNACENO                 --虚拟炉号
		)
		SELECT
		    'IA'||to_char(sysdate,'yymmdd')|| '#rn#'
		    || SUBSTR(
            10000+ROWNUM+(select  to_number(substr(100000+substr(nvl(max(INSTOCK_SQE),100000),-5),-5))  from 
            Ydm_Gp_Inlist
            --where instock_doc like 'IA'||to_char(sysdate,'yymmdd')|| '%'),-4
            where instock_doc  = 'IA'||to_char(sysdate,'yymmdd')|| '#rn#'),-4
            )
		   /*
		   (
		   WITH t
		   AS
		   (
		   select  substr(100000+substr(nvl(max(instock_doc),100000),-5)+1,-5) rn from 
		   Ydm_Gp_Inlist
		   where instock_doc like 'IA'||to_char(sysdate,'yymmdd')|| '%'
		   )
		   select 'IA'||to_char(sysdate,'yymmdd')|| '#rn#' 
		   || SUBSTR(10000+ROWNUM+
		    (select  to_number(substr(100000+substr(nvl(max(instock_doc),100000),-5)+1,-5))  from 
            Ydm_Gp_Inlist
            where instock_doc like 'IA'||to_char(sysdate,'yymmdd')|| '%')
		   ,-4) */
		   ,
		   (
		   WITH t
		   AS
		   (
		   select  substr(100000+substr(nvl(max(instock_doc),100000),-5)+1,-5) rn from 
		   Ydm_Gp_Inlist
		   where instock_doc like 'IA'||to_char(sysdate,'yymmdd')|| '%'
		   )
		   select 'IA'||to_char(sysdate,'yymmdd')|| '#rn#' from dual
		   ),
		   '800701',
		   '产出入库',
		   '#car_no#',
		   '#judge_stove_no#'||
		   substr((
		   select  nvl(max(mat_no),10000) rn from 
	           Ydm_Gp_Inlist
		   where judge_stove_no ='#judge_stove_no#'
	           ) +rownum,-4),
		   '801401',
		   '80150101',
		   '#stove_no#',
		   '#judge_stove_no#',
		   '801301',
		   '外购',
           (SELECT  SUPP_CODE  FROM COM_BASE_SUPP
           WHERE SUPP_SHORT_NAME =(select SUPP_CODE from buy_gp_order where ord_no_pk='#ord_no_pk#')),
           (select SUPP_CODE from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		   (select ORDER_NO || '/' ||           
           SUBSTR(TO_CHAR(1000+TO_NUMBER(ORDER_SQE)),-3) from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		   '#ord_no_pk#',
		  (select material_no from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		  (select material_name from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		  (select gradecode from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		  (select gradename from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		  (select std_code from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		  null,
		  (select diameter from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		  (select len_gp_single * #bc# from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		  #bc#,
		  (select len_gp_single from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		  1,
		  --'#act_weight#',
		  case  when ROWNUM <#count#  then round(#weight#/#count#,3)  else #weight#-round((#weight#/#count#),3)*(#count# - 1) end,
		  null,
		  (select STORAGE_NO from YDM_BS_STORAGE where storage_name = '#storage_name#'),
		  (select LOCATION_NO from ydm_bs_location
		  WHERE STORAGE_NO =
		  (
 			SELECT STORAGE_NO FROM YDM_BS_STORAGE WHERE storage_name ='#storage_name#' 
		  ) and LOCATION_NAME='#location#' ),
		  '#level#',
		  null,
		  sysdate,
		  null,
		  null, 
		  sysdate,
		  (select STORAGE_ATTR from YDM_BS_STORAGE where  storage_name = '#storage_name#'),
		  (select STORAGE_ATTR_NAME from YDM_BS_STORAGE where  storage_name = '#storage_name#'),
		  (select STORAGE_TYPE_NO from YDM_BS_STORAGE where  storage_name = '#storage_name#'),
		  (select STORAGE_TYPE_NAME from YDM_BS_STORAGE where  storage_name = '#storage_name#'),
		  '#create_name#',
		  sysdate,
		  (select CASE GPTYPE WHEN '1' THEN '连铸坯(外购)' ELSE '锻坯(外购)' END from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		  (select CASE GPTYPE WHEN '1' THEN 'C063' ELSE 'C064' END from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		  '002001001',
		  '生产计划部',
		  '#bc#',
		  '#judge_stove_no#' || '-01',
		  '#judge_stove_no#' ||'-'||'1'
		FROM DUAL CONNECT BY ROWNUM <= #count# 
		]]>
	</query>
	<query id="BuyGpDAL.insert_STL_LG_INSTORE_RESULT_older20180204" desc="插入管坯交库实绩表历史版本备份">
		<![CDATA[   
		  INSERT INTO STL_LG_INSTORE_RESULT
		  (
		    PRO_PLAN_ID,   --铸造订单编号(不空) 外购坯需求单号
			GX_PLAN_NO,    --工序排产序号(不空) 1
			FURNACENO,     --虚拟炉号         （不空)
			STOVE_NO,      --熔炼炉号
			JUDGE_STOVE_NO,--标识炉号
			MATERIAL_NO,   --物料码
			MATERIAL_NAME, --物料描述
			GRADECODE,     --钢种代码
			GRADENAME,     --钢种
			DIAMETER,      --直径
			FIX_NUM,       --倍尺数
			FIX_LEN,       --单倍长度
			LENGTH,        --长度
			ACT_COUNT,     --支数
			WEIGHT,        --重量
			JUDGE_STOVE_NO_SEQ,  --判定炉号（序号）--判定炉号-01
			SEQUENCENO  ,         --顺序号（虚拟炉号） 所有都写1
			NODE_FUR_FLAG        --结炉标识
		  )
		  
		SELECT 
		(select gpbuyplanid from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		1,
		'#judge_stove_no#' ||'-'||'#bc#',
		'#stove_no#',
		'#judge_stove_no#',
		(select material_no from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		(select material_name from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		(select gradecode from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		(select gradename from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		(select diameter from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		#bc#,
		(select len_gp_single from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		(select len_gp_single * #bc# from buy_gp_order where ord_no_pk='#ord_no_pk#'),
		#count#,
		#weight#,
		'#judge_stove_no#' || '-01',
		1,
		'#jielu#'
		FROM DUAL
		WHERE NOT EXISTS
		(SELECT * FROM  STL_LG_INSTORE_RESULT 
		 WHERE 
		 PRO_PLAN_ID =(select gpbuyplanid from buy_gp_order where ord_no_pk='#ord_no_pk#')
		 AND JUDGE_STOVE_NO='#judge_stove_no#'
		 AND FIX_NUM =#bc# )
		]]>
	</query>
	<query id="BuyGpDAL.UPDATE_STL_LG_INSTORE_RESULT1" desc="更新管坯交库实绩表">
		<![CDATA[   
		  UPDATE STL_LG_INSTORE_RESULT
		  SET ACT_COUNT = ACT_COUNT + #count#,
		      WEIGHT    = WEIGHT + #weight#,
		      NODE_FUR_FLAG = '#jielu#'
		  WHERE NODE_FUR_FLAG ='0'
		        AND PRO_PLAN_ID =(select gpbuyplanid from buy_gp_order where ord_no_pk='#ord_no_pk#')
		 		AND JUDGE_STOVE_NO='#judge_stove_no#'
		        AND FIX_NUM =#bc#
	 ]]>
	</query>
	<query id="BuyGpDAL.UPDATE_STL_LG_INSTORE_RESULT" desc="更新管坯交库实绩表">
		<![CDATA[   
		  UPDATE STL_LG_INSTORE_RESULT
		  SET ACT_COUNT = ACT_COUNT + #count#,
		      WEIGHT    = WEIGHT + #weight#,
		      NODE_FUR_FLAG = '#jielu#'
		  WHERE NODE_FUR_FLAG ='0'
		        AND PRO_PLAN_ID =(select gpbuyplanid from buy_gp_order where ord_no_pk='#ord_no_pk#')
		 		AND JUDGE_STOVE_NO='#judge_stove_no#'
		        AND FIX_NUM =#bc#
	 ]]>
	</query>
	<query id="BuyGpDAL.UPDATE_STL_LG_INSTORE_RESULT_TH" desc="更新管坯交库实绩表(天淮)">
		<![CDATA[   
		  UPDATE STL_LG_INSTORE_RESULT
		  SET ACT_COUNT = ACT_COUNT + #count#,
		      WEIGHT    = WEIGHT + #weight#
		      --NODE_FUR_FLAG = DECODE(NODE_FUR_FLAG,'1','1','#jielu#')
		  WHERE 
		        PRO_PLAN_ID =(select gpbuyplanid from buy_gp_order where ord_no_pk='#ord_no_pk#')
		 		AND STOVE_NO='#stove_no#'
		        AND LENGTH =#gplength#
	 ]]>
	</query>
	<query id="BuyGpDAL.UPDATE_STL_LG_INSTORE_RESULT_JIELU" desc="更新管坯交库实绩表状态">
		<![CDATA[   
		  UPDATE STL_LG_INSTORE_RESULT
		  SET NODE_FUR_FLAG = DECODE(NODE_FUR_FLAG,'1','1','#jielu#')
		  WHERE  PRO_PLAN_ID =(select gpbuyplanid from buy_gp_order where ord_no_pk='#ord_no_pk#')
		 		AND STOVE_NO='#stove_no#'
	 ]]>
	</query>
	<query id="BuyGpDAL.UPDATE_STL_LG_INSTORE_RESULT_JIELU_TH" desc="更新管坯交库实绩表状态">
		<![CDATA[   
		  UPDATE STL_LG_INSTORE_RESULT
		  SET NODE_FUR_FLAG = '#jielu#'
		  WHERE NODE_FUR_FLAG ='0'
		        AND PRO_PLAN_ID =(select gpbuyplanid from buy_gp_order where ord_no_pk='#ord_no_pk#')
		 		AND JUDGE_STOVE_NO='#judge_stove_no#'
	 ]]>
	</query>
	<query id="BuyGpDAL.SELECT_STL_LG_INSTORE_RESULT_JIELU" desc="查询坯交库实绩结炉状态">
		<![CDATA[   
		  SELECT COUNT(*) FROM  STL_LG_INSTORE_RESULT
		  WHERE NODE_FUR_FLAG ='1'
		        AND PRO_PLAN_ID =(select gpbuyplanid from buy_gp_order where ord_no_pk='#ord_no_pk#')
		 		AND JUDGE_STOVE_NO='#judge_stove_no#'
	 ]]>
	</query>
	<query id="BuyGpDAL.get_CGP_RK_Orders" desc="采购坯入库筛选合同">
		<![CDATA[
		  SELECT
	      SUPP_CODE 供应商,                
	      b.ORDER_NO || '/' || SUBSTR(TO_CHAR(1000+TO_NUMBER(ORDER_SQE)),-3) 合同号,          
	      b.GRADENAME 钢种, 
	      DIAMETER 断面,          
	      CASE b.GPTYPE WHEN '0' THEN '轧坯'  WHEN '1' THEN '铸坯' WHEN '2' THEN '锻坯' ELSE ''  END 管坯类型,                 
	      b.LEN_GP_SINGLE 单倍坯长,
	      CAST(FIX_NUM AS INT) 倍尺,   
	      LENGTH 管坯长度,                                       
	      WEIGHT_NUM 合同量,
	      (SELECT count(*) from BUY_GP_DCYB
          WHERE  ord_no_pk = b.ord_no_pk
          GROUP BY  ord_no_pk ) 预报条数,
          ORD_NO_PK,
          GPBUYPLANID
	      FROM
	      BUY_GP_ORDER b
	      WHERE 1=1 AND GPBUYPLANID IN
	      (
	       SELECT gpreq_id  FROM  PLN_REQINF_GP
			where ifbuyplan ='1' 
			and req_status !='4'
			AND SUPPLY_UNIT_CODE='120501'
	      )
		]]>
	</query>
	<query id="BuyGpDAL.get_CGP_RK_OrdersTH" desc="采购坯入库筛选合同(天淮)">
		<![CDATA[
		  SELECT
	      SUPP_CODE 供应商,                
	      b.ORDER_NO || '/' || SUBSTR(TO_CHAR(1000+TO_NUMBER(ORDER_SQE)),-3) 合同号,          
	      b.GRADENAME 钢种, 
	      DIAMETER 断面,          
	      CASE b.GPTYPE WHEN '0' THEN '轧坯'  WHEN '1' THEN '铸坯' WHEN '2' THEN '锻坯' ELSE ''  END 管坯类型,                 
	      b.LEN_GP_SINGLE 单倍坯长,
	      CAST(FIX_NUM AS INT) 倍尺,   
	      LENGTH 管坯长度,                                       
	      WEIGHT_NUM 合同量,
	      (SELECT count(*) from BUY_GP_DCYB
          WHERE  ord_no_pk = b.ord_no_pk
          GROUP BY  ord_no_pk ) 预报条数,
          ORD_NO_PK,
          GPBUYPLANID
	      FROM
	      BUY_GP_ORDER b
	      WHERE 1=1 AND GPBUYPLANID IN
	      (
	       SELECT gpreq_id  FROM  PLN_REQINF_GP
			where ifbuyplan ='1' 
			and req_status !='4'
			AND SUPPLY_UNIT_CODE='120504'
	      )
		]]>
	</query>
	<query id="BuyGpDAL.get_CGP_Orders_Dcyb" desc="采购坯入库筛选到厂预报">
		<![CDATA[
		  SELECT 
			STOVE_NO 炉号,
			JUDGE_STOVE_NO 判定炉号,
			PLAN_COUNT 支数,
			PLAN_WEIGHT 重量
			FROM buy_gp_dcyb
			WHERE ORD_NO_PK=? 
				]]>
	</query>
	<query id="BuyGpDAL.get_CGP_RUKU_Level" desc="获取采购坯入库层数">
		<![CDATA[
		  select level
		  from dual
          connect by level <21
				]]>
	</query>
	<query id="BuyGpDAL.get_CGP_RUKU_Stock" desc="获取采购坯入库仓库信息">
		<![CDATA[
		  select 
		  t.storage_name,
		  t.storage_no 
		  from ydm_bs_storage t
		  where (t.storage_type_name like '%管坯%' 
          --and t.storage_attr_name in ('投料库','离线库')
          and t.management_no  IN (#departments#)
          )
				]]>
	</query>
	<query id="BuyGpDAL.get_CGP_RUKU_Stock_Location" desc="获取采购坯入库库位信息">
		<![CDATA[
		  select LOCATION_NO,LOCATION_NAME from ydm_bs_location
		  WHERE STORAGE_NO =
		  (
 			SELECT STORAGE_NO FROM YDM_BS_STORAGE WHERE storage_name ='#storage_name#' 
		  )
		  ORDER BY LOCATION_NO
				]]>
	</query>
	<query id="BuyGpDAL.get_CGP_RUKU_Stock_CHEDAN" desc="获取采购坯入库实际信息(撤单使用)">
		<![CDATA[
		/*
		 SELECT INSTOCK_DOC,JUDGE_STOVE_NO,GRADENAME,ORDER_NO,MATERIAL_NAME,SUM(ACT_COUNT) AS ACT_COUNT,SUM(ACT_WEIGHT) AS ACT_WEIGHT,CREATE_TIME,
		(select max(t.pro_plan_id)  from mat_gp_m t
		where t.judge_stove_no = t1.judge_stove_no) GPREQ_ID
		 FROM ydm_gp_inlist t1
         WHERE MAT_ORIGIN_NAME='外购' 
         AND STORAGE_NO =(select storage_no  from ydm_bs_storage where storage_name = '#STORAGE_NAME#')
         AND JUDGE_STOVE_NO IN
         (select t.judge_stove_no
 		  from mat_gp_m t
 		  where  t.mat_origin_name ='外购' and t.qcm_staus ='00'
 		  group by t.judge_stove_no
 		 )
 		 AND ('#JUDGE_STOVE_NO#'= '无判定炉号' OR  JUDGE_STOVE_NO ='#JUDGE_STOVE_NO#')
 		 AND ('#ORDER_NO#'= '无合同号' OR  ORDER_NO LIKE  '%#ORDER_NO#%')
         GROUP BY INSTOCK_DOC,JUDGE_STOVE_NO,GRADENAME,ORDER_NO,MATERIAL_NAME,CREATE_TIME
         ORDER BY CREATE_TIME DESC
         */
      with t
      as
      (
      select t.instock_doc,t.mat_no,
      t1.mat_no as mat_no1,
      t2.mat_no as mat_no2,
      t2.storage_no
      from 
           （select instock_doc,mat_no from Ydm_Gp_Inlist t where MAT_ORIGIN_NAME ='外购' 
            and storage_no=(select STORAGE_NO from YDM_BS_STORAGE where storage_name = '#STORAGE_NAME#')） t
      left join (select * from mat_gp_m where jugde_apply_code is null and  mat_origin_name='外购') t1
      on t.mat_no = t1.mat_no
      left join (select * from YDM_GP_BUTTRESS where storage_no = (select STORAGE_NO from YDM_BS_STORAGE where storage_name = '#STORAGE_NAME#')) t2
      on t.mat_no = t2.mat_no
      )
      
       SELECT INSTOCK_DOC,JUDGE_STOVE_NO,GRADENAME,ORDER_NO,MATERIAL_NAME,SUM(ACT_COUNT) AS ACT_COUNT,SUM(ACT_WEIGHT) AS ACT_WEIGHT,CREATE_TIME,
    (select max(t.pro_plan_id)  from mat_gp_m t
    where t.judge_stove_no = t1.judge_stove_no) GPREQ_ID
     FROM ydm_gp_inlist t1
         WHERE MAT_ORIGIN_NAME='外购' 
         AND STORAGE_NO =(select storage_no  from ydm_bs_storage where storage_name ='#STORAGE_NAME#')
         AND 
         INSTOCK_DOC NOT IN (SELECT INSTOCK_DOC FROM t WHERE MAT_NO1 IS NULL OR MAT_NO2 IS NULL)
     AND ('#JUDGE_STOVE_NO#'= '无判定炉号' OR  JUDGE_STOVE_NO ='#JUDGE_STOVE_NO#')
     AND ('#ORDER_NO#'= '无合同号' OR  ORDER_NO LIKE  '%#ORDER_NO#%')
         GROUP BY INSTOCK_DOC,JUDGE_STOVE_NO,GRADENAME,ORDER_NO,MATERIAL_NAME,CREATE_TIME
         ORDER BY CREATE_TIME DESC
				]]>
	</query>
		<query id="BuyGpDAL.get_CGP_RUKU_Stock_CHEDAN_TH" desc="获取采购坯入库实际信息(撤单使用)">
		<![CDATA[
		with t
	    as
	    (
	    select a.INSTOCK_DOC,a.stove_no as JUDGE_STOVE_NO,a.GRADENAME ,a.ORDER_NO ,a.MATERIAL_NAME,sum(a.act_count) ACT_COUNT,
	    sum(a.act_weight) ACT_WEIGHT,min(a.create_time) CREATE_TIME from ydm_gp_inlist a
	    inner join 
	    (
	    select t.mat_no from mat_gp_m t 
	    where t.supply_unit_code ='120504' and t.jugde_apply_code is null and t.judge_result_code is null
	    ) b
	    on a.mat_no = b.mat_no
	    group by a.INSTOCK_DOC,a.stove_no,a.gradename,a.order_no,a.MATERIAL_NAME
	    )
	    select * from t 
	    where 1=1 #sql#
	    order by create_time desc
				]]>
	</query>
	<query id="BuyGpDAL.get_CGP_RUKU_Stock_CHEDAN_Details" desc="获取采购坯入库实际信息详细(撤单使用)">
		<![CDATA[
		 SELECT SUM(ACT_COUNT) AS COUNT,SUM(ACT_WEIGHT) AS WEIGHT,FIX_NUM AS BC,MAX(ACT_LEN) AS ACT_LEN FROM MAT_GP_M
			WHERE MAT_NO IN
			(
			SELECT MAT_NO 
			FROM ydm_gp_inlist
			WHERE INSTOCK_DOC  = '#instock_doc#' AND mat_origin_name ='外购'
			)
			GROUP BY FIX_NUM
				]]>
	</query>
	<query id="BuyGpDAL.get_CGP_RUKU_Stock_CHEDAN_Details_TH" desc="获取采购坯入库实际信息详细(撤单使用)">
		<![CDATA[
		 SELECT SUM(ACT_COUNT) AS COUNT,SUM(ACT_WEIGHT) AS WEIGHT,MAX(FIX_NUM) AS BC,ACT_LEN FROM MAT_GP_M
			WHERE MAT_NO IN
			(
			SELECT MAT_NO 
			FROM ydm_gp_inlist
			WHERE INSTOCK_DOC  = '#instock_doc#' AND mat_origin_name ='外购'
			)
			GROUP BY ACT_LEN
				]]>
	</query>
	<query id="BuyGpDAL.getMaxInstockDoc" desc="获取入库单号">
		<![CDATA[
		    select  substr(100000+substr(nvl(max(instock_doc),100000),-5)+1,-5) rn from 
		    Ydm_Gp_Inlist
		    where instock_doc like 'IA'||to_char(sysdate,'yymmdd')|| '%'
				]]>
	</query>
	<query id="BuyGpDAL.deleteInstockDoc" desc="撤单">
		<![CDATA[
		    
		    declare v_count integer :=0;
		    
		    BEGIN
		   
		    with t
			as
			(
			select t.instock_doc,t.mat_no,
			t1.mat_no as mat_no1,
			t2.mat_no as mat_no2,
			t2.storage_no
			from Ydm_Gp_Inlist t
			left join (select * from mat_gp_m where jugde_apply_code is null) t1
			on t.mat_no = t1.mat_no
			left join (select * from YDM_GP_BUTTRESS where storage_no = (select STORAGE_NO from YDM_BS_STORAGE where storage_name = '#storage_name#')) t2
			on t.mat_no = t2.mat_no
			where t.instock_doc IN (#instock_doc#) AND t.mat_origin_name ='外购'
			)
			select count(*) into v_count from  t where mat_no1 is null or mat_no2 is null;
			
			if v_count > 0 then
			   dbms_output.put_line(v_count);
			   return;
			end if;
			
			--return;
		    
		    
		    delete from ydm_gp_buttress
			where mat_no in (select mat_no from ydm_gp_inlist  where instock_doc IN (#instock_doc#) and mat_origin_name ='外购'
			--and mat_no in (select mat_no from mat_gp_m where qcm_staus ='00' and mat_origin_name ='外购')
			);
			
			delete from mat_gp_m
			where mat_no in (select mat_no from ydm_gp_inlist  where instock_doc IN (#instock_doc#) and mat_origin_name ='外购'
			--and mat_no in (select mat_no from mat_gp_m where qcm_staus ='00' and mat_origin_name ='外购')
			);
			
			
			UPDATE stl_lg_instore_result a
			SET ACT_COUNT = ACT_COUNT - NVL((SELECT SUM(ACT_COUNT) FROM  ydm_gp_inlist  b
			                where  instock_doc IN (#instock_doc#) AND b.JUDGE_STOVE_NO = a.JUDGE_STOVE_NO 
			                                                   AND b.FIX_NUM = a.FIX_NUM
			                GROUP BY b.JUDGE_STOVE_NO,b.FIX_NUM),0),
			WEIGHT = WEIGHT - NVL((SELECT SUM(ACT_WEIGHT) FROM  ydm_gp_inlist  b
			                where instock_doc IN (#instock_doc#) AND b.mat_origin_name ='外购' AND b.JUDGE_STOVE_NO = a.JUDGE_STOVE_NO 
			                                                   AND b.FIX_NUM = a.FIX_NUM
		    --where exists (select mat_no from ydm_gp_inlist  where instock_doc IN (#instock_doc#)
			--and mat_no in (select mat_no from mat_gp_m where qcm_staus ='00' and mat_origin_name ='外购')
			--)
		    GROUP BY b.JUDGE_STOVE_NO,b.FIX_NUM),0);
			                
			DELETE FROM stl_lg_instore_result WHERE (ACT_COUNT<=0 OR ACT_COUNT IS NULL) AND  (pro_plan_id like 'GP_W%' or pro_plan_id like 'DP_W%');
			
			delete from ydm_gp_inlist
			where instock_doc IN(#instock_doc#) and mat_origin_name ='外购'
			--and mat_no in (select mat_no from mat_gp_m where qcm_staus ='00' and mat_origin_name ='外购')
			;
			
			END;
				]]>
	</query>
	<query id="BuyGpDAL.deleteInstockDocNew" desc="撤单新">
		<![CDATA[
		    
		    declare v_count integer :=0;
		    
		    BEGIN
		   
		    with t
			as
			(
			select t.instock_doc,t.mat_no,
			t1.mat_no as mat_no1,
			t2.mat_no as mat_no2,
			t2.storage_no
			from Ydm_Gp_Inlist t
			left join (select * from mat_gp_m where jugde_apply_code is null) t1
			on t.mat_no = t1.mat_no
			left join (select * from YDM_GP_BUTTRESS where storage_no = (select STORAGE_NO from YDM_BS_STORAGE where storage_name = '#storage_name#')) t2
			on t.mat_no = t2.mat_no
			where t.JUDGE_STOVE_NO IN (#judge_stove_no#) AND t.instock_doc IN (#instock_doc#) AND t.mat_origin_name ='外购'
			)
			select count(*) into v_count from  t where mat_no1 is null or mat_no2 is null;
			
			if v_count > 0 then
			   dbms_output.put_line(v_count);
			   return;
			end if;
			
			--return;
		    
		    
		    delete from ydm_gp_buttress
			where mat_no in (select mat_no from ydm_gp_inlist  where JUDGE_STOVE_NO IN (#judge_stove_no#) AND instock_doc IN (#instock_doc#) and mat_origin_name ='外购'
			--and mat_no in (select mat_no from mat_gp_m where qcm_staus ='00' and mat_origin_name ='外购')
			);
			
			delete from mat_gp_m
			where mat_no in (select mat_no from ydm_gp_inlist  where JUDGE_STOVE_NO IN (#judge_stove_no#) AND instock_doc IN (#instock_doc#) and mat_origin_name ='外购'
			--and mat_no in (select mat_no from mat_gp_m where qcm_staus ='00' and mat_origin_name ='外购')
			);
			
			
			UPDATE stl_lg_instore_result a
			SET ACT_COUNT = ACT_COUNT - NVL((SELECT SUM(ACT_COUNT) FROM  ydm_gp_inlist  b
			                where JUDGE_STOVE_NO IN (#judge_stove_no#) AND  instock_doc IN (#instock_doc#) AND b.JUDGE_STOVE_NO = a.JUDGE_STOVE_NO 
			                                                   AND b.FIX_NUM = a.FIX_NUM
			                GROUP BY b.JUDGE_STOVE_NO,b.FIX_NUM),0),
			WEIGHT = WEIGHT - NVL((SELECT SUM(ACT_WEIGHT) FROM  ydm_gp_inlist  b
			                where JUDGE_STOVE_NO IN (#judge_stove_no#) AND instock_doc IN (#instock_doc#) AND b.mat_origin_name ='外购' AND b.JUDGE_STOVE_NO = a.JUDGE_STOVE_NO 
			                                                   AND b.FIX_NUM = a.FIX_NUM
		    --where exists (select mat_no from ydm_gp_inlist  where instock_doc IN (#instock_doc#)
			--and mat_no in (select mat_no from mat_gp_m where qcm_staus ='00' and mat_origin_name ='外购')
			--)
		    GROUP BY b.JUDGE_STOVE_NO,b.FIX_NUM),0);
			                
			DELETE FROM stl_lg_instore_result WHERE (ACT_COUNT<=0 OR ACT_COUNT IS NULL) AND  (pro_plan_id like 'GP_W%' or pro_plan_id like 'DP_W%');
			
			delete from ydm_gp_inlist
			where JUDGE_STOVE_NO IN (#judge_stove_no#) AND instock_doc IN(#instock_doc#) and mat_origin_name ='外购'
			--and mat_no in (select mat_no from mat_gp_m where qcm_staus ='00' and mat_origin_name ='外购')
			;
			
			END;
				]]>
	</query>
	<query id="BuyGpDAL.deleteInstockDocTH" desc="撤单新">
		<![CDATA[
		    BEGIN
		    delete from ydm_gp_buttress
			where mat_no in (select mat_no from ydm_gp_inlist  where STOVE_NO IN (#judge_stove_no#) AND instock_doc IN (#instock_doc#) and mat_origin_name ='外购'
			);
			
			delete from mat_gp_m
			where mat_no in (select mat_no from ydm_gp_inlist  where STOVE_NO IN (#judge_stove_no#) AND instock_doc IN (#instock_doc#) and mat_origin_name ='外购'
			);
			
			UPDATE stl_lg_instore_result a
			SET ACT_COUNT = ACT_COUNT - NVL((SELECT SUM(ACT_COUNT) FROM  ydm_gp_inlist  b
			                where STOVE_NO =#judge_stove_no# AND  instock_sqe like #instock_doc#||'%' AND b.STOVE_NO = a.STOVE_NO 
			                                                   AND b.act_len = a.length
			                GROUP BY b.STOVE_NO,b.act_len),0),
			WEIGHT = WEIGHT - NVL((SELECT SUM(ACT_WEIGHT) FROM  ydm_gp_inlist  b
			                where STOVE_NO =#judge_stove_no# AND  instock_sqe like #instock_doc#||'%' AND b.STOVE_NO = a.STOVE_NO 
			                                                   AND b.act_len = a.length
			                GROUP BY b.STOVE_NO,b.act_len),0)
			WHERE a.STOVE_NO =#judge_stove_no#;
			                
			DELETE FROM stl_lg_instore_result WHERE (ACT_COUNT<=0 OR ACT_COUNT IS NULL) AND  (pro_plan_id like 'GP_W%' or pro_plan_id like 'DP_W%');
			
			delete from ydm_gp_inlist
			where STOVE_NO IN (#judge_stove_no#) AND instock_doc IN(#instock_doc#) and mat_origin_name ='外购';
			END;
				]]>
	</query>
	<query id="BuyGpDAL.updateJIELUStatus" desc="设置结炉状态">
		<![CDATA[
		  update stl_lg_instore_result

		  set node_fur_flag = '#jielu#'

		  where judge_stove_no ='#judge_stove_no#'
				]]>
	</query>
	<!-- 以下是外购坯轧管装炉所需语句 START -->
	<query id="BuyGpDAL.selectPlnOrderZg" desc="查询轧管订单">
		SELECT S.*
		FROM
		PLN_ORDER_ZG_S S
		WHERE S.GPREQ_ID = '#PRO_PLAN_ID#'
		AND S.EXE_STATUS IN('0','1')
		ORDER BY
		TO_NUMBER(S.GX_PRO_SEQ) ASC
</query>
	<query id="BuyGpDAL.selectPlnOrderDz" desc="查询锻造订单">
		SELECT T.*
		FROM
		PLN_ORDER_DZ_S T
		WHERE T.GPREQ_ID = '#PRO_PLAN_ID#'
		AND T.EXE_STATUS IN('0','1')
		ORDER BY
		TO_NUMBER(T.GX_PRO_SEQ) ASC
</query>
	<query id="BuyGpDAL.selectMatGpMNumZg" desc="查询已挂单倍坯支数">
	SELECT GET_GP_PLNZGM_NUM('#PRO_PLAN_ID#','#GX_PLAN_NO#') AS DB_ACT_COUNT FROM DUAL
</query>

	<query id="BuyGpDAL.selectMatGpMNum" desc="查询已入支数(未挂单号)">
		SELECT
		NVL(SUM(T.ACT_COUNT),0)ACT_COUNT,
		T.FIX_NUM,T.STOVE_NO,T.JUDGE_STOVE_NO,T.PRO_PLAN_ID,T.GX_PLAN_NO
		FROM
		MAT_GP_M T
		WHERE T.PRO_PLAN_ID = ?
		AND T.STOVE_NO = ?
		AND
		T.JUDGE_STOVE_NO =?
		AND T.PRO_PLAN_ID_ZG IS NULL
		AND T.QCM_STAUS = '00'
		GROUP BY T.PRO_PLAN_ID,
		T.GX_PLAN_NO,
		T.STOVE_NO,
		T.JUDGE_STOVE_NO,
		T.FIX_NUM
		ORDER BY T.FIX_NUM DESC
</query>

	<query id="BuyGpDAL.updateMatGpMZg" desc="写入轧管订单号">
<![CDATA[
DECLARE
BEGIN
  FOR MYROW IN (SELECT *
                  FROM (SELECT *
                          FROM MAT_GP_M T
                         WHERE T.PRO_PLAN_ID = '#PRO_PLAN_ID#'
                           AND T.STOVE_NO = '#STOVE_NO#'
                           AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                           AND T.FIX_NUM = '#FIX_NUM#'
                           AND T.QCM_STAUS = '00'
                           AND T.PRO_PLAN_ID_ZG IS NULL
                         ORDER BY T.MAT_NO ASC)
                 WHERE ROWNUM <= #ACT_COUNT#) LOOP
    UPDATE MAT_GP_M T
       SET T.PRO_PLAN_ID_ZG = '#PRO_PLAN_ID_ZG#',
           T.GX_PLAN_NO_ZG  = '#GX_PLAN_NO_ZG#'
     WHERE T.MAT_NO = MYROW.MAT_NO;
  END LOOP;
END;
]]>
	</query>
	<!-- 以上是外购坯轧管装炉所需语句 END -->
	<query id="BuyGpDAL.selectMatGpMRules" desc="查询是否不符合入库规则">
<![CDATA[
    select gradename,dimater,fix_len,judge_stove_no,
    (select storage_name from YDM_BS_STORAGE a where  a.storage_no = t.storage_no) storage_name
	from ydm_gp_inlist t
	where judge_stove_no = '#judge_stove_no#'
]]>
	</query>
	
 	<query id="BuyGpDAL.selectMatGpMStocks" desc="查询外购坯库存">
	<![CDATA[
	    with t
		as
		(
		select (select STORAGE_NAME from YDM_BS_STORAGE where storage_no = t1.storage_no) AS storage_name,
		t.jugde_apply_code,t.judge_stove_no,
		t.material_name,gradename,t.fix_len,sum(act_count) as act_count,sum(act_weight) as act_weight
		from mat_gp_m t
		left join ydm_gp_buttress t1
		on t.mat_no = t1.mat_no
		where t.mat_origin_name ='外购' 
		AND ('#JUDGE_STOVE_NO#'= '无判定炉号' OR  t.judge_stove_no ='#JUDGE_STOVE_NO#')
		group by 
		t1.storage_no,t.jugde_apply_code,t.judge_stove_no,
		t.material_name,gradename,t.fix_len
		),
		t1 as
		(
		 SELECT t.judge_stove_no,t.node_fur_flag FROM STL_LG_INSTORE_RESULT t
		group by t.judge_stove_no,t.node_fur_flag
		)
		
		select t.*,case t1.node_fur_flag when '1' then '是' else '否' end node_fur_flag from t
		left join t1
		on t.judge_stove_no = t1.judge_stove_no
		order by t.storage_name , t.judge_stove_no
	]]>
	</query>
	<query id="BuyGpDAL.selectMatGpMStocksTH" desc="查询外购坯库存（天淮）结炉撤结炉用">
	<![CDATA[
	    with t
		as
		(
		SELECT t1.storage_no,t.stove_no,t.judge_stove_no,t.material_name,t.gradename,
		t.act_len,t.act_count,t.act_weight,t.jugde_apply_code
		FROM mat_gp_m t,ydm_gp_buttress t1
		where t.supply_unit_code ='120504' and t.mat_no = t1.mat_no(+)
		and ('#STOVE_NO#'='无冶炼炉号' or t.stove_no = '#STOVE_NO#')
		),
		t2
		as
		(
		select storage_no,stove_no,judge_stove_no,material_name,gradename,
		min(act_len) fix_len,jugde_apply_code,sum(act_count) act_count,sum(act_weight) act_weight
		from t
		group by storage_no,stove_no,judge_stove_no,material_name,gradename,jugde_apply_code
		)
		select (select STORAGE_NAME from YDM_BS_STORAGE where storage_no = t2.storage_no) AS storage_name,
		t2.*,decode(t3.node_fur_flag,'1','是','0','否',null) node_fur_flag from t2,stl_lg_instore_result t3
		where t2.stove_no = t3.stove_no(+)
		group by storage_no,t2.stove_no,t2.judge_stove_no,t2.material_name,t2.gradename,t2.fix_len,jugde_apply_code,
		t2.act_count,t2.act_weight,node_fur_flag
		order by t2.stove_no
	]]>
	</query>
		<query id="BuyGpDAL.selectMatGpMStocksJieluInfo" desc="查询退结炉信息">
	<![CDATA[
       select (select STORAGE_NAME from YDM_BS_STORAGE where storage_no = t1.storage_no) AS storage_name,
		t.jugde_apply_code,t.judge_stove_no,t.gpreq_id
		from mat_gp_m t
		left join ydm_gp_buttress t1
		on t.mat_no = t1.mat_no
		where t.mat_origin_name ='外购' 
		AND  (t.judge_stove_no ='#JUDGE_STOVE_NO#')
	]]>
	</query>
	
		
	<query id="BuyGpDAL.deleteMatGpMStocksJielu" desc="撤销结炉">
	<![CDATA[
        update  STL_LG_INSTORE_RESULT t
		set t.node_fur_flag = '0'
		where t.judge_stove_no = ?
		and t.node_fur_flag = '1'
	]]>
	</query>
	<query id="BuyGpDAL.deleteMatGpMStocksJieluTH" desc="撤销结炉天淮">
	<![CDATA[
        update  STL_LG_INSTORE_RESULT t
		set t.node_fur_flag = '0'
		where t.stove_no = ?
		and t.node_fur_flag = '1'
	]]>
	</query>
	<query id="BuyGpDAL.updateMatGpMStocksJielu" desc="增加结炉">
	<![CDATA[
        update  STL_LG_INSTORE_RESULT t
		set t.node_fur_flag = '1'
		where t.judge_stove_no = ?
		and t.node_fur_flag = '0'
	]]>
	</query>
	<query id="BuyGpDAL.updateMatGpMStocksJieluTH" desc="增加结炉">
	<![CDATA[
        update  STL_LG_INSTORE_RESULT t
		set t.node_fur_flag = '1'
		where t.stove_no = ?
		and t.node_fur_flag = '0'
	]]>
	</query>
	<query id="BuyGpDAL.myTest" desc="我的测试">
	<![CDATA[
        SELECT t.gpbuyplanid as My_Id  FROM BUY_GP_ORDER t
		where t.gpbuyplanid ='#MY_ID#' 
		--AND t.Order_No ='#MY_AGE#';
	]]>
	</query>
	
	<query id="BuyGpDAL.selectRptSalesAll" desc="获取销售管理数据">
	<![CDATA[
       SELECT RPT_YM,
       SUM(DECODE(DEPT_NAME,'国际贸易部',SALES_WEIGHT)) AS GM1_SALES_WEIGHT,
       SUM(DECODE(DEPT_NAME,'钢贸公司',SALES_WEIGHT)) AS GM2_SALES_WEIGHT,
       SUM(DECODE(DEPT_NAME,'国内贸易部',SALES_WEIGHT)) AS XS_SALES_WEIGHT,
       SUM(SALES_WEIGHT) AS TOTAL_SALES_WEIGHT,
       SUM(DECODE(DEPT_NAME,'国际贸易部',PC_WEIGHT)) AS GM1_PC_WEIGHT,
       SUM(DECODE(DEPT_NAME,'钢贸公司',PC_WEIGHT)) AS GM2_PC_WEIGHT,
       SUM(DECODE(DEPT_NAME,'国内贸易部',PC_WEIGHT)) AS XS_PC_WEIGHT,
       SUM(PC_WEIGHT) AS TOTAL_PC_WEIGHT,
       SUM(DECODE(DEPT_NAME,'国际贸易部',STOCK_WEIGHT)) AS GM1_STOCK_WEIGHT,
       SUM(DECODE(DEPT_NAME,'钢贸公司',STOCK_WEIGHT)) AS GM2_STOCK_WEIGHT,
       SUM(DECODE(DEPT_NAME,'国内贸易部',STOCK_WEIGHT)) AS XS_STOCK_WEIGHT,
       SUM(STOCK_WEIGHT) AS TOTAL_STOCK_WEIGHT,
       SUM(DECODE(DEPT_NAME,'国际贸易部',STOCKIN_WEIGHT)) AS GM1_STOCKIN_WEIGHT,
       SUM(DECODE(DEPT_NAME,'钢贸公司',STOCKIN_WEIGHT)) AS GM2_STOCKIN_WEIGHT,
       SUM(DECODE(DEPT_NAME,'国内贸易部',STOCKIN_WEIGHT)) AS XS_STOCKIN_WEIGHT,
       SUM(STOCKIN_WEIGHT) AS TOTAL_STOCKIN_WEIGHT,
       SUM(DECODE(DEPT_NAME,'国际贸易部',STOCKOUT_WEIGHT)) AS GM1_STOCKOUT_WEIGHT,
       SUM(DECODE(DEPT_NAME,'钢贸公司',STOCKOUT_WEIGHT)) AS GM2_STOCKOUT_WEIGHT,
       SUM(DECODE(DEPT_NAME,'国内贸易部',STOCKOUT_WEIGHT)) AS XS_STOCKOUT_WEIGHT,
       SUM(STOCKOUT_WEIGHT) AS TOTAL_STOCKOUT_WEIGHT,
       SUM(DECODE(DEPT_NAME,'国际贸易部',DQ_STOCK)) AS GM1_DQ_STOCK,
       SUM(DECODE(DEPT_NAME,'钢贸公司',DQ_STOCK)) AS GM2_DQ_STOCK,
       SUM(DECODE(DEPT_NAME,'国内贸易部',DQ_STOCK)) AS XS_DQ_STOCK,
       SUM(DECODE(DEPT_NAME,'国际贸易部',QQ_STOCK)) AS GM1_QQ_STOCK,
       SUM(DECODE(DEPT_NAME,'钢贸公司',QQ_STOCK)) AS GM2_QQ_STOCK,
       SUM(DECODE(DEPT_NAME,'国内贸易部',QQ_STOCK)) AS XS_QQ_STOCK,
       SUM(QQ_STOCK) AS TOTAL_QQ_STOCK,
       SUM(DECODE(DEPT_NAME,'国际贸易部',STOCK_NODER_WEIGHT)) AS GM1_NODER_WEIGHT,
       SUM(DECODE(DEPT_NAME,'钢贸公司',STOCK_NODER_WEIGHT)) AS GM2_NODER_WEIGHT,
       SUM(DECODE(DEPT_NAME,'国内贸易部',STOCK_NODER_WEIGHT)) AS XS_NODER_WEIGHT,
       SUM(STOCK_NODER_WEIGHT) AS TOTAL_NODER_WEIGHT
       FROM RPT_SALES_ALL
       WHERE RPT_YM LIKE '#RPT_YM#%'
       GROUP BY RPT_YM
       ORDER BY RPT_YM DESC
	]]>
	</query>
	<query id="BuyGpDAL.selectRptManagementAll" desc="获取管理数据">
	<![CDATA[
       SELECT rpt_ym,
       ROUND(BCP, 3) AS BCP,
       ROUND(BCP_ZT, 3) AS BCP_ZT,
       ROUND(NVL(BCP,0) + NVL(BCP_ZT,0),3) AS TOTAL_BCP,
       ROUND(GP, 3)  AS GP,
       ROUND(GP_ZT, 3)  AS GP_ZT,
       ROUND(NVL(GP,0) + NVL(GP_ZT,0),3) AS TOTAL_GP,
       ROUND(NVL(BCP,0) + NVL(BCP_ZT,0)+NVL(GP,0) + NVL(GP_ZT,0),3) AS TOTAL_GP_BCP,
       ROUND(WGP_RATE, 2) || '%' AS WGP_RATE,
       ROUND(WGP_WEIGHT, 3) AS WGP_WEIGHT
  	   FROM rpt_management_all
       WHERE RPT_YM LIKE '#RPT_YM#%'
 	   order by rpt_ym desc
	]]>
	</query>
	<query id="BuyGpDAL.selectRptPlineJudgeAll" desc="获取生产判定数据">
	<![CDATA[
       WITH t1
		AS
		(
		SELECT t.pline_code,t.pline_name,t.department_desc_p,t.department_code_p,t.process_code,
		DECODE(t.department_desc_p,'特钢公司',1,'轧管一部',2,'轧管二部',3,'轧管三部',4,'管加工部',5,'生产计划部',6,'三圆公司',7,9) AS deptid
		FROM Com_Base_Pline t
		)
       SELECT t.rpt_ym,
       t.pline_name,
       t.cl,
       ROUND(t.zcp,2) AS ZCP,
       DECODE(t.ccl,NULL,NULL,t.ccl || '%') AS CCL,
       decode(t.zyl,null,null,t.zyl || '%')  as zyl,
       t.clwcl,
       t.wxtjsj,
       t.sbgztj,
       t.yxzyl,
       t.nosendjudge,
       t.waittojudge,
       t.judgeweight,
       decode(t.ychgrate,null,null,t.ychgrate || '%')  as ychgrate,
       t.fpweight,t1.department_desc_p
	   FROM rpt_pline_judge_all t , t1
	   WHERE t.Rpt_Ym = '#RPT_YM#'  AND t.Pline_Code = t1.pline_code
	   ORDER BY deptid,process_code,t.pline_code
	]]>
	</query>
	<query id="BuyGpDAL.selectRptMeasureCg" desc="获取生铁废钢计量数据">
	<![CDATA[
      SELECT 
        t.rpt_date,
    	MAX(CASE WHEN t.material='废钢' AND t.material_source='采购' THEN ACT_WEIGHT ELSE NULL END) FGCG,
    	MAX(CASE WHEN t.material='废钢' AND t.material_source='回废' THEN ACT_WEIGHT ELSE NULL END) FGHF,
	    SUM(CASE WHEN t.material='废钢' THEN ACT_WEIGHT ELSE NULL END) AS FGTOTAL,
	    SUM(CASE WHEN t.material='废钢+生铁'  THEN ACT_WEIGHT ELSE NULL END) FGSTXH,
	    SUM(CASE WHEN t.material='铁水' AND t.material_source='自产' THEN ACT_WEIGHT ELSE NULL END) TSZC,
	    SUM(CASE WHEN t.material='铁水' AND t.material_source='采购' THEN ACT_WEIGHT ELSE NULL END) TSCG,
	    SUM(CASE WHEN t.material='铁水' THEN ACT_WEIGHT ELSE NULL END) AS TSTOTAL,
	    SUM(CASE WHEN t.material='铁水' THEN ACT_WEIGHT ELSE NULL END) AS TSXHTOTAL,
	    MAX(CASE WHEN t.material='生铁' AND t.material_source='自产' THEN ACT_WEIGHT ELSE NULL END) STZC,
	    MAX(CASE WHEN t.material='生铁' AND t.material_source='采购' THEN ACT_WEIGHT ELSE NULL END) STCG,
	    SUM(CASE WHEN t.material='生铁' THEN ACT_WEIGHT ELSE NULL END) AS STTOTAL,
	    SUM(DECODE(t.material,'生铁',ACT_WEIGHT,'废钢',ACT_WEIGHT,NULL)) - SUM(CASE WHEN t.material='废钢+生铁'  THEN ACT_WEIGHT ELSE NULL END) AS FGSTTOTALJXH,
	      SUM(CASE WHEN t.To_Dept='一炼钢厂'AND t.material='废钢+生铁' AND t.material_type='消耗' THEN ACT_WEIGHT ELSE NULL END) AS FGSTYLG,
      SUM(CASE WHEN t.To_Dept='二炼钢厂'AND t.material='废钢+生铁' AND t.material_type='消耗' THEN ACT_WEIGHT ELSE NULL END) AS FGSTERLG,
      SUM(CASE WHEN t.To_Dept='一炼钢厂'AND t.material='铁水' AND t.material_type='入库/消耗' THEN ACT_WEIGHT ELSE NULL END) AS TSYLG,
      SUM(CASE WHEN t.To_Dept='二炼钢厂'AND t.material='铁水' AND t.material_type='入库/消耗' THEN ACT_WEIGHT ELSE NULL END) AS TSERLG,
      SUM(CASE WHEN t.To_Dept='一炼钢厂'AND t.material_type='产出'  THEN ACT_WEIGHT ELSE NULL END) AS MATERIALOUTYLG,
      SUM(CASE WHEN t.To_Dept='二炼钢厂'AND t.material_type='产出'  THEN ACT_WEIGHT ELSE NULL END) AS MATERIALOUTERLG,
      SUM(CASE WHEN t.material_type='产出'  THEN ACT_WEIGHT ELSE NULL END) AS MATERIALOUTTOTAL,
      
         ROUND(SUM(CASE WHEN t.To_Dept='一炼钢厂'AND t.material_type IN ('消耗','入库/消耗')  THEN ACT_WEIGHT ELSE NULL END)*1000/
    SUM(CASE WHEN t.to_dept ='一炼钢厂' AND  t.material_type='产出' THEN t.act_weight ELSE NULL END),0)  AS GTLRATEYLG,
    ROUND(SUM(CASE WHEN t.To_Dept='二炼钢厂'AND t.material_type IN ('消耗','入库/消耗')  THEN ACT_WEIGHT ELSE NULL END)*1000/
    SUM(CASE WHEN t.to_dept ='二炼钢厂' AND t.material_type='产出'  THEN t.act_weight ELSE NULL END),0) AS GTLRATEERLG,
    ROUND(SUM(CASE WHEN t.material_type IN ('消耗','入库/消耗')  THEN ACT_WEIGHT ELSE NULL END)*1000/
    SUM(CASE WHEN  t.material_type='产出'  THEN t.act_weight ELSE NULL END),0)  AS GTLRATETOTAL
		FROM rpt_CG_MEASURE_TJ_HZ t
		WHERE t.rpt_date LIKE '#RPT_YM#%' AND t.rpt_date <=to_char(SYSDATE,'yyyy-MM-dd')
		GROUP BY t.rpt_date
    	ORDER BY t.rpt_date DESC
	]]>
	</query>
	<query id="BuyGpDAL.selectRptLsAll" desc="获取生产流速数据">
	<![CDATA[
      WITH
		ta
		AS
		(
		SELECT t.tj_ym,t.department_desc_p,t.pline_name,t.final_result,COUNT(*) AS qty FROM  RPT_LS t
		WHERE t.final_result ='OK' AND t.tj_ym IS NOT NULL  and t.RPT_YEAR = '#RPT_YEAR#'
		GROUP BY t.tj_ym,t.department_desc_p,t.pline_name,t.final_result
		),
		tb
		AS
		(
		SELECT t.tj_ym,t.department_desc_p,t.pline_name,COUNT(*) AS qty FROM  RPT_LS t
		WHERE (t.final_result ='OK'OR t.final_result ='NO') AND t.tj_ym IS NOT NULL
		GROUP BY t.tj_ym,t.department_desc_p,t.pline_name
		),
		tc
		AS
		(
		SELECT ta.tj_ym,ta.department_desc_p,ta.pline_name,ROUND((ta.qty*100/tb.qty),2) || '%' AS ls FROM ta,tb WHERE ta.tj_ym = tb.tj_ym AND ta.pline_name = tb.pline_name
		)
		SELECT * FROM (SELECT tj_ym,department_desc_p , pline_name ,ls,
		DECODE(tc.department_desc_p,'特钢公司',1,'轧管一部',3,'轧管二部',5,'轧管三部',7,'三圆公司',9,'管加工部',11,'生产计划部',13,99) AS px1,
		DECODE(tc.pline_name,'一炼铸机', 1,
		'二炼铸机', 3,
		'三炼铸机', 5,
		'250机组',  7,
		'250双探线', 9,
		'258机组',  11,
		'258双探线', 13,
		'168机组',  15,
		'168精整探伤线', 17,
		'168精整线', 19,
		'二部离线探伤线',  21,
		'冷轧不锈精整线',  23,
		'冷轧热处理线', 25,
		'460机组',  27,
		'720加工线', 29,
		'720热处理线',  31,
		'720旋扩',  33,
		'热扩', 35,
		'热扩探伤线',  37,
		'加工线01#（管加工1#线）', 29,
		'加工线02#（管加工2#线）', 31,
		'加工线03#（管加工3#线）', 33,
		'加工线04#（管加工4#线）', 35,
		'加工线05#（管加工5#线）', 37,
		'加工线06#（管加工6#线）', 39,
		'加工线07#（管加工油套线）', 41,
		'加工线08#（管加工试验线）', 43,
		'加工线09#（管加工油特线）', 45,
		'加工线10#（管加工特扣线）', 47,
		'加工线11#（元通油管线）',  49,
		'加工线12#（元通1#套管线）',  51,
		'加工线13#（元通2#套管线）',  53,
		'加工线14#（深加工油管线）', 55,
		'加工线15#（管加工短节线）', 57,
		'加工线21#（管加工1#光管线）', 59,
		'加工线22#（管加工2#光管线）', 61,
		'加工线23#（元通光管线）',  63,
		'加工线24#（深加工光管线）', 65,
		'加工线25#（深加工专业管线）',  67,
		'加工线26#（深加工深海管线）',  69,
		'热处理01#（管加工1号热）', 1,
		'热处理02#（管加工2号热）', 3,
		'热处理03#（管加工3号热）', 5,
		'热处理04#（管加工4号热）', 7,
		'热处理05#（管加工5号热）', 9,
		'热处理06#（深加工大）', 11,
		'热处理07#（深加工专）', 13,
		'热处理08#（深加工小）', 15,
		'热处理09#（元通一号热）',  17,
		'热处理10#（元通二热）', 19,
		'镦粗01#（管加工镦粗线）',  21,
		'热扩精整线',  23,
		'外委-镦粗',  25,
		'外委热处理',  27,null) AS px2 
		FROM tc) PIVOT(max(ls) FOR tj_ym IN #RPT_YM#)
		ORDER BY px1,px2
	]]>
	</query>
	<query id="BuyGpDAL.selectRptLsDetails" desc="获取生产流速详细数据">
	<![CDATA[
       SELECT 
        t.tj_ym,
        t.department_desc_p,
        t.pline_name,
        t.process_code,
        t.exe_status,
        t.judge_stove_no,
        t.order_no,
        t.spec_desc,
        t.material_desc,
        t.model_desc,
        t.steelname,
        t.std_style_desc,
        t.lh_normal,
        t.hon,
        t.bundling,
        t.scrap_num,
        t.material_in_qty,
        t.material_in_weight,
        t.qa_ton,
        t.feed_time,
        t.judge_time,
        t.standard_time,
        t.interval_time,     
        t.tj_ymd,
        t.qa_qty,
        t.final_result              
		FROM rpt_ls t
		WHERE t.tj_ym ='#RPTYM#'
		AND   t.department_desc_p ='#DEPT#'
		AND   t.pline_name ='#PLINE#'
		AND   t.final_result IN ('OK','NO')
	]]>
	</query>
	<query id="BuyGpDAL.selectRptDaySCKB20200714" desc="日生产运行快报（总调）数据">
	<![CDATA[
	WITH 
/**********************************形成表结构**************************************/
T00 AS
      (
       SELECT * FROM
        (
        SELECT T.PLINE_CODE,
               T.PLINE_NAME,
               DECODE(T.PROCESS_DESC, '轧制', '轧管', T.PROCESS_DESC) PROCESS_DESC,
               CASE WHEN T.PLINE_CODE IN ('C022','C023','C024','C025','C026') THEN 'F1'
                     WHEN T.PLINE_CODE IN ('C049','C050') THEN 'F2'
                     WHEN T.PLINE_CODE IN ('C048','C054','C055') THEN 'F3'  
                     ELSE T.PROCESS_CODE END PROCESS_CODE,
               DECODE(T.PLINE_CODE,'C001',-5,'C003',-4,'C008',1,'C009',2,'C010',3,'C017',4,'C022',6,'C023',7,'C024',8,'C025',9,
                                    'C026',10,'C049',12,'C050',13,'C054',15,'C055',16,'C048',17) PLINEORDER
          FROM COM_BASE_PLINE T
         WHERE T.PROCESS_CODE IN ('A', 'D','F')
         AND T.PLINE_CODE IN ('C001', 'C003', 'C008', 'C009', 'C010', 'C017','C022','C023','C024','C025','C026','C049','C050','C054','C055','C048')
         UNION ALL
         SELECT NULL,'合计','炼钢','A',-1 FROM DUAL
         UNION ALL
         SELECT NULL,'合计','轧管','D',5  FROM DUAL
         UNION ALL
          SELECT NULL,'小计','热处理(本部)','F1',11 FROM DUAL
         UNION ALL
         SELECT NULL,'小计','热处理(元通)','F2',14  FROM DUAL
          UNION ALL
         SELECT NULL,'小计','热处理(深加工)','F3',18  FROM DUAL
          UNION ALL
         SELECT NULL,'合计','热处理','F4',19  FROM DUAL
         )ta,
         (
          SELECT NULL ZCNB,NULL ZCWB,NULL YCNB,NULL YCWB,NULL TJTIMETOTAL,NULL TIMETOTAL,NULL YXNB,NULL YXZH,NULL DAYZYL,
                  NULL ZCNBDAY,NULL ZCWBDAY,NULL YCNBDAY,NULL YCWBDAY,NULL TJTIMETOTALDAY,NULL TIMETOTALDAY,NULL YXNBDAY,NULL YXZHDAY,NULL DAYZYLDAY
          FROM DUAL
         )tb
      ),
/**********************************炼钢时间范围查询**************************************/
T10 AS
       (SELECT SUM(TJTIME) AS TJTIME, PLINENAME, TJREASON
          FROM (SELECT T10.CONTROL_ID,
                       T10.STOP_REASON,
                       T10.LOGS_BEG,
                       T10.LOGS_END,
                       (TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                       TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                       (SELECT BASENAME
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T10.STOP_TYPE) STOPTYPE,
                       (SELECT PROPERA
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T10.STOP_REASON) STOPREASON,
                       (SELECT PLINE_NAME
                          FROM COM_BASE_PLINE
                         WHERE PLINE_CODE = T10.EF_PLINE_CODE) PLINENAME,
                       CASE
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '内部原因' THEN
                          'ZCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '外部原因' THEN
                          'ZCWB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '内部原因' THEN
                          'YCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '外部原因' THEN
                          'YCWB'
                       END TJREASON
                  FROM STL_CONTROL_LOG T10
                 WHERE T10.PRO_TYPE = '2'
                  AND TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                       TO_DATE('#LASTDATE#', 'yyyy-mm-dd hh24:mi:ss')
                   AND TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
                       TO_DATE('#BGEINDATE#', 'yyyy-mm-dd hh24:mi:ss')
                   AND T10.STOP_TYPE IN ('300101', '300102')
                   AND T10.EF_PLINE_CODE IN ('C001', 'C003')
                   AND EXISTS (SELECT *
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T10.STOP_REASON
                           AND VALIDFLAG = '1')) TA
         GROUP BY TA.PLINENAME, TA.TJREASON),    
      T11 AS
       (SELECT 'A' PROCESS_CODE, 
               PLINENAME,
               MAX(DECODE(TJREASON, 'ZCNB', TJTIME, NULL)) AS ZCNB,
               MAX(DECODE(TJREASON, 'ZCWB', TJTIME, NULL)) AS ZCWB,
               MAX(DECODE(TJREASON, 'YCNB', TJTIME, NULL)) AS YCNB,
               MAX(DECODE(TJREASON, 'YCWB', TJTIME, NULL)) AS YCWB,
               SUM(TJTIME) TJTIMETOTAL,
               24 * 60 * #DAYS# TIMETOTAL
          FROM T10
         GROUP BY PLINENAME),
/**********************************炼钢日范围查询**************************************/  
      T12 AS
       (SELECT SUM(TJTIME) AS TJTIME, PLINENAME, TJREASON
          FROM (SELECT T10.CONTROL_ID,
                       T10.STOP_REASON,
                       T10.LOGS_BEG,
                       T10.LOGS_END,
                       (TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                       TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                       (SELECT BASENAME
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T10.STOP_TYPE) STOPTYPE,
                       (SELECT PROPERA
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T10.STOP_REASON) STOPREASON,
                       (SELECT PLINE_NAME
                          FROM COM_BASE_PLINE
                         WHERE PLINE_CODE = T10.EF_PLINE_CODE) PLINENAME,
                       CASE
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '内部原因' THEN
                          'ZCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '外部原因' THEN
                          'ZCWB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '内部原因' THEN
                          'YCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '外部原因' THEN
                          'YCWB'
                       END TJREASON
                  FROM STL_CONTROL_LOG T10
                 WHERE T10.PRO_TYPE = '2'
                  AND TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                       TO_DATE('#ENDDATE#', 'yyyy-mm-dd hh24:mi:ss')
                   AND TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
                       TO_DATE('#BGEINDATE#', 'yyyy-mm-dd hh24:mi:ss')
                   AND T10.STOP_TYPE IN ('300101', '300102')
                   AND T10.EF_PLINE_CODE IN ('C001', 'C003')
                   AND EXISTS (SELECT *
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T10.STOP_REASON
                           AND VALIDFLAG = '1')) TA
         GROUP BY TA.PLINENAME, TA.TJREASON),
      T13 AS
       (SELECT 'A' PROCESS_CODE,
               PLINENAME ,
               MAX(DECODE(TJREASON, 'ZCNB', TJTIME, NULL)) AS ZCNBDAY,
               MAX(DECODE(TJREASON, 'ZCWB', TJTIME, NULL)) AS ZCWBDAY,
               MAX(DECODE(TJREASON, 'YCNB', TJTIME, NULL)) AS YCNBDAY,
               MAX(DECODE(TJREASON, 'YCWB', TJTIME, NULL)) AS YCWBDAY,
               SUM(TJTIME) TJTIMETOTALDAY,
               24 * 60 TIMETOTALDAY
          FROM T12
         GROUP BY PLINENAME),
     /********炼钢累计数值*******/
     T14 AS
     (
      SELECT * FROM T11
      UNION ALL
      SELECT 'A' PROCESS_CODE ,'合计' PLINENAME,SUM(ZCNB) ZCNB,SUM(ZCWB)ZCWB,SUM(YCNB) YCNB,SUM(YCWB) YCWB,
      SUM(TJTIMETOTAL) TJTIMETOTAL,SUM(TIMETOTAL) TIMETOTAL FROM T11
     ),
     /********炼钢日数值*******/
     T15 AS
     (
      SELECT * FROM T13
      UNION ALL
      SELECT  'A' PROCESS_CODE,'合计' PLINENAME,SUM(ZCNBDAY) ZCNBDAY,SUM(ZCWBDAY)ZCWBDAY,SUM(YCNBDAY) YCNBDAY,SUM(YCWBDAY) YCWBDAY,
      SUM(TJTIMETOTALDAY) TJTIMETOTALDAY,SUM(TIMETOTALDAY) TIMETOTALDAY FROM T13
     ),
     /**********************************轧管时间范围查询**************************************/       
       T AS
       (SELECT SUM(TJTIME) AS TJTIME, PLINENAME, TJREASON
          FROM (SELECT T.CONTROL_ID,
                       T.STOP_REASON,
                       T.LOGS_BEG,
                       T.LOGS_END,
                       (TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                       TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                       (SELECT BASENAME
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_TYPE) STOPTYPE,
                       (SELECT PROPERA
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON) STOPREASON,
                       (SELECT PLINE_NAME
                          FROM COM_BASE_PLINE
                         WHERE PLINE_CODE = T.PLINE_CODE) PLINENAME,
                       CASE
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'ZCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'ZCWB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'YCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'YCWB'
                       END TJREASON
                  FROM MIL_CONTROL_LOG T
                 WHERE T.PRO_TYPE = '2'
                   AND TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                        TO_DATE('#LASTDATE#', 'yyyy-mm-dd hh24:mi:ss')
                   AND TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
                        TO_DATE('#BGEINDATE#', 'yyyy-mm-dd hh24:mi:ss')
                   AND T.STOP_TYPE IN ('500601', '500602')
                   AND T.PLINE_CODE IN ('C008', 'C009', 'C010', 'C017')
                   AND EXISTS (SELECT *
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON
                           AND VALIDFLAG = '1')) TA
         GROUP BY TA.PLINENAME, TA.TJREASON),      
      T1 AS
       (SELECT 'D' PROCESS_CODE, 
               PLINENAME,
               MAX(DECODE(TJREASON, 'ZCNB', TJTIME, NULL)) AS ZCNB,
               MAX(DECODE(TJREASON, 'ZCWB', TJTIME, NULL)) AS ZCWB,
               MAX(DECODE(TJREASON, 'YCNB', TJTIME, NULL)) AS YCNB,
               MAX(DECODE(TJREASON, 'YCWB', TJTIME, NULL)) AS YCWB,
               SUM(TJTIME) TJTIMETOTAL,
               24 * 60 * #DAYS# TIMETOTAL
          FROM T
         GROUP BY PLINENAME),
/**********************************轧管日范围查询**************************************/   
      T2 AS
       (SELECT SUM(TJTIME) AS TJTIME, PLINENAME, TJREASON
          FROM (SELECT T.CONTROL_ID,
                       T.STOP_REASON,
                       T.LOGS_BEG,
                       T.LOGS_END,
                       (TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                       TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                       (SELECT BASENAME
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_TYPE) STOPTYPE,
                       (SELECT PROPERA
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON) STOPREASON,
                       (SELECT PLINE_NAME
                          FROM COM_BASE_PLINE
                         WHERE PLINE_CODE = T.PLINE_CODE) PLINENAME,
                       CASE
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'ZCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'ZCWB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'YCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'YCWB'
                       END TJREASON
                  FROM MIL_CONTROL_LOG T
                 WHERE T.PRO_TYPE = '2'
                   AND TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                       TO_DATE('#ENDDATE#', 'yyyy-mm-dd hh24:mi:ss')
                   AND TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
                       TO_DATE('#BGEINDATE#', 'yyyy-mm-dd hh24:mi:ss')
                   AND T.STOP_TYPE IN ('500601', '500602')
                   AND T.PLINE_CODE IN ('C008', 'C009', 'C010', 'C017')
                   AND EXISTS (SELECT *
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON
                           AND VALIDFLAG = '1')) TA
         GROUP BY TA.PLINENAME, TA.TJREASON),
      T3 AS
       (SELECT  'D' PROCESS_CODE, 
               PLINENAME ,
               MAX(DECODE(TJREASON, 'ZCNB', TJTIME, NULL)) AS ZCNBDAY,
               MAX(DECODE(TJREASON, 'ZCWB', TJTIME, NULL)) AS ZCWBDAY,
               MAX(DECODE(TJREASON, 'YCNB', TJTIME, NULL)) AS YCNBDAY,
               MAX(DECODE(TJREASON, 'YCWB', TJTIME, NULL)) AS YCWBDAY,
               SUM(TJTIME) TJTIMETOTALDAY,
               24 * 60 TIMETOTALDAY
          FROM T2
         GROUP BY PLINENAME),
     /********轧管累计数值*******/
     T4 AS
     (
      SELECT * FROM T1
      UNION ALL
      SELECT 'D' PROCESS_CODE ,'合计' PLINENAME,SUM(ZCNB) ZCNB,SUM(ZCWB)ZCWB,SUM(YCNB) YCNB,SUM(YCWB) YCWB,
      SUM(TJTIMETOTAL) TJTIMETOTAL,SUM(TIMETOTAL) TIMETOTAL FROM T1
     ),
     /********轧管日数值*******/
     T5 AS
     (
      SELECT * FROM T3
      UNION ALL
      SELECT  'D' PROCESS_CODE,'合计' PLINENAME,SUM(ZCNBDAY) ZCNBDAY,SUM(ZCWBDAY)ZCWBDAY,SUM(YCNBDAY) YCNBDAY,SUM(YCWBDAY) YCWBDAY,
      SUM(TJTIMETOTALDAY) TJTIMETOTALDAY,SUM(TIMETOTALDAY) TIMETOTALDAY FROM T3
     ),
      /**********************************热处理时间范围查询**************************************/       
       T30 AS
       (SELECT SUM(TJTIME) AS TJTIME, PLINENAME, TJREASON,PLINE_CODE
          FROM (SELECT T.CONTROL_ID,
                       T.STOP_REASON,
                       T.LOGS_BEG,
                       T.LOGS_END,
                       (TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                       TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                       (SELECT BASENAME
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_TYPE) STOPTYPE,
                       (SELECT PROPERA
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON) STOPREASON,
                       (SELECT PLINE_NAME
                          FROM COM_BASE_PLINE
                         WHERE PLINE_CODE = T.PLINE_CODE) PLINENAME,
                       CASE
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'ZCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'ZCWB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'YCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'YCWB'
                       END TJREASON,
                       PLINE_CODE
                  FROM (SELECT T1.CONTROL_ID,
                         T1.LOGS_BEG,
                         T1.LOGS_END,
                         T.PLINE_CODE,
                         T1.STOP_TYPE,
                         T1.STOP_REASON,
                         T1.STOP_SMALL
                    FROM HTT_CONTROL_LOG T, HTT_CONTROL_LOG_DETAIL T1
                    WHERE T.PRO_TYPE = '2'
                    AND T.CONTROL_ID = T1.CONTROL_ID
                    AND TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                        TO_DATE('#LASTDATE#', 'yyyy-mm-dd hh24:mi:ss')
                   AND TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
                        TO_DATE('#BGEINDATE#', 'yyyy-mm-dd hh24:mi:ss')
                   AND T.PLINE_CODE IN ('C022','C023','C024','C025','C026','C049','C050','C054','C055','C048')) T
                 WHERE 1=1
                   --AND T.STOP_TYPE IN ('500601', '500602')
                   AND EXISTS (SELECT *
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON
                           AND VALIDFLAG = '1')) TA
         GROUP BY TA.PLINENAME,TA.PLINE_CODE,TA.TJREASON),      
      T31 AS
       (SELECT 
              --'F' PROCESS_CODE,
               CASE WHEN PLINE_CODE IN ('C022','C023','C024','C025','C026') THEN 'F1'
                     WHEN PLINE_CODE IN ('C049','C050') THEN 'F2'
                     WHEN PLINE_CODE IN ('C048','C054','C055') THEN 'F3'  
                     ELSE NULL END PROCESS_CODE, 
               PLINENAME,
               MAX(DECODE(TJREASON, 'ZCNB', TJTIME, NULL)) AS ZCNB,
               MAX(DECODE(TJREASON, 'ZCWB', TJTIME, NULL)) AS ZCWB,
               MAX(DECODE(TJREASON, 'YCNB', TJTIME, NULL)) AS YCNB,
               MAX(DECODE(TJREASON, 'YCWB', TJTIME, NULL)) AS YCWB,
               SUM(TJTIME) TJTIMETOTAL,
               24 * 60  TIMETOTAL
          FROM T30
         GROUP BY PLINENAME,PLINE_CODE),
       /**********************************热处理日范围查询**************************************/   
       T32 AS
       (SELECT SUM(TJTIME) AS TJTIME, PLINENAME, TJREASON,PLINE_CODE
          FROM (SELECT T.CONTROL_ID,
                       T.STOP_REASON,
                       T.LOGS_BEG,
                       T.LOGS_END,
                       (TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                       TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                       (SELECT BASENAME
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_TYPE) STOPTYPE,
                       (SELECT PROPERA
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON) STOPREASON,
                       (SELECT PLINE_NAME
                          FROM COM_BASE_PLINE
                         WHERE PLINE_CODE = T.PLINE_CODE) PLINENAME,
                       CASE
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'ZCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'ZCWB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'YCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'YCWB'
                       END TJREASON,
                       PLINE_CODE
                  FROM (SELECT T1.CONTROL_ID,
                         T1.LOGS_BEG,
                         T1.LOGS_END,
                         T.PLINE_CODE,
                         T1.STOP_TYPE,
                         T1.STOP_REASON,
                         T1.STOP_SMALL
                    FROM HTT_CONTROL_LOG T, HTT_CONTROL_LOG_DETAIL T1
                    WHERE T.PRO_TYPE = '2'
                    AND T.CONTROL_ID = T1.CONTROL_ID
                    AND TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                        TO_DATE('#ENDDATE#', 'yyyy-mm-dd hh24:mi:ss')
                   AND TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
                        TO_DATE('#BGEINDATE#', 'yyyy-mm-dd hh24:mi:ss')
                   AND T.PLINE_CODE IN ('C022','C023','C024','C025','C026','C049','C050','C054','C055','C048')) T
                 WHERE 1=1
                   --AND T.STOP_TYPE IN ('500601', '500602')
                   AND EXISTS (SELECT *
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON
                           AND VALIDFLAG = '1')) TA
         GROUP BY TA.PLINENAME,TA.PLINE_CODE,TA.TJREASON),            
      T33 AS
       (SELECT 
              --'F' PROCESS_CODE,
               CASE WHEN PLINE_CODE IN ('C022','C023','C024','C025','C026') THEN 'F1'
                     WHEN PLINE_CODE IN ('C049','C050') THEN 'F2'
                     WHEN PLINE_CODE IN ('C048','C054','C055') THEN 'F3'  
                     ELSE NULL END PROCESS_CODE, 
               PLINENAME,
               MAX(DECODE(TJREASON, 'ZCNB', TJTIME, NULL)) AS ZCNBDAY,
               MAX(DECODE(TJREASON, 'ZCWB', TJTIME, NULL)) AS ZCWBDAY,
               MAX(DECODE(TJREASON, 'YCNB', TJTIME, NULL)) AS YCNBDAY,
               MAX(DECODE(TJREASON, 'YCWB', TJTIME, NULL)) AS YCWBDAY,
               SUM(TJTIME) TJTIMETOTALDAY,
               24 * 60  TIMETOTALDAY
          FROM T32
         GROUP BY PLINENAME,PLINE_CODE),
          /********热处理累计数值*******/
     T34 AS
     (
      SELECT * FROM T31
      UNION ALL
      SELECT PROCESS_CODE ,'小计' PLINENAME,SUM(ZCNB) ZCNB,SUM(ZCWB)ZCWB,SUM(YCNB) YCNB,SUM(YCWB) YCWB,
      SUM(TJTIMETOTAL) TJTIMETOTAL,SUM(TIMETOTAL) TIMETOTAL FROM T31 GROUP BY PROCESS_CODE
      UNION ALL
      SELECT 'F4' PROCESS_CODE ,'合计' PLINENAME,SUM(ZCNB) ZCNB,SUM(ZCWB)ZCWB,SUM(YCNB) YCNB,SUM(YCWB) YCWB,
      SUM(TJTIMETOTAL) TJTIMETOTAL,SUM(TIMETOTAL) TIMETOTAL FROM T31
     ),
     /********热处理日数值*******/
     T35 AS
     (
      SELECT * FROM T33
      UNION ALL
      SELECT PROCESS_CODE ,'小计' PLINENAME,SUM(ZCNBDAY) ZCNBDAY,SUM(ZCWBDAY)ZCWBDAY,SUM(YCNBDAY) YCNBDAY,SUM(YCWBDAY) YCWBDAY,
      SUM(TJTIMETOTALDAY) TJTIMETOTALDAY,SUM(TIMETOTALDAY) TIMETOTALDAY FROM T33 GROUP BY PROCESS_CODE
      UNION ALL
      SELECT  'F4' PROCESS_CODE,'合计' PLINENAME,SUM(ZCNBDAY) ZCNBDAY,SUM(ZCWBDAY)ZCWBDAY,SUM(YCNBDAY) YCNBDAY,SUM(YCWBDAY) YCWBDAY,
      SUM(TJTIMETOTALDAY) TJTIMETOTALDAY,SUM(TIMETOTALDAY) TIMETOTALDAY FROM T33
     ),
     T99
     AS
     (
     SELECT T00.PLINEORDER,T00.PROCESS_DESC,T00.PLINE_NAME,PLINE_CODE,
     DECODE(T00.PROCESS_CODE,'A',NVL(T14.ZCNB,T00.ZCNB),
                              'D',NVL(T4.ZCNB,T00.ZCNB),
                              'F1',NVL(T34.ZCNB,T00.ZCNB),
                              'F2',NVL(T34.ZCNB,T00.ZCNB),
                              'F3',NVL(T34.ZCNB,T00.ZCNB),
                              'F4',NVL(T34.ZCNB,T00.ZCNB),
                               T00.ZCNB) ZCNB,
     DECODE(T00.PROCESS_CODE,'A',NVL(T14.ZCWB,T00.ZCWB),
                              'D',NVL(T4.ZCWB,T00.ZCWB),
                               'F1',NVL(T34.ZCWB,T00.ZCWB),
                               'F2',NVL(T34.ZCWB,T00.ZCWB),
                               'F3',NVL(T34.ZCWB,T00.ZCWB),
                               'F4',NVL(T34.ZCWB,T00.ZCWB),
                              T00.ZCWB) ZCWB,
     DECODE(T00.PROCESS_CODE,'A',NVL(T14.YCNB,T00.YCNB),
                              'D',NVL(T4.YCNB,T00.YCNB),
                              'F1',NVL(T34.YCNB,T00.YCNB),
                              'F2',NVL(T34.YCNB,T00.YCNB),
                              'F3',NVL(T34.YCNB,T00.YCNB),
                              'F4',NVL(T34.YCNB,T00.YCNB),
                              T00.YCNB) YCNB,
     DECODE(T00.PROCESS_CODE,'A',NVL(T14.YCWB,T00.YCWB),
                              'D',NVL(T4.YCWB,T00.YCWB),
                              'F1',NVL(T34.YCWB,T00.YCWB),
                              'F2',NVL(T34.YCWB,T00.YCWB),
                              'F3',NVL(T34.YCWB,T00.YCWB),
                              'F4',NVL(T34.YCWB,T00.YCWB),
                              T00.YCWB) YCWB,
     DECODE(T00.PROCESS_CODE,'A',NVL(T14.TJTIMETOTAL,T00.TJTIMETOTAL),
                              'D',NVL(T4.TJTIMETOTAL,T00.TJTIMETOTAL),
                              'F1',NVL(T34.TJTIMETOTAL,T00.TJTIMETOTAL),
                              'F2',NVL(T34.TJTIMETOTAL,T00.TJTIMETOTAL),
                              'F3',NVL(T34.TJTIMETOTAL,T00.TJTIMETOTAL),
                              'F4',NVL(T34.TJTIMETOTAL,T00.TJTIMETOTAL),
                              T00.TJTIMETOTAL) TJTIMETOTAL,
     DECODE(T00.PROCESS_CODE,'A',NVL(T14.TIMETOTAL,T00.TIMETOTAL),
                              'D',NVL(T4.TIMETOTAL,T00.TIMETOTAL),
                              'F1',NVL(T34.TIMETOTAL,T00.TIMETOTAL),
                              'F2',NVL(T34.TIMETOTAL,T00.TIMETOTAL),
                              'F3',NVL(T34.TIMETOTAL,T00.TIMETOTAL),
                              'F4',NVL(T34.TIMETOTAL,T00.TIMETOTAL),
                              T00.TIMETOTAL) TIMETOTAL,
     YXNB,YXZH,DAYZYL,
     DECODE(T00.PROCESS_CODE,'A',NVL(T15.ZCNBDAY,T00.ZCNBDAY),
                              'D',NVL(T5.ZCNBDAY,T00.ZCNBDAY),
                              'F1',NVL(T35.ZCNBDAY,T00.ZCNBDAY),
                              'F2',NVL(T35.ZCNBDAY,T00.ZCNBDAY),
                              'F3',NVL(T35.ZCNBDAY,T00.ZCNBDAY),
                              'F4',NVL(T35.ZCNBDAY,T00.ZCNBDAY),
                              T00.ZCNBDAY) ZCNBDAY,
     DECODE(T00.PROCESS_CODE,'A',NVL(T15.ZCWBDAY,T00.ZCWBDAY),
                              'D',NVL(T5.ZCWBDAY,T00.ZCWBDAY),
                              'F1',NVL(T35.ZCWBDAY,T00.ZCWBDAY),
                              'F2',NVL(T35.ZCWBDAY,T00.ZCWBDAY),
                              'F3',NVL(T35.ZCWBDAY,T00.ZCWBDAY),
                              'F4',NVL(T35.ZCWBDAY,T00.ZCWBDAY),
                              T00.ZCWBDAY) ZCWBDAY,
     DECODE(T00.PROCESS_CODE,'A',NVL(T15.YCNBDAY,T00.YCNBDAY),
                              'D',NVL(T5.YCNBDAY,T00.YCNBDAY),
                              'F1',NVL(T35.YCNBDAY,T00.YCNBDAY),
                              'F2',NVL(T35.YCNBDAY,T00.YCNBDAY),
                              'F3',NVL(T35.YCNBDAY,T00.YCNBDAY),
                              'F4',NVL(T35.YCNBDAY,T00.YCNBDAY),
                              T00.YCNBDAY) YCNBDAY,
     DECODE(T00.PROCESS_CODE,'A',NVL(T15.YCWBDAY,T00.YCWBDAY),
                              'D',NVL(T5.YCWBDAY,T00.YCWBDAY),
                              'F1',NVL(T35.YCWBDAY,T00.YCWBDAY),
                              'F2',NVL(T35.YCWBDAY,T00.YCWBDAY),
                              'F3',NVL(T35.YCWBDAY,T00.YCWBDAY),
                              'F4',NVL(T35.YCWBDAY,T00.YCWBDAY),
                              T00.YCWBDAY) YCWBDAY,
     DECODE(T00.PROCESS_CODE,'A',NVL(T15.TJTIMETOTALDAY,T00.TJTIMETOTALDAY),
                              'D',NVL(T5.TJTIMETOTALDAY,T00.TJTIMETOTALDAY),
                              'F1',NVL(T35.TJTIMETOTALDAY,T00.TJTIMETOTALDAY),
                              'F2',NVL(T35.TJTIMETOTALDAY,T00.TJTIMETOTALDAY),
                              'F3',NVL(T35.TJTIMETOTALDAY,T00.TJTIMETOTALDAY),
                              'F4',NVL(T35.TJTIMETOTALDAY,T00.TJTIMETOTALDAY),
                              T00.TJTIMETOTALDAY) TJTIMETOTALDAY,
     DECODE(T00.PROCESS_CODE,'A',NVL(T15.TIMETOTALDAY,T00.TIMETOTALDAY),
                              'D',NVL(T5.TIMETOTALDAY,T00.TIMETOTALDAY),
                              'F1',NVL(T35.TIMETOTALDAY,T00.TIMETOTALDAY),
                              'F2',NVL(T35.TIMETOTALDAY,T00.TIMETOTALDAY),
                              'F3',NVL(T35.TIMETOTALDAY,T00.TIMETOTALDAY),
                              'F4',NVL(T35.TIMETOTALDAY,T00.TIMETOTALDAY),
                              T00.TIMETOTALDAY) TIMETOTALDAY,
     YXNBDAY,YXZHDAY,DAYZYLDAY     
     FROM T00,T14,T15,T4,T5,T34,T35
     WHERE 1=1 
     AND T00.PROCESS_CODE = T14.PROCESS_CODE(+) AND T00.PLINE_NAME = T14.PLINENAME(+)
     AND T00.PROCESS_CODE = T15.PROCESS_CODE(+) AND T00.PLINE_NAME = T15.PLINENAME(+)
     AND T00.PROCESS_CODE = T4.PROCESS_CODE(+) AND T00.PLINE_NAME = T4.PLINENAME(+)
     AND T00.PROCESS_CODE = T5.PROCESS_CODE(+) AND T00.PLINE_NAME = T5.PLINENAME(+)
     AND T00.PROCESS_CODE = T34.PROCESS_CODE(+) AND T00.PLINE_NAME = T34.PLINENAME(+)
     AND T00.PROCESS_CODE = T35.PROCESS_CODE(+) AND T00.PLINE_NAME = T35.PLINENAME(+)
     ),
     T100
     AS
     (
      SELECT PLINEORDER,PROCESS_DESC,PLINE_NAME,PLINE_CODE,ZCNB,ZCWB,YCNB,YCWB,TJTIMETOTAL,TIMETOTAL,
      CASE WHEN TJTIMETOTAL=TIMETOTAL AND TJTIMETOTAL=YCNB THEN '0.00' WHEN TJTIMETOTAL IS NULL THEN '100.00' WHEN TJTIMETOTAL=TIMETOTAL THEN '100.00'
        ELSE TO_CHAR((TIMETOTAL - NVL(TJTIMETOTAL, 0)) * 100 /(TIMETOTAL - NVL(TJTIMETOTAL, 0) + NVL(YCNB, 0)),'fm99999999999990.00') END || '%' YXNB,
      CASE WHEN TJTIMETOTAL=TIMETOTAL AND (TJTIMETOTAL=YCNB OR TJTIMETOTAL=YCWB) THEN '0.00' WHEN TJTIMETOTAL=TIMETOTAL  THEN '0.00' WHEN TJTIMETOTAL IS NULL THEN '100.00'
        ELSE TO_CHAR((TIMETOTAL - NVL(TJTIMETOTAL, 0)) * 100 /(TIMETOTAL - NVL(TJTIMETOTAL, 0) + NVL(YCNB, 0)+NVL(YCWB, 0)),'fm99999999999990.00') END || '%' YXZH,
      CASE WHEN TJTIMETOTAL=TIMETOTAL THEN '0.00' WHEN TJTIMETOTAL IS NULL THEN '100.00'
        ELSE TO_CHAR((TIMETOTAL - NVL(TJTIMETOTAL, 0)) * 100 /TIMETOTAL,'fm99999999999990.00') END || '%' DAYZYL,
      ZCNBDAY,ZCWBDAY,YCNBDAY,YCWBDAY,TJTIMETOTALDAY,TIMETOTALDAY,
      CASE WHEN TJTIMETOTALDAY=TIMETOTALDAY AND TJTIMETOTALDAY=YCNBDAY THEN '0.00' WHEN TJTIMETOTALDAY IS NULL THEN '100.00' WHEN TJTIMETOTALDAY=TIMETOTALDAY THEN '100.00' 
        ELSE TO_CHAR((TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0)) * 100 /(TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0) + NVL(YCNBDAY, 0)),'fm99999999999990.00') END || '%' YXNBDAY,
      CASE WHEN TJTIMETOTALDAY=TIMETOTALDAY AND (TJTIMETOTALDAY=YCNBDAY OR TJTIMETOTALDAY=YCWBDAY) THEN '0.00' WHEN TJTIMETOTALDAY IS NULL THEN '100.00' 
        ELSE TO_CHAR((TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0)) * 100 /(TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0) + NVL(YCNBDAY, 0)+NVL(YCWBDAY, 0)),'fm99999999999990.00') END || '%' YXZHDAY,
      CASE WHEN TJTIMETOTALDAY=TIMETOTALDAY THEN '0.00' WHEN TJTIMETOTALDAY IS NULL THEN '100.00' 
        ELSE TO_CHAR((TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0)) * 100 /TIMETOTALDAY,'fm99999999999990.00') END || '%' DAYZYLDAY
      
      FROM T99
     )
     SELECT PLINEORDER,
     CASE WHEN PLINE_CODE IN ('C022','C023','C024','C025','C026') THEN '热处理(本部)'
           WHEN  PLINE_CODE IN ('C049','C050') THEN '热处理(元通)'
           WHEN PLINE_CODE IN ('C048','C054','C055') THEN  '热处理(深加工)'
           ELSE PROCESS_DESC END  DEPT,
     PLINE_NAME PLINENAME,PLINE_CODE PLINECODE,
     TO_CHAR(ZCNB/60,'fm99999999999990.00') ZCNB,
     TO_CHAR(ZCWB/60,'fm99999999999990.00') ZCWB,
     TO_CHAR(YCNB/60,'fm99999999999990.00') YCNB,
     TO_CHAR(YCWB/60,'fm99999999999990.00') YCWB,
     TO_CHAR(TJTIMETOTAL/60,'fm99999999999990.00') TJTIMETOTAL,
     TIMETOTAL,
     YXNB,YXZH,DAYZYL,
     TO_CHAR(ZCNBDAY/60,'fm99999999999990.00') ZCNBDAY,
     TO_CHAR(ZCWBDAY/60,'fm99999999999990.00')    ZCWBDAY,
     TO_CHAR(YCNBDAY/60,'fm99999999999990.00') YCNBDAY,
     TO_CHAR(YCWBDAY/60,'fm99999999999990.00')  YCWBDAY,
     TO_CHAR(TJTIMETOTALDAY/60,'fm99999999999990.00') TJTIMETOTALDAY,
     TIMETOTALDAY,
     YXNBDAY,YXZHDAY,DAYZYLDAY
     FROM T100
     ORDER BY PLINEORDER
	]]>
	</query>

	<query id="BuyGpDAL.selectRptDaySCKB" desc="日生产运行快报（总调）数据">
	<![CDATA[
WITH 
/**********************************形成表结构**************************************/
T01 AS
(
  SELECT T.PLINE_CODE,
               T.PLINE_NAME ,
               T.PROCESS_DESC ,
               CASE WHEN T.PLINE_CODE IN ('C022','C023','C024','C025','C026') THEN 'F1'
                     WHEN T.PLINE_CODE IN ('C049','C050') THEN 'F1'
                     WHEN T.PLINE_CODE IN ('C048','C054','C055') THEN 'F1'  
                     ELSE T.PROCESS_CODE END PROCESS_CODE,
              DECODE(T.PLINE_CODE,'C001',-5,'C003',-4,'C008',1,'C009',2,'C010',3,'C017',4,'C022',6,'C023',7,'C024',8,'C025',9,
                                    'C026',10,'C049',15,'C050',16,'C054',20,'C055',21,'C048',22) PLINEORDER
          FROM COM_BASE_PLINE T
         WHERE T.PROCESS_CODE IN ('F')
         AND T.PLINE_CODE IN ('C022','C023','C024','C025','C026','C049','C050','C054','C055','C048')
    UNION ALL
     SELECT T.PLINE_CODE,
               T.PLINE_NAME ,
               T.PROCESS_DESC ,
               CASE WHEN T.PLINE_CODE IN ('C022','C023','C024','C025','C026') THEN 'F2'
                     WHEN T.PLINE_CODE IN ('C049','C050') THEN 'F2'
                     WHEN T.PLINE_CODE IN ('C048','C054','C055') THEN 'F2'  
                     ELSE T.PROCESS_CODE END PROCESS_CODE,
               DECODE(T.PLINE_CODE,'C001',-5,'C003',-4,'C008',1,'C009',2,'C010',3,'C017',4,'C022',30,'C023',31,'C024',32,'C025',33,
                                    'C026',34,'C049',41,'C050',42,'C054',45,'C055',46,'C048',47) PLINEORDER
          FROM COM_BASE_PLINE T
         WHERE T.PROCESS_CODE IN ('F')
         AND T.PLINE_CODE IN ('C022','C023','C024','C025','C026','C049','C050','C054','C055','C048')
     UNION ALL
     SELECT T.PLINE_CODE,
               T.PLINE_NAME ,
               T.PROCESS_DESC ,
               CASE WHEN T.PLINE_CODE IN ('C028','C029','C030','C031','C032','C033','C034','C035','C036','C037','C053','C056') THEN 'G1'
                     WHEN T.PLINE_CODE IN ( 'C039','C051','C038','C057') THEN 'G2'
                     WHEN T.PLINE_CODE IN ( 'C052','C078','C058') THEN 'G3'  
                     ELSE T.PROCESS_CODE END PROCESS_CODE,
               DECODE(T.PLINE_CODE,'C028',55,'C029',56,'C030',57,'C031',58,'C032',59,'C033',60,'C034',61,'C035',62,'C036',63,'C037',64,
                                    'C053',65,'C056',66,'C039',70,'C051',71,'C038',72,'C057',73,'C052',80,'C078',81,'C058',82) PLINEORDER
          FROM COM_BASE_PLINE T
          WHERE T.PLINE_CODE IN ('C028','C029','C030','C031','C032','C033','C034','C035','C036','C037','C053','C056',
                                'C039','C051','C038','C057','C052','C078','C058')    
    ORDER BY PROCESS_DESC,PROCESS_CODE,PLINE_CODE
),
T00 AS
      (
       SELECT DECODE(PLINEORDER,-1, 24*60*2 , 5,24*60*5 ,11,24*60*5,17,24*60*2,23,24*60*3,
                                  24,24*60*10,35,24*60*5,43,24*60*2,48,24*60*3,49,24*60*10,
                                  67,24*60*12,74,24*60*4,83,24*60*3,100,24*60*19,24*60) TIMETOTALDAY1,
			  DECODE(PLINEORDER,-1, 24*60*2* #DAYS# , 5,24*60*5* #DAYS# ,11,24*60*5* #DAYS#,17,24*60*2* #DAYS#,23,24*60*3* #DAYS#,
                                  24,24*60*10* #DAYS#,35,24*60*5* #DAYS#,43,24*60*2* #DAYS#,48,24*60*3* #DAYS#,49,24*60*10* #DAYS#,
                                  67,24*60*12* #DAYS#,74,24*60*4* #DAYS#,83,24*60*3* #DAYS#,100,24*60*19* #DAYS#,24*60* #DAYS#) TIMETOTAL1,
                                  ta.*,tb.*
        FROM
        (
        SELECT T.PLINE_CODE,
               T.PLINE_NAME,
               DECODE(T.PROCESS_DESC, '轧制', '轧管', T.PROCESS_DESC) PROCESS_DESC,
               CASE WHEN T.PLINE_CODE IN ('C022','C023','C024','C025','C026') THEN 'F1'
                     WHEN T.PLINE_CODE IN ('C049','C050') THEN 'F2'
                     WHEN T.PLINE_CODE IN ('C048','C054','C055') THEN 'F3'  
                     ELSE T.PROCESS_CODE END PROCESS_CODE,
               DECODE(T.PLINE_CODE,'C001',-5,'C003',-4,'C008',1,'C009',2,'C010',3,'C017',4,'C022',6,'C023',7,'C024',8,'C025',9,
                                    'C026',10,'C049',12,'C050',13,'C054',15,'C055',16,'C048',17) PLINEORDER
          FROM COM_BASE_PLINE T
         WHERE T.PROCESS_CODE IN ('A', 'D','F')
         AND T.PLINE_CODE IN ('C001', 'C003', 'C008', 'C009', 'C010', 'C017')
         UNION ALL
         SELECT NULL,'合计','炼钢','A',-1 FROM DUAL
         UNION ALL
         SELECT NULL,'合计','轧管','D',5  FROM DUAL
         UNION ALL
          SELECT NULL ,'本部热处理(炉)合计','热处理','F1',11 FROM DUAL
          UNION ALL
          SELECT NULL,'本部热处理(探伤)合计','热处理','F2',35 FROM DUAL
         UNION ALL
          SELECT NULL,'元通热处理(炉)合计','热处理','F1',17 FROM DUAL
          UNION ALL
          SELECT NULL,'元通热处理(探伤)合计','热处理','F2',43 FROM DUAL
           UNION ALL
          SELECT NULL,'深加工热处理(炉)合计','热处理','F1',23 FROM DUAL
          UNION ALL
          SELECT NULL,'深加工热处理(探伤)合计','热处理','F2',48 FROM DUAL
         UNION ALL
          SELECT NULL,'管加工热处理(炉)合计','热处理','F1',24 FROM DUAL
          UNION ALL
          SELECT NULL,'管加工热处理(探伤)合计','热处理','F2',49 FROM DUAL
         UNION ALL
         SELECT * FROM T01
         UNION ALL
         SELECT 'G1','本部加工线合计','加工','G1',67 FROM DUAL
         UNION ALL
         SELECT 'G2','元通加工线合计','加工','G2',74 FROM DUAL
         UNION ALL
         SELECT 'G3','深加工加工线合计','加工','G3',83 FROM DUAL
         UNION ALL
         SELECT NULL,'管加工加工线合计','加工','G',100 FROM DUAL
         )ta,
         (
          SELECT NULL ZCNB,NULL ZCWB,NULL YCNB,NULL YCWB,NULL TJTIMETOTAL,NULL TIMETOTAL,NULL YXNB,NULL YXZH,NULL DAYZYL,
                  NULL ZCNBDAY,NULL ZCWBDAY,NULL YCNBDAY,NULL YCWBDAY,NULL TJTIMETOTALDAY,NULL TIMETOTALDAY,NULL YXNBDAY,NULL YXZHDAY,NULL DAYZYLDAY
          FROM DUAL
         )tb
      ),
/**********************************炼钢时间范围查询**************************************/
T10 AS
       (SELECT SUM(TJTIME) AS TJTIME, PLINENAME, TJREASON
          FROM (SELECT T10.CONTROL_ID,
                       T10.STOP_REASON,
                       T10.LOGS_BEG,
                       T10.LOGS_END,
                       (TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                       TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                       (SELECT BASENAME
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T10.STOP_TYPE) STOPTYPE,
                       (SELECT PROPERA
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T10.STOP_REASON) STOPREASON,
                       (SELECT PLINE_NAME
                          FROM COM_BASE_PLINE
                         WHERE PLINE_CODE = T10.EF_PLINE_CODE) PLINENAME,
                       CASE
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '内部原因' THEN
                          'ZCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '外部原因' THEN
                          'ZCWB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '内部原因' THEN
                          'YCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '外部原因' THEN
                          'YCWB'
                       END TJREASON
                  FROM STL_CONTROL_LOG T10
                 WHERE T10.PRO_TYPE = '2'
                  AND TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                       TO_DATE('#LASTDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
                   AND TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
                       TO_DATE('#BGEINDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
                   AND T10.STOP_TYPE IN ('300101', '300102')
                   AND T10.EF_PLINE_CODE IN ('C001', 'C003')
                   AND EXISTS (SELECT *
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T10.STOP_REASON
                           AND VALIDFLAG = '1')) TA
         GROUP BY TA.PLINENAME, TA.TJREASON),    
      T11 AS
       (SELECT 'A' PROCESS_CODE, 
               PLINENAME,
               MAX(DECODE(TJREASON, 'ZCNB', TJTIME, NULL)) AS ZCNB,
               MAX(DECODE(TJREASON, 'ZCWB', TJTIME, NULL)) AS ZCWB,
               MAX(DECODE(TJREASON, 'YCNB', TJTIME, NULL)) AS YCNB,
               MAX(DECODE(TJREASON, 'YCWB', TJTIME, NULL)) AS YCWB,
               SUM(TJTIME) TJTIMETOTAL,
               24 * 60 * #DAYS# TIMETOTAL
          FROM T10
         GROUP BY PLINENAME),
/**********************************炼钢日范围查询**************************************/  
      T12 AS
       (SELECT SUM(TJTIME) AS TJTIME, PLINENAME, TJREASON
          FROM (SELECT T10.CONTROL_ID,
                       T10.STOP_REASON,
                       T10.LOGS_BEG,
                       T10.LOGS_END,
                       (TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                       TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                       (SELECT BASENAME
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T10.STOP_TYPE) STOPTYPE,
                       (SELECT PROPERA
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T10.STOP_REASON) STOPREASON,
                       (SELECT PLINE_NAME
                          FROM COM_BASE_PLINE
                         WHERE PLINE_CODE = T10.EF_PLINE_CODE) PLINENAME,
                       CASE
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '内部原因' THEN
                          'ZCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '外部原因' THEN
                          'ZCWB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '内部原因' THEN
                          'YCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '外部原因' THEN
                          'YCWB'
                       END TJREASON
                  FROM STL_CONTROL_LOG T10
                 WHERE T10.PRO_TYPE = '2'
                  AND TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                       TO_DATE('#ENDDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
                   AND TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
                       TO_DATE('#BGEINDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
                   AND T10.STOP_TYPE IN ('300101', '300102')
                   AND T10.EF_PLINE_CODE IN ('C001', 'C003')
                   AND EXISTS (SELECT *
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T10.STOP_REASON
                           AND VALIDFLAG = '1')) TA
         GROUP BY TA.PLINENAME, TA.TJREASON),
      T13 AS
       (SELECT 'A' PROCESS_CODE,
               PLINENAME ,
               MAX(DECODE(TJREASON, 'ZCNB', TJTIME, NULL)) AS ZCNBDAY,
               MAX(DECODE(TJREASON, 'ZCWB', TJTIME, NULL)) AS ZCWBDAY,
               MAX(DECODE(TJREASON, 'YCNB', TJTIME, NULL)) AS YCNBDAY,
               MAX(DECODE(TJREASON, 'YCWB', TJTIME, NULL)) AS YCWBDAY,
               SUM(TJTIME) TJTIMETOTALDAY,
               24 * 60 TIMETOTALDAY
          FROM T12
         GROUP BY PLINENAME),
     /********炼钢累计数值*******/
     T14 AS
     (
      SELECT * FROM T11
      UNION ALL
      SELECT 'A' PROCESS_CODE ,'合计' PLINENAME,SUM(ZCNB) ZCNB,SUM(ZCWB)ZCWB,SUM(YCNB) YCNB,SUM(YCWB) YCWB,
      SUM(TJTIMETOTAL) TJTIMETOTAL,SUM(TIMETOTAL) TIMETOTAL FROM T11
     ),
     /********炼钢日数值*******/
     T15 AS
     (
      SELECT * FROM T13
      UNION ALL
      SELECT  'A' PROCESS_CODE,'合计' PLINENAME,SUM(ZCNBDAY) ZCNBDAY,SUM(ZCWBDAY)ZCWBDAY,SUM(YCNBDAY) YCNBDAY,SUM(YCWBDAY) YCWBDAY,
      SUM(TJTIMETOTALDAY) TJTIMETOTALDAY,SUM(TIMETOTALDAY) TIMETOTALDAY FROM T13
     ),
     /**********************************轧管时间范围查询**************************************/       
       T AS
       (SELECT SUM(TJTIME) AS TJTIME, PLINENAME, TJREASON
          FROM (SELECT T.CONTROL_ID,
                       T.STOP_REASON,
                       T.LOGS_BEG,
                       T.LOGS_END,
                       (TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                       TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                       (SELECT BASENAME
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_TYPE) STOPTYPE,
                       (SELECT PROPERA
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON) STOPREASON,
                       (SELECT PLINE_NAME
                          FROM COM_BASE_PLINE
                         WHERE PLINE_CODE = T.PLINE_CODE) PLINENAME,
                       CASE
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'ZCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'ZCWB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'YCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'YCWB'
                       END TJREASON
                  FROM MIL_CONTROL_LOG T
                 WHERE T.PRO_TYPE = '2'
                   AND TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                        TO_DATE('#LASTDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
                   AND TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
                        TO_DATE('#BGEINDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
                   AND T.STOP_TYPE IN ('500601', '500602')
                   AND T.PLINE_CODE IN ('C008', 'C009', 'C010', 'C017')
                   AND EXISTS (SELECT *
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON
                           AND VALIDFLAG = '1')) TA
         GROUP BY TA.PLINENAME, TA.TJREASON),      
      T1 AS
       (SELECT 'D' PROCESS_CODE, 
               PLINENAME,
               MAX(DECODE(TJREASON, 'ZCNB', TJTIME, NULL)) AS ZCNB,
               MAX(DECODE(TJREASON, 'ZCWB', TJTIME, NULL)) AS ZCWB,
               MAX(DECODE(TJREASON, 'YCNB', TJTIME, NULL)) AS YCNB,
               MAX(DECODE(TJREASON, 'YCWB', TJTIME, NULL)) AS YCWB,
               SUM(TJTIME) TJTIMETOTAL,
               24 * 60 * #DAYS# TIMETOTAL
          FROM T
         GROUP BY PLINENAME),
/**********************************轧管日范围查询**************************************/   
      T2 AS
       (SELECT SUM(TJTIME) AS TJTIME, PLINENAME, TJREASON
          FROM (SELECT T.CONTROL_ID,
                       T.STOP_REASON,
                       T.LOGS_BEG,
                       T.LOGS_END,
                       (TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                       TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                       (SELECT BASENAME
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_TYPE) STOPTYPE,
                       (SELECT PROPERA
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON) STOPREASON,
                       (SELECT PLINE_NAME
                          FROM COM_BASE_PLINE
                         WHERE PLINE_CODE = T.PLINE_CODE) PLINENAME,
                       CASE
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'ZCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'ZCWB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'YCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'YCWB'
                       END TJREASON
                  FROM MIL_CONTROL_LOG T
                 WHERE T.PRO_TYPE = '2'
                   AND TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                       TO_DATE('#ENDDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
                   AND TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
                       TO_DATE('#BGEINDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
                   AND T.STOP_TYPE IN ('500601', '500602')
                   AND T.PLINE_CODE IN ('C008', 'C009', 'C010', 'C017')
                   AND EXISTS (SELECT *
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON
                           AND VALIDFLAG = '1')) TA
         GROUP BY TA.PLINENAME, TA.TJREASON),
      T3 AS
       (SELECT  'D' PROCESS_CODE, 
               PLINENAME ,
               MAX(DECODE(TJREASON, 'ZCNB', TJTIME, NULL)) AS ZCNBDAY,
               MAX(DECODE(TJREASON, 'ZCWB', TJTIME, NULL)) AS ZCWBDAY,
               MAX(DECODE(TJREASON, 'YCNB', TJTIME, NULL)) AS YCNBDAY,
               MAX(DECODE(TJREASON, 'YCWB', TJTIME, NULL)) AS YCWBDAY,
               SUM(TJTIME) TJTIMETOTALDAY,
               24 * 60 TIMETOTALDAY
          FROM T2
         GROUP BY PLINENAME),
     /********轧管累计数值*******/
     T4 AS
     (
      SELECT * FROM T1
      UNION ALL
      SELECT 'D' PROCESS_CODE ,'合计' PLINENAME,SUM(ZCNB) ZCNB,SUM(ZCWB)ZCWB,SUM(YCNB) YCNB,SUM(YCWB) YCWB,
      SUM(TJTIMETOTAL) TJTIMETOTAL,SUM(TIMETOTAL) TIMETOTAL FROM T1
     ),
     /********轧管日数值*******/
     T5 AS
     (
      SELECT * FROM T3
      UNION ALL
      SELECT  'D' PROCESS_CODE,'合计' PLINENAME,SUM(ZCNBDAY) ZCNBDAY,SUM(ZCWBDAY)ZCWBDAY,SUM(YCNBDAY) YCNBDAY,SUM(YCWBDAY) YCWBDAY,
      SUM(TJTIMETOTALDAY) TJTIMETOTALDAY,SUM(TIMETOTALDAY) TIMETOTALDAY FROM T3
     ),
		 /**********************************热处理时间范围查询**************************************/       
       T30 AS
       (SELECT SUM(TJTIME) AS TJTIME, PLINENAME || DECODE(STATION,'0','(热处理)','1','(探伤)') PLINENAME, TJREASON,PLINE_CODE,STATION
          FROM (SELECT T.CONTROL_ID,
                       T.STOP_REASON,
                       T.LOGS_BEG,
                       T.LOGS_END,
                       (TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                       TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                       (SELECT BASENAME
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_TYPE) STOPTYPE,
                       (SELECT PROPERA
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON) STOPREASON,
                       (SELECT PLINE_NAME
                          FROM COM_BASE_PLINE
                         WHERE PLINE_CODE = T.PLINE_CODE) PLINENAME,
                       CASE
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'ZCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'ZCWB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'YCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'YCWB'
                       END TJREASON,
                       PLINE_CODE,
                       STATION
                  FROM (SELECT T.CONTROL_ID,
                         T.LOGS_BEG,
                         T.LOGS_END,
                         T.PLINE_CODE,
                         T.STOP_TYPE,
                         T.STOP_REASON,
                         T.STOP_SMALL,
                         T.STATION
                    FROM HTT_CONTROL_LOG T
                                        WHERE T.PRO_TYPE = '2'
                                        AND TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                        TO_DATE('#LASTDATE#' || '2100', 'yyyy-mm-dd hh24:mi:ss')
                   AND TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
                        TO_DATE('#BGEINDATE#' || '2100', 'yyyy-mm-dd hh24:mi:ss')
                   AND T.PLINE_CODE IN ('C022','C023','C024','C025','C026','C054','C055','C048')
                   AND T.STATION IN ('0','1')
                   UNION ALL
                   SELECT T.CONTROL_ID,
                         T.LOGS_BEG,
                         T.LOGS_END,
                         T.PLINE_CODE,
                         T.STOP_TYPE,
                         T.STOP_REASON,
                         T.STOP_SMALL,
                         T.STATION
                    FROM HTT_CONTROL_LOG T
                                        WHERE T.PRO_TYPE = '2'
                                        AND TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                        TO_DATE('#LASTDATE#' || '2000', 'yyyy-mm-dd hh24:mi:ss')
                   AND TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
                        TO_DATE('#BGEINDATE#' || '2000', 'yyyy-mm-dd hh24:mi:ss')
                   AND T.PLINE_CODE IN ('C049','C050')
                   AND T.STATION IN ('0','1')
                   ) T
                 WHERE 1=1
                                      AND EXISTS (SELECT *
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON
                           AND VALIDFLAG = '1')) TA
         GROUP BY TA.PLINENAME,TA.PLINE_CODE,TA.TJREASON,TA.STATION), 
	  T31 AS
       (SELECT 
                             CASE WHEN PLINE_CODE IN ('C022','C023','C024','C025','C026') THEN 'F1'
                     WHEN PLINE_CODE IN ('C049','C050') THEN 'F2'
                     WHEN PLINE_CODE IN ('C048','C054','C055') THEN 'F3'  
                     ELSE NULL END PROCESS_CODE, 
               PLINENAME,
               MAX(DECODE(TJREASON, 'ZCNB', TJTIME, NULL)) AS ZCNB,
               MAX(DECODE(TJREASON, 'ZCWB', TJTIME, NULL)) AS ZCWB,
               MAX(DECODE(TJREASON, 'YCNB', TJTIME, NULL)) AS YCNB,
               MAX(DECODE(TJREASON, 'YCWB', TJTIME, NULL)) AS YCWB,
               SUM(TJTIME) TJTIMETOTAL,
               24 * 60 *  #DAYS# TIMETOTAL,
               STATION,
                CASE WHEN PLINE_CODE='C022' AND STATION ='0' THEN 6
             WHEN PLINE_CODE='C023' AND STATION ='0' THEN 7
             WHEN PLINE_CODE='C024' AND STATION ='0' THEN 8
             WHEN PLINE_CODE='C025' AND STATION ='0' THEN 9
             WHEN PLINE_CODE='C026' AND STATION ='0' THEN 10
             WHEN PLINE_CODE='C049' AND STATION ='0' THEN 15
             WHEN PLINE_CODE='C050' AND STATION ='0' THEN 16
             WHEN PLINE_CODE='C054' AND STATION ='0' THEN 20
             WHEN PLINE_CODE='C055' AND STATION ='0' THEN 21
             WHEN PLINE_CODE='C048' AND STATION ='0' THEN 22
             WHEN PLINE_CODE='C022' AND STATION ='1' THEN 30
             WHEN PLINE_CODE='C023' AND STATION ='1' THEN 31
             WHEN PLINE_CODE='C024' AND STATION ='1' THEN 32
             WHEN PLINE_CODE='C025' AND STATION ='1' THEN 33
             WHEN PLINE_CODE='C026' AND STATION ='1' THEN 34
             WHEN PLINE_CODE='C049' AND STATION ='1' THEN 41
             WHEN PLINE_CODE='C050' AND STATION ='1' THEN 42
             WHEN PLINE_CODE='C054' AND STATION ='1' THEN 45
             WHEN PLINE_CODE='C055' AND STATION ='1' THEN 46
             WHEN PLINE_CODE='C048' AND STATION ='1' THEN 47
          ELSE NULL END PLINEORDER
          FROM T30
         GROUP BY PLINENAME,PLINE_CODE,STATION),
	   /**********************************热处理日范围查询**************************************/   
       T32 AS
       (SELECT SUM(TJTIME) AS TJTIME, PLINENAME || DECODE(STATION,'0','(热处理)','1','(探伤)') PLINENAME, TJREASON,PLINE_CODE,STATION
          FROM (SELECT T.CONTROL_ID,
                       T.STOP_REASON,
                       T.LOGS_BEG,
                       T.LOGS_END,
                       (TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                       TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                       (SELECT BASENAME
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_TYPE) STOPTYPE,
                       (SELECT PROPERA
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON) STOPREASON,
                       (SELECT PLINE_NAME
                          FROM COM_BASE_PLINE
                         WHERE PLINE_CODE = T.PLINE_CODE) PLINENAME,
                       CASE
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'ZCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'ZCWB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'YCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'YCWB'
                       END TJREASON,
                       PLINE_CODE,
                       STATION
                  FROM (SELECT T.CONTROL_ID,
                         T.LOGS_BEG,
                         T.LOGS_END,
                         T.PLINE_CODE,
                         T.STOP_TYPE,
                         T.STOP_REASON,
                         T.STOP_SMALL,
                         T.STATION
                    FROM HTT_CONTROL_LOG T
                                        WHERE T.PRO_TYPE = '2'
                                        AND TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                       TO_DATE('#ENDDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
                   AND TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
                        TO_DATE('#BGEINDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
                   AND T.PLINE_CODE IN ('C022','C023','C024','C025','C026','C054','C055','C048')
                   AND T.STATION IN ('0','1')
                   UNION ALL
                   SELECT T.CONTROL_ID,
                         T.LOGS_BEG,
                         T.LOGS_END,
                         T.PLINE_CODE,
                         T.STOP_TYPE,
                         T.STOP_REASON,
                         T.STOP_SMALL,
                         T.STATION
                    FROM HTT_CONTROL_LOG T
                                        WHERE T.PRO_TYPE = '2'
                                        AND TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                        TO_DATE('#ENDDATE#'||'2000', 'yyyy-mm-dd hh24:mi:ss')
                   AND TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
                        TO_DATE('#BGEINDATE#'||'2000', 'yyyy-mm-dd hh24:mi:ss')
                   AND T.PLINE_CODE IN ('C049','C050')
                   AND T.STATION IN ('0','1')
                   ) T
                 WHERE 1=1
                                      AND EXISTS (SELECT *
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON
                           AND VALIDFLAG = '1')) TA
         GROUP BY TA.PLINENAME,TA.PLINE_CODE,TA.TJREASON,TA.STATION),   
       T33 AS
       (SELECT 
                             CASE WHEN PLINE_CODE IN ('C022','C023','C024','C025','C026') THEN 'F1'
                     WHEN PLINE_CODE IN ('C049','C050') THEN 'F2'
                     WHEN PLINE_CODE IN ('C048','C054','C055') THEN 'F3'  
                     ELSE NULL END PROCESS_CODE, 
               PLINENAME,
               MAX(DECODE(TJREASON, 'ZCNB', TJTIME, NULL)) AS ZCNBDAY,
               MAX(DECODE(TJREASON, 'ZCWB', TJTIME, NULL)) AS ZCWBDAY,
               MAX(DECODE(TJREASON, 'YCNB', TJTIME, NULL)) AS YCNBDAY,
               MAX(DECODE(TJREASON, 'YCWB', TJTIME, NULL)) AS YCWBDAY,
               SUM(TJTIME) TJTIMETOTALDAY,
               24 * 60  TIMETOTALDAY,
               STATION,
                 CASE WHEN PLINE_CODE='C022' AND STATION ='0' THEN 6
             WHEN PLINE_CODE='C023' AND STATION ='0' THEN 7
             WHEN PLINE_CODE='C024' AND STATION ='0' THEN 8
             WHEN PLINE_CODE='C025' AND STATION ='0' THEN 9
             WHEN PLINE_CODE='C026' AND STATION ='0' THEN 10
             WHEN PLINE_CODE='C049' AND STATION ='0' THEN 15
             WHEN PLINE_CODE='C050' AND STATION ='0' THEN 16
             WHEN PLINE_CODE='C054' AND STATION ='0' THEN 20
             WHEN PLINE_CODE='C055' AND STATION ='0' THEN 21
             WHEN PLINE_CODE='C048' AND STATION ='0' THEN 22
             WHEN PLINE_CODE='C022' AND STATION ='1' THEN 30
             WHEN PLINE_CODE='C023' AND STATION ='1' THEN 31
             WHEN PLINE_CODE='C024' AND STATION ='1' THEN 32
             WHEN PLINE_CODE='C025' AND STATION ='1' THEN 33
             WHEN PLINE_CODE='C026' AND STATION ='1' THEN 34
             WHEN PLINE_CODE='C049' AND STATION ='1' THEN 41
             WHEN PLINE_CODE='C050' AND STATION ='1' THEN 42
             WHEN PLINE_CODE='C054' AND STATION ='1' THEN 45
             WHEN PLINE_CODE='C055' AND STATION ='1' THEN 46
             WHEN PLINE_CODE='C048' AND STATION ='1' THEN 47
          ELSE NULL END PLINEORDER
          FROM T32
         GROUP BY PLINENAME,PLINE_CODE,STATION),
              /********热处理累计数值*******/
     T34 AS
     (
      SELECT * FROM T31
      UNION ALL
      SELECT PROCESS_CODE ,DECODE(station,'0','热处理','1','探伤') || '小计' PLINENAME,SUM(ZCNB) ZCNB,SUM(ZCWB)ZCWB,SUM(YCNB) YCNB,SUM(YCWB) YCWB,
      SUM(TJTIMETOTAL) TJTIMETOTAL,SUM(TIMETOTAL) TIMETOTAL,STATION,
      CASE WHEN PROCESS_CODE='F1' AND STATION ='0' THEN 11 
           WHEN PROCESS_CODE='F2' AND STATION ='0' THEN 17 
           WHEN PROCESS_CODE='F3' AND STATION ='0' THEN 23 
           WHEN PROCESS_CODE='F1' AND STATION ='1' THEN 35 
           WHEN PROCESS_CODE='F2' AND STATION ='1' THEN 43 
           WHEN PROCESS_CODE='F3' AND STATION ='1' THEN 48 
           END PLINEORDER 
       FROM T31 GROUP BY PROCESS_CODE,STATION
     UNION ALL
      SELECT '热处理' PROCESS_CODE ,DECODE(station,'0','管加工热处理(炉)','1','管加工热处理(探伤)') || '合计' PLINENAME,SUM(ZCNB) ZCNB,SUM(ZCWB)ZCWB,SUM(YCNB) YCNB,SUM(YCWB) YCWB,
      SUM(TJTIMETOTAL) TJTIMETOTAL,SUM(TIMETOTAL) TIMETOTAL,STATION,
      CASE WHEN  STATION ='0' THEN 24 
           WHEN STATION ='1' THEN 49
           END PLINEORDER 
       FROM T31 GROUP BY  STATION
     ),
     /********热处理日数值*******/
     T35 AS
     (
      SELECT * FROM T33
      UNION ALL
      SELECT PROCESS_CODE ,DECODE(station,'0','管加工热处理(炉)','1','管加工热处理(探伤)') || '合计' PLINENAME,SUM(ZCNBDAY) ZCNBDAY,SUM(ZCWBDAY)ZCWBDAY,SUM(YCNBDAY) YCNBDAY,SUM(YCWBDAY) YCWBDAY,
      SUM(TJTIMETOTALDAY) TJTIMETOTALDAY,SUM(TIMETOTALDAY) TIMETOTALDAY,STATION,
      CASE WHEN PROCESS_CODE='F1' AND STATION ='0' THEN 11 
           WHEN PROCESS_CODE='F2' AND STATION ='0' THEN 17 
           WHEN PROCESS_CODE='F3' AND STATION ='0' THEN 23 
           WHEN PROCESS_CODE='F1' AND STATION ='1' THEN 35 
           WHEN PROCESS_CODE='F2' AND STATION ='1' THEN 43 
           WHEN PROCESS_CODE='F3' AND STATION ='1' THEN 48 
           END PLINEORDER  FROM T33 GROUP BY PROCESS_CODE,STATION
      UNION ALL
      SELECT '热处理' PROCESS_CODE ,DECODE(station,'0','管加工热处理(炉)','1','管加工热处理(探伤)') || '合计' PLINENAME,SUM(ZCNBDAY) ZCNBDAY,SUM(ZCWBDAY)ZCWBDAY,SUM(YCNBDAY) YCNBDAY,SUM(YCWBDAY) YCWBDAY,
      SUM(TJTIMETOTALDAY) TJTIMETOTALDAY,SUM(TIMETOTALDAY) TIMETOTALDAY,STATION,
      CASE WHEN  STATION ='0' THEN 24 
           WHEN STATION ='1' THEN 49
           END PLINEORDER 
       FROM T33 GROUP BY  STATION
     ),
	   /**********************************加工时间范围查询**************************************/       
       T40 AS
       (SELECT SUM(TJTIME) AS TJTIME, TJREASON, PLINE_CODE
          FROM (SELECT T.CONTROL_ID,
                       T.STOP_REASON,
                       T.LOGS_BEG,
                       T.LOGS_END,
                       (TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                       TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                       (SELECT BASENAME
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_TYPE) STOPTYPE,
                       (SELECT PROPERA
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON) STOPREASON,
                       (SELECT PLINE_NAME
                          FROM COM_BASE_PLINE
                         WHERE PLINE_CODE = T.PLINE_CODE) PLINENAME,
                       CASE
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'ZCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'ZCWB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'YCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'YCWB'
                       END TJREASON,
                       PLINE_CODE
                  FROM (SELECT T.CONTROL_ID,
                         T.LOGS_BEG,
                         T.LOGS_END,
                         T.PLINE_CODE,
                         T.STOP_TYPE,
                         T.STOP_REASON,
                         T.STOP_SMALL
                    FROM HTT_CONTROL_LOG T
                                        WHERE T.PRO_TYPE = '2'
                                        AND TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                         TO_DATE('#LASTDATE#' || '2100', 'yyyy-mm-dd hh24:mi:ss')
                   AND TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
                        TO_DATE('#BGEINDATE#' || '2100', 'yyyy-mm-dd hh24:mi:ss')
                   AND T.PLINE_CODE IN ('C028','C029','C030','C031','C032','C033','C034','C035','C036','C037','C053','C056',
                                          'C039','C051','C038','C057',
                                          'C052','C078','C058'
                                        )

                   ) T
                 WHERE 1=1
                                      AND EXISTS (SELECT *
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON
                           AND VALIDFLAG = '1')) TA
         GROUP BY TA.TJREASON,TA.PLINE_CODE) ,  
       T41 AS
       (SELECT
                CASE WHEN
                     PLINE_CODE IN ('C028','C029','C030','C031','C032','C033','C034','C035','C036','C037','C053','C056') THEN 'G1' 
                     WHEN
                     PLINE_CODE IN ( 'C039','C051','C038','C057') THEN 'G2' 
                     WHEN
                     PLINE_CODE IN ( 'C052','C078','C058') THEN 'G3' 
                     ELSE NULL END PROCESS_CODE,  
               PLINE_CODE,
               MAX(DECODE(TJREASON, 'ZCNB', TJTIME, NULL)) AS ZCNB,
               MAX(DECODE(TJREASON, 'ZCWB', TJTIME, NULL)) AS ZCWB,
               MAX(DECODE(TJREASON, 'YCNB', TJTIME, NULL)) AS YCNB,
               MAX(DECODE(TJREASON, 'YCWB', TJTIME, NULL)) AS YCWB,
               SUM(TJTIME) TJTIMETOTAL,
               24*60*7 TIMETOTAL,
               CASE WHEN PLINE_CODE='C028'  THEN 55
             WHEN PLINE_CODE='C029'  THEN 56
             WHEN PLINE_CODE='C030'  THEN 57
             WHEN PLINE_CODE='C031'  THEN 58
             WHEN PLINE_CODE='C032'  THEN 59
             WHEN PLINE_CODE='C033'  THEN 60
             WHEN PLINE_CODE='C034'  THEN 61
             WHEN PLINE_CODE='C035'  THEN 62
             WHEN PLINE_CODE='C036'  THEN 63
             WHEN PLINE_CODE='C037'  THEN 64
             WHEN PLINE_CODE='C053'  THEN 65
             WHEN PLINE_CODE='C056'  THEN 66
             WHEN PLINE_CODE='C039'  THEN 70
             WHEN PLINE_CODE='C051'  THEN 71
             WHEN PLINE_CODE='C038'  THEN 72
             WHEN PLINE_CODE='C057'  THEN 73
             WHEN PLINE_CODE='C052'  THEN 80
             WHEN PLINE_CODE='C078'  THEN 81
             WHEN PLINE_CODE='C058'  THEN 82
          ELSE NULL END PLINEORDER
          FROM T40
         GROUP BY PLINE_CODE),
	  /**********************************加工线日范围查询**************************************/ 
       T42 AS
       (SELECT SUM(TJTIME) AS TJTIME, TJREASON, PLINE_CODE
          FROM (SELECT T.CONTROL_ID,
                       T.STOP_REASON,
                       T.LOGS_BEG,
                       T.LOGS_END,
                       (TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                       TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                       (SELECT BASENAME
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_TYPE) STOPTYPE,
                       (SELECT PROPERA
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON) STOPREASON,
                       (SELECT PLINE_NAME
                          FROM COM_BASE_PLINE
                         WHERE PLINE_CODE = T.PLINE_CODE) PLINENAME,
                       CASE
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'ZCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'ZCWB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'YCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'YCWB'
                       END TJREASON,
                       PLINE_CODE
                  FROM (SELECT T.CONTROL_ID,
                         T.LOGS_BEG,
                         T.LOGS_END,
                         T.PLINE_CODE,
                         T.STOP_TYPE,
                         T.STOP_REASON,
                         T.STOP_SMALL
                    FROM HTT_CONTROL_LOG T
                                        WHERE T.PRO_TYPE = '2'
                                        AND TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                         TO_DATE('#ENDDATE#' || '2100', 'yyyy-mm-dd hh24:mi:ss')
                   AND TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
                        TO_DATE('#BGEINDATE#' || '2100', 'yyyy-mm-dd hh24:mi:ss')
                   AND T.PLINE_CODE IN ('C028','C029','C030','C031','C032','C033','C034','C035','C036','C037','C053','C056',
                                          'C039','C051','C038','C057',
                                          'C052','C078','C058'
                                        )

                   ) T
                 WHERE 1=1
                                      AND EXISTS (SELECT *
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON
                           AND VALIDFLAG = '1')) TA
         GROUP BY TA.TJREASON,TA.PLINE_CODE),   
      T43 AS
      (SELECT
                CASE WHEN
                     PLINE_CODE IN ('C028','C029','C030','C031','C032','C033','C034','C035','C036','C037','C053','C056') THEN 'G1' 
                     WHEN
                     PLINE_CODE IN ( 'C039','C051','C038','C057') THEN 'G2' 
                     WHEN
                     PLINE_CODE IN ( 'C052','C078','C058') THEN 'G3' 
                     ELSE NULL END PROCESS_CODE,  
               PLINE_CODE,
               MAX(DECODE(TJREASON, 'ZCNB', TJTIME, NULL)) AS ZCNBDAY,
               MAX(DECODE(TJREASON, 'ZCWB', TJTIME, NULL)) AS ZCWBDAY,
               MAX(DECODE(TJREASON, 'YCNB', TJTIME, NULL)) AS YCNBDAY,
               MAX(DECODE(TJREASON, 'YCWB', TJTIME, NULL)) AS YCWBDAY,
               SUM(TJTIME) TJTIMETOTALDAY,
               24*60 TIMETOTALDAY,
               CASE WHEN PLINE_CODE='C028'  THEN 55
             WHEN PLINE_CODE='C029'  THEN 56
             WHEN PLINE_CODE='C030'  THEN 57
             WHEN PLINE_CODE='C031'  THEN 58
             WHEN PLINE_CODE='C032'  THEN 59
             WHEN PLINE_CODE='C033'  THEN 60
             WHEN PLINE_CODE='C034'  THEN 61
             WHEN PLINE_CODE='C035'  THEN 62
             WHEN PLINE_CODE='C036'  THEN 63
             WHEN PLINE_CODE='C037'  THEN 64
             WHEN PLINE_CODE='C053'  THEN 65
             WHEN PLINE_CODE='C056'  THEN 66
             WHEN PLINE_CODE='C039'  THEN 70
             WHEN PLINE_CODE='C051'  THEN 71
             WHEN PLINE_CODE='C038'  THEN 72
             WHEN PLINE_CODE='C057'  THEN 73
             WHEN PLINE_CODE='C052'  THEN 80
             WHEN PLINE_CODE='C078'  THEN 81
             WHEN PLINE_CODE='C058'  THEN 82
          ELSE NULL END PLINEORDER
          FROM T42
         GROUP BY PLINE_CODE),
                /********加工线累计数值*******/
     T44 AS
     (
      SELECT * FROM T41
      UNION ALL
      SELECT PROCESS_CODE ,DECODE(PROCESS_CODE,'G1','本部加工线','G2','元通加工线','G3','深加工加工线') || '合计' PLINENAME,SUM(ZCNB) ZCNB,SUM(ZCWB)ZCWB,SUM(YCNB) YCNB,SUM(YCWB) YCWB,
      SUM(TJTIMETOTAL) TJTIMETOTAL,SUM(TIMETOTAL) TIMETOTAL,
      CASE WHEN PROCESS_CODE='G1'  THEN 67 
           WHEN PROCESS_CODE='G2'  THEN 74 
           WHEN PROCESS_CODE='G3'  THEN 83 
           END PLINEORDER 
       FROM T41 GROUP BY PROCESS_CODE
     UNION ALL
      SELECT 'G' PROCESS_CODE , 
      '管加工加工线合计' PLINENAME,
      SUM(ZCNB) ZCNB,SUM(ZCWB)ZCWB,SUM(YCNB) YCNB,SUM(YCWB) YCWB,
      SUM(TJTIMETOTAL) TJTIMETOTAL,SUM(TIMETOTAL) TIMETOTAL,
      100 PLINEORDER 
       FROM T41 
     ),
     /********加工线日数值*******/
     T45 AS
     (
       SELECT * FROM T43
      UNION ALL
      SELECT PROCESS_CODE ,DECODE(PROCESS_CODE,'G1','本部加工线','G2','元通加工线','G3','深加工加工线') || '合计' PLINENAME,SUM(ZCNBDAY) ZCNBDAY,SUM(ZCWBDAY) ZCWBDAY,SUM(YCNBDAY) YCNBDAY,SUM(YCWBDAY) YCWBDAY,
      SUM(TJTIMETOTALDAY) TJTIMETOTALDAY,SUM(TIMETOTALDAY) TIMETOTALDAY,
      CASE WHEN PROCESS_CODE='G1'  THEN 67 
           WHEN PROCESS_CODE='G2'  THEN 74 
           WHEN PROCESS_CODE='G3'  THEN 83 
           END PLINEORDER 
       FROM T43 GROUP BY PROCESS_CODE
     UNION ALL
      SELECT 'G' PROCESS_CODE , 
      '管加工加工线合计' PLINENAME,
      SUM(ZCNBDAY) ZCNB,SUM(ZCWBDAY)ZCWB,SUM(YCNBDAY) YCNB,SUM(YCWBDAY) YCWB,
      SUM(TJTIMETOTALDAY) TJTIMETOTAL,SUM(TIMETOTALDAY) TIMETOTAL,
      100 PLINEORDER 
       FROM T43
     ),
     T99 AS
     (
     SELECT T00.PLINEORDER,T00.PROCESS_DESC,T00.PLINE_NAME,T00.PLINE_CODE,
     DECODE(T00.PROCESS_CODE,'A',NVL(T14.ZCNB,T00.ZCNB),
                              'D',NVL(T4.ZCNB,T00.ZCNB),
                              'F1',NVL(T34.ZCNB,T00.ZCNB),
                              'F2',NVL(T34.ZCNB,T00.ZCNB),
                              'F3',NVL(T34.ZCNB,T00.ZCNB),
                              'G1',NVL(T44.ZCNB,T00.ZCNB),
                              'G2',NVL(T44.ZCNB,T00.ZCNB),
                              'G3',NVL(T44.ZCNB,T00.ZCNB),
                              'G',NVL(T44.ZCNB,T00.ZCNB),
                               T00.ZCNB) ZCNB,
     DECODE(T00.PROCESS_CODE,'A',NVL(T14.ZCWB,T00.ZCWB),
                              'D',NVL(T4.ZCWB,T00.ZCWB),
                               'F1',NVL(T34.ZCWB,T00.ZCWB),
                               'F2',NVL(T34.ZCWB,T00.ZCWB),
                               'F3',NVL(T34.ZCWB,T00.ZCWB),
                               'G1',NVL(T44.ZCWB,T00.ZCWB),
                              'G2',NVL(T44.ZCWB,T00.ZCWB),
                              'G3',NVL(T44.ZCWB,T00.ZCWB),
                               'G',NVL(T44.ZCWB,T00.ZCWB),
                              T00.ZCWB) ZCWB,
     DECODE(T00.PROCESS_CODE,'A',NVL(T14.YCNB,T00.YCNB),
                              'D',NVL(T4.YCNB,T00.YCNB),
                              'F1',NVL(T34.YCNB,T00.YCNB),
                              'F2',NVL(T34.YCNB,T00.YCNB),
                              'F3',NVL(T34.YCNB,T00.YCNB),
                             'G1',NVL(T44.YCNB,T00.YCNB),
                              'G2',NVL(T44.YCNB,T00.YCNB),
                              'G3',NVL(T44.YCNB,T00.YCNB),
                               'G',NVL(T44.YCNB,T00.YCNB),
                              T00.YCNB) YCNB,
     DECODE(T00.PROCESS_CODE,'A',NVL(T14.YCWB,T00.YCWB),
                              'D',NVL(T4.YCWB,T00.YCWB),
                              'F1',NVL(T34.YCWB,T00.YCWB),
                              'F2',NVL(T34.YCWB,T00.YCWB),
                              'F3',NVL(T34.YCWB,T00.YCWB),
                               'G1',NVL(T44.YCWB,T00.YCWB),
                              'G2',NVL(T44.YCWB,T00.YCWB),
                              'G3',NVL(T44.YCWB,T00.YCWB),
                               'G',NVL(T44.YCWB,T00.YCWB),
                              T00.YCWB) YCWB,
     DECODE(T00.PROCESS_CODE,'A',NVL(T14.TJTIMETOTAL,T00.TJTIMETOTAL),
                              'D',NVL(T4.TJTIMETOTAL,T00.TJTIMETOTAL),
                              'F1',NVL(T34.TJTIMETOTAL,T00.TJTIMETOTAL),
                              'F2',NVL(T34.TJTIMETOTAL,T00.TJTIMETOTAL),
                              'F3',NVL(T34.TJTIMETOTAL,T00.TJTIMETOTAL),
                              'G1',NVL(T44.TJTIMETOTAL,T00.TJTIMETOTAL),
                              'G2',NVL(T44.TJTIMETOTAL,T00.TJTIMETOTAL),
                              'G3',NVL(T44.TJTIMETOTAL,T00.TJTIMETOTAL),
                               'G',NVL(T44.TJTIMETOTAL,T00.TJTIMETOTAL),
                              T00.TJTIMETOTAL) TJTIMETOTAL,
                              T00.TIMETOTAL1 TIMETOTAL,
     YXNB,YXZH,DAYZYL,
     DECODE(T00.PROCESS_CODE,'A',NVL(T15.ZCNBDAY,T00.ZCNBDAY),
                              'D',NVL(T5.ZCNBDAY,T00.ZCNBDAY),
                              'F1',NVL(T35.ZCNBDAY,T00.ZCNBDAY),
                              'F2',NVL(T35.ZCNBDAY,T00.ZCNBDAY),
                              'F3',NVL(T35.ZCNBDAY,T00.ZCNBDAY),
                              'G1',NVL(T45.ZCNBDAY,T00.ZCNBDAY),
                              'G2',NVL(T45.ZCNBDAY,T00.ZCNBDAY),
                              'G3',NVL(T45.ZCNBDAY,T00.ZCNBDAY),
                               'G',NVL(T45.ZCNBDAY,T00.ZCNBDAY),
                              T00.ZCNBDAY) ZCNBDAY,
     DECODE(T00.PROCESS_CODE,'A',NVL(T15.ZCWBDAY,T00.ZCWBDAY),
                              'D',NVL(T5.ZCWBDAY,T00.ZCWBDAY),
                              'F1',NVL(T35.ZCWBDAY,T00.ZCWBDAY),
                              'F2',NVL(T35.ZCWBDAY,T00.ZCWBDAY),
                              'F3',NVL(T35.ZCWBDAY,T00.ZCWBDAY),
                              'G1',NVL(T45.ZCWBDAY,T00.ZCWBDAY),
                              'G2',NVL(T45.ZCWBDAY,T00.ZCWBDAY),
                              'G3',NVL(T45.ZCWBDAY,T00.ZCWBDAY),
                               'G',NVL(T45.ZCWBDAY,T00.ZCWBDAY),
                              T00.ZCWBDAY) ZCWBDAY,
     DECODE(T00.PROCESS_CODE,'A',NVL(T15.YCNBDAY,T00.YCNBDAY),
                              'D',NVL(T5.YCNBDAY,T00.YCNBDAY),
                              'F1',NVL(T35.YCNBDAY,T00.YCNBDAY),
                              'F2',NVL(T35.YCNBDAY,T00.YCNBDAY),
                              'F3',NVL(T35.YCNBDAY,T00.YCNBDAY),
                               'G1',NVL(T45.YCNBDAY,T00.YCNBDAY),
                              'G2',NVL(T45.YCNBDAY,T00.YCNBDAY),
                              'G3',NVL(T45.YCNBDAY,T00.YCNBDAY),
                               'G',NVL(T45.YCNBDAY,T00.YCNBDAY),
                              T00.YCNBDAY) YCNBDAY,
     DECODE(T00.PROCESS_CODE,'A',NVL(T15.YCWBDAY,T00.YCWBDAY),
                              'D',NVL(T5.YCWBDAY,T00.YCWBDAY),
                              'F1',NVL(T35.YCWBDAY,T00.YCWBDAY),
                              'F2',NVL(T35.YCWBDAY,T00.YCWBDAY),
                              'F3',NVL(T35.YCWBDAY,T00.YCWBDAY),
                              'G1',NVL(T45.YCWBDAY,T00.YCWBDAY),
                              'G2',NVL(T45.YCWBDAY,T00.YCWBDAY),
                              'G3',NVL(T45.YCWBDAY,T00.YCWBDAY),
                               'G',NVL(T45.YCWBDAY,T00.YCWBDAY),
                              T00.YCWBDAY) YCWBDAY,
     DECODE(T00.PROCESS_CODE,'A',NVL(T15.TJTIMETOTALDAY,T00.TJTIMETOTALDAY),
                              'D',NVL(T5.TJTIMETOTALDAY,T00.TJTIMETOTALDAY),
                              'F1',NVL(T35.TJTIMETOTALDAY,T00.TJTIMETOTALDAY),
                              'F2',NVL(T35.TJTIMETOTALDAY,T00.TJTIMETOTALDAY),
                              'F3',NVL(T35.TJTIMETOTALDAY,T00.TJTIMETOTALDAY),
                              'G1',NVL(T45.TJTIMETOTALDAY,T00.TJTIMETOTALDAY),
                              'G2',NVL(T45.TJTIMETOTALDAY,T00.TJTIMETOTALDAY),
                              'G3',NVL(T45.TJTIMETOTALDAY,T00.TJTIMETOTALDAY),
                               'G',NVL(T45.TJTIMETOTALDAY,T00.TJTIMETOTALDAY),
                              T00.TJTIMETOTALDAY) TJTIMETOTALDAY,
                              T00.TIMETOTALDAY1 TIMETOTALDAY,
     YXNBDAY,YXZHDAY,DAYZYLDAY     
     FROM T00,T14,T15,T4,T5,T34,T35,T44,T45
     WHERE 1=1 
     AND T00.PROCESS_CODE = T14.PROCESS_CODE(+) AND T00.PLINE_NAME = T14.PLINENAME(+)
     AND T00.PROCESS_CODE = T15.PROCESS_CODE(+) AND T00.PLINE_NAME = T15.PLINENAME(+)
     AND T00.PROCESS_CODE = T4.PROCESS_CODE(+) AND T00.PLINE_NAME = T4.PLINENAME(+)
     AND T00.PROCESS_CODE = T5.PROCESS_CODE(+) AND T00.PLINE_NAME = T5.PLINENAME(+)
     AND T00.PLINEORDER = T34.PLINEORDER(+) 
     AND T00.PLINEORDER = T35.PLINEORDER(+) 
     AND T00.PLINEORDER = T44.PLINEORDER(+) 
     AND T00.PLINEORDER = T45.PLINEORDER(+)
     ),
     T100
     AS
     (
      SELECT PLINEORDER,PROCESS_DESC,PLINE_NAME,PLINE_CODE,ZCNB,ZCWB,YCNB,YCWB,TJTIMETOTAL,TIMETOTAL,
      CASE WHEN TJTIMETOTAL=TIMETOTAL AND TJTIMETOTAL=YCNB THEN '0.00' WHEN TJTIMETOTAL IS NULL THEN '100.00' WHEN TJTIMETOTAL=TIMETOTAL THEN '100.00'
        ELSE TO_CHAR((TIMETOTAL - NVL(TJTIMETOTAL, 0)) * 100 /(TIMETOTAL - NVL(TJTIMETOTAL, 0) + NVL(YCNB, 0)),'fm99999999999990.00') END || '%' YXNB,
      CASE WHEN TJTIMETOTAL=TIMETOTAL AND (TJTIMETOTAL=YCNB OR TJTIMETOTAL=YCWB) THEN '0.00' WHEN TJTIMETOTAL=TIMETOTAL  THEN '0.00' WHEN TJTIMETOTAL IS NULL THEN '100.00'
        ELSE TO_CHAR((TIMETOTAL - NVL(TJTIMETOTAL, 0)) * 100 /(TIMETOTAL - NVL(TJTIMETOTAL, 0) + NVL(YCNB, 0)+NVL(YCWB, 0)),'fm99999999999990.00') END || '%' YXZH,
      CASE WHEN TJTIMETOTAL=TIMETOTAL THEN '0.00' WHEN TJTIMETOTAL IS NULL THEN '100.00'
        ELSE TO_CHAR((TIMETOTAL - NVL(TJTIMETOTAL, 0)) * 100 /TIMETOTAL,'fm99999999999990.00') END || '%' DAYZYL,
      ZCNBDAY,ZCWBDAY,YCNBDAY,YCWBDAY,TJTIMETOTALDAY,TIMETOTALDAY,
      CASE WHEN TJTIMETOTALDAY=TIMETOTALDAY AND TJTIMETOTALDAY=YCNBDAY THEN '0.00' WHEN TJTIMETOTALDAY IS NULL THEN '100.00' WHEN TJTIMETOTALDAY=TIMETOTALDAY THEN '100.00' 
        ELSE TO_CHAR((TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0)) * 100 /(TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0) + NVL(YCNBDAY, 0)),'fm99999999999990.00') END || '%' YXNBDAY,
      CASE WHEN TJTIMETOTALDAY=TIMETOTALDAY AND (TJTIMETOTALDAY=YCNBDAY OR TJTIMETOTALDAY=YCWBDAY) THEN '0.00' WHEN TJTIMETOTALDAY IS NULL THEN '100.00' 
        WHEN NVL(YCNBDAY,0) + NVL(YCWBDAY,0) =0 THEN '100.00'
        ELSE TO_CHAR((TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0)) * 100 /(TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0) + NVL(YCNBDAY, 0)+NVL(YCWBDAY, 0)),'fm99999999999990.00') END || '%' YXZHDAY,
      CASE WHEN TJTIMETOTALDAY=TIMETOTALDAY THEN '0.00' WHEN TJTIMETOTALDAY IS NULL THEN '100.00' 
        ELSE TO_CHAR((TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0)) * 100 /TIMETOTALDAY,'fm99999999999990.00') END || '%' DAYZYLDAY
      
      FROM T99
     )
         SELECT PLINEORDER,
     CASE WHEN PLINEORDER IN ( 6,7,8,9,10,11,15,16,17,20,21,22,23,24) THEN '管加工热处理(炉)'
           WHEN  PLINEORDER IN ( 30,31,32,33,34,35,41,42,43,44,45,46,47,48,49) THEN '管加工热处理(探伤)'
           WHEN PLINEORDER IN (55,56,57,58,59,60,61,62,63,64,65,66,67,70,71,72,73,74,80,81,82,83,100) THEN '管加工加工线'
           ELSE PROCESS_DESC END  DEPT,
     PLINE_NAME PLINENAME,
      CASE WHEN PLINEORDER IN ( 6,7,8,9,10,11,15,16,17,20,21,22,23,24) THEN PLINE_CODE || '0' 
           WHEN PLINEORDER IN ( 30,31,32,33,34,35,41,42,43,44,45,46,47,48,49) THEN PLINE_CODE || '1'
              ELSE PLINE_CODE END PLINECODE,
     TO_CHAR(ZCNB/60,'fm99999999999990.00') ZCNB,
     TO_CHAR(ZCWB/60,'fm99999999999990.00') ZCWB,
     TO_CHAR(YCNB/60,'fm99999999999990.00') YCNB,
     TO_CHAR(YCWB/60,'fm99999999999990.00') YCWB,
     TO_CHAR(TJTIMETOTAL/60,'fm99999999999990.00') TJTIMETOTAL,
     TIMETOTAL,
     YXNB,YXZH,DAYZYL,
     TO_CHAR(ZCNBDAY/60,'fm99999999999990.00') ZCNBDAY,
     TO_CHAR(ZCWBDAY/60,'fm99999999999990.00')    ZCWBDAY,
     TO_CHAR(YCNBDAY/60,'fm99999999999990.00') YCNBDAY,
     TO_CHAR(YCWBDAY/60,'fm99999999999990.00')  YCWBDAY,
     TO_CHAR(TJTIMETOTALDAY/60,'fm99999999999990.00') TJTIMETOTALDAY,
     TIMETOTALDAY,
     YXNBDAY,YXZHDAY,DAYZYLDAY
     FROM T100
     ORDER BY PLINEORDER
	]]>
	</query>
	<query id="BuyGpDAL.selectRptDaySCKB_2021_01_12" desc="日生产运行快报（总调）数据">
	<![CDATA[
WITH 
/**********************************形成表结构**************************************/
T01 AS
(
  SELECT T.PLINE_CODE,
               T.PLINE_NAME || '(热处理)' PLINE_NAME,
               T.PROCESS_DESC,
               CASE WHEN T.PLINE_CODE IN ('C022','C023','C024','C025','C026') THEN 'F1'
                     WHEN T.PLINE_CODE IN ('C049','C050') THEN 'F2'
                     WHEN T.PLINE_CODE IN ('C048','C054','C055') THEN 'F3'  
                     ELSE T.PROCESS_CODE END PROCESS_CODE,
              DECODE(T.PLINE_CODE,'C001',-5,'C003',-4,'C008',1,'C009',2,'C010',3,'C017',4,'C022',6,'C023',7,'C024',8,'C025',9,
                                    'C026',10,'C049',30,'C050',31,'C054',40,'C055',41,'C048',42) PLINEORDER
          FROM COM_BASE_PLINE T
         WHERE T.PROCESS_CODE IN ('F')
         AND T.PLINE_CODE IN ('C022','C023','C024','C025','C026','C049','C050','C054','C055','C048')
    UNION ALL
     SELECT T.PLINE_CODE,
               T.PLINE_NAME || '(探伤)' PLINE_NAME,
               T.PROCESS_DESC,
               CASE WHEN T.PLINE_CODE IN ('C022','C023','C024','C025','C026') THEN 'F1'
                     WHEN T.PLINE_CODE IN ('C049','C050') THEN 'F2'
                     WHEN T.PLINE_CODE IN ('C048','C054','C055') THEN 'F3'  
                     ELSE T.PROCESS_CODE END PROCESS_CODE,
               DECODE(T.PLINE_CODE,'C001',-5,'C003',-4,'C008',1,'C009',2,'C010',3,'C017',4,'C022',20,'C023',21,'C024',22,'C025',23,
                                    'C026',24,'C049',35,'C050',36,'C054',50,'C055',51,'C048',52) PLINEORDER
          FROM COM_BASE_PLINE T
         WHERE T.PROCESS_CODE IN ('F')
         AND T.PLINE_CODE IN ('C022','C023','C024','C025','C026','C049','C050','C054','C055','C048')
         
    ORDER BY PLINE_CODE,PLINE_NAME
),
T00 AS
      (
       SELECT * FROM
        (
        SELECT T.PLINE_CODE,
               T.PLINE_NAME,
               DECODE(T.PROCESS_DESC, '轧制', '轧管', T.PROCESS_DESC) PROCESS_DESC,
               CASE WHEN T.PLINE_CODE IN ('C022','C023','C024','C025','C026') THEN 'F1'
                     WHEN T.PLINE_CODE IN ('C049','C050') THEN 'F2'
                     WHEN T.PLINE_CODE IN ('C048','C054','C055') THEN 'F3'  
                     ELSE T.PROCESS_CODE END PROCESS_CODE,
               DECODE(T.PLINE_CODE,'C001',-5,'C003',-4,'C008',1,'C009',2,'C010',3,'C017',4,'C022',6,'C023',7,'C024',8,'C025',9,
                                    'C026',10,'C049',12,'C050',13,'C054',15,'C055',16,'C048',17) PLINEORDER
          FROM COM_BASE_PLINE T
         WHERE T.PROCESS_CODE IN ('A', 'D','F')
         AND T.PLINE_CODE IN ('C001', 'C003', 'C008', 'C009', 'C010', 'C017')
         UNION ALL
         SELECT NULL,'合计','炼钢','A',-1 FROM DUAL
         UNION ALL
         SELECT NULL,'合计','轧管','D',5  FROM DUAL
         UNION ALL
          SELECT NULL ,'热处理小计','热处理(本部)','F1',11 FROM DUAL
          UNION ALL
          SELECT NULL,'探伤小计','热处理(本部)','F1',25 FROM DUAL
         UNION ALL
          SELECT NULL,'热处理小计','热处理(元通)','F2',32 FROM DUAL
          UNION ALL
          SELECT NULL,'探伤小计','热处理(元通)','F2',37 FROM DUAL
           UNION ALL
          SELECT NULL,'热处理小计','热处理(深加工)','F3',43 FROM DUAL
          UNION ALL
          SELECT NULL,'探伤小计','热处理(深加工)','F3',53 FROM DUAL
         UNION ALL
         SELECT * FROM T01
         UNION ALL
         SELECT 'G1','本部加工线','加工','G',60 FROM DUAL
         UNION ALL
         SELECT 'G2','元通加工线','加工','G',61 FROM DUAL
         UNION ALL
         SELECT 'G3','深加工加工线','加工','G',62 FROM DUAL
         UNION ALL
         SELECT NULL,'合计','加工','G',63 FROM DUAL
         )ta,
         (
          SELECT NULL ZCNB,NULL ZCWB,NULL YCNB,NULL YCWB,NULL TJTIMETOTAL,NULL TIMETOTAL,NULL YXNB,NULL YXZH,NULL DAYZYL,
                  NULL ZCNBDAY,NULL ZCWBDAY,NULL YCNBDAY,NULL YCWBDAY,NULL TJTIMETOTALDAY,NULL TIMETOTALDAY,NULL YXNBDAY,NULL YXZHDAY,NULL DAYZYLDAY
          FROM DUAL
         )tb
      ),
/**********************************炼钢时间范围查询**************************************/
T10 AS
       (SELECT SUM(TJTIME) AS TJTIME, PLINENAME, TJREASON
          FROM (SELECT T10.CONTROL_ID,
                       T10.STOP_REASON,
                       T10.LOGS_BEG,
                       T10.LOGS_END,
                       (TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                       TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                       (SELECT BASENAME
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T10.STOP_TYPE) STOPTYPE,
                       (SELECT PROPERA
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T10.STOP_REASON) STOPREASON,
                       (SELECT PLINE_NAME
                          FROM COM_BASE_PLINE
                         WHERE PLINE_CODE = T10.EF_PLINE_CODE) PLINENAME,
                       CASE
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '内部原因' THEN
                          'ZCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '外部原因' THEN
                          'ZCWB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '内部原因' THEN
                          'YCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '外部原因' THEN
                          'YCWB'
                       END TJREASON
                  FROM STL_CONTROL_LOG T10
                 WHERE T10.PRO_TYPE = '2'
                  AND TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                       TO_DATE('#LASTDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
                   AND TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
                       TO_DATE('#BGEINDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
                   AND T10.STOP_TYPE IN ('300101', '300102')
                   AND T10.EF_PLINE_CODE IN ('C001', 'C003')
                   AND EXISTS (SELECT *
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T10.STOP_REASON
                           AND VALIDFLAG = '1')) TA
         GROUP BY TA.PLINENAME, TA.TJREASON),    
      T11 AS
       (SELECT 'A' PROCESS_CODE, 
               PLINENAME,
               MAX(DECODE(TJREASON, 'ZCNB', TJTIME, NULL)) AS ZCNB,
               MAX(DECODE(TJREASON, 'ZCWB', TJTIME, NULL)) AS ZCWB,
               MAX(DECODE(TJREASON, 'YCNB', TJTIME, NULL)) AS YCNB,
               MAX(DECODE(TJREASON, 'YCWB', TJTIME, NULL)) AS YCWB,
               SUM(TJTIME) TJTIMETOTAL,
               24 * 60 * #DAYS# TIMETOTAL
          FROM T10
         GROUP BY PLINENAME),
/**********************************炼钢日范围查询**************************************/  
      T12 AS
       (SELECT SUM(TJTIME) AS TJTIME, PLINENAME, TJREASON
          FROM (SELECT T10.CONTROL_ID,
                       T10.STOP_REASON,
                       T10.LOGS_BEG,
                       T10.LOGS_END,
                       (TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                       TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                       (SELECT BASENAME
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T10.STOP_TYPE) STOPTYPE,
                       (SELECT PROPERA
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T10.STOP_REASON) STOPREASON,
                       (SELECT PLINE_NAME
                          FROM COM_BASE_PLINE
                         WHERE PLINE_CODE = T10.EF_PLINE_CODE) PLINENAME,
                       CASE
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '内部原因' THEN
                          'ZCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '外部原因' THEN
                          'ZCWB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '内部原因' THEN
                          'YCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '外部原因' THEN
                          'YCWB'
                       END TJREASON
                  FROM STL_CONTROL_LOG T10
                 WHERE T10.PRO_TYPE = '2'
                  AND TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                       TO_DATE('#ENDDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
                   AND TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
                       TO_DATE('#BGEINDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
                   AND T10.STOP_TYPE IN ('300101', '300102')
                   AND T10.EF_PLINE_CODE IN ('C001', 'C003')
                   AND EXISTS (SELECT *
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T10.STOP_REASON
                           AND VALIDFLAG = '1')) TA
         GROUP BY TA.PLINENAME, TA.TJREASON),
      T13 AS
       (SELECT 'A' PROCESS_CODE,
               PLINENAME ,
               MAX(DECODE(TJREASON, 'ZCNB', TJTIME, NULL)) AS ZCNBDAY,
               MAX(DECODE(TJREASON, 'ZCWB', TJTIME, NULL)) AS ZCWBDAY,
               MAX(DECODE(TJREASON, 'YCNB', TJTIME, NULL)) AS YCNBDAY,
               MAX(DECODE(TJREASON, 'YCWB', TJTIME, NULL)) AS YCWBDAY,
               SUM(TJTIME) TJTIMETOTALDAY,
               24 * 60 TIMETOTALDAY
          FROM T12
         GROUP BY PLINENAME),
     /********炼钢累计数值*******/
     T14 AS
     (
      SELECT * FROM T11
      UNION ALL
      SELECT 'A' PROCESS_CODE ,'合计' PLINENAME,SUM(ZCNB) ZCNB,SUM(ZCWB)ZCWB,SUM(YCNB) YCNB,SUM(YCWB) YCWB,
      SUM(TJTIMETOTAL) TJTIMETOTAL,SUM(TIMETOTAL) TIMETOTAL FROM T11
     ),
     /********炼钢日数值*******/
     T15 AS
     (
      SELECT * FROM T13
      UNION ALL
      SELECT  'A' PROCESS_CODE,'合计' PLINENAME,SUM(ZCNBDAY) ZCNBDAY,SUM(ZCWBDAY)ZCWBDAY,SUM(YCNBDAY) YCNBDAY,SUM(YCWBDAY) YCWBDAY,
      SUM(TJTIMETOTALDAY) TJTIMETOTALDAY,SUM(TIMETOTALDAY) TIMETOTALDAY FROM T13
     ),
     /**********************************轧管时间范围查询**************************************/       
       T AS
       (SELECT SUM(TJTIME) AS TJTIME, PLINENAME, TJREASON
          FROM (SELECT T.CONTROL_ID,
                       T.STOP_REASON,
                       T.LOGS_BEG,
                       T.LOGS_END,
                       (TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                       TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                       (SELECT BASENAME
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_TYPE) STOPTYPE,
                       (SELECT PROPERA
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON) STOPREASON,
                       (SELECT PLINE_NAME
                          FROM COM_BASE_PLINE
                         WHERE PLINE_CODE = T.PLINE_CODE) PLINENAME,
                       CASE
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'ZCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'ZCWB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'YCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'YCWB'
                       END TJREASON
                  FROM MIL_CONTROL_LOG T
                 WHERE T.PRO_TYPE = '2'
                   AND TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                        TO_DATE('#LASTDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
                   AND TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
                        TO_DATE('#BGEINDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
                   AND T.STOP_TYPE IN ('500601', '500602')
                   AND T.PLINE_CODE IN ('C008', 'C009', 'C010', 'C017')
                   AND EXISTS (SELECT *
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON
                           AND VALIDFLAG = '1')) TA
         GROUP BY TA.PLINENAME, TA.TJREASON),      
      T1 AS
       (SELECT 'D' PROCESS_CODE, 
               PLINENAME,
               MAX(DECODE(TJREASON, 'ZCNB', TJTIME, NULL)) AS ZCNB,
               MAX(DECODE(TJREASON, 'ZCWB', TJTIME, NULL)) AS ZCWB,
               MAX(DECODE(TJREASON, 'YCNB', TJTIME, NULL)) AS YCNB,
               MAX(DECODE(TJREASON, 'YCWB', TJTIME, NULL)) AS YCWB,
               SUM(TJTIME) TJTIMETOTAL,
               24 * 60 * #DAYS# TIMETOTAL
          FROM T
         GROUP BY PLINENAME),
/**********************************轧管日范围查询**************************************/   
      T2 AS
       (SELECT SUM(TJTIME) AS TJTIME, PLINENAME, TJREASON
          FROM (SELECT T.CONTROL_ID,
                       T.STOP_REASON,
                       T.LOGS_BEG,
                       T.LOGS_END,
                       (TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                       TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                       (SELECT BASENAME
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_TYPE) STOPTYPE,
                       (SELECT PROPERA
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON) STOPREASON,
                       (SELECT PLINE_NAME
                          FROM COM_BASE_PLINE
                         WHERE PLINE_CODE = T.PLINE_CODE) PLINENAME,
                       CASE
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'ZCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'ZCWB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'YCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'YCWB'
                       END TJREASON
                  FROM MIL_CONTROL_LOG T
                 WHERE T.PRO_TYPE = '2'
                   AND TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                       TO_DATE('#ENDDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
                   AND TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
                       TO_DATE('#BGEINDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
                   AND T.STOP_TYPE IN ('500601', '500602')
                   AND T.PLINE_CODE IN ('C008', 'C009', 'C010', 'C017')
                   AND EXISTS (SELECT *
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON
                           AND VALIDFLAG = '1')) TA
         GROUP BY TA.PLINENAME, TA.TJREASON),
      T3 AS
       (SELECT  'D' PROCESS_CODE, 
               PLINENAME ,
               MAX(DECODE(TJREASON, 'ZCNB', TJTIME, NULL)) AS ZCNBDAY,
               MAX(DECODE(TJREASON, 'ZCWB', TJTIME, NULL)) AS ZCWBDAY,
               MAX(DECODE(TJREASON, 'YCNB', TJTIME, NULL)) AS YCNBDAY,
               MAX(DECODE(TJREASON, 'YCWB', TJTIME, NULL)) AS YCWBDAY,
               SUM(TJTIME) TJTIMETOTALDAY,
               24 * 60 TIMETOTALDAY
          FROM T2
         GROUP BY PLINENAME),
     /********轧管累计数值*******/
     T4 AS
     (
      SELECT * FROM T1
      UNION ALL
      SELECT 'D' PROCESS_CODE ,'合计' PLINENAME,SUM(ZCNB) ZCNB,SUM(ZCWB)ZCWB,SUM(YCNB) YCNB,SUM(YCWB) YCWB,
      SUM(TJTIMETOTAL) TJTIMETOTAL,SUM(TIMETOTAL) TIMETOTAL FROM T1
     ),
     /********轧管日数值*******/
     T5 AS
     (
      SELECT * FROM T3
      UNION ALL
      SELECT  'D' PROCESS_CODE,'合计' PLINENAME,SUM(ZCNBDAY) ZCNBDAY,SUM(ZCWBDAY)ZCWBDAY,SUM(YCNBDAY) YCNBDAY,SUM(YCWBDAY) YCWBDAY,
      SUM(TJTIMETOTALDAY) TJTIMETOTALDAY,SUM(TIMETOTALDAY) TIMETOTALDAY FROM T3
     ),
      /**********************************热处理时间范围查询**************************************/       
       T30 AS
       (SELECT SUM(TJTIME) AS TJTIME, PLINENAME || DECODE(STATION,'0','(热处理)','1','(探伤)') PLINENAME, TJREASON,PLINE_CODE,STATION
          FROM (SELECT T.CONTROL_ID,
                       T.STOP_REASON,
                       T.LOGS_BEG,
                       T.LOGS_END,
                       (TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                       TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                       (SELECT BASENAME
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_TYPE) STOPTYPE,
                       (SELECT PROPERA
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON) STOPREASON,
                       (SELECT PLINE_NAME
                          FROM COM_BASE_PLINE
                         WHERE PLINE_CODE = T.PLINE_CODE) PLINENAME,
                       CASE
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'ZCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'ZCWB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'YCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'YCWB'
                       END TJREASON,
                       PLINE_CODE,
                       STATION
                  FROM (SELECT T.CONTROL_ID,
                         T.LOGS_BEG,
                         T.LOGS_END,
                         T.PLINE_CODE,
                         T.STOP_TYPE,
                         T.STOP_REASON,
                         T.STOP_SMALL,
                         T.STATION
                    FROM HTT_CONTROL_LOG T
                    --, HTT_CONTROL_LOG_DETAIL T1
                    WHERE T.PRO_TYPE = '2'
                    --AND T.CONTROL_ID = T1.CONTROL_ID
                    AND TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                        TO_DATE('#LASTDATE#' || '2100', 'yyyy-mm-dd hh24:mi:ss')
                   AND TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
                        TO_DATE('#BGEINDATE#' || '2100', 'yyyy-mm-dd hh24:mi:ss')
                   AND T.PLINE_CODE IN ('C022','C023','C024','C025','C026','C054','C055','C048')
                   AND T.STATION IN ('0','1')
                   UNION ALL
                   SELECT T.CONTROL_ID,
                         T.LOGS_BEG,
                         T.LOGS_END,
                         T.PLINE_CODE,
                         T.STOP_TYPE,
                         T.STOP_REASON,
                         T.STOP_SMALL,
                         T.STATION
                    FROM HTT_CONTROL_LOG T
                    --, HTT_CONTROL_LOG_DETAIL T1
                    WHERE T.PRO_TYPE = '2'
                    --AND T.CONTROL_ID = T1.CONTROL_ID
                    AND TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                        TO_DATE('#LASTDATE#' || '2000', 'yyyy-mm-dd hh24:mi:ss')
                   AND TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
                        TO_DATE('#BGEINDATE#' || '2000', 'yyyy-mm-dd hh24:mi:ss')
                   AND T.PLINE_CODE IN ('C049','C050')
                   AND T.STATION IN ('0','1')
                   ) T
                 WHERE 1=1
                   --AND T.STOP_TYPE IN ('500601', '500602')
                   AND EXISTS (SELECT *
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON
                           AND VALIDFLAG = '1')) TA
         GROUP BY TA.PLINENAME,TA.PLINE_CODE,TA.TJREASON,TA.STATION),      
      T31 AS
       (SELECT 
              --'F' PROCESS_CODE,
               CASE WHEN PLINE_CODE IN ('C022','C023','C024','C025','C026') THEN 'F1'
                     WHEN PLINE_CODE IN ('C049','C050') THEN 'F2'
                     WHEN PLINE_CODE IN ('C048','C054','C055') THEN 'F3'  
                     ELSE NULL END PROCESS_CODE, 
               PLINENAME,
               MAX(DECODE(TJREASON, 'ZCNB', TJTIME, NULL)) AS ZCNB,
               MAX(DECODE(TJREASON, 'ZCWB', TJTIME, NULL)) AS ZCWB,
               MAX(DECODE(TJREASON, 'YCNB', TJTIME, NULL)) AS YCNB,
               MAX(DECODE(TJREASON, 'YCWB', TJTIME, NULL)) AS YCWB,
               SUM(TJTIME) TJTIMETOTAL,
               24 * 60 * #DAYS# TIMETOTAL,
               STATION
          FROM T30
         GROUP BY PLINENAME,PLINE_CODE,STATION),
       /**********************************热处理日范围查询**************************************/   
       T32 AS
       (SELECT SUM(TJTIME) AS TJTIME, PLINENAME || DECODE(STATION,'0','(热处理)','1','(探伤)') PLINENAME, TJREASON,PLINE_CODE,STATION
          FROM (SELECT T.CONTROL_ID,
                       T.STOP_REASON,
                       T.LOGS_BEG,
                       T.LOGS_END,
                       (TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                       TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                       (SELECT BASENAME
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_TYPE) STOPTYPE,
                       (SELECT PROPERA
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON) STOPREASON,
                       (SELECT PLINE_NAME
                          FROM COM_BASE_PLINE
                         WHERE PLINE_CODE = T.PLINE_CODE) PLINENAME,
                       CASE
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'ZCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'ZCWB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'YCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'YCWB'
                       END TJREASON,
                       PLINE_CODE,
                       STATION
                  FROM (SELECT T.CONTROL_ID,
                         T.LOGS_BEG,
                         T.LOGS_END,
                         T.PLINE_CODE,
                         T.STOP_TYPE,
                         T.STOP_REASON,
                         T.STOP_SMALL,
                         T.STATION
                    FROM HTT_CONTROL_LOG T
                    --, HTT_CONTROL_LOG_DETAIL T1
                    WHERE T.PRO_TYPE = '2'
                    --AND T.CONTROL_ID = T1.CONTROL_ID
                    AND TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                        TO_DATE('#ENDDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
                   AND TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
                        TO_DATE('#BGEINDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
                   AND T.PLINE_CODE IN ('C022','C023','C024','C025','C026','C054','C055','C048')
                   AND T.STATION IN ('0','1')
                   UNION ALL
                   SELECT T.CONTROL_ID,
                         T.LOGS_BEG,
                         T.LOGS_END,
                         T.PLINE_CODE,
                         T.STOP_TYPE,
                         T.STOP_REASON,
                         T.STOP_SMALL,
                         T.STATION
                    FROM HTT_CONTROL_LOG T
                    --, HTT_CONTROL_LOG_DETAIL T1
                    WHERE T.PRO_TYPE = '2'
                    --AND T.CONTROL_ID = T1.CONTROL_ID
                    AND TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                        TO_DATE('#ENDDATE#'||'2000', 'yyyy-mm-dd hh24:mi:ss')
                   AND TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
                        TO_DATE('#BGEINDATE#'||'2000', 'yyyy-mm-dd hh24:mi:ss')
                   AND T.PLINE_CODE IN ('C049','C050')
                   AND T.STATION IN ('0','1')
                   ) T
                 WHERE 1=1
                   --AND T.STOP_TYPE IN ('500601', '500602')
                   AND EXISTS (SELECT *
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON
                           AND VALIDFLAG = '1')) TA
         GROUP BY TA.PLINENAME,TA.PLINE_CODE,TA.TJREASON,TA.STATION),            
      T33 AS
       (SELECT 
              --'F' PROCESS_CODE,
               CASE WHEN PLINE_CODE IN ('C022','C023','C024','C025','C026') THEN 'F1'
                     WHEN PLINE_CODE IN ('C049','C050') THEN 'F2'
                     WHEN PLINE_CODE IN ('C048','C054','C055') THEN 'F3'  
                     ELSE NULL END PROCESS_CODE, 
               PLINENAME,
               MAX(DECODE(TJREASON, 'ZCNB', TJTIME, NULL)) AS ZCNBDAY,
               MAX(DECODE(TJREASON, 'ZCWB', TJTIME, NULL)) AS ZCWBDAY,
               MAX(DECODE(TJREASON, 'YCNB', TJTIME, NULL)) AS YCNBDAY,
               MAX(DECODE(TJREASON, 'YCWB', TJTIME, NULL)) AS YCWBDAY,
               SUM(TJTIME) TJTIMETOTALDAY,
               24 * 60  TIMETOTALDAY,
               STATION
          FROM T32
         GROUP BY PLINENAME,PLINE_CODE,STATION),
              /********热处理累计数值*******/
     T34 AS
     (
      SELECT * FROM T31
      UNION ALL
      SELECT PROCESS_CODE ,DECODE(station,'0','热处理','1','探伤') || '小计' PLINENAME,SUM(ZCNB) ZCNB,SUM(ZCWB)ZCWB,SUM(YCNB) YCNB,SUM(YCWB) YCWB,
      SUM(TJTIMETOTAL) TJTIMETOTAL,SUM(TIMETOTAL) TIMETOTAL,STATION FROM T31 GROUP BY PROCESS_CODE,STATION
     ),
     /********热处理日数值*******/
     T35 AS
     (
      SELECT * FROM T33
      UNION ALL
      SELECT PROCESS_CODE ,DECODE(station,'0','热处理','1','探伤') || '小计' PLINENAME,SUM(ZCNBDAY) ZCNBDAY,SUM(ZCWBDAY)ZCWBDAY,SUM(YCNBDAY) YCNBDAY,SUM(YCWBDAY) YCWBDAY,
      SUM(TJTIMETOTALDAY) TJTIMETOTALDAY,SUM(TIMETOTALDAY) TIMETOTALDAY,STATION FROM T33 GROUP BY PROCESS_CODE,STATION
     ),
      /**********************************加工时间范围查询**************************************/       
       T40 AS
       (SELECT SUM(TJTIME) AS TJTIME, DECODE(STATION,'G1','本部加工线','G2','元通加工线','G3','深加工加工线') PLINENAME, TJREASON,STATION PLINE_CODE
          FROM (SELECT T.CONTROL_ID,
                       T.STOP_REASON,
                       T.LOGS_BEG,
                       T.LOGS_END,
                       (TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                       TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                       (SELECT BASENAME
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_TYPE) STOPTYPE,
                       (SELECT PROPERA
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON) STOPREASON,
                       (SELECT PLINE_NAME
                          FROM COM_BASE_PLINE
                         WHERE PLINE_CODE = T.PLINE_CODE) PLINENAME,
                       CASE
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'ZCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'ZCWB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'YCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'YCWB'
                       END TJREASON,
                       PLINE_CODE,
                       CASE WHEN
                        PLINE_CODE IN ('C028','C029','C030','C031','C032','C033','C034','C035','C036','C037','C053','C056') THEN 'G1' 
                         WHEN
                        PLINE_CODE IN ( 'C039','C051','C038','C057') THEN 'G2' 
                         WHEN
                        PLINE_CODE IN ( 'C052','C078','C058') THEN 'G3' 
                       END  STATION
                  FROM (SELECT T.CONTROL_ID,
                         T.LOGS_BEG,
                         T.LOGS_END,
                         T.PLINE_CODE,
                         T.STOP_TYPE,
                         T.STOP_REASON,
                         T.STOP_SMALL,
                         T.STATION
                    FROM HTT_CONTROL_LOG T
                                        WHERE T.PRO_TYPE = '2'
                                        AND TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                        TO_DATE('#LASTDATE#' || '2100', 'yyyy-mm-dd hh24:mi:ss')
                   AND TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
                        TO_DATE('#BGEINDATE#' || '2100', 'yyyy-mm-dd hh24:mi:ss')
                   AND T.PLINE_CODE IN ('C028','C029','C030','C031','C032','C033','C034','C035','C036','C037','C053','C056',
                                          'C039','C051','C038','C057',
                                          'C052','C078','C058'
                                        )

                   ) T
                 WHERE 1=1
                                      AND EXISTS (SELECT *
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON
                           AND VALIDFLAG = '1')) TA
         GROUP BY TA.TJREASON,TA.STATION),     
      T41 AS
       (SELECT 
               'G'  PROCESS_CODE,             
               PLINENAME,
               PLINE_CODE,
               MAX(DECODE(TJREASON, 'ZCNB', TJTIME, NULL)) AS ZCNB,
               MAX(DECODE(TJREASON, 'ZCWB', TJTIME, NULL)) AS ZCWB,
               MAX(DECODE(TJREASON, 'YCNB', TJTIME, NULL)) AS YCNB,
               MAX(DECODE(TJREASON, 'YCWB', TJTIME, NULL)) AS YCWB,
               SUM(TJTIME) TJTIMETOTAL,
               DECODE(PLINE_CODE ,'G1',24 * 60*12 * #DAYS#,'G2',24 * 60* 4 * #DAYS#,'G3',24 * 60 * 3 * #DAYS#) TIMETOTAL
          FROM T40
         GROUP BY PLINENAME,PLINE_CODE),
       /**********************************加工线日范围查询**************************************/   
       T42 AS
       (SELECT SUM(TJTIME) AS TJTIME, DECODE(STATION,'G1','本部加工线','G2','元通加工线','G3','深加工加工线') PLINENAME, TJREASON,STATION PLINE_CODE
          FROM (SELECT T.CONTROL_ID,
                       T.STOP_REASON,
                       T.LOGS_BEG,
                       T.LOGS_END,
                       (TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                       TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                       (SELECT BASENAME
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_TYPE) STOPTYPE,
                       (SELECT PROPERA
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON) STOPREASON,
                       (SELECT PLINE_NAME
                          FROM COM_BASE_PLINE
                         WHERE PLINE_CODE = T.PLINE_CODE) PLINENAME,
                       CASE
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'ZCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'ZCWB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'YCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'YCWB'
                       END TJREASON,
                       PLINE_CODE,
                       CASE WHEN
                        PLINE_CODE IN ('C028','C029','C030','C031','C032','C033','C034','C035','C036','C037','C053','C056') THEN 'G1' 
                         WHEN
                        PLINE_CODE IN ( 'C039','C051','C038','C057') THEN 'G2' 
                         WHEN
                        PLINE_CODE IN ( 'C052','C078','C058') THEN 'G3' 
                       END  STATION
                  FROM (SELECT T.CONTROL_ID,
                         T.LOGS_BEG,
                         T.LOGS_END,
                         T.PLINE_CODE,
                         T.STOP_TYPE,
                         T.STOP_REASON,
                         T.STOP_SMALL,
                         T.STATION
                    FROM HTT_CONTROL_LOG T
                                        WHERE T.PRO_TYPE = '2'
                                        AND TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                        TO_DATE('#ENDDATE#' || '2100', 'yyyy-mm-dd hh24:mi:ss')
                   AND TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
                        TO_DATE('#BGEINDATE#' || '2100', 'yyyy-mm-dd hh24:mi:ss')
                   AND T.PLINE_CODE IN ('C028','C029','C030','C031','C032','C033','C034','C035','C036','C037','C053','C056',
                                          'C039','C051','C038','C057',
                                          'C052','C078','C058'
                                        )

                   ) T
                 WHERE 1=1
                                      AND EXISTS (SELECT *
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON
                           AND VALIDFLAG = '1')) TA
         GROUP BY TA.TJREASON,TA.STATION),          
      T43 AS
      (SELECT 
               'G'  PROCESS_CODE,             
               PLINENAME,
               PLINE_CODE,
               MAX(DECODE(TJREASON, 'ZCNB', TJTIME, NULL)) AS ZCNB,
               MAX(DECODE(TJREASON, 'ZCWB', TJTIME, NULL)) AS ZCWB,
               MAX(DECODE(TJREASON, 'YCNB', TJTIME, NULL)) AS YCNB,
               MAX(DECODE(TJREASON, 'YCWB', TJTIME, NULL)) AS YCWB,
               SUM(TJTIME) TJTIMETOTAL,
               DECODE(PLINE_CODE ,'G1',24 * 60*12 * 1,'G2',24 * 60* 4 * 1,'G3',24 * 60* 4 * 1) TIMETOTAL
          FROM T42
         GROUP BY PLINENAME,PLINE_CODE),
              /********加工线累计数值*******/
     T44 AS
     (
      SELECT PROCESS_CODE,PLINENAME,ZCNB,ZCWB,YCNB,YCWB,TJTIMETOTAL,TIMETOTAL FROM T41
      UNION ALL
      SELECT 'G' PROCESS_CODE ,'合计' PLINENAME,SUM(ZCNB) ZCNB,SUM(ZCWB)ZCWB,SUM(YCNB) YCNB,SUM(YCWB) YCWB,
      SUM(TJTIMETOTAL) TJTIMETOTAL,SUM(TIMETOTAL) TIMETOTAL FROM T41
     ),
     /********加工线日数值*******/
     T45 AS
     (
      SELECT PROCESS_CODE,PLINENAME,ZCNB ZCNBDAY,ZCWB ZCWBDAY,YCNB YCNBDAY,YCWB YCWBDAY,TJTIMETOTAL TJTIMETOTALDAY,TIMETOTAL TIMETOTALDAY FROM T43
      UNION ALL
      SELECT 'G' PROCESS_CODE ,'合计' PLINENAME,SUM(ZCNB) ZCNB,SUM(ZCWB)ZCWB,SUM(YCNB) YCNB,SUM(YCWB) YCWB,
      SUM(TJTIMETOTAL) TJTIMETOTAL,SUM(TIMETOTAL) TIMETOTAL FROM T43
     ),
     T99
     AS
     (
     SELECT T00.PLINEORDER,T00.PROCESS_DESC,T00.PLINE_NAME,PLINE_CODE,
     DECODE(T00.PROCESS_CODE,'A',NVL(T14.ZCNB,T00.ZCNB),
                              'D',NVL(T4.ZCNB,T00.ZCNB),
                              'F1',NVL(T34.ZCNB,T00.ZCNB),
                              'F2',NVL(T34.ZCNB,T00.ZCNB),
                              'F3',NVL(T34.ZCNB,T00.ZCNB),
                              'F4',NVL(T34.ZCNB,T00.ZCNB),
                              'G',NVL(T44.ZCNB,T00.ZCNB),
                               T00.ZCNB) ZCNB,
     DECODE(T00.PROCESS_CODE,'A',NVL(T14.ZCWB,T00.ZCWB),
                              'D',NVL(T4.ZCWB,T00.ZCWB),
                               'F1',NVL(T34.ZCWB,T00.ZCWB),
                               'F2',NVL(T34.ZCWB,T00.ZCWB),
                               'F3',NVL(T34.ZCWB,T00.ZCWB),
                               'F4',NVL(T34.ZCWB,T00.ZCWB),
                                'G',NVL(T44.ZCWB,T00.ZCWB),
                              T00.ZCWB) ZCWB,
     DECODE(T00.PROCESS_CODE,'A',NVL(T14.YCNB,T00.YCNB),
                              'D',NVL(T4.YCNB,T00.YCNB),
                              'F1',NVL(T34.YCNB,T00.YCNB),
                              'F2',NVL(T34.YCNB,T00.YCNB),
                              'F3',NVL(T34.YCNB,T00.YCNB),
                              'F4',NVL(T34.YCNB,T00.YCNB),
                              'G',NVL(T44.YCNB,T00.YCNB),
                              T00.YCNB) YCNB,
     DECODE(T00.PROCESS_CODE,'A',NVL(T14.YCWB,T00.YCWB),
                              'D',NVL(T4.YCWB,T00.YCWB),
                              'F1',NVL(T34.YCWB,T00.YCWB),
                              'F2',NVL(T34.YCWB,T00.YCWB),
                              'F3',NVL(T34.YCWB,T00.YCWB),
                              'F4',NVL(T34.YCWB,T00.YCWB),
                               'G',NVL(T44.YCWB,T00.YCWB),
                              T00.YCWB) YCWB,
     DECODE(T00.PROCESS_CODE,'A',NVL(T14.TJTIMETOTAL,T00.TJTIMETOTAL),
                              'D',NVL(T4.TJTIMETOTAL,T00.TJTIMETOTAL),
                              'F1',NVL(T34.TJTIMETOTAL,T00.TJTIMETOTAL),
                              'F2',NVL(T34.TJTIMETOTAL,T00.TJTIMETOTAL),
                              'F3',NVL(T34.TJTIMETOTAL,T00.TJTIMETOTAL),
                              'F4',NVL(T34.TJTIMETOTAL,T00.TJTIMETOTAL),
                               'G',NVL(T44.TJTIMETOTAL,T00.TJTIMETOTAL),
                              T00.TJTIMETOTAL) TJTIMETOTAL,
     DECODE(T00.PROCESS_CODE,'A',NVL(T14.TIMETOTAL,T00.TIMETOTAL),
                              'D',NVL(T4.TIMETOTAL,T00.TIMETOTAL),
                              'F1',NVL(T34.TIMETOTAL,T00.TIMETOTAL),
                              'F2',NVL(T34.TIMETOTAL,T00.TIMETOTAL),
                              'F3',NVL(T34.TIMETOTAL,T00.TIMETOTAL),
                              'F4',NVL(T34.TIMETOTAL,T00.TIMETOTAL),
                              'G',NVL(T44.TIMETOTAL,T00.TIMETOTAL),
                              T00.TIMETOTAL) TIMETOTAL,
     YXNB,YXZH,DAYZYL,
     DECODE(T00.PROCESS_CODE,'A',NVL(T15.ZCNBDAY,T00.ZCNBDAY),
                              'D',NVL(T5.ZCNBDAY,T00.ZCNBDAY),
                              'F1',NVL(T35.ZCNBDAY,T00.ZCNBDAY),
                              'F2',NVL(T35.ZCNBDAY,T00.ZCNBDAY),
                              'F3',NVL(T35.ZCNBDAY,T00.ZCNBDAY),
                              'F4',NVL(T35.ZCNBDAY,T00.ZCNBDAY),
                              'G',NVL(T45.ZCNBDAY,T00.ZCNBDAY),
                              T00.ZCNBDAY) ZCNBDAY,
     DECODE(T00.PROCESS_CODE,'A',NVL(T15.ZCWBDAY,T00.ZCWBDAY),
                              'D',NVL(T5.ZCWBDAY,T00.ZCWBDAY),
                              'F1',NVL(T35.ZCWBDAY,T00.ZCWBDAY),
                              'F2',NVL(T35.ZCWBDAY,T00.ZCWBDAY),
                              'F3',NVL(T35.ZCWBDAY,T00.ZCWBDAY),
                              'F4',NVL(T35.ZCWBDAY,T00.ZCWBDAY),
                              'G',NVL(T45.ZCWBDAY,T00.ZCWBDAY),
                              T00.ZCWBDAY) ZCWBDAY,
     DECODE(T00.PROCESS_CODE,'A',NVL(T15.YCNBDAY,T00.YCNBDAY),
                              'D',NVL(T5.YCNBDAY,T00.YCNBDAY),
                              'F1',NVL(T35.YCNBDAY,T00.YCNBDAY),
                              'F2',NVL(T35.YCNBDAY,T00.YCNBDAY),
                              'F3',NVL(T35.YCNBDAY,T00.YCNBDAY),
                              'F4',NVL(T35.YCNBDAY,T00.YCNBDAY),
                              'G',NVL(T45.YCNBDAY,T00.YCNBDAY),
                              T00.YCNBDAY) YCNBDAY,
     DECODE(T00.PROCESS_CODE,'A',NVL(T15.YCWBDAY,T00.YCWBDAY),
                              'D',NVL(T5.YCWBDAY,T00.YCWBDAY),
                              'F1',NVL(T35.YCWBDAY,T00.YCWBDAY),
                              'F2',NVL(T35.YCWBDAY,T00.YCWBDAY),
                              'F3',NVL(T35.YCWBDAY,T00.YCWBDAY),
                              'F4',NVL(T35.YCWBDAY,T00.YCWBDAY),
                               'G',NVL(T45.YCWBDAY,T00.YCWBDAY),
                              T00.YCWBDAY) YCWBDAY,
     DECODE(T00.PROCESS_CODE,'A',NVL(T15.TJTIMETOTALDAY,T00.TJTIMETOTALDAY),
                              'D',NVL(T5.TJTIMETOTALDAY,T00.TJTIMETOTALDAY),
                              'F1',NVL(T35.TJTIMETOTALDAY,T00.TJTIMETOTALDAY),
                              'F2',NVL(T35.TJTIMETOTALDAY,T00.TJTIMETOTALDAY),
                              'F3',NVL(T35.TJTIMETOTALDAY,T00.TJTIMETOTALDAY),
                              'F4',NVL(T35.TJTIMETOTALDAY,T00.TJTIMETOTALDAY),
                              'G',NVL(T45.TJTIMETOTALDAY,T00.TJTIMETOTALDAY),
                              T00.TJTIMETOTALDAY) TJTIMETOTALDAY,
     DECODE(T00.PROCESS_CODE,'A',NVL(T15.TIMETOTALDAY,T00.TIMETOTALDAY),
                              'D',NVL(T5.TIMETOTALDAY,T00.TIMETOTALDAY),
                              'F1',NVL(T35.TIMETOTALDAY,T00.TIMETOTALDAY),
                              'F2',NVL(T35.TIMETOTALDAY,T00.TIMETOTALDAY),
                              'F3',NVL(T35.TIMETOTALDAY,T00.TIMETOTALDAY),
                              'F4',NVL(T35.TIMETOTALDAY,T00.TIMETOTALDAY),
                              'G',NVL(T45.TIMETOTALDAY,T00.TIMETOTALDAY),
                              T00.TIMETOTALDAY) TIMETOTALDAY,
     YXNBDAY,YXZHDAY,DAYZYLDAY     
     FROM T00,T14,T15,T4,T5,T34,T35,T44,T45
     WHERE 1=1 
     AND T00.PROCESS_CODE = T14.PROCESS_CODE(+) AND T00.PLINE_NAME = T14.PLINENAME(+)
     AND T00.PROCESS_CODE = T15.PROCESS_CODE(+) AND T00.PLINE_NAME = T15.PLINENAME(+)
     AND T00.PROCESS_CODE = T4.PROCESS_CODE(+) AND T00.PLINE_NAME = T4.PLINENAME(+)
     AND T00.PROCESS_CODE = T5.PROCESS_CODE(+) AND T00.PLINE_NAME = T5.PLINENAME(+)
     AND T00.PROCESS_CODE = T34.PROCESS_CODE(+) AND T00.PLINE_NAME = T34.PLINENAME(+)
     AND T00.PROCESS_CODE = T35.PROCESS_CODE(+) AND T00.PLINE_NAME = T35.PLINENAME(+)
     AND T00.PROCESS_CODE = T44.PROCESS_CODE(+) AND T00.PLINE_NAME = T44.PLINENAME(+)
     AND T00.PROCESS_CODE = T45.PROCESS_CODE(+) AND T00.PLINE_NAME = T45.PLINENAME(+)
     ),
     T100
     AS
     (
      SELECT PLINEORDER,PROCESS_DESC,PLINE_NAME,PLINE_CODE,ZCNB,ZCWB,YCNB,YCWB,TJTIMETOTAL,TIMETOTAL,
      CASE WHEN TJTIMETOTAL=TIMETOTAL AND TJTIMETOTAL=YCNB THEN '0.00' WHEN TJTIMETOTAL IS NULL THEN '100.00' WHEN TJTIMETOTAL=TIMETOTAL THEN '100.00'
        ELSE TO_CHAR((TIMETOTAL - NVL(TJTIMETOTAL, 0)) * 100 /(TIMETOTAL - NVL(TJTIMETOTAL, 0) + NVL(YCNB, 0)),'fm99999999999990.00') END || '%' YXNB,
      CASE WHEN TJTIMETOTAL=TIMETOTAL AND (TJTIMETOTAL=YCNB OR TJTIMETOTAL=YCWB) THEN '0.00' WHEN TJTIMETOTAL=TIMETOTAL  THEN '0.00' WHEN TJTIMETOTAL IS NULL THEN '100.00'
        ELSE TO_CHAR((TIMETOTAL - NVL(TJTIMETOTAL, 0)) * 100 /(TIMETOTAL - NVL(TJTIMETOTAL, 0) + NVL(YCNB, 0)+NVL(YCWB, 0)),'fm99999999999990.00') END || '%' YXZH,
      CASE WHEN TJTIMETOTAL=TIMETOTAL THEN '0.00' WHEN TJTIMETOTAL IS NULL THEN '100.00'
        ELSE TO_CHAR((TIMETOTAL - NVL(TJTIMETOTAL, 0)) * 100 /TIMETOTAL,'fm99999999999990.00') END || '%' DAYZYL,
      ZCNBDAY,ZCWBDAY,YCNBDAY,YCWBDAY,TJTIMETOTALDAY,TIMETOTALDAY,
      CASE WHEN TJTIMETOTALDAY=TIMETOTALDAY AND TJTIMETOTALDAY=YCNBDAY THEN '0.00' WHEN TJTIMETOTALDAY IS NULL THEN '100.00' WHEN TJTIMETOTALDAY=TIMETOTALDAY THEN '100.00' 
        ELSE TO_CHAR((TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0)) * 100 /(TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0) + NVL(YCNBDAY, 0)),'fm99999999999990.00') END || '%' YXNBDAY,
      CASE WHEN TJTIMETOTALDAY=TIMETOTALDAY AND (TJTIMETOTALDAY=YCNBDAY OR TJTIMETOTALDAY=YCWBDAY) THEN '0.00' WHEN TJTIMETOTALDAY IS NULL THEN '100.00' 
        WHEN NVL(YCNBDAY,0) + NVL(YCWBDAY,0) =0 THEN '100.00'
        ELSE TO_CHAR((TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0)) * 100 /(TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0) + NVL(YCNBDAY, 0)+NVL(YCWBDAY, 0)),'fm99999999999990.00') END || '%' YXZHDAY,
      CASE WHEN TJTIMETOTALDAY=TIMETOTALDAY THEN '0.00' WHEN TJTIMETOTALDAY IS NULL THEN '100.00' 
        ELSE TO_CHAR((TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0)) * 100 /TIMETOTALDAY,'fm99999999999990.00') END || '%' DAYZYLDAY
      
      FROM T99
     )
         SELECT PLINEORDER,
     CASE WHEN PLINE_CODE IN ('C022','C023','C024','C025','C026') THEN '热处理(本部)'
           WHEN  PLINE_CODE IN ('C049','C050') THEN '热处理(元通)'
           WHEN PLINE_CODE IN ('C048','C054','C055') THEN  '热处理(深加工)'
           ELSE PROCESS_DESC END  DEPT,
     PLINE_NAME PLINENAME,
      CASE WHEN PLINEORDER IN (6,7,8,9,10,30,31,40,41,42) THEN PLINE_CODE || '0' 
           WHEN PLINEORDER IN (20,21,22,23,24,35,36,50,51,52) THEN PLINE_CODE || '1'
              ELSE PLINE_CODE END PLINECODE,
     TO_CHAR(ZCNB/60,'fm99999999999990.00') ZCNB,
     TO_CHAR(ZCWB/60,'fm99999999999990.00') ZCWB,
     TO_CHAR(YCNB/60,'fm99999999999990.00') YCNB,
     TO_CHAR(YCWB/60,'fm99999999999990.00') YCWB,
     TO_CHAR(TJTIMETOTAL/60,'fm99999999999990.00') TJTIMETOTAL,
     TIMETOTAL,
     YXNB,YXZH,DAYZYL,
     TO_CHAR(ZCNBDAY/60,'fm99999999999990.00') ZCNBDAY,
     TO_CHAR(ZCWBDAY/60,'fm99999999999990.00')    ZCWBDAY,
     TO_CHAR(YCNBDAY/60,'fm99999999999990.00') YCNBDAY,
     TO_CHAR(YCWBDAY/60,'fm99999999999990.00')  YCWBDAY,
     TO_CHAR(TJTIMETOTALDAY/60,'fm99999999999990.00') TJTIMETOTALDAY,
     TIMETOTALDAY,
     YXNBDAY,YXZHDAY,DAYZYLDAY
     FROM T100
     ORDER BY PLINEORDER
	]]>
	</query>
	<query id="BuyGpDAL.selectRptDaySCKB20210104" desc="日生产运行快报（总调）数据">
	<![CDATA[
WITH 
/**********************************形成表结构**************************************/
T01 AS
(
  SELECT T.PLINE_CODE,
               T.PLINE_NAME || '(热处理)' PLINE_NAME,
               T.PROCESS_DESC,
               CASE WHEN T.PLINE_CODE IN ('C022','C023','C024','C025','C026') THEN 'F1'
                     WHEN T.PLINE_CODE IN ('C049','C050') THEN 'F2'
                     WHEN T.PLINE_CODE IN ('C048','C054','C055') THEN 'F3'  
                     ELSE T.PROCESS_CODE END PROCESS_CODE,
              DECODE(T.PLINE_CODE,'C001',-5,'C003',-4,'C008',1,'C009',2,'C010',3,'C017',4,'C022',6,'C023',7,'C024',8,'C025',9,
                                    'C026',10,'C049',30,'C050',31,'C054',40,'C055',41,'C048',42) PLINEORDER
          FROM COM_BASE_PLINE T
         WHERE T.PROCESS_CODE IN ('F')
         AND T.PLINE_CODE IN ('C022','C023','C024','C025','C026','C049','C050','C054','C055','C048')
    UNION ALL
     SELECT T.PLINE_CODE,
               T.PLINE_NAME || '(探伤)' PLINE_NAME,
               T.PROCESS_DESC,
               CASE WHEN T.PLINE_CODE IN ('C022','C023','C024','C025','C026') THEN 'F1'
                     WHEN T.PLINE_CODE IN ('C049','C050') THEN 'F2'
                     WHEN T.PLINE_CODE IN ('C048','C054','C055') THEN 'F3'  
                     ELSE T.PROCESS_CODE END PROCESS_CODE,
               DECODE(T.PLINE_CODE,'C001',-5,'C003',-4,'C008',1,'C009',2,'C010',3,'C017',4,'C022',20,'C023',21,'C024',22,'C025',23,
                                    'C026',24,'C049',35,'C050',36,'C054',50,'C055',51,'C048',52) PLINEORDER
          FROM COM_BASE_PLINE T
         WHERE T.PROCESS_CODE IN ('F')
         AND T.PLINE_CODE IN ('C022','C023','C024','C025','C026','C049','C050','C054','C055','C048')
         
    ORDER BY PLINE_CODE,PLINE_NAME
),
T00 AS
      (
       SELECT * FROM
        (
        SELECT T.PLINE_CODE,
               T.PLINE_NAME,
               DECODE(T.PROCESS_DESC, '轧制', '轧管', T.PROCESS_DESC) PROCESS_DESC,
               CASE WHEN T.PLINE_CODE IN ('C022','C023','C024','C025','C026') THEN 'F1'
                     WHEN T.PLINE_CODE IN ('C049','C050') THEN 'F2'
                     WHEN T.PLINE_CODE IN ('C048','C054','C055') THEN 'F3'  
                     ELSE T.PROCESS_CODE END PROCESS_CODE,
               DECODE(T.PLINE_CODE,'C001',-5,'C003',-4,'C008',1,'C009',2,'C010',3,'C017',4,'C022',6,'C023',7,'C024',8,'C025',9,
                                    'C026',10,'C049',12,'C050',13,'C054',15,'C055',16,'C048',17) PLINEORDER
          FROM COM_BASE_PLINE T
         WHERE T.PROCESS_CODE IN ('A', 'D','F')
         AND T.PLINE_CODE IN ('C001', 'C003', 'C008', 'C009', 'C010', 'C017')
         UNION ALL
         SELECT NULL,'合计','炼钢','A',-1 FROM DUAL
         UNION ALL
         SELECT NULL,'合计','轧管','D',5  FROM DUAL
         UNION ALL
          SELECT NULL ,'热处理小计','热处理(本部)','F1',11 FROM DUAL
          UNION ALL
          SELECT NULL,'探伤小计','热处理(本部)','F1',25 FROM DUAL
         UNION ALL
          SELECT NULL,'热处理小计','热处理(元通)','F2',32 FROM DUAL
          UNION ALL
          SELECT NULL,'探伤小计','热处理(元通)','F2',37 FROM DUAL
           UNION ALL
          SELECT NULL,'热处理小计','热处理(深加工)','F3',43 FROM DUAL
          UNION ALL
          SELECT NULL,'探伤小计','热处理(深加工)','F3',53 FROM DUAL
         UNION ALL
         SELECT * FROM T01
         )ta,
         (
          SELECT NULL ZCNB,NULL ZCWB,NULL YCNB,NULL YCWB,NULL TJTIMETOTAL,NULL TIMETOTAL,NULL YXNB,NULL YXZH,NULL DAYZYL,
                  NULL ZCNBDAY,NULL ZCWBDAY,NULL YCNBDAY,NULL YCWBDAY,NULL TJTIMETOTALDAY,NULL TIMETOTALDAY,NULL YXNBDAY,NULL YXZHDAY,NULL DAYZYLDAY
          FROM DUAL
         )tb
      ),
/**********************************炼钢时间范围查询**************************************/
T10 AS
       (SELECT SUM(TJTIME) AS TJTIME, PLINENAME, TJREASON
          FROM (SELECT T10.CONTROL_ID,
                       T10.STOP_REASON,
                       T10.LOGS_BEG,
                       T10.LOGS_END,
                       (TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                       TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                       (SELECT BASENAME
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T10.STOP_TYPE) STOPTYPE,
                       (SELECT PROPERA
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T10.STOP_REASON) STOPREASON,
                       (SELECT PLINE_NAME
                          FROM COM_BASE_PLINE
                         WHERE PLINE_CODE = T10.EF_PLINE_CODE) PLINENAME,
                       CASE
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '内部原因' THEN
                          'ZCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '外部原因' THEN
                          'ZCWB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '内部原因' THEN
                          'YCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '外部原因' THEN
                          'YCWB'
                       END TJREASON
                  FROM STL_CONTROL_LOG T10
                 WHERE T10.PRO_TYPE = '2'
                  AND TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                       TO_DATE('#LASTDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
                   AND TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
                       TO_DATE('#BGEINDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
                   AND T10.STOP_TYPE IN ('300101', '300102')
                   AND T10.EF_PLINE_CODE IN ('C001', 'C003')
                   AND EXISTS (SELECT *
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T10.STOP_REASON
                           AND VALIDFLAG = '1')) TA
         GROUP BY TA.PLINENAME, TA.TJREASON),    
      T11 AS
       (SELECT 'A' PROCESS_CODE, 
               PLINENAME,
               MAX(DECODE(TJREASON, 'ZCNB', TJTIME, NULL)) AS ZCNB,
               MAX(DECODE(TJREASON, 'ZCWB', TJTIME, NULL)) AS ZCWB,
               MAX(DECODE(TJREASON, 'YCNB', TJTIME, NULL)) AS YCNB,
               MAX(DECODE(TJREASON, 'YCWB', TJTIME, NULL)) AS YCWB,
               SUM(TJTIME) TJTIMETOTAL,
               24 * 60 * #DAYS# TIMETOTAL
          FROM T10
         GROUP BY PLINENAME),
/**********************************炼钢日范围查询**************************************/  
      T12 AS
       (SELECT SUM(TJTIME) AS TJTIME, PLINENAME, TJREASON
          FROM (SELECT T10.CONTROL_ID,
                       T10.STOP_REASON,
                       T10.LOGS_BEG,
                       T10.LOGS_END,
                       (TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                       TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                       (SELECT BASENAME
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T10.STOP_TYPE) STOPTYPE,
                       (SELECT PROPERA
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T10.STOP_REASON) STOPREASON,
                       (SELECT PLINE_NAME
                          FROM COM_BASE_PLINE
                         WHERE PLINE_CODE = T10.EF_PLINE_CODE) PLINENAME,
                       CASE
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '内部原因' THEN
                          'ZCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '外部原因' THEN
                          'ZCWB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '内部原因' THEN
                          'YCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '外部原因' THEN
                          'YCWB'
                       END TJREASON
                  FROM STL_CONTROL_LOG T10
                 WHERE T10.PRO_TYPE = '2'
                  AND TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                       TO_DATE('#ENDDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
                   AND TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
                       TO_DATE('#BGEINDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
                   AND T10.STOP_TYPE IN ('300101', '300102')
                   AND T10.EF_PLINE_CODE IN ('C001', 'C003')
                   AND EXISTS (SELECT *
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T10.STOP_REASON
                           AND VALIDFLAG = '1')) TA
         GROUP BY TA.PLINENAME, TA.TJREASON),
      T13 AS
       (SELECT 'A' PROCESS_CODE,
               PLINENAME ,
               MAX(DECODE(TJREASON, 'ZCNB', TJTIME, NULL)) AS ZCNBDAY,
               MAX(DECODE(TJREASON, 'ZCWB', TJTIME, NULL)) AS ZCWBDAY,
               MAX(DECODE(TJREASON, 'YCNB', TJTIME, NULL)) AS YCNBDAY,
               MAX(DECODE(TJREASON, 'YCWB', TJTIME, NULL)) AS YCWBDAY,
               SUM(TJTIME) TJTIMETOTALDAY,
               24 * 60 TIMETOTALDAY
          FROM T12
         GROUP BY PLINENAME),
     /********炼钢累计数值*******/
     T14 AS
     (
      SELECT * FROM T11
      UNION ALL
      SELECT 'A' PROCESS_CODE ,'合计' PLINENAME,SUM(ZCNB) ZCNB,SUM(ZCWB)ZCWB,SUM(YCNB) YCNB,SUM(YCWB) YCWB,
      SUM(TJTIMETOTAL) TJTIMETOTAL,SUM(TIMETOTAL) TIMETOTAL FROM T11
     ),
     /********炼钢日数值*******/
     T15 AS
     (
      SELECT * FROM T13
      UNION ALL
      SELECT  'A' PROCESS_CODE,'合计' PLINENAME,SUM(ZCNBDAY) ZCNBDAY,SUM(ZCWBDAY)ZCWBDAY,SUM(YCNBDAY) YCNBDAY,SUM(YCWBDAY) YCWBDAY,
      SUM(TJTIMETOTALDAY) TJTIMETOTALDAY,SUM(TIMETOTALDAY) TIMETOTALDAY FROM T13
     ),
     /**********************************轧管时间范围查询**************************************/       
       T AS
       (SELECT SUM(TJTIME) AS TJTIME, PLINENAME, TJREASON
          FROM (SELECT T.CONTROL_ID,
                       T.STOP_REASON,
                       T.LOGS_BEG,
                       T.LOGS_END,
                       (TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                       TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                       (SELECT BASENAME
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_TYPE) STOPTYPE,
                       (SELECT PROPERA
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON) STOPREASON,
                       (SELECT PLINE_NAME
                          FROM COM_BASE_PLINE
                         WHERE PLINE_CODE = T.PLINE_CODE) PLINENAME,
                       CASE
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'ZCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'ZCWB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'YCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'YCWB'
                       END TJREASON
                  FROM MIL_CONTROL_LOG T
                 WHERE T.PRO_TYPE = '2'
                   AND TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                        TO_DATE('#LASTDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
                   AND TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
                        TO_DATE('#BGEINDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
                   AND T.STOP_TYPE IN ('500601', '500602')
                   AND T.PLINE_CODE IN ('C008', 'C009', 'C010', 'C017')
                   AND EXISTS (SELECT *
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON
                           AND VALIDFLAG = '1')) TA
         GROUP BY TA.PLINENAME, TA.TJREASON),      
      T1 AS
       (SELECT 'D' PROCESS_CODE, 
               PLINENAME,
               MAX(DECODE(TJREASON, 'ZCNB', TJTIME, NULL)) AS ZCNB,
               MAX(DECODE(TJREASON, 'ZCWB', TJTIME, NULL)) AS ZCWB,
               MAX(DECODE(TJREASON, 'YCNB', TJTIME, NULL)) AS YCNB,
               MAX(DECODE(TJREASON, 'YCWB', TJTIME, NULL)) AS YCWB,
               SUM(TJTIME) TJTIMETOTAL,
               24 * 60 * #DAYS# TIMETOTAL
          FROM T
         GROUP BY PLINENAME),
/**********************************轧管日范围查询**************************************/   
      T2 AS
       (SELECT SUM(TJTIME) AS TJTIME, PLINENAME, TJREASON
          FROM (SELECT T.CONTROL_ID,
                       T.STOP_REASON,
                       T.LOGS_BEG,
                       T.LOGS_END,
                       (TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                       TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                       (SELECT BASENAME
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_TYPE) STOPTYPE,
                       (SELECT PROPERA
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON) STOPREASON,
                       (SELECT PLINE_NAME
                          FROM COM_BASE_PLINE
                         WHERE PLINE_CODE = T.PLINE_CODE) PLINENAME,
                       CASE
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'ZCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'ZCWB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'YCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'YCWB'
                       END TJREASON
                  FROM MIL_CONTROL_LOG T
                 WHERE T.PRO_TYPE = '2'
                   AND TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                       TO_DATE('#ENDDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
                   AND TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
                       TO_DATE('#BGEINDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
                   AND T.STOP_TYPE IN ('500601', '500602')
                   AND T.PLINE_CODE IN ('C008', 'C009', 'C010', 'C017')
                   AND EXISTS (SELECT *
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON
                           AND VALIDFLAG = '1')) TA
         GROUP BY TA.PLINENAME, TA.TJREASON),
      T3 AS
       (SELECT  'D' PROCESS_CODE, 
               PLINENAME ,
               MAX(DECODE(TJREASON, 'ZCNB', TJTIME, NULL)) AS ZCNBDAY,
               MAX(DECODE(TJREASON, 'ZCWB', TJTIME, NULL)) AS ZCWBDAY,
               MAX(DECODE(TJREASON, 'YCNB', TJTIME, NULL)) AS YCNBDAY,
               MAX(DECODE(TJREASON, 'YCWB', TJTIME, NULL)) AS YCWBDAY,
               SUM(TJTIME) TJTIMETOTALDAY,
               24 * 60 TIMETOTALDAY
          FROM T2
         GROUP BY PLINENAME),
     /********轧管累计数值*******/
     T4 AS
     (
      SELECT * FROM T1
      UNION ALL
      SELECT 'D' PROCESS_CODE ,'合计' PLINENAME,SUM(ZCNB) ZCNB,SUM(ZCWB)ZCWB,SUM(YCNB) YCNB,SUM(YCWB) YCWB,
      SUM(TJTIMETOTAL) TJTIMETOTAL,SUM(TIMETOTAL) TIMETOTAL FROM T1
     ),
     /********轧管日数值*******/
     T5 AS
     (
      SELECT * FROM T3
      UNION ALL
      SELECT  'D' PROCESS_CODE,'合计' PLINENAME,SUM(ZCNBDAY) ZCNBDAY,SUM(ZCWBDAY)ZCWBDAY,SUM(YCNBDAY) YCNBDAY,SUM(YCWBDAY) YCWBDAY,
      SUM(TJTIMETOTALDAY) TJTIMETOTALDAY,SUM(TIMETOTALDAY) TIMETOTALDAY FROM T3
     ),
      /**********************************热处理时间范围查询**************************************/       
       T30 AS
       (SELECT SUM(TJTIME) AS TJTIME, PLINENAME || DECODE(STATION,'0','(热处理)','1','(探伤)') PLINENAME, TJREASON,PLINE_CODE,STATION
          FROM (SELECT T.CONTROL_ID,
                       T.STOP_REASON,
                       T.LOGS_BEG,
                       T.LOGS_END,
                       (TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                       TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                       (SELECT BASENAME
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_TYPE) STOPTYPE,
                       (SELECT PROPERA
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON) STOPREASON,
                       (SELECT PLINE_NAME
                          FROM COM_BASE_PLINE
                         WHERE PLINE_CODE = T.PLINE_CODE) PLINENAME,
                       CASE
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'ZCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'ZCWB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'YCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'YCWB'
                       END TJREASON,
                       PLINE_CODE,
                       STATION
                  FROM (SELECT T.CONTROL_ID,
                         T.LOGS_BEG,
                         T.LOGS_END,
                         T.PLINE_CODE,
                         T.STOP_TYPE,
                         T.STOP_REASON,
                         T.STOP_SMALL,
                         T.STATION
                    FROM HTT_CONTROL_LOG T
                    --, HTT_CONTROL_LOG_DETAIL T1
                    WHERE T.PRO_TYPE = '2'
                    --AND T.CONTROL_ID = T1.CONTROL_ID
                    AND TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                        TO_DATE('#LASTDATE#' || '2100', 'yyyy-mm-dd hh24:mi:ss')
                   AND TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
                        TO_DATE('#BGEINDATE#' || '2100', 'yyyy-mm-dd hh24:mi:ss')
                   AND T.PLINE_CODE IN ('C022','C023','C024','C025','C026','C054','C055','C048')
                   AND T.STATION IN ('0','1')
                   UNION ALL
                   SELECT T.CONTROL_ID,
                         T.LOGS_BEG,
                         T.LOGS_END,
                         T.PLINE_CODE,
                         T.STOP_TYPE,
                         T.STOP_REASON,
                         T.STOP_SMALL,
                         T.STATION
                    FROM HTT_CONTROL_LOG T
                    --, HTT_CONTROL_LOG_DETAIL T1
                    WHERE T.PRO_TYPE = '2'
                    --AND T.CONTROL_ID = T1.CONTROL_ID
                    AND TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                        TO_DATE('#LASTDATE#' || '2000', 'yyyy-mm-dd hh24:mi:ss')
                   AND TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
                        TO_DATE('#BGEINDATE#' || '2000', 'yyyy-mm-dd hh24:mi:ss')
                   AND T.PLINE_CODE IN ('C049','C050')
                   AND T.STATION IN ('0','1')
                   ) T
                 WHERE 1=1
                   --AND T.STOP_TYPE IN ('500601', '500602')
                   AND EXISTS (SELECT *
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON
                           AND VALIDFLAG = '1')) TA
         GROUP BY TA.PLINENAME,TA.PLINE_CODE,TA.TJREASON,TA.STATION),      
      T31 AS
       (SELECT 
              --'F' PROCESS_CODE,
               CASE WHEN PLINE_CODE IN ('C022','C023','C024','C025','C026') THEN 'F1'
                     WHEN PLINE_CODE IN ('C049','C050') THEN 'F2'
                     WHEN PLINE_CODE IN ('C048','C054','C055') THEN 'F3'  
                     ELSE NULL END PROCESS_CODE, 
               PLINENAME,
               MAX(DECODE(TJREASON, 'ZCNB', TJTIME, NULL)) AS ZCNB,
               MAX(DECODE(TJREASON, 'ZCWB', TJTIME, NULL)) AS ZCWB,
               MAX(DECODE(TJREASON, 'YCNB', TJTIME, NULL)) AS YCNB,
               MAX(DECODE(TJREASON, 'YCWB', TJTIME, NULL)) AS YCWB,
               SUM(TJTIME) TJTIMETOTAL,
               24 * 60 * #DAYS# TIMETOTAL,
               STATION
          FROM T30
         GROUP BY PLINENAME,PLINE_CODE,STATION),
       /**********************************热处理日范围查询**************************************/   
       T32 AS
       (SELECT SUM(TJTIME) AS TJTIME, PLINENAME || DECODE(STATION,'0','(热处理)','1','(探伤)') PLINENAME, TJREASON,PLINE_CODE,STATION
          FROM (SELECT T.CONTROL_ID,
                       T.STOP_REASON,
                       T.LOGS_BEG,
                       T.LOGS_END,
                       (TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                       TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                       (SELECT BASENAME
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_TYPE) STOPTYPE,
                       (SELECT PROPERA
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON) STOPREASON,
                       (SELECT PLINE_NAME
                          FROM COM_BASE_PLINE
                         WHERE PLINE_CODE = T.PLINE_CODE) PLINENAME,
                       CASE
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'ZCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'ZCWB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'YCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'YCWB'
                       END TJREASON,
                       PLINE_CODE,
                       STATION
                  FROM (SELECT T.CONTROL_ID,
                         T.LOGS_BEG,
                         T.LOGS_END,
                         T.PLINE_CODE,
                         T.STOP_TYPE,
                         T.STOP_REASON,
                         T.STOP_SMALL,
                         T.STATION
                    FROM HTT_CONTROL_LOG T
                    --, HTT_CONTROL_LOG_DETAIL T1
                    WHERE T.PRO_TYPE = '2'
                    --AND T.CONTROL_ID = T1.CONTROL_ID
                    AND TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                        TO_DATE('#ENDDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
                   AND TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
                        TO_DATE('#BGEINDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
                   AND T.PLINE_CODE IN ('C022','C023','C024','C025','C026','C054','C055','C048')
                   AND T.STATION IN ('0','1')
                   UNION ALL
                   SELECT T.CONTROL_ID,
                         T.LOGS_BEG,
                         T.LOGS_END,
                         T.PLINE_CODE,
                         T.STOP_TYPE,
                         T.STOP_REASON,
                         T.STOP_SMALL,
                         T.STATION
                    FROM HTT_CONTROL_LOG T
                    --, HTT_CONTROL_LOG_DETAIL T1
                    WHERE T.PRO_TYPE = '2'
                    --AND T.CONTROL_ID = T1.CONTROL_ID
                    AND TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                        TO_DATE('#ENDDATE#'||'2000', 'yyyy-mm-dd hh24:mi:ss')
                   AND TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
                        TO_DATE('#BGEINDATE#'||'2000', 'yyyy-mm-dd hh24:mi:ss')
                   AND T.PLINE_CODE IN ('C049','C050')
                   AND T.STATION IN ('0','1')
                   ) T
                 WHERE 1=1
                   --AND T.STOP_TYPE IN ('500601', '500602')
                   AND EXISTS (SELECT *
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON
                           AND VALIDFLAG = '1')) TA
         GROUP BY TA.PLINENAME,TA.PLINE_CODE,TA.TJREASON,TA.STATION),            
      T33 AS
       (SELECT 
              --'F' PROCESS_CODE,
               CASE WHEN PLINE_CODE IN ('C022','C023','C024','C025','C026') THEN 'F1'
                     WHEN PLINE_CODE IN ('C049','C050') THEN 'F2'
                     WHEN PLINE_CODE IN ('C048','C054','C055') THEN 'F3'  
                     ELSE NULL END PROCESS_CODE, 
               PLINENAME,
               MAX(DECODE(TJREASON, 'ZCNB', TJTIME, NULL)) AS ZCNBDAY,
               MAX(DECODE(TJREASON, 'ZCWB', TJTIME, NULL)) AS ZCWBDAY,
               MAX(DECODE(TJREASON, 'YCNB', TJTIME, NULL)) AS YCNBDAY,
               MAX(DECODE(TJREASON, 'YCWB', TJTIME, NULL)) AS YCWBDAY,
               SUM(TJTIME) TJTIMETOTALDAY,
               24 * 60  TIMETOTALDAY,
               STATION
          FROM T32
         GROUP BY PLINENAME,PLINE_CODE,STATION),
              /********热处理累计数值*******/
     T34 AS
     (
      SELECT * FROM T31
      UNION ALL
      SELECT PROCESS_CODE ,DECODE(station,'0','热处理','1','探伤') || '小计' PLINENAME,SUM(ZCNB) ZCNB,SUM(ZCWB)ZCWB,SUM(YCNB) YCNB,SUM(YCWB) YCWB,
      SUM(TJTIMETOTAL) TJTIMETOTAL,SUM(TIMETOTAL) TIMETOTAL,STATION FROM T31 GROUP BY PROCESS_CODE,STATION
     ),
     /********热处理日数值*******/
     T35 AS
     (
      SELECT * FROM T33
      UNION ALL
      SELECT PROCESS_CODE ,DECODE(station,'0','热处理','1','探伤') || '小计' PLINENAME,SUM(ZCNBDAY) ZCNBDAY,SUM(ZCWBDAY)ZCWBDAY,SUM(YCNBDAY) YCNBDAY,SUM(YCWBDAY) YCWBDAY,
      SUM(TJTIMETOTALDAY) TJTIMETOTALDAY,SUM(TIMETOTALDAY) TIMETOTALDAY,STATION FROM T33 GROUP BY PROCESS_CODE,STATION
     ),
     T99
     AS
     (
     SELECT T00.PLINEORDER,T00.PROCESS_DESC,T00.PLINE_NAME,PLINE_CODE,
     DECODE(T00.PROCESS_CODE,'A',NVL(T14.ZCNB,T00.ZCNB),
                              'D',NVL(T4.ZCNB,T00.ZCNB),
                              'F1',NVL(T34.ZCNB,T00.ZCNB),
                              'F2',NVL(T34.ZCNB,T00.ZCNB),
                              'F3',NVL(T34.ZCNB,T00.ZCNB),
                              'F4',NVL(T34.ZCNB,T00.ZCNB),
                               T00.ZCNB) ZCNB,
     DECODE(T00.PROCESS_CODE,'A',NVL(T14.ZCWB,T00.ZCWB),
                              'D',NVL(T4.ZCWB,T00.ZCWB),
                               'F1',NVL(T34.ZCWB,T00.ZCWB),
                               'F2',NVL(T34.ZCWB,T00.ZCWB),
                               'F3',NVL(T34.ZCWB,T00.ZCWB),
                               'F4',NVL(T34.ZCWB,T00.ZCWB),
                              T00.ZCWB) ZCWB,
     DECODE(T00.PROCESS_CODE,'A',NVL(T14.YCNB,T00.YCNB),
                              'D',NVL(T4.YCNB,T00.YCNB),
                              'F1',NVL(T34.YCNB,T00.YCNB),
                              'F2',NVL(T34.YCNB,T00.YCNB),
                              'F3',NVL(T34.YCNB,T00.YCNB),
                              'F4',NVL(T34.YCNB,T00.YCNB),
                              T00.YCNB) YCNB,
     DECODE(T00.PROCESS_CODE,'A',NVL(T14.YCWB,T00.YCWB),
                              'D',NVL(T4.YCWB,T00.YCWB),
                              'F1',NVL(T34.YCWB,T00.YCWB),
                              'F2',NVL(T34.YCWB,T00.YCWB),
                              'F3',NVL(T34.YCWB,T00.YCWB),
                              'F4',NVL(T34.YCWB,T00.YCWB),
                              T00.YCWB) YCWB,
     DECODE(T00.PROCESS_CODE,'A',NVL(T14.TJTIMETOTAL,T00.TJTIMETOTAL),
                              'D',NVL(T4.TJTIMETOTAL,T00.TJTIMETOTAL),
                              'F1',NVL(T34.TJTIMETOTAL,T00.TJTIMETOTAL),
                              'F2',NVL(T34.TJTIMETOTAL,T00.TJTIMETOTAL),
                              'F3',NVL(T34.TJTIMETOTAL,T00.TJTIMETOTAL),
                              'F4',NVL(T34.TJTIMETOTAL,T00.TJTIMETOTAL),
                              T00.TJTIMETOTAL) TJTIMETOTAL,
     DECODE(T00.PROCESS_CODE,'A',NVL(T14.TIMETOTAL,T00.TIMETOTAL),
                              'D',NVL(T4.TIMETOTAL,T00.TIMETOTAL),
                              'F1',NVL(T34.TIMETOTAL,T00.TIMETOTAL),
                              'F2',NVL(T34.TIMETOTAL,T00.TIMETOTAL),
                              'F3',NVL(T34.TIMETOTAL,T00.TIMETOTAL),
                              'F4',NVL(T34.TIMETOTAL,T00.TIMETOTAL),
                              T00.TIMETOTAL) TIMETOTAL,
     YXNB,YXZH,DAYZYL,
     DECODE(T00.PROCESS_CODE,'A',NVL(T15.ZCNBDAY,T00.ZCNBDAY),
                              'D',NVL(T5.ZCNBDAY,T00.ZCNBDAY),
                              'F1',NVL(T35.ZCNBDAY,T00.ZCNBDAY),
                              'F2',NVL(T35.ZCNBDAY,T00.ZCNBDAY),
                              'F3',NVL(T35.ZCNBDAY,T00.ZCNBDAY),
                              'F4',NVL(T35.ZCNBDAY,T00.ZCNBDAY),
                              T00.ZCNBDAY) ZCNBDAY,
     DECODE(T00.PROCESS_CODE,'A',NVL(T15.ZCWBDAY,T00.ZCWBDAY),
                              'D',NVL(T5.ZCWBDAY,T00.ZCWBDAY),
                              'F1',NVL(T35.ZCWBDAY,T00.ZCWBDAY),
                              'F2',NVL(T35.ZCWBDAY,T00.ZCWBDAY),
                              'F3',NVL(T35.ZCWBDAY,T00.ZCWBDAY),
                              'F4',NVL(T35.ZCWBDAY,T00.ZCWBDAY),
                              T00.ZCWBDAY) ZCWBDAY,
     DECODE(T00.PROCESS_CODE,'A',NVL(T15.YCNBDAY,T00.YCNBDAY),
                              'D',NVL(T5.YCNBDAY,T00.YCNBDAY),
                              'F1',NVL(T35.YCNBDAY,T00.YCNBDAY),
                              'F2',NVL(T35.YCNBDAY,T00.YCNBDAY),
                              'F3',NVL(T35.YCNBDAY,T00.YCNBDAY),
                              'F4',NVL(T35.YCNBDAY,T00.YCNBDAY),
                              T00.YCNBDAY) YCNBDAY,
     DECODE(T00.PROCESS_CODE,'A',NVL(T15.YCWBDAY,T00.YCWBDAY),
                              'D',NVL(T5.YCWBDAY,T00.YCWBDAY),
                              'F1',NVL(T35.YCWBDAY,T00.YCWBDAY),
                              'F2',NVL(T35.YCWBDAY,T00.YCWBDAY),
                              'F3',NVL(T35.YCWBDAY,T00.YCWBDAY),
                              'F4',NVL(T35.YCWBDAY,T00.YCWBDAY),
                              T00.YCWBDAY) YCWBDAY,
     DECODE(T00.PROCESS_CODE,'A',NVL(T15.TJTIMETOTALDAY,T00.TJTIMETOTALDAY),
                              'D',NVL(T5.TJTIMETOTALDAY,T00.TJTIMETOTALDAY),
                              'F1',NVL(T35.TJTIMETOTALDAY,T00.TJTIMETOTALDAY),
                              'F2',NVL(T35.TJTIMETOTALDAY,T00.TJTIMETOTALDAY),
                              'F3',NVL(T35.TJTIMETOTALDAY,T00.TJTIMETOTALDAY),
                              'F4',NVL(T35.TJTIMETOTALDAY,T00.TJTIMETOTALDAY),
                              T00.TJTIMETOTALDAY) TJTIMETOTALDAY,
     DECODE(T00.PROCESS_CODE,'A',NVL(T15.TIMETOTALDAY,T00.TIMETOTALDAY),
                              'D',NVL(T5.TIMETOTALDAY,T00.TIMETOTALDAY),
                              'F1',NVL(T35.TIMETOTALDAY,T00.TIMETOTALDAY),
                              'F2',NVL(T35.TIMETOTALDAY,T00.TIMETOTALDAY),
                              'F3',NVL(T35.TIMETOTALDAY,T00.TIMETOTALDAY),
                              'F4',NVL(T35.TIMETOTALDAY,T00.TIMETOTALDAY),
                              T00.TIMETOTALDAY) TIMETOTALDAY,
     YXNBDAY,YXZHDAY,DAYZYLDAY     
     FROM T00,T14,T15,T4,T5,T34,T35
     WHERE 1=1 
     AND T00.PROCESS_CODE = T14.PROCESS_CODE(+) AND T00.PLINE_NAME = T14.PLINENAME(+)
     AND T00.PROCESS_CODE = T15.PROCESS_CODE(+) AND T00.PLINE_NAME = T15.PLINENAME(+)
     AND T00.PROCESS_CODE = T4.PROCESS_CODE(+) AND T00.PLINE_NAME = T4.PLINENAME(+)
     AND T00.PROCESS_CODE = T5.PROCESS_CODE(+) AND T00.PLINE_NAME = T5.PLINENAME(+)
     AND T00.PROCESS_CODE = T34.PROCESS_CODE(+) AND T00.PLINE_NAME = T34.PLINENAME(+)
     AND T00.PROCESS_CODE = T35.PROCESS_CODE(+) AND T00.PLINE_NAME = T35.PLINENAME(+)
     ),
     T100
     AS
     (
      SELECT PLINEORDER,PROCESS_DESC,PLINE_NAME,PLINE_CODE,ZCNB,ZCWB,YCNB,YCWB,TJTIMETOTAL,TIMETOTAL,
      CASE WHEN TJTIMETOTAL=TIMETOTAL AND TJTIMETOTAL=YCNB THEN '0.00' WHEN TJTIMETOTAL IS NULL THEN '100.00' WHEN TJTIMETOTAL=TIMETOTAL THEN '100.00'
        ELSE TO_CHAR((TIMETOTAL - NVL(TJTIMETOTAL, 0)) * 100 /(TIMETOTAL - NVL(TJTIMETOTAL, 0) + NVL(YCNB, 0)),'fm99999999999990.00') END || '%' YXNB,
      CASE WHEN TJTIMETOTAL=TIMETOTAL AND (TJTIMETOTAL=YCNB OR TJTIMETOTAL=YCWB) THEN '0.00' WHEN TJTIMETOTAL=TIMETOTAL  THEN '0.00' WHEN TJTIMETOTAL IS NULL THEN '100.00'
        ELSE TO_CHAR((TIMETOTAL - NVL(TJTIMETOTAL, 0)) * 100 /(TIMETOTAL - NVL(TJTIMETOTAL, 0) + NVL(YCNB, 0)+NVL(YCWB, 0)),'fm99999999999990.00') END || '%' YXZH,
      CASE WHEN TJTIMETOTAL=TIMETOTAL THEN '0.00' WHEN TJTIMETOTAL IS NULL THEN '100.00'
        ELSE TO_CHAR((TIMETOTAL - NVL(TJTIMETOTAL, 0)) * 100 /TIMETOTAL,'fm99999999999990.00') END || '%' DAYZYL,
      ZCNBDAY,ZCWBDAY,YCNBDAY,YCWBDAY,TJTIMETOTALDAY,TIMETOTALDAY,
      CASE WHEN TJTIMETOTALDAY=TIMETOTALDAY AND TJTIMETOTALDAY=YCNBDAY THEN '0.00' WHEN TJTIMETOTALDAY IS NULL THEN '100.00' WHEN TJTIMETOTALDAY=TIMETOTALDAY THEN '100.00' 
        ELSE TO_CHAR((TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0)) * 100 /(TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0) + NVL(YCNBDAY, 0)),'fm99999999999990.00') END || '%' YXNBDAY,
      CASE WHEN TJTIMETOTALDAY=TIMETOTALDAY AND (TJTIMETOTALDAY=YCNBDAY OR TJTIMETOTALDAY=YCWBDAY) THEN '0.00' WHEN TJTIMETOTALDAY IS NULL THEN '100.00' 
        WHEN NVL(YCNBDAY,0) + NVL(YCWBDAY,0) =0 THEN '100.00'
        ELSE TO_CHAR((TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0)) * 100 /(TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0) + NVL(YCNBDAY, 0)+NVL(YCWBDAY, 0)),'fm99999999999990.00') END || '%' YXZHDAY,
      CASE WHEN TJTIMETOTALDAY=TIMETOTALDAY THEN '0.00' WHEN TJTIMETOTALDAY IS NULL THEN '100.00' 
        ELSE TO_CHAR((TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0)) * 100 /TIMETOTALDAY,'fm99999999999990.00') END || '%' DAYZYLDAY
      
      FROM T99
     )
     SELECT PLINEORDER,
     CASE WHEN PLINE_CODE IN ('C022','C023','C024','C025','C026') THEN '热处理(本部)'
           WHEN  PLINE_CODE IN ('C049','C050') THEN '热处理(元通)'
           WHEN PLINE_CODE IN ('C048','C054','C055') THEN  '热处理(深加工)'
           ELSE PROCESS_DESC END  DEPT,
     PLINE_NAME PLINENAME,
      CASE WHEN PLINEORDER IN (6,7,8,9,10,30,31,40,41,42) THEN PLINE_CODE || '0' 
           WHEN PLINEORDER IN (20,21,22,23,24,35,36,50,51,52) THEN PLINE_CODE || '1'
              ELSE PLINE_CODE END PLINECODE,
     TO_CHAR(ZCNB/60,'fm99999999999990.00') ZCNB,
     TO_CHAR(ZCWB/60,'fm99999999999990.00') ZCWB,
     TO_CHAR(YCNB/60,'fm99999999999990.00') YCNB,
     TO_CHAR(YCWB/60,'fm99999999999990.00') YCWB,
     TO_CHAR(TJTIMETOTAL/60,'fm99999999999990.00') TJTIMETOTAL,
     TIMETOTAL,
     YXNB,YXZH,DAYZYL,
     TO_CHAR(ZCNBDAY/60,'fm99999999999990.00') ZCNBDAY,
     TO_CHAR(ZCWBDAY/60,'fm99999999999990.00')    ZCWBDAY,
     TO_CHAR(YCNBDAY/60,'fm99999999999990.00') YCNBDAY,
     TO_CHAR(YCWBDAY/60,'fm99999999999990.00')  YCWBDAY,
     TO_CHAR(TJTIMETOTALDAY/60,'fm99999999999990.00') TJTIMETOTALDAY,
     TIMETOTALDAY,
     YXNBDAY,YXZHDAY,DAYZYLDAY
     FROM T100
     ORDER BY PLINEORDER
	]]>
	</query>
	<query id="BuyGpDAL.selectRptDaySCKB4" desc="日生产运行快报（总调）数据">
	<![CDATA[
	WITH 
/**********************************形成表结构**************************************/
T00 AS
      (
       SELECT * FROM
        (
        SELECT T.PLINE_CODE,
               T.PLINE_NAME,
               DECODE(T.PROCESS_DESC, '轧制', '轧管', T.PROCESS_DESC) PROCESS_DESC,
               CASE WHEN T.PLINE_CODE IN ('C022','C023','C024','C025','C026') THEN 'F1'
                     WHEN T.PLINE_CODE IN ('C049','C050') THEN 'F2'
                     WHEN T.PLINE_CODE IN ('C054','C055','C048') THEN 'F3'
                     ELSE T.PROCESS_CODE END PROCESS_CODE,
               DECODE(T.PLINE_CODE,'C001',-5,'C003',-4,'C008',1,'C009',2,'C010',3,'C017',4,'C022',6,'C023',7,'C024',8,'C025',9,
                                    'C026',10,'C049',12,'C050',13,'C054',15,'C055',16,'C048',17) PLINEORDER
          FROM COM_BASE_PLINE T
         WHERE T.PROCESS_CODE IN ('A', 'D','F')
         AND T.PLINE_CODE IN ('C001', 'C003', 'C008', 'C009', 'C010', 'C017','C022','C023','C024','C025','C026','C049','C050','C054','C055','C048')
         UNION ALL
         SELECT NULL,'合计','炼钢','A',-1 FROM DUAL
         UNION ALL
         SELECT NULL,'合计','轧管','D',5  FROM DUAL
         UNION ALL
         SELECT NULL,'合计','本部','F',11 FROM DUAL
         UNION ALL
         SELECT NULL,'合计','元通','F',14  FROM DUAL
          UNION ALL
         SELECT NULL,'合计','深加工','F',18  FROM DUAL
         )ta,
         (
          SELECT NULL ZCNB,NULL ZCWB,NULL YCNB,NULL YCWB,NULL TJTIMETOTAL,NULL TIMETOTAL,NULL YXNB,NULL YXZH,NULL DAYZYL,
                  NULL ZCNBDAY,NULL ZCWBDAY,NULL YCNBDAY,NULL YCWBDAY,NULL TJTIMETOTALDAY,NULL TIMETOTALDAY,NULL YXNBDAY,NULL YXZHDAY,NULL DAYZYLDAY
          FROM DUAL
         )tb
      ),
/**********************************炼钢时间范围查询**************************************/
T10 AS
       (SELECT SUM(TJTIME) AS TJTIME, PLINENAME, TJREASON
          FROM (SELECT T10.CONTROL_ID,
                       T10.STOP_REASON,
                       T10.LOGS_BEG,
                       T10.LOGS_END,
                       (TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                       TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                       (SELECT BASENAME
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T10.STOP_TYPE) STOPTYPE,
                       (SELECT PROPERA
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T10.STOP_REASON) STOPREASON,
                       (SELECT PLINE_NAME
                          FROM COM_BASE_PLINE
                         WHERE PLINE_CODE = T10.EF_PLINE_CODE) PLINENAME,
                       CASE
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '内部原因' THEN
                          'ZCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '外部原因' THEN
                          'ZCWB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '内部原因' THEN
                          'YCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '外部原因' THEN
                          'YCWB'
                       END TJREASON
                  FROM STL_CONTROL_LOG T10
                 WHERE T10.PRO_TYPE = '2'
                  AND TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                       TO_DATE('#LASTDATE#', 'yyyy-mm-dd hh24:mi:ss')
                   AND TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
                       TO_DATE('#BGEINDATE#', 'yyyy-mm-dd hh24:mi:ss')
                   AND T10.STOP_TYPE IN ('300101', '300102')
                   AND T10.EF_PLINE_CODE IN ('C001', 'C003')
                   AND EXISTS (SELECT *
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T10.STOP_REASON
                           AND VALIDFLAG = '1')) TA
         GROUP BY TA.PLINENAME, TA.TJREASON),    
      T11 AS
       (SELECT 'A' PROCESS_CODE, 
               PLINENAME,
               MAX(DECODE(TJREASON, 'ZCNB', TJTIME, NULL)) AS ZCNB,
               MAX(DECODE(TJREASON, 'ZCWB', TJTIME, NULL)) AS ZCWB,
               MAX(DECODE(TJREASON, 'YCNB', TJTIME, NULL)) AS YCNB,
               MAX(DECODE(TJREASON, 'YCWB', TJTIME, NULL)) AS YCWB,
               SUM(TJTIME) TJTIMETOTAL,
               24 * 60 * #DAYS# TIMETOTAL
          FROM T10
         GROUP BY PLINENAME),
/**********************************炼钢日范围查询**************************************/  
      T12 AS
       (SELECT SUM(TJTIME) AS TJTIME, PLINENAME, TJREASON
          FROM (SELECT T10.CONTROL_ID,
                       T10.STOP_REASON,
                       T10.LOGS_BEG,
                       T10.LOGS_END,
                       (TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                       TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                       (SELECT BASENAME
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T10.STOP_TYPE) STOPTYPE,
                       (SELECT PROPERA
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T10.STOP_REASON) STOPREASON,
                       (SELECT PLINE_NAME
                          FROM COM_BASE_PLINE
                         WHERE PLINE_CODE = T10.EF_PLINE_CODE) PLINENAME,
                       CASE
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '内部原因' THEN
                          'ZCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '外部原因' THEN
                          'ZCWB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '内部原因' THEN
                          'YCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '外部原因' THEN
                          'YCWB'
                       END TJREASON
                  FROM STL_CONTROL_LOG T10
                 WHERE T10.PRO_TYPE = '2'
                  AND TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                       TO_DATE('#ENDDATE#', 'yyyy-mm-dd hh24:mi:ss')
                   AND TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
                       TO_DATE('#BGEINDATE#', 'yyyy-mm-dd hh24:mi:ss')
                   AND T10.STOP_TYPE IN ('300101', '300102')
                   AND T10.EF_PLINE_CODE IN ('C001', 'C003')
                   AND EXISTS (SELECT *
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T10.STOP_REASON
                           AND VALIDFLAG = '1')) TA
         GROUP BY TA.PLINENAME, TA.TJREASON),
      T13 AS
       (SELECT 'A' PROCESS_CODE,
               PLINENAME ,
               MAX(DECODE(TJREASON, 'ZCNB', TJTIME, NULL)) AS ZCNBDAY,
               MAX(DECODE(TJREASON, 'ZCWB', TJTIME, NULL)) AS ZCWBDAY,
               MAX(DECODE(TJREASON, 'YCNB', TJTIME, NULL)) AS YCNBDAY,
               MAX(DECODE(TJREASON, 'YCWB', TJTIME, NULL)) AS YCWBDAY,
               SUM(TJTIME) TJTIMETOTALDAY,
               24 * 60 TIMETOTALDAY
          FROM T12
         GROUP BY PLINENAME),
     /********炼钢累计数值*******/
     T14 AS
     (
      SELECT * FROM T11
      UNION ALL
      SELECT 'A' PROCESS_CODE ,'合计' PLINENAME,SUM(ZCNB) ZCNB,SUM(ZCWB)ZCWB,SUM(YCNB) YCNB,SUM(YCWB) YCWB,
      SUM(TJTIMETOTAL) TJTIMETOTAL,SUM(TIMETOTAL) TIMETOTAL FROM T11
     ),
     /********炼钢日数值*******/
     T15 AS
     (
      SELECT * FROM T13
      UNION ALL
      SELECT  'A' PROCESS_CODE,'合计' PLINENAME,SUM(ZCNBDAY) ZCNBDAY,SUM(ZCWBDAY)ZCWBDAY,SUM(YCNBDAY) YCNBDAY,SUM(YCWBDAY) YCWBDAY,
      SUM(TJTIMETOTALDAY) TJTIMETOTALDAY,SUM(TIMETOTALDAY) TIMETOTALDAY FROM T13
     ),
     /**********************************轧管时间范围查询**************************************/       
       T AS
       (SELECT SUM(TJTIME) AS TJTIME, PLINENAME, TJREASON
          FROM (SELECT T.CONTROL_ID,
                       T.STOP_REASON,
                       T.LOGS_BEG,
                       T.LOGS_END,
                       (TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                       TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                       (SELECT BASENAME
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_TYPE) STOPTYPE,
                       (SELECT PROPERA
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON) STOPREASON,
                       (SELECT PLINE_NAME
                          FROM COM_BASE_PLINE
                         WHERE PLINE_CODE = T.PLINE_CODE) PLINENAME,
                       CASE
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'ZCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'ZCWB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'YCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'YCWB'
                       END TJREASON
                  FROM MIL_CONTROL_LOG T
                 WHERE T.PRO_TYPE = '2'
                   AND TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                        TO_DATE('#LASTDATE#', 'yyyy-mm-dd hh24:mi:ss')
                   AND TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
                        TO_DATE('#BGEINDATE#', 'yyyy-mm-dd hh24:mi:ss')
                   AND T.STOP_TYPE IN ('500601', '500602')
                   AND T.PLINE_CODE IN ('C008', 'C009', 'C010', 'C017')
                   AND EXISTS (SELECT *
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON
                           AND VALIDFLAG = '1')) TA
         GROUP BY TA.PLINENAME, TA.TJREASON),      
      T1 AS
       (SELECT 'D' PROCESS_CODE, 
               PLINENAME,
               MAX(DECODE(TJREASON, 'ZCNB', TJTIME, NULL)) AS ZCNB,
               MAX(DECODE(TJREASON, 'ZCWB', TJTIME, NULL)) AS ZCWB,
               MAX(DECODE(TJREASON, 'YCNB', TJTIME, NULL)) AS YCNB,
               MAX(DECODE(TJREASON, 'YCWB', TJTIME, NULL)) AS YCWB,
               SUM(TJTIME) TJTIMETOTAL,
               24 * 60 * #DAYS# TIMETOTAL
          FROM T
         GROUP BY PLINENAME),
/**********************************轧管日范围查询**************************************/   
      T2 AS
       (SELECT SUM(TJTIME) AS TJTIME, PLINENAME, TJREASON
          FROM (SELECT T.CONTROL_ID,
                       T.STOP_REASON,
                       T.LOGS_BEG,
                       T.LOGS_END,
                       (TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                       TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                       (SELECT BASENAME
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_TYPE) STOPTYPE,
                       (SELECT PROPERA
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON) STOPREASON,
                       (SELECT PLINE_NAME
                          FROM COM_BASE_PLINE
                         WHERE PLINE_CODE = T.PLINE_CODE) PLINENAME,
                       CASE
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'ZCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'ZCWB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'YCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'YCWB'
                       END TJREASON
                  FROM MIL_CONTROL_LOG T
                 WHERE T.PRO_TYPE = '2'
                   AND TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                       TO_DATE('#ENDDATE#', 'yyyy-mm-dd hh24:mi:ss')
                   AND TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
                       TO_DATE('#BGEINDATE#', 'yyyy-mm-dd hh24:mi:ss')
                   AND T.STOP_TYPE IN ('500601', '500602')
                   AND T.PLINE_CODE IN ('C008', 'C009', 'C010', 'C017')
                   AND EXISTS (SELECT *
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON
                           AND VALIDFLAG = '1')) TA
         GROUP BY TA.PLINENAME, TA.TJREASON),
      T3 AS
       (SELECT  'D' PROCESS_CODE, 
               PLINENAME ,
               MAX(DECODE(TJREASON, 'ZCNB', TJTIME, NULL)) AS ZCNBDAY,
               MAX(DECODE(TJREASON, 'ZCWB', TJTIME, NULL)) AS ZCWBDAY,
               MAX(DECODE(TJREASON, 'YCNB', TJTIME, NULL)) AS YCNBDAY,
               MAX(DECODE(TJREASON, 'YCWB', TJTIME, NULL)) AS YCWBDAY,
               SUM(TJTIME) TJTIMETOTALDAY,
               24 * 60 TIMETOTALDAY
          FROM T2
         GROUP BY PLINENAME),
     /********轧管累计数值*******/
     T4 AS
     (
      SELECT * FROM T1
      UNION ALL
      SELECT 'D' PROCESS_CODE ,'合计' PLINENAME,SUM(ZCNB) ZCNB,SUM(ZCWB)ZCWB,SUM(YCNB) YCNB,SUM(YCWB) YCWB,
      SUM(TJTIMETOTAL) TJTIMETOTAL,SUM(TIMETOTAL) TIMETOTAL FROM T1
     ),
     /********轧管日数值*******/
     T5 AS
     (
      SELECT * FROM T3
      UNION ALL
      SELECT  'D' PROCESS_CODE,'合计' PLINENAME,SUM(ZCNBDAY) ZCNBDAY,SUM(ZCWBDAY)ZCWBDAY,SUM(YCNBDAY) YCNBDAY,SUM(YCWBDAY) YCWBDAY,
      SUM(TJTIMETOTALDAY) TJTIMETOTALDAY,SUM(TIMETOTALDAY) TIMETOTALDAY FROM T3
     ),
     /**********************************热处理时间范围查询**************************************/       
       T30 AS
       (SELECT SUM(TJTIME) AS TJTIME, PLINENAME, TJREASON
          FROM (SELECT T.CONTROL_ID,
                       T.STOP_REASON,
                       T.LOGS_BEG,
                       T.LOGS_END,
                       (TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                       TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                       (SELECT BASENAME
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_TYPE) STOPTYPE,
                       (SELECT PROPERA
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON) STOPREASON,
                       (SELECT PLINE_NAME
                          FROM COM_BASE_PLINE
                         WHERE PLINE_CODE = T.PLINE_CODE) PLINENAME,
                       CASE
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'ZCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'ZCWB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'YCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'YCWB'
                       END TJREASON
                  FROM  (SELECT t1.control_id,t1.logs_beg,t1.logs_end,
						 t.pline_code,t1.stop_type,t1.stop_reason,t1.stop_small
						 FROM HTT_CONTROL_LOG t,HTT_CONTROL_LOG_DETAIL t1
						WHERE t.pro_type ='2' AND t.control_id = t1.control_id
						AND TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                        TO_DATE('#LASTDATE#', 'yyyy-mm-dd hh24:mi:ss')
                   AND TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
                        TO_DATE('#BGEINDATE#', 'yyyy-mm-dd hh24:mi:ss')
                   AND t.pline_code IN ('C022','C023','C024','C025','C026','C049','C050','C054','C055','C048')) T
                 WHERE 1=1
                   AND EXISTS (SELECT *
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON
                           AND VALIDFLAG = '1')) TA
         GROUP BY TA.PLINENAME, TA.TJREASON),      
      T31 AS
       (SELECT 'F' PROCESS_CODE, 
               PLINENAME,
               MAX(DECODE(TJREASON, 'ZCNB', TJTIME, NULL)) AS ZCNB,
               MAX(DECODE(TJREASON, 'ZCWB', TJTIME, NULL)) AS ZCWB,
               MAX(DECODE(TJREASON, 'YCNB', TJTIME, NULL)) AS YCNB,
               MAX(DECODE(TJREASON, 'YCWB', TJTIME, NULL)) AS YCWB,
               SUM(TJTIME) TJTIMETOTAL,
               24 * 60 * 8 TIMETOTAL
          FROM T30
         GROUP BY PLINENAME),
/**********************************热处理日范围查询**************************************/   
      T32 AS
       (SELECT SUM(TJTIME) AS TJTIME, PLINENAME, TJREASON
          FROM (SELECT T.CONTROL_ID,
                       T.STOP_REASON,
                       T.LOGS_BEG,
                       T.LOGS_END,
                       (TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                       TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                       (SELECT BASENAME
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_TYPE) STOPTYPE,
                       (SELECT PROPERA
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON) STOPREASON,
                       (SELECT PLINE_NAME
                          FROM COM_BASE_PLINE
                         WHERE PLINE_CODE = T.PLINE_CODE) PLINENAME,
                       CASE
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'ZCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'ZCWB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'YCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'YCWB'
                       END TJREASON
                  FROM  (SELECT t1.control_id,t1.logs_beg,t1.logs_end,
						 t.pline_code,t1.stop_type,t1.stop_reason,t1.stop_small
						 FROM HTT_CONTROL_LOG t,HTT_CONTROL_LOG_DETAIL t1
						WHERE t.pro_type ='2' AND t.control_id = t1.control_id
				   AND TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                       TO_DATE('#ENDDATE#', 'yyyy-mm-dd hh24:mi:ss')
                   AND TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
                       TO_DATE('#BGEINDATE#', 'yyyy-mm-dd hh24:mi:ss')
                   AND t.pline_code IN ('C022','C023','C024','C025','C026','C049','C050','C054','C055','C048')) T
                 WHERE 1=1
                   AND EXISTS (SELECT *
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON
                           AND VALIDFLAG = '1')) TA
         GROUP BY TA.PLINENAME, TA.TJREASON),
      T33 AS
       (SELECT  'F' PROCESS_CODE, 
               PLINENAME ,
               MAX(DECODE(TJREASON, 'ZCNB', TJTIME, NULL)) AS ZCNBDAY,
               MAX(DECODE(TJREASON, 'ZCWB', TJTIME, NULL)) AS ZCWBDAY,
               MAX(DECODE(TJREASON, 'YCNB', TJTIME, NULL)) AS YCNBDAY,
               MAX(DECODE(TJREASON, 'YCWB', TJTIME, NULL)) AS YCWBDAY,
               SUM(TJTIME) TJTIMETOTALDAY,
               24 * 60 TIMETOTALDAY
          FROM T32
         GROUP BY PLINENAME),
     /********热处理累计数值*******/
     T34 AS
     (
      SELECT * FROM T31
      UNION ALL
      SELECT 'F' PROCESS_CODE ,'合计' PLINENAME,SUM(ZCNB) ZCNB,SUM(ZCWB)ZCWB,SUM(YCNB) YCNB,SUM(YCWB) YCWB,
      SUM(TJTIMETOTAL) TJTIMETOTAL,SUM(TIMETOTAL) TIMETOTAL FROM T31
     ),
     /********热处理日数值*******/
     T35 AS
     (
      SELECT * FROM T33
      UNION ALL
      SELECT  'F' PROCESS_CODE,'合计' PLINENAME,SUM(ZCNBDAY) ZCNBDAY,SUM(ZCWBDAY)ZCWBDAY,SUM(YCNBDAY) YCNBDAY,SUM(YCWBDAY) YCWBDAY,
      SUM(TJTIMETOTALDAY) TJTIMETOTALDAY,SUM(TIMETOTALDAY) TIMETOTALDAY FROM T3
     ),
     T99
     AS
     (
          SELECT T00.PLINEORDER,T00.PROCESS_DESC,T00.PLINE_NAME,PLINE_CODE,
     DECODE(T00.PROCESS_CODE,'A',NVL(T14.ZCNB,T00.ZCNB),'D',NVL(T4.ZCNB,T00.ZCNB),'F',NVL(T34.ZCNB,T00.ZCNB),T00.ZCNB) ZCNB,
     DECODE(T00.PROCESS_CODE,'A',NVL(T14.ZCWB,T00.ZCWB),'D',NVL(T4.ZCWB,T00.ZCWB),'F',NVL(T34.ZCWB,T00.ZCWB),T00.ZCWB) ZCWB,
     DECODE(T00.PROCESS_CODE,'A',NVL(T14.YCNB,T00.YCNB),'D',NVL(T4.YCNB,T00.YCNB),'F',NVL(T34.YCNB,T00.YCNB),T00.YCNB) YCNB,
     DECODE(T00.PROCESS_CODE,'A',NVL(T14.YCWB,T00.YCWB),'D',NVL(T4.YCWB,T00.YCWB),'F',NVL(T34.YCWB,T00.YCWB),T00.YCWB) YCWB,
     DECODE(T00.PROCESS_CODE,'A',NVL(T14.TJTIMETOTAL,T00.TJTIMETOTAL),'D',NVL(T4.TJTIMETOTAL,T00.TJTIMETOTAL),'F',NVL(T34.TJTIMETOTAL,T00.TJTIMETOTAL),T00.TJTIMETOTAL) TJTIMETOTAL,
     DECODE(T00.PROCESS_CODE,'A',NVL(T14.TIMETOTAL,T00.TIMETOTAL),'D',NVL(T4.TIMETOTAL,T00.TIMETOTAL),'F',NVL(T34.TIMETOTAL,T00.TIMETOTAL),T00.TIMETOTAL) TIMETOTAL,
     YXNB,YXZH,DAYZYL,
     DECODE(T00.PROCESS_CODE,'A',NVL(T15.ZCNBDAY,T00.ZCNBDAY),'D',NVL(T5.ZCNBDAY,T00.ZCNBDAY),'F',NVL(T35.ZCNBDAY,T00.ZCNBDAY),T00.ZCNBDAY) ZCNBDAY,
     DECODE(T00.PROCESS_CODE,'A',NVL(T15.ZCWBDAY,T00.ZCWBDAY),'D',NVL(T5.ZCWBDAY,T00.ZCWBDAY),'F',NVL(T35.ZCWBDAY,T00.ZCWBDAY),T00.ZCWBDAY) ZCWBDAY,
     DECODE(T00.PROCESS_CODE,'A',NVL(T15.YCNBDAY,T00.YCNBDAY),'D',NVL(T5.YCNBDAY,T00.YCNBDAY),'F',NVL(T35.YCNBDAY,T00.YCNBDAY),T00.YCNBDAY) YCNBDAY,
     DECODE(T00.PROCESS_CODE,'A',NVL(T15.YCWBDAY,T00.YCWBDAY),'D',NVL(T5.YCWBDAY,T00.YCWBDAY),'F',NVL(T5.YCWBDAY,T00.YCWBDAY),T00.YCWBDAY) YCWBDAY,
     DECODE(T00.PROCESS_CODE,'A',NVL(T15.TJTIMETOTALDAY,T00.TJTIMETOTALDAY),'D',NVL(T5.TJTIMETOTALDAY,T00.TJTIMETOTALDAY),'F',NVL(T35.TJTIMETOTALDAY,T00.TJTIMETOTALDAY),T00.TJTIMETOTALDAY) TJTIMETOTALDAY,
     DECODE(T00.PROCESS_CODE,'A',NVL(T15.TIMETOTALDAY,T00.TIMETOTALDAY),'D',NVL(T5.TIMETOTALDAY,T00.TIMETOTALDAY),'F',NVL(T35.TIMETOTALDAY,T00.TIMETOTALDAY),T00.TIMETOTALDAY) TIMETOTALDAY,
     YXNBDAY,YXZHDAY,DAYZYLDAY     
     FROM T00,T14,T15,T4,T5,T34,T35
     WHERE 1=1 
     AND T00.PROCESS_CODE = T14.PROCESS_CODE(+) AND T00.PLINE_NAME = T14.PLINENAME(+)
     AND T00.PROCESS_CODE = T15.PROCESS_CODE(+) AND T00.PLINE_NAME = T15.PLINENAME(+)
     AND T00.PROCESS_CODE = T4.PROCESS_CODE(+) AND T00.PLINE_NAME = T4.PLINENAME(+)
     AND T00.PROCESS_CODE = T5.PROCESS_CODE(+) AND T00.PLINE_NAME = T5.PLINENAME(+)
     AND T00.PROCESS_CODE = T34.PROCESS_CODE(+) AND T00.PLINE_NAME = T34.PLINENAME(+)
     AND T00.PROCESS_CODE = T35.PROCESS_CODE(+) AND T00.PLINE_NAME = T35.PLINENAME(+)
     ),
     T100
     AS
     (
      SELECT PLINEORDER,PROCESS_DESC,PLINE_NAME,PLINE_CODE,ZCNB,ZCWB,YCNB,YCWB,TJTIMETOTAL,TIMETOTAL,
      CASE WHEN TJTIMETOTAL=TIMETOTAL AND TJTIMETOTAL=YCNB THEN '0.00' WHEN TJTIMETOTAL IS NULL THEN '100.00' WHEN TJTIMETOTAL=TIMETOTAL THEN '100.00'
        ELSE TO_CHAR((TIMETOTAL - NVL(TJTIMETOTAL, 0)) * 100 /(TIMETOTAL - NVL(TJTIMETOTAL, 0) + NVL(YCNB, 0)),'fm99999999999990.00') END || '%' YXNB,
      CASE WHEN TJTIMETOTAL=TIMETOTAL AND (TJTIMETOTAL=YCNB OR TJTIMETOTAL=YCWB) THEN '0.00' WHEN TJTIMETOTAL IS NULL THEN '100.00'
        ELSE TO_CHAR((TIMETOTAL - NVL(TJTIMETOTAL, 0)) * 100 /(TIMETOTAL - NVL(TJTIMETOTAL, 0) + NVL(YCNB, 0)+NVL(YCWB, 0)),'fm99999999999990.00') END || '%' YXZH,
      CASE WHEN TJTIMETOTAL=TIMETOTAL THEN '0.00' WHEN TJTIMETOTAL IS NULL THEN '100.00'
        ELSE TO_CHAR((TIMETOTAL - NVL(TJTIMETOTAL, 0)) * 100 /TIMETOTAL,'fm99999999999990.00') END || '%' DAYZYL,
      ZCNBDAY,ZCWBDAY,YCNBDAY,YCWBDAY,TJTIMETOTALDAY,TIMETOTALDAY,
      CASE WHEN TJTIMETOTALDAY=TIMETOTALDAY AND TJTIMETOTALDAY=YCNBDAY THEN '0.00' WHEN TJTIMETOTALDAY IS NULL THEN '100.00' WHEN TJTIMETOTALDAY=TIMETOTALDAY THEN '100.00' 
        ELSE TO_CHAR((TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0)) * 100 /(TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0) + NVL(YCNBDAY, 0)),'fm99999999999990.00') END || '%' YXNBDAY,
      CASE WHEN TJTIMETOTALDAY=TIMETOTALDAY AND (TJTIMETOTALDAY=YCNBDAY OR TJTIMETOTALDAY=YCWBDAY) THEN '0.00' WHEN TJTIMETOTALDAY IS NULL THEN '100.00' 
        WHEN NVL(YCNBDAY,0) + NVL(YCWBDAY,0) =0 THEN '100.00'
        ELSE TO_CHAR((TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0)) * 100 /(TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0) + NVL(YCNBDAY, 0)+NVL(YCWBDAY, 0)),'fm99999999999990.00') END || '%' YXZHDAY,
      CASE WHEN TJTIMETOTALDAY=TIMETOTALDAY THEN '0.00' WHEN TJTIMETOTALDAY IS NULL THEN '100.00' 
        ELSE TO_CHAR((TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0)) * 100 /TIMETOTALDAY,'fm99999999999990.00') END || '%' DAYZYLDAY
      
      FROM T99
     )
     SELECT PLINEORDER,PROCESS_DESC DEPT,PLINE_NAME PLINENAME,PLINE_CODE PLINECODE,
     TO_CHAR(ZCNB/60,'fm99999999999990.00') ZCNB,
     TO_CHAR(ZCWB/60,'fm99999999999990.00') ZCWB,
     TO_CHAR(YCNB/60,'fm99999999999990.00') YCNB,
     TO_CHAR(YCWB/60,'fm99999999999990.00') YCWB,
     TO_CHAR(TJTIMETOTAL/60,'fm99999999999990.00') TJTIMETOTAL,
     TIMETOTAL,
     YXNB,YXZH,DAYZYL,
     TO_CHAR(ZCNBDAY/60,'fm99999999999990.00') ZCNBDAY,
     TO_CHAR(ZCWBDAY/60,'fm99999999999990.00')    ZCWBDAY,
     TO_CHAR(YCNBDAY/60,'fm99999999999990.00') YCNBDAY,
     TO_CHAR(YCWBDAY/60,'fm99999999999990.00')  YCWBDAY,
     TO_CHAR(TJTIMETOTALDAY/60,'fm99999999999990.00') TJTIMETOTALDAY,
     TIMETOTALDAY,
     YXNBDAY,YXZHDAY,DAYZYLDAY
     FROM T100
     ORDER BY PLINEORDER
	
	]]>
	</query>
	<query id="BuyGpDAL.selectRptDaySCKB3" desc="日生产运行快报（总调）数据">
	<![CDATA[
	WITH 
/**********************************形成表结构**************************************/
T00 AS
      (
       SELECT * FROM
        (
        SELECT T.PLINE_CODE,
               T.PLINE_NAME,
               DECODE(T.PROCESS_DESC, '轧制', '轧管', T.PROCESS_DESC) PROCESS_DESC,
               T.PROCESS_CODE,
               DECODE(T.PLINE_CODE,'C001',-5,'C003',-4,'C008',1,'C009',2,'C010',3,'C017',4) PLINEORDER
          FROM COM_BASE_PLINE T
         WHERE T.PROCESS_CODE IN ('A', 'D')
         AND T.PLINE_CODE IN ('C001', 'C003', 'C008', 'C009', 'C010', 'C017')
         UNION ALL
         SELECT NULL,'合计','炼钢','A',-1 FROM DUAL
         UNION ALL
         SELECT NULL,'合计','轧管','D',5  FROM DUAL
         )ta,
         (
          SELECT NULL ZCNB,NULL ZCWB,NULL YCNB,NULL YCWB,NULL TJTIMETOTAL,NULL TIMETOTAL,NULL YXNB,NULL YXZH,NULL DAYZYL,
                  NULL ZCNBDAY,NULL ZCWBDAY,NULL YCNBDAY,NULL YCWBDAY,NULL TJTIMETOTALDAY,NULL TIMETOTALDAY,NULL YXNBDAY,NULL YXZHDAY,NULL DAYZYLDAY
          FROM DUAL
         )tb
      ),
/**********************************炼钢时间范围查询**************************************/
T10 AS
       (SELECT SUM(TJTIME) AS TJTIME, PLINENAME, TJREASON
          FROM (SELECT T10.CONTROL_ID,
                       T10.STOP_REASON,
                       T10.LOGS_BEG,
                       T10.LOGS_END,
                       (TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                       TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                       (SELECT BASENAME
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T10.STOP_TYPE) STOPTYPE,
                       (SELECT PROPERA
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T10.STOP_REASON) STOPREASON,
                       (SELECT PLINE_NAME
                          FROM COM_BASE_PLINE
                         WHERE PLINE_CODE = T10.EF_PLINE_CODE) PLINENAME,
                       CASE
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '内部原因' THEN
                          'ZCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '外部原因' THEN
                          'ZCWB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '内部原因' THEN
                          'YCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '外部原因' THEN
                          'YCWB'
                       END TJREASON
                  FROM STL_CONTROL_LOG T10
                 WHERE T10.PRO_TYPE = '2'
                  AND TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                       TO_DATE('#LASTDATE#', 'yyyy-mm-dd hh24:mi:ss')
                   AND TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
                       TO_DATE('#BGEINDATE#', 'yyyy-mm-dd hh24:mi:ss')
                   AND T10.STOP_TYPE IN ('300101', '300102')
                   AND T10.EF_PLINE_CODE IN ('C001', 'C003')
                   AND EXISTS (SELECT *
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T10.STOP_REASON
                           AND VALIDFLAG = '1')) TA
         GROUP BY TA.PLINENAME, TA.TJREASON),    
      T11 AS
       (SELECT 'A' PROCESS_CODE, 
               PLINENAME,
               MAX(DECODE(TJREASON, 'ZCNB', TJTIME, NULL)) AS ZCNB,
               MAX(DECODE(TJREASON, 'ZCWB', TJTIME, NULL)) AS ZCWB,
               MAX(DECODE(TJREASON, 'YCNB', TJTIME, NULL)) AS YCNB,
               MAX(DECODE(TJREASON, 'YCWB', TJTIME, NULL)) AS YCWB,
               SUM(TJTIME) TJTIMETOTAL,
               24 * 60 * #DAYS# TIMETOTAL
          FROM T10
         GROUP BY PLINENAME),
/**********************************炼钢日范围查询**************************************/  
      T12 AS
       (SELECT SUM(TJTIME) AS TJTIME, PLINENAME, TJREASON
          FROM (SELECT T10.CONTROL_ID,
                       T10.STOP_REASON,
                       T10.LOGS_BEG,
                       T10.LOGS_END,
                       (TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                       TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                       (SELECT BASENAME
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T10.STOP_TYPE) STOPTYPE,
                       (SELECT PROPERA
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T10.STOP_REASON) STOPREASON,
                       (SELECT PLINE_NAME
                          FROM COM_BASE_PLINE
                         WHERE PLINE_CODE = T10.EF_PLINE_CODE) PLINENAME,
                       CASE
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '内部原因' THEN
                          'ZCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '外部原因' THEN
                          'ZCWB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '内部原因' THEN
                          'YCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '外部原因' THEN
                          'YCWB'
                       END TJREASON
                  FROM STL_CONTROL_LOG T10
                 WHERE T10.PRO_TYPE = '2'
                  AND TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                       TO_DATE('#ENDDATE#', 'yyyy-mm-dd hh24:mi:ss')
                   AND TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
                       TO_DATE('#BGEINDATE#', 'yyyy-mm-dd hh24:mi:ss')
                   AND T10.STOP_TYPE IN ('300101', '300102')
                   AND T10.EF_PLINE_CODE IN ('C001', 'C003')
                   AND EXISTS (SELECT *
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T10.STOP_REASON
                           AND VALIDFLAG = '1')) TA
         GROUP BY TA.PLINENAME, TA.TJREASON),
      T13 AS
       (SELECT 'A' PROCESS_CODE,
               PLINENAME ,
               MAX(DECODE(TJREASON, 'ZCNB', TJTIME, NULL)) AS ZCNBDAY,
               MAX(DECODE(TJREASON, 'ZCWB', TJTIME, NULL)) AS ZCWBDAY,
               MAX(DECODE(TJREASON, 'YCNB', TJTIME, NULL)) AS YCNBDAY,
               MAX(DECODE(TJREASON, 'YCWB', TJTIME, NULL)) AS YCWBDAY,
               SUM(TJTIME) TJTIMETOTALDAY,
               24 * 60 TIMETOTALDAY
          FROM T12
         GROUP BY PLINENAME),
     /********炼钢累计数值*******/
     T14 AS
     (
      SELECT * FROM T11
      UNION ALL
      SELECT 'A' PROCESS_CODE ,'合计' PLINENAME,SUM(ZCNB) ZCNB,SUM(ZCWB)ZCWB,SUM(YCNB) YCNB,SUM(YCWB) YCWB,
      SUM(TJTIMETOTAL) TJTIMETOTAL,SUM(TIMETOTAL) TIMETOTAL FROM T11
     ),
     /********炼钢日数值*******/
     T15 AS
     (
      SELECT * FROM T13
      UNION ALL
      SELECT  'A' PROCESS_CODE,'合计' PLINENAME,SUM(ZCNBDAY) ZCNBDAY,SUM(ZCWBDAY)ZCWBDAY,SUM(YCNBDAY) YCNBDAY,SUM(YCWBDAY) YCWBDAY,
      SUM(TJTIMETOTALDAY) TJTIMETOTALDAY,SUM(TIMETOTALDAY) TIMETOTALDAY FROM T13
     ),
     /**********************************轧管时间范围查询**************************************/       
       T AS
       (SELECT SUM(TJTIME) AS TJTIME, PLINENAME, TJREASON
          FROM (SELECT T.CONTROL_ID,
                       T.STOP_REASON,
                       T.LOGS_BEG,
                       T.LOGS_END,
                       (TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                       TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                       (SELECT BASENAME
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_TYPE) STOPTYPE,
                       (SELECT PROPERA
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON) STOPREASON,
                       (SELECT PLINE_NAME
                          FROM COM_BASE_PLINE
                         WHERE PLINE_CODE = T.PLINE_CODE) PLINENAME,
                       CASE
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'ZCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'ZCWB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'YCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'YCWB'
                       END TJREASON
                  FROM MIL_CONTROL_LOG T
                 WHERE T.PRO_TYPE = '2'
                   AND TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                        TO_DATE('#LASTDATE#', 'yyyy-mm-dd hh24:mi:ss')
                   AND TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
                        TO_DATE('#BGEINDATE#', 'yyyy-mm-dd hh24:mi:ss')
                   AND T.STOP_TYPE IN ('500601', '500602')
                   AND T.PLINE_CODE IN ('C008', 'C009', 'C010', 'C017')
                   AND EXISTS (SELECT *
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON
                           AND VALIDFLAG = '1')) TA
         GROUP BY TA.PLINENAME, TA.TJREASON),      
      T1 AS
       (SELECT 'D' PROCESS_CODE, 
               PLINENAME,
               MAX(DECODE(TJREASON, 'ZCNB', TJTIME, NULL)) AS ZCNB,
               MAX(DECODE(TJREASON, 'ZCWB', TJTIME, NULL)) AS ZCWB,
               MAX(DECODE(TJREASON, 'YCNB', TJTIME, NULL)) AS YCNB,
               MAX(DECODE(TJREASON, 'YCWB', TJTIME, NULL)) AS YCWB,
               SUM(TJTIME) TJTIMETOTAL,
               24 * 60 * #DAYS# TIMETOTAL
          FROM T
         GROUP BY PLINENAME),
/**********************************轧管日范围查询**************************************/   
      T2 AS
       (SELECT SUM(TJTIME) AS TJTIME, PLINENAME, TJREASON
          FROM (SELECT T.CONTROL_ID,
                       T.STOP_REASON,
                       T.LOGS_BEG,
                       T.LOGS_END,
                       (TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                       TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                       (SELECT BASENAME
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_TYPE) STOPTYPE,
                       (SELECT PROPERA
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON) STOPREASON,
                       (SELECT PLINE_NAME
                          FROM COM_BASE_PLINE
                         WHERE PLINE_CODE = T.PLINE_CODE) PLINENAME,
                       CASE
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'ZCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'ZCWB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'YCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'YCWB'
                       END TJREASON
                  FROM MIL_CONTROL_LOG T
                 WHERE T.PRO_TYPE = '2'
                   AND TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                       TO_DATE('#ENDDATE#', 'yyyy-mm-dd hh24:mi:ss')
                   AND TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
                       TO_DATE('#BGEINDATE#', 'yyyy-mm-dd hh24:mi:ss')
                   AND T.STOP_TYPE IN ('500601', '500602')
                   AND T.PLINE_CODE IN ('C008', 'C009', 'C010', 'C017')
                   AND EXISTS (SELECT *
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON
                           AND VALIDFLAG = '1')) TA
         GROUP BY TA.PLINENAME, TA.TJREASON),
      T3 AS
       (SELECT  'D' PROCESS_CODE, 
               PLINENAME ,
               MAX(DECODE(TJREASON, 'ZCNB', TJTIME, NULL)) AS ZCNBDAY,
               MAX(DECODE(TJREASON, 'ZCWB', TJTIME, NULL)) AS ZCWBDAY,
               MAX(DECODE(TJREASON, 'YCNB', TJTIME, NULL)) AS YCNBDAY,
               MAX(DECODE(TJREASON, 'YCWB', TJTIME, NULL)) AS YCWBDAY,
               SUM(TJTIME) TJTIMETOTALDAY,
               24 * 60 TIMETOTALDAY
          FROM T2
         GROUP BY PLINENAME),
     /********轧管累计数值*******/
     T4 AS
     (
      SELECT * FROM T1
      UNION ALL
      SELECT 'D' PROCESS_CODE ,'合计' PLINENAME,SUM(ZCNB) ZCNB,SUM(ZCWB)ZCWB,SUM(YCNB) YCNB,SUM(YCWB) YCWB,
      SUM(TJTIMETOTAL) TJTIMETOTAL,SUM(TIMETOTAL) TIMETOTAL FROM T1
     ),
     /********轧管日数值*******/
     T5 AS
     (
      SELECT * FROM T3
      UNION ALL
      SELECT  'D' PROCESS_CODE,'合计' PLINENAME,SUM(ZCNBDAY) ZCNBDAY,SUM(ZCWBDAY)ZCWBDAY,SUM(YCNBDAY) YCNBDAY,SUM(YCWBDAY) YCWBDAY,
      SUM(TJTIMETOTALDAY) TJTIMETOTALDAY,SUM(TIMETOTALDAY) TIMETOTALDAY FROM T3
     ),
     T99
     AS
     (
     SELECT T00.PLINEORDER,T00.PROCESS_DESC,T00.PLINE_NAME,PLINE_CODE,
     DECODE(T00.PROCESS_CODE,'A',NVL(T14.ZCNB,T00.ZCNB),'D',NVL(T4.ZCNB,T00.ZCNB),T00.ZCNB) ZCNB,
     DECODE(T00.PROCESS_CODE,'A',NVL(T14.ZCWB,T00.ZCWB),'D',NVL(T4.ZCWB,T00.ZCWB),T00.ZCWB) ZCWB,
     DECODE(T00.PROCESS_CODE,'A',NVL(T14.YCNB,T00.YCNB),'D',NVL(T4.YCNB,T00.YCNB),T00.YCNB) YCNB,
     DECODE(T00.PROCESS_CODE,'A',NVL(T14.YCWB,T00.YCWB),'D',NVL(T4.YCWB,T00.YCWB),T00.YCWB) YCWB,
     DECODE(T00.PROCESS_CODE,'A',NVL(T14.TJTIMETOTAL,T00.TJTIMETOTAL),'D',NVL(T4.TJTIMETOTAL,T00.TJTIMETOTAL),T00.TJTIMETOTAL) TJTIMETOTAL,
     DECODE(T00.PROCESS_CODE,'A',NVL(T14.TIMETOTAL,T00.TIMETOTAL),'D',NVL(T4.TIMETOTAL,T00.TIMETOTAL),T00.TIMETOTAL) TIMETOTAL,
     YXNB,YXZH,DAYZYL,
     DECODE(T00.PROCESS_CODE,'A',NVL(T15.ZCNBDAY,T00.ZCNBDAY),'D',NVL(T5.ZCNBDAY,T00.ZCNBDAY),T00.ZCNBDAY) ZCNBDAY,
     DECODE(T00.PROCESS_CODE,'A',NVL(T15.ZCWBDAY,T00.ZCWBDAY),'D',NVL(T5.ZCWBDAY,T00.ZCWBDAY),T00.ZCWBDAY) ZCWBDAY,
     DECODE(T00.PROCESS_CODE,'A',NVL(T15.YCNBDAY,T00.YCNBDAY),'D',NVL(T5.YCNBDAY,T00.YCNBDAY),T00.YCNBDAY) YCNBDAY,
     DECODE(T00.PROCESS_CODE,'A',NVL(T15.YCWBDAY,T00.YCWBDAY),'D',NVL(T5.YCWBDAY,T00.YCWBDAY),T00.YCWBDAY) YCWBDAY,
     DECODE(T00.PROCESS_CODE,'A',NVL(T15.TJTIMETOTALDAY,T00.TJTIMETOTALDAY),'D',NVL(T5.TJTIMETOTALDAY,T00.TJTIMETOTALDAY),T00.TJTIMETOTALDAY) TJTIMETOTALDAY,
     DECODE(T00.PROCESS_CODE,'A',NVL(T15.TIMETOTALDAY,T00.TIMETOTALDAY),'D',NVL(T5.TIMETOTALDAY,T00.TIMETOTALDAY),T00.TIMETOTALDAY) TIMETOTALDAY,
     YXNBDAY,YXZHDAY,DAYZYLDAY     
     FROM T00,T14,T15,T4,T5
     WHERE 1=1 
     AND T00.PROCESS_CODE = T14.PROCESS_CODE(+) AND T00.PLINE_NAME = T14.PLINENAME(+)
     AND T00.PROCESS_CODE = T15.PROCESS_CODE(+) AND T00.PLINE_NAME = T15.PLINENAME(+)
     AND T00.PROCESS_CODE = T4.PROCESS_CODE(+) AND T00.PLINE_NAME = T4.PLINENAME(+)
     AND T00.PROCESS_CODE = T5.PROCESS_CODE(+) AND T00.PLINE_NAME = T5.PLINENAME(+)
     ),
     T100
     AS
     (
      SELECT PLINEORDER,PROCESS_DESC,PLINE_NAME,PLINE_CODE,ZCNB,ZCWB,YCNB,YCWB,TJTIMETOTAL,TIMETOTAL,
      CASE WHEN TJTIMETOTAL=TIMETOTAL AND TJTIMETOTAL=YCNB THEN '0.00' WHEN TJTIMETOTAL IS NULL THEN '100.00' WHEN TJTIMETOTAL=TIMETOTAL THEN '100.00'
        ELSE TO_CHAR((TIMETOTAL - NVL(TJTIMETOTAL, 0)) * 100 /(TIMETOTAL - NVL(TJTIMETOTAL, 0) + NVL(YCNB, 0)),'fm99999999999990.00') END || '%' YXNB,
      CASE WHEN TJTIMETOTAL=TIMETOTAL AND (TJTIMETOTAL=YCNB OR TJTIMETOTAL=YCWB) THEN '0.00' WHEN TJTIMETOTAL IS NULL THEN '100.00'
        ELSE TO_CHAR((TIMETOTAL - NVL(TJTIMETOTAL, 0)) * 100 /(TIMETOTAL - NVL(TJTIMETOTAL, 0) + NVL(YCNB, 0)+NVL(YCWB, 0)),'fm99999999999990.00') END || '%' YXZH,
      CASE WHEN TJTIMETOTAL=TIMETOTAL THEN '0.00' WHEN TJTIMETOTAL IS NULL THEN '100.00'
        ELSE TO_CHAR((TIMETOTAL - NVL(TJTIMETOTAL, 0)) * 100 /TIMETOTAL,'fm99999999999990.00') END || '%' DAYZYL,
      ZCNBDAY,ZCWBDAY,YCNBDAY,YCWBDAY,TJTIMETOTALDAY,TIMETOTALDAY,
      CASE WHEN TJTIMETOTALDAY=TIMETOTALDAY AND TJTIMETOTALDAY=YCNBDAY THEN '0.00' WHEN TJTIMETOTALDAY IS NULL THEN '100.00' WHEN TJTIMETOTALDAY=TIMETOTALDAY THEN '100.00' 
        ELSE TO_CHAR((TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0)) * 100 /(TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0) + NVL(YCNBDAY, 0)),'fm99999999999990.00') END || '%' YXNBDAY,
      CASE WHEN TJTIMETOTALDAY=TIMETOTALDAY AND (TJTIMETOTALDAY=YCNBDAY OR TJTIMETOTALDAY=YCWBDAY) THEN '0.00' WHEN TJTIMETOTALDAY IS NULL THEN '100.00' 
        ELSE TO_CHAR((TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0)) * 100 /(TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0) + NVL(YCNBDAY, 0)+NVL(YCWBDAY, 0)),'fm99999999999990.00') END || '%' YXZHDAY,
      CASE WHEN TJTIMETOTALDAY=TIMETOTALDAY THEN '0.00' WHEN TJTIMETOTALDAY IS NULL THEN '100.00' 
        ELSE TO_CHAR((TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0)) * 100 /TIMETOTALDAY,'fm99999999999990.00') END || '%' DAYZYLDAY
      
      FROM T99
     )
     SELECT PLINEORDER,PROCESS_DESC DEPT,PLINE_NAME PLINENAME,PLINE_CODE PLINECODE,
     TO_CHAR(ZCNB/60,'fm99999999999990.00') ZCNB,
     TO_CHAR(ZCWB/60,'fm99999999999990.00') ZCWB,
     TO_CHAR(YCNB/60,'fm99999999999990.00') YCNB,
     TO_CHAR(YCWB/60,'fm99999999999990.00') YCWB,
     TO_CHAR(TJTIMETOTAL/60,'fm99999999999990.00') TJTIMETOTAL,
     TIMETOTAL,
     YXNB,YXZH,DAYZYL,
     TO_CHAR(ZCNBDAY/60,'fm99999999999990.00') ZCNBDAY,
     TO_CHAR(ZCWBDAY/60,'fm99999999999990.00')    ZCWBDAY,
     TO_CHAR(YCNBDAY/60,'fm99999999999990.00') YCNBDAY,
     TO_CHAR(YCWBDAY/60,'fm99999999999990.00')  YCWBDAY,
     TO_CHAR(TJTIMETOTALDAY/60,'fm99999999999990.00') TJTIMETOTALDAY,
     TIMETOTALDAY,
     YXNBDAY,YXZHDAY,DAYZYLDAY
     FROM T100
     ORDER BY PLINEORDER
	
	]]>
	</query>
	
	
	<query id="BuyGpDAL.selectRptDaySCKB2" desc="日生产运行快报（总调）数据">
	<![CDATA[
	
		

  WITH T10 AS
       (SELECT SUM(TJTIME) AS TJTIME, PLINENAME, TJREASON
          FROM (SELECT T10.CONTROL_ID,
                       T10.STOP_REASON,
                       T10.LOGS_BEG,
                       T10.LOGS_END,
                       (TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                       TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                       (SELECT BASENAME
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T10.STOP_TYPE) STOPTYPE,
                       (SELECT PROPERA
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T10.STOP_REASON) STOPREASON,
                       (SELECT PLINE_NAME
                          FROM COM_BASE_PLINE
                         WHERE PLINE_CODE = T10.EF_PLINE_CODE) PLINENAME,
                       CASE
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '内部原因' THEN
                          'ZCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '外部原因' THEN
                          'ZCWB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '内部原因' THEN
                          'YCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '外部原因' THEN
                          'YCWB'
                       END TJREASON
                  FROM STL_CONTROL_LOG T10
                 WHERE T10.PRO_TYPE = '2'
                  AND TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
			                 TO_DATE('#LASTDATE#', 'yyyy-mm-dd hh24:mi:ss')
			             AND TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
			                 TO_DATE('#BGEINDATE#', 'yyyy-mm-dd hh24:mi:ss')
                   AND T10.STOP_TYPE IN ('300101', '300102')
                   AND T10.EF_PLINE_CODE IN ('C001', 'C003')
                   AND EXISTS (SELECT *
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T10.STOP_REASON
                           AND VALIDFLAG = '1')) TA
         GROUP BY TA.PLINENAME, TA.TJREASON),
      T11 AS
       (SELECT PLINENAME,
               MAX(DECODE(TJREASON, 'ZCNB', TJTIME, NULL)) AS ZCNB,
               MAX(DECODE(TJREASON, 'ZCWB', TJTIME, NULL)) AS ZCWB,
               MAX(DECODE(TJREASON, 'YCNB', TJTIME, NULL)) AS YCNB,
               MAX(DECODE(TJREASON, 'YCWB', TJTIME, NULL)) AS YCWB,
               SUM(TJTIME) TJTIMETOTAL,
               24 * 60 * #DAYS# TIMETOTAL,
               DECODE(PLINENAME,
                      '一炼钢电炉',
                      -5,
                      '二炼钢电炉',
                      -4,
                      -1) PLINEORDER
          FROM T10
         GROUP BY PLINENAME),
      T12 AS
       (SELECT SUM(TJTIME) AS TJTIME, PLINENAME, TJREASON
          FROM (SELECT T10.CONTROL_ID,
                       T10.STOP_REASON,
                       T10.LOGS_BEG,
                       T10.LOGS_END,
                       (TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                       TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                       (SELECT BASENAME
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T10.STOP_TYPE) STOPTYPE,
                       (SELECT PROPERA
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T10.STOP_REASON) STOPREASON,
                       (SELECT PLINE_NAME
                          FROM COM_BASE_PLINE
                         WHERE PLINE_CODE = T10.EF_PLINE_CODE) PLINENAME,
                       CASE
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '内部原因' THEN
                          'ZCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '外部原因' THEN
                          'ZCWB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '内部原因' THEN
                          'YCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T10.STOP_TYPE) = '外部原因' THEN
                          'YCWB'
                       END TJREASON
                  FROM STL_CONTROL_LOG T10
                 WHERE T10.PRO_TYPE = '2'
                  AND TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
			                 TO_DATE('#ENDDATE#', 'yyyy-mm-dd hh24:mi:ss')
			             AND TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
			                 TO_DATE('#BGEINDATE#', 'yyyy-mm-dd hh24:mi:ss')
                   AND T10.STOP_TYPE IN ('300101', '300102')
                   AND T10.EF_PLINE_CODE IN ('C001', 'C003')
                   AND EXISTS (SELECT *
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T10.STOP_REASON
                           AND VALIDFLAG = '1')) TA
         GROUP BY TA.PLINENAME, TA.TJREASON),
      T13 AS
       (SELECT PLINENAME PLINENAME1,
               MAX(DECODE(TJREASON, 'ZCNB', TJTIME, NULL)) AS ZCNBDAY,
               MAX(DECODE(TJREASON, 'ZCWB', TJTIME, NULL)) AS ZCWBDAY,
               MAX(DECODE(TJREASON, 'YCNB', TJTIME, NULL)) AS YCNBDAY,
               MAX(DECODE(TJREASON, 'YCWB', TJTIME, NULL)) AS YCWBDAY,
               SUM(TJTIME) TJTIMETOTALDAY,
               24 * 60 TIMETOTALDAY,
                 DECODE(PLINENAME,
                      '一炼钢电炉',
                      -5,
                      '二炼钢电炉',
                      -4,
                      -1) PLINEORDER1
          FROM T12
         GROUP BY PLINENAME),
      T14 AS
       (SELECT T13.*,
               CASE
                 WHEN TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0) = 0 THEN
                  '0.00'
                 ELSE
                  TO_CHAR(ROUND((TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0)) * 100 /
                                (TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0) +
                                NVL(YCNBDAY, 0)),
                                2),
                          'fm99999999999990.00')
               END || '%' YXNBDAY,
               CASE
                 WHEN TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0) = 0 THEN
                  '0.00'
                 ELSE
                  TO_CHAR(ROUND((TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0)) * 100 /
                                (TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0) +
                                NVL(YCNBDAY, 0) + NVL(YCWBDAY, 0)),
                                2),
                          'fm99999999999990.00')
               END || '%' YXZHDAY,
               CASE
                 WHEN TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0) = 0 THEN
                  '0.00'
                 ELSE
                  TO_CHAR(ROUND((TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0)) * 100 /
                                TIMETOTALDAY,
                                2),
                          'fm99999999999990.00')
               END  DAYZYLDAY
          FROM T13),
      T15 AS
       (
        SELECT '炼钢' AS DEPT,
               PLINENAME,
               TO_CHAR(ZCNB) ZCNB,
               TO_CHAR(ZCWB) ZCWB,
               TO_CHAR(YCNB) YCNB,
               TO_CHAR(YCWB) YCWB,
               TJTIMETOTAL,
               TO_CHAR(ROUND(TJTIMETOTAL / 60, 2), 'fm99999999999990.00') TJTIMEHOURS,
               TO_CHAR(ROUND((TIMETOTAL - NVL(TJTIMETOTAL, 0)) * 100 /
                             (TIMETOTAL - NVL(TJTIMETOTAL, 0) + NVL(YCNB, 0)),
                             2),
                       'fm99999999999990.00') || '%' YXNB,
               TO_CHAR(ROUND((TIMETOTAL - NVL(TJTIMETOTAL, 0)) * 100 /
                             (TIMETOTAL - NVL(TJTIMETOTAL, 0) + NVL(YCNB, 0) +
                             NVL(YCWB, 0)),
                             2),
                       'fm99999999999990.00') || '%' YXZH,
               TO_CHAR(ROUND((TIMETOTAL - NVL(TJTIMETOTAL, 0)) * 100 / TIMETOTAL,
                             2),
                       'fm99999999999990.00') DAYZYL,
               PLINEORDER
          FROM T11
        UNION ALL
        SELECT '炼钢' AS DEPT,
               '合计' PLINENAME,
               TO_CHAR(SUM(ZCNB)) ZCNB,
               TO_CHAR(SUM(ZCWB)) ZCWB,
               TO_CHAR(SUM(YCNB)) YCNB,
               TO_CHAR(SUM(YCWB)) YCWB,
               SUM(TJTIMETOTAL),
               TO_CHAR(ROUND(SUM(TJTIMETOTAL) / 60, 2), 'fm99999999999990.00') TJTIMEHOURS,
               TO_CHAR((2*24*60*#DAYS#-ROUND(SUM(TJTIMETOTAL),0))*100/(2*24*60*#DAYS#-ROUND(SUM(TJTIMETOTAL),0)+ROUND(NVL(SUM(YCNB),0),0)), 'fm99999999999990.00') || '%' YXNB ,
               TO_CHAR((2*24*60*#DAYS#-ROUND(SUM(TJTIMETOTAL),0))*100/(2*24*60*#DAYS#-ROUND(SUM(TJTIMETOTAL),0)+ROUND(NVL(SUM(YCNB),0),0)+ROUND(NVL(SUM(YCWB),0),0)), 'fm99999999999990.00') || '%'  YXZH,
               NULL DAYZYL,
               -1 PLINEORDER
          FROM T11
         WHERE PLINENAME IS NOT NULL
          )，
            T16 AS (
               SELECT '炼钢' AS DEPT, PLINENAME1,
               TO_CHAR(ROUND(ZCNBDAY,0)) ZCNBDAY,
               TO_CHAR(ROUND(ZCWBDAY,0)) ZCWBDAY, 
               TO_CHAR(ROUND(YCNBDAY,0)) YCNBDAY,
               TO_CHAR(ROUND(YCWBDAY,0)) YCWBDAY,
               TO_CHAR(ROUND(TJTIMETOTALDAY,0)) TJTIMETOTALDAY, 
               TO_CHAR(ROUND(TIMETOTALDAY,0)) TIMETOTALDAY,
               NVL(YXNBDAY,'100.00%')YXNBDAY,NVL(YXZHDAY,'100.00%') YXZHDAY,NVL(DAYZYLDAY,'100.00%') DAYZYLDAY,
               5 AS PLINEORDER FROM T14
               UNION ALL
               SELECT '炼钢' AS DEPT,
               '合计' PLINENAME,
               TO_CHAR(ROUND(SUM(ZCNBDAY),0)) ZCNBDAY,
               TO_CHAR(ROUND(SUM(ZCWBDAY),0)) ZCWBDAY,
               TO_CHAR(ROUND(SUM(YCNBDAY),0)) YCNBDAY,
               TO_CHAR(ROUND(SUM(YCWBDAY),0)) YCWBDAY,
               TO_CHAR(ROUND(SUM(TJTIMETOTALDAY),0)) TJTIMETOTALDAY,
               TO_CHAR(ROUND(SUM(TIMETOTALDAY),0))  TJTIMEHOURS,
               TO_CHAR((24*60*2-NVL(ROUND(SUM(TJTIMETOTALDAY),0),0))*100/(24*60*2-NVL(ROUND(SUM(TJTIMETOTALDAY),0),0)+NVL(ROUND(NVL(SUM(YCNBDAY),0),0),0)), 'fm99999999999990.00') || '%' YXNBDAY,
               TO_CHAR((24*60*2-NVL(ROUND(SUM(TJTIMETOTALDAY),0),0))*100/(24*60*2-NVL(ROUND(SUM(TJTIMETOTALDAY),0),0)+NVL(ROUND(NVL(SUM(YCNBDAY),0),0),0)+NVL(ROUND(NVL(SUM(YCWBDAY),0),0),0)), 'fm99999999999990.00') || '%' YXZHDAY,
               NULL DAYZYLDAY,
               -1 PLINEORDER
          FROM T14
      ),
      T17 AS
      (
      SELECT '一炼钢电炉'  PLINENAME,100 DAYZYLDAY FROM DUAL
      UNION ALL  
      SELECT '二炼钢电炉'  PLINENAME,100 DAYZYLDAY FROM DUAL
      UNION ALL  
      SELECT '合计'  PLINENAME,100 DAYZYLDAY FROM DUAL
      ),
      T18 AS
      (
       SELECT '炼钢' AS DEPT, NVL(T16.PLINENAME1,T17.PLINENAME) PLINENAME1,T16.ZCNBDAY,T16.ZCWBDAY,T16.YCNBDAY,T16.YCWBDAY,T16.TJTIMETOTALDAY,T16.TIMETOTALDAY,
       NVL(T16.YXNBDAY,'100.00%') YXNBDAY,NVL(T16.YXZHDAY,'100.00%') YXZHDAY ,NVL(T16.DAYZYLDAY,T17.DAYZYLDAY) DAYZYLDAY,T16.PLINEORDER
       FROM T16,T17 WHERE T16.PLINENAME1(+) =T17.PLINENAME
      ),
       T AS
       (SELECT SUM(TJTIME) AS TJTIME, PLINENAME, TJREASON
          FROM (SELECT T.CONTROL_ID,
                       T.STOP_REASON,
                       T.LOGS_BEG,
                       T.LOGS_END,
                       (TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                       TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                       (SELECT BASENAME
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_TYPE) STOPTYPE,
                       (SELECT PROPERA
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON) STOPREASON,
                       (SELECT PLINE_NAME
                          FROM COM_BASE_PLINE
                         WHERE PLINE_CODE = T.PLINE_CODE) PLINENAME,
                       CASE
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'ZCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'ZCWB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'YCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'YCWB'
                       END TJREASON
                  FROM MIL_CONTROL_LOG T
                 WHERE T.PRO_TYPE = '2'
                   AND TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
			                 TO_DATE('#LASTDATE#', 'yyyy-mm-dd hh24:mi:ss')
			             AND TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
			                 TO_DATE('#BGEINDATE#', 'yyyy-mm-dd hh24:mi:ss')
                   AND T.STOP_TYPE IN ('500601', '500602')
                   AND T.PLINE_CODE IN ('C008', 'C009', 'C010', 'C017')
                   AND EXISTS (SELECT *
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON
                           AND VALIDFLAG = '1')) TA
         GROUP BY TA.PLINENAME, TA.TJREASON),
      T1 AS
       (SELECT PLINENAME,
               MAX(DECODE(TJREASON, 'ZCNB', TJTIME, NULL)) AS ZCNB,
               MAX(DECODE(TJREASON, 'ZCWB', TJTIME, NULL)) AS ZCWB,
               MAX(DECODE(TJREASON, 'YCNB', TJTIME, NULL)) AS YCNB,
               MAX(DECODE(TJREASON, 'YCWB', TJTIME, NULL)) AS YCWB,
               SUM(TJTIME) TJTIMETOTAL,
               24 * 60 * #DAYS# TIMETOTAL,
               DECODE(PLINENAME,
                      '250机组',
                      1,
                      '258机组',
                      2,
                      '168机组',
                      3,
                      '460机组',
                      4,
                      5) PLINEORDER
          FROM T
         GROUP BY PLINENAME),
      T2 AS
       (SELECT SUM(TJTIME) AS TJTIME, PLINENAME, TJREASON
          FROM (SELECT T.CONTROL_ID,
                       T.STOP_REASON,
                       T.LOGS_BEG,
                       T.LOGS_END,
                       (TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                       TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                       (SELECT BASENAME
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_TYPE) STOPTYPE,
                       (SELECT PROPERA
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON) STOPREASON,
                       (SELECT PLINE_NAME
                          FROM COM_BASE_PLINE
                         WHERE PLINE_CODE = T.PLINE_CODE) PLINENAME,
                       CASE
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'ZCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'ZCWB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
                          'YCNB'
                         WHEN (SELECT PROPERA
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
                              (SELECT BASENAME
                                 FROM COM_BASE_INFO
                                WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
                          'YCWB'
                       END TJREASON
                  FROM MIL_CONTROL_LOG T
                 WHERE T.PRO_TYPE = '2'
                   AND TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
			                 TO_DATE('#ENDDATE#', 'yyyy-mm-dd hh24:mi:ss')
			             AND TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
			                 TO_DATE('#BGEINDATE#', 'yyyy-mm-dd hh24:mi:ss')
                   AND T.STOP_TYPE IN ('500601', '500602')
                   AND T.PLINE_CODE IN ('C008', 'C009', 'C010', 'C017')
                   AND EXISTS (SELECT *
                          FROM COM_BASE_INFO
                         WHERE BASECODE = T.STOP_REASON
                           AND VALIDFLAG = '1')) TA
         GROUP BY TA.PLINENAME, TA.TJREASON),
      T3 AS
       (SELECT PLINENAME PLINENAME1,
               MAX(DECODE(TJREASON, 'ZCNB', TJTIME, NULL)) AS ZCNBDAY,
               MAX(DECODE(TJREASON, 'ZCWB', TJTIME, NULL)) AS ZCWBDAY,
               MAX(DECODE(TJREASON, 'YCNB', TJTIME, NULL)) AS YCNBDAY,
               MAX(DECODE(TJREASON, 'YCWB', TJTIME, NULL)) AS YCWBDAY,
               SUM(TJTIME) TJTIMETOTALDAY,
               24 * 60 TIMETOTALDAY,
               DECODE(PLINENAME,
                      '250机组',
                      1,
                      '258机组',
                      2,
                      '168机组',
                      3,
                      '460机组',
                      4,
                      5) PLINEORDER1
          FROM T2
         GROUP BY PLINENAME),
      T4 AS
       (SELECT T3.*,
               CASE
                 WHEN TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0) = 0 THEN
                  '0.00'
                 ELSE
                  TO_CHAR(ROUND((TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0)) * 100 /
                                (TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0) +
                                NVL(YCNBDAY, 0)),
                                2),
                          'fm99999999999990.00')
               END || '%' YXNBDAY,
               CASE
                 WHEN TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0) = 0 THEN
                  '0.00'
                 ELSE
                  TO_CHAR(ROUND((TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0)) * 100 /
                                (TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0) +
                                NVL(YCNBDAY, 0) + NVL(YCWBDAY, 0)),
                                2),
                          'fm99999999999990.00')
               END || '%' YXZHDAY,
               CASE
                 WHEN TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0) = 0 THEN
                  '0.00'
                 ELSE
                  TO_CHAR(ROUND((TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0)) * 100 /
                                TIMETOTALDAY,
                                2),
                          'fm99999999999990.00')
               END  DAYZYLDAY
          FROM T3),
      T5 AS
       (
        SELECT '轧管' AS DEPT,
               PLINENAME,
               TO_CHAR(ZCNB) ZCNB,
               TO_CHAR(ZCWB) ZCWB,
               TO_CHAR(YCNB) YCNB,
               TO_CHAR(YCWB) YCWB,
               TJTIMETOTAL,
               TO_CHAR(ROUND(TJTIMETOTAL / 60, 2), 'fm99999999999990.00') TJTIMEHOURS,
               CASE WHEN TIMETOTAL= TJTIMETOTAL THEN '0.00%' ELSE TO_CHAR(ROUND((TIMETOTAL - NVL(TJTIMETOTAL, 0)) * 100 /
                             (TIMETOTAL - NVL(TJTIMETOTAL, 0) + NVL(YCNB, 0)),
                             2),
                       'fm99999999999990.00') || '%' END YXNB,
               CASE WHEN TIMETOTAL= TJTIMETOTAL THEN '0.00%' ELSE TO_CHAR(ROUND((TIMETOTAL - NVL(TJTIMETOTAL, 0)) * 100 /
                             (TIMETOTAL - NVL(TJTIMETOTAL, 0) + NVL(YCNB, 0) +
                             NVL(YCWB, 0)),
                             2),
                       'fm99999999999990.00') || '%' END YXZH,
               CASE WHEN TIMETOTAL= TJTIMETOTAL THEN '0.00' ELSE TO_CHAR(ROUND((TIMETOTAL - NVL(TJTIMETOTAL, 0)) * 100 / TIMETOTAL,
                             2),
                       'fm99999999999990.00') END DAYZYL,
               PLINEORDER
          FROM T1
        UNION ALL
        SELECT '轧管' AS DEPT,
               '合计' PLINENAME,
               TO_CHAR(SUM(ZCNB)) ZCNB,
               TO_CHAR(SUM(ZCWB)) ZCWB,
               TO_CHAR(SUM(YCNB)) YCNB,
               TO_CHAR(SUM(YCWB)) YCWB,
               SUM(TJTIMETOTAL),
               TO_CHAR(ROUND(SUM(TJTIMETOTAL) / 60, 2), 'fm99999999999990.00') TJTIMEHOURS,
               TO_CHAR((4*24*60*#DAYS#-ROUND(SUM(TJTIMETOTAL),0))*100/(4*24*60*#DAYS#-ROUND(SUM(TJTIMETOTAL),0)+ROUND(NVL(SUM(YCNB),0),0)), 'fm99999999999990.00') || '%' YXNB ,
               TO_CHAR((4*24*60*#DAYS#-ROUND(SUM(TJTIMETOTAL),0))*100/(4*24*60*#DAYS#-ROUND(SUM(TJTIMETOTAL),0)+ROUND(NVL(SUM(YCNB),0),0)+ROUND(NVL(SUM(YCWB),0),0)), 'fm99999999999990.00') || '%'  YXZH,
               NULL DAYZYL,
               5 PLINEORDER
          FROM T1
         WHERE PLINENAME IS NOT NULL
          )，
            T6 AS (
               SELECT '轧管' AS DEPT, PLINENAME1,
               TO_CHAR(ROUND(ZCNBDAY,0)) ZCNBDAY,
               TO_CHAR(ROUND(ZCWBDAY,0)) ZCWBDAY, 
               TO_CHAR(ROUND(YCNBDAY,0)) YCNBDAY,
               TO_CHAR(ROUND(YCWBDAY,0)) YCWBDAY,
               TO_CHAR(ROUND(TJTIMETOTALDAY,0)) TJTIMETOTALDAY, 
               TO_CHAR(ROUND(TIMETOTALDAY,0)) TIMETOTALDAY,
               YXNBDAY,YXZHDAY,DAYZYLDAY,5 AS PLINEORDER FROM T4
               UNION ALL
               SELECT '轧管' AS DEPT,
               '合计' PLINENAME,
               TO_CHAR(ROUND(SUM(ZCNBDAY),0)) ZCNBDAY,
               TO_CHAR(ROUND(SUM(ZCWBDAY),0)) ZCWBDAY,
               TO_CHAR(ROUND(SUM(YCNBDAY),0)) YCNBDAY,
               TO_CHAR(ROUND(SUM(YCWBDAY),0)) YCWBDAY,
               TO_CHAR(ROUND(SUM(TJTIMETOTALDAY),0)) TJTIMETOTALDAY,
               TO_CHAR(ROUND(SUM(TIMETOTALDAY),0))  TJTIMEHOURS,
               TO_CHAR((24*60*4-ROUND(SUM(TJTIMETOTALDAY),0))*100/(24*60*4-ROUND(SUM(TJTIMETOTALDAY),0)+ROUND(NVL(SUM(YCNBDAY),0),0)), 'fm99999999999990.00') || '%' YXNBDAY,
               TO_CHAR((24*60*4-ROUND(SUM(TJTIMETOTALDAY),0))*100/(24*60*4-ROUND(SUM(TJTIMETOTALDAY),0)+ROUND(NVL(SUM(YCNBDAY),0),0)+ROUND(NVL(SUM(YCWBDAY),0),0)), 'fm99999999999990.00') || '%' YXZHDAY,
               NULL DAYZYLDAY,
               5 PLINEORDER
          FROM T4
      ) 
      SELECT * FROM 
      (
      SELECT
        NVL(T15.DEPT,'炼钢') DEPT,NVL(T15.PLINENAME,T18.PLINENAME1) PLINENAME,
        TO_CHAR(T15.ZCNB/60, 'fm99999999999990.00') ZCNB,
        TO_CHAR(T15.ZCWB/60, 'fm99999999999990.00') ZCWB,
        TO_CHAR(T15.YCNB/60, 'fm99999999999990.00') YCNB,
        TO_CHAR(T15.YCWB/60, 'fm99999999999990.00') YCWB,
        TO_CHAR(T15.TJTIMETOTAL/60, 'fm99999999999990.00') TJTIMETOTAL,
        T15.TJTIMEHOURS,NVL(T15.YXNB,'100.00%') YXNB,NVL(T15.YXZH,'100.00%') YXZH,
        TO_CHAR(DECODE(PLINENAME1,'一炼钢电炉',NVL(T15.DAYZYL,'100.00'),'二炼钢电炉',NVL(T15.DAYZYL,'100.00'),
       '合计',(SELECT AVG(DAYZYL) FROM T15 WHERE PLINENAME !='合计')),'fm99999999999990.00') || '%' DAYZYL,
        --T15.PLINEORDER,
        DECODE(PLINENAME1,'一炼钢电炉',-5,'二炼钢电炉',-4,'合计',-1) AS PLINEORDER,
       TO_CHAR(ZCNBDAY/60, 'fm99999999999990.00') ZCNBDAY,
       TO_CHAR(ZCWBDAY/60, 'fm99999999999990.00') ZCWBDAY,
       TO_CHAR(YCNBDAY/60, 'fm99999999999990.00') YCNBDAY,
       TO_CHAR(YCWBDAY/60, 'fm99999999999990.00') YCWBDAY,
       TO_CHAR(TJTIMETOTALDAY/60, 'fm99999999999990.00') TJTIMETOTALDAY,
       TIMETOTALDAY,
       DECODE(PLINENAME1,'一炼钢电炉',NVL(YXNBDAY,'100.00%'),'二炼钢电炉',NVL(YXNBDAY,'100.00%'),'合计',YXNBDAY) YXNBDAY,
       DECODE(PLINENAME1,'一炼钢电炉',NVL(YXZHDAY,'100.00%'),'二炼钢电炉',NVL(YXZHDAY,'100.00%'),'合计',YXZHDAY) YXZHDAY,
       TO_CHAR(DECODE(PLINENAME1,'一炼钢电炉',NVL(DAYZYLDAY,'100.00'),'二炼钢电炉',NVL(DAYZYLDAY,'100.00'),'合计',(SELECT AVG(DAYZYLDAY) FROM T18 WHERE PLINENAME1 !='合计')),'fm99999999999990.00') || '%' DAYZYLDAY,
      (SELECT PLINE_CODE FROM com_base_pline ta WHERE ta.PLINE_NAME=T15.PLINENAME) AS PLINECODE
        FROM T15, T18
       WHERE T15.PLINENAME(+) = T18.PLINENAME1 AND T15.DEPT(+) = T18.DEPT
       UNION ALL
       SELECT
        T5.DEPT,T5.PLINENAME,
        TO_CHAR(T5.ZCNB/60, 'fm99999999999990.00') ZCNB,
        TO_CHAR(T5.ZCWB/60, 'fm99999999999990.00') ZCWB,
        TO_CHAR(T5.YCNB/60, 'fm99999999999990.00') YCNB,
        TO_CHAR(T5.YCWB/60, 'fm99999999999990.00') YCWB,
        TO_CHAR(T5.TJTIMETOTAL/60, 'fm99999999999990.00') TJTIMETOTAL,
        T5.TJTIMEHOURS,T5.YXNB,T5.YXZH,
        TO_CHAR(DECODE(PLINENAME,'250机组',T5.DAYZYL,'258机组',T5.DAYZYL,
       '168机组',T5.DAYZYL,'460机组',T5.DAYZYL,
       '合计',(SELECT AVG(DAYZYL) FROM T5 WHERE PLINENAME !='合计')),'fm99999999999990.00') || '%' DAYZYL,
        T5.PLINEORDER,
       TO_CHAR(ZCNBDAY/60, 'fm99999999999990.00') ZCNBDAY,
       TO_CHAR(ZCWBDAY/60, 'fm99999999999990.00') ZCWBDAY,
       TO_CHAR(YCNBDAY/60, 'fm99999999999990.00') YCNBDAY,
       TO_CHAR(YCWBDAY/60, 'fm99999999999990.00') YCWBDAY,
       TO_CHAR(TJTIMETOTALDAY/60, 'fm99999999999990.00') TJTIMETOTALDAY,
       TIMETOTALDAY,YXNBDAY,YXZHDAY,
       TO_CHAR(DECODE(PLINENAME,'250机组',DAYZYLDAY,'258机组',DAYZYLDAY,
       '168机组',DAYZYLDAY,'460机组',DAYZYLDAY,
       '合计',(SELECT AVG(DAYZYLDAY) FROM T6 WHERE PLINENAME1 !='合计')),'fm99999999999990.00') || '%' DAYZYLDAY,
      (SELECT PLINE_CODE FROM com_base_pline ta WHERE ta.PLINE_NAME=t5.PLINENAME) AS PLINECODE
        FROM T5, T6
       WHERE T5.PLINENAME = T6.PLINENAME1(+) AND T5.DEPT = T6.DEPT(+)
       ) ta
       ORDER BY ta.PLINEORDER
		]]>
	</query>
	<query id="BuyGpDAL.selectRptDaySCKB1" desc="日生产运行快报（总调）数据">
	<![CDATA[
       WITH T AS
			 (SELECT SUM(TJTIME) AS TJTIME, PLINENAME, TJREASON
			    FROM (SELECT T.CONTROL_ID,
			                 T.STOP_REASON,
			                 T.LOGS_BEG,
			                 T.LOGS_END,
			                 (TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
			                 TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
			                 (SELECT BASENAME
			                    FROM COM_BASE_INFO
			                   WHERE BASECODE = T.STOP_TYPE) STOPTYPE,
			                 (SELECT PROPERA
			                    FROM COM_BASE_INFO
			                   WHERE BASECODE = T.STOP_REASON) STOPREASON,
			                 (SELECT PLINE_NAME
			                    FROM COM_BASE_PLINE
			                   WHERE PLINE_CODE = T.PLINE_CODE) PLINENAME,
			                 CASE
			                   WHEN (SELECT PROPERA
			                           FROM COM_BASE_INFO
			                          WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
			                        (SELECT BASENAME
			                           FROM COM_BASE_INFO
			                          WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
			                    'ZCNB'
			                   WHEN (SELECT PROPERA
			                           FROM COM_BASE_INFO
			                          WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
			                        (SELECT BASENAME
			                           FROM COM_BASE_INFO
			                          WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
			                    'ZCWB'
			                   WHEN (SELECT PROPERA
			                           FROM COM_BASE_INFO
			                          WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
			                        (SELECT BASENAME
			                           FROM COM_BASE_INFO
			                          WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
			                    'YCNB'
			                   WHEN (SELECT PROPERA
			                           FROM COM_BASE_INFO
			                          WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
			                        (SELECT BASENAME
			                           FROM COM_BASE_INFO
			                          WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
			                    'YCWB'
			                 END TJREASON
			            FROM MIL_CONTROL_LOG T
			           WHERE T.PRO_TYPE = '2'
			             AND TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
			                 TO_DATE('#LASTDATE#', 'yyyy-mm-dd hh24:mi:ss')
			             AND TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
			                 TO_DATE('#BGEINDATE#', 'yyyy-mm-dd hh24:mi:ss')
			             AND T.STOP_TYPE IN ('500601', '500602')
			             AND T.PLINE_CODE IN ('C008', 'C009', 'C010', 'C017')
			             AND EXISTS (SELECT *
			                    FROM COM_BASE_INFO
			                   WHERE BASECODE = T.STOP_REASON
			                     AND VALIDFLAG = '1')) TA
			   GROUP BY TA.PLINENAME, TA.TJREASON),
			T1 AS
			 (SELECT PLINENAME,
			         MAX(DECODE(TJREASON, 'ZCNB', TJTIME, NULL)) AS ZCNB,
			         MAX(DECODE(TJREASON, 'ZCWB', TJTIME, NULL)) AS ZCWB,
			         MAX(DECODE(TJREASON, 'YCNB', TJTIME, NULL)) AS YCNB,
			         MAX(DECODE(TJREASON, 'YCWB', TJTIME, NULL)) AS YCWB,
			         SUM(TJTIME) TJTIMETOTAL,
			         24 * 60 * '#DAYS#' TIMETOTAL,
			         DECODE(PLINENAME,
			                '250机组',
			                1,
			                '258机组',
			                2,
			                '168机组',
			                3,
			                '460机组',
			                4,
			                5) PLINEORDER
			    FROM T
			   GROUP BY PLINENAME),
			T2 AS
			 (SELECT SUM(TJTIME) AS TJTIME, PLINENAME, TJREASON
			    FROM (SELECT T.CONTROL_ID,
			                 T.STOP_REASON,
			                 T.LOGS_BEG,
			                 T.LOGS_END,
			                 (TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
			                 TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
			                 (SELECT BASENAME
			                    FROM COM_BASE_INFO
			                   WHERE BASECODE = T.STOP_TYPE) STOPTYPE,
			                 (SELECT PROPERA
			                    FROM COM_BASE_INFO
			                   WHERE BASECODE = T.STOP_REASON) STOPREASON,
			                 (SELECT PLINE_NAME
			                    FROM COM_BASE_PLINE
			                   WHERE PLINE_CODE = T.PLINE_CODE) PLINENAME,
			                 CASE
			                   WHEN (SELECT PROPERA
			                           FROM COM_BASE_INFO
			                          WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
			                        (SELECT BASENAME
			                           FROM COM_BASE_INFO
			                          WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
			                    'ZCNB'
			                   WHEN (SELECT PROPERA
			                           FROM COM_BASE_INFO
			                          WHERE BASECODE = T.STOP_REASON) = '正常停机' AND
			                        (SELECT BASENAME
			                           FROM COM_BASE_INFO
			                          WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
			                    'ZCWB'
			                   WHEN (SELECT PROPERA
			                           FROM COM_BASE_INFO
			                          WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
			                        (SELECT BASENAME
			                           FROM COM_BASE_INFO
			                          WHERE BASECODE = T.STOP_TYPE) = '内部原因' THEN
			                    'YCNB'
			                   WHEN (SELECT PROPERA
			                           FROM COM_BASE_INFO
			                          WHERE BASECODE = T.STOP_REASON) = '异常停机' AND
			                        (SELECT BASENAME
			                           FROM COM_BASE_INFO
			                          WHERE BASECODE = T.STOP_TYPE) = '外部原因' THEN
			                    'YCWB'
			                 END TJREASON
			            FROM MIL_CONTROL_LOG T
			           WHERE T.PRO_TYPE = '2'
			             AND TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
			                 TO_DATE('#ENDDATE#', 'yyyy-mm-dd hh24:mi:ss')
			             AND TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
			                 TO_DATE('#BGEINDATE#', 'yyyy-mm-dd hh24:mi:ss')
			             AND T.STOP_TYPE IN ('500601', '500602')
			             AND T.PLINE_CODE IN ('C008', 'C009', 'C010', 'C017')
			             AND EXISTS (SELECT *
			                    FROM COM_BASE_INFO
			                   WHERE BASECODE = T.STOP_REASON
			                     AND VALIDFLAG = '1')) TA
			   GROUP BY TA.PLINENAME, TA.TJREASON),
			T3 AS
			 (SELECT PLINENAME PLINENAME1,
			         MAX(DECODE(TJREASON, 'ZCNB', TJTIME, NULL)) AS ZCNBDAY,
			         MAX(DECODE(TJREASON, 'ZCWB', TJTIME, NULL)) AS ZCWBDAY,
			         MAX(DECODE(TJREASON, 'YCNB', TJTIME, NULL)) AS YCNBDAY,
			         MAX(DECODE(TJREASON, 'YCWB', TJTIME, NULL)) AS YCWBDAY,
			         SUM(TJTIME) TJTIMETOTALDAY,
			         24 * 60 TIMETOTALDAY,
			         DECODE(PLINENAME,
			                '250机组',
			                1,
			                '258机组',
			                2,
			                '168机组',
			                3,
			                '460机组',
			                4,
			                5) PLINEORDER1
			    FROM T2
			   GROUP BY PLINENAME),
			T4 AS
			 (SELECT T3.*,
			         CASE
			           WHEN TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0) = 0 THEN
			            '0.00'
			           ELSE
			            TO_CHAR(ROUND((TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0)) * 100 /
			                          (TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0) +
			                          NVL(YCNBDAY, 0)),
			                          2),
			                    'fm99999999999990.00')
			         END || '%' YXNBDAY,
			         CASE
			           WHEN TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0) = 0 THEN
			            '0.00'
			           ELSE
			            TO_CHAR(ROUND((TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0)) * 100 /
			                          (TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0) +
			                          NVL(YCNBDAY, 0) + NVL(YCWBDAY, 0)),
			                          2),
			                    'fm99999999999990.00')
			         END || '%' YXZHDAY,
			         CASE
			           WHEN TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0) = 0 THEN
			            '0.00'
			           ELSE
			            TO_CHAR(ROUND((TIMETOTALDAY - NVL(TJTIMETOTALDAY, 0)) * 100 /
			                          TIMETOTALDAY,
			                          2),
			                    'fm99999999999990.00')
			         END || '%' DAYZYLDAY
			    FROM T3),
			T5 AS
			 (SELECT '炼钢' AS DEPT,
			         '一炼' AS PLINENAME,
			         NULL AS ZCNB,
			         NULL AS ZCWB,
			         NULL AS YCNB,
			         NULL AS YCWB,
			         NULL AS TJTIMETOTAL,
			         NULL AS TJTIMEHOURS,
			         NULL AS YXNB,
			         NULL AS YXZH,
			         NULL AS DAYZYL,
			         -2 AS PLINEORDER
			    FROM DUAL
			  UNION ALL
			  SELECT '炼钢' AS DEPT,
			         '二炼' AS PLINENAME,
			         NULL AS ZCNB,
			         NULL AS ZCWB,
			         NULL AS YCNB,
			         NULL AS YCWB,
			         NULL AS TJTIMETOTAL,
			         NULL AS TJTIMEHOURS,
			         NULL AS YXNB,
			         NULL AS YXZH,
			         NULL AS DAYZYL,
			         -1 AS PLINEORDER
			    FROM DUAL
			  UNION ALL
			  SELECT '轧管' AS DEPT,
			         PLINENAME,
			         TO_CHAR(ZCNB) ZCNB,
			         TO_CHAR(ZCWB) ZCWB,
			         TO_CHAR(YCNB) YCNB,
			         TO_CHAR(YCWB) YCWB,
			         TJTIMETOTAL,
			         TO_CHAR(ROUND(TJTIMETOTAL / 60, 2), 'fm99999999999990.00') TJTIMEHOURS,
			         TO_CHAR(ROUND((TIMETOTAL - NVL(TJTIMETOTAL, 0)) * 100 /
			                       (TIMETOTAL - NVL(TJTIMETOTAL, 0) + NVL(YCNB, 0)),
			                       2),
			                 'fm99999999999990.00') || '%' YXNB,
			         TO_CHAR(ROUND((TIMETOTAL - NVL(TJTIMETOTAL, 0)) * 100 /
			                       (TIMETOTAL - NVL(TJTIMETOTAL, 0) + NVL(YCNB, 0) +
			                       NVL(YCWB, 0)),
			                       2),
			                 'fm99999999999990.00') || '%' YXZH,
			         TO_CHAR(ROUND((TIMETOTAL - NVL(TJTIMETOTAL, 0)) * 100 / TIMETOTAL,
			                       2),
			                 'fm99999999999990.00') || '%' DAYZYL,
			         PLINEORDER
			    FROM T1
			  UNION ALL
			  SELECT '轧管' AS DEPT,
			         '合计' PLINENAME,
			         TO_CHAR(SUM(ZCNB)) ZCNB,
			         TO_CHAR(SUM(ZCWB)) ZCWB,
			         TO_CHAR(SUM(YCNB)) YCNB,
			         TO_CHAR(SUM(YCWB)) YCWB,
			         SUM(TJTIMETOTAL),
			         TO_CHAR(ROUND(SUM(TJTIMETOTAL) / 60, 2), 'fm99999999999990.00') TJTIMEHOURS,
			         NULL YXNB,
			         NULL YXZH,
			         NULL DAYZYL,
			         5 PLINEORDER
			    FROM T1
			   WHERE PLINENAME IS NOT NULL
			  UNION ALL
			  SELECT '管加工(加工线)' AS DEPT,
			         '本部' AS PLINENAME,
			         NULL AS ZCNB,
			         NULL AS ZCWB,
			         NULL AS YCNB,
			         NULL AS YCWB,
			         NULL AS TJTIMETOTAL,
			         NULL AS TJTIMEHOURS,
			         NULL AS YXNB,
			         NULL AS YXZH,
			         NULL AS DAYZYL,
			         6 AS PLINEORDER
			    FROM DUAL
			  UNION ALL
			  SELECT '管加工(加工线)' AS DEPT,
			         '元通' AS PLINENAME,
			         NULL AS ZCNB,
			         NULL AS ZCWB,
			         NULL AS YCNB,
			         NULL AS YCWB,
			         NULL AS TJTIMETOTAL,
			         NULL AS TJTIMEHOURS,
			         NULL AS YXNB,
			         NULL AS YXZH,
			         NULL AS DAYZYL,
			         7 AS PLINEORDER
			    FROM DUAL
			  UNION ALL
			  SELECT '管加工(加工线)' AS DEPT,
			         '深加工' AS PLINENAME,
			         NULL AS ZCNB,
			         NULL AS ZCWB,
			         NULL AS YCNB,
			         NULL AS YCWB,
			         NULL AS TJTIMETOTAL,
			         NULL AS TJTIMEHOURS,
			         NULL AS YXNB,
			         NULL AS YXZH,
			         NULL AS DAYZYL,
			         8 AS PLINEORDER
			    FROM DUAL
			  UNION ALL
			  SELECT '管加工(热处理)' AS DEPT,
			         '本部' AS PLINENAME,
			         NULL AS ZCNB,
			         NULL AS ZCWB,
			         NULL AS YCNB,
			         NULL AS YCWB,
			         NULL AS TJTIMETOTAL,
			         NULL AS TJTIMEHOURS,
			         NULL AS YXNB,
			         NULL AS YXZH,
			         NULL AS DAYZYL,
			         9 AS PLINEORDER
			    FROM DUAL
			  UNION ALL
			  SELECT '管加工(热处理)' AS DEPT,
			         '元通' AS PLINENAME,
			         NULL AS ZCNB,
			         NULL AS ZCWB,
			         NULL AS YCNB,
			         NULL AS YCWB,
			         NULL AS TJTIMETOTAL,
			         NULL AS TJTIMEHOURS,
			         NULL AS YXNB,
			         NULL AS YXZH,
			         NULL AS DAYZYL,
			         10 AS PLINEORDER
			    FROM DUAL
			  UNION ALL
			  SELECT '管加工(热处理)' AS DEPT,
			         '深加工' AS PLINENAME,
			         NULL AS ZCNB,
			         NULL AS ZCWB,
			         NULL AS YCNB,
			         NULL AS YCWB,
			         NULL AS TJTIMETOTAL,
			         NULL AS TJTIMEHOURS,
			         NULL AS YXNB,
			         NULL AS YXZH,
			         NULL AS DAYZYL,
			         11 AS PLINEORDER
			    FROM DUAL)，
			      T6 AS (
               SELECT '轧管' AS DEPT, PLINENAME1,
               TO_CHAR(ROUND(ZCNBDAY,0)) ZCNBDAY,
               TO_CHAR(ROUND(ZCWBDAY,0)) ZCWBDAY, 
               TO_CHAR(ROUND(YCNBDAY,0)) YCNBDAY,
               TO_CHAR(ROUND(YCWBDAY,0)) YCWBDAY,
               TO_CHAR(ROUND(TJTIMETOTALDAY,0)) TJTIMETOTALDAY, 
               TO_CHAR(ROUND(TIMETOTALDAY,0)) TIMETOTALDAY,
               YXNBDAY,YXZHDAY,DAYZYLDAY,5 AS PLINEORDER FROM T4
               UNION ALL
               SELECT '轧管' AS DEPT,
               '合计' PLINENAME,
               TO_CHAR(ROUND(SUM(ZCNBDAY),0)) ZCNBDAY,
               TO_CHAR(ROUND(SUM(ZCWBDAY),0)) ZCWBDAY,
               TO_CHAR(ROUND(SUM(YCNBDAY),0)) YCNBDAY,
               TO_CHAR(ROUND(SUM(YCWBDAY),0)) YCWBDAY,
               TO_CHAR(ROUND(SUM(TJTIMETOTALDAY),0)) TJTIMETOTALDAY,
               TO_CHAR(ROUND(SUM(TIMETOTALDAY),0))  TJTIMEHOURS,
               NULL YXNBDAY,
               NULL YXZHDAY,
               NULL DAYZYLDAY,
               5 PLINEORDER
          FROM T4
      ) 
      
       SELECT
        T5.DEPT,T5.PLINENAME,
        TO_CHAR(T5.ZCNB/60, 'fm99999999999990.00') ZCNB,
        TO_CHAR(T5.ZCWB/60, 'fm99999999999990.00') ZCWB,
        TO_CHAR(T5.YCNB/60, 'fm99999999999990.00') YCNB,
        TO_CHAR(T5.YCWB/60, 'fm99999999999990.00') YCWB,
        TO_CHAR(T5.TJTIMETOTAL/60, 'fm99999999999990.00') TJTIMETOTAL,
        T5.TJTIMEHOURS,T5.YXNB,T5.YXZH,T5.DAYZYL,T5.PLINEORDER,
        
       TO_CHAR(ZCNBDAY/60, 'fm99999999999990.00') ZCNBDAY,
       TO_CHAR(ZCWBDAY/60, 'fm99999999999990.00') ZCWBDAY,
       TO_CHAR(YCNBDAY/60, 'fm99999999999990.00') YCNBDAY,
       TO_CHAR(YCWBDAY/60, 'fm99999999999990.00') YCWBDAY,
       TO_CHAR(TJTIMETOTALDAY/60, 'fm99999999999990.00') TJTIMETOTALDAY,
       TIMETOTALDAY,YXNBDAY,YXZHDAY,DAYZYLDAY,
      (SELECT PLINE_CODE FROM com_base_pline ta WHERE ta.PLINE_NAME=t5.PLINENAME) AS PLINECODE
        FROM T5, T6
       WHERE T5.PLINENAME = T6.PLINENAME1(+) AND T5.DEPT = T6.DEPT(+)
       ORDER BY T5.PLINEORDER

	]]>
	</query>
	
	<query id="BuyGpDAL.selectRptJGONLINE" desc="获取接箍在线数据">
	<![CDATA[
       SELECT TO_CHAR(SYSDATE, 'yyyyMM') SCMONTH,
       '管加工' AS FACTORY,
       PLINE_NAME,
       '接箍料' KIND,
       STEELNAME,
       STEELNAME,
       GRADENAME,
       SPEC_JG_DESC,
       MODEL_DESC,
       JUDGE_STOVE_NO,
       BATCH_NO,
       REAL_BL_NUM,
       REAL_BL_WT
		  FROM PLN_ZY_JG_WORKBILL T
		 WHERE 1 = 1
		   AND T.PLINE_CODE IN
		       ('C081', 'C041', 'C042', 'C043', 'C044', 'C045', 'C046', 'C047')
		   AND T.ZY_BILL_STATUS IN ('2')
		 ORDER BY T.GX_PRO_SEQ ASC
	]]>
	</query>
	<query id="BuyGpDAL.selectRptJGHSK" desc="获取接箍核算科数据">
	<![CDATA[
       SELECT
       '接箍' KIND,
       MAX(TA.STEELNAME) STEELNAME, --钢级
       MAX(TA.GRADENAME) GRADENAME, --钢种
       MAX(JG.MIN_D) AS WAIJING,
       MAX(JG.MIN_H) AS BIHOU,
       MAX(t3.model_desc) MODEL_DESC,
       TA.JUDGE_STOVE_NO,
       SUM(TA.LOAD_PIECES) LOAD_PIECES,
       SUM(TA.LOAD_WEIGHT) LOAD_WEIGHT,
       (SELECT SUM(M.COL_COUNT) FROM COUPLING_PHOSPHATE_RESULT M WHERE TA.JUDGE_STOVE_NO = M.JUDGE_STOVE_NO) PRO_NUM,
       (SELECT SUM(M.REJECTED_PCS) FROM COUPLING_THREADING_RESULT M WHERE TA.JUDGE_STOVE_NO = M.JUDGE_STOVE_NO) REJECTED_PCS
 
	  FROM COUPLING_LOADING_RESULT TA,PLN_ZY_JG_WORKBILL t3,COM_MSC_JG JG 
	  WHERE TA.LOAD_TIME BETWEEN
	      TO_DATE('#BGEINDATE#', 'yyyy-mm-dd hh24:mi:ss') AND
	      TO_DATE('#ENDDATE#', 'yyyy-mm-dd hh24:mi:ss')
	      AND TA.WO_ID = t3.WO_ID AND T3.CODE_JG = JG.CODE_JG
	      --AND TA.JUDGE_STOVE_NO ='695177'
	 GROUP BY  TA.JUDGE_STOVE_NO
	]]>
	</query>
	<query id="IndDAL.getGRCLYB" desc="查询个人产量月报数据 ">
	<![CDATA[
      SELECT 班次,机床,姓名,产量,机床号 FROM
		(
		SELECT DECODE(T.COL_GROUP, '1', '甲', '2', '乙', '3', '丙', '4', '丁', '') AS 班次,
		       '车丝' AS 机床,
		       T.COL_OPERATOR1 AS 姓名,
		       SUM(T.QUALIRIED_PCS) AS 产量,
		       --T.MACHINE_NO,
		       --T.CREATE_TIME, 
		       TO_CHAR(WM_CONCAT(DISTINCT T.MACHINE_NO)) AS 机床号,
		       1 AS 排序,
		        T.COL_GROUP AS 排序1
		  FROM COUPLING_THREADING_RESULT T
		 WHERE T.COL_OPERATOR1 IS NOT NULL
		   AND T.CREATE_TIME >=
		       TO_DATE(#RPT_YM1#, 'yyyy-mm-dd hh24:mi:ss')
		       AND
		       T.CREATE_TIME <
		       TO_DATE(#RPT_YM2#, 'yyyy-mm-dd hh24:mi:ss') 
		 GROUP BY T.COL_GROUP, T.COL_OPERATOR1
		 
		 UNION ALL
		 
		 SELECT DECODE(T.COL_GROUP, '1', '甲', '2', '乙', '3', '丙', '4', '丁', '') AS 班次,
		       '磷化' AS 机床,
		       T.COL_OPERATOR AS 姓名,
		       SUM(T.Col_Count) AS 产量,
		       --T.MACHINE_NO,
		       --T.CREATE_TIME, 
		       NULL AS 机床号,
		       2 AS 排序,
		       T.COL_GROUP AS 排序1
		  FROM COUPLING_PHOSPHATE_RESULT T
		 WHERE T.COL_OPERATOR IS NOT NULL
		       AND T.CREATE_TIME >=
		       TO_DATE(#RPT_YM1#, 'yyyy-mm-dd hh24:mi:ss')
		       AND
		       T.CREATE_TIME <
		       TO_DATE(#RPT_YM2#, 'yyyy-mm-dd hh24:mi:ss') 
		 GROUP BY T.COL_GROUP, T.COL_OPERATOR
		 
		 UNION ALL
		 
		 SELECT DECODE(T.COL_GROUP, '1', '甲', '2', '乙', '3', '丙', '4', '丁', '') AS 班次,
		       '切管' AS 机床,
		       T.COL_OPERATOR AS 姓名,
		       SUM(T.Qualified_Number) AS 产量,
		       --T.MACHINE_NO,
		       --T.CREATE_TIME, 
		       NULL AS 机床号,
		       3 AS 排序,
		        T.COL_GROUP AS 排序1
		  FROM COUPLING_CUT_RESULT T
		 WHERE T.COL_OPERATOR IS NOT NULL
		       AND T.CREATE_TIME >=
		       TO_DATE(#RPT_YM1#, 'yyyy-mm-dd hh24:mi:ss')
		       AND
		       T.CREATE_TIME <
		       TO_DATE(#RPT_YM2#, 'yyyy-mm-dd hh24:mi:ss') 
		 GROUP BY T.COL_GROUP, T.COL_OPERATOR
		 ) ta
		 
		 ORDER BY ta.排序1,ta.排序
				]]>
	</query>
		<query id="IndDAL.getJGSCYB" desc="查询生产准备数据 ">
	<![CDATA[
	WITH t
		AS
		(
		SELECT t.code_jg ,t.Gradename,t.steelname,t.spec_jg_desc,t.outdiameter,t.wallthick,t.model_desc,t.deal_num,t.GOWHERE_NAME
		  FROM COUPLING_MAT_DEAL T
		 WHERE 1=1
		 AND T.GOWHERE_NAME IN ('加工线01#（管加工1#线）',
		                          '加工线02#（管加工2#线）',
		                          '加工线03#（管加工3#线）',
		                          '加工线04#（管加工4#线）',
		                          '加工线05#（管加工5#线）',
		                          '加工线06#（管加工6#线）',
		                          '加工线07#（管加工油套线）',
		                          '加工线08#（管加工试验线）',
		                          '加工线09#（管加工油特线）',
		                          '加工线10#（管加工特扣线）',
		                          '加工线11#（元通油管线）',
		                          '加工线12#（元通1#套管线）',
		                          '加工线13#（元通2#套管线）',
		                          '加工线15#（管加工短节线）')
		   AND T.CREATE_TIME BETWEEN
		       TO_DATE(#RPT_YM1#, 'YYYY-MM-DD HH24:MI:SS') AND
		       TO_DATE(#RPT_YM2#, 'YYYY-MM-DD HH24:MI:SS')
		   AND T.DEAL_TYPE_CODE = '800801'
		   AND T.OUT_FLAG = '2'
		   AND T.HANDLE_FLAG = '0'
		)
		SELECT *
		from t 
		pivot(
		SUM(t.deal_num)
		for  GOWHERE_NAME IN ('加工线01#（管加工1#线）',
		                          '加工线02#（管加工2#线）',
		                          '加工线03#（管加工3#线）',
		                          '加工线04#（管加工4#线）',
		                          '加工线05#（管加工5#线）',
		                          '加工线06#（管加工6#线）',
		                          '加工线07#（管加工油套线）',
		                          '加工线08#（管加工试验线）',
		                          '加工线09#（管加工油特线）',
		                          '加工线10#（管加工特扣线）',
		                          '加工线11#（元通油管线）',
		                          '加工线12#（元通1#套管线）',
		                          '加工线13#（元通2#套管线）',
		                          '加工线15#（管加工短节线）')
		)
		ORDER BY steelname,gradename,spec_jg_desc,model_desc
		
			]]>
	</query>
	
	<query id="BuyGpDAL.selectZGTJ" desc="获取调度停机数据">
	<![CDATA[
       WITH t1
		AS
		(
		SELECT CASE
         WHEN (TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
              TO_DATE(SUBSTR(T.LOGS_BEG, 1, 8) || '2100',
                       'yyyy-mm-dd hh24:mi:ss')) THEN
          TO_CHAR(TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') + 1,
                  'yyyy-MM-dd')
         ELSE
          TO_CHAR(TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss'),
                  'yyyy-MM-dd')
       END TJ_DATE,
       ROUND((TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
           TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60,0) AS TJ_TIME,
       TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') LOGS_BEG,
       TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') LOGS_END,
       (SELECT PLINE_NAME FROM Com_Base_Pline WHERE pline_code = T.PLINE_CODE) PLINE_NAME,
       DECODE(T.PRO_BC, '1', '早', '2', '中', '3', '夜', T.PRO_BC) PRO_BC,
       DECODE(T.PRO_BZ,
              '1',
              '甲',
              '2',
              '乙',
              '3',
              '丙',
              '4',
              '丁',
              T.PRO_BZ) PRO_BZ,
       (SELECT MAX(BASENAME) FROM COM_BASE_INFO  WHERE basecode=T.STOP_TYPE) STOP_TYPE,
       (SELECT MAX(BASENAME) FROM COM_BASE_INFO  WHERE basecode=T.STOP_SMALL) STOP_SMALL,
       (SELECT MAX(BASENAME) FROM COM_BASE_INFO  WHERE basecode=T.STOP_REASON) STOP_REASON,
       T.MEMO,
       DECODE(T.CONFIRM_FLAG, '1', '确认', '0', '未确认', T.CONFIRM_FLAG) CONFIRM_FLAG,
       T.USER_NAME,
       T.CONFIRM_NAME,
       T.USER_DATE,
       T.CONFIRM_TIME,
       0 AS flag,
       NULL AS TJHOURS
	  FROM MIL_CONTROL_LOG T
	 WHERE T.PRO_TYPE = '2'
	   AND TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >= to_date(to_char(last_day(add_months(TO_DATE('#DATE#', 'yyyy-mm-dd hh24:mi:ss'),-1)),'yyyyMMdd')||'2100', 'yyyy-mm-dd hh24:mi:ss')
	   AND TO_DATE(T.Logs_End, 'yyyy-mm-dd hh24:mi:ss') <= to_date('#DATE#'|| ' 21:00:00','yyyy-mm-dd hh24:mi:ss')
	   AND T.PLINE_CODE ='#PLINECODE#'
	 ORDER BY T.PLINE_CODE, T.LOGS_BEG DESC
	 ),
	 t2
	AS
	(
	 SELECT *  FROM t1
	 UNION ALL
	SELECT TJ_DATE,SUM(TJ_TIME),NULL,NULL,PLINE_NAME,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, 1 AS FLAG,ROUND(SUM(TJ_TIME)/60,2) FROM t1
	GROUP BY TJ_DATE,PLINE_NAME
	 UNION ALL
	SELECT '1900-01-01',SUM(TJ_TIME),NULL,NULL,PLINE_NAME,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, 2 AS FLAG,ROUND(SUM(TJ_TIME)/60,2) FROM t1
	GROUP BY PLINE_NAME
	)
	SELECT * FROM t2
	ORDER BY TJ_DATE DESC,FLAG
	]]>
	</query>
	<query id="BuyGpDAL.selectLGTJ" desc="获取调度停机数据(炼钢)">
	<![CDATA[
       WITH t1
		AS
		(
		SELECT CASE
         WHEN (TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
              TO_DATE(SUBSTR(T.LOGS_BEG, 1, 8) || '2100',
                       'yyyy-mm-dd hh24:mi:ss')) THEN
          TO_CHAR(TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') + 1,
                  'yyyy-MM-dd')
         ELSE
          TO_CHAR(TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss'),
                  'yyyy-MM-dd')
       END TJ_DATE,
       ROUND((TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
           TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60,0) AS TJ_TIME,
       TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') LOGS_BEG,
       TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') LOGS_END,
       (SELECT PLINE_NAME FROM Com_Base_Pline WHERE pline_code = T.EF_PLINE_CODE) PLINE_NAME,
       DECODE(T.PRO_BC, '1', '早', '2', '中', '3', '夜', T.PRO_BC) PRO_BC,
       DECODE(T.PRO_BZ,
              '1',
              '甲',
              '2',
              '乙',
              '3',
              '丙',
              '4',
              '丁',
              T.PRO_BZ) PRO_BZ,
       (SELECT MAX(BASENAME) FROM COM_BASE_INFO  WHERE basecode=T.STOP_TYPE) STOP_TYPE,
       (SELECT MAX(BASENAME) FROM COM_BASE_INFO  WHERE basecode=T.STOP_SMALL) STOP_SMALL,
       (SELECT MAX(BASENAME) FROM COM_BASE_INFO  WHERE basecode=T.STOP_REASON) STOP_REASON,
       T.MEMO,
       DECODE(T.CONFIRM_FLAG, '1', '确认', '0', '未确认', T.CONFIRM_FLAG) CONFIRM_FLAG,
       T.USER_NAME,
       T.CONFIRM_NAME,
       T.USER_DATE,
       T.CONFIRM_TIME,
       0 AS flag,
       NULL AS TJHOURS
	  FROM STL_CONTROL_LOG T
	 WHERE T.PRO_TYPE = '2'
	   AND TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >= to_date(to_char(last_day(add_months(TO_DATE('#DATE#', 'yyyy-mm-dd hh24:mi:ss'),-1)),'yyyyMMdd')||'2100', 'yyyy-mm-dd hh24:mi:ss')
	   AND TO_DATE(T.Logs_End, 'yyyy-mm-dd hh24:mi:ss') <= to_date('#DATE#'|| ' 21:00:00','yyyy-mm-dd hh24:mi:ss')
	   AND T.EF_PLINE_CODE ='#PLINECODE#'
	 ORDER BY T.PLINE_CODE, T.LOGS_BEG DESC
	 ),
	 t2
	AS
	(
	 SELECT *  FROM t1
	 UNION ALL
	SELECT TJ_DATE,SUM(TJ_TIME),NULL,NULL,PLINE_NAME,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, 1 AS FLAG,ROUND(SUM(TJ_TIME)/60,2) FROM t1
	GROUP BY TJ_DATE,PLINE_NAME
	 UNION ALL
	SELECT '1900-01-01',SUM(TJ_TIME),NULL,NULL,PLINE_NAME,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, 2 AS FLAG,ROUND(SUM(TJ_TIME)/60,2) FROM t1
	GROUP BY PLINE_NAME
	)
	SELECT * FROM t2
	ORDER BY TJ_DATE DESC,FLAG
	]]>
	</query>
	<query id="BuyGpDAL.selectZGTJ1" desc="获取调度停机数据新">
	<![CDATA[
       WITH t1
		AS
		(
		SELECT CASE
         WHEN (TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
              TO_DATE(SUBSTR(T.LOGS_BEG, 1, 8) || '2100',
                       'yyyy-mm-dd hh24:mi:ss')) THEN
          TO_CHAR(TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') + 1,
                  'yyyy-MM-dd')
         ELSE
          TO_CHAR(TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss'),
                  'yyyy-MM-dd')
       END TJ_DATE,
       ROUND((TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
           TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60,0) AS TJ_TIME,
       TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') LOGS_BEG,
       TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') LOGS_END,
       (SELECT PLINE_NAME FROM Com_Base_Pline WHERE pline_code = T.PLINE_CODE) PLINE_NAME,
       DECODE(T.PRO_BC, '1', '早', '2', '中', '3', '夜', T.PRO_BC) PRO_BC,
       DECODE(T.PRO_BZ,
              '1',
              '甲',
              '2',
              '乙',
              '3',
              '丙',
              '4',
              '丁',
              T.PRO_BZ) PRO_BZ,
       (SELECT MAX(BASENAME) FROM COM_BASE_INFO  WHERE basecode=T.STOP_TYPE) STOP_TYPE,
       (SELECT MAX(BASENAME) FROM COM_BASE_INFO  WHERE basecode=T.STOP_SMALL) STOP_SMALL,
       (SELECT MAX(BASENAME) FROM COM_BASE_INFO  WHERE basecode=T.STOP_REASON) STOP_REASON,
       T.MEMO,
       DECODE(T.CONFIRM_FLAG, '1', '确认', '0', '未确认', T.CONFIRM_FLAG) CONFIRM_FLAG,
       T.USER_NAME,
       T.CONFIRM_NAME,
       T.USER_DATE,
       T.CONFIRM_TIME,
       0 AS flag,
       NULL AS TJHOURS,
       (SELECT DEPT FROM COM_BASE_INFO WHERE BASECODE = T.STOP_REASON) DEPT
	  FROM MIL_CONTROL_LOG T
	 WHERE T.PRO_TYPE = '2'
	   AND TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >= to_date('#DATE1#'|| ' 21:00:00','yyyy-mm-dd hh24:mi:ss')
	   AND TO_DATE(T.Logs_End, 'yyyy-mm-dd hh24:mi:ss') <= to_date('#DATE#'|| ' 21:00:00','yyyy-mm-dd hh24:mi:ss')
	   AND T.PLINE_CODE ='#PLINECODE#'
	 ORDER BY T.PLINE_CODE, T.LOGS_BEG DESC
	 ),
	 t2
	AS
	(
	 SELECT *  FROM t1
	 UNION ALL
	SELECT TJ_DATE,SUM(TJ_TIME),NULL,NULL,PLINE_NAME,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, 1 AS FLAG,ROUND(SUM(TJ_TIME)/60,2),NULL FROM t1
	GROUP BY TJ_DATE,PLINE_NAME
	 UNION ALL
	SELECT '1900-01-01',SUM(TJ_TIME),NULL,NULL,PLINE_NAME,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, 2 AS FLAG,ROUND(SUM(TJ_TIME)/60,2),NULL FROM t1
	GROUP BY PLINE_NAME
	)
	SELECT * FROM t2
	ORDER BY TJ_DATE DESC,FLAG
	]]>
	</query>
	<query id="BuyGpDAL.selectLGTJ1" desc="获取调度停机数据(炼钢)新">
	<![CDATA[
       WITH t1
		AS
		(
		SELECT CASE
         WHEN (TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
              TO_DATE(SUBSTR(T.LOGS_BEG, 1, 8) || '2100',
                       'yyyy-mm-dd hh24:mi:ss')) THEN
          TO_CHAR(TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') + 1,
                  'yyyy-MM-dd')
         ELSE
          TO_CHAR(TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss'),
                  'yyyy-MM-dd')
       END TJ_DATE,
       ROUND((TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
           TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60,0) AS TJ_TIME,
       TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') LOGS_BEG,
       TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') LOGS_END,
       (SELECT PLINE_NAME FROM Com_Base_Pline WHERE pline_code = T.EF_PLINE_CODE) PLINE_NAME,
       DECODE(T.PRO_BC, '1', '早', '2', '中', '3', '夜', T.PRO_BC) PRO_BC,
       DECODE(T.PRO_BZ,
              '1',
              '甲',
              '2',
              '乙',
              '3',
              '丙',
              '4',
              '丁',
              T.PRO_BZ) PRO_BZ,
       (SELECT MAX(BASENAME) FROM COM_BASE_INFO  WHERE basecode=T.STOP_TYPE) STOP_TYPE,
       (SELECT MAX(BASENAME) FROM COM_BASE_INFO  WHERE basecode=T.STOP_SMALL) STOP_SMALL,
       (SELECT MAX(BASENAME) FROM COM_BASE_INFO  WHERE basecode=T.STOP_REASON) STOP_REASON,
       T.MEMO,
       DECODE(T.CONFIRM_FLAG, '1', '确认', '0', '未确认', T.CONFIRM_FLAG) CONFIRM_FLAG,
       T.USER_NAME,
       T.CONFIRM_NAME,
       T.USER_DATE,
       T.CONFIRM_TIME,
       0 AS flag,
       NULL AS TJHOURS,
       (SELECT DEPT FROM COM_BASE_INFO WHERE BASECODE = T.STOP_REASON) DEPT
	  FROM STL_CONTROL_LOG T
	 WHERE T.PRO_TYPE = '2'
	   AND TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >= to_date('#DATE1#'|| ' 21:00:00','yyyy-mm-dd hh24:mi:ss')
	   AND TO_DATE(T.Logs_End, 'yyyy-mm-dd hh24:mi:ss') <= to_date('#DATE#'|| ' 21:00:00','yyyy-mm-dd hh24:mi:ss')
	   AND T.EF_PLINE_CODE ='#PLINECODE#'
	 ORDER BY T.PLINE_CODE, T.LOGS_BEG DESC
	 ),
	 t2
	AS
	(
	 SELECT *  FROM t1
	 UNION ALL
	SELECT TJ_DATE,SUM(TJ_TIME),NULL,NULL,PLINE_NAME,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, 1 AS FLAG,ROUND(SUM(TJ_TIME)/60,2),NULL FROM t1
	GROUP BY TJ_DATE,PLINE_NAME
	 UNION ALL
	SELECT '1900-01-01',SUM(TJ_TIME),NULL,NULL,PLINE_NAME,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, 2 AS FLAG,ROUND(SUM(TJ_TIME)/60,2),NULL FROM t1
	GROUP BY PLINE_NAME
	)
	SELECT * FROM t2
	ORDER BY TJ_DATE DESC,FLAG
	]]>
	</query>
	<query id="BuyGpDAL.selectRCLTJ" desc="获取热处理调度停机数据(不包含元通)">
	<![CDATA[
      WITH t1
	    AS
	    (
	    SELECT CASE
	         WHEN (TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
	              TO_DATE(SUBSTR(T.LOGS_BEG, 1, 8) || '2100',
	                       'yyyy-mm-dd hh24:mi:ss')) THEN
	          TO_CHAR(TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') + 1,
	                  'yyyy-MM-dd')
	         ELSE
	          TO_CHAR(TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss'),
	                  'yyyy-MM-dd')
	       END TJ_DATE,
	       ROUND((TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
	           TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60,0) AS TJ_TIME,
	       TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') LOGS_BEG,
	       TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') LOGS_END,
	       (SELECT PLINE_NAME FROM Com_Base_Pline WHERE pline_code = T.PLINE_CODE) PLINE_NAME,
	       DECODE(T.PRO_BC, '1', '早', '2', '中', '3', '夜', T.PRO_BC) PRO_BC,
	       DECODE(T.PRO_BZ,
	              '1',
	              '甲',
	              '2',
	              '乙',
	              '3',
	              '丙',
	              '4',
	              '丁',
	              T.PRO_BZ) PRO_BZ,
	       (SELECT MAX(BASENAME) FROM COM_BASE_INFO  WHERE basecode=T.STOP_TYPE) STOP_TYPE,
	       (SELECT MAX(BASENAME) FROM COM_BASE_INFO  WHERE basecode=T.STOP_SMALL) STOP_SMALL,
	       (SELECT MAX(BASENAME) FROM COM_BASE_INFO  WHERE basecode=T.STOP_REASON) STOP_REASON,
	       T.MEMO,
	       DECODE(T.CONFIRM_FLAG, '2','已审核','1', '确认', '0', '未确认', T.CONFIRM_FLAG) CONFIRM_FLAG,
	       T.USER_NAME,
	       T.CONFIRM_NAME,
	       T.USER_DATE,
	       T.CONFIRM_TIME,
	       0 AS flag,
	       NULL AS TJHOURS,
	       (SELECT DEPT FROM COM_BASE_INFO WHERE BASECODE = T.STOP_REASON) DEPT
	    FROM (SELECT T.CONTROL_ID,
	                         T.LOGS_BEG,
	                         T.LOGS_END,
	                         T.PLINE_CODE,
	                         T.STOP_TYPE,
	                         T.STOP_REASON,
	                         T.STOP_SMALL,
	                         T.CONFIRM_TIME,
	                         T.USER_DATE,
	                         T.CONFIRM_NAME,
	                         T.USER_NAME,
	                         T.CONFIRM_FLAG,
	                         T.MEMO,
	                         T.PRO_BZ,
	                         T.PRO_BC
	                    FROM HTT_CONTROL_LOG T
	                    --, HTT_CONTROL_LOG_DETAIL T1
	                    WHERE T.PRO_TYPE = '2' AND T.STATION IN ('#STATION#')
	                    --AND T.CONTROL_ID = T1.CONTROL_ID
	                    AND TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
	                        TO_DATE('#DATE1#'|| ' 21:00:00', 'yyyy-mm-dd hh24:mi:ss')
	                   AND TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
	                        TO_DATE('#DATE#'|| ' 21:00:00', 'yyyy-mm-dd hh24:mi:ss')
	                   AND T.PLINE_CODE = '#PLINECODE#') T
	
	   ORDER BY T.PLINE_CODE, T.LOGS_BEG DESC
	   ),
	   t2
	  AS
	  (
	   SELECT *  FROM t1
	   UNION ALL
	  SELECT TJ_DATE,SUM(TJ_TIME),NULL,NULL,PLINE_NAME,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, 1 AS FLAG,ROUND(SUM(TJ_TIME)/60,2),NULL FROM t1
	  GROUP BY TJ_DATE,PLINE_NAME
	   UNION ALL
	  SELECT '1900-01-01',SUM(TJ_TIME),NULL,NULL,PLINE_NAME,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, 2 AS FLAG,ROUND(SUM(TJ_TIME)/60,2),NULL FROM t1
	  GROUP BY PLINE_NAME
	  )
	  SELECT * FROM t2
	  ORDER BY TJ_DATE DESC,FLAG 
	]]>
	</query>
	<query id="BuyGpDAL.selectRCLTJG" desc="获取加工线调度停机数据">
	<![CDATA[
      WITH t1
	    AS
	    (
	    SELECT CASE
	         WHEN (TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
	              TO_DATE(SUBSTR(T.LOGS_BEG, 1, 8) || '2100',
	                       'yyyy-mm-dd hh24:mi:ss')) THEN
	          TO_CHAR(TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') + 1,
	                  'yyyy-MM-dd')
	         ELSE
	          TO_CHAR(TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss'),
	                  'yyyy-MM-dd')
	       END TJ_DATE,
	       ROUND((TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
	           TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60,0) AS TJ_TIME,
	       TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') LOGS_BEG,
	       TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') LOGS_END,
	       (SELECT PLINE_NAME FROM Com_Base_Pline WHERE pline_code = T.PLINE_CODE) PLINE_NAME,
	       DECODE(T.PRO_BC, '1', '早', '2', '中', '3', '夜', T.PRO_BC) PRO_BC,
	       DECODE(T.PRO_BZ,
	              '1',
	              '甲',
	              '2',
	              '乙',
	              '3',
	              '丙',
	              '4',
	              '丁',
	              T.PRO_BZ) PRO_BZ,
	       (SELECT MAX(BASENAME) FROM COM_BASE_INFO  WHERE basecode=T.STOP_TYPE) STOP_TYPE,
	       (SELECT MAX(BASENAME) FROM COM_BASE_INFO  WHERE basecode=T.STOP_SMALL) STOP_SMALL,
	       (SELECT MAX(BASENAME) FROM COM_BASE_INFO  WHERE basecode=T.STOP_REASON) STOP_REASON,
	       T.MEMO,
	       DECODE(T.CONFIRM_FLAG, '2','已审核','1', '确认', '0', '未确认', T.CONFIRM_FLAG) CONFIRM_FLAG,
	       T.USER_NAME,
	       T.CONFIRM_NAME,
	       T.USER_DATE,
	       T.CONFIRM_TIME,
	       0 AS flag,
	       NULL AS TJHOURS,
	       (SELECT DEPT FROM COM_BASE_INFO WHERE BASECODE = T.STOP_REASON) DEPT
	    FROM (SELECT T.CONTROL_ID,
	                         T.LOGS_BEG,
	                         T.LOGS_END,
	                         T.PLINE_CODE,
	                         T.STOP_TYPE,
	                         T.STOP_REASON,
	                         T.STOP_SMALL,
	                         T.CONFIRM_TIME,
	                         T.USER_DATE,
	                         T.CONFIRM_NAME,
	                         T.USER_NAME,
	                         T.CONFIRM_FLAG,
	                         T.MEMO,
	                         T.PRO_BZ,
	                         T.PRO_BC
	                    FROM HTT_CONTROL_LOG T
	                    --, HTT_CONTROL_LOG_DETAIL T1
	                    WHERE T.PRO_TYPE = '2' 
	                    --AND T.CONTROL_ID = T1.CONTROL_ID
	                    AND TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
	                        TO_DATE('#DATE1#'|| ' 21:00:00', 'yyyy-mm-dd hh24:mi:ss')
	                   AND TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
	                        TO_DATE('#DATE#'|| ' 21:00:00', 'yyyy-mm-dd hh24:mi:ss')
	                   AND T.PLINE_CODE = '#PLINECODE#'
	                   )T
	   ORDER BY T.PLINE_CODE, T.LOGS_BEG DESC
	   ),
	   t2
	  AS
	  (
	   SELECT *  FROM t1
	   UNION ALL
	  SELECT TJ_DATE,SUM(TJ_TIME),NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, 1 AS FLAG,ROUND(SUM(TJ_TIME)/60,2),NULL FROM t1
	  GROUP BY TJ_DATE
	   UNION ALL
	  SELECT '1900-01-01',SUM(TJ_TIME),NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, 2 AS FLAG,ROUND(SUM(TJ_TIME)/60,2),NULL FROM t1
	  --GROUP BY PLINE_NAME
	  )
	  SELECT * FROM t2
	  ORDER BY TJ_DATE DESC,FLAG,PLINE_NAME
	]]>
	</query>
		<query id="BuyGpDAL.selectRCLTJ1" desc="获取热处理调度停机数据(元通热处理 C049 C050)">
	<![CDATA[
      WITH t1
	    AS
	    (
	    SELECT CASE
	         WHEN (TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
	              TO_DATE(SUBSTR(T.LOGS_BEG, 1, 8) || '2000',
	                       'yyyy-mm-dd hh24:mi:ss')) THEN
	          TO_CHAR(TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') + 1,
	                  'yyyy-MM-dd')
	         ELSE
	          TO_CHAR(TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss'),
	                  'yyyy-MM-dd')
	       END TJ_DATE,
	       ROUND((TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
	           TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60,0) AS TJ_TIME,
	       TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') LOGS_BEG,
	       TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') LOGS_END,
	       (SELECT PLINE_NAME FROM Com_Base_Pline WHERE pline_code = T.PLINE_CODE) PLINE_NAME,
	       DECODE(T.PRO_BC, '1', '早', '2', '中', '3', '夜', T.PRO_BC) PRO_BC,
	       DECODE(T.PRO_BZ,
	              '1',
	              '甲',
	              '2',
	              '乙',
	              '3',
	              '丙',
	              '4',
	              '丁',
	              T.PRO_BZ) PRO_BZ,
	       (SELECT MAX(BASENAME) FROM COM_BASE_INFO  WHERE basecode=T.STOP_TYPE) STOP_TYPE,
	       (SELECT MAX(BASENAME) FROM COM_BASE_INFO  WHERE basecode=T.STOP_SMALL) STOP_SMALL,
	       (SELECT MAX(BASENAME) FROM COM_BASE_INFO  WHERE basecode=T.STOP_REASON) STOP_REASON,
	       T.MEMO,
	       DECODE(T.CONFIRM_FLAG, '2','已审核','1', '确认', '0', '未确认', T.CONFIRM_FLAG) CONFIRM_FLAG,
	       T.USER_NAME,
	       T.CONFIRM_NAME,
	       T.USER_DATE,
	       T.CONFIRM_TIME,
	       0 AS flag,
	       NULL AS TJHOURS,
	       (SELECT DEPT FROM COM_BASE_INFO WHERE BASECODE = T.STOP_REASON) DEPT
	    FROM (SELECT T.CONTROL_ID,
	                         T.LOGS_BEG,
	                         T.LOGS_END,
	                         T.PLINE_CODE,
	                         T.STOP_TYPE,
	                         T.STOP_REASON,
	                         T.STOP_SMALL,
	                         T.CONFIRM_TIME,
	                         T.USER_DATE,
	                         T.CONFIRM_NAME,
	                         T.USER_NAME,
	                         T.CONFIRM_FLAG,
	                         T.MEMO,
	                         T.PRO_BZ,
	                         T.PRO_BC
	                    FROM HTT_CONTROL_LOG T
	                    --, HTT_CONTROL_LOG_DETAIL T1
	                    WHERE T.PRO_TYPE = '2' AND T.STATION IN ('#STATION#')
	                    --AND T.CONTROL_ID = T1.CONTROL_ID
	                    AND TO_DATE(T.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
	                        TO_DATE('#DATE1#'|| ' 20:00:00', 'yyyy-mm-dd hh24:mi:ss')
	                   AND TO_DATE(T.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
	                        TO_DATE('#DATE#'|| ' 20:00:00', 'yyyy-mm-dd hh24:mi:ss')
	                   AND T.PLINE_CODE = '#PLINECODE#') T
	
	   ORDER BY T.PLINE_CODE, T.LOGS_BEG DESC
	   ),
	   t2
	  AS
	  (
	   SELECT *  FROM t1
	   UNION ALL
	  SELECT TJ_DATE,SUM(TJ_TIME),NULL,NULL,PLINE_NAME,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, 1 AS FLAG,ROUND(SUM(TJ_TIME)/60,2),NULL FROM t1
	  GROUP BY TJ_DATE,PLINE_NAME
	   UNION ALL
	  SELECT '1900-01-01',SUM(TJ_TIME),NULL,NULL,PLINE_NAME,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, 2 AS FLAG,ROUND(SUM(TJ_TIME)/60,2),NULL FROM t1
	  GROUP BY PLINE_NAME
	  )
	  SELECT * FROM t2
	  ORDER BY TJ_DATE DESC,FLAG 
	]]>
	</query>
	<query id="BuyGpDAL.selectLGDDTJ" desc="获取炼钢调度停机图数据">
	<![CDATA[
	--形成初始表结构
	WITH t
	AS
	(
	SELECT * FROM
	(
	SELECT               
	                  DISTINCT     CASE WHEN T10.STOP_SMALL ='30010201' THEN '工艺停机'
                               ELSE (SELECT DEPT FROM COM_BASE_INFO WHERE BASECODE = T10.STOP_REASON) END DEPT
	                  FROM STL_CONTROL_LOG T10
	                 WHERE T10.PRO_TYPE = '2'
	                  AND TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
	                       TO_DATE('#STARTDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
	                   AND TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
	                       TO_DATE('#ENDDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
	                   AND T10.STOP_TYPE IN ('300101', '300102')
	                   AND T10.EF_PLINE_CODE IN ('#PLINECODE#')
	                   AND EXISTS (SELECT *
	                          FROM COM_BASE_INFO
	                         WHERE BASECODE = T10.STOP_REASON
	                           AND VALIDFLAG = '1')
	 ) ta ,(
	 SELECT to_char(TO_DATE('#ENDDATE#', 'yyyy-mm-dd hh24:mi:ss') - LEVEL + 1, 'yyyy-mm-dd') dates FROM DUAL connect BY LEVEL <= #DAYS#
	 ) tb
	 ORDER BY dates,DEPT
	 ),
	 --炼钢调度汇报实际数值
	t1 AS
	(
	SELECT ta.tj_date,ta.dept,ta.plinename,ta.plinecode,SUM(ta.tjtime) tjtime FROM
	(
	SELECT                T10.STOP_REASON,
	                       T10.LOGS_BEG,
	                       T10.LOGS_END,
	                       CASE
	                         WHEN (TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
	                              TO_DATE(SUBSTR(T10.LOGS_BEG, 1, 8) || '2100',
	                                       'yyyy-mm-dd hh24:mi:ss')) THEN
	                          TO_CHAR(TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') + 1,
	                                  'yyyy-MM-dd')
	                         ELSE
	                          TO_CHAR(TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss'),
	                                  'yyyy-MM-dd')
	                       END TJ_DATE,
	                       (TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
	                       TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
	                       CASE WHEN T10.STOP_SMALL ='30010201' THEN '工艺停机'
                               ELSE (SELECT DEPT FROM COM_BASE_INFO WHERE BASECODE = T10.STOP_REASON) END DEPT,
	                       (SELECT PLINE_NAME
	                          FROM COM_BASE_PLINE
	                         WHERE PLINE_CODE = T10.EF_PLINE_CODE) PLINENAME,
	                       T10.EF_PLINE_CODE PLINECODE
	                  FROM STL_CONTROL_LOG T10
	                 WHERE T10.PRO_TYPE = '2'
	                  AND TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
	                       TO_DATE('#STARTDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
	                   AND TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
	                       TO_DATE('#ENDDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
	                   AND T10.STOP_TYPE IN ('300101', '300102')
	                   AND T10.EF_PLINE_CODE IN ('#PLINECODE#')
	                   AND EXISTS (SELECT *
	                          FROM COM_BASE_INFO
	                         WHERE BASECODE = T10.STOP_REASON
	                           AND VALIDFLAG = '1')
	) ta
	GROUP BY ta.tj_date,ta.dept,ta.plinename,ta.plinecode
	ORDER BY ta.tj_date,ta.plinename,ta.plinecode
	),
	--各个部门停机元素明细
	t2 AS
	(
	SELECT t.*,nvl(t1.tjtime,0) tjtime FROM t,t1 WHERE t.dates = t1.tj_date(+) AND t.dept = t1.dept(+)
	ORDER BY t.dates
	),
	t3 AS
	(
	SELECT '作业时间' ,TO_DATE(dates, 'yyyy-mm-dd hh24:mi:ss') dates,ROUND((24*60 -sum(tjtime))/60,2) zytime FROM t2 GROUP BY dates
	),
	t4 AS
	(
	SELECT t2.dept,TO_DATE(t2.dates, 'yyyy-mm-dd hh24:mi:ss') opdate,CAST(tjtime/60 as number(8,2)) optime FROM t2
	UNION ALL
	SELECT * FROM t3
	)
	SELECT * FROM t4
	ORDER BY opdate,dept desc
 
		]]>
	</query>
	<query id="BuyGpDAL.selectLGDDTJAll" desc="获取炼钢调度停机图数据全部（汇总）">
	<![CDATA[
	--形成初始表结构
	WITH t
	AS
	(
	SELECT * FROM
	(
	SELECT               
	                  DISTINCT     CASE WHEN T10.STOP_SMALL ='30010201' THEN '工艺停机'
                               ELSE (SELECT DEPT FROM COM_BASE_INFO WHERE BASECODE = T10.STOP_REASON) END DEPT
	                  FROM STL_CONTROL_LOG T10
	                 WHERE T10.PRO_TYPE = '2'
	                  AND TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
	                       TO_DATE('#STARTDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
	                   AND TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
	                       TO_DATE('#ENDDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
	                   AND T10.STOP_TYPE IN ('300101', '300102')
	                   AND T10.EF_PLINE_CODE IN ('C001','C003')
	                   AND EXISTS (SELECT *
	                          FROM COM_BASE_INFO
	                         WHERE BASECODE = T10.STOP_REASON
	                           AND VALIDFLAG = '1')
	 ) ta ,(
	 SELECT to_char(TO_DATE('#ENDDATE#', 'yyyy-mm-dd hh24:mi:ss') - LEVEL + 1, 'yyyy-mm-dd') dates FROM DUAL connect BY LEVEL <= #DAYS#
	 ) tb
	 ORDER BY dates,DEPT
	 ),
	 --炼钢调度汇报实际数值
	t1 AS
	(select tb.tj_date,tb.dept,SUM(tb.tjtime)/(2670+2670) tjtime from
	(
	SELECT ta.tj_date,ta.dept,ta.plinename,ta.plinecode,
	DECODE(ta.plinecode,'C001',SUM(ta.tjtime)*2670,'C003',SUM(ta.tjtime)*2670) tjtime FROM
	(
	SELECT                T10.STOP_REASON,
	                       T10.LOGS_BEG,
	                       T10.LOGS_END,
	                       CASE
	                         WHEN (TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
	                              TO_DATE(SUBSTR(T10.LOGS_BEG, 1, 8) || '2100',
	                                       'yyyy-mm-dd hh24:mi:ss')) THEN
	                          TO_CHAR(TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') + 1,
	                                  'yyyy-MM-dd')
	                         ELSE
	                          TO_CHAR(TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss'),
	                                  'yyyy-MM-dd')
	                       END TJ_DATE,
	                       (TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
	                       TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
	                       CASE WHEN T10.STOP_SMALL ='30010201' THEN '工艺停机'
                               ELSE (SELECT DEPT FROM COM_BASE_INFO WHERE BASECODE = T10.STOP_REASON) END DEPT,
	                       (SELECT PLINE_NAME
	                          FROM COM_BASE_PLINE
	                         WHERE PLINE_CODE = T10.EF_PLINE_CODE) PLINENAME,
	                       T10.EF_PLINE_CODE PLINECODE
	                  FROM STL_CONTROL_LOG T10
	                 WHERE T10.PRO_TYPE = '2'
	                  AND TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
	                       TO_DATE('#STARTDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
	                   AND TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
	                       TO_DATE('#ENDDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
	                   AND T10.STOP_TYPE IN ('300101', '300102')
	                   AND T10.EF_PLINE_CODE IN ('C001','C003')
	                   AND EXISTS (SELECT *
	                          FROM COM_BASE_INFO
	                         WHERE BASECODE = T10.STOP_REASON
	                           AND VALIDFLAG = '1')
	) ta
	GROUP BY ta.tj_date,ta.dept,ta.plinename,ta.plinecode
	ORDER BY ta.tj_date,ta.plinename,ta.plinecode
	)tb
	GROUP BY tb.tj_date,tb.dept
	),
	--各个部门停机元素明细
	t2 AS
	(
	SELECT t.*,nvl(t1.tjtime,0) tjtime FROM t,t1 WHERE t.dates = t1.tj_date(+) AND t.dept = t1.dept(+)
	ORDER BY t.dates
	),
	t3 AS
	(
	SELECT '作业时间' ,TO_DATE(dates, 'yyyy-mm-dd hh24:mi:ss') dates,ROUND((24*60 -sum(tjtime))/60,2) zytime FROM t2 GROUP BY dates
	),
	t4 AS
	(
	SELECT t2.dept,TO_DATE(t2.dates, 'yyyy-mm-dd hh24:mi:ss') opdate,CAST(tjtime/60 as number(8,2)) optime FROM t2
	UNION ALL
	SELECT * FROM t3
	)
	SELECT * FROM t4
	ORDER BY opdate,dept desc
 
		]]>
	</query>
    <query id="BuyGpDAL.selectZGDDTJ" desc="获取轧制调度停机图数据">
	<![CDATA[
    WITH t
		  AS
		  (
		  SELECT * FROM
		  (
		  SELECT               
		                    DISTINCT     CASE WHEN T10.STOP_SMALL ='50060201' THEN '工艺停机'
                               ELSE (SELECT DEPT FROM COM_BASE_INFO WHERE BASECODE = T10.STOP_REASON) END DEPT
		                    FROM MIL_CONTROL_LOG T10
		                   WHERE T10.PRO_TYPE = '2'
		                    AND TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
			                       TO_DATE('#STARTDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
			                   AND TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
			                       TO_DATE('#ENDDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
		                     AND T10.STOP_TYPE IN ('500601', '500602')
		                     AND T10.PLINE_CODE IN ('#PLINECODE#')
		                     AND EXISTS (SELECT *
		                            FROM COM_BASE_INFO
		                           WHERE BASECODE = T10.STOP_REASON
		                             AND VALIDFLAG = '1')
		   ) ta ,(
		   SELECT to_char(TO_DATE('#ENDDATE#', 'yyyy-mm-dd hh24:mi:ss') - LEVEL + 1, 'yyyy-mm-dd') dates FROM DUAL connect BY LEVEL <= #DAYS#
		   ) tb
		   ORDER BY dates,DEPT
		   ),
		    t1 AS
		  (
		  SELECT ta.tj_date,ta.dept,ta.plinename,ta.plinecode,SUM(ta.tjtime) tjtime FROM
		  (
		  SELECT                T10.STOP_REASON,
		                         T10.LOGS_BEG,
		                         T10.LOGS_END,
		                         CASE
		                           WHEN (TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
		                                TO_DATE(SUBSTR(T10.LOGS_BEG, 1, 8) || '2100',
		                                         'yyyy-mm-dd hh24:mi:ss')) THEN
		                            TO_CHAR(TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') + 1,
		                                    'yyyy-MM-dd')
		                           ELSE
		                            TO_CHAR(TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss'),
		                                    'yyyy-MM-dd')
		                         END TJ_DATE,
		                         (TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
		                         TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
		                         CASE WHEN T10.STOP_SMALL ='50060201' THEN '工艺停机'
                                 ELSE (SELECT DEPT FROM COM_BASE_INFO WHERE BASECODE = T10.STOP_REASON) END DEPT,
		                         (SELECT PLINE_NAME
		                            FROM COM_BASE_PLINE
		                           WHERE PLINE_CODE = T10.PLINE_CODE) PLINENAME,
		                         T10.PLINE_CODE PLINECODE
		                    FROM MIL_CONTROL_LOG T10
		                   WHERE T10.PRO_TYPE = '2'
		                    AND TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
			                       TO_DATE('#STARTDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
			                   AND TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
			                       TO_DATE('#ENDDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
		                     AND T10.STOP_TYPE IN ('500601', '500602')
		                     AND T10.PLINE_CODE IN ('#PLINECODE#')
		                     AND EXISTS (SELECT *
		                            FROM COM_BASE_INFO
		                           WHERE BASECODE = T10.STOP_REASON
		                             AND VALIDFLAG = '1')
		  ) ta
		  GROUP BY ta.tj_date,ta.dept,ta.plinename,ta.plinecode
		  ORDER BY ta.tj_date,ta.plinename,ta.plinecode
		  ),
		    t2 AS
		  (
		  SELECT t.*,nvl(t1.tjtime,0) tjtime FROM t,t1 WHERE t.dates = t1.tj_date(+) AND t.dept = t1.dept(+)
		  ORDER BY t.dates
		  ),
		  t3 AS
		  (
		  SELECT '作业时间' ,TO_DATE(dates, 'yyyy-mm-dd hh24:mi:ss') dates,ROUND((24*60 -sum(tjtime))/60,2) zytime FROM t2 GROUP BY dates
		  ),
		  t4 AS
		  (
		  SELECT t2.dept,TO_DATE(t2.dates, 'yyyy-mm-dd hh24:mi:ss') opdate,CAST(tjtime/60 as number(8,2)) optime FROM t2
		  UNION ALL
		  SELECT * FROM t3
		  )
		  SELECT * FROM t4
		  ORDER BY opdate,dept desc
 
		]]>
	</query>
	<query id="BuyGpDAL.selectZGDDTJAll" desc="获取轧制调度停机图数据全部（汇总）">
	<![CDATA[
    WITH t
		  AS
		  (
		  SELECT * FROM
		  (
		  SELECT               
		                    DISTINCT     CASE WHEN T10.STOP_SMALL ='50060201' THEN '工艺停机'
                               ELSE (SELECT DEPT FROM COM_BASE_INFO WHERE BASECODE = T10.STOP_REASON) END DEPT
		                    FROM MIL_CONTROL_LOG T10
		                   WHERE T10.PRO_TYPE = '2'
		                    AND TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
			                       TO_DATE('#STARTDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
			                   AND TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
			                       TO_DATE('#ENDDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
		                     AND T10.STOP_TYPE IN ('500601', '500602')
		                     AND T10.PLINE_CODE IN ('C008','C009','C010','C017')
		                     AND EXISTS (SELECT *
		                            FROM COM_BASE_INFO
		                           WHERE BASECODE = T10.STOP_REASON
		                             AND VALIDFLAG = '1')
		   ) ta ,(
		   SELECT to_char(TO_DATE('#ENDDATE#', 'yyyy-mm-dd hh24:mi:ss') - LEVEL + 1, 'yyyy-mm-dd') dates FROM DUAL connect BY LEVEL <= #DAYS#
		   ) tb
		   ORDER BY dates,DEPT
		   ),
		    t1 AS
		  (select tb.tj_date,tb.dept,SUM(tb.tjtime)/(2100+1670+1500+2500) tjtime from
		  (
		  SELECT ta.tj_date,ta.dept,ta.plinename,ta.plinecode,
		  DECODE(ta.plinecode,'C008',SUM(ta.tjtime)*2100,'C009',SUM(ta.tjtime)*1670
		  					 ,'C010',SUM(ta.tjtime)*1500,'C017',SUM(ta.tjtime)*2500 )  tjtime FROM
		  (
		  SELECT                T10.STOP_REASON,
		                         T10.LOGS_BEG,
		                         T10.LOGS_END,
		                         CASE
		                           WHEN (TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
		                                TO_DATE(SUBSTR(T10.LOGS_BEG, 1, 8) || '2100',
		                                         'yyyy-mm-dd hh24:mi:ss')) THEN
		                            TO_CHAR(TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') + 1,
		                                    'yyyy-MM-dd')
		                           ELSE
		                            TO_CHAR(TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss'),
		                                    'yyyy-MM-dd')
		                         END TJ_DATE,
		                         (TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
		                         TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
		                         CASE WHEN T10.STOP_SMALL ='50060201' THEN '工艺停机'
                                 ELSE (SELECT DEPT FROM COM_BASE_INFO WHERE BASECODE = T10.STOP_REASON) END DEPT,
		                         (SELECT PLINE_NAME
		                            FROM COM_BASE_PLINE
		                           WHERE PLINE_CODE = T10.PLINE_CODE) PLINENAME,
		                         T10.PLINE_CODE PLINECODE
		                    FROM MIL_CONTROL_LOG T10
		                   WHERE T10.PRO_TYPE = '2'
		                    AND TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
			                       TO_DATE('#STARTDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
			                   AND TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
			                       TO_DATE('#ENDDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
		                     AND T10.STOP_TYPE IN ('500601', '500602')
		                     AND T10.PLINE_CODE IN ('C008','C009','C010','C017')
		                     AND EXISTS (SELECT *
		                            FROM COM_BASE_INFO
		                           WHERE BASECODE = T10.STOP_REASON
		                             AND VALIDFLAG = '1')
		  ) ta
		  GROUP BY ta.tj_date,ta.dept,ta.plinename,ta.plinecode
		  ORDER BY ta.tj_date,ta.plinename,ta.plinecode
		  )tb
		  GROUP BY tb.tj_date,tb.dept
		  ),
		    t2 AS
		  (
		  SELECT t.*,nvl(t1.tjtime,0) tjtime FROM t,t1 WHERE t.dates = t1.tj_date(+) AND t.dept = t1.dept(+)
		  ORDER BY t.dates
		  ),
		  t3 AS
		  (
		  SELECT '作业时间' ,TO_DATE(dates, 'yyyy-mm-dd hh24:mi:ss') dates,ROUND((24*60 -sum(tjtime))/60,2) zytime FROM t2 GROUP BY dates
		  ),
		  t4 AS
		  (
		  SELECT t2.dept,TO_DATE(t2.dates, 'yyyy-mm-dd hh24:mi:ss') opdate,CAST(tjtime/60 as number(8,2)) optime FROM t2
		  UNION ALL
		  SELECT * FROM t3
		  )
		  SELECT * FROM t4
		  ORDER BY opdate,dept desc
 
		]]>
	</query>
	  <query id="BuyGpDAL.selectRCLDDTJ" desc="获取热处理调度停机图数据">
	<![CDATA[
    WITH t
      AS
      (
      SELECT * FROM
      (
      SELECT               
                        DISTINCT     CASE WHEN T10.STOP_SMALL ='60060309' THEN '工艺停机'
                               ELSE (SELECT DEPT FROM COM_BASE_INFO WHERE BASECODE = T10.STOP_REASON) END DEPT
                        FROM HTT_CONTROL_LOG T10
                       WHERE T10.PRO_TYPE = '2'
                        AND TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
			                       TO_DATE('#STARTDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
			                   AND TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
			                       TO_DATE('#ENDDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
                         AND T10.STOP_TYPE IN ('600602', '600603')
                         AND T10.PLINE_CODE IN ('#PLINECODE#')
                         AND T10.STATION IN ('#STATION#')
                         AND EXISTS (SELECT *
                                FROM COM_BASE_INFO
                               WHERE BASECODE = T10.STOP_REASON
                                 AND VALIDFLAG = '1')
                         AND (TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                             TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) >0
       ) ta ,(
        SELECT to_char(TO_DATE('#ENDDATE#', 'yyyy-mm-dd hh24:mi:ss') - LEVEL + 1, 'yyyy-mm-dd') dates FROM DUAL connect BY LEVEL <= #DAYS#
       ) tb
       ORDER BY dates,DEPT
       ),
        t1 AS
      (
      SELECT ta.tj_date,ta.dept,ta.plinename,ta.plinecode,SUM(ta.tjtime) tjtime FROM
      (
      SELECT                T10.STOP_REASON,
                             T10.LOGS_BEG,
                             T10.LOGS_END,
                             CASE
                               WHEN (TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                                    TO_DATE(SUBSTR(T10.LOGS_BEG, 1, 8) || '2100',
                                             'yyyy-mm-dd hh24:mi:ss')) THEN
                                TO_CHAR(TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') + 1,
                                        'yyyy-MM-dd')
                               ELSE
                                TO_CHAR(TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss'),
                                        'yyyy-MM-dd')
                             END TJ_DATE,
                             (TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                             TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                             CASE WHEN T10.STOP_SMALL ='60060309' THEN '工艺停机'
                                 ELSE (SELECT DEPT FROM COM_BASE_INFO WHERE BASECODE = T10.STOP_REASON) END DEPT,
                             (SELECT PLINE_NAME
                                FROM COM_BASE_PLINE
                               WHERE PLINE_CODE = T10.PLINE_CODE) PLINENAME,
                             T10.PLINE_CODE PLINECODE
                        FROM HTT_CONTROL_LOG T10
                       WHERE T10.PRO_TYPE = '2'
                        AND TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
			                       TO_DATE('#STARTDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
			                   AND TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
			                       TO_DATE('#ENDDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
                        AND T10.STOP_TYPE IN ('600602', '600603')
                         AND T10.PLINE_CODE IN ('#PLINECODE#')
                         AND T10.STATION IN ('#STATION#')
                         AND EXISTS (SELECT *
                                FROM COM_BASE_INFO
                               WHERE BASECODE = T10.STOP_REASON
                                 AND VALIDFLAG = '1')
                         AND (TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                             TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) >0
      ) ta
      GROUP BY ta.tj_date,ta.dept,ta.plinename,ta.plinecode
      ORDER BY ta.tj_date,ta.plinename,ta.plinecode
      ),
        t2 AS
      (
      SELECT t.*,nvl(t1.tjtime,0) tjtime FROM t,t1 WHERE t.dates = t1.tj_date(+) AND t.dept = t1.dept(+)
      ORDER BY t.dates
      ),
      t3 AS
      (
      SELECT '作业时间' ,TO_DATE(dates, 'yyyy-mm-dd hh24:mi:ss') dates,ROUND((24*60 -sum(tjtime))/60,2) zytime FROM t2 GROUP BY dates
      ),
      t4 AS
      (
      SELECT t2.dept,TO_DATE(t2.dates, 'yyyy-mm-dd hh24:mi:ss') opdate,CAST(tjtime/60 as number(8,2)) optime FROM t2
      UNION ALL
      SELECT * FROM t3
      )
      SELECT * FROM t4
      ORDER BY opdate,dept desc
 
		]]>
	</query>
	<query id="BuyGpDAL.selectRCLDDTJYT" desc="获取热处理调度停机图数据元通">
		<![CDATA[
    WITH t
      AS
      (
      SELECT * FROM
      (
      SELECT
                        DISTINCT     CASE WHEN T10.STOP_SMALL ='60060309' THEN '工艺停机'
                               ELSE (SELECT DEPT FROM COM_BASE_INFO WHERE BASECODE = T10.STOP_REASON) END DEPT
                        FROM HTT_CONTROL_LOG T10
                       WHERE T10.PRO_TYPE = '2'
                        AND TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
			                       TO_DATE('#STARTDATE#'||'2000', 'yyyy-mm-dd hh24:mi:ss')
			                   AND TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
			                       TO_DATE('#ENDDATE#'||'2000', 'yyyy-mm-dd hh24:mi:ss')
                         AND T10.STOP_TYPE IN ('600602', '600603')
                         AND T10.PLINE_CODE IN ('#PLINECODE#')
                         AND T10.STATION IN ('#STATION#')
                         AND EXISTS (SELECT *
                                FROM COM_BASE_INFO
                               WHERE BASECODE = T10.STOP_REASON
                                 AND VALIDFLAG = '1')
                         AND (TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                             TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) >0
       ) ta ,(
        SELECT to_char(TO_DATE('#ENDDATE#', 'yyyy-mm-dd hh24:mi:ss') - LEVEL + 1, 'yyyy-mm-dd') dates FROM DUAL connect BY LEVEL <= #DAYS#
       ) tb
       ORDER BY dates,DEPT
       ),
        t1 AS
      (
      SELECT ta.tj_date,ta.dept,ta.plinename,ta.plinecode,SUM(ta.tjtime) tjtime FROM
      (
      SELECT                T10.STOP_REASON,
                             T10.LOGS_BEG,
                             T10.LOGS_END,
                             CASE
                               WHEN (TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                                    TO_DATE(SUBSTR(T10.LOGS_BEG, 1, 8) || '2000',
                                             'yyyy-mm-dd hh24:mi:ss')) THEN
                                TO_CHAR(TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') + 1,
                                        'yyyy-MM-dd')
                               ELSE
                                TO_CHAR(TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss'),
                                        'yyyy-MM-dd')
                             END TJ_DATE,
                             (TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                             TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                             CASE WHEN T10.STOP_SMALL ='60060309' THEN '工艺停机'
                                 ELSE (SELECT DEPT FROM COM_BASE_INFO WHERE BASECODE = T10.STOP_REASON) END DEPT,
                             (SELECT PLINE_NAME
                                FROM COM_BASE_PLINE
                               WHERE PLINE_CODE = T10.PLINE_CODE) PLINENAME,
                             T10.PLINE_CODE PLINECODE
                        FROM HTT_CONTROL_LOG T10
                       WHERE T10.PRO_TYPE = '2'
                        AND TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
			                       TO_DATE('#STARTDATE#'||'2000', 'yyyy-mm-dd hh24:mi:ss')
			                   AND TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
			                       TO_DATE('#ENDDATE#'||'2000', 'yyyy-mm-dd hh24:mi:ss')
                        AND T10.STOP_TYPE IN ('600602', '600603')
                         AND T10.PLINE_CODE IN ('#PLINECODE#')
                         AND T10.STATION IN ('#STATION#')
                         AND EXISTS (SELECT *
                                FROM COM_BASE_INFO
                               WHERE BASECODE = T10.STOP_REASON
                                 AND VALIDFLAG = '1')
                         AND (TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                             TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) >0
      ) ta
      GROUP BY ta.tj_date,ta.dept,ta.plinename,ta.plinecode
      ORDER BY ta.tj_date,ta.plinename,ta.plinecode
      ),
        t2 AS
      (
      SELECT t.*,nvl(t1.tjtime,0) tjtime FROM t,t1 WHERE t.dates = t1.tj_date(+) AND t.dept = t1.dept(+)
      ORDER BY t.dates
      ),
      t3 AS
      (
      SELECT '作业时间' ,TO_DATE(dates, 'yyyy-mm-dd hh24:mi:ss') dates,ROUND((24*60 -sum(tjtime))/60,2) zytime FROM t2 GROUP BY dates
      ),
      t4 AS
      (
      SELECT t2.dept,TO_DATE(t2.dates, 'yyyy-mm-dd hh24:mi:ss') opdate,CAST(tjtime/60 as number(8,2)) optime FROM t2
      UNION ALL
      SELECT * FROM t3
      )
      SELECT * FROM t4
      ORDER BY opdate,dept desc

		]]>
	</query>
	<query id="BuyGpDAL.selectRCLDDTJAll" desc="获取热处理调度停机图数据全部（汇总）">
	<![CDATA[
    WITH t
      AS
      (
      SELECT * FROM
      (
      SELECT               
                        DISTINCT     CASE WHEN T10.STOP_SMALL ='60060309' THEN '工艺停机'
                               ELSE (SELECT DEPT FROM COM_BASE_INFO WHERE BASECODE = T10.STOP_REASON) END DEPT
                        FROM HTT_CONTROL_LOG T10
                       WHERE T10.PRO_TYPE = '2'
                        AND TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
			                       TO_DATE('#STARTDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
			                   AND TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
			                       TO_DATE('#ENDDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
                         AND T10.STOP_TYPE IN ('600602', '600603')
                         AND T10.PLINE_CODE IN ('C022','C023','C024','C025','C026',
                                                'C054','C055','C048','C049','C050')
                         AND T10.STATION IN ('#STATION#')
                         AND EXISTS (SELECT *
                                FROM COM_BASE_INFO
                               WHERE BASECODE = T10.STOP_REASON
                                 AND VALIDFLAG = '1')
       ) ta ,(
        SELECT to_char(TO_DATE('#ENDDATE#', 'yyyy-mm-dd hh24:mi:ss') - LEVEL + 1, 'yyyy-mm-dd') dates FROM DUAL connect BY LEVEL <= #DAYS#
       ) tb
       ORDER BY dates,DEPT
       ),
        t1 AS
      (SELECT tb.tj_date,tb.dept,sum(tb.tjtime)/(550+330+280+550+280+170+280+200+620+220) tjtime FROM
      (
      SELECT ta.tj_date,ta.dept,ta.plinename,ta.plinecode,
      DECODE(ta.plinecode,'C022',SUM(ta.tjtime)*550,'C023',SUM(ta.tjtime)*330
		  					 ,'C024',SUM(ta.tjtime)*280,'C025',SUM(ta.tjtime)*550
		  					 ,'C026',SUM(ta.tjtime)*280,'C054',SUM(ta.tjtime)*170
		  					 ,'C055',SUM(ta.tjtime)*280,'C048',SUM(ta.tjtime)*200
		  					 ,'C049',SUM(ta.tjtime)*620,'C050',SUM(ta.tjtime)*220)  tjtime FROM
      (
      SELECT                T10.STOP_REASON,
                             T10.LOGS_BEG,
                             T10.LOGS_END,
                             CASE
                               WHEN (TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                                    TO_DATE(SUBSTR(T10.LOGS_BEG, 1, 8) || '2100',
                                             'yyyy-mm-dd hh24:mi:ss')) THEN
                                TO_CHAR(TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') + 1,
                                        'yyyy-MM-dd')
                               ELSE
                                TO_CHAR(TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss'),
                                        'yyyy-MM-dd')
                             END TJ_DATE,
                             (TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                             TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                             CASE WHEN T10.STOP_SMALL ='60060309' THEN '工艺停机'
                                 ELSE (SELECT DEPT FROM COM_BASE_INFO WHERE BASECODE = T10.STOP_REASON) END DEPT,
                             (SELECT PLINE_NAME
                                FROM COM_BASE_PLINE
                               WHERE PLINE_CODE = T10.PLINE_CODE) PLINENAME,
                             T10.PLINE_CODE PLINECODE
                        FROM HTT_CONTROL_LOG T10
                       WHERE T10.PRO_TYPE = '2'
                        AND TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
			                       TO_DATE('#STARTDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
			                   AND TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
			                       TO_DATE('#ENDDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
                        AND T10.STOP_TYPE IN ('600602', '600603')
                         AND T10.PLINE_CODE IN ('C022','C023','C024','C025','C026',
                                                'C054','C055','C048','C049','C050')
                         AND T10.STATION IN ('#STATION#')
                         AND EXISTS (SELECT *
                                FROM COM_BASE_INFO
                               WHERE BASECODE = T10.STOP_REASON
                                 AND VALIDFLAG = '1')
                         AND (TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                             TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) >0
      ) ta
      GROUP BY ta.tj_date,ta.dept,ta.plinename,ta.plinecode
      ORDER BY ta.tj_date,ta.plinename,ta.plinecode
      )tb
      GROUP BY tb.tj_date,tb.dept
      ),
        t2 AS
      (
      SELECT t.*,nvl(t1.tjtime,0) tjtime FROM t,t1 WHERE t.dates = t1.tj_date(+) AND t.dept = t1.dept(+)
      ORDER BY t.dates
      ),
      t3 AS
      (
      SELECT '作业时间' ,TO_DATE(dates, 'yyyy-mm-dd hh24:mi:ss') dates,ROUND((24*60 -sum(tjtime))/60,2) zytime FROM t2 GROUP BY dates
      ),
      t4 AS
      (
      SELECT t2.dept,TO_DATE(t2.dates, 'yyyy-mm-dd hh24:mi:ss') opdate,CAST(tjtime/60 as number(8,2)) optime FROM t2
      UNION ALL
      SELECT * FROM t3
      )
      SELECT * FROM t4
      ORDER BY opdate,dept desc
 
		]]>
	</query>
	<query id="BuyGpDAL.selectRCLDDTJPARTIAL" desc="获取热处理调度停机图数据全部（分区域）">
	<![CDATA[
    WITH t
      AS
      (
      SELECT * FROM
      (
      SELECT               
                        DISTINCT     CASE WHEN T10.STOP_SMALL ='60060309' THEN '工艺停机'
                               ELSE (SELECT DEPT FROM COM_BASE_INFO WHERE BASECODE = T10.STOP_REASON) END DEPT
                        FROM HTT_CONTROL_LOG T10
                       WHERE T10.PRO_TYPE = '2'
                        AND TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
			                       TO_DATE('#STARTDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
			                   AND TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
			                       TO_DATE('#ENDDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
                         AND T10.STOP_TYPE IN ('600602', '600603')
                         AND T10.PLINE_CODE IN (#PLINECODE#)
                         AND T10.STATION IN ('#STATION#')
                         AND EXISTS (SELECT *
                                FROM COM_BASE_INFO
                               WHERE BASECODE = T10.STOP_REASON
                                 AND VALIDFLAG = '1')
       ) ta ,(
        SELECT to_char(TO_DATE('#ENDDATE#', 'yyyy-mm-dd hh24:mi:ss') - LEVEL + 1, 'yyyy-mm-dd') dates FROM DUAL connect BY LEVEL <= #DAYS#
       ) tb
       ORDER BY dates,DEPT
       ),
        t1 AS
      (SELECT tb.tj_date,tb.dept,sum(tb.tjtime)/DECODE('#REGION#','F01',(550+330+280+550+280),'F02',(170+280+200),'F03',(620+220),
                                                                 'F11',(550+330+280+550+280),'F12',(170+280+200),'F13',(620+220)) tjtime FROM
      (
      SELECT ta.tj_date,ta.dept,ta.plinename,ta.plinecode,
      DECODE(ta.plinecode,'C022',SUM(ta.tjtime)*550,'C023',SUM(ta.tjtime)*330
		  					 ,'C024',SUM(ta.tjtime)*280,'C025',SUM(ta.tjtime)*550
		  					 ,'C026',SUM(ta.tjtime)*280,'C054',SUM(ta.tjtime)*170
		  					 ,'C055',SUM(ta.tjtime)*280,'C048',SUM(ta.tjtime)*200
		  					 ,'C049',SUM(ta.tjtime)*620,'C050',SUM(ta.tjtime)*220)  tjtime FROM
      (
      SELECT                T10.STOP_REASON,
                             T10.LOGS_BEG,
                             T10.LOGS_END,
                             CASE
                               WHEN (TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                                    TO_DATE(SUBSTR(T10.LOGS_BEG, 1, 8) || '2100',
                                             'yyyy-mm-dd hh24:mi:ss')) THEN
                                TO_CHAR(TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') + 1,
                                        'yyyy-MM-dd')
                               ELSE
                                TO_CHAR(TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss'),
                                        'yyyy-MM-dd')
                             END TJ_DATE,
                             (TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                             TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                             CASE WHEN T10.STOP_SMALL ='60060309' THEN '工艺停机'
                                 ELSE (SELECT DEPT FROM COM_BASE_INFO WHERE BASECODE = T10.STOP_REASON) END DEPT,
                             (SELECT PLINE_NAME
                                FROM COM_BASE_PLINE
                               WHERE PLINE_CODE = T10.PLINE_CODE) PLINENAME,
                             T10.PLINE_CODE PLINECODE
                        FROM HTT_CONTROL_LOG T10
                       WHERE T10.PRO_TYPE = '2'
                        AND TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
			                       TO_DATE('#STARTDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
			                   AND TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
			                       TO_DATE('#ENDDATE#'||'2100', 'yyyy-mm-dd hh24:mi:ss')
                        AND T10.STOP_TYPE IN ('600602', '600603')
                         AND T10.PLINE_CODE IN (#PLINECODE#)
                         AND T10.STATION IN ('#STATION#')
                         AND EXISTS (SELECT *
                                FROM COM_BASE_INFO
                               WHERE BASECODE = T10.STOP_REASON
                                 AND VALIDFLAG = '1')
                         AND (TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                             TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) >0
      ) ta
      GROUP BY ta.tj_date,ta.dept,ta.plinename,ta.plinecode
      ORDER BY ta.tj_date,ta.plinename,ta.plinecode
      )tb
      GROUP BY tb.tj_date,tb.dept
      ),
        t2 AS
      (
      SELECT t.*,nvl(t1.tjtime,0) tjtime FROM t,t1 WHERE t.dates = t1.tj_date(+) AND t.dept = t1.dept(+)
      ORDER BY t.dates
      ),
      t3 AS
      (
      SELECT '作业时间' ,TO_DATE(dates, 'yyyy-mm-dd hh24:mi:ss') dates,ROUND((24*60 -sum(tjtime))/60,2) zytime FROM t2 GROUP BY dates
      ),
      t4 AS
      (
      SELECT t2.dept,TO_DATE(t2.dates, 'yyyy-mm-dd hh24:mi:ss') opdate,CAST(tjtime/60 as number(8,2)) optime FROM t2
      UNION ALL
      SELECT * FROM t3
      )
      SELECT * FROM t4
      ORDER BY opdate,dept desc
 
		]]>
	</query>
	<query id="BuyGpDAL.selectRCLDDTJPARTIALYT" desc="获取热处理调度停机图数据全部元通（分区域）">
		<![CDATA[
    WITH t
      AS
      (
      SELECT * FROM
      (
      SELECT
                        DISTINCT     CASE WHEN T10.STOP_SMALL ='60060309' THEN '工艺停机'
                               ELSE (SELECT DEPT FROM COM_BASE_INFO WHERE BASECODE = T10.STOP_REASON) END DEPT
                        FROM HTT_CONTROL_LOG T10
                       WHERE T10.PRO_TYPE = '2'
                        AND TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
			                       TO_DATE('#STARTDATE#'||'2000', 'yyyy-mm-dd hh24:mi:ss')
			                   AND TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
			                       TO_DATE('#ENDDATE#'||'2000', 'yyyy-mm-dd hh24:mi:ss')
                         AND T10.STOP_TYPE IN ('600602', '600603')
                         AND T10.PLINE_CODE IN (#PLINECODE#)
                         AND T10.STATION IN ('#STATION#')
                         AND EXISTS (SELECT *
                                FROM COM_BASE_INFO
                               WHERE BASECODE = T10.STOP_REASON
                                 AND VALIDFLAG = '1')
       ) ta ,(
        SELECT to_char(TO_DATE('#ENDDATE#', 'yyyy-mm-dd hh24:mi:ss') - LEVEL + 1, 'yyyy-mm-dd') dates FROM DUAL connect BY LEVEL <= #DAYS#
       ) tb
       ORDER BY dates,DEPT
       ),
        t1 AS
      (SELECT tb.tj_date,tb.dept,sum(tb.tjtime)/DECODE('#REGION#','F01',(550+330+280+550+280),'F02',(170+280+200),'F03',(620+220),
                                                                 'F11',(550+330+280+550+280),'F12',(170+280+200),'F13',(620+220)) tjtime FROM
      (
      SELECT ta.tj_date,ta.dept,ta.plinename,ta.plinecode,
      DECODE(ta.plinecode,'C022',SUM(ta.tjtime)*550,'C023',SUM(ta.tjtime)*330
		  					 ,'C024',SUM(ta.tjtime)*280,'C025',SUM(ta.tjtime)*550
		  					 ,'C026',SUM(ta.tjtime)*280,'C054',SUM(ta.tjtime)*170
		  					 ,'C055',SUM(ta.tjtime)*280,'C048',SUM(ta.tjtime)*200
		  					 ,'C049',SUM(ta.tjtime)*620,'C050',SUM(ta.tjtime)*220)  tjtime FROM
      (
      SELECT                T10.STOP_REASON,
                             T10.LOGS_BEG,
                             T10.LOGS_END,
                             CASE
                               WHEN (TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
                                    TO_DATE(SUBSTR(T10.LOGS_BEG, 1, 8) || '2000',
                                             'yyyy-mm-dd hh24:mi:ss')) THEN
                                TO_CHAR(TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') + 1,
                                        'yyyy-MM-dd')
                               ELSE
                                TO_CHAR(TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss'),
                                        'yyyy-MM-dd')
                             END TJ_DATE,
                             (TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                             TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 AS TJTIME,
                             CASE WHEN T10.STOP_SMALL ='60060309' THEN '工艺停机'
                                 ELSE (SELECT DEPT FROM COM_BASE_INFO WHERE BASECODE = T10.STOP_REASON) END DEPT,
                             (SELECT PLINE_NAME
                                FROM COM_BASE_PLINE
                               WHERE PLINE_CODE = T10.PLINE_CODE) PLINENAME,
                             T10.PLINE_CODE PLINECODE
                        FROM HTT_CONTROL_LOG T10
                       WHERE T10.PRO_TYPE = '2'
                        AND TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss') >=
			                       TO_DATE('#STARTDATE#'||'2000', 'yyyy-mm-dd hh24:mi:ss')
			                   AND TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') <=
			                       TO_DATE('#ENDDATE#'||'2000', 'yyyy-mm-dd hh24:mi:ss')
                        AND T10.STOP_TYPE IN ('600602', '600603')
                         AND T10.PLINE_CODE IN (#PLINECODE#)
                         AND T10.STATION IN ('#STATION#')
                         AND EXISTS (SELECT *
                                FROM COM_BASE_INFO
                               WHERE BASECODE = T10.STOP_REASON
                                 AND VALIDFLAG = '1')
                         AND (TO_DATE(T10.LOGS_END, 'yyyy-mm-dd hh24:mi:ss') -
                             TO_DATE(T10.LOGS_BEG, 'yyyy-mm-dd hh24:mi:ss')) >0
      ) ta
      GROUP BY ta.tj_date,ta.dept,ta.plinename,ta.plinecode
      ORDER BY ta.tj_date,ta.plinename,ta.plinecode
      )tb
      GROUP BY tb.tj_date,tb.dept
      ),
        t2 AS
      (
      SELECT t.*,nvl(t1.tjtime,0) tjtime FROM t,t1 WHERE t.dates = t1.tj_date(+) AND t.dept = t1.dept(+)
      ORDER BY t.dates
      ),
      t3 AS
      (
      SELECT '作业时间' ,TO_DATE(dates, 'yyyy-mm-dd hh24:mi:ss') dates,ROUND((24*60 -sum(tjtime))/60,2) zytime FROM t2 GROUP BY dates
      ),
      t4 AS
      (
      SELECT t2.dept,TO_DATE(t2.dates, 'yyyy-mm-dd hh24:mi:ss') opdate,CAST(tjtime/60 as number(8,2)) optime FROM t2
      UNION ALL
      SELECT * FROM t3
      )
      SELECT * FROM t4
      ORDER BY opdate,dept desc

		]]>
	</query>


	<query id="BuyGpDAL.UpdateExamineStatus" desc="工艺审批">
		<![CDATA[
        UPDATE PLN_REQINF_GP
        SET EXAMINE_STATUS={0},EXAMINE_TIME=SYSDATE
        WHERE EXAMINE_STATUS={1}
		]]>
	</query>
</queryMap>