<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc = "下线管理">
<query id = "FrmDownlineManage.doQueryOffLine" desc = "查询下线数据">
<![CDATA[
SELECT 
		T.CONTRACT_NO,--TZH ADD 工序合同号
		T.RECHECK_NUM,
       T.PRODUCNAME,
       NVL(T.STEELCODE, T1.STEELCODE) STEELCODE,
       T.STEELNAME,
       NVL(T.GRADECODE, T1.GRADECODE) GRADECODE,
       T.GRADENAME,
       NVL(T.SPEC_CODE, T1.PIPE_SIZE_CODE) SPEC_CODE,
       T.SPEC_NAME,
       NVL(T.MODEL_CODE, T1.BUCKLE_TYPE_CODE) MODEL_CODE,
       T.MODEL_DESC,
       NVL(T.STD_CODE, T1.ROLL_STANDRAD_CODE) STD_CODE,
       T.STD_NAME,
       NVL(T.STD_STYLE, T1.STD_STYLE) STD_STYLE,
       T.STD_STYLE_DESC,
       T.ACT_LEN_RANGE,
       T.CONTRACT_NO,
       T1.FINISH_USER,
       NVL(T.PRODUCCODE,T1.VARIETIES_CODE) PRODUCCODE,
       T.INSTORAGE_NUM,
       T.QUALIFIED_NUM,
       T.SCRAP_NUM,
       T.ZP_M_LH,
       T.LOT_NO,
       T.STOVE_NO,
       T.JUDGE_STOVE_NO,
       T.DIAMETER,
       T.THICKNESS,
       T.LENGTH,
       T.PLINE_CODE,
       DECODE(T.OFFLINE_PRO,
              'TS',
              '探伤',
              'ZJ',
              '质检',
              'JZ',
              '矫直',
              'XX',
              '交库') OFFLINE_PRO,
       T.REAL_TIME_STATUS,
       T.OFFLINE_NUM,
       T.BACKLINE_NUM,
       T.GROUP_NUM,
       T.SUBCONTRACT_NUM,
       T.SUBCONTRACTCOMPLETE_NUM,
       T.SUBCONTRACT_NO,
       T.FINAL_NUM,
       DECODE(T.ZP_FLAG, '0', '正常下线', '1', '组炉批') ZP_FLAG,
       T.STATUS,
       T.TYPE_FLAG,
       TO_CHAR(T.OFFLINE_TIME, 'YYYY-MM-DD HH24:MI:SS') OFFLINE_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.OFFLINE_TYPE,
       (TO_NUMBER(NVL(T.OFFLINE_NUM, 0)) - TO_NUMBER(NVL(T.GROUP_NUM, 0)) -
       TO_NUMBER(NVL(T.RECHECK_NUM, 0)) -
       TO_NUMBER(NVL(T.BACKLINE_NUM, 0)) -
       TO_NUMBER(NVL(T.SUBCONTRACT_NUM, 0)) +
       TO_NUMBER(NVL(T.SUBCONTRACTCOMPLETE_NUM, 0))) RESIDUE_NUM,
       (TO_NUMBER(NVL(T.OFFLINE_NUM, 0)) - TO_NUMBER(NVL(T.GROUP_NUM, 0)) -
       TO_NUMBER(NVL(T.RECHECK_NUM, 0)) -
       TO_NUMBER(NVL(T.BACKLINE_NUM, 0)) -
       TO_NUMBER(NVL(T.SUBCONTRACT_NUM, 0)) +
       TO_NUMBER(NVL(T.SUBCONTRACTCOMPLETE_NUM, 0))) GROUP_NUM_COUNT,
       T.TARGET,
       T.SUBCONTRACTCOMPLETE_WGT,
       T.SUBCONTRACT_COMPLETE_CUT,
       T.SUBCONTRACT_COMPLETE_LEN,
       T.SUBCONTRACTSCRAP_NUM,
       T.IMP_PROCESS,
       T.PRO_PLAN_ID,
       T.GX_PLAN_NO,
       T.OFFLINE_DOC
  FROM MIL_OFFLINE_RESLUT T, MIL_PLAN T1
 WHERE T.JUDGE_STOVE_NO = T1.JUDGE_STOVE_NO(+)
   AND T.PRO_PLAN_ID = T1.PRO_PLAN_ID(+)
   AND T.GX_PLAN_NO = T1.GX_PLAN_NO(+)
   AND T.STATUS = '0'
 ]]>
</query>
<query id = "FrmDownlineManage.doQueryFurnace" desc= "查询组炉履历">
<![CDATA[
SELECT 
       VARIETIES,
       PLINE_CODE,
       MODEL_DESC,
       ZP_JUDGE_STOVE_NO,
       ZP_LOT_NO,
       SUM(NVL(ZP_COUNT,0))ZP_COUNT,
       ZP_STANDRAD,
       ZP_STEEL,
       ZP_GRADE,
       ZP_LENGTH,
       SUM(NVL(ZP_HEIGHT,0))ZP_HEIGHT,
       ZP_LENGTH_RANGE,
       ZP_LEVEL,
       ZP_SIZE,
       ZP_M_LH,
       ZP_S_LH,
       ZP_M_PH,
       MAX(TO_CHAR(ZP_TIME, 'YYYY-MM-DD HH24:MI:SS')) ZP_TIME,
       REMARK,
       COL_USER,
       DECODE(COL_SHIFT,'0','常白班','1','早班','2','中班','3','夜班')COL_SHIFT,
       DECODE(COL_GROUP,'1','甲班','2','乙班','3','丙班','4','丁班')COL_GROUP,
       DIAMETER,
       THICKNESS,
       OFFLINE_PRO
 FROM MIL_OFFLINE_GROUP T
 WHERE 1=1
 ]]>
</query>
<query id = "FrmDownlineManage.doQueryFurnaceChildRow" desc = "查询组炉履历子行">
<![CDATA[
SELECT 
       ZP_JUDGE_STOVE_NO,
       ZP_LOT_NO,
       ZP_COUNT,
       TO_CHAR(ZP_TIME, 'YYYY-MM-DD HH24:MI:SS') ZP_TIME,
       REMARK,
       COL_USER,
       DECODE(COL_SHIFT,'0','常白班','1','早班','2','中班','3','夜班')COL_SHIFT,
       DECODE(COL_GROUP,'1','甲班','2','乙班','3','丙班','4','丁班')COL_GROUP,
       OLD_ZP_JUDGE_STOVE_NO,
       OLD_ZP_LOT_NO,
       OLD_ZP_STANDRAD,
       OLD_ZP_STEEL,
       OLD_ZP_GRADE,
       OLD_ZP_LENGTH,
       OLD_ZP_LENGTH_RANGE,
       OLD_DIAMETER,
       OLD_THICKNESS,
       OLD_VARIETIES,
       OPERATION_ID,
       ZP_M_LH,
       ZP_HEIGHT,
       OFFLINE_PRO
 FROM MIL_OFFLINE_GROUP T
 WHERE 1=1
 ]]>
</query>
<query id = "FrmDownlineManage.doQualityInspectionTrust" desc = "查询质检委托实绩">
<![CDATA[
SELECT 
       T.LOT_NO,
       T.JUDGE_STOVE_NO,
       DECODE(T.OPERATION_TYPE,'0','组炉批',1,'探伤返线',2,'复检',3,'交库返线','4','矫直返线')OPERATION_TYPE,
       T.ACT_COUNT,
       T.ACT_WEIGHT,
       TO_CHAR(T.COL_TIME, 'YYYY-MM-DD HH24:MI:SS') COL_TIME,
       T.REMARK,
       T.COL_USER,
       DECODE(COL_SHIFT,'0','常白班','1','早班','2','中班','3','夜班')COL_SHIFT,
       DECODE(COL_GROUP,'1','甲班','2','乙班','3','丙班','4','丁班')COL_GROUP,
       T.OPERATION_ID,
       T.PLINE_CODE,
       T.ID,
       T.OFFLINE_TYPE,
       T.BACK_JUDGE_STOVE_NO
 FROM MIL_OFFLINE_RESULT_DETIA T
 WHERE  T.OPERATION_TYPE IN('1','2','3','4','5')
 ]]>
</query>
<query id = "doFurnace.insertGroup" desc = "组炉插入">
DECLARE
  V_TIME         MIL_OFFLINE_RESLUT.OFFLINE_TIME%TYPE := SYSDATE;
  V_OPERATION_ID MIL_OFFLINE_RESULT_DETIA.OPERATION_ID%TYPE := NULL;
  V_OFFLINE_NUM  MIL_OFFLINE_RESLUT.OFFLINE_NUM%TYPE := NULL;
  V_TOTALCOUNT   MIL_OFFLINE_RESLUT.OFFLINE_NUM%TYPE := NULL;
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_OFFLINE_RESULT_DETIA T
   WHERE TO_CHAR(T.COL_TIME, 'YYYY-MM-DD') = TO_CHAR(SYSDATE, 'YYYY-MM-DD');
  FOR MYROW IN (SELECT T.*,
                       NVL(T.PRO_PLAN_ID, T1.PRO_PLAN_ID) PRO_PLAN_ID2,
                       NVL(T.GX_PLAN_NO, T1.GX_PLAN_NO) GX_PLAN_NO2
                  FROM MIL_OFFLINE_RESLUT T, MIL_PLAN T1
                 WHERE T.JUDGE_STOVE_NO = T1.JUDGE_STOVE_NO
                   AND T.PLINE_CODE = T1.PLINE_CODE
                   AND T.JUDGE_STOVE_NO = ?
                   AND T.LOT_NO = ?
                   AND T.PLINE_CODE = ?
                   AND T.OFFLINE_TYPE = ?
                   AND T.OFFLINE_PRO = ?) LOOP
    INSERT INTO MIL_OFFLINE_GROUP
      (VARIETIES,
       PLINE_CODE,
       ZP_JUDGE_STOVE_NO,
       ZP_LOT_NO,
       ZP_COUNT,
       ZP_STANDRAD,
       ZP_STEEL,
       ZP_GRADE,
       ZP_LENGTH,
       ZP_LENGTH_RANGE,
       ZP_LEVEL,
       
       ZP_SIZE,
       ZP_M_LH,
       ZP_S_LH,
       ZP_M_PH,
       ZP_TIME,
       REMARK,
       COL_USER,
       COL_GROUP,
       COL_SHIFT,
       OLD_ZP_JUDGE_STOVE_NO,
       OLD_ZP_LOT_NO,
       OLD_ZP_STANDRAD,
       OLD_ZP_STEEL,
       OLD_ZP_GRADE,
       OLD_ZP_LENGTH,
       OLD_ZP_LENGTH_RANGE,
       DIAMETER,
       THICKNESS,
       OLD_DIAMETER,
       OLD_THICKNESS,
       OLD_VARIETIES,
       ZP_HEIGHT,
       OPERATION_ID,
       OFFLINE_PRO,
       PRO_PLAN_ID,
       GX_PLAN_NO)
    VALUES
      (?,
       MYROW.PLINE_CODE,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       '',
       ?,
       ?,
       '',
       '',
       TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
       '',
       ?,
       ?,
       ?,
       MYROW.JUDGE_STOVE_NO,
       MYROW.LOT_NO,
       MYROW.STD_NAME,
       MYROW.STEELNAME,
       MYROW.GRADENAME,
       MYROW.LENGTH,
       MYROW.ACT_LEN_RANGE,
       ?,
       ?,
       MYROW.DIAMETER,
       MYROW.THICKNESS,
       MYROW.PRODUCNAME,
       ?,
       V_OPERATION_ID,
       MYROW.OFFLINE_PRO,
       MYROW.PRO_PLAN_ID2,
       MYROW.GX_PLAN_NO2);
    UPDATE MIL_OFFLINE_RESLUT T
       SET T.GROUP_NUM = TO_NUMBER(T.GROUP_NUM) + TO_NUMBER(?)
     WHERE T.JUDGE_STOVE_NO = ?
       AND T.LOT_NO = ?
       AND T.PLINE_CODE = ?
       AND T.OFFLINE_TYPE = ?
       AND T.OFFLINE_PRO = ?;
    INSERT INTO MIL_OFFLINE_RESULT_DETIA
      (LOT_NO,
       JUDGE_STOVE_NO,
       OPERATION_TYPE,
       ACT_COUNT,
       ACT_WEIGHT,
       COL_TIME,
       REMARK,
       COL_USER,
       COL_GROUP,
       COL_SHIFT,
       OPERATION_ID,
       PLINE_CODE,
       PRO_PLAN_ID,
       GX_PLAN_NO)
    VALUES
      (MYROW.LOT_NO,
       MYROW.JUDGE_STOVE_NO,
       '0',
       ?,
       ?,
       TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
       '',
       ?,
       ?,
       ?,
       V_OPERATION_ID,
       MYROW.PLINE_CODE,
       MYROW.PRO_PLAN_ID2,
       MYROW.GX_PLAN_NO2);
    SELECT T.OFFLINE_NUM,
           (TO_NUMBER(T.GROUP_NUM) + TO_NUMBER(T.BACKLINE_NUM) +
           TO_NUMBER(T.RECHECK_NUM) + TO_NUMBER(T.INSTORAGE_NUM))
      INTO V_OFFLINE_NUM, V_TOTALCOUNT
      FROM MIL_OFFLINE_RESLUT T
     WHERE T.JUDGE_STOVE_NO = ?
       AND T.LOT_NO = ?
       AND T.PLINE_CODE = ?
       AND T.OFFLINE_TYPE = ?
       AND T.OFFLINE_PRO = ?;
    IF (V_OFFLINE_NUM = V_TOTALCOUNT) THEN
      UPDATE MIL_OFFLINE_RESLUT T
         SET T.STATUS = '1'
       WHERE T.JUDGE_STOVE_NO = ?
         AND T.LOT_NO = ?
         AND T.PLINE_CODE = ?
         AND T.OFFLINE_TYPE = ?;
    END IF;
  END LOOP;
END;
</query>
<query id = "doFurnace.insertOffline" desc = "插入下线表">
<![CDATA[
DECLARE
  V_TIME           MIL_OFFLINE_RESLUT.OFFLINE_TIME%TYPE := SYSDATE;
  V_JUDGE_STOVE_NO MIL_OFFLINE_RESLUT.JUDGE_STOVE_NO%TYPE := ?;
  V_LOT_NO         MIL_OFFLINE_RESLUT.LOT_NO%TYPE := ?;
  V_PLINE_CODE     MIL_OFFLINE_RESLUT.PLINE_CODE%TYPE := ?;
  V_OFFLINE_PRO    MIL_OFFLINE_RESLUT.OFFLINE_PRO%TYPE := ?;
  V_OFFLINE_TYPE   MIL_OFFLINE_RESLUT.OFFLINE_TYPE%TYPE := ?;
BEGIN
  FOR MYROW IN (SELECT T.*,
                       NVL(T.PRO_PLAN_ID, T1.PRO_PLAN_ID) PRO_PLAN_ID2,
                       NVL(T.GX_PLAN_NO, T1.GX_PLAN_NO) GX_PLAN_NO2
                  FROM MIL_OFFLINE_RESLUT T, MIL_PLAN T1
                 WHERE T.JUDGE_STOVE_NO = T1.JUDGE_STOVE_NO
                   AND T.PLINE_CODE = T1.PLINE_CODE
                   AND T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
                   AND T.LOT_NO = V_LOT_NO
                   AND T.PLINE_CODE = V_PLINE_CODE
                   AND T.OFFLINE_PRO = V_OFFLINE_PRO
                   AND T.OFFLINE_TYPE = V_OFFLINE_TYPE) LOOP
    INSERT INTO MIL_OFFLINE_RESLUT
      (RECHECK_NUM,
       PRODUCNAME,
       STEELCODE,
       STEELNAME,
       GRADECODE,
       GRADENAME,
       SPEC_CODE,
       SPEC_NAME,
       MODEL_CODE,
       MODEL_DESC,
       STD_CODE,
       STD_NAME,
       STD_STYLE,
       STD_STYLE_DESC,
       ACT_LEN_RANGE,
       CONTRACT_NO,
       PRODUCCODE,
       INSTORAGE_NUM,
       QUALIFIED_NUM,
       SCRAP_NUM,
       ZP_M_LH,
       LOT_NO,
       STOVE_NO,
       JUDGE_STOVE_NO,
       DIAMETER,
       THICKNESS,
       LENGTH,
       PLINE_CODE,
       OFFLINE_PRO,
       REAL_TIME_STATUS,
       OFFLINE_NUM,
       BACKLINE_NUM,
       GROUP_NUM,
       FINAL_NUM,
       ZP_FLAG,
       STATUS,
       TYPE_FLAG,
       OFFLINE_TIME,
       REMARK,
       COL_USER,
       COL_GROUP,
       COL_SHIFT,
       OFFLINE_TYPE,
       ZP_HEIGHT,
       TARGET,
       IMP_PROCESS,
       PRO_PLAN_ID,
       GX_PLAN_NO,
       OFFLINE_DOC)
    VALUES
      ('0',
       myrow.producname,
       myrow.steelcode,
       myrow.steelname,
       myrow.gradecode,
       myrow.gradename,
       myrow.spec_code,
       myrow.spec_name,
       myrow.model_code,
       myrow.model_desc,
       myrow.std_code,
       myrow.std_name,
       myrow.std_style,
       myrow.std_style_desc,
       myrow.ACT_LEN_RANGE,
       myrow.contract_no,
       myrow.produccode,
       '0',
       '0',
       '0',
       myrow.judge_stove_no,
       ?,
       '',
       ?,
       myrow.diameter,
       myrow.thickness,
       myrow.length,
       myrow.pline_code,
       myrow.offline_pro,
       myrow.REAL_TIME_STATUS,
       ?,
       '0',
       '0',
       '0',
       '1',
       '0',
       '0',
       TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
       '',
       ?,
       ?,
       ?,
       ?,
       ?,
       myrow.TARGET,
       myrow.IMP_PROCESS,
       myrow.PRO_PLAN_ID2,
       myrow.GX_PLAN_NO2,
       myrow.Offline_Doc);
  
  END LOOP;

  FOR MYROW2 IN (select t.*
                   from MIL_OFFLINE_GROUP t
                  WHERE T.ZP_JUDGE_STOVE_NO = ?) LOOP
    UPDATE MIL_TAKE_RESLUT T
       SET T.TAKE_NUM_BACK = T.TAKE_NUM
     WHERE T.JUDGE_STOVE_NO = MYROW2.OLD_ZP_JUDGE_STOVE_NO;
     
     UPDATE PLN_ZY_ZG_M T
       SET T.PLANSTATUS = '30'
     WHERE T.FEED_HEAT_NO = REGEXP_REPLACE(MYROW2.OLD_ZP_JUDGE_STOVE_NO, '-.*', '')
       AND T.PLINE_CODE = MYROW2.PLINE_CODE;
  END LOOP;
END;
]]>
</query>

<query id = "doFurnace.deleteMat" desc = "删除库存信息">
DECLARE
BEGIN
  FOR MYROW IN (SELECT MAT_NO
                  FROM MAT_BC_M T
                 WHERE T.JUDGE_STOVE_NO = ?
                   AND T.BATCH_NO = 'X'
                   AND T.PRODUCT_FLAG = '801401'
                   AND T.MAT_STATUS = '80150104' ORDER BY MAT_NO DESC) LOOP
  DELETE FROM YDM_BC_BUTTRESS WHERE MAT_NO = MYROW.MAT_NO;
  DELETE FROM YDM_BC_INLIST WHERE MAT_NO = MYROW.MAT_NO;
  END LOOP;
  DELETE FROM MAT_BC_M T
   WHERE T.JUDGE_STOVE_NO = ?
     AND T.BATCH_NO = 'X'
     AND T.PRODUCT_FLAG = '801401'
     AND T.MAT_STATUS = '80150104';
END;
</query>
<query id = "doCancelFurnace.doQueryOfflineResult" desc = "查询炉信息是否发生改变">
<![CDATA[
SELECT COUNT(1) ACOUNT
  FROM MIL_OFFLINE_RESLUT T
 WHERE T.LOT_NO = ?
   AND T.JUDGE_STOVE_NO = ?
   AND T.STATUS = '1'
   ]]>
</query>
<query id = "FrmDownlineManage.doCancelFurnace" desc = "撤销组炉批">
<![CDATA[
DECLARE
  V_TIME MIL_OFFLINE_RESLUT.OFFLINE_TIME%TYPE := SYSDATE;
BEGIN
  FOR MYROW IN (SELECT *
                  FROM (SELECT *
                          FROM PORT_MIL_BATCH_SAMPLE_RESULT T
                         WHERE T.JUDGE_STOVE_NO = ?
                           AND T.GROUP_FLAG = '1'
                         ORDER BY T.MAT_NO DESC)
                 WHERE ROWNUM <= ?) LOOP
    UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T
       SET T.GROUP_FLAG = '0'
     WHERE T.MAT_NO = MYROW.MAT_NO
       AND T.JUDGE_STOVE_NO = ?;
  END LOOP;
  
  DELETE FROM MIL_OFFLINE_RESLUT T
   WHERE T.JUDGE_STOVE_NO = ?
     AND T.LOT_NO = ?;
  DELETE FROM MIL_OFFLINE_GROUP T WHERE T.OPERATION_ID = ?;
  DELETE FROM MIL_OFFLINE_RESULT_DETIA T WHERE T.OPERATION_ID = ?;
  UPDATE MIL_OFFLINE_RESLUT T
     SET T.GROUP_NUM = TO_NUMBER(T.GROUP_NUM) - TO_NUMBER(?),
         T.STATUS    = '0'
   WHERE T.JUDGE_STOVE_NO = ?
     AND T.LOT_NO = ?
     AND NVL(T.OFFLINE_PRO, '/') = NVL(?, '/');

  UPDATE MIL_TAKE_RESLUT T
     SET T.TAKE_NUM_BACK = TO_NUMBER(T.TAKE_NUM_BACK) - TO_NUMBER(?)
   WHERE T.JUDGE_STOVE_NO = ?
     AND T.LOT_NO = ?
     AND NVL(T.OFFLINE_PRO, '/') = NVL(?, '/');
END;

]]>
</query>
<query id = "doFurnace.doQueryMilPlan" desc= "查询是否已结炉">
<![CDATA[
SELECT COUNT(1) ACOUNT
  FROM MIL_PLAN T
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.LOT_NO = ?
   AND T.NODE_STATUS >= ?
   --AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
   --AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
]]>
</query>
<query id= "doFurnace.doQueryMilPlanJugeNo" desc = "查询是否已存在该炉号">
SELECT COUNT(1) ACOUNT
  FROM MIL_PLAN T
 WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') =
       REGEXP_REPLACE(?, '-.*', '')
</query>

<query id= "doFurnace.doQueryMilOfflineGroup" desc = "查询是否已存在该炉号">
SELECT COUNT(1) ACOUNT
    FROM MIL_OFFLINE_GROUP T
 WHERE REGEXP_REPLACE(T.ZP_JUDGE_STOVE_NO, '-.*', '') = REGEXP_REPLACE(?, '-.*', '')
</query>

<query id = "FrmDownlineManage.qualityInspectionTrust" desc = "生成质检委托">
DECLARE
  V_TIME           MIL_OFFLINE_RESLUT.OFFLINE_TIME%TYPE := SYSDATE;
  V_JUDGE_STOVE_NO MIL_PLAN.JUDGE_STOVE_NO%TYPE := NULL;
  V_ID             MIL_PLAN.ID%TYPE := NULL;
  V_OPERATION_ID   MIL_OFFLINE_RESULT_DETIA.OPERATION_ID%TYPE := NULL;
  V_OFFLINE_NUM    MIL_OFFLINE_RESLUT.OFFLINE_NUM%TYPE :=NULL;
  V_TOTAL_COUNT    MIL_OFFLINE_RESLUT.OFFLINE_NUM%TYPE :=NULL;
BEGIN
  --生成新炉号
  SELECT REGEXP_REPLACE(?, '-.*', '') || '-' ||
         LPAD(NVL(MAX(SUBSTR(T.JUDGE_STOVE_NO, -2)), 0) + 1, 2, 0) JUDGE_STOVE_NO
    INTO V_JUDGE_STOVE_NO
    FROM MIL_PLAN T
   WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = REGEXP_REPLACE(?, '-.*', '')
     AND T.PLINE_CODE = ?;
  --生成主键
  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 = ?
   AND INSTR(T.ID, '-') = 0
     --AND REGEXP_REPLACE(T.ID,'^[-\+]?\D+(\.\D+)?$','') IS NULL
     AND TO_CHAR(T.TOM, 'YYYY-MM-DD') = TO_CHAR(SYSDATE, 'YYYY-MM-DD');
   --生成操作ID
     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_OFFLINE_RESULT_DETIA T
   WHERE T.PLINE_CODE = ?
     AND TO_CHAR(T.COL_TIME, 'YYYY-MM-DD') =
         TO_CHAR(SYSDATE, 'YYYY-MM-DD');
  FOR MYROW IN (SELECT *
                  FROM MIL_PLAN T
                 WHERE T.JUDGE_STOVE_NO = ?
                   AND T.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)
    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,
       TO_DATE(?,'YYYY-MM-DD HH24:MI:SS'),
       TO_DATE(?,'YYYY-MM-DD HH24:MI:SS'),
       TO_DATE(?,'YYYY-MM-DD HH24:MI:SS'),
       '',
       '90',
       MYROW.CUT_HEAD_LENGTHP,
       MYROW.CUT_TRAIL_LENGTHP,
       MYROW.CONTROL_THICKP,
       '2',
       '0',
       '',
       MYROW.CUT_TYPE,
       '0',
       MYROW.PRODUCE_STANDRAD,
       MYROW.SIMPLE_PROCESS,
       '1',
       '9',
       MYROW.FEED_TIME,
       V_ID,
       MYROW.SEQ,
       MYROW.STOVE_NO,
       V_JUDGE_STOVE_NO,
       ?,
       MYROW.CONTRACT_NO,
       MYROW.IMP_PROCESS,
       MYROW.PLINE_CODE,
       '95',
       MYROW.PRODUCER,
       MYROW.PROCESS_STATUS,
       MYROW.DB_LENGTH,
       MYROW.DB_HEIGHT,
       MYROW.ROLL_LENGTH,
       MYROW.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);
       INSERT INTO MIL_OFFLINE_RESULT_DETIA(
        LOT_NO,
        JUDGE_STOVE_NO,
        OPERATION_TYPE,
        ACT_COUNT,
        ACT_WEIGHT,
        COL_TIME,
        REMARK,
        COL_USER,
        COL_GROUP，
        COL_SHIFT,
        OPERATION_ID,
        PLINE_CODE,
        ID,
        OFFLINE_TYPE)
 VALUES( 
        ?,
        ?,
        '2',
        ?,
        ?,
        TO_DATE(?,'YYYY-MM-DD HH24:MI:SS'),
        '',
        ?,
        ?,
        ?,
        V_OPERATION_ID,
        MYROW.PLINE_CODE,
        V_ID,
        ?);
  END LOOP;
  UPDATE MIL_OFFLINE_RESLUT T SET T.RECHECK_NUM = TO_NUMBER(T.RECHECK_NUM) + TO_NUMBER(?) WHERE T.JUDGE_STOVE_NO = ? AND T.LOT_NO = ? AND T.PLINE_CODE = ? AND T.OFFLINE_PRO = ? AND T.OFFLINE_TYPE = ?;
  SELECT T.OFFLINE_NUM,
               (T.GROUP_NUM + T.BACKLINE_NUM + T.RECHECK_NUM) INTO V_OFFLINE_NUM,V_TOTAL_COUNT
          FROM MIL_OFFLINE_RESLUT T
         WHERE T.JUDGE_STOVE_NO = ?
           AND T.LOT_NO = ?
           AND T.PLINE_CODE = ?
           AND T.OFFLINE_PRO = ?
           AND T.OFFLINE_TYPE = ?;
           IF(V_OFFLINE_NUM = V_TOTAL_COUNT)THEN
           UPDATE MIL_OFFLINE_RESLUT T SET T.STATUS = '1' WHERE T.JUDGE_STOVE_NO = ? AND T.LOT_NO = ? AND T.PLINE_CODE = ? AND T.OFFLINE_PRO = ? AND T.OFFLINE_TYPE = ?;
           END IF;
END;
</query>

<query id = "FrmDownlineManage.insertRack" desc = "插入管号队列(质检返质检)">
<![CDATA[
DECLARE
  V_ID             MIL_PLAN.ID%TYPE := NULL;
  V_JUDGE_STOVE_NO MIL_PLAN.JUDGE_STOVE_NO%TYPE := NULL;
  V_SEQ            MIL_QA_RACK.SEQ%TYPE := NULL;
  V_PRO_PLAN_ID    MIL_PLAN.PRO_PLAN_ID%TYPE := ?;
  V_GX_PLAN_NO     MIL_PLAN.GX_PLAN_NO%TYPE := ?;
BEGIN
  --生成新炉号
  SELECT REGEXP_REPLACE(?, '-.*', '') || '-' ||
         LPAD(NVL(MAX(SUBSTR(T.JUDGE_STOVE_NO, -2)), 0) + 1, 2, 0) JUDGE_STOVE_NO
    INTO V_JUDGE_STOVE_NO
    FROM MIL_PLAN T
   WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') =
         REGEXP_REPLACE(?, '-.*', '')
        /*AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
        AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')*/
     AND T.PLINE_CODE = ?;
  --生成主键
  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 = ?
     AND INSTR(T.ID, '-') = 0
        --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 MIL_QA_RACK T
   WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
        /*AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
        AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')*/
     AND T.PLINE_CODE = ?;
  FOR MYROW IN (SELECT *
                  FROM (SELECT T.*
                          FROM PORT_MIL_BATCH_SAMPLE_RESULT T
                         WHERE T.JUDGE_STOVE_NO = ?
                              /*AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
                              AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')*/
                           AND T.LOT_NO = ?
                           AND T.PLINE_CODE = ?
                           AND T.Status = '3'
                           AND T.Op_Process = '11'
                           AND T.GROUP_FLAG = ?
                         ORDER BY T.SEQ ASC)
                 WHERE ROWNUM <= ?) LOOP
    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,
       PRO_PLAN_ID,
       GX_PLAN_NO)
    VALUES
      (MYROW.MAT_NO,
       ?,
       V_JUDGE_STOVE_NO,
       ?,
       '',
       '',
       '1',
       TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
       V_SEQ,
       MYROW.Plan_Id,
       MYROW.Order_Length,
       V_PRO_PLAN_ID,
       V_GX_PLAN_NO);
    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,
       SAMPLE_PIPE_LEN,
       GET_SAMPLE_NAME,
       GET_SAMPLE_TIME,
       GET_SAMPLE_SHIFT,
       GET_SAMPLE_CLASS,
       ORDER_LENGTH,
       ACT_THEORY_WEIGHT,
       ACT_COUNT,
       CRATE_TIME,
       M_MAT_NO,
       M_M_MAT_NO,
       INPUT_WEIGHT,
       STATUS,
       BACK_PROCESS,
       BAL_YEAR_MONTH,
       PRO_PLAN_ID,
       GX_PLAN_NO,
       MEASURE_LEN,
       MEASURE_WEIGHT,
       MEASURING_SEQ,
       MAT_INFO,
       MEASURING_FLAG,
       MEASURE_RESULT_NO,
       ACT_THEORY_WEIGHT_BAK)
    VALUES
      (MYROW.PLAN_ID,
       ?,
       ?,
       V_JUDGE_STOVE_NO,
       MYROW.PLINE_CODE,
       MYROW.BATCH_NO,
       V_SEQ,
       MYROW.MAT_NO,
       MYROW.IS_SAMPLE_PIPE,
       MYROW.SAMPLE_PIPE_LEN,
       MYROW.GET_SAMPLE_NAME,
       MYROW.GET_SAMPLE_TIME,
       MYROW.GET_SAMPLE_SHIFT,
       MYROW.GET_SAMPLE_CLASS,
       MYROW.ORDER_LENGTH,
       MYROW.ACT_THEORY_WEIGHT,
       MYROW.ACT_COUNT,
       SYSDATE,
       MYROW.M_MAT_NO,
       MYROW.M_M_MAT_NO,
       MYROW.INPUT_WEIGHT,
       '0',
       '',
       MYROW.BAL_YEAR_MONTH,
       V_PRO_PLAN_ID,
       V_GX_PLAN_NO,
       MYROW.MEASURE_LEN,
       MYROW.MEASURE_WEIGHT,
       MYROW.MEASURING_SEQ,
       MYROW.MAT_INFO,
       MYROW.MEASURING_FLAG,
       MYROW.MEASURE_RESULT_NO,
       MYROW.ACT_THEORY_WEIGHT_BAK);
    UPDATE MIL_TESTING_RACK T
       SET T.OFFLINE_FLAG = '2'
     WHERE T.JUDGE_STOVE_NO = ?
       AND T.LOT_NO = ?
       AND T.PLINE_CODE = ?
       AND T.MAT_NO = MYROW.MAT_NO;
    UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T
       SET T.STATUS = '4', T.BACK_PROCESS = '11'
     WHERE T.JUDGE_STOVE_NO = ?
       AND T.MAT_NO = MYROW.MAT_NO;
    V_SEQ := V_SEQ + 1;
  END LOOP;
END;

]]>
</query>

<query id = "FrmDownlineManage.insertRack1" desc = "插入管号队列(探伤返质检)">
<![CDATA[
DECLARE
  V_ID             MIL_PLAN.ID%TYPE := NULL;
  V_JUDGE_STOVE_NO MIL_PLAN.JUDGE_STOVE_NO%TYPE := NULL;
  V_SEQ            MIL_QA_RACK.SEQ%TYPE := NULL;
BEGIN
  --生成新炉号
  SELECT REGEXP_REPLACE(?, '-.*', '') || '-' ||
         LPAD(NVL(MAX(SUBSTR(T.JUDGE_STOVE_NO, -2)), 0) + 1, 2, 0) JUDGE_STOVE_NO
    INTO V_JUDGE_STOVE_NO
    FROM MIL_PLAN T
   WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') =
         REGEXP_REPLACE(?, '-.*', '')
     AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
     AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
     AND T.PLINE_CODE = ?;
  --生成主键
  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 = ?
     AND INSTR(T.ID, '-') = 0
        --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 MIL_QA_RACK T
   WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
     AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
     AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
     AND T.PLINE_CODE = ?;
  FOR MYROW IN (SELECT *
                  FROM (SELECT T.*
                          FROM PORT_MIL_BATCH_SAMPLE_RESULT T
                         WHERE T.JUDGE_STOVE_NO = ?
                           AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
                           AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
                           AND T.LOT_NO = ?
                           AND T.PLINE_CODE = ?
                           AND T.Status = '3'
                           AND T.Op_Process = '10'
                           AND T.GROUP_FLAG = ?
                         ORDER BY T.SEQ ASC)
                 WHERE ROWNUM <= ?) LOOP
    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,
       PRO_PLAN_ID,
       GX_PLAN_NO)
    VALUES
      (MYROW.MAT_NO,
       ?,
       V_JUDGE_STOVE_NO,
       ?,
       '',
       '',
       '1',
       TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
       V_SEQ,
       MYROW.Plan_Id,
       MYROW.Order_Length,
       ?,
       ?);
    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,
       SAMPLE_PIPE_LEN,
       GET_SAMPLE_NAME,
       GET_SAMPLE_TIME,
       GET_SAMPLE_SHIFT,
       GET_SAMPLE_CLASS,
       ORDER_LENGTH,
       ACT_THEORY_WEIGHT,
       ACT_COUNT,
       CRATE_TIME,
       M_MAT_NO,
       M_M_MAT_NO,
       INPUT_WEIGHT,
       STATUS,
       BACK_PROCESS,
       BAL_YEAR_MONTH,
       PRO_PLAN_ID,
       GX_PLAN_NO,
       MEASURE_LEN,
       MEASURE_WEIGHT,
       MEASURING_SEQ,
       MAT_INFO,
       MEASURING_FLAG,
       MEASURE_RESULT_NO,
       ACT_THEORY_WEIGHT_BAK)
    VALUES
      (MYROW.PLAN_ID,
       ?,
       ?,
       V_JUDGE_STOVE_NO,
       MYROW.PLINE_CODE,
       MYROW.BATCH_NO,
       V_SEQ,
       MYROW.MAT_NO,
       MYROW.IS_SAMPLE_PIPE,
       MYROW.SAMPLE_PIPE_LEN,
       MYROW.GET_SAMPLE_NAME,
       MYROW.GET_SAMPLE_TIME,
       MYROW.GET_SAMPLE_SHIFT,
       MYROW.GET_SAMPLE_CLASS,
       MYROW.ORDER_LENGTH,
       MYROW.ACT_THEORY_WEIGHT,
       MYROW.ACT_COUNT,
       SYSDATE,
       MYROW.M_MAT_NO,
       MYROW.M_M_MAT_NO,
       MYROW.INPUT_WEIGHT,
       '0',
       '',
       MYROW.BAL_YEAR_MONTH,
       ?,
       ?,
       MYROW.MEASURE_LEN,
       MYROW.MEASURE_WEIGHT,
       MYROW.MEASURING_SEQ,
       MYROW.MAT_INFO,
       MYROW.MEASURING_FLAG,
       MYROW.MEASURE_RESULT_NO,
       MYROW.ACT_THEORY_WEIGHT_BAK);
    UPDATE MIL_TESTING_RACK T
       SET T.OFFLINE_FLAG = '2'
     WHERE T.JUDGE_STOVE_NO = ?
       AND T.LOT_NO = ?
       AND T.PLINE_CODE = ?
       AND T.MAT_NO = MYROW.MAT_NO;
    UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T
       SET T.STATUS = '4', T.BACK_PROCESS = '11'
     WHERE T.JUDGE_STOVE_NO = ?
       AND T.MAT_NO = MYROW.MAT_NO;
    V_SEQ := V_SEQ + 1;
  END LOOP;
END;

]]>
</query>

<query id = "qualityInspectionTrust.doQueryJugeNo" desc = "查询组炉原炉号">
SELECT T.OLD_ZP_JUDGE_STOVE_NO,
       T.OLD_ZP_LOT_NO,
       T.ZP_COUNT,
       T.PRO_PLAN_ID,
       T.GX_PLAN_NO
  FROM MIL_OFFLINE_GROUP T
 WHERE T.ZP_JUDGE_STOVE_NO = ?
   AND T.PLINE_CODE = ?
</query>
<query id = "cancelQualityInspectionTrust.doQueryResult" desc = "查询是否已生成质检实绩">
SELECT COUNT(1)ACOUNT FROM MIL_SURFACE_RESULT T WHERE T.RESULT_NO = ? AND T.JUDGE_STOVE_NO = ?
</query>
<query id = "cancelQualityInspectionTrust.doQueryBackLineResult" desc = "查询是否已生产探伤实绩">
SELECT NVL(SUM(QUALIFIED_NUM),0)ACOUNT FROM (
SELECT NVL(COUNT(1),0)QUALIFIED_NUM FROM MIL_MT_RESULT T WHERE T.RESULT_NO = ? AND T.JUDGE_STOVE_NO = ?
UNION ALL 
SELECT NVL(COUNT(1),0)QUALIFIED_NUM FROM MIL_ET_RESULT T WHERE T.RESULT_NO = ? AND T.JUDGE_STOVE_NO = ?
UNION ALL
SELECT NVL(COUNT(1),0)QUALIFIED_NUM FROM MIL_UL_RESUL T WHERE T.RESULT_NO = ? AND T.JUDGE_STOVE_NO = ?
)
</query>
<query id = "cancelQualityInspectionTrust.doQueryBackStaLineResult" desc = "查询是否已生成矫直实绩">
SELECT NVL(COUNT(1),0)ACOUNT FROM MIL_STRAIGHTENING_RESULT T WHERE T.RESULT_NO = ? AND T.JUDGE_STOVE_NO = ?
</query>
<query id = "FrmDownlineManage.cancelQualityInspectionTrust" desc = "撤销质检委托">
<![CDATA[
DECLARE
  V_ZP_FLAG MIL_OFFLINE_RESLUT.ZP_FLAG%TYPE := NULL;
BEGIN
  DELETE FROM MIL_PLAN T WHERE T.ID = ? AND T.JUDGE_STOVE_NO = ?;
  SELECT T.ZP_FLAG
    INTO V_ZP_FLAG
    FROM MIL_OFFLINE_RESLUT T
   WHERE T.JUDGE_STOVE_NO = ?
     AND T.OFFLINE_PRO = 'ZJ'
     AND T.ZP_FLAG = '0';
  IF (V_ZP_FLAG = 1) THEN
    FOR MYROWJUGENO IN (SELECT T.OLD_ZP_JUDGE_STOVE_NO,
                               T.PLINE_CODE,
                               T.ZP_COUNT
                          FROM MIL_OFFLINE_GROUP T
                         WHERE T.ZP_JUDGE_STOVE_NO = ?) LOOP
      FOR MYROW IN (SELECT *
                      FROM (SELECT T.SEQ,T.MAT_NO
                              FROM PORT_MIL_BATCH_SAMPLE_RESULT T
                             WHERE T.JUDGE_STOVE_NO =
                                   MYROWJUGENO.OLD_ZP_JUDGE_STOVE_NO
                               AND T.STATUS = '4'
                               AND T.GROUP_FLAG = '1')
                     WHERE ROWNUM <= MYROWJUGENO.ZP_COUNT) LOOP
        UPDATE MIL_QA_RACK T
           SET T.OFFLINE_FLAG = '1'
         WHERE T.JUDGE_STOVE_NO = MYROWJUGENO.OLD_ZP_JUDGE_STOVE_NO
           AND T.MAT_NO = MYROW.MAT_NO;
           UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T SET T.STATUS = '3',T.BACK_PROCESS = '' WHERE T.JUDGE_STOVE_NO = MYROWJUGENO.OLD_ZP_JUDGE_STOVE_NO AND T.MAT_NO = MYROW.MAT_NO;
      END LOOP;
    END LOOP;
  ELSE
    FOR MYROW IN (SELECT *
                    FROM (SELECT T.SEQ,T.JUDGE_STOVE_NO,T.MAT_NO
                            FROM PORT_MIL_BATCH_SAMPLE_RESULT T
                           WHERE T.JUDGE_STOVE_NO = ?
                             AND T.STATUS = '4')
                   WHERE ROWNUM <= ?) LOOP
      UPDATE MIL_QA_RACK T
         SET T.OFFLINE_FLAG = '1'
       WHERE T.JUDGE_STOVE_NO = ?
         AND T.MAT_NO = MYROW.MAT_NO;
         UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T SET T.STATUS = '3',T.BACK_PROCESS = '' WHERE T.JUDGE_STOVE_NO = MYROW.JUDGE_STOVE_NO AND T.MAT_NO = MYROW.MAT_NO;
    END LOOP;
  END IF;

  DELETE FROM MIL_OFFLINE_RESULT_DETIA T WHERE T.OPERATION_ID = ? AND T.BACK_JUDGE_STOVE_NO = ?;
  DELETE FROM MIL_QA_RACK T WHERE T.RESULT_NO = ? AND T.JUDGE_STOVE_NO = ?;
  UPDATE MIL_OFFLINE_RESLUT T
     SET T.STATUS      = '0',
         T.RECHECK_NUM = TO_NUMBER(T.RECHECK_NUM) - TO_NUMBER(?)
   WHERE T.JUDGE_STOVE_NO = ?
     AND T.LOT_NO = ?
     AND T.PLINE_CODE = ?
     AND T.OFFLINE_PRO = ?;
  DELETE FROM PORT_MIL_BATCH_SAMPLE_RESULT T WHERE T.PLAN_ID = ? AND T.JUDGE_STOVE_NO = ?;
END;
]]>
</query>
<!-- 
DECLARE
BEGIN
  DELETE FROM MIL_PLAN T WHERE T.ID = ?;
  FOR MYROW IN (SELECT *
                  FROM (SELECT T.SEQ
                          FROM MIL_QA_RACK T
                         WHERE T.JUDGE_STOVE_NO = ?
                           AND T.OFFLINE_FLAG = '2')
                 WHERE ROWNUM <= ?) LOOP
                 UPDATE MIL_QA_RACK T
     SET T.OFFLINE_FLAG = '1'
   WHERE T.JUDGE_STOVE_NO = ?
     AND T.SEQ = MYROW.SEQ;
  END LOOP;
  DELETE FROM MIL_OFFLINE_RESULT_DETIA T WHERE T.OPERATION_ID = ?;
  DELETE FROM MIL_QA_RACK T WHERE T.RESULT_NO = ?;
  UPDATE MIL_OFFLINE_RESLUT T
     SET T.STATUS      = '0',
         T.RECHECK_NUM = TO_NUMBER(T.RECHECK_NUM) - TO_NUMBER(?)
   WHERE T.JUDGE_STOVE_NO = ?
     AND T.LOT_NO = ?
     AND T.PLINE_CODE = ?
     AND T.OFFLINE_PRO = ?;
     DELETE FROM PORT_MIL_BATCH_SAMPLE_RESULT T WHERE T.PLAN_ID = ?;
END;
 -->
<query id = "FrmDownlineManage.cancelQualityInspectionTrustTS" desc = "撤销探伤下线质检委托">
<![CDATA[
DECLARE
  V_ZP_FLAG MIL_OFFLINE_RESLUT.ZP_FLAG%TYPE := NULL;
BEGIN
  DELETE FROM MIL_PLAN T WHERE T.ID = ? AND T.JUDGE_STOVE_NO = ?;
  DELETE FROM MIL_OFFLINE_RESULT_DETIA T WHERE T.OPERATION_ID = ? AND T.BACK_JUDGE_STOVE_NO = ?;
  DELETE FROM MIL_QA_RACK T WHERE T.RESULT_NO = ? AND T.JUDGE_STOVE_NO = ?;
  UPDATE MIL_OFFLINE_RESLUT T
     SET T.STATUS      = '0',
         T.RECHECK_NUM = TO_NUMBER(T.RECHECK_NUM) - TO_NUMBER(?)
   WHERE T.JUDGE_STOVE_NO = ?
     AND T.LOT_NO = ?
     AND T.PLINE_CODE = ?
     AND T.OFFLINE_PRO = ?
     AND T.OFFLINE_TYPE = ?;
  SELECT T.ZP_FLAG
    INTO V_ZP_FLAG
    FROM MIL_OFFLINE_RESLUT T
   WHERE T.JUDGE_STOVE_NO = ?
     AND T.OFFLINE_PRO = ?
     AND T.OFFLINE_TYPE = ?;
  IF (V_ZP_FLAG = 1) THEN
    FOR MYROWJUGENO IN (SELECT T.OLD_ZP_JUDGE_STOVE_NO,
                               T.PLINE_CODE,
                               T.ZP_COUNT
                          FROM MIL_OFFLINE_GROUP T
                         WHERE T.ZP_JUDGE_STOVE_NO = ?) LOOP
      FOR MYROW IN (SELECT *
                      FROM (SELECT *
                              FROM PORT_MIL_BATCH_SAMPLE_RESULT T1
                             WHERE T1.JUDGE_STOVE_NO =
                                   MYROWJUGENO.OLD_ZP_JUDGE_STOVE_NO
                               AND T1.PLINE_CODE = MYROWJUGENO.PLINE_CODE
                               AND T1.STATUS = '4'
                               AND T1.BACK_PROCESS = '11'
                               AND T1.OFFLINE_TYPE = ?
                               AND T1.GROUP_FLAG = '1'
                             ORDER BY T1.SEQ DESC)
                     WHERE ROWNUM <= MYROWJUGENO.ZP_COUNT) LOOP
        UPDATE MIL_TESTING_RACK T
           SET T.OFFLINE_FLAG = '1'
         WHERE T.JUDGE_STOVE_NO = MYROWJUGENO.OLD_ZP_JUDGE_STOVE_NO
           AND T.PLINE_CODE = MYROWJUGENO.PLINE_CODE
           AND T.OFFLINE_TYPE = ?
           AND T.OFFLINE_FLAG = '2'
           AND T.MAT_NO = MYROW.MAT_NO;
        UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T
           SET T.STATUS = '3', T.BACK_PROCESS = ''
         WHERE T.JUDGE_STOVE_NO = MYROWJUGENO.OLD_ZP_JUDGE_STOVE_NO
           AND T.MAT_NO = MYROW.MAT_NO;
      END LOOP;
    END LOOP;
  ELSE
    FOR MYROW1 IN (SELECT *
                    FROM (SELECT *
                            FROM PORT_MIL_BATCH_SAMPLE_RESULT T
                           WHERE T.JUDGE_STOVE_NO = ?
                             AND T.PLINE_CODE = ?
                             AND T.Status = '4'
                             AND T.Back_Process = '11'
                             AND T.OFFLINE_TYPE = ?
                           ORDER BY T.SEQ DESC)
                   WHERE ROWNUM <= ?) LOOP
      UPDATE MIL_TESTING_RACK T
         SET T.OFFLINE_FLAG = '1'
       WHERE T.JUDGE_STOVE_NO = ?
         AND T.PLINE_CODE = ?
         AND T.OFFLINE_TYPE = ?
         AND T.OFFLINE_FLAG = '2'
         AND T.MAT_NO = MYROW1.MAT_NO;
      UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T
         SET T.STATUS = '3', T.BACK_PROCESS = ''
       WHERE T.JUDGE_STOVE_NO = ?
         AND T.MAT_NO = MYROW1.MAT_NO;
    END LOOP;
  END IF;
  DELETE FROM PORT_MIL_BATCH_SAMPLE_RESULT T WHERE T.PLAN_ID = ? AND T.JUDGE_STOVE_NO = ?;
END;
]]>
</query>
<!-- 
DECLARE
BEGIN
  DELETE FROM MIL_PLAN T WHERE T.ID = ?;
  DELETE FROM MIL_OFFLINE_RESULT_DETIA T WHERE T.OPERATION_ID = ?;
  DELETE FROM MIL_QA_RACK T WHERE T.RESULT_NO = ?;
  UPDATE MIL_OFFLINE_RESLUT T
     SET T.STATUS = '0',
     T.RECHECK_NUM = TO_NUMBER(T.RECHECK_NUM) - TO_NUMBER(?)
   WHERE T.JUDGE_STOVE_NO = ?
     AND T.LOT_NO = ?
     AND T.PLINE_CODE = ?
     AND T.OFFLINE_PRO = ?
     AND T.OFFLINE_TYPE = ?;
  FOR MYROW IN (SELECT *
                  FROM (SELECT *
                          FROM MIL_TESTING_RACK T
                         WHERE T.JUDGE_STOVE_NO = ?
                           AND T.PLINE_CODE = ?
                           AND T.OFFLINE_FLAG = '2'
                           AND T.OFFLINE_TYPE = ?
                         ORDER BY T.SEQ DESC)
                 WHERE ROWNUM <= ?) LOOP
    UPDATE MIL_TESTING_RACK T
       SET T.OFFLINE_FLAG = '1'
     WHERE T.JUDGE_STOVE_NO = ?
       AND T.PLINE_CODE = ?
       AND T.OFFLINE_TYPE = ?
       AND T.OFFLINE_FLAG = '2'
       AND T.SEQ = MYROW.SEQ;
       UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T SET T.STATUS = '3',T.BACK_PROCESS = '' WHERE T.JUDGE_STOVE_NO = ? AND T.MAT_NO = MYROW.MAT_NO;
  END LOOP;
  DELETE FROM PORT_MIL_BATCH_SAMPLE_RESULT T WHERE T.PLAN_ID = ?;
END;
 -->
<query id = "FrmDownlineManage.cancelBackLine" desc = "撤销探伤返线">
<![CDATA[
DECLARE
  V_ZP_FLAG MIL_OFFLINE_RESLUT.ZP_FLAG%TYPE := NULL;
BEGIN
  DELETE FROM MIL_PLAN T WHERE T.ID = ? AND T.JUDGE_STOVE_NO = ?;
  DELETE FROM MIL_OFFLINE_RESULT_DETIA T WHERE T.OPERATION_ID = ? AND T.BACK_JUDGE_STOVE_NO = ?;
  DELETE FROM MIL_QA_RACK T WHERE T.RESULT_NO = ? AND T.JUDGE_STOVE_NO = ?;
  DELETE FROM MIL_TESTING_RACK T WHERE T.RESULT_NO = ? AND T.JUDGE_STOVE_NO = ?;
  DELETE FROM MIL_STRAIGHTENING_RESULT T WHERE T.RESULT_NO = ? AND T.JUDGE_STOVE_NO = ?;
  UPDATE MIL_OFFLINE_RESLUT T
     SET T.STATUS       = '0',
         T.BACKLINE_NUM = TO_NUMBER(T.BACKLINE_NUM) - TO_NUMBER(?)
   WHERE T.JUDGE_STOVE_NO = ?
     AND T.OFFLINE_PRO = 'TS'
     AND T.OFFLINE_TYPE = ?;
  SELECT T.ZP_FLAG
    INTO V_ZP_FLAG
    FROM MIL_OFFLINE_RESLUT T
   WHERE T.JUDGE_STOVE_NO = ?
     AND T.OFFLINE_PRO = 'TS'
     AND T.OFFLINE_TYPE = ?;
  IF (V_ZP_FLAG = 1) THEN
    FOR MYROWJUGENO IN (SELECT T.OLD_ZP_JUDGE_STOVE_NO,
                               T.PLINE_CODE,
                               T.ZP_COUNT
                          FROM MIL_OFFLINE_GROUP T
                         WHERE T.ZP_JUDGE_STOVE_NO = ?) LOOP
    
      FOR MYROW IN (SELECT *
                      FROM (SELECT T1.SEQ, T1.MAT_NO
                              FROM PORT_MIL_BATCH_SAMPLE_RESULT T1
                             WHERE T1.JUDGE_STOVE_NO =
                                   MYROWJUGENO.OLD_ZP_JUDGE_STOVE_NO
                               AND T1.PLINE_CODE = MYROWJUGENO.PLINE_CODE
                               AND T1.Status = '4'
                               AND T1.BACK_PROCESS = '10'
                               AND T1.OFFLINE_TYPE = ?
                               AND T1.GROUP_FLAG = '1'
                             ORDER BY T1.SEQ DESC)
                     WHERE ROWNUM <= MYROWJUGENO.ZP_COUNT) LOOP
        UPDATE MIL_TESTING_RACK T
           SET T.OFFLINE_FLAG = '1'
         WHERE T.JUDGE_STOVE_NO = MYROWJUGENO.OLD_ZP_JUDGE_STOVE_NO
           AND T.PLINE_CODE = MYROWJUGENO.PLINE_CODE
           AND T.MAT_NO = MYROW.MAT_NO;
        UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T
           SET T.STATUS = '3', T.BACK_PROCESS = ''
         WHERE T.JUDGE_STOVE_NO = MYROWJUGENO.OLD_ZP_JUDGE_STOVE_NO
           AND T.MAT_NO = MYROW.MAT_NO;
      END LOOP;
    END LOOP;
  ELSE
    FOR MYROW1 IN (SELECT *
                    FROM (SELECT T.SEQ, T.MAT_NO
                            FROM PORT_MIL_BATCH_SAMPLE_RESULT T
                           WHERE T.JUDGE_STOVE_NO = ?
                             AND T.PLINE_CODE = ?
                             AND T.STATUS = '4'
                             AND T.BACK_PROCESS = '10'
                             AND T.OFFLINE_TYPE = ?
                           ORDER BY T.SEQ DESC)
                   WHERE ROWNUM <= ?) LOOP
      UPDATE MIL_TESTING_RACK T
         SET T.OFFLINE_FLAG = '1'
       WHERE T.JUDGE_STOVE_NO = ?
         AND T.PLINE_CODE = ?
         AND T.MAT_NO = MYROW1.MAT_NO;
      UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T
         SET T.STATUS = '3', T.BACK_PROCESS = ''
       WHERE T.JUDGE_STOVE_NO = ?
         AND T.MAT_NO = MYROW1.MAT_NO;
    END LOOP;
  END IF;
  DELETE FROM PORT_MIL_BATCH_SAMPLE_RESULT T WHERE T.PLAN_ID = ? AND T.JUDGE_STOVE_NO = ?;
END;
]]>
</query>
<query id = "FrmDownlineManage.cancelBackLineSta" desc = "撤销矫直返线">
<![CDATA[
DECLARE
BEGIN
  DELETE FROM MIL_PLAN T WHERE T.ID = ? AND T.JUDGE_STOVE_NO = ?;
  DELETE FROM MIL_OFFLINE_RESULT_DETIA T WHERE T.OPERATION_ID = ? AND T.BACK_JUDGE_STOVE_NO = ?;
  DELETE FROM MIL_QA_RACK T WHERE T.RESULT_NO = ? AND T.JUDGE_STOVE_NO = ?;
  DELETE FROM MIL_TESTING_RACK T WHERE T.RESULT_NO = ? AND T.JUDGE_STOVE_NO = ?;
  DELETE FROM MIL_STRAIGH_RACK T WHERE T.RESULT_NO = ? AND T.JUDGE_STOVE_NO = ?;
  UPDATE MIL_OFFLINE_RESLUT T
     SET T.STATUS       = '0',
         T.BACKLINE_NUM = TO_NUMBER(T.BACKLINE_NUM) - TO_NUMBER(?)
   WHERE T.JUDGE_STOVE_NO = ?
     AND T.OFFLINE_PRO = 'JZ';
    FOR MYROW IN (SELECT *
                    FROM (SELECT T.SEQ, T.MAT_NO
                            FROM PORT_MIL_BATCH_SAMPLE_RESULT T
                           WHERE T.JUDGE_STOVE_NO = ?
                             AND T.PLINE_CODE = ?
                             AND T.STATUS = '4'
                             AND TRIM(T.BACK_PROCESS) = '9'
                           ORDER BY T.SEQ DESC)
                   WHERE ROWNUM <= ?) LOOP
      UPDATE MIL_STRAIGH_RACK T
         SET T.OFFLINE_FLAG = '1'
       WHERE T.JUDGE_STOVE_NO = ?
         AND T.PLINE_CODE = ?
         AND T.MAT_NO = MYROW.MAT_NO;
      UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T
         SET T.STATUS = '3', T.BACK_PROCESS = ''
       WHERE T.JUDGE_STOVE_NO = ?
         AND T.MAT_NO = MYROW.MAT_NO;
    END LOOP;
  DELETE FROM PORT_MIL_BATCH_SAMPLE_RESULT T WHERE T.PLAN_ID = ? AND T.JUDGE_STOVE_NO = ?;
END;
]]>
</query>
<query id = "FrmDownlineManage.cancelBackPipe" desc = "撤销交库返线">
<![CDATA[
DECLARE
BEGIN
  DELETE FROM MIL_PLAN T WHERE T.ID = ? AND T.JUDGE_STOVE_NO = ?;
  DELETE FROM MIL_OFFLINE_RESULT_DETIA T WHERE T.OPERATION_ID = ? AND T.BACK_JUDGE_STOVE_NO = ?;
  UPDATE MIL_OFFLINE_RESLUT T
     SET T.STATUS       = '0',
         T.BACKLINE_NUM = TO_NUMBER(T.BACKLINE_NUM) - TO_NUMBER(?)
   WHERE T.JUDGE_STOVE_NO = ?
     AND T.OFFLINE_PRO = 'XX';
    FOR MYROW IN (SELECT *
                    FROM (SELECT T.SEQ, T.MAT_NO
                            FROM PORT_MIL_BATCH_SAMPLE_RESULT T
                           WHERE T.JUDGE_STOVE_NO = ?
                             AND T.PLINE_CODE = ?
                             AND T.STATUS = '4'
                             AND TRIM(T.BACK_PROCESS) = '12'
                           ORDER BY T.SEQ DESC)
                   WHERE ROWNUM <= ?) LOOP
      UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T
         SET T.STATUS = '3', T.BACK_PROCESS = ''
       WHERE T.JUDGE_STOVE_NO = ?
         AND T.MAT_NO = MYROW.MAT_NO;
    END LOOP;
  DELETE FROM PORT_MIL_BATCH_SAMPLE_RESULT T WHERE T.PLAN_ID = ? AND T.JUDGE_STOVE_NO = ?;
END;
]]>
</query>
<query id = "cancelQualityInspectionTrust.doQueryMat" desc = "查询是否有已交库">
SELECT COUNT(1)ACOUNT FROM MAT_BC_M T WHERE T.ZG_STOVE_SQE = ? 
</query>
<!-- DECLARE
BEGIN
  DELETE FROM MIL_PLAN T WHERE T.ID = ?;
  DELETE FROM MIL_OFFLINE_RESULT_DETIA T WHERE T.OPERATION_ID = ?;
  DELETE FROM MIL_QA_RACK T WHERE T.RESULT_NO = ?;
  DELETE FROM MIL_TESTING_RACK T WHERE T.RESULT_NO = ?;
  DELETE FROM MIL_STRAIGHTENING_RESULT T WHERE T.RESULT_NO = ?;
  UPDATE MIL_OFFLINE_RESLUT T
     SET T.STATUS       = '0',
         T.BACKLINE_NUM = TO_NUMBER(T.BACKLINE_NUM) - TO_NUMBER(?)
   WHERE T.JUDGE_STOVE_NO = ?
     AND T.OFFLINE_PRO = 'TS'
     AND T.OFFLINE_TYPE = ?;
  FOR MYROW IN (SELECT *
                  FROM (SELECT T.SEQ,T.MAT_NO
                          FROM MIL_TESTING_RACK T
                         WHERE T.JUDGE_STOVE_NO = ?
                           AND T.PLINE_CODE = ?
                           AND T.OFFLINE_FLAG = '2'
                           AND T.OFFLINE_TYPE = ?
                         ORDER BY T.SEQ DESC)
                 WHERE ROWNUM <= ?) LOOP
    UPDATE MIL_TESTING_RACK T
       SET T.OFFLINE_FLAG = '1'
     WHERE T.JUDGE_STOVE_NO = ?
       AND T.PLINE_CODE = ?
       AND T.SEQ = MYROW.SEQ;
       UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T SET T.STATUS = '3',T.BACK_PROCESS = '' WHERE T.JUDGE_STOVE_NO = ? AND T.MAT_NO = MYROW.MAT_NO;
  END LOOP;
  DELETE FROM PORT_MIL_BATCH_SAMPLE_RESULT T WHERE T.PLAN_ID = ?;
END; -->
<query id = "FrmDownlineManage.canceInstroe" desc = "撤销入库转移">
DECLARE
BEGIN
  FOR MYROW IN (SELECT T.MAT_NO
                  FROM YDM_BC_INLIST T
                 WHERE T.INSTOCK_DOC = ?
                 ORDER BY T.MAT_NO DESC) LOOP
    DELETE FROM YDM_BC_BUTTRESS T WHERE T.MAT_NO = MYROW.MAT_NO;
    DELETE FROM YDM_BC_INLIST T WHERE T.MAT_NO = MYROW.MAT_NO AND T.INSTOCK_DOC = MYROW.INSTOCK_DOC;
  END LOOP;
  UPDATE MIL_OFFLINE_RESLUT T
       SET T.INSTORAGE_NUM = TO_NUMBER(T.INSTORAGE_NUM) - TO_NUMBER(?)
     WHERE T.JUDGE_STOVE_NO = ?
       AND T.LOT_NO = ?
       AND T.OFFLINE_TYPE = ?;
  DELETE FROM MIL_OFFLINE_RESULT_DETIA T WHERE T.OPERATION_ID = ?;
END;
</query>
<query id = "cancelQualityInspectionTrust.doQueryMilPlan" desc = "查询主计划炉号">
SELECT T.JUDGE_STOVE_NO FROM MIL_PLAN T WHERE T.ID = ?
</query>
<query id = "FrmDownlineManage.qualityInspectionTrust1" desc = "生成质检委托">
<![CDATA[ 
DECLARE
  V_TIME           MIL_OFFLINE_RESLUT.OFFLINE_TIME%TYPE := SYSDATE;
  V_JUDGE_STOVE_NO MIL_PLAN.JUDGE_STOVE_NO%TYPE := NULL;
  V_ID             MIL_PLAN.ID%TYPE := NULL;
  V_OPERATION_ID   MIL_OFFLINE_RESULT_DETIA.OPERATION_ID%TYPE := NULL;
  V_OFFLINE_NUM    MIL_OFFLINE_RESLUT.OFFLINE_NUM%TYPE := NULL;
  V_TOTAL_COUNT    MIL_OFFLINE_RESLUT.OFFLINE_NUM%TYPE := NULL;
  V_ABRVITION      SLM_ORDER_HEAD.ABRVITION%TYPE := NULL;
  V_COUNT          MIL_PLAN.BRANCH%TYPE := 0;
  V_PRO_PLAN_ID    MIL_PLAN.PRO_PLAN_ID%TYPE := ?;
  V_GX_PLAN_NO     MIL_PLAN.GX_PLAN_NO%TYPE := ?;

  V_ORDER_NO    PLN_ORDER_ZG_S.ORDER_NO%TYPE := ?; --合同号
  V_CONTRACT_NO MIL_PLAN.CONTRACT_NO%TYPE := ?; --合同号（带序号）

  V_PRO_PLAN_ID_G   MIL_PLAN.PRO_PLAN_ID%TYPE := NULL; --轧管订单编号
  V_GX_PLAN_NO_G    MIL_PLAN.GX_PLAN_NO%TYPE := NULL; --工序排产序号
  V_ORD_LN_DLY_PK_G MIL_PLAN.ORD_LN_DLY_PK%TYPE := NULL;
  V_CRAFT_SEQ_G     MIL_PLAN.CRAFT_SEQ%TYPE := NULL;
  V_CIC_G           MIL_PLAN.CIC%TYPE := NULL;
  V_INDEX_SEQ_G     MIL_PLAN.INDEX_SEQ%TYPE := NULL;
  V_PIC_G           MIL_PLAN.PIC%TYPE := NULL;
  V_IF_PRODUCT_G    MIL_PLAN.IF_PRODUCT%TYPE := NULL;
BEGIN
  SELECT COUNT(1)
    INTO V_COUNT
    FROM SLM_ORDER_HEAD T
   WHERE T.VALIDFLAG = '1'
     AND T.ORDER_NO = V_ORDER_NO;
  IF (V_COUNT > 0) THEN
    select max((select c.ABRVITION
                 from slm_base_customer c
                where c.customer_no = t1.FINAL_USER))
      into V_ABRVITION
      from pln_order_zg_s t, pln_saleord t1
     where t1.ord_ln_dly_pk = t.ord_ln_dly_pk
       and t.ORDER_NO = V_ORDER_NO;
  END IF;

  --改交合同的轧管订单编号
  SELECT COUNT(1)
    INTO V_COUNT
    FROM PLN_SALEORD T3, PLN_ORDER_ZG_S S1
   WHERE T3.ORD_LN_DLY_PK = S1.ORD_LN_DLY_PK
     AND S1.EXE_STATUS = '0'
     AND T3.ORDER_NO || '/' || T3.ORDER_SEQ = V_CONTRACT_NO;

  IF (V_COUNT > 0) THEN
    SELECT MAX(T3.ORD_LN_DLY_PK),
           MAX(S1.PRO_PLAN_ID),
           MAX(S1.GX_PLAN_NO),
           MAX(S1.CRAFT_SEQ),
           MAX(SUBSTR(S1.CIC, 1, 10)),
           MAX(S1.INDEX_SEQ),
           MAX(SUBSTR(S1.PIC, 1, 10))
      INTO V_ORD_LN_DLY_PK_G,
           V_PRO_PLAN_ID_G,
           V_GX_PLAN_NO_G,
           V_CRAFT_SEQ_G,
           V_CIC_G,
           V_INDEX_SEQ_G,
           V_PIC_G
      FROM PLN_SALEORD T3, PLN_ORDER_ZG_S S1
     WHERE T3.ORD_LN_DLY_PK = S1.ORD_LN_DLY_PK
       AND S1.EXE_STATUS = '0'
       AND T3.ORDER_NO || '/' || T3.ORDER_SEQ = V_CONTRACT_NO;
  END IF;

  --生成新炉号
  SELECT REGEXP_REPLACE(?, '-.*', '') || '-' ||
         LPAD(NVL(MAX(SUBSTR(T.JUDGE_STOVE_NO, -2)), 0) + 1, 2, 0) JUDGE_STOVE_NO
    INTO V_JUDGE_STOVE_NO
    FROM MIL_PLAN T
   WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = REGEXP_REPLACE(?, '-.*', '')
        --AND NVL(T.PRO_PLAN_ID, '/') = NVL(V_PRO_PLAN_ID, '/')
        --AND NVL(T.GX_PLAN_NO, '/') = NVL(V_GX_PLAN_NO, '/')
     AND T.PLINE_CODE = ?;
  --生成主键
  SELECT ? || LPAD(NVL(MAX(SUBSTR(T.ID, 7)), 0) + 1, 3, 0) DI
    INTO V_ID
    FROM MIL_PLAN T
   WHERE T.PLINE_CODE = ?
     AND INSTR(T.ID, '-') = 0
        --AND REGEXP_REPLACE(T.ID,'^[-\+]?\D+(\.\D+)?$','') IS NULL
     AND TO_CHAR(T.TOM, 'YYYY-MM-DD') = TO_CHAR(SYSDATE, 'YYYY-MM-DD');
  --生成操作ID
  SELECT ? || LPAD(NVL(MAX(SUBSTR(T.OPERATION_ID, 7)), 0) + 1, 5, 0) OPERATION_ID
    INTO V_OPERATION_ID
    FROM MIL_OFFLINE_RESULT_DETIA T
   WHERE TO_CHAR(T.COL_TIME, 'YYMMDD') = ?;
  FOR MYROW IN (SELECT *
                  FROM MIL_PLAN T
                 WHERE T.JUDGE_STOVE_NO = ?
                   AND T.BACK_SLAB_FLAG <> '2'
                      /* AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
                      AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')*/
                   AND T.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,
       TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
       TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
       TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
       '',
       '90',
       MYROW.CUT_HEAD_LENGTHP,
       MYROW.CUT_TRAIL_LENGTHP,
       MYROW.CONTROL_THICKP,
       '2',
       '0',
       '',
       MYROW.CUT_TYPE,
       '0',
       --MYROW.PRODUCE_STANDRAD,
       ?,
       MYROW.SIMPLE_PROCESS,
       '1',
       '9',
       MYROW.FEED_TIME,
       MYROW.ID,
       MYROW.SEQ,
       MYROW.STOVE_NO,
       V_JUDGE_STOVE_NO,
       ?,
       --MYROW.CONTRACT_NO
       ?,
       ?,
       --MYROW.IMP_PROCESS,
       MYROW.PLINE_CODE,
       '95',
       MYROW.PRODUCER,
       MYROW.PROCESS_STATUS,
       MYROW.DB_LENGTH,
       MYROW.DB_HEIGHT,
       MYROW.ROLL_LENGTH,
       MYROW.SAW_NUM,
       -- MYROW.TARGET_LENGTH,
       ?,
       V_ABRVITION,
       MYROW.TARGET_LIABRARY,
       --MYROW.VARIETIES,
       ?,
       --MYROW.PIPE_SIZE,
       ?,
       --MYROW.BUCKLE_TYPE,
       ?,
       ?,
       --MYROW.LENGTH_RANGE,
       --MYROW.ROLL_STANDRAD,
       ?,
       MYROW.PIPE_SECTION,
       --MYROW.STEELCODE,
       NVL(?, MYROW.STEELCODE),
       --MYROW.STEELNAME,
       NVL(?, MYROW.STEELNAME),
       MYROW.GRADECODE,
       MYROW.GRADENAME,
       DECODE(MYROW.CONTRACT_NO,
              V_CONTRACT_NO,
              MYROW.ORD_LN_DLY_PK,
              V_ORD_LN_DLY_PK_G),
       MYROW.PRT_FLAG,
       DECODE(MYROW.CONTRACT_NO,
              V_CONTRACT_NO,
              V_PRO_PLAN_ID,
              V_PRO_PLAN_ID_G),
       DECODE(MYROW.CONTRACT_NO,
              V_CONTRACT_NO,
              V_GX_PLAN_NO,
              V_GX_PLAN_NO_G),
       
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       DECODE(MYROW.CONTRACT_NO,
              V_CONTRACT_NO,
              MYROW.CRAFT_SEQ,
              V_CRAFT_SEQ_G),
       DECODE(MYROW.CONTRACT_NO, V_CONTRACT_NO, MYROW.CIC, V_CIC_G),
       DECODE(MYROW.CONTRACT_NO,
              V_CONTRACT_NO,
              MYROW.INDEX_SEQ,
              V_INDEX_SEQ_G),
       DECODE(MYROW.CONTRACT_NO, V_CONTRACT_NO, MYROW.PIC, V_PIC_G),
       MYROW.IF_PRODUCT,
       MYROW.PRDCR_NO,
       MYROW.IF_MONITOR);
  
    INSERT INTO MIL_OFFLINE_RESULT_DETIA
      (LOT_NO,
       JUDGE_STOVE_NO,
       OPERATION_TYPE,
       ACT_COUNT,
       ACT_WEIGHT,
       COL_TIME,
       REMARK,
       COL_USER,
       COL_GROUP,
       COL_SHIFT,
       OPERATION_ID,
       PLINE_CODE,
       ID,
       OFFLINE_TYPE,
       BACK_JUDGE_STOVE_NO,
       PRO_PLAN_ID,
       GX_PLAN_NO)
    VALUES
      (?,
       ?,
       '2',
       ?,
       ?,
       TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
       '',
       ?,
       ?,
       ?,
       V_OPERATION_ID,
       MYROW.PLINE_CODE,
       MYROW.ID,
       ?,
       V_JUDGE_STOVE_NO,
       V_PRO_PLAN_ID,
       V_GX_PLAN_NO);
  END LOOP;
  UPDATE MIL_OFFLINE_RESLUT T
     SET T.RECHECK_NUM = TO_NUMBER(T.RECHECK_NUM) + TO_NUMBER(?)
   WHERE T.JUDGE_STOVE_NO = ?
        /*AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
        AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')*/
     AND T.LOT_NO = ?
     AND T.PLINE_CODE = ?
     AND T.OFFLINE_PRO = ?
     AND T.OFFLINE_TYPE = ?;
  SELECT T.OFFLINE_NUM, (T.GROUP_NUM + T.BACKLINE_NUM + T.RECHECK_NUM)
    INTO V_OFFLINE_NUM, V_TOTAL_COUNT
    FROM MIL_OFFLINE_RESLUT T
   WHERE T.JUDGE_STOVE_NO = ?
        /*AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
        AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')*/
     AND T.LOT_NO = ?
     AND T.PLINE_CODE = ?
     AND T.STATUS = '0'
     AND T.OFFLINE_PRO = ?
     AND T.OFFLINE_TYPE = ?;
  IF (V_OFFLINE_NUM = V_TOTAL_COUNT) THEN
    UPDATE MIL_OFFLINE_RESLUT T
       SET T.STATUS = '1'
     WHERE T.JUDGE_STOVE_NO = ?
          /*AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
          AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')*/
       AND T.LOT_NO = ?
       AND T.PLINE_CODE = ?
       AND T.OFFLINE_PRO = ?
       AND T.OFFLINE_TYPE = ?;
  END IF;
END;
 ]]>
</query>
<query id = "FrmDownlineManage.doBackLine" desc = "探伤返线">
<![CDATA[
DECLARE
  V_TIME           MIL_OFFLINE_RESLUT.OFFLINE_TIME%TYPE := SYSDATE;
  V_JUDGE_STOVE_NO MIL_PLAN.JUDGE_STOVE_NO%TYPE := NULL;
  V_ID             MIL_PLAN.ID%TYPE := NULL;
  V_OPERATION_ID   MIL_OFFLINE_RESULT_DETIA.OPERATION_ID%TYPE := NULL;
  V_OFFLINE_NUM    MIL_OFFLINE_RESLUT.OFFLINE_NUM%TYPE := NULL;
  V_TOTAL_COUNT    MIL_OFFLINE_RESLUT.OFFLINE_NUM%TYPE := NULL;
  V_ABRVITION      SLM_ORDER_HEAD.ABRVITION%TYPE := NULL;
  V_COUNT          MIL_PLAN.BRANCH%TYPE := 0;

  V_ORDER_NO    PLN_ORDER_ZG_S.ORDER_NO%TYPE := ?; --合同号
  V_CONTRACT_NO MIL_PLAN.CONTRACT_NO%TYPE := ?; --合同号（带序号）

  V_PRO_PLAN_ID_G   MIL_PLAN.PRO_PLAN_ID%TYPE := NULL; --轧管订单编号
  V_GX_PLAN_NO_G    MIL_PLAN.GX_PLAN_NO%TYPE := NULL; --工序排产序号
  V_ORD_LN_DLY_PK_G MIL_PLAN.ORD_LN_DLY_PK%TYPE := NULL;
  V_CRAFT_SEQ_G     MIL_PLAN.CRAFT_SEQ%TYPE := NULL;
  V_CIC_G           MIL_PLAN.CIC%TYPE := NULL;
  V_INDEX_SEQ_G     MIL_PLAN.INDEX_SEQ%TYPE := NULL;
  V_PIC_G           MIL_PLAN.PIC%TYPE := NULL;
  V_IF_PRODUCT_G    MIL_PLAN.IF_PRODUCT%TYPE := NULL;
BEGIN
  SELECT COUNT(1)
    INTO V_COUNT
    FROM SLM_ORDER_HEAD T
   WHERE T.VALIDFLAG = '1'
     AND T.ORDER_NO = V_ORDER_NO;
  IF (V_COUNT > 0) THEN
    select max((select c.ABRVITION
                 from slm_base_customer c
                where c.customer_no = t1.FINAL_USER))
      into V_ABRVITION
      from pln_order_zg_s t, pln_saleord t1
     where t1.ord_ln_dly_pk = t.ord_ln_dly_pk
       and t.ORDER_NO = V_ORDER_NO;
  END IF;

  --改交合同的轧管订单编号
  SELECT COUNT(1)
    INTO V_COUNT
    FROM PLN_SALEORD T3, PLN_ORDER_ZG_S S1
   WHERE T3.ORD_LN_DLY_PK = S1.ORD_LN_DLY_PK
     AND S1.EXE_STATUS = '0'
     AND T3.ORDER_NO || '/' || T3.ORDER_SEQ = V_CONTRACT_NO;

  IF (V_COUNT > 0) THEN
    SELECT MAX(T3.ORD_LN_DLY_PK),
           MAX(S1.PRO_PLAN_ID),
           MAX(S1.GX_PLAN_NO),
           MAX(S1.CRAFT_SEQ),
           MAX(S1.CIC),
           MAX(S1.INDEX_SEQ),
           MAX(S1.PIC)
      INTO V_ORD_LN_DLY_PK_G,
           V_PRO_PLAN_ID_G,
           V_GX_PLAN_NO_G,
           V_CRAFT_SEQ_G,
           V_CIC_G,
           V_INDEX_SEQ_G,
           V_PIC_G
      FROM PLN_SALEORD T3, PLN_ORDER_ZG_S S1
     WHERE T3.ORD_LN_DLY_PK = S1.ORD_LN_DLY_PK
       AND S1.EXE_STATUS = '0'
       AND T3.ORDER_NO || '/' || T3.ORDER_SEQ = V_CONTRACT_NO;
  END IF;

  --生成新炉号
  SELECT REGEXP_REPLACE(?, '-.*', '') || '-' ||
         LPAD(NVL(MAX(SUBSTR(T.JUDGE_STOVE_NO, -2)), 0) + 1, 2, 0) JUDGE_STOVE_NO
    INTO V_JUDGE_STOVE_NO
    FROM MIL_PLAN T
   WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') =
         REGEXP_REPLACE(?, '-.*', '')
     AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
     AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
     AND T.PLINE_CODE = ?;
  --生成主键
  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 = ?
     AND INSTR(T.ID, '-') = 0
        --AND REGEXP_REPLACE(T.ID,'^[-\+]?\D+(\.\D+)?$','') IS NULL
     AND TO_CHAR(T.TOM, 'YYYY-MM-DD') = TO_CHAR(SYSDATE, 'YYYY-MM-DD');
  --生成操作ID
  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_OFFLINE_RESULT_DETIA T
   WHERE TO_CHAR(T.COL_TIME, 'YYYY-MM-DD') = TO_CHAR(SYSDATE, 'YYYY-MM-DD');
  FOR MYROW IN (SELECT *
                  FROM MIL_PLAN T
                 WHERE T.JUDGE_STOVE_NO = ?
                   AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
                   AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
                   AND T.BACK_SLAB_FLAG <> '2'
                   AND T.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,
       CODE_SAMPLE_FLAG,
       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,
       TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
       TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
       TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
       '',
       '80',
       MYROW.CUT_HEAD_LENGTHP,
       MYROW.CUT_TRAIL_LENGTHP,
       MYROW.CONTROL_THICKP,
       '2',
       '0',
       '',
       MYROW.CUT_TYPE,
       '0',
       --MYROW.PRODUCE_STANDRAD,
       ?,
       MYROW.SIMPLE_PROCESS,
       '1',
       '8',
       MYROW.FEED_TIME,
       MYROW.ID,
       MYROW.SEQ,
       MYROW.STOVE_NO,
       V_JUDGE_STOVE_NO,
       ?,
       --MYROW.CONTRACT_NO,
       ?,
       ?,
       --MYROW.IMP_PROCESS,
       MYROW.PLINE_CODE,
       '85',
       MYROW.PRODUCER,
       MYROW.PROCESS_STATUS,
       MYROW.DB_LENGTH,
       MYROW.DB_HEIGHT,
       MYROW.ROLL_LENGTH,
       MYROW.SAW_NUM,
       --MYROW.TARGET_LENGTH,
       ?,
       V_ABRVITION,
       MYROW.TARGET_LIABRARY,
       --MYROW.VARIETIES,
       ?,
       --MYROW.PIPE_SIZE,
       ?,
       --MYROW.BUCKLE_TYPE,
       ?,
       ?,
       --MYROW.LENGTH_RANGE,
       --MYROW.ROLL_STANDRAD,
       ?,
       MYROW.PIPE_SECTION,
       --MYROW.STEELCODE,
       --MYROW.STEELNAME,
       NVL(?, MYROW.STEELCODE),
       NVL(?, MYROW.STEELNAME),
       MYROW.GRADECODE,
       MYROW.GRADENAME,
       MYROW.CODE_SAMPLE_FLAG,
       DECODE(MYROW.CONTRACT_NO,
              V_CONTRACT_NO,
              MYROW.ORD_LN_DLY_PK,
              V_ORD_LN_DLY_PK_G),
       MYROW.PRT_FLAG,
       DECODE(MYROW.CONTRACT_NO,
              V_CONTRACT_NO,
              MYROW.PRO_PLAN_ID,
              V_PRO_PLAN_ID_G),
       DECODE(MYROW.CONTRACT_NO,
              V_CONTRACT_NO,
              MYROW.GX_PLAN_NO,
              V_GX_PLAN_NO_G),
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       DECODE(MYROW.CONTRACT_NO,
              V_CONTRACT_NO,
              MYROW.CRAFT_SEQ,
              V_CRAFT_SEQ_G),
       DECODE(MYROW.CONTRACT_NO, V_CONTRACT_NO, MYROW.CIC, V_CIC_G),
       DECODE(MYROW.CONTRACT_NO,
              V_CONTRACT_NO,
              MYROW.INDEX_SEQ,
              V_INDEX_SEQ_G),
       DECODE(MYROW.CONTRACT_NO, V_CONTRACT_NO, MYROW.PIC, V_PIC_G),
       MYROW.IF_PRODUCT,
       MYROW.PRDCR_NO,
       MYROW.IF_MONITOR);
  
    INSERT INTO MIL_OFFLINE_RESULT_DETIA
      (LOT_NO,
       JUDGE_STOVE_NO,
       OPERATION_TYPE,
       ACT_COUNT,
       ACT_WEIGHT,
       COL_TIME,
       REMARK,
       COL_USER,
       COL_GROUP,
       COL_SHIFT,
       OPERATION_ID,
       PLINE_CODE,
       ID,
       OFFLINE_TYPE,
       BACK_JUDGE_STOVE_NO,
       PRO_PLAN_ID,
       GX_PLAN_NO)
    VALUES
      (?,
       ?,
       '1',
       ?,
       ?,
       TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
       ?,
       ?,
       ?,
       ?,
       V_OPERATION_ID,
       MYROW.PLINE_CODE,
       MYROW.ID,
       ?,
       V_JUDGE_STOVE_NO,
       MYROW.PRO_PLAN_ID,
       MYROW.GX_PLAN_NO);
  
    INSERT INTO MIL_STRAIGHTENING_RESULT
      (RESULT_NO,
       LOT_NO,
       STOVE_NO,
       JUDGE_STOVE_NO,
       PLINE_CODE,
       IN_MAT_NUM,
       QUALIFIED_NUM,
       QA_TON,
       USER_ID,
       COL_USER,
       COL_GROUP,
       COL_SHIFT,
       COL_TIME,
       START_TIME,
       END_TIME,
       KG_FLAG,
       NODE_FUR_FLAG,
       PRO_PLAN_ID,
       GX_PLAN_NO)
    VALUES
      (MYROW.ID,
       ?,
       '',
       V_JUDGE_STOVE_NO,
       MYROW.PLINE_CODE,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
       TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
       TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
       '0',
       '1',
       MYROW.PRO_PLAN_ID,
       MYROW.GX_PLAN_NO);
  
    UPDATE MIL_OFFLINE_RESLUT T
       SET T.BACKLINE_NUM = TO_NUMBER(T.BACKLINE_NUM) + TO_NUMBER(?)
     WHERE T.JUDGE_STOVE_NO = ?
       AND NVL(T.PRO_PLAN_ID, '/') = NVL(MYROW.PRO_PLAN_ID, '/')
       AND NVL(T.GX_PLAN_NO, '/') = NVL(MYROW.GX_PLAN_NO, '/')
       AND T.LOT_NO = ?
       AND T.PLINE_CODE = ?
       AND T.OFFLINE_PRO = 'TS'
       AND T.OFFLINE_TYPE = ?;
  
    SELECT T.OFFLINE_NUM, (T.GROUP_NUM + T.BACKLINE_NUM + T.RECHECK_NUM)
      INTO V_OFFLINE_NUM, V_TOTAL_COUNT
      FROM MIL_OFFLINE_RESLUT T
     WHERE T.JUDGE_STOVE_NO = ?
       AND NVL(T.PRO_PLAN_ID, '/') = NVL(MYROW.PRO_PLAN_ID, '/')
       AND NVL(T.GX_PLAN_NO, '/') = NVL(MYROW.GX_PLAN_NO, '/')
       AND T.LOT_NO = ?
       AND T.PLINE_CODE = ?
       AND T.OFFLINE_PRO = 'TS'
       AND T.OFFLINE_TYPE = ?;
  
    IF (V_OFFLINE_NUM = V_TOTAL_COUNT) THEN
      UPDATE MIL_OFFLINE_RESLUT T
         SET T.STATUS = '1'
       WHERE T.JUDGE_STOVE_NO = ?
         AND NVL(T.PRO_PLAN_ID, '/') = NVL(MYROW.PRO_PLAN_ID, '/')
         AND NVL(T.GX_PLAN_NO, '/') = NVL(MYROW.GX_PLAN_NO, '/')
         AND T.LOT_NO = ?
         AND T.PLINE_CODE = ?
         AND T.OFFLINE_PRO = 'TS'
         AND T.OFFLINE_TYPE = ?;
    END IF;
  END LOOP;
END;

]]>
</query>
<query id = "FrmDownlineManage.doBackStaightLine" desc = "矫直返线">
<![CDATA[
DECLARE
  V_TIME           MIL_OFFLINE_RESLUT.OFFLINE_TIME%TYPE := SYSDATE;
  V_JUDGE_STOVE_NO MIL_PLAN.JUDGE_STOVE_NO%TYPE := NULL;
  V_ID             MIL_PLAN.ID%TYPE := NULL;
  V_OPERATION_ID   MIL_OFFLINE_RESULT_DETIA.OPERATION_ID%TYPE := NULL;
  V_OFFLINE_NUM    MIL_OFFLINE_RESLUT.OFFLINE_NUM%TYPE := NULL;
  V_TOTAL_COUNT    MIL_OFFLINE_RESLUT.OFFLINE_NUM%TYPE := NULL;
  V_ABRVITION      SLM_ORDER_HEAD.ABRVITION%TYPE := NULL;
  V_COUNT          MIL_PLAN.BRANCH%TYPE := 0;
BEGIN
  SELECT COUNT(1)
    INTO V_COUNT
    FROM SLM_ORDER_HEAD T
   WHERE T.VALIDFLAG = '1'
     AND T.ORDER_NO = ?;
  IF (V_COUNT > 0) THEN
    select max((select c.ABRVITION
                 from slm_base_customer c
                where c.customer_no = t1.FINAL_USER))
      into V_ABRVITION
      from pln_order_zg_s t, pln_saleord t1
     where t1.ord_ln_dly_pk = t.ord_ln_dly_pk
       and t.ORDER_NO = ?;
  END IF;
  --生成新炉号
  SELECT REGEXP_REPLACE(?, '-.*', '') || '-' ||
         LPAD(NVL(MAX(SUBSTR(T.JUDGE_STOVE_NO, -2)), 0) + 1, 2, 0) JUDGE_STOVE_NO
    INTO V_JUDGE_STOVE_NO
    FROM MIL_PLAN T
   WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = REGEXP_REPLACE(?, '-.*', '')
     AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
     AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
     AND T.PLINE_CODE = ?;
  --生成主键
  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 = ?
   AND INSTR(T.ID, '-') = 0
        --AND REGEXP_REPLACE(T.ID,'^[-\+]?\D+(\.\D+)?$','') IS NULL
     AND TO_CHAR(T.TOM, 'YYYY-MM-DD') = TO_CHAR(SYSDATE, 'YYYY-MM-DD');
  --生成操作ID
  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_OFFLINE_RESULT_DETIA T
   WHERE TO_CHAR(T.COL_TIME, 'YYYY-MM-DD') = TO_CHAR(SYSDATE, 'YYYY-MM-DD');
  FOR MYROW IN (SELECT *
                  FROM MIL_PLAN T
                 WHERE T.JUDGE_STOVE_NO = ?
                   AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
                   AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
                   AND T.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,
       CODE_SAMPLE_FLAG,
       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)
    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,
       TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
       TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
       TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
       '',
       '70',
       MYROW.CUT_HEAD_LENGTHP,
       MYROW.CUT_TRAIL_LENGTHP,
       MYROW.CONTROL_THICKP,
       '2',
       '0',
       '',
       MYROW.CUT_TYPE,
       '0',
       --MYROW.PRODUCE_STANDRAD,
       ?,
       MYROW.SIMPLE_PROCESS,
       '1',
       '7',
       MYROW.FEED_TIME,
       MYROW.ID,
       MYROW.SEQ,
       MYROW.STOVE_NO,
       V_JUDGE_STOVE_NO,
       ?,
       --MYROW.CONTRACT_NO,
       ?,
       ?,
       --MYROW.IMP_PROCESS,
       MYROW.PLINE_CODE,
       '75',
       MYROW.PRODUCER,
       MYROW.PROCESS_STATUS,
       MYROW.DB_LENGTH,
       MYROW.DB_HEIGHT,
       MYROW.ROLL_LENGTH,
       MYROW.SAW_NUM,
       --MYROW.TARGET_LENGTH,
       ?,
       V_ABRVITION,
       --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,
       NVL(?, MYROW.STEELCODE),
       NVL(?, MYROW.STEELNAME),
       MYROW.GRADECODE,
       MYROW.GRADENAME,
       MYROW.CODE_SAMPLE_FLAG,
       MYROW.ORD_LN_DLY_PK,
       MYROW.PRT_FLAG,
       MYROW.PRO_PLAN_ID,
       MYROW.GX_PLAN_NO,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?);
  
    INSERT INTO MIL_OFFLINE_RESULT_DETIA
      (LOT_NO,
       JUDGE_STOVE_NO,
       OPERATION_TYPE,
       ACT_COUNT,
       ACT_WEIGHT,
       COL_TIME,
       REMARK,
       COL_USER,
       COL_GROUP,
       COL_SHIFT,
       OPERATION_ID,
       PLINE_CODE,
       ID,
       OFFLINE_TYPE,
       BACK_JUDGE_STOVE_NO,
       PRO_PLAN_ID,
       GX_PLAN_NO)
    VALUES
      (?,
       ?,
       '4',
       ?,
       ?,
       TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
       ?,
       ?,
       ?,
       ?,
       V_OPERATION_ID,
       MYROW.PLINE_CODE,
       MYROW.ID,
       ?,
       V_JUDGE_STOVE_NO,
       MYROW.PRO_PLAN_ID,
       MYROW.GX_PLAN_NO);
    UPDATE MIL_OFFLINE_RESLUT T
       SET T.BACKLINE_NUM = TO_NUMBER(T.BACKLINE_NUM) + TO_NUMBER(?)
     WHERE T.JUDGE_STOVE_NO = ?
       AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
       AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
       AND T.LOT_NO = ?
       AND T.PLINE_CODE = ?
       AND T.OFFLINE_PRO = 'JZ';
    SELECT T.OFFLINE_NUM, (T.GROUP_NUM + T.BACKLINE_NUM + T.RECHECK_NUM)
      INTO V_OFFLINE_NUM, V_TOTAL_COUNT
      FROM MIL_OFFLINE_RESLUT T
     WHERE T.JUDGE_STOVE_NO = ?
       AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
       AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
       AND T.LOT_NO = ?
       AND T.PLINE_CODE = ?
       AND T.OFFLINE_PRO = 'JZ';
    IF (V_OFFLINE_NUM = V_TOTAL_COUNT) THEN
      UPDATE MIL_OFFLINE_RESLUT T
         SET T.STATUS = '1'
       WHERE T.JUDGE_STOVE_NO = ?
         AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
         AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
         AND T.LOT_NO = ?
         AND T.PLINE_CODE = ?
         AND T.OFFLINE_PRO = 'JZ';
    END IF;
  END LOOP;
END;
]]>
</query>
<query id = "FrmDownlineManage.backPipeMianPlan" desc = "返线交库点">
	<![CDATA[
DECLARE
  V_TIME           MIL_OFFLINE_RESLUT.OFFLINE_TIME%TYPE := SYSDATE;
  V_JUDGE_STOVE_NO MIL_PLAN.JUDGE_STOVE_NO%TYPE := NULL;
  V_ID             MIL_PLAN.ID%TYPE := NULL;
  V_OPERATION_ID   MIL_OFFLINE_RESULT_DETIA.OPERATION_ID%TYPE := NULL;
  V_OFFLINE_NUM    MIL_OFFLINE_RESLUT.OFFLINE_NUM%TYPE := NULL;
  V_TOTAL_COUNT    MIL_OFFLINE_RESLUT.OFFLINE_NUM%TYPE := NULL;

  V_SEQ       MIL_QA_RACK.SEQ%TYPE := NULL;
  V_MAT_NO    PORT_MIL_BATCH_SAMPLE_RESULT.MAT_NO%TYPE := NULL;
  V_COUNT     PORT_MIL_BATCH_SAMPLE_RESULT.ACT_COUNT%TYPE := NULL;
  V_ABRVITION SLM_ORDER_HEAD.ABRVITION%TYPE := NULL;
  V_COUNT1    MIL_PLAN.BRANCH%TYPE := 0;

  V_JUDGE_STOVE_NO1   MIL_OFFLINE_RESLUT.JUDGE_STOVE_NO%TYPE := ?;
  V_PLINE_CODE        MIL_OFFLINE_RESLUT.PLINE_CODE%TYPE := ?;
  V_JUDGE_STOVE_NO_ZP MIL_OFFLINE_RESLUT.JUDGE_STOVE_NO%TYPE := ?;
  V_PRO_PLAN_ID       MIL_OFFLINE_RESLUT.PRO_PLAN_ID%TYPE := NULL;
  V_GX_PLAN_NO        MIL_OFFLINE_RESLUT.GX_PLAN_NO%TYPE := NULL;
  V_STORAGE_NO        MIL_ENTRUSTED_BILL.ENTRUSTED_PLINE_CODE%TYPE := NULL;

  V_ORDER_NO    PLN_ORDER_ZG_S.ORDER_NO%TYPE := ?; --合同号
  V_CONTRACT_NO MIL_PLAN.CONTRACT_NO%TYPE := ?; --合同号（带序号）

  V_PRO_PLAN_ID_G   MIL_PLAN.PRO_PLAN_ID%TYPE := NULL; --轧管订单编号
  V_GX_PLAN_NO_G    MIL_PLAN.GX_PLAN_NO%TYPE := NULL; --工序排产序号
  V_ORD_LN_DLY_PK_G MIL_PLAN.ORD_LN_DLY_PK%TYPE := NULL;
  V_CRAFT_SEQ_G     MIL_PLAN.CRAFT_SEQ%TYPE := NULL;
  V_CIC_G           MIL_PLAN.CIC%TYPE := NULL;
  V_INDEX_SEQ_G     MIL_PLAN.INDEX_SEQ%TYPE := NULL;
  V_PIC_G           MIL_PLAN.PIC%TYPE := NULL;
  V_IF_PRODUCT_G    MIL_PLAN.IF_PRODUCT%TYPE := NULL;
BEGIN
  SELECT T.PRO_PLAN_ID, T.GX_PLAN_NO
    INTO V_PRO_PLAN_ID, V_GX_PLAN_NO
    FROM MIL_PLAN T
   WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO_ZP
     AND T.PLINE_CODE = V_PLINE_CODE;

  /* SELECT PLINE_CODE
  INTO V_STORAGE_NO
  FROM (SELECT T.ENTRUSTED_PLINE_CODE PLINE_CODE
          FROM MIL_ENTRUSTED_BILL T
         WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO1
           AND T.PLINE_CODE = V_PLINE_CODE
           AND T.SUBCONTRACT_FLAG = '1'
           AND T.ENTRUSTED_FLAG = '1'
        UNION ALL
        
        SELECT T.SUBCONTRACT_PLINE_CODE PLINE_CODE
          FROM HTT_ENTRUST T
         WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO1
           AND T.PLINE_CODE =V_PLINE_CODE);*/

  SELECT COUNT(1)
    INTO V_COUNT1
    FROM SLM_ORDER_HEAD T
   WHERE T.VALIDFLAG = '1'
     AND T.ORDER_NO = V_ORDER_NO;
  IF (V_COUNT1 > 0) THEN
    select max((select c.ABRVITION
                 from slm_base_customer c
                where c.customer_no = t1.FINAL_USER))
      into V_ABRVITION
      from pln_order_zg_s t, pln_saleord t1
     where t1.ord_ln_dly_pk = t.ord_ln_dly_pk
       and t.ORDER_NO = V_ORDER_NO;
  END IF;

  --改交合同的轧管订单编号
  SELECT COUNT(1)
    INTO V_COUNT1
    FROM PLN_SALEORD T3, PLN_ORDER_ZG_S S1
   WHERE T3.ORD_LN_DLY_PK = S1.ORD_LN_DLY_PK
     AND S1.EXE_STATUS = '0'
     AND T3.ORDER_NO || '/' || T3.ORDER_SEQ = V_CONTRACT_NO;

  IF (V_COUNT1 > 0) THEN
    SELECT MAX(T3.ORD_LN_DLY_PK),
           MAX(S1.PRO_PLAN_ID),
           MAX(S1.GX_PLAN_NO),
           MAX(S1.CRAFT_SEQ),
           MAX(S1.CIC),
           MAX(S1.INDEX_SEQ),
           MAX(S1.PIC)
      INTO V_ORD_LN_DLY_PK_G,
           V_PRO_PLAN_ID_G,
           V_GX_PLAN_NO_G,
           V_CRAFT_SEQ_G,
           V_CIC_G,
           V_INDEX_SEQ_G,
           V_PIC_G
      FROM PLN_SALEORD T3, PLN_ORDER_ZG_S S1
     WHERE T3.ORD_LN_DLY_PK = S1.ORD_LN_DLY_PK
       AND S1.EXE_STATUS = '0'
       AND T3.ORDER_NO || '/' || T3.ORDER_SEQ = V_CONTRACT_NO;
  END IF;
  --生成新炉号
  SELECT REGEXP_REPLACE(?, '-.*', '') || '-' ||
         LPAD(NVL(MAX(SUBSTR(T.JUDGE_STOVE_NO, -2)), 0) + 1, 2, 0) JUDGE_STOVE_NO
    INTO V_JUDGE_STOVE_NO
    FROM MIL_PLAN T
   WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') =
         REGEXP_REPLACE(V_JUDGE_STOVE_NO1, '-.*', '')
     AND T.PLINE_CODE = V_PLINE_CODE;
  --生成主键
  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 = ?
     AND INSTR(T.ID, '-') = 0
     AND TO_CHAR(T.TOM, 'YYYY-MM-DD') = TO_CHAR(SYSDATE, 'YYYY-MM-DD');
  --生成操作ID
  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_OFFLINE_RESULT_DETIA T
   WHERE TO_CHAR(T.COL_TIME, '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_JUDGE_STOVE_NO
     AND T.PLINE_CODE = ?;

  FOR MYROW IN (SELECT *
                  FROM MIL_PLAN T
                 WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO_ZP
                   AND T.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,
       CODE_SAMPLE_FLAG,
       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,
       TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
       TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
       TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
       '',
       '96',
       MYROW.CUT_HEAD_LENGTHP,
       MYROW.CUT_TRAIL_LENGTHP,
       MYROW.CONTROL_THICKP,
       '2',
       '0',
       '',
       MYROW.CUT_TYPE,
       '0',
       MYROW.PRODUCE_STANDRAD,
       MYROW.SIMPLE_PROCESS,
       '1',
       '10',
       MYROW.FEED_TIME,
       MYROW.ID,
       MYROW.SEQ,
       MYROW.STOVE_NO,
       V_JUDGE_STOVE_NO,
       ?,
       --MYROW.CONTRACT_NO,
       ?,
       MYROW.IMP_PROCESS,
       MYROW.PLINE_CODE,
       '96',
       MYROW.PRODUCER,
       MYROW.PROCESS_STATUS,
       MYROW.DB_LENGTH,
       MYROW.DB_HEIGHT,
       MYROW.ROLL_LENGTH,
       MYROW.SAW_NUM,
       --MYROW.TARGET_LENGTH,
       ?,
       V_ABRVITION,
       MYROW.TARGET_LIABRARY,
       --MYROW.VARIETIES,
       ?,
       --MYROW.PIPE_SIZE,
       ?,
       --MYROW.BUCKLE_TYPE,
       ?,
       ?,
       --MYROW.LENGTH_RANGE,
       MYROW.ROLL_STANDRAD,
       --?,
       MYROW.PIPE_SECTION,
       --MYROW.STEELCODE,
       --MYROW.STEELNAME,
       NVL(?, MYROW.STEELCODE),
       NVL(?, MYROW.STEELNAME),
       MYROW.GRADECODE,
       MYROW.GRADENAME,
       MYROW.CODE_SAMPLE_FLAG,
       DECODE(MYROW.CONTRACT_NO,
              V_CONTRACT_NO,
              MYROW.ORD_LN_DLY_PK,
              V_ORD_LN_DLY_PK_G),
       MYROW.PRT_FLAG,
       DECODE(MYROW.CONTRACT_NO,
              V_CONTRACT_NO,
              MYROW.PRO_PLAN_ID,
              V_PRO_PLAN_ID_G),
       DECODE(MYROW.CONTRACT_NO,
              V_CONTRACT_NO,
              MYROW.GX_PLAN_NO,
              V_GX_PLAN_NO_G),
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       DECODE(MYROW.CONTRACT_NO,
              V_CONTRACT_NO,
              MYROW.CRAFT_SEQ,
              V_CRAFT_SEQ_G),
       DECODE(MYROW.CONTRACT_NO, V_CONTRACT_NO, MYROW.CIC, V_CIC_G),
       DECODE(MYROW.CONTRACT_NO,
              V_CONTRACT_NO,
              MYROW.INDEX_SEQ,
              V_INDEX_SEQ_G),
       DECODE(MYROW.CONTRACT_NO, V_CONTRACT_NO, MYROW.PIC, V_PIC_G),
       MYROW.IF_PRODUCT,
       MYROW.PRDCR_NO,
       MYROW.IF_MONITOR);
  
    INSERT INTO MIL_OFFLINE_RESULT_DETIA
      (LOT_NO,
       JUDGE_STOVE_NO,
       OPERATION_TYPE,
       ACT_COUNT,
       ACT_WEIGHT,
       COL_TIME,
       REMARK,
       COL_USER,
       COL_GROUP,
       COL_SHIFT,
       OPERATION_ID,
       PLINE_CODE,
       ID,
       OFFLINE_TYPE,
       BACK_JUDGE_STOVE_NO)
    VALUES
      (?,
       ?,
       '3',
       ?,
       ?,
       DECODE(?, '', SYSDATE, SYSDATE), --TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),同操作ID一样用数据库时间
       ?,
       ?,
       ?,
       ?,
       V_OPERATION_ID,
       MYROW.PLINE_CODE,
       MYROW.ID,
       ?,
       V_JUDGE_STOVE_NO);
    UPDATE MIL_OFFLINE_RESLUT T
       SET T.BACKLINE_NUM = TO_NUMBER(T.BACKLINE_NUM) + TO_NUMBER(?)
     WHERE T.JUDGE_STOVE_NO = ?
       AND T.LOT_NO = ?
       AND T.PLINE_CODE = ?
       AND T.OFFLINE_PRO = 'XX';
    SELECT T.OFFLINE_NUM, (T.GROUP_NUM + T.BACKLINE_NUM + T.RECHECK_NUM)
      INTO V_OFFLINE_NUM, V_TOTAL_COUNT
      FROM MIL_OFFLINE_RESLUT T
     WHERE T.JUDGE_STOVE_NO = ?
       AND T.LOT_NO = ?
       AND T.PLINE_CODE = ?
       AND T.OFFLINE_PRO = 'XX';
    --IF (V_OFFLINE_NUM = ?) THEN
    UPDATE MIL_OFFLINE_RESLUT T
       SET T.STATUS = '1'
     WHERE T.JUDGE_STOVE_NO = ?
       AND T.LOT_NO = ?
       AND T.PLINE_CODE = ?
       AND T.OFFLINE_PRO = 'XX';
    --END IF;
  END LOOP;
  FOR MYROW IN (SELECT *
                  FROM (SELECT *
                          FROM PORT_MIL_BATCH_SAMPLE_RESULT T
                         WHERE T.JUDGE_STOVE_NO = ?
                           AND T.LOT_NO = ?
                           AND T.PLINE_CODE = ?
                           AND T.STATUS = '3'
                           AND T.OP_PROCESS = '12'
                         ORDER BY T.MAT_NO ASC)
                 WHERE ROWNUM <= ?) LOOP
    V_COUNT := 1;
    WHILE (V_COUNT <= ?) LOOP
      V_MAT_NO := MYROW.MAT_NO || V_COUNT;
      INSERT INTO PORT_MIL_BATCH_SAMPLE_RESULT
        (PLAN_ID,
         LOT_NO,
         JUDGE_STOVE_NO,
         PLINE_CODE,
         BATCH_NO,
         SEQ,
         MAT_NO,
         IS_SAMPLE_PIPE,
         SAMPLE_PIPE_LEN,
         GET_SAMPLE_NAME,
         GET_SAMPLE_TIME,
         GET_SAMPLE_SHIFT,
         GET_SAMPLE_CLASS,
         ORDER_LENGTH,
         ACT_THEORY_WEIGHT,
         ACT_COUNT,
         CRATE_TIME,
         M_MAT_NO,
         M_M_MAT_NO,
         INPUT_WEIGHT,
         PRO_PLAN_ID,
         GX_PLAN_NO,
         BAL_YEAR_MONTH,
         -- STORAGE_NO,
         MEASURE_LEN,
         MEASURE_WEIGHT,
         MEASURING_SEQ,
         MAT_INFO,
         MEASURING_FLAG,
         MEASURE_RESULT_NO,
         ACT_THEORY_WEIGHT_BAK)
      VALUES
        (MYROW.PLAN_ID,
         ?,
         V_JUDGE_STOVE_NO,
         MYROW.PLINE_CODE,
         MYROW.BATCH_NO,
         V_SEQ,
         V_MAT_NO,
         MYROW.IS_SAMPLE_PIPE,
         MYROW.SAMPLE_PIPE_LEN,
         MYROW.GET_SAMPLE_NAME,
         MYROW.GET_SAMPLE_TIME,
         MYROW.GET_SAMPLE_SHIFT,
         MYROW.GET_SAMPLE_CLASS,
         NVL(?, MYROW.ORDER_LENGTH),
         TO_NUMBER(MYROW.ACT_THEORY_WEIGHT) / ?,
         MYROW.ACT_COUNT,
         SYSDATE,
         MYROW.M_MAT_NO,
         MYROW.M_M_MAT_NO,
         TO_NUMBER(MYROW.INPUT_WEIGHT) / ?,
         V_PRO_PLAN_ID,
         V_GX_PLAN_NO,
         MYROW.BAL_YEAR_MONTH,
         --V_STORAGE_NO,
         MYROW.MEASURE_LEN,
         MYROW.MEASURE_WEIGHT,
         MYROW.MEASURING_SEQ,
         MYROW.MAT_INFO,
         MYROW.MEASURING_FLAG,
         MYROW.MEASURE_RESULT_NO,
         MYROW.ACT_THEORY_WEIGHT_BAK);
    
      V_COUNT := V_COUNT + 1;
      V_SEQ   := V_SEQ + 1;
    
    END LOOP;
    UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T
       SET T.STATUS = '4', T.BACK_PROCESS = '12'
     WHERE T.JUDGE_STOVE_NO = ?
       AND T.MAT_NO = MYROW.MAT_NO;
  END LOOP;
  FOR MYROW2 IN (SELECT *
                   FROM (SELECT T.MAT_NO
                           FROM PORT_MIL_BATCH_SAMPLE_RESULT T
                          WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
                          ORDER BY T.IS_SAMPLE_PIPE ASC, T.MAT_NO DESC)
                  WHERE ROWNUM <= ?) LOOP
    UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T
       SET T.STATUS = '6', T.OP_PROCESS = '13'
     WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
       AND T.MAT_NO = MYROW2.MAT_NO;
  
  END LOOP;
END;
]]>
<query id = "FrmDownlineManage.backPipePort" desc = "插入进程表管号队列">
<![CDATA[
DECLARE
  V_ID             MIL_PLAN.ID%TYPE := NULL;
  V_JUDGE_STOVE_NO MIL_PLAN.JUDGE_STOVE_NO%TYPE := NULL;
  V_SEQ            MIL_QA_RACK.SEQ%TYPE := NULL;
  V_MAT_NO         PORT_MIL_BATCH_SAMPLE_RESULT.MAT_NO%TYPE := NULL;
  V_COUNT          PORT_MIL_BATCH_SAMPLE_RESULT.ACT_COUNT%TYPE :=NULL;
BEGIN
  V_COUNT:=1;
  --生成新炉号
  SELECT REGEXP_REPLACE(?, '-.*', '') || '-' ||
         LPAD(NVL(MAX(SUBSTR(T.JUDGE_STOVE_NO, -2)), 0) + 1, 2, 0) JUDGE_STOVE_NO
    INTO V_JUDGE_STOVE_NO
    FROM MIL_PLAN T
   WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = REGEXP_REPLACE(?, '-.*', '')
     AND T.PLINE_CODE = ?;
  --生成主键
  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 = ?
   AND INSTR(T.ID, '-') = 0
     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_JUDGE_STOVE_NO
     AND T.PLINE_CODE = ?;
  FOR MYROW IN (SELECT *
                  FROM (SELECT *
                          FROM PORT_MIL_BATCH_SAMPLE_RESULT T
                         WHERE T.JUDGE_STOVE_NO = ?
                           AND T.LOT_NO = ?
                           AND T.PLINE_CODE = ?
                           AND T.STATUS = '3'
                           AND T.OP_PROCESS = '12'
                         ORDER BY T.MAT_NO ASC)
                 WHERE ROWNUM <= ?) LOOP
    WHILE (V_COUNT <= ?) LOOP
      V_MAT_NO := MYROW.MAT_NO || V_COUNT;
      BEGIN
        INSERT INTO PORT_MIL_BATCH_SAMPLE_RESULT
          (PLAN_ID,
           LOT_NO,
           JUDGE_STOVE_NO,
           PLINE_CODE,
           BATCH_NO,
           SEQ,
           MAT_NO,
           IS_SAMPLE_PIPE,
           SAMPLE_PIPE_LEN,
           GET_SAMPLE_NAME,
           GET_SAMPLE_TIME,
           GET_SAMPLE_SHIFT,
           GET_SAMPLE_CLASS,
           ORDER_LENGTH,
           ACT_THEORY_WEIGHT,
           ACT_COUNT,
           CRATE_TIME,
           M_MAT_NO,
           M_M_MAT_NO,
           INPUT_WEIGHT)
        VALUES
          (MYROW.PLAN_ID,
           ?,
           V_JUDGE_STOVE_NO,
           MYROW.PLINE_CODE,
           MYROW.BATCH_NO,
           V_SEQ,
           V_MAT_NO,
           '0',
           '',
           '',
           '',
           '',
           '',
           ?,
           '',
           MYROW.ACT_COUNT,
           SYSDATE,
           MYROW.M_MAT_NO,
           MYROW.M_M_MAT_NO,
           MYROW.INPUT_WEIGHT/?);
           V_COUNT:= V_COUNT + 1;
        V_SEQ := V_SEQ + 1;
      END;
    END LOOP;
    UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T
       SET T.STATUS = '4', T.BACK_PROCESS = '12'
     WHERE T.JUDGE_STOVE_NO = ?
       AND T.MAT_NO = MYROW.MAT_NO;
  END LOOP;
  FOR MYROW2 IN (SELECT *
                   FROM (SELECT T.MAT_NO
                           FROM PORT_MIL_BATCH_SAMPLE_RESULT T
                          WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
                          ORDER BY T.MAT_NO DESC)
                  WHERE ROWNUM <= ?) LOOP
    UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T
       SET T.STATUS = '6', T.OP_PROCESS = '13'
     WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
       AND T.MAT_NO = MYROW2.MAT_NO;
       UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T SET T.IS_SAMPLE_PIPE = '1' WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO AND T.STATUS = '0' AND ROWNUM = 2;
  END LOOP;
END;
]]>
</query>
	</query>
<query id = "doBackLine.deleteMat" desc = "消除库存">
<![CDATA[
DECLARE
  V_COUNT MIL_OFFLINE_RESLUT.OFFLINE_NUM%TYPE := NULL;
BEGIN
  FOR MYROW IN (SELECT *
                  FROM (SELECT T.MAT_NO
                          FROM MAT_BC_M T, YDM_BC_BUTTRESS S
                         WHERE T.MAT_NO = S.MAT_NO
                         AND T.ZG_STOVE_SQE = ?
                         ORDER BY T.MAT_NO DESC)
                         WHERE ROWNUM <= ?) LOOP
                   DELETE FROM YDM_BC_BUTTRESS S WHERE S.MAT_NO = MYROW.MAT_NO;
  END LOOP;
  --UPDATE MIL_OFFLINE_RESLUT T SET T.INSTORAGE_NUM = TO_NUMBER(T.INSTORAGE_NUM)-TO_NUMBER(?) WHERE T.JUDGE_STOVE_NO = ? AND T.LOT_NO = ? AND T.OFFLINE_TYPE = ?;
END;
]]>
</query>
<query id = "doBackLine.selectMat" desc = "查询库存现有支数">
SELECT COUNT(1) ACOUNT FROM MAT_BC_M T,YDM_BC_BUTTRESS S WHERE T.MAT_NO = S.MAT_NO AND T.ZG_STOVE_SQE = ? AND T.BATCH_NO = 'X'
</query>
<query id = "doBackLine.insertRack" desc = "探伤返线插入管号队列">
<![CDATA[
DECLARE
  V_ID             MIL_PLAN.ID%TYPE := NULL;
  V_JUDGE_STOVE_NO MIL_PLAN.JUDGE_STOVE_NO%TYPE := NULL;
  V_SEQ            MIL_QA_RACK.SEQ%TYPE := NULL;
BEGIN
  --生成新炉号
  SELECT REGEXP_REPLACE(?, '-.*', '') || '-' ||
         LPAD(NVL(MAX(SUBSTR(T.JUDGE_STOVE_NO, -2)), 0) + 1, 2, 0) JUDGE_STOVE_NO
    INTO V_JUDGE_STOVE_NO
    FROM MIL_PLAN T
   WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') =
         REGEXP_REPLACE(?, '-.*', '')
     AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
     AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
     AND T.PLINE_CODE = ?;
  --生成主键
  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 = ?
     AND INSTR(T.ID, '-') = 0
        --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 MIL_TESTING_RACK T
   WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
     AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
     AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
     AND T.PLINE_CODE = ?;
  FOR MYROW IN (SELECT *
                  FROM (SELECT *
                          FROM PORT_MIL_BATCH_SAMPLE_RESULT T
                         WHERE T.JUDGE_STOVE_NO = ?
                           AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
                           AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
                           AND T.LOT_NO = ?
                           AND T.PLINE_CODE = ?
                           AND T.Status = '3'
                           AND T.Op_Process = '10'
                           AND T.GROUP_FLAG = ?
                         ORDER BY T.SEQ ASC)
                 WHERE ROWNUM <= ?) LOOP
    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,
       PRO_PLAN_ID,
       GX_PLAN_NO)
    VALUES
      (MYROW.MAT_NO,
       ?,
       V_JUDGE_STOVE_NO,
       ?,
       '',
       '',
       '1',
       TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
       V_SEQ,
       MYROW.Plan_Id,
       MYROW.Order_Length,
       ?,
       ?);
    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,
       PRO_PLAN_ID,
       GX_PLAN_NO)
    VALUES
      ('',
       ?,
       V_JUDGE_STOVE_NO,
       ?,
       '',
       '',
       '1',
       TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
       V_SEQ,
       MYROW.PLAN_ID,
       MYROW.Order_Length,
       ?,
       ?);
  
    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,
       SAMPLE_PIPE_LEN,
       GET_SAMPLE_NAME,
       GET_SAMPLE_TIME,
       GET_SAMPLE_SHIFT,
       GET_SAMPLE_CLASS,
       ORDER_LENGTH,
       ACT_THEORY_WEIGHT,
       ACT_COUNT,
       CRATE_TIME,
       M_MAT_NO,
       M_M_MAT_NO,
       INPUT_WEIGHT,
       BAL_YEAR_MONTH,
       PRO_PLAN_ID,
       GX_PLAN_NO,
       MEASURE_LEN,
       MEASURE_WEIGHT,
       MEASURING_SEQ,
       MAT_INFO,
       MEASURING_FLAG,
       MEASURE_RESULT_NO,
       ACT_THEORY_WEIGHT_BAK)
    VALUES
      (MYROW.PLAN_ID,
       ?,
       ?,
       V_JUDGE_STOVE_NO,
       MYROW.PLINE_CODE,
       MYROW.BATCH_NO,
       V_SEQ,
       MYROW.MAT_NO,
       MYROW.IS_SAMPLE_PIPE,
       MYROW.SAMPLE_PIPE_LEN,
       MYROW.GET_SAMPLE_NAME,
       MYROW.GET_SAMPLE_TIME,
       MYROW.GET_SAMPLE_SHIFT,
       MYROW.GET_SAMPLE_CLASS,
       MYROW.ORDER_LENGTH,
       MYROW.ACT_THEORY_WEIGHT,
       MYROW.ACT_COUNT,
       SYSDATE,
       MYROW.M_MAT_NO,
       MYROW.M_M_MAT_NO,
       MYROW.INPUT_WEIGHT,
       MYROW.BAL_YEAR_MONTH,
       ?,
       ?,
       MYROW.MEASURE_LEN,
       MYROW.MEASURE_WEIGHT,
       MYROW.MEASURING_SEQ,
       MYROW.MAT_INFO,
       MYROW.MEASURING_FLAG,
       MYROW.MEASURE_RESULT_NO,
       MYROW.ACT_THEORY_WEIGHT_BAK);
  
    UPDATE MIL_TESTING_RACK T
       SET T.OFFLINE_FLAG = '2'
     WHERE T.JUDGE_STOVE_NO = ?
       AND T.LOT_NO = ?
       AND T.PLINE_CODE = ?
       AND T.MAT_NO = MYROW.MAT_NO;
    UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T
       SET T.STATUS = '4', T.BACK_PROCESS = '10'
     WHERE T.JUDGE_STOVE_NO = ?
       AND T.MAT_NO = MYROW.MAT_NO;
    V_SEQ := V_SEQ + 1;
  END LOOP;
END;

]]>
</query>
<query id = "doBackStaightLine.insertRack" desc = "矫直返线插入管号队列">
<![CDATA[
DECLARE
  V_ID             MIL_PLAN.ID%TYPE := NULL;
  V_JUDGE_STOVE_NO MIL_PLAN.JUDGE_STOVE_NO%TYPE := NULL;
  V_SEQ            MIL_QA_RACK.SEQ%TYPE := NULL;
BEGIN
  --生成新炉号
  SELECT REGEXP_REPLACE(?, '-.*', '') || '-' ||
         LPAD(NVL(MAX(SUBSTR(T.JUDGE_STOVE_NO, -2)), 0) + 1, 2, 0) JUDGE_STOVE_NO
    INTO V_JUDGE_STOVE_NO
    FROM MIL_PLAN T
   WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') =
         REGEXP_REPLACE(?, '-.*', '')
     AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
     AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
     AND T.PLINE_CODE = ?;
  --生成主键
  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 = ?
     AND INSTR(T.ID, '-') = 0
        --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 MIL_STRAIGH_RACK T
   WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
     AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
     AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
     AND T.PLINE_CODE = ?;
  FOR MYROW IN (SELECT *
                  FROM (SELECT *
                          FROM PORT_MIL_BATCH_SAMPLE_RESULT T
                         WHERE T.JUDGE_STOVE_NO = ?
                           AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
                           AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
                           AND T.LOT_NO = ?
                           AND T.PLINE_CODE = ?
                           AND T.STATUS = '3'
                           AND T.OP_PROCESS = '9'
                         ORDER BY T.SEQ ASC)
                 WHERE ROWNUM <= ?) 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,
       PRO_PLAN_ID,
       GX_PLAN_NO)
    VALUES
      (MYROW.MAT_NO,
       ?,
       V_JUDGE_STOVE_NO,
       ?,
       '',
       '',
       '1',
       TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
       V_SEQ,
       MYROW.Plan_Id,
       MYROW.Order_Length,
       '1',
       MYROW.PRO_PLAN_ID,
       MYROW.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,
       PRO_PLAN_ID,
       GX_PLAN_NO)
    VALUES
      (MYROW.MAT_NO,
       ?,
       V_JUDGE_STOVE_NO,
       ?,
       '',
       '',
       '1',
       TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
       V_SEQ,
       MYROW.Plan_Id,
       MYROW.Order_Length,
       MYROW.PRO_PLAN_ID,
       MYROW.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,
       PRO_PLAN_ID,
       GX_PLAN_NO)
    VALUES
      ('',
       ?,
       V_JUDGE_STOVE_NO,
       ?,
       '',
       '',
       '1',
       TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
       V_SEQ,
       MYROW.Plan_Id,
       MYROW.Order_Length,
       MYROW.PRO_PLAN_ID,
       MYROW.GX_PLAN_NO);
    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,
       SAMPLE_PIPE_LEN,
       GET_SAMPLE_NAME,
       GET_SAMPLE_TIME,
       GET_SAMPLE_SHIFT,
       GET_SAMPLE_CLASS,
       ORDER_LENGTH,
       ACT_THEORY_WEIGHT,
       ACT_COUNT,
       CRATE_TIME,
       M_MAT_NO,
       M_M_MAT_NO,
       INPUT_WEIGHT,
       BAL_YEAR_MONTH,
       PRO_PLAN_ID,
       GX_PLAN_NO,
       MEASURE_LEN,
       MEASURE_WEIGHT,
       MEASURING_SEQ,
       MAT_INFO,
       MEASURING_FLAG,
       MEASURE_RESULT_NO,
       ACT_THEORY_WEIGHT_BAK)
    VALUES
      (MYROW.PLAN_ID,
       ?,
       ?,
       V_JUDGE_STOVE_NO,
       MYROW.PLINE_CODE,
       MYROW.BATCH_NO,
       V_SEQ,
       MYROW.MAT_NO,
       MYROW.IS_SAMPLE_PIPE,
       MYROW.SAMPLE_PIPE_LEN,
       MYROW.GET_SAMPLE_NAME,
       MYROW.GET_SAMPLE_TIME,
       MYROW.GET_SAMPLE_SHIFT,
       MYROW.GET_SAMPLE_CLASS,
       MYROW.ORDER_LENGTH,
       MYROW.ACT_THEORY_WEIGHT,
       MYROW.ACT_COUNT,
       SYSDATE,
       MYROW.M_MAT_NO,
       MYROW.M_M_MAT_NO,
       MYROW.INPUT_WEIGHT,
       MYROW.BAL_YEAR_MONTH,
       MYROW.PRO_PLAN_ID,
       MYROW.GX_PLAN_NO,
       MYROW.MEASURE_LEN,
       MYROW.MEASURE_WEIGHT,
       MYROW.MEASURING_SEQ,
       MYROW.MAT_INFO,
       MYROW.MEASURING_FLAG,
       MYROW.MEASURE_RESULT_NO,
       MYROW.ACT_THEORY_WEIGHT_BAK);
  
    UPDATE MIL_STRAIGH_RACK T
       SET T.OFFLINE_FLAG = '2'
     WHERE T.JUDGE_STOVE_NO = ?
       AND T.LOT_NO = ?
       AND T.PLINE_CODE = ?
       AND T.MAT_NO = MYROW.MAT_NO;
    UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T
       SET T.STATUS = '4', T.BACK_PROCESS = '9'
     WHERE T.JUDGE_STOVE_NO = ?
       AND T.MAT_NO = MYROW.MAT_NO;
    V_SEQ := V_SEQ + 1;
  END LOOP;
END;

]]>
</query>
<query id = "FrmDownlineManage.doQuerySubContractNo" desc = "生成委外单号">
SELECT ? || TO_CHAR(SYSDATE, 'YYMMDD') ||
         LPAD(NVL(MAX(SUBSTR(T.SUBCONTRACT_NO, 11)), 0) + 1, 3, 0) SUBCONTRACT_NO
    FROM MIL_ENTRUSTED_BILL T
   WHERE T.PLINE_CODE = ?
     AND TO_CHAR(T.ENTRUSTED_TIME, 'YYYY-MM-DD') =
         TO_CHAR(SYSDATE, 'YYYY-MM-DD')
</query>
<query id = "FrmDownlineManage.doQuerySubContractNoSeq" desc = "生成委外流水号">
SELECT ? ||
       LPAD(NVL(MAX(SUBSTR(T.SUBCONTRACT_NO_SEQ, LENGTH(T.SUBCONTRACT_NO_SEQ) - 3)), 0) + 1,
            3,
            0) SUBCONTRACT_NO_SEQ
  FROM MIL_ENTRUSTED_BILL T
 WHERE T.SUBCONTRACT_NO = ?
</query>
<query id = "FrmDownlineManage.doSubcontract" desc = "委外加工">
DECLARE
  V_SUBCONTRACTNO MIL_ENTRUSTED_BILL.SUBCONTRACT_NO%TYPE := NULL;
  V_OFFLINECOUNT  MIL_OFFLINE_RESLUT.Offline_Num%TYPE := NULL;
  V_TOTALOUNT     MIL_OFFLINE_RESLUT.Offline_Num%TYPE := NULL;
BEGIN
  INSERT INTO MIL_ENTRUSTED_BILL
    (SUBCONTRACT_NO_SEQ,
     SUBCONTRACT_NO,
     LOT_NO,
     STOVE_NO,
     JUDGE_STOVE_NO,
     PLINE_CODE,
     OFFLINE_PRO,
     
     SUBCONTRACT_NUM,
     ENTRUSTED_TIME,
     REMARK,
     COL_USER,
     COL_SHIFT,
     COL_GROUP,
     SUBCONTRACT_FLAG,
     OFFLINE_TYPE,
     SUBCONTRACT_WGT,
     CRAFT_FILE_NO,
     STEEL_PIPE_PROCESS,
     UL_TESTING,
     SUBCONTRACT_TYPE,
     TESTING_GRADE,
     TESTING_TYPE,
     PRO_PLAN_ID,
     GX_PLAN_NO)
  VALUES
    (?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?);
  UPDATE MIL_OFFLINE_RESLUT T
     SET T.SUBCONTRACT_NUM = ?
   WHERE T.JUDGE_STOVE_NO = ?
     AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
     AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
     AND T.LOT_NO = ?
     AND T.STATUS = '0'
     AND T.OFFLINE_TYPE = ?
     AND T.OFFLINE_PRO = ?;
  SELECT T.OFFLINE_NUM,
         (T.BACKLINE_NUM + T.GROUP_NUM + T.RECHECK_NUM + T.INSTORAGE_NUM +
         T.SUBCONTRACT_NUM - T.SUBCONTRACTCOMPLETE_NUM)
    INTO V_OFFLINECOUNT, V_TOTALOUNT
    FROM MIL_OFFLINE_RESLUT T
   WHERE T.JUDGE_STOVE_NO = ?
     AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
     AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
     AND T.LOT_NO = ?
     AND T.STATUS = '0'
     AND T.OFFLINE_TYPE = ?
     AND T.OFFLINE_PRO = ?;
  IF (V_OFFLINECOUNT = V_TOTALOUNT) THEN
    UPDATE MIL_OFFLINE_RESLUT T
       SET T.STATUS = '1'
     WHERE T.JUDGE_STOVE_NO = ?
       AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
       AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
       AND T.LOT_NO = ?
       AND T.STATUS = '0'
       AND T.OFFLINE_TYPE = ?
       AND T.OFFLINE_PRO = ?;
  END IF;
END;
</query>
<query id = "FrmDownlineManage.doQuerySubcontract" desc = "查询委外实绩">
<![CDATA[
SELECT T.SUBCONTRACT_NO,
       T.LOT_NO,
       T.STOVE_NO,
       T.JUDGE_STOVE_NO,
       (SELECT T1.PLINE_NAME FROM COM_BASE_PLINE T1 WHERE T1.PLINE_CODE = T.PLINE_CODE)PLINE_CODE,
       T.OFFLINE_PRO,
       T.BACKLINE_NUM,
       T.SUBCONTRACTCOMPLETE_NUM,
       T.SUBCONTRACT_NUM,
       T.SUBCONTRACT_COMPLETE_WGT,
       TO_CHAR(T.ENTRUSTED_TIME, 'YYYY-MM-DD HH24:MI:SS') ENTRUSTED_TIME,
       T.REMARK,
       T.SUBCONTRACT_FLAG,
       T.OFFLINE_TYPE,
       T.SUBCONTRACTSCRAP_NUM,
       T.ENTRUSTED_FLAG,
       T.ENTRUSTED_PLINE_CODE,
       T.ENTRUSTED_PLINE_NAME,
       T.ENTRUSTED_REMARK,
       T.SUBCONTRACT_WGT,
       T.CRAFT_FILE_NO,
       T.STEEL_PIPE_PROCESS,
       T.UL_TESTING,
       DECODE(T.COL_SHIFT,
              '0',
              '常白班',
              '1',
              '早班',
              '2',
              '中班',
              '3',
              '晚班') COL_SHIFT,
       DECODE(T.COL_GROUP,
              '1',
              '甲班',
              '2',
              '乙班',
              '3',
              '丙班',
              '4',
              '丁班') COL_GROUP,
              T.SUBCONTRACT_NO_SEQ
  FROM MIL_ENTRUSTED_BILL T
 WHERE 1=1
   ]]>
</query>
<query id = "FrmDownlineManage.subcontractComplete" desc = "回报委外加工实绩">
<![CDATA[
DECLARE
  V_OFFLINECOUNT MIL_OFFLINE_RESLUT.Offline_Num%TYPE := NULL;
  V_TOTALOUNT    MIL_OFFLINE_RESLUT.Offline_Num%TYPE := NULL;
BEGIN
  UPDATE MIL_ENTRUSTED_BILL T
     SET T.SUBCONTRACTCOMPLETE_NUM  = ?,
         T.SUBCONTRACTSCRAP_NUM     = ?,
         T.SUBCONTRACT_COMPLETE_WGT = ?,
         T.SUBCONTRACT_COMPLETE_LEN = ?,
         T.SUBCONTRACT_COMPLETE_CUT = ?,
         T.SUBCONTRACT_FLAG         = '1'
   WHERE T.SUBCONTRACT_NO_SEQ = ?;
  UPDATE MIL_OFFLINE_RESLUT T
     SET T.SUBCONTRACTCOMPLETE_NUM = TO_NUMBER(T.SUBCONTRACTCOMPLETE_NUM) +
                                     TO_NUMBER(?),
         T.SUBCONTRACTCOMPLETE_WGT = TO_NUMBER(NVL(T.SUBCONTRACTCOMPLETE_WGT,0)) + TO_NUMBER(?),
         T.SUBCONTRACT_COMPLETE_CUT = ?,
         T.SUBCONTRACT_COMPLETE_LEN = ?,
         T.SUBCONTRACTSCRAP_NUM     = ?                            
   WHERE T.JUDGE_STOVE_NO = ?
     AND T.LOT_NO = ?
     AND T.OFFLINE_TYPE = ?
     AND T.OFFLINE_PRO = ?;
  SELECT T.OFFLINE_NUM,
         (T.BACKLINE_NUM + T.GROUP_NUM + T.RECHECK_NUM + T.INSTORAGE_NUM +
         T.SUBCONTRACT_NUM - T.SUBCONTRACTCOMPLETE_NUM)
    INTO V_OFFLINECOUNT, V_TOTALOUNT
    FROM MIL_OFFLINE_RESLUT T
   WHERE T.JUDGE_STOVE_NO = ?
     AND T.LOT_NO = ?
     AND T.OFFLINE_TYPE = ?
     AND T.OFFLINE_PRO = ?;
  FOR MYROW1 IN (SELECT * FROM (SELECT T.MAT_NO
                   FROM MAT_BC_M T, YDM_BC_BUTTRESS S
                  WHERE T.MAT_NO = S.MAT_NO
                    AND T.ZG_STOVE_SQE = ?
                    AND T.BATCH_NO = 'X'
                    ORDER BY T.MAT_NO DESC) WHERE ROWNUM <= ?) LOOP
                    DELETE FROM MAT_BC_M T WHERE T.MAT_NO= MYROW1.MAT_NO;
                    DELETE FROM YDM_BC_BUTTRESS S WHERE S.MAT_NO = MYROW1.MAT_NO;
                    --DELETE FROM YDM_BC_INLIST T WHERE T.MAT_NO = MYROW1.MAT_NO;
  END LOOP;
  IF (V_OFFLINECOUNT > V_TOTALOUNT) THEN
    UPDATE MIL_OFFLINE_RESLUT T
       SET T.STATUS = '0'
     WHERE T.JUDGE_STOVE_NO = ?
       AND T.LOT_NO = ?
       AND T.OFFLINE_TYPE = ?
       AND T.OFFLINE_PRO = ?;
  END IF;
  IF (? = 0) THEN
    FOR MYROW IN (SELECT * FROM (SELECT T.MAT_NO
                    FROM PORT_MIL_BATCH_SAMPLE_RESULT T
                   WHERE T.JUDGE_STOVE_NO = ?
                   AND T.LOT_NO = ?
                   AND T.STATUS = '3'
                   ORDER BY T.MAT_NO DESC) WHERE ROWNUM <= ?) LOOP
                   UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T SET T.STATUS = '6' WHERE T.JUDGE_STOVE_NO = ? AND T.MAT_NO = MYROW.MAT_NO;
    END LOOP;
  END IF;
END;
]]>
</query>
<query id = "FrmDownlineManage.cancelSubcontractComplete" desc = "撤销委外加工完成">
<![CDATA[
DECLARE
V_OFFLINECOUNT MIL_OFFLINE_RESLUT.Offline_Num%TYPE := NULL;
  V_TOTALOUNT    MIL_OFFLINE_RESLUT.Offline_Num%TYPE := NULL;
BEGIN
  UPDATE MIL_ENTRUSTED_BILL T
     SET T.SUBCONTRACTCOMPLETE_NUM  = '',
         T.SUBCONTRACTSCRAP_NUM     = '',
         T.SUBCONTRACT_COMPLETE_WGT = '',
         T.SUBCONTRACT_COMPLETE_LEN = '',
         T.SUBCONTRACT_COMPLETE_CUT = '',
         T.SUBCONTRACT_FLAG         = '0'
   WHERE T.SUBCONTRACT_NO_SEQ = ?;
  UPDATE MIL_OFFLINE_RESLUT T
     SET T.SUBCONTRACTCOMPLETE_NUM = TO_NUMBER(T.SUBCONTRACTCOMPLETE_NUM) -
                                     TO_NUMBER(?),
         T.SUBCONTRACTCOMPLETE_WGT = TO_NUMBER(NVL(T.SUBCONTRACTCOMPLETE_WGT,0)) - TO_NUMBER(?),
         T.SUBCONTRACT_COMPLETE_CUT = '',
         T.SUBCONTRACT_COMPLETE_LEN = '',
         T.SUBCONTRACTSCRAP_NUM     = ''                            
   WHERE T.JUDGE_STOVE_NO = ?
     AND T.LOT_NO = ?
     AND T.OFFLINE_TYPE = ?
     AND T.OFFLINE_PRO = ?;
  SELECT T.OFFLINE_NUM,
         (T.BACKLINE_NUM + T.GROUP_NUM + T.RECHECK_NUM + T.INSTORAGE_NUM +
         T.SUBCONTRACT_NUM - T.SUBCONTRACTCOMPLETE_NUM)
    INTO V_OFFLINECOUNT, V_TOTALOUNT
    FROM MIL_OFFLINE_RESLUT T
   WHERE T.JUDGE_STOVE_NO = ?
     AND T.LOT_NO = ?
     AND T.OFFLINE_TYPE = ?
     AND T.OFFLINE_PRO = ?;
    UPDATE MIL_OFFLINE_RESLUT T
       SET T.STATUS = '1'
     WHERE T.JUDGE_STOVE_NO = ?
       AND T.LOT_NO = ?
       AND T.OFFLINE_TYPE = ?
       AND T.OFFLINE_PRO = ?;
   IF (? = 0) THEN
    FOR MYROW IN (SELECT * FROM (SELECT T.MAT_NO
                    FROM PORT_MIL_BATCH_SAMPLE_RESULT T
                   WHERE T.JUDGE_STOVE_NO = ?
                   AND T.LOT_NO = ?
                   AND T.STATUS = '6'
                   ORDER BY T.MAT_NO DESC) WHERE ROWNUM <= ?) LOOP
                   UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T SET T.STATUS = '3' WHERE T.JUDGE_STOVE_NO = ? AND T.MAT_NO = MYROW.MAT_NO;
    END LOOP;
  END IF;
END;
]]>
</query>
<query id = "FrmDownlineManage.cancelSubcontract" desc = "撤销委外加工">
DECLARE
BEGIN
  DELETE FROM MIL_ENTRUSTED_BILL T WHERE T.SUBCONTRACT_NO_SEQ = ?;
  UPDATE MIL_OFFLINE_RESLUT T
     SET T.SUBCONTRACT_NUM         = TO_NUMBER(T.SUBCONTRACT_NUM) -
                                     TO_NUMBER(?),
         T.SUBCONTRACTCOMPLETE_NUM = TO_NUMBER(T.SUBCONTRACTCOMPLETE_NUM) -
                                     TO_NUMBER(?),
         T.STATUS                  = '0'          
   WHERE T.Judge_Stove_No = ?
   AND T.LOT_NO = ?
   AND T.OFFLINE_TYPE = ?
   AND T.OFFLINE_PRO = ?;
END;
</query>
<query id = "FrmDownlineManage.SelectSubcontractComplete" desc = "查询委外实绩是否完成">
SELECT T.SUBCONTRACT_FLAG FROM MIL_ENTRUSTED_BILL T WHERE T.SUBCONTRACT_NO_SEQ = ? AND T.JUDGE_STOVE_NO = ?
</query>
<query id = "FrmDownlineManage.doPipe" desc = "入库转移">
DECLARE
  V_INSTOCK_DOC    YDM_BC_INLIST.INSTOCK_DOC%TYPE := NULL; --入库单号
  V_INSTOCK_SQE    YDM_BC_INLIST.INSTOCK_SQE%TYPE := NULL; --入库流水
  V_IMEMO          COM_BASE_INFO.MEMO%TYPE := NULL;
  V_BASENAME       COM_BASE_INFO.BASENAME%TYPE := NULL;
  V_ICOUNT         NUMBER := 1;
  V_TIME           YDM_BC_INLIST.CREATE_TIME%TYPE := SYSDATE;
  V_BATHYEAR       YDM_BC_INLIST.BAL_YEAR_MONTH%TYPE := TO_CHAR(SYSDATE,
                                                                'YYYYMM');
  V_BATCH_GROUD_NO MAT_BC_M.BATCH_GROUD_NO%TYPE := NULL;
  V_OFFLINECOUNT   MIL_OFFLINE_RESLUT.OFFLINE_NUM%TYPE :=NULL;
  V_TOTALOUNT      MIL_OFFLINE_RESLUT.OFFLINE_NUM%TYPE :=NULL;
BEGIN
  INSERT INTO YDM_BC_BUTTRESS
    (JUDGE_STOVE_NO,
     BATCH_NO,
     BATCH_GROUD_NO,
     STORAGE_NO,
     LOCATION_NO,
     STORAGE_TYPE_NO,
     STORAGE_TYPE_NAME,
     CREATE_NAME,
     MAT_NO,
     CREATE_TIME,
     MANAGEMENT_NO,
     MANAGEMENT_NAME,
     DEPARTMENT_CODE,
     DEPARTMENT_DESC)
  VALUES
    (?, ?, ?, ?, ?, ?, ?, ?, ?, V_TIME, ?, ?, ?, ?);
  
  INSERT INTO MAT_BC_M
    (JUDGE_STOVE_NO,
     BATCH_NO,
     BATCH_GROUD_NO,
     PRODUCCODE,
     PRODUCNAME,
     STEELCODE,
     STEELNAME,
     SPEC_CODE,
     SPEC_NAME,
     MODEL_CODE,
     MODEL_DESC,
     STD_CODE,
     STD_NAME,
     BELONG_CODE,
     BELONG_NAME,
     STD_STYLE,
     STD_STYLE_DESC,
     ORDER_NO,
     ORDER_SEQ,
     ORDER_SEQ_NO,
     ORD_PK,
     ORD_LN_PK,
     ORD_LN_DLY_PK,
     ACT_DIMATER,
     ACT_HEIGHT,
     LEN_NO,
     LEN_DESC,
     LEN_UNIT,
     ACT_LEN_MIN,
     ACT_LEN_MAX,
     CREATE_NAME,
     ACT_COUNT,
     ACT_WEIGHT,
     CREATE_TIME,
     INSTOCK_TIME,
     MAT_NO,
     MEMO,
     JUGDE_APPLY_FLAG,
     INSTOCK_FLAG,
     PRODUCT_FLAG,
     MAT_STATUS,
     ACT_LEN,
     JUDGE_STD_NAME,
     BAL_YEAR_MONTH,
     PLINE_CODE,
     PLINE_NAME,
     GRADECODE,
     GRADENAME,
     PIPMEMO,
     OLD_ORDER_NO,
     JUDGE_RESULT_TIME,
     MAT_ORIGIN_CODE,
     MAT_ORIGIN_NAME,
     SOURE_CODE,
     SOURE_NAME,
     MATERIAL_NO,
     MATERIAL_NAME,
     PLN_GRADECODE,
     PLN_GRADENAME,
     PLN_STEELCODE,
     PLN_STEELNAME,
     PRO_ORDER_NO,
     DETECT_RESULT_CODE,
     FACE_RESULT_CODE,
     QCM_STAUS,
     SAMPLE_FLAG,
     HEAT_PLAN_NO,
     ZG_STOVE_SQE)
  VALUES
    (?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     V_TIME,
     V_TIME,
     ?,
     '',
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     V_BATHYEAR,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?);
      
END;
</query>
<!-- 
INSERT INTO YDM_BC_INLIST
    (ZG_STOVE_SQE,
     MANAGEMENT_NO,
     MANAGEMENT_NAME,
     INSTOCK_SQE,
     INSTOCK_DOC,
     INSTOCK_TYPE_CODE,
     INSTOCK_TYPE_NAME,
     MAT_NO,
     LOT_NO,
     STOVE_NO,
     JUDGE_STOVE_NO,
     BATCH_NO,
     BATCH_GROUD_NO,
     PRODUCCODE,
     PRODUCNAME,
     STD_CODE,
     STD_NAME,
     STEELCODE,
     STEELNAME,
     STD_STYLE,
     STD_STYLE_DESC,
     SPEC_CODE,
     SPEC_NAME,
     MODEL_CODE,
     MODEL_DESC,
     ACT_DIMATER,
     ACT_HEIGHT,
     ACT_LEN_MIN,
     ACT_LEN_MAX,
     ACT_COUNT,
     ACT_WEIGHT,
     ACT_THEORY_WEIGHT,
     BELONG_CODE,
     BELONG_NAME,
     STORAGE_NO,
     MEMO,
     VALIDFLAG,
     CREATE_NAME,
     CREATE_TIME,
     ORDER_NO,
     ORDER_SEQ,
     DELIVERY_NO,
     ORD_PK,
     ORD_LN_PK,
     ORD_LN_DLY_PK,
     PRODUCT_FLAG,
     MAT_STATUS,
     INSTOCK_TIME,
     ZB_RCDID,
     ACT_LEN,
     DEPARTMENT_CODE,
     DEPARTMENT_DESC,
     JUDGE_STD_NAME,
     PLINE_CODE,
     PLINE_NAME,
     GRADECODE,
     GRADENAME,
     BAL_YEAR_MONTH,
     IN_TIME_F,
     PIPMEMO,
     MAT_ORIGIN_CODE,
     MAT_ORIGIN_NAME,
     SOURE_CODE,
     SOURE_NAME,
     MATERIAL_NO,
     MATERIAL_NAME,
     PRO_ORDER_NO)
  VALUES
    (?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     V_TIME,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     V_TIME,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     V_BATHYEAR,
     V_TIME,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?);
 -->
<query id = "FrmDownlineManage.insertDetail" desc = "插入下线操作记录表 ">
INSERT INTO MIL_OFFLINE_RESULT_DETIA(
        LOT_NO,
        JUDGE_STOVE_NO,
        OPERATION_TYPE,
        ACT_COUNT,
        ACT_WEIGHT,
        COL_TIME,
        
        COL_USER,
        COL_SHIFT,
        COL_GROUP,
        OPERATION_ID,
        PLINE_CODE,
        ID,
        OFFLINE_TYPE)
 VALUES( 
        ?,
        ?,
        '3',
        ?,
        ?,
        TO_DATE(?,'YYYY-MM-DD HH24:MI:SS'),
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?)
</query>
<query id = "FrmDownlineManage.updateInstore" desc = "修改下线表入库支数">
UPDATE MIL_OFFLINE_RESLUT T
     SET T.INSTORAGE_NUM = TO_NUMBER(T.INSTORAGE_NUM) + TO_NUMBER(?)
   WHERE T.JUDGE_STOVE_NO = ?
     AND T.LOT_NO = ?
     AND T.OFFLINE_TYPE = ?
</query>
<query id = "FrmDownlineManage.doQueryCckCount" desc = "查询待处理在产出库的支数">
<![CDATA[
SELECT COUNT(1) ACOUNT
  FROM MAT_BC_M T, YDM_BC_BUTTRESS S, COM_BASE_PLINE C
 WHERE T.MAT_NO = S.MAT_NO
   AND T.PLINE_CODE = C.PLINE_CODE
   AND T.QCM_STAUS = '11'
   AND S.STORAGE_NO = C.OUT_REPOSITORY
   AND T.ZG_STOVE_SQE = ?
   AND T.OFFLINE_DOC = ?
     ]]>
</query>
<query id = "FrmDownlineManage.deleteMatStore" desc = "消亡虚拟库存">
<![CDATA[
DECLARE
  V_JUDGE_STOVE_NO MAT_BC_M.ZG_STOVE_SQE%TYPE := ?;
  V_OFFLINE_DOC    MAT_BC_M.OFFLINE_DOC%TYPE := ?;
  V_OUTSTOCK_DOC   YDM_BC_OUTLIST.OUTSTOCK_DOC%TYPE := NULL;
BEGIN
  FOR MYROW IN (SELECT *
                  FROM (SELECT T.*,
                               S.STORAGE_NO,
                               S.LOCATION_NO,
                               S.MANAGEMENT_NO,
                               S.MANAGEMENT_NAME,
                               S.STORAGE_TYPE_NO,
                               S.STORAGE_TYPE_NAME,
                               S.STORAGE_ATTR,
                               S.STORAGE_ATTR_NAME,
                               REPLACE(T.SPEC_NAME, '*', 'x') SPEC_NAME1
                          FROM MAT_BC_M T, YDM_BC_BUTTRESS S
                         WHERE T.MAT_NO = S.MAT_NO
                           AND T.ZG_STOVE_SQE = V_JUDGE_STOVE_NO
                           AND T.OFFLINE_DOC = V_OFFLINE_DOC
                           AND T.QCM_STAUS = '11'
                         ORDER BY T.MAT_NO DESC)
                 WHERE ROWNUM <= ?) LOOP
    DELETE FROM YDM_BC_BUTTRESS_BACK B WHERE B.MAT_NO = MYROW.MAT_NO;
    UPDATE YDM_BC_BUTTRESS T
       SET T.PLINE_CODE = MYROW.PLINE_CODE
     WHERE T.MAT_NO = MYROW.MAT_NO;
    INSERT INTO YDM_BC_BUTTRESS_BACK B
      SELECT * FROM YDM_BC_BUTTRESS T WHERE T.MAT_NO = MYROW.MAT_NO;
    DELETE FROM YDM_BC_BUTTRESS T WHERE T.MAT_NO = MYROW.MAT_NO;
    DELETE FROM MAT_BC_M T WHERE T.MAT_NO = MYROW.MAT_NO;
  END LOOP;
END;
]]>
</query>

<query id = "FrmDownlineManage.insertOutlist" desc = "插入出库表计录">
<![CDATA[
DECLARE
  V_JUDGE_STOVE_NO MAT_BC_M.ZG_STOVE_SQE%TYPE := ?;
  V_OUTSTOCK_DOC   YDM_BC_OUTLIST.OUTSTOCK_DOC%TYPE := NULL;
  ACT_COUNT        YDM_BC_OUTLIST.ACT_COUNT%TYPE := 1;
  V_BELONG_CODE    YDM_BC_OUTLIST.BELONG_CODE%TYPE := ?;
  V_BELONG_NAME    YDM_BC_OUTLIST.BELONG_NAME%TYPE := ?;
  V_MAT_NO         PORT_MIL_BATCH_SAMPLE_RESULT.MAT_NO%TYPE := NULL;

BEGIN
  --生成出库单编号
  SELECT 'FX' || TO_CHAR(SYSDATE, 'YYMMDD') ||
         LPAD(NVL(MAX(SUBSTR(T.Outstock_Doc, 9)), 0) + 1, 5, 0) DI
    INTO V_OUTSTOCK_DOC
    FROM YDM_BC_OUTLIST T
   WHERE T.OUTSTOCK_TYPE_CODE = '800810'
     AND TO_CHAR(T.OUTSTOCK_TIME, 'YYYY-MM-DD') =
         TO_CHAR(SYSDATE, 'YYYY-MM-DD');

  --生成材料号
  SELECT SUBSTR(MAX(T.MAT_NO), 1, 6) || 'X'
    INTO V_MAT_NO
    FROM PORT_MIL_BATCH_SAMPLE_RESULT T
   WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO;

  FOR MYROW IN (SELECT *
                  FROM (SELECT B.MAT_NO,
                               A.LOT_NO,
                               REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') JUDGE_STOVE_NO,
                               CASE SUBSTR(A.JUDGE_STOVE_NO, -1)
                                 WHEN '1' THEN
                                  REGEXP_SUBSTR(GET_WL_CODE(SUBSTR(A.Ord_Ln_Dly_Pk,
                                                                   0,
                                                                   LENGTH(A.Ord_Ln_Dly_Pk) - 3)),
                                                '[^#]+',
                                                1,
                                                1)
                                 ELSE
                                  REGEXP_SUBSTR(GET_WL_CODE2(A.CONTRACT_NO),
                                                '[^#]+',
                                                1,
                                                1)
                               END MATERIAL_NO,
                               
                               CASE SUBSTR(A.JUDGE_STOVE_NO, -1)
                                 WHEN '1' THEN
                                  REGEXP_SUBSTR(GET_WL_CODE(SUBSTR(A.Ord_Ln_Dly_Pk,
                                                                   0,
                                                                   LENGTH(A.Ord_Ln_Dly_Pk) - 3)),
                                                '[^#]+',
                                                1,
                                                2)
                                 ELSE
                                  REGEXP_SUBSTR(GET_WL_CODE2(A.CONTRACT_NO),
                                                '[^#]+',
                                                1,
                                                2)
                               END MATERIAL_NAME,
                               A.VARIETIES_CODE PRODUCCODE,
                               A.VARIETIES PRODUCNAME,
                               A.ROLL_STANDRAD_CODE STD_CODE,
                               A.STEEL_STANDRAD STD_NAME,
                               GRADECODE,
                               GRADENAME,
                               STEELCODE,
                               STEELNAME,
                               STD_STYLE,
                               STD_STYLE_DESC,
                               A.PIPE_SIZE_CODE SPEC_CODE,
                               REPLACE(A.PIPE_SIZE, '*', 'x') SPEC_NAME,
                               A.BUCKLE_TYPE_CODE MODEL_CODE,
                               A.BUCKLE_TYPE MODEL_DESC,
                               A.CONTRACT_NO PRO_ORDER_NO,
                               A.PLINE_CODE,
                               (SELECT C1.PLINE_NAME
                                  FROM COM_BASE_PLINE C1
                                 WHERE C1.PLINE_CODE = A.PLINE_CODE) PLINE_NAME,
                               '' ACT_DIMATER,
                               '' ACT_HEIGHT,
                               A.ORDER_LENGTHA ACT_LEN,
                               '' ACT_LEN_MIN,
                               '' ACT_LEN_MAX,
                               '1' ACT_COUNT,
                               B.ACT_THEORY_WEIGHT ACT_WEIGHT
                          FROM MIL_PLAN A, PORT_MIL_BATCH_SAMPLE_RESULT B
                         WHERE A.JUDGE_STOVE_NO = B.JUDGE_STOVE_NO
                           AND A.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO)
                 WHERE ROWNUM <= ?) LOOP
  
    INSERT INTO YDM_BC_OUTLIST
      (OUTSTOCK_SQE,
       OUTSTOCK_DOC,
       OUTSTOCK_TYPE_CODE,
       OUTSTOCK_TYPE_NAME,
       MAT_NO,
       LOT_NO,
       JUDGE_STOVE_NO,
       BATCH_NO,
       BATCH_GROUD_NO,
       --MATERIAL_NO,
       --MATERIAL_NAME,
       PRODUCCODE,
       PRODUCNAME,
       STD_CODE,
       STD_NAME,
       GRADECODE,
       GRADENAME,
       STEELCODE,
       STEELNAME,
       STD_STYLE,
       STD_STYLE_DESC,
       SPEC_CODE,
       SPEC_NAME,
       MODEL_CODE,
       MODEL_DESC,
       PRO_ORDER_NO,
       PLINE_CODE,
       PLINE_NAME,
       ACT_DIMATER,
       ACT_HEIGHT,
       ACT_LEN,
       ACT_LEN_MIN,
       ACT_LEN_MAX,
       ACT_COUNT,
       ACT_WEIGHT,
       --ACT_THEORY_WEIGHT,
       BELONG_CODE,
       BELONG_NAME,
       
       MANAGEMENT_NO,
       MANAGEMENT_NAME,
       OUTSTOCK_TIME,
       OUT_BC,
       OUT_BZ,
       CREATE_NAME,
       CREATE_TIME,
       
       DEPARTMENT_CODE,
       DEPARTMENT_DESC)
    VALUES
      (V_OUTSTOCK_DOC || TO_CHAR(ACT_COUNT, 'FM0000'),
       V_OUTSTOCK_DOC,
       '800810',
       '返线出库',
       V_MAT_NO || TO_CHAR(ACT_COUNT, 'FM0000'),
       MYROW.LOT_NO,
       MYROW.JUDGE_STOVE_NO,
       'X',
       '001',
       --MYROW.MATERIAL_NO,
       --MYROW.MATERIAL_NAME,
       MYROW.PRODUCCODE,
       MYROW.PRODUCNAME,
       MYROW.STD_CODE,
       MYROW.STD_NAME,
       MYROW.GRADECODE,
       MYROW.GRADENAME,
       MYROW.STEELCODE,
       MYROW.STEELNAME,
       MYROW.STD_STYLE,
       MYROW.STD_STYLE_DESC,
       MYROW.SPEC_CODE,
       MYROW.SPEC_NAME,
       MYROW.MODEL_CODE,
       MYROW.MODEL_DESC,
       MYROW.PRO_ORDER_NO,
       MYROW.PLINE_CODE,
       MYROW.PLINE_NAME,
       MYROW.ACT_DIMATER,
       MYROW.ACT_HEIGHT,
       MYROW.ACT_LEN,
       MYROW.ACT_LEN_MIN,
       MYROW.ACT_LEN_MAX,
       MYROW.ACT_COUNT,
       MYROW.ACT_WEIGHT,
       --MYROW.ACT_THEORY_WEIGHT,
       V_BELONG_CODE,
       V_BELONG_NAME,
       
       V_BELONG_CODE,
       V_BELONG_NAME,
       SYSDATE,
       ?,
       ?,
       ?,
       SYSDATE,
       
       V_BELONG_CODE,
       V_BELONG_NAME);
  
    ACT_COUNT := ACT_COUNT + 1;
  
  END LOOP;
END;

]]>
</query>
<query id = "FrmDownlineManage.insertButressData" desc = "撤销操作时还原虚拟库存">
<![CDATA[
DECLARE
  V_TIME MIL_OFFLINE_RESLUT.OFFLINE_TIME%TYPE := SYSDATE;
BEGIN
  INSERT INTO YDM_BC_BUTTRESS
    (JUDGE_STOVE_NO,
     BATCH_NO,
     BATCH_GROUD_NO,
     STORAGE_NO,
     LOCATION_NO,
     STORAGE_TYPE_NO,
     STORAGE_TYPE_NAME,
     CREATE_NAME,
     MAT_NO,
     CREATE_TIME,
     MANAGEMENT_NO,
     MANAGEMENT_NAME,
     DEPARTMENT_CODE,
     DEPARTMENT_DESC)
  VALUES
    (?, ?, ?, ?, ?, ?, ?, ?, ?, V_TIME, ?, ?, ?, ?);
  INSERT INTO MAT_BC_M
    (JUDGE_STOVE_NO,
     BATCH_NO,
     BATCH_GROUD_NO,
     ACT_COUNT,
     ACT_WEIGHT,
     CREATE_TIME,
     MAT_NO,
     PRODUCT_FLAG,
     MAT_STATUS,
     PLINE_CODE,
     PLINE_NAME,
     QCM_STAUS,
     HEAT_PLAN_NO,
     ZG_STOVE_SQE,
     PRODUCCODE,
     PRODUCNAME,
     STEELCODE,
     STEELNAME,
     SPEC_CODE,
     SPEC_NAME,
     GRADECODE,
     GRADENAME,
     MODEL_CODE,
     MODEL_DESC,
     STD_CODE,
     STD_NAME,
     BELONG_CODE,
     BELONG_NAME,
     STD_STYLE,
     STD_STYLE_DESC,
     ACT_DIMATER,
     ACT_HEIGHT,
     ACT_LEN_MIN,
     ACT_LEN_MAX,
     LOT_NO,
     PRO_ORDER_NO,
     ACT_LEN,
     TARGET,
     PROCESS_STATUS,
     FLAG_STOVE_NO_ZG,
     BAL_YEAR_MONTH,
     MATERIAL_NO,
     MATERIAL_NAME,
     INPUT_MATERIAL_NO,
     INPUT_MATERIAL_NAME,
     CIC,
     JUDGE_STD_DES,
     CRAFT_SEQ,
     PRO_ORDER_ID,
     GX_PLAN_NO,
     PROCESS_CDOE,
     PROCESS_DESC,
     INSTOCK_TIME,
     OFFLINE_DOC)
  VALUES
    (?,
     ?,
     ?,
     ?,
     ?,
     TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     'D',
     '轧制',
     TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
     (SELECT MAX(M.OFFLINE_DOC)
        FROM MIL_OFFLINE_RESLUT M
       WHERE M.JUDGE_STOVE_NO = ?));

  DELETE FROM YDM_BC_OUTLIST t
   WHERE T.JUDGE_STOVE_NO = ?
     AND T.OUTSTOCK_TYPE_CODE = '800810'
     AND rownum = 1;
END;

]]>
</query>
<!-- INSERT INTO YDM_BC_INLIST
      (MANAGEMENT_NO,
       MANAGEMENT_NAME,
       INSTOCK_SQE,
       INSTOCK_DOC,
       INSTOCK_TYPE_CODE,
       INSTOCK_TYPE_NAME,
       MAT_NO,
       LOT_NO,
       STOVE_NO,
       JUDGE_STOVE_NO,
       BATCH_NO,
       BATCH_GROUD_NO,
       PRODUCCODE,
       PRODUCNAME,
       STD_CODE,
       STD_NAME,
       STEELCODE,
       STEELNAME,
       STD_STYLE,
       STD_STYLE_DESC,
       SPEC_CODE,
       SPEC_NAME,
       MODEL_CODE,
       MODEL_DESC,
       ACT_DIMATER,
       ACT_HEIGHT,
       ACT_LEN_MIN,
       ACT_LEN_MAX,
       ACT_COUNT,
       ACT_WEIGHT,
       ACT_THEORY_WEIGHT,
       BELONG_CODE,
       BELONG_NAME,
       STORAGE_NO,
       MEMO,
       VALIDFLAG,
       CREATE_NAME,
       CREATE_TIME,
       ORDER_NO,
       ORDER_SEQ,
       DELIVERY_NO,
       ORD_PK,
       ORD_LN_PK,
       ORD_LN_DLY_PK,
       PRODUCT_FLAG,
       MAT_STATUS,
       INSTOCK_TIME,
       ZB_RCDID,
       ACT_LEN,
       DEPARTMENT_CODE,
       DEPARTMENT_DESC,
       JUDGE_STD_NAME,
       PLINE_CODE,
       PLINE_NAME,
       GRADECODE,
       GRADENAME,
       BAL_YEAR_MONTH,
       IN_TIME_F,
       PIPMEMO,
       MAT_ORIGIN_CODE,
       MAT_ORIGIN_NAME,
       SOURE_CODE,
       SOURE_NAME,
       MATERIAL_NO,
       MATERIAL_NAME,
       PRO_ORDER_NO,
       QCM_STAUS,
       ZG_STOVE_SQE)
    VALUES
      (?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       TO_DATE(?,'YYYY-MM-DD HH24:MI:SS'),
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       TO_DATE(?,'YYYY-MM-DD HH24:MI:SS'),
       '',
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       TO_DATE(?,'YYYY-MM-DD HH24:MI:SS'),
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?);
      -->
<query id = "FrmDownlineManage.selectMilPlanData" desc = "查询炉计划信息">
	SELECT T.* FROM MIL_PLAN T WHERE T.JUDGE_STOVE_NO = ?
	</query>
	<query id = "FrmDownlineManage.selectMilOfflineGroup" desc = "查询组炉支数重量">
	SELECT T.OLD_ZP_JUDGE_STOVE_NO,T.OLD_ZP_LOT_NO,T.ZP_COUNT,T.ZP_HEIGHT FROM MIL_OFFLINE_GROUP T WHERE T.ZP_JUDGE_STOVE_NO = ?
	</query>
	<query id = "FrmDownlineManage.selectSubcontract" desc = "查询委外 审核标志">
	SELECT T.ENTRUSTED_FLAG FROM MIL_ENTRUSTED_BILL T WHERE T.SUBCONTRACT_NO_SEQ = ?
	</query>
	<query id = "FrmDownlineManage.updateOrderLength" desc = "组炉后修改长度">
	DECLARE
BEGIN
  UPDATE MIL_OFFLINE_RESLUT T
     SET T.LENGTH = '#LENGTH#',
     T.DIAMETER = '#DIAMETER#',
     T.THICKNESS = '#THICKNESS#',
     T.PRODUCCODE = '#PRODUCCODE#',
     T.PRODUCNAME = '#PRODUCNAME#',
     T.STEELCODE = '#STEELCODE#',
     T.STEELNAME = '#STEELNAME#',
     T.SPEC_CODE = '#SPEC_CODE#',
     T.SPEC_NAME = '#SPEC_NAME#',
     T.MODEL_CODE = '#MODEL_CODE#',
     T.MODEL_DESC = '#MODEL_DESC#',
     T.STD_STYLE = '#STD_STYLE#',
     T.STD_STYLE_DESC = '#STD_STYLE_DESC#',
     T.STD_CODE = '#STD_CODE#',
     T.STD_NAME = '#STD_NAME#',
     T.CONTRACT_NO = '#CONTRACT_NO#',
     T.IMP_PROCESS = '#IMP_PROCESS#',
     T.ACT_LEN_RANGE = '#ACT_LEN_RANGE#'
   WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#';
   --UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T SET T.ORDER_LENGTH = '#ZP_LENGTH#' WHERE T.JUDGE_STOVE_NO = '#ZP_JUDGE_STOVE_NO#';
   --UPDATE MIL_OFFLINE_GROUP T SET T.ZP_LENGTH = '#ZP_LENGTH#' WHERE T.ZP_JUDGE_STOVE_NO = '#ZP_JUDGE_STOVE_NO#';
END;
	</query>
	<query id = "FrmDownlineManage.selectPortNum" desc= "查询是否返线">
	SELECT NVL(COUNT(1),0)ACOUNT FROM PORT_MIL_BATCH_SAMPLE_RESULT T WHERE T.JUDGE_STOVE_NO = ? 
	</query>
	<query id = "FrmDownlineManage.selectMilPlanImProcess" desc = "查询执行工艺号">
	SELECT T.IMP_PROCESS
  FROM MIL_PLAN T
 WHERE T.JUDGE_STOVE_NO = ?
   AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
   AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
	</query>
	<query id = "FrmDownlineManage.doQueryProName" desc = "查询品名">
	SELECT T.PRODUCNAME,T.PRODUCCODE FROM COM_BASE_PRODUCT T
	</query>
	<query id = "FrmDownlineManage.doQuerySteelName" desc = "查询钢级">
	SELECT T.STEELNAME,T.STEELCODE FROM COM_BASE_STEEL T
	</query>
	<query id = "FrmDownlineManage.doQuerySpecName" desc = "查询规格">
	SELECT T.SPEC_NAME,T.SPEC_CODE FROM COM_BASE_SPEC T
	</query>
	<query id = "FrmDownlineManage.doQueryModleName" desc = "查询扣型">
	SELECT T.MODEL_DESC,T.MODEL_CODE FROM COM_BASE_MODEL T
	</query>
	<query id = "FrmDownlineManage.doQueryStyName" desc = "查询标准类别">
	SELECT T.STD_STYLE_DESC,T.STD_STYLE FROM COM_BASE_STD_STYLE T
	</query>
	<!-- 
	SELECT T1.*,
       T2.CRAFT_FILE_NO AS CRAFT_NO,
       T2.LEN_ROLL_MIN || '-' || T2.LEN_ROLL_MAX AS LENGTH_RANGE,
       T2.AIMLENGTH AS ROLL_LENGTH,
       T2.PRO_PLAN_ID,
       T2.GX_PLAN_NO
  FROM (SELECT T.ORDER_NO,
               S.ORDER_SEQ,
               S.PRODUCCODE,
               S.PRODUCNAME,
               S.STEELCODE,
               S.STEELNAME,
               S.SPEC_CODE,
               S.SPEC_NAME,
               S.MODEL_CODE,
               S.MODEL_DESC,
               S.STD_CODE,
               S.STD_NAME,
               S.STD_STYLE,
               S.STD_STYLE_DESC,
               T.ABRVITION
          FROM SLM_ORDER_HEAD T, SLM_ORDER_LINE S
         WHERE T.ORD_PK = S.ORD_PK
           AND T.ORDER_TYP != '120102'
           AND T.VALIDFLAG = '1'
           AND S.VALIDFLAG = '1'
           AND T.ORDER_NO || '&' LIKE '%' || ? || '%') T1,
       PLN_ORDER_ZG_S T2
 WHERE T1.ORDER_NO = T2.ORDER_NO
   AND T1.ORDER_SEQ = T2.ORDER_SEQ
   AND T2.EXE_STATUS = '0'
UNION ALL
	 -->
	<query id = "FrmDownlineManage.doQueryOrderNo" desc ="查询工序合同">
	<![CDATA[
SELECT T3.ORDER_NO,
       T3.ORDER_SEQ,
       T3.PRODUCCODE,
       T3.PRODUCNAME,
       T3.STEELCODE,
       T3.STEELNAME,
       T3.SPEC_CODE,
       T3.SPEC_NAME,
       T3.MODEL_CODE,
       T3.MODEL_DESC,
       T3.STD_CODE,
       T3.STD_NAME,
       (SELECT T.STD_STYLE
          FROM COM_BASE_STD_STYLE T
         WHERE T.STD_STYLE_DESC = T3.STD_STYLE_DESC) STD_STYLE,
       T3.STD_STYLE_DESC,
       (SELECT S2.ABRVITION
          FROM SLM_BASE_CUSTOMER S2
         WHERE S2.CUSTOMER_NO = T3.FINAL_USER) ABRVITION,
       S1.CRAFT_FILE_NO AS CRAFT_NO,
       S1.LEN_ROLL_MIN || '-' || S1.LEN_ROLL_MAX AS LENGTH_RANGE,
       S1.AIMLENGTH AS ROLL_LENGTH,
       S1.PRO_PLAN_ID,
       S1.GX_PLAN_NO
  FROM PLN_SALEORD T3, PLN_ORDER_ZG_S S1
 WHERE T3.ORD_LN_DLY_PK = S1.ORD_LN_DLY_PK
   AND S1.EXE_STATUS = '0'
   AND T3.ORDER_NO || '&' LIKE '%' || ? || '%'
 ]]>
	</query>
	<query id= "FrmDownlineManage.doQueryLxStore" desc = "查询离线库存">
	<![CDATA[
	SELECT NVL(SUM(T.ACT_COUNT),0)ACT_COUNT
  FROM MAT_BC_M T, YDM_BC_BUTTRESS S
 WHERE T.MAT_NO = S.MAT_NO
   AND T.ZG_STOVE_SQE = ?
   AND T.QCM_STAUS = '11'
   ]]>
	</query>
	<query id = "doFurnace.updatePortFlag" desc = "修改进程表组炉标识">
	<![CDATA[
	DECLARE
  V_TIME MIL_OFFLINE_RESLUT.OFFLINE_TIME%TYPE := SYSDATE;
BEGIN
  FOR MYROW IN (SELECT *
                  FROM (SELECT *
                          FROM PORT_MIL_BATCH_SAMPLE_RESULT T
                         WHERE T.JUDGE_STOVE_NO = ?
                         AND T.STATUS = '3'
                         ORDER BY T.MAT_NO ASC)
                 WHERE ROWNUM <= ?) LOOP
    UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T
       SET T.GROUP_FLAG = '1'
     WHERE T.MAT_NO = MYROW.MAT_NO
       AND T.JUDGE_STOVE_NO = ?;
  END LOOP;
END;
	]]>
	</query>
	<query id = "doQueryNodesPro.TS" desc = "查询探伤点是否结炉">
	SELECT *
  FROM (SELECT T.NODE_FUR_FLAG
          FROM MIL_MT_RESULT T
         WHERE T.JUDGE_STOVE_NO = ?
           AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
           AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
        UNION ALL
        SELECT T1.NODE_FUR_FLAG
          FROM MIL_ET_RESULT T1
         WHERE T1.JUDGE_STOVE_NO = ?
           AND NVL(T1.PRO_PLAN_ID, '/') = NVL(?, '/')
           AND NVL(T1.GX_PLAN_NO, '/') = NVL(?, '/'))
	</query>
	<query id = "doQueryNodesPro.JZ" desc = "查询质检点是否结炉">
	SELECT T.NODE_FUR_FLAG
  FROM MIL_SURFACE_RESULT T
 WHERE T.JUDGE_STOVE_NO = ?
   AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
   AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
	</query>
	<query id = "FrmDownlineManage.doQueryEntust" desc = "查询是否存在委外加工委托">
	SELECT *
  FROM MIL_ENTRUSTED_BILL T
 WHERE T.JUDGE_STOVE_NO = ?
   AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
   AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
	</query>
	<query id = "doQueryNodesPro.XX" desc = "查询交库点是否结炉">
	SELECT COUNT(1)
  FROM MIL_PLAN T
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.NODE_STATUS = '99'
   AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
   AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
	</query>
	<query id = "cancelQualityInspectionTrust.doQueryEntrustAcount" desc = "查询双探废品支数">
	SELECT TO_NUMBER(T.SUBCONTRACTSCRAP_NUM) /
       TO_NUMBER(T.SUBCONTRACT_COMPLETE_CUT)SUBCONTRACTSCRAP_NUM
  FROM MIL_ENTRUSTED_BILL T
 WHERE T.JUDGE_STOVE_NO = ?
	</query>
	
	<query id = "FrmDownlineManage.updateID" desc = "统一组炉炉号进程表ID">
<![CDATA[
DECLARE
  V_PLAN_ID        PORT_MIL_BATCH_SAMPLE_RESULT.PLAN_ID%TYPE := NULL;
  V_JUDGE_STOVE_NO PORT_MIL_BATCH_SAMPLE_RESULT.JUDGE_STOVE_NO%TYPE := ?;
BEGIN
  SELECT MAX(B.ID)
    INTO V_PLAN_ID
    FROM MIL_OFFLINE_GROUP A, MIL_PLAN B
   WHERE A.ZP_M_LH = B.JUDGE_STOVE_NO
     AND A.ZP_JUDGE_STOVE_NO = V_JUDGE_STOVE_NO;

  UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T
     SET T.PLAN_ID = V_PLAN_ID
   WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO;
END;
]]>
</query>

<query id = "cancelQualityInspectionTrust.doQueryOffline" desc = "查询是否有交库点离线数据未撤销">
<![CDATA[
select COUNT(1) ACOUNT
  from MIL_OFFLINE_RESLUT t
 WHERE T.OFFLINE_PRO = 'XX'
   AND T.JUDGE_STOVE_NO = ?
]]>
</query>

<query id = "cancelQualityInspectionTrust.doQueryInstore" desc = "判断是否交库">
<![CDATA[
select COUNT(1) ACOUNT from MAT_BC_M t WHERE T.ZG_STOVE_SQE = ?
]]>
</query>

<query id = "FrmDownlineManage.doQueryZP" desc = "查询该炉是否是组炉炉号">
<![CDATA[
SELECT SUM(ACOUNT) ACOUNT
  FROM (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)
        UNION ALL
        SELECT COUNT(1) ACOUNT
          FROM MIL_OFFLINE_GROUP T
         WHERE T.ZP_JUDGE_STOVE_NO = ?)
]]>
</query>

<query id = "doFurnace.insertMilTakeReslut" desc = "插入脱单实绩表,脱单,回写PLN_ORDER_ZG_S">
<![CDATA[
DECLARE
  V_JUDGE_STOVE_NO MIL_OFFLINE_RESLUT.JUDGE_STOVE_NO%TYPE := ?;
  V_OFFLINE_PRO    MIL_OFFLINE_RESLUT.REMARK%TYPE := ?;
  V_OFFLINE_TYPE   MIL_OFFLINE_RESLUT.OFFLINE_TYPE%TYPE := ?;
  V_PLINE_CODE     MIL_OFFLINE_RESLUT.PLINE_CODE%TYPE := ?;

  V_ID           MIL_TAKE_RESLUT.ID%TYPE := NULL;
  V_OFFLINE_PRO1 MIL_OFFLINE_RESLUT.REMARK%TYPE := NULL;
  V_INPUT_WEIGHT PORT_MIL_BATCH_SAMPLE_RESULT.INPUT_WEIGHT%TYPE := NULL;
  V_NMB          MIL_TAKE_RESLUT.ID%TYPE := NULL;
BEGIN
  --生成ID
  SELECT TO_CHAR(SYSDATE, 'YYMMDD') || V_PLINE_CODE ||
         LPAD(NVL(MAX(SUBSTR(T.ID, 11)), 0) + 1, 3, 0) DI
    INTO V_ID
    FROM MIL_TAKE_RESLUT T
   WHERE T.PLINE_CODE = V_PLINE_CODE
   AND INSTR(T.ID, '-') = 0
     AND TO_CHAR(T.TAKE_TIME, 'YYYY-MM-DD') =
         TO_CHAR(SYSDATE, 'YYYY-MM-DD');

  --转换工序
  SELECT DECODE(V_OFFLINE_PRO,
                '矫直',
                'JZ',
                '探伤',
                'TS',
                '质检',
                'ZJ',
                '交库',
                'XX')
    INTO V_OFFLINE_PRO1
    FROM DUAL;

  FOR MYROW IN (SELECT *
                  FROM MIL_OFFLINE_RESLUT T
                 WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
                   AND T.OFFLINE_PRO = V_OFFLINE_PRO1
                   AND T.OFFLINE_TYPE = V_OFFLINE_TYPE
                   AND T.PLINE_CODE = V_PLINE_CODE) LOOP
  
    SELECT DECODE(MYROW.OFFLINE_PRO,
                  'JZ',
                  '9',
                  'TS',
                  '10',
                  'ZJ',
                  '11',
                  'XX',
                  '12')
      INTO V_NMB
      FROM DUAL;
  
    SELECT SUM(T.Act_Theory_Weight)
      INTO V_INPUT_WEIGHT
      FROM PORT_MIL_BATCH_SAMPLE_RESULT T
     WHERE T.STATUS = '3'
       AND T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
       AND T.PLINE_CODE = V_PLINE_CODE
       AND TRIM(T.OP_PROCESS) = V_NMB;
  
    INSERT INTO MIL_TAKE_RESLUT
  (ID,
   LOT_NO,
   STOVE_NO,
   JUDGE_STOVE_NO,
   DIAMETER,
   THICKNESS,
   LENGTH,
   PLINE_CODE,
   OFFLINE_PRO,
   REAL_TIME_STATUS,
   OFFLINE_NUM,
   BACKLINE_NUM,
   GROUP_NUM,
   FINAL_NUM,
   ZP_FLAG,
   STATUS,
   TYPE_FLAG,
   OFFLINE_TIME,
   REMARK,
   COL_USER,
   COL_SHIFT,
   COL_GROUP,
   ZP_HEIGHT,
   RECHECK_NUM,
   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,
   INSTORAGE_NUM,
   QUALIFIED_NUM,
   SCRAP_NUM,
   ZP_M_LH,
   ACT_LEN_RANGE,
   OFFLINE_TYPE,
   SUBCONTRACT_NUM,
   SUBCONTRACTCOMPLETE_NUM,
   SUBCONTRACT_NO,
   TARGET,
   SUBCONTRACTCOMPLETE_WGT,
   SUBCONTRACT_COMPLETE_CUT,
   SUBCONTRACT_COMPLETE_LEN,
   SUBCONTRACTSCRAP_NUM,
   IMP_PROCESS,
   PRO_PLAN_ID,
   GX_PLAN_NO,
   TAKE_TIME,
   TAKE_USER,
   TAKE_NUM)
VALUES
  (V_ID,
   MYROW.LOT_NO,
   MYROW.STOVE_NO,
   MYROW.JUDGE_STOVE_NO,
   MYROW.DIAMETER,
   MYROW.THICKNESS,
   MYROW.LENGTH,
   MYROW.PLINE_CODE,
   MYROW.OFFLINE_PRO,
   MYROW.REAL_TIME_STATUS,
   MYROW.OFFLINE_NUM,
   MYROW.BACKLINE_NUM,
   MYROW.GROUP_NUM,
   MYROW.FINAL_NUM,
   MYROW.ZP_FLAG,
   MYROW.STATUS,
   MYROW.TYPE_FLAG,
   MYROW.OFFLINE_TIME,
   MYROW.REMARK,
   MYROW.COL_USER,
   MYROW.COL_SHIFT,
   MYROW.COL_GROUP,
   MYROW.ZP_HEIGHT,
   MYROW.RECHECK_NUM,
   MYROW.PRODUCNAME,
   MYROW.STEELCODE,
   MYROW.STEELNAME,
   MYROW.GRADECODE,
   MYROW.GRADENAME,
   MYROW.SPEC_CODE,
   MYROW.SPEC_NAME,
   MYROW.MODEL_CODE,
   MYROW.MODEL_DESC,
   MYROW.STD_CODE,
   MYROW.STD_NAME,
   MYROW.STD_STYLE,
   MYROW.STD_STYLE_DESC,
   MYROW.CONTRACT_NO,
   MYROW.PRODUCCODE,
   MYROW.INSTORAGE_NUM,
   MYROW.QUALIFIED_NUM,
   MYROW.SCRAP_NUM,
   MYROW.ZP_M_LH,
   MYROW.ACT_LEN_RANGE,
   MYROW.OFFLINE_TYPE,
   MYROW.SUBCONTRACT_NUM,
   MYROW.SUBCONTRACTCOMPLETE_NUM,
   MYROW.SUBCONTRACT_NO,
   MYROW.TARGET,
   MYROW.SUBCONTRACTCOMPLETE_WGT,
   MYROW.SUBCONTRACT_COMPLETE_CUT,
   MYROW.SUBCONTRACT_COMPLETE_LEN,
   MYROW.SUBCONTRACTSCRAP_NUM,
   MYROW.IMP_PROCESS,
   MYROW.PRO_PLAN_ID,
   MYROW.GX_PLAN_NO,
   SYSDATE,
   ?,
   NVL(MYROW.OFFLINE_NUM, 0) - NVL(MYROW.GROUP_NUM, 0) -
   NVL(MYROW.RECHECK_NUM, 0) - NVL(MYROW.BACKLINE_NUM, 0));

    UPDATE MIL_OFFLINE_RESLUT T
       SET T.PRO_PLAN_ID = '', T.GX_PLAN_NO = '', T.CONTRACT_NO = '',T.IS_TAKE = '1'
     WHERE T.JUDGE_STOVE_NO = MYROW.JUDGE_STOVE_NO
       AND T.PLINE_CODE = MYROW.PLINE_CODE
       AND T.OFFLINE_PRO = V_OFFLINE_PRO1
       AND T.OFFLINE_TYPE = V_OFFLINE_TYPE;
  
    UPDATE PLN_ORDER_ZG_S T
       SET T.TAKE_NUM = NVL(T.TAKE_NUM, 0) + NVL(MYROW.OFFLINE_NUM, 0) -
                        NVL(MYROW.GROUP_NUM, 0) - NVL(MYROW.RECHECK_NUM, 0) -
                        NVL(MYROW.BACKLINE_NUM, 0),
           T.TAKE_WT  = V_INPUT_WEIGHT
     WHERE T.PRO_PLAN_ID = MYROW.PRO_PLAN_ID
       AND T.GX_PLAN_NO = MYROW.GX_PLAN_NO;
  END LOOP;
END;
]]>
</query>

<query id = "FrmDownlineManage.doQueryOfflineType" desc = "查询是否未探下线">
<![CDATA[
select t.OFFLINE_TYPE
  from MIL_OFFLINE_RESLUT t
 where t.judge_stove_no = ?
   AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
   AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
]]>
</query>

<query id = "FrmDownlineManage.doQueryTake" desc = "查询是否已脱单">
<![CDATA[
select count(1) ACOUNT
  from MIL_TAKE_RESLUT t
 where t.judge_stove_no = ?
   and t.lot_no = ?
   and t.offline_pro = ?
   AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
   AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
]]>
</query>

<query id = "FrmDownlineManage.doQueryTake2" desc = "查询是否已脱单">
<![CDATA[
select COUNT(1) ACOUNT
  from MIL_OFFLINE_RESLUT t
 WHERE T.IS_TAKE = '1'
   AND T.JUDGE_STOVE_NO = ?
   AND T.LOT_NO = ?
   AND T.PLINE_CODE = ?
]]>
</query>

<query id = "FrmDownlineManage.doQuerySubcontract" desc = "是否委外完成">
<![CDATA[
select NVL(T.SUBCONTRACT_NUM, 0) - NVL(T.SUBCONTRACTCOMPLETE_NUM, 0) ACOUNT
  from MIL_OFFLINE_RESLUT t
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.LOT_NO = ?
   AND T.PLINE_CODE = ?
]]>
</query>

<query id = "FrmDownlineManage.doQueryZpJudgeStoveNo" desc = "生成天淮组炉炉号">
<![CDATA[
SELECT ? || TO_CHAR(SYSDATE, 'YYMM') ||
       LPAD(NVL(SUBSTR(MAX(NUM), 1, 4), 0) + 1, 4, 0) AS NUMFROM
  FROM (SELECT SUBSTR(T.JUDGE_STOVE_NO, 6, 4) AS NUM
          FROM MIL_PLAN T
         WHERE T.PLINE_CODE = 'C072'
           AND T.JUDGE_STOVE_NO LIKE ? || TO_CHAR(SYSDATE, 'YYMM') || '%'
        UNION
        SELECT SUBSTR(T.FEED_HEAT_NO, 6, 4) AS NUM
          FROM PLN_ZY_ZG_M T
         WHERE T.PLINE_CODE = 'C072'
           AND T.FEED_HEAT_NO LIKE ? || TO_CHAR(SYSDATE, 'YYMM') || '%'
        UNION
        SELECT SUBSTR(T.JUDGE_STOVE_NO, 6, 4) AS NUM
          FROM MIL_OFFLINE_RESLUT T
         WHERE T.PLINE_CODE = 'C072'
           AND T.JUDGE_STOVE_NO LIKE ? || TO_CHAR(SYSDATE, 'YYMM') || '%')

]]>
</query>

<query id = "FrmDownlineManage.doQueryNodeXX" desc = "查询下线点是否结炉">
<![CDATA[
select COUNT(1) ACOUNT
  from MIL_INSTORE_RESULT t
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.NODE_FUR_FLAG = '1'
]]>
</query>
</queryMap>