<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="下线，返线操作方法 类">
	<query id="OffLine.GetMILPlan0" desc="矯直工序">
	  <![CDATA[ 
select *
  from MIL_PLAN a
 WHERE a.judge_stove_no in
       (select t.judge_stove_no
          from MIL_SAW_RESULT t
         where t.node_fur_flag=1
         AND t.judge_stove_no in
               (select b.judge_stove_no
                  from MIL_STRAIGHTENING_RESULT b
                 where b.node_fur_flag = 0))
   AND a.offline_flag <> '1'
   AND a.JUDGE_STOVE_NO || '&' LIKE '%' || ? || '%' 
       AND a.PLINE_CODE = ?
       AND a.PRO_PLAN_ID  || '&' LIKE '%' || ? || '%'
       AND a.GX_PLAN_NO  || '&' LIKE '%' || ? || '%'
      ]]>
   </query>

	<query id="OffLine.GetMILPlan11" desc="探傷工序">
	 <![CDATA[ 
    select *
      from MIL_PLAN a
     WHERE a.judge_stove_no in
           (select t.judge_stove_no
              from Mil_Straightening_Result t
             where t.node_fur_flag=1
             AND t.judge_stove_no in
                   (select b.judge_stove_no
                      from MIL_ET_RESULT b
                     where b.node_fur_flag = 0))
       AND a.offline_flag <> '1'
       AND a.JUDGE_STOVE_NO || '&' LIKE '%' || ? || '%' 
       AND a.PLINE_CODE = ?
       AND a.PRO_PLAN_ID  || '&' LIKE '%' || ? || '%'
       AND a.GX_PLAN_NO  || '&' LIKE '%' || ? || '%'
          ]]>
   </query>
   <query id="OffLine.GetMILPlan12" desc="探傷工序">
    <![CDATA[ 
    select *
      from MIL_PLAN a
     WHERE a.judge_stove_no in
           (select t.judge_stove_no
              from Mil_Straightening_Result t
             where t.node_fur_flag=1
             AND t.judge_stove_no in
                   (select b.judge_stove_no
                      from MIL_MT_RESULT b
                     where b.node_fur_flag = 0))
       AND a.offline_flag <> '1'
       AND a.JUDGE_STOVE_NO || '&' LIKE '%' || ? || '%' 
       AND a.PLINE_CODE = ?
       AND a.PRO_PLAN_ID  || '&' LIKE '%' || ? || '%'
       AND a.GX_PLAN_NO  || '&' LIKE '%' || ? || '%'
       ]]>
   </query>
   <query id="OffLine.GetMILPlan13" desc="探傷工序">
    <![CDATA[ 
    select *
      from MIL_PLAN a
     WHERE a.judge_stove_no in
           (select t.judge_stove_no
              from Mil_Straightening_Result t
             where t.node_fur_flag=1
             AND t.judge_stove_no in
                   (select b.judge_stove_no
                      from MIL_UL_RESUL b
                     where b.node_fur_flag = 0))
                     
       AND a.offline_flag <> '1'
       AND a.JUDGE_STOVE_NO || '&' LIKE '%' || ? || '%' 
       AND a.PLINE_CODE = ?
       AND a.PRO_PLAN_ID  || '&' LIKE '%' || ? || '%'
       AND a.GX_PLAN_NO  || '&' LIKE '%' || ? || '%'
       ]]>
   </query>
<query id = "OffLine.GetMILPlanXX" desc = "下线点">
<![CDATA[
select *
  from MIL_PLAN a
 WHERE a.judge_stove_no || '&' LIKE '%' || ? || '%' 
 AND a.PLINE_CODE = ?
 AND a.PRO_PLAN_ID  || '&' LIKE '%' || ? || '%'
 AND a.GX_PLAN_NO  || '&' LIKE '%' || ? || '%'
 ]]>
</query>

<query id="OffLine.GetMILPlan21" desc="探傷工序">
	 <![CDATA[ 
    select *
      from MIL_PLAN a
     WHERE a.judge_stove_no in
           (select t.judge_stove_no
              from Mil_Straightening_Result t
             where t.node_fur_flag=1
             AND t.judge_stove_no in
                   (select b.judge_stove_no
                      from MIL_ET_RESULT b
                     where b.node_fur_flag = 0))
       AND a.offline_flag <> '1'
       AND a.judge_stove_no = ?
          ]]>
   </query>
   <query id="OffLine.GetMILPlan22" desc="探傷工序">
    <![CDATA[ 
    select *
      from MIL_PLAN a
     WHERE a.judge_stove_no in
           (select t.judge_stove_no
              from Mil_Straightening_Result t
             where t.node_fur_flag=1
             AND t.judge_stove_no in
                   (select b.judge_stove_no
                      from MIL_MT_RESULT b
                     where b.node_fur_flag = 0))
       AND a.offline_flag <> '1'
       AND a.judge_stove_no = ?
       ]]>
   </query>
   <query id="OffLine.GetMILPlan23" desc="探傷工序">
    <![CDATA[ 
    select *
      from MIL_PLAN a
     WHERE a.judge_stove_no in
           (select t.judge_stove_no
              from Mil_Straightening_Result t
             where t.node_fur_flag=1
             AND t.judge_stove_no in
                   (select b.judge_stove_no
                      from MIL_UL_RESUL b
                     where b.node_fur_flag = 0))                  
       AND a.offline_flag <> '1'
       AND a.judge_stove_no = ?
       ]]>
   </query>

	<query id="OffLine.UpdateRack0" desc="矯直工序">
	       <![CDATA[ 
		Update Mil_Straigh_Rack t
		set t.OFFLINE_FLAG ='1',
		t.offline_time =SYSDATE
    WHERE t.judge_stove_no=?
    AND t.seq in(   select SEQ
        from ( select a.seq AS SEQ
               from  Mil_Straigh_Rack a 
                       WHERE a.STATUS = 0
                       AND a.offline_flag <> 1
                       AND a.judge_stove_no = ?
                       AND a.col_no=?
                       AND a.mat_no is not null
                       order by a.seq desc )
                       WHERE rownum between 1 and ?)
                        ]]>
	</query>
	<query id="OffLine.UpdatetsRack0" desc="矫直工序下线要反应到探伤跟踪表里">
	<![CDATA[
	Update MIL_TESTING_RACK t
    set t.OFFLINE_FLAG ='1'
    WHERE t.judge_stove_no=?
    AND t.seq in(   select SEQ
        from ( select a.seq AS SEQ
               from  MIL_TESTING_RACK a 
                       WHERE a.STATUS <> 1
                       AND a.offline_flag <> 1
                       AND a.judge_stove_no = ?
                       AND a.col_no=?
                       order by a.seq desc )
                       WHERE rownum between 1 and ?)
		
	
	]]>
	</query>
	<query id="OffLine.UpdateResult01" desc="矫直实绩1#">
		UPDATE
		MIL_STRAIGHTENING_RESULT a
		SET a.OFFLINE_NUM1= a.OFFLINE_NUM1+?,
		a.OFFLINE_NUM_TOTAL=?+a.OFFLINE_NUM1
		+a.OFFLINE_NUM2+a.OFFLINE_NUM3
		WHERE a.JUDGE_STOVE_NO=?
	</query>
	<query id="OffLine.UpdateResult02" desc="矫直实绩2#">
		UPDATE
		MIL_STRAIGHTENING_RESULT a
		SET a.OFFLINE_NUM2= a.OFFLINE_NUM2+?,
		a.OFFLINE_NUM_TOTAL=OFFLINE_NUM2+
		?+a.OFFLINE_NUM1+a.OFFLINE_NUM3
		WHERE a.JUDGE_STOVE_NO=?
	</query>
	<query id="OffLine.UpdateResult03" desc="矫直实绩3#">
		UPDATE MIL_STRAIGHTENING_RESULT a
		SET a.OFFLINE_NUM3=a.OFFLINE_NUM3+?,
		a.OFFLINE_NUM_TOTAL=OFFLINE_NUM3+ ?+a.OFFLINE_NUM1+a.OFFLINE_NUM2
		WHERE a.JUDGE_STOVE_NO=?
	</query>

	<query id="OffLine.UpdateRack1" desc="探傷工序">
	     <![CDATA[ 
		Update MIL_TESTING_RACK t
		set t.OFFLINE_FLAG ='1',
		t.offline_time =SYSDATE,
		t.col_no=?
    WHERE t.judge_stove_no=?
    AND  t.seq in(   select SEQ
        from ( select a.seq AS SEQ
               from  MIL_TESTING_RACK a 
                       WHERE a.STATUS <> 1
                       AND a.offline_flag <> 1
                       AND a.judge_stove_no = ?
                       AND (a.col_no='' OR a.col_no is null) 
                       --AND a.mat_no is not null
                       order by a.seq  desc)
                       WHERE rownum between 1 and ?)
                        ]]>
		
	</query>
	<query id="OffLine.UpdateQARack" desc="人工质检">
	<![CDATA[ 
	Update MIL_QA_RACK t
		set t.OFFLINE_FLAG ='1'
    WHERE t.judge_stove_no=?
    AND t.seq in(   select SEQ
        from ( select a.seq AS SEQ
               from  MIL_QA_RACK a 
                       WHERE a.STATUS = 0
                       AND a.offline_flag <> 1
                       AND a.judge_stove_no = ?
                       order by a.seq  desc)
                       WHERE rownum between 1 and ?)
                       ]]>
	</query>
	
	<query id="OffLine.UpdateResult111" desc="探伤实绩ET">
	UPDATE MIL_ET_RESULT t
    SET
    t.OFFLINE_NUM1=t.OFFLINE_NUM1+?,
    t.OFFLINE_NUM=t.OFFLINE_NUM1+?+t.OFFLINE_NUM2+t.OFFLINE_NUM3
    WHERE
	t.Judge_Stove_No=?
	</query>
		<query id="OffLine.UpdateResult112" desc="探伤实绩ET">
	UPDATE MIL_ET_RESULT t
    SET 
    t.OFFLINE_NUM2=t.OFFLINE_NUM2+?,
    t.OFFLINE_NUM=t.OFFLINE_NUM1+?+t.OFFLINE_NUM2+t.OFFLINE_NUM3
    WHERE
	t.Judge_Stove_No=?
	</query>
		<query id="OffLine.UpdateResult113" desc="探伤实绩ET">
	UPDATE MIL_ET_RESULT t
    SET 
    t.OFFLINE_NUM3=t.OFFLINE_NUM3+?,
    t.OFFLINE_NUM=t.OFFLINE_NUM1+?+t.OFFLINE_NUM2+t.OFFLINE_NUM3
    WHERE
	t.Judge_Stove_No=?
	</query>
	<query id="OffLine.UpdateResult121" desc="探伤实绩MT">
	UPDATE MIL_MT_RESULT t
    SET 
     t.OFFLINE_NUM=t.OFFLINE_NUM1+to_number(?)+t.OFFLINE_NUM2,
     t.OFFLINE_NUM1=t.OFFLINE_NUM1+to_number(?)
    WHERE
	t.Judge_Stove_No=?
	</query>
		<query id="OffLine.UpdateResult122" desc="探伤实绩MT">
	UPDATE MIL_MT_RESULT t
    SET 
     t.OFFLINE_NUM=t.OFFLINE_NUM1+?+t.OFFLINE_NUM2,
     t.OFFLINE_NUM2=t.OFFLINE_NUM2+?
    WHERE
	t.Judge_Stove_No=?
	</query>
	<query id="OffLine.UpdateResult131" desc="探伤实绩UT">
	UPDATE MIL_UL_RESUL t
    SET 
     t.OFFLINE_NUM=t.OFFLINE_NUM1+?+t.OFFLINE_NUM2,
     t.OFFLINE_NUM1=t.OFFLINE_NUM1+?
    WHERE
	t.Judge_Stove_No=?
	</query>
		<query id="OffLine.UpdateResult132" desc="探伤实绩UT">
	UPDATE MIL_UL_RESUL t
    SET 
     t.OFFLINE_NUM=t.OFFLINE_NUM1+?+t.OFFLINE_NUM2,
     t.OFFLINE_NUM2=t.OFFLINE_NUM2+?
    WHERE
	t.Judge_Stove_No=?
	</query>

	<query id="OffLine.UpdateMILPLAN" desc="更新主表下线标识及时间">
		UPDATE MIL_PLAN t SET
		t.OFFLINE_DATE=SYSDATE,
		t.OFFLINE_FLAG='1'
		WHERE
		t.JUDGE_STOVE_NO=?
	</query>
<query id="OffLine.InsertOfflineResult" desc="插入下线实绩">
INSERT INTO MIL_OFFLINE_RESLUT(
        LOT_NO,
        STOVE_NO,
        JUDGE_STOVE_NO,
        DIAMETER,
        THICKNESS,
        LENGTH,
        PLINE_CODE,
        OFFLINE_PRO,
        OFFLINE_NUM,
        STATUS,
        TYPE_FLAG,
        OFFLINE_TIME,
        COL_USER,
        COL_SHIFT,
        COL_GROUP)
 VALUES( 
        '#LOT_NO#',
        '#STOVE_NO#',
        '#JUDGE_STOVE_NO#',
        '#DIAMETER#',
        '#THICKNESS#',
        '#LENGTH#',
        '#PLINE_CODE#',
        '#OFFLINE_PRO#',
        '#OFFLINE_NUM#',
        '#STATUS#',
        '#TYPE_FLAG#',
        SYSDATE,
        '#COL_USER#',
        '#COL_SHIFT#',
        '#COL_GROUP#')
</query>
<query id="OffLine.UpdateOfflineResultNum1" desc="更新下线实绩">
 UPDATE MIL_OFFLINE_RESLUT
   SET 
        OFFLINE_NUM = '#OFFLINE_NUM1#'+OFFLINE_NUM
 WHERE
 1=1
 AND  JUDGE_STOVE_NO='#JUDGE_STOVE_NO#'
 AND  OFFLINE_PRO='#OFFLINE_PRO#'
</query>
<query id="OffLine.UpdateOfflineResultNum2" desc="更新下线实绩">
 UPDATE MIL_OFFLINE_RESLUT
   SET 
        
        OFFLINE_NUM = '#OFFLINE_NUM2#'+OFFLINE_NUM
 WHERE
 1=1
 AND  JUDGE_STOVE_NO='#JUDGE_STOVE_NO#'
 AND  OFFLINE_PRO='#OFFLINE_PRO#'
</query>
<query id="OffLine.UpdateOfflineResultNum3" desc="更新下线实绩">
 UPDATE MIL_OFFLINE_RESLUT
   SET 
        
        OFFLINE_NUM = '#OFFLINE_NUM3#'+OFFLINE_NUM
 WHERE
 1=1
 AND  JUDGE_STOVE_NO='#JUDGE_STOVE_NO#'
 AND  OFFLINE_PRO='#OFFLINE_PRO#'
</query>

<query id="OffLine.UpdateOfflineResult" desc="更新下线实绩">
 UPDATE MIL_OFFLINE_RESLUT
   SET 
        LOT_NO = '#LOT_NO#',
        STOVE_NO = '#STOVE_NO#',
        DIAMETER = '#DIAMETER#',
        THICKNESS = '#THICKNESS#',
        LENGTH = '#LENGTH#',
        PLINE_CODE = '#PLINE_CODE#',
        OFFLINE_PRO = '#OFFLINE_PRO#',
        OFF_LEVEL = '#OFF_LEVEL#',
        STATUS = '#STATUS#',
        TYPE_FLAG = '#TYPE_FLAG#',
        REMARK = '#REMARK#',
        COL_USER = '#COL_USER#',
        COL_SHIFT = '#COL_SHIFT#',
        COL_GROUP = '#COL_GROUP#'
 WHERE
 1=1
 AND  JUDGE_STOVE_NO='#JUDGE_STOVE_NO#'
 AND  OFFLINE_PRO='#OFFLINE_PRO#'
</query>
<query id="OffLine.UpdateRackBack1" desc="探伤下线管号队列修改">
<![CDATA[ 
Update MIL_TESTING_RACK t
    set t.OFFLINE_FLAG ='0',
    t.offline_time ='',
    t.col_no=''
    WHERE t.judge_stove_no=?
    AND  t.seq in(   select SEQ
        from ( select a.seq AS SEQ
               from  MIL_TESTING_RACK a 
                       WHERE a.STATUS <> 1
                       AND a.offline_flag = 1
                       AND a.judge_stove_no = ?
                       AND a.col_no=?
                       --AND a.mat_no is not null
                       order by a.seq  desc)
                       WHERE rownum between 1 and ?)
                        ]]>                     
</query>
<query id="OffLine.UpdateResultBack111" desc="修改ET探伤下线实绩">
	UPDATE MIL_ET_RESULT t
    SET
    t.OFFLINE_NUM1=t.OFFLINE_NUM1-?,
    t.OFFLINE_NUM=t.OFFLINE_NUM1-?+t.OFFLINE_NUM2+t.OFFLINE_NUM3
    WHERE
	t.Judge_Stove_No=?
</query>
<query id="OffLine.UpdateResultBack112" desc="修改ET探伤下线实绩">
	UPDATE MIL_ET_RESULT t
    SET 
    t.OFFLINE_NUM2=t.OFFLINE_NUM2-?,
    t.OFFLINE_NUM=t.OFFLINE_NUM1-?+t.OFFLINE_NUM2+t.OFFLINE_NUM3
    WHERE
	t.Judge_Stove_No=?
</query>
<query id="OffLine.UpdateResultBack113" desc="修改ET探伤下线实绩">
	UPDATE MIL_ET_RESULT t
    SET 
    t.OFFLINE_NUM3=t.OFFLINE_NUM3-?,
    t.OFFLINE_NUM=t.OFFLINE_NUM1-?+t.OFFLINE_NUM2+t.OFFLINE_NUM3
    WHERE
	t.Judge_Stove_No=?
</query>
<query id ="OffLine.UpdateResultBack121" desc="修改MT探伤下线实绩">
	UPDATE MIL_MT_RESULT t
    SET 
     t.OFFLINE_NUM=t.OFFLINE_NUM1-?+t.OFFLINE_NUM2,
     t.OFFLINE_NUM1=t.OFFLINE_NUM1-?
    WHERE
	t.Judge_Stove_No=?
</query>
<query id="OffLine.UpdateResultBack122" desc="修改MT探伤下线实绩">
	UPDATE MIL_MT_RESULT t
    SET 
     t.OFFLINE_NUM=t.OFFLINE_NUM1-?+t.OFFLINE_NUM2,
     t.OFFLINE_NUM2=t.OFFLINE_NUM2-?
    WHERE
	t.Judge_Stove_No=?
</query>
<query id="OffLine.UpdateResultBack131" desc="修改UT探伤下线实绩">
	UPDATE MIL_UL_RESUL t
    SET 
     t.OFFLINE_NUM=t.OFFLINE_NUM1-?+t.OFFLINE_NUM2,
     t.OFFLINE_NUM1=t.OFFLINE_NUM1-?
    WHERE
	t.Judge_Stove_No=?
</query>
<query id="OffLine.UpdateResultBack132" desc="修改UT探伤下线实绩">
	UPDATE MIL_UL_RESUL t
    SET 
     t.OFFLINE_NUM=t.OFFLINE_NUM1-?+t.OFFLINE_NUM2,
     t.OFFLINE_NUM2=t.OFFLINE_NUM2-?
    WHERE
	t.Judge_Stove_No=?
</query>
<query id="OffLine.UpdateQARackBack" desc="修改人工质检管号队列">
<![CDATA[ 
  Update MIL_QA_RACK t
    set t.OFFLINE_FLAG ='0'
    WHERE t.judge_stove_no=?
    AND t.seq in(   select SEQ
        from ( select a.seq AS SEQ
               from  MIL_QA_RACK a 
                       WHERE a.STATUS = 0
                       AND a.offline_flag = 1
                       AND a.judge_stove_no = ?
                       order by a.seq  desc)
                       WHERE rownum between 1 and ?)
                       ]]>
</query>
<query id = "OffLine.getOffineCount" desc = "查询可下线支数">
SELECT (T.QUALIFIED_NUM - S.QUALIFIED_NUM-S.SCRAP_NUM-S.INSPECTIONED_OFFLINE_NUM-S.OFFLINE_NUM-S.SAMPLE_NUM)AS OFFLINE_COUNT
          FROM MIL_STRAIGHTENING_RESULT T
          LEFT JOIN #TABLENAME# S ON T.JUDGE_STOVE_NO = S.JUDGE_STOVE_NO
                                   AND T.RESULT_NO = S.RESULT_NO
                                   WHERE T.JUDGE_STOVE_NO = ?
                                   AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
   									AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
</query>
<query id = "OffLine.getStraighteningCount" desc = "查询矫直可下线支数">
SELECT (T.CUT_DBNUM - nvl(S.SCRAP_NUM,0) -
       nvl(S.OFFLINE_NUM_TOTAL,0)) AS OFFLINE_COUNT
  FROM MIL_SAW_RESULT T
  LEFT JOIN MIL_STRAIGHTENING_RESULT S ON T.JUDGE_STOVE_NO = S.JUDGE_STOVE_NO
                         AND T.RESULT_NO = S.RESULT_NO
 WHERE T.JUDGE_STOVE_NO = ?
 AND T.PLINE_CODE = ?
</query>
<!-- SELECT (T.Cut_Dbnum - S.SCRAP_NUM -
       S.OFFLINE_NUM_TOTAL) AS OFFLINE_COUNT
  FROM MIL_SAW_RESULT T
  LEFT JOIN MIL_STRAIGHTENING_RESULT S ON T.JUDGE_STOVE_NO = S.JUDGE_STOVE_NO
                         AND T.RESULT_NO = S.RESULT_NO
 WHERE T.JUDGE_STOVE_NO = ?
 AND T.PLINE_CODE = ? -->
<query id = "Offline.GetCountHAS" desc = "查询已下线支数">
SELECT NVL(T.OFFLINE_NUM, 0) OFFLINE_NUM
  FROM MIL_OFFLINE_RESLUT T
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.OFFLINE_PRO = ?
   AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
   AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
   AND T.OFFLINE_TYPE = '1'
</query>
<query id = "Offline.GetStraighteningCountHAS" desc = "查询矫直已下线支数">
SELECT NVL(T.OFFLINE_NUM,0)OFFLINE_NUM FROM MIL_OFFLINE_RESLUT T WHERE T.JUDGE_STOVE_NO = ? AND T.OFFLINE_PRO = ?
</query>
<query id = "FrmOffLine.offLineTS" desc = "下线操作">
<![CDATA[
DECLARE
  V_OFFCOUNT       MIL_OFFLINE_RESLUT.OFFLINE_NUM%TYPE := NULL;
  V_RESULTCOUNT    MIL_MT_RESULT.OFFLINE_NUM%TYPE := NULL;
  V_QUALIFIED_NUM  MIL_MT_RESULT.QUALIFIED_NUM%TYPE := NULL;
  V_JUDGE_STOVE_NO MIL_OFFLINE_RESLUT.JUDGE_STOVE_NO%TYPE := ?;
  V_PLINE_CODE     MIL_OFFLINE_RESLUT.PLINE_CODE%TYPE := ?;
  V_PRO_PLAN_ID    MIL_OFFLINE_RESLUT.PRO_PLAN_ID%TYPE := ?;
  V_GX_PLAN_NO     MIL_OFFLINE_RESLUT.GX_PLAN_NO%TYPE := ?;
  V_OFFLINE_DOC    MIL_OFFLINE_RESLUT.OFFLINE_DOC%TYPE := NULL;
BEGIN
  SELECT 'D' || TO_CHAR(SYSDATE, 'YYYYMM') ||
         LPAD(NVL(MAX(SUBSTR(T.OFFLINE_DOC, 8, 4)), 0) + 1, 4, 0)
    INTO V_OFFLINE_DOC
    FROM MIL_OFFLINE_RESLUT T
   WHERE TO_CHAR(T.OFFLINE_TIME, 'YYYYMM') = TO_CHAR(SYSDATE, 'YYYYMM');

  SELECT COUNT(1)
    INTO V_OFFCOUNT
    FROM MIL_OFFLINE_RESLUT T
   WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
     AND T.PRO_PLAN_ID = V_PRO_PLAN_ID
     AND T.GX_PLAN_NO = V_GX_PLAN_NO
     AND T.PLINE_CODE = V_PLINE_CODE
     AND T.OFFLINE_PRO = 'TS'
     AND T.STATUS = '0'
     AND T.OFFLINE_TYPE = '1';

  IF (V_OFFCOUNT > 0) THEN
    UPDATE MIL_OFFLINE_RESLUT T
       SET T.OFFLINE_NUM = TO_NUMBER(T.OFFLINE_NUM) + TO_NUMBER(?)
     WHERE T.JUDGE_STOVE_NO = ?
       AND T.PRO_PLAN_ID = V_PRO_PLAN_ID
       AND T.GX_PLAN_NO = V_GX_PLAN_NO
       AND T.OFFLINE_PRO = 'TS'
       AND T.STATUS = '0'
       AND T.OFFLINE_TYPE = '1';
  ELSE
    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_SHIFT,
       COL_GROUP,
       OFFLINE_TYPE,
       ZP_HEIGHT,
       TARGET,
       IMP_PROCESS,
       PRO_PLAN_ID,
       GX_PLAN_NO,
       OFFLINE_DOC)
    VALUES
      ('0',
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       REPLACE(?,'*','x'),
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       '0',
       '0',
       '0',
       '',
       ?,
       '',
       ?,
       ?,
       ?,
       ?,
       ?,
       'TS',
       '0',
       ?,
       '0',
       '0',
       '0',
       '0',
       '0',
       ?,
       TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
       '',
       ?,
       ?,
       ?,
       '1',
       ?,
       ?,
       ?,
       V_PRO_PLAN_ID,
       V_GX_PLAN_NO,
       V_OFFLINE_DOC);
  END IF;

  IF (? = 'C009' OR ? = 'C008' OR ? = 'C017') THEN
    UPDATE MIL_MT_RESULT T
       SET T.OFFLINE_NUM = TO_NUMBER(T.OFFLINE_NUM) + TO_NUMBER(?)
     WHERE T.JUDGE_STOVE_NO = ?
       AND T.PRO_PLAN_ID = V_PRO_PLAN_ID
       AND T.GX_PLAN_NO = V_GX_PLAN_NO
       AND T.PLINE_CODE = ?;
  ELSIF (? = 'C010') THEN
    UPDATE MIL_ET_RESULT T
       SET T.OFFLINE_NUM = TO_NUMBER(T.OFFLINE_NUM) + TO_NUMBER(?)
     WHERE T.JUDGE_STOVE_NO = ?
       AND T.PRO_PLAN_ID = V_PRO_PLAN_ID
       AND T.GX_PLAN_NO = V_GX_PLAN_NO
       AND T.PLINE_CODE = ?;
  END IF;
  FOR MYROW IN (SELECT *
                  FROM (SELECT T.SEQ
                          FROM MIL_TESTING_RACK T
                         WHERE T.JUDGE_STOVE_NO = ?
                           AND T.PLINE_CODE = ?
                           AND T.PRO_PLAN_ID = V_PRO_PLAN_ID
                           AND T.GX_PLAN_NO = V_GX_PLAN_NO
                              --AND T.COL_SHIFT IS NULL
                              --AND T.COL_GROUP IS NULL
                           AND T.OFFLINE_FLAG = '0'
                           AND T.STATUS = '0'
                           AND T.SUSPECT_FLAG = '0'
                         ORDER BY T.SEQ ASC)
                 WHERE ROWNUM <= ?) LOOP
    UPDATE MIL_TESTING_RACK T
       SET T.OFFLINE_FLAG = '1',
           T.OFFLINE_TYPE = '1',
           T.OFFLINE_TIME = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS')
     WHERE T.JUDGE_STOVE_NO = ?
       AND T.PRO_PLAN_ID = V_PRO_PLAN_ID
       AND T.GX_PLAN_NO = V_GX_PLAN_NO
       AND T.PLINE_CODE = ?
       AND T.SEQ = MYROW.SEQ;
  END LOOP;
  IF (? = 1) THEN
    SELECT SUM(QUALIFIED_NUM)
      INTO V_QUALIFIED_NUM
      FROM (SELECT T.QUALIFIED_NUM
              FROM MIL_MT_RESULT T
             WHERE T.JUDGE_STOVE_NO = ?
               AND T.PRO_PLAN_ID = V_PRO_PLAN_ID
               AND T.GX_PLAN_NO = V_GX_PLAN_NO
            UNION ALL
            SELECT T.QUALIFIED_NUM
              FROM MIL_ET_RESULT T
             WHERE T.JUDGE_STOVE_NO = ?
               AND T.PRO_PLAN_ID = V_PRO_PLAN_ID
               AND T.GX_PLAN_NO = V_GX_PLAN_NO
            UNION ALL
            SELECT T.QUALIFIED_NUM
              FROM MIL_UL_RESUL T
             WHERE T.JUDGE_STOVE_NO = ?
               AND T.PRO_PLAN_ID = V_PRO_PLAN_ID
               AND T.GX_PLAN_NO = V_GX_PLAN_NO);
    IF (V_QUALIFIED_NUM = 0) THEN
      UPDATE MIL_PLAN T
         SET T.ROLLING_STATUS = '1'
       WHERE JUDGE_STOVE_NO = ?
         AND T.PRO_PLAN_ID = V_PRO_PLAN_ID
         AND T.GX_PLAN_NO = V_GX_PLAN_NO;
    END IF;
  END IF;
END;
]]>
</query>
<query id = "FrmOffLine.offLineJZ" desc = "矫直下线操作">
<![CDATA[
DECLARE
  V_OFFCOUNT       MIL_OFFLINE_RESLUT.OFFLINE_NUM%TYPE := NULL;
  V_RESULTCOUNT    MIL_STRAIGHTENING_RESULT.OFFLINE_NUM_TOTAL%TYPE := NULL;
  V_QUALIFIED_NUM  MIL_STRAIGHTENING_RESULT.QUALIFIED_NUM%TYPE := NULL;
  V_JUDGE_STOVE_NO MIL_OFFLINE_RESLUT.JUDGE_STOVE_NO%TYPE := ?;
  V_PLINE_CODE     MIL_OFFLINE_RESLUT.PLINE_CODE%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;
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
     AND T.PLINE_CODE = V_PLINE_CODE;

  SELECT COUNT(1)
    INTO V_OFFCOUNT
    FROM MIL_OFFLINE_RESLUT T
   WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
     AND T.PLINE_CODE = V_PLINE_CODE
     AND T.OFFLINE_PRO = 'JZ';

  IF (V_OFFCOUNT > 0) THEN
    UPDATE MIL_OFFLINE_RESLUT T
       SET T.OFFLINE_NUM = TO_NUMBER(T.OFFLINE_NUM) + TO_NUMBER(?)
     WHERE T.JUDGE_STOVE_NO = ?
       AND T.OFFLINE_PRO = 'JZ';
  ELSE
    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_SHIFT,
       COL_GROUP,
       OFFLINE_TYPE,
       ZP_HEIGHT,
       TARGET,
       IMP_PROCESS,
       PRO_PLAN_ID,
       GX_PLAN_NO)
    VALUES
      ('0',
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       REPLACE(?,'*','x'),
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       '0',
       '0',
       '0',
       '',
       ?,
       '',
       ?,
       ?,
       ?,
       ?,
       ?,
       'JZ',
       '0',
       ?,
       '0',
       '0',
       '0',
       '0',
       '0',
       ?,
       TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
       '',
       ?,
       ?,
       ?,
       '3',
       ?,
       ?,
       ?,
       V_PRO_PLAN_ID,
       V_GX_PLAN_NO);
  END IF;
  UPDATE MIL_STRAIGHTENING_RESULT T
     SET T.OFFLINE_NUM_TOTAL = TO_NUMBER(T.OFFLINE_NUM_TOTAL) + TO_NUMBER(?),
         T.QUALIFIED_NUM     = TO_NUMBER(T.QUALIFIED_NUM) - TO_NUMBER(?)
   WHERE T.JUDGE_STOVE_NO = ?
     AND T.PLINE_CODE = ?;
  FOR MYROW IN (SELECT *
                  FROM (SELECT T.SEQ
                          FROM MIL_STRAIGH_RACK T
                         WHERE T.JUDGE_STOVE_NO = ?
                           AND T.PLINE_CODE = ?
                              --AND T.COL_SHIFT IS NULL
                              --AND T.COL_GROUP IS NULL
                           AND T.OFFLINE_FLAG = '0'
                           AND T.STATUS = '0'
                         ORDER BY T.SEQ ASC)
                 WHERE ROWNUM <= ?) LOOP
    UPDATE MIL_STRAIGH_RACK T
       SET T.OFFLINE_FLAG = '1',
           T.STATUS       = '3',
           T.OFFLINE_TIME = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS')
     WHERE T.JUDGE_STOVE_NO = ?
       AND T.PLINE_CODE = ?
       AND T.SEQ = MYROW.SEQ;
  END LOOP;
  IF (? = 1) THEN
    SELECT SUM(QUALIFIED_NUM)
      INTO V_QUALIFIED_NUM
      FROM (SELECT T.QUALIFIED_NUM
              FROM MIL_STRAIGHTENING_RESULT T
             WHERE T.JUDGE_STOVE_NO = ?);
    IF (V_QUALIFIED_NUM = 0) THEN
      UPDATE MIL_PLAN T
         SET T.ROLLING_STATUS = '1'
       WHERE JUDGE_STOVE_NO = ?;
    END IF;
  END IF;
END;
]]>
</query>

<query id = "FrmOffLine.offLineXX" desc = "下线点离线操作">
<![CDATA[
DECLARE
  V_OFFCOUNT            MIL_OFFLINE_RESLUT.OFFLINE_NUM%TYPE := NULL;
  V_RESULTCOUNT         MIL_STRAIGHTENING_RESULT.OFFLINE_NUM_TOTAL%TYPE := NULL;
  V_QUALIFIED_NUM       MIL_STRAIGHTENING_RESULT.QUALIFIED_NUM%TYPE := NULL;
  V_JUDGE_STOVE_NO      MIL_OFFLINE_RESLUT.JUDGE_STOVE_NO%TYPE := ?;
  V_PLINE_CODE          MIL_OFFLINE_RESLUT.PLINE_CODE%TYPE := ?;
  V_PRO_PLAN_ID         MIL_OFFLINE_RESLUT.PRO_PLAN_ID%TYPE := ?;
  V_GX_PLAN_NO          MIL_OFFLINE_RESLUT.GX_PLAN_NO%TYPE := ?;
  V_LOAD_JUDGE_STOVE_NO MIL_OFFLINE_RESLUT.LOAD_JUDGE_STOVE_NO%TYPE := NULL;
BEGIN
  --上料炉号
  SELECT T.FEED_HEAT_NO
    INTO V_LOAD_JUDGE_STOVE_NO
    FROM MIL_PLAN T
   WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
     AND T.PLINE_CODE = V_PLINE_CODE
     AND NVL(T.PRO_PLAN_ID, '/') = NVL(V_PRO_PLAN_ID, '/')
     AND NVL(T.GX_PLAN_NO, '/') = NVL(V_GX_PLAN_NO, '/');

  SELECT COUNT(1)
    INTO V_OFFCOUNT
    FROM MIL_OFFLINE_RESLUT T
   WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
     AND T.PLINE_CODE = V_PLINE_CODE
     AND NVL(T.PRO_PLAN_ID, '/') = NVL(V_PRO_PLAN_ID, '/')
     AND NVL(T.GX_PLAN_NO, '/') = NVL(V_GX_PLAN_NO, '/')
     AND T.OFFLINE_PRO = 'XX';

  IF (V_OFFCOUNT > 0) THEN
    UPDATE MIL_OFFLINE_RESLUT T
       SET T.OFFLINE_NUM = TO_NUMBER(T.OFFLINE_NUM) + TO_NUMBER(?)
     WHERE T.JUDGE_STOVE_NO = ?
       AND NVL(T.PRO_PLAN_ID, '/') = NVL(V_PRO_PLAN_ID, '/')
       AND NVL(T.GX_PLAN_NO, '/') = NVL(V_GX_PLAN_NO, '/')
       AND T.OFFLINE_PRO = 'XX';
  ELSE
    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_SHIFT,
       COL_GROUP,
       OFFLINE_TYPE,
       ZP_HEIGHT,
       TARGET,
       IMP_PROCESS,
       PRO_PLAN_ID,
       GX_PLAN_NO,
       OFFLINE_DOC,
       LOAD_JUDGE_STOVE_NO)
    VALUES
      ('0',
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       '0',
       '0',
       '0',
       '',
       ?,
       '',
       ?,
       ?,
       ?,
       ?,
       ?,
       'XX',
       '0',
       ?,
       '0',
       '0',
       '0',
       '0',
       '0',
       ?,
       TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
       '',
       ?,
       ?,
       ?,
       '0',
       ?,
       ?,
       ?,
       V_PRO_PLAN_ID,
       V_GX_PLAN_NO,
       ?,
       V_LOAD_JUDGE_STOVE_NO);
  END IF;
END;

]]>
</query>
<!-- UPDATE MIL_STRAIGHTENING_RESULT T SET T.OFFLINE_NUM_TOTAL = TO_NUMBER(T.OFFLINE_NUM_TOTAL)+TO_NUMBER(?),T.QUALIFIED_NUM = TO_NUMBER(T.QUALIFIED_NUM)-TO_NUMBER(?) WHERE T.JUDGE_STOVE_NO = ? AND T.PLINE_CODE = ?;
FOR MYROW IN (SELECT *
                  FROM (SELECT T.MAT_NO
                          FROM PORT_MIL_BATCH_SAMPLE_RESULT T  
                         WHERE T.JUDGE_STOVE_NO = ?
                           AND T.PLINE_CODE = ?
                           AND T.STATUS = '0'
                           AND T.INSTORE_FLAG = '0'
                         ORDER BY T.IS_SAMPLE_PIPE,T.MAT_NO ASC)
                 WHERE ROWNUM <= ?)LOOP
  UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T
   SET T.STATUS = '3',
   T.OP_PROCESS = '12'
   WHERE T.JUDGE_STOVE_NO = ?
     AND T.PLINE_CODE = ?
     AND T.MAT_NO = MYROW.MAT_NO;
     END LOOP; -->

<query id = "FrmOffLine.insertMilSlab" desc = "下线插入剔除序号表">
<![CDATA[
DECLARE
  V_OFFCOUNT      MIL_OFFLINE_RESLUT.OFFLINE_NUM%TYPE := NULL;
  V_RESULTCOUNT   MIL_MT_RESULT.OFFLINE_NUM%TYPE := NULL;
  V_QUALIFIED_NUM MIL_MT_RESULT.QUALIFIED_NUM%TYPE := NULL;
BEGIN

  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 NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
                           AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
                           AND T.OFFLINE_FLAG = '0'
                           AND T.STATUS = '0'
                           AND T.SUSPECT_FLAG = '0'
                         ORDER BY T.SEQ ASC)
                 WHERE ROWNUM <= ?) LOOP
    INSERT INTO MIL_SLAB_SCRAP_SEQ
      (COL_NO,
       COL_TYPE,
       JUDGE_STOVE_NO,
       PROCESS_NO,
       SEQ,
       TIME,
       FLAG,
       COL_MODE,
       COL_TIME,
       COL_USER,
       COL_SHIFT,
       COL_GROUP,
       RESULT_NO,
       OFFLINE_TYPE,
       PRO_PLAN_ID,
       GX_PLAN_NO,
       MAT_NO)
    VALUES
      (?,
       ?,
       ?,
       ?,
       MYROW.SEQ,
       SYSDATE,
       ?,
       ?,
       SYSDATE,
       ?,
       ?,
       ?,
       ?,
       '1',
       ?,
       ?,
       MYROW.MAT_NO);
  END LOOP;
END;

]]>
</query>
<query id = "FrmOffLine.insertMilSlab1" desc = "矫直下线插入剔除序号表">
<![CDATA[
DECLARE
  V_OFFCOUNT      MIL_OFFLINE_RESLUT.OFFLINE_NUM%TYPE := NULL;
  V_RESULTCOUNT   MIL_MT_RESULT.OFFLINE_NUM%TYPE := NULL;
  V_QUALIFIED_NUM MIL_MT_RESULT.QUALIFIED_NUM%TYPE := NULL;
BEGIN
  FOR MYROW IN (SELECT *
                  FROM (SELECT T.SEQ,T.PRO_PLAN_ID,T.GX_PLAN_NO,T.MAT_NO
                          FROM MIL_STRAIGH_RACK T
                         WHERE T.JUDGE_STOVE_NO = ?
                           AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
                           AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
                           AND T.PLINE_CODE = ?
                              --AND T.COL_SHIFT IS NULL
                              --AND T.COL_GROUP IS NULL
                           AND T.OFFLINE_FLAG = '0'
                           AND T.STATUS = '0'
                         ORDER BY T.SEQ ASC)
                 WHERE ROWNUM <= ?) LOOP
    INSERT INTO MIL_SLAB_SCRAP_SEQ
      (COL_NO,
       COL_TYPE,
       JUDGE_STOVE_NO,
       PROCESS_NO,
       SEQ,
       TIME,
       FLAG,
       COL_MODE,
       COL_TIME,
       COL_USER,
       COL_SHIFT,
       COL_GROUP,
       RESULT_NO,
       PRO_PLAN_ID,
       GX_PLAN_NO,
       MAT_NO)
    VALUES
      (?,
       ?,
       ?,
       ?,
       MYROW.SEQ,
       SYSDATE,
       ?,
       ?,
       SYSDATE,
       ?,
       ?,
       ?,
       ?,
       MYROW.PRO_PLAN_ID,
       MYROW.GX_PLAN_NO,
       MYROW.MAT_NO);
  END LOOP;
END;
]]>
</query>
<query id = "FrmOffLine.insertMatTS" desc = "离线时入在线库">
DECLARE
  V_TIME              MIL_OFFLINE_RESLUT.OFFLINE_TIME%TYPE := SYSDATE;
  V_JUDGE_STOVE_NO    MIL_PLAN.JUDGE_STOVE_NO%TYPE := ?;
  V_BATCH_NO          PORT_MIL_BATCH_SAMPLE_RESULT.BATCH_NO%TYPE := ?;
  V_JUDGE_STOVE_NO_ZP MIL_PLAN.JUDGE_STOVE_NO%TYPE := NULL; --组炉炉号
  V_COUNT             MIL_PLAN.CRAFT_SEQ%TYPE := 0;
BEGIN
  select COUNT(1)
    INTO V_COUNT
    from MIL_OFFLINE_GROUP t
   WHERE REGEXP_REPLACE(T.ZP_JUDGE_STOVE_NO, '-.*', '') = V_JUDGE_STOVE_NO;

  IF (V_COUNT > 0) THEN
    select REGEXP_REPLACE(T.ZP_M_LH, '-.*', '')
      INTO V_JUDGE_STOVE_NO_ZP
      from MIL_OFFLINE_GROUP t
     WHERE REGEXP_REPLACE(T.ZP_JUDGE_STOVE_NO, '-.*', '') =
           V_JUDGE_STOVE_NO
       AND ROWNUM = 1;
  END IF;

  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_JUDGE_STOVE_NO, V_BATCH_NO, ?, ?, ?, ?, ?, ?, ?, V_TIME, ?, ?, ?, ?);

  FOR MYROW IN (SELECT A.*,
                       B.ORD_PK,
                       B.ORD_LN_PK,
                       (SELECT MAX(M.PIPE_SIZE_CODE)
                          FROM MIL_PLAN M
                         WHERE M.JUDGE_STOVE_NO LIKE A.FEED_HEAT_NO || '-%') SPEC_CODE,
                       (SELECT MAX(M.ROLL_STANDRAD_CODE)
                          FROM MIL_PLAN M
                         WHERE M.JUDGE_STOVE_NO LIKE A.FEED_HEAT_NO || '-%') STD_CODE,
                       (SELECT MAX(M.STD_STYLE)
                          FROM MIL_PLAN M
                         WHERE M.JUDGE_STOVE_NO LIKE A.FEED_HEAT_NO || '-%') STD_STYLE,
                       (SELECT DECODE(H.ORDER_TYP,
                                      '120108',
                                      '1',
                                      '120107',
                                      '2',
                                      '0')
                          FROM SLM_ORDER_HEAD H
                         WHERE H.ORD_PK = B.ORD_PK) ORDER_TYP
                  FROM PLN_ZY_ZG_M A, SLM_ORDER_LINE_DELIVERY B
                 WHERE A.ORD_LN_DLY_PK = B.ORD_LN_DLY_PK(+)
                   AND A.IF_FLAG = '0'
                   AND A.PLANSTATUS > '00'
                   AND A.FEED_HEAT_NO =
                       NVL(V_JUDGE_STOVE_NO_ZP, V_JUDGE_STOVE_NO)) LOOP
    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,
       INSTOCK_TIME,
       STOVE_NO,
       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,
       ORDER_NO,
       ORDER_SEQ,
       ORDER_SEQ_NO,
       ORD_PK,
       ORD_LN_PK,
       ORD_LN_DLY_PK,
       OFFLINE_DOC,
       IS_DEALER,
       MAT_GOWHERE_CODE,
       MAT_GOWHERE_NAME,
       BELONG_CODE_RESPONSE,
       BELONG_NAME_RESPONSE)
    VALUES
      (?,
       ?,
       ?,
       ?,
       ?,
       TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
       ?,
       ?,
       ?,
       ?,
       (SELECT P.PLINE_NAME FROM COM_BASE_PLINE P WHERE P.PLINE_CODE = ?),
       ?,
       ?,
       ?,
       NVL(?, MYROW.PRODUCCODE),
       ?,
       NVL(?, MYROW.STEELCODE),
       ?,
       NVL(?, MYROW.SPEC_CODE),
       ?,
       NVL(?, MYROW.GRADECODE),
       ?,
       NVL(?, MYROW.MODEL_CODE),
       ?,
       NVL(?, MYROW.STD_CODE),
       ?,
       ?,
       ?,
       NVL(?, MYROW.STD_STYLE),
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       SYSDATE,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       'D',
       '轧制',
       MYROW.ORDER_NO,
       MYROW.ORDER_SEQ,
       MYROW.DELIVERY_NO,
       MYROW.ORD_PK,
       MYROW.ORD_LN_PK,
       MYROW.ORD_LN_DLY_PK,
       ?,
       MYROW.ORDER_TYP,
       NVL(MYROW.GOWHERE_CODE, '/'),
       NVL(MYROW.GOWHERE_NAME, '/'),
       MYROW.PLINE_CODE,
       MYROW.PLINE_NAME);
  END LOOP;
END;

</query>
<query id = "FrmOffLine.doQueryResult" desc = "查询是否已存在实绩">
SELECT SUM(ACOUNT)ACOUNT FROM (
SELECT COUNT(1)ACOUNT FROM MIL_MT_RESULT T WHERE T.Judge_Stove_No = ?
UNION ALL 
SELECT COUNT(1)ACOUNT FROM MIL_ET_RESULT T WHERE T.Judge_Stove_No = ?
UNION ALL
SELECT COUNT(1)ACOUNT FROM MIL_UL_RESUL T WHERE T.Judge_Stove_No = ?
)
</query>

<query id = "FrmOffLine.selectBelongCode" desc = " 查询产线、科室">
select t.*, t.rowid from COM_BASE_PLINE t WHERE T.PLINE_CODE = ? 
</query>
<query id = "FrmOffLine.newOfflineBack" desc = "下线回退">
<![CDATA[
DECLARE
  V_OFFINECOUNT MIL_OFFLINE_RESLUT.OFFLINE_NUM%TYPE := NULL;
BEGIN
  UPDATE MIL_OFFLINE_RESLUT T
     SET T.OFFLINE_NUM = TO_NUMBER(T.OFFLINE_NUM) - TO_NUMBER(?),
         T.ZP_HEIGHT   = TO_NUMBER(T.ZP_HEIGHT) - TO_NUMBER(?)
   WHERE T.JUDGE_STOVE_NO = ?
     AND T.OFFLINE_PRO = ?
     AND T.OFFLINE_TYPE = '1';
  UPDATE MIL_MT_RESULT T
     SET T.OFFLINE_NUM = TO_NUMBER(T.OFFLINE_NUM) - TO_NUMBER(?)
   WHERE T.JUDGE_STOVE_NO = ?;
  UPDATE MIL_ET_RESULT T
     SET T.OFFLINE_NUM = TO_NUMBER(T.OFFLINE_NUM) - TO_NUMBER(?)
   WHERE T.JUDGE_STOVE_NO = ?;
  UPDATE MIL_UL_RESUL T
     SET T.OFFLINE_NUM = TO_NUMBER(T.OFFLINE_NUM) - TO_NUMBER(?)
   WHERE T.JUDGE_STOVE_NO = ?;
  FOR MYROW IN (SELECT *
                  FROM (SELECT T.SEQ
                          FROM MIL_TESTING_RACK T
                         WHERE T.JUDGE_STOVE_NO = ?
                           AND T.OFFLINE_FLAG = '1'
                           AND T.OFFLINE_TYPE = '1'
                         ORDER BY T.SEQ DESC)
                 WHERE ROWNUM <= ?) LOOP
    UPDATE MIL_TESTING_RACK T
       SET T.OFFLINE_FLAG = '0',T.OFFLINE_TIME = '',T.OFFLINE_TYPE = '0'
     WHERE T.JUDGE_STOVE_NO = ?
       AND T.SEQ = MYROW.SEQ;
       DELETE FROM MIL_SLAB_SCRAP_SEQ T WHERE T.JUDGE_STOVE_NO = ? AND T.SEQ = MYROW.SEQ;
  END LOOP;
  SELECT T.OFFLINE_NUM
    INTO V_OFFINECOUNT
    FROM MIL_OFFLINE_RESLUT T
   WHERE T.JUDGE_STOVE_NO = ?
     AND T.OFFLINE_PRO = ?
     AND T.OFFLINE_TYPE = '1';
  IF (V_OFFINECOUNT = 0) THEN
    DELETE FROM MIL_OFFLINE_RESLUT T
     WHERE T.JUDGE_STOVE_NO = ?
       AND T.OFFLINE_PRO = ?
       AND T.OFFLINE_TYPE = '1';
  END IF;
  UPDATE MIL_PLAN T SET T.ROLLING_STATUS = '0',T.NODE_STATUS = '80' WHERE T.JUDGE_STOVE_NO = ?;
  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.QCM_STAUS = '11'
                           AND T.PRODUCT_FLAG = '801401'
                           AND T.MAT_STATUS = '80150104' 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 T WHERE T.MAT_NO = MYROW1.MAT_NO;
                  DELETE FROM YDM_BC_INLIST T WHERE T.MAT_NO = MYROW1.MAT_NO;
  END LOOP;
END;
]]>
</query>

<query id = "FrmOffLine.newStaOfflineBack" desc = "矫直下线回退">
<![CDATA[
DECLARE
  V_OFFINECOUNT MIL_OFFLINE_RESLUT.OFFLINE_NUM%TYPE := NULL;
BEGIN
  UPDATE MIL_OFFLINE_RESLUT T
     SET T.OFFLINE_NUM = TO_NUMBER(T.OFFLINE_NUM) - TO_NUMBER(?),
         T.ZP_HEIGHT   = TO_NUMBER(T.ZP_HEIGHT) - TO_NUMBER(?)
   WHERE T.JUDGE_STOVE_NO = ?
     AND T.OFFLINE_PRO = ?;
 
  UPDATE MIL_STRAIGHTENING_RESULT T
     SET T.OFFLINE_NUM_TOTAL = TO_NUMBER(T.OFFLINE_NUM_TOTAL) - TO_NUMBER(?),
     T.QUALIFIED_NUM = TO_NUMBER(T.QUALIFIED_NUM) + TO_NUMBER(?)
   WHERE T.JUDGE_STOVE_NO = ?;
  FOR MYROW IN (SELECT *
                  FROM (SELECT T.SEQ
                          FROM MIL_STRAIGH_RACK T
                         WHERE T.JUDGE_STOVE_NO = ?
                           AND T.OFFLINE_FLAG = '1'
                         ORDER BY T.SEQ DESC)
                 WHERE ROWNUM <= ?) LOOP
    UPDATE MIL_STRAIGH_RACK T
       SET T.OFFLINE_FLAG = '0',T.OFFLINE_TIME = '',T.STATUS = '0'
     WHERE T.JUDGE_STOVE_NO = ?
       AND T.SEQ = MYROW.SEQ;
       DELETE FROM MIL_SLAB_SCRAP_SEQ T WHERE T.JUDGE_STOVE_NO = ? AND T.SEQ = MYROW.SEQ;
  END LOOP;
  SELECT T.OFFLINE_NUM
    INTO V_OFFINECOUNT
    FROM MIL_OFFLINE_RESLUT T
   WHERE T.JUDGE_STOVE_NO = ?
     AND T.OFFLINE_PRO = ?;
  IF (V_OFFINECOUNT = 0) THEN
    DELETE FROM MIL_OFFLINE_RESLUT T
     WHERE T.JUDGE_STOVE_NO = ?
       AND T.OFFLINE_PRO = ?;
  END IF;
  UPDATE MIL_PLAN T SET T.ROLLING_STATUS = '0',T.NODE_STATUS = '70' WHERE T.JUDGE_STOVE_NO = ?;
  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.QCM_STAUS = '11'
                           AND T.PRODUCT_FLAG = '801401'
                           AND T.MAT_STATUS = '80150104' 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 T WHERE T.MAT_NO = MYROW1.MAT_NO;
                  DELETE FROM YDM_BC_INLIST T WHERE T.MAT_NO = MYROW1.MAT_NO;
  END LOOP;
END;
]]>
</query>

<query id = "FrmOffLine.newXXOfflineBack" desc = "下线点离线回退">
<![CDATA[
DECLARE
  V_OFFINECOUNT MIL_OFFLINE_RESLUT.OFFLINE_NUM%TYPE := NULL;
BEGIN
  UPDATE MIL_OFFLINE_RESLUT T
     SET T.OFFLINE_NUM = TO_NUMBER(T.OFFLINE_NUM) - TO_NUMBER(?),
         T.ZP_HEIGHT   = TO_NUMBER(T.ZP_HEIGHT) - TO_NUMBER(?)
   WHERE T.JUDGE_STOVE_NO = ?
     AND T.OFFLINE_PRO = ?;
  FOR MYROW IN (SELECT *
                  FROM (SELECT T.MAT_NO
                          FROM PORT_MIL_BATCH_SAMPLE_RESULT T
                         WHERE T.JUDGE_STOVE_NO = ?
                           AND T.STATUS = '3'
                           AND T.OP_PROCESS = '12'
                         ORDER BY T.IS_SAMPLE_PIPE, T.MAT_NO ASC)
                 WHERE ROWNUM <= ?) LOOP
    UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T
       SET T.STATUS = '0', T.OP_PROCESS = ''
     WHERE T.JUDGE_STOVE_NO = ?
       AND T.MAT_NO = MYROW.MAT_NO;
  END LOOP;
  SELECT T.OFFLINE_NUM
    INTO V_OFFINECOUNT
    FROM MIL_OFFLINE_RESLUT T
   WHERE T.JUDGE_STOVE_NO = ?
     AND T.OFFLINE_PRO = ?;
  IF (V_OFFINECOUNT = 0) THEN
    DELETE FROM MIL_OFFLINE_RESLUT T
     WHERE T.JUDGE_STOVE_NO = ?
       AND T.OFFLINE_PRO = ?;
  END IF;
  FOR MYROW1 IN (SELECT *
                   FROM (SELECT T.MAT_NO
                           FROM MAT_BC_M        T,
                                YDM_BC_BUTTRESS S,
                                COM_BASE_PLINE  C
                          WHERE T.MAT_NO = S.MAT_NO
                            AND T.ZG_STOVE_SQE = ?
                            AND T.QCM_STAUS = '11'
                            AND T.PLINE_CODE = C.PLINE_CODE
                            AND (S.STORAGE_NO = C.OUT_REPOSITORY OR
                                S.STORAGE_NO IN ('BZJ1', 'BZJ2'))
                            AND T.PRODUCT_FLAG = '801401'
                            AND T.MAT_STATUS = '80150104'
                          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 T WHERE T.MAT_NO = MYROW1.MAT_NO;
    DELETE FROM YDM_BC_INLIST T WHERE T.MAT_NO = MYROW1.MAT_NO;
  END LOOP;
END;
]]>
</query>


<query id = "FrmOffLine.selectMianPlanNode" desc = "查询该炉是否已结炉">
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 T.NODE_FUR_FLAG
  FROM MIL_ET_RESULT T
 WHERE T.JUDGE_STOVE_NO = ?
   AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
   AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
UNION ALL
SELECT T.NODE_FUR_FLAG
  FROM MIL_UL_RESUL T
 WHERE T.JUDGE_STOVE_NO = ?
   AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
   AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
</query>
<query id = "FrmOffLine.selectMianPlanNode1" desc = "查询是否结炉">
SELECT T.NODE_FUR_FLAG FROM MIL_STRAIGHTENING_RESULT T WHERE T.JUDGE_STOVE_NO = ?
</query>
<query id = "FrmOffLine.selectMianPlanXX" desc = "查询是否结炉">
SELECT T.NODE_STATUS FROM MIL_PLAN T WHERE T.JUDGE_STOVE_NO = ?
</query>
<query id = "FrmOffLine.selectOfflineResultDetia" desc = "查询此炉是否进行其他操作">
<![CDATA[
SELECT NVL(COUNT(1),0) ACOUNT
  FROM MIL_OFFLINE_RESLUT T
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.OFFLINE_PRO = ?
   AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
   AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
   AND (T.GROUP_NUM <> '0'
   OR T.BACKLINE_NUM <>'0'
   OR T.SUBCONTRACT_NUM <> '0')
   ]]>
</query>
<query id = "FrmOffLine.doQueryJugeCount" desc = "查询进程表支数情况">
SELECT NVL(SUM(T.ACT_COUNT),0)QUALIFIEDNUM
  FROM PORT_MIL_BATCH_SAMPLE_RESULT T
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.STATUS = '0'
   AND T.INSTORE_FLAG = '0'
</query>
<query id = "FrmOffLine.doQueryOfflineEdCount" desc = "查询进程表下线点离线支数">
SELECT NVL(SUM(T.ACT_COUNT),0)OFFLINE_COUNT
  FROM PORT_MIL_BATCH_SAMPLE_RESULT T
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.STATUS = '3'
   AND T.OP_PROCESS = '12'
</query>

<query id = "FrmOffLine.doQueryXxOfflinNum" desc = "查询交库点交库和离线的支数">
select T.JUDGE_STOVE_NO,
       (NVL(T.QUALIFIED_NUM, 0) + NVL(T.OFFLINE_NUM, 0)) OFFLINE_NUM
  from MIL_INSTORE_RESULT t
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.PLINE_CODE = ?
   AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
   AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
</query>

<query id = "FrmOffLine.doQueryHgNum" desc = "查询合格品支数">
select COUNT(1) ACOUNT
  from PORT_MIL_BATCH_SAMPLE_RESULT t
 WHERE T.STATUS = '0'
   AND T.JUDGE_STOVE_NO = ?
   AND T.PLINE_CODE = ?
   AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
   AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
</query>

<query id = "OffLine.getOfflineXXCount" desc = "查询交库可下线支数">
SELECT (T1.QUALIFIEDNUM - NVL(S.QUALIFIED_NUM, 0) - NVL(S.OFFLINE_NUM, 0) -
       NVL(S.SCRAP_NUM, 0)) QUALIFIEDNUM
  FROM (SELECT NVL(SUM(T.ACT_COUNT), 0) QUALIFIEDNUM,
               T.PLAN_ID,
               T.JUDGE_STOVE_NO,
               T.PRO_PLAN_ID,
               T.GX_PLAN_NO
          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.PLINE_CODE = ?
           AND T.STATUS = '0'
         GROUP BY T.PLAN_ID, T.JUDGE_STOVE_NO, T.PRO_PLAN_ID, T.GX_PLAN_NO) T1
  LEFT JOIN MIL_INSTORE_RESULT S
    ON T1.PLAN_ID = S.RESULT_NO
   AND T1.JUDGE_STOVE_NO = S.JUDGE_STOVE_NO
   AND NVL(T1.PRO_PLAN_ID, '/') = NVL(S.PRO_PLAN_ID, '/')
   AND NVL(T1.GX_PLAN_NO, '/') = NVL(S.GX_PLAN_NO, '/')
</query>
<query id = "Offline.getXXCountHAS" desc = "查询已下线支数">
SELECT NVL(T.OFFLINE_NUM, 0) OFFLINE_COUNT
  FROM MIL_INSTORE_RESULT T
 WHERE T.JUDGE_STOVE_NO = ?
   AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
   AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
</query>
<query id = "FrmOffLine.insertMilInstore" desc = "下线点离线写实绩表">
DECLARE
  V_COUNT MIL_INSTORE_RESULT.QUALIFIED_NUM%TYPE := NULL;
BEGIN
  SELECT COUNT(1)
    INTO V_COUNT
    FROM MIL_INSTORE_RESULT T
   WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
     AND NVL(T.PRO_PLAN_ID, '/') = NVL('#PRO_PLAN_ID#', '/')
     AND NVL(T.GX_PLAN_NO, '/') = NVL('#GX_PLAN_NO#', '/')
     AND T.RESULT_NO = '#ID#';
  IF (V_COUNT > 0) THEN
  
    UPDATE MIL_INSTORE_RESULT T
       SET T.OFFLINE_NUM = TO_NUMBER(NVL(OFFLINE_NUM, 0)) + TO_NUMBER(?)
     WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
       AND NVL(T.PRO_PLAN_ID, '/') = NVL('#PRO_PLAN_ID#', '/')
       AND NVL(T.GX_PLAN_NO, '/') = NVL('#GX_PLAN_NO#', '/')
       AND T.RESULT_NO = '#ID#';
  ELSE
    INSERT INTO MIL_INSTORE_RESULT
      (RESULT_NO,
       JUDGE_STOVE_NO,
       LOT_NO,
       PLINE_CODE,
       TYPE,
       TARGET_DIAMETER,
       TARGET_THICKNESS,
       TARGET_LENGTH,
       QUALIFIED_NUM,
       QUALIFIED_TONS,
       SCRAP_NUM,
       SCRAP_TONS,
       OFFLINE_NUM,
       OFFLINE_TONS,
       PRO_PLAN_ID,
       GX_PLAN_NO)
    VALUES
      ('#ID#',
       '#JUDGE_STOVE_NO#',
       '#LOT_NO#',
       '#PLINE_CODE#',
       '#GRADENAME#',
       '',
       '',
       '#TARGET_LENGTH#',
       '',
       '',
       '',
       '',
       ?,
       '',
       '#PRO_PLAN_ID#',
       '#GX_PLAN_NO#');
  END IF;
END;
</query>
<query id = "FrmOffLine.deleteMilInStore" desc= "交库点离线回退减支数">
UPDATE MIL_INSTORE_RESULT T
   SET T.OFFLINE_NUM = TO_NUMBER(T.OFFLINE_NUM) - TO_NUMBER(?)
 WHERE T.RESULT_NO = ?
   AND T.JUDGE_STOVE_NO = ?
   AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
   AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
</query>
<query id = "FrmOffLine.insertInListX" desc = "插入入库表(待处理)">
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,
       IN_BC,
       IN_BZ)
    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>

<query id="FrmOffLine.insertMatScrap" desc="废品入半成品库存">
    <![CDATA[ 
 DECLARE
  V_JUDGE_STOVE_NO MIL_PLAN.JUDGE_STOVE_NO%type := ?;
  V_PRO_PLAN_ID    MIL_PLAN.PRO_PLAN_ID%type := ?;
  V_GX_PLAN_NO     MIL_PLAN.GX_PLAN_NO%type := ?;
  V_PLINE_CODE     MIL_PLAN.PLINE_CODE%type := ?;
  V_OP_PROCESS     PORT_MIL_BATCH_SAMPLE_RESULT.OP_PROCESS%type := ?;

  V_INSTOCK_DOC       YDM_BC_INLIST.INSTOCK_DOC%type := NULL;
  V_STORAGE_NO        YDM_BC_BUTTRESS.STORAGE_NO%type := NULL;
  V_DEPARTMENT_CODE   YDM_BC_BUTTRESS.DEPARTMENT_CODE%type := NULL;
  V_DEPARTMENT_DESC   YDM_BC_BUTTRESS.DEPARTMENT_DESC%type := NULL;
  V_DEPARTMENT_CODE_P COM_BASE_PLINE.DEPARTMENT_CODE_P%TYPE := NULL;
  V_DEPARTMENT_DESC_P COM_BASE_PLINE.DEPARTMENT_DESC_P%TYPE := NULL;
  V_MAT_NO            MAT_BC_M.MAT_NO%type := NULL;
  V_JUDGE_STOVE_NO_6  MAT_BC_M.JUDGE_STOVE_NO%type := NULL;
  V_BATCH_NO          MAT_BC_M.BATCH_NO%type := 'F';
  V_TIME              MAT_BC_M.CREATE_TIME%type := SYSDATE;
  V_ICOUNT            NUMBER := 1;

BEGIN

  --入库单号
  SELECT 'IA' || V_PLINE_CODE || TO_CHAR(V_TIME, 'YYMMDD') ||
         LPAD(NVL(MAX(SUBSTR(T.INSTOCK_DOC, LENGTH(T.INSTOCK_DOC) - 4)), 0) + 1,
              5,
              0) INSTOCK_DOC
    INTO V_INSTOCK_DOC
    FROM YDM_BC_INLIST T
   WHERE TRUNC(T.CREATE_TIME) = TRUNC(V_TIME)
     AND T.INSTOCK_TYPE_CODE = '800701'
     AND PLINE_CODE = V_PLINE_CODE;

  --仓库代码
  SELECT T.OUT_REPOSITORY
    INTO V_STORAGE_NO
    FROM COM_BASE_PLINE T
   WHERE T.PLINE_CODE = V_PLINE_CODE;

  --部门科室表
  SELECT T.DEPARTID, T.DEPARTNAME, REGEXP_REPLACE(V_JUDGE_STOVE_NO, '-.*', '')
    INTO V_DEPARTMENT_CODE, V_DEPARTMENT_DESC, V_JUDGE_STOVE_NO_6
    FROM CORE_APP_DEPARTMENT T
   WHERE T.DEPARTNO = V_PLINE_CODE;

  --产线-管理部门
  SELECT T.DEPARTMENT_CODE_P, T.DEPARTMENT_DESC_P
    INTO V_DEPARTMENT_CODE_P, V_DEPARTMENT_DESC_P
    FROM COM_BASE_PLINE T
   WHERE T.PLINE_CODE = V_PLINE_CODE;

  FOR MYROW IN (SELECT T2.*,
                       T.ACT_COUNT,
                       T.ACT_THEORY_WEIGHT,
                       T.BAL_YEAR_MONTH BAL_YEAR_MONTH1,
                       T.MAT_NO,
                       T.PLAN_ID,
                       T.ORDER_LENGTH,
                       T1.PLINE_NAME,
                       T1.INWL_ID,
                       T1.INWL_DESC,
                       T1.OUTWL_ID,
                       NVL(T1.OUTWL_DESC,
                           T2.VARIETIES || ',' || T2.STEELNAME || ',' ||
                           T2.PIPE_SIZE || ',' || T2.BUCKLE_TYPE) OUTWL_DESC,
                       T1.OUTDIAMETER,
                       T1.WALLTHICK,
                       T1.LEN_ROLL_MIN,
                       T1.LEN_ROLL_MAX,
                       T1.ORDER_NO,
                       T1.ORDER_SEQ,
                       T1.DELIVERY_NO
                  FROM PORT_MIL_BATCH_SAMPLE_RESULT T,
                       MIL_PLAN T2,
                       (SELECT T1.PRO_PLAN_ID,
                               T1.GX_PLAN_NO,
                               T1.PLINE_CODE,
                               T1.PLINE_NAME,
                               T1.INWL_ID,
                               T1.INWL_DESC,
                               T1.OUTWL_ID,
                               T1.OUTWL_DESC,
                               T1.OUTDIAMETER,
                               T1.WALLTHICK,
                               T1.LEN_ROLL_MIN,
                               T1.LEN_ROLL_MAX,
                               T1.ORDER_NO,
                               T1.ORDER_SEQ,
                               T1.DELIVERY_NO
                        
                          FROM PLN_ZY_ZG_M T1
                         WHERE T1.PRO_PLAN_ID = V_PRO_PLAN_ID
                           AND T1.GX_PLAN_NO = V_GX_PLAN_NO
                         GROUP BY T1.PRO_PLAN_ID,
                                  T1.GX_PLAN_NO,
                                  T1.PLINE_CODE,
                                  T1.PLINE_NAME,
                                  T1.INWL_ID,
                                  T1.INWL_DESC,
                                  T1.OUTWL_ID,
                                  T1.OUTWL_DESC,
                                  T1.OUTDIAMETER,
                                  T1.WALLTHICK,
                                  T1.LEN_ROLL_MIN,
                                  T1.LEN_ROLL_MAX,
                                  T1.ORDER_NO,
                                  T1.ORDER_SEQ,
                                  T1.DELIVERY_NO) T1
                 WHERE T.PRO_PLAN_ID = T1.PRO_PLAN_ID(+)
                   AND T.GX_PLAN_NO = T1.GX_PLAN_NO(+)
                   AND T.PLINE_CODE = T1.PLINE_CODE(+)
                   AND T.JUDGE_STOVE_NO = T2.JUDGE_STOVE_NO
                   AND T.PRO_PLAN_ID = T2.PRO_PLAN_ID
                   AND T.GX_PLAN_NO = T2.GX_PLAN_NO
                   AND T.STATUS = '2'
                   AND T.OP_PROCESS = V_OP_PROCESS
                   AND T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
                   AND T.PRO_PLAN_ID = V_PRO_PLAN_ID
                   AND T.GX_PLAN_NO = V_GX_PLAN_NO
                   AND T.PLINE_CODE = V_PLINE_CODE) LOOP
  
    --生成材料号
    SELECT V_JUDGE_STOVE_NO_6 || V_BATCH_NO ||
           LPAD(NVL(MAX(SUBSTR(T.MAT_NO, LENGTH(T.MAT_NO) - 3)), 0) + 1,
                4,
                0) MAT_NO
      INTO V_MAT_NO
      FROM (SELECT MAX(T1.MAT_NO) MAT_NO
              FROM MAT_BC_M T1
             WHERE T1.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO_6
               AND T1.BATCH_NO = V_BATCH_NO
            UNION ALL
            SELECT MAX(T3.MAT_NO) MAT_NO
              FROM MAT_ZC_BACKUP T3
             WHERE T3.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO_6
               AND T3.BATCH_NO = V_BATCH_NO
            UNION ALL
            SELECT MAX(T4.MAT_NO) MAT_NO
              FROM YDM_BC_INLIST T4
             WHERE T4.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO_6
               AND T4.BATCH_NO = V_BATCH_NO) T;
  
    --位置表
    INSERT INTO YDM_BC_BUTTRESS
      (JUDGE_STOVE_NO,
       BATCH_NO,
       BATCH_GROUD_NO,
       STORAGE_NO,
       LOCATION_NO,
       STORAGE_TYPE_NO,
       STORAGE_TYPE_NAME,
       MAT_NO,
       CREATE_TIME,
       MANAGEMENT_NO,
       MANAGEMENT_NAME,
       DEPARTMENT_CODE,
       DEPARTMENT_DESC,
       PLINE_CODE)
    VALUES
      (V_JUDGE_STOVE_NO_6,
       V_BATCH_NO,
       '001',
       V_STORAGE_NO,
       V_STORAGE_NO || '10101',
       '800202',
       '钢管',
       V_MAT_NO,
       V_TIME,
       V_DEPARTMENT_CODE,
       V_DEPARTMENT_DESC,
       V_DEPARTMENT_CODE,
       V_DEPARTMENT_DESC,
       V_PLINE_CODE);
  
    --材料表
    INSERT INTO MAT_BC_M
      (JUDGE_STOVE_NO,
       BATCH_NO,
       BATCH_GROUD_NO,
       ACT_COUNT,
       ACT_WEIGHT,
       MATERIAL_NO,
       MATERIAL_NAME,
       INPUT_MATERIAL_NAME,
       INPUT_MATERIAL_NO,
       CREATE_TIME,
       MAT_NO,
       ZG_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,
       INSTOCK_TIME,
       STOVE_NO,
       PROCESS_CDOE,
       PROCESS_DESC,
       JUDGE_RESULT_CODE,
       JUDGE_RESULT,
       BELONG_CODE_RESPONSE,
       BELONG_NAME_RESPONSE,
       SCRAP_TYPE,
       CRAF_NO,
       CRAFT_SEQ)
    VALUES
      (V_JUDGE_STOVE_NO_6,
       V_BATCH_NO,
       '001',
       MYROW.ACT_COUNT,
       MYROW.ACT_THEORY_WEIGHT, --重量
       NVL(MYROW.OUTWL_ID, '/'),
       NVL(MYROW.OUTWL_DESC, '/'),
       MYROW.INWL_DESC,
       MYROW.INWL_ID,
       
       V_TIME,
       V_MAT_NO,
       MYROW.MAT_NO, --轧管材料号
       '801401',
       '80150101',
       MYROW.PLINE_CODE,
       MYROW.PLINE_NAME,
       '22',
       MYROW.PLAN_ID,
       MYROW.JUDGE_STOVE_NO,
       MYROW.VARIETIES_CODE,
       MYROW.VARIETIES,
       MYROW.STEELCODE,
       MYROW.STEELNAME,
       MYROW.PIPE_SIZE_CODE,
       REPLACE(MYROW.PIPE_SIZE, '*', 'x'),
       MYROW.GRADECODE,
       MYROW.GRADENAME,
       MYROW.BUCKLE_TYPE_CODE,
       MYROW.BUCKLE_TYPE,
       MYROW.ROLL_STANDRAD_CODE,
       MYROW.ROLL_STANDRAD,
       
       V_DEPARTMENT_CODE,
       V_DEPARTMENT_DESC,
       MYROW.STD_STYLE,
       MYROW.STD_STYLE_DESC,
       MYROW.OUTDIAMETER,
       MYROW.WALLTHICK,
       MYROW.LEN_ROLL_MIN,
       MYROW.LEN_ROLL_MAX,
       MYROW.LOT_NO,
       MYROW.ORDER_NO,
       MYROW.ORDER_LENGTH,
       MYROW.TARGET,
       MYROW.PROCESS_STATUS,
       '000000',
       V_TIME,
       MYROW.STOVE_NO,
       'D',
       '轧制',
       '40740705',
       '废品',
       V_DEPARTMENT_CODE_P,
       V_DEPARTMENT_DESC_P,
       '0',
       MYROW.IMP_PROCESS,
       MYROW.CRAFT_SEQ);
  
    --入库表
    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
      (V_DEPARTMENT_CODE,
       V_DEPARTMENT_DESC,
       V_INSTOCK_DOC || LPAD(V_ICOUNT, 4, 0),
       V_INSTOCK_DOC,
       '800701',
       '产出入库',
       V_MAT_NO,
       MYROW.LOT_NO,
       MYROW.STOVE_NO,
       V_JUDGE_STOVE_NO_6,
       V_BATCH_NO,
       '001',
       MYROW.VARIETIES_CODE,
       MYROW.VARIETIES,
       MYROW.ROLL_STANDRAD_CODE,
       MYROW.ROLL_STANDRAD,
       MYROW.STEELCODE,
       MYROW.STEELNAME,
       MYROW.STD_STYLE,
       MYROW.STD_STYLE_DESC,
       MYROW.PIPE_SIZE_CODE,
       MYROW.PIPE_SIZE,
       MYROW.BUCKLE_TYPE_CODE,
       MYROW.BUCKLE_TYPE,
       MYROW.OUTDIAMETER,
       MYROW.WALLTHICK,
       MYROW.LEN_ROLL_MIN,
       MYROW.LEN_ROLL_MAX,
       MYROW.ACT_COUNT,
       MYROW.ACT_THEORY_WEIGHT,
       MYROW.ACT_THEORY_WEIGHT,
       V_DEPARTMENT_CODE,
       V_DEPARTMENT_DESC,
       V_STORAGE_NO,
       '',
       '1',
       '',
       V_TIME,
       MYROW.ORDER_NO,
       MYROW.ORDER_SEQ,
       MYROW.DELIVERY_NO,
       '',
       '',
       MYROW.ORD_LN_DLY_PK,
       '801401',
       '80150101',
       V_TIME,
       '',
       MYROW.ORDER_LENGTH,
       V_DEPARTMENT_CODE,
       V_DEPARTMENT_DESC,
       MYROW.ROLL_STANDRAD,
       MYROW.PLINE_CODE,
       MYROW.PLINE_NAME,
       MYROW.GRADECODE,
       MYROW.GRADENAME,
       MYROW.BAL_YEAR_MONTH1,
       V_TIME,
       '',
       '801302',
       '机组',
       MYROW.PLINE_CODE,
       MYROW.PLINE_NAME,
       NVL(MYROW.OUTWL_ID, '/'),
       NVL(MYROW.OUTWL_DESC, '/'),
       MYROW.CONTRACT_NO,
       '22',
       V_JUDGE_STOVE_NO);
  
    V_ICOUNT := V_ICOUNT + 1;
  END LOOP;

  --探伤废品原因
  FOR MYROW2 IN (SELECT T.REASON, SUM(NVL(T.REASON_NUMBER, 0)) REASON_NUMBER
                   from MIL_TESTING_RESULT_DETAIL_DES t
                  WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
                    AND T.PLINE_CODE = V_PLINE_CODE
                    AND T.REASON_FLAG = '剔除'
                  GROUP BY T.REASON) LOOP
    IF (MYROW2.REASON_NUMBER > 0) THEN
      UPDATE MAT_BC_M T
         SET T.SCRAP_REASON = MYROW2.REASON,
             T.SOURE_CODE   = '501011',
             T.SOURE_NAME   = '探伤实绩'
       WHERE T.PROCESS_CDOE = 'D'
         AND T.BATCH_NO = 'F'
         AND T.SCRAP_REASON IS NULL
         AND T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO_6
         AND T.PLINE_CODE = V_PLINE_CODE
         AND ROWNUM <= MYROW2.REASON_NUMBER;
    END IF;
  END LOOP;

  --表检废品原因
  FOR MYROW3 IN (select T.DEFECT_ITEM, SUM(T.WASTE_BRANCH) WASTE_BRANCH
                   from MIL_CHECK_DEATIL_SIMPLE t
                  WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
                  GROUP BY T.DEFECT_ITEM) LOOP
    IF (MYROW3.WASTE_BRANCH > 0) THEN
      UPDATE MAT_BC_M T
         SET T.SCRAP_REASON = MYROW3.DEFECT_ITEM,
             T.SOURE_CODE   = '501012',
             T.SOURE_NAME   = '表检实绩'
       WHERE T.PROCESS_CDOE = 'D'
         AND T.BATCH_NO = 'F'
         AND T.SCRAP_REASON IS NULL
         AND T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO_6
         AND T.PLINE_CODE = V_PLINE_CODE
         AND ROWNUM <= MYROW3.WASTE_BRANCH;
    END IF;
  END LOOP;
END;
       ]]>
   </query>
   
   <query id="FrmOffLine.insertMatScrapBack" desc="废品入半成品库存回退">
	  <![CDATA[ 
DECLARE
V_JUDGE_STOVE_NO MIL_PLAN.JUDGE_STOVE_NO%type := ?;
BEGIN
  FOR MYROW IN (SELECT T.MAT_NO
                  FROM MAT_BC_M                     T,
                       YDM_BC_BUTTRESS              S,
                       PORT_MIL_BATCH_SAMPLE_RESULT M
                 WHERE T.MAT_NO = S.MAT_NO
                   AND T.ZG_MAT_NO = M.MAT_NO
                   AND T.ZG_STOVE_SQE = M.JUDGE_STOVE_NO
                   AND M.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
                   AND M.PRO_PLAN_ID = ?
                   AND M.GX_PLAN_NO = ?
                   AND M.PLINE_CODE = ?
                   AND T.BATCH_NO = 'F'
                   AND T.QCM_STAUS = '22'
                 ORDER BY T.MAT_NO DESC) LOOP
  
    DELETE FROM MAT_BC_M T
     WHERE T.MAT_NO = MYROW.MAT_NO
       AND T.ZG_STOVE_SQE = V_JUDGE_STOVE_NO
       AND ROWNUM = 1;
    DELETE FROM YDM_BC_BUTTRESS T
     WHERE T.MAT_NO = MYROW.MAT_NO
       AND ROWNUM = 1;
    DELETE FROM YDM_BC_INLIST T
     WHERE T.MAT_NO = MYROW.MAT_NO
       AND ROWNUM = 1;
  END LOOP;
END;

      ]]>
   </query>
   
   <query id = "FrmOffLine.doQueryMatScrap" desc = "查询废品库存是否发运">
SELECT COUNT(1) ACOUNT
  FROM MAT_BC_M T, YDM_BC_BUTTRESS S, PORT_MIL_BATCH_SAMPLE_RESULT M
 WHERE T.MAT_NO = S.MAT_NO
   AND T.ZG_MAT_NO = M.MAT_NO
   AND T.ZG_STOVE_SQE = M.JUDGE_STOVE_NO
   AND M.JUDGE_STOVE_NO = ?
   AND M.PRO_PLAN_ID = ?
   AND M.GX_PLAN_NO = ?
   AND M.PLINE_CODE = ?
   AND T.OUTSTOCK_DOC IS NOT NULL
   AND T.BATCH_NO = 'F'
   AND T.QCM_STAUS = '22'
</query>

<query id = "FrmOffLine.selectMaterialNo" desc = "查询物料码">
select DECODE(TRIM(T.IF_PRODUCT), '0', '', '1', T.CIC || '+') || T.PIC || '+' ||
       T.SIC || '+' || T.DIC judgeStdDes,
       T.CIC,
       T.INWL_ID,
       T.INWL_DESC,
       T.OUTWL_ID,
       T.OUTWL_DESC,
       T.CRAFT_SEQ,
       T.GOWHERE_CODE,
       T.GOWHERE_NAME
  from pln_zy_zg_m t
 where t.pro_plan_id = ?
   and t.gx_plan_no = ?
 group by T.IF_PRODUCT,
          T.CIC,
          T.PIC,
          T.SIC,
          T.DIC,
          T.INWL_ID,
          T.INWL_DESC,
          T.OUTWL_ID,
          T.OUTWL_DESC,
          T.CRAFT_SEQ,
          T.GOWHERE_CODE,
          T.GOWHERE_NAME
</query>

<query id = "FrmOffLine.selectMaterialNo2" desc = "查询物料码">
select DECODE(TRIM(T.IF_PRODUCT), '0', '', '1', T.CIC || '+') || T.PIC || '+' ||
       T.SIC || '+' || T.DIC judgeStdDes,
       T.CIC,
       T.INWL_ID,
       T.INWL_DESC,
       T.OUTWL_ID,
       T.OUTWL_DESC,
       T.CRAFT_SEQ,
       T.PRO_PLAN_ID,
       T.GX_PLAN_NO,
       T.GOWHERE_CODE,
       T.GOWHERE_NAME
  from pln_zy_zg_m t
 where t.HEAT_PLAN_NO = ?
 group by T.IF_PRODUCT,
          T.CIC,
          T.PIC,
          T.SIC,
          T.DIC,
          T.INWL_ID,
          T.INWL_DESC,
          T.OUTWL_ID,
          T.OUTWL_DESC,
          T.CRAFT_SEQ,
          T.PRO_PLAN_ID,
          T.GX_PLAN_NO,
          T.GOWHERE_CODE,
          T.GOWHERE_NAME
</query>

<query id = "FrmOffLine.offlineDoc" desc = "离线单号">
SELECT 'D' || TO_CHAR(SYSDATE, 'YYYYMM') ||
       LPAD(NVL(MAX(SUBSTR(T.OFFLINE_DOC, 8, 4)), 0) + 1, 4, 0) OFFLINE_DOC
  FROM MIL_OFFLINE_RESLUT T
 WHERE TO_CHAR(T.OFFLINE_TIME, 'YYYYMM') = TO_CHAR(SYSDATE, 'YYYYMM')
</query>

<query id = "FrmOffLine.offlineResult" desc = "查询离线实绩">
SELECT T.*
  FROM MIL_OFFLINE_RESLUT T
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.PLINE_CODE = ?
   AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
   AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
   AND T.OFFLINE_PRO = ?
</query>
   
</queryMap>
