<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc = "荒管组炉管理">
<query id = "FrmComposeFurnaces.doQueryScrap" desc = "荒管剔除待处理实绩表">
<![CDATA[
SELECT T.LOT_NO,
       T.STOVE_NO,
       T.JUDGE_STOVE_NO,
       T.DIAMETER,
       T.THICKNESS,
       T.LENGTH,
       T.PLINE_CODE,
       (SELECT P.PLINE_NAME
          FROM COM_BASE_PLINE P
         WHERE P.PLINE_CODE = T.PLINE_CODE) pline_Name,
       T.OFFLINE_NUM,
       (T.OFFLINE_NUM - T.GROUP_NUM) Col_Num,
       T.GROUP_NUM,
       T.ZP_FLAG,
       T.STATUS,
       TO_CHAR(T.COL_TIME, 'YYYY-MM-DD HH24:MI:SS') COL_TIME,
       T.REMARK,
       T.COL_USER,
       DECODE(T.COL_SHIFT,
              '0',
              '常白班',
              '1',
              '早班',
              '2',
              '中班',
              '3',
              '夜班') COL_SHIFT,
       DECODE(T.COL_GROUP,
              '1',
              '甲班',
              '2',
              '乙班',
              '3',
              '丙班',
              '4',
              '丁班') COL_GROUP,
       T.ZP_HEIGHT,
       T.RECHECK_NUM,
       T.PRODUCNAME,
       T.STEELCODE,
       T.STEELNAME,
       T.GRADECODE,
       T.GRADENAME,
       T.SPEC_CODE,
       T.SPEC_NAME,
       T.MODEL_CODE,
       T.MODEL_DESC,
       T.STD_CODE,
       T.STD_NAME,
       T.STD_STYLE,
       T.STD_STYLE_DESC,
       T.CONTRACT_NO,
       T.PRODUCCODE,
       T.ACT_LEN_RANGE,
       T.TARGET,
       T.PRO_PLAN_ID,
       T.GX_PLAN_NO
  FROM MIL_FURNACES_RESLUT T
 where 1 = 1
   AND T.JUDGE_STOVE_NO || '&' LIKE '%' || ? || '%'
   AND T.PLINE_CODE = ?
   AND T.STATUS = '0'

 ]]>
</query>

<query id = "FrmComposeFurnaces.updateFurnaceReslut" desc = "修改荒管剔除待处理实绩表状态，以及插入子表数据">
<![CDATA[
	DECLARE
  V_COL_NUM        MIL_FURNACES_RESLUT.OFFLINE_NUM%TYPE := ?;
  V_OFFLINE_NUM    MIL_FURNACES_RESLUT.OFFLINE_NUM%TYPE := ?;
  V_GROUP_NUM      MIL_FURNACES_RESLUT.GROUP_NUM%TYPE := ?;
  V_JUDGE_STOVE_NO MIL_FURNACES_RESLUT.JUDGE_STOVE_NO%TYPE := ?;
  V_LOT_NO         MIL_FURNACES_RESLUT.LOT_NO%TYPE := ?;
  V_PLINE_CODE     MIL_FURNACES_RESLUT.PLINE_CODE%TYPE := ?;
  V_PRO_PLAN_ID    MIL_FURNACES_RESLUT.PRO_PLAN_ID%TYPE := ?;
  V_GX_PLAN_NO     MIL_FURNACES_RESLUT.GX_PLAN_NO%TYPE := ?;
  V_ZP_HEIGHT      MIL_FURNACES_RESLUT.ZP_HEIGHT%TYPE := NULL;

BEGIN

  IF (V_OFFLINE_NUM - V_GROUP_NUM > V_COL_NUM) THEN
    UPDATE MIL_FURNACES_RESLUT T
       SET T.GROUP_NUM = V_GROUP_NUM + V_COL_NUM, T.ZP_FLAG = '1'
     WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
       AND T.LOT_NO = V_LOT_NO
       AND T.PRO_PLAN_ID = V_PRO_PLAN_ID
       AND T.GX_PLAN_NO = V_GX_PLAN_NO
       AND T.PLINE_CODE = V_PLINE_CODE;
  ELSE
    UPDATE MIL_FURNACES_RESLUT T
       SET T.GROUP_NUM = V_OFFLINE_NUM, T.ZP_FLAG = '2', T.STATUS = '1'
     WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
       AND T.LOT_NO = V_LOT_NO
       AND T.PRO_PLAN_ID = V_PRO_PLAN_ID
       AND T.GX_PLAN_NO = V_GX_PLAN_NO
       AND T.PLINE_CODE = V_PLINE_CODE;
  END IF;

  SELECT T.ZP_HEIGHT / T.OFFLINE_NUM * V_COL_NUM
    INTO V_ZP_HEIGHT
    FROM MIL_FURNACES_RESLUT T
   WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
     AND T.LOT_NO = V_LOT_NO
     AND T.PRO_PLAN_ID = V_PRO_PLAN_ID
     AND T.GX_PLAN_NO = V_GX_PLAN_NO
     AND T.PLINE_CODE = V_PLINE_CODE;

  INSERT INTO MIL_FURNACES_RESLUT_DETIA
    (LOT_NO,
     STOVE_NO,
     JUDGE_STOVE_NO,
     DIAMETER,
     THICKNESS,
     
     LENGTH,
     PLINE_CODE,
     GROUP_NUM,
     
     COL_TIME,
     REMARK,
     COL_USER,
     COL_SHIFT,
     COL_GROUP,
     
     ZP_HEIGHT,
     PRODUCNAME,
     STEELCODE,
     STEELNAME,
     GRADECODE,
     
     GRADENAME,
     SPEC_CODE,
     SPEC_NAME,
     MODEL_CODE,
     MODEL_DESC,
     
     STD_CODE,
     STD_NAME,
     STD_STYLE,
     STD_STYLE_DESC,
     CONTRACT_NO,
     
     PRODUCCODE,
     ACT_LEN_RANGE,
     ZP_LOT_NO,
     ZP_JUDGE_STOVE_NO,
     TARGET,
     PRO_PLAN_ID,
     GX_PLAN_NO)
  VALUES
    (V_LOT_NO,
     ?,
     V_JUDGE_STOVE_NO,
     ?,
     ?,
     ?,
     ?,
     V_COL_NUM,
     
     SYSDATE,
     ?,
     ?,
     ?,
     ?,
     
     V_ZP_HEIGHT,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     V_PRO_PLAN_ID,
     V_GX_PLAN_NO);
END;
 ]]>
</query>

<query id = "FrmComposeFurnaces.insertFurnaceGroup" desc = "插入荒管组炉实绩表">
<![CDATA[
DECLARE
  V_OPERATION_ID      MIL_FURNACES_GROUP.OPERATION_ID%TYPE := NULL;
  V_ZP_COUNT          MIL_FURNACES_GROUP.ZP_COUNT%TYPE := NULL;
  V_ZP_HEIGHT         MIL_FURNACES_GROUP.ZP_HEIGHT%TYPE := NULL;
  V_ZP_JUDGE_STOVE_NO MIL_FURNACES_GROUP.ZP_JUDGE_STOVE_NO%TYPE := ?;
  V_ZP_LOT_NO         MIL_FURNACES_GROUP.ZP_LOT_NO%TYPE := ?;
  V_PLINE_CODE        MIL_FURNACES_GROUP.PLINE_CODE%TYPE := ?;
BEGIN
  SELECT TO_CHAR(SYSDATE, 'YYMMDD') ||
         LPAD(NVL(MAX(SUBSTR(T.OPERATION_ID, 7)), 0) + 1, 5, 0) OPERATION_ID
    INTO V_OPERATION_ID
    FROM MIL_FURNACES_GROUP T
   WHERE TO_CHAR(T.ZP_TIME, 'YYYY-MM-DD') = TO_CHAR(SYSDATE, 'YYYY-MM-DD');

  SELECT SUM(T.GROUP_NUM), SUM(T.ZP_HEIGHT)
    INTO V_ZP_COUNT, V_ZP_HEIGHT
    FROM MIL_FURNACES_RESLUT_DETIA T
   WHERE T.ZP_JUDGE_STOVE_NO = V_ZP_JUDGE_STOVE_NO
     AND T.ZP_LOT_NO = V_ZP_LOT_NO
     AND T.PLINE_CODE = V_PLINE_CODE;

  INSERT INTO MIL_FURNACES_GROUP
    (ZP_JUDGE_STOVE_NO,
     ZP_LOT_NO,
     ZP_COUNT,
     ZP_STANDRAD,
     ZP_STEEL,
     
     ZP_GRADE,
     ZP_LENGTH,
     ZP_HEIGHT,
     ZP_LENGTH_RANGE,
     ZP_LEVEL,
     
     ZP_SIZE,
     ZP_TIME,
     REMARK,
     COL_USER,
     COL_SHIFT,
     COL_GROUP,
     DIAMETER,
     THICKNESS,
     VARIETIES,
     PLINE_CODE,
     MODEL_DESC,
     OPERATION_ID,
     PRO_PLAN_ID,
     GX_PLAN_NO)
  VALUES
    (V_ZP_JUDGE_STOVE_NO,
     V_ZP_LOT_NO,
     V_ZP_COUNT,
     ?,
     ?,
     
     ?,
     ?,
     V_ZP_HEIGHT,
     ?,
     '',
     
     ?,
     SYSDATE,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     V_OPERATION_ID,
     ?,
     ?);
END;
 ]]>
</query>

	<query id= "FrmComposeFurnaces.doQueryFuracesGroup" desc = "查询是否已存在该炉号">
	
	SELECT COUNT(1) ACOUNT
	  FROM MIL_FURNACES_GROUP T
	 WHERE T.ZP_JUDGE_STOVE_NO = ?
	</query>
	
	<query id= "FrmComposeFurnaces.insertMilPlan" desc = "插入计划表、锯切实绩表">
	<![CDATA[
	DECLARE
  V_JUDGE_STOVE_NO    MIL_PLAN.JUDGE_STOVE_NO%TYPE := ?;
  V_LOT_NO            MIL_PLAN.LOT_NO%TYPE := ?;
  V_PLINE_CODE        MIL_PLAN.PLINE_CODE%TYPE := ?;
  V_ZP_JUDGE_STOVE_NO MIL_PLAN.JUDGE_STOVE_NO%TYPE := ?;
  V_ZP_LOT_NO         MIL_PLAN.LOT_NO%TYPE := ?;
  V_ID                MIL_PLAN.ID%TYPE := NULL;
  V_QUALIFIED_NUM     MIL_ROLLING_RESULT.QUALIFIED_NUM%TYPE := ?;
  V_SAW_NUM           MIL_PLAN.SAW_NUM%TYPE := NULL;
  V_SAW_NUM2          MIL_PLAN.SAW_NUM%TYPE := ?;
BEGIN

  --生成主键
  SELECT TO_CHAR(SYSDATE, 'YYMMDD') ||
         LPAD(NVL(MAX(SUBSTR(T.ID, 7)), 0) + 1, 3, 0) DI
    INTO V_ID
    FROM MIL_PLAN T
   WHERE T.PLINE_CODE = V_PLINE_CODE
     AND TO_CHAR(T.TOM, 'YYYY-MM-DD') = TO_CHAR(SYSDATE, 'YYYY-MM-DD');

  SELECT CASE
           WHEN V_SAW_NUM2 > 0 THEN
            V_SAW_NUM2
           ELSE
            MAX(T.SAW_NUM)
         END
    INTO V_SAW_NUM
    FROM MIL_PLAN T
   WHERE T.CONTRACT_NO = ?;

  FOR MYROW IN (SELECT *
                  FROM MIL_PLAN T
                 WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
                   AND T.LOT_NO = V_LOT_NO
                   AND T.PLINE_CODE = V_PLINE_CODE) LOOP
    INSERT INTO MIL_PLAN
      (LENGTHCP,
       CUT_HEAD_LENGTHA,
       CUT_TRAIL_LENGTHA,
       ORDER_LENGTHA,
       HOT_CHECK_FLAG,
       FEED_SEQ,
       FEED_HEAT_NO,
       LOT_SEQ,
       STEEL_STANDRAD,
       TARGET,
       
       BRANCH,
       TON,
       CUT_TARGET,
       CUT_LENGTH,
       CUT_WEIGHT,
       --DB_NUM,
       START_TIME,
       END_TIME,
       TOM,
       TOC,
       NODE_STATUS,
       
       CUT_HEAD_LENGTHP,
       CUT_TRAIL_LENGTHP,
       CONTROL_THICKP,
       OFFLINE_FLAG,
       IS_BATCH,
       OFFLINE_DATE,
       CUT_TYPE,
       ROLLING_STATUS,
       PRODUCE_STANDRAD,
       SIMPLE_PROCESS,
       
       BACK_LINE_FLAG,
       BACK_PLAN_FLAG,
       FEED_TIME,
       ID,
       SEQ,
       STOVE_NO,
       JUDGE_STOVE_NO,
       LOT_NO,
       CONTRACT_NO,
       IMP_PROCESS,
       
       PLINE_CODE,
       STATUS,
       PRODUCER,
       PROCESS_STATUS,
       DB_LENGTH,
       DB_HEIGHT,
       ROLL_LENGTH,
       SAW_NUM,
       TARGET_LENGTH,
       FINISH_USER,
       
       TARGET_LIABRARY,
       VARIETIES,
       PIPE_SIZE,
       BUCKLE_TYPE,
       LENGTH_RANGE,
       ROLL_STANDRAD,
       PIPE_SECTION,
       STEELCODE,
       STEELNAME,
       GRADECODE,
       GRADENAME,
       ORD_LN_DLY_PK,
       PRT_FLAG,
       PRO_PLAN_ID,
       GX_PLAN_NO,
       
       VARIETIES_CODE,
       PIPE_SIZE_CODE,
       BUCKLE_TYPE_CODE,
       ROLL_STANDRAD_CODE,
       STD_STYLE,
       STD_STYLE_DESC,
       CRAFT_SEQ,
       CIC,
       INDEX_SEQ,
       PIC,
       IF_PRODUCT,
       PRDCR_NO,
       IF_MONITOR)
    VALUES
      (MYROW.LENGTHCP,
       MYROW.CUT_HEAD_LENGTHA,
       MYROW.CUT_TRAIL_LENGTHA,
       MYROW.ORDER_LENGTHA,
       MYROW.HOT_CHECK_FLAG,
       MYROW.FEED_SEQ,
       MYROW.FEED_HEAT_NO,
       MYROW.LOT_SEQ,
       MYROW.STEEL_STANDRAD,
       MYROW.TARGET,
       
       '',
       '',
       MYROW.CUT_TARGET,
       MYROW.CUT_LENGTH,
       MYROW.CUT_WEIGHT,
       --MYROW.DB_NUM,
       sysdate,
       sysdate,
       sysdate,
       '',
       '40',
       
       MYROW.CUT_HEAD_LENGTHP,
       MYROW.CUT_TRAIL_LENGTHP,
       MYROW.CONTROL_THICKP,
       '2',
       '0',
       '',
       MYROW.CUT_TYPE,
       '0',
       MYROW.PRODUCE_STANDRAD,
       --?,
       MYROW.SIMPLE_PROCESS,
       '0',
       '5',
       MYROW.FEED_TIME,
       MYROW.ID,
       MYROW.SEQ,
       MYROW.STOVE_NO,
       --JUDGE_STOVE_NO,
       V_ZP_JUDGE_STOVE_NO,
       --LOT_NO,
       V_ZP_LOT_NO,
       --MYROW.CONTRACT_NO
       ?,
       MYROW.IMP_PROCESS,
       MYROW.PLINE_CODE,
       '45',
       MYROW.PRODUCER,
       MYROW.PROCESS_STATUS,
       MYROW.DB_LENGTH,
       MYROW.DB_HEIGHT,
       MYROW.ROLL_LENGTH,
       V_SAW_NUM,
       MYROW.TARGET_LENGTH,
       MYROW.FINISH_USER,
       MYROW.TARGET_LIABRARY,
       --MYROW.VARIETIES,
       ?,
       --MYROW.PIPE_SIZE,
       ?,
       --MYROW.BUCKLE_TYPE,
       ?,
       MYROW.LENGTH_RANGE,
       MYROW.ROLL_STANDRAD,
       
       MYROW.PIPE_SECTION,
       MYROW.STEELCODE,
       --?,
       MYROW.STEELNAME,
       --?,
       MYROW.GRADECODE,
       MYROW.GRADENAME,
       MYROW.ORD_LN_DLY_PK,
       MYROW.PRT_FLAG,
       MYROW.PRO_PLAN_ID,
       MYROW.GX_PLAN_NO,
       
       MYROW.VARIETIES_CODE,
       MYROW.PIPE_SIZE_CODE,
       MYROW.BUCKLE_TYPE_CODE,
       MYROW.ROLL_STANDRAD_CODE,
       MYROW.STD_STYLE,
       MYROW.STD_STYLE_DESC,
       MYROW.CRAFT_SEQ,
       MYROW.CIC,
       MYROW.INDEX_SEQ,
       MYROW.PIC,
       MYROW.IF_PRODUCT,
       MYROW.PRDCR_NO,
       MYROW.IF_MONITOR);
  
    UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T
       SET T.PLAN_ID = MYROW.ID
     WHERE T.JUDGE_STOVE_NO = V_ZP_JUDGE_STOVE_NO
       AND T.LOT_NO = V_ZP_LOT_NO
       AND T.PLINE_CODE = V_PLINE_CODE;
  
    UPDATE MIL_REFUR_RACK T
       SET T.RESULT_NO = MYROW.ID
     WHERE T.JUDGE_STOVE_NO = V_ZP_JUDGE_STOVE_NO
       AND T.LOT_NO = V_ZP_LOT_NO
       AND T.PLINE_CODE = V_PLINE_CODE;
  
    INSERT INTO MIL_FEEDSAW_RESULT
      (RESULT_NO,
       LOT_NO,
       JUDGE_STOVE_NO,
       PLINE_CODE,
       COL_TIME,
       PRO_PLAN_ID,
       GX_PLAN_NO)
    VALUES
      (MYROW.ID,
       V_ZP_LOT_NO,
       V_ZP_JUDGE_STOVE_NO,
       V_PLINE_CODE,
       SYSDATE,
       MYROW.PRO_PLAN_ID,
       MYROW.GX_PLAN_NO);
  
    INSERT INTO MIL_ROLLING_RESULT
      (RESULT_NO,
       LOT_NO,
       JUDGE_STOVE_NO,
       PLINE_CODE,
       COL_TIME,
       QUALIFIED_NUM,
       ROLLINGNUM,
       PRO_PLAN_ID,
       GX_PLAN_NO)
    VALUES
      (MYROW.ID,
       V_ZP_LOT_NO,
       V_ZP_JUDGE_STOVE_NO,
       V_PLINE_CODE,
       SYSDATE,
       V_QUALIFIED_NUM,
       V_QUALIFIED_NUM,
       MYROW.PRO_PLAN_ID,
       MYROW.GX_PLAN_NO);
  
  END LOOP;
END;
	]]>
	</query>
	
	<query id= "FrmComposeFurnaces.insertRefurRack" desc = "插入再加热炉及后续工序管号队列跟踪表">
	<![CDATA[
	DECLARE
  V_SEQ               MIL_REFUR_RACK.SEQ%TYPE := NULL;
  V_SEQ1              MIL_REFUR_RACK.SEQ%TYPE := NULL;
  V_SEQ2              MIL_REFUR_RACK.SEQ%TYPE := NULL;
  V_JUDGE_STOVE_NO    MIL_REFUR_RACK.JUDGE_STOVE_NO%TYPE := ?; --当前炉号
  V_LOT_NO            MIL_REFUR_RACK.LOT_NO%TYPE := ?; --当前生产批号
  V_PLINE_CODE        MIL_REFUR_RACK.PLINE_CODE%TYPE := ?; --产线
  V_ZP_JUDGE_STOVE_NO MIL_REFUR_RACK.JUDGE_STOVE_NO%TYPE := ?; --组炉炉号
  V_ZP_LOT_NO         MIL_REFUR_RACK.LOT_NO%TYPE := ?; --组炉生产批号
  V_GROUP_NUM         MIL_FURNACES_RESLUT_DETIA.GROUP_NUM%TYPE := ?; --操作支数
  V_SAW_NUM           MIL_PLAN.SAW_NUM%TYPE := ?; --传进来的分切数
  V_SAW_NUM_M         MIL_PLAN.SAW_NUM%TYPE := NULL; --主炉号分切数
  V_SAW_NUM_T         MIL_PLAN.SAW_NUM%TYPE := NULL; --当前炉分切数
  V_GROUP_NUM1        MIL_FURNACES_RESLUT_DETIA.GROUP_NUM%TYPE := NULL; --切后支数
  N                   MIL_FURNACES_RESLUT_DETIA.GROUP_NUM%TYPE := 1;
  M                   MIL_FURNACES_RESLUT_DETIA.GROUP_NUM%TYPE := 1;
  V_JUDGE_STOVE_NO_M  MIL_REFUR_RACK.JUDGE_STOVE_NO%TYPE := ?; --主炉炉号
  V_LOT_NO_M          MIL_REFUR_RACK.LOT_NO%TYPE := ?; --主炉生产批号
  V_ID                MIL_PLAN.ID%TYPE := NULL; --主炉ID
  V_TARGET            MIL_PLAN.TARGET%TYPE := NULL;
  V_ORDER_LENGTHA     MIL_PLAN.ORDER_LENGTHA%TYPE := NULL;
  V_PRO_PLAN_ID       MIL_PLAN.PRO_PLAN_ID%TYPE := NULL;
  V_GX_PLAN_NO        MIL_PLAN.GX_PLAN_NO%TYPE := NULL;
  V_BAL_YEAR_MONTH    PORT_MIL_BATCH_SAMPLE_RESULT.BAL_YEAR_MONTH%TYPE := NULL;
  V_COUNT             MIL_FURNACES_RESLUT_DETIA.GROUP_NUM%TYPE := 0; --已写入的坯子数
BEGIN
  --生成管序号
  SELECT (NVL(MAX(T.SEQ), 0) + 1) SEQ
    INTO V_SEQ
    FROM MIL_REFUR_RACK T
   WHERE T.JUDGE_STOVE_NO = V_ZP_JUDGE_STOVE_NO
     AND T.LOT_NO = V_ZP_LOT_NO
     AND T.PLINE_CODE = V_PLINE_CODE;

  --生成冷区管序号
  SELECT (NVL(MAX(T.SEQ), 0) + 1) SEQ
    INTO V_SEQ1
    FROM MIL_STRAIGH_RACK T
   WHERE T.JUDGE_STOVE_NO = V_ZP_JUDGE_STOVE_NO
     AND T.LOT_NO = V_ZP_LOT_NO
     AND T.PLINE_CODE = V_PLINE_CODE;

  --生成进程表管序号
  SELECT (NVL(MAX(T.SEQ), 0) + 1) SEQ
    INTO V_SEQ2
    FROM PORT_MIL_BATCH_SAMPLE_RESULT T
   WHERE T.JUDGE_STOVE_NO = V_ZP_JUDGE_STOVE_NO
     AND T.LOT_NO = V_ZP_LOT_NO
     AND T.PLINE_CODE = V_PLINE_CODE;

  --计算切后支数
  IF (V_SAW_NUM > 0) THEN
    V_GROUP_NUM1 := V_SAW_NUM * V_GROUP_NUM;
  ELSE
    SELECT T.SAW_NUM * V_GROUP_NUM, T.SAW_NUM
      INTO V_GROUP_NUM1, V_SAW_NUM
      FROM MIL_PLAN T
     WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO_M
       AND T.LOT_NO = V_LOT_NO_M
       AND T.PLINE_CODE = V_PLINE_CODE;
  END IF;

  --查询主炉号的ID,去向，定尺长度 ORDER_LENGTHA
  SELECT T.ID,
         DECODE(T.TARGET, 'A', '01', 'B', '02', 'C', '03'),
         T.ORDER_LENGTHA,
         T.PRO_PLAN_ID,
         T.GX_PLAN_NO
    INTO V_ID, V_TARGET, V_ORDER_LENGTHA, V_PRO_PLAN_ID, V_GX_PLAN_NO
    FROM MIL_PLAN T
   WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO_M
     AND T.LOT_NO = V_LOT_NO_M
     AND T.PLINE_CODE = V_PLINE_CODE;

  --查询当炉的结转年月
  SELECT MIN(T.BAL_YEAR_MONTH)
    INTO V_BAL_YEAR_MONTH
    FROM PORT_MIL_BATCH_SAMPLE_RESULT T
   WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
     AND T.PLINE_CODE = V_PLINE_CODE;

  --当前炉的分切数
  SELECT T.SAW_NUM
    INTO V_SAW_NUM_T
    FROM MIL_PLAN T
   WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
     AND T.PLINE_CODE = V_PLINE_CODE;

  --已写入的坯子数
  SELECT COUNT(1)
    INTO V_COUNT
    FROM MIL_REFUR_RACK T
   WHERE T.JUDGE_STOVE_NO = V_ZP_JUDGE_STOVE_NO
     AND T.PLINE_CODE = V_PLINE_CODE;

  WHILE N < V_GROUP_NUM + 1 LOOP
    BEGIN
      V_COUNT := V_COUNT + 1;
    
      --插入再加热炉跟踪表         
      INSERT INTO MIL_REFUR_RACK
        (MAT_NO,
         LOT_NO,
         JUDGE_STOVE_NO,
         PLINE_CODE,
         GROUP_FLAG,
         COL_TIME,
         SEQ,
         RESULT_NO,
         STATUS,
         PRO_PLAN_ID,
         GX_PLAN_NO)
      VALUES
        (REGEXP_REPLACE(V_ZP_JUDGE_STOVE_NO, '-.*', '') || V_TARGET || V_COUNT ||
         V_COUNT,
         V_ZP_LOT_NO,
         V_ZP_JUDGE_STOVE_NO,
         V_PLINE_CODE,
         '1',
         SYSDATE,
         V_SEQ,
         V_ID,
         '0',
         V_PRO_PLAN_ID,
         V_GX_PLAN_NO);
    
      --插入定径跟踪表
      INSERT INTO MIL_SIZING_RACK
        ( --MAT_NO,
         LOT_NO,
         JUDGE_STOVE_NO,
         PLINE_CODE,
         GROUP_FLAG,
         COL_TIME,
         SEQ,
         RESULT_NO,
         STATUS,
         PRO_PLAN_ID,
         GX_PLAN_NO)
      VALUES
        ( --MYROW.MAT_NO,
         V_ZP_LOT_NO,
         V_ZP_JUDGE_STOVE_NO,
         V_PLINE_CODE,
         '1',
         SYSDATE,
         V_SEQ,
         V_ID,
         '0',
         V_PRO_PLAN_ID,
         V_GX_PLAN_NO);
    
      --插入管排锯跟踪表
      INSERT INTO MIL_SAW_RACK
        ( --MAT_NO,
         LOT_NO,
         JUDGE_STOVE_NO,
         PLINE_CODE,
         GROUP_FLAG,
         COL_TIME,
         SEQ,
         RESULT_NO,
         STATUS,
         PRO_PLAN_ID,
         GX_PLAN_NO)
      VALUES
        ( --MYROW.MAT_NO,
         V_ZP_LOT_NO,
         V_ZP_JUDGE_STOVE_NO,
         V_PLINE_CODE,
         '1',
         SYSDATE,
         V_SEQ,
         V_ID,
         '0',
         V_PRO_PLAN_ID,
         V_GX_PLAN_NO);
    
      V_SEQ := V_SEQ + 1;
    
      M := 1;
      WHILE M < V_SAW_NUM + 1 LOOP
        BEGIN
          --插入矫直跟踪表
          INSERT INTO MIL_STRAIGH_RACK
            ( --MAT_NO,
             LOT_NO,
             JUDGE_STOVE_NO,
             PLINE_CODE,
             START_STRAIGHTENING_TIME,
             END_STRAIGHTENING_TIME,
             --FOLLOW_FLAG,
             COL_TIME,
             SEQ,
             RESULT_NO,
             --PIPE_LENGTH,
             COL_NO,
             STATUS,
             PRO_PLAN_ID,
             GX_PLAN_NO)
          VALUES
            ( --MYROW1.MAT_NO,
             V_ZP_LOT_NO,
             V_ZP_JUDGE_STOVE_NO,
             V_PLINE_CODE,
             '',
             '',
             --'1',
             SYSDATE,
             V_SEQ1,
             V_ID,
             --V_ORDER_LENGTHA,
             '1',
             '0',
             V_PRO_PLAN_ID,
             V_GX_PLAN_NO);
        
          --插入探伤炉跟踪表
          INSERT INTO MIL_TESTING_RACK
            ( --MAT_NO,
             LOT_NO,
             JUDGE_STOVE_NO,
             PLINE_CODE,
             START_INSPECTION_TIME,
             END_INSPECTION_TIME,
             --FOLLOW_FLAG,
             COL_TIME,
             SEQ,
             RESULT_NO,
             PIPE_LENGTH,
             STATUS,
             PRO_PLAN_ID,
             GX_PLAN_NO)
          VALUES
            ( --MYROW1.MAT_NO,
             V_ZP_LOT_NO,
             V_ZP_JUDGE_STOVE_NO,
             V_PLINE_CODE,
             '',
             '',
             --'1',
             SYSDATE,
             V_SEQ1,
             V_ID,
             V_ORDER_LENGTHA,
             '0',
             V_PRO_PLAN_ID,
             V_GX_PLAN_NO);
        
          --插入表检跟踪表
          INSERT INTO MIL_QA_RACK
            ( --MAT_NO,
             LOT_NO,
             JUDGE_STOVE_NO,
             PLINE_CODE,
             START_TIME,
             END_TIME,
             --FOLLOW_FLAG,
             COL_TIME,
             SEQ,
             RESULT_NO,
             PIPE_LENGTH,
             STATUS,
             PRO_PLAN_ID,
             GX_PLAN_NO)
          VALUES
            ( --MYROW1.MAT_NO,
             V_ZP_LOT_NO,
             V_ZP_JUDGE_STOVE_NO,
             V_PLINE_CODE,
             '',
             '',
             --'1',
             SYSDATE,
             V_SEQ1,
             V_ID,
             V_ORDER_LENGTHA,
             '0',
             V_PRO_PLAN_ID,
             V_GX_PLAN_NO);
        
          --插入进程表
          INSERT INTO PORT_MIL_BATCH_SAMPLE_RESULT
            (PLAN_ID,
             LOT_NO,
             JUDGE_STOVE_NO,
             PLINE_CODE,
             SEQ,
             MAT_NO,
             
             ORDER_LENGTH,
             CRATE_TIME,
             M_MAT_NO,
             M_M_MAT_NO,
             PRO_PLAN_ID,
             GX_PLAN_NO,
             bal_year_month)
          VALUES
            (V_ID,
             V_ZP_LOT_NO,
             V_ZP_JUDGE_STOVE_NO,
             V_PLINE_CODE,
             V_SEQ2,
             REGEXP_REPLACE(V_ZP_JUDGE_STOVE_NO, '-.*', '') || V_TARGET || V_COUNT ||
             V_COUNT || M,
             
             V_ORDER_LENGTHA,
             SYSDATE,
             REGEXP_REPLACE(V_ZP_JUDGE_STOVE_NO, '-.*', '') || V_TARGET || V_COUNT ||
             V_COUNT,
             REGEXP_REPLACE(V_ZP_JUDGE_STOVE_NO, '-.*', '') || V_TARGET || V_COUNT,
             
             V_PRO_PLAN_ID,
             V_GX_PLAN_NO,
             V_BAL_YEAR_MONTH);
        
          V_SEQ1 := V_SEQ1 + 1;
          V_SEQ2 := V_SEQ2 + 1;
          M      := M + 1;
        
        END;
      END LOOP;
      N := N + 1;
    END;
  END LOOP;

  --修改原炉号组炉后的状态
  FOR MYROW IN (SELECT *
                  FROM (SELECT T.*
                          FROM PORT_MIL_BATCH_SAMPLE_RESULT T
                         WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
                           AND T.LOT_NO = V_LOT_NO
                           AND T.PLINE_CODE = V_PLINE_CODE
                           AND T.Status = '1'
                           AND TRIM(T.Op_Process) = '5'
                           AND T.GROUP_FLAG = '0'
                         ORDER BY T.SEQ ASC)
                 WHERE ROWNUM <= V_GROUP_NUM * V_SAW_NUM_T) LOOP
  
    UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T
       SET T.BACK_PROCESS = '5', T.GROUP_FLAG = '1'
     WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
       AND T.MAT_NO = MYROW.MAT_NO;
  END LOOP;
END;
	]]>
	</query>
	
	<query id= "FrmComposeFurnaces.insertRefurRackBF" desc = "插入再加热炉及后续工序管号队列跟踪表">
	<![CDATA[
	DECLARE
  V_SEQ               MIL_REFUR_RACK.SEQ%TYPE := NULL;
  V_SEQ1              MIL_REFUR_RACK.SEQ%TYPE := NULL;
  V_JUDGE_STOVE_NO    MIL_REFUR_RACK.JUDGE_STOVE_NO%TYPE := ?;
  V_LOT_NO            MIL_REFUR_RACK.LOT_NO%TYPE := ?;
  V_PLINE_CODE        MIL_REFUR_RACK.PLINE_CODE%TYPE := ?;
  V_ZP_JUDGE_STOVE_NO MIL_REFUR_RACK.JUDGE_STOVE_NO%TYPE := ?;
  V_ZP_LOT_NO         MIL_REFUR_RACK.LOT_NO%TYPE := ?;
  V_GROUP_NUM         MIL_FURNACES_RESLUT_DETIA.GROUP_NUM%TYPE := ?;
  V_GROUP_NUM1        MIL_FURNACES_RESLUT_DETIA.GROUP_NUM%TYPE := NULL;
BEGIN
  --生成管序号
  SELECT (NVL(MAX(T.SEQ), 0) + 1) SEQ
    INTO V_SEQ
    FROM MIL_REFUR_RACK T
   WHERE T.JUDGE_STOVE_NO = V_ZP_JUDGE_STOVE_NO
     AND T.LOT_NO = V_ZP_LOT_NO
     AND T.PLINE_CODE = V_PLINE_CODE;

  --生成冷区管序号
  SELECT (NVL(MAX(T.SEQ), 0) + 1) SEQ
    INTO V_SEQ1
    FROM MIL_STRAIGH_RACK T
   WHERE T.JUDGE_STOVE_NO = V_ZP_JUDGE_STOVE_NO
     AND T.LOT_NO = V_ZP_LOT_NO
     AND T.PLINE_CODE = V_PLINE_CODE;

  --计算切后支数
  SELECT T.SAW_NUM * V_GROUP_NUM
    INTO V_GROUP_NUM1
    FROM MIL_PLAN T
   WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
     AND T.LOT_NO = V_LOT_NO
     AND T.PLINE_CODE = V_PLINE_CODE;

  FOR MYROW IN (SELECT *
                  FROM (SELECT T.*
                          FROM MIL_REFUR_RACK T
                         WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
                           AND T.LOT_NO = V_LOT_NO
                           AND T.PLINE_CODE = V_PLINE_CODE
                           AND T.STATUS = '1'
                           AND (T.GROUP_FLAG = '0' OR T.GROUP_FLAG IS NULL)
                         ORDER BY T.SEQ ASC)
                 WHERE ROWNUM <= V_GROUP_NUM) LOOP
    --插入再加热炉跟踪表         
    INSERT INTO MIL_REFUR_RACK
      (MAT_NO,
       LOT_NO,
       JUDGE_STOVE_NO,
       PLINE_CODE,
       GROUP_FLAG,
       COL_TIME,
       SEQ,
       RESULT_NO,
       STATUS)
    VALUES
      (MYROW.MAT_NO,
       V_ZP_LOT_NO,
       V_ZP_JUDGE_STOVE_NO,
       V_PLINE_CODE,
       '1',
       SYSDATE,
       V_SEQ,
       MYROW.RESULT_NO,
       '0');
  
    --插入定径跟踪表
    INSERT INTO MIL_SIZING_RACK
      (--MAT_NO,
       LOT_NO,
       JUDGE_STOVE_NO,
       PLINE_CODE,
       GROUP_FLAG,
       COL_TIME,
       SEQ,
       RESULT_NO,
       STATUS)
    VALUES
      (--MYROW.MAT_NO,
       V_ZP_LOT_NO,
       V_ZP_JUDGE_STOVE_NO,
       V_PLINE_CODE,
       '1',
       SYSDATE,
       V_SEQ,
       MYROW.RESULT_NO,
       '0');
  
    --插入管排锯跟踪表
    INSERT INTO MIL_SAW_RACK
      (--MAT_NO,
       LOT_NO,
       JUDGE_STOVE_NO,
       PLINE_CODE,
       GROUP_FLAG,
       COL_TIME,
       SEQ,
       RESULT_NO,
       STATUS)
    VALUES
      (--MYROW.MAT_NO,
       V_ZP_LOT_NO,
       V_ZP_JUDGE_STOVE_NO,
       V_PLINE_CODE,
       '1',
       SYSDATE,
       V_SEQ,
       MYROW.RESULT_NO,
       '0');
  
    UPDATE MIL_REFUR_RACK T
       SET T.GROUP_FLAG = '1'
     WHERE T.MAT_NO = MYROW.MAT_NO;
  
    V_SEQ := V_SEQ + 1;
  END LOOP;

  FOR MYROW1 IN (SELECT *
                   FROM (SELECT *
                           FROM PORT_MIL_BATCH_SAMPLE_RESULT T
                          WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
                            AND T.LOT_NO = V_LOT_NO
                            AND T.PLINE_CODE = V_PLINE_CODE
                            AND T.STATUS = '1'
                            AND T.OP_PROCESS = '5'
                          ORDER BY T.SEQ ASC)
                  WHERE ROWNUM <= V_GROUP_NUM1) LOOP
    --插入矫直跟踪表
    INSERT INTO MIL_STRAIGH_RACK
      (--MAT_NO,
       LOT_NO,
       JUDGE_STOVE_NO,
       PLINE_CODE,
       START_STRAIGHTENING_TIME,
       END_STRAIGHTENING_TIME,
       --FOLLOW_FLAG,
       COL_TIME,
       SEQ,
       RESULT_NO,
       PIPE_LENGTH,
       COL_NO,
       STATUS)
    VALUES
      (--MYROW1.MAT_NO,
       V_ZP_LOT_NO,
       V_ZP_JUDGE_STOVE_NO,
       V_PLINE_CODE,
       '',
       '',
       --'1',
       SYSDATE,
       V_SEQ1,
       MYROW1.Plan_Id,
       MYROW1.Order_Length,
       '1',
       '0');
  
    --插入探伤炉跟踪表
    INSERT INTO MIL_TESTING_RACK
      (--MAT_NO,
       LOT_NO,
       JUDGE_STOVE_NO,
       PLINE_CODE,
       START_INSPECTION_TIME,
       END_INSPECTION_TIME,
       --FOLLOW_FLAG,
       COL_TIME,
       SEQ,
       RESULT_NO,
       PIPE_LENGTH,
       STATUS)
    VALUES
      (--MYROW1.MAT_NO,
       V_ZP_LOT_NO,
       V_ZP_JUDGE_STOVE_NO,
       V_PLINE_CODE,
       '',
       '',
       --'1',
       SYSDATE,
       V_SEQ1,
       MYROW1.Plan_Id,
       MYROW1.Order_Length,
       '0');
  
    --插入表检跟踪表
    INSERT INTO MIL_QA_RACK
      (--MAT_NO,
       LOT_NO,
       JUDGE_STOVE_NO,
       PLINE_CODE,
       START_TIME,
       END_TIME,
       --FOLLOW_FLAG,
       COL_TIME,
       SEQ,
       RESULT_NO,
       PIPE_LENGTH,
       STATUS)
    VALUES
      (--MYROW1.MAT_NO,
       V_ZP_LOT_NO,
       V_ZP_JUDGE_STOVE_NO,
       V_PLINE_CODE,
       '',
       '',
       --'1',
       SYSDATE,
       V_SEQ1,
       MYROW1.Plan_Id,
       MYROW1.Order_Length,
       '0');
  
    V_SEQ1 := V_SEQ1 + 1;
  END LOOP;
END;
	
	]]>
	</query>
	
	<query id= "FrmComposeFurnaces.insertBatch" desc = "插入进程表">
	<![CDATA[
	DECLARE
  V_ID                MIL_PLAN.ID%TYPE := NULL;
  V_SEQ               PORT_MIL_BATCH_SAMPLE_RESULT.SEQ%TYPE := NULL;
  V_GROUP_NUM         MIL_FURNACES_RESLUT_DETIA.GROUP_NUM%TYPE := NULL;
  V_ZP_JUDGE_STOVE_NO MIL_PLAN.JUDGE_STOVE_NO%TYPE := ?;
  V_ZP_LOT_NO         MIL_PLAN.LOT_NO%TYPE := ?;
  V_JUDGE_STOVE_NO    MIL_PLAN.JUDGE_STOVE_NO%TYPE := ?;
  V_LOT_NO            MIL_PLAN.LOT_NO%TYPE := ?;
  V_PLINE_CODE        MIL_PLAN.PLINE_CODE%TYPE := ?;
  V_COL_NUM           MIL_FURNACES_RESLUT.OFFLINE_NUM%TYPE := ?;
  V_PRO_PLAN_ID       MIL_PLAN.PRO_PLAN_ID%TYPE := ?;
  V_GX_PLAN_NO        MIL_PLAN.GX_PLAN_NO%TYPE := ?;
  V_PRO_PLAN_ID_M     MIL_PLAN.PRO_PLAN_ID%TYPE := ?;
  V_GX_PLAN_NO_M      MIL_PLAN.GX_PLAN_NO%TYPE := ?;

BEGIN

  --生成主键
  SELECT TO_CHAR(SYSDATE, 'YYMMDD') ||
         LPAD(NVL(MAX(SUBSTR(T.ID, 7)), 0) + 1, 3, 0) DI
    INTO V_ID
    FROM MIL_PLAN T
   WHERE T.PLINE_CODE = V_PLINE_CODE
        --AND REGEXP_REPLACE(T.ID,'^[-\+]?\D+(\.\D+)?$','') IS NULL
     AND TO_CHAR(T.TOM, 'YYYY-MM-DD') = TO_CHAR(SYSDATE, 'YYYY-MM-DD');
  --生成管序号
  SELECT (NVL(MAX(T.SEQ), 0) + 1) SEQ
    INTO V_SEQ
    FROM PORT_MIL_BATCH_SAMPLE_RESULT T
   WHERE T.JUDGE_STOVE_NO = V_ZP_JUDGE_STOVE_NO
     AND T.LOT_NO = V_ZP_LOT_NO
     AND T.PRO_PLAN_ID = V_PRO_PLAN_ID_M
     AND T.GX_PLAN_NO = V_PRO_PLAN_ID_M
     AND T.PLINE_CODE = V_PLINE_CODE;

  --进程表中的操作支数
  SELECT MAX(T.SAW_NUM) * V_COL_NUM
    INTO V_GROUP_NUM
    FROM MIL_PLAN T
   WHERE T.CONTRACT_NO = ?;

  /* SELECT V_SAW_NUM 
   INTO V_GROUP_NUM
   FROM MIL_PLAN T
  WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
    AND T.LOT_NO = V_LOT_NO
    AND T.PLINE_CODE = V_PLINE_CODE;*/

  FOR MYROW IN (SELECT *
                  FROM (SELECT T.*
                          FROM PORT_MIL_BATCH_SAMPLE_RESULT T
                         WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
                           AND T.LOT_NO = V_LOT_NO
                           AND T.PRO_PLAN_ID = V_PRO_PLAN_ID
                           AND T.GX_PLAN_NO = V_GX_PLAN_NO
                           AND T.PLINE_CODE = V_PLINE_CODE
                           AND T.Status = '1'
                           AND TRIM(T.Op_Process) = '5'
                           AND T.GROUP_FLAG = '0'
                         ORDER BY T.SEQ ASC)
                 WHERE ROWNUM <= V_GROUP_NUM) LOOP
  
    INSERT INTO PORT_MIL_BATCH_SAMPLE_RESULT
      (PLAN_ID,
       LOT_NO,
       STOVE_NO,
       JUDGE_STOVE_NO,
       PLINE_CODE,
       BATCH_NO,
       SEQ,
       MAT_NO,
       IS_SAMPLE_PIPE,
       
       ORDER_LENGTH,
       ACT_THEORY_WEIGHT,
       ACT_COUNT,
       CRATE_TIME,
       M_MAT_NO,
       M_M_MAT_NO,
       INPUT_WEIGHT,
       STATUS,
       BACK_PROCESS,
       PRO_PLAN_ID,
       GX_PLAN_NO,
       bal_year_month)
    VALUES
      (MYROW.PLAN_ID,
       V_ZP_LOT_NO,
       '',
       V_ZP_JUDGE_STOVE_NO,
       MYROW.PLINE_CODE,
       MYROW.BATCH_NO,
       V_SEQ,
       MYROW.MAT_NO,
       '0',
       
       MYROW.ORDER_LENGTH,
       MYROW.ACT_THEORY_WEIGHT,
       MYROW.ACT_COUNT,
       SYSDATE,
       MYROW.M_MAT_NO,
       MYROW.M_M_MAT_NO,
       MYROW.INPUT_WEIGHT,
       '0',
       '',
       V_PRO_PLAN_ID_M,
       V_GX_PLAN_NO_M,
       MYROW.bal_year_month);
  
    UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T
       SET T.BACK_PROCESS = '5', T.GROUP_FLAG = '1'
     WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
       AND T.MAT_NO = MYROW.MAT_NO;
    V_SEQ := V_SEQ + 1;
  END LOOP;
END;
	]]>
	</query>


<query id= "FrmComposeFurnaces.cancelFurnaceReslut" desc = "修改荒管剔除待处理实绩表状态，以及删除子表数据">
	<![CDATA[
	DECLARE
  V_ZP_JUDGE_STOVE_NOM MIL_FURNACES_RESLUT_DETIA.ZP_JUDGE_STOVE_NO%TYPE := ?;
  V_ZP_LOT_NO          MIL_FURNACES_RESLUT_DETIA.ZP_LOT_NO%TYPE := ?;
  V_PLINE_CODE         MIL_FURNACES_RESLUT_DETIA.PLINE_CODE%TYPE := ?;
BEGIN

  FOR MYROW IN (SELECT *
                  FROM MIL_FURNACES_RESLUT_DETIA T
                 WHERE T.ZP_JUDGE_STOVE_NO = ZP_JUDGE_STOVE_NO
                   AND T.ZP_LOT_NO = V_ZP_LOT_NO
                   AND T.PLINE_CODE = V_PLINE_CODE) LOOP
    --更新荒管剔除待处理实绩表状态
    UPDATE MIL_FURNACES_RESLUT T
       SET T.ZP_FLAG   = '0',
           T.GROUP_NUM = T.GROUP_NUM - MYROW.GROUP_NUM,
           T.STATUS    = '0'
     WHERE 1 = 1
       AND T.JUDGE_STOVE_NO = MYROW.JUDGE_STOVE_NO;
    --删除荒管组炉实绩表子表
    DELETE FROM MIL_FURNACES_RESLUT_DETIA T
     WHERE T.JUDGE_STOVE_NO = MYROW.JUDGE_STOVE_NO
       AND T.ZP_JUDGE_STOVE_NO = V_ZP_JUDGE_STOVE_NOM
       AND T.ZP_LOT_NO = V_ZP_LOT_NO
       AND T.PLINE_CODE = V_PLINE_CODE;
  END LOOP;
END;

	]]>
	</query>
	
	<query id= "FrmComposeFurnaces.cancelFurnaceGroup" desc = "删除荒管组炉实绩表数据">
	<![CDATA[
	DELETE FROM  MIL_FURNACES_GROUP T WHERE T.ZP_JUDGE_STOVE_NO = ? AND T.ZP_LOT_NO =? AND T.PLINE_CODE =?
	]]>
	</query>
	
	<query id= "FrmComposeFurnaces.doQueryMilPlan" desc = "查询该组炉是否已开始再加热炉">
	<![CDATA[
	SELECT COUNT(1) ACOUNT FROM MIL_REFUR_RESULT T WHERE T.JUDGE_STOVE_NO = ? AND T.LOT_NO = ? AND T.PLINE_CODE = ?
	]]>
	</query>
	
	<query id= "FrmComposeFurnaces.cancelMilPlan" desc = "删除计划表">
	<![CDATA[
	DECLARE
  V_JUDGE_STOVE_NO MIL_PLAN.JUDGE_STOVE_NO%TYPE := ?;
  V_LOT_NO         MIL_PLAN.LOT_NO%TYPE := ?;
  V_PLINE_CODE     MIL_PLAN.PLINE_CODE%TYPE := ?;
BEGIN
  DELETE FROM MIL_PLAN T
   WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
     AND T.LOT_NO = V_LOT_NO
     AND T.PLINE_CODE = V_PLINE_CODE;

  DELETE FROM MIL_FEEDSAW_RESULT T
   WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
     AND T.LOT_NO = V_LOT_NO
     AND T.PLINE_CODE = V_PLINE_CODE;

  DELETE FROM MIL_ROLLING_RESULT T
   WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
     AND T.LOT_NO = V_LOT_NO
     AND T.PLINE_CODE = V_PLINE_CODE;

END;
	]]>
	</query>
	
	<query id= "FrmComposeFurnaces.cancelFeedSaw" desc = "删除管坯锯切实绩表">
	<![CDATA[
	DELETE FROM  MIL_FEEDSAW_RESULT T WHERE T.JUDGE_STOVE_NO = ? AND T.LOT_NO =? AND T.PLINE_CODE =?
	]]>
	</query>
	
	<query id= "FrmComposeFurnaces.cancelRefurRack" desc = "删除再加热炉及后续工序管号队列跟踪表">
	<![CDATA[
	DECLARE
  V_JUDGE_STOVE_NO MIL_REFUR_RACK.JUDGE_STOVE_NO%TYPE := ?;
  V_LOT_NO         MIL_REFUR_RACK.LOT_NO%TYPE := ?;
  V_PLINE_CODE     MIL_REFUR_RACK.PLINE_CODE%TYPE := ?;
BEGIN
  FOR MYROW IN (SELECT T.*
                  FROM MIL_REFUR_RACK T
                 WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
                   AND T.LOT_NO = V_LOT_NO
                   AND T.PLINE_CODE = V_PLINE_CODE) LOOP
    UPDATE MIL_REFUR_RACK T
       SET T.GROUP_FLAG = '0'
     WHERE T.MAT_NO = MYROW.MAT_NO
       AND T.JUDGE_STOVE_NO <> MYROW.JUDGE_STOVE_NO;
    DELETE FROM MIL_REFUR_RACK T
     WHERE T.MAT_NO = MYROW.MAT_NO
       AND T.JUDGE_STOVE_NO = MYROW.JUDGE_STOVE_NO;
  END LOOP;

  DELETE FROM MIL_SIZING_RACK T
   WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
     AND T.LOT_NO = V_LOT_NO
     AND T.PLINE_CODE = V_PLINE_CODE;

  DELETE FROM MIL_SAW_RACK T
   WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
     AND T.LOT_NO = V_LOT_NO
     AND T.PLINE_CODE = V_PLINE_CODE;

  DELETE FROM MIL_STRAIGH_RACK T
   WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
     AND T.LOT_NO = V_LOT_NO
     AND T.PLINE_CODE = V_PLINE_CODE;

  DELETE FROM MIL_TESTING_RACK T
   WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
     AND T.LOT_NO = V_LOT_NO
     AND T.PLINE_CODE = V_PLINE_CODE;

  DELETE FROM MIL_QA_RACK T
   WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
     AND T.LOT_NO = V_LOT_NO
     AND T.PLINE_CODE = V_PLINE_CODE;
END;
	
	]]>
	</query>
	
	<query id= "FrmComposeFurnaces.cancelBatch" desc = "删除进程表">
	<![CDATA[
	DECLARE
  V_JUDGE_STOVE_NO PORT_MIL_BATCH_SAMPLE_RESULT.JUDGE_STOVE_NO%TYPE := ?;
  V_LOT_NO         PORT_MIL_BATCH_SAMPLE_RESULT.LOT_NO%TYPE := ?;
  V_PLINE_CODE     PORT_MIL_BATCH_SAMPLE_RESULT.PLINE_CODE%TYPE := ?;
BEGIN
  FOR MYROW IN (SELECT T.*
                  FROM PORT_MIL_BATCH_SAMPLE_RESULT T
                 WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
                   AND T.LOT_NO = V_LOT_NO
                   AND T.PLINE_CODE = V_PLINE_CODE) LOOP
  
    DELETE FROM PORT_MIL_BATCH_SAMPLE_RESULT T
     WHERE T.JUDGE_STOVE_NO = MYROW.JUDGE_STOVE_NO
       AND T.MAT_NO = MYROW.MAT_NO;
  END LOOP;

  FOR MYROW1 IN (SELECT M.*
                   FROM MIL_FURNACES_RESLUT_DETIA M
                  WHERE M.ZP_JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
                    AND M.PLINE_CODE = V_PLINE_CODE) LOOP
  
    UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T
       SET T.GROUP_FLAG = 0, T.BACK_PROCESS = ''
     WHERE T.STATUS = 1
       AND T.GROUP_FLAG = 1
       AND TRIM(T.OP_PROCESS) = '5'
       AND T.JUDGE_STOVE_NO = MYROW1.JUDGE_STOVE_NO;
  END LOOP;
END;
	]]>
	</query>
	
	<query id= "FrmComposeFurnaces.doQueryFurnace" desc = "组炉实绩查询（主表）">
	<![CDATA[
	SELECT T.ZP_JUDGE_STOVE_NO,
       T.ZP_LOT_NO,
       T.ZP_COUNT,
       T.ZP_STANDRAD,
       T.ZP_STEEL,
       T.ZP_GRADE,
       T.ZP_LENGTH,
       T.ZP_HEIGHT,
       T.ZP_LENGTH_RANGE,
       T.ZP_LEVEL,
       T.ZP_SIZE,
       TO_CHAR(T.ZP_TIME, 'YYYY-MM-DD HH24:MI:SS') ZP_TIME,
       T.REMARK,
       T.COL_USER,
       DECODE(T.COL_SHIFT,
              '0',
              '常白班',
              '1',
              '早班',
              '2',
              '中班',
              '3',
              '夜班') COL_SHIFT,
       DECODE(T.COL_GROUP,
              '1',
              '甲班',
              '2',
              '乙班',
              '3',
              '丙班',
              '4',
              '丁班') COL_GROUP,
       T.DIAMETER,
       T.THICKNESS,
       T.VARIETIES,
       T.PLINE_CODE,
       (SELECT P.PLINE_NAME
          FROM COM_BASE_PLINE P
         WHERE P.PLINE_CODE = T.PLINE_CODE) pline_Name,
       T.MODEL_DESC,
       T.OPERATION_ID
  FROM MIL_FURNACES_GROUP T
 WHERE 1 = 1
   AND T.ZP_JUDGE_STOVE_NO || '&' LIKE '%' || ? || '%'
   AND T.PLINE_CODE = ?
	
	]]>
	</query>
	
	<query id= "FrmComposeFurnaces.doQueryFurnaceChildRow" desc = "组炉实绩查询（从表）">
	<![CDATA[
	 SELECT 
       T.LOT_NO,
       T.STOVE_NO,
       T.JUDGE_STOVE_NO,
       T.DIAMETER,
       T.THICKNESS,
       T.LENGTH,
       T.PLINE_CODE,
       (SELECT P.PLINE_NAME
          FROM COM_BASE_PLINE P
         WHERE P.PLINE_CODE = T.PLINE_CODE) pline_Name,
       T.GROUP_NUM,
       T.ZP_FLAG,
       T.STATUS,
       TO_CHAR(T.COL_TIME, 'YYYY-MM-DD HH24:MI:SS') COL_TIME,
       T.REMARK,
       T.COL_USER,
       DECODE(T.COL_SHIFT,
              '0',
              '常白班',
              '1',
              '早班',
              '2',
              '中班',
              '3',
              '夜班') COL_SHIFT,
       DECODE(T.COL_GROUP,
              '1',
              '甲班',
              '2',
              '乙班',
              '3',
              '丙班',
              '4',
              '丁班') COL_GROUP,
       T.ZP_HEIGHT,
       T.PRODUCNAME,
       T.STEELCODE,
       T.STEELNAME,
       T.GRADECODE,
       T.GRADENAME,
       T.SPEC_CODE,
       T.SPEC_NAME,
       T.MODEL_CODE,
       T.MODEL_DESC,
       T.STD_CODE,
       T.STD_NAME,
       T.STD_STYLE,
       T.STD_STYLE_DESC,
       T.CONTRACT_NO,
       T.PRODUCCODE,
       T.ACT_LEN_RANGE,
       T.ZP_LOT_NO,
       T.ZP_JUDGE_STOVE_NO,
       T.TARGET
 FROM MIL_FURNACES_RESLUT_DETIA T
 WHERE 1 = 1
   AND T.Zp_Judge_Stove_No || '&' LIKE '%' || ? || '%'
   AND T.PLINE_CODE = ?
	]]>
	</query>
	
	<query id = "FrmComposeFurnaces.updateOrderMain" desc = "修改主炉信息">
	<![CDATA[
	UPDATE MIL_FURNACES_RESLUT T
   SET 
       T.DIAMETER       = '#DIAMETER#',
       T.THICKNESS      = '#THICKNESS#',
       T.LENGTH         = '#LENGTH#',
       T.REMARK         = '#REMARK#',
       T.RECHECK_NUM    = '#RECHECK_NUM#',
       T.PRODUCNAME     = '#PRODUCNAME#',
       T.STEELCODE      = '#STEELCODE#',
       T.STEELNAME      = '#STEELNAME#',
       T.GRADECODE      = '#GRADECODE#',
       T.GRADENAME      = '#GRADENAME#',
       T.SPEC_CODE      = '#SPEC_CODE#',
       T.SPEC_NAME      = '#SPEC_NAME#',
       T.MODEL_CODE     = '#MODEL_CODE#',
       T.MODEL_DESC     = '#MODEL_DESC#',
       T.STD_CODE       = '#STD_CODE#',
       T.STD_NAME       = '#STD_NAME#',
       T.STD_STYLE      = '#STD_STYLE#',
       T.STD_STYLE_DESC = '#STD_STYLE_DESC#',
       T.CONTRACT_NO    = '#CONTRACT_NO#',
       T.PRODUCCODE     = '#PRODUCCODE#',
       T.ACT_LEN_RANGE  = '#ACT_LEN_RANGE#',
       T.TARGET         = '#TARGET#'
 WHERE 1 = 1
   AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND T.LOT_NO = '#LOT_NO#'
	
	]]>
	</query>
	
	<query id= "FrmComposeFurnaces.doQueryZP" desc = "查询该炉号是否是回炉坯或者荒管组炉">
	SELECT COUNT(1) ACOUNT FROM MIL_PLAN T WHERE  T.JUDGE_STOVE_NO = ? AND (T.BACK_SLAB_FLAG = 1 OR T.BACK_PLAN_FLAG = 5)
	</query>
	
	<query id= "FrmComposeFurnaces.updateInputWeigth" desc = "更新进程表投料量">
	<![CDATA[
	DECLARE
  V_MAT_TOTAL_HEIGHT  MIL_FEED_PLAN.MAT_TOTAL_HEIGHT%TYPE := NULL; --组炉的总重量
  V_ZP_JUDGE_STOVE_NO MIL_REFUR_RACK.JUDGE_STOVE_NO%TYPE := ?; --组炉炉号
  V_ZP_LOT_NO         MIL_REFUR_RACK.LOT_NO%TYPE := ?; --组炉生产批号
  V_PLINE_CODE        MIL_REFUR_RACK.PLINE_CODE%TYPE := ?; --产线
  V_ACT_COUNT         PORT_MIL_BATCH_SAMPLE_RESULT.ACT_COUNT%TYPE := NULL;
  V_INPUT_WEIGHT      PORT_MIL_BATCH_SAMPLE_RESULT.INPUT_WEIGHT%TYPE := NULL;
  V_INPUT_WEIGHT1     PORT_MIL_BATCH_SAMPLE_RESULT.INPUT_WEIGHT%TYPE := NULL;
BEGIN
  --组炉的总重量
  select SUM(T.INPUT_WEIGHT)
    INTO V_MAT_TOTAL_HEIGHT
    from PORT_MIL_BATCH_SAMPLE_RESULT t
   WHERE T.STATUS = 1
     AND T.GROUP_FLAG = 1
     AND TRIM(T.OP_PROCESS) = '5'
     AND EXISTS (SELECT 1
            FROM MIL_FURNACES_RESLUT_DETIA M
           WHERE M.JUDGE_STOVE_NO = T.JUDGE_STOVE_NO
             AND M.ZP_JUDGE_STOVE_NO = V_ZP_JUDGE_STOVE_NO);

  --组炉的总支数
  SELECT COUNT(1)
    INTO V_ACT_COUNT
    FROM PORT_MIL_BATCH_SAMPLE_RESULT T
   WHERE T.JUDGE_STOVE_NO = V_ZP_JUDGE_STOVE_NO
     AND T.LOT_NO = V_ZP_LOT_NO
     AND T.PLINE_CODE = V_PLINE_CODE;

  SELECT TRUNC(V_MAT_TOTAL_HEIGHT / V_ACT_COUNT, 3)
    INTO V_INPUT_WEIGHT
    FROM DUAL;

  SELECT V_MAT_TOTAL_HEIGHT - ((V_ACT_COUNT - 1) * V_INPUT_WEIGHT)
    INTO V_INPUT_WEIGHT1
    FROM DUAL;

  UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T
     SET T.INPUT_WEIGHT = V_INPUT_WEIGHT
   WHERE T.JUDGE_STOVE_NO = V_ZP_JUDGE_STOVE_NO
     AND T.LOT_NO = V_ZP_LOT_NO
     AND T.PLINE_CODE = V_PLINE_CODE
     AND T.SEQ <> 1;

  UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T
     SET T.INPUT_WEIGHT = V_INPUT_WEIGHT1
   WHERE T.JUDGE_STOVE_NO = V_ZP_JUDGE_STOVE_NO
     AND T.LOT_NO = V_ZP_LOT_NO
     AND T.PLINE_CODE = V_PLINE_CODE
     AND T.SEQ = 1;
END;
	]]>
	</query>

	
</queryMap>