<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="轧管炉计划">

	<query id="FrmPlanStoveD.queryPlanStoveD" desc="查询轧管虚拟炉计划">
            <![CDATA[
        SELECT T2.*,   (SELECT TO_CHAR(MIN(S.PLN_STARTTIME),'YYYY-MM-DD HH24:MI:SS')
          FROM PLN_STEELFORFURNACE S
         WHERE S.FURNACENO =
               (SELECT DISTINCT O.FURNACENO
                  FROM PLN_STEELFOR_ORD O
                 WHERE O.JUDGE_STOVE_NO = T2.JUDGE_STOVE_NO AND O.CCM_PLN_TYPE='00'
                 AND ROWNUM = 1)) PLN_TIME_STRAT FROM (SELECT T.HEAT_PLAN_NO,
       T.GX_PRO_SEQ,
       T1.ZY_BATCH_ID,
       CASE
         WHEN T.STOVE_NO IS NULL AND T.UPPER_PROCESS_CODE = 'B' THEN
          (SELECT O.STOVE_NO
             FROM PLN_STEELFOR_ORD O
            WHERE O.FURNACENO || '/' || O.SEQUENCENO = T.UPPER_HEATPLAN_ID)
         ELSE
          T.STOVE_NO
       END STOVE_NO,
         CASE
         WHEN T.JUDGE_STOVE_NO IS NULL AND T.UPPER_PROCESS_CODE = 'B' THEN
          (SELECT O.JUDGE_STOVE_NO
             FROM PLN_STEELFOR_ORD O
            WHERE O.FURNACENO || '/' || O.SEQUENCENO = T.UPPER_HEATPLAN_ID)   
         ELSE
          T.JUDGE_STOVE_NO
       END JUDGE_STOVE_NO,
        CASE
         WHEN T.FLAG_STOVE_NO IS NULL AND T.UPPER_PROCESS_CODE = 'B' THEN
          (SELECT O.FLAG_STOVE_NO
             FROM PLN_STEELFOR_ORD O
            WHERE O.FURNACENO || '/' || O.SEQUENCENO = T.UPPER_HEATPLAN_ID)
         ELSE
          T.FLAG_STOVE_NO
       END FLAG_STOVE_NO,
       T.FLAG_HEAT_NO,
       DECODE(T.PLANSTATUS,
              '00',
              '计划',
              '10',
              '下发',
              '20',
              '生产中',
              '30',
              '生产完成',
              '40',
              '关闭A') PLANSTATUS,
       T.UPPER_HEATPLAN_ID,
       T.PRO_PLAN_ID||'/'||T.GX_PLAN_NO PRO_PLAN_ID,
       T.GX_PLAN_NO,
       T.CCM_PRO_PLAN_ID ||'/'||T.CCM_GX_PLAN_NO CCM_PRO_PLAN_ID,
       T.CCM_GX_PLAN_NO,
       T.PLINE_CODE,
       T.PLINE_NAME,
       T.PROCESS_CODE_C,
       T.PROCESS_DESC_C,
       T.UPPER_PROCESS_CODE,
       T.NEXT_PROCESS_CODE,
       DECODE(T.ISENDGX, '0', '/', '1', '是') ISENDGX,
       DECODE(T.IF_MATCH_ODD, '0', '/', '1', '前轧管利库','4','后轧管利库','6','本工序精整利库','炼钢利库') IF_MATCH_ODD,
       DECODE(T.IF_DO_HEAT_PLAN, '0', '/', '1', '是') IF_DO_HEAT_PLAN,
       T.ORDER_SOURCE,
       (SELECT MAX(CUSTOMER_NM) FROM SLM_ORDER_HEAD WHERE ORDER_NO = T.ORDER_NO AND VALIDFLAG = '1') CUSTOMER_NM,
       T.ORD_LN_DLY_PK,
       T.ORDER_NO ||'/'||T.ORDER_SEQ ORDER_NO,
       T.ORDER_SEQ,
       T.DELIVERY_NO,
       T.REQ_BL_ID,
       T.IF_EXPORT,
       T.PRIORITY,
       T.PRIORITY_MEMO,
       T.PRO_MONTH,
       DECODE(T.IF_LEN_CONTROL, '0', '/', '1', '是') IF_LEN_CONTROL,
       DECODE(T.IF_MINUS_SIC_ROLL, '0', '/', '1', '是') IF_MINUS_SIC_ROLL,
       T.PROD_STANDARD,
       T.OUTPUT_STANDARD,
       T.DECISION,
       T.PROGY_MEMO,
       T.GOWHERE_CODE,
       T.GOWHERE_NAME,
       DECODE(T.OUTS_BILLET_FL, '1', '外购', '0', '自炼') OUTS_BILLET_FL,
       DECODE(T.GPTYPE, '1', '铸坯', '2', '锻坯') GPTYPE,
       T.INWL_ID,
       T.INWL_DESC,
       T.OUTWL_ID,
       T.OUTWL_DESC,
       T.GRADECODE,
       T.GRADENAME,
       T.STEELCODE,
       T.STEELNAME,
       T.PRODUCCODE,
       T.PRODUCNAME,
       T.MODEL_CODE,
       T.MODEL_DESC,
       T.DIAMETER,
       T.LEN_GP_SINGLE,
       T.WT_GP_SINGLE,
       T.PLN_INSINGLE_NUM,
       T.PLN_INSINGLE_WT,
       T.PLN_OUTSINGLE_NUM,
       T.PLN_OUTSINGLE_W,
       T.REDUCED_WT,
       T.OUTDIAMETER,
       T.WALLTHICK,
       T.OUTDIAMETER_ZG,
       T.WALLTHICK_ZG,
       T.AIMOUTDIAMETER,
       T.AIMWALLTHICK,
       T.THICKNESS_WALL,
       T.LEN_ROLL_MAX,
       T.LEN_ROLL_MIN,
       T.AIMLENGTH,
       T.ROLL_LENGTH,
       T.OUTNUM_CUT,
       DECODE(T.CUT_TYPE, '0', '被动', '1', '主动') CUT_TYPE,
       T1.LEN_CUTEND,
       T1.LEN_CUTHEAD,
       T1.DIAMETER_MANDREL,
       T1.PASS_CODE,
       T1.PASS_NAME,
       DECODE(T.IF_MONITOR, '0', '/', '1', '是') IF_MONITOR,
       T.PRDCR_NO,
       T.MONITOR_POINT,
       T1.BOM,
       T.WHOLE_BACKLOG,
       T1.WHOLE_BACKLOG_DESC,
       T.CIC,
       T.PIC,
       T.SIC,
       T.DIC,
       T1.CRAFT_FILE_NO,
       T1.CRAFT_FILE_MAN,
       T1.CRAFT_SEQ,
       T.SEC_CRAFT_FILE_NO,
       T.STATION_ROAD,
       TO_CHAR(TO_DATE(T.PRO_DAY, 'YYYY-MM-DD'), 'YYYY-MM-DD') PRO_DAY,
       TO_CHAR(TO_DATE(T.BAL_YEAR_MONTH, 'YYYY-MM'), 'YYYY-MM') BAL_YEAR_MONTH,
       T.CREATE_NAME,
       TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
       T.UPDATE_NAME,
       TO_CHAR(T.UPDATE_TIME, 'YYYY-MM-DD HH24:MI:SS') UPDATE_TIME,
       TO_CHAR(T1.PLAN_TIME_B,'YYYY-MM-DD HH24:MI:SS')PLAN_TIME_B,
       (select GET_ZG_BUTTRESS(T.JUDGE_STOVE_NO,T.PRO_PLAN_ID,T.GX_PLAN_NO) from dual)STORAGE_NAME,
       T.DOWNMAN,
       TO_CHAR(T.DOWNTIME, 'YYYY-MM-DD HH24:MI:SS') DOWNTIME,
       DECODE(T.IS_LOAD, '0', '未上料', '1', '已上料') IS_LOAD,
       DECODE(T.PLN_TYPE, '0', '正常计划', '1', '试轧料') PLN_TYPE, 
       T.INDEX_SEQ,
       TO_CHAR(L.DELVRY_EDATE,'YYYY-MM-DD') DELVRY_BDATE,
       DECODE(T.JUDGE_STOVE_NO,'','未结炉','已结炉') STEEL_FALG,
          DECODE(CASE
                WHEN T.PLANSTATUS = '00' THEN
                 0
                ELSE
                 (SELECT COUNT(*)
                    FROM PLN_ZY_ZG_C T1, MIL_FEED_PLAN F
                   WHERE T1.HEAT_PLAN_SQE = F.FEED_ROW_NO
                     AND T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO)
              END,
              '0',
              '未生成上料行',
              '-1','','已生成上料行') FEED_ROW_NO,
               CASE
         WHEN T.UPPER_PROCESS_CODE = 'B' THEN
          (SELECT DECODE(O.STATUS,
                         '00',
                         '编制中',
                         '10',
                         '已下发',
                         '20',
                         '生产中',
                         '30',
                         '已生产',
                         '40',
                         '关闭')
             FROM PLN_STEELFOR_ORD O
            WHERE O.FURNACENO || '/' || O.SEQUENCENO = T.UPPER_HEATPLAN_ID)
         ELSE
          (SELECT DECODE(O.PLANSTATUS,
                         '00',
                         '编制中',
                         '10',
                         '已下发',
                         '20',
                         '生产中',
                         '30',
                         '已生产',
                         '40',
                         '关闭')
             FROM PLN_ZY_DZ_M O
            WHERE O.HEAT_PLAN_NO = T.UPPER_HEATPLAN_ID)
       END UPPER_STRAT,
               T.FEED_HEAT_NO,
               T.MEMO,
               T1.GX_PRO_SEQ GX_PRO_SEQ_PC,
               CASE
                 WHEN NVL((SELECT COUNT(1)
                    FROM PLN_ORDER_ZG_S S1
                   WHERE S1.TH_ORDER_NO_SEQ =
                         T1.ORDER_NO || '/' || T1.ORDER_SEQ),
                  0) > 0 THEN
                  '是'
                 ELSE
                  '否'
               END IF_FLAG_HEAT_NO
          FROM PLN_ZY_ZG_M             T,
               PLN_ORDER_ZG_S          T1,
               SLM_ORDER_LINE          L,
               SLM_ORDER_LINE_DELIVERY LY
			WHERE 1 = 1
           AND T1.ORD_LN_DLY_PK = LY.ORD_LN_DLY_PK
           AND LY.ORD_LN_PK = L.ORD_LN_PK
           AND T.PRO_PLAN_ID = T1.PRO_PLAN_ID
           AND T.GX_PLAN_NO = T1.GX_PLAN_NO
              ]]>
	</query>
	<query id="FrmPlanStoveD.queryPlanStoveDc" desc="查询轧管实际炉计划">
            <![CDATA[
             SELECT 
       T.HEAT_PLAN_NO,
       T.HEAT_PLAN_SQE,
       T.JUGDE_APPLY_CODE,
       T.ZY_BATCH_ID,
       T.STOVE_NO,
       T.JUDGE_STOVE_NO,
       T.PRO_PLAN_ID,
       T.GX_PLAN_NO,
       T.PLINE_CODE,
       T.PLINE_NAME,
       T.DIAMETER,
       T.LEN_GP_SINGLE,
       T.WT_GP_SINGLE,
       T.CUT_NUM_GP,
       T.LENGTH_M,
       T.WEIGHT_M,
       T.PLAN_INDOUBLE_NUM,
       T.PLAN_INDOUBLE_WT,
       T.REAL_INDOUBLE_NUM,
       T.REAL_INDOUBLE_WT,
       T.FLAG_STOVE_NO,
       T.CREATE_NAME,
       TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
       T.UPDATE_NAME,
       TO_CHAR(T.UPDATE_TIME, 'YYYY-MM-DD HH24:MI:SS') UPDATE_TIME,T.FEED_HEAT_NO
 FROM PLN_ZY_ZG_C T
 WHERE 1=1
              ]]>
	</query>
	<query id="FrmPlanStoveD.AddMilPlan" desc="新增轧管炉计划接收表">
            <![CDATA[
            INSERT INTO MIL_PLAN
  (ID,
   SEQ,
   STOVE_NO,
   JUDGE_STOVE_NO,
   LOT_NO,
   CONTRACT_NO,
   IMP_PROCESS,
   PLINE_CODE,
   PRODUCER,
   PROCESS_STATUS,
   DB_LENGTH,
   DB_HEIGHT,
   ROLL_LENGTH,
   SAW_NUM,
   TARGET_LENGTH,
   FINISH_USER,
   TARGET_LIABRARY,
   VARIETIES,
   VARIETIES_CODE,
   PIPE_SIZE,
   PIPE_SIZE_CODE,
   BUCKLE_TYPE,
   BUCKLE_TYPE_CODE,
   LENGTH_RANGE,
   ROLL_STANDRAD,
   PIPE_SECTION,
   STEELCODE,
   STEELNAME,
   GRADECODE,
   GRADENAME,
   STEEL_STANDRAD,
   TARGET,
   BRANCH,
   TON,
   DB_NUM,
   TOM,
   CUT_HEAD_LENGTHP,
   CUT_TRAIL_LENGTHP,
   CONTROL_THICKP,
   PRODUCE_STANDRAD,
   FEED_SEQ,
   LOT_SEQ,
   FEED_HEAT_NO,
   LENGTHCP,
   CODE_SAMPLE_FLAG,
   ROLL_STANDRAD_CODE,
   STD_STYLE,
   STD_STYLE_DESC,
   CHECK_NO,
   ORD_LN_DLY_PK,
   PRT_FLAG,
   PRO_PLAN_ID,
   GX_PLAN_NO,
   TUBE_TYPE,
   TUBE_SUORCE,
   TYPE,STATUS,NODE_STATUS,IS_LOAD,CRAFT_SEQ,CIC,INDEX_SEQ,PIC,IF_PRODUCT,PRDCR_NO,IF_MONITOR)
VALUES
  ('#ID#',
   '#SEQ#',
   '#STOVE_NO#',
   '#JUDGE_STOVE_NO#',
   '#LOT_NO#',
   '#CONTRACT_NO#',
   '#IMP_PROCESS#',
   '#PLINE_CODE#',
   '#PRODUCER#',
   '#PROCESS_STATUS#',
   '#DB_LENGTH#',
   '#DB_HEIGHT#',
   '#ROLL_LENGTH#',
   '#SAW_NUM#',
   '#TARGET_LENGTH#',
   '#FINISH_USER#',
   '#TARGET_LIABRARY#',
   '#VARIETIES#',
   '#VARIETIES_CODE#',
   '#PIPE_SIZE#',
   '#PIPE_SIZE_CODE#',
   '#BUCKLE_TYPE#',
   '#BUCKLE_TYPE_CODE#',
   '#LENGTH_RANGE#',
   '#ROLL_STANDRAD#',
   '#PIPE_SECTION#',
   '#STEELCODE#',
   '#STEELNAME#',
   '#GRADECODE#',
   '#GRADENAME#',
   '#STEEL_STANDRAD#',
   '#TARGET#',
   '#BRANCH#',
   '#TON#',
   '#DB_NUM#',
   TO_DATE('#TOM#','YYYY-MM-DD HH24:MI:SS'),
   '#CUT_HEAD_LENGTHP#',
   '#CUT_TRAIL_LENGTHP#',
   '#CONTROL_THICKP#',
   '#PRODUCE_STANDRAD#',
   '#FEED_SEQ#',
   '#LOT_SEQ#',
   '#FEED_HEAT_NO#',
   '#LENGTHCP#',
   '#CODE_SAMPLE_FLAG#',
   '#ROLL_STANDRAD_CODE#',
   '#STD_STYLE#',
   '#STD_STYLE_DESC#',
   '#CHECK_NO#',
   '#ORD_LN_DLY_PK#',
   '#PRT_FLAG#',
   '#PRO_PLAN_ID#',
   '#GX_PLAN_NO#',
   '#TUBE_TYPE#',
   '#TUBE_SUORCE#',
   '#TYPE#','#STATUS#','#NODE_STATUS#','0','#CRAFT_SEQ#','#CIC#','#INDEX_SEQ#','#PIC#','#IF_PRODUCT#','#PRDCR_NO#','#IF_MONITOR#')]]>
	</query>
	<query id="FrmPlanStoveD.AddMilFeedPlan" desc="新增轧管炉计划上料表">
            <![CDATA[
             INSERT INTO MIL_FEED_PLAN(
        FEED_ROW_NO,
        SEQ,
        LOT_NO,
        STOVE_NO,
        JUDGE_STOVE_NO,
        PLINE_CODE,
        DB_NUM,
        MAT_HEIGHT,
        MAT_TOTAL_HEIGHT,
        FEED_NUM,
        FEED_LENGTH,
        USE_LENGTH,
        CUT_TARGET,
        CUT_LENGTH,
        CUT_WEIGHT,
        REMARK,
        DB_LENGTH,
        NON_USE_LENGTH,
        PIPE_SECTION,
        DB_HEIGHT,
        FEED_NUM_PLAN,
        PRO_PLAN_ID,
        GX_PLAN_NO,CREATE_NAME,CREATE_TIME)
 VALUES( 
        '#FEED_ROW_NO#',
        '#SEQ#',
        '#LOT_NO#',
        '#STOVE_NO#',
        '#JUDGE_STOVE_NO#',
        '#PLINE_CODE#',
        '#DB_NUM#',
        '#MAT_HEIGHT#',
        '#MAT_TOTAL_HEIGHT#',
        '#FEED_NUM#',
        '#FEED_LENGTH#',
        '#USE_LENGTH#',
        '#CUT_TARGET#',
        '#CUT_LENGTH#',
        '#CUT_WEIGHT#',
        '#REMARK#',
        '#DB_LENGTH#',
        '#NON_USE_LENGTH#',
        '#PIPE_SECTION#',
        '#DB_HEIGHT#',
        '#FEED_NUM_PLAN#',
        '#PRO_PLAN_ID#',
        '#GX_PLAN_NO#','#CREATE_NAME#',TO_DATE('#CREATE_TIME#','YYYY-MM-DD HH24:MI:SS'))
            ]]>
	</query>
	<query id="FrmPlanStoveD.QueryfeedJut" desc="获取在最大上料行">
            <![CDATA[
            SELECT CASE
         WHEN MAX(T.FEED_HEAT_NO) IS NULL THEN
          ?
         ELSE
          ? ||
          LPAD(SUBSTR(NVL(MAX(T.FEED_HEAT_NO), '0000'), -4, 4) + 1, 4, '0')
       END FEED_HEAT_NO
  FROM PLN_ZY_ZG_M T
 WHERE T.FEED_HEAT_NO IS NOT NULL
   --AND T.PLINE_CODE = ?
   AND T.FEED_HEAT_NO LIKE ? || '____'
             ]]>
	</query>
	<query id="FrmPlanStoveD.QueryHeatPlanNo" desc="获取轧管炉计划主键">
            <![CDATA[
     SELECT T3.*
  FROM (SELECT T2.HEAT_PLAN_NO,
               T2.FEED_HEAT_NO,
               MAX(T2.GX_PRO_SEQ) GX_PRO_SEQ
          FROM (SELECT T.HEAT_PLAN_NO, T.FEED_HEAT_NO, T1.GX_PRO_SEQ
                  FROM PLN_ZY_ZG_M T, PLN_ORDER_ZG_S T1
                 WHERE T.PRO_PLAN_ID = T1.PRO_PLAN_ID
                   AND T.GX_PLAN_NO = T1.GX_PLAN_NO
                   AND (SELECT CASE
                                 WHEN T1.JUDGE_STOVE_NO IS NULL AND
                                      T1.UPPER_PROCESS_CODE = 'B' THEN
                                  (SELECT O.JUDGE_STOVE_NO
                                     FROM PLN_STEELFOR_ORD O
                                    WHERE O.FURNACENO || '/' || O.SEQUENCENO =
                                          T1.UPPER_HEATPLAN_ID)
                                 ELSE
                                  T1.JUDGE_STOVE_NO
                               END JUDGE_STOVE_NO
                          FROM PLN_ZY_ZG_M T1
                         WHERE T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO) = ?
                UNION ALL
                SELECT T.ID,
                       REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') JUDGE_STOVE_NO,
                       '-10'
                  FROM MIL_PLAN T,
                       (SELECT CASE
                                 WHEN M.JUDGE_STOVE_NO IS NULL AND
                                      M.UPPER_PROCESS_CODE = 'B' THEN
                                  (SELECT O.JUDGE_STOVE_NO
                                     FROM PLN_STEELFOR_ORD O
                                    WHERE O.FURNACENO || '/' || O.SEQUENCENO =
                                          M.UPPER_HEATPLAN_ID)
                                 ELSE
                                  M.JUDGE_STOVE_NO
                               END JUDGE_STOVE_NO,
                               M.HEAT_PLAN_NO,
                               M.FEED_HEAT_NO
                          FROM PLN_ZY_ZG_M M) M1
                 WHERE T.ID != M1.HEAT_PLAN_NO
                   AND T.FEED_HEAT_NO = M1.JUDGE_STOVE_NO
                   AND T.FEED_HEAT_NO = ?
                 GROUP BY T.ID, T.JUDGE_STOVE_NO) T2
         GROUP BY T2.HEAT_PLAN_NO, T2.FEED_HEAT_NO) T3
 ORDER BY TO_NUMBER(T3.GX_PRO_SEQ) ASC
             ]]>
	</query>
	
	<query id="FrmPlanStoveD.QueryHeatPlanNo2" desc="获取轧管产线">
            <![CDATA[
    SELECT T3.*
  FROM (SELECT T2.HEAT_PLAN_NO,
               T2.PLINE_CODE,
               T2.FEED_HEAT_NO,
               MAX(T2.GX_PRO_SEQ) GX_PRO_SEQ
          FROM (SELECT T.HEAT_PLAN_NO,
                       T.PLINE_CODE,
                       T.FEED_HEAT_NO,
                       T1.GX_PRO_SEQ
                  FROM PLN_ZY_ZG_M T, PLN_ORDER_ZG_S T1
                 WHERE T.PRO_PLAN_ID = T1.PRO_PLAN_ID
                   AND T.GX_PLAN_NO = T1.GX_PLAN_NO
                   AND (SELECT CASE
                                 WHEN T1.JUDGE_STOVE_NO IS NULL AND
                                      T1.UPPER_PROCESS_CODE = 'B' THEN
                                  (SELECT O.JUDGE_STOVE_NO
                                     FROM PLN_STEELFOR_ORD O
                                    WHERE O.FURNACENO || '/' || O.SEQUENCENO =
                                          T1.UPPER_HEATPLAN_ID)
                                 ELSE
                                  T1.JUDGE_STOVE_NO
                               END JUDGE_STOVE_NO
                          FROM PLN_ZY_ZG_M T1
                         WHERE T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO) = ?
                UNION ALL
                SELECT T.ID,
                       T.PLINE_CODE,
                       REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') JUDGE_STOVE_NO,
                       '-10'
                  FROM MIL_PLAN T,
                       (SELECT CASE
                                 WHEN M.JUDGE_STOVE_NO IS NULL AND
                                      M.UPPER_PROCESS_CODE = 'B' THEN
                                  (SELECT O.JUDGE_STOVE_NO
                                     FROM PLN_STEELFOR_ORD O
                                    WHERE O.FURNACENO || '/' || O.SEQUENCENO =
                                          M.UPPER_HEATPLAN_ID)
                                 ELSE
                                  M.JUDGE_STOVE_NO
                               END JUDGE_STOVE_NO,
                               M.HEAT_PLAN_NO,
                               M.FEED_HEAT_NO
                          FROM PLN_ZY_ZG_M M) M1
                 WHERE T.ID != M1.HEAT_PLAN_NO
                   AND T.FEED_HEAT_NO = M1.JUDGE_STOVE_NO
                   AND T.FEED_HEAT_NO = ?
                 GROUP BY T.ID, T.PLINE_CODE, T.JUDGE_STOVE_NO) T2
         GROUP BY T2.HEAT_PLAN_NO, T2.PLINE_CODE, T2.FEED_HEAT_NO) T3
 ORDER BY TO_NUMBER(T3.GX_PRO_SEQ) ASC
             ]]>
	</query>
	<query id="FrmPlanStoveD.QueryFeedAll" desc="获取轧管炉计划所有上料行">
            <![CDATA[
            SELECT T2.FEED_HEAT_NO
  FROM (SELECT T.FEED_HEAT_NO, T.JUDGE_STOVE_NO
          FROM PLN_ZY_ZG_M T
         WHERE T.FEED_HEAT_NO LIKE ?||'%'
           AND (SELECT CASE
                         WHEN T1.JUDGE_STOVE_NO IS NULL AND
                              T1.UPPER_PROCESS_CODE = 'B' THEN
                          (SELECT O.JUDGE_STOVE_NO
                             FROM PLN_STEELFOR_ORD O
                            WHERE O.FURNACENO || '/' || O.SEQUENCENO =
                                  T1.UPPER_HEATPLAN_ID) 
                         ELSE
                          T1.JUDGE_STOVE_NO
                       END JUDGE_STOVE_NO
                  FROM PLN_ZY_ZG_M T1
                 WHERE T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO) != ?
                   UNION ALL
        SELECT T.FEED_HEAT_NO, T.JUDGE_STOVE_NO
          FROM PLN_ZY_ZG_M T
         WHERE T.FEED_HEAT_NO LIKE ?||'%'
           AND (SELECT CASE
                         WHEN T1.JUDGE_STOVE_NO IS NULL AND
                              T1.UPPER_PROCESS_CODE = 'B' THEN
                          (SELECT O.JUDGE_STOVE_NO
                             FROM PLN_STEELFOR_ORD O
                            WHERE O.FURNACENO || '/' || O.SEQUENCENO =
                                  T1.UPPER_HEATPLAN_ID)
                         ELSE
                          T1.JUDGE_STOVE_NO
                       END JUDGE_STOVE_NO
                  FROM PLN_ZY_ZG_M T1
                 WHERE T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO) = ?) T2
 WHERE 1 = 1
 ORDER BY T2.FEED_HEAT_NO
            
               ]]>
	</query>

	<query id="FrmPlanStoveD.updateMatGpMEntity" desc="修改管坯物料挂料信息">
             <![CDATA[
DECLARE
BEGIN
  FOR MYROW IN (SELECT MAT_NO
                  FROM (SELECT T.MAT_NO
                          FROM MAT_GP_M T
                         WHERE T.JUGDE_APPLY_CODE = ?
                           AND T.JUDGE_STOVE_NO=?
                           AND T.FIX_NUM = TO_NUMBER(?)
                         ORDER BY T.MAT_NO ASC)
                 WHERE ROWNUM <= ?) LOOP
    UPDATE MAT_GP_M T SET T.HANGING_FLAG = ?,T.MAT_STATUS=?,T.PRO_PLAN_ID_ZG=?,T.GX_PLAN_NO_ZG=? WHERE T.MAT_NO = MYROW.MAT_NO;
  END LOOP;
END; 
               ]]>
	</query>
	
	<query id="FrmPlanStoveD.queryPlanStoveM" desc="查询轧管虚拟炉计划">
            <![CDATA[
        SELECT T2.*,(select GET_ZG_BUTTRESS(T2.JUDGE_STOVE_NO,T2.PRO_PLAN_ID1,T2.GX_PLAN_NO) from dual) Storage_No, 
          (SELECT TO_CHAR(MIN(S.PLN_STARTTIME),'YYYY-MM-DD HH24:MI:SS')
          FROM PLN_STEELFORFURNACE S
         WHERE S.FURNACENO =
               (SELECT DISTINCT O.FURNACENO
                  FROM PLN_STEELFOR_ORD O
                 WHERE O.JUDGE_STOVE_NO = T2.JUDGE_STOVE_NO AND O.CCM_PLN_TYPE='00')) PLN_TIME_STRAT FROM (SELECT T.HEAT_PLAN_NO,
       T.GX_PRO_SEQ,
       T3.ZY_BATCH_ID,
       CASE
         WHEN T.STOVE_NO IS NULL AND T.UPPER_PROCESS_CODE = 'B' THEN
          (SELECT O.STOVE_NO
             FROM PLN_STEELFOR_ORD O
            WHERE O.FURNACENO || '/' || O.SEQUENCENO = T.UPPER_HEATPLAN_ID)  
         ELSE
          T.STOVE_NO
       END STOVE_NO,
         CASE
         WHEN T.JUDGE_STOVE_NO IS NULL AND T.UPPER_PROCESS_CODE = 'B' THEN
          (SELECT O.JUDGE_STOVE_NO
             FROM PLN_STEELFOR_ORD O
            WHERE O.FURNACENO || '/' || O.SEQUENCENO = T.UPPER_HEATPLAN_ID)
         ELSE
          T.JUDGE_STOVE_NO
       END JUDGE_STOVE_NO,
        CASE
         WHEN T.FLAG_STOVE_NO IS NULL AND T.UPPER_PROCESS_CODE = 'B' THEN
          (SELECT O.FLAG_STOVE_NO
             FROM PLN_STEELFOR_ORD O
            WHERE O.FURNACENO || '/' || O.SEQUENCENO = T.UPPER_HEATPLAN_ID)
         ELSE
          T.FLAG_STOVE_NO
       END FLAG_STOVE_NO,
       DECODE(T.PLANSTATUS,
              '00',
              '计划',
              '10',
              '下发',
              '20',
              '生产中',
              '30',
              '生产完成',
              '40',
              '关闭A') PLANSTATUS,
       T.UPPER_HEATPLAN_ID,
       T.PRO_PLAN_ID||'/'||T.GX_PLAN_NO PRO_PLAN_ID,
       T.PRO_PLAN_ID PRO_PLAN_ID1,
       T.GX_PLAN_NO,
       T.CCM_PRO_PLAN_ID ||'/'||T.CCM_GX_PLAN_NO CCM_PRO_PLAN_ID,
       T.CCM_GX_PLAN_NO,
       T.PLINE_CODE,
       T.PLINE_NAME,
       T.PROCESS_CODE_C,
       T.PROCESS_DESC_C,
       T.UPPER_PROCESS_CODE,
       T.NEXT_PROCESS_CODE,
       DECODE(T.ISENDGX, '0', '/', '1', '是') ISENDGX,
       DECODE(T.IF_MATCH_ODD, '0', '/', '1', '前轧管利库','4','后轧管利库','6','本工序精整利库','炼钢利库') IF_MATCH_ODD,
       DECODE(T.IF_DO_HEAT_PLAN, '0', '/', '1', '是') IF_DO_HEAT_PLAN,
       T.ORDER_SOURCE,
       T.ORD_LN_DLY_PK,
       T.ORDER_NO ||'/'||T.ORDER_SEQ ORDER_NO,
       T.ORDER_SEQ,
       T.DELIVERY_NO,
       T.REQ_BL_ID,
       T.IF_EXPORT,
       T.PRIORITY,
       T.PRIORITY_MEMO,
       T.PRO_MONTH,
       DECODE(T.IF_LEN_CONTROL, '0', '/', '1', '是') IF_LEN_CONTROL,
       DECODE(T.IF_MINUS_SIC_ROLL, '0', '/', '1', '是') IF_MINUS_SIC_ROLL,
       T.PROD_STANDARD,
       T.OUTPUT_STANDARD,
       T.DECISION,
       T.PROGY_MEMO,
       T.GOWHERE_CODE,
       T.GOWHERE_NAME,
       DECODE(T.OUTS_BILLET_FL, '1', '外购', '0', '自炼') OUTS_BILLET_FL,
       DECODE(T.GPTYPE, '1', '铸坯', '2', '锻坯') GPTYPE,
       T.INWL_ID,
       T.INWL_DESC,
       T.OUTWL_ID,
       T.OUTWL_DESC,
       T.GRADECODE,
       T.GRADENAME,
       T.STEELCODE,
       T.STEELNAME,
       T.PRODUCCODE,
       T.PRODUCNAME,
       T.MODEL_CODE,
       T.MODEL_DESC,
       T.DIAMETER,
       T.LEN_GP_SINGLE,
       T.WT_GP_SINGLE,
       T.PLN_INSINGLE_NUM,
       T.PLN_INSINGLE_WT,
       T.PLN_OUTSINGLE_NUM,
       T.PLN_OUTSINGLE_W,
       T.REDUCED_WT,
       T.OUTDIAMETER,
       T.WALLTHICK,
       T.OUTDIAMETER_ZG,
       T.WALLTHICK_ZG,
       T.AIMOUTDIAMETER,
       T.AIMWALLTHICK,
       T.THICKNESS_WALL,
       T.LEN_ROLL_MAX,
       T.LEN_ROLL_MIN,
       T.AIMLENGTH,
       T.ROLL_LENGTH,
       T.OUTNUM_CUT,
       DECODE(T.CUT_TYPE, '0', '被动', '1', '主动') CUT_TYPE,
       T3.LEN_CUTEND,
       T3.LEN_CUTHEAD,
       T3.DIAMETER_MANDREL,
       T3.PASS_CODE,
       T3.PASS_NAME,
       DECODE(T.IF_MONITOR, '0', '/', '1', '是') IF_MONITOR,
       T.PRDCR_NO,
       T.MONITOR_POINT,
       T3.BOM,
       T.WHOLE_BACKLOG,
       T3.WHOLE_BACKLOG_DESC,
       T.CIC,
       T.PIC,
       T.SIC,
       T.DIC,
       T3.CRAFT_FILE_NO,
       T3.CRAFT_FILE_MAN,
       T3.CRAFT_SEQ,
       T.SEC_CRAFT_FILE_NO,
       T.STATION_ROAD,
       TO_CHAR(TO_DATE(T.PRO_DAY, 'YYYYMMDD'), 'YYYY-MM-DD') PRO_DAY,
       TO_CHAR(TO_DATE(T.BAL_YEAR_MONTH, 'YYYYMM'), 'YYYY-MM') BAL_YEAR_MONTH,
       T.CREATE_NAME,
       TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
       T.UPDATE_NAME,
       TO_CHAR(T.UPDATE_TIME, 'YYYY-MM-DD HH24:MI:SS') UPDATE_TIME,
       T.DOWNMAN,
       TO_CHAR(T.DOWNTIME, 'YYYY-MM-DD HH24:MI:SS') DOWNTIME,
       DECODE(T.IS_LOAD, '0', '未上料', '1', '已上料') IS_LOAD,
       DECODE(T.PLN_TYPE, '0', '正常计划', '1', '试轧料') PLN_TYPE, 
       T.INDEX_SEQ,
       DECODE(T.JUDGE_STOVE_NO,'','未结炉','已结炉') steel_falg,
          DECODE(CASE
                WHEN T.PLANSTATUS = '00' THEN
                 0
                ELSE
                 (SELECT COUNT(*)
                    FROM PLN_ZY_ZG_C T1, MIL_FEED_PLAN F
                   WHERE T1.HEAT_PLAN_SQE = F.FEED_ROW_NO
                     AND T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO)
              END,
              '0',
              '未生成上料行',
              '-1','','已生成上料行') FEED_ROW_NO,
               CASE
         WHEN T.UPPER_PROCESS_CODE = 'B' THEN
          (SELECT DECODE(O.STATUS,
                         '00',
                         '编制中',
                         '10',
                         '已下发',
                         '20',
                         '生产中',
                         '30',
                         '已生产',
                         '40',
                         '关闭')
             FROM PLN_STEELFOR_ORD O
            WHERE O.FURNACENO || '/' || O.SEQUENCENO = T.UPPER_HEATPLAN_ID)
         ELSE
          (SELECT DECODE(O.PLANSTATUS,
                         '00',
                         '编制中',
                         '10',
                         '已下发',
                         '20',
                         '生产中',
                         '30',
                         '已生产',
                         '40',
                         '关闭')
             FROM PLN_ZY_DZ_M O
            WHERE O.HEAT_PLAN_NO = T.UPPER_HEATPLAN_ID)
        END UPPER_STRAT,T.FEED_HEAT_NO,T.MEMO,T1.PLAN_INDOUBLE_NUM ACTUA_NUM,
        T1.PLAN_INDOUBLE_WT ACTUA_WT,T1.CUT_NUM_GP,T1.LENGTH_M,T1.LEN_GP_SINGLE LEN_GP_SINGLE_D,
        T1.REAL_INDOUBLE_NUM,T1.REAL_INDOUBLE_WT,
        NVL(CASE
         WHEN T.UPPER_PROCESS_CODE = 'B' THEN
          (SELECT O.TOT_MUM_M
             FROM PLN_STEELFOR_ORD O
            WHERE O.FURNACENO || '/' || O.SEQUENCENO = T.UPPER_HEATPLAN_ID)
         ELSE
          0
       END,0) TOT_MUM_M,
        NVL(CASE
         WHEN T.UPPER_PROCESS_CODE = 'B' THEN
          (SELECT O.TOT_WEIGHT_M
             FROM PLN_STEELFOR_ORD O
            WHERE O.FURNACENO || '/' || O.SEQUENCENO = T.UPPER_HEATPLAN_ID)
         ELSE
          0
       END,0) TOT_WEIGHT_M,T1.HEAT_PLAN_SQE,T3.GX_PRO_SEQ GX_PRO_SEQ_PC,T1.CUT_TARGET,T1.CUT_LENGTH,T1.CUT_WEIGHT
  FROM PLN_ZY_ZG_M T,PLN_ZY_ZG_C T1,PLN_ORDER_ZG_S T3
 WHERE T.HEAT_PLAN_NO=T1.HEAT_PLAN_NO(+)
  AND T.PRO_PLAN_ID=T3.PRO_PLAN_ID
 AND T.GX_PLAN_NO=T3.GX_PLAN_NO
              ]]>
	</query>
	<query id="FrmPlanStoveD.addPlnZyZgC" desc="新增轧管实际炉计划">
             <![CDATA[  
              INSERT INTO PLN_ZY_ZG_C(
        HEAT_PLAN_NO,
        HEAT_PLAN_SQE,
        JUGDE_APPLY_CODE,
        ZY_BATCH_ID,
        STOVE_NO,
        JUDGE_STOVE_NO,
        PRO_PLAN_ID,
        GX_PLAN_NO,
        PLINE_CODE,
        PLINE_NAME,
        DIAMETER,
        LEN_GP_SINGLE,
        WT_GP_SINGLE,
        CUT_NUM_GP,
        LENGTH_M,
        WEIGHT_M,
        PLAN_INDOUBLE_NUM,
        PLAN_INDOUBLE_WT,
        REAL_INDOUBLE_NUM,
        REAL_INDOUBLE_WT,
        FLAG_STOVE_NO,
        CREATE_NAME,
        CREATE_TIME,FEED_HEAT_NO,CUT_TARGET,CUT_LENGTH,CUT_WEIGHT)
 VALUES( 
        '#HEAT_PLAN_NO#',
        '#HEAT_PLAN_SQE#',
        '#JUGDE_APPLY_CODE#',
        '#ZY_BATCH_ID#',
        '#STOVE_NO#',
        '#JUDGE_STOVE_NO#',
        '#PRO_PLAN_ID#',
        '#GX_PLAN_NO#',
        '#PLINE_CODE#',
        '#PLINE_NAME#',
        '#DIAMETER#',
        '#LEN_GP_SINGLE#',
        '#WT_GP_SINGLE#',
        '#CUT_NUM_GP#',
        '#LENGTH_M#',
        '#WEIGHT_M#',
        '#PLAN_INDOUBLE_NUM#',
        '#PLAN_INDOUBLE_WT#',
        '#REAL_INDOUBLE_NUM#',
        '#REAL_INDOUBLE_WT#',
        '#FLAG_STOVE_NO#',
        '#CREATE_NAME#',
        TO_DATE('#CREATE_TIME#','YYYY-MM-DD HH24:MI:SS'),'#FEED_HEAT_NO#','#CUT_TARGET#','#CUT_LENGTH#','#CUT_WEIGHT#')
              ]]>
	</query>
	<query id="FrmPlanStoveD.QueryPlnZYStatus" desc="新增轧管实际炉计划状态">
             <![CDATA[  
             SELECT COUNT(*) COUNT, MAX(T.PLANSTATUS) PLANSTATUS
  FROM PLN_ZY_ZG_M T
 WHERE T.PRO_PLAN_ID = ?
   AND T.GX_PLAN_NO = ?
   AND (SELECT CASE
                 WHEN T1.JUDGE_STOVE_NO IS NULL AND
                      T1.UPPER_PROCESS_CODE = 'B' THEN
                  (SELECT O.JUDGE_STOVE_NO
                     FROM PLN_STEELFOR_ORD O
                    WHERE O.FURNACENO || '/' || O.SEQUENCENO =
                          T1.UPPER_HEATPLAN_ID)
                 ELSE
                  T1.JUDGE_STOVE_NO
               END JUDGE_STOVE_NO
          FROM PLN_ZY_ZG_M T1
         WHERE T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO) = ?
              ]]>
	</query>
	<query id="FrmPlanStoveD.QueryRemaZg" desc="查询是否有上料剩余计划支">
             <![CDATA[
   SELECT T1.FEED_HEAT_NO,
       T1.JUDGE_STOVE_NO,
       T.JUGDE_APPLY_CODE,
       T1.PRO_PLAN_ID,
       T1.GX_PLAN_NO,
       T.LENGTH_M_OLD,
       T.LEN_GP_SINGLE_OLD,
       T.CUT_NUM_OLD,
       T.PLAN_INDOUBLE_NUM,
       NVL(T.REAL_INDOUBLE_NUM, 0) REAL_INDOUBLE_NUM,
       TO_NUMBER(NVL(T.PLAN_INDOUBLE_NUM, 0)) -
       TO_NUMBER(NVL(T.REAL_INDOUBLE_NUM, 0)) COUNTNUM,
       (SELECT NVL(SUM(M.ACT_COUNT), 0)
          FROM MAT_GP_M M
         WHERE M.JUDGE_STOVE_NO = T.JUDGE_STOVE_NO
           AND NVL(M.JUGDE_APPLY_CODE, '/') = NVL(T.JUGDE_APPLY_CODE, '/')
           AND M.PRO_PLAN_ID_ZG = T.PRO_PLAN_ID
           AND M.GX_PLAN_NO_ZG = T.GX_PLAN_NO
           AND M.ACT_LEN = T.LENGTH_M_OLD
           AND M.FIX_LEN = T.LEN_GP_SINGLE_OLD
           AND M.FIX_NUM = T.CUT_NUM_OLD
           AND M.MAT_STATUS = '80150103') ACT_COUNT,
           T1.PLANSTATUS
  FROM PLN_ZY_ZG_C T,PLN_ZY_ZG_M T1
 WHERE T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO(+)
   AND T.HEAT_PLAN_NO = ?
   AND T.HEAT_PLAN_SQE = ?         
             ]]>
	</query>
	<query id="FrmPlanStoveD.updateMatYc" desc="释放管坯余材">
             <![CDATA[
             DECLARE
BEGIN
  FOR MYROW IN (SELECT M.MAT_NO, M.INSTANCY_FLAG
                  FROM MAT_GP_M M
                 WHERE M.JUDGE_STOVE_NO = ?
                   AND NVL(M.JUGDE_APPLY_CODE, '/') = NVL(?, '/')
                   AND M.PRO_PLAN_ID_ZG = ?
                   AND M.GX_PLAN_NO_ZG = ?
                   AND M.ACT_LEN = ?
                   AND M.FIX_LEN = ?
                   AND M.FIX_NUM = ?
                   AND M.MAT_STATUS = '80150103') LOOP
    IF (MYROW.INSTANCY_FLAG = '1') THEN
      UPDATE MAT_GP_M M
         SET M.PRO_PLAN_ID_ZG    = '',
             M.GX_PLAN_NO_ZG     = '',
             M.MAT_STATUS        = '80150101',
             M.HANGING_FLAG      = '0',
             M.LK_FLAG           = '0',
             M.CUT_YU_LONG       = '0',
             M.HEAT_PLAN_NO_NEXT = ''
       WHERE M.MAT_NO = MYROW.MAT_NO;
    ELSE
      UPDATE MAT_GP_M M
         SET M.PRO_PLAN_ID_ZG    = '',
             M.GX_PLAN_NO_ZG     = '',
             M.MAT_STATUS        = '80150102',
             M.HANGING_FLAG      = '0',
             M.LK_FLAG           = '0',
             M.CUT_YU_LONG       = '0',
             M.HEAT_PLAN_NO_NEXT = ''
       WHERE M.MAT_NO = MYROW.MAT_NO;
    END IF;
  END LOOP;
END;
               ]]>
	</query>
	<query id = "FrmPlanStoveD.doQueryStorageNo" desc = "查询所有仓库">
		SELECT T.STORAGE_NAME,T.STORAGE_NO FROM YDM_BS_STORAGE T WHERE T.STORAGE_TYPE_NO IN ('800202','800205') AND T.VALIDFLAG = '1'
	</query>
	<query id = "FrmPlanStoveD.updateGoWhere" desc = "修改物流去向">
		UPDATE PLN_ZY_ZG_M T
		SET T.GOWHERE_CODE = '#GOWHERE_CODE#', T.GOWHERE_NAME = '#GOWHERE_NAME#'
		WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
	</query>
	<query id = "FrmPlanStoveD.queryZyMCount" desc = "查询上料炉号是否已在虚拟炉计划中生成">
		<![CDATA[
		SELECT COUNT(1) ACOUNT
		FROM PLN_ZY_ZG_M T
		WHERE T.JUDGE_STOVE_NO = ?
		AND T.PLINE_CODE = ?
		AND T.HEAT_PLAN_NO <> ?
		AND T.FEED_HEAT_NO IS NOT NULL
		]]>
	</query>
	<query id = "FrmPlanStoveD.queryMatBackFlag" desc = "查询装炉是否有回炉坯">
		SELECT COUNT(1) ACOUNT
		FROM MAT_GP_M T
		WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
		AND T.HEAT_PLAN_NO_NEXT = '#HEAT_PLAN_NO#'
		AND T.BACK_FLAG = '1'
	</query>
	<query id = "FrmPlanStoveD.queryMaxJudgeNo" desc = "查询本部来天淮转换最大炉号">
		SELECT ?||TO_CHAR(SYSDATE,'YYMM')||LPAD(NVL(MAX(SUBSTR(T.FEED_HEAT_NO, 6)), 0) + 1, 4, 0)FEED_HEAT_NO
		FROM PLN_ZY_ZG_M T
		WHERE T.PLINE_CODE = ?
		AND T.FEED_HEAT_NO LIKE ?||TO_CHAR(SYSDATE,'YYMM')||'____'
	</query>
	
	<query id = "FrmPlanStoveD.updateFlagHeatNo" desc = "获取天津喷印炉号">
	<![CDATA[
		UPDATE PLN_ZY_ZG_M T
   SET T.FLAG_HEAT_NO = CASE
                          WHEN (SELECT SUM(ACOUNT)
                                  FROM (SELECT COUNT(1) ACOUNT
                                          FROM PLN_ZY_ZG_M S
                                         WHERE S.JUDGE_STOVE_NO = '#STOVE_NO#'
                                        UNION ALL
                                        SELECT COUNT(1) ACOUNT
                                          FROM PLN_ZY_DBK_M S
                                         WHERE S.JUDGE_STOVE_NO = '#STOVE_NO#'
                                        UNION ALL
                                        SELECT COUNT(1) ACOUNT
                                          FROM PLN_ZY_RCL_M S
                                         WHERE S.JUDGE_STOVE_NO = '#STOVE_NO#'
                                        UNION ALL
                                        SELECT COUNT(1) ACOUNT
                                          FROM PLN_ZY_JGX_M S
                                         WHERE S.JUDGE_STOVE_NO = '#STOVE_NO#')) = 0 AND
                               (SELECT LENGTH('#STOVE_NO#') FROM DUAL) = 6 THEN
                            LPAD(TO_NUMBER('#STOVE_NO#'),6,0)
                          ELSE
                            LPAD((SELECT MAX(JUDGE_STOVE_NO) + 1 JUDGE_STOVE_NO
                              FROM (SELECT TO_NUMBER(MAX(T.JUDGE_STOVE_NO)) JUDGE_STOVE_NO
                                      FROM PLN_ZY_DBK_M T
                                     WHERE T.JUDGE_STOVE_NO >=
                                           (SELECT T1.BASENAME
                                              FROM COM_BASE_INFO T1
                                             WHERE T1.BASECODE = '200701')
                                       AND T.JUDGE_STOVE_NO <=
                                           (SELECT T1.BASENAME
                                              FROM COM_BASE_INFO T1
                                             WHERE T1.BASECODE = '200702')
                                    UNION ALL
                                    SELECT TO_NUMBER(MAX(T.JUDGE_STOVE_NO)) JUDGE_STOVE_NO
                                      FROM PLN_ZY_RCL_M T
                                     WHERE T.JUDGE_STOVE_NO >=
                                           (SELECT T1.BASENAME
                                              FROM COM_BASE_INFO T1
                                             WHERE T1.BASECODE = '200701')
                                       AND T.JUDGE_STOVE_NO <=
                                           (SELECT T1.BASENAME
                                              FROM COM_BASE_INFO T1
                                             WHERE T1.BASECODE = '200702')
                                    UNION ALL
                                    SELECT TO_NUMBER(MAX(T.JUDGE_STOVE_NO)) JUDGE_STOVE_NO
                                      FROM PLN_ZY_JGX_M T
                                     WHERE T.JUDGE_STOVE_NO >=
                                           (SELECT T1.BASENAME
                                              FROM COM_BASE_INFO T1
                                             WHERE T1.BASECODE = '200701')
                                       AND T.JUDGE_STOVE_NO <=
                                           (SELECT T1.BASENAME
                                              FROM COM_BASE_INFO T1
                                             WHERE T1.BASECODE = '200702')
                                    UNION ALL
                                    SELECT TO_NUMBER(MAX(T.JUDGE_STOVE_NO)) JUDGE_STOVE_NO
                                      FROM PLN_ZY_JG_M T
                                     WHERE T.JUDGE_STOVE_NO >=
                                           (SELECT T1.BASENAME
                                              FROM COM_BASE_INFO T1
                                             WHERE T1.BASECODE = '200701')
                                       AND T.JUDGE_STOVE_NO <=
                                           (SELECT T1.BASENAME
                                              FROM COM_BASE_INFO T1
                                             WHERE T1.BASECODE = '200702')
                                    UNION ALL
                                    --天淮给本部生产用
                                    SELECT TO_NUMBER(MAX(T.FLAG_HEAT_NO)) JUDGE_STOVE_NO
                                      FROM PLN_ZY_ZG_M T
                                     WHERE T.FLAG_HEAT_NO >=
                                           (SELECT T1.BASENAME
                                              FROM COM_BASE_INFO T1
                                             WHERE T1.BASECODE = '200701')
                                       AND T.FLAG_HEAT_NO <=
                                           (SELECT T1.BASENAME
                                              FROM COM_BASE_INFO T1
                                             WHERE T1.BASECODE = '200702')
                                    UNION ALL
                                    SELECT TO_NUMBER(T1.BASENAME) - 1 JUDGE_STOVE_NO
                                      FROM COM_BASE_INFO T1
                                     WHERE T1.BASECODE = '200701')),6,0)
                        END
 WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
 ]]>
	</query>
	<query id = "FrmPlanStoveD.cancleFlagHeatNo" desc = "撤销喷印炉号">
		UPDATE PLN_ZY_ZG_M T
   SET T.FLAG_HEAT_NO = ''
 WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
	</query>
</queryMap>