<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc = "交库管理">
<query id = "FrmInOnlineStore.querySinglePlan" desc = "查询炉计划">

<![CDATA[
SELECT * FROM (
SELECT T.JUDGE_STOVE_NO, REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '')JUDGE_NO, T.LOT_NO, CASE T.NODE_STATUS WHEN 
       '00' THEN '' WHEN
        '10'  THEN '锯切完成' WHEN
       '15' THEN '入炉' WHEN
       '20'  THEN '出炉' WHEN
       '25' THEN '开始穿孔' WHEN
       '30'  THEN '穿孔完成' WHEN
       '35' THEN '开始连轧' WHEN
       '40'  THEN '连轧完成' WHEN
       '45' THEN '入再加热炉' WHEN
       '50'  THEN '出再加热炉' WHEN
       '55' THEN '开始定径' WHEN
       '60'  THEN '定径完成' WHEN
       '65' THEN '开始分切' WHEN
       '70'  THEN '分切完成' WHEN
       '75' THEN '开始矫直' WHEN
       '80'  THEN '矫直完成 ' WHEN
       '85' THEN '开始探伤' WHEN
       '90'  THEN '探伤完成' WHEN  
       '96' THEN '人工质检完成' WHEN
       '99' THEN '入库完成'
       END AS NODE_STATUS,
       S.END_TIME,
       T.ORD_LN_DLY_PK,
       T.ID,
       T.STATUS,
       T.BACK_PLAN_FLAG,
       T.PRO_PLAN_ID,
       T.GX_PLAN_NO,
       T.PLINE_CODE,
       ((select count(*)
                   from PORT_MIL_BATCH_SAMPLE_RESULT t1
                  where t1.judge_stove_no = t.JUDGE_STOVE_NO
                    and t1.status = '0') +
               (select count(*)
                   from PORT_MIL_BATCH_SAMPLE_RESULT t2
                  where t2.judge_stove_no = t.JUDGE_STOVE_NO
                    and trim(t2.op_process) >= 12)) PLAN_COUNT
  FROM MIL_PLAN T,MIL_SURFACE_RESULT S
 WHERE T.JUDGE_STOVE_NO = S.JUDGE_STOVE_NO(+)
   AND T.BACK_SLAB_FLAG <> '2'
   AND T.ROLLING_STATUS IN('0','1')
   ]]>
</query>

<query id="FrmInOnlineStore.doSaveOrdLnDlyPk" desc="获取备注">
<![CDATA[
	UPDATE MAT_BC_M T
	SET T.ORD_LN_DLY_PK = '#ORD_LN_DLY_PK#',
	    T.ORDER_SEQ_NO = '#ORDER_SEQ_NO#'
	WHERE
	T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
	AND
	T.BATCH_NO = '#BATCH_NO#'
	AND 
	T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
	AND
	T.LENGTH_TYPE  = '#LENGTH_TYPE#'
	AND
	T.TARGET = 'A'
]]>
</query>

<query id = "FrmInOnlineStore.doQuerySingleJugStove" desc = "查询投入产出">
<![CDATA[
SELECT JUDGE_STOVE_NO,
       JUDGE_NO,
       LOT_NO,
       OUTWL_ID,
       OUTWL_DESC,
       ORDER_NO,
       SUM(INCOUNT)INCOUNT,
       SUM(INWEIGHT)INWEIGHT,
       SUM(PENDINGCOUNT)PENDINGCOUNT,
       SUM(PENDINGWEIGHT)PENDINGWEIGHT,
       SUM(SCRAPCOUNT)SCRAPCOUNT,
       SUM(SCRAPWEIGHT)SCRAPWEIGHT,
       SUM((INCOUNT -PENDINGCOUNT - SCRAPCOUNT))OUTCOUNT,
       SUM((INWEIGHT -PENDINGWEIGHT - SCRAPWEIGHT))OUTWEIGHT,
       SUM(SOUTCOUNT)SOUTCOUNT,
       SUM(SOUTWEIGHT)SOUTWEIGHT,
       SUM((INCOUNT -PENDINGCOUNT - SCRAPCOUNT - SOUTCOUNT)) INOUTCOUNT,
       SUM((INWEIGHT -PENDINGWEIGHT - SCRAPWEIGHT - SOUTWEIGHT)) INOUTWEIGHT
  FROM (SELECT REGEXP_REPLACE(S.JUDGE_STOVE_NO, '-.*', '') JUDGE_STOVE_NO,
               S.JUDGE_STOVE_NO AS JUDGE_NO,
               S.LOT_NO,
               T1.OUTWL_ID,
               T1.OUTWL_DESC,
               T1.ORDER_NO || '/' || T1.ORDER_SEQ AS ORDER_NO,
               (CASE
                 WHEN S.OFFLINE_FLAG = '2' THEN
                  S.BRANCH
                 ELSE
                  S.DB_NUM * S.SAW_NUM
               END) INCOUNT,
               (CASE
                 WHEN S.OFFLINE_FLAG = '2' THEN
                  S.TON
                 ELSE
                  S.DB_NUM * S.DB_HEIGHT
               END) INWEIGHT,
               0 AS PENDINGCOUNT,
               0 AS PENDINGWEIGHT,
               0 AS SCRAPCOUNT,
               0 AS SCRAPWEIGHT,
               0 AS OUTCOUNT,
               0 AS OUTWEIGHT,
               0 AS SOUTCOUNT,
               0 AS SOUTWEIGHT
          FROM MIL_PLAN S,
               (SELECT OUTWL_ID, OUTWL_DESC,ORDER_NO, ORDER_SEQ
                  FROM PLN_ORDER_ZG
                 GROUP BY OUTWL_ID,OUTWL_DESC, ORDER_NO, ORDER_SEQ) T1
         WHERE S.CONTRACT_NO = T1.ORDER_NO || '/' || T1.ORDER_SEQ
           #condtions1#
           AND S.PLINE_CODE = ?
           AND S.JUDGE_STOVE_NO || '&' LIKE '%' || ? || '%'
           AND S.LOT_NO || '&' LIKE '%' || ? || '%'
        #condtions#
        UNION ALL (
       SELECT REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') JUDGE_STOVE_NO,
       T.JUDGE_NO,
       T.LOT_NO,
       S.OUTWL_ID,
       S.OUTWL_DESC,
       S.ORDER_NO || '/' || S.ORDER_SEQ AS ORDER_NO,
       0 AS INCOUNT,
       0 AS INWEIGHT,
       T.PENDINGCOUNT,
       0 AS PENDINGWEIGHT,
       0 AS SCRAPCOUNT,
       0 AS SCRAPWEIGHT,
       0 AS OUTCOUNT,
       0 AS OUTWEIGHT,
       0 AS SOUTCOUNT,
       0 AS SOUTWEIGHT
  FROM (SELECT JUDGE_STOVE_NO,
               JUDGE_NO,
               LOT_NO,
               SUM(PENDINGCOUNT) PENDINGCOUNT
          FROM (SELECT REGEXP_REPLACE(T2.JUDGE_STOVE_NO, '-.*', '') JUDGE_STOVE_NO,
                       T2.JUDGE_STOVE_NO AS JUDGE_NO,
                       S.LOT_NO,
                       (CASE
                         WHEN T2.PROCESS_NO >= 8 THEN
                          COUNT(1)
                         ELSE
                          COUNT(1) * S.SAW_NUM
                       END) PENDINGCOUNT
                  FROM MIL_SLAB_SCRAP_SEQ T2, MIL_PLAN S
                 WHERE T2.JUDGE_STOVE_NO = S.JUDGE_STOVE_NO
                   AND T2.PROCESS_NO < 8
                   AND T2.FLAG = '0'
                    OR (T2.FLAG = '1' AND T2.HANDLE_RESULT <> '500201')
                 GROUP BY T2.JUDGE_STOVE_NO,
                          S.LOT_NO,
                          S.SAW_NUM,
                          T2.PROCESS_NO)
         GROUP BY JUDGE_STOVE_NO, JUDGE_NO, LOT_NO) T,
       (SELECT t3.OUTWL_ID,
               t3.OUTWL_DESC,
               t3.ORDER_NO,
               t3.ORDER_SEQ,
               S.Judge_Stove_No,
               S.Lot_No,
               S.Pline_Code,
               S.Node_Status,
               S.START_TIME
          FROM MIL_PLAN S
          LEFT JOIN (SELECT OUTWL_ID, OUTWL_DESC, ORDER_NO, ORDER_SEQ
                      FROM PLN_ORDER_ZG
                     GROUP BY OUTWL_ID, OUTWL_DESC, ORDER_NO, ORDER_SEQ) T3 on S.CONTRACT_NO =
                                                                               T3.ORDER_NO || '/' ||
                                                                               T3.ORDER_SEQ) S
 WHERE T.JUDGE_STOVE_NO = S.JUDGE_STOVE_NO
   --REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = REGEXP_REPLACE(S.JUDGE_STOVE_NO, '-.*', '')
   AND T.LOT_NO = S.LOT_NO
   #condtions1#
   AND S.PLINE_CODE = ?
   AND S.JUDGE_STOVE_NO || '&' LIKE '%' || ? || '%'
   AND S.LOT_NO || '&' LIKE '%' || ? || '%'
   #condtions#
UNION ALL
SELECT REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') JUDGE_STOVE_NO,
       T.JUDGE_NO,
       T.LOT_NO,
       T1.OUTWL_ID,
       T1.OUTWL_DESC,
       T1.ORDER_NO || '/' || T1.ORDER_SEQ AS ORDER_NO,
       0 AS INCOUNT,
       0 AS INWEIGHT,
       PENGDINGCOUNT AS PENDINGCOUNT,
       (S.DB_NUM / S.SAW_NUM * T.PENGDINGCOUNT) AS PENDINGWEIGHT,
       0 AS SCRAPCOUNT,
       0 AS SCRAPWEIGHT,
       0 AS OUTCOUNT,
       0 AS OUTWEIGHT,
       0 AS SOUTCOUNT,
       0 AS SOUTWEIGHT
  FROM (SELECT REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') JUDGE_STOVE_NO,
               T.JUDGE_STOVE_NO AS JUDGE_NO,
               T.LOT_NO,
               SUM(T.OFFLINE_NUM) PENGDINGCOUNT
          FROM MIL_OFFLINE_RESLUT T
         GROUP BY T.JUDGE_STOVE_NO, T.LOT_NO) T,
       MIL_PLAN S,
       (SELECT OUTWL_ID, OUTWL_DESC, ORDER_NO, ORDER_SEQ
          FROM PLN_ORDER_ZG
         GROUP BY OUTWL_ID, OUTWL_DESC, ORDER_NO, ORDER_SEQ) T1
 WHERE T.JUDGE_STOVE_NO = S.JUDGE_STOVE_NO
   --REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = REGEXP_REPLACE(S.JUDGE_STOVE_NO, '-.*', '')
   AND S.CONTRACT_NO = T1.ORDER_NO || '/' || T1.ORDER_SEQ
   AND T.LOT_NO = S.LOT_NO
   #condtions1#
   AND S.PLINE_CODE = ?
   AND S.JUDGE_STOVE_NO || '&' LIKE '%' || ? || '%'
   AND S.LOT_NO || '&' LIKE '%' || ? || '%'
   #condtions#
        )
        UNION ALL
        SELECT REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') JUDGE_STOVE_NO,
               T.JUDGE_NO,
               T.LOT_NO,
               T1.OUTWL_ID,
               T1.OUTWL_DESC,
               T1.ORDER_NO || '/' || T1.ORDER_SEQ AS ORDER_NO,
               0 AS INCOUNT,
               0 AS INWEIGHT,
               0 AS PENDINGCOUNT,
               0 AS PENDINGWEIGHT,
               SCRAPCOUNT,
               (S.DB_NUM / S.SAW_NUM * T.SCRAPCOUNT) AS SCRAPWEIGHT,
               0 AS OUTCOUNT,
               0 AS OUTWEIGHT,
               0 AS SOUTCOUNT,
               0 AS SOUTWEIGHT
          FROM (SELECT REGEXP_REPLACE(JUDGE_STOVE_NO, '-.*', '') JUDGE_STOVE_NO,
                       JUDGE_STOVE_NO AS JUDGE_NO,
                       LOT_NO,
                       COUNT(1) SCRAPCOUNT
                  FROM MIL_SLAB_SCRAP D
                 WHERE D.FLAG = '1'
                   AND D.HANDLE_RESULT = '500201'
                   AND D.PROCESS_NO <8
                 GROUP BY JUDGE_STOVE_NO,LOT_NO
                 UNION ALL 
                 SELECT REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') JUDGE_STOVE_NO,
                       T.JUDGE_STOVE_NO AS JUDGE_NO,
                       S.LOT_NO,
                       COUNT(1) SCRAPCOUNT FROM MIL_SLAB_SCRAP_SEQ T,MIL_PLAN S
                       WHERE T.JUDGE_STOVE_NO = S.JUDGE_STOVE_NO AND T.PROCESS_NO >=8
                       AND T.COL_TYPE = '0'
                       GROUP BY T.JUDGE_STOVE_NO,S.LOT_NO) T,
               MIL_PLAN S,
               (SELECT OUTWL_ID,OUTWL_DESC, ORDER_NO, ORDER_SEQ
                  FROM PLN_ORDER_ZG
                 GROUP BY OUTWL_ID,OUTWL_DESC, ORDER_NO, ORDER_SEQ) T1
         WHERE T.JUDGE_STOVE_NO = S.JUDGE_STOVE_NO
           --REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = REGEXP_REPLACE(S.JUDGE_STOVE_NO, '-.*', '')
           AND S.CONTRACT_NO = T1.ORDER_NO || '/' || T1.ORDER_SEQ
           #condtions1#
           AND S.PLINE_CODE = ?
           AND S.JUDGE_STOVE_NO || '&' LIKE '%' || ? || '%'
           AND S.LOT_NO || '&' LIKE '%' || ? || '%'
         #condtions#
         GROUP BY T.JUDGE_STOVE_NO,
                  T.JUDGE_NO,
                  S.DB_NUM,
                  S.SAW_NUM,
                  T.SCRAPCOUNT,
                  T.LOT_NO,
                  T1.OUTWL_ID,
                  T1.OUTWL_DESC,
                  T1.ORDER_NO,
                  T1.ORDER_SEQ
        UNION ALL
        SELECT REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') JUDGE_STOVE_NO,
               T.Judge_No,
               T.LOT_NO,
               T1.OUTWL_ID,
               T1.OUTWL_DESC,
               T1.ORDER_NO || '/' || T1.ORDER_SEQ AS ORDER_NO,
               0 AS INCOUNT,
               0 AS INWEIGHT,
               0 AS PENDINGCOUNT,
               0 AS PENDINGWEIGHT,
               0 AS SCRAPCOUNT,
               0 AS SCRAPWEIGHT,
               COUNT(1) AS OUTCOUNT,
               S.DB_NUM / S.SAW_NUM * T.OUTCOUNT AS OUTWEIGHT,
               0 AS SOUTCOUNT,
               0 AS SOUTWEIGHT
          FROM (SELECT REGEXP_REPLACE(JUDGE_STOVE_NO, '-.*', '') JUDGE_STOVE_NO,
                       JUDGE_STOVE_NO AS JUDGE_NO,
                       LOT_NO,
                       COUNT(1) OUTCOUNT
                  FROM MIL_SURFACE_RESULT D
                 GROUP BY JUDGE_STOVE_NO, LOT_NO) T,
               MIL_PLAN S,
               (SELECT OUTWL_ID,OUTWL_DESC, ORDER_NO, ORDER_SEQ
                  FROM PLN_ORDER_ZG
                 GROUP BY OUTWL_ID,OUTWL_DESC, ORDER_NO, ORDER_SEQ) T1
         WHERE T.JUDGE_STOVE_NO = S.JUDGE_STOVE_NO
           AND S.CONTRACT_NO = T1.ORDER_NO || '/' || T1.ORDER_SEQ
           AND T.LOT_NO = S.LOT_NO
           #condtions1#
           AND S.PLINE_CODE = ?
           AND S.JUDGE_STOVE_NO || '&' LIKE '%' || ? || '%'
           AND S.LOT_NO || '&' LIKE '%' || ? || '%'
        #condtions#
         GROUP BY T.JUDGE_STOVE_NO,
                  T.JUDGE_NO,
                  S.DB_NUM,
                  S.SAW_NUM,
                  T.OUTCOUNT,
                  T.LOT_NO,
                  T1.OUTWL_ID,
                  T1.OUTWL_DESC,
                  T1.ORDER_NO,
                  T1.ORDER_SEQ
        UNION ALL
        SELECT 
        REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') JUDGE_STOVE_NO,
               T.JUDGE_STOVE_NO AS JUDGE_NO,
               T.LOT_NO,
               T1.OUTWL_ID,
               T1.OUTWL_DESC,
               T1.ORDER_NO || '/' || T1.ORDER_SEQ AS ORDER_NO,
               0 AS INCOUNT,
               0 AS INWEIGHT,
               0 AS PENDINGCOUNT,
               0 AS PENDINGWEIGHT,
               0 AS SCRAPCOUNT,
               0 AS SCRAPWEIGHT,
               0 AS OUTCOUNT,
               0 AS OUTWEIGHT,
               T.QUALIFIED_BRANCH AS SOUTCOUNT,
               T.QUALIFIED_TONS AS SOUTWEIGHT
         FROM MIL_SURFACE_RESULT T,MIL_PLAN S,
               (SELECT OUTWL_ID,OUTWL_DESC, ORDER_NO, ORDER_SEQ
                  FROM PLN_ORDER_ZG
                 GROUP BY OUTWL_ID,OUTWL_DESC, ORDER_NO, ORDER_SEQ) T1
                 WHERE T.JUDGE_STOVE_NO = S.JUDGE_STOVE_NO
           AND S.CONTRACT_NO = T1.ORDER_NO || '/' || T1.ORDER_SEQ
           AND T.LOT_NO = S.LOT_NO
           #condtions1#
           AND S.PLINE_CODE = ?
           AND S.JUDGE_STOVE_NO || '&' LIKE '%' || ? || '%'
           AND S.LOT_NO || '&' LIKE '%' || ? || '%'
           #condtions#
                  )
                  GROUP BY JUDGE_STOVE_NO,
       JUDGE_NO,
       LOT_NO,
       OUTWL_ID,
       OUTWL_DESC,
       ORDER_NO
]]>
</query>
<query id = "FrmInOnlineStore.doQuerySingleJugStove1" desc = "投入产出">
<![CDATA[
SELECT JUDGE_STOVE_NO,
       JUDGE_NO,
       ORDER_NO,
       OUTWL_ID,
       OUTWL_DESC,
       LOT_NO,
       SUM(INCOUNT) INCOUNT,
       SUM(INWEIGHT) INWEIGHT,
       SUM(PENDINGCOUNT) PENDINGCOUNT,
       SUM(PENDINGWEIGHT) PENDINGWEIGHT,
       SUM(SCRAPCOUNT) SCRAPCOUNT,
       SUM(SCRAPWEIGHT) SCRAPWEIGHT,
       SUM(SOUTCOUNT) SOUTCOUNT,
       SUM(SOUTWEIGHT) SOUTWEIGHT,
       SUM((INCOUNT - PENDINGCOUNT - SCRAPCOUNT)) OUTCOUNT,
       0 AS OUTWEIGHT,
       SUM((INCOUNT - PENDINGCOUNT - SCRAPCOUNT - SOUTCOUNT)) INOUTCOUNT,
       0 AS INOUTWEIGHT
  FROM (SELECT REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') JUDGE_STOVE_NO,
               T.JUDGE_STOVE_NO AS JUDGE_NO,
               T.CONTRACT_NO AS ORDER_NO,
               T.LOT_NO,
               T1.OUTWL_ID,
               T1.OUTWL_DESC,
               T2.ACT_COUNT AS INCOUNT,
               0 AS INWEIGHT,
               0 AS PENDINGCOUNT,
               0 AS PENDINGWEIGHT,
               0 AS SCRAPCOUNT,
               0 AS SCRAPWEIGHT,
               0 AS SOUTCOUNT,
               0 AS SOUTWEIGHT
          FROM MIL_PLAN T
          LEFT JOIN (SELECT OUTWL_ID, OUTWL_DESC, ORDER_NO, ORDER_SEQ
                      FROM PLN_ORDER_ZG
                     GROUP BY OUTWL_ID, OUTWL_DESC, ORDER_NO, ORDER_SEQ) T1 ON T.CONTRACT_NO =
                                                                               T1.ORDER_NO || '/' ||
                                                                               T1.ORDER_SEQ
          LEFT JOIN (SELECT T3.JUDGE_STOVE_NO,
                           T3.PLAN_ID,
                           --T3.STATUS,
                           SUM(T3.ACT_COUNT) ACT_COUNT
                      FROM PORT_MIL_BATCH_SAMPLE_RESULT T3
                      WHERE T3.STATUS  != '4'
                     GROUP BY T3.JUDGE_STOVE_NO, T3.PLAN_ID) T2 ON T.ID =
                                                                              T2.PLAN_ID
                                                                          AND T.JUDGE_STOVE_NO =
                                                                              T2.JUDGE_STOVE_NO
         WHERE T.JUDGE_STOVE_NO || '&' LIKE '%' || '#JUDGE_STOVE_NO#' || '%'
           AND T.LOT_NO || '&' LIKE '%' || '#LOT_NO#' || '%'
           AND T.PLINE_CODE = '#PLINE_CODE#'
           #condtions1#
           #condtions#
           
        UNION ALL
        SELECT REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') JUDGE_STOVE_NO,
               T.JUDGE_STOVE_NO AS JUDGE_NO,
               T.CONTRACT_NO AS ORDER_NO,
               T.LOT_NO,
               T1.OUTWL_ID,
               T1.OUTWL_DESC,
               0 AS INCOUNT,
               0 AS INWEIGHT,
               t2.ACT_COUNT AS PENDINGCOUNT,
               0 AS PENDINGWEIGHT,
               0 AS SCRAPCOUNT,
               0 AS SCRAPWEIGHT,
               0 AS SOUTCOUNT,
               0 AS SOUTWEIGHT
          FROM MIL_PLAN T
          LEFT JOIN (SELECT OUTWL_ID, OUTWL_DESC, ORDER_NO, ORDER_SEQ
                       FROM PLN_ORDER_ZG
                      GROUP BY OUTWL_ID, OUTWL_DESC, ORDER_NO, ORDER_SEQ) T1 ON T.CONTRACT_NO =
                                                                                T1.ORDER_NO || '/' ||
                                                                                T1.ORDER_SEQ
          LEFT JOIN (SELECT T3.JUDGE_STOVE_NO,
                            T3.PLAN_ID,
                            T3.STATUS,
                            NVL(SUM(T3.ACT_COUNT),0) ACT_COUNT
                       FROM PORT_MIL_BATCH_SAMPLE_RESULT T3
                      WHERE T3.STATUS in ('1', '3')
                      GROUP BY T3.JUDGE_STOVE_NO, T3.PLAN_ID, T3.STATUS) T2 ON T.ID =
                                                                               T2.PLAN_ID
                                                                           AND T.JUDGE_STOVE_NO =
                                                                               T2.JUDGE_STOVE_NO
         WHERE T.JUDGE_STOVE_NO || '&' LIKE '%' || '#JUDGE_STOVE_NO#' || '%'
           AND T.LOT_NO || '&' LIKE '%' || '#LOT_NO#' || '%'
           AND T.PLINE_CODE = '#PLINE_CODE#'
           #condtions1#
           #condtions#
           --AND ROWNUM = 1
        union all
        SELECT REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') JUDGE_STOVE_NO,
               T.JUDGE_STOVE_NO AS JUDGE_NO,
               T.CONTRACT_NO AS ORDER_NO,
               T.LOT_NO,
               T1.OUTWL_ID,
               T1.OUTWL_DESC,
               0 AS INCOUNT,
               0 AS INWEIGHT,
               0 AS PENDINGCOUNT,
               0 AS PENDINGWEIGHT,
               t2.ACT_COUNT AS SCRAPCOUNT,
               0            AS SCRAPWEIGHT,
               0 AS SOUTCOUNT,
               0 AS SOUTWEIGHT
          FROM MIL_PLAN T
          LEFT JOIN (SELECT OUTWL_ID, OUTWL_DESC, ORDER_NO, ORDER_SEQ
                       FROM PLN_ORDER_ZG
                      GROUP BY OUTWL_ID, OUTWL_DESC, ORDER_NO, ORDER_SEQ) T1 ON T.CONTRACT_NO =
                                                                                T1.ORDER_NO || '/' ||
                                                                                T1.ORDER_SEQ
          LEFT JOIN (SELECT T3.JUDGE_STOVE_NO,
                            T3.PLAN_ID,
                            T3.STATUS,
                            SUM(T3.ACT_COUNT) ACT_COUNT
                       FROM PORT_MIL_BATCH_SAMPLE_RESULT T3
                      WHERE T3.STATUS = '2'
                      GROUP BY T3.JUDGE_STOVE_NO, T3.PLAN_ID, T3.STATUS) T2 ON T.ID =
                                                                               T2.PLAN_ID
                                                                           AND T.JUDGE_STOVE_NO =
                                                                               T2.JUDGE_STOVE_NO
         WHERE T.JUDGE_STOVE_NO || '&' LIKE '%' || '#JUDGE_STOVE_NO#' || '%'
           AND T.LOT_NO || '&' LIKE '%' || '#LOT_NO#' || '%'
           AND T.PLINE_CODE = '#PLINE_CODE#'
           #condtions1#
           #condtions#
           --AND ROWNUM = 1
        UNION ALL
        SELECT REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') JUDGE_STOVE_NO,
               T.JUDGE_STOVE_NO AS JUDGE_NO,
               T.CONTRACT_NO AS ORDER_NO,
               T.LOT_NO,
               T1.OUTWL_ID,
               T1.OUTWL_DESC,
               0 AS INCOUNT,
               0 AS INWEIGHT,
               0 AS PENDINGCOUNT,
               0 AS PENDINGWEIGHT,
               0 AS SCRAPCOUNT,
               0 AS SCRAPWEIGHT,
               T2.ACT_COUNT AS SOUTCOUNT,
               0                   AS SOUTWEIGHT
        
          FROM MIL_PLAN T
          LEFT JOIN (SELECT OUTWL_ID, OUTWL_DESC, ORDER_NO, ORDER_SEQ
                       FROM PLN_ORDER_ZG
                      GROUP BY OUTWL_ID, OUTWL_DESC, ORDER_NO, ORDER_SEQ) T1 ON T.CONTRACT_NO =
                                                                                T1.ORDER_NO || '/' ||
                                                                                T1.ORDER_SEQ
          LEFT JOIN (SELECT T3.JUDGE_STOVE_NO,
                            T3.PLAN_ID,
                            T3.STATUS,
                            SUM(T3.ACT_COUNT) ACT_COUNT
                       FROM PORT_MIL_BATCH_SAMPLE_RESULT T3
                      WHERE T3.STATUS = '0'
                      GROUP BY T3.JUDGE_STOVE_NO, T3.PLAN_ID, T3.STATUS) T2 ON T.id = T2.PLAN_ID
                                         AND T.JUDGE_STOVE_NO =
                                             T2.JUDGE_STOVE_NO
         WHERE T.JUDGE_STOVE_NO || '&' LIKE '%' || '#JUDGE_STOVE_NO#' || '%'
           AND T.LOT_NO || '&' LIKE '%' || '#LOT_NO#' || '%'
           AND T.PLINE_CODE = '#PLINE_CODE#'
           #condtions1#
           #condtions#
           --AND ROWNUM = 1
           )
 GROUP BY JUDGE_STOVE_NO, JUDGE_NO, ORDER_NO, OUTWL_ID, OUTWL_DESC,LOT_NO
 ]]>
</query>
<query id = "FrmInOnlineStore.doQuerySingleJugStove2" desc = "投入产出">
<![CDATA[
SELECT JUDGE_STOVE_NO,
       JUDGE_NO,
       ORDER_NO,
       
       OUTWL_DESC,
       LOT_NO,
       TARGET_LIABRARY,
       SUM(INCOUNT) INCOUNT,
       SUM(INWEIGHT) INWEIGHT,
       SUM(PENDINGCOUNT) PENDINGCOUNT,
       SUM(PENDINGWEIGHT) PENDINGWEIGHT,
       SUM(SCRAPCOUNT) SCRAPCOUNT,
       SUM(SCRAPWEIGHT) SCRAPWEIGHT,
       SUM(SOUTCOUNT) SOUTCOUNT,
       SUM(SOUTWEIGHT) SOUTWEIGHT,
       SUM((INCOUNT - PENDINGCOUNT - SCRAPCOUNT)) OUTCOUNT,
       0 AS OUTWEIGHT,
       SUM((INCOUNT - PENDINGCOUNT - SCRAPCOUNT - SOUTCOUNT)) INOUTCOUNT,
       0 AS INOUTWEIGHT
  FROM (SELECT REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') JUDGE_STOVE_NO,
               T.JUDGE_STOVE_NO AS JUDGE_NO,
               T.CONTRACT_NO AS ORDER_NO,
               T.LOT_NO,
               T.TARGET_LIABRARY,
               --T1.OUTWL_ID,
               --REGEXP_SUBSTR(GET_WL_CODE(SUBSTR(T.Ord_Ln_Dly_Pk,0,LENGTH(T.Ord_Ln_Dly_Pk)-3)),'[^#]+',1,1)OUTWL_ID,
               --T.VARIETIES||','||T.STEELNAME||','||T.PIPE_SIZE||','||T.BUCKLE_TYPE OUTWL_DESC,
               --REGEXP_SUBSTR(GET_WL_CODE(SUBSTR(T.Ord_Ln_Dly_Pk,0,LENGTH(T.Ord_Ln_Dly_Pk)-3)),'[^#]+',1,2) OUTWL_DESC,
               CASE SUBSTR(T.JUDGE_STOVE_NO, -1)
                 WHEN '1' THEN
                  REGEXP_SUBSTR(GET_WL_CODE(SUBSTR(T.Ord_Ln_Dly_Pk,
                                                   0,
                                                   LENGTH(T.Ord_Ln_Dly_Pk) - 3)),
                                '[^#]+',
                                1,
                                1)
                 ELSE
                  REGEXP_SUBSTR(GET_WL_CODE2(T.CONTRACT_NO), '[^#]+', 1, 1)
               END OUTWL_ID,
               
               CASE SUBSTR(T.JUDGE_STOVE_NO, -1)
                 WHEN '1' THEN
                  REGEXP_SUBSTR(GET_WL_CODE(SUBSTR(T.Ord_Ln_Dly_Pk,
                                                   0,
                                                   LENGTH(T.Ord_Ln_Dly_Pk) - 3)),
                                '[^#]+',
                                1,
                                2)
                 ELSE
                  REGEXP_SUBSTR(GET_WL_CODE2(T.CONTRACT_NO), '[^#]+', 1, 2)
               END OUTWL_DESC,
               T2.ACT_COUNT AS INCOUNT,
               0 AS INWEIGHT,
               0 AS PENDINGCOUNT,
               0 AS PENDINGWEIGHT,
               0 AS SCRAPCOUNT,
               0 AS SCRAPWEIGHT,
               0 AS SOUTCOUNT,
               0 AS SOUTWEIGHT
          FROM MIL_PLAN T
          LEFT JOIN (SELECT T3.JUDGE_STOVE_NO,
                           T3.PLAN_ID,
                           --T3.STATUS,
                           SUM(T3.ACT_COUNT) ACT_COUNT
                      FROM PORT_MIL_BATCH_SAMPLE_RESULT T3
                     WHERE T3.STATUS != '4'
                     GROUP BY T3.JUDGE_STOVE_NO, T3.PLAN_ID) T2
            ON T.ID = T2.PLAN_ID
           AND T.JUDGE_STOVE_NO = T2.JUDGE_STOVE_NO
         WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
           AND T.LOT_NO = '#LOT_NO#'
           AND T.BACK_SLAB_FLAG <> '2'
           AND T.PLINE_CODE = '#PLINE_CODE#' #condtions1# #condtions#
        
        UNION ALL
        SELECT REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') JUDGE_STOVE_NO,
               T.JUDGE_STOVE_NO AS JUDGE_NO,
               T.CONTRACT_NO AS ORDER_NO,
               T.LOT_NO,
               T.TARGET_LIABRARY,
               --T1.OUTWL_ID,
               --REGEXP_SUBSTR(GET_WL_CODE(SUBSTR(T.Ord_Ln_Dly_Pk,0,LENGTH(T.Ord_Ln_Dly_Pk)-3)),'[^#]+',1,1)OUTWL_ID,
               --T.VARIETIES||','||T.STEELNAME||','||T.PIPE_SIZE||','||T.BUCKLE_TYPE OUTWL_DESC,
               --REGEXP_SUBSTR(GET_WL_CODE(SUBSTR(T.Ord_Ln_Dly_Pk,0,LENGTH(T.Ord_Ln_Dly_Pk)-3)),'[^#]+',1,2) OUTWL_DESC,
               CASE SUBSTR(T.JUDGE_STOVE_NO, -1)
                 WHEN '1' THEN
                  REGEXP_SUBSTR(GET_WL_CODE(SUBSTR(T.Ord_Ln_Dly_Pk,
                                                   0,
                                                   LENGTH(T.Ord_Ln_Dly_Pk) - 3)),
                                '[^#]+',
                                1,
                                1)
                 ELSE
                  REGEXP_SUBSTR(GET_WL_CODE2(T.CONTRACT_NO), '[^#]+', 1, 1)
               END OUTWL_ID,
               
               CASE SUBSTR(T.JUDGE_STOVE_NO, -1)
                 WHEN '1' THEN
                  REGEXP_SUBSTR(GET_WL_CODE(SUBSTR(T.Ord_Ln_Dly_Pk,
                                                   0,
                                                   LENGTH(T.Ord_Ln_Dly_Pk) - 3)),
                                '[^#]+',
                                1,
                                2)
                 ELSE
                  REGEXP_SUBSTR(GET_WL_CODE2(T.CONTRACT_NO), '[^#]+', 1, 2)
               END OUTWL_DESC,
               0 AS INCOUNT,
               0 AS INWEIGHT,
               --(NVL(t2.ACT_COUNT,0) + NVL(t4.offline_num,0)) AS PENDINGCOUNT,
               NVL(t2.ACT_COUNT, 0) AS PENDINGCOUNT,
               0 AS PENDINGWEIGHT,
               0 AS SCRAPCOUNT,
               0 AS SCRAPWEIGHT,
               0 AS SOUTCOUNT,
               0 AS SOUTWEIGHT
          FROM MIL_PLAN T
          LEFT JOIN (SELECT T3.JUDGE_STOVE_NO,
                           T3.PLAN_ID,
                           T3.STATUS,
                           NVL(SUM(T3.ACT_COUNT), 0) ACT_COUNT
                      FROM PORT_MIL_BATCH_SAMPLE_RESULT T3
                     WHERE T3.STATUS IN ('1', '3')
                     GROUP BY T3.JUDGE_STOVE_NO, T3.PLAN_ID, T3.STATUS) T2
            ON T.ID = T2.PLAN_ID
           AND T.JUDGE_STOVE_NO = T2.JUDGE_STOVE_NO
          LEFT JOIN MIL_INSTORE_RESULT T4
            ON T.ID = T4.RESULT_NO
           AND T.JUDGE_STOVE_NO = T4.JUDGE_STOVE_NO
         WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
           AND T.LOT_NO = '#LOT_NO#'
           AND T.BACK_SLAB_FLAG <> '2'
           AND T.PLINE_CODE = '#PLINE_CODE#' #condtions1# #condtions#
        union all
        SELECT REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') JUDGE_STOVE_NO,
               T.JUDGE_STOVE_NO AS JUDGE_NO,
               T.CONTRACT_NO AS ORDER_NO,
               T.LOT_NO,
               T.TARGET_LIABRARY,
               --T1.OUTWL_ID,
               --REGEXP_SUBSTR(GET_WL_CODE(SUBSTR(T.Ord_Ln_Dly_Pk,0,LENGTH(T.Ord_Ln_Dly_Pk)-3)),'[^#]+',1,1)OUTWL_ID,
               --T.VARIETIES||','||T.STEELNAME||','||T.PIPE_SIZE||','||T.BUCKLE_TYPE OUTWL_DESC,
               --REGEXP_SUBSTR(GET_WL_CODE(SUBSTR(T.Ord_Ln_Dly_Pk,0,LENGTH(T.Ord_Ln_Dly_Pk)-3)),'[^#]+',1,2) OUTWL_DESC,
               CASE SUBSTR(T.JUDGE_STOVE_NO, -1)
                 WHEN '1' THEN
                  REGEXP_SUBSTR(GET_WL_CODE(SUBSTR(T.Ord_Ln_Dly_Pk,
                                                   0,
                                                   LENGTH(T.Ord_Ln_Dly_Pk) - 3)),
                                '[^#]+',
                                1,
                                1)
                 ELSE
                  REGEXP_SUBSTR(GET_WL_CODE2(T.CONTRACT_NO), '[^#]+', 1, 1)
               END OUTWL_ID,
               
               CASE SUBSTR(T.JUDGE_STOVE_NO, -1)
                 WHEN '1' THEN
                  REGEXP_SUBSTR(GET_WL_CODE(SUBSTR(T.Ord_Ln_Dly_Pk,
                                                   0,
                                                   LENGTH(T.Ord_Ln_Dly_Pk) - 3)),
                                '[^#]+',
                                1,
                                2)
                 ELSE
                  REGEXP_SUBSTR(GET_WL_CODE2(T.CONTRACT_NO), '[^#]+', 1, 2)
               END OUTWL_DESC,
               0 AS INCOUNT,
               0 AS INWEIGHT,
               0 AS PENDINGCOUNT,
               0 AS PENDINGWEIGHT,
               t2.ACT_COUNT AS SCRAPCOUNT,
               0 AS SCRAPWEIGHT,
               0 AS SOUTCOUNT,
               0 AS SOUTWEIGHT
          FROM MIL_PLAN T
        
          LEFT JOIN (SELECT T3.JUDGE_STOVE_NO,
                           T3.PLAN_ID,
                           T3.STATUS,
                           SUM(T3.ACT_COUNT) ACT_COUNT
                      FROM PORT_MIL_BATCH_SAMPLE_RESULT T3
                     WHERE T3.STATUS IN ('2', '5', '6')
                     GROUP BY T3.JUDGE_STOVE_NO, T3.PLAN_ID, T3.STATUS) T2
            ON T.ID = T2.PLAN_ID
           AND T.JUDGE_STOVE_NO = T2.JUDGE_STOVE_NO
         WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
           AND T.LOT_NO = '#LOT_NO#'
           AND T.BACK_SLAB_FLAG <> '2'
           AND T.PLINE_CODE = '#PLINE_CODE#' #condtions1# #condtions#
        UNION ALL
        SELECT REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') JUDGE_STOVE_NO,
               T.JUDGE_STOVE_NO AS JUDGE_NO,
               T.CONTRACT_NO AS ORDER_NO,
               T.LOT_NO,
               T.TARGET_LIABRARY,
               --T1.OUTWL_ID,
               --REGEXP_SUBSTR(GET_WL_CODE(SUBSTR(T.Ord_Ln_Dly_Pk,0,LENGTH(T.Ord_Ln_Dly_Pk)-3)),'[^#]+',1,1)OUTWL_ID,
               --T.VARIETIES||','||T.STEELNAME||','||T.PIPE_SIZE||','||T.BUCKLE_TYPE OUTWL_DESC,
               --REGEXP_SUBSTR(GET_WL_CODE(SUBSTR(T.Ord_Ln_Dly_Pk,0,LENGTH(T.Ord_Ln_Dly_Pk)-3)),'[^#]+',1,2) OUTWL_DESC,
               CASE SUBSTR(T.JUDGE_STOVE_NO, -1)
                 WHEN '1' THEN
                  REGEXP_SUBSTR(GET_WL_CODE(SUBSTR(T.Ord_Ln_Dly_Pk,
                                                   0,
                                                   LENGTH(T.Ord_Ln_Dly_Pk) - 3)),
                                '[^#]+',
                                1,
                                1)
                 ELSE
                  REGEXP_SUBSTR(GET_WL_CODE2(T.CONTRACT_NO), '[^#]+', 1, 1)
               END OUTWL_ID,
               
               CASE SUBSTR(T.JUDGE_STOVE_NO, -1)
                 WHEN '1' THEN
                  REGEXP_SUBSTR(GET_WL_CODE(SUBSTR(T.Ord_Ln_Dly_Pk,
                                                   0,
                                                   LENGTH(T.Ord_Ln_Dly_Pk) - 3)),
                                '[^#]+',
                                1,
                                2)
                 ELSE
                  REGEXP_SUBSTR(GET_WL_CODE2(T.CONTRACT_NO), '[^#]+', 1, 2)
               END OUTWL_DESC,
               0 AS INCOUNT,
               0 AS INWEIGHT,
               0 AS PENDINGCOUNT,
               0 AS PENDINGWEIGHT,
               0 AS SCRAPCOUNT,
               0 AS SCRAPWEIGHT,
               T2.ACT_COUNT AS SOUTCOUNT,
               0 AS SOUTWEIGHT
        
          FROM MIL_PLAN T
          LEFT JOIN (SELECT T3.JUDGE_STOVE_NO,
                           T3.PLAN_ID,
                           T3.STATUS,
                           SUM(T3.ACT_COUNT) ACT_COUNT
                      FROM PORT_MIL_BATCH_SAMPLE_RESULT T3
                     WHERE T3.STATUS = '0'
                     GROUP BY T3.JUDGE_STOVE_NO, T3.PLAN_ID, T3.STATUS) T2
            ON T.id = T2.PLAN_ID
           AND T.JUDGE_STOVE_NO = T2.JUDGE_STOVE_NO
         WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
           AND T.LOT_NO = '#LOT_NO#'
           AND T.BACK_SLAB_FLAG <> '2'
           AND T.PLINE_CODE = '#PLINE_CODE#' #condtions1# #condtions#)
 GROUP BY JUDGE_STOVE_NO, JUDGE_NO, ORDER_NO, OUTWL_DESC, LOT_NO,TARGET_LIABRARY
 ]]>
</query>
<query id = "FrmInOnlineStore.doQueryQaStove" desc = "查询表检炉批信息">
SELECT T.JUDGE_STOVE_NO, T.LOT_NO
  FROM MIL_SURFACE_RESULT T
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.PLINE_CODE = ?
 GROUP BY T.JUDGE_STOVE_NO, T.LOT_NO
</query>
<query id = "FrmInOnlineStore.doQuerySurface" desc = "查询炉批详细信息(成品)">
<![CDATA[
SELECT T3.MATERIAL_NO,
       T3.MATERIAL_DESC,
       T.VARIETIES_CODE   PRODUCCODE,
       T.VARIETIES        PRODUCNAME,
       T.STEELCODE        STEELCODE,
       T.STEELNAME        STEELNAME,
       T.STD_STYLE        STD_STYLE,
       T.STD_STYLE_DESC   STD_STYLE_DESC,
       T.PIPE_SIZE_CODE   SPEC_CODE,
       T.PIPE_SIZE        SPEC_NAME,
       T.BUCKLE_TYPE_CODE MODEL_CODE,
       T.BUCKLE_TYPE      MODEL_DESC,
       --SUBSTR(T.PIPE_SIZE, INSTR(T.PIPE_SIZE, '*', -1, 1) + 1) HEIGHT,
       --SUBSTR(T.PIPE_SIZE, 0, INSTR(T.PIPE_SIZE, '*', -1, 1) - 1) DIMATER,
       CASE
         WHEN INSTR(T.PIPE_SIZE, '*', -1, 1) > 0 THEN
          SUBSTR(T.PIPE_SIZE, INSTR(T.PIPE_SIZE, '*', -1, 1) + 1)
         ELSE
          SUBSTR(T.PIPE_SIZE, INSTR(T.PIPE_SIZE, 'x', -1, 1) + 1)
       END HEIGHT,
       CASE
         WHEN INSTR(T.PIPE_SIZE, '*', -1, 1) > 0 THEN
          SUBSTR(T.PIPE_SIZE, 0, INSTR(T.PIPE_SIZE, '*', -1, 1) - 1)
         ELSE
          SUBSTR(T.PIPE_SIZE, 0, INSTR(T.PIPE_SIZE, 'x', -1, 1) - 1)
       END DIMATER,
       T.GRADECODE,
       T.GRADENAME,
       T.ROLL_STANDRAD_CODE,
       T.ROLL_STANDRAD,
       T.CONTRACT_NO,
       T.IMP_PROCESS,
       T.PRODUCE_STANDRAD,
       T3.PLINE_CODE,
       T3.PLINE_NAME,
       REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') JUDGE_STOVE_NO,
       T.JUDGE_STOVE_NO AS JUDGE_NO,
       T.LOT_NO,
       SUBSTR(T.LENGTH_RANGE, INSTR(T.LENGTH_RANGE, '-', -1, 1) + 1) LENGTHMAX,
       SUBSTR(T.LENGTH_RANGE, 0, INSTR(T.LENGTH_RANGE, '-', -1, 1) - 1) LENGTHMIN,
       T.TARGET,
       DECODE(T.TARGET, 'A', '成品', 'B', '半成品', 'C', '镦拔扩及热处理') GO_TYPE,
       T.PROCESS_STATUS,
       '合格' ASTATUS,
       T.ID,
       (SELECT T.NEXT_GX
          FROM PLN_ORDER_ZG T
         WHERE T.PRO_ORDER_NO = T3.PRO_ORDER_NO) NEXT_GX,
       T.PRO_PLAN_ID,
       T.GX_PLAN_NO,
       T.ORD_LN_DLY_PK,
       T.STOVE_NO
  FROM MIL_PLAN T
  LEFT JOIN (SELECT T2.PLINE_CODE,
                    T2.PLINE_NAME,
                    T2.ORD_LN_DLY_PK,
                    
                    T2.ORDER_NO || '/' || T2.ORDER_SEQ AS ORDERNO,
                    T2.PRO_PLAN_ID,
                    T4.MATERIAL_NO,
                    T4.MATERIAL_DESC,
                    T4.PRODUCCODE,
                    T4.PRODUCNAME,
                    T4.STD_STYLE,
                    T4.STD_STYLE_DESC,
                    T4.STEELCODE,
                    T4.STEELNAME,
                    T4.GRADECODE,
                    T4.GRADENAME,
                    T4.DIMATER,
                    T4.HEIGHT,
                    T4.SPEC_CODE,
                    T4.SPEC_NAME,
                    T4.MODEL_CODE,
                    T4.MODEL_DESC,
                    T2.PRO_ORDER_NO
               FROM PLN_ORDER_ZG_S T2, SLM_BASE_MATERIAL T4
              WHERE T2.OUTWL_ID = T4.MATERIAL_NO(+)
              GROUP BY T2.PLINE_CODE,
                       T2.PLINE_NAME,
                       T2.ORD_LN_DLY_PK,
                       T2.ORDER_NO || '/' || T2.ORDER_SEQ,
                       T2.PRO_PLAN_ID,
                       T2.PRO_ORDER_NO,
                       T4.MATERIAL_NO,
                       T4.MATERIAL_DESC,
                       T4.PRODUCCODE,
                       T4.PRODUCNAME,
                       T4.STD_STYLE,
                       T4.STD_STYLE_DESC,
                       T4.STEELCODE,
                       T4.STEELNAME,
                       T4.GRADECODE,
                       T4.GRADENAME,
                       T4.DIMATER,
                       T4.HEIGHT,
                       T4.SPEC_CODE,
                       T4.SPEC_NAME,
                       T4.MODEL_CODE,
                       T4.MODEL_DESC) T3
    ON T.CONTRACT_NO = T3.ORDERNO
 WHERE T.JUDGE_STOVE_NO = ?
      --T.JUDGE_STOVE_NO || '&' LIKE '%' || ? || '%'
      --AND T.LOT_NO || '&' LIKE '%' || ? || '%'
   AND T.LOT_NO = ?
   AND T.PLINE_CODE = ?
   AND ROWNUM = 1
UNION ALL
SELECT T3.MATERIAL_NO,
       T3.MATERIAL_DESC,
       T.VARIETIES_CODE   PRODUCCODE,
       T.VARIETIES        PRODUCNAME,
       T.STEELCODE        STEELCODE,
       T.STEELNAME        STEELNAME,
       T.STD_STYLE        STD_STYLE,
       T.STD_STYLE_DESC   STD_STYLE_DESC,
       T.PIPE_SIZE_CODE   SPEC_CODE,
       T.PIPE_SIZE        SPEC_NAME,
       T.BUCKLE_TYPE_CODE MODEL_CODE,
       T.BUCKLE_TYPE      MODEL_DESC,
       --SUBSTR(T.PIPE_SIZE, INSTR(T.PIPE_SIZE, '*', -1, 1) + 1) HEIGHT,
       --SUBSTR(T.PIPE_SIZE, 0, INSTR(T.PIPE_SIZE, '*', -1, 1) - 1) DIMATER,
       CASE
         WHEN INSTR(T.PIPE_SIZE, '*', -1, 1) > 0 THEN
          SUBSTR(T.PIPE_SIZE, INSTR(T.PIPE_SIZE, '*', -1, 1) + 1)
         ELSE
          SUBSTR(T.PIPE_SIZE, INSTR(T.PIPE_SIZE, 'x', -1, 1) + 1)
       END HEIGHT,
       CASE
         WHEN INSTR(T.PIPE_SIZE, '*', -1, 1) > 0 THEN
          SUBSTR(T.PIPE_SIZE, 0, INSTR(T.PIPE_SIZE, '*', -1, 1) - 1)
         ELSE
          SUBSTR(T.PIPE_SIZE, 0, INSTR(T.PIPE_SIZE, 'x', -1, 1) - 1)
       END DIMATER,
       T.GRADECODE,
       T.GRADENAME,
       T.ROLL_STANDRAD_CODE,
       T.ROLL_STANDRAD,
       T.CONTRACT_NO,
       T.IMP_PROCESS,
       T.PRODUCE_STANDRAD,
       T3.PLINE_CODE,
       T3.PLINE_NAME,
       REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') JUDGE_STOVE_NO,
       T.JUDGE_STOVE_NO AS JUDGE_NO,
       T.LOT_NO,
       SUBSTR(T.LENGTH_RANGE, INSTR(T.LENGTH_RANGE, '-', -1, 1) + 1) LENGTHMAX,
       SUBSTR(T.LENGTH_RANGE, 0, INSTR(T.LENGTH_RANGE, '-', -1, 1) - 1) LENGTHMIN,
       T.TARGET,
       DECODE(T.TARGET, 'A', '成品', 'B', '半成品', 'C', '镦拔扩及热处理') GO_TYPE,
       T.PROCESS_STATUS,
       '判废' ASTATUS,
       T.ID,
       (SELECT T.NEXT_GX
          FROM PLN_ORDER_ZG T
         WHERE T.PRO_ORDER_NO = T3.PRO_ORDER_NO) NEXT_GX,
       T.PRO_PLAN_ID,
       T.GX_PLAN_NO,
       T.ORD_LN_DLY_PK,
       T.STOVE_NO
  FROM MIL_PLAN T
  LEFT JOIN (SELECT T2.PLINE_CODE,
                    T2.PLINE_NAME,
                    T2.ORD_LN_DLY_PK,
                    
                    T2.ORDER_NO || '/' || T2.ORDER_SEQ AS ORDERNO,
                    T2.PRO_PLAN_ID,
                    T4.MATERIAL_NO,
                    T4.MATERIAL_DESC,
                    T4.PRODUCCODE,
                    T4.PRODUCNAME,
                    T4.STD_STYLE,
                    T4.STD_STYLE_DESC,
                    T4.STEELCODE,
                    T4.STEELNAME,
                    T4.GRADECODE,
                    T4.GRADENAME,
                    T4.DIMATER,
                    T4.HEIGHT,
                    T4.SPEC_CODE,
                    T4.SPEC_NAME,
                    T4.MODEL_CODE,
                    T4.MODEL_DESC,
                    T2.PRO_ORDER_NO
               FROM PLN_ORDER_ZG_S T2, SLM_BASE_MATERIAL T4
              WHERE T2.OUTWL_ID = T4.MATERIAL_NO(+)
              GROUP BY T2.PLINE_CODE,
                       T2.PLINE_NAME,
                       T2.ORD_LN_DLY_PK,
                       T2.ORDER_NO || '/' || T2.ORDER_SEQ,
                       T2.PRO_PLAN_ID,
                       T2.PRO_ORDER_NO,
                       T4.MATERIAL_NO,
                       T4.MATERIAL_DESC,
                       T4.PRODUCCODE,
                       T4.PRODUCNAME,
                       T4.STD_STYLE,
                       T4.STD_STYLE_DESC,
                       T4.STEELCODE,
                       T4.STEELNAME,
                       T4.GRADECODE,
                       T4.GRADENAME,
                       T4.DIMATER,
                       T4.HEIGHT,
                       T4.SPEC_CODE,
                       T4.SPEC_NAME,
                       T4.MODEL_CODE,
                       T4.MODEL_DESC) T3
    ON T.CONTRACT_NO = T3.ORDERNO
 WHERE T.JUDGE_STOVE_NO = ?
      --T.JUDGE_STOVE_NO || '&' LIKE '%' || ? || '%'
      --AND T.LOT_NO || '&' LIKE '%' || ? || '%'
   AND T.LOT_NO = ?
   AND T.PLINE_CODE = ?
   AND ROWNUM = 1
UNION ALL
SELECT T3.MATERIAL_NO,
       T3.MATERIAL_DESC,
       T.VARIETIES_CODE   PRODUCCODE,
       T.VARIETIES        PRODUCNAME,
       T.STEELCODE        STEELCODE,
       T.STEELNAME        STEELNAME,
       T.STD_STYLE        STD_STYLE,
       T.STD_STYLE_DESC   STD_STYLE_DESC,
       T.PIPE_SIZE_CODE   SPEC_CODE,
       T.PIPE_SIZE        SPEC_NAME,
       T.BUCKLE_TYPE_CODE MODEL_CODE,
       T.BUCKLE_TYPE      MODEL_DESC,
       --SUBSTR(T.PIPE_SIZE, INSTR(T.PIPE_SIZE, '*', -1, 1) + 1) HEIGHT,
       --SUBSTR(T.PIPE_SIZE, 0, INSTR(T.PIPE_SIZE, '*', -1, 1) - 1) DIMATER,
       CASE
         WHEN INSTR(T.PIPE_SIZE, '*', -1, 1) > 0 THEN
          SUBSTR(T.PIPE_SIZE, INSTR(T.PIPE_SIZE, '*', -1, 1) + 1)
         ELSE
          SUBSTR(T.PIPE_SIZE, INSTR(T.PIPE_SIZE, 'x', -1, 1) + 1)
       END HEIGHT,
       CASE
         WHEN INSTR(T.PIPE_SIZE, '*', -1, 1) > 0 THEN
          SUBSTR(T.PIPE_SIZE, 0, INSTR(T.PIPE_SIZE, '*', -1, 1) - 1)
         ELSE
          SUBSTR(T.PIPE_SIZE, 0, INSTR(T.PIPE_SIZE, 'x', -1, 1) - 1)
       END DIMATER,
       T.GRADECODE,
       T.GRADENAME,
       T.ROLL_STANDRAD_CODE,
       T.ROLL_STANDRAD,
       T.CONTRACT_NO,
       T.IMP_PROCESS,
       T.PRODUCE_STANDRAD,
       T3.PLINE_CODE,
       T3.PLINE_NAME,
       REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') JUDGE_STOVE_NO,
       T.JUDGE_STOVE_NO AS JUDGE_NO,
       T.LOT_NO,
       SUBSTR(T.LENGTH_RANGE, INSTR(T.LENGTH_RANGE, '-', -1, 1) + 1) LENGTHMAX,
       SUBSTR(T.LENGTH_RANGE, 0, INSTR(T.LENGTH_RANGE, '-', -1, 1) - 1) LENGTHMIN,
       T.TARGET,
       DECODE(T.TARGET, 'A', '成品', 'B', '半成品', 'C', '镦拔扩及热处理') GO_TYPE,
       T.PROCESS_STATUS,
       '样管' ASTATUS,
       T.ID,
       (SELECT T.NEXT_GX
          FROM PLN_ORDER_ZG T
         WHERE T.PRO_ORDER_NO = T3.PRO_ORDER_NO) NEXT_GX,
       T.PRO_PLAN_ID,
       T.GX_PLAN_NO,
       T.ORD_LN_DLY_PK,
       T.STOVE_NO
  FROM (SELECT T1.JUDGE_STOVE_NO, T1.LOT_NO, T1.PLINE_CODE, T1.PLAN_ID
          FROM PORT_MIL_BATCH_SAMPLE_RESULT T1
         WHERE T1.IS_SAMPLE_PIPE = '1'
         GROUP BY T1.JUDGE_STOVE_NO, T1.LOT_NO, T1.PLINE_CODE, T1.PLAN_ID) S
  LEFT JOIN MIL_PLAN T
    ON T.JUDGE_STOVE_NO = S.JUDGE_STOVE_NO
   AND T.ID = S.PLAN_ID
  LEFT JOIN (SELECT T2.PLINE_CODE,
                    T2.PLINE_NAME,
                    T2.ORD_LN_DLY_PK,
                    
                    T2.ORDER_NO || '/' || T2.ORDER_SEQ AS ORDERNO,
                    T2.PRO_PLAN_ID,
                    T4.MATERIAL_NO,
                    T4.MATERIAL_DESC,
                    T4.PRODUCCODE,
                    T4.PRODUCNAME,
                    T4.STD_STYLE,
                    T4.STD_STYLE_DESC,
                    T4.STEELCODE,
                    T4.STEELNAME,
                    T4.GRADECODE,
                    T4.GRADENAME,
                    T4.DIMATER,
                    T4.HEIGHT,
                    T4.SPEC_CODE,
                    T4.SPEC_NAME,
                    T4.MODEL_CODE,
                    T4.MODEL_DESC,
                    T2.PRO_ORDER_NO
               FROM PLN_ORDER_ZG_S T2, SLM_BASE_MATERIAL T4
              WHERE T2.OUTWL_ID = T4.MATERIAL_NO(+)
              GROUP BY T2.PLINE_CODE,
                       T2.PLINE_NAME,
                       T2.ORD_LN_DLY_PK,
                       T2.ORDER_NO || '/' || T2.ORDER_SEQ,
                       T2.PRO_PLAN_ID,
                       T2.PRO_ORDER_NO,
                       T4.MATERIAL_NO,
                       T4.MATERIAL_DESC,
                       T4.PRODUCCODE,
                       T4.PRODUCNAME,
                       T4.STD_STYLE,
                       T4.STD_STYLE_DESC,
                       T4.STEELCODE,
                       T4.STEELNAME,
                       T4.GRADECODE,
                       T4.GRADENAME,
                       T4.DIMATER,
                       T4.HEIGHT,
                       T4.SPEC_CODE,
                       T4.SPEC_NAME,
                       T4.MODEL_CODE,
                       T4.MODEL_DESC) T3
    ON T.CONTRACT_NO = T3.ORDERNO
 WHERE S.JUDGE_STOVE_NO = ?
      --S.JUDGE_STOVE_NO || '&' LIKE '%' || ? || '%'
      --AND S.LOT_NO || '&' LIKE '%' || ? || '%'
   AND S.LOT_NO = ?
   AND S.PLINE_CODE = ?
   AND ROWNUM = 1
    ]]>
</query>

<query id = "FrmInOnlineStore.doQuerySurface1" desc = "查询炉批详细信息（半成品）">
<![CDATA[
   SELECT T.CONTRACT_NO,
       T.IMP_PROCESS,
       T.PRODUCE_STANDRAD,
       T.PLINE_CODE,
       REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') JUDGE_STOVE_NO,
       T.JUDGE_STOVE_NO AS JUDGE_NO,
       T.LOT_NO,
       SUBSTR(T.LENGTH_RANGE, INSTR(T.LENGTH_RANGE, '-', -1, 1) + 1) LENGTHMAX,
       SUBSTR(T.LENGTH_RANGE, 0, INSTR(T.LENGTH_RANGE, '-', -1, 1) - 1) LENGTHMIN,
       --SUBSTR(T.PIPE_SIZE, 0, INSTR(T.PIPE_SIZE, '*', -1, 1) - 1) DIMATER,
       --SUBSTR(T.PIPE_SIZE, INSTR(T.PIPE_SIZE, '*', -1, 1) + 1) HEIGHT,
       CASE
         WHEN INSTR(T.PIPE_SIZE, '*', -1, 1) > 0 THEN
          SUBSTR(T.PIPE_SIZE, 0, INSTR(T.PIPE_SIZE, '*', -1, 1) - 1)
         ELSE
          SUBSTR(T.PIPE_SIZE, 0, INSTR(T.PIPE_SIZE, 'x', -1, 1) - 1)
       END DIMATER,
       CASE
         WHEN INSTR(T.PIPE_SIZE, '*', -1, 1) > 0 THEN
          SUBSTR(T.PIPE_SIZE, INSTR(T.PIPE_SIZE, '*', -1, 1) + 1)
         ELSE
          SUBSTR(T.PIPE_SIZE, INSTR(T.PIPE_SIZE, 'x', -1, 1) + 1)
       END HEIGHT,
       
       --T2.OUTDIAMETER DIMATER,
       --T2.WALLTHICK HEIGHT,
       --SUBSTR(T2.OUTWL_ID, 3, INSTR(T2.OUTWL_ID, ',', 1, 1) - 3) SPEC_CODE,
       --(SELECT F.SPEC_NAME
       --  FROM COM_BASE_SPEC F
       -- WHERE F.SPEC_CODE =
       --      SUBSTR(T2.OUTWL_ID, 3, INSTR(T2.OUTWL_ID, ',', 1, 1) - 3)) SPEC_NAME,
       --SUBSTR(T2.OUTWL_ID, INSTR(T2.OUTWL_ID, ',', 1, 1) + 1) GRADECODE,
       --(SELECT F1.GRADENAME
       -- FROM COM_BASE_GRADE F1
       -- WHERE F1.GRADECODE =
       --       SUBSTR(T2.OUTWL_ID, INSTR(T2.OUTWL_ID, ',', 1, 1) + 1)) GRADENAME,
       T.TARGET,
       DECODE(T.TARGET, 'A', '成品', 'B', '半成品', 'C', '镦拔扩及热处理') GO_TYPE,
       T.PROCESS_STATUS,
       '合格' ASTATUS,
       T.ID,
       (SELECT T.NEXT_GX
          FROM PLN_ORDER_ZG T
         WHERE T.PRO_ORDER_NO = T2.PRO_ORDER_NO) NEXT_GX,
       T.PRO_PLAN_ID,
       T.GX_PLAN_NO,
       T.VARIETIES_CODE,
       T.VARIETIES,
       T.STD_STYLE,
       T.Std_Style_Desc,
       T.STEELCODE,
       T.STEELNAME,
       T.PIPE_SIZE_code,
       T.Pipe_Size,
       T.BUCKLE_TYPE_CODE,
       T.Buckle_Type,
       T.Gradecode,
       T.Gradename,
       T.Roll_Standrad_Code,
       T.Roll_Standrad,
       T.ORD_LN_DLY_PK,
       T.STOVE_NO
  FROM MIL_PLAN T
  LEFT JOIN (SELECT PLINE_CODE,
                    PLINE_NAME,
                    OUTDIAMETER,
                    WALLTHICK,
                    OUTWL_ID,
                    PRO_PLAN_ID,
                    ORDER_NO,
                    ORDER_SEQ,
                    ORD_LN_DLY_PK,
                    PRO_ORDER_NO
               FROM PLN_ORDER_ZG_S
              GROUP BY PLINE_CODE,
                       PLINE_NAME,
                       OUTDIAMETER,
                       WALLTHICK,
                       OUTWL_ID,
                       PRO_PLAN_ID,
                       ORDER_NO,
                       ORDER_SEQ,
                       ORD_LN_DLY_PK,
                       PRO_ORDER_NO) T2
    ON T.CONTRACT_NO = T2.ORDER_NO || '/' || T2.ORDER_SEQ
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.LOT_NO = ?
   AND T.PLINE_CODE = ?
   AND ROWNUM = 1
UNION ALL
SELECT T.CONTRACT_NO,
       T.IMP_PROCESS,
       T.PRODUCE_STANDRAD,
       T.PLINE_CODE,
       REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') JUDGE_STOVE_NO,
       T.JUDGE_STOVE_NO AS JUDGE_NO,
       T.LOT_NO,
       SUBSTR(T.LENGTH_RANGE, INSTR(T.LENGTH_RANGE, '-', -1, 1) + 1) LENGTHMAX,
       SUBSTR(T.LENGTH_RANGE, 0, INSTR(T.LENGTH_RANGE, '-', -1, 1) - 1) LENGTHMIN,
       --SUBSTR(T.PIPE_SIZE, 0, INSTR(T.PIPE_SIZE, '*', -1, 1) - 1) DIMATER,
       --SUBSTR(T.PIPE_SIZE, INSTR(T.PIPE_SIZE, '*', -1, 1) + 1) HEIGHT,
       CASE
         WHEN INSTR(T.PIPE_SIZE, '*', -1, 1) > 0 THEN
          SUBSTR(T.PIPE_SIZE, 0, INSTR(T.PIPE_SIZE, '*', -1, 1) - 1)
         ELSE
          SUBSTR(T.PIPE_SIZE, 0, INSTR(T.PIPE_SIZE, 'x', -1, 1) - 1)
       END DIMATER,
       CASE
         WHEN INSTR(T.PIPE_SIZE, '*', -1, 1) > 0 THEN
          SUBSTR(T.PIPE_SIZE, INSTR(T.PIPE_SIZE, '*', -1, 1) + 1)
         ELSE
          SUBSTR(T.PIPE_SIZE, INSTR(T.PIPE_SIZE, 'x', -1, 1) + 1)
       END HEIGHT,
       --T2.OUTDIAMETER DIMATER,
       --T2.WALLTHICK HEIGHT,
       --SUBSTR(T2.OUTWL_ID, 3, INSTR(T2.OUTWL_ID, ',', 1, 1) - 3) SPEC_CODE,
       --(SELECT F.SPEC_NAME
       --  FROM COM_BASE_SPEC F
       -- WHERE F.SPEC_CODE =
       --      SUBSTR(T2.OUTWL_ID, 3, INSTR(T2.OUTWL_ID, ',', 1, 1) - 3)) SPEC_NAME,
       --SUBSTR(T2.OUTWL_ID, INSTR(T2.OUTWL_ID, ',', 1, 1) + 1) GRADECODE,
       --(SELECT F1.GRADENAME
       -- FROM COM_BASE_GRADE F1
       -- WHERE F1.GRADECODE =
       --       SUBSTR(T2.OUTWL_ID, INSTR(T2.OUTWL_ID, ',', 1, 1) + 1)) GRADENAME,
       T.TARGET,
       DECODE(T.TARGET, 'A', '成品', 'B', '半成品', 'C', '镦拔扩及热处理') GO_TYPE,
       T.PROCESS_STATUS,
       '判废' ASTATUS,
       T.ID,
       (SELECT T.NEXT_GX
          FROM PLN_ORDER_ZG T
         WHERE T.PRO_ORDER_NO = T2.PRO_ORDER_NO) NEXT_GX,
       T.PRO_PLAN_ID,
       T.GX_PLAN_NO,
       T.VARIETIES_CODE,
       T.VARIETIES,
       T.STD_STYLE,
       T.Std_Style_Desc,
       T.STEELCODE,
       T.STEELNAME,
       T.PIPE_SIZE_code,
       T.Pipe_Size,
       T.BUCKLE_TYPE_CODE,
       T.Buckle_Type,
       T.Gradecode,
       T.Gradename,
       T.Roll_Standrad_Code,
       T.Roll_Standrad,
       T.ORD_LN_DLY_PK,
       T.STOVE_NO
  FROM MIL_PLAN T
  LEFT JOIN (SELECT PLINE_CODE,
                    PLINE_NAME,
                    OUTDIAMETER,
                    WALLTHICK,
                    OUTWL_ID,
                    PRO_PLAN_ID,
                    ORDER_NO,
                    ORDER_SEQ,
                    ORD_LN_DLY_PK,
                    PRO_ORDER_NO
               FROM PLN_ORDER_ZG_S
              GROUP BY PLINE_CODE,
                       PLINE_NAME,
                       OUTDIAMETER,
                       WALLTHICK,
                       OUTWL_ID,
                       PRO_PLAN_ID,
                       ORDER_NO,
                       ORDER_SEQ,
                       ORD_LN_DLY_PK,
                       PRO_ORDER_NO) T2
    ON T.CONTRACT_NO = T2.ORDER_NO || '/' || T2.ORDER_SEQ
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.LOT_NO = ?
   AND T.PLINE_CODE = ?
   AND ROWNUM = 1
UNION ALL
SELECT T.CONTRACT_NO,
       T.IMP_PROCESS,
       T.PRODUCE_STANDRAD,
       T.PLINE_CODE,
       REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') JUDGE_STOVE_NO,
       T.JUDGE_STOVE_NO AS JUDGE_NO,
       T.LOT_NO,
       SUBSTR(T.LENGTH_RANGE, INSTR(T.LENGTH_RANGE, '-', -1, 1) + 1) LENGTHMAX,
       SUBSTR(T.LENGTH_RANGE, 0, INSTR(T.LENGTH_RANGE, '-', -1, 1) - 1) LENGTHMIN,
       --SUBSTR(T.PIPE_SIZE, 0, INSTR(T.PIPE_SIZE, '*', -1, 1) - 1) DIMATER,
       --SUBSTR(T.PIPE_SIZE, INSTR(T.PIPE_SIZE, '*', -1, 1) + 1) HEIGHT,
       CASE
         WHEN INSTR(T.PIPE_SIZE, '*', -1, 1) > 0 THEN
          SUBSTR(T.PIPE_SIZE, 0, INSTR(T.PIPE_SIZE, '*', -1, 1) - 1)
         ELSE
          SUBSTR(T.PIPE_SIZE, 0, INSTR(T.PIPE_SIZE, 'x', -1, 1) - 1)
       END DIMATER,
       CASE
         WHEN INSTR(T.PIPE_SIZE, '*', -1, 1) > 0 THEN
          SUBSTR(T.PIPE_SIZE, INSTR(T.PIPE_SIZE, '*', -1, 1) + 1)
         ELSE
          SUBSTR(T.PIPE_SIZE, INSTR(T.PIPE_SIZE, 'x', -1, 1) + 1)
       END HEIGHT,
       --T2.OUTDIAMETER DIMATER,
       --T2.WALLTHICK HEIGHT,
       --SUBSTR(T2.OUTWL_ID, 3, INSTR(T2.OUTWL_ID, ',', 1, 1) - 3) SPEC_CODE,
       --(SELECT F.SPEC_NAME
       --   FROM COM_BASE_SPEC F
       --  WHERE F.SPEC_CODE =
       --       SUBSTR(T2.OUTWL_ID, 3, INSTR(T2.OUTWL_ID, ',', 1, 1) - 3)) SPEC_NAME,
       --SUBSTR(T2.OUTWL_ID, INSTR(T2.OUTWL_ID, ',', 1, 1) + 1) GRADECODE,
       --(SELECT F1.GRADENAME
       --  FROM COM_BASE_GRADE F1
       -- WHERE F1.GRADECODE =
       --      SUBSTR(T2.OUTWL_ID, INSTR(T2.OUTWL_ID, ',', 1, 1) + 1)) GRADENAME,
       T.TARGET,
       DECODE(T.TARGET, 'A', '成品', 'B', '半成品', 'C', '镦拔扩及热处理') GO_TYPE,
       T.PROCESS_STATUS,
       '样管' ASTATUS,
       T.ID,
       (SELECT T.NEXT_GX
          FROM PLN_ORDER_ZG T
         WHERE T.PRO_ORDER_NO = T2.PRO_ORDER_NO) NEXT_GX,
       T.PRO_PLAN_ID,
       T.GX_PLAN_NO,
       T.VARIETIES_CODE,
       T.VARIETIES,
       T.STD_STYLE,
       T.Std_Style_Desc,
       T.STEELCODE,
       T.STEELNAME,
       T.PIPE_SIZE_code,
       T.Pipe_Size,
       T.BUCKLE_TYPE_CODE,
       T.Buckle_Type,
       T.Gradecode,
       T.Gradename,
       T.Roll_Standrad_Code,
       T.Roll_Standrad,
       T.ORD_LN_DLY_PK,
       T.STOVE_NO
  FROM (SELECT T1.JUDGE_STOVE_NO, T1.LOT_NO, T1.PLINE_CODE
          FROM PORT_MIL_BATCH_SAMPLE_RESULT T1
         WHERE T1.IS_SAMPLE_PIPE = '1'
         GROUP BY T1.JUDGE_STOVE_NO, T1.LOT_NO, T1.PLINE_CODE) S
  LEFT JOIN MIL_PLAN T
    ON T.JUDGE_STOVE_NO = S.JUDGE_STOVE_NO
   AND T.LOT_NO = S.LOT_NO
  LEFT JOIN (SELECT PLINE_CODE,
                    PLINE_NAME,
                    OUTDIAMETER,
                    WALLTHICK,
                    OUTWL_ID,
                    PRO_PLAN_ID,
                    ORDER_NO,
                    ORDER_SEQ,
                    ORD_LN_DLY_PK,
                    PRO_ORDER_NO
               FROM PLN_ORDER_ZG_S
              GROUP BY PLINE_CODE,
                       PLINE_NAME,
                       OUTDIAMETER,
                       WALLTHICK,
                       OUTWL_ID,
                       PRO_PLAN_ID,
                       ORDER_NO,
                       ORDER_SEQ,
                       ORD_LN_DLY_PK,
                       PRO_ORDER_NO) T2
    ON T.CONTRACT_NO = T2.ORDER_NO || '/' || T2.ORDER_SEQ
 WHERE S.JUDGE_STOVE_NO = ?
   AND S.LOT_NO = ?
   AND S.PLINE_CODE = ?
   AND ROWNUM = 1

]]>
</query>
<!-- 
SELECT S.QUALIFIED_BRANCH AS ACT_COUNT,
       (T.DB_NUM / T.SAW_NUM * S.QUALIFIED_BRANCH) ACT_WEIGHT,
       T.CONTRACT_NO,
       T.IMP_PROCESS,
       T.PRODUCE_STANDRAD,
       T2.PLINE_CODE,
       T.JUDGE_STOVE_NO,
       T.LOT_NO,
       T2.PLINE_NAME,
       T2.LENGTHMAX,
       T2.LENGTHMIN,
       T2.OUTDIAMETER DIMATER,
       T2.WALLTHICK HEIGHT,
       SUBSTR(T2.OUTWL_ID, 3, INSTR(T2.OUTWL_ID, ',', 1, 1) - 3) SPEC_CODE,
       (SELECT F.SPEC_NAME
          FROM COM_BASE_SPEC F
         WHERE F.SPEC_CODE =
               SUBSTR(T2.OUTWL_ID, 3, INSTR(T2.OUTWL_ID, ',', 1, 1) - 3)) SPEC_NAME,
       SUBSTR(T2.OUTWL_ID, INSTR(T2.OUTWL_ID, ',', 1, 1) + 1) GRADECODE,
       (SELECT F1.GRADENAME
          FROM COM_BASE_GRADE F1
         WHERE F1.GRADECODE =
               SUBSTR(T2.OUTWL_ID, INSTR(T2.OUTWL_ID, ',', 1, 1) + 1)) GRADENAME,
       T.TARGET,
       S.PIPE_LENGTH AS ACT_LEN,
       DECODE(T2.GO_TYPE,'A','成品','B','半成品','C','镦拔扩及热处理')GO_TYPE,
       '合格' ASTATUS
  FROM MIL_PLAN T,
       (SELECT COUNT(1) QUALIFIED_BRANCH, T1.JUDGE_STOVE_NO, T1.LOT_NO,T1.PIPE_LENGTH
          FROM MIL_QA_RACK T1
         WHERE T1.STATUS = '0'
         GROUP BY T1.JUDGE_STOVE_NO, T1.LOT_NO) S,
       PLN_ORDER_ZG T2
 WHERE T.JUDGE_STOVE_NO = S.JUDGE_STOVE_NO
   AND T.LOT_NO = S.LOT_NO
   AND T.CONTRACT_NO = T2.ORDER_NO || '/' || T2.ORDER_SEQ
   AND T.JUDGE_STOVE_NO = ?
   AND T.LOT_NO = ?
   AND T.PLINE_CODE = ?
UNION ALL
SELECT S.QUALIFIED_BRANCH AS ACT_COUNT,
       (T.DB_NUM / T.SAW_NUM * S.QUALIFIED_BRANCH) ACT_WEIGHT,
       
       T.CONTRACT_NO,
       T.IMP_PROCESS,
       T.PRODUCE_STANDRAD,
       T2.PLINE_CODE,
       T.JUDGE_STOVE_NO,
       T.LOT_NO,
       T2.PLINE_NAME,
       T2.LENGTHMAX,
       T2.LENGTHMIN,
       T2.OUTDIAMETER DIMATER,
       T2.WALLTHICK HEIGHT,
       SUBSTR(T2.OUTWL_ID, 3, INSTR(T2.OUTWL_ID, ',', 1, 1) - 3) SPEC_CODE,
       (SELECT F.SPEC_NAME
          FROM COM_BASE_SPEC F
         WHERE F.SPEC_CODE =
               SUBSTR(T2.OUTWL_ID, 3, INSTR(T2.OUTWL_ID, ',', 1, 1) - 3)) SPEC_NAME,
       SUBSTR(T2.OUTWL_ID, INSTR(T2.OUTWL_ID, ',', 1, 1) + 1) GRADECODE,
       (SELECT F1.GRADENAME
          FROM COM_BASE_GRADE F1
         WHERE F1.GRADECODE =
               SUBSTR(T2.OUTWL_ID, INSTR(T2.OUTWL_ID, ',', 1, 1) + 1)) GRADENAME,
       T.TARGET,
       S.PIPE_LENGTH AS ACT_LEN,
       DECODE(T2.GO_TYPE,'A','成品','B','半成品','C','镦拔扩及热处理')GO_TYPE,
       '判废' ASTATUS
  FROM MIL_PLAN T,
       (SELECT COUNT(1) QUALIFIED_BRANCH,
               T1.JUDGE_STOVE_NO,
               T1.FLAG,
               T1.HANDLE_RESULT,
               T1.LOT_NO,
               T1.PIPE_LENGTH
          FROM MIL_SLAB_SCRAP T1 WHERE T.FLAG = '1' AND T.HANDLE_RESULT = '500201'
         GROUP BY T1.JUDGE_STOVE_NO, T1.FLAG, T1.HANDLE_RESULT, T1.LOT_NO,T1.PIPE_LENGTH) S,
       PLN_ORDER_ZG T2
 WHERE T.JUDGE_STOVE_NO = S.JUDGE_STOVE_NO
   AND T.LOT_NO = S.LOT_NO
   AND T.CONTRACT_NO = T2.ORDER_NO || '/' || T2.ORDER_SEQ
   AND T.JUDGE_STOVE_NO = ?
   AND T.LOT_NO = ?
   AND T.PLINE_CODE = ?
UNION ALL
SELECT S.QUALIFIED_BRANCH AS ACT_COUNT,
       (T.DB_NUM / T.SAW_NUM * S.QUALIFIED_BRANCH) ACT_WEIGHT,
       
       T.CONTRACT_NO,
       T.IMP_PROCESS,
       T.PRODUCE_STANDRAD,
       T2.PLINE_CODE,
       T.JUDGE_STOVE_NO,
       T.LOT_NO,
       T2.PLINE_NAME,
       T2.LENGTHMAX,
       T2.LENGTHMIN,
       T2.OUTDIAMETER DIMATER,
       T2.WALLTHICK HEIGHT,
       SUBSTR(T2.OUTWL_ID, 3, INSTR(T2.OUTWL_ID, ',', 1, 1) - 3) SPEC_CODE,
       (SELECT F.SPEC_NAME
          FROM COM_BASE_SPEC F
         WHERE F.SPEC_CODE =
               SUBSTR(T2.OUTWL_ID, 3, INSTR(T2.OUTWL_ID, ',', 1, 1) - 3)) SPEC_NAME,
       SUBSTR(T2.OUTWL_ID, INSTR(T2.OUTWL_ID, ',', 1, 1) + 1) GRADECODE,
       (SELECT F1.GRADENAME
          FROM COM_BASE_GRADE F1
         WHERE F1.GRADECODE =
               SUBSTR(T2.OUTWL_ID, INSTR(T2.OUTWL_ID, ',', 1, 1) + 1)) GRADENAME,
       T.TARGET,
       S.PIPE_LENGTH AS ACT_LEN,
       DECODE(T2.GO_TYPE,'A','成品','B','半成品','C','镦拔扩及热处理')GO_TYPE,
       '样管' ASTATUS
  FROM MIL_PLAN T,
       (SELECT DISTINCT COUNT(1) QUALIFIED_BRANCH,
                        T1.JUDGE_STOVE_NO,
                        T1.LOT_NO,
                        T1.PIPE_LENGTH
          FROM PORT_MIL_GET_SAMPLE_RESULT T1
         GROUP BY T1.JUDGE_STOVE_NO, T1.LOT_NO,T1.PIPE_LENGTH) S,
       PLN_ORDER_ZG T2
 WHERE T.JUDGE_STOVE_NO = S.JUDGE_STOVE_NO
   AND T.LOT_NO = S.LOT_NO
   AND T.CONTRACT_NO = T2.ORDER_NO || '/' || T2.ORDER_SEQ
   AND T.JUDGE_STOVE_NO = ?
   AND T.LOT_NO = ?
   AND T.PLINE_CODE = ?
UNION ALL(SELECT S.QUALIFIED_BRANCH AS ACT_COUNT,
                  (T.DB_NUM / T.SAW_NUM * S.QUALIFIED_BRANCH) ACT_WEIGHT,
                  
                  T.CONTRACT_NO,
                  T.IMP_PROCESS,
                  T.PRODUCE_STANDRAD,
                  T2.PLINE_CODE,
                  T.JUDGE_STOVE_NO,
                  T.LOT_NO,
                  T2.PLINE_NAME,
                  T2.LENGTHMAX,
                  T2.LENGTHMIN,
                  T2.OUTDIAMETER DIMATER,
                  T2.WALLTHICK HEIGHT,
                  SUBSTR(T2.OUTWL_ID, 3, INSTR(T2.OUTWL_ID, ',', 1, 1) - 3) SPEC_CODE,
                  (SELECT F.SPEC_NAME
                     FROM COM_BASE_SPEC F
                    WHERE F.SPEC_CODE =
                          SUBSTR(T2.OUTWL_ID,
                                 3,
                                 INSTR(T2.OUTWL_ID, ',', 1, 1) - 3)) SPEC_NAME,
                  SUBSTR(T2.OUTWL_ID, INSTR(T2.OUTWL_ID, ',', 1, 1) + 1) GRADECODE,
                  (SELECT F1.GRADENAME
                     FROM COM_BASE_GRADE F1
                    WHERE F1.GRADECODE =
                          SUBSTR(T2.OUTWL_ID,
                                 INSTR(T2.OUTWL_ID, ',', 1, 1) + 1)) GRADENAME,
                  T.TARGET,
                  S.PIPE_LENGTH AS ACT_LEN,
                  DECODE(T2.GO_TYPE,'A','成品','B','半成品','C','镦拔扩及热处理')GO_TYPE,
                  '待处理' ASTATUS
             FROM MIL_PLAN T,
                  (SELECT T.JUDGE_STOVE_NO,
                          T.LOT_NO,
                          COUNT(1) AS QUALIFIED_BRANCH,
                          T.PIPE_LENGTH
                     FROM MIL_SLAB_SCRAP T
                    WHERE T.FLAG = '0'
                       OR (T.FLAG = '1' AND T.HANDLE_RESULT <> '500201')
                    GROUP BY T.JUDGE_STOVE_NO, T.LOT_NO,T.PIPE_LENGTH) S,
                  PLN_ORDER_ZG T2
            WHERE T.JUDGE_STOVE_NO = S.JUDGE_STOVE_NO
              AND T.LOT_NO = S.LOT_NO
              AND T.CONTRACT_NO = T2.ORDER_NO || '/' || T2.ORDER_SEQ
              AND T.JUDGE_STOVE_NO = ?
              AND T.LOT_NO = ?
              AND T.PLINE_CODE = ?
           UNION ALL
           SELECT S.QUALIFIED_BRANCH AS ACT_COUNT,
                  (T.DB_NUM / T.SAW_NUM * S.QUALIFIED_BRANCH) ACT_WEIGHT,
                  
                  T.CONTRACT_NO,
                  T.IMP_PROCESS,
                  T.PRODUCE_STANDRAD,
                  T2.PLINE_CODE,
                  T.JUDGE_STOVE_NO,
                  T.LOT_NO,
                  T2.PLINE_NAME,
                  T2.LENGTHMAX,
                  T2.LENGTHMIN,
                  T2.OUTDIAMETER DIMATER,
                  T2.WALLTHICK HEIGHT,
                  SUBSTR(T2.OUTWL_ID, 3, INSTR(T2.OUTWL_ID, ',', 1, 1) - 3) SPEC_CODE,
                  (SELECT F.SPEC_NAME
                     FROM COM_BASE_SPEC F
                    WHERE F.SPEC_CODE =
                          SUBSTR(T2.OUTWL_ID,
                                 3,
                                 INSTR(T2.OUTWL_ID, ',', 1, 1) - 3)) SPEC_NAME,
                  SUBSTR(T2.OUTWL_ID, INSTR(T2.OUTWL_ID, ',', 1, 1) + 1) GRADECODE,
                  (SELECT F1.GRADENAME
                     FROM COM_BASE_GRADE F1
                    WHERE F1.GRADECODE =
                          SUBSTR(T2.OUTWL_ID,
                                 INSTR(T2.OUTWL_ID, ',', 1, 1) + 1)) GRADENAME,
                  T.TARGET,
                  S.PIPE_LENGTH AS ACT_LEN,
                  DECODE(T2.GO_TYPE,'A','成品','B','半成品','C','镦拔扩及热处理')GO_TYPE,
                  '待处理' ASTATUS
             FROM MIL_PLAN T,
                  (SELECT T.JUDGE_STOVE_NO,
                          T.LOT_NO,
                          COUNT(1) QUALIFIED_BRANCH,
                          T.PIPE_LENGTH
                     FROM MIL_QA_RACK T
                    WHERE T.STATUS = '3'
                       OR T.OFFLINE_FLAG = '1'
                    GROUP BY T.JUDGE_STOVE_NO, T.LOT_NO,T.PIPE_LENGTH) S,
                  PLN_ORDER_ZG T2
            WHERE T.JUDGE_STOVE_NO = S.JUDGE_STOVE_NO
              AND T.LOT_NO = S.LOT_NO
              AND T.CONTRACT_NO = T2.ORDER_NO || '/' || T2.ORDER_SEQ
              AND T.JUDGE_STOVE_NO = ?
              AND T.LOT_NO = ?
              AND T.PLINE_CODE = ?)

 -->
 <query id = "FrmInOnlineStore.selectPortBatchMatNo" desc = "查询轧管材料号">
 <![CDATA[
 SELECT MAT_NO FROM (SELECT MAT_NO
  FROM PORT_MIL_BATCH_SAMPLE_RESULT T
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.BATCH_NO = ?
   AND ((TO_NUMBER(T.ORDER_LENGTH) - TO_NUMBER(NVL(T.SAMPLE_PIPE_LEN,0)) / 1000 = ? AND
       NVL(T.RECUT_LENGTH, '0') = NVL('', '0')) OR
       TO_NUMBER(T.RECUT_LENGTH) - TO_NUMBER(NVL(T.SAMPLE_PIPE_LEN,0)) / 1000 = ?)
   --AND (T.ORDER_LENGTH = ? or t.recut_length = ?)
   AND T.IS_SAMPLE_PIPE = ?
   AND T.STATUS = ?
   AND T.INSTORE_FLAG = '0'
 ORDER BY T.MAT_NO DESC)
 WHERE ROWNUM <=?
 ]]>
 </query>
<query id = "FrmInOnlineStore.selectPortBatchMatNo1" desc = "查询轧管材料号">
 <![CDATA[
 SELECT MAT_NO FROM (SELECT MAT_NO
  FROM PORT_MIL_BATCH_SAMPLE_RESULT T
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.BATCH_NO = ?
   AND ((TO_NUMBER(T.ORDER_LENGTH) = ? AND
       NVL(T.RECUT_LENGTH, '0') = NVL('', '0')) OR
       TO_NUMBER(T.RECUT_LENGTH) = ?)
   --AND (T.ORDER_LENGTH = ? or t.recut_length = ?)
   AND T.IS_SAMPLE_PIPE = ?
   AND T.STATUS = ?
   AND T.INSTORE_FLAG = '0'
 ORDER BY T.MAT_NO DESC)
 WHERE ROWNUM <=?
 ]]>
 </query>
 <query id = "FrmInOnlineStore.doPipeButress" desc = "交库插入位置表">
 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,
   PLINE_CODE)
VALUES
  (?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
   ?,
   ?,
   ?,
   ?,
   ?)
 </query>
 <query id = "FrmInOnlineStore.doPipeInList" 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
  (?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   round(?, 3),
   round(?, 3),
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   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 = "FrmInOnlineStore.doPipeInListB" desc = "交库插入入库表(所属权)">
 INSERT INTO YDM_BC_INLIST_B
      (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)
    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 = "FrmInOnlineStore.doPipeMat" desc = "交库插入材料表">
 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,
   
   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,
   PRO_ORDER_ID,
   ZG_MAT_NO,
   MAT_GOWHERE_CODE,
   MAT_GOWHERE_NAME,
   TARGET,
   PROCESS_STATUS,
   PROCESS_CDOE,
   PROCESS_DESC,
   LOT_NO,
   FIXTYPE_CODE,
   FLAG_STOVE_NO_ZG,
   CRAF_NO,
   PACK_FLAG,
   MAT_RETURN_FLAG,
   CHEM_RESULT_CODE,
   PHY_RESULT_CODE,
   TESTING_TYPE1,
   TESTING_GRADE1,
   --ZG_PLINE_CODE,
   --ZG_PLINE_NAME,
   GX_PLAN_NO,
   STOVE_NO,
   --NEXT_PROCESS_CDOE,
   --NEXT_PROCESS_DESC,
   --PRO_PLAN_ID_NEXT,
   --GX_PLAN_NO_NEXT,
   JUDGE_STD_DES,
   CUT_NUM,
   ACT_THEORY_WEIGHT,
   INPUT_MATERIAL_NO,
   INPUT_MATERIAL_NAME,
   CRAFT_SEQ,
   CIC,
   HEAT_PLAN_NO_OLD,
   IS_DEALER,
   PONDER_GROSS_WT,
   MEMO)
VALUES
  (?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   round(?, 3),
   TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
   TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
   ?,
   ?,
   ?,
   
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   'D',
   '轧制',
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   --?,
   --?,
   --?,
   --?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   round(?, 3),
   ?)

 </query>
<query id = "FrmInOnlineStore.doPipe" desc = "交库">
<![CDATA[
DECLARE
  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;
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 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)
    VALUES
      (?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       V_TIME,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       V_TIME,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       V_BATHYEAR,
       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,
       PRO_ORDER_ID,
       ZG_MAT_NO,
       MAT_GOWHERE_CODE,
       MAT_GOWHERE_NAME,
       TARGET,
       PROCESS_STATUS,
       PROCESS_CDOE,
       PROCESS_DESC,
       LOT_NO)
    VALUES
      (?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       V_TIME,
       V_TIME,
       ?,
       '',
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       V_BATHYEAR,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       'D',
       '轧制',
       ?);
       UPDATE MIL_PLAN T SET T.STATUS = '99' WHERE T.ID = ?;
       UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T SET T.INSTORE_FLAG = '1',T.GROUP_NO = ? WHERE T.MAT_NO = ?;
END;
]]>
</query>
<query id = "FrmInOnlineStore.updateStaus" desc= "修改状态">
DECLARE
  V_GROUP_NO       PORT_MIL_BATCH_SAMPLE_RESULT.GROUP_NO%type := ?;
  V_MAT_NO         PORT_MIL_BATCH_SAMPLE_RESULT.MAT_NO%type := ?;
  V_JUDGE_STOVE_NO PORT_MIL_BATCH_SAMPLE_RESULT.JUDGE_STOVE_NO%type := ?;
BEGIN

  FOR MYROW IN (SELECT *
                  FROM PORT_MIL_BATCH_SAMPLE_RESULT T
                 WHERE T.MAT_NO = V_MAT_NO
                   AND T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO) LOOP
    UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T
       SET /*T.INSTORE_FLAG = '1',*/ T.GROUP_NO = V_GROUP_NO
     WHERE T.MAT_NO = V_MAT_NO
       AND T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO;
  
    UPDATE MAT_BC_M T1
       SET T1.ZG_MAT_NO       = V_MAT_NO
     WHERE T1.ZG_STOVE_SQE = V_JUDGE_STOVE_NO
       AND T1.ZG_MAT_NO IS NULL
       AND T1.QCM_STAUS = '00'
       AND T1.PROCESS_CDOE = 'D'
       AND ROWNUM = 1;
  END LOOP;
END;
</query>
<query id = "FrmInOnlineStore.updatePlanStaus" desc = "修改计划状态">
UPDATE MIL_PLAN T SET T.STATUS = '99' WHERE T.ID = ?
</query>
<query id = "FrmInOnlineStore.cancelPipeIn" desc = "撤销交库">
<![CDATA[
DECLARE
BEGIN
  FOR MYROW IN (SELECT * FROM (SELECT MAT_NO
                  FROM MAT_BC_M T
                 WHERE T.JUDGE_STOVE_NO = ?
                   AND T.BATCH_NO = ?
                   AND T.BATCH_GROUD_NO = ?
                   AND T.ACT_LEN = ?
                   ORDER BY T.MAT_NO DESC)WHERE ROWNUM <= ?) LOOP
                  FOR MYROW1 IN (SELECT T.ZG_MAT_NO FROM MAT_BC_M T WHERE T.MAT_NO = MYROW.MAT_NO)LOOP
                  DELETE FROM MAT_BC_M T WHERE T.MAT_NO = MYROW.MAT_NO;
                  DELETE FROM YDM_BC_BUTTRESS T WHERE T.MAT_NO = MYROW.MAT_NO;
                  --UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T SET T.INSTORE_FLAG = '0',T.GROUP_NO = '' WHERE T.MAT_NO = MYROW1.ZG_MAT_NO;
                  END LOOP;
  END LOOP;
  DELETE FROM YDM_BC_INLIST T
   WHERE T.INSTOCK_DOC = ?
     AND T.JUDGE_STOVE_NO = ?
     AND T.BATCH_NO = ?
     AND T.BATCH_GROUD_NO = ?;
END;
]]>
</query>
<query id = "FrmInOnlineStore.cancelPipeIn1" desc = "撤销交库">
<![CDATA[
DECLARE
  V_ZG_STOVE_SQE   MAT_BC_M.ZG_STOVE_SQE%type := ?;
  V_BATCH_NO       MAT_BC_M.BATCH_NO%type := ?;
  V_BATCH_GROUD_NO MAT_BC_M.BATCH_GROUD_NO%type := ?;
  V_PLINE_CODE     MAT_BC_M.PLINE_CODE%type := ?;
  V_JUDGE_STOVE_NO MAT_BC_M.JUDGE_STOVE_NO%type := ?;
  V_ACT_LEN        MAT_BC_M.ACT_LEN%type := ?;
  V_QCM_STAUS      MAT_BC_M.QCM_STAUS%type := ?;
  V_SAMPLE_FLAG    MAT_BC_M.SAMPLE_FLAG%type := ?;
  V_ACT_COUNT      MAT_BC_M.ACT_COUNT%type := ?;

  V_INSTOCK_DOC YDM_BC_INLIST.INSTOCK_DOC%type := ?;

  V_STORAGE_NO YDM_BC_BUTTRESS.STORAGE_NO%type := NULL;
BEGIN
  SELECT C.OUT_REPOSITORY
    INTO V_STORAGE_NO
    FROM COM_BASE_PLINE C
   WHERE C.PLINE_CODE = V_PLINE_CODE;

  FOR MYROW IN (SELECT *
                  FROM (SELECT T.MAT_NO,
                               T.ZG_STOVE_SQE,
                               T.BATCH_NO,
                               T.BATCH_GROUD_NO,
                               T.QCM_STAUS,
                               T.SAMPLE_FLAG,
                               T.ZG_MAT_NO
                          FROM MAT_BC_M        T,
                               YDM_BC_INLIST   S,
                               YDM_BC_BUTTRESS T1
                         WHERE T.MAT_NO = S.MAT_NO
                           AND T.MAT_NO = T1.MAT_NO
                           AND S.ZG_STOVE_SQE = V_ZG_STOVE_SQE
                           AND T.BATCH_NO = V_BATCH_NO
                           AND T.BATCH_GROUD_NO = V_BATCH_GROUD_NO
                           --AND TO_NUMBER(T.ACT_LEN) = to_number(V_ACT_LEN)
                              --AND T.OUTSTOCK_DOC IS NULL
                           AND T.QCM_STAUS = V_QCM_STAUS
                           AND S.INSTOCK_DOC = V_INSTOCK_DOC
                           AND T.SAMPLE_FLAG = V_SAMPLE_FLAG
                           AND (T1.STORAGE_NO = V_STORAGE_NO OR
                               T1.STORAGE_NO IN ('BZJ1', 'BZJ2','BZJ3'))
                         ORDER BY T.MAT_NO ASC)
                 WHERE ROWNUM <= V_ACT_COUNT) LOOP
    DELETE FROM MAT_BC_M T WHERE T.MAT_NO = MYROW.MAT_NO;
    DELETE FROM YDM_BC_BUTTRESS T WHERE T.MAT_NO = MYROW.MAT_NO;
  
    DELETE FROM YDM_BC_INLIST T
     WHERE T.INSTOCK_DOC = V_INSTOCK_DOC
       AND T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
       AND T.BATCH_NO = V_BATCH_NO
       AND T.BATCH_GROUD_NO = V_BATCH_GROUD_NO
       AND T.QCM_STAUS = V_QCM_STAUS
       AND T.MAT_NO = MYROW.MAT_NO;
  
    UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T
       SET T.INSTORE_FLAG = '0'
     WHERE T.JUDGE_STOVE_NO = V_ZG_STOVE_SQE
       AND T.BATCH_NO = V_BATCH_NO
       AND T.MAT_NO = MYROW.ZG_MAT_NO;
  END LOOP;
END;

]]>
</query>
<query id = "FrmInOnlineStore.doPipe1" desc = "插入（成品下的废品）">
<![CDATA[
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;
BEGIN
  --生成入库单号
  SELECT LPAD(NVL(MAX(SUBSTR(T.BATCH_GROUD_NO, 3)), 0) + 1, 3, 0)
    INTO V_BATCH_GROUD_NO
    FROM MAT_BC_M T
   WHERE T.JUDGE_STOVE_NO = ?
     AND T.BATCH_NO = ?;
  SELECT MEMO, BASENAME
    INTO V_IMEMO, V_BASENAME
    FROM COM_BASE_INFO
   WHERE BASECODE = ?;
  SELECT 'ZG' || ? || V_IMEMO || TO_CHAR(SYSDATE, 'YYMMDD') ||
         LPAD(NVL(MAX(SUBSTR(T.INSTOCK_DOC, 15)), 0) + 1, 5, 0) INSTOCK_DOC
    INTO V_INSTOCK_DOC
    FROM YDM_BC_INLIST T
   WHERE T.INSTOCK_TYPE_CODE = ?
     AND T.PLINE_CODE = ?
     AND TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD') =
         TO_CHAR(SYSDATE, 'YYYY-MM-DD');
  FOR MYROW IN (SELECT S.OFFLINE_NUM,
                       TO_CHAR(0.02466 * T3.Height*(T3.Dimater-t3.height)*S.Pipe_Length,'FM999990.000') ZP_HEIGHT,
                       S.MAT_NO,
                       T3.MATERIAL_NO,
                       T3.MATERIAL_DESC,
                       T3.PRODUCCODE,
                       T3.PRODUCNAME,
                       T3.STEELCODE,
                       T3.STEELNAME,
                       T3.STD_STYLE,
                       T3.STD_STYLE_DESC,
                       T3.SPEC_CODE,
                       T3.SPEC_NAME,
                       T3.MODEL_CODE,
                       T3.MODEL_DESC,
                       T3.DIMATER,
                       T3.HEIGHT,
                       T3.GRADECODE,
                       T3.GRADENAME,
                       T.CONTRACT_NO,
                       T.IMP_PROCESS,
                       T.PRODUCE_STANDRAD,
                       T3.PLINE_CODE,
                       T3.PLINE_NAME,
                       T.JUDGE_STOVE_NO,
                       T.LOT_NO,
                       T3.LENGTHMAX,
                       T3.LENGTHMIN,
                       T3.ORDER_NO,
                       T3.ORDER_SEQ,
                       T3.ORD_LN_DLY_PK,
                       T3.DELIVERY_NO
                  FROM MIL_PLAN T,
                       MIL_SLAB_SCRAP S,
                       (SELECT T2.PLINE_CODE,
                               T2.PLINE_NAME,
                               T2.LENGTHMAX,
                               T2.LENGTHMIN,
                               T4.MATERIAL_NO,
                               T4.MATERIAL_DESC,
                               T4.PRODUCCODE,
                       T4.PRODUCNAME,
                       T4.STEELCODE,
                       T4.STEELNAME,
                       T4.STD_STYLE,
                       T4.STD_STYLE_DESC,
                       T4.SPEC_CODE,
                       T4.SPEC_NAME,
                       T4.MODEL_CODE,
                       T4.MODEL_DESC,
                       T4.DIMATER,
                       T4.HEIGHT,
                       T4.GRADECODE,
                       T4.GRADENAME,
                       T2.ORDER_NO,
                       T2.ORDER_SEQ,
                       T2.DELIVERY_NO,
                       T2.ORD_LN_DLY_PK,
                       T2.ORDER_NO || '/' || T2.ORDER_SEQ AS CONTRACT_NO
                        FROM 
                               PLN_ORDER_ZG T2,
                               SLM_BASE_MATERIAL T4
                         WHERE T2.OUTWL_ID = T4.MATERIAL_NO) T3
                 WHERE T.JUDGE_STOVE_NO = S.JUDGE_STOVE_NO
                   AND T.LOT_NO = S.LOT_NO
                   AND T.CONTRACT_NO = T3.CONTRACT_NO
                   AND S.FLAG = '1'
                   AND S.HANDLE_RESULT = '500201'
                   AND T.JUDGE_STOVE_NO = ?
                   AND T.LOT_NO = ?
                   AND T.PLINE_CODE = ?) LOOP
    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
      (MYROW.JUDGE_STOVE_NO,
       MYROW.LOT_NO,
       V_BATCH_GROUD_NO,
       ?,
       ?,
       ?,
       ?,
       ?,
       MYROW.MAT_NO,
       V_TIME,
       ?,
       ?,
       ?,
       ?);
    V_INSTOCK_SQE := V_INSTOCK_DOC || LPAD(V_ICOUNT, 4, 0);
    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)
    VALUES
      (?,
       ?,
       V_INSTOCK_SQE,
       V_INSTOCK_DOC,
       ?,
       ?,
       MYROW.MAT_NO,
       MYROW.LOT_NO,
       '',
       MYROW.JUDGE_STOVE_NO,
       MYROW.LOT_NO,
       V_BATCH_GROUD_NO,
       MYROW.PRODUCCODE,
       MYROW.PRODUCNAME,
       '',
       '',
       MYROW.STEELCODE,
       MYROW.STEELNAME,
       MYROW.STD_STYLE,
       MYROW.STD_STYLE_DESC,
       MYROW.SPEC_CODE,
       MYROW.SPEC_NAME,
       MYROW.MODEL_CODE,
       MYROW.MODEL_DESC,
       MYROW.DIMATER,
       MYROW.HEIGHT,
       MYROW.LENGTHMIN,
       MYROW.LENGTHMAX,
       MYROW.OFFLINE_NUM,
       MYROW.ZP_HEIGHT,
       '',
       ?,
       ?,
       ?,
       '',
       '1',
       ?,
       V_TIME,
       '',
       '',
       '',
       '',
       '',
       '',
       ?,
       ?,
       V_TIME,
       '',
       '',
       ?,
       ?,
       ?,
       MYROW.PLINE_CODE,
       MYROW.PLINE_NAME,
       MYROW.GRADECODE,
       MYROW.GRADENAME,
       V_BATHYEAR,
       V_TIME,
       '',
       '801302',
       '机组',
       MYROW.PLINE_CODE,
       MYROW.PLINE_NAME,
       MYROW.MATERIAL_NO,
       MYROW.MATERIAL_DESC,
       MYROW.CONTRACT_NO);
    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)
    VALUES
      (MYROW.JUDGE_STOVE_NO,
       MYROW.LOT_NO,
       V_BATCH_GROUD_NO,
       MYROW.PRODUCCODE,
       MYROW.PRODUCNAME,
       MYROW.STEELCODE,
       MYROW.STEELNAME,
       MYROW.SPEC_CODE,
       MYROW.SPEC_NAME,
       MYROW.MODEL_CODE,
       MYROW.MODEL_DESC,
       '',
       '',
       ?,
       ?,
       MYROW.STD_STYLE,
       MYROW.STD_STYLE_DESC,
       '',
       '',
       '',
       '',
       '',
       '',
       MYROW.DIMATER,
       MYROW.HEIGHT,
       '',
       '',
       '',
       MYROW.LENGTHMIN,
       MYROW.LENGTHMAX,
       ?,
       MYROW.OFFLINE_NUM,
       MYROW.ZP_HEIGHT,
       V_TIME,
       V_TIME,
       MYROW.MAT_NO,
       '',
       '1',
       '1',
       ?,
       ?,
       '',
       ?,
       V_BATHYEAR,
       MYROW.PLINE_CODE,
       MYROW.PLINE_NAME,
       MYROW.GRADECODE,
       MYROW.GRADENAME,
       '',
       '',
       '',
       '801302',
       '机组',
       MYROW.PLINE_CODE,
       MYROW.PLINE_NAME,
       MYROW.MATERIAL_NO,
       MYROW.MATERIAL_DESC,
       MYROW.GRADECODE,
       MYROW.GRADENAME,
       MYROW.STEELCODE,
       MYROW.STEELNAME,
       MYROW.CONTRACT_NO);
    V_ICOUNT := V_ICOUNT + 1;
  END LOOP;
END;
]]>
</query>
<query id = "FrmInOnlineStore.doPipe2" 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;
BEGIN
  --生成入库单号
  SELECT LPAD(NVL(MAX(SUBSTR(T.BATCH_GROUD_NO, 3)), 0) + 1, 3, 0)
    INTO V_BATCH_GROUD_NO
    FROM MAT_BC_M T
   WHERE T.JUDGE_STOVE_NO = ?
     AND T.BATCH_NO = ?;
  SELECT MEMO, BASENAME
    INTO V_IMEMO, V_BASENAME
    FROM COM_BASE_INFO
   WHERE BASECODE = ?;
  SELECT 'ZG' || ? || V_IMEMO || TO_CHAR(SYSDATE, 'YYMMDD') ||
         LPAD(NVL(MAX(SUBSTR(T.INSTOCK_DOC, 15)), 0) + 1, 5, 0) INSTOCK_DOC
    INTO V_INSTOCK_DOC
    FROM YDM_BC_INLIST T
   WHERE T.INSTOCK_TYPE_CODE = ?
     AND T.PLINE_CODE = ?
     AND TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD') =
         TO_CHAR(SYSDATE, 'YYYY-MM-DD');
  FOR MYROW IN (SELECT SUBSTR(T2.OUTWL_ID,
                              3,
                              INSTR(T2.OUTWL_ID, ',', 1, 1) - 3) SPEC_CODE,
                       (SELECT F.SPEC_NAME
                          FROM COM_BASE_SPEC F
                         WHERE F.SPEC_CODE =
                               SUBSTR(T2.OUTWL_ID,
                                      3,
                                      INSTR(T2.OUTWL_ID, ',', 1, 1) - 3)) SPEC_NAME,
                       SUBSTR(T2.OUTWL_ID, INSTR(T2.OUTWL_ID, ',', 1, 1) + 1) GRADECODE,
                       (SELECT F1.GRADENAME
                          FROM COM_BASE_GRADE F1
                         WHERE F1.GRADECODE =
                               SUBSTR(T2.OUTWL_ID,
                                      INSTR(T2.OUTWL_ID, ',', 1, 1) + 1)) GRADENAME,
                       T2.LENGTHMIN,
                       T2.LENGTHMAX,
                       T2.PLINE_CODE,
                       T2.PLINE_NAME,
                       T1.ROLL_STANDRAD,
                       T2.OUTDIAMETER DIMATER,
                       T2.WALLTHICK HEIGHT,
                       T1.CONTRACT_NO,
                       T2.OUTWL_ID MATERIAL_NO,
                       T2.OUT_MATERIAL_DESC MATERIAL_DESC,
                       T1.MAT_NO,
                       TO_CHAR(0.02466 * T2.WALLTHICK *
                               (T2.OUTDIAMETER - T2.WALLTHICK) *
                               S.PIPE_LENGTH,
                               'FM999990.000') ZP_HEIGHT
                  FROM (SELECT T.CONTRACT_NO,
                               T.JUDGE_STOVE_NO,
                               T.LOT_NO,
                               T.ROLL_STANDRAD,
                               S.PIPE_LENGTH,
                               S.MAT_NO
                          FROM MIL_PLAN T, MIL_QA_RACK S
                         WHERE T.JUDGE_STOVE_NO = S.JUDGE_STOVE_NO
                           AND T.LOT_NO = S.LOT_NO
                           AND T.JUDGE_STOVE_NO = ?
                           AND T.LOT_NO = ?
                           AND T.PLINE_CODE = ?) T1,
                       (SELECT T3.*, T4.OUT_MATERIAL_DESC
                          FROM PLN_ORDER_ZG T3, SLM_ORD_DESIGN_BOM_D T4
                         WHERE T3.BOM = T4.BOM
                           AND T3.OUTWL_ID = T4.OUT_MATERIAL_NO
                           AND T3.INWL_GP = T4.IN_MATERIAL_NO
                           AND T3.ORDER_NO||'/'||T3.ORDER_SEQ = ?) T2
                 WHERE T1.CONTRACT_NO = T2.ORDER_NO || '/' || T2.ORDER_SEQ) LOOP
    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
      (MYROW.JUDGE_STOVE_NO,
       MYROW.LOT_NO,
       V_BATCH_GROUD_NO,
       ?,
       ?,
       ?,
       ?,
       ?,
       MYROW.MAT_NO,
       V_TIME,
       ?,
       ?,
       ?,
       ?);
    V_INSTOCK_SQE := V_INSTOCK_DOC || LPAD(V_ICOUNT, 4, 0);
    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)
    VALUES
      (?,
       ?,
       V_INSTOCK_SQE,
       V_INSTOCK_DOC,
       ?,
       ?,
       MYROW.MAT_NO,
       MYROW.LOT_NO,
       '',
       MYROW.JUDGE_STOVE_NO,
       MYROW.LOT_NO,
       V_BATCH_GROUD_NO,
       '',
       '',
       '',
       '',
       '',
       '',
       '',
       '',
       MYROW.SPEC_CODE,
       MYROW.SPEC_NAME,
       '',
       '',
       MYROW.DIMATER,
       MYROW.HEIGHT,
       MYROW.LENGTHMIN,
       MYROW.LENGTHMAX,
       '1',
       MYROW.ZP_HEIGHT,
       '',
       ?,
       ?,
       ?,
       '',
       '1',
       ?,
       V_TIME,
       '',
       '',
       '',
       '',
       '',
       '',
       ?,
       ?,
       V_TIME,
       '',
       '',
       ?,
       ?,
       ?,
       MYROW.PLINE_CODE,
       MYROW.PLINE_NAME,
       MYROW.GRADECODE,
       MYROW.GRADENAME,
       V_BATHYEAR,
       V_TIME,
       '',
       '801302',
       '机组',
       MYROW.PLINE_CODE,
       MYROW.PLINE_NAME,
       MYROW.MATERIAL_NO,
       MYROW.MATERIAL_DESC,
       MYROW.CONTRACT_NO);
    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)
    VALUES
      (MYROW.JUDGE_STOVE_NO,
       MYROW.LOT_NO,
       V_BATCH_GROUD_NO,
       '',
       '',
       '',
       '',
       MYROW.SPEC_CODE,
       MYROW.SPEC_NAME,
       '',
       '',
       '',
       '',
       ?,
       ?,
       '',
       '',
       '',
       '',
       '',
       '',
       '',
       '',
       MYROW.DIMATER,
       MYROW.HEIGHT,
       '',
       '',
       '',
       MYROW.LENGTHMIN,
       MYROW.LENGTHMAX,
       ?,
       '1',
       MYROW.ZP_HEIGHT,
       V_TIME,
       V_TIME,
       MYROW.MAT_NO,
       '',
       '1',
       '1',
       ?,
       ?,
       '',
       ?,
       V_BATHYEAR,
       MYROW.PLINE_CODE,
       MYROW.PLINE_NAME,
       MYROW.GRADECODE,
       MYROW.GRADENAME,
       '',
       '',
       '',
       '801302',
       '机组',
       MYROW.PLINE_CODE,
       MYROW.PLINE_NAME,
       MYROW.MATERIAL_NO,
       MYROW.MATERIAL_DESC,
       MYROW.GRADECODE,
       MYROW.GRADENAME,
       '',
       '',
       MYROW.CONTRACT_NO);
    V_ICOUNT := V_ICOUNT + 1;
  END LOOP;
END;
</query>
<query id = "FrmInOnlineStore.doPipe3" 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;
BEGIN
  --生成入库单号
  SELECT LPAD(NVL(MAX(SUBSTR(T.BATCH_GROUD_NO, 3)), 0) + 1, 3, 0)
    INTO V_BATCH_GROUD_NO
    FROM MAT_BC_M T
   WHERE T.JUDGE_STOVE_NO = ?
     AND T.BATCH_NO = ?;
  SELECT MEMO, BASENAME
    INTO V_IMEMO, V_BASENAME
    FROM COM_BASE_INFO
   WHERE BASECODE = ?;
  SELECT 'ZG' || ? || V_IMEMO || TO_CHAR(SYSDATE, 'YYMMDD') ||
         LPAD(NVL(MAX(SUBSTR(T.INSTOCK_DOC, 15)), 0) + 1, 5, 0) INSTOCK_DOC
    INTO V_INSTOCK_DOC
    FROM YDM_BC_INLIST T
   WHERE T.INSTOCK_TYPE_CODE = ?
     AND T.PLINE_CODE = ?
     AND TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD') =
         TO_CHAR(SYSDATE, 'YYYY-MM-DD');
  FOR MYROW IN (SELECT SUBSTR(T2.OUTWL_ID,
                              3,
                              INSTR(T2.OUTWL_ID, ',', 1, 1) - 3) SPEC_CODE,
                       (SELECT F.SPEC_NAME
                          FROM COM_BASE_SPEC F
                         WHERE F.SPEC_CODE =
                               SUBSTR(T2.OUTWL_ID,
                                      3,
                                      INSTR(T2.OUTWL_ID, ',', 1, 1) - 3)) SPEC_NAME,
                       SUBSTR(T2.OUTWL_ID, INSTR(T2.OUTWL_ID, ',', 1, 1) + 1) GRADECODE,
                       (SELECT F1.GRADENAME
                          FROM COM_BASE_GRADE F1
                         WHERE F1.GRADECODE =
                               SUBSTR(T2.OUTWL_ID,
                                      INSTR(T2.OUTWL_ID, ',', 1, 1) + 1)) GRADENAME,
                       T2.LENGTHMIN,
                       T2.LENGTHMAX,
                       T2.PLINE_CODE,
                       T2.PLINE_NAME,
                       T1.ROLL_STANDRAD,
                       T2.OUTDIAMETER DIMATER,
                       T2.WALLTHICK HEIGHT,
                       T1.CONTRACT_NO,
                       T2.OUTWL_ID MATERIAL_NO,
                       T2.OUT_MATERIAL_DESC MATERIAL_DESC,
                       T1.MAT_NO,
                       TO_CHAR(0.02466 * T2.WALLTHICK *
                               (T2.OUTDIAMETER - T2.WALLTHICK) *
                               S.PIPE_LENGTH,
                               'FM999990.000') ZP_HEIGHT
                  FROM (SELECT T.CONTRACT_NO,
                               T.JUDGE_STOVE_NO,
                               T.LOT_NO,
                               T.ROLL_STANDRAD,
                               S.PIPE_LENGTH,
                               S.MAT_NO
                          FROM MIL_PLAN T, MIL_SLAB_SCRAP S
                         WHERE T.JUDGE_STOVE_NO = S.JUDGE_STOVE_NO
                           AND T.LOT_NO = S.LOT_NO
                           AND S.FLAG = '1'
                           AND S.HANDLE_RESULT = '500201'
                           AND T.JUDGE_STOVE_NO = ?
                           AND T.LOT_NO = ?
                           AND T.PLINE_CODE = ?) T1,
                       (SELECT T3.*, T4.OUT_MATERIAL_DESC
                          FROM PLN_ORDER_ZG T3, SLM_ORD_DESIGN_BOM_D T4
                         WHERE T3.BOM = T4.BOM
                           AND T3.OUTWL_ID = T4.OUT_MATERIAL_NO
                           AND T3.INWL_GP = T4.IN_MATERIAL_NO
                           AND T3.ORDER_NO||'/'||T3.ORDER_SEQ = ?) T2
                 WHERE T1.CONTRACT_NO = T2.ORDER_NO || '/' || T2.ORDER_SEQ) LOOP
    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
      (MYROW.JUDGE_STOVE_NO,
       MYROW.LOT_NO,
       V_BATCH_GROUD_NO,
       ?,
       ?,
       ?,
       ?,
       ?,
       MYROW.MAT_NO,
       V_TIME,
       ?,
       ?,
       ?,
       ?);
    V_INSTOCK_SQE := V_INSTOCK_DOC || LPAD(V_ICOUNT, 4, 0);
    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)
    VALUES
      (?,
       ?,
       V_INSTOCK_SQE,
       V_INSTOCK_DOC,
       ?,
       ?,
       MYROW.MAT_NO,
       MYROW.LOT_NO,
       '',
       MYROW.JUDGE_STOVE_NO,
       MYROW.LOT_NO,
       V_BATCH_GROUD_NO,
       '',
       '',
       '',
       '',
       '',
       '',
       '',
       '',
       MYROW.SPEC_CODE,
       MYROW.SPEC_NAME,
       '',
       '',
       MYROW.DIMATER,
       MYROW.HEIGHT,
       MYROW.LENGTHMIN,
       MYROW.LENGTHMAX,
       '1',
       MYROW.ZP_HEIGHT,
       '',
       ?,
       ?,
       ?,
       '',
       '1',
       ?,
       V_TIME,
       '',
       '',
       '',
       '',
       '',
       '',
       ?,
       ?,
       V_TIME,
       '',
       '',
       ?,
       ?,
       ?,
       MYROW.PLINE_CODE,
       MYROW.PLINE_NAME,
       MYROW.GRADECODE,
       MYROW.GRADENAME,
       V_BATHYEAR,
       V_TIME,
       '',
       '801302',
       '机组',
       MYROW.PLINE_CODE,
       MYROW.PLINE_NAME,
       MYROW.MATERIAL_NO,
       MYROW.MATERIAL_DESC,
       MYROW.CONTRACT_NO);
    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)
    VALUES
      (MYROW.JUDGE_STOVE_NO,
       MYROW.LOT_NO,
       V_BATCH_GROUD_NO,
       '',
       '',
       '',
       '',
       MYROW.SPEC_CODE,
       MYROW.SPEC_NAME,
       '',
       '',
       '',
       '',
       ?,
       ?,
       '',
       '',
       '',
       '',
       '',
       '',
       '',
       '',
       MYROW.DIMATER,
       MYROW.HEIGHT,
       '',
       '',
       '',
       MYROW.LENGTHMIN,
       MYROW.LENGTHMAX,
       ?,
       '1',
       MYROW.ZP_HEIGHT,
       V_TIME,
       V_TIME,
       MYROW.MAT_NO,
       '',
       '1',
       '1',
       ?,
       ?,
       '',
       ?,
       V_BATHYEAR,
       MYROW.PLINE_CODE,
       MYROW.PLINE_NAME,
       MYROW.GRADECODE,
       MYROW.GRADENAME,
       '',
       '',
       '',
       '801302',
       '机组',
       MYROW.PLINE_CODE,
       MYROW.PLINE_NAME,
       MYROW.MATERIAL_NO,
       MYROW.MATERIAL_DESC,
       MYROW.GRADECODE,
       MYROW.GRADENAME,
       '',
       '',
       MYROW.CONTRACT_NO);
    V_ICOUNT := V_ICOUNT + 1;
  END LOOP;
END;
</query>
<query id = "482046" desc = "查询送判数据">
<![CDATA[
select t.*
  from QCM_ZG_JUGDE_APPLY t
 WHERE 1=1
  ]]>
</query>
<query id = "FrmInOnlineStore.doQueryMat" desc = "查询材料实绩">
<![CDATA[
SELECT T1.JUDGE_STOVE_NO,
       T1.LOT_NO,
       T1.PRODUCCODE,
       T1.PRODUCNAME,
       T1.STEELCODE,
       T1.STEELNAME,
       T1.SPEC_CODE,
       T1.SPEC_NAME,
       T1.MODEL_CODE,
       T1.MODEL_DESC,
       T1.STD_CODE,
       (SELECT SUM(Q.ACT_COUNT)
          FROM QCM_ZG_JUGDE_APPLY Q
         WHERE Q.JUDGE_STOVE_NO = T1.JUDGE_STOVE_NO
           AND Q.PLINE_CODE = T1.PLINE_CODE) SPZ,
       
       (SELECT SUM(M.ACT_COUNT)
          FROM MIL_INSPECTION M
         WHERE M.JUDGE_STOVE_NO = T1.JUDGE_STOVE_NO
           AND M.PLINE_CODE = T1.PLINE_CODE
           AND M.HEAT_PLAN_NO = T1.HEAT_PLAN_NO
           AND M.VALIDFLAG = '1') BJZ,
       (SELECT SUM(M.ACT_COUNT)
          FROM MIL_INSPECTION M
         WHERE M.JUDGE_STOVE_NO = T1.JUDGE_STOVE_NO
           AND M.PLINE_CODE = T1.PLINE_CODE
           AND M.HEAT_PLAN_NO = T1.HEAT_PLAN_NO
           AND M.VALIDFLAG = '1'
           AND M.INSPECTION_FLAG > 1) YJZ,
       (SELECT SUM(M.ACT_COUNT)
          FROM MIL_INSPECTION M
         WHERE M.JUDGE_STOVE_NO = T1.JUDGE_STOVE_NO
           AND M.PLINE_CODE = T1.PLINE_CODE
           AND M.HEAT_PLAN_NO = T1.HEAT_PLAN_NO
           AND M.VALIDFLAG = '1'
           AND M.RECHECK = '1') XCJZ,
       (SELECT SUM(M.ACT_COUNT)
          FROM MIL_INSPECTION M
         WHERE M.JUDGE_STOVE_NO = T1.JUDGE_STOVE_NO
           AND M.PLINE_CODE = T1.PLINE_CODE
           AND M.HEAT_PLAN_NO = T1.HEAT_PLAN_NO
           AND M.VALIDFLAG = '1'
           AND M.RECHECK = '2') YCJZ,
           (SELECT DECODE(MIN(M.INSPECTION_FLAG),
                      '0',
                      '待抽',
                      '1',
                      '待检',
                      '2',
                      '已检',
                      '3',
                      '免检')
          FROM MIL_INSPECTION M
         WHERE M.JUDGE_STOVE_NO = T1.JUDGE_STOVE_NO
           AND M.PLINE_CODE = T1.PLINE_CODE
           AND M.HEAT_PLAN_NO = T1.HEAT_PLAN_NO
           AND M.VALIDFLAG = '1') INSPECTION_FLAG,
       
       (SELECT SUBSTR(L.STD_NAME, 1, 70) ||
               decode(L.USE_DESC, '/', '', '', '', ',' || L.USE_DESC)
          FROM SLM_ORDER_LINE L
         WHERE L.ORD_LN_PK = T1.ORD_LN_PK
           AND L.VALIDFLAG = '1') STD_NAME,
       T1.ACT_DIMATER,
       T1.ACT_HEIGHT,
       T1.BELONG_CODE,
       T1.BELONG_NAME,
       T1.STD_STYLE,
       T1.STD_STYLE_DESC,
       T1.GRADECODE,
       T1.GRADENAME,
       sum(T1.ACT_COUNT) ACT_COUNT,
       to_char(sum(T1.Act_Weight), 'FM999999990.000') Act_Weight,
       to_char(sum(T1.ACT_THEORY_WEIGHT), 'FM999999990.000') ACT_THEORY_WEIGHT,
       sum(nvl(T1.ACT_LEN, 0)) as ACT_LEN,
       sum(NVL(T1.PONDER_GROSS_WT, 0)) PONDER_GROSS_WT,
       SUM(CASE
             WHEN T1.PONDER_GROSS_WT > 0 THEN
              1
             ELSE
              0
           END) PONDER_GROSS_COUNT,
       /*T1.LEN_DESC,
       T1.LEN_UNIT,*/
       to_char(T1.ACT_LEN_MIN, 'FM999990.00') AS ACT_LEN_MIN,
       to_char(T1.ACT_LEN_MAX, 'FM999990.00') AS ACT_LEN_MAX,
       to_char(T1.ACT_LEN_MIN, 'FM999990.00') || '-' ||
       to_char(T1.ACT_LEN_MAX, 'FM999990.00') as LEN,
       T1.MATERIAL_NO,
       T1.MATERIAL_NAME,
       MAX(T1.MEMO) MEMO,
       MAX(T1.PIPMEMO) PIPMEMO,
       T1.JUDGE_STD_NAME,
       T1.PLINE_CODE,
       T1.PLINE_NAME,
       T1.MAT_STATUS,
       (SELECT MAX(E.DETECT_RESULT_PATH)
          FROM QCM_INSPECTION_REPORT E
         WHERE E.JUDGE_STOVE_NO = T1.JUDGE_STOVE_NO
           AND E.LOT_NO = T1.LOT_NO
           AND E.PLINE_CODE = T1.PLINE_CODE) DETECT_RESULT_PATH,
       
       (SELECT MAX(F.FACE_RESULT_PATH)
          FROM QCM_SURFACE_REPORT F
         WHERE F.JUDGE_STOVE_NO = T1.JUDGE_STOVE_NO
           AND F.LOT_NO = T1.LOT_NO
           AND F.PLINE_CODE = T1.PLINE_CODE) FACE_RESULT_PATH,
       T1.PRODUCT_FLAG,
       MAX(T1.CHEM_RESULT_CODE) CHEM_RESULT_CODE,
       T1.TARGET,
       DECODE(T1.PACK_FLAG, '0', '否', '1', '是') PACK_FLAG,
       T1.PRO_ORDER_ID,
       MAX(T1.GX_PLAN_NO) GX_PLAN_NO,
       MAX(Q.MCH_DIMENSIONS_RESULT) MCH_DIMENSIONS_RESULT,
       MAX(Q.MCH_VISUAL_RESULT) MCH_VISUAL_RESULT
  FROM MAT_BC_M T1
  left join (SELECT T.MAT_NO, S.STORAGE_NO, S.STORAGE_NAME, T.LOCATION_NO
               FROM YDM_BC_BUTTRESS T, YDM_BS_STORAGE S
              WHERE T.STORAGE_NO = S.STORAGE_NO) T2
    on T1.MAT_NO = T2.MAT_NO
  LEFT JOIN (SELECT MAX(Q.MCH_DIMENSIONS_RESULT) MCH_DIMENSIONS_RESULT,
                    MAX(Q.MCH_VISUAL_RESULT) MCH_VISUAL_RESULT,
                    JUGDE_APPLY_CODE
               FROM QCM_ZG_JUGDE_APPLY Q
              GROUP BY JUGDE_APPLY_CODE) Q
    ON T1.JUGDE_APPLY_CODE = Q.JUGDE_APPLY_CODE
 where T1.QCM_STAUS = '00'
   AND T1.PROCESS_CDOE = 'D'
   AND T1.OFFLINE_DOC IS NULL
--AND (T1.PRO_ORDER_ID IS NOT NULL OR T1.LOT_NO = '试轧料')
 #someThing#
 GROUP BY T1.JUDGE_STOVE_NO,
          T1.PRODUCCODE,
          T1.PRODUCNAME,
          T1.STEELCODE,
          T1.STEELNAME,
          T1.SPEC_CODE,
          T1.SPEC_NAME,
          T1.MODEL_CODE,
          T1.GRADECODE,
          T1.GRADENAME,
          T1.STD_STYLE,
          T1.STD_STYLE_DESC,
          T1.HEAT_PLAN_NO,
          --T1.PIPMEMO,
          T1.MAT_STATUS,
          T1.MODEL_DESC,
          T1.STD_CODE,
          T1.STD_NAME,
          T1.ACT_DIMATER,
          T1.ACT_HEIGHT,
          T1.BELONG_CODE,
          T1.BELONG_NAME,
          T1.PLINE_CODE,
          T1.PLINE_NAME,
          T1.MATERIAL_NO,
          T1.MATERIAL_NAME,
          T1.ACT_LEN_MIN,
          T1.ACT_LEN_MAX,
          --T1.MEMO,
          T1.PRODUCT_FLAG,
          T1.JUDGE_STD_NAME,
          --T1.CHEM_RESULT_CODE,
          T1.TARGET,
          T1.PACK_FLAG,
          T1.LOT_NO,
          T1.ORD_LN_PK,
          T1.PRO_ORDER_ID

  ]]>
</query>
<query id = "FrmInOnlineStore.doQueryMatWG" desc = "查询外购材料实绩">
<![CDATA[
SELECT T1.JUDGE_STOVE_NO,
       
       T1.PRODUCCODE,
       T1.PRODUCNAME,
       T1.STEELCODE,
       T1.STEELNAME,
       T1.SPEC_CODE,
       T1.SPEC_NAME,
       T1.MODEL_CODE,
       T1.MODEL_DESC,
       T1.STD_CODE,
       T1.STD_NAME,
       T1.ORDER_NO,
       T1.ORDER_SEQ,
       T1.ORDER_SEQ_NO,
       T1.ACT_DIMATER,
       T1.ACT_HEIGHT,
       T1.BELONG_CODE,
       T1.BELONG_NAME,
       --T1.LEN_NO,
       T1.STD_STYLE,
       T1.STD_STYLE_DESC,
       T1.GRADECODE,
       T1.GRADENAME,
       sum(T1.ACT_COUNT)ACT_COUNT,
       to_char(sum(T1.Act_Weight),'FM999999990.000')Act_Weight,
       to_char(sum(T1.ACT_THEORY_WEIGHT),'FM999999990.000')ACT_THEORY_WEIGHT,
       sum(nvl(T1.ACT_LEN,0)) as ACT_LEN,
       sum(NVL(T1.PONDER_GROSS_WT,0))PONDER_GROSS_WT,
       SUM(CASE
             WHEN T1.PONDER_GROSS_WT > 0 THEN
              1
             ELSE
              0
           END) PONDER_GROSS_COUNT,
       --T1.LEN_DESC,
       --T1.LEN_UNIT,
       to_char(T1.ACT_LEN_MIN,'FM999990.00') AS ACT_LEN_MIN,
       to_char(T1.ACT_LEN_MAX,'FM999990.00') AS ACT_LEN_MAX,
       to_char(T1.ACT_LEN_MIN,'FM999990.00')||'-'||to_char(T1.ACT_LEN_MAX,'FM999990.00') as LEN,
       --max(TO_CHAR(T1.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS')) CREATE_TIME,
       --max(to_char(T1.INSTOCK_TIME,'YYYY-MM-DD')) INSTOCK_TIME,
       T1.MATERIAL_NO,
       T1.MATERIAL_NAME,
       T1.MEMO,
       T1.PIPMEMO,
       T1.JUDGE_STD_DES,
       T1.JUDGE_STD_NAME,
       T1.PLINE_CODE,
       T1.PLINE_NAME,
       --T1.OLD_ORDER_NO,
       T1.MAT_STATUS,
       --T2.STORAGE_NO,
       --T2.STORAGE_NAME,
       --T2.LOCATION_NO,
       --T1.OUTSTOCK_DOC,
       T1.PRODUCT_FLAG,
       --T1.Heat_Plan_No,
       T1.CHEM_RESULT_CODE,
       T1.TARGET,
       DECODE(T1.PACK_FLAG,'0','否','1','是')PACK_FLAG
  FROM MAT_BC_M T1
  left join (SELECT T.MAT_NO,S.STORAGE_NO,S.STORAGE_NAME,T.LOCATION_NO FROM YDM_BC_BUTTRESS T,YDM_BS_STORAGE S WHERE T.STORAGE_NO = S.STORAGE_NO)T2
  on T1.MAT_NO = T2.MAT_NO
  where T1.JUDGE_STOVE_NO  || '&' LIKE ('%' || upper(?) || '%')
  AND T1.QCM_STAUS = '00'
  AND T1.OFFLINE_DOC IS NULL
  AND T1.PLINE_CODE IN('C065','C066','C098','C099')
  ]]>
</query>

<query id = "FrmInOnlineStore.doQueryMatPlanNo" desc = "查询炉次计划号详细炉批行信息">
<![CDATA[
SELECT T2.*,
       DECODE(T4.APPLY_FLAG,
              '0',
              '正常送判',
              '1',
              '退判',
              '2',
              '退申请判定') APPLY_FLAG,
       T4.BACK_JUGDE_MEMO
  FROM (SELECT T1.JUDGE_STOVE_NO,
               T1.BATCH_NO,
               T1.LOT_NO,
               T1.BATCH_GROUD_NO,
               T1.PRODUCCODE,
               T1.PRODUCNAME,
               T1.STEELCODE,
               T1.STEELNAME,
               T1.SPEC_CODE,
               T1.SPEC_NAME,
               T1.MODEL_CODE,
               T1.MODEL_DESC,
               T1.STD_CODE,
               (SELECT SUBSTR(L.STD_NAME, 1, 70) ||
                       decode(L.USE_DESC, '/', '', '', '', ',' || L.USE_DESC)
                  FROM SLM_ORDER_LINE L
                 WHERE L.ORD_LN_PK = T1.ORD_LN_PK
                   AND L.VALIDFLAG = '1') STD_NAME,
               T1.ACT_DIMATER,
               T1.ACT_HEIGHT,
               T1.BELONG_CODE,
               T1.BELONG_NAME,
               T1.STD_STYLE,
               T1.STD_STYLE_DESC,
               T1.GRADECODE,
               T1.GRADENAME,
               T1.PRO_ORDER_NO,
               T1.ORDER_NO,
               T1.ORDER_SEQ_NO,
               T1.ORD_LN_PK,
               SUM(T1.ACT_COUNT) ACT_COUNT,
               TO_CHAR(SUM(T1.ACT_WEIGHT), 'FM999999990.000') ACT_WEIGHT,
               TO_CHAR(SUM(T1.ACT_THEORY_WEIGHT), 'FM999999990.000') ACT_THEORY_WEIGHT,
               SUM(NVL(T1.ACT_LEN, 0)) AS ACT_LEN,

               TO_CHAR(T1.ACT_LEN_MIN, 'FM999990.00') AS ACT_LEN_MIN,
               TO_CHAR(T1.ACT_LEN_MAX, 'FM999990.00') AS ACT_LEN_MAX,
               TO_CHAR(T1.ACT_LEN_MIN, 'FM999990.00') || '-' ||
               TO_CHAR(T1.ACT_LEN_MAX, 'FM999990.00') AS LEN,
               MAX(TO_CHAR(T1.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS')) CREATE_TIME,
               MAX(TO_CHAR(T1.INSTOCK_TIME, 'YYYY-MM-DD')) INSTOCK_TIME,
               T1.MATERIAL_NO,
               T1.MATERIAL_NAME,
               MAX(T1.MEMO) MEMO,
               MAX(T1.PIPMEMO) PIPMEMO,
               T1.JUDGE_STD_NAME,
               T1.PLINE_CODE,
               T1.PLINE_NAME,
               T1.MAT_STATUS,
               T1.PRODUCT_FLAG,
               T1.JUGDE_APPLY_CODE,
               T1.HEAT_PLAN_NO,
               DECODE(T1.QCM_STAUS,
                      '00',
                      '合格',
                      '11',
                      '待处理',
                      '22',
                      '判废',
                      '10',
                      '处理合格',
                      '12',
                      '处理判废') QCM_STAUS,
               MAX(T1.DETECT_RESULT_CODE) DETECT_RESULT_CODE,
               MAX(T1.FACE_RESULT_CODE) FACE_RESULT_CODE,
               T1.JUDGE_RESULT_CODE,
               T1.JUDGE_RESULT,
               MAX(T1.SPEC_RESULT_CODE) SPEC_RESULT_CODE,
               MAX(T1.CHEM_RESULT_CODE) CHEM_RESULT_CODE,
               MAX(T1.PHY_RESULT_CODE) PHY_RESULT_CODE,
               T1.PRO_ORDER_ID,
               MAX(T1.GX_PLAN_NO) GX_PLAN_NO,
               T1.ORD_LN_DLY_PK,
               T1.PRO_PLAN_ID_NEXT,
               MAX(T1.GX_PLAN_NO_NEXT) GX_PLAN_NO_NEXT,
               t1.LENGTH_TYPE,
               MAX(T6.ORDER_UNIT) ORDER_UNIT,
       MAX(T6.ORDERWEIGHT) ORDERWEIGHT,
       MAX(T6.PAYDOWN_WT_MAX) PAYDOWN_WT_MAX,
       MAX(T6.ORDER_WT_MAX_SHORT) ORDER_WT_MAX_SHORT,
       MAX(T6.ORDER_WT_MAX_LONG) ORDER_WT_MAX_LONG,
       MAX(T6.ACT_LEN) ACT_LEN1,
       MAX(T6.ACT_WEIGHT) ACT_WEIGHT1,
       MAX(T6.ACT_WEIGHT_L) ACT_WEIGHT_L,
       MAX(T6.ACT_WEIGHT_S) ACT_WEIGHT_S,
       MAX(T6.ACT_LEN2) ACT_LEN2,
       MAX(T6.ACT_WEIGHT2) ACT_WEIGHT2,
       CASE WHEN MAX(T6.RECEIV_NM) IN('天津腾飞钢管有限公司','沈阳腾飞钢铁经销有限公司','天津宝仓物流有限公司','天津市安利金属制造有限公司') OR MAX(T6.SUPPLY_UNIT)> 120501
         THEN '801703'
         WHEN MAX(T6.CUSTOMER_NM) IN('天津腾飞钢管有限公司','沈阳腾飞钢铁经销有限公司','天津宝仓物流有限公司','天津市安利金属制造有限公司') 
         THEN '801703'
         WHEN MAX(T6.STLMT_UNIT_NM) IN('天津腾飞钢管有限公司','沈阳腾飞钢铁经销有限公司','天津宝仓物流有限公司','天津市安利金属制造有限公司') 
         THEN '801703'
         WHEN (select MAX(t9.PORDERSTATUS) from pln_saleord t9 where t9.ord_ln_dly_pk =T1.ord_ln_dly_pk)>=5 
             THEN '801701'
         WHEN MAX(NVL(T6.SHORTEST,0))>0 AND MAX(T1.ACT_LEN_MIN) < MAX(NVL(T6.SHORTEST,0))
             THEN '801701'
               WHEN MAX(NVL(T6.LONGEST,0))>0 AND MAX(T1.ACT_LEN_MAX) > MAX(NVL(T6.LONGEST,0))
             THEN '801701'
           ELSE
             CASE WHEN MAX(T6.ORDER_UNIT) = '吨' THEN
       CASE
         --缴库量上限 < 累计送判吨（按计划入）+ 单支重量
           WHEN  MAX(T6.PAYDOWN_WT_MAX) < MAX(T6.ACT_WEIGHT2) + ROUND(ROUND(SUM(T1.ACT_WEIGHT), 3)/SUM(T1.ACT_COUNT),3）
             THEN '801701'
               WHEN T1.LENGTH_TYPE = '1'  AND  MAX(T6.ORDER_WT_MAX_LONG) <  MAX(T6.ACT_WEIGHT_L) + ROUND(ROUND(SUM(T1.ACT_WEIGHT), 3)/SUM(T1.ACT_COUNT),3）
             THEN '801701'
               WHEN T1.LENGTH_TYPE = '2'  AND  MAX(T6.ORDER_WT_MAX_SHORT) <  MAX(T6.ACT_WEIGHT_S) + ROUND(ROUND(SUM(T1.ACT_WEIGHT), 3)/SUM(T1.ACT_COUNT),3）
             THEN '801701'
               ELSE
                 '801703'
               END
               
                WHEN MAX(T6.ORDER_UNIT) IN( '米' ,'英尺') THEN
                 CASE
         --缴库量上限 < 累计送判吨（按计划入）+ 单支重量
           WHEN  MAX(T6.PAYDOWN_WT_MAX) < MAX(T6.ACT_LEN2) + ROUND(ROUND(SUM(T1.ACT_LEN), 3)/SUM(T1.ACT_COUNT),3）
             THEN '801701'
               WHEN T1.LENGTH_TYPE = '1'  AND  MAX(T6.ORDER_WT_MAX_LONG) <  MAX(T6.ACT_LEN_L) + ROUND(ROUND(SUM(T1.ACT_LEN), 3)/SUM(T1.ACT_COUNT),3）
             THEN '801701'
               WHEN T1.LENGTH_TYPE = '2'  AND  MAX(T6.ORDER_WT_MAX_SHORT) <  MAX(T6.ACT_LEN_S) + ROUND(ROUND(SUM(T1.ACT_LEN), 3)/SUM(T1.ACT_COUNT),3）
             THEN '801701'
               ELSE
                 '801703'
               END
              END
             END IN_MOLD,
             
             CASE WHEN MAX(T6.RECEIV_NM) IN('天津腾飞钢管有限公司','沈阳腾飞钢铁经销有限公司','天津宝仓物流有限公司','天津市安利金属制造有限公司') OR MAX(T6.SUPPLY_UNIT)> 120501
         THEN SUM(T1.ACT_COUNT)
         WHEN MAX(T6.CUSTOMER_NM) IN('天津腾飞钢管有限公司','沈阳腾飞钢铁经销有限公司','天津宝仓物流有限公司','天津市安利金属制造有限公司') 
         THEN SUM(T1.ACT_COUNT)
         WHEN MAX(T6.STLMT_UNIT_NM) IN('天津腾飞钢管有限公司','沈阳腾飞钢铁经销有限公司','天津宝仓物流有限公司','天津市安利金属制造有限公司') 
         THEN SUM(T1.ACT_COUNT)
           ELSE
             CASE WHEN MAX(T6.ORDER_UNIT) = '吨' THEN
               CASE WHEN T1.LENGTH_TYPE = '0' AND MAX(T6.PAYDOWN_WT_MAX) -  MAX(T6.ACT_WEIGHT2) > 0 THEN
                 FLOOR((MAX(T6.PAYDOWN_WT_MAX) -  MAX(T6.ACT_WEIGHT2))/(ROUND(SUM(T1.ACT_WEIGHT), 3)/SUM(T1.ACT_COUNT)))
                 WHEN T1.LENGTH_TYPE = '1' AND MAX(T6.ORDER_WT_MAX_LONG) -  MAX(T6.ACT_WEIGHT_L)  > 0 THEN
                  FLOOR(LEAST((MAX(T6.ORDER_WT_MAX_LONG) -  MAX(T6.ACT_WEIGHT_L)),(MAX(T6.PAYDOWN_WT_MAX) -  MAX(T6.ACT_WEIGHT2)))/(ROUND(SUM(T1.ACT_WEIGHT), 3)/SUM(T1.ACT_COUNT)))
                 WHEN T1.LENGTH_TYPE = '2' AND MAX(T6.ORDER_WT_MAX_SHORT) -  MAX(T6.ACT_WEIGHT_S)  > 0 THEN
                  FLOOR(LEAST((MAX(T6.ORDER_WT_MAX_SHORT) -  MAX(T6.ACT_WEIGHT_S)),(MAX(T6.PAYDOWN_WT_MAX) -  MAX(T6.ACT_WEIGHT2)))/(ROUND(SUM(T1.ACT_WEIGHT), 3)/SUM(T1.ACT_COUNT)))
                   END
               WHEN MAX(T6.ORDER_UNIT) IN( '米' ,'英尺') THEN
                 CASE WHEN T1.LENGTH_TYPE = '0' AND MAX(T6.PAYDOWN_WT_MAX) -  MAX(T6.ACT_LEN2) > 0 THEN
                 FLOOR((MAX(T6.PAYDOWN_WT_MAX) -  MAX(T6.ACT_LEN2))/(ROUND(SUM(T1.ACT_LEN), 3)/SUM(T1.ACT_COUNT)))
                 WHEN T1.LENGTH_TYPE = '1' AND MAX(T6.ORDER_WT_MAX_LONG) -  MAX(T6.ACT_LEN_L)  > 0 THEN
                  FLOOR(LEAST((MAX(T6.ORDER_WT_MAX_LONG) -  MAX(T6.ACT_LEN_L)),(MAX(T6.PAYDOWN_WT_MAX) -  MAX(T6.ACT_LEN2)))/(ROUND(SUM(T1.ACT_LEN), 3)/SUM(T1.ACT_COUNT)))
                 WHEN T1.LENGTH_TYPE = '2' AND MAX(T6.ORDER_WT_MAX_SHORT) -  MAX(T6.ACT_WEIGHT_S)  > 0 THEN
                  FLOOR(LEAST((MAX(T6.ORDER_WT_MAX_SHORT) -  MAX(T6.ACT_LEN_S)),(MAX(T6.PAYDOWN_WT_MAX) -  MAX(T6.ACT_LEN2)))/(ROUND(SUM(T1.ACT_LEN), 3)/SUM(T1.ACT_COUNT)))
                   END
                   END
                 END KSPZ
          FROM MAT_BC_M T1
          LEFT JOIN QCM_ZC_APPLY T6
    ON SUBSTR(T1.ORD_LN_DLY_PK,1,38) = T6.ORD_LN_DLY_PK
          LEFT JOIN (SELECT T.MAT_NO,
                           S.STORAGE_NO,
                           S.STORAGE_NAME,
                           T.LOCATION_NO
                      FROM YDM_BC_BUTTRESS T, YDM_BS_STORAGE S
                     WHERE T.STORAGE_NO = S.STORAGE_NO) T2
            ON T1.MAT_NO = T2.MAT_NO
         WHERE T1.JUDGE_STOVE_NO = ?
           AND T1.QCM_STAUS = '00'
           AND T1.OFFLINE_DOC IS NULL
              --AND (T1.PRO_ORDER_ID IS NOT NULL OR T1.LOT_NO = '试轧料')
           AND (T1.BELONG_CODE = '002001016003' OR
               T1.BELONG_CODE = '002001017003' OR
               T1.BELONG_CODE = '002001016002' OR
               T1.BELONG_CODE = '002023018001' OR
               T1.BELONG_CODE = '002001018003')
        
         GROUP BY T1.JUDGE_STOVE_NO,
                  T1.BATCH_NO,
                  T1.LOT_NO,
                  T1.BATCH_GROUD_NO,
                  T1.PRODUCCODE,
                  T1.PRODUCNAME,
                  T1.STEELCODE,
                  T1.STEELNAME,
                  T1.SPEC_CODE,
                  T1.SPEC_NAME,
                  T1.MODEL_CODE,
                  T1.GRADECODE,
                  T1.GRADENAME,
                  T1.STD_STYLE,
                  T1.STD_STYLE_DESC,
                  T1.MAT_STATUS,
                  T1.HEAT_PLAN_NO,
                  T1.JUGDE_APPLY_CODE,
                  T1.QCM_STAUS,
                  T1.MODEL_DESC,
                  T1.STD_CODE,
                  T1.STD_NAME,
                  T1.ACT_DIMATER,
                  T1.ACT_HEIGHT,
                  T1.BELONG_CODE,
                  T1.BELONG_NAME,
                  T1.PLINE_CODE,
                  T1.PLINE_NAME,
                  T1.MATERIAL_NO,
                  T1.MATERIAL_NAME,
                  t1.LENGTH_TYPE,
                  T1.JUDGE_RESULT_CODE,
                  T1.JUDGE_RESULT,
                  T1.ACT_LEN_MIN,
                  T1.ACT_LEN_MAX,
                  T1.PRODUCT_FLAG,
                  T1.JUDGE_STD_NAME,
                  T1.PRO_ORDER_ID,
                  T1.ORD_LN_PK,
                  T1.ORD_LN_DLY_PK,
                  T1.PRO_PLAN_ID_NEXT,
                  T1.ORDER_NO,
                  T1.ORDER_SEQ_NO,
                  T1.PRO_ORDER_NO) T2
  LEFT JOIN (SELECT T3.JUGDE_APPLY_CODE, T3.APPLY_FLAG, T3.BACK_JUGDE_MEMO
               FROM QCM_ZG_JUGDE_APPLY T3
              WHERE T3.IS_FLAG = '0'
              GROUP BY T3.JUGDE_APPLY_CODE,
                       T3.APPLY_FLAG,
                       T3.BACK_JUGDE_MEMO) T4
    ON T2.JUGDE_APPLY_CODE = T4.JUGDE_APPLY_CODE
  ]]>
</query>

<query id = "FrmInOnlineStore.doQueryMatPlanNoWG" desc = "查询炉次计划号详细炉批行信息(外购管)">
<![CDATA[
SELECT T2.*,DECODE(T4.APPLY_FLAG,'0','正常送判','1','退判','未送判')APPLY_FLAG,T4.BACK_JUGDE_MEMO 
FROM (
SELECT T1.JUDGE_STOVE_NO,
       T1.BATCH_NO,
       T1.BATCH_GROUD_NO,
       T1.PRODUCCODE,
       T1.PRODUCNAME,
       T1.STEELCODE,
       T1.STEELNAME,
       T1.SPEC_CODE,
       T1.SPEC_NAME,
       T1.MODEL_CODE,
       T1.MODEL_DESC,
       T1.STD_CODE,
       T1.STD_NAME,
       T1.ORDER_NO,
       T1.ORDER_SEQ,
       T1.ORDER_SEQ_NO,
       T1.ACT_DIMATER,
       T1.ACT_HEIGHT,
       T1.BELONG_CODE,
       T1.BELONG_NAME,
       --T1.LEN_NO,
       T1.STD_STYLE,
       T1.STD_STYLE_DESC,
       T1.GRADECODE,
       T1.GRADENAME,
       T1.PRO_ORDER_NO,
       T1.ORD_LN_PK,
       SUM(T1.ACT_COUNT) ACT_COUNT,
       TO_CHAR(SUM(T1.ACT_WEIGHT), 'FM999999990.000') ACT_WEIGHT,
       TO_CHAR(SUM(T1.ACT_THEORY_WEIGHT), 'FM999999990.000') ACT_THEORY_WEIGHT,
       SUM(NVL(T1.ACT_LEN, 0)) AS ACT_LEN,
       --T1.LEN_DESC,
       --T1.LEN_UNIT,
       TO_CHAR(T1.ACT_LEN_MIN, 'FM999990.00') AS ACT_LEN_MIN,
       TO_CHAR(T1.ACT_LEN_MAX, 'FM999990.00') AS ACT_LEN_MAX,
       TO_CHAR(T1.ACT_LEN_MIN, 'FM999990.00') || '-' ||
       TO_CHAR(T1.ACT_LEN_MAX, 'FM999990.00') AS LEN,
       MAX(TO_CHAR(T1.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS')) CREATE_TIME,
       MAX(TO_CHAR(T1.INSTOCK_TIME, 'YYYY-MM-DD')) INSTOCK_TIME,
       T1.MATERIAL_NO,
       T1.MATERIAL_NAME,
       T1.MEMO,
       T1.PIPMEMO,
       T1.JUDGE_STD_DES,
       T1.JUDGE_STD_NAME,
       T1.PLINE_CODE,
       T1.PLINE_NAME,
       --T1.OLD_ORDER_NO,
       T1.MAT_STATUS,
       TO_CHAR(TO_DATE(T1.BAL_YEAR_MONTH, 'YYYY-MM'), 'YYYY-MM') AS BAL_YEAR_MONTH,
       T1.PRODUCT_FLAG,
       T1.JUGDE_APPLY_CODE,
       DECODE(T1.QCM_STAUS,
              '00',
              '合格',
              '11',
              '待处理',
              '22',
              '判废',
              '10',
              '处理合格',
              '12',
              '处理判废') QCM_STAUS,
       T1.DETECT_RESULT_CODE,
       T1.FACE_RESULT_CODE,
       T1.JUDGE_RESULT_CODE,
       T1.JUDGE_RESULT,
       T1.SPEC_RESULT_CODE,
       T1.CHEM_RESULT_CODE,
       T1.PHY_RESULT_CODE
  FROM MAT_BC_M T1
  LEFT JOIN (SELECT T.MAT_NO, S.STORAGE_NO, S.STORAGE_NAME, T.LOCATION_NO
               FROM YDM_BC_BUTTRESS T, YDM_BS_STORAGE S
              WHERE T.STORAGE_NO = S.STORAGE_NO) T2 ON T1.MAT_NO =
                                                       T2.MAT_NO
 WHERE T1.JUDGE_STOVE_NO = ?
   AND T1.QCM_STAUS = '00'
   AND T1.OFFLINE_DOC IS NULL
   AND T1.BELONG_CODE IN( '002001001','002023005')
   AND T1.PLINE_CODE IN('C065','C066','C098','C099')
 GROUP BY T1.JUDGE_STOVE_NO,
          T1.BATCH_NO,
          T1.BATCH_GROUD_NO,
          T1.PRODUCCODE,
          T1.PRODUCNAME,
          T1.STEELCODE,
          T1.STEELNAME,
          T1.SPEC_CODE,
          T1.SPEC_NAME,
          T1.MODEL_CODE,
          T1.GRADECODE,
          T1.GRADENAME,
          T1.STD_STYLE,
          T1.STD_STYLE_DESC,
          T1.PIPMEMO,
          --T1.OLD_ORDER_NO,
          T1.MAT_STATUS,
          T1.JUGDE_APPLY_CODE,
          T1.QCM_STAUS,
          T1.SPEC_RESULT_CODE,
          T1.CHEM_RESULT_CODE,
          T1.PHY_RESULT_CODE,
          T1.MODEL_DESC,
          T1.STD_CODE,
          T1.STD_NAME,
          T1.ORDER_NO,
          T1.ORDER_SEQ,
          T1.ORDER_SEQ_NO,
          T1.ACT_DIMATER,
          T1.ACT_HEIGHT,
          
          T1.BELONG_CODE,
          T1.BELONG_NAME,
          T1.PLINE_CODE,
          T1.PLINE_NAME,
          T1.BAL_YEAR_MONTH,
          T1.MATERIAL_NO,
          T1.MATERIAL_NAME,
          T1.DETECT_RESULT_CODE,
          T1.FACE_RESULT_CODE,
          T1.JUDGE_RESULT_CODE,
          T1.JUDGE_RESULT,
          T1.ACT_LEN_MIN,
          T1.ACT_LEN_MAX,
          T1.MEMO,
          T1.PRODUCT_FLAG,
          T1.JUDGE_STD_DES,
          T1.JUDGE_STD_NAME,
          T1.ORD_LN_PK,
          T1.PRO_ORDER_NO) T2 LEFT JOIN (SELECT T3.JUGDE_APPLY_CODE,T3.APPLY_FLAG,T3.BACK_JUGDE_MEMO FROM QCM_ZG_JUGDE_APPLY T3 GROUP BY T3.JUGDE_APPLY_CODE,T3.APPLY_FLAG,T3.BACK_JUGDE_MEMO)T4
          ON T2.JUGDE_APPLY_CODE = T4.JUGDE_APPLY_CODE
 ORDER BY T2.BAL_YEAR_MONTH DESC
  ]]>
</query>

<query id = "FrmInOnlineStore.insertJugeApply" desc = "插入判定表">
<![CDATA[
DECLARE
  v_COUNT               MAT_BC_M.QUALITY_GROUP_ZG%TYPE := NULL;
  v_ACT_COUNT           MAT_BC_M.ACT_COUNT%TYPE := NULL;
  v_MAT_GOWHERE_CODE    MAT_BC_M.MAT_GOWHERE_CODE%TYPE := NULL;
  v_MAT_GOWHERE_NAME    MAT_BC_M.MAT_GOWHERE_NAME%TYPE := NULL;
  V_JUDGE_STOVE_NO      MAT_BC_M.JUDGE_STOVE_NO%TYPE := ?;
  V_BATCH_NO            MAT_BC_M.BATCH_NO%TYPE := ?;
  V_BATCH_GROUD_NO      MAT_BC_M.BATCH_GROUD_NO%TYPE := ?;
  V_PLINE_CODE          MAT_BC_M.PLINE_CODE%TYPE := ?;
  v_ACT_COUNT6           MAT_BC_M.ACT_COUNT%TYPE := ?;
  V_JUGDE_APPLY_CODE    MAT_BC_M.JUGDE_APPLY_CODE%TYPE := ?;
  V_JUGDE_APPLY_SEQUENO QCM_ZG_JUGDE_APPLY.JUGDE_APPLY_SEQUENO%TYPE := NULL;
  V_SYSDATE             QCM_ZG_JUGDE_APPLY.APPLY_TIME%TYPE := SYSDATE;
  V_PRO_PLAN_ID         MIL_PLAN.PRO_PLAN_ID%TYPE := NULL;
  V_GX_PLAN_NO          MIL_PLAN.GX_PLAN_NO%TYPE := NULL;
  V_SUPPLY_UNIT         QCM_ZG_JUGDE_APPLY.SUPPLY_UNIT%TYPE := '120501';
  V_SUPPLY_UNIT_DESC    QCM_ZG_JUGDE_APPLY.SUPPLY_UNIT_DESC%TYPE := '天津钢管制造有限公司';
  v_ACT_COUNT2          MAT_BC_M.ACT_COUNT%TYPE := NULL;
BEGIN
  SELECT T.MAT_GOWHERE_CODE, T.MAT_GOWHERE_NAME
    INTO v_MAT_GOWHERE_CODE, v_MAT_GOWHERE_NAME
    FROM MAT_BC_M T
   WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
     AND T.BATCH_NO = V_BATCH_NO
     AND T.BATCH_GROUD_NO = V_BATCH_GROUD_NO
     AND T.PROCESS_CDOE = 'D'
     AND ROWNUM = 1;
  --制造商
  --按合同找制造商暂时不用了
  /*SELECT COUNT(*)
    INTO v_ACT_COUNT2
    FROM SLM_ORDER_HEAD S, SLM_ORDER_LINE S1, MAT_BC_M T, COM_BASE_INFO C
   WHERE S.ORD_PK = S1.ORD_PK
     AND S.ORDER_NO || '/' || S1.ORDER_SEQ = T.PRO_ORDER_NO
     AND S.SUPPLY_UNIT = C.BASECODE
     AND T.PROCESS_CDOE = 'D'
     AND T.QCM_STAUS = '00'
     AND T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
     AND T.BATCH_NO = V_BATCH_NO;
 
  IF (v_ACT_COUNT2 > 0) THEN
    SELECT S.SUPPLY_UNIT, C.BASENAME
      INTO V_SUPPLY_UNIT, V_SUPPLY_UNIT_DESC
      FROM SLM_ORDER_HEAD S, SLM_ORDER_LINE S1, MAT_BC_M T, COM_BASE_INFO C
     WHERE S.ORD_PK = S1.ORD_PK
       AND S.ORDER_NO || '/' || S1.ORDER_SEQ = T.PRO_ORDER_NO
       AND S.SUPPLY_UNIT = C.BASECODE
       AND T.PROCESS_CDOE = 'D'
       AND T.QCM_STAUS = '00'
       AND T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
       AND T.BATCH_NO = V_BATCH_NO
       AND ROWNUM = 1;
  END IF;*/
  --按产线区分制造商
  SELECT C.SUPPLY_UNIT_CODE, C.SUPPLY_UNIT
    INTO V_SUPPLY_UNIT, V_SUPPLY_UNIT_DESC
    FROM COM_BASE_PLINE C
   WHERE C.PLINE_CODE = V_PLINE_CODE;
  --生成申请判定顺序号
  SELECT COUNT(1) + 1
    INTO V_JUGDE_APPLY_SEQUENO
    FROM QCM_ZG_JUGDE_APPLY T
   WHERE T.JUGDE_APPLY_CODE = V_JUGDE_APPLY_CODE
     AND T.VALIDFLAG IN ('00', '15', '20')
     AND T.PROCESS_CODE = 'D';
  FOR MYROW IN  (SELECT SUM(T.ACT_COUNT) ACT_COUNT,
       SUM(T.ACT_THEORY_WEIGHT) ACT_THEORY_WEIGHT,
       SUM(NVL(T.PONDER_GROSS_WT, T.ACT_WEIGHT)) ACT_WEIGHT,
       SUM(T.ACT_LEN) ACT_LEN,
       T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       T.BATCH_GROUD_NO,
       MAX(T.FACE_RESULT_CODE) FACE_RESULT_CODE,
       MAX(T.SPEC_RESULT_CODE) SPEC_RESULT_CODE,
       MAX(T.CHEM_RESULT_CODE) CHEM_RESULT_CODE,
       MAX(T.PHY_RESULT_CODE) PHY_RESULT_CODE,
       MAX(T.DETECT_RESULT_CODE) DETECT_RESULT_CODE,
       MAX(T.WPRESSURE_RESULT_CODE) WPRESSURE_RESULT_CODE,
       T.PLINE_CODE,
       MAX(T.PRO_ORDER_ID) PRO_ORDER_ID,
       MAX(T.GX_PLAN_NO) GX_PLAN_NO,
       T.LOT_NO,
       T.PLINE_NAME,
       MAX(T.PRO_ORDER_NO) PRO_ORDER_NO,
       T.TARGET,
       T.PROCESS_STATUS,
       T.ACT_DIMATER,
       T.Act_Height,
       T.ACT_LEN_MIN,
       T.ACT_LEN_MAX,
       MAX(T.CRAF_NO) CRAF_NO,
       T.MATERIAL_NO,
       T.MATERIAL_NAME,
       MAX(T.MEMO) MEMO,
       MAX(T.PIPMEMO) PIPMEMO,
       T.PRODUCCODE,
       T.PRODUCNAME,
       T.SPEC_CODE,
       T.SPEC_NAME,
       T.STEELCODE,
       T.STEELNAME,
       T.MODEL_CODE,
       T.MODEL_DESC,
       T.STD_CODE,
       T.STD_NAME,
       T.STD_STYLE,
       T.STD_STYLE_DESC,
       T.GRADECODE,
       T.GRADENAME,
       T.CRAFT_SEQ,
       T.CIC,
       T.ORD_LN_DLY_PK,
       T.BELONG_CODE,
       T.BELONG_NAME,
       MAX(T.STOVE_NO) STOVE_NO,
       DECODE(MAX(T.judge_std_des),
              '',
              MAX(T.JUDGE_STD_NAME),
              MAX(T.judge_std_des)) STEEL_STANDRAD,
       T.PRO_PLAN_ID_NEXT,
       MAX(T.GX_PLAN_NO_NEXT) GX_PLAN_NO_NEXT,
       T.HEAT_PLAN_NO_NEXT,
       T.HEAT_PLAN_NO,
       T.lock_liku LK_FLAG,
       MAX(T.NEXT_PROCESS_CDOE) NEXT_PROCESS_CDOE,
       MAX(T.ZZB_FLAG) ZZB_FLAG
  FROM (SELECT *
          FROM (SELECT *
                  FROM MAT_BC_M T
                 WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
                   AND T.BATCH_NO = V_BATCH_NO
                   AND T.BATCH_GROUD_NO = V_BATCH_GROUD_NO
                   AND T.PLINE_CODE = V_PLINE_CODE
                   AND T.JUGDE_APPLY_CODE IS NULL
                   AND T.QCM_STAUS = '00'
                   AND T.PROCESS_CDOE = 'D'
                 ORDER BY MAT_NO ASC)
         WHERE ROWNUM <= v_ACT_COUNT6
         ORDER BY MAT_NO ASC) T
 GROUP BY T.JUDGE_STOVE_NO,
          T.BATCH_NO,
          T.BATCH_GROUD_NO,
          T.PLINE_CODE,
          T.LOT_NO,
          T.PLINE_NAME,
          T.TARGET,
          T.PROCESS_STATUS,
          T.ACT_DIMATER,
          T.Act_Height,
          T.ACT_LEN_MIN,
          T.ACT_LEN_MAX,
          T.MATERIAL_NO,
          T.MATERIAL_NAME,
          T.PRODUCCODE,
          T.PRODUCNAME,
          T.SPEC_CODE,
          T.SPEC_NAME,
          T.STEELCODE,
          T.STEELNAME,
          T.MODEL_CODE,
          T.MODEL_DESC,
          T.STD_CODE,
          T.STD_NAME,
          T.STD_STYLE,
          T.STD_STYLE_DESC,
          T.GRADECODE,
          T.GRADENAME,
          T.CRAFT_SEQ,
          T.CIC,
          T.ORD_LN_DLY_PK,
          T.BELONG_CODE,
          T.PRO_PLAN_ID_NEXT,
          --T.GX_PLAN_NO_NEXT,
          T.HEAT_PLAN_NO_NEXT,
          T.HEAT_PLAN_NO,
          T.lock_liku,
          T.BELONG_NAME) LOOP
    INSERT INTO QCM_ZG_JUGDE_APPLY
      (JUGDE_APPLY_CODE,
       JUDGE_STOVE_NO,
       BATCH_NO,
       BATCH_GROUD_NO,
       PROCESS_CODE,
       PLINE_CODE,
       ACT_COUNT,
       ACT_WEIGHT,
       ACT_THEORY_WEIGHT,
       PRO_ORDER_ID,
       FACE_RESULT_CODE,
       SPEC_RESULT_CODE,
       CHEM_RESULT_CODE,
       PHY_RESULT_CODE,
       DETECT_RESULT_CODE,
       WPRESSURE_RESULT_CODE,
       --PROCESS_RESULT_CODE,
       APPLY_NAME,
       APPLY_TIME,
       MEMO,
       QUALITY_GROUP,
       LOT_NO,
       PLINE_NAME,
       PRO_ORDER_NO,
       TARGET,
       PROCESS_STATUS,
       MAT_GOWHERE_CODE,
       MAT_GOWHERE_NAME,
       ACT_DIMATER,
       Act_Height,
       ACT_LEN_MIN,
       ACT_LEN_MAX,
       Craf_No,
       MATERIAL_NO,
       MATERIAL_NAME,
       PRODUCCODE,
       PRODUCNAME,
       SPEC_CODE,
       SPEC_NAME,
       STEELCODE,
       STEELNAME,
       MODEL_CODE,
       MODEL_DESC,
       STD_CODE,
       STD_NAME,
       STD_STYLE,
       STD_STYLE_DESC,
       GRADECODE,
       GRADENAME,
       TESTING_GRADE,
       TESTING_TYPE,
       TESTING_GRADE1,
       TESTING_TYPE1,
       ORD_LN_DLY_PK,
       BELONG_CODE,
       BELONG_NAME,
       EXIT_TEMP,
       SAMPLE_NEWS,
       ACT_LEN,
       GX_PLAN_NO,
       BELONG_CODE_JUGDE,
       BELONG_NAME_JUGDE,
       INPUT_COUNT,
       INPUT_WEIGHT,
       OUTPUT_COUNT,
       OUTPUT_WEIGHT,
       STOVE_NO,
       STEEL_STANDRAD,
       PRO_PLAN_ID_NEXT,
       GX_PLAN_NO_NEXT,
       HEAT_PLAN_NO_NEXT,
       LK_FLAG,
       NEXT_PROCESS_CDOE,
       JUGDE_APPLY_SEQUENO,
       HEAT_PLAN_NO,
       DELIVERY_STATE_CODE,
       DELIVERY_STATE_NAME,
       LOAD_JUDGE_STOVE_NO,
       CHECK_NO,
       ZP_M_LH,
       ZP_COLL,
       CRAFT_SEQ,
       CIC,
       MCH_VISUAL_RESULT,
       MCH_DIMENSIONS_RESULT,
       TESTING_STANDAR,
       NOTCH_INFO,
       NOTCH_LENGTH,
       NOTCH_WIDTH,
       NOTCH_DEPTH,
       FACE_RESULT_PATH,
       DETECT_RESULT_PATH,
       ZZB_FLAG,
       TEST_PRESSURE,
       HOLDTIME_TIME,
       TEST_PRESSURE_Y,
       SUPPLY_UNIT,
       SUPPLY_UNIT_DESC,
       IN_MOLD)
    VALUES
      (V_JUGDE_APPLY_CODE,
       MYROW.JUDGE_STOVE_NO,
       MYROW.BATCH_NO,
       MYROW.BATCH_GROUD_NO,
       'D',
       MYROW.PLINE_CODE,
       MYROW.ACT_COUNT,
       MYROW.ACT_WEIGHT,
       MYROW.ACT_THEORY_WEIGHT,
       MYROW.PRO_ORDER_ID,
       MYROW.FACE_RESULT_CODE,
       MYROW.SPEC_RESULT_CODE,
       MYROW.CHEM_RESULT_CODE,
       MYROW.PHY_RESULT_CODE,
       ?,
       MYROW.WPRESSURE_RESULT_CODE,
       --?,
       ?,
       V_SYSDATE,
       NVL(?, MYROW.PIPMEMO),
       '1',
       MYROW.LOT_NO,
       MYROW.PLINE_NAME,
       MYROW.PRO_ORDER_NO,
       MYROW.TARGET,
       MYROW.PROCESS_STATUS,
       v_MAT_GOWHERE_CODE,
       v_MAT_GOWHERE_NAME,
       MYROW.ACT_DIMATER,
       MYROW.Act_Height,
       MYROW.ACT_LEN_MIN,
       MYROW.ACT_LEN_MAX,
       MYROW.Craf_No,
       MYROW.MATERIAL_NO,
       MYROW.MATERIAL_NAME,
       MYROW.PRODUCCODE,
       MYROW.PRODUCNAME,
       MYROW.SPEC_CODE,
       MYROW.SPEC_NAME,
       MYROW.STEELCODE,
       MYROW.STEELNAME,
       MYROW.MODEL_CODE,
       MYROW.MODEL_DESC,
       MYROW.STD_CODE,
       MYROW.STD_NAME,
       MYROW.STD_STYLE,
       MYROW.STD_STYLE_DESC,
       MYROW.GRADECODE,
       MYROW.GRADENAME,
       ?,
       ?,
       ?,
       ?,
       CASE WHEN INSTR(MYROW.ORD_LN_DLY_PK, '-', 10, 1) > 0 THEN
       SUBSTR(MYROW.ORD_LN_DLY_PK,
              0,
              INSTR(MYROW.ORD_LN_DLY_PK, '-', 10, 1) - 1) ELSE
       MYROW.ORD_LN_DLY_PK END,
       MYROW.BELONG_CODE,
       MYROW.BELONG_NAME,
       ?,
       ?,
       MYROW.ACT_LEN,
       MYROW.GX_PLAN_NO,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       MYROW.STOVE_NO,
       MYROW.STEEL_STANDRAD,
       MYROW.PRO_PLAN_ID_NEXT,
       MYROW.GX_PLAN_NO_NEXT,
       MYROW.HEAT_PLAN_NO_NEXT,
       MYROW.LK_FLAG,
       MYROW.NEXT_PROCESS_CDOE,
       V_JUGDE_APPLY_SEQUENO,
       MYROW.HEAT_PLAN_NO,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       MYROW.CRAFT_SEQ,
       MYROW.CIC,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       (SELECT MAX(R.FACE_RESULT_PATH)
          FROM QCM_SURFACE_REPORT R
         WHERE R.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
           AND R.PLINE_CODE = V_PLINE_CODE),
       (SELECT MAX(R.DETECT_RESULT_PATH)
          FROM QCM_INSPECTION_REPORT R
         WHERE R.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
           AND R.PLINE_CODE = V_PLINE_CODE),
       MYROW.ZZB_FLAG,
       ?,
       ?,
       ?,
       V_SUPPLY_UNIT,
       V_SUPPLY_UNIT_DESC,
       ?);
 
    V_PRO_PLAN_ID := MYROW.PRO_ORDER_ID;
    V_GX_PLAN_NO  := MYROW.GX_PLAN_NO;
 
    FOR MYROW1 IN (SELECT *
                     FROM (SELECT T.MAT_NO,
                                  T.PROCESS_CDOE,
                                  T.STOVE_NO,
                                  T.JUDGE_STOVE_NO,
                                  T.BATCH_NO,
                                  T.GRADECODE,
                                  T.GRADENAME,
                                  T.MATERIAL_NO,
                                  T.MATERIAL_NAME
                             FROM MAT_BC_M T
                            WHERE T.JUDGE_STOVE_NO = MYROW.JUDGE_STOVE_NO
                              AND T.BATCH_NO = MYROW.BATCH_NO
                              AND T.BATCH_GROUD_NO = MYROW.BATCH_GROUD_NO
                              AND T.JUGDE_APPLY_CODE IS NULL
                              AND NVL(T.HEAT_PLAN_NO_NEXT, '/') =
                                  NVL(MYROW.HEAT_PLAN_NO_NEXT, '/')
                              AND NVL(T.FACE_RESULT_CODE, '/') =
                                  NVL(MYROW.FACE_RESULT_CODE, '/')
                              AND NVL(T.DETECT_RESULT_CODE, '/') =
                                  NVL(MYROW.DETECT_RESULT_CODE, '/')
                              AND NVL(T.SPEC_RESULT_CODE, '/') =
                                  NVL(MYROW.SPEC_RESULT_CODE, '/')
                              AND NVL(T.CHEM_RESULT_CODE, '/') =
                                  NVL(MYROW.CHEM_RESULT_CODE, '/')
                              AND NVL(T.PHY_RESULT_CODE, '/') =
                                  NVL(MYROW.PHY_RESULT_CODE, '/')
                              AND NVL(T.WPRESSURE_RESULT_CODE, '/') =
                                  NVL(MYROW.WPRESSURE_RESULT_CODE, '/')
                              AND T.BELONG_CODE NOT IN
                                  ('100101', '100102', '100103')
                              AND T.QCM_STAUS = '00'
                              AND T.PROCESS_CDOE = 'D'
                            ORDER BY T.MAT_NO ASC)
                    WHERE ROWNUM <= MYROW.ACT_COUNT) LOOP
      UPDATE MAT_BC_M T
         SET /*T.QUALITY_GROUP_ZG = v_COUNT,*/       T.TESTING_GRADE = ?,
             T.TESTING_TYPE        = ?,
             T.TESTING_GRADE1      = ?,
             T.TESTING_TYPE1       = ?,
             T.JUGDE_APPLY_SEQUENO = V_JUGDE_APPLY_SEQUENO,
             T.JUGDE_APPLY_CODE    = V_JUGDE_APPLY_CODE,
             T.JUGDE_APPLY_TIME    = SYSDATE
       WHERE T.MAT_NO = MYROW1.MAT_NO
         AND T.PROCESS_CDOE = 'D';
   
      select count(1)
        into v_ACT_COUNT
        from MAT_BC_QCMTRACK
       where mat_no = MYROW1.MAT_NO
         and PROCESS_CDOE = MYROW1.PROCESS_CDOE;
      if (v_ACT_COUNT = 0) then
     
        INSERT INTO MAT_BC_QCMTRACK
          (MAT_NO,
           PROCESS_CDOE,
           STOVE_NO,
           JUDGE_STOVE_NO,
           BATCH_NO,
           GRADECODE,
           GRADENAME,
           MATERIAL_NO,
           MATERIAL_NAME,
           JUGDE_APPLY_CODE,
           JUGDE_APPLY_TIME,
           JUGDE_APPLY_MAKER)
        VALUES
          (MYROW1.MAT_NO,
           MYROW1.PROCESS_CDOE,
           MYROW1.STOVE_NO,
           MYROW1.JUDGE_STOVE_NO,
           MYROW1.BATCH_NO,
           MYROW1.GRADECODE,
           MYROW1.GRADENAME,
           MYROW1.MATERIAL_NO,
           MYROW1.MATERIAL_NAME,
           ?,
           V_SYSDATE,
           ?);
      end if;
   
    END LOOP;
    V_JUGDE_APPLY_SEQUENO := V_JUGDE_APPLY_SEQUENO + 1;
    /*v_COUNT := v_COUNT + 1;*/
 
  END LOOP;
  --判定表加判定要的字段(精整利库,材料表没有字段，取订单表)
  FOR MYROW3 IN (select T.PRO_PLAN_ID,
                        T.GX_PLAN_NO,
                        T.CRAFT_SEQ,
                        T.INDEX_SEQ,
                        T.CIC_GP CIC,
                        T.PIC PIC,
                        T.SIC SIC,
                        T.DIC DIC
                   from PLN_ORDER_ZG_S t
                  WHERE T.PRO_PLAN_ID = V_PRO_PLAN_ID
                    AND T.GX_PLAN_NO = V_GX_PLAN_NO
                  GROUP BY T.PRO_PLAN_ID,
                           T.GX_PLAN_NO,
                           T.CRAFT_SEQ,
                           T.INDEX_SEQ,
                           T.CIC_GP,
                           T.PIC,
                           T.SIC,
                           T.DIC) LOOP
    UPDATE QCM_ZG_JUGDE_APPLY T
       SET T.INDEX_SEQ = NVL(T.INDEX_SEQ,MYROW3.INDEX_SEQ),
           T.CIC       = NVL(T.CIC,MYROW3.CIC),
           T.PIC       = NVL(T.PIC,MYROW3.PIC),
           T.SIC       = NVL(T.SIC,MYROW3.SIC),
           T.DIC       = NVL(T.DIC,MYROW3.DIC)
     WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
       AND T.PLINE_CODE = V_PLINE_CODE
       AND T.JUGDE_APPLY_CODE = V_JUGDE_APPLY_CODE;
  END LOOP;
END;

]]>
</query>
<query id = "FrmInOnlineStore.SelectUTResult" desc = "获取超声探伤等级">
SELECT T.UL_TESTING FROM MIL_ENTRUSTED_BILL T WHERE T.JUDGE_STOVE_NO  LIKE ?||'%' 
</query>

<query id = "FrmInOnlineStore.SelectHttEntrustResult" desc = "获取外委探伤等级和种类">
select t.*
  from HTT_ENTRUST_RESULT t, HTT_ENTRUST T1
 WHERE T.SUBCONTRACT_NO = T1.SUBCONTRACT_NO
   AND T.SUBCONTRACT_NO_SEQ = T1.SUBCONTRACT_NO_SEQ
   AND T.JUDGE_STOVE_NO = ?
   AND T1.PLINE_CODE = ?
</query>

<query id = "FrmInOnlineStore.doQueryMatDataOut" desc = "查询炉次计划号转移炉批行信息">
<![CDATA[
SELECT T1.JUDGE_STOVE_NO,
       T1.BATCH_NO,
       T1.BATCH_GROUD_NO,
       T1.PRODUCCODE,
       T1.PRODUCNAME,
       T1.STEELCODE,
       T1.STEELNAME,
       T1.SPEC_CODE,
       T1.SPEC_NAME,
       T1.MODEL_CODE,
       T1.MODEL_DESC,
       T1.STD_CODE,
       T1.STD_NAME,
       T1.ORDER_NO,
       T1.ORDER_SEQ,
       T1.ORDER_SEQ_NO,
       T1.ACT_DIMATER,
       T1.ACT_HEIGHT,
       T1.BELONG_CODE,
       T1.BELONG_NAME,
       T1.LEN_NO,
       T1.STD_STYLE,
       T1.STD_STYLE_DESC,
       T1.GRADECODE,
       T1.GRADENAME,
       sum(T1.ACT_COUNT)ACT_COUNT,
       to_char(sum(T1.Act_Weight),'FM999999990.000')Act_Weight,
       to_char(sum(T1.ACT_THEORY_WEIGHT),'FM999999990.000')ACT_THEORY_WEIGHT,
       sum(nvl(T1.ACT_LEN,0)) as ACT_LEN,
       T1.LEN_DESC,
       T1.LEN_UNIT,
       to_char(T1.ACT_LEN_MIN,'FM999990.00') AS ACT_LEN_MIN,
       to_char(T1.ACT_LEN_MAX,'FM999990.00') AS ACT_LEN_MAX,
       to_char(T1.ACT_LEN_MIN,'FM999990.00')||'-'||to_char(T1.ACT_LEN_MAX,'FM999990.00') as LEN,
       T1.CREATE_NAME,
       max(TO_CHAR(T1.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS')) CREATE_TIME,
       max(to_char(T1.INSTOCK_TIME,'YYYY-MM-DD')) INSTOCK_TIME,
       T1.MATERIAL_NO,
       T1.MATERIAL_NAME,
       T1.MEMO,
       T1.PIPMEMO,
       T1.JUDGE_STD_CODE,
       T1.JUDGE_STD_NAME,
       T1.PLINE_CODE,
       T1.PLINE_NAME,
       T1.OLD_ORDER_NO,
       T1.MAT_STATUS,
       T2.STORAGE_NO,
       T2.STORAGE_NAME,
       T2.LOCATION_NO,
       T1.OUTSTOCK_DOC,
       to_char(to_date(T1.BAL_YEAR_MONTH,'YYYY-MM'),'yyyy-MM') as BAL_YEAR_MONTH,
       T1.PRODUCT_FLAG,
       T1.JUGDE_APPLY_CODE,
       T1.Heat_Plan_No,
       DECODE(T1.QCM_STAUS,'00','合格','11','待处理','22','判废','10','处理合格','12','处理判废')QCM_STAUS,
       T1.OUTSTOCK_DOC
  FROM MAT_BC_M T1
  left join (SELECT T.MAT_NO,S.STORAGE_NO,S.STORAGE_NAME,T.LOCATION_NO FROM YDM_BC_BUTTRESS T,YDM_BS_STORAGE S WHERE T.STORAGE_NO = S.STORAGE_NO)T2
  on T1.MAT_NO = T2.MAT_NO
  where T1.Heat_Plan_No   = ?
  ]]>
</query>

<query id = "FrmInOnlineStore.doQueryMatButess" desc = "查询库存实绩">
<![CDATA[
 SELECT T1.JUDGE_STOVE_NO,
       T1.BATCH_NO,
       T1.BATCH_GROUD_NO,
       T1.PRODUCCODE,
       T1.PRODUCNAME,
       T1.STEELCODE,
       T1.STEELNAME,
       T1.SPEC_CODE,
       T1.SPEC_NAME,
       T1.MODEL_CODE,
       T1.MODEL_DESC,
       T1.STD_CODE,
       T1.STD_NAME,
       T1.ORDER_NO,
       T1.ORDER_SEQ,
       T1.ORDER_SEQ_NO,
       T1.ACT_DIMATER,
       T1.ACT_HEIGHT,
       T1.BELONG_CODE,
       T1.BELONG_NAME,

       T1.STD_STYLE,
       T1.STD_STYLE_DESC,
       T1.GRADECODE,
       T1.GRADENAME,
       T1.MATERIAL_NO,
       T1.MATERIAL_NAME,
      sum(T1.ACT_COUNT)
            ACT_COUNT,
            to_char(sum(T1.Act_Weight),'FM999999990.000')
           Act_Weight,
           to_char(sum(T1.ACT_THEORY_WEIGHT),'FM999999990.000')
           ACT_THEORY_WEIGHT,
       sum(nvl(T1.ACT_LEN,0)) as ACT_LEN,

       to_char(T1.ACT_LEN_MIN,'FM999990.00') AS ACT_LEN_MIN,
       to_char(T1.ACT_LEN_MAX,'FM999990.00') AS ACT_LEN_MAX,
       --to_char(T1.ACT_LEN_MIN,'FM999990.00')||'-'||to_char(T1.ACT_LEN_MAX,'FM999990.00') as LEN,
       T1.CREATE_NAME,
       max(TO_CHAR(T1.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS')) CREATE_TIME,
       max(to_char(T1.INSTOCK_TIME,'YYYY-MM-DD')) INSTOCK_TIME,
       T2.STORAGE_NO,
       S.STORAGE_NAME,
       T1.MEMO,
       T1.PIPMEMO,
       T1.JUDGE_STD_DES,
       T1.JUDGE_STD_NAME,
       T1.PLINE_CODE,
       T1.PLINE_NAME,

       T1.MAT_STATUS,
       --T1.BAL_YEAR_MONTH,
       to_char(to_date(T1.BAL_YEAR_MONTH,'YYYY-MM'),'yyyy-MM') as BAL_YEAR_MONTH,
       T1.PRODUCT_FLAG
       --T1.HEAT_PLAN_NO
  FROM MAT_BC_M T1, YDM_BC_BUTTRESS T2
 LEFT JOIN ydm_bs_storage S ON S.STORAGE_NO=T2.STORAGE_NO
 WHERE T1.JUDGE_STOVE_NO = T2.JUDGE_STOVE_NO
   AND T1.BATCH_NO = T2.BATCH_NO
    AND T1.MAT_NO=T2.MAT_NO

  ]]>
</query>

<query id = "FrmInOnlineStore.doQueryInList" desc = "查询入库实绩">
<![CDATA[
 SELECT t.INSTOCK_DOC,
       t.JUDGE_STOVE_NO,
       t.BATCH_NO,
       t.PRODUCCODE,
       t.PRODUCNAME,
       t.STD_CODE,
       t.STD_NAME,
       t.STEELCODE,
       t.STEELNAME,
       t.STD_STYLE,
       t.STD_STYLE_DESC,
       t.SPEC_CODE,
       t.SPEC_NAME,
       t.MODEL_CODE,
       t.MODEL_DESC,
       t.ACT_DIMATER,
       t.ACT_HEIGHT,
       to_char(t.ACT_LEN_MIN, 'FM999990.00') AS ACT_LEN_MIN,
       to_char(t.ACT_LEN_MAX, 'FM999990.00') AS ACT_LEN_MAX,
       sum(t.ACT_COUNT) as ACT_COUNT,
       to_char(sum(t.ACT_WEIGHT), 'FM999999990.000') as ACT_WEIGHT,
       t.ACT_LEN,
       t.BELONG_CODE,
       t.BELONG_NAME,
       s.STORAGE_NAME AS STORAGE_NO,
       t.MEMO,
       t.CREATE_NAME,
       max(to_char(t.INSTOCK_TIME, 'YYYY-MM-DD HH24:MI:SS')) as INSTOCK_TIME,
       max(to_char(t.IN_TIME_F, 'YYYY-MM-DD')) AS IN_TIME_F,
       to_char(to_date(t.BAL_YEAR_MONTH, 'YYYY-MM'), 'yyyy-MM') as BAL_YEAR_MONTH,
       t.ORDER_NO,
       t.ORDER_SEQ,
       t.DELIVERY_NO,
       t.JUDGE_STD_CODE,
       t.JUDGE_STD_NAME,
       t.PLINE_CODE,
       t.PLINE_NAME,
       t.GRADECODE,
       t.GRADENAME,
       t.MATERIAL_NO,
       t.MATERIAL_NAME,
       DECODE(t.PRODUCT_FLAG,
              '801401',
              '在制品',
              '801402',
              '成品',
              '801403',
              '商品') PRODUCT_FLAG,
       t.MAT_STATUS,
       t.ZB_RCDID,
       t.PIPMEMO,
       t.BATCH_GROUD_NO,
       m.basename as GROUPNAME,
       t.qcm_staus,
       t1.sample_flag,
       t.ZG_STOVE_SQE
  FROM YDM_BC_INLIST t
  left join (select m.pline_code, g.basename
               from com_base_pline m, com_base_info g
              where m.group_pay = g.basecode) m
    on m.pline_code = t.pline_code
  LEFT JOIN MAT_BC_M T1
    ON T.MAT_NO = T1.MAT_NO, YDM_BC_BUTTRESS T2
  left join ydm_bs_storage s
    on T2.STORAGE_NO = s.STORAGE_NO
 where t.INSTOCK_TYPE_CODE = '800701'
   AND t.HAND_FLAG = '0'
   AND T.QCM_STAUS <> '11'
   AND T.MAT_NO = T2.MAT_NO #SOMETHING#
 group by t.JUDGE_STOVE_NO,
          t.BATCH_NO,
          t.INSTOCK_DOC,
          t.PRODUCCODE,
          t.PRODUCNAME,
          t.STD_CODE,
          t.STD_NAME,
          t.STEELCODE,
          t.STEELNAME,
          t.STD_STYLE,
          t.STD_STYLE_DESC,
          t.SPEC_CODE,
          t.SPEC_NAME,
          t.JUDGE_STD_CODE,
          t.JUDGE_STD_NAME,
          t.GRADECODE,
          t.GRADENAME,
          t.BAL_YEAR_MONTH,
          t.PIPMEMO,
          t.BATCH_GROUD_NO,
          t.MATERIAL_NO,
          t.MATERIAL_NAME,
          t.MAT_STATUS,
          t.qcm_staus,
          t1.sample_flag,
          t.MODEL_DESC,
          t.ACT_DIMATER,
          t.ACT_HEIGHT,
          t.ACT_LEN_MIN,
          t.ACT_LEN_MAX,
          t.BELONG_CODE,
          t.BELONG_NAME,
          s.STORAGE_NAME,
          t.MEMO,
          t.CREATE_NAME,
          t.ORDER_NO,
          t.ORDER_SEQ,
          t.DELIVERY_NO,
          t.MODEL_CODE,
          t.PRODUCT_FLAG,
          t.ZB_RCDID,
          t.PLINE_CODE,
          t.PLINE_NAME,
          m.basename,
          t.ACT_LEN,
          t.ZG_STOVE_SQE
 order by t.instock_doc desc
   ]]>
</query>
<query id = "FrmInOnlineStore.doQueryGoType" desc = "查询去向">
SELECT T.TARGET AS GO_TYPE FROM MIL_PLAN T WHERE T.JUDGE_STOVE_NO = ?
</query>
<query id = "FrmInOnlineStore.doQueryStoreNo" desc = "查询仓库信息">
SELECT T.OUT_REPOSITORY STORAGE_NO, S.STORAGE_TYPE_NO, S.STORAGE_TYPE_NAME
  FROM COM_BASE_PLINE T, YDM_BS_STORAGE S
 WHERE T.OUT_REPOSITORY = S.STORAGE_NO
   AND T.PLINE_CODE = ?
</query>

<query id = "FrmInOnlineStore.doQueryStoreNo2" desc = "根据产线,炉号找仓库信息">
select T.STORAGE_NO, T.STORAGE_TYPE_NO, T.STORAGE_TYPE_NAME
  from YDM_BC_BUTTRESS_BACK T
 WHERE T.PLINE_CODE = ?
   AND T.JUDGE_STOVE_NO = REGEXP_REPLACE(?, '-.*', '')
</query>

<query id = "FrmInOnlineStore.doQueryDept" desc = "根据产线查找科室">
select t.* from COM_BASE_PLINE t WHERE T.PLINE_CODE = ?
</query>

<query id = "FrmInOnlineStore.queryGroupNo" desc = "查询同炉同批组号">
       SELECT LPAD(NVL(MAX(T.BATCH_GROUD_NO), 0)+1,3,0)BATCH_GROUD_NO FROM MAT_BC_M T WHERE T.JUDGE_STOVE_NO = ? AND T.BATCH_NO = ?
       </query>
       <query id = "FrmInOnlineStore.getInListDoc1" desc = "查询入库流水">
	<![CDATA[
	SELECT ?||LPAD(NVL(MAX(SUBSTR(T.INSTOCK_SQE, LENGTH(T.INSTOCK_SQE) - 4)), 0)+1,5,0)INSTOCK_SQE FROM YDM_BC_INLIST T
    WHERE 
    TRUNC(T.CREATE_TIME) =  TRUNC(SYSDATE)
    AND T.INSTOCK_DOC = ?
    ]]>
	</query>
	<query id = "FrmInOnlineStore.querySurplusOrderNo" desc = "查询余材合同号">
	<![CDATA[
	SELECT ? || TO_CHAR(SYSDATE, 'YYYYMM') ||
       LPAD(NVL(MAX(SUBSTR(T.PRO_ORDER_NO, LENGTH(T.PRO_ORDER_NO) - 3)), 0) + 1,
            3,
            0) PRO_ORDER_NO
  FROM MAT_BC_M T
 WHERE TRUNC(T.CREATE_TIME) = TRUNC(SYSDATE)
   AND T.PLINE_CODE = ?
   AND (T.BELONG_CODE = '002001016003' or T.BELONG_CODE = '002001017003' or T.BELONG_CODE = '002001016002' or T.BELONG_CODE = '002001018003')
   AND T.PRO_ORDER_NO LIKE 'C0%'
    ]]>
	</query>
	<query id = "FrmInOnlineStore.getInListDoc" desc = "查询入库单号">
	<![CDATA[
    SELECT ?||?||TO_CHAR(TO_DATE(?,'YYYY-MM-DD HH24:MI:SS'),'YYMMDD')||LPAD(NVL(MAX(SUBSTR(T.INSTOCK_DOC, LENGTH(T.INSTOCK_DOC) - 4)), 0)+1,5,0) INSTOCK_DOC FROM YDM_BC_INLIST T
    WHERE 
    TRUNC(T.CREATE_TIME) = TRUNC(TO_DATE(?,'YYYY-MM-DD HH24:MI:SS'))
    --AND T.INSTOCK_TYPE_CODE  = ?
    AND PLINE_CODE = ?
    --AND T.BELONG_CODE NOT IN ('100101', '100103', '100102')
    ]]>
	</query>
	<query id = "doQueryNum.Qualified" desc = "查询合格的支数">
	<![CDATA[
	SELECT T.ORDER_LENGTH AS ACT_LEN
  FROM MIL_SAW_RACK T
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.LOT_NO = ?
   GROUP BY T.ORDER_LENGTH
   ]]>
	</query>
	<query id = "doQueryNum.sample" desc = "取样管长度">
	SELECT T.ORDER_LENGTH - S.SAMPLE_LEN AS ACT_LEN
  FROM MIL_SAW_RACK T,
       (SELECT SUM(SAMPLE_LEN) SAMPLE_LEN, JUDGE_STOVE_NO, LOT_NO, SEQ
          FROM PORT_MIL_GET_SAMPLE_RESULT
         GROUP BY JUDGE_STOVE_NO, LOT_NO, SEQ) S
 WHERE T.JUDGE_STOVE_NO = S.JUDGE_STOVE_NO
   AND T.LOT_NO = S.LOT_NO
   AND T.JUDGE_STOVE_NO = ?
   AND T.LOT_NO = ?
	</query>
	<query id = "FrmInOnlineStore.doQueryBacthNoInformation" desc = "查询炉批信息样管">
	SELECT ACT_LEN,
       BATCH_NO,
       THACT_COUNT,
       NVL(ACT_WEIGHT, '0') ACT_WEIGHT,
       (THACT_COUNT - INSTORECOUNT) ACT_COUNT,
       --'0.000' AS ACT_WEIGHT,
       --'0' AS ACT_COUNT,
       INSTORECOUNT
  FROM (SELECT (CASE
                 WHEN S.RECUT_LENGTH IS NULL THEN
                  S.ORDER_LENGTH - S.SAMPLE_PIPE_LEN / 1000
                 ELSE
                  S.RECUT_LENGTH - S.SAMPLE_PIPE_LEN / 1000
               END) AS ACT_LEN,
               S.BATCH_NO,
               SUM(S.ACT_COUNT) AS THACT_COUNT,
               S1.ACT_WEIGHT,
               NVL(T1.INACT_COUNT, 0) AS INSTORECOUNT
          FROM PORT_MIL_BATCH_SAMPLE_RESULT S
          left join (SELECT SUM(T.ACT_COUNT) INACT_COUNT,
                           T.PLAN_ID,
                           T.BATCH_NO,
                           T.ORDER_LENGTH,
                           T.RECUT_LENGTH,
                           T.SAMPLE_PIPE_LEN,
                           T.judge_stove_no
                      FROM PORT_MIL_BATCH_SAMPLE_RESULT T
                     WHERE T.PLAN_ID = ?
                       And T.JUDGE_STOVE_NO = ?
                       AND T.IS_SAMPLE_PIPE = '1'
                       AND T.STATUS = '0'
                       AND T.INSTORE_FLAG = '1'
                     GROUP BY T.PLAN_ID,
                              T.BATCH_NO,
                              T.ORDER_LENGTH,
                              T.RECUT_LENGTH,
                              T.SAMPLE_PIPE_LEN,
                              T.judge_stove_no) T1 on S.PLAN_ID =
                                                       T1.PLAN_ID
                                                   and NVL(S.BATCH_NO,'/') =
                                                       NVL(T1.BATCH_NO,'/')
                                                   and S.ORDER_LENGTH =
                                                       T1.ORDER_LENGTH
                                                   and NVL(S.RECUT_LENGTH,
                                                           '0') =
                                                       NVL(T1.RECUT_LENGTH,
                                                           '0')
                                                   and S.SAMPLE_PIPE_LEN =
                                                       T1.Sample_Pipe_Len
                                                       
                                                       
          left join (SELECT S2.JUDGE_STOVE_NO,
                            S2.PLAN_ID,
                            SUM((CASE
                                  WHEN S2.RECUT_LENGTH IS NULL THEN
                                   S2.ACT_THEORY_WEIGHT
                                  ELSE
                                   S2.CUT_ACT_THEORY_WEIGHT
                                END)) AS ACT_WEIGHT,
                            (CASE
                              WHEN S2.RECUT_LENGTH IS NULL THEN
                               S2.ORDER_LENGTH
                              ELSE
                               S2.Recut_Length
                            END) ORDER_LENGTH,
                            S2.BATCH_NO
                       FROM PORT_MIL_BATCH_SAMPLE_RESULT S2
                      WHERE S2.INSTORE_FLAG = '0'
                        AND S2.STATUS = '0'
                        AND S2.IS_SAMPLE_PIPE = '1'
                        AND S2.JUDGE_STOVE_NO = ?
                      GROUP BY S2.JUDGE_STOVE_NO,
                               S2.PLAN_ID,
                               S2.ORDER_LENGTH,
                               S2.RECUT_LENGTH,
                               S2.BATCH_NO) S1 on S.plan_id = s1.plan_id
                                                  and S.judge_stove_no =
                                                      s1.JUDGE_STOVE_NO
                                                  and NVL(S.Batch_No,'/') = NVL(s1.BATCH_NO,'/')
                                                  and S.order_length =
                                                      s1.ORDER_LENGTH
         WHERE S.JUDGE_STOVE_NO = ?
           AND S.LOT_NO = ?
           AND S.PLAN_ID = ?
           AND S.IS_SAMPLE_PIPE = ?
           AND S.STATUS = '0'
         GROUP BY S.ORDER_LENGTH,
                  S.BATCH_NO,
                  S.SAMPLE_PIPE_LEN,
                  S.RECUT_LENGTH,
                  T1.INACT_COUNT,
                  S1.ACT_WEIGHT)
	
	</query>
	<query id = "FrmInOnlineStore.doQueryBacthNoInformation3" desc = "查询炉批信息样管">
	SELECT ACT_LEN,
       BATCH_NO,
       THACT_COUNT,
       NVL(ACT_WEIGHT,'0')ACT_WEIGHT,
       (ACT_COUNT - INSTORECOUNT) ACT_COUNT,
       -- '0.000' AS ACT_WEIGHT,
       --'0' AS ACT_COUNT,
       INSTORECOUNT
  FROM (SELECT (CASE
                 WHEN S.RECUT_LENGTH IS NULL THEN
                  S.ORDER_LENGTH
                 ELSE
                  S.RECUT_LENGTH
               END) AS ACT_LEN,
               S.BATCH_NO,
               SUM(S.ACT_COUNT) AS ACT_COUNT,
               SUM(S.ACT_COUNT) AS THACT_COUNT,
               --SUM(S.ACT_THEORY_WEIGHT) AS ACT_WEIGHT,
               MAX(S1.ACT_WEIGHT) ACT_WEIGHT,
               MAX(NVL(T1.INACT_COUNT, 0)) AS INSTORECOUNT
          FROM PORT_MIL_BATCH_SAMPLE_RESULT S
          left join (SELECT SUM(T.ACT_COUNT) INACT_COUNT,
                           T.PLAN_ID,
                           T.BATCH_NO,
                           T.ORDER_LENGTH,
                           T.RECUT_LENGTH
                      FROM PORT_MIL_BATCH_SAMPLE_RESULT T
                     WHERE T.PLAN_ID = ?
                       And T.JUDGE_STOVE_NO = ?
                       AND T.IS_SAMPLE_PIPE = '1'
                       AND T.STATUS = '0'
                       AND T.INSTORE_FLAG = '1'
                     GROUP BY T.PLAN_ID,
                              T.BATCH_NO,
                              T.ORDER_LENGTH,
                              T.RECUT_LENGTH
                             ) T1 on S.PLAN_ID =
                                                       T1.PLAN_ID
                                                   and NVL(S.BATCH_NO,'/') =
                                                       NVL(T1.BATCH_NO,'/')
                                                   and S.ORDER_LENGTH =
                                                       T1.ORDER_LENGTH
                                                   and NVL(S.RECUT_LENGTH,
                                                           '0') =
                                                       NVL(T1.RECUT_LENGTH,
                                                           '0')
                                                           left join (SELECT S2.JUDGE_STOVE_NO,
                           S2.PLAN_ID,
                           SUM((CASE
                                 WHEN S2.RECUT_LENGTH IS NULL THEN
                                  S2.ACT_THEORY_WEIGHT
                                 ELSE
                                  S2.CUT_ACT_THEORY_WEIGHT
                               END)) AS ACT_WEIGHT,
                               S2.BATCH_NO
                      FROM PORT_MIL_BATCH_SAMPLE_RESULT S2
                     WHERE S2.INSTORE_FLAG = '0'
                       AND S2.STATUS = '0'
                       AND S2.IS_SAMPLE_PIPE = '1'
                       AND S2.JUDGE_STOVE_NO = ?
                     GROUP BY S2.JUDGE_STOVE_NO, S2.PLAN_ID,
                     S2.BATCH_NO) S1 on s.plan_id =
                                                                   s1.plan_id
                                                               and NVL(S.Batch_No,'/') = NVL(s1.BATCH_NO,'/')    
                                                               and s.judge_stove_no =
                                                                   s1.JUDGE_STOVE_NO
                                                   
         WHERE S.JUDGE_STOVE_NO = ?
           AND S.LOT_NO = ?
           AND S.PLAN_ID = ?
           AND S.IS_SAMPLE_PIPE = ?
           AND S.STATUS = '0'
         GROUP BY S.ORDER_LENGTH,
                  S.BATCH_NO,
                  S.RECUT_LENGTH)
	</query>
	<!-- SELECT S.ORDER_LENGTH AS ACT_LEN,
       S.BATCH_NO,
       SUM(S.ACT_COUNT) AS ACT_COUNT,
       SUM(S.ACT_COUNT) AS THACT_COUNT,
       SUM(S.ACT_THEORY_WEIGHT) AS ACT_WEIGHT,
       NVL(T1.ACOUNT,0) AS INSTORECOUNT
  FROM PORT_MIL_BATCH_SAMPLE_RESULT S
  LEFT JOIN (SELECT SUM(T.ACT_COUNT) ACOUNT,
                    t.ZG_STOVE_SQE,
                    t.BATCH_NO,
                    t.Qcm_Staus,
                    t.act_len
               FROM MAT_BC_M T
              where t.zg_stove_sqe = ?
                AND T.SAMPLE_FLAG = '1'
              group by t.ZG_STOVE_SQE, t.BATCH_NO, t.Qcm_Staus, t.act_len) T1 ON S.JUDGE_STOVE_NO =
                                                                                 T1.ZG_STOVE_SQE
                                                                             AND S.BATCH_NO =
                                                                                 T1.BATCH_NO
                                                                             AND S.ORDER_LENGTH =
                                                                                 T1.act_len
 WHERE S.JUDGE_STOVE_NO = ?
   AND S.LOT_NO = ?
   AND S.PLAN_ID = ?
   AND S.IS_SAMPLE_PIPE = ?
 GROUP BY S.ORDER_LENGTH, S.BATCH_NO, T1.ACOUNT -->
	<query id = "FrmInOnlineStore.doQueryBacthNoInformation1" desc = "查询炉批信息合格">
	SELECT ACT_LEN,
       BATCH_NO,
       THACT_COUNT,
       --NVL(ACT_WEIGHT, '0') ACT_WEIGHT,
       --(THACT_COUNT - INSTORECOUNT) ACT_COUNT,
       '0.000' AS ACT_WEIGHT,
       '0' AS ACT_COUNT,
       INSTORECOUNT
  FROM (SELECT (CASE
                  WHEN S.RECUT_LENGTH IS NULL THEN
                   S.ORDER_LENGTH
                  ELSE
                   S.RECUT_LENGTH
                END) ACT_LEN,
                S.BATCH_NO,
                SUM(S.ACT_COUNT) AS THACT_COUNT,
                S1.ACT_WEIGHT,
                NVL(T1.INACT_COUNT, 0) AS INSTORECOUNT
           FROM PORT_MIL_BATCH_SAMPLE_RESULT S
           LEFT JOIN (SELECT SUM(T.ACT_COUNT) INACT_COUNT,
                            T.PLAN_ID,
                            T.BATCH_NO,
                            T.ORDER_LENGTH,
                            T.RECUT_LENGTH,
                            T.JUDGE_STOVE_NO
                       FROM PORT_MIL_BATCH_SAMPLE_RESULT T
                      WHERE T.PLAN_ID = ?
                        And T.JUDGE_STOVE_NO = ?
                        AND T.IS_SAMPLE_PIPE = '0'
                        AND T.STATUS = '0'
                        AND T.INSTORE_FLAG = '1'
                      GROUP BY T.PLAN_ID,
                               T.BATCH_NO,
                               T.ORDER_LENGTH,
                               T.RECUT_LENGTH,
                               T.JUDGE_STOVE_NO) T1 on S.PLAN_ID = T1.PLAN_ID
                                                   and S.JUDGE_STOVE_NO =
                                                       T1.JUDGE_STOVE_NO
                                                   and NVL(S.BATCH_NO,'/') =
                                                       NVL(T1.BATCH_NO,'/')
                                                   and S.ORDER_LENGTH =
                                                       T1.ORDER_LENGTH
                                                   and NVL(S.RECUT_LENGTH,
                                                           '0') =
                                                       NVL(T1.RECUT_LENGTH,
                                                           '0')
           left join (SELECT S2.JUDGE_STOVE_NO,
                            S2.PLAN_ID,
                            SUM((CASE
                                  WHEN S2.RECUT_LENGTH IS NULL THEN
                                   S2.ACT_THEORY_WEIGHT
                                  ELSE
                                   S2.CUT_ACT_THEORY_WEIGHT
                                END)) AS ACT_WEIGHT,
                            (CASE
                              WHEN S2.RECUT_LENGTH IS NULL THEN
                               S2.ORDER_LENGTH
                              ELSE
                               S2.Recut_Length
                            END) ORDER_LENGTH,
                            S2.BATCH_NO
                       FROM PORT_MIL_BATCH_SAMPLE_RESULT S2
                      WHERE S2.INSTORE_FLAG = '0'
                        AND S2.STATUS = '0'
                        AND S2.IS_SAMPLE_PIPE = '0'
                        AND S2.JUDGE_STOVE_NO = ?
                      GROUP BY S2.JUDGE_STOVE_NO,
                               S2.PLAN_ID,
                               S2.ORDER_LENGTH,
                               S2.RECUT_LENGTH,
                               S2.BATCH_NO) S1 on S.plan_id = s1.plan_id
                                                  and S.judge_stove_no =
                                                      S1.JUDGE_STOVE_NO
                                                  and NVL(S.Batch_No,'/') = NVL(s1.BATCH_NO,'/')
                                                  and S.order_length =
                                                      s1.ORDER_LENGTH
          WHERE S.JUDGE_STOVE_NO = ?
       AND S.LOT_NO = ?
       AND S.PLAN_ID = ?
       AND S.IS_SAMPLE_PIPE = ?
       AND S.STATUS = '0'
          GROUP BY S.ORDER_LENGTH,
                   S.BATCH_NO,
                   S.RECUT_LENGTH,
                   S1.ACT_WEIGHT,
                   T1.INACT_COUNT)
	</query>
	
	<query id = "FrmInOnlineStore.doQueryBacthNoInformation2" desc = "查询炉批信息废品">
	SELECT ACT_LEN,BATCH_NO,THACT_COUNT,NVL(ACT_WEIGHT,'0')ACT_WEIGHT,(ACT_COUNT - INSTORECOUNT) ACT_COUNT,INSTORECOUNT
 FROM (
	SELECT S.ORDER_LENGTH AS ACT_LEN,
       S.BATCH_NO,
       SUM(S.ACT_COUNT) AS ACT_COUNT,
       SUM(S.ACT_COUNT) AS THACT_COUNT,
       --SUM(S.ACT_THEORY_WEIGHT) AS ACT_WEIGHT,
       MAX(S1.ACT_WEIGHT) ACT_WEIGHT,
       MAX(NVL(T1.INACT_COUNT, 0)) AS INSTORECOUNT
  FROM PORT_MIL_BATCH_SAMPLE_RESULT S
  left join (SELECT SUM(T.ACT_COUNT)INACT_COUNT,T.PLAN_ID,T.BATCH_NO,T.ORDER_LENGTH
               FROM PORT_MIL_BATCH_SAMPLE_RESULT T
              WHERE T.PLAN_ID = ? And T.JUDGE_STOVE_NO = ?
                AND T.STATUS = '2'
                AND T.INSTORE_FLAG = '1'
                GROUP BY T.PLAN_ID,T.BATCH_NO,T.ORDER_LENGTH)T1
                on S.PLAN_ID = T1.PLAN_ID
                and NVL(S.BATCH_NO,'/') = NVL(T1.BATCH_NO,'/')
                and S.ORDER_LENGTH = T1.ORDER_LENGTH
                left join (SELECT S2.JUDGE_STOVE_NO,
                           S2.PLAN_ID,
                           SUM((CASE
                                 WHEN S2.RECUT_LENGTH IS NULL THEN
                                  S2.ACT_THEORY_WEIGHT
                                 ELSE
                                  S2.CUT_ACT_THEORY_WEIGHT
                               END)) AS ACT_WEIGHT,
                               S2.BATCH_NO
                      FROM PORT_MIL_BATCH_SAMPLE_RESULT S2
                     WHERE S2.INSTORE_FLAG = '0'
                       AND S2.STATUS ='2'
                     GROUP BY S2.JUDGE_STOVE_NO, S2.PLAN_ID,S2.BATCH_NO) S1 on s.plan_id =
                                                                   s1.plan_id
                                                               and NVL(S.Batch_No,'/') = NVL(s1.BATCH_NO,'/')
                                                               and s.judge_stove_no =
                                                                   s1.JUDGE_STOVE_NO
 WHERE S.JUDGE_STOVE_NO = ?
   AND S.LOT_NO = ?
   AND S.PLAN_ID = ?
   AND S.STATUS = '2'
 GROUP BY S.ORDER_LENGTH, S.BATCH_NO)
	</query>
	
	<!-- SELECT COUNT(1) ACT_COUNT, T1.JUDGE_STOVE_NO, T1.LOT_NO,T1.PIPE_LENGTH AS ACT_LEN,
	       0.02466 * T4.WALLTHICK *(T4.OUTDIAMETER - T4.WALLTHICK)*T1.PIPE_LENGTH AS ACT_WEIGHT
           FROM MIL_QA_RACK T1,
           (SELECT T3.OUTDIAMETER,T3.WALLTHICK,T2.JUDGE_STOVE_NO,T2.LOT_NO
         FROM MIL_PLAN T2, PLN_ORDER_ZG T3
        WHERE T2.CONTRACT_NO = T3.ORDER_NO || '/' || T3.ORDER_SEQ)T4
          WHERE T1.JUDGE_STOVE_NO = T4.JUDGE_STOVE_NO
          AND T1.LOT_NO = T4.LOT_NO
          AND T1.STATUS = '0'
          AND T1.JUDGE_STOVE_NO = ?
          AND T1.LOT_NO = ?
          AND NVL(T1.PIPE_LENGTH) = NVL(?,'/')
          GROUP BY T1.JUDGE_STOVE_NO, T1.LOT_NO,T1.PIPE_LENGTH,T4.WALLTHICK,T4.OUTDIAMETER -->
	<query id = "doQueryNum.Scrap" desc = "查询废品的支数">
	SELECT COUNT(1) ACT_COUNT,
       T1.JUDGE_STOVE_NO,
       T1.LOT_NO,
       T1.PIPE_LENGTH AS ACT_LEN,
       0.02466 * T4.WALLTHICK *(T4.OUTDIAMETER - T4.WALLTHICK)*T1.PIPE_LENGTH AS ACT_WEIGHT
  FROM MIL_SLAB_SCRAP T1,
  (SELECT T3.OUTDIAMETER,T3.WALLTHICK,T2.JUDGE_STOVE_NO,T2.LOT_NO
         FROM MIL_PLAN T2, PLN_ORDER_ZG T3
        WHERE T2.CONTRACT_NO = T3.ORDER_NO || '/' || T3.ORDER_SEQ)T4
 WHERE T1.JUDGE_STOVE_NO = T4.JUDGE_STOVE_NO
   AND T1.LOT_NO = T4.LOT_NO
   AND T1.JUDGE_STOVE_NO = ?
   AND T1.LOT_NO = ?
   AND NVL(T1.PIPE_LENGTH,'/') = NVL(?,'/')
   AND T1.FLAG = '1'
   AND T1.HANDLE_RESULT = '500201'  
 GROUP BY T1.JUDGE_STOVE_NO, T1.LOT_NO,T1.PIPE_LENGTH,T4.OUTDIAMETER,T4.WALLTHICK
	</query>
	<query id = "doQueryNum.Slample" desc= "查询样管信息">
	SELECT DISTINCT COUNT(1) ACT_COUNT,
                        T1.JUDGE_STOVE_NO,
                        T1.LOT_NO,
                        T1.Pipe_Length,
                        0.02466 * T4.WALLTHICK *(T4.OUTDIAMETER - T4.WALLTHICK)*T1.PIPE_LENGTH AS ACT_WEIGHT
          FROM PORT_MIL_GET_SAMPLE_RESULT T1,
          (SELECT T3.OUTDIAMETER,T3.WALLTHICK,T2.JUDGE_STOVE_NO,T2.LOT_NO
         FROM MIL_PLAN T2, PLN_ORDER_ZG T3
        WHERE T2.CONTRACT_NO = T3.ORDER_NO || '/' || T3.ORDER_SEQ)T4
          WHERE T1.JUDGE_STOVE_NO = T4.JUDGE_STOVE_NO
          AND T1.LOT_NO = T4.LOT_NO
          AND T1.JUDGE_STOVE_NO = ?
          AND T1.LOT_NO = ?
          AND NVL(T1.PIPE_LENGTH,'/') = NVL(?,'/')
         GROUP BY T1.JUDGE_STOVE_NO, T1.LOT_NO,T1.Pipe_Length,T4.OUTDIAMETER,T4.WALLTHICK
	</query>
<query id="FrmInOnlineStore.queryMatNoM" desc="自动生存材料号">
		<![CDATA[
	 SELECT ? || ? ||
       LPAD(NVL(MAX(SUBSTR(T.MAT_NO, LENGTH(T.MAT_NO) - 3)), 0) + 1, 4, 0) MAT_NO
  FROM (SELECT MAX(T1.MAT_NO) MAT_NO
          FROM MAT_BC_M T1
         WHERE T1.JUDGE_STOVE_NO = ?
           AND T1.BATCH_NO = ?
        UNION ALL
        SELECT MAX(T3.MAT_NO) MAT_NO
          FROM MAT_ZC_BACKUP T3
         WHERE T3.JUDGE_STOVE_NO = ?
           AND T3.BATCH_NO = ?
        UNION ALL
        SELECT MAX(T4.MAT_NO) MAT_NO
          FROM YDM_BC_INLIST T4
         WHERE T4.JUDGE_STOVE_NO = ?
           AND T4.BATCH_NO = ?) T
		]]>
	</query>
	<query id = "FrmInOnlineStore.doQueryBacthNo" desc = "查询取样所有批号">
	<![CDATA[
	SELECT T.BATCH_NO AS BATCHCODE,T.BATCH_NO
          FROM PORT_MIL_GET_BATCH_RESULT T
         WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = REGEXP_REPLACE(?, '-.*', '')
          AND T.LOT_NO = ?
          AND T.PLAN_ID = ?
           ORDER BY T.BATCH_NO
           ]]>
	</query>	
	<query id = "FrmInOnlineStore.doQueryFlawStaus" desc = "查询探伤结果">
	SELECT T.BASENAME,T.BASECODE
  FROM COM_BASE_INFO T
 WHERE T.SORTCODE = '407404'
	</query>
	<query id = "FrmInOnlineStore.doQueryTestingStaus" desc = "查询表检结果">
	SELECT T.BASENAME,T.BASECODE
  FROM COM_BASE_INFO T
 WHERE T.SORTCODE = '407406'
	</query>
	<query id = "doDecision.jugdeApplyNo" desc = "生产判定单号">
	<![CDATA[
	SELECT ? || ? || TO_CHAR(SYSDATE, 'YYYYMMDD') ||
         LPAD(NVL(MAX(SUBSTR(T.JUGDE_APPLY_CODE, 19,5)), 0) + 1, 5, 0) JUGDE_APPLY_CODE
    FROM QCM_ZG_JUGDE_APPLY T
   WHERE TRUNC(T.APPLY_TIME) = TRUNC(SYSDATE)
   AND T.IS_ALL_SCRAP != '3'
   AND T.IS_ALL_SCRAP != '4'
   AND T.PROCESS_CODE = 'D'
   ]]>
	</query>
	<query id = "FrmInOnlineStore.doDecision" desc = "申请判定">
	DECLARE
  V_JUGDE_APPLY_CODE MAT_BC_M.JUGDE_APPLY_CODE%TYPE := NULL;
BEGIN
  --SELECT ? || ? || TO_CHAR(SYSDATE, 'YYYYMMDD') ||
        -- LPAD(NVL(MAX(SUBSTR(T.JUGDE_APPLY_CODE, 19)), 0) + 1, 5, 0)
   -- INTO V_JUGDE_APPLY_CODE
   -- FROM MAT_BC_M T
   --WHERE T.PLINE_CODE = ?
    -- AND T.PRODUCT_FLAG = ?;
  FOR MYROW IN (SELECT T.MAT_NO
                  FROM MAT_BC_M T
                  LEFT JOIN YDM_BC_BUTTRESS S ON T.MAT_NO = S.MAT_NO
                 WHERE T.JUDGE_STOVE_NO = ?
                   AND T.BATCH_NO = ?
                   AND T.BATCH_GROUD_NO = ?
                   --AND NVL(S.STORAGE_NO,'/') = NVL(?,'/')
                   --AND NVL(S.LOCATION_NO,'/') = NVL(?,'/')
                   AND T.PRODUCT_FLAG = ?
                   AND T.MAT_STATUS = ?
                   AND T.JUGDE_APPLY_CODE IS NULL
                   ORDER BY T.MAT_NO ASC) LOOP
    UPDATE MAT_BC_M T
       SET T.JUGDE_APPLY_CODE = ?,
       T.JUGDE_APPLY_SEQUENO = '1',
       T.JUGDE_APPLY_TIME = SYSDATE
     WHERE T.MAT_NO = MYROW.MAT_NO;
  END LOOP;
END;
	</query>
	<query id = "FrmInOnlineStore.queryMatZcCount" desc = "查询已入库支数">
	<![CDATA[
	SELECT NVL(COUNT(1),0)ACOUNT
	FROM MAT_BC_M T
	WHERE T.ZG_STOVE_SQE = ?
	AND T.PLINE_CODE = ?
	AND T.BATCH_NO <> 'X'
	AND T.QCM_STAUS = '00'
	]]>
	</query>
	<!-- SELECT (TO_NUMBER(NVL(T.QUALIFIED_NUM,0))+TO_NUMBER(NVL(T.OFFLINE_NUM,0))) ACOUNT
  FROM MIL_INSTORE_RESULT T
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.PLINE_CODE = ? -->
	<query id = "FrmInOnlineStore.doQueryMilCount" desc = "轧管已产出支数">
	<![CDATA[
	SELECT NVL(T.QUALIFIED_NUM,0) AS ACOUNT FROM MIL_INSTORE_RESULT T WHERE T.JUDGE_STOVE_NO = ? AND T.PLINE_CODE = ?
	]]>
	</query>
	<!-- SELECT NVL(SUM(T.QUALIFIED_BRANCH),0) AS ACOUNT FROM MIL_SURFACE_RESULT T WHERE T.JUDGE_STOVE_NO = ? AND T.PLINE_CODE = ? -->
	<!-- SELECT (CASE
                 WHEN T.OFFLINE_FLAG = '2' THEN
                  T.BRANCH
                 ELSE
                  T.DB_NUM * T.SAW_NUM
               END) ACOUNT FROM MIL_PLAN T WHERE T.JUDGE_STOVE_NO = ? AND T.PLINE_CODE = ? -->
	<!-- SELECT SUM(ACOUNT)ACOUNT FROM (SELECT SUM(T.QUALIFIED_BRANCH) ACOUNT
  FROM MIL_SURFACE_RESULT T
 WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = ?
   AND T.PLINE_CODE = ?
UNION ALL
SELECT COUNT(1) ACOUNT
  FROM MIL_SLAB_SCRAP T
 WHERE T.FLAG = '1'
   AND T.HANDLE_RESULT = '500201'
   AND REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = ?
   AND T.PLINE_CODE = ?
UNION ALL
SELECT COUNT(1) ACOUNT
  FROM MIL_SLAB_SCRAP T
 WHERE T.FLAG = '0'
    OR (T.FLAG = '1' AND T.HANDLE_RESULT <> '500201')
   AND REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = ?
   AND T.PLINE_CODE = ?
UNION ALL
SELECT COUNT(1) ACOUNT
  FROM MIL_QA_RACK T
 WHERE T.STATUS = '3'
    OR T.OFFLINE_FLAG = '1'
   AND REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = ?
   AND T.PLINE_CODE = ?) -->
	<query id = "FrmInOnlineStore.doBeside" desc = "交库结炉">
UPDATE MIL_PLAN T
   SET T.NODE_STATUS = '99'
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.LOT_NO = ?
   AND T.PLINE_CODE = ?
   AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
   AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
	</query>
	<query id = "FrmInOnlineStore.updateMilInstoreStaus" desc = "交库结炉修改实绩表结炉实绩">
UPDATE MIL_INSTORE_RESULT T
   SET T.NODE_FUR_FLAG = '1', T.USER_ID = ?, T.END_TIME = SYSDATE
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.LOT_NO = ?
   AND T.PLINE_CODE = ?
   AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
   AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
	</query>
	<query id = "FrmInOnlineStore.cancelDoBeside" desc = "结炉回退">
    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 := ?;
BEGIN
  UPDATE MIL_PLAN T
     SET T.NODE_STATUS = '96'
   WHERE T.JUDGE_STOVE_NO = V_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, '/');

  UPDATE MIL_INSTORE_RESULT T
     SET T.NODE_FUR_FLAG = '0'
   WHERE T.JUDGE_STOVE_NO = V_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, '/');
     
  UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T
     SET T.STATUS = '0', T.OP_PROCESS = ''
   WHERE T.OP_PROCESS = '12'
     AND T.JUDGE_STOVE_NO = V_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, '/');
     
  UPDATE MAT_BC_M T1
     SET T1.ZG_MAT_NO = ''
   where T1.ZG_STOVE_SQE = V_JUDGE_STOVE_NO;
END;
	</query>
	<query id = "FrmInOnlineStore.selectNodeStaus" desc = "查询炉计划状态">
	SELECT T.NODE_STATUS, T.ID
  FROM MIL_PLAN T
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.LOT_NO = ?
   AND T.PLINE_CODE = ?
	</query>
	<query id = "cancelDoDecision.doQuery" desc = "查询是否有已进行判定支数">
	<![CDATA[
	SELECT COUNT(1) ACOUNT
  FROM QCM_ZG_JUGDE_APPLY T
 WHERE T.JUGDE_APPLY_CODE = ?
   AND T.JUDGE_STOVE_NO = ?
   AND T.BATCH_NO = ?
   AND T.BATCH_GROUD_NO = ?
   AND (T.VALIDFLAG = '20' OR T.INSTANCY_FLAG = '1' OR
       T.TOL_INSTANCY_FLAG = '1')
         ]]>
	</query>
	<query id = "FrmInOnlineStore.cancelDoDecision" desc = "撤销申请修改材料状态">
	DECLARE
  V_JUGDE_APPLY_CODE QCM_ZG_JUGDE_APPLY.JUGDE_APPLY_CODE%type := ?;
  V_JUDGE_STOVE_NO   QCM_ZG_JUGDE_APPLY.JUDGE_STOVE_NO%type := ?;
  V_BATCH_NO         QCM_ZG_JUGDE_APPLY.BATCH_NO%type := ?;
  V_BATCH_GROUD_NO   QCM_ZG_JUGDE_APPLY.BATCH_GROUD_NO%type := ?;
  V_ORD_LN_DLY_PK    QCM_ZG_JUGDE_APPLY.ORD_LN_DLY_PK%type := NULL;
  V_TARGET           QCM_ZG_JUGDE_APPLY.TARGET%type := NULL;
BEGIN
  SELECT T.ORD_LN_DLY_PK, T.TARGET
    INTO V_ORD_LN_DLY_PK, V_TARGET
    FROM QCM_ZG_JUGDE_APPLY T
   WHERE T.JUGDE_APPLY_CODE = V_JUGDE_APPLY_CODE
     AND T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
     AND T.BATCH_NO = V_BATCH_NO
     AND T.BATCH_GROUD_NO = V_BATCH_GROUD_NO
     AND ROWNUM = 1;

  DELETE FROM QCM_ZG_JUGDE_APPLY T
   WHERE T.JUGDE_APPLY_CODE = V_JUGDE_APPLY_CODE
     AND T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
     AND T.BATCH_NO = V_BATCH_NO
     AND T.BATCH_GROUD_NO = V_BATCH_GROUD_NO;

  UPDATE MAT_BC_M T
     SET T.JUGDE_APPLY_CODE    = '',
         T.TESTING_GRADE       = '',
         T.TESTING_TYPE        = '',
         T.TESTING_GRADE1      = '',
         T.TESTING_TYPE1       = '',
         T.JUGDE_APPLY_TIME    = '',
         T.JUGDE_APPLY_SEQUENO = '1'
   WHERE T.JUGDE_APPLY_CODE = V_JUGDE_APPLY_CODE
     AND T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
     AND T.BATCH_NO = V_BATCH_NO
     AND T.BATCH_GROUD_NO = V_BATCH_GROUD_NO
     AND T.PROCESS_CDOE = 'D';

  DELETE FROM MAT_BC_QCMTRACK T
   WHERE T.JUGDE_APPLY_CODE = V_JUGDE_APPLY_CODE
     AND T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
     AND T.BATCH_NO = V_BATCH_NO
     AND T.PROCESS_CDOE = 'D';

  DELETE FROM QCM_ADD_ASK T
   WHERE T.JUGDE_APPLY_CODE = V_JUGDE_APPLY_CODE
     AND T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO;

  UPDATE PORT_MIL_BATCH_SAMPLE_RESULT P
     SET P.TR_FLAG2 = ''
   WHERE P.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO || '-01'
     AND P.TR_FLAG2 LIKE V_JUGDE_APPLY_CODE || '_';

  --更新成品送判量统计表
  IF (V_TARGET = 'A') THEN
    SET_QCM_ZC_APPLY2(V_ORD_LN_DLY_PK);
  END IF;

END;
	</query>
	<query id = "FrmInOnlineStore.cancelDoDecisionException" desc = "撤销申请判定(退判)">
	DECLARE
  V_JUGDE_APPLY_CODE QCM_ZG_JUGDE_APPLY.JUGDE_APPLY_CODE%type := ?;
  V_JUDGE_STOVE_NO   QCM_ZG_JUGDE_APPLY.JUDGE_STOVE_NO%type := ?;
  V_BATCH_NO         QCM_ZG_JUGDE_APPLY.BATCH_NO%type := ?;
  V_BATCH_GROUD_NO   QCM_ZG_JUGDE_APPLY.BATCH_GROUD_NO%type := ?;
BEGIN
  UPDATE QCM_ZG_JUGDE_APPLY T
     SET T.IS_FLAG = '1'
   WHERE T.JUGDE_APPLY_CODE = V_JUGDE_APPLY_CODE
     AND T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
     AND T.BATCH_NO = V_BATCH_NO
     AND T.BATCH_GROUD_NO = V_BATCH_GROUD_NO;

  UPDATE MAT_BC_M T
   SET T.JUGDE_APPLY_CODE    = '',
       T.JUGDE_APPLY_TIME    = '',
       T.JUGDE_APPLY_SEQUENO = '1'
 WHERE T.JUGDE_APPLY_CODE = V_JUGDE_APPLY_CODE
   AND T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
   AND T.BATCH_NO = V_BATCH_NO
   AND T.BATCH_GROUD_NO = V_BATCH_GROUD_NO
   AND T.PROCESS_CDOE = 'D';

  DELETE FROM MAT_BC_QCMTRACK T
   WHERE T.JUGDE_APPLY_CODE = V_JUGDE_APPLY_CODE
     AND T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
     AND T.BATCH_NO = V_BATCH_NO
     AND T.PROCESS_CDOE = 'D';
     
     DELETE FROM QCM_ADD_ASK T
   WHERE T.JUGDE_APPLY_CODE = V_JUGDE_APPLY_CODE
     AND T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO;
END;
	</query>
	<query id = "cancelDoDecision.ReciveZB" desc = "查询质保系统是否已接收">
	SELECT COUNT(1)ACOUNT
  FROM QCM_ZG_JUGDE_APPLY T
 WHERE T.JUGDE_APPLY_CODE = ?
   AND T.JUDGE_STOVE_NO = ?
   AND T.BATCH_NO = ?
   AND T.BATCH_GROUD_NO = ?
   AND T.VALIDFLAG = '15'
	</query>
	<query id = "cancelDoDecision.SelectPassApply" desc = "查询是否已紧急放行">
	SELECT COUNT(1) ACOUNT
  FROM QCM_BC_PASS_APPLY T
 WHERE T.JUGDE_APPLY_CODE = ?
   AND T.JUDGE_STOVE_NO = ?
   AND T.VALIDFLAG = '1'
	</query>
	<query id = "cancelPipeIn.doQueryStaus" desc= "查询材料状态">
	SELECT NVL(SUM(T.ACT_COUNT),0)ACOUNT
  FROM MAT_BC_M T
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.BATCH_NO = ?
   AND T.BATCH_GROUD_NO = ?
   AND T.ZG_STOVE_SQE = ?
   AND T.JUGDE_APPLY_CODE IS  NULL
	</query>
	<query id = "cancelPipeIn.doQueryCount" desc = "查询库存中可撤销的支数">
SELECT NVL(SUM(T.ACT_COUNT), 0) ACOUNT
  FROM MAT_BC_M T, YDM_BC_BUTTRESS S, COM_BASE_PLINE C, YDM_BC_INLIST T2
 WHERE T.MAT_NO = S.MAT_NO
   AND T.MAT_NO = T2.MAT_NO
   AND T2.INSTOCK_TYPE_NAME = '产出入库'
   AND T.PLINE_CODE = C.PLINE_CODE
   AND T.QCM_STAUS = '00'
   AND T.LOCK_LIKU = '0'
   AND T.JUGDE_APPLY_CODE IS NULL
   AND T.JUDGE_STOVE_NO = ?
   AND T.BATCH_NO = ?
   AND T.BATCH_GROUD_NO = ?
   AND T2.INSTOCK_DOC = ?
   AND (C.OUT_REPOSITORY = S.STORAGE_NO OR S.STORAGE_NO IN ('BZJ1', 'BZJ2','BZJ3'))
	</query>
	
	<query id = "cancelPipeIn.doQueryCountPipe" desc = "查询交库返线后导运的支数">
	   SELECT NVL(SUM(T.ACT_COUNT), 0) ACOUNT
  FROM MAT_BC_M T, YDM_BC_BUTTRESS S, YDM_BC_BUTTRESS_BACK C
 WHERE T.MAT_NO = S.MAT_NO
   AND T.MAT_NO = C.MAT_NO
   AND S.STORAGE_NO != C.STORAGE_NO
   AND T.QCM_STAUS = '00'
   AND T.LOCK_LIKU = '0'
   AND T.JUDGE_STOVE_NO = ?
   AND T.BATCH_NO = ?
   AND T.BATCH_GROUD_NO = ?
	</query>
	<query id = "creatGroup.selectMilInStore" desc = "查询是否已存在满足的组号">
	<![CDATA[
	SELECT T.BATCH_GROUD_NO
  FROM MIL_INSTORE T
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.BATCH_NO = ?
   --AND T.SAMPLE_FLAG = ?
   --AND T.TEST_STAUS = ?
   --AND T.SURFACE_STAUS = ?
   AND ? >= T.ACT_LEN_MIN
   AND ? <= T.ACT_LEN_MAX
   AND T.PROCESS_CODE = ?
   ]]>
	</query>
	<query id = "creatGroup.InsertMilInStore" desc = "新增组号记录">
	 INSERT INTO MIL_INSTORE(
        INSTORE_ID,
        JUDGE_STOVE_NO,
        BATCH_NO,
        SAMPLE_FLAG,
        TEST_STAUS,
        SURFACE_STAUS,
        ACT_LEN_MIN,
        ACT_LEN_MAX,
        BATCH_GROUD_NO,
        PROCESS_CODE)
 VALUES( 
        ?,
        ?,
        ?,
        '',
        ?,
        ?,
        ?,
        ?,
        ?,
        ?)
	</query>
	<query id = "FrmInOnlineStore.SelectdoPipeInstore" desc = "查询炉批已入库支数">
	SELECT NVL(SUM(T.ACT_COUNT),0) ACOUNT
  FROM MAT_BC_M T
 WHERE T.ZG_STOVE_SQE = ?
   AND T.BATCH_NO = ?
   --AND T.PRODUCT_FLAG = '801401'
	</query>
	<query id = "FrmInOnlineStore.doQueryProcess" desc = "查询管号队列进程信息">
	<![CDATA[
	 SELECT 
       T.PLAN_ID,
       T.LOT_NO,
       T.STOVE_NO,
       T.JUDGE_STOVE_NO,
       T.GROUP_NO,
       T.PLINE_CODE,
       T.BATCH_NO,
       T.SEQ,
       T.MAT_NO,
       DECODE(T.IS_SAMPLE_PIPE,'0','非样管','1','样管')IS_SAMPLE_PIPE,
       T.IS_VALID,
       T.REMARK,
       T.SAMPLE_PIPE_LEN,
       T.GET_SAMPLE_NAME,
       TO_CHAR(T.GET_SAMPLE_TIME, 'YYYY-MM-DD HH24:MI:SS') GET_SAMPLE_TIME,
       T.GET_SAMPLE_SHIFT,
       T.GET_SAMPLE_CLASS,
       (CASE
         WHEN T.RECUT_LENGTH IS NOT NULL THEN
          T.RECUT_LENGTH
         ELSE
          T.ORDER_LENGTH
       END) ORDER_LENGTH,
       T.ACT_THEORY_WEIGHT,
       T.ACT_COUNT,
       TO_CHAR(T.CRATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CRATE_TIME,
       --DECODE(T.STATUS,'0','合格','1','热区剔除','2','冷区剔除','3','下线','4','返线')STATUS,
       T.STATUS,
       T.M_MAT_NO,
       DECODE(T.GROUP_FLAG,'0','未组炉','1','已组炉')GROUP_FLAG,
       CASE T.OP_PROCESS
         WHEN '0' THEN
          '上料'
         WHEN '2' THEN
          '加热炉'
         WHEN '3' THEN
          '穿孔'
         WHEN '4' THEN
          '连轧'
         WHEN '5' THEN
          '再加热炉'
          WHEN '6' THEN
          '定径'
          WHEN '7' THEN
          '分切'
          WHEN '9' THEN
          '矫直'
          WHEN '10' THEN
          '探伤'
          WHEN '11' THEN
          '人工质检'
          WHEN '12' THEN
          '交库'
          WHEN '13' THEN
          '委外'
       END AS OP_PROCESS,
       DECODE(trim(T.BACK_PROCESS),'10','探伤','11','复检','9','矫直')BACK_PROCESS,
       T.M_M_MAT_NO,
       --DECODE(T.INSTORE_FLAG,'0','未入库','1','已入库')INSTORE_FLAG,
       T.REAL_BATCH_NO
 FROM PORT_MIL_BATCH_SAMPLE_RESULT T
 WHERE T.PLAN_ID = ?
 AND T.JUDGE_STOVE_NO = ?
 AND T.STATUS = ?
 ORDER BY T.SEQ ASC
 ]]>
	</query>
	<query id = "FrmInOnlineStore.doQueryJugeNoProcess" desc = "查询进程炉信息">
	<![CDATA[
	SELECT 
       T.PLAN_ID,
       T.LOT_NO,
       T.JUDGE_STOVE_NO,
       T.PLINE_CODE,
       T.STATUS,
       SUM(T.ACT_COUNT)ACT_COUNT
 FROM PORT_MIL_BATCH_SAMPLE_RESULT T
 WHERE T.Judge_Stove_No || '&' LIKE ('%' || ? || '%')
 AND T.LOT_NO || '&' LIKE ('%' || ? || '%')
 AND T.PLINE_CODE = ?
 GROUP BY T.PLAN_ID,
       T.LOT_NO,
       T.JUDGE_STOVE_NO,
       T.PLINE_CODE,
       T.STATUS
       ]]>
	</query>
	<query id = "FrmInOnlineStore.SelectPorssWt" desc = "查询是否存在无过磅重量">
			SELECT NVL(SUM(T.ACT_COUNT), 0) ACOUNT
	  FROM MAT_BC_M T
	 WHERE T.JUDGE_STOVE_NO = ?
	   AND T.PONDER_GROSS_WT IS NULL
	   AND T.INSTOCK_FLAG = '1'
	   AND T.QCM_STAUS = '00'
	   AND (T.BELONG_CODE = '002001016003' or T.BELONG_CODE = '002001017003' or
	       T.BELONG_CODE = '002001016002' or T.BELONG_CODE = '002001018003')
    </query>
	<query id = "insertProssWt.selectCount" desc = "查询该炉总支数">
	SELECT NVL(SUM(T.ACT_COUNT), 0) ACOUNT
  FROM MAT_BC_M T
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.BELONG_CODE = ?
   AND T.LOT_NO = ?
   AND T.JUGDE_APPLY_CODE IS NULL
   AND T.QCM_STAUS = '00'
	</query>
	<query id = "insertProssWt.selectMatNo" desc = "查询所有材料号">
	SELECT T.MAT_NO
  FROM MAT_BC_M T
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.BELONG_CODE = ?
   AND T.LOT_NO = ?
   AND T.JUGDE_APPLY_CODE IS NULL
   AND T.QCM_STAUS = '00'
	</query>
	<query id = "insertProssWt.updatePossWt" desc = "修改过磅重量">
	UPDATE MAT_BC_M T
   SET T.PONDER_GROSS_WT = ?,
       T.ACT_WEIGHT      = ?,
       T.PONDER_NAME     = ?,
       T.PONDER_TIME     = SYSDATE
 WHERE T.MAT_NO = ?
   AND T.JUDGE_STOVE_NO = ?
   AND T.BELONG_CODE = ?
   AND T.LOT_NO = ?
	</query>
	<query id = "FrmInOnlineStore.doQueryApplyCodeNull" desc = "查询该炉是否有未送判数据">
	SELECT NVL(SUM(T.ACT_COUNT),0)ACT_COUNT FROM MAT_BC_M T WHERE T.JUDGE_STOVE_NO = ? AND T.BELONG_CODE = ? AND T.PLINE_CODE = ? AND T.QCM_STAUS = '00' AND T.JUGDE_APPLY_CODE IS NULL
	</query>
	<query id = "FrmInOnlineStore.doQueryJugeNoApply" desc = "查询该炉是否都已入库">
	<![CDATA[
	SELECT NVL(COUNT(1),0)ACOUNT FROM MIL_PLAN T WHERE T.JUDGE_STOVE_NO || '&' LIKE ('%' || ? || '%') AND T.NODE_STATUS <> '99'
	]]>
	</query>
	<query id = "FrmInOnlineStore.getStoreNo" desc = "获取所有库">
	SELECT STORAGE_NAME, STORAGE_NO
  FROM YDM_BS_STORAGE T
 WHERE VALIDFLAG = '1'
      --AND DUMMY_FLAG = '0'
   AND SUBSTR(T.MANAGEMENT_NO, 1, 6) = SUBSTR(?, 1, 6)
   AND STORAGE_TYPE_NO IN( '800202','800205')
 ORDER BY STORAGE_ATTR, STORAGE_NAME ASC
	</query>
	<query id = "FrmInOnlineStore.updateStatus" desc = "交库剔除废管">
	DECLARE

BEGIN
  UPDATE MIL_INSTORE_RESULT T
     SET T.SCRAP_NUM = TO_NUMBER(T.SCRAP_NUM)+ TO_NUMBER('1')
   WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#';
      INSERT INTO MIL_SLAB_SCRAP_SEQ(
        JUDGE_STOVE_NO,
        PROCESS_NO,
        SEQ,
        TIME,
        COL_TIME,
        COL_USER,
        COL_SHIFT,
        COL_GROUP,
        RESULT_NO)
 VALUES( 
        '#JUDGE_STOVE_NO#',
        '12',
        '#SEQ#',
        SYSDATE,
        SYSDATE,
        '#COL_USER#',
        '#COL_SHIFT#',
        '#COL_GROUP#',
        '#PLAN_ID#'
        );
END;
	</query>
	<query id = "FrmInOnlineStore.updateLen" desc = "修改长度">
	UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T
   SET T.ORDER_LENGTH      = '#ORDER_LENGTH#',
       T.ACT_THEORY_WEIGHT = ROUND(TO_NUMBER(T.ACT_THEORY_WEIGHT) *
                                   TO_NUMBER('#ORDER_LENGTH#') /
                                   TO_NUMBER(T.ORDER_LENGTH),
                                   3)
 WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND T.MAT_NO = '#MAT_NO#'
	</query>
	<query id = "FrmInOnlineStore.SelectNodeStatus" desc = "查询是否表检结炉">
	SELECT T.NODE_STATUS FROM MIL_PLAN T WHERE T.JUDGE_STOVE_NO = ?
	</query>
	<query id = "FrmInOnlineStore.updateStatusBack" desc = "剔除回退">
	DECLARE
BEGIN
  UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T
     SET T.STATUS = '0',
     T.OP_PROCESS = ' '
   WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
     AND T.MAT_NO = '#MAT_NO#';
  DELETE FROM MIL_SLAB_SCRAP_SEQ T WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#' AND T.PROCESS_NO = '12';
END;
	</query>
	<query id = "FrmInOnlineStore.doQuerySampleNum" desc = "查询是否存在样管">
	<![CDATA[
	SELECT NVL(SUM(T.ACT_COUNT), 0) ACT_COUNT
  FROM PORT_MIL_BATCH_SAMPLE_RESULT T
 WHERE T.JUDGE_STOVE_NO || '&' LIKE ('%' || ? || '%')
   AND T.PLINE_CODE = ?
   AND T.IS_SAMPLE_PIPE = '1'
   AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
   AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
	]]>
	</query>
	<query id = "FrmInOnlineStore.copyMatNo" desc = "赋值材料号">
	<![CDATA[
	DECLARE
  CURSOR OPOrder_Cursor IS
    SELECT MAT_NO
      FROM (SELECT MAT_NO
              FROM PORT_MIL_BATCH_SAMPLE_RESULT T
             WHERE T.JUDGE_STOVE_NO = ?
               AND T.BATCH_NO = ?
               AND ((TO_NUMBER(T.ORDER_LENGTH) -
                   TO_NUMBER(NVL(T.SAMPLE_PIPE_LEN, 0)) / 1000 = ? AND
                   NVL(T.RECUT_LENGTH, '0') = NVL('', '0')) OR
                   TO_NUMBER(T.RECUT_LENGTH) -
                   TO_NUMBER(NVL(T.SAMPLE_PIPE_LEN, 0)) / 1000 = ?)
               AND T.IS_SAMPLE_PIPE = ?
               AND T.STATUS = ?
               --AND T.INSTORE_FLAG = '0'
             ORDER BY T.MAT_NO ASC)
     WHERE ROWNUM <= ?;
  curOPOrder OPOrder_Cursor%RowType;
BEGIN
  open OPOrder_Cursor;
  LOOP
    fetch OPOrder_Cursor
      into curOPOrder;
    EXIT WHEN OPOrder_Cursor%NOTFOUND;
    UPDATE MAT_BC_M T
       SET T.ZG_MAT_NO = curOPOrder.MAT_NO
     WHERE T.ZG_STOVE_SQE = ?
       AND (T.BELONG_CODE = '002001016003' or T.BELONG_CODE = '002001017003' or T.BELONG_CODE = '002001016002' or T.BELONG_CODE = '002001018003')
       AND T.ZG_MAT_NO IS NULL
       AND ROWNUM = 1;
       --UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T SET T.INSTORE_FLAG = '1',T.GROUP_NO = ? WHERE T.MAT_NO = curOPOrder.MAT_NO;
  END LOOP;
  close OPOrder_Cursor;
END;
]]>
</query>
	<query id = "FrmInOnlineStore.insertMilInstore" desc = "插入交库实绩表">
	DECLARE
  V_COUNT          MIL_INSTORE_RESULT.QUALIFIED_NUM%TYPE := NULL;
  V_JUDGE_STOVE_NO MIL_INSTORE_RESULT.JUDGE_STOVE_NO%TYPE := ?;
  V_RESULT_NO      MIL_INSTORE_RESULT.RESULT_NO%TYPE := ?;
  V_PRO_PLAN_ID    MIL_INSTORE_RESULT.PRO_PLAN_ID%TYPE := ?;
  V_GX_PLAN_NO     MIL_INSTORE_RESULT.GX_PLAN_NO%TYPE := ?;
  V_ZERO_COUNT     NUMBER := 0;
BEGIN
  -- 先检查是否有0支0吨的记录
  SELECT COUNT(1)
    INTO V_ZERO_COUNT
    FROM MIL_INSTORE_RESULT T
   WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
     AND T.RESULT_NO = V_RESULT_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.QUALIFIED_NUM = 0
     AND T.QUALIFIED_TONS = 0
     and T.GX_PLAN_NO is null;
  
  -- 如果有0支0吨的记录，先删除
  IF (V_ZERO_COUNT > 0) THEN
    DELETE FROM MIL_INSTORE_RESULT T
     WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
       AND T.RESULT_NO = V_RESULT_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.QUALIFIED_NUM = 0
       AND T.QUALIFIED_TONS = 0
       and T.GX_PLAN_NO is null;
  END IF;

  -- 原有逻辑保持不变
  SELECT COUNT(1)
    INTO V_COUNT
    FROM MIL_INSTORE_RESULT T
   WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
     AND T.RESULT_NO = V_RESULT_NO
     AND NVL(T.PRO_PLAN_ID, '/') = NVL(V_PRO_PLAN_ID, '/')
     AND NVL(T.GX_PLAN_NO, '/') = NVL(V_GX_PLAN_NO, '/');
     
  IF (V_COUNT > 0) THEN
    UPDATE MIL_INSTORE_RESULT T
       SET T.QUALIFIED_NUM  = TO_NUMBER(NVL(T.QUALIFIED_NUM, 0)) +
                              TO_NUMBER(?),
           T.QUALIFIED_TONS = TO_NUMBER(NVL(T.QUALIFIED_TONS, 0)) +
                              TO_NUMBER(?)
     WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
       AND T.RESULT_NO = V_RESULT_NO
       AND NVL(T.PRO_PLAN_ID, '/') = NVL(V_PRO_PLAN_ID, '/')
       AND NVL(T.GX_PLAN_NO, '/') = NVL(V_GX_PLAN_NO, '/');
  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,
       START_TIME,
       PRO_PLAN_ID,
       GX_PLAN_NO)
    VALUES
      (?,
       ?,
       ?,
       ?,
       ?,
       '',
       '',
       ?,
       ?,
       ?,
       '',
       '',
       sysdate,
       V_PRO_PLAN_ID,
       V_GX_PLAN_NO);
  END IF;
END;
	</query>
	
	<query id = "FrmInOnlineStore.updateMilInstore" desc = "修改交库实绩表">
	<![CDATA[
	DECLARE
  V_COUNT          MIL_INSTORE_RESULT.QUALIFIED_NUM%TYPE := NULL;
  V_COUNT1         MIL_INSTORE_RESULT.QUALIFIED_NUM%TYPE := NULL;
  V_COUNT2         MIL_INSTORE_RESULT.QUALIFIED_NUM%TYPE := NULL;
  V_QUALIFIED_TONS MIL_INSTORE_RESULT.QUALIFIED_TONS%TYPE := NULL;
  V_JUDGE_STOVE_NO MIL_INSTORE_RESULT.JUDGE_STOVE_NO%TYPE := ?;
  V_RESULT_NO      MIL_INSTORE_RESULT.RESULT_NO%TYPE := ?;
BEGIN

  select MAX(SUBSTR(A.JUDGE_STOVE_NO, -1))
    INTO V_COUNT
    from PORT_MIL_BATCH_SAMPLE_RESULT A
   where A.PLAN_ID = V_RESULT_NO;

  SELECT COUNT(1)
    INTO V_COUNT1
    FROM PORT_MIL_BATCH_SAMPLE_RESULT A
   WHERE A.PLAN_ID = V_RESULT_NO
     AND A.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
     AND A.STATUS = '0';

  SELECT COUNT(1), SUM(B.ACT_WEIGHT)
    INTO V_COUNT2, V_QUALIFIED_TONS
    FROM MAT_BC_M B
   WHERE B.JUDGE_STOVE_NO = REGEXP_REPLACE(V_JUDGE_STOVE_NO, '-.*', '')
     AND B.MAT_GOWHERE_CODE IS NOT NULL
     AND B.QCM_STAUS = '00'
     AND B.PROCESS_CDOE = 'D';

  IF (V_COUNT = 1) THEN
    IF (V_COUNT1 = V_COUNT2) THEN
      UPDATE MIL_INSTORE_RESULT T
         SET T.QUALIFIED_NUM  = V_COUNT2,
             T.QUALIFIED_TONS = V_QUALIFIED_TONS
       WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
         AND T.RESULT_NO = V_RESULT_NO;
    END IF;
  END IF;
END;
]]>
	</query>
	
	<query id = "FrmInOnlineStore.updateMilInstore2" desc = "修改交库实绩表">
	<![CDATA[
	DECLARE
  V_COUNT2         MIL_INSTORE_RESULT.QUALIFIED_NUM%TYPE := NULL;
  V_QUALIFIED_TONS MIL_INSTORE_RESULT.QUALIFIED_TONS%TYPE := NULL;
  V_JUDGE_STOVE_NO MIL_INSTORE_RESULT.JUDGE_STOVE_NO%TYPE := ?;
  V_RESULT_NO      MIL_INSTORE_RESULT.RESULT_NO%TYPE := ?;
BEGIN

  SELECT SUM(ACOUT), SUM(AWEIGHT)
    INTO V_COUNT2, V_QUALIFIED_TONS
    FROM (SELECT SUM(B.ACT_COUNT) ACOUT, SUM(B.ACT_WEIGHT) AWEIGHT
          
            FROM MAT_BC_M B
           WHERE B.JUDGE_STOVE_NO =
                 REGEXP_REPLACE(V_JUDGE_STOVE_NO, '-.*', '')
             AND B.ZG_STOVE_SQE = V_JUDGE_STOVE_NO
             AND B.QCM_STAUS = '00'
             AND B.PROCESS_CDOE = 'D'
          UNION ALL
          SELECT SUM(B.ACT_COUNT) ACOUT, SUM(B.ACT_WEIGHT) AWEIGHT
          
            FROM MAT_BC_BACKUP B
           WHERE B.JUDGE_STOVE_NO =
                 REGEXP_REPLACE(V_JUDGE_STOVE_NO, '-.*', '')
             AND B.ZG_STOVE_SQE = V_JUDGE_STOVE_NO
             AND B.QCM_STAUS = '00'
             AND B.PROCESS_CDOE = 'D');

  UPDATE MIL_INSTORE_RESULT T
     SET T.QUALIFIED_NUM = V_COUNT2, T.QUALIFIED_TONS = V_QUALIFIED_TONS
   WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
     AND T.RESULT_NO = V_RESULT_NO;

END;
]]>
	</query>
	
	<query id = "FrmInOnlineStore.updateMilInstroe" desc = "撤销交库时修改实绩表数据">
	UPDATE MIL_INSTORE_RESULT T
       SET T.QUALIFIED_NUM  = TO_NUMBER(T.QUALIFIED_NUM) -
                              TO_NUMBER('#ACT_COUNT#'),
           T.QUALIFIED_TONS = TO_NUMBER(T.QUALIFIED_TONS) -
                              TO_NUMBER('#ACT_WEIGHT#'),
           T.NODE_FUR_FLAG  = '0'
     WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
	</query>
	<query id = "FrmInOnlineStore.updateMilInstroe1" desc = "撤销交库时修改实绩表数据">
	<![CDATA[
	DECLARE
V_COUNT MAT_BC_M.ACT_COUNT%TYPE := NULL;
V_WEIGHT MAT_BC_M.ACT_WEIGHT%TYPE :=NULL;
BEGIN
SELECT SUM(ACT_WEIGHT),SUM(ACT_COUNT)INTO V_WEIGHT,V_COUNT
  FROM (SELECT * FROM (SELECT *
          FROM MAT_BC_M T
         WHERE T.JUDGE_STOVE_NO = ?
           AND T.BATCH_NO = ?
           AND T.BATCH_GROUD_NO = ?
           AND T.ACT_LEN = ?
           AND T.QCM_STAUS = '00'
         ORDER BY T.MAT_NO DESC)
 WHERE ROWNUM <= ?);
 UPDATE MIL_INSTORE_RESULT T
       SET T.QUALIFIED_NUM  = TO_NUMBER(T.QUALIFIED_NUM) -
                              TO_NUMBER(V_COUNT),
           T.QUALIFIED_TONS = TO_NUMBER(T.QUALIFIED_TONS) -
                              TO_NUMBER(V_WEIGHT),
           T.NODE_FUR_FLAG  = '0'
     WHERE T.JUDGE_STOVE_NO = ?;
 END;
 ]]>
	</query>
	<query id = "FrmInOnlineStore.selectLenM" desc = "查询轧管转移长度">
	SELECT NVL(S.LEN_ROLL_MIN,0) AS LENGTHMIN,
       NVL(S.LEN_ROLL_MAX,0) AS LENGTHMAX,
       SUBSTR(T.LENGTH_RANGE, INSTR(T.LENGTH_RANGE, '-', -1, 1) + 1)ROLL_MAX,
       SUBSTR(T.LENGTH_RANGE, 0, INSTR(T.LENGTH_RANGE, '-', -1, 1) - 1) ROLL_MIN
  FROM MIL_PLAN T
  LEFT JOIN PLN_ORDER_ZG_S S ON SUBSTR(T.ORD_LN_DLY_PK,
                                       0,
                                       length(T.ORD_LN_DLY_PK) - 3) =
                                S.ORD_LN_DLY_PK
 WHERE T.ORD_LN_DLY_PK = ?
   AND ROWNUM = 1
	</query>
	<query id = "FrmInOnlineStore.doQueryNode" desc = "查询该炉是否已交库">
	<![CDATA[
	SELECT COUNT(1) ACOUNT
  FROM MIL_INSTORE_RESULT T
 WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = ?
   AND T.PLINE_CODE = ?
   AND T.NODE_FUR_FLAG = '0'
   AND (T.QUALIFIED_NUM > 0 OR T.OFFLINE_NUM > 0)
   ]]>
	</query>
	<query id = "FrmInOnlineStore.doQueryFApply" desc = "查询是否存在已申请判定数据">
	<![CDATA[
SELECT SUM(ACOUNT) ACOUNT
  FROM (SELECT COUNT(1) ACOUNT
          FROM MAT_BC_M T
         WHERE T.ZG_STOVE_SQE = ?
           AND T.PROCESS_CDOE = 'D'
           AND T.BATCH_NO <> 'X'
           AND T.JUGDE_APPLY_CODE IS NOT NULL
        
        UNION ALL
        
        SELECT COUNT(1) ACOUNT
          FROM MAT_BC_BACKUP T
         WHERE T.ZG_STOVE_SQE = ?
           AND T.PROCESS_CDOE = 'D'
           AND T.BATCH_NO <> 'X'
           AND T.JUGDE_APPLY_CODE IS NOT NULL)
           ]]>
	</query>
	
	<query id = "FrmInOnlineStore.doQueryFQY" desc = "查询是否有复取样废品">
	SELECT COUNT(1) ACOUNT
  FROM PORT_MIL_BATCH_SAMPLE_RESULT T
 WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = REGEXP_REPLACE(?, '-.*', '')
   AND T.STATUS = '2'
   AND T.OP_PROCESS = '14'
	</query>
	
	 <query id = "FrmInOnlineStore.insertZgMatNo" desc = "插入轧管材料号">
	DECLARE
  V_MAT_NO MAT_BC_M.MAT_NO%TYPE;
  CURSOR OPOrder_Cursor IS
    SELECT ROWNUM SEQ, MAT_NO,JUDGE_STOVE_NO
      from (SELECT T.SEQ, T.MAT_NO,T.JUDGE_STOVE_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.STATUS = '0'
             ORDER BY T.IS_SAMPLE_PIPE,T.SEQ ASC);
  curOPOrder OPOrder_Cursor%RowType;
BEGIN
  open OPOrder_Cursor;
  LOOP
    fetch OPOrder_Cursor
      into curOPOrder;
    EXIT WHEN OPOrder_Cursor%NOTFOUND;
    SELECT MAT_NO INTO V_MAT_NO FROM(
      SELECT ROWNUM SEQ,T.MAT_NO
        FROM MAT_BC_M T
       WHERE T.ZG_STOVE_SQE = curOPOrder.JUDGE_STOVE_NO
       AND T.QCM_STAUS = '00'
       ORDER BY T.SAMPLE_FLAG,T.MAT_NO ASC)WHERE SEQ = curOPOrder.SEQ ;
    UPDATE MAT_BC_M T
       SET T.ZG_MAT_NO = curOPOrder.MAT_NO
     WHERE T.ZG_STOVE_SQE = curOPOrder.JUDGE_STOVE_NO
     AND T.MAT_NO = V_MAT_NO;
  END LOOP;
  close OPOrder_Cursor;
END;
	</query> 
	
	<query id = "FrmInOnlineStore.insertZgMatNo2" desc = "交库时插入轧管材料号">
	<![CDATA[
	DECLARE
  V_JUDGE_STOVE_NO PORT_MIL_BATCH_SAMPLE_RESULT.JUDGE_STOVE_NO%type := ?;
  V_PRO_PLAN_ID    PORT_MIL_BATCH_SAMPLE_RESULT.PRO_PLAN_ID%type := ?;
  V_GX_PLAN_NO     PORT_MIL_BATCH_SAMPLE_RESULT.GX_PLAN_NO%type := ?;
BEGIN
  FOR MYROW IN (SELECT T.*
                  FROM PORT_MIL_BATCH_SAMPLE_RESULT T
                 WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
                   AND T.PRO_PLAN_ID = V_PRO_PLAN_ID
                   AND T.STATUS = '0'
                   AND T.INSTORE_FLAG = '1'
                   AND T.GX_PLAN_NO = V_GX_PLAN_NO) LOOP
    UPDATE MAT_BC_M T1
       SET T1.ZG_MAT_NO = MYROW.MAT_NO
     WHERE T1.ZG_STOVE_SQE = V_JUDGE_STOVE_NO
       AND T1.ZG_MAT_NO IS NULL
       AND ROWNUM = 1;
  END LOOP;
END;
	]]>
	</query> 
	
	 <!--<query id = "FrmInOnlineStore.insertZgMatNo" desc = "插入轧管材料号">
	<![CDATA[
	DECLARE
  V_JUDGE_STOVE_NO PORT_MIL_BATCH_SAMPLE_RESULT.JUDGE_STOVE_NO%TYPE := ?;
  V_MAT_NO         MAT_BC_M.MAT_NO%TYPE := NULL;
BEGIN

  FOR MYROW IN (SELECT T1.MAT_NO, T1.BATCH_NO, T1.JUDGE_STOVE_NO
                  FROM PORT_MIL_BATCH_SAMPLE_RESULT T1
                 WHERE T1.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
                   AND T1.STATUS = '0') LOOP
    SELECT MAT_NO
      INTO V_MAT_NO
      FROM (SELECT T.MAT_NO, ROWNUM
              FROM MAT_BC_M T
             WHERE T.JUDGE_STOVE_NO = SUBSTR(MYROW.JUDGE_STOVE_NO,1,6)
               AND T.BATCH_NO = MYROW.BATCH_NO
               AND T.ZG_MAT_NO IS NULL
             ORDER BY T.MAT_NO)
     WHERE ROWNUM = 1;
  
    UPDATE MAT_BC_M T
       SET T.ZG_MAT_NO = MYROW.MAT_NO
     WHERE T.ZG_STOVE_SQE = MYROW.JUDGE_STOVE_NO
       AND T.BATCH_NO = MYROW.BATCH_NO
       AND T.MAT_NO = V_MAT_NO;
  
  END LOOP;
END;
	]]>
	</query>-->
	
	<query id = "cancelPipeIn.doQueryNodeStaus" desc = "查询是否已结炉">
	SELECT T.NODE_FUR_FLAG FROM MIL_INSTORE_RESULT T WHERE T.JUDGE_STOVE_NO = ?
	</query>
	<query id = "FrmInOnlineStore.adjustWgt" desc = "调整理论重量">
	 UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T SET
 T.ACT_THEORY_WEIGHT = round(TO_NUMBER(?) * TO_NUMBER(T.ORDER_LENGTH),3)
 WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = ?
	</query>
	<query id = "FrmInOnlineStore.queryXMat" desc = "查询待处理库存信息">
	<![CDATA[
	SELECT T1.JUDGE_STOVE_NO,
       T1.BATCH_NO,
       T1.BATCH_GROUD_NO,
       T1.LOT_NO,
       T1.PRODUCCODE,
       T1.PRODUCNAME,
       T1.STEELCODE,
       T1.STEELNAME,
       T1.SPEC_CODE,
       T1.SPEC_NAME,
       T1.MODEL_CODE,
       T1.MODEL_DESC,
       T1.STD_CODE,
       T1.STD_NAME,
       T1.ORDER_NO,
       T1.ORDER_SEQ,
       T1.ORDER_SEQ_NO,
       T1.ACT_DIMATER,
       T1.ACT_HEIGHT,
       T1.BELONG_CODE,
       T1.BELONG_NAME,
       --T1.LEN_NO,
       T1.STD_STYLE,
       T1.STD_STYLE_DESC,
       T1.GRADECODE,
       T1.GRADENAME,
       T1.MATERIAL_NO,
       T1.MATERIAL_NAME,
      sum(T1.ACT_COUNT)
            ACT_COUNT,
            to_char(sum(T1.Act_Weight),'FM999999990.000')
           Act_Weight,
           to_char(sum(T1.ACT_THEORY_WEIGHT),'FM999999990.000')
           ACT_THEORY_WEIGHT,
       sum(nvl(T1.ACT_LEN,0)) as ACT_LEN,
       --T1.LEN_DESC,
       --T1.LEN_UNIT,
       to_char(T1.ACT_LEN_MIN,'FM999990.00') AS ACT_LEN_MIN,
       to_char(T1.ACT_LEN_MAX,'FM999990.00') AS ACT_LEN_MAX,
       --to_char(T1.ACT_LEN_MIN,'FM999990.00')||'-'||to_char(T1.ACT_LEN_MAX,'FM999990.00') as LEN,
       T1.CREATE_NAME,
       max(TO_CHAR(T1.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS')) CREATE_TIME,
       max(to_char(T1.INSTOCK_TIME,'YYYY-MM-DD')) INSTOCK_TIME,
       T2.STORAGE_NO,
       S.STORAGE_NAME,
       T1.MEMO,
       T1.PIPMEMO,
       T1.JUDGE_STD_DES,
       T1.JUDGE_STD_NAME,
       T1.PLINE_CODE,
       T1.PLINE_NAME,
       --T1.OLD_ORDER_NO,
       T1.MAT_STATUS,
       --T1.BAL_YEAR_MONTH,
       to_char(to_date(T1.BAL_YEAR_MONTH,'YYYY-MM'),'yyyy-MM') as BAL_YEAR_MONTH,
       T1.PRODUCT_FLAG,
       --T1.HEAT_PLAN_NO
       T1.FLAG_STOVE_NO_ZG
  FROM MAT_BC_M T1, YDM_BC_BUTTRESS T2
 LEFT JOIN ydm_bs_storage S ON S.STORAGE_NO=T2.STORAGE_NO
 WHERE T1.JUDGE_STOVE_NO = T2.JUDGE_STOVE_NO
   AND T1.BATCH_NO = T2.BATCH_NO
    AND T1.MAT_NO=T2.MAT_NO
  AND T1.JUDGE_STOVE_NO  || '&' LIKE ('%' || upper(?) || '%')
  AND T1.PLINE_CODE = ?
  AND (T1.QCM_STAUS = '11' OR (T1.QCM_STAUS = '22' AND T1.BATCH_NO = 'F'))
  ]]>
	</query>
	<query id = "FrmInOnlineStore.updateFlagStove" desc = "修改标识炉号">
	UPDATE MAT_BC_M T
   SET T.FLAG_STOVE_NO_ZG = ?
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.BATCH_NO = ?
   AND T.BATCH_GROUD_NO = ?
   AND (T.BELONG_CODE = '002001016003' or T.BELONG_CODE = '002001017003' or T.BELONG_CODE = '002001016002' or T.BELONG_CODE = '002001018003')
   AND T.QCM_STAUS = '11'
	</query>
	<query id = "FrmInOnlineStore.queryXOut" desc = "查询待处理出库记录">
	<![CDATA[
SELECT 
       to_char(to_date(t.BAL_YEAR_MONTH,'YYYY-MM'),'yyyy-MM') as BAL_YEAR_MONTH,
       
       T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       T.BATCH_GROUD_NO,
       T.MATERIAL_NO,
       T.MATERIAL_NAME,
       T.PRODUCCODE,
       T.PRODUCNAME,
       T.STD_CODE,
       T.STD_NAME,
       T.GRADECODE,
       T.GRADENAME,
       T.STEELCODE,
       T.STEELNAME,
       T.STD_STYLE,
       T.STD_STYLE_DESC,
       T.SPEC_CODE,
       T.SPEC_NAME,
       T.MODEL_CODE,
       T.MODEL_DESC,
       T.PRO_ORDER_NO,
       T.PLINE_CODE,
       T.PLINE_NAME,
       T.ACT_DIMATER,
       T.ACT_HEIGHT,
       T.ACT_LEN,
       T.ACT_LEN_MIN,
       T.ACT_LEN_MAX,
       sum(T.ACT_COUNT) ACT_COUNT,
       sum(T.ACT_WEIGHT)ACT_WEIGHT,
       sum(T.ACT_THEORY_WEIGHT)ACT_THEORY_WEIGHT,
       T.BELONG_CODE,
       T.BELONG_NAME,
       
       T.STORAGE_NO,
       
       max(TO_CHAR(T.OUTSTOCK_TIME, 'YYYY-MM-DD HH24:MI:SS')) OUTSTOCK_TIME,
       
       T.ORD_PK,
       T.ORD_LN_PK,
       T.ORD_LN_DLY_PK,
       
       T.ORDER_NO,
       T.ORDER_SEQ,
       T.DELIVERY_NO,
       T.JUDGE_STD_NAME,
       T.JUDGE_STD_CODE,
       T.PONDER_NO,
       sum(T.PONDER_GROSS_WT)PONDER_GROSS_WT,
       T.OUTSTOCK_PLAN_NO,
       T.OUTSTOCK_DOC,
       T.OUTSTOCK_TYPE_CODE,
       T.OUTSTOCK_TYPE_NAME,
       T.VEHICLE_NO,
       s.storage_name
 FROM YDM_BC_OUTLIST t,ydm_bs_storage s
 WHERE t.storage_no = s.storage_no
 AND T.JUDGE_STOVE_NO || '&' LIKE '%' || ? || '%'
 AND T.OUTSTOCK_DOC || '&' LIKE '%' || ? || '%'
 AND T.PLINE_CODE = ?
 AND T.OUTSTOCK_TYPE_CODE = '800803'
 AND T.BATCH_NO = 'X'
 ]]>
	</query>
	<query id = "FrmInOnlineStore.cancelOutList" desc = "撤销出库记录">
	<![CDATA[
	DECLARE
BEGIN
  FOR MYROW IN (SELECT * FROM (SELECT *
          FROM YDM_BC_OUTLIST T
         WHERE T.OUTSTOCK_DOC = ?
         ORDER BY T.MAT_NO DESC) WHERE ROWNUM <= ?)LOOP
      INSERT INTO YDM_GP_BUTTRESS(
        MAT_NO,
        LOT_NO,
        JUDGE_STOVE_NO,
        BATCH_NO,
        STORAGE_NO,
        LOCATION_NO,
        STORAGE_TYPE_NO,
        STORAGE_TYPE_NAME,
        DEPARTMENT_CODE,
        DEPARTMENT_DESC,
        MANAGEMENT_NO,
        MANAGEMENT_NAME,
        CREATE_NAME,
        CREATE_TIME,
        GROUD_NO)
 VALUES( 
        MYROW.MAT_NO,
        MYROW.LOT_NO,
        MYROW.JUDGE_STOVE_NO,
        MYROW.BATCH_NO,
        MYROW.STORAGE_NO,
        MYROW.LOCATION_NO,
        MYROW.STORAGE_TYPE_NO,
        MYROW.STORAGE_TYPE_NAME,
        MYROW.DEPARTMENT_CODE,
        MYROW.DEPARTMENT_DESC,
        MYROW.MANAGEMENT_NO,
        MYROW.MANAGEMENT_NAME,
        MYROW.CREATE_NAME,
        MYROW.OUTSTOCK_TIME,
        MYROW.BATCH_GROUD_NO);
        DELETE FROM YDM_BC_OUTLIST T WHERE T.MAT_NO = MYROW.MAT_NO;
        UPDATE MAT_BC_M T SET T.OUTSTOCK_DOC = '' WHERE T.MAT_NO = MYROW.MAT_NO;
     END LOOP;
 END;
 ]]>
	</query>
	<query id = "FrmInOnlineStore.updateChemResult" desc = "修改成分结果">
	UPDATE MAT_BC_M T
   SET T.CHEM_RESULT_CODE = ?
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.BELONG_NAME NOT IN ('100101', '100102', '100103')
	</query>
	<query id = "FrmInOnlineStore.updatePhyResult" desc = "修改理化结果">
	UPDATE MAT_BC_M T
   SET T.PHY_RESULT_CODE = ?
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.BATCH_NO = ?
   AND T.BELONG_CODE NOT IN ('100101', '100102', '100103')
	</query>
	<query id = "FrmInOnlineStore.doQueryResult" desc = "查询信息是否完整">
	SELECT COUNT(1)
  FROM MAT_BC_M T
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.BATCH_NO = ?
   AND T.BATCH_GROUD_NO = ?
   AND T.QCM_STAUS = '00'
   AND T.BELONG_CODE NOT IN ('100101', '100102', '100103')
   AND (T.CHEM_RESULT_CODE IS NULL OR T.PHY_RESULT_CODE IS NULL OR
       T.TESTING_GRADE IS NULL)
	</query>
	<query id = "FrmInOnlineStore.doQueryResult1" desc = "查询信息是否完整">
	SELECT COUNT(1)
  FROM MAT_BC_M T
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.BATCH_NO = ?
   AND T.BATCH_GROUD_NO = ?
   AND T.QCM_STAUS = '00'
   AND T.BELONG_CODE NOT IN ('100101', '100102', '100103')
   AND (T.CHEM_RESULT_CODE IS NULL OR
       T.TESTING_GRADE IS NULL)
	</query>
	<query id = "doQueryTestingResult.EMI" desc = "查询探伤实绩">
	SELECT T.*
  FROM MIL_MT_RESULT T
  LEFT JOIN MIL_OFFLINE_GROUP S ON T.JUDGE_STOVE_NO = S.ZP_M_LH
 WHERE S.ZP_JUDGE_STOVE_NO = ?
UNION ALL
SELECT T.* FROM MIL_MT_RESULT T WHERE T.JUDGE_STOVE_NO = ?
	</query>
	<query id = "doQueryTestingResult.ET" desc = "查询探伤实绩">
	SELECT T.*
  FROM MIL_ET_RESULT T
  LEFT JOIN MIL_OFFLINE_GROUP S ON T.JUDGE_STOVE_NO = S.ZP_M_LH
 WHERE S.ZP_JUDGE_STOVE_NO = ?
UNION ALL
SELECT T.* FROM MIL_ET_RESULT T WHERE T.JUDGE_STOVE_NO = ?
	</query>
	<query id = "FrmInOnlineStore.updateMatTestResult" desc = "修改探伤等级种类">
	UPDATE MAT_BC_M T
   SET T.TESTING_GRADE = ?, T.TESTING_TYPE = ?
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.BELONG_CODE NOT IN ('100101', '100102', '100103')
	</query>
	<query id = "FrmInOnlineStore.doQueryMilPlan" desc = "查询计划去向">
	<![CDATA[
	SELECT *
  FROM MIL_PLAN T
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.PRO_PLAN_ID || '&' LIKE '%' || ? || '%'
   AND T.GX_PLAN_NO || '&' LIKE '%' || ? || '%'
   ]]>
	</query>
	
	<query id = "FrmInOnlineStore.doQueryPortMilState" desc = "交库前验证：查进程表是否取样，材料表是否有样管交库">
	<![CDATA[
	  select sum(acount) acount, sum(acount2) acount2
  from (select nvl(count(1), 0) acount, 0 acount2
          from PORT_MIL_BATCH_SAMPLE_RESULT t
         WHERE T.JUDGE_STOVE_NO = ?
           and t.is_sample_pipe = '1'
           and nvl(t.pro_plan_id, '/') = nvl(?, '/')
           and nvl(t.gx_plan_no, '/') = nvl(?, '/')
        
        union all
        
        select 0 acount, nvl(sum(t.act_count), 0) acount2
          from MAT_BC_M t
         WHERE T.JUDGE_STOVE_NO = REGEXP_REPLACE(?, '-.*', '')
           and t.sample_flag = '1'
           and nvl(t.pro_order_id, '/') = nvl(?, '/')
           and nvl(t.gx_plan_no, '/') = nvl(?, '/'))
   ]]>
	</query>
	
	<query id = "FrmInOnlineStore.doQueryOrderAsk" desc = "查询附加要求">
	SELECT S.ASK_SUB_ITME_VAL_DESC ,S.ASK_ITME
  FROM PLN_SALEORD T
  LEFT JOIN SLM_ORDER_ADD_ASK S ON T.ADD_ASK_NO = S.ADD_ASK_NO
 WHERE T.ORDER_NO || '/' || T.ORDER_SEQ = ?
	</query>
	<query id = "FrmInOnlineStore.doUpdatePrn" desc = "修改过磅标识">
	UPDATE MIL_PLAN T SET T.PRT_FLAG = ? WHERE SUBSTR(T.JUDGE_STOVE_NO,1,6) = ?
	</query>
	<query id = "FrmInOnlineStore.doQueryMilPlanPrt" desc = "查询计划是否过磅">
	SELECT T.PRT_FLAG FROM MIL_PLAN T WHERE T.JUDGE_STOVE_NO = ?
	</query>
	<query id = "FrmInOnlineStore.doQueryWgt" desc = "获取对应支数重量">
	<![CDATA[
	SELECT NVL(SUM(T.ACT_THEORY_WEIGHT),0)ACT_WEIGHT
  FROM PORT_MIL_BATCH_SAMPLE_RESULT T
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.INSTORE_FLAG = '0'
   AND T.STATUS = ?
   AND T.IS_SAMPLE_PIPE = ?
   AND ROWNUM <= ?
   ]]>
	</query>
	<query id = "FrmInOnlineStore.doQueryThickDs" desc = "查询目标外径\控制壁厚">
	SELECT T.CONTROL_THICKP,NVL(S.AIMOUTDIAMETER,0)AIMOUTDIAMETER,T.VARIETIES,
	SUBSTR(T.PIPE_SIZE,0,INSTR(T.PIPE_SIZE,'*', -1, 1)-1)OUTDIAMETER
  FROM MIL_PLAN T LEFT JOIN PLN_ORDER_ZG_S S ON 
  SUBSTR(T.ORD_LN_DLY_PK,0,length(T.ORD_LN_DLY_PK)-3) = S.ORD_LN_DLY_PK
 WHERE T.JUDGE_STOVE_NO = ?
 AND ROWNUM = 1
	</query>
	<query id = "FrmInOnlineStore.selectOrderLnDiv" desc = "查询交货行信息">
	SELECT * FROM SLM_ORDER_LINE_DELIVERY T WHERE T.ORD_LN_DLY_PK = ?
	</query>
	<query id = "FrmInOnlineStore.selectIsDealer" desc = "查询是否双经销">
	SELECT DECODE(T.ORDER_TYP,'120108','1','120107','2','120109','3', '0') ORDER_TYP FROM SLM_ORDER_HEAD T WHERE T.ORD_PK  = ?
	</query>
	<query id = "FrmInOnlineStore.selectLengthMin" desc = "查询成品长度上下限">
	select t.* from PLN_SALEORD t where t.ord_ln_dly_pk = ?
	</query>
	<query id = "FrmInOnlineStore.selectMateriaCode" desc = "查询物料码">
	SELECT T.OUT_MATERIAL_NO FROM SLM_BASE_MATERIAL_D T WHERE T.OUT_MATERIAL_DESC = ?
	</query>
	<query id = "FrmInOnlineStore.selectActWeigth" desc = "查询单支重量">
	select T.ACT_THEORY_WEIGHT
  from PORT_MIL_BATCH_SAMPLE_RESULT t
 WHERE t.Judge_Stove_No = ?
   and t.pro_plan_id = ?
   and t.gx_plan_no = ?
   AND ROWNUM = 1
	</query>
	<query id = "FrmInOnlineStore.selectnextProcessCode" desc = "查询下工序代码">
		select t.next_process_code,
       t1.process_desc,
       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, com_base_pline t1
 where t.next_process_code = t1.process_code(+)
   and t.feed_heat_no = ?
   and t.pro_plan_id = ?
   and t.gx_plan_no = ?
 group by t.next_process_code,
          t1.process_desc,
          T.HEAT_PLAN_NO,
          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 = "FrmInOnlineStore.selectZPMateriaNo" 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.CIC,
          T.PIC,
          T.SIC,
          T.DIC,
          T.IF_PRODUCT,
          T.INWL_ID,
          T.INWL_DESC,
          T.OUTWL_ID,
          T.OUTWL_DESC,
          T.CRAFT_SEQ,
          T.GOWHERE_CODE,
          T.GOWHERE_NAME
	</query>
	
	<query id = "FrmInOnlineStore.selectZPMateriaNo2" desc = "查询组炉物料码">
		SELECT T.INWL_ID,
       T.INWL_DESC,
       T.OUTWL_ID,
       T.OUTWL_DESC,
       T.CIC_GP CIC,
       T.CRAFT_SEQ,
       CASE
         WHEN (SELECT COUNT(*) COUNT
                 FROM PLN_ORDER_ZG_S              T,
                      PLN_SALEORD                 T1,
                      CRAFT_ORD_DESIGN            M,
                      CRAFT_ORD_DESIGN_MSC_PL_STI C
                WHERE T1.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
                  AND M.ORD_LN_PK = T1.ORD_LN_PK
                  AND M.CRAFT_SEQ = T.CRAFT_SEQ
                  AND C.DESGIN_KEY = M.DESGIN_KEY
                  AND C.MSC_PLINE = T.INDEX_SEQ
                  AND C.STATION_TYPE = '403201'
                  AND C.PROCESS_CODE = 'D'
                  AND T.PRO_PLAN_ID = ?
                  AND T.GX_PLAN_NO = ?) > 0 THEN
          T.CIC_GP || '+' || SUBSTR(T.PIC, 0, 10) || '+' ||
          SUBSTR(T.SIC, 0, 10) || '+' || SUBSTR(T.DIC, 0, 10)
         ELSE
          SUBSTR(T.PIC, 0, 10) || '+' || SUBSTR(T.SIC, 0, 10) || '+' ||
          SUBSTR(T.DIC, 0, 10)
       END judgeStdDes
  FROM PLN_ORDER_ZG_S T
 where T.PRO_PLAN_ID = ?
   AND T.GX_PLAN_NO = ?
	</query>
	
	<query id = "FrmInOnlineStore.selectPlnZyDBK" desc = "查询镦拔扩炉计划">
		SELECT E.PRO_PLAN_ID, E.GX_PLAN_NO, E.PLN_OUTSINGLE_NUM,E.HEAT_PLAN_NO
  FROM pln_zy_zg_m T, PLN_ZY_DBK_M E
 WHERE E.UPPER_HEATPLAN_ID = T.HEAT_PLAN_NO
   AND t.feed_heat_no = ?
   and t.pro_plan_id = ?
   and t.gx_plan_no = ?
	</query>
	
	<query id = "FrmInOnlineStore.selectPlnZyRCL" desc = "查询热处理炉计划">
		SELECT F.PRO_PLAN_ID, F.GX_PLAN_NO, F.PLN_OUTSINGLE_NUM,F.HEAT_PLAN_NO
  FROM pln_zy_zg_m T, PLN_ZY_RCL_M F
 WHERE F.UPPER_HEATPLAN_ID = T.HEAT_PLAN_NO
   AND t.feed_heat_no = ?
   and t.pro_plan_id = ?
   and t.gx_plan_no = ?
	</query>
	
	<query id = "FrmInOnlineStore.selectPlnZyJGX" desc = "查询加工炉计划">
		SELECT G.PRO_PLAN_ID, G.GX_PLAN_NO, G.PLN_OUTSINGLE_NUM,G.HEAT_PLAN_NO
  FROM pln_zy_zg_m T, PLN_ZY_JGX_M G
 WHERE G.UPPER_HEATPLAN_ID = T.HEAT_PLAN_NO
   AND t.feed_heat_no = ?
   and t.pro_plan_id = ?
   and t.gx_plan_no = ?
	</query>
	
	<query id = "FrmInOnlineStore.updateNextProPlanID" desc = "修改材料表下工序订单编号">
	<![CDATA[
			DECLARE
  V_JUDGE_STOVE_NO MAT_BC_M.JUDGE_STOVE_NO%TYPE := ?;
  V_PLINE_CODE     MAT_BC_M.PLINE_CODE%TYPE := ?;
  V_PRO_ORDER_ID   MAT_BC_M.PRO_ORDER_ID%TYPE := ?;
  V_GX_PLAN_NO     MAT_BC_M.GX_PLAN_NO%TYPE := ?;
  V_ACT_COUNT      MAT_BC_M.ACT_COUNT%TYPE := ?; --支数,停用
BEGIN
  FOR MYROW IN --(SELECT * FROM 
   (SELECT T.MAT_NO, T.JUDGE_STOVE_NO
      FROM MAT_BC_M T
     WHERE T.PROCESS_CDOE = 'D'
       AND T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
       AND T.PLINE_CODE = V_PLINE_CODE
       AND NVL(T.PRO_ORDER_ID, '/') = NVL(V_PRO_ORDER_ID, '/')
       AND NVL(T.GX_PLAN_NO, '/') = NVL(V_GX_PLAN_NO, '/')
       AND T.PRO_PLAN_ID_NEXT IS NULL
     ORDER BY T.MAT_NO ASC)
  --WHERE ROWNUM <= V_ACT_COUNT)
   LOOP
  
    UPDATE MAT_BC_M T
       SET T.PRO_PLAN_ID_NEXT  = ?,
           T.GX_PLAN_NO_NEXT   = ?,
           T.NEXT_PROCESS_CDOE = ?,
           T.NEXT_PROCESS_DESC = ?,
           T.HEAT_PLAN_NO_NEXT = ?
     WHERE T.JUDGE_STOVE_NO = MYROW.JUDGE_STOVE_NO
       AND T.MAT_NO = MYROW.MAT_NO;
  END LOOP;
END;

		]]>
	</query>
	
	<query id = "FrmInOnlineStore.updateNextProcessCode" desc = "同步材料表下工序代码">
	<![CDATA[
		DECLARE
  V_JUDGE_STOVE_NO MAT_BC_M.JUDGE_STOVE_NO%TYPE := ?;
  V_PLINE_CODE     MAT_BC_M.PLINE_CODE%TYPE := ?;
  V_PRO_ORDER_ID   MAT_BC_M.PRO_ORDER_ID%TYPE := ?;
  V_GX_PLAN_NO     MAT_BC_M.GX_PLAN_NO%TYPE := ?;

BEGIN
  FOR MYROW IN (SELECT T.MAT_NO, T.JUDGE_STOVE_NO
                  FROM MAT_BC_M T
                 WHERE T.PROCESS_CDOE = 'D'
                   AND T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
                   AND T.PLINE_CODE = V_PLINE_CODE
                   AND NVL(T.PRO_ORDER_ID, '/') = NVL(V_PRO_ORDER_ID, '/')
                   AND NVL(T.GX_PLAN_NO, '/') = NVL(V_GX_PLAN_NO, '/')
                   AND (T.PRO_PLAN_ID_NEXT IS NULL OR
                       T.GX_PLAN_NO_NEXT IS NULL OR
                       T.NEXT_PROCESS_CDOE IS NULL OR
                       T.NEXT_PROCESS_DESC IS NULL)) LOOP
  
    UPDATE MAT_BC_M T
       SET T.PRO_PLAN_ID_NEXT  = '',
           T.GX_PLAN_NO_NEXT   = '',
           T.NEXT_PROCESS_CDOE = '',
           T.NEXT_PROCESS_DESC = ''
     WHERE T.JUDGE_STOVE_NO = MYROW.JUDGE_STOVE_NO
       AND T.MAT_NO = MYROW.MAT_NO;
  END LOOP;
END;
		]]>
	</query>
	
	<query id = "FrmInOnlineStore.doQueryOfflineCount" desc = "查询是否存在待处理品">
	<![CDATA[
	SELECT * FROM PORT_MIL_BATCH_SAMPLE_RESULT T WHERE T.STATUS = '3' AND T.JUDGE_STOVE_NO || '&' LIKE '%' || ? || '%' 
	]]>
	</query>
	<query id = "FrmInOnlineStore.doQueryZgJugdeCount" desc = "查询申请判定表是否存在同炉同合同">
		SELECT NVL(SUM(T.ACT_COUNT),0) ACT_COUNT
	  FROM QCM_ZG_JUGDE_APPLY T
	 WHERE T.JUDGE_STOVE_NO = ?
	   AND T.PRO_ORDER_NO = ?
	   AND T.IS_FLAG = '0'
	</query>
	<query id = "FrmInOnlineStore.doQueryZgContratNo" desc = "查询工序合同号">
	SELECT T.CONTRACT_NO FROM MIL_PLAN T WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = ?
	</query>
	<query id = "FrmInOnlineStore.doQueryZgPrtFlag" desc = "查询是否过磅">
	SELECT T.PRT_FLAG FROM MIL_PLAN T WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = ?
	</query>
	<query id = "FrmInOnlineStore.doQueryZgPonderGrossWT" desc = "查询过磅重量">
	SELECT NVL(SUM(T.PONDER_GROSS_WT), 0) PONDER_GROSS_WT
  FROM MAT_BC_M t
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.PROCESS_CDOE = 'D'
	</query>
	<query id = "FrmInOnlineStore.getTestGrade" desc = "查询超声探伤等级">
	SELECT T.BASENAME,T.BASECODE FROM COM_BASE_INFO T WHERE T.SORTCODE LIKE '%4022%'
	</query>
	<query id = "FrmInOnlineStore.updateQuXiang" desc = "调整库去向">
		 UPDATE MAT_BC_M t
	   SET T.MAT_GOWHERE_CODE = ?, T.MAT_GOWHERE_NAME = ?
	 WHERE T.JUDGE_STOVE_NO = ?
	   AND T.LOT_NO = ?
	   AND T.PLINE_CODE = ?
	</query>
	<query id = "FrmInOnlineStore.updateInputWt" desc = "调整投料量">
		 DECLARE
  V_JUGDE_APPLY_CODE    QCM_ZG_JUGDE_APPLY.JUGDE_APPLY_CODE%type := ?;
  V_JUGDE_APPLY_SEQUENO QCM_ZG_JUGDE_APPLY.JUGDE_APPLY_SEQUENO%type := ?;
  V_JUDGE_STOVE_NO      QCM_ZG_JUGDE_APPLY.JUDGE_STOVE_NO%type := ?;
  V_BATCH_NO            QCM_ZG_JUGDE_APPLY.BATCH_NO%type := ?;
  V_BATCH_GROUD_NO      QCM_ZG_JUGDE_APPLY.BATCH_GROUD_NO%type := ?;
  V_INPUT_COUNT         QCM_ZG_JUGDE_APPLY.INPUT_COUNT%type := ?;
  V_INPUT_WEIGHT        QCM_ZG_JUGDE_APPLY.INPUT_WEIGHT%type := ?;
  V_COL_NAME            QCM_ZG_JUDGE_INPUT_RECORD.COL_NAME%type := ?;
BEGIN
  FOR MYROW IN (SELECT *
                  FROM QCM_ZG_JUGDE_APPLY T
                 WHERE T.JUGDE_APPLY_CODE = V_JUGDE_APPLY_CODE
                   AND T.JUGDE_APPLY_SEQUENO = V_JUGDE_APPLY_SEQUENO
                   AND T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
                   AND T.BATCH_NO = V_BATCH_NO
                   AND T.BATCH_GROUD_NO = V_BATCH_GROUD_NO) LOOP
    INSERT INTO QCM_ZG_JUDGE_INPUT_RECORD
      (JUGDE_APPLY_CODE,
       JUDGE_STOVE_NO,
       BATCH_NO,
       BATCH_GROUD_NO,
       PROCESS_CODE,
       PLINE_CODE,
       ACT_COUNT,
       ACT_WEIGHT,
       ACT_THEORY_WEIGHT,
       INPUT_WEIGHT,
       INPUT_COUNT,
       INPUT_WEIGHT2,
       INPUT_COUNT2,
       BAL_YEAR_MONTH,
       JUGDE_APPLY_SEQUENO,
       COL_NAME,
       COL_TIME,
       PLINE_NAME,
       QUALITY_GROUP,
       MAT_GOWHERE_CODE,
       MAT_GOWHERE_NAME)
    VALUES
      (MYROW.JUGDE_APPLY_CODE,
       MYROW.JUDGE_STOVE_NO,
       MYROW.BATCH_NO,
       MYROW.BATCH_GROUD_NO,
       MYROW.PROCESS_CODE,
       MYROW.PLINE_CODE,
       MYROW.ACT_COUNT,
       MYROW.ACT_WEIGHT,
       MYROW.ACT_THEORY_WEIGHT,
       MYROW.INPUT_WEIGHT,
       MYROW.INPUT_COUNT,
       V_INPUT_WEIGHT,
       V_INPUT_COUNT,
       MYROW.BAL_YEAR_MONTH,
       MYROW.JUGDE_APPLY_SEQUENO,
       V_COL_NAME,
       SYSDATE,
       MYROW.PLINE_NAME,
       MYROW.QUALITY_GROUP,
       MYROW.MAT_GOWHERE_CODE,
       MYROW.MAT_GOWHERE_NAME);
  
    UPDATE QCM_ZG_JUGDE_APPLY T
       SET T.INPUT_COUNT   = V_INPUT_COUNT,
           T.OUTPUT_COUNT  = V_INPUT_COUNT,
           T.INPUT_WEIGHT  = V_INPUT_WEIGHT,
           T.OUTPUT_WEIGHT = V_INPUT_WEIGHT
     WHERE T.JUGDE_APPLY_CODE = V_JUGDE_APPLY_CODE
       AND T.JUGDE_APPLY_SEQUENO = V_JUGDE_APPLY_SEQUENO
       AND T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
       AND T.BATCH_NO = V_BATCH_NO
       AND T.BATCH_GROUD_NO = V_BATCH_GROUD_NO;
  END LOOP;
END;
	</query>
	<query id = "FrmInOnlineStore.doQueryEntrustT" desc = "查询委外超声探伤等级">
	SELECT T.UL_TESTING
  FROM MIL_ENTRUSTED_BILL T
 WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = ?
   AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
   AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
	</query>
	<query id = "FrmInOnlineStore.doQueryPortSlample" desc = "查询样管是否已交库">
	
	</query>
	<query id = "FrmInOnlineStore.SelectETResult" desc = "查询涡流探伤级别">
	SELECT T.ACCEPTANCE_GRADE    AS TEST_GRADE,
       T.INSPECTION_STANDARD AS TESTING_STANDAR,
       T.NOTCH_INFO,
       T.NOTCH_LENGTH,
       T.NOTCH_WIDTH,
       T.NOTCH_DEPTH
  FROM MIL_ET_RESULT T
 WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = ?
   AND ROWNUM = 1
UNION ALL (SELECT T.ACCEPTANCE_GRADE    AS TEST_GRADE,
                  T.INSPECTION_STANDARD AS TESTING_STANDAR,
                  T.NOTCH_INFO,
                  T.NOTCH_LENGTH,
                  T.NOTCH_WIDTH,
                  T.NOTCH_DEPTH
             FROM MIL_ET_RESULT T, MIL_OFFLINE_RESLUT S
            WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = REGEXP_REPLACE(S.Zp_m_Lh, '-.*', '')
              AND REGEXP_REPLACE(S.JUDGE_STOVE_NO, '-.*', '') = ?
              AND ROWNUM = 1)
	</query>
	<query id = "FrmInOnlineStore.SelectMTResult" desc = "查询涡流探伤级别">
	SELECT T.LO_SURFACE          AS TEST_GRADE,
       T.INSPECTION_STANDARD AS TESTING_STANDAR,
       T.NOTCH_INFO,
       T.NOTCH_LENGTH,
       T.NOTCH_WIDTH,
       T.NOTCH_DEPTH
  FROM MIL_MT_RESULT T
 WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = ?
   AND ROWNUM = 1
UNION ALL (SELECT T.LO_SURFACE          AS TEST_GRADE,
                  T.INSPECTION_STANDARD AS TESTING_STANDAR,
                  T.NOTCH_INFO,
                  T.NOTCH_LENGTH,
                  T.NOTCH_WIDTH,
                  T.NOTCH_DEPTH
             FROM MIL_MT_RESULT T, MIL_OFFLINE_RESLUT S
            WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = REGEXP_REPLACE(S.Zp_m_Lh, '-.*', '')
              AND REGEXP_REPLACE(S.JUDGE_STOVE_NO, '-.*', '') = ?
              AND ROWNUM = 1)
	</query>
	<query id = "FrmInOnlineStore.SelectEntrBillResult" desc = "查询委托探伤类别 等级">
	SELECT NVL(T.TESTING_TYPE,'')TESTING_TYPE,NVL(T.TESTING_GRADE,'')TESTING_GRADE FROM HTT_ENTRUST_RESULT T WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = ?
	</query>
	<query id = "FrmInOnlineStore.SelectMilInStore" desc = "查询该炉在下线点是否结炉">
	SELECT COUNT(1) AS ACOUNT FROM MIL_INSTORE_RESULT T WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = ? AND T.NODE_FUR_FLAG = '0'
	</query>
	<query id = "FrmInOnlineStore.updateTarget" desc = "修改去向">
	UPDATE MAT_BC_M T SET T.TARGET = ?,T.PRODUCT_FLAG = ?,T.MAT_STATUS = ? WHERE T.JUDGE_STOVE_NO = ?
	</query>
	<query id = "FrmInOnlineStore.SelectQcmAppleJuge" desc = "查询该炉是否有已判定">
	SELECT NVL(COUNT(1),0)ACOUNT FROM QCM_ZG_JUGDE_APPLY T WHERE T.JUDGE_STOVE_NO = ? AND T.IS_FLAG = '0'
	</query>
	<query id = "FrmInOnlineStore.doQueryMilInstoreResultNode" desc = "查询该炉是否都结炉">
	SELECT COUNT(1)AS ACOUNT FROM MIL_INSTORE_RESULT T WHERE T.NODE_FUR_FLAG = '0' AND REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = ? AND (T.QUALIFIED_NUM > 0 OR T.OFFLINE_NUM > 0)
	</query>
	<query id = "FrmInOnlineStore.doQueryIsCarryVoer" desc = "查询该炉批是否结转">
		SELECT COUNT(1) AS ACOUNT
	  FROM QCM_ZG_JUGDE_APPLY T
	 WHERE T.IS_CARRY_VOER = '1'
	   AND T.JUGDE_APPLY_CODE = ?
	   AND T.JUGDE_APPLY_SEQUENO = ?
	   AND T.JUDGE_STOVE_NO = ?
	   AND T.BATCH_NO = ?
	   AND T.BATCH_GROUD_NO = ?
	</query>
	<query id = "FrmInOnlineStore.QueryZgApplyInputRecord" desc = "查询投料量调整记录">
		SELECT T.*
  FROM QCM_ZG_JUDGE_INPUT_RECORD T
 WHERE T.JUGDE_APPLY_CODE = ?
   AND T.JUGDE_APPLY_SEQUENO = ?
   AND T.JUDGE_STOVE_NO = ?
   AND T.BATCH_NO = ?
   AND T.BATCH_GROUD_NO = ?
 ORDER BY T.COL_TIME
	</query>
	<query id = "FrmInOnlineStore.selectMilPlanBackPlan" desc = "查询返线标识">
	SELECT T.BACK_PLAN_FLAG FROM MIL_PLAN T WHERE T.JUDGE_STOVE_NO = ?
	</query>
    <query id = "FrmInOnlineStore.updateGroupNo" desc = "结炉写组号，结转年月">
    DECLARE
  V_GROUP_NO PORT_MIL_BATCH_SAMPLE_RESULT.GROUP_NO%TYPE := NULL;
BEGIN
  FOR MYROW IN (SELECT T.MAT_NO, T.JUDGE_STOVE_NO
                  FROM PORT_MIL_BATCH_SAMPLE_RESULT T
                 WHERE T.STATUS = '0'
                   AND T.JUDGE_STOVE_NO = ?
                   AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
         		   AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
                 ORDER BY T.MAT_NO ASC) LOOP
    SELECT T.BATCH_GROUD_NO
      INTO V_GROUP_NO
      FROM MAT_BC_M T
     WHERE T.ZG_STOVE_SQE = MYROW.JUDGE_STOVE_NO
       AND T.ZG_MAT_NO = MYROW.MAT_NO
       AND T.PROCESS_CDOE = 'D'
       AND ROWNUM = 1;
  
    UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T
       SET T.GROUP_NO = V_GROUP_NO
     WHERE T.JUDGE_STOVE_NO = MYROW.JUDGE_STOVE_NO
       AND T.MAT_NO = MYROW.MAT_NO;
  END LOOP;
  --UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T SET T.BAL_YEAR_MONTH = ? WHERE T.JUDGE_STOVE_NO = ?;
  
END;
    </query>
    <query id = "FrmInOnlineStore.doQueryPortCount" desc = "查询进程表合格支数">
    SELECT NVL(COUNT(1),0)ACOUNT FROM PORT_MIL_BATCH_SAMPLE_RESULT T WHERE T.JUDGE_STOVE_NO = ? AND T.LOT_NO = ? AND T.PLAN_ID = ? AND T.STATUS = '0'
    </query>
    <query id = "FrmInOnlineStore.doQueryPipeCount" desc = "查询已交库支数">
    <![CDATA[
    SELECT SUM(ACOUNT) ACOUNT
  FROM (SELECT NVL(SUM(T.ACT_COUNT), 0) ACOUNT
          FROM MAT_BC_M T
         WHERE T.ZG_STOVE_SQE = ?
           AND T.LOT_NO = ?
           AND T.BATCH_NO <> 'X'
              --AND T.HEAT_PLAN_NO = ?
           AND T.QCM_STAUS = '00'
           AND T.PROCESS_CDOE = 'D'
        
        UNION ALL
        
        SELECT NVL(SUM(T.ACT_COUNT), 0) ACOUNT
          FROM MAT_BC_BACKUP T
         WHERE T.ZG_STOVE_SQE = ?
           AND T.LOT_NO = ?
           AND T.BATCH_NO <> 'X'
              --AND T.HEAT_PLAN_NO = ?
           AND T.QCM_STAUS = '00'
           AND T.PROCESS_CDOE = 'D')
             ]]>
    </query>
    <query id = "FrmInOnlineStore.selectSurfaceToInStore" desc = "比对质检支数和缴库支数">
    SELECT NVL(T.QUALIFIED_BRANCH,0) - NVL(S.QUALIFIED_NUM,0) - NVL(S.OFFLINE_NUM,0) - NVL(S.SCRAP_NUM,0) AS ACOUNT
  FROM MIL_SURFACE_RESULT T
  LEFT JOIN MIL_INSTORE_RESULT S ON T.JUDGE_STOVE_NO = S.JUDGE_STOVE_NO
  WHERE T.JUDGE_STOVE_NO = ?
    </query>
    <query id = "FrmInOnlineStore.SelectMilInstore" desc = "查询是否已开始交库">
    SELECT NVL(COUNT(1),0)ACOUNT FROM MIL_INSTORE_RESULT T WHERE T.JUDGE_STOVE_NO = ?
    </query>
    <query id = "FrmInOnlineStore.updatePortStaus" desc = "结炉时处理交库点离线数据状态">
    <![CDATA[
    DECLARE
  V_OFFLINE_NUM MIL_INSTORE_RESULT.OFFLINE_NUM%TYPE := NULL;
  V_SCRAP_NUM   MIL_INSTORE_RESULT.SCRAP_NUM%TYPE := NULL;
BEGIN
  SELECT NVL(SUM(T.OFFLINE_NUM), 0), NVL(SUM(T.SCRAP_NUM), 0)
    INTO V_OFFLINE_NUM, V_SCRAP_NUM
    FROM MIL_INSTORE_RESULT T
   WHERE T.JUDGE_STOVE_NO = ?
     AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
     AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/');
  FOR MYROW IN (SELECT *
                  FROM (SELECT T.MAT_NO, T.JUDGE_STOVE_NO
                          FROM PORT_MIL_BATCH_SAMPLE_RESULT T
                         WHERE T.STATUS = '0'
                           AND T.JUDGE_STOVE_NO = ?
                           AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
                           AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
                         ORDER BY T.IS_SAMPLE_PIPE, T.MAT_NO ASC)
                 WHERE ROWNUM <= V_OFFLINE_NUM) LOOP
    UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T
       SET T.STATUS = '3', T.OP_PROCESS = '12'
     WHERE T.JUDGE_STOVE_NO = MYROW.JUDGE_STOVE_NO
       AND T.MAT_NO = MYROW.MAT_NO;
  END LOOP;

  FOR MYROW1 IN (SELECT *
                   FROM (SELECT T.MAT_NO, T.JUDGE_STOVE_NO
                           FROM PORT_MIL_BATCH_SAMPLE_RESULT T
                          WHERE T.STATUS = '0'
                            AND T.JUDGE_STOVE_NO = ?
                            AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
                            AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
                          ORDER BY T.IS_SAMPLE_PIPE, T.MAT_NO ASC)
                  WHERE ROWNUM <= V_SCRAP_NUM) LOOP
    UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T
       SET T.STATUS = '2', T.OP_PROCESS = '12'
     WHERE T.JUDGE_STOVE_NO = MYROW1.JUDGE_STOVE_NO
       AND T.MAT_NO = MYROW1.MAT_NO;
  END LOOP;
END;
  ]]>
    </query>
    <query id = "FrmInOnlineStore.doQueryPipeLXCount" desc = "查询交库点已离线支数">
    SELECT NVL(SUM(T.OFFLINE_NUM),0)OFFLINE_NUM FROM MIL_INSTORE_RESULT T WHERE T.RESULT_NO = ? AND T.JUDGE_STOVE_NO = ?
    </query>
    <query id = "doDecision.SelectExitTemp" desc = "查询定径工序终轧温度">
    SELECT T.EXIT_TEMP
  FROM MIL_SIZING_RESULT T
 WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = ?
UNION ALL
SELECT S1.EXIT_TEMP
  FROM MIL_OFFLINE_RESLUT S
  LEFT JOIN MIL_SIZING_RESULT S1
    ON REGEXP_REPLACE(S.ZP_M_LH, '-.*', '') = REGEXP_REPLACE(S1.JUDGE_STOVE_NO, '-.*', '')
 WHERE REGEXP_REPLACE(S.JUDGE_STOVE_NO, '-.*', '') = ?
   AND S.ZP_M_LH IS NOT NULL
    </query>
    <query id = "doDecision.SelectSampleNews" desc = "查询样管信息">
    SELECT T.REMARK AS SAMPLE_NEWS
  FROM MIL_MT_RESULT T
 WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = ?
UNION ALL
SELECT S1.REMARK AS SAMPLE_NEWS
  FROM MIL_OFFLINE_RESLUT S
  LEFT JOIN MIL_MT_RESULT S1 ON S.ZP_M_LH = S1.JUDGE_STOVE_NO
  WHERE REGEXP_REPLACE(S.JUDGE_STOVE_NO, '-.*', '') = ?
  AND S.ZP_M_LH IS NOT NULL
UNION ALL
SELECT F.SAMPLE_NEWS
  FROM MIL_ET_RESULT F
 WHERE REPLACE(F.JUDGE_STOVE_NO, '-.*', '') = ?
UNION ALL
SELECT S1.SAMPLE_NEWS
  FROM MIL_OFFLINE_RESLUT S
  LEFT JOIN MIL_ET_RESULT S1 ON S.ZP_M_LH = S1.JUDGE_STOVE_NO
  WHERE REGEXP_REPLACE(S.JUDGE_STOVE_NO, '-.*', '') = ?
  AND S.ZP_M_LH IS NOT NULL
    </query>
    <query id = "doDecision.SelectLoFace" desc = "查询表面方向">
    SELECT T.LO_SURFACE,T.LI_SURFACE,T.TO_SURFACE,T.TI_SURFACE 
  FROM MIL_MT_RESULT T
 WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = ?
UNION ALL
SELECT T.LO_SURFACE,T.LI_SURFACE,T.TO_SURFACE,T.TI_SURFACE
  FROM MIL_OFFLINE_RESLUT S
  LEFT JOIN MIL_MT_RESULT T ON S.ZP_M_LH = T.JUDGE_STOVE_NO
  WHERE REGEXP_REPLACE(S.JUDGE_STOVE_NO, '-.*', '') = ?
  AND S.ZP_M_LH IS NOT NULL
    </query>
    <query id = "FrmInOnlineStore.selectSawNumW" desc = "查询外委分切数">
	<![CDATA[
		SELECT NVL(MAX(T.SUBCONTRACT_COMPLETE_CUT), 1) SUBCONTRACT_COMPLETE_CUT
  FROM MIL_OFFLINE_RESLUT T
 WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = ?
   AND T.PLINE_CODE = ?
	]]>
	</query>
    <query id = "FrmInOnlineStore.selectActcount" desc = "查询可交库支数（按批）">
	<![CDATA[
		SELECT NVL(SUM(T.ACT_COUNT), 0) -
       NVL((SELECT SUM(M.ACT_COUNT)
             FROM MAT_BC_M M
            WHERE 1 = 1
              AND M.JUDGE_STOVE_NO = ?
              AND M.BATCH_NO = T.BATCH_NO
              AND M.SAMPLE_FLAG = T.IS_SAMPLE_PIPE
              AND M.ZG_STOVE_SQE = T.JUDGE_STOVE_NO
              AND M.PLINE_CODE = T.PLINE_CODE),
           0) ACT_COUNT
  FROM PORT_MIL_BATCH_SAMPLE_RESULT T
 WHERE /*T.STATUS = '0'
     AND REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = ?*/
 T.JUDGE_STOVE_NO = ? --|| '-01'
 AND T.BATCH_NO = ?
 AND T.IS_SAMPLE_PIPE = ?
 AND T.PLINE_CODE = ?
 GROUP BY ACT_COUNT, T.JUDGE_STOVE_NO,T.BATCH_NO, T.IS_SAMPLE_PIPE, T.PLINE_CODE
	]]>
	</query>
	<query id = "FrmInOnlineStore.doQueryJugeMemo" desc = "查询管捆信息">
	SELECT T.MEMO FROM QCM_ZG_JUGDE_APPLY T WHERE T.JUDGE_STOVE_NO = ? AND ROWNUM = 1
	</query>
	<query id = "FrmInOnlineStore.SelectInital" desc = "查询是否已存在下月期初">
<![CDATA[
SELECT COUNT(1)ACOUNT FROM YDM_ZC_INITIAL_ZG T WHERE T.BAL_YEAR_MONTH = ? AND T.BELONG_CODE || '&' LIKE (upper(?) || '%')
]]>
</query>
<query id = "doDecision.SelectOfflineNum" desc = "查询是否有离线支">
SELECT COUNT(1)ACOUNT FROM MIL_OFFLINE_RESLUT T WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = ?
</query>
<query id = "doDecision.SelectBalance1" desc = "平衡1">
SELECT SUM(ACT_COUNT) ACOUNT
    FROM (SELECT NVL(SUM(T.ACT_COUNT), 0) ACT_COUNT
            FROM PORT_MIL_BATCH_SAMPLE_RESULT T
           WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = ?
             AND T.STATUS != '3'
             AND T.STATUS != '4'
          UNION ALL
          SELECT -1 * NVL(SUM(T.ACT_COUNT), 0) ACT_COUNT
            FROM PORT_MIL_BATCH_SAMPLE_RESULT T
           WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = ?
             AND T.STATUS IN ('1', '2', '5')
             AND T.OP_PROCESS != '14'
          UNION ALL
          SELECT -1 * NVL(SUM(T.ACT_COUNT), 0) ACT_COUNT
            FROM PORT_MIL_BATCH_SAMPLE_RESULT T
           WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = ?
             AND T.STATUS IN ('7')
          UNION ALL
          SELECT -1 * NVL(SUM(S.QUALIFIED_NUM), 0) ACT_COUNT
            FROM MIL_INSTORE_RESULT S
           WHERE REGEXP_REPLACE(S.JUDGE_STOVE_NO, '-.*', '') = ?)
</query>
<query id = "doDecision.SelectOfflineNum1" desc = "查询是否存在离线待处理支">
SELECT COUNT(1)ACOUNT FROM MIL_OFFLINE_RESLUT T WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = ? AND T.STATUS = '0'
</query>
<query id = "doDecision.SelectBalance2" des = "平衡2">
SELECT SUM(ACOUNT) ACOUNT
  FROM (
       --预计生产支
       SELECT NVL(SUM(T.ACT_COUNT), 0) ACOUNT
          FROM PORT_MIL_BATCH_SAMPLE_RESULT T
         WHERE T.JUDGE_STOVE_NO = ?||'-01'
        UNION ALL
        --剔除废
        SELECT -1*NVL(SUM(T.ACT_COUNT), 0) ACOUNT
          FROM PORT_MIL_BATCH_SAMPLE_RESULT T
         WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = ?
           AND T.STATUS IN ('1', '2', '5')
           AND T.OP_PROCESS != '14'
        UNION ALL
        --委外废
        SELECT -1*NVL(SUM(T.ACT_COUNT), 0) ACOUNT
          FROM PORT_MIL_BATCH_SAMPLE_RESULT T
         WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = ?
         AND T.STATUS = '6'
         UNION ALL
         --离线支,转压库
         SELECT -1*NVL(SUM(T.ACT_COUNT),0)ACOUNT
         FROM PORT_MIL_BATCH_SAMPLE_RESULT T
         WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = ?
         AND T.STATUS IN('3','4','7')
         UNION ALL
         --返线支
         SELECT NVL(SUM(T.ACT_COUNT),0)ACOUNT
         FROM PORT_MIL_BATCH_SAMPLE_RESULT T
         WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = ?
         AND T.STATUS = '4'
         union all
         --组炉返线支
         SELECT -NVL(SUM(T.ACT_COUNT),0)ACOUNT
         FROM PORT_MIL_BATCH_SAMPLE_RESULT T
         WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = ?
         AND T.STATUS = '4'
         AND T.GROUP_FLAG = '1'
         union all
         --交库支
         SELECT -1*NVL(SUM(S.QUALIFIED_NUM),0) ACOUNT FROM 
         MIL_INSTORE_RESULT S WHERE REGEXP_REPLACE(S.JUDGE_STOVE_NO, '-.*', '') = ?
         )
</query>
<query id = "doDecision.SelectBalance3" desc = "平衡3">
SELECT SUM(ACOUNT) ACOUNT
  FROM (
       --预计生产支
       SELECT NVL(SUM(T.ACT_COUNT), 0) ACOUNT
          FROM PORT_MIL_BATCH_SAMPLE_RESULT T
         WHERE T.JUDGE_STOVE_NO = ?||'-01'
         AND T.GROUP_FLAG = '0'
        UNION ALL
        --剔除废
        SELECT -1*NVL(SUM(T.ACT_COUNT), 0) ACOUNT
          FROM PORT_MIL_BATCH_SAMPLE_RESULT T
         WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = ?
           AND T.STATUS IN ('1', '2', '5', '6')
           AND T.OP_PROCESS != '14'
         UNION ALL
         --离线支,转压库
         SELECT -1*NVL(SUM(T.ACT_COUNT),0)ACOUNT
         FROM PORT_MIL_BATCH_SAMPLE_RESULT T
         WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = ?
         AND T.STATUS IN( '3','7')
         UNION ALL
         --交库支
         SELECT -1*NVL(SUM(S.QUALIFIED_NUM),0) ACOUNT FROM 
         MIL_INSTORE_RESULT S WHERE REGEXP_REPLACE(S.JUDGE_STOVE_NO, '-.*', '') = ?
         )
</query>

<query id = "cancelPipeIn.doQueryOutStock" desc = "查询该炉未发运的支数">
<![CDATA[
SELECT COUNT(1) ACT_COUNT
  FROM MAT_BC_M T, YDM_BC_INLIST S
 WHERE T.MAT_NO = S.MAT_NO
   AND S.ZG_STOVE_SQE = ?
   AND T.BATCH_NO = ?
   AND T.BATCH_GROUD_NO = ?
   AND TO_NUMBER(T.ACT_LEN) = to_number(?)
   AND T.OUTSTOCK_DOC IS NULL
   AND T.QCM_STAUS = ?
   AND S.INSTOCK_DOC = ?
   AND T.SAMPLE_FLAG = ?                  
]]>
</query>
<query id = "doDecision.SelectOrderSlaOrg" desc= "查询合同所属部门">
SELECT S.SALE_ORG, S.SALE_ORG_DESC
  FROM SLM_ORDER_HEAD S,SLM_ORDER_LINE S1,MAT_BC_M T
 WHERE S.ORD_PK = S1.ORD_PK
   AND S.ORDER_NO ||'/'||S1.ORDER_SEQ = T.PRO_ORDER_NO
   AND T.JUDGE_STOVE_NO = ?
   AND ROWNUM = 1
</query>
<query id = "FrmInOnlineStore.selectSupplyUnit" desc= "查询制造商">
SELECT S.SUPPLY_UNIT, C.BASENAME SUPPLY_UNIT_DESC
  FROM SLM_ORDER_HEAD S, SLM_ORDER_LINE S1, MAT_BC_M T, COM_BASE_INFO C
 WHERE S.ORD_PK = S1.ORD_PK
   AND S.ORDER_NO || '/' || S1.ORDER_SEQ = T.PRO_ORDER_NO
   AND S.SUPPLY_UNIT = C.BASECODE
   AND T.PROCESS_CDOE = 'D'
   AND T.QCM_STAUS = '00'
   AND T.JUDGE_STOVE_NO = ?
   AND ROWNUM = 1
</query>
<query id = "doDecision.SelectPlanNextG" desc= "查询半成品下一道工序">
SELECT T1.NEXT_GX, T2.PRO_PLAN_ID
          FROM PLN_ORDER_ZG T1, PLN_ORDER_ZG_S T2
         WHERE T1.PRO_ORDER_NO = T2.PRO_ORDER_NO
         AND T2.PRO_PLAN_ID = ?
         AND T2.GX_PLAN_NO = ?
</query>
<query id = "doDecision.SelectDBKDepartCode" desc = "查询镦拔扩指定产线管理部门">
SELECT S.DEPARTMENT_CODE_P
  FROM #PLAN# T, COM_BASE_PLINE S
 WHERE T.PLINE_CODE = S.PLINE_CODE
 AND T.ORD_LN_DLY_PK = ?
 AND ROWNUM = 1
</query>
<query id = "doDecision.SelectINPUTCOUNTWGT" desc = "查询投料支吨">
<![CDATA[
SELECT *
                         FROM (SELECT S.M_MAT_NO
                                 FROM PORT_MIL_BATCH_SAMPLE_RESULT S
                                WHERE S.JUDGE_STOVE_NO =
                                      ? || '-01'
                                  AND S.TR_FLAG = '0'
                                  AND S.JUGDE_APPLY_CODE IS NULL
                                GROUP BY S.M_MAT_NO
                                ORDER BY S.M_MAT_NO)
                        WHERE ROWNUM <= ?
                        ]]>
</query>
<!-- SELECT SUM(T2.ACT_COUNT) INPUT_COUNT, SUM(T2.INPUT_WEIGHT) INPUT_WEIGHT
  FROM (SELECT SUM(S.ACT_COUNT) ACT_COUNT, SUM(S.INPUT_WEIGHT) INPUT_WEIGHT
          FROM PORT_MIL_BATCH_SAMPLE_RESULT S,
               (SELECT T.ZG_STOVE_SQE
                  FROM MAT_BC_M T
                 WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                   AND T.BATCH_NO = '#BATCH_NO#'
                   AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
                   AND T.PLINE_CODE = '#PLINE_CODE#'
                   AND T.JUGDE_APPLY_CODE IS NULL
                   AND T.QCM_STAUS = '00'
                 GROUP BY T.ZG_STOVE_SQE) T1
         WHERE S.JUDGE_STOVE_NO = T1.ZG_STOVE_SQE
           AND S.BATCH_NO = '#BATCH_NO#'
           AND S.GROUP_NO = '#BATCH_GROUD_NO#'
           AND S.STATUS IN ('0', '1', '2', '5', '6')
           AND S.GROUP_FLAG = '0'
         GROUP BY S.M_MAT_NO) T2 -->
<query id = "doDecision.SelectINPUTCOUNTWGT1" desc = "查询投料支吨1">
SELECT M_MAT_NO FROM(
SELECT SUM(T3.ACT_COUNT)INPUT_COUNT,SUM(T3.INPUT_WEIGHT)INPUT_WEIGHT,T3.M_MAT_NO
  FROM (SELECT S.M_MAT_NO, S.JUDGE_STOVE_NO
          FROM PORT_MIL_BATCH_SAMPLE_RESULT S,
               (SELECT T.ZG_STOVE_SQE
                  FROM MAT_BC_M T
                 WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                   AND T.BATCH_NO = '#BATCH_NO#'
                   AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
                   AND T.PLINE_CODE = '#PLINE_CODE#'
                   AND T.JUGDE_APPLY_CODE IS NULL
                   AND T.QCM_STAUS = '00'
                 GROUP BY T.ZG_STOVE_SQE) T1
         WHERE S.JUDGE_STOVE_NO = T1.ZG_STOVE_SQE
           AND S.BATCH_NO = '#BATCH_NO#'
           AND S.GROUP_NO = '#BATCH_GROUD_NO#'
           AND S.STATUS IN ('0', '1', '2', '5', '6')
           AND S.TR_FLAG = '0'
           AND S.GROUP_FLAG = '0'
         GROUP BY S.M_MAT_NO,S.JUDGE_STOVE_NO) T2,
       PORT_MIL_BATCH_SAMPLE_RESULT T3
 WHERE T2.M_MAT_NO = T3.M_MAT_NO
   AND T2.JUDGE_STOVE_NO = T3.JUDGE_STOVE_NO
   GROUP BY T3.M_MAT_NO
UNION ALL
SELECT SUM(T3.ACT_COUNT)INPUT_COUNT,SUM(T3.INPUT_WEIGHT)INPUT_WEIGHT,T3.M_MAT_NO
  FROM (SELECT S.M_MAT_NO, S.JUDGE_STOVE_NO
          FROM PORT_MIL_BATCH_SAMPLE_RESULT S,
               (SELECT T.ZG_STOVE_SQE
                  FROM MAT_BC_M T
                 WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                   AND T.BATCH_NO = '#BATCH_NO#'
                   AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
                   AND T.PLINE_CODE = '#PLINE_CODE#'
                   AND T.JUGDE_APPLY_CODE IS NULL
                   AND T.QCM_STAUS = '00'
                 GROUP BY T.ZG_STOVE_SQE) T1
         WHERE S.JUDGE_STOVE_NO = T1.ZG_STOVE_SQE
           AND (S.BATCH_NO IS NULL OR S.GROUP_NO IS NULL)
           AND S.STATUS IN ('1', '2', '5', '6')
           AND S.TR_FLAG = '0'
           AND S.GROUP_FLAG = '0'
         GROUP BY S.M_MAT_NO,S.JUDGE_STOVE_NO) T2,
       PORT_MIL_BATCH_SAMPLE_RESULT T3
 WHERE T2.M_MAT_NO = T3.M_MAT_NO
   AND T2.JUDGE_STOVE_NO = T3.JUDGE_STOVE_NO
   GROUP BY T3.M_MAT_NO,T3.JUDGE_STOVE_NO)
   GROUP BY M_MAT_NO
</query>
<query id = "doDecision.SelectOUTCOUNTWGT" desc = "查询判定支+废品支"> 
        SELECT SUM(S.ACT_COUNT) OUTPUT_COUNT,
               SUM(S.INPUT_WEIGHT) OUTPUT_WEIGHT
          FROM PORT_MIL_BATCH_SAMPLE_RESULT S,
               (SELECT T.ZG_STOVE_SQE
                  FROM MAT_BC_M T
                 WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                   AND T.BATCH_NO = '#BATCH_NO#'
                   AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
                   AND T.PLINE_CODE = '#PLINE_CODE#'
                   AND T.JUGDE_APPLY_CODE IS NULL
                   AND T.QCM_STAUS = '00'
                 GROUP BY T.ZG_STOVE_SQE) T1
         WHERE S.JUDGE_STOVE_NO = T1.ZG_STOVE_SQE
           AND S.BATCH_NO = '#BATCH_NO#'
           AND S.GROUP_NO = '#BATCH_GROUD_NO#'
           AND S.STATUS IN ('0','1', '2', '5', '6')
           AND S.GROUP_FLAG = '0'
          
</query>
<!-- 
SELECT SUM(ACT_COUNT) OUTPUT_COUNT, SUM(ACT_WEIGHT) OUTPUT_WEIGHT
  FROM (SELECT SUM(T.ACT_COUNT) ACT_COUNT,
               SUM(CASE
                     WHEN T.PONDER_GROSS_WT IS NOT NULL THEN
                      T.PONDER_GROSS_WT
                     ELSE
                      T.ACT_WEIGHT
                   END) ACT_WEIGHT
          FROM MAT_BC_M T
         WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
           AND T.BATCH_NO = '#BATCH_NO#'
           AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
           AND T.PLINE_CODE = '#PLINE_CODE#'
           AND T.JUGDE_APPLY_CODE IS NULL
           AND T.QCM_STAUS = '00'
        UNION ALL
        SELECT SUM(S.ACT_COUNT) ACT_COUNT,
               SUM(S.INPUT_WEIGHT) ACT_WEIGHT
          FROM PORT_MIL_BATCH_SAMPLE_RESULT S,
               (SELECT T.ZG_STOVE_SQE
                  FROM MAT_BC_M T
                 WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                   AND T.BATCH_NO = '#BATCH_NO#'
                   AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
                   AND T.PLINE_CODE = '#PLINE_CODE#'
                   AND T.JUGDE_APPLY_CODE IS NULL
                   AND T.QCM_STAUS = '00'
                 GROUP BY T.ZG_STOVE_SQE) T1
         WHERE S.JUDGE_STOVE_NO = T1.ZG_STOVE_SQE
           AND S.BATCH_NO = '#BATCH_NO#'
           AND S.STATUS IN ('1', '2', '5', '6')
           AND S.GROUP_FLAG = '0')
 -->
<query id = "doDecision.SelectOUTCOUNTWGT1" desc = "查询判定+废品支吨1">
SELECT SUM(ACT_COUNT) OUTPUT_COUNT, SUM(ACT_WEIGHT) OUTPUT_WEIGHT
  FROM (
        SELECT SUM(S.ACT_COUNT) ACT_COUNT,
               SUM(S.INPUT_WEIGHT) ACT_WEIGHT
          FROM PORT_MIL_BATCH_SAMPLE_RESULT S,
               (SELECT T.ZG_STOVE_SQE
                  FROM MAT_BC_M T
                 WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                   AND T.BATCH_NO = '#BATCH_NO#'
                   AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
                   AND T.PLINE_CODE = '#PLINE_CODE#'
                   AND T.JUGDE_APPLY_CODE IS NULL
                   AND T.QCM_STAUS = '00'
                 GROUP BY T.ZG_STOVE_SQE) T1
         WHERE S.JUDGE_STOVE_NO = T1.ZG_STOVE_SQE
           AND S.BATCH_NO = '#BATCH_NO#'
           AND S.GROUP_NO = '#BATCH_GROUD_NO#'
           AND S.STATUS = '0'
           AND S.GROUP_FLAG = '0'
           union all
           SELECT SUM(S.ACT_COUNT) ACT_COUNT,
               SUM(S.INPUT_WEIGHT) ACT_WEIGHT
          FROM PORT_MIL_BATCH_SAMPLE_RESULT S,
               (SELECT T.ZG_STOVE_SQE
                  FROM MAT_BC_M T
                 WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                   AND T.BATCH_NO = '#BATCH_NO#'
                   AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
                   AND T.PLINE_CODE = '#PLINE_CODE#'
                   AND T.JUGDE_APPLY_CODE IS NULL
                   AND T.QCM_STAUS = '00'
                 GROUP BY T.ZG_STOVE_SQE) T1
         WHERE S.JUDGE_STOVE_NO = T1.ZG_STOVE_SQE
           AND (S.BATCH_NO IS NULL OR GROUP_NO IS NULL)
           AND S.STATUS IN ('1', '2', '5', '6')
           AND S.GROUP_FLAG = '0')
</query>
<!-- SELECT SUM(ACT_COUNT) OUTPUT_COUNT, SUM(ACT_WEIGHT) OUTPUT_WEIGHT
  FROM (SELECT SUM(T.ACT_COUNT) ACT_COUNT,
               SUM(CASE
                     WHEN T.PONDER_GROSS_WT IS NOT NULL THEN
                      T.PONDER_GROSS_WT
                     ELSE
                      T.ACT_WEIGHT
                   END) ACT_WEIGHT
          FROM MAT_BC_M T
         WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
           AND T.BATCH_NO = '#BATCH_NO#'
           AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
           AND T.PLINE_CODE = '#PLINE_CODE#'
           AND T.JUGDE_APPLY_CODE IS NULL
           AND T.QCM_STAUS = '00'
        UNION ALL
        SELECT SUM(S.ACT_COUNT) ACT_COUNT,
               SUM(S.INPUT_WEIGHT) ACT_WEIGHT
          FROM PORT_MIL_BATCH_SAMPLE_RESULT S,
               (SELECT T.ZG_STOVE_SQE
                  FROM MAT_BC_M T
                 WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                   AND T.BATCH_NO = '#BATCH_NO#'
                   AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
                   AND T.PLINE_CODE = '#PLINE_CODE#'
                   AND T.JUGDE_APPLY_CODE IS NULL
                   AND T.QCM_STAUS = '00'
                 GROUP BY T.ZG_STOVE_SQE) T1
         WHERE S.JUDGE_STOVE_NO = T1.ZG_STOVE_SQE
           AND S.BATCH_NO = '#BATCH_NO#'
           AND S.STATUS IN ('1', '2', '5', '6')
           AND S.GROUP_FLAG = '0'
           union all
           SELECT SUM(S.ACT_COUNT) ACT_COUNT,
               SUM(S.INPUT_WEIGHT) ACT_WEIGHT
          FROM PORT_MIL_BATCH_SAMPLE_RESULT S,
               (SELECT T.ZG_STOVE_SQE
                  FROM MAT_BC_M T
                 WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                   AND T.BATCH_NO = '#BATCH_NO#'
                   AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
                   AND T.PLINE_CODE = '#PLINE_CODE#'
                   AND T.JUGDE_APPLY_CODE IS NULL
                   AND T.QCM_STAUS = '00'
                 GROUP BY T.ZG_STOVE_SQE) T1
         WHERE S.JUDGE_STOVE_NO = T1.ZG_STOVE_SQE
           AND (S.BATCH_NO IS NULL OR (S.BATCH_NO IS NOT NULL AND S.GROUP_NO IS NULL))
           AND S.STATUS IN ('1', '2', '5', '6')
           AND S.GROUP_FLAG = '0') -->
<query id = "doDecision.SelectPlanSaw" desc = "查询分切数">
SELECT T.SAW_NUM FROM MIL_PLAN T WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = ? AND ROWNUM = 1 ORDER BY T.START_TIME ASC
</query>
<query id = "doDecision.SelectMaxGroupNo" desc = "查询最大批号">
SELECT MAX(T.BATCH_NO) BATCH_NO, MAX(T.GROUP_NO) GROUP_NO
  FROM PORT_MIL_BATCH_SAMPLE_RESULT T
 WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = '#JUDGE_STOVE_NO#'
</query>
<query id = "doDecision.SelectOutCount" desc = "查询判定吨+废品">
<![CDATA[
SELECT SUM(S.INPUT_WEIGHT) OUTPUT_WEIGHT
  FROM (SELECT SUM(T2.INPUT_WEIGHT) INPUT_WEIGHT, T2.JUDGE_STOVE_NO
          FROM PORT_MIL_BATCH_SAMPLE_RESULT T2
         WHERE T2.GROUP_FLAG = '0'
         GROUP BY T2.M_MAT_NO, T2.JUDGE_STOVE_NO) S,
       (SELECT T.ZG_STOVE_SQE
          FROM MAT_BC_M T
         WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
           AND T.BATCH_NO = '#BATCH_NO#'
           AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
           AND T.QCM_STAUS = '00'
         GROUP BY T.ZG_STOVE_SQE) T1
 WHERE S.JUDGE_STOVE_NO = T1.ZG_STOVE_SQE
   AND ROWNUM <= ?
   ]]>
</query>
<query id = "FrmInOnlineStore.updtaePortFlag" desc = "修改标识">
UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T
   SET T.JUGDE_APPLY_CODE = ?,
   T.TR_FLAG = '1'
 WHERE T.JUDGE_STOVE_NO = ?||'-01'
   AND T.M_MAT_NO = ?
   
</query>
<query id = "FrmInOnlineStore.cancelPortFlag" desc = "撤销时修改标识">
UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T SET T.JUGDE_APPLY_CODE ='',T.TR_FLAG = '0' WHERE T.JUGDE_APPLY_CODE = ?
</query>
<query id = "doDecision.SelectPortWgt" desc = "查询重量">
SELECT NVL(SUM(T.INPUT_WEIGHT),0) INPUT_WEIGHT
  FROM PORT_MIL_BATCH_SAMPLE_RESULT T
 WHERE T.M_MAT_NO = ?
   AND T.JUDGE_STOVE_NO = ?||'-01'
</query>
<query id = "doDecision.SelectScrapCount" desc = "查询所有废品支">
SELECT NVL(SUM(T.ACT_COUNT),0) ACT_COUNT
        FROM PORT_MIL_BATCH_SAMPLE_RESULT T
       WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '')= '#JUDGE_STOVE_NO#'
       AND T.STATUS IN('1','2','5','6')
       AND T.GROUP_FLAG ='0'
</query>
<query id = "doDecision.SelectJudegNo" desc = "查询该炉是否进行一判">
SELECT *
  FROM (SELECT T.JUGDE_APPLY_CODE, T.IS_FLAG, T.IS_ALL_SCRAP, T.APPLY_TIME
          FROM QCM_ZG_JUGDE_APPLY T
         WHERE T.JUDGE_STOVE_NO = ?
           AND T.IS_FLAG = '0'
           AND T.IS_ALL_SCRAP = '0'
           AND T.PROCESS_CODE = 'D'
         ORDER BY T.APPLY_TIME DESC)
 WHERE ROWNUM = 1
</query>
<query id = "doDecision.SelectOldJugeNo" desc = "查询组炉原炉号">
SELECT REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') JUDGE_STOVE_NO
  FROM MIL_SLAB_SCRAP T
 WHERE REGEXP_REPLACE(T.NEW_HEAT_NO, '-.*', '') = ?
 GROUP BY T.JUDGE_STOVE_NO
UNION ALL
SELECT REGEXP_REPLACE(T1.OLD_ZP_JUDGE_STOVE_NO, '-.*', '') JUDGE_STOVE_NO
  FROM MIL_OFFLINE_GROUP T1
 WHERE REGEXP_REPLACE(T1.ZP_JUDGE_STOVE_NO, '-.*', '') = ?
UNION ALL
SELECT REGEXP_REPLACE(T2.JUDGE_STOVE_NO, '-.*', '') JUDGE_STOVE_NO
  FROM MIL_FURNACES_RESLUT_DETIA T2
 WHERE REGEXP_REPLACE(T2.Zp_Judge_Stove_No, '-.*', '') = ?
</query>

 <query id = "FrmInOnlineStore.insertMilProcess" desc = "更新进程表mil_processes数据">
    <![CDATA[
   DECLARE
  V_JUDGE_STOVE_NO MIL_PROCESSES.JUDGE_STOVE_NO%TYPE := ?;
  V_LOT_NO         MIL_PROCESSES.LOT_NO%TYPE := ?;
  V_PLINE_CODE     MIL_PROCESSES.PLINE_CODE%TYPE := ?;
  V_PRO_PLAN_ID    MIL_PROCESSES.PRO_PLAN_ID%TYPE := ?;
  V_GX_PLAN_NO     MIL_PROCESSES.GX_PLAN_NO%TYPE := ?;
  V_COUNT          MIL_PROCESSES.YJZ%TYPE := NULL;

BEGIN
  SELECT COUNT(1)
    INTO V_COUNT
    FROM MIL_PROCESSES T
   WHERE T.JUDGE_STOVE_NO = REGEXP_REPLACE(V_JUDGE_STOVE_NO, '-.*', '')
     AND T.LOT_NO = V_LOT_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, '/');

  FOR MYROW IN (SELECT AA.*,
                       CASE
                         WHEN AA.NODE_STATUS < 20 THEN
                          0
                         ELSE
                          AA.HGZ1 - AA.FPZ2
                       END HGZ2,
                       CASE
                         WHEN AA.NODE_STATUS < 20 THEN
                          0
                         ELSE
                          AA.HGD1 - AA.FPD2
                       END HGD2,
                       
                       CASE
                         WHEN AA.NODE_STATUS < 30 THEN
                          0
                         ELSE
                          AA.HGZ1 - AA.FPZ2 - AA.FPZ3
                       END HGZ3,
                       CASE
                         WHEN AA.NODE_STATUS < 30 THEN
                          0
                         ELSE
                          AA.HGD1 - AA.FPD2 - AA.FPD3
                       END HGD3,
                       
                       CASE
                         WHEN AA.NODE_STATUS < 40 THEN
                          0
                         ELSE
                          AA.HGZ1 - AA.FPZ2 - AA.FPZ3 - AA.FPZ4
                       END HGZ4,
                       CASE
                         WHEN AA.NODE_STATUS < 40 THEN
                          0
                         ELSE
                          AA.HGD1 - AA.FPD2 - AA.FPD3 - AA.FPD4
                       END HGD4,
                       
                       CASE
                         WHEN AA.NODE_STATUS < 50 THEN
                          0
                         ELSE
                          AA.HGZ1 - AA.FPZ2 - AA.FPZ3 - AA.FPZ4 - AA.FPZ5
                       END HGZ5,
                       CASE
                         WHEN AA.NODE_STATUS < 50 THEN
                          0
                         ELSE
                          AA.HGD1 - AA.FPD2 - AA.FPD3 - AA.FPD4 - AA.FPD5
                       END HGD5,
                       
                       CASE
                         WHEN AA.NODE_STATUS < 60 THEN
                          0
                         ELSE
                          AA.HGZ1 - AA.FPZ2 - AA.FPZ3 - AA.FPZ4 - AA.FPZ5 -
                          AA.FPZ6
                       END HGZ6,
                       CASE
                         WHEN AA.NODE_STATUS < 60 THEN
                          0
                         ELSE
                          AA.HGD1 - AA.FPD2 - AA.FPD3 - AA.FPD4 - AA.FPD5 -
                          AA.FPD6
                       END HGD6,
                       
                       CASE
                         WHEN AA.NODE_STATUS < 80 THEN
                          0
                         ELSE
                          AA.HGZ7 - AA.FPZ9 - AA.XXZ9 - AA.ZLZ9
                       END HGZ9,
                       CASE
                         WHEN AA.NODE_STATUS < 80 THEN
                          0
                         ELSE
                          AA.HGD7 - AA.FPD9 - AA.XXD9 - AA.ZLD9
                       END HGD9,
                       
                       CASE
                         WHEN AA.NODE_STATUS < 90 THEN
                          0
                         ELSE
                          AA.HGZ7 - AA.FPZ9 - AA.XXZ9 - AA.FPZ10 - AA.XXZ10 -
                          AA.ZLZ10
                       END HGZ10,
                       CASE
                         WHEN AA.NODE_STATUS < 90 THEN
                          0
                         ELSE
                          AA.HGD7 - AA.FPD9 - AA.XXD9 - AA.FPD10 - AA.XXD10 -
                          AA.ZLD10
                       END HGD10,
                       
                       CASE
                         WHEN AA.NODE_STATUS < 96 THEN
                          0
                         ELSE
                          AA.HGZ7 - AA.FPZ9 - AA.XXZ9 - AA.FPZ10 - AA.XXZ10 -
                          AA.FPZ11 - AA.XXZ11 - AA.ZLZ11
                       END HGZ11,
                       CASE
                         WHEN AA.NODE_STATUS < 96 THEN
                          0
                         ELSE
                          AA.HGD7 - AA.FPD9 - AA.XXD9 - AA.FPD10 - AA.XXD10 -
                          AA.FPD11 - AA.XXD11 - AA.ZLD11
                       END HGD11,
                       CASE AA.NODE_STATUS
                         WHEN '10' THEN
                          '锯切完成'
                         WHEN '20' THEN
                          '出炉'
                         WHEN '30' THEN
                          '穿孔完成'
                         WHEN '40' THEN
                          '连轧完成'
                         WHEN '50' THEN
                          '出再加热炉'
                         WHEN '60' THEN
                          '出定径'
                         WHEN '70' THEN
                          '分切完成'
                         WHEN '80' THEN
                          '矫直完成'
                         WHEN '90' THEN
                          '探伤完成'
                         WHEN '96' THEN
                          '质检完成'
                         WHEN '99' THEN
                          '下线'
                       END NODE_STATUS1
                
                  FROM (select REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '') JUDGE_STOVE_NO,
                               T1.ID,
                               T1.LOT_NO,
                               T1.PLINE_CODE,
                               (SELECT A.PLINE_NAME
                                  FROM COM_BASE_PLINE A
                                 WHERE A.PLINE_CODE = T1.PLINE_CODE) PLINE_CODE1,
                               T1.CONTRACT_NO,
                               MAX(T1.TARGET) TARGET,
                               MAX(T1.VARIETIES) VARIETIES,
                               MAX(T1.VARIETIES_CODE) VARIETIES_CODE,
                               MAX(T1.STEELNAME) STEELNAME,
                               MAX(T1.STEELCODE) STEELCODE,
                               MAX(T1.GRADENAME) GRADENAME,
                               MAX(T1.GRADECODE) GRADECODE,
                               REPLACE(MAX(T1.PIPE_SIZE), '*', 'x') PIPE_SIZE,
                               MAX(T1.PIPE_SIZE_CODE) PIPE_SIZE_CODE,
                               MAX(T1.BUCKLE_TYPE) BUCKLE_TYPE,
                               MAX(T1.BUCKLE_TYPE_CODE) BUCKLE_TYPE_CODE,
                               MAX(T1.LENGTH_RANGE) LENGTH_RANGE,
                               MAX(T1.ROLL_STANDRAD) ROLL_STANDRAD,
                               MIN(T1.FEED_TIME) FEED_TIME,
                               
                               --MAX(T1.NODE_STATUS) NODE_STATUS,
                               MAX(T1.PRO_PLAN_ID) PRO_PLAN_ID,
                               MAX(T1.GX_PLAN_NO) GX_PLAN_NO,
                               
                               (SELECT MAX(NODE_STATUS)
                                  FROM MIL_PLAN
                                 WHERE ID = T1.ID) NODE_STATUS,
                               
                               (SELECT count(1)
                                  from (SELECT B.JUDGE_STOVE_NO,
                                               B.m_mat_no,
                                               SUM(B.ACT_THEORY_WEIGHT) ACT_THEORY_WEIGHT
                                          FROM PORT_MIL_BATCH_SAMPLE_RESULT B
                                         WHERE B.IS_VALID = '1'
                                           AND (TRIM(B.Op_Process) != '0' OR
                                               B.Op_Process IS NULL)
                                         group by B.m_mat_no, B.JUDGE_STOVE_NO) A
                                 WHERE A.JUDGE_STOVE_NO = T1.JUDGE_STOVE_NO
                                 GROUP BY A.JUDGE_STOVE_NO) HGZ1,
                               
                               (SELECT SUM(A.ACT_THEORY_WEIGHT)
                                  from (SELECT B.JUDGE_STOVE_NO,
                                               B.m_mat_no,
                                               SUM(B.ACT_THEORY_WEIGHT) ACT_THEORY_WEIGHT
                                          FROM PORT_MIL_BATCH_SAMPLE_RESULT B
                                         WHERE B.IS_VALID = '1'
                                           AND (TRIM(B.Op_Process) != '0' OR
                                               B.Op_Process IS NULL)
                                         group by B.m_mat_no, B.JUDGE_STOVE_NO) A
                                 WHERE A.JUDGE_STOVE_NO = T1.JUDGE_STOVE_NO
                                 GROUP BY A.JUDGE_STOVE_NO) HGD1,
                               
                               (select COUNT(1)
                                  from (select B.JUDGE_STOVE_NO,
                                               TRIM(B.OP_PROCESS) OP_PROCESS,
                                               B.m_mat_no,
                                               SUM(B.ACT_THEORY_WEIGHT) ACT_THEORY_WEIGHT
                                          from PORT_MIL_BATCH_SAMPLE_RESULT B
                                         WHERE B.IS_VALID = '1'
                                           AND B.STATUS = '1'
                                         group by B.JUDGE_STOVE_NO,
                                                  B.m_mat_no,
                                                  B.op_process) A
                                 WHERE A.JUDGE_STOVE_NO = T1.JUDGE_STOVE_NO
                                   AND A.OP_PROCESS = '0') FPZ1,
                               
                               NVL((select SUM(A.ACT_THEORY_WEIGHT)
                                     from (select B.JUDGE_STOVE_NO,
                                                  TRIM(B.OP_PROCESS) OP_PROCESS,
                                                  B.m_mat_no,
                                                  SUM(B.ACT_THEORY_WEIGHT) ACT_THEORY_WEIGHT
                                             from PORT_MIL_BATCH_SAMPLE_RESULT B
                                            WHERE B.IS_VALID = '1'
                                              AND B.STATUS = '1'
                                            group by B.JUDGE_STOVE_NO,
                                                     B.m_mat_no,
                                                     B.op_process) A
                                    WHERE A.JUDGE_STOVE_NO =
                                          T1.JUDGE_STOVE_NO
                                      AND A.OP_PROCESS = '0'),
                                   0) FPD1,
                               
                               (select COUNT(1)
                                  from (select B.JUDGE_STOVE_NO,
                                               TRIM(B.OP_PROCESS) OP_PROCESS,
                                               B.m_mat_no,
                                               SUM(B.ACT_THEORY_WEIGHT) ACT_THEORY_WEIGHT
                                          from PORT_MIL_BATCH_SAMPLE_RESULT B
                                         WHERE B.IS_VALID = '1'
                                           AND B.STATUS = '1'
                                         group by B.JUDGE_STOVE_NO,
                                                  B.m_mat_no,
                                                  B.op_process) A
                                 WHERE A.JUDGE_STOVE_NO = T1.JUDGE_STOVE_NO
                                   AND A.OP_PROCESS = '2') FPZ2,
                               
                               NVL((select SUM(A.ACT_THEORY_WEIGHT)
                                     from (select B.JUDGE_STOVE_NO,
                                                  TRIM(B.OP_PROCESS) OP_PROCESS,
                                                  B.m_mat_no,
                                                  SUM(B.ACT_THEORY_WEIGHT) ACT_THEORY_WEIGHT
                                             from PORT_MIL_BATCH_SAMPLE_RESULT B
                                            WHERE B.IS_VALID = '1'
                                              AND B.STATUS = '1'
                                            group by B.JUDGE_STOVE_NO,
                                                     B.m_mat_no,
                                                     B.op_process) A
                                    WHERE A.JUDGE_STOVE_NO =
                                          T1.JUDGE_STOVE_NO
                                      AND A.OP_PROCESS = '2'),
                                   0) FPD2,
                               
                               (select COUNT(1)
                                  from (select B.JUDGE_STOVE_NO,
                                               TRIM(B.OP_PROCESS) OP_PROCESS,
                                               B.m_mat_no,
                                               SUM(B.ACT_THEORY_WEIGHT) ACT_THEORY_WEIGHT
                                          from PORT_MIL_BATCH_SAMPLE_RESULT B
                                         WHERE B.IS_VALID = '1'
                                           AND B.STATUS = '1'
                                         group by B.JUDGE_STOVE_NO,
                                                  B.m_mat_no,
                                                  B.op_process) A
                                 WHERE A.JUDGE_STOVE_NO = T1.JUDGE_STOVE_NO
                                   AND A.OP_PROCESS = '3') FPZ3,
                               
                               NVL((select SUM(A.ACT_THEORY_WEIGHT)
                                     from (select B.JUDGE_STOVE_NO,
                                                  TRIM(B.OP_PROCESS) OP_PROCESS,
                                                  B.m_mat_no,
                                                  SUM(B.ACT_THEORY_WEIGHT) ACT_THEORY_WEIGHT
                                             from PORT_MIL_BATCH_SAMPLE_RESULT B
                                            WHERE B.IS_VALID = '1'
                                              AND B.STATUS = '1'
                                            group by B.JUDGE_STOVE_NO,
                                                     B.m_mat_no,
                                                     B.op_process) A
                                    WHERE A.JUDGE_STOVE_NO =
                                          T1.JUDGE_STOVE_NO
                                      AND A.OP_PROCESS = '3'),
                                   0) FPD3,
                               
                               (select COUNT(1)
                                  from (select B.JUDGE_STOVE_NO,
                                               TRIM(B.OP_PROCESS) OP_PROCESS,
                                               B.m_mat_no,
                                               SUM(B.ACT_THEORY_WEIGHT) ACT_THEORY_WEIGHT
                                          from PORT_MIL_BATCH_SAMPLE_RESULT B
                                         WHERE B.IS_VALID = '1'
                                           AND B.STATUS = '1'
                                         group by B.JUDGE_STOVE_NO,
                                                  B.m_mat_no,
                                                  B.op_process) A
                                 WHERE A.JUDGE_STOVE_NO = T1.JUDGE_STOVE_NO
                                   AND A.OP_PROCESS = '4') FPZ4,
                               
                               NVL((select SUM(A.ACT_THEORY_WEIGHT)
                                     from (select B.JUDGE_STOVE_NO,
                                                  TRIM(B.OP_PROCESS) OP_PROCESS,
                                                  B.m_mat_no,
                                                  SUM(B.ACT_THEORY_WEIGHT) ACT_THEORY_WEIGHT
                                             from PORT_MIL_BATCH_SAMPLE_RESULT B
                                            WHERE B.IS_VALID = '1'
                                              AND B.STATUS = '1'
                                            group by B.JUDGE_STOVE_NO,
                                                     B.m_mat_no,
                                                     B.op_process) A
                                    WHERE A.JUDGE_STOVE_NO =
                                          T1.JUDGE_STOVE_NO
                                      AND A.OP_PROCESS = '4'),
                                   0) FPD4,
                               
                               (select COUNT(1)
                                  from (select B.JUDGE_STOVE_NO,
                                               TRIM(B.OP_PROCESS) OP_PROCESS,
                                               B.m_mat_no,
                                               SUM(B.ACT_THEORY_WEIGHT) ACT_THEORY_WEIGHT
                                          from PORT_MIL_BATCH_SAMPLE_RESULT B
                                         WHERE 1 = 1
                                           AND B.IS_VALID = '1'
                                           AND B.STATUS = '1'
                                         group by B.JUDGE_STOVE_NO,
                                                  B.m_mat_no,
                                                  B.op_process) A
                                 WHERE A.JUDGE_STOVE_NO = T1.JUDGE_STOVE_NO
                                   AND A.OP_PROCESS = '5') FPZ5,
                               
                               NVL((select SUM(A.ACT_THEORY_WEIGHT)
                                     from (select B.JUDGE_STOVE_NO,
                                                  TRIM(B.OP_PROCESS) OP_PROCESS,
                                                  B.m_mat_no,
                                                  SUM(B.ACT_THEORY_WEIGHT) ACT_THEORY_WEIGHT
                                             from PORT_MIL_BATCH_SAMPLE_RESULT B
                                            WHERE B.IS_VALID = '1'
                                              AND B.STATUS = '1'
                                            group by B.JUDGE_STOVE_NO,
                                                     B.m_mat_no,
                                                     B.op_process) A
                                    WHERE A.JUDGE_STOVE_NO =
                                          T1.JUDGE_STOVE_NO
                                      AND A.OP_PROCESS = '5'),
                                   0) FPD5,
                               
                               (select COUNT(1)
                                  from (select B.JUDGE_STOVE_NO,
                                               TRIM(B.OP_PROCESS) OP_PROCESS,
                                               B.m_mat_no,
                                               SUM(B.ACT_THEORY_WEIGHT) ACT_THEORY_WEIGHT
                                          from PORT_MIL_BATCH_SAMPLE_RESULT B
                                         WHERE B.IS_VALID = '1'
                                           AND B.STATUS = '1'
                                         group by B.JUDGE_STOVE_NO,
                                                  B.m_mat_no,
                                                  B.op_process) A
                                 WHERE A.JUDGE_STOVE_NO = T1.JUDGE_STOVE_NO
                                   AND A.OP_PROCESS = '6') FPZ6,
                               
                               NVL((select SUM(A.ACT_THEORY_WEIGHT)
                                     from (select B.JUDGE_STOVE_NO,
                                                  TRIM(B.OP_PROCESS) OP_PROCESS,
                                                  B.m_mat_no,
                                                  SUM(B.ACT_THEORY_WEIGHT) ACT_THEORY_WEIGHT
                                             from PORT_MIL_BATCH_SAMPLE_RESULT B
                                            WHERE B.IS_VALID = '1'
                                              AND B.STATUS = '1'
                                            group by B.JUDGE_STOVE_NO,
                                                     B.m_mat_no,
                                                     B.op_process) A
                                    WHERE A.JUDGE_STOVE_NO =
                                          T1.JUDGE_STOVE_NO
                                      AND A.OP_PROCESS = '6'),
                                   0) FPD6,
                               
                               (SELECT sum(A.act_count)
                                  FROM PORT_MIL_BATCH_SAMPLE_RESULT A
                                 WHERE A.IS_VALID = '1'
                                   AND A.STATUS <> '1'
                                   AND (TRIM(A.OP_PROCESS) <> '7' OR
                                       A.OP_PROCESS IS NULL)
                                   AND SUBSTR(A.JUDGE_STOVE_NO, -2) = '01'
                                   AND A.JUDGE_STOVE_NO = T1.JUDGE_STOVE_NO) HGZ7,
                               
                               (SELECT SUM(A.ACT_THEORY_WEIGHT)
                                  FROM PORT_MIL_BATCH_SAMPLE_RESULT A
                                 WHERE A.IS_VALID = '1'
                                   AND A.STATUS <> '1'
                                   AND (TRIM(A.OP_PROCESS) <> '7' OR
                                       A.OP_PROCESS IS NULL)
                                   AND SUBSTR(A.JUDGE_STOVE_NO, -2) = '01'
                                   AND A.JUDGE_STOVE_NO = T1.JUDGE_STOVE_NO) HGD7,
                               
                               NVL((select sum(A.act_count)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.STATUS = '2'
                                      AND TRIM(A.OP_PROCESS) = '7'
                                      AND A.JUDGE_STOVE_NO =
                                          T1.JUDGE_STOVE_NO),
                                   0) FPZ7,
                               
                               NVL((select SUM(A.ACT_THEORY_WEIGHT)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.STATUS = '2'
                                      AND TRIM(A.OP_PROCESS) = '7'
                                      AND A.JUDGE_STOVE_NO =
                                          T1.JUDGE_STOVE_NO),
                                   0) FPD7,
                               
                               NVL((select sum(1)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.STATUS = '2'
                                      AND TRIM(A.OP_PROCESS) = '9'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) FPZ9,
                               
                               NVL((select sum(A.act_count)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.STATUS = '2'
                                      AND TRIM(A.OP_PROCESS) = '9'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) FPD9,
                               
                               NVL((select sum(A.act_count)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.STATUS = '3'
                                      AND TRIM(A.OP_PROCESS) = '9'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) XXZ9,
                               
                               NVL((select SUM(A.ACT_THEORY_WEIGHT)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.STATUS = '3'
                                      AND TRIM(A.OP_PROCESS) = '9'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) XXD9,
                               
                               NVL((select sum(A.act_count)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.STATUS IN ('2', '5')
                                      AND TRIM(A.OP_PROCESS) = '10'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) FPZ10,
                               
                               NVL((select SUM(A.ACT_THEORY_WEIGHT)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.STATUS IN ('2', '5')
                                      AND TRIM(A.OP_PROCESS) = '10'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) FPD10,
                               
                               NVL((select sum(A.act_count)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.STATUS = '3'
                                      AND TRIM(A.OP_PROCESS) = '10'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) XXZ10,
                               
                               NVL((select SUM(A.ACT_THEORY_WEIGHT)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.STATUS = '3'
                                      AND TRIM(A.OP_PROCESS) = '10'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) XXD10,
                               
                               NVL((select sum(A.act_count)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.STATUS = '2'
                                      AND TRIM(A.OP_PROCESS) = '11'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) FPZ11,
                               
                               NVL((select SUM(A.ACT_THEORY_WEIGHT)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.STATUS = '2'
                                      AND TRIM(A.OP_PROCESS) = '11'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) FPD11,
                               
                               NVL((select sum(A.act_count)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.STATUS = '3'
                                      AND TRIM(A.OP_PROCESS) = '11'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) XXZ11,
                               
                               NVL((select SUM(A.ACT_THEORY_WEIGHT)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.STATUS = '3'
                                      AND TRIM(A.OP_PROCESS) = '11'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) XXD11,
                               
                               NVL((select sum(1)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.GROUP_FLAG = '1'
                                      AND TRIM(A.OP_PROCESS) = '9'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) ZLZ9,
                               
                               NVL((select sum(A.ACT_THEORY_WEIGHT)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.GROUP_FLAG = '1'
                                      AND TRIM(A.OP_PROCESS) = '9'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) ZLD9,
                               
                               NVL((select sum(1)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.GROUP_FLAG = '1'
                                      AND TRIM(A.OP_PROCESS) = '10'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) ZLZ10,
                               
                               NVL((select sum(A.ACT_THEORY_WEIGHT)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.GROUP_FLAG = '1'
                                      AND TRIM(A.OP_PROCESS) = '10'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) ZLD10,
                               
                               NVL((select sum(1)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.GROUP_FLAG = '1'
                                      AND TRIM(A.OP_PROCESS) = '11'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) ZLZ11,
                               
                               NVL((select sum(A.ACT_THEORY_WEIGHT)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.GROUP_FLAG = '1'
                                      AND TRIM(A.OP_PROCESS) = '11'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) ZLD11,
                               
                               (SELECT DECODE(B.DIRECTOR_QUANTITY,
                                              0,
                                              '',
                                              TO_CHAR(NVL(B.QUALIFIED_BRANCH, 0) * 100 /
                                                      B.DIRECTOR_QUANTITY,
                                                      'FM990.00') || '%')
                                  FROM mil_surface_result B
                                 WHERE B.JUDGE_STOVE_NO = T1.JUDGE_STOVE_NO) qualifiedRate,
                               
                               SUM(B.FEED_NUM_PLAN) SLZ,
                               SUM(B.MAT_TOTAL_HEIGHT -
                                   B.FEED_NUM * DECODE(B.CUT_TARGET,
                                          '返废',
                                          B.CUT_WEIGHT,
                                         /*  '回库',
                                          NVL(round(B.CUT_WEIGHT / B.FEED_NUM,
                                                    3),
                                              0),*/
                                          0)) SLD,
                               SUM(B.FEED_NUM_PLAN * B.DB_NUM) *
                               MAX(T1.SAW_NUM) YJZ,
                               
                               NVL((select sum(A.act_count)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.STATUS = '1'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) undeterminedNum,
                               
                               NVL((select sum(A.INPUT_WEIGHT)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.STATUS = '1'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) undeterminedD,
                               
                               NVL((select sum(A.act_count)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.STATUS IN ('2', '5')
                                      AND A.OP_PROCESS <> '14'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) ScrapNum,
                               
                               NVL((select sum(A.ACT_THEORY_WEIGHT)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.STATUS IN ('2', '5')
                                      AND A.OP_PROCESS <> '14'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) ScrapD,
                               
                               NVL((select sum(A.act_count)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.STATUS = '2'
                                      AND A.OP_PROCESS = '14'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) FQY,
                               
                               NVL((select sum(A.act_count)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.STATUS = '6'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) WWFPZ,
                               
                               NVL((SELECT NVL(SUM(T12.QUALIFIED_NUM), 0)
                                     FROM MIL_INSTORE_RESULT T12
                                    WHERE T12.RESULT_NO = T1.ID
                                      AND REGEXP_REPLACE(T12.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')
                                      AND T12.NODE_FUR_FLAG = '1'),
                                   0) XXZ,
                               
                               NVL((SELECT NVL(SUM(T12.QUALIFIED_TONS), 0)
                                     FROM MIL_INSTORE_RESULT T12
                                    WHERE T12.RESULT_NO = T1.ID
                                      AND REGEXP_REPLACE(T12.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')
                                      AND T12.NODE_FUR_FLAG = '1'),
                                   0) XXD,
                               
                               NVL((SELECT NVL(SUM(T12.QUALIFIED_NUM), 0)
                                     FROM MIL_INSTORE_RESULT T12
                                    WHERE T12.RESULT_NO = T1.ID
                                      AND REGEXP_REPLACE(T12.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) HGZ12,
                               
                               NVL((SELECT NVL(SUM(T12.QUALIFIED_TONS), 0)
                                     FROM MIL_INSTORE_RESULT T12
                                    WHERE T12.RESULT_NO = T1.ID
                                      AND REGEXP_REPLACE(T12.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) HGD12,
                               
                               0 HGM12,
                               
                               NVL((select SUM(Q.ACT_COUNT)
                                     from QCM_ZG_JUGDE_APPLY Q
                                    WHERE Q.VALIDFLAG = '20'
                                      AND Q.APPLY_FLAG = '0'
                                      AND Q.JUDGE_STOVE_NO =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) PDZ,
                               
                               NVL((select DECODE(NVL(SUM(Q.ACT_WEIGHT), 0),
                                                 0,
                                                 SUM(Q.ACT_THEORY_WEIGHT),
                                                 SUM(Q.ACT_WEIGHT))
                                     from QCM_ZG_JUGDE_APPLY Q
                                    WHERE Q.VALIDFLAG = '20'
                                      AND Q.APPLY_FLAG = '0'
                                      AND Q.JUDGE_STOVE_NO =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) PDD,
                               
                               NVL((select SUM(Q.ACT_LEN)
                                     from QCM_ZG_JUGDE_APPLY Q
                                    WHERE 1 = 1
                                      AND Q.VALIDFLAG = '20'
                                      AND Q.APPLY_FLAG = '0'
                                      AND Q.JUDGE_STOVE_NO =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) PDM,
                               
                               NVL((select SUM(Q.ACT_COUNT)
                                     from QCM_ZG_JUGDE_APPLY Q
                                    WHERE Q.APPLY_FLAG = '0'
                                      AND Q.JUDGE_STOVE_NO =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) SPZ,
                               
                               NVL((select DECODE(NVL(SUM(Q.ACT_WEIGHT), 0),
                                                 0,
                                                 SUM(Q.ACT_THEORY_WEIGHT),
                                                 SUM(Q.ACT_WEIGHT))
                                     from QCM_ZG_JUGDE_APPLY Q
                                    WHERE Q.APPLY_FLAG = '0'
                                      AND Q.JUDGE_STOVE_NO =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) SPD,
                               
                               NVL((select SUM(Q.ACT_LEN)
                                     from QCM_ZG_JUGDE_APPLY Q
                                    WHERE Q.APPLY_FLAG = '0'
                                      AND Q.JUDGE_STOVE_NO =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) SPM,
                               
                               (NVL((select sum(A.act_count)
                                      from PORT_MIL_BATCH_SAMPLE_RESULT A
                                     WHERE A.IS_VALID = '1'
                                       AND A.STATUS IN ('3', '4')
                                       AND A.OP_PROCESS <> '12'
                                       AND A.PLAN_ID = T1.ID),
                                    0) +
                               NVL((SELECT NVL(SUM(T12.OFFLINE_NUM), 0)
                                      FROM MIL_INSTORE_RESULT T12
                                     WHERE T12.RESULT_NO = T1.ID
                                       AND REGEXP_REPLACE(T12.JUDGE_STOVE_NO, '-.*', '') =
                                           REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                    0)) LXZ,
                               
                               NVL((select sum(A.act_count)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.STATUS = '4'
                                      AND A.GROUP_FLAG = '0'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) FXZ,
                               
                               NVL((select sum(A.act_count)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.GROUP_FLAG = '1'
                                      AND TRIM(A.OP_PROCESS) > 6
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) ZLZ,
                               
                               NVL((select sum(A.ACT_THEORY_WEIGHT)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.GROUP_FLAG = '1'
                                      AND TRIM(A.OP_PROCESS) > 6
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) ZLD,
                               
                               (select MAX(A.BAL_YEAR_MONTH)
                                  from PORT_MIL_BATCH_SAMPLE_RESULT A
                                 WHERE A.PLAN_ID = T1.ID) BAL_YEAR_MONTH,
                               
                               TO_CHAR(NVL((select SUM(A.ACT_THEORY_WEIGHT)
                                             from PORT_MIL_BATCH_SAMPLE_RESULT A
                                            WHERE A.IS_VALID = '1'
                                              AND A.STATUS <> '2'
                                              AND A.STATUS <> '3'
                                              AND A.STATUS <> '6'
                                              AND A.JUDGE_STOVE_NO =
                                                  T1.JUDGE_STOVE_NO),
                                           0) / SUM(B.MAT_TOTAL_HEIGHT) * 100,
                                       'FM990.00') || '%' RATE,
                               
                               SUM(B.MAT_TOTAL_HEIGHT) *
                               (1 - NVL((select R.BURNNING_RATE
                                           from MIL_FUR_RESULT R
                                          WHERE R.JUDGE_STOVE_NO =
                                                T1.JUDGE_STOVE_NO) / 100,
                                        0)) -
                               DECODE(MAX(T1.CONTROL_THICKP),
                                      0,
                                      0,
                                      (MAX(T1.CUT_HEAD_LENGTHP) +
                                      MAX(T1.CUT_TRAIL_LENGTHP)) / 1000 *
                                      (0.02466 * MAX(T1.CONTROL_THICKP) / 1000 * 1.02 *
                                      ((SUBSTR(MAX(T1.PIPE_SIZE),
                                                1,
                                                INSTR(MAX(T1.PIPE_SIZE), '*') - 1)) *
                                      (CASE
                                        WHEN INSTR(MAX(T1.VARIETIES), '套管') > 0 THEN
                                         1.005
                                        WHEN INSTR(MAX(T1.VARIETIES), '油管') > 0 THEN
                                         1.005
                                        ELSE
                                         1
                                      END) -
                                      (MAX(T1.CONTROL_THICKP) / 1000 * 1.02)) *
                                      SUM(B.FEED_NUM_PLAN * B.DB_NUM))) YJD,
                               
                               TO_CHAR(NVL((select DECODE(NVL(SUM(Q.ACT_WEIGHT),
                                                             0),
                                                         0,
                                                         SUM(Q.ACT_THEORY_WEIGHT),
                                                         SUM(Q.ACT_WEIGHT))
                                             from QCM_ZG_JUGDE_APPLY Q
                                            WHERE Q.VALIDFLAG = '20'
                                              AND Q.APPLY_FLAG = '0'
                                              AND Q.JUDGE_STOVE_NO =
                                                  REGEXP_REPLACE(T1.JUDGE_STOVE_NO,
                                                                 '-.*',
                                                                 '')),
                                           0) * 100 / SUM(B.MAT_TOTAL_HEIGHT),
                                       'FM990.00') || '%' RATE2
                        
                          from MIL_PLAN T1, MIL_FEED_PLAN B
                         WHERE T1.JUDGE_STOVE_NO = B.JUDGE_STOVE_NO
                           AND T1.PRO_PLAN_ID = B.PRO_PLAN_ID
                           AND T1.BACK_SLAB_FLAG <> '2'
                           AND T1.JUDGE_STOVE_NO =
                               REGEXP_REPLACE(V_JUDGE_STOVE_NO, '-.*', '') || '-01'
                           AND T1.LOT_NO = V_LOT_NO
                           AND T1.PLINE_CODE = V_PLINE_CODE
                           AND NVL(T1.PRO_PLAN_ID, '/') =
                               NVL(V_PRO_PLAN_ID, '/')
                           AND NVL(T1.GX_PLAN_NO, '/') =
                               NVL(V_GX_PLAN_NO, '/')
                         GROUP BY T1.JUDGE_STOVE_NO,
                                  T1.LOT_NO,
                                  T1.PLINE_CODE,
                                  T1.JUDGE_STOVE_NO,
                                  T1.ID,
                                  T1.PRO_PLAN_ID,
                                  t1.gx_plan_no,
                                  T1.ID,
                                  T1.CONTRACT_NO) AA
                 ORDER BY AA.FEED_TIME ASC) LOOP
    IF (V_COUNT > 0) THEN
      UPDATE MIL_PROCESSES T
         SET T.YJZ             = MYROW.YJZ,
             T.YJD             = MYROW.YJD,
             T.SLZ             = MYROW.SLZ,
             T.SLD             = MYROW.SLD,
             T.ZZL            =
           (SELECT SUM(TR.QUALIFIED_WT)
              FROM MIL_CONTROL_LOG TR
             WHERE TR.JUDGE_STOVE_NO = T.JUDGE_STOVE_NO || '-01'),
           T.ZZZ            =
           (SELECT SUM(TR.QUALIFIED_NUM)
              FROM MIL_CONTROL_LOG TR
             WHERE TR.JUDGE_STOVE_NO = T.JUDGE_STOVE_NO || '-01'),
             T.UNDETERMINEDNUM = MYROW.UNDETERMINEDNUM,
             T.UNDETERMINEDD   = MYROW.UNDETERMINEDD,
             T.SCRAPNUM        = MYROW.SCRAPNUM,
             T.SCRAPD          = MYROW.SCRAPD,
             T.WWFPZ           = MYROW.WWFPZ,
             T.FQY             = MYROW.FQY,
             T.LXZ             = MYROW.LXZ,
             T.FXZ             = MYROW.FXZ,
             T.ZLZ             = MYROW.ZLZ,
             T.ZLD             = MYROW.ZLD,
             T.SPZ             = MYROW.SPZ,
             T.SPD             = MYROW.SPD,
             T.SPM             = MYROW.SPM,
             T.PDZ             = MYROW.PDZ,
             T.PDD             = MYROW.PDD,
             T.PDM             = MYROW.PDM,
             T.HGZ1            = MYROW.HGZ1,
             T.HGD1            = MYROW.HGD1,
             T.FPZ1            = MYROW.FPZ1,
             T.FPD1            = MYROW.FPD1,
             T.HGZ2            = MYROW.HGZ2,
             T.HGD2            = MYROW.HGD2,
             T.FPZ2            = MYROW.FPZ2,
             T.FPD2            = MYROW.FPD2,
             T.HGZ3            = MYROW.HGZ3,
             T.HGD3            = MYROW.HGD3,
             T.FPZ3            = MYROW.FPZ3,
             T.FPD3            = MYROW.FPD3,
             T.HGZ4            = MYROW.HGZ4,
             T.HGD4            = MYROW.HGD4,
             T.FPZ4            = MYROW.FPZ4,
             T.FPD4            = MYROW.FPD4,
             T.HGZ5            = MYROW.HGZ5,
             T.HGD5            = MYROW.HGD5,
             T.FPZ5            = MYROW.FPZ5,
             T.FPD5            = MYROW.FPD5,
             T.HGZ6            = MYROW.HGZ6,
             T.HGD6            = MYROW.HGD6,
             T.FPZ6            = MYROW.FPZ6,
             T.FPD6            = MYROW.FPD6,
             T.HGZ7            = MYROW.HGZ7,
             T.HGD7            = MYROW.HGD7,
             T.FPZ7            = MYROW.FPZ7,
             T.FPD7            = MYROW.FPD7,
             T.HGZ9            = MYROW.HGZ9,
             T.HGD9            = MYROW.HGD9,
             T.FPZ9            = MYROW.FPZ9,
             T.FPD9            = MYROW.FPD9,
             T.HGZ10           = MYROW.HGZ10,
             T.HGD10           = MYROW.HGD10,
             T.FPZ10           = MYROW.FPZ10,
             T.FPD10           = MYROW.FPD10,
             T.HGZ11           = MYROW.HGZ11,
             T.HGD11           = MYROW.HGD11,
             T.FPZ11           = MYROW.FPZ11,
             T.FPD11           = MYROW.FPD11,
             T.HGZ12           = MYROW.HGZ12,
             T.HGD12           = MYROW.HGD12,
             T.RATE            = MYROW.RATE,
             T.QUALIFIEDRATE   = MYROW.QUALIFIEDRATE,
             T.RATE2           = MYROW.RATE2,
             T.NODE_STATUS1    = MYROW.NODE_STATUS1
       WHERE T.JUDGE_STOVE_NO = MYROW.JUDGE_STOVE_NO
         AND T.LOT_NO = V_LOT_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, '/');
    
     ELSIF (V_COUNT = 0) THEN
      INSERT INTO MIL_PROCESSES
        (ID,
         JUDGE_STOVE_NO,
         LOT_NO,
         PRO_PLAN_ID,
         GX_PLAN_NO,
         PLINE_CODE,
         TARGET,
         VARIETIES,
         VARIETIES_CODE,
         STEELCODE,
         STEELNAME,
         GRADECODE,
         GRADENAME,
         PIPE_SIZE,
         PIPE_SIZE_CODE,
         BUCKLE_TYPE,
         BUCKLE_TYPE_CODE,
         FEED_TIME,
         SLZ,
         SLD,
         YJZ,
         YJD,
         UNDETERMINEDNUM,
         UNDETERMINEDD,
         SCRAPNUM,
         SCRAPD,
         WWFPZ,
         FQY,
         LXZ,
         FXZ,
         ZLZ,
         ZLD,
         SPZ,
         SPD,
         SPM,
         PDZ,
         PDD,
         PDM,
         HGZ1,
         HGD1,
         FPZ1,
         FPD1,
         HGZ2,
         HGD2,
         FPZ2,
         FPD2,
         HGZ3,
         HGD3,
         FPZ3,
         FPD3,
         HGZ4,
         HGD4,
         FPZ4,
         FPD4,
         HGZ5,
         HGD5,
         FPZ5,
         FPD5,
         HGZ6,
         HGD6,
         FPZ6,
         FPD6,
         HGZ7,
         HGD7,
         FPZ7,
         FPD7,
         HGZ9,
         HGD9,
         FPZ9,
         FPD9,
         HGZ10,
         HGD10,
         FPZ10,
         FPD10,
         HGZ11,
         HGD11,
         FPZ11,
         FPD11,
         HGZ12,
         HGD12,
         RATE,
         QUALIFIEDRATE,
         RATE2,
         --ZLC,
         --ISCLOSE,
         CONTRACT_NO,
         BAL_YEAR_MONTH,
         NODE_STATUS1)
      VALUES
        (MYROW.ID,
         MYROW.JUDGE_STOVE_NO,
         MYROW.LOT_NO,
         MYROW.PRO_PLAN_ID,
         MYROW.GX_PLAN_NO,
         MYROW.PLINE_CODE,
         MYROW.TARGET,
         MYROW.VARIETIES,
         MYROW.VARIETIES_CODE,
         MYROW.STEELCODE,
         MYROW.STEELNAME,
         MYROW.GRADECODE,
         MYROW.GRADENAME,
         MYROW.PIPE_SIZE,
         MYROW.PIPE_SIZE_CODE,
         MYROW.BUCKLE_TYPE,
         MYROW.BUCKLE_TYPE_CODE,
         MYROW.FEED_TIME,
         MYROW.SLZ,
         MYROW.SLD,
         MYROW.YJZ,
         MYROW.YJD,
         MYROW.UNDETERMINEDNUM,
         MYROW.UNDETERMINEDD,
         MYROW.SCRAPNUM,
         MYROW.SCRAPD,
         MYROW.WWFPZ,
         MYROW.FQY,
         MYROW.LXZ,
         MYROW.FXZ,
         MYROW.ZLZ,
         MYROW.ZLD,
         MYROW.SPZ,
         MYROW.SPD,
         MYROW.SPM,
         MYROW.PDZ,
         MYROW.PDD,
         MYROW.PDM,
         MYROW.HGZ1,
         MYROW.HGD1,
         MYROW.FPZ1,
         MYROW.FPD1,
         MYROW.HGZ2,
         MYROW.HGD2,
         MYROW.FPZ2,
         MYROW.FPD2,
         MYROW.HGZ3,
         MYROW.HGD3,
         MYROW.FPZ3,
         MYROW.FPD3,
         MYROW.HGZ4,
         MYROW.HGD4,
         MYROW.FPZ4,
         MYROW.FPD4,
         MYROW.HGZ5,
         MYROW.HGD5,
         MYROW.FPZ5,
         MYROW.FPD5,
         MYROW.HGZ6,
         MYROW.HGD6,
         MYROW.FPZ6,
         MYROW.FPD6,
         MYROW.HGZ7,
         MYROW.HGD7,
         MYROW.FPZ7,
         MYROW.FPD7,
         MYROW.HGZ9,
         MYROW.HGD9,
         MYROW.FPZ9,
         MYROW.FPD9,
         MYROW.HGZ10,
         MYROW.HGD10,
         MYROW.FPZ10,
         MYROW.FPD10,
         MYROW.HGZ11,
         MYROW.HGD11,
         MYROW.FPZ11,
         MYROW.FPD11,
         MYROW.HGZ12,
         MYROW.HGD12,
         MYROW.RATE,
         MYROW.QUALIFIEDRATE,
         MYROW.RATE2,
         --MYROW.ZLC,
         -- MYROW.ISCLOSE,
         MYROW.CONTRACT_NO,
         MYROW.BAL_YEAR_MONTH,
         MYROW.NODE_STATUS1);
    
    END IF;
  
    IF (MYROW.YJD > MYROW.HGD12) THEN
      UPDATE MIL_PROCESSES T
         SET T.ZLC = NVL(MYROW.YJD, 0) - NVL(MYROW.HGD12, 0)
       WHERE T.JUDGE_STOVE_NO = MYROW.JUDGE_STOVE_NO
         AND T.LOT_NO = V_LOT_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, '/');
    ELSE
      UPDATE MIL_PROCESSES T
         SET T.ZLC = 0
       WHERE T.JUDGE_STOVE_NO = MYROW.JUDGE_STOVE_NO
         AND T.LOT_NO = V_LOT_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, '/');
    END IF;
  END LOOP;

END;
  ]]>
    </query>
    
    <query id = "FrmInOnlineStore.insertMilProcess2" desc = "更新进程表mil_processes数据">
    <![CDATA[
    DECLARE
  V_JUDGE_STOVE_NO MIL_PROCESSES.JUDGE_STOVE_NO%TYPE := '#JUDGE_STOVE_NO#';
  V_LOT_NO         MIL_PROCESSES.LOT_NO%TYPE := '#LOT_NO#';
  V_PLINE_CODE     MIL_PROCESSES.PLINE_CODE%TYPE := '#PLINE_CODE#';
  V_PRO_PLAN_ID    MIL_PROCESSES.PRO_PLAN_ID%TYPE := '#PRO_PLAN_ID#';
  V_GX_PLAN_NO     MIL_PROCESSES.GX_PLAN_NO%TYPE := '#GX_PLAN_NO#';
  V_COUNT          MIL_PROCESSES.YJZ%TYPE := NULL;

BEGIN
  SELECT COUNT(1)
    INTO V_COUNT
    FROM MIL_PROCESSES T
   WHERE T.JUDGE_STOVE_NO = REGEXP_REPLACE(V_JUDGE_STOVE_NO, '-.*', '')
     AND T.LOT_NO = V_LOT_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, '/');

  FOR MYROW IN (SELECT AA.*,
                       CASE
                         WHEN AA.NODE_STATUS < 20 THEN
                          0
                         ELSE
                          AA.HGZ1 - AA.FPZ2
                       END HGZ2,
                       CASE
                         WHEN AA.NODE_STATUS < 20 THEN
                          0
                         ELSE
                          AA.HGD1 - AA.FPD2
                       END HGD2,
                       
                       CASE
                         WHEN AA.NODE_STATUS < 30 THEN
                          0
                         ELSE
                          AA.HGZ1 - AA.FPZ2 - AA.FPZ3
                       END HGZ3,
                       CASE
                         WHEN AA.NODE_STATUS < 30 THEN
                          0
                         ELSE
                          AA.HGD1 - AA.FPD2 - AA.FPD3
                       END HGD3,
                       
                       CASE
                         WHEN AA.NODE_STATUS < 40 THEN
                          0
                         ELSE
                          AA.HGZ1 - AA.FPZ2 - AA.FPZ3 - AA.FPZ4
                       END HGZ4,
                       CASE
                         WHEN AA.NODE_STATUS < 40 THEN
                          0
                         ELSE
                          AA.HGD1 - AA.FPD2 - AA.FPD3 - AA.FPD4
                       END HGD4,
                       
                       CASE
                         WHEN AA.NODE_STATUS < 50 THEN
                          0
                         ELSE
                          AA.HGZ1 - AA.FPZ2 - AA.FPZ3 - AA.FPZ4 - AA.FPZ5
                       END HGZ5,
                       CASE
                         WHEN AA.NODE_STATUS < 50 THEN
                          0
                         ELSE
                          AA.HGD1 - AA.FPD2 - AA.FPD3 - AA.FPD4 - AA.FPD5
                       END HGD5,
                       
                       CASE
                         WHEN AA.NODE_STATUS < 60 THEN
                          0
                         ELSE
                          AA.HGZ1 - AA.FPZ2 - AA.FPZ3 - AA.FPZ4 - AA.FPZ5 -
                          AA.FPZ6
                       END HGZ6,
                       CASE
                         WHEN AA.NODE_STATUS < 60 THEN
                          0
                         ELSE
                          AA.HGD1 - AA.FPD2 - AA.FPD3 - AA.FPD4 - AA.FPD5 -
                          AA.FPD6
                       END HGD6,
                       
                       CASE
                         WHEN AA.NODE_STATUS < 80 THEN
                          0
                         ELSE
                          AA.HGZ7 - AA.FPZ9 - AA.XXZ9 - AA.ZLZ9
                       END HGZ9,
                       CASE
                         WHEN AA.NODE_STATUS < 80 THEN
                          0
                         ELSE
                          AA.HGD7 - AA.FPD9 - AA.XXD9 - AA.ZLD9
                       END HGD9,
                       
                       CASE
                         WHEN AA.NODE_STATUS < 90 THEN
                          0
                         ELSE
                          AA.HGZ7 - AA.FPZ9 - AA.XXZ9 - AA.FPZ10 - AA.XXZ10 -
                          AA.ZLZ10
                       END HGZ10,
                       CASE
                         WHEN AA.NODE_STATUS < 90 THEN
                          0
                         ELSE
                          AA.HGD7 - AA.FPD9 - AA.XXD9 - AA.FPD10 - AA.XXD10 -
                          AA.ZLD10
                       END HGD10,
                       
                       CASE
                         WHEN AA.NODE_STATUS < 96 THEN
                          0
                         ELSE
                          AA.HGZ7 - AA.FPZ9 - AA.XXZ9 - AA.FPZ10 - AA.XXZ10 -
                          AA.FPZ11 - AA.XXZ11 - AA.ZLZ11
                       END HGZ11,
                       CASE
                         WHEN AA.NODE_STATUS < 96 THEN
                          0
                         ELSE
                          AA.HGD7 - AA.FPD9 - AA.XXD9 - AA.FPD10 - AA.XXD10 -
                          AA.FPD11 - AA.XXD11 - AA.ZLD11
                       END HGD11,
                       CASE AA.NODE_STATUS
                         WHEN '10' THEN
                          '锯切完成'
                         WHEN '20' THEN
                          '出炉'
                         WHEN '30' THEN
                          '穿孔完成'
                         WHEN '40' THEN
                          '连轧完成'
                         WHEN '50' THEN
                          '出再加热炉'
                         WHEN '60' THEN
                          '出定径'
                         WHEN '70' THEN
                          '分切完成'
                         WHEN '80' THEN
                          '矫直完成'
                         WHEN '90' THEN
                          '探伤完成'
                         WHEN '96' THEN
                          '质检完成'
                         WHEN '99' THEN
                          '下线'
                       END NODE_STATUS1
                
                  FROM (select REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '') JUDGE_STOVE_NO,
                               T1.ID,
                               T1.LOT_NO,
                               T1.PLINE_CODE,
                               (SELECT A.PLINE_NAME
                                  FROM COM_BASE_PLINE A
                                 WHERE A.PLINE_CODE = T1.PLINE_CODE) PLINE_CODE1,
                               T1.CONTRACT_NO,
                               MAX(T1.TARGET) TARGET,
                               MAX(T1.VARIETIES) VARIETIES,
                               MAX(T1.VARIETIES_CODE) VARIETIES_CODE,
                               MAX(T1.STEELNAME) STEELNAME,
                               MAX(T1.STEELCODE) STEELCODE,
                               MAX(T1.GRADENAME) GRADENAME,
                               MAX(T1.GRADECODE) GRADECODE,
                               REPLACE(MAX(T1.PIPE_SIZE), '*', 'x') PIPE_SIZE,
                               MAX(T1.PIPE_SIZE_CODE) PIPE_SIZE_CODE,
                               MAX(T1.BUCKLE_TYPE) BUCKLE_TYPE,
                               MAX(T1.BUCKLE_TYPE_CODE) BUCKLE_TYPE_CODE,
                               MAX(T1.LENGTH_RANGE) LENGTH_RANGE,
                               MAX(T1.ROLL_STANDRAD) ROLL_STANDRAD,
                               MIN(T1.FEED_TIME) FEED_TIME,
                               
                               --MAX(T1.NODE_STATUS) NODE_STATUS,
                               MAX(T1.PRO_PLAN_ID) PRO_PLAN_ID,
                               MAX(T1.GX_PLAN_NO) GX_PLAN_NO,
                               
                               (SELECT MAX(NODE_STATUS)
                                  FROM MIL_PLAN
                                 WHERE ID = T1.ID
                                   AND BACK_SLAB_FLAG <> '2') NODE_STATUS,
                               
                               (SELECT count(1)
                                  from (SELECT B.JUDGE_STOVE_NO,
                                               B.m_mat_no,
                                               SUM(B.ACT_THEORY_WEIGHT) ACT_THEORY_WEIGHT
                                          FROM PORT_MIL_BATCH_SAMPLE_RESULT B
                                         WHERE B.IS_VALID = '1'
                                           AND (TRIM(B.Op_Process) != '0' OR
                                               B.Op_Process IS NULL)
                                         group by B.m_mat_no, B.JUDGE_STOVE_NO) A
                                 WHERE A.JUDGE_STOVE_NO = T1.JUDGE_STOVE_NO
                                 GROUP BY A.JUDGE_STOVE_NO) HGZ1,
                               
                               (SELECT SUM(A.ACT_THEORY_WEIGHT)
                                  from (SELECT B.JUDGE_STOVE_NO,
                                               B.m_mat_no,
                                               SUM(B.ACT_THEORY_WEIGHT) ACT_THEORY_WEIGHT
                                          FROM PORT_MIL_BATCH_SAMPLE_RESULT B
                                         WHERE B.IS_VALID = '1'
                                           AND (TRIM(B.Op_Process) != '0' OR
                                               B.Op_Process IS NULL)
                                         group by B.m_mat_no, B.JUDGE_STOVE_NO) A
                                 WHERE A.JUDGE_STOVE_NO = T1.JUDGE_STOVE_NO
                                 GROUP BY A.JUDGE_STOVE_NO) HGD1,
                               
                               (select COUNT(1)
                                  from (select B.JUDGE_STOVE_NO,
                                               TRIM(B.OP_PROCESS) OP_PROCESS,
                                               B.m_mat_no,
                                               SUM(B.ACT_THEORY_WEIGHT) ACT_THEORY_WEIGHT
                                          from PORT_MIL_BATCH_SAMPLE_RESULT B
                                         WHERE B.IS_VALID = '1'
                                           AND B.STATUS = '1'
                                         group by B.JUDGE_STOVE_NO,
                                                  B.m_mat_no,
                                                  B.op_process) A
                                 WHERE A.JUDGE_STOVE_NO = T1.JUDGE_STOVE_NO
                                   AND A.OP_PROCESS = '0') FPZ1,
                               
                               NVL((select SUM(A.ACT_THEORY_WEIGHT)
                                     from (select B.JUDGE_STOVE_NO,
                                                  TRIM(B.OP_PROCESS) OP_PROCESS,
                                                  B.m_mat_no,
                                                  SUM(B.ACT_THEORY_WEIGHT) ACT_THEORY_WEIGHT
                                             from PORT_MIL_BATCH_SAMPLE_RESULT B
                                            WHERE B.IS_VALID = '1'
                                              AND B.STATUS = '1'
                                            group by B.JUDGE_STOVE_NO,
                                                     B.m_mat_no,
                                                     B.op_process) A
                                    WHERE A.JUDGE_STOVE_NO =
                                          T1.JUDGE_STOVE_NO
                                      AND A.OP_PROCESS = '0'),
                                   0) FPD1,
                               
                               (select COUNT(1)
                                  from (select B.JUDGE_STOVE_NO,
                                               TRIM(B.OP_PROCESS) OP_PROCESS,
                                               B.m_mat_no,
                                               SUM(B.ACT_THEORY_WEIGHT) ACT_THEORY_WEIGHT
                                          from PORT_MIL_BATCH_SAMPLE_RESULT B
                                         WHERE B.IS_VALID = '1'
                                           AND B.STATUS = '1'
                                         group by B.JUDGE_STOVE_NO,
                                                  B.m_mat_no,
                                                  B.op_process) A
                                 WHERE A.JUDGE_STOVE_NO = T1.JUDGE_STOVE_NO
                                   AND A.OP_PROCESS = '2') FPZ2,
                               
                               NVL((select SUM(A.ACT_THEORY_WEIGHT)
                                     from (select B.JUDGE_STOVE_NO,
                                                  TRIM(B.OP_PROCESS) OP_PROCESS,
                                                  B.m_mat_no,
                                                  SUM(B.ACT_THEORY_WEIGHT) ACT_THEORY_WEIGHT
                                             from PORT_MIL_BATCH_SAMPLE_RESULT B
                                            WHERE B.IS_VALID = '1'
                                              AND B.STATUS = '1'
                                            group by B.JUDGE_STOVE_NO,
                                                     B.m_mat_no,
                                                     B.op_process) A
                                    WHERE A.JUDGE_STOVE_NO =
                                          T1.JUDGE_STOVE_NO
                                      AND A.OP_PROCESS = '2'),
                                   0) FPD2,
                               
                               (select COUNT(1)
                                  from (select B.JUDGE_STOVE_NO,
                                               TRIM(B.OP_PROCESS) OP_PROCESS,
                                               B.m_mat_no,
                                               SUM(B.ACT_THEORY_WEIGHT) ACT_THEORY_WEIGHT
                                          from PORT_MIL_BATCH_SAMPLE_RESULT B
                                         WHERE B.IS_VALID = '1'
                                           AND B.STATUS = '1'
                                         group by B.JUDGE_STOVE_NO,
                                                  B.m_mat_no,
                                                  B.op_process) A
                                 WHERE A.JUDGE_STOVE_NO = T1.JUDGE_STOVE_NO
                                   AND A.OP_PROCESS = '3') FPZ3,
                               
                               NVL((select SUM(A.ACT_THEORY_WEIGHT)
                                     from (select B.JUDGE_STOVE_NO,
                                                  TRIM(B.OP_PROCESS) OP_PROCESS,
                                                  B.m_mat_no,
                                                  SUM(B.ACT_THEORY_WEIGHT) ACT_THEORY_WEIGHT
                                             from PORT_MIL_BATCH_SAMPLE_RESULT B
                                            WHERE B.IS_VALID = '1'
                                              AND B.STATUS = '1'
                                            group by B.JUDGE_STOVE_NO,
                                                     B.m_mat_no,
                                                     B.op_process) A
                                    WHERE A.JUDGE_STOVE_NO =
                                          T1.JUDGE_STOVE_NO
                                      AND A.OP_PROCESS = '3'),
                                   0) FPD3,
                               
                               (select COUNT(1)
                                  from (select B.JUDGE_STOVE_NO,
                                               TRIM(B.OP_PROCESS) OP_PROCESS,
                                               B.m_mat_no,
                                               SUM(B.ACT_THEORY_WEIGHT) ACT_THEORY_WEIGHT
                                          from PORT_MIL_BATCH_SAMPLE_RESULT B
                                         WHERE B.IS_VALID = '1'
                                           AND B.STATUS = '1'
                                         group by B.JUDGE_STOVE_NO,
                                                  B.m_mat_no,
                                                  B.op_process) A
                                 WHERE A.JUDGE_STOVE_NO = T1.JUDGE_STOVE_NO
                                   AND A.OP_PROCESS = '4') FPZ4,
                               
                               NVL((select SUM(A.ACT_THEORY_WEIGHT)
                                     from (select B.JUDGE_STOVE_NO,
                                                  TRIM(B.OP_PROCESS) OP_PROCESS,
                                                  B.m_mat_no,
                                                  SUM(B.ACT_THEORY_WEIGHT) ACT_THEORY_WEIGHT
                                             from PORT_MIL_BATCH_SAMPLE_RESULT B
                                            WHERE B.IS_VALID = '1'
                                              AND B.STATUS = '1'
                                            group by B.JUDGE_STOVE_NO,
                                                     B.m_mat_no,
                                                     B.op_process) A
                                    WHERE A.JUDGE_STOVE_NO =
                                          T1.JUDGE_STOVE_NO
                                      AND A.OP_PROCESS = '4'),
                                   0) FPD4,
                               
                               (select COUNT(1)
                                  from (select B.JUDGE_STOVE_NO,
                                               TRIM(B.OP_PROCESS) OP_PROCESS,
                                               B.m_mat_no,
                                               SUM(B.ACT_THEORY_WEIGHT) ACT_THEORY_WEIGHT
                                          from PORT_MIL_BATCH_SAMPLE_RESULT B
                                         WHERE 1 = 1
                                           AND B.IS_VALID = '1'
                                           AND B.STATUS = '1'
                                         group by B.JUDGE_STOVE_NO,
                                                  B.m_mat_no,
                                                  B.op_process) A
                                 WHERE A.JUDGE_STOVE_NO = T1.JUDGE_STOVE_NO
                                   AND A.OP_PROCESS = '5') FPZ5,
                               
                               NVL((select SUM(A.ACT_THEORY_WEIGHT)
                                     from (select B.JUDGE_STOVE_NO,
                                                  TRIM(B.OP_PROCESS) OP_PROCESS,
                                                  B.m_mat_no,
                                                  SUM(B.ACT_THEORY_WEIGHT) ACT_THEORY_WEIGHT
                                             from PORT_MIL_BATCH_SAMPLE_RESULT B
                                            WHERE B.IS_VALID = '1'
                                              AND B.STATUS = '1'
                                            group by B.JUDGE_STOVE_NO,
                                                     B.m_mat_no,
                                                     B.op_process) A
                                    WHERE A.JUDGE_STOVE_NO =
                                          T1.JUDGE_STOVE_NO
                                      AND A.OP_PROCESS = '5'),
                                   0) FPD5,
                               
                               (select COUNT(1)
                                  from (select B.JUDGE_STOVE_NO,
                                               TRIM(B.OP_PROCESS) OP_PROCESS,
                                               B.m_mat_no,
                                               SUM(B.ACT_THEORY_WEIGHT) ACT_THEORY_WEIGHT
                                          from PORT_MIL_BATCH_SAMPLE_RESULT B
                                         WHERE B.IS_VALID = '1'
                                           AND B.STATUS = '1'
                                         group by B.JUDGE_STOVE_NO,
                                                  B.m_mat_no,
                                                  B.op_process) A
                                 WHERE A.JUDGE_STOVE_NO = T1.JUDGE_STOVE_NO
                                   AND A.OP_PROCESS = '6') FPZ6,
                               
                               NVL((select SUM(A.ACT_THEORY_WEIGHT)
                                     from (select B.JUDGE_STOVE_NO,
                                                  TRIM(B.OP_PROCESS) OP_PROCESS,
                                                  B.m_mat_no,
                                                  SUM(B.ACT_THEORY_WEIGHT) ACT_THEORY_WEIGHT
                                             from PORT_MIL_BATCH_SAMPLE_RESULT B
                                            WHERE B.IS_VALID = '1'
                                              AND B.STATUS = '1'
                                            group by B.JUDGE_STOVE_NO,
                                                     B.m_mat_no,
                                                     B.op_process) A
                                    WHERE A.JUDGE_STOVE_NO =
                                          T1.JUDGE_STOVE_NO
                                      AND A.OP_PROCESS = '6'),
                                   0) FPD6,
                               
                               (SELECT sum(A.act_count)
                                  FROM PORT_MIL_BATCH_SAMPLE_RESULT A
                                 WHERE A.IS_VALID = '1'
                                   AND A.STATUS <> '1'
                                   AND (TRIM(A.OP_PROCESS) <> '7' OR
                                       A.OP_PROCESS IS NULL)
                                   AND SUBSTR(A.JUDGE_STOVE_NO, -2) = '01'
                                   AND A.JUDGE_STOVE_NO = T1.JUDGE_STOVE_NO) HGZ7,
                               
                               (SELECT SUM(A.ACT_THEORY_WEIGHT)
                                  FROM PORT_MIL_BATCH_SAMPLE_RESULT A
                                 WHERE A.IS_VALID = '1'
                                   AND A.STATUS <> '1'
                                   AND (TRIM(A.OP_PROCESS) <> '7' OR
                                       A.OP_PROCESS IS NULL)
                                   AND SUBSTR(A.JUDGE_STOVE_NO, -2) = '01'
                                   AND A.JUDGE_STOVE_NO = T1.JUDGE_STOVE_NO) HGD7,
                               
                               NVL((select sum(A.act_count)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.STATUS = '2'
                                      AND TRIM(A.OP_PROCESS) = '7'
                                      AND A.JUDGE_STOVE_NO =
                                          T1.JUDGE_STOVE_NO),
                                   0) FPZ7,
                               
                               NVL((select SUM(A.ACT_THEORY_WEIGHT)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.STATUS = '2'
                                      AND TRIM(A.OP_PROCESS) = '7'
                                      AND A.JUDGE_STOVE_NO =
                                          T1.JUDGE_STOVE_NO),
                                   0) FPD7,
                               
                               NVL((select sum(1)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.STATUS = '2'
                                      AND TRIM(A.OP_PROCESS) = '9'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) FPZ9,
                               
                               NVL((select sum(A.act_count)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.STATUS = '2'
                                      AND TRIM(A.OP_PROCESS) = '9'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) FPD9,
                               
                               NVL((select sum(A.act_count)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.STATUS = '3'
                                      AND TRIM(A.OP_PROCESS) = '9'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) XXZ9,
                               
                               NVL((select SUM(A.ACT_THEORY_WEIGHT)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.STATUS = '3'
                                      AND TRIM(A.OP_PROCESS) = '9'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) XXD9,
                               
                               NVL((select sum(A.act_count)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.STATUS IN ('2', '5')
                                      AND TRIM(A.OP_PROCESS) = '10'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) FPZ10,
                               
                               NVL((select SUM(A.ACT_THEORY_WEIGHT)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.STATUS IN ('2', '5')
                                      AND TRIM(A.OP_PROCESS) = '10'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) FPD10,
                               
                               NVL((select sum(A.act_count)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.STATUS = '3'
                                      AND TRIM(A.OP_PROCESS) = '10'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) XXZ10,
                               
                               NVL((select SUM(A.ACT_THEORY_WEIGHT)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.STATUS = '3'
                                      AND TRIM(A.OP_PROCESS) = '10'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) XXD10,
                               
                               NVL((select sum(A.act_count)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.STATUS = '2'
                                      AND TRIM(A.OP_PROCESS) = '11'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) FPZ11,
                               
                               NVL((select SUM(A.ACT_THEORY_WEIGHT)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.STATUS = '2'
                                      AND TRIM(A.OP_PROCESS) = '11'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) FPD11,
                               
                               NVL((select sum(A.act_count)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.STATUS = '3'
                                      AND TRIM(A.OP_PROCESS) = '11'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) XXZ11,
                               
                               NVL((select SUM(A.ACT_THEORY_WEIGHT)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.STATUS = '3'
                                      AND TRIM(A.OP_PROCESS) = '11'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) XXD11,
                               
                               NVL((select sum(1)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.GROUP_FLAG = '1'
                                      AND TRIM(A.OP_PROCESS) = '9'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) ZLZ9,
                               
                               NVL((select sum(A.ACT_THEORY_WEIGHT)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.GROUP_FLAG = '1'
                                      AND TRIM(A.OP_PROCESS) = '9'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) ZLD9,
                               
                               NVL((select sum(1)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.GROUP_FLAG = '1'
                                      AND TRIM(A.OP_PROCESS) = '10'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) ZLZ10,
                               
                               NVL((select sum(A.ACT_THEORY_WEIGHT)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.GROUP_FLAG = '1'
                                      AND TRIM(A.OP_PROCESS) = '10'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) ZLD10,
                               
                               NVL((select sum(1)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.GROUP_FLAG = '1'
                                      AND TRIM(A.OP_PROCESS) = '11'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) ZLZ11,
                               
                               NVL((select sum(A.ACT_THEORY_WEIGHT)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.GROUP_FLAG = '1'
                                      AND TRIM(A.OP_PROCESS) = '11'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) ZLD11,
                               
                               (SELECT DECODE(B.DIRECTOR_QUANTITY,
                                              0,
                                              '',
                                              TO_CHAR(NVL(B.QUALIFIED_BRANCH, 0) * 100 /
                                                      B.DIRECTOR_QUANTITY,
                                                      'FM990.00') || '%')
                                  FROM mil_surface_result B
                                 WHERE B.JUDGE_STOVE_NO = T1.JUDGE_STOVE_NO) qualifiedRate,
                               
                               SUM(B.FEED_NUM_PLAN) SLZ,
                               SUM(B.MAT_TOTAL_HEIGHT -
                                   B.FEED_NUM * DECODE(B.CUT_TARGET,
                                          '返废',
                                          B.CUT_WEIGHT,
                                        /*  '回库',
                                          NVL(round(B.CUT_WEIGHT / B.FEED_NUM,
                                                    3),
                                              0),*/
                                          0)) SLD,
                               SUM(B.FEED_NUM_PLAN * B.DB_NUM) *
                               MAX(T1.SAW_NUM) YJZ,
                               
                               NVL((select sum(A.act_count)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.STATUS = '1'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) undeterminedNum,
                               
                               NVL((select sum(A.INPUT_WEIGHT)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.STATUS = '1'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) undeterminedD,
                               
                               NVL((select sum(A.act_count)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.STATUS IN ('2', '5')
                                      AND A.OP_PROCESS <> '14'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) ScrapNum,
                               
                               NVL((select sum(A.ACT_THEORY_WEIGHT)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.STATUS IN ('2', '5')
                                      AND A.OP_PROCESS <> '14'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) ScrapD,
                               
                               NVL((select sum(A.act_count)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.STATUS = '2'
                                      AND A.OP_PROCESS = '14'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) FQY,
                               
                               NVL((select sum(A.act_count)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.STATUS = '6'
                                      AND A.PLAN_ID = T1.ID
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) WWFPZ,
                               
                               NVL((SELECT NVL(SUM(T12.QUALIFIED_NUM), 0)
                                     FROM MIL_INSTORE_RESULT T12
                                    WHERE T12.RESULT_NO = T1.ID
                                      AND REGEXP_REPLACE(T12.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')
                                      AND T12.NODE_FUR_FLAG = '1'),
                                   0) XXZ,
                               
                               NVL((SELECT NVL(SUM(T12.QUALIFIED_TONS), 0)
                                     FROM MIL_INSTORE_RESULT T12
                                    WHERE T12.RESULT_NO = T1.ID
                                      AND REGEXP_REPLACE(T12.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')
                                      AND T12.NODE_FUR_FLAG = '1'),
                                   0) XXD,
                               
                               NVL((SELECT NVL(SUM(T12.QUALIFIED_NUM), 0)
                                     FROM MIL_INSTORE_RESULT T12
                                    WHERE T12.RESULT_NO = T1.ID
                                      AND REGEXP_REPLACE(T12.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) HGZ12,
                               
                               NVL((SELECT NVL(SUM(T12.QUALIFIED_TONS), 0)
                                     FROM MIL_INSTORE_RESULT T12
                                    WHERE T12.RESULT_NO = T1.ID
                                      AND REGEXP_REPLACE(T12.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) HGD12,
                               
                               0 HGM12,
                               
                               NVL((select SUM(Q.ACT_COUNT)
                                     from QCM_ZG_JUGDE_APPLY Q
                                    WHERE Q.VALIDFLAG = '20'
                                      AND Q.APPLY_FLAG = '0'
                                      AND Q.PROCESS_CODE = 'D'
                                      AND Q.JUDGE_STOVE_NO =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) PDZ,
                               
                               NVL((select DECODE(NVL(SUM(Q.ACT_WEIGHT), 0),
                                                 0,
                                                 SUM(Q.ACT_THEORY_WEIGHT),
                                                 SUM(Q.ACT_WEIGHT))
                                     from QCM_ZG_JUGDE_APPLY Q
                                    WHERE Q.VALIDFLAG = '20'
                                      AND Q.APPLY_FLAG = '0'
                                      AND Q.PROCESS_CODE = 'D'
                                      AND Q.JUDGE_STOVE_NO =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) PDD,
                               
                               NVL((select SUM(Q.ACT_LEN)
                                     from QCM_ZG_JUGDE_APPLY Q
                                    WHERE 1 = 1
                                      AND Q.VALIDFLAG = '20'
                                      AND Q.APPLY_FLAG = '0'
                                      AND Q.PROCESS_CODE = 'D'
                                      AND Q.JUDGE_STOVE_NO =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) PDM,
                               
                               NVL((select SUM(Q.ACT_COUNT)
                                     from QCM_ZG_JUGDE_APPLY Q
                                    WHERE Q.APPLY_FLAG = '0'
                                      AND Q.PROCESS_CODE = 'D'
                                      AND Q.JUDGE_STOVE_NO =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) SPZ,
                               
                               NVL((select DECODE(NVL(SUM(Q.ACT_WEIGHT), 0),
                                                 0,
                                                 SUM(Q.ACT_THEORY_WEIGHT),
                                                 SUM(Q.ACT_WEIGHT))
                                     from QCM_ZG_JUGDE_APPLY Q
                                    WHERE Q.APPLY_FLAG = '0'
                                      AND Q.PROCESS_CODE = 'D'
                                      AND Q.JUDGE_STOVE_NO =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) SPD,
                               
                               NVL((select SUM(Q.ACT_LEN)
                                     from QCM_ZG_JUGDE_APPLY Q
                                    WHERE Q.APPLY_FLAG = '0'
                                      AND Q.PROCESS_CODE = 'D'
                                      AND Q.JUDGE_STOVE_NO =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                   0) SPM,
                               
                               (NVL((select sum(A.act_count)
                                      from PORT_MIL_BATCH_SAMPLE_RESULT A
                                     WHERE A.IS_VALID = '1'
                                       AND A.STATUS IN ('3', '4')
                                       AND A.OP_PROCESS <> '12'
                                       AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                           REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')
                                       AND NVL(A.PRO_PLAN_ID, '/') =
                                           NVL(T1.PRO_PLAN_ID, '/')
                                       AND NVL(A.GX_PLAN_NO, '/') =
                                           NVL(T1.GX_PLAN_NO, '/')),
                                    0) +
                               NVL((SELECT NVL(SUM(T12.OFFLINE_NUM), 0)
                                      FROM MIL_INSTORE_RESULT T12
                                     WHERE T12.RESULT_NO = T1.ID
                                       AND REGEXP_REPLACE(T12.JUDGE_STOVE_NO, '-.*', '') =
                                           REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')),
                                    0)) LXZ,
                               
                               NVL((select sum(A.act_count)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.STATUS = '4'
                                      AND A.GROUP_FLAG = '0'
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')
                                      AND NVL(A.PRO_PLAN_ID, '/') =
                                          NVL(T1.PRO_PLAN_ID, '/')
                                      AND NVL(A.GX_PLAN_NO, '/') =
                                          NVL(T1.GX_PLAN_NO, '/')),
                                   0) FXZ,
                               
                               NVL((select sum(A.act_count)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.GROUP_FLAG = '1'
                                      AND TRIM(A.OP_PROCESS) > 6
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')
                                      AND NVL(A.PRO_PLAN_ID, '/') =
                                          NVL(T1.PRO_PLAN_ID, '/')
                                      AND NVL(A.GX_PLAN_NO, '/') =
                                          NVL(T1.GX_PLAN_NO, '/')),
                                   0) ZLZ,
                               
                               NVL((select sum(A.ACT_THEORY_WEIGHT)
                                     from PORT_MIL_BATCH_SAMPLE_RESULT A
                                    WHERE A.IS_VALID = '1'
                                      AND A.GROUP_FLAG = '1'
                                      AND TRIM(A.OP_PROCESS) > 6
                                      AND REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                          REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')
                                      AND NVL(A.PRO_PLAN_ID, '/') =
                                          NVL(T1.PRO_PLAN_ID, '/')
                                      AND NVL(A.GX_PLAN_NO, '/') =
                                          NVL(T1.GX_PLAN_NO, '/')),
                                   0) ZLD,
                               
                               (select MAX(A.BAL_YEAR_MONTH)
                                  from PORT_MIL_BATCH_SAMPLE_RESULT A
                                 WHERE REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') =
                                       REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')
                                   AND NVL(A.PRO_PLAN_ID, '/') =
                                       NVL(T1.PRO_PLAN_ID, '/')
                                   AND NVL(A.GX_PLAN_NO, '/') =
                                       NVL(T1.GX_PLAN_NO, '/')) BAL_YEAR_MONTH,
                               
                               TO_CHAR(NVL((select SUM(A.ACT_THEORY_WEIGHT)
                                             from PORT_MIL_BATCH_SAMPLE_RESULT A
                                            WHERE A.IS_VALID = '1'
                                              AND A.STATUS <> '2'
                                              AND A.STATUS <> '3'
                                              AND A.STATUS <> '6'
                                              AND A.JUDGE_STOVE_NO =
                                                  T1.JUDGE_STOVE_NO),
                                           0) / SUM(B.MAT_TOTAL_HEIGHT) * 100,
                                       'FM990.00') || '%' RATE,
                               
                               SUM(B.MAT_TOTAL_HEIGHT) *
                               (1 - NVL((select R.BURNNING_RATE
                                           from MIL_FUR_RESULT R
                                          WHERE R.JUDGE_STOVE_NO =
                                                T1.JUDGE_STOVE_NO) / 100,
                                        0)) -
                               DECODE(MAX(T1.CONTROL_THICKP),
                                      0,
                                      0,
                                      (MAX(T1.CUT_HEAD_LENGTHP) +
                                      MAX(T1.CUT_TRAIL_LENGTHP)) / 1000 *
                                      (0.02466 * MAX(T1.CONTROL_THICKP) / 1000 * 1.02 *
                                      ((SUBSTR(MAX(T1.PIPE_SIZE),
                                                1,
                                                INSTR(MAX(T1.PIPE_SIZE), '*') - 1)) *
                                      (CASE
                                        WHEN INSTR(MAX(T1.VARIETIES), '套管') > 0 THEN
                                         1.005
                                        WHEN INSTR(MAX(T1.VARIETIES), '油管') > 0 THEN
                                         1.005
                                        ELSE
                                         1
                                      END) -
                                      (MAX(T1.CONTROL_THICKP) / 1000 * 1.02)) *
                                      SUM(B.FEED_NUM_PLAN * B.DB_NUM))) YJD,
                               
                               TO_CHAR(NVL((select DECODE(NVL(SUM(Q.ACT_WEIGHT),
                                                             0),
                                                         0,
                                                         SUM(Q.ACT_THEORY_WEIGHT),
                                                         SUM(Q.ACT_WEIGHT))
                                             from QCM_ZG_JUGDE_APPLY Q
                                            WHERE Q.VALIDFLAG = '20'
                                              AND Q.APPLY_FLAG = '0'
                                              AND Q.JUDGE_STOVE_NO =
                                                  REGEXP_REPLACE(T1.JUDGE_STOVE_NO,
                                                                 '-.*',
                                                                 '')),
                                           0) * 100 / SUM(B.MAT_TOTAL_HEIGHT),
                                       'FM990.00') || '%' RATE2
                        
                          from MIL_PLAN T1, MIL_FEED_PLAN B
                         WHERE T1.JUDGE_STOVE_NO = B.JUDGE_STOVE_NO
                           AND T1.PRO_PLAN_ID = B.PRO_PLAN_ID
   							AND T1.BACK_SLAB_FLAG <> '2'
                           AND T1.JUDGE_STOVE_NO =
                               REGEXP_REPLACE(V_JUDGE_STOVE_NO, '-.*', '') || '-01'
                           AND T1.LOT_NO = V_LOT_NO
                           AND T1.PLINE_CODE = V_PLINE_CODE
                           AND NVL(T1.PRO_PLAN_ID, '/') =
                               NVL(V_PRO_PLAN_ID, '/')
                           AND NVL(T1.GX_PLAN_NO, '/') =
                               NVL(V_GX_PLAN_NO, '/')
                         GROUP BY T1.JUDGE_STOVE_NO,
                                  T1.LOT_NO,
                                  T1.PLINE_CODE,
                                  T1.JUDGE_STOVE_NO,
                                  T1.ID,
                                  T1.PRO_PLAN_ID,
                                  t1.gx_plan_no,
                                  T1.ID,
                                  T1.CONTRACT_NO) AA
                 ORDER BY AA.FEED_TIME ASC) LOOP
    IF (V_COUNT > 0) THEN
      UPDATE MIL_PROCESSES T
         SET T.YJZ             = MYROW.YJZ,
             T.YJD             = MYROW.YJD,
             T.SLZ             = MYROW.SLZ,
             T.SLD             = MYROW.SLD,
             T.ZZL            =
           (SELECT SUM(TR.QUALIFIED_WT)
              FROM MIL_CONTROL_LOG TR
             WHERE TR.JUDGE_STOVE_NO = T.JUDGE_STOVE_NO || '-01'),
           T.ZZZ            =
           (SELECT SUM(TR.QUALIFIED_NUM)
              FROM MIL_CONTROL_LOG TR
             WHERE TR.JUDGE_STOVE_NO = T.JUDGE_STOVE_NO || '-01'),
             T.UNDETERMINEDNUM = MYROW.UNDETERMINEDNUM,
             T.UNDETERMINEDD   = MYROW.UNDETERMINEDD,
             T.SCRAPNUM        = MYROW.SCRAPNUM,
             T.SCRAPD          = MYROW.SCRAPD,
             T.WWFPZ           = MYROW.WWFPZ,
             T.FQY             = MYROW.FQY,
             T.LXZ             = MYROW.LXZ,
             T.FXZ             = MYROW.FXZ,
             T.ZLZ             = MYROW.ZLZ,
             T.ZLD             = MYROW.ZLD,
             T.SPZ             = MYROW.SPZ,
             T.SPD             = MYROW.SPD,
             T.SPM             = MYROW.SPM,
             T.PDZ             = MYROW.PDZ,
             T.PDD             = MYROW.PDD,
             T.PDM             = MYROW.PDM,
             T.HGZ1            = MYROW.HGZ1,
             T.HGD1            = MYROW.HGD1,
             T.FPZ1            = MYROW.FPZ1,
             T.FPD1            = MYROW.FPD1,
             T.HGZ2            = MYROW.HGZ2,
             T.HGD2            = MYROW.HGD2,
             T.FPZ2            = MYROW.FPZ2,
             T.FPD2            = MYROW.FPD2,
             T.HGZ3            = MYROW.HGZ3,
             T.HGD3            = MYROW.HGD3,
             T.FPZ3            = MYROW.FPZ3,
             T.FPD3            = MYROW.FPD3,
             T.HGZ4            = MYROW.HGZ4,
             T.HGD4            = MYROW.HGD4,
             T.FPZ4            = MYROW.FPZ4,
             T.FPD4            = MYROW.FPD4,
             T.HGZ5            = MYROW.HGZ5,
             T.HGD5            = MYROW.HGD5,
             T.FPZ5            = MYROW.FPZ5,
             T.FPD5            = MYROW.FPD5,
             T.HGZ6            = MYROW.HGZ6,
             T.HGD6            = MYROW.HGD6,
             T.FPZ6            = MYROW.FPZ6,
             T.FPD6            = MYROW.FPD6,
             T.HGZ7            = MYROW.HGZ7,
             T.HGD7            = MYROW.HGD7,
             T.FPZ7            = MYROW.FPZ7,
             T.FPD7            = MYROW.FPD7,
             T.HGZ9            = MYROW.HGZ9,
             T.HGD9            = MYROW.HGD9,
             T.FPZ9            = MYROW.FPZ9,
             T.FPD9            = MYROW.FPD9,
             T.HGZ10           = MYROW.HGZ10,
             T.HGD10           = MYROW.HGD10,
             T.FPZ10           = MYROW.FPZ10,
             T.FPD10           = MYROW.FPD10,
             T.HGZ11           = MYROW.HGZ11,
             T.HGD11           = MYROW.HGD11,
             T.FPZ11           = MYROW.FPZ11,
             T.FPD11           = MYROW.FPD11,
             T.HGZ12           = MYROW.HGZ12,
             T.HGD12           = MYROW.HGD12,
             T.RATE            = MYROW.RATE,
             T.QUALIFIEDRATE   = MYROW.QUALIFIEDRATE,
             T.RATE2           = MYROW.RATE2,
             T.NODE_STATUS1    = MYROW.NODE_STATUS1
       WHERE T.JUDGE_STOVE_NO = MYROW.JUDGE_STOVE_NO
         AND T.LOT_NO = V_LOT_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, '/');
    
    ELSIF (V_COUNT = 0) THEN
      INSERT INTO MIL_PROCESSES
        (ID,
         JUDGE_STOVE_NO,
         LOT_NO,
         PRO_PLAN_ID,
         GX_PLAN_NO,
         PLINE_CODE,
         TARGET,
         VARIETIES,
         VARIETIES_CODE,
         STEELCODE,
         STEELNAME,
         GRADECODE,
         GRADENAME,
         PIPE_SIZE,
         PIPE_SIZE_CODE,
         BUCKLE_TYPE,
         BUCKLE_TYPE_CODE,
         FEED_TIME,
         SLZ,
         SLD,
         YJZ,
         YJD,
         UNDETERMINEDNUM,
         UNDETERMINEDD,
         SCRAPNUM,
         SCRAPD,
         WWFPZ,
         FQY,
         LXZ,
         FXZ,
         ZLZ,
         ZLD,
         SPZ,
         SPD,
         SPM,
         PDZ,
         PDD,
         PDM,
         HGZ1,
         HGD1,
         FPZ1,
         FPD1,
         HGZ2,
         HGD2,
         FPZ2,
         FPD2,
         HGZ3,
         HGD3,
         FPZ3,
         FPD3,
         HGZ4,
         HGD4,
         FPZ4,
         FPD4,
         HGZ5,
         HGD5,
         FPZ5,
         FPD5,
         HGZ6,
         HGD6,
         FPZ6,
         FPD6,
         HGZ7,
         HGD7,
         FPZ7,
         FPD7,
         HGZ9,
         HGD9,
         FPZ9,
         FPD9,
         HGZ10,
         HGD10,
         FPZ10,
         FPD10,
         HGZ11,
         HGD11,
         FPZ11,
         FPD11,
         HGZ12,
         HGD12,
         RATE,
         QUALIFIEDRATE,
         RATE2,
         --ZLC,
         --ISCLOSE,
         CONTRACT_NO,
         BAL_YEAR_MONTH,
         NODE_STATUS1)
      VALUES
        (MYROW.ID,
         MYROW.JUDGE_STOVE_NO,
         MYROW.LOT_NO,
         MYROW.PRO_PLAN_ID,
         MYROW.GX_PLAN_NO,
         MYROW.PLINE_CODE,
         MYROW.TARGET,
         MYROW.VARIETIES,
         MYROW.VARIETIES_CODE,
         MYROW.STEELCODE,
         MYROW.STEELNAME,
         MYROW.GRADECODE,
         MYROW.GRADENAME,
         MYROW.PIPE_SIZE,
         MYROW.PIPE_SIZE_CODE,
         MYROW.BUCKLE_TYPE,
         MYROW.BUCKLE_TYPE_CODE,
         MYROW.FEED_TIME,
         MYROW.SLZ,
         MYROW.SLD,
         MYROW.YJZ,
         MYROW.YJD,
         MYROW.UNDETERMINEDNUM,
         MYROW.UNDETERMINEDD,
         MYROW.SCRAPNUM,
         MYROW.SCRAPD,
         MYROW.WWFPZ,
         MYROW.FQY,
         MYROW.LXZ,
         MYROW.FXZ,
         MYROW.ZLZ,
         MYROW.ZLD,
         MYROW.SPZ,
         MYROW.SPD,
         MYROW.SPM,
         MYROW.PDZ,
         MYROW.PDD,
         MYROW.PDM,
         MYROW.HGZ1,
         MYROW.HGD1,
         MYROW.FPZ1,
         MYROW.FPD1,
         MYROW.HGZ2,
         MYROW.HGD2,
         MYROW.FPZ2,
         MYROW.FPD2,
         MYROW.HGZ3,
         MYROW.HGD3,
         MYROW.FPZ3,
         MYROW.FPD3,
         MYROW.HGZ4,
         MYROW.HGD4,
         MYROW.FPZ4,
         MYROW.FPD4,
         MYROW.HGZ5,
         MYROW.HGD5,
         MYROW.FPZ5,
         MYROW.FPD5,
         MYROW.HGZ6,
         MYROW.HGD6,
         MYROW.FPZ6,
         MYROW.FPD6,
         MYROW.HGZ7,
         MYROW.HGD7,
         MYROW.FPZ7,
         MYROW.FPD7,
         MYROW.HGZ9,
         MYROW.HGD9,
         MYROW.FPZ9,
         MYROW.FPD9,
         MYROW.HGZ10,
         MYROW.HGD10,
         MYROW.FPZ10,
         MYROW.FPD10,
         MYROW.HGZ11,
         MYROW.HGD11,
         MYROW.FPZ11,
         MYROW.FPD11,
         MYROW.HGZ12,
         MYROW.HGD12,
         MYROW.RATE,
         MYROW.QUALIFIEDRATE,
         MYROW.RATE2,
         --MYROW.ZLC,
         -- MYROW.ISCLOSE,
         MYROW.CONTRACT_NO,
         MYROW.BAL_YEAR_MONTH,
         MYROW.NODE_STATUS1);
    
    END IF;
  
    IF (MYROW.YJD > MYROW.HGD12) THEN
      UPDATE MIL_PROCESSES T
         SET T.ZLC = NVL(MYROW.YJD, 0) - NVL(MYROW.HGD12, 0)
       WHERE T.JUDGE_STOVE_NO = MYROW.JUDGE_STOVE_NO
         AND T.LOT_NO = V_LOT_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, '/');
    ELSE
      UPDATE MIL_PROCESSES T
         SET T.ZLC = 0
       WHERE T.JUDGE_STOVE_NO = MYROW.JUDGE_STOVE_NO
         AND T.LOT_NO = V_LOT_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, '/');
    END IF;
  END LOOP;

END;
  ]]>
    </query>
    
    <query id = "FrmInOnlineStore.updateJudgeStoveNoSeq" desc = "更新判定表JUDGE_STOVE_NO_SEQ">
<![CDATA[
  update QCM_ZG_JUGDE_APPLY t
     set t.JUDGE_STOVE_NO_SEQ =
         (select dbms_lob.substr(wm_concat(distinct zg_stove_sqe))
            from MAT_BC_M
           where JUDGE_STOVE_NO = t.judge_stove_no
             and jugde_apply_code = t.jugde_apply_code)
   where t.IS_FLAG = '0'
     and t.IS_ALL_SCRAP = '0'
     and t.VALIDFLAG = '00'
     AND T.PROCESS_CODE = 'D'
     and t.judge_stove_no = ?
       ]]>
</query>
    
    <query id = "FrmInOnlineStore.updateJudgeStoveNoSeq2" desc = "更新判定表投料量">
<![CDATA[
DECLARE
  V_JUDGE_STOVE_NO   QCM_ZG_JUGDE_APPLY.JUDGE_STOVE_NO%TYPE := ?;
  V_JUGDE_APPLY_CODE QCM_ZG_JUGDE_APPLY.JUGDE_APPLY_CODE%TYPE := ?;
  V_COUNT            QCM_ZG_JUGDE_APPLY.ACT_COUNT%TYPE := NULL;
BEGIN
  FOR MYROW IN (SELECT T.*
                  FROM QCM_ZG_JUGDE_APPLY T
                 WHERE T.JUGDE_APPLY_CODE = V_JUGDE_APPLY_CODE
                   AND T.PROCESS_CODE = 'D'
                   AND T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO) LOOP
  
    SELECT NVL((SELECT COUNT(1)
                 FROM PORT_MIL_BATCH_SAMPLE_RESULT P
                WHERE REGEXP_REPLACE(P.JUDGE_STOVE_NO, '-.*', '') =
                      V_JUDGE_STOVE_NO
                  AND P.STATUS IN ('0', '3')),
               0) - NVL((SELECT COUNT(1)
                          FROM PORT_MIL_BATCH_SAMPLE_RESULT P
                         WHERE REGEXP_REPLACE(P.JUDGE_STOVE_NO, '-.*', '') =
                               V_JUDGE_STOVE_NO
                           AND P.TR_FLAG2 IS NOT NULL),
                        0)
      INTO V_COUNT
      FROM DUAL;
    IF (V_COUNT > MYROW.ACT_COUNT) THEN
      UPDATE PORT_MIL_BATCH_SAMPLE_RESULT P
         SET P.TR_FLAG2 = MYROW.JUGDE_APPLY_CODE ||
                          MYROW.JUGDE_APPLY_SEQUENO
       WHERE P.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO || '-01'
         AND P.TR_FLAG2 IS NULL
         AND ROWNUM <= MYROW.ACT_COUNT;
    
    ELSE
      UPDATE PORT_MIL_BATCH_SAMPLE_RESULT P
         SET P.TR_FLAG2 = MYROW.JUGDE_APPLY_CODE ||
                          MYROW.JUGDE_APPLY_SEQUENO
       WHERE P.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO || '-01'
         AND P.TR_FLAG2 IS NULL;
    END IF;
  
    --更新成品送判量统计表
    IF (MYROW.TARGET = 'A') THEN
      SET_QCM_ZC_APPLY2(MYROW.ORD_LN_DLY_PK);
    END IF;
  END LOOP;

  FOR MYROW2 IN (SELECT P.TR_FLAG2, SUM(P.INPUT_WEIGHT) INPUT_WEIGHT
                   FROM PORT_MIL_BATCH_SAMPLE_RESULT P
                  WHERE P.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO || '-01'
                  GROUP BY P.TR_FLAG2) LOOP
    UPDATE QCM_ZG_JUGDE_APPLY T
       SET T.INPUT_WEIGHT2 = MYROW2.INPUT_WEIGHT
     WHERE T.JUGDE_APPLY_CODE || T.JUGDE_APPLY_SEQUENO = MYROW2.TR_FLAG2
       AND T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
       AND T.PROCESS_CODE = 'D';
  END LOOP;
END;

       ]]>
</query>

<query id = "FrmInOnlineStore.updateJudgeStoveNoSeq3" desc = "天淮更新判定表投料量">
<![CDATA[
DECLARE
  V_JUDGE_STOVE_NO QCM_ZG_JUGDE_APPLY.JUDGE_STOVE_NO%TYPE := ?;
  V_PLINE_CODE     QCM_ZG_JUGDE_APPLY.PLINE_CODE%TYPE := ?;
  V_COUNT          QCM_ZG_JUGDE_APPLY.ACT_COUNT%TYPE := NULL;
  V_ACT_WEIGHT     QCM_ZG_JUGDE_APPLY.ACT_WEIGHT%TYPE := NULL;
  V_APPLY_TIME     QCM_ZG_JUGDE_APPLY.APPLY_TIME%TYPE := NULL;

BEGIN

  SELECT SUM(T.MAT_TOTAL_HEIGHT), SUM(T.DB_NUM * T.FEED_NUM)
    INTO V_ACT_WEIGHT, V_COUNT
    FROM MIL_FEED_PLAN T
   WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO || '-01'
     AND T.PLINE_CODE = V_PLINE_CODE;

  SELECT MIN(T.APPLY_TIME)
    INTO V_APPLY_TIME
    FROM QCM_ZG_JUGDE_APPLY T
   WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
     AND T.PLINE_CODE = V_PLINE_CODE;
--2021年12月25日后，天淮投料量一次带走
  IF (V_APPLY_TIME > TO_DATE('2021-12-25', 'YYYY-MM-DD')) THEN
    UPDATE QCM_ZG_JUGDE_APPLY T
       SET T.INPUT_COUNT   = 0,
           T.INPUT_WEIGHT  = 0,
           T.OUTPUT_COUNT  = 0,
           T.OUTPUT_WEIGHT = 0
     WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
       AND T.PLINE_CODE = V_PLINE_CODE;
       
       UPDATE QCM_ZG_JUGDE_APPLY T
       SET T.INPUT_COUNT   = V_COUNT,
           T.INPUT_WEIGHT  = V_ACT_WEIGHT,
           T.OUTPUT_COUNT  = V_COUNT,
           T.OUTPUT_WEIGHT = V_ACT_WEIGHT
     WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
       AND T.PLINE_CODE = V_PLINE_CODE
       AND T.APPLY_TIME = V_APPLY_TIME;
  
  END IF;
END;

       ]]>
</query>


    <query id = "FrmInOnlineStore.doQueryPortStoreNo" desc = "查询外委数据进程表库号">
<![CDATA[
	 select MAX(t.Storage_No) Storage_No
  from PORT_MIL_BATCH_SAMPLE_RESULT t
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.PLINE_CODE = ?
   AND T.STORAGE_NO IS NOT NULL
       ]]>
</query>

<query id = "FrmInOnlineStore.doQueryMilProcess" desc = "验证数据平衡">
	<![CDATA[
	 select NVL(T.YJZ - T.UNDETERMINEDNUM - T.SCRAPNUM - T.WWFPZ - T.ZLZ -
           T.HGZ12,
           1) ACOUNT
  from MIL_PROCESSES t
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.PRO_PLAN_ID = ?
   AND T.GX_PLAN_NO = ?
       ]]>	
	</query>


<query id = "FrmInOnlineStore.doQueryMilProcess" desc = "验证数据平衡">
	<![CDATA[
	 select NVL(T.YJZ - T.UNDETERMINEDNUM - T.SCRAPNUM - T.WWFPZ - T.ZLZ -
           T.HGZ12,
           1) ACOUNT
  from MIL_PROCESSES t
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.PRO_PLAN_ID = ?
   AND T.GX_PLAN_NO = ?
       ]]>	
	</query>
	
	<query id = "FrmInOnlineStore.updatePlnZyZgM" desc = "更新计划表计划状态">
	<![CDATA[
	 DECLARE
  V_JUDGE_STOVE_NO MIL_PROCESSES.JUDGE_STOVE_NO%TYPE := ?;
  V_PLINE_CODE     MIL_PROCESSES.PLINE_CODE%TYPE := ?;
  V_PRO_PLAN_ID    MIL_PROCESSES.PRO_PLAN_ID%TYPE := ?;
  V_GX_PLAN_NO     MIL_PROCESSES.GX_PLAN_NO%TYPE := ?;
  V_COUNT          MIL_PROCESSES.YJZ%TYPE := NULL;

BEGIN
  select NVL(T.YJZ - T.UNDETERMINEDNUM - T.SCRAPNUM - T.WWFPZ - T.LXZ + T.FXZ -
           T.HGZ12,
           1) + NVL(T.LXZ - T.FXZ - T.ZLZ, 1) ACOUNT
    INTO V_COUNT
    from MIL_PROCESSES 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;

  UPDATE PLN_ZY_ZG_M M
     SET M.PLANSTATUS = DECODE(V_COUNT, 0, '30', 20)
   WHERE M.FEED_HEAT_NO = V_JUDGE_STOVE_NO
     AND M.PLINE_CODE = V_PLINE_CODE
     AND M.PRO_PLAN_ID = V_PRO_PLAN_ID
     AND M.GX_PLAN_NO = V_GX_PLAN_NO;
END;
       ]]>	
	</query>
	
	<query id = "FrmInOnlineStore.selectDeliveryState" desc = "查询交货状态">
		select T.INWL_ID,
       T.INWL_DESC,
       T.OUTWL_ID,
       T.OUTWL_DESC,
       T.CRAFT_SEQ,
       T.JUDGE_STOVE_NO,
       GET_SHIPPED_STATE(T2.DESGIN_KEY, T.INDEX_SEQ, T.DECISION) DELIVERY_STATE_CODE,
       (SELECT A.BASENAME
          FROM COM_BASE_INFO A
         WHERE A.BASECODE =
               GET_SHIPPED_STATE(T2.DESGIN_KEY, T.INDEX_SEQ, T.DECISION)) DELIVERY_STATE_NAME
  from pln_zy_zg_m t, PLN_SALEORD t1, CRAFT_ORD_DESIGN T2
 where T.ORD_LN_DLY_PK = T1.ORD_LN_DLY_PK
   AND T1.ORD_LN_PK = T2.ORD_LN_PK
   AND T.CRAFT_SEQ = T2.CRAFT_SEQ
   and t.feed_heat_no = ?
   and t.pro_plan_id = ?
   and t.gx_plan_no = ?
 group by T.INWL_ID,
          T.INWL_DESC,
          T.JUDGE_STOVE_NO,
          T.OUTWL_ID,
          T.OUTWL_DESC,
          T2.DESGIN_KEY,
          T.DECISION,
          T.INDEX_SEQ,
          T.CRAFT_SEQ
	</query>
	
	<query id = "FrmInOnlineStore.selectZPJudgeStoveNo" desc = "查询组炉轧管上料炉号">
		select t.*
  from mil_plan t
 where t.judge_stove_no = ? || '-01'
   and t.pro_plan_id = ?
   and t.gx_plan_no = ?
	</query>
	
	<query id = "FrmInOnlineStore.selectZPDeliveryState" desc = "查询组交货状态">
		select T.INWL_ID,
       T.INWL_DESC,
       T.OUTWL_ID,
       T.OUTWL_DESC,
       T.CRAFT_SEQ,
       T.JUDGE_STOVE_NO,
       GET_SHIPPED_STATE(T2.DESGIN_KEY, T.INDEX_SEQ, T.DECISION) DELIVERY_STATE_CODE,
       (SELECT A.BASENAME
          FROM COM_BASE_INFO A
         WHERE A.BASECODE =
               GET_SHIPPED_STATE(T2.DESGIN_KEY, T.INDEX_SEQ, T.DECISION)) DELIVERY_STATE_NAME
  from pln_zy_zg_m t, PLN_SALEORD t1, CRAFT_ORD_DESIGN T2
 where T.ORD_LN_DLY_PK = T1.ORD_LN_DLY_PK
   AND T1.ORD_LN_PK = T2.ORD_LN_PK
   AND T.CRAFT_SEQ = T2.CRAFT_SEQ
      --and t.feed_heat_no = ?
   and t.pro_plan_id = ?
   and t.gx_plan_no = ?
 group by T.INWL_ID,
          T.INWL_DESC,
          T.OUTWL_ID,
          T.OUTWL_DESC,
          T.JUDGE_STOVE_NO,
          T2.DESGIN_KEY,
          T.DECISION,
          T.INDEX_SEQ,
          T.CRAFT_SEQ
	</query>
	
	<query id = "FrmInOnlineStore.selectCheckNo" desc = "查询检验编号">
	<![CDATA[
		select T.CHECK_NO
  from MIL_PLAN t
 where t.Judge_Stove_No = ? || '-01'
   and t.pro_plan_id = ?
   and t.gx_plan_no = ?
   ]]>
	</query>
	
	<query id = "FrmInOnlineStore.selectCutNo" desc = "查询外委分切数">
	<![CDATA[
	select NVL(MAX(T.SUBCONTRACT_COMPLETE_CUT), 1) CUT_NO
  from mil_offline_reslut t
 where t.judge_stove_no || '&' LIKE '%' || ? || '%'
   ]]>
	</query>
	
	<query id = "FrmInOnlineStore.selectTestPressure" desc = "查询外委水压信息">
	<![CDATA[
		SELECT *
  FROM HTT_ENTRUST_RESULT T
 WHERE JUDGE_STOVE_NO = ?
   AND INSTR(PROJECT_CODE, '702206') > 0
   AND ROWNUM = 1
   ]]>
	</query>
	
	<query id = "FrmInOnlineStore.selectZPJudgeStoveNo2" desc = "查询组批主炉号">
	<![CDATA[
		SELECT REGEXP_REPLACE(T.ZP_M_LH, '-.*', '') ZP_M_LH,
       LISTAGG(REGEXP_REPLACE(T.OLD_ZP_JUDGE_STOVE_NO, '-.*', ''), ',') within GROUP(order by T.ZP_JUDGE_STOVE_NO DESC) over(partition by T.ZP_JUDGE_STOVE_NO, T.ZP_LOT_NO) MEMO
  FROM MIL_OFFLINE_GROUP T
 WHERE T.ZP_JUDGE_STOVE_NO = ? || '-01'

union all

SELECT REGEXP_REPLACE(MAX(JUDGE_STOVE_NO), '-.*', '') ZP_M_LH, MEMO
  FROM (SELECT T.ZP_JUDGE_STOVE_NO,
               T.ZP_LOT_NO,
               T.GROUP_NUM,
               T.JUDGE_STOVE_NO,
               '荒管组炉(单倍坯)' ZL_TYPE,
               LISTAGG(REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', ''), ',') within GROUP(order by T.ZP_JUDGE_STOVE_NO) over(partition by T.ZP_JUDGE_STOVE_NO, T.ZP_LOT_NO) MEMO
          FROM MIL_FURNACES_RESLUT_DETIA T
         WHERE 1 = 1
           AND T.ZP_JUDGE_STOVE_NO = ? || '-01')
 GROUP BY ZP_JUDGE_STOVE_NO, ZP_LOT_NO, ZL_TYPE, MEMO

union all

SELECT REGEXP_REPLACE(MIN(JUDGE_STOVE_NO), '-.*', '') ZP_M_LH, MEMO
  FROM (select MIN(T.JUDGE_STOVE_NO) JUDGE_STOVE_NO,
               LISTAGG(REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', ''), ',') within GROUP(order by T.NEW_HEAT_NO) over(partition by T.NEW_HEAT_NO) MEMO
          from MIL_SLAB_SCRAP t
         WHERE T.GROUP_FLAG = 1
           AND T.NEW_HEAT_NO = ? || '-01'
         GROUP BY T.JUDGE_STOVE_NO, T.NEW_HEAT_NO)
 GROUP BY MEMO
 ]]>
	</query>
	
	<query id = "FrmInOnlineStore.doQueryZpJudgeStoveNo" desc = "验证是不是组炉炉号">
	<![CDATA[
		select COUNT(1) ACOUNT from MIL_OFFLINE_GROUP t WHERE SUBSTR(T.ZP_JUDGE_STOVE_NO,1,6) = ? AND T.PLINE_CODE = ?
   ]]>
	</query>
	
	<query id = "FrmInOnlineStore.doQueryZpMLh" desc = "查询组炉炉的送判信息">
	<![CDATA[
		select t.*
  from QCM_ZG_JUGDE_APPLY t
 WHERE T.PROCESS_CODE = 'D'
   AND T.JUDGE_STOVE_NO = ?
   AND T.PLINE_CODE = ?
   AND T.APPLY_FLAG = '0'
   AND T.IS_ALL_SCRAP = '0'
   ]]>
	</query>
<query id = "FrmInOnlineStore.QueryQcmAddAsk" desc = "查询合同附加要求信息 （QCM_ADD_ASK）">
<![CDATA[
select t.* from QCM_ADD_ASK t WHERE T.JUGDE_APPLY_CODE = ? AND T.JUDGE_STOVE_NO = ?
  ]]>
</query>

<query id = "FrmInOnlineStore.QueryQcmAddAsk2" desc = "查询合同附加要求信息 (CRAFT_ORD_DESIGN_ADD_ASK)">
<![CDATA[
select t.DESGIN_KEY,
       T.ASK_ITME,
       T.ASK_ITME_DESC,
       T.ASK_SUB_ITME,
       T.ASK_SUB_ITME_DESC,
       T.ASK_SUB_ITME_VAL,
       T.ASK_SUB_ITME_VAL_DESC
  from CRAFT_ORD_DESIGN_ADD_ASK t
 WHERE T.DESGIN_KEY =
       (SELECT C.DESGIN_KEY
          FROM SLM_ORDER_HEAD A, SLM_ORDER_LINE B, CRAFT_ORD_DESIGN C
         WHERE A.ORD_PK = B.ORD_PK
           AND C.ORD_LN_PK = B.ORD_LN_PK
           AND C.VALIDFLAG = '1'
           AND A.ORDER_NO || '/' || B.ORDER_SEQ = ?)
  ]]>
</query>

<query id = "FrmInOnlineStore.insertQcmAddAsk" desc = "新增合同附加要求信息 （QCM_ADD_ASK）">
<![CDATA[
 INSERT INTO QCM_ADD_ASK(
        JUGDE_APPLY_CODE,
        JUDGE_STOVE_NO,
        DESGIN_KEY,
        ASK_ITME,
        ASK_ITME_DESC,
        ASK_SUB_ITME,
        ASK_SUB_ITME_DESC,
        ASK_SUB_ITME_VAL,
        ASK_SUB_ITME_VAL_DESC,
        ASK_IS_COMFRIM,
        ASK_VAL_DESC,
        COMFRIM_NAME,
        COMFRIM_TIME)
 VALUES( 
        '#JUGDE_APPLY_CODE#',
        '#JUDGE_STOVE_NO#',
        '#DESGIN_KEY#',
        '#ASK_ITME#',
        '#ASK_ITME_DESC#',
        '#ASK_SUB_ITME#',
        '#ASK_SUB_ITME_DESC#',
        '#ASK_SUB_ITME_VAL#',
        '#ASK_SUB_ITME_VAL_DESC#',
        '#ASK_IS_COMFRIM#',
        '#ASK_VAL_DESC#',
        '#COMFRIM_NAME#',
        SYSDATE)
  ]]>
</query>

<query id = "FrmInOnlineStore.QueryZgJugdeApply" desc = "查询送判数据">
<![CDATA[
select t.*
  from QCM_ZG_JUGDE_APPLY t
 WHERE 1=1
  ]]>
</query>

<query id = "FrmInOnlineStore.SelectAcount" desc = "查询送判支与进程表标记的支数差值">
<![CDATA[
SELECT NVL((select SUM(T.ACT_COUNT)
             from QCM_ZG_JUGDE_APPLY t
            WHERE T.JUGDE_APPLY_CODE = ?),
           0) - NVL((SELECT COUNT(1)
                      FROM PORT_MIL_BATCH_SAMPLE_RESULT P
                     WHERE P.JUGDE_APPLY_CODE = ?),
                    0) ACOUNT
  FROM DUAL
  ]]>
</query>
<query id = "FrmInOnlineStore.selectTmsDemandM" desc = "查询下线的支、吨">
<![CDATA[
SELECT NVL(SUM(ACT_COUNT), 0) ACT_COUNT, 
SUM(DECODE(ACT_WEIGHT,
                  NULL,
                  0,
                  '',
                  0,
                  0,
                  0,
                  TO_CHAR(ACT_WEIGHT, 'FM999990.0099'))) ACT_WEIGHT
  FROM (select NVL(SUM(T.ACT_COUNT), 0) ACT_COUNT,
               NVL(SUM(T.ACT_WEIGHT), 0) ACT_WEIGHT
          from MAT_BC_M t
         WHERE T.JUDGE_STOVE_NO = REGEXP_REPLACE(?, '-.*', '')
           AND T.HEAT_PLAN_NO = ?
           AND T.PROCESS_CDOE = 'D'
           AND T.QCM_STAUS = '00'
        
        UNION ALL
        
        select NVL(SUM(T.ACT_COUNT), 0) ACT_COUNT,
               NVL(SUM(T.ACT_WEIGHT), 0) ACT_WEIGHT
          from MAT_BC_BACKUP t
         WHERE T.JUDGE_STOVE_NO = REGEXP_REPLACE(?, '-.*', '')
           AND T.HEAT_PLAN_NO = ?
           AND T.PROCESS_CDOE = 'D'
           AND T.QCM_STAUS = '00')
       ]]>
</query>

<query id = "FrmInOnlineStore.UpdateTmsDemandM" desc = "更新运输需求">
<![CDATA[
DECLARE
  V_ACT_COUNT      TMS_DEMAND_M.OUTPUT_QTY_VAL%type := ?;
  V_ACT_WEIGHT     TMS_DEMAND_M.DEMAND_WT_VAL%type := ?;
  V_JUDGE_STOVE_NO TMS_DEMAND_M.HEAT_NO%type := REGEXP_REPLACE(?, '-.*', '');
  V_CURRENT_JOB_NO TMS_DEMAND_M.CURRENT_JOB_NO%type := ?;
  V_FLAG           TMS_DEMAND_M.CURRENT_JOB_NO%type := ?;
  V_SCRAP_QTY_VAL  TMS_DEMAND_M.SCRAP_QTY_VAL%type := ?;
  V_SCRAP_WT_VAL   TMS_DEMAND_M.SCRAP_WT_VAL%type := ?;
  V_WEIGHING_IF    TMS_DEMAND_M.WEIGHING_IF%type := ?;
BEGIN
  FOR MYROW IN (SELECT T.*
                  FROM TMS_DEMAND_M T
                 WHERE T.HEAT_NO = V_JUDGE_STOVE_NO
                   AND T.CURRENT_JOB_NO = V_CURRENT_JOB_NO
                   AND T.TRAN_CLASS_CODE = 'XX'
                 ORDER BY T.CREATE_TIME DESC) LOOP
    --恢复原始数据
    UPDATE TMS_DEMAND_M T
       SET T.SCRAP_QTY_VAL  = 0,
           T.SCRAP_WT_VAL   = 0,
           T.OUTPUT_QTY_VAL = 0,
           T.OUTPUT_WT_VAL  = 0
     WHERE T.DEMAND_NO = MYROW.DEMAND_NO;
    --写实际数量
    IF (V_ACT_COUNT > 0) THEN
      IF (MYROW.DEMAND_QTY_VAL >= V_ACT_COUNT) THEN
        UPDATE TMS_DEMAND_M T
           SET T.OUTPUT_QTY_VAL = V_ACT_COUNT,
               T.OUTPUT_WT_VAL  = V_ACT_WEIGHT,
               T.WEIGHING_IF    = V_WEIGHING_IF
         WHERE T.DEMAND_NO = MYROW.DEMAND_NO;
        V_ACT_COUNT  := 0;
        V_ACT_WEIGHT := 0;
      ELSE
        UPDATE TMS_DEMAND_M T
           SET T.OUTPUT_QTY_VAL = T.DEMAND_QTY_VAL,
               T.OUTPUT_WT_VAL  = T.DEMAND_WT_VAL,
               T.WEIGHING_IF    = V_WEIGHING_IF
         WHERE T.DEMAND_NO = MYROW.DEMAND_NO;
        V_ACT_COUNT  := V_ACT_COUNT - MYROW.DEMAND_QTY_VAL;
        V_ACT_WEIGHT := V_ACT_WEIGHT - MYROW.DEMAND_WT_VAL;
      END IF;
    END IF;
  END LOOP;

  --结炉的数据处理
  FOR MYROW1 IN (SELECT T.*
                   FROM TMS_DEMAND_M T
                  WHERE T.HEAT_NO = V_JUDGE_STOVE_NO
                    AND T.CURRENT_JOB_NO = V_CURRENT_JOB_NO
                    AND T.TRAN_CLASS_CODE = 'XX'
                  ORDER BY T.CREATE_TIME DESC) LOOP
  
    IF (V_FLAG = 'JL') THEN
      IF (V_SCRAP_QTY_VAL > 0) THEN
        IF (MYROW1.DEMAND_QTY_VAL - MYROW1.OUTPUT_QTY_VAL >=
           V_SCRAP_QTY_VAL) THEN
          UPDATE TMS_DEMAND_M T
             SET T.SCRAP_QTY_VAL = V_SCRAP_QTY_VAL,
                 T.SCRAP_WT_VAL  = V_SCRAP_WT_VAL
           WHERE T.DEMAND_NO = MYROW1.DEMAND_NO;
          V_SCRAP_QTY_VAL := 0;
          V_SCRAP_WT_VAL  := 0;
        ELSE
          UPDATE TMS_DEMAND_M T
             SET T.SCRAP_QTY_VAL = T.DEMAND_QTY_VAL - T.OUTPUT_QTY_VAL,
                 T.SCRAP_WT_VAL =
                 (T.DEMAND_QTY_VAL - T.OUTPUT_QTY_VAL) / V_SCRAP_QTY_VAL *
                 V_SCRAP_WT_VAL
           WHERE T.DEMAND_NO = MYROW1.DEMAND_NO;
        
          V_SCRAP_QTY_VAL := V_SCRAP_QTY_VAL - MYROW1.DEMAND_QTY_VAL +
                             MYROW1.OUTPUT_QTY_VAL;
          V_SCRAP_WT_VAL  := (V_SCRAP_QTY_VAL - MYROW1.DEMAND_QTY_VAL +
                             MYROW1.OUTPUT_QTY_VAL) / V_SCRAP_QTY_VAL *
                             V_SCRAP_WT_VAL;
        END IF;
      END IF;
    END IF;
  END LOOP;
END;
       ]]>
</query>

<query id = "FrmInOnlineStore.doQueryHeatPlanNo" desc= "查询炉计划ID">
<![CDATA[
	SELECT T.HEAT_PLAN_NO
  FROM MAT_BC_M T
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.BATCH_NO = ?
   AND T.BATCH_GROUD_NO = ?
   AND T.ZG_STOVE_SQE = ?
   AND ROWNUM = 1
   ]]>
	</query>
	
	<query id = "FrmInOnlineStore.selectTmsScrap" desc= "查询废品支、吨">
	<![CDATA[
	select NVL(SUM(T.ACT_COUNT), 0) actCountScrap,
       NVL(SUM(T.ACT_THEORY_WEIGHT), 0) actWeightScrap
  from PORT_MIL_BATCH_SAMPLE_RESULT t
 WHERE T.STATUS IN ('1', '2', '6')
   AND T.GROUP_FLAG = '0'
   AND T.PLAN_ID = ?
   ]]>
	</query>
	
	<query id = "FrmInOnlineStore.selectTmsPrtFlag" desc= "查询过磅标识">
	<![CDATA[
	select DECODE(T.TARGET, 'A', '1', T.PRT_FLAG) PRT_FLAG
  from MIL_PLAN t
 WHERE T.ID = ?
   AND REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = REGEXP_REPLACE(?, '-.*', '')
   ]]>
	</query>
	
	<query id = "FrmInOnlineStore.GetInspectionNO" desc = "报检编号">
SELECT ? || TO_CHAR(SYSDATE, 'yyyyMMDD') ||
       LPAD(NVL(MAX(TO_NUMBER(SUBSTR(T.INSPECTION_NO,
                                     LENGTH(T.INSPECTION_NO) - 5))),
                0) + 1,
            6,
            '0') INSPECTION_NO
  FROM MIL_INSPECTION T
 WHERE T.INSPECTION_NO LIKE ? || TO_CHAR(SYSDATE, 'yyyyMMDD') || '______'
</query>

<query id = "FrmInOnlineStore.inspection" desc= "报检">
	<![CDATA[
 DECLARE
  V_INSPECTION_NO MIL_INSPECTION.INSPECTION_NO%TYPE := ?;
  V_PROCESS_CODE  MIL_INSPECTION.PROCESS_CODE%TYPE := ?;
  V_FLAG          MIL_INSPECTION.PROCESS_CODE%TYPE := ?; --0正常报检  1必检
  V_CREATE_NAME   MIL_INSPECTION.CREATE_NAME%TYPE := ?; --报检员

  V_ACT_COUNT1      MIL_INSPECTION.ACT_COUNT%TYPE := NULL; --交库支
  V_ACT_WEIGHT1     MIL_INSPECTION.ACT_WEIGHT%TYPE := NULL; --交库吨
  V_ACT_COUNT2      MIL_INSPECTION.ACT_COUNT%TYPE := NULL; --已报检支
  V_ACT_WEIGHT2     MIL_INSPECTION.ACT_WEIGHT%TYPE := NULL; --已报检吨
  V_ORDER_NO        MIL_INSPECTION.ORDER_NO%TYPE := NULL; --合同号
  V_ORDER_SEQ       MIL_INSPECTION.ORDER_SEQ%TYPE := NULL; --合同行号
  V_CRAFT_FILE_NO   MIL_INSPECTION.CRAFT_FILE_NO%TYPE := NULL; --工艺文件号
  V_ZY_BATCH_ID     MIL_INSPECTION.ZY_BATCH_ID%TYPE := NULL; --生产批次
  V_CUSTOMER_NM     MIL_INSPECTION.CUSTOMER_NM%TYPE := NULL; --客户
  V_SYSDATE         MIL_INSPECTION.CREATE_TIME%TYPE := SYSDATE; --日期
  V_PROC_DATE       MIL_INSPECTION.PROC_DATE%TYPE := NULL; --报检年月日
  V_SEQ             MIL_INSPECTION.SEQ%TYPE := NULL; --序号
  V_TYPE            MIL_INSPECTION.SEQ%TYPE := NULL; --类型（0-普通品种，1-特殊品种）
  V_INSPECTION_FLAG MIL_INSPECTION.INSPECTION_FLAG%TYPE := NULL; --抽检状态

  V_GRADECODE MIL_INSPECTION.GRADECODE%TYPE := NULL; --钢种
  V_GRADENAME MIL_INSPECTION.GRADENAME%TYPE := NULL; --钢种
  V_INDEX_SEQ PLN_ZY_ZG_M.INDEX_SEQ%TYPE := NULL; --制程索引号

BEGIN
  --报检年月日
  SELECT CASE
           WHEN TO_CHAR(V_SYSDATE, 'HH24') < 7 THEN
            TO_CHAR(V_SYSDATE - 1, 'YYYYMMDD')
           ELSE
            TO_CHAR(V_SYSDATE, 'YYYYMMDD')
         END
    INTO V_PROC_DATE
    FROM DUAL;

  --序号
  SELECT NVL(MAX(T.SEQ), 0) + 1
    INTO V_SEQ
    FROM MIL_INSPECTION T
   WHERE T.PROC_DATE = V_PROC_DATE
     AND T.PROCESS_CODE = V_PROCESS_CODE
     AND T.PLINE_CODE = '#PLINE_CODE#'
        --AND (T.STD_NAME LIKE '%8162%' OR T.STD_NAME LIKE '%8163%')
        --AND (T.GRADENAME = '20' OR T.STEELNAME = '20')
     AND (INSTR(T.PRODUCNAME, '结构管') > 0 OR
         INSTR(T.PRODUCNAME, '低中压锅炉管') > 0 OR
         INSTR(T.PRODUCNAME, '流体输送管') > 0)
     AND T.VALIDFLAG = '1';

  --类型（0-普通品种，1-特殊品种）
  SELECT CASE
           WHEN V_PROCESS_CODE = 'D' AND
                ('#GRADENAME#' = 'GM' OR '#STEELNAME#' = 'GM') THEN
            '0'
           WHEN V_PROCESS_CODE = 'D' AND (INSTR('#STD_NAME#', 'JY') > 0) THEN
            '0'
           WHEN V_PROCESS_CODE = 'D' AND
                (INSTR('#PRODUCNAME#', '结构管') > 0 OR
                INSTR('#PRODUCNAME#', '低中压锅炉管') > 0 OR
                INSTR('#PRODUCNAME#', '流体输送管') > 0) THEN
            '0'
           WHEN V_PROCESS_CODE <> 'D' THEN --热处理，加工都是待抽，每炉10抽1
            '0'
           ELSE
            '1'
         END
    INTO V_TYPE
    FROM DUAL;

  --抽检状态(普通品种 10抽1，特殊品种必抽，其实免检)
  SELECT CASE
           WHEN V_TYPE = '0' THEN
            '0'
           WHEN V_TYPE = '1' THEN
            '1'
           ELSE
            '3'
         END
    INTO V_INSPECTION_FLAG
    FROM DUAL;

  --查钢种
  IF (V_PROCESS_CODE = 'D') THEN
    SELECT T.GRADECODE, T.GRADENAME, T.INDEX_SEQ
      INTO V_GRADECODE, V_GRADENAME, V_INDEX_SEQ
      FROM MIL_PLAN T
     WHERE T.ID = '#HEAT_PLAN_NO#'
       AND REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = '#JUDGE_STOVE_NO#'
       AND T.PLINE_CODE = '#PLINE_CODE#'
       AND ROWNUM = 1;
  ELSIF (V_PROCESS_CODE = 'E') THEN
    SELECT T.GRADECODE, T.GRADENAME, T.INDEX_SEQ
      INTO V_GRADECODE, V_GRADENAME, V_INDEX_SEQ
      FROM PLN_ZY_DBK_M T
     WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
       AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
       AND T.PLINE_CODE = '#PLINE_CODE#'
       AND ROWNUM = 1;
  ELSIF (V_PROCESS_CODE = 'F') THEN
    SELECT T.GRADECODE, T.GRADENAME, T.INDEX_SEQ
      INTO V_GRADECODE, V_GRADENAME, V_INDEX_SEQ
      FROM PLN_ZY_RCL_M T
     WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
       AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
       AND T.PLINE_CODE = '#PLINE_CODE#'
       AND ROWNUM = 1;
  ELSIF (V_PROCESS_CODE = 'G') THEN
    SELECT T.GRADECODE, T.GRADENAME, T.INDEX_SEQ
      INTO V_GRADECODE, V_GRADENAME, V_INDEX_SEQ
      FROM PLN_ZY_JGX_M T
     WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
       AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
       AND T.PLINE_CODE = '#PLINE_CODE#'
       AND ROWNUM = 1;
  END IF;

  --交库支吨
  SELECT SUM(ACT_COUNT), SUM(ACT_WEIGHT)
    INTO V_ACT_COUNT1, V_ACT_WEIGHT1
    FROM (SELECT SUM(T.ACT_COUNT) ACT_COUNT, SUM(T.ACT_WEIGHT) ACT_WEIGHT
            FROM MAT_BC_M T
           WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
             AND T.BATCH_NO = '#BATCH_NO#'
             AND T.PLINE_CODE = '#PLINE_CODE#'
             AND T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
             AND T.QCM_STAUS = '00'
             AND T.JUGDE_APPLY_CODE IS NULL
          
          UNION ALL
          
          SELECT SUM(T1.ACT_COUNT) ACT_COUNT, SUM(T1.ACT_WEIGHT) ACT_WEIGHT
            FROM QCM_ZG_JUGDE_APPLY T1
           WHERE T1.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
             AND T1.BATCH_NO = '#BATCH_NO#'
             AND T1.PLINE_CODE = '#PLINE_CODE#'
             AND T1.HEAT_PLAN_NO = '#HEAT_PLAN_NO#');

  --需要复检
  FOR MYROW IN (SELECT T.*
                  FROM MIL_INSPECTION T
                 WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
                   AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                   AND T.BATCH_NO = '#BATCH_NO#'
                   AND T.PLINE_CODE = '#PLINE_CODE#'
                   AND T.RECHECK = '1') LOOP
    INSERT INTO MIL_INSPECTION
      (INSPECTION_NO,
       INSPECTION_NUM,
       HEAT_PLAN_NO,
       ZY_BATCH_ID,
       JUDGE_STOVE_NO,
       BATCH_NO,
       INSPECTION_FLAG,
       INSPECTION_RESULT,
       PRODUCCODE,
       PRODUCNAME,
       STEELCODE,
       STEELNAME,
       GRADECODE,
       GRADENAME,
       SPEC_CODE,
       SPEC_NAME,
       MODEL_CODE,
       MODEL_DESC,
       STD_CODE,
       STD_NAME,
       STD_STYLE,
       STD_STYLE_DESC,
       CRAFT_FILE_NO,
       CUSTOMER_NM,
       ACT_COUNT,
       ACT_WEIGHT,
       CREATE_TIME,
       LOAD_TIME,
       INSPECTION_TIME,
       INSPECTION_NAME,
       APPLY_FLAG,
       PROCESS_CODE,
       UNQUALIFIED_REASONS,
       DISPOSAL_METHOD,
       DISPOSAL_FLAG,
       PLINE_CODE,
       PLINE_NAME,
       DISPOSAL_TIME,
       DISPOSAL_NAME,
       ORDER_NO,
       ORDER_SEQ,
       PROC_DATE,
       CREATE_NAME)
      SELECT INSPECTION_NO,
             INSPECTION_NUM + 1,
             HEAT_PLAN_NO,
             ZY_BATCH_ID,
             JUDGE_STOVE_NO,
             BATCH_NO,
             '1',
             '',
             PRODUCCODE,
             PRODUCNAME,
             STEELCODE,
             STEELNAME,
             GRADECODE,
             GRADENAME,
             SPEC_CODE,
             SPEC_NAME,
             MODEL_CODE,
             MODEL_DESC,
             STD_CODE,
             STD_NAME,
             STD_STYLE,
             STD_STYLE_DESC,
             CRAFT_FILE_NO,
             CUSTOMER_NM,
             CASE
               WHEN V_ACT_COUNT1 < ACT_COUNT THEN
                V_ACT_COUNT1
               ELSE
                ACT_COUNT
             END,
             CASE
               WHEN V_ACT_COUNT1 < ACT_COUNT THEN
                V_ACT_WEIGHT1
               ELSE
                ACT_WEIGHT
             END,
             -- ACT_COUNT - NVL(SCRAP_NUM, 0),
             -- ACT_WEIGHT - NVL(SCRAP_WT, 0),
             V_SYSDATE,
             LOAD_TIME,
             '',
             '',
             '0',
             PROCESS_CODE,
             '',
             '',
             '',
             PLINE_CODE,
             PLINE_NAME,
             '',
             '',
             ORDER_NO,
             ORDER_SEQ,
             CASE
               WHEN TO_CHAR(V_SYSDATE, 'HH24') < 7 THEN
                TO_CHAR(V_SYSDATE - 1, 'YYYYMMDD')
               ELSE
                TO_CHAR(V_SYSDATE, 'YYYYMMDD')
             END,
             V_CREATE_NAME
        FROM MIL_INSPECTION T1
       WHERE T1.INSPECTION_NO = MYROW.INSPECTION_NO
         AND T1.INSPECTION_NUM = MYROW.INSPECTION_NUM;
  
    FOR MYROW1 IN (SELECT T.*
                     FROM MIL_INSPECTION_DETAIL T
                    WHERE T.INSPECTION_NO = MYROW.INSPECTION_NO
                      AND T.INSPECTION_NUM = MYROW.INSPECTION_NUM) LOOP
      INSERT INTO MIL_INSPECTION_DETAIL
        (INSPECTION_NO, INSPECTION_NUM, PROJECT_CATEGORY, PROJECT_NAME)
        SELECT T1.INSPECTION_NO,
               T1.INSPECTION_NUM + 1,
               T1.PROJECT_CATEGORY,
               T1.PROJECT_NAME
          FROM MIL_INSPECTION_DETAIL T1
         WHERE T1.GUID = MYROW1.GUID;
    END LOOP;
  
    UPDATE MIL_INSPECTION T
       SET T.RECHECK = '2'
     WHERE T.INSPECTION_NO = MYROW.INSPECTION_NO
       AND T.INSPECTION_NUM = MYROW.INSPECTION_NUM;
  
  END LOOP;

  --找库存信息
  SELECT SUBSTR(MAX(T.CRAF_NO), 1, INSTR(MAX(T.CRAF_NO), '/') - 1),
         SUBSTR(MAX(T.CRAF_NO), INSTR(MAX(T.CRAF_NO), '/') + 1, 3),
         MAX(T.CRAF_NO),
         MAX(T.LOT_NO)
    INTO V_ORDER_NO, V_ORDER_SEQ, V_CRAFT_FILE_NO, V_ZY_BATCH_ID
    FROM MAT_BC_M T
   WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
     AND T.BATCH_NO = '#BATCH_NO#'
     AND T.PLINE_CODE = '#PLINE_CODE#'
     AND T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
     AND T.QCM_STAUS = '00'
     AND T.JUGDE_APPLY_CODE IS NULL;

  --找客户名称
  SELECT MAX(T.CUSTOMER_NM)
    INTO V_CUSTOMER_NM
    FROM SLM_ORDER_HEAD T
   WHERE T.ORDER_NO = V_ORDER_NO
     AND T.VALIDFLAG = '1';

  --报检支吨
  SELECT SUM(T.ACT_COUNT), SUM(T.ACT_WEIGHT)
    INTO V_ACT_COUNT2, V_ACT_WEIGHT2
    FROM MIL_INSPECTION T
   WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
     AND T.BATCH_NO = '#BATCH_NO#'
     AND T.PLINE_CODE = '#PLINE_CODE#'
     AND T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
     AND T.VALIDFLAG = '1'
     AND T.RECHECK = '0';

  --交库支数大于报检支数才会增加报检记录
  IF (NVL(V_ACT_COUNT1, 0) - NVL(V_ACT_COUNT2, 0) > 0) THEN
    --增加主表
    INSERT INTO MIL_INSPECTION
      (INSPECTION_NO,
       INSPECTION_NUM,
       HEAT_PLAN_NO,
       ZY_BATCH_ID,
       JUDGE_STOVE_NO,
       BATCH_NO,
       INSPECTION_FLAG,
       INSPECTION_RESULT,
       PRODUCCODE,
       PRODUCNAME,
       STEELCODE,
       STEELNAME,
       GRADECODE,
       GRADENAME,
       SPEC_CODE,
       SPEC_NAME,
       MODEL_CODE,
       MODEL_DESC,
       STD_CODE,
       STD_NAME,
       STD_STYLE,
       STD_STYLE_DESC,
       CRAFT_FILE_NO,
       CUSTOMER_NM,
       ACT_COUNT,
       ACT_WEIGHT,
       CREATE_TIME,
       LOAD_TIME,
       INSPECTION_TIME,
       INSPECTION_NAME,
       APPLY_FLAG,
       PROCESS_CODE,
       
       PLINE_CODE,
       PLINE_NAME,
       ORDER_NO,
       ORDER_SEQ,
       PROC_DATE,
       SEQ,
       CREATE_NAME)
    VALUES
      (V_INSPECTION_NO,
       '1',
       '#HEAT_PLAN_NO#',
       V_ZY_BATCH_ID,
       '#JUDGE_STOVE_NO#',
       '#BATCH_NO#',
       DECODE(V_FLAG, '1', '1', '0', V_TYPE, '3', '3'),
       '',
       '#PRODUCCODE#',
       '#PRODUCNAME#',
       '#STEELCODE#',
       '#STEELNAME#',
       V_GRADECODE,
       V_GRADENAME,
       '#SPEC_CODE#',
       '#SPEC_NAME#',
       '#MODEL_CODE#',
       '#MODEL_DESC#',
       '#STD_CODE#',
       '#STD_NAME#',
       '#STD_STYLE#',
       '#STD_STYLE_DESC#',
       V_CRAFT_FILE_NO,
       V_CUSTOMER_NM,
       NVL(V_ACT_COUNT1, 0) - NVL(V_ACT_COUNT2, 0),
       NVL(V_ACT_WEIGHT1, 0) - NVL(V_ACT_WEIGHT2, 0),
       SYSDATE,
       SYSDATE,
       '',
       '',
       '0',
       V_PROCESS_CODE,
       '#PLINE_CODE#',
       (SELECT P.PLINE_NAME
          FROM COM_BASE_PLINE P
         WHERE P.PLINE_CODE = '#PLINE_CODE#'),
       V_ORDER_NO,
       V_ORDER_SEQ,
       V_PROC_DATE,
       V_SEQ,
       V_CREATE_NAME);
  
    --增加子表
    FOR MYROW2 IN (SELECT '几何尺寸' XM, NVL(S.BIAS_NAME, '-') GC
                     FROM CRAFT_ORD_DESIGN_MSC_PL_PRC T,
                          CRAFT_ORD_DESIGN_STD_SIC    S
                    WHERE T.DESGIN_KEY = S.DESGIN_KEY(+)
                      AND T.MSC_PLINE = S.MSC_PLINE(+)
                      and t.PROCESS_CODE = S.PROCESS_CODE(+)
                      AND S.SPECL_FL(+) = '2'
                      AND T.PROCESS_CODE = V_PROCESS_CODE
                      AND T.MSC_PLINE = V_INDEX_SEQ
                      AND T.DESGIN_KEY IN
                          (SELECT C.DESGIN_KEY
                             FROM SLM_ORDER_HEAD   A,
                                  SLM_ORDER_LINE   B,
                                  CRAFT_ORD_DESIGN C
                            WHERE A.ORD_PK = B.ORD_PK
                              AND C.ORD_LN_PK = B.ORD_LN_PK
                              AND C.VALIDFLAG = '1'
                              AND A.ORDER_NO = V_ORDER_NO
                              AND B.ORDER_SEQ = V_ORDER_SEQ)) LOOP
      INSERT INTO MIL_INSPECTION_DETAIL
        (INSPECTION_NO, INSPECTION_NUM, PROJECT_CATEGORY, PROJECT_NAME)
      values
        (V_INSPECTION_NO, 1, MYROW2.XM, MYROW2.GC);
    END LOOP;
  
    INSERT INTO MIL_INSPECTION_DETAIL
      (INSPECTION_NO, INSPECTION_NUM, PROJECT_CATEGORY, PROJECT_NAME)
    values
      (V_INSPECTION_NO, 1, '表面质量', '表面质量');
  
    INSERT INTO MIL_INSPECTION_DETAIL
      (INSPECTION_NO, INSPECTION_NUM, PROJECT_CATEGORY, PROJECT_NAME)
    values
      (V_INSPECTION_NO, 1, '外包装质量', '外包装质量');
  END IF;
END;
   ]]>
	</query>
	
	<query id = "FrmInOnlineStore.doQueryBjCount" desc = "查询成品可送判支">
	SELECT NVL((select SUM(T.ACT_COUNT)
             from MIL_INSPECTION t
            WHERE T.JUDGE_STOVE_NO = ?
              AND T.PLINE_CODE = ?
              AND T.INSPECTION_FLAG > 1
              AND T.INSPECTION_RESULT = '合格'),
           0) - NVL((SELECT SUM(T1.ACT_COUNT)
                      FROM QCM_ZG_JUGDE_APPLY T1
                     WHERE T1.JUDGE_STOVE_NO = ?
                       AND T1.PLINE_CODE = ?
                       AND T1.TARGET = 'A'),
                    0) ACT_COUNT
  FROM DUAL
	</query>

   <query id = "FrmInOnlineStore.getThJudgeNo" desc = "查询天淮炉号">
    SELECT
     JUDGE_STOVE_NO
    FROM
     YDM_ZC_BILL_C
    WHERE
    (BILL_NO,RECEIVE_FLAG) =
    (SELECT BILL_NO,INSTOCK_DOC FROM YDM_BC_INLIST WHERE JUDGE_STOVE_NO = ?
        AND BILL_NO IS NOT NULL  AND ROWNUM = 1)
   </query>
   
   <query id = "FrmInOnlineStore.QueryOfflineProcess" desc = "离线管理查询">
   <![CDATA[
     SELECT T.RESULT_NO,
       T.PLINE_CODE,
       T.PLINE_NAME,
       T.STATION_CODE,
       T.STATION_DESC,
       T.HEAT_PLAN_NO,
       T.PRO_PLAN_ID,
       T.GX_PLAN_NO,
       T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       T.BATCH_GROUD_NO,
       T.STOVE_NO,
       T.FLAG_STOVE_NO,
       T.TARGET,
       T.PROCESS_CDOE,
       T.PROCESS_DESC,
       TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
       T.PRODUCCODE,
       T.PRODUCNAME,
       T.STEELCODE,
       T.STEELNAME,
       T.GRADECODE,
       T.GRADENAME,
       T.SPEC_CODE,
       T.SPEC_NAME,
       T.MODEL_CODE,
       T.MODEL_DESC,
       T.STD_CODE,
       T.STD_NAME,
       T.STD_STYLE,
       T.STD_STYLE_DESC,
       T.ORDER_NO,
       T.ORDER_SEQ,
       T.CRAFT_FILE_NO,
       T.CUSTOMER_NO,
       T.CUSTOMER_NM,
       T.OFFLINE_NUM,
       T.OFFLINE_WT,
       T.RE_NUM,
       T.RE_WT,
       T.GROUP_NUM,
       T.GROUP_WT,
       T.SUBCONTRACT_NO,
       T.SUBCONTRACT_NO_SEQ,
       T.SUBCONTRACT_NUM,
       T.SUBCONTRACT_WT,
       TO_CHAR(T.SUBCONTRACT_TIME, 'YYYY-MM-DD HH24:MI:SS') SUBCONTRACT_TIME,
       T.SUBCONTRACT_NAME,
       T.SUBCONTRACTCOMPLETE_NUM,
       T.SUBCONTRACTCOMPLETE_WT,
       T.HB_FP_NUM,
       T.HB_FP_WT,
       TO_CHAR(T.SUBCONTRACTCOMPLETE_TIME, 'YYYY-MM-DD HH24:MI:SS') SUBCONTRACTCOMPLETE_TIME,
       T.SUBCONTRACTCOMPLETE_NAME,
       TO_CHAR(T.OFFLINE_TIME, 'YYYY-MM-DD HH24:MI:SS') OFFLINE_TIME,
       ROUND(SYSDATE - T.OFFLINE_TIME, 2) LXTS,
       TO_CHAR(T.RE_TIME, 'YYYY-MM-DD HH24:MI:SS') RE_TIME,
       T.MEMO,
       T.REASON1,
       T.REASON2,
       T.REASON3,
       T.ANALYSIS_RESULTS,
       T.PLINE_CODE_RESPONSE,
       T.PLINE_NAME_RESPONSE,
       T.PLINE_CODE_A,
       T.PLINE_NAME_A,
       T.PLINE_CODE_D,
       T.PLINE_NAME_D,
       T.PLINE_CODE_E,
       T.PLINE_NAME_E,
       T.PLINE_CODE_F,
       T.PLINE_NAME_F,
       T.DISPOSAL_OPINION,
       T.IS_AUDIT,
       T.DISPOSAL_OPINION_SCHEDULE,
       TO_CHAR(T.DELVRY_EDATE, 'YYYY-MM-DD HH24:MI:SS') DELVRY_EDATE,
       CASE
         WHEN SYSDATE - DELVRY_EDATE > 0 THEN
          ROUND(SYSDATE - DELVRY_EDATE, 2)
       END HTCQ
  FROM OFFLINE_PROCESS T
 WHERE 1 = 1
 ]]>
   </query>
	<query id = "FrmInOnlineStore.updateProssWt" desc = "获取测量点重量">
   <![CDATA[
     DECLARE
  V_JUDGE_STOVE_NO MAT_BC_M.JUDGE_STOVE_NO%TYPE := ?;
  V_PLINE_CODE     MAT_BC_M.PLINE_CODE%TYPE := ?;
  V_PRO_ORDER_ID   MAT_BC_M.PRO_ORDER_ID%TYPE := ?;
  V_GX_PLAN_NO     MAT_BC_M.GX_PLAN_NO%TYPE := ?;
  V_PONDER_NAME    MAT_BC_M.PONDER_NAME%TYPE := ?;

BEGIN
  FOR MYROW IN (SELECT T.*, T1.MEASURE_LEN, T1.MEASURE_WEIGHT
                  FROM MAT_BC_M T, PORT_MIL_BATCH_SAMPLE_RESULT T1
                 WHERE T.PROCESS_CDOE = 'D'
                   AND T.JUDGE_STOVE_NO =
                       REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')
                   AND T.ZG_MAT_NO = T1.MAT_NO
                   AND T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
                   AND T.PLINE_CODE = V_PLINE_CODE
                   AND NVL(T.PRO_ORDER_ID, '/') = NVL(V_PRO_ORDER_ID, '/')
                   AND NVL(T.GX_PLAN_NO, '/') = NVL(V_GX_PLAN_NO, '/')
                   AND T.JUGDE_APPLY_CODE IS NULL
                   AND T.QCM_STAUS = '00'
                   AND T1.MEASURING_SEQ IS NOT NULL) LOOP
  
    UPDATE MAT_BC_M T
       SET T.ACT_LEN         = MYROW.MEASURE_LEN,
           T.ACT_WEIGHT      = MYROW.MEASURE_WEIGHT,
           T.PONDER_GROSS_WT = MYROW.MEASURE_WEIGHT,
           T.MEASURING_SEQ   = MYROW.MEASURING_SEQ,
           T.PONDER_NAME     = V_PONDER_NAME,
           T.PONDER_TIME     = SYSDATE
     WHERE T.JUDGE_STOVE_NO = MYROW.JUDGE_STOVE_NO
       AND T.MAT_NO = MYROW.MAT_NO;
  END LOOP;
END;
 ]]>
   </query>
   <query id = "FrmInOnlineStore.selectOutlist" desc = "查询是否有在倒运的记录">
   <![CDATA[
     SELECT COUNT(1) ACOUNT
  FROM MAT_BC_M T, YDM_BC_BUTTRESS T1
 WHERE T.PROCESS_CDOE = 'D'
   AND T.JUDGE_STOVE_NO = T1.JUDGE_STOVE_NO
   AND T.MAT_NO = T1.MAT_NO
   AND T.JUDGE_STOVE_NO = ?
   AND T.PLINE_CODE = ?
   AND NVL(T.PRO_ORDER_ID, '/') = NVL(?, '/')
   AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
   AND T.JUGDE_APPLY_CODE IS NULL
   AND T.QCM_STAUS = '00'
   AND T1.STORAGE_NO IS NULL
 ]]>
   </query>
 <query id = "FrmInOnlineStore.insertJugdeApplyLog" desc = "添加记录">
  <![CDATA[
 INSERT INTO QCM_JUGDE_APPLY_LOG(
        JUGDE_APPLY_CODE,
        JUDGE_STOVE_NO,
        BATCH_NO,
        BATCH_GROUD_NO,
        PROCESS_CODE,
        PLINE_CODE,
        ACT_COUNT,
        ACT_WEIGHT,
        CREATE_NAME,
        CREATE_TIME,
        LOG_TYPE)
 VALUES(
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        SYSDATE,
        ?)
  ]]>
 </query>
</queryMap>