<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc = "半成品管转成品管">
<query id = "FrmBcPipeApplPro.doQueryMat" desc = "查询炉信息">
<![CDATA[
SELECT T.JUDGE_STOVE_NO,
       T.LOT_NO,
       T.STOVE_NO,
       T.BATCH_NO,
       T.BATCH_GROUD_NO,
       T.ORDER_NO,
       T.ORDER_SEQ,
       T.ORDER_SEQ_NO,
       T.ORD_PK,
       T.ORD_LN_PK,
       T.ORD_LN_DLY_PK,
       T.CRAF_NO,
       T.CRAFT_SEQ,
       T.JUDGE_RESULT,
       T.JUDGE_MAKER,
       T.JUGDE_APPLY_CODE,
       T.JUGDE_APPLY_SEQUENO,
       T.PROCESS_CDOE,
       T.PROCESS_DESC,
       T.PRODUCCODE,
       T.PRODUCNAME,
       T.STEELCODE,
       T.STEELNAME,
       T.SPEC_CODE,
       T.SPEC_NAME,
       T.MODEL_CODE,
       T.MODEL_DESC,
       T.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 = T.ORD_LN_PK
           AND L.VALIDFLAG = '1') STD_NAME,
       T.ACT_DIMATER,
       T.ACT_HEIGHT,
       T.BELONG_CODE,
       T.BELONG_NAME,
       T.STD_STYLE,
       T.STD_STYLE_DESC,
       T.GRADECODE,
       T.GRADENAME,
       sum(T.ACT_COUNT) ACT_COUNT,
       to_char(sum(T.Act_Weight), 'FM999999990.000') Act_Weight,
       to_char(sum(T.ACT_THEORY_WEIGHT), 'FM999999990.000') ACT_THEORY_WEIGHT,
       sum(nvl(T.ACT_LEN, 0)) as ACT_LEN,
       sum(NVL(T.PONDER_GROSS_WT, 0)) PONDER_GROSS_WT,
       
       to_char(T.ACT_LEN_MIN, 'FM999990.00') AS ACT_LEN_MIN,
       to_char(T.ACT_LEN_MAX, 'FM999990.00') AS ACT_LEN_MAX,
       to_char(T.ACT_LEN_MIN, 'FM999990.00') || '-' ||
       to_char(T.ACT_LEN_MAX, 'FM999990.00') as LEN,
       T.MATERIAL_NO,
       T.MATERIAL_NAME,
       T.INPUT_MATERIAL_NO,
       T.INPUT_MATERIAL_NAME,
       T.MEMO,
       T.PIPMEMO,
       T.JUDGE_STD_NAME,
       T.PLINE_CODE,
       T.PLINE_NAME,
       T.MAT_STATUS,
       T.PRODUCT_FLAG,
       T.TARGET,
       DECODE(T.PACK_FLAG, '0', '否', '1', '是') PACK_FLAG,
       T.PRO_ORDER_ID,
       T.GX_PLAN_NO
  FROM MAT_BC_M T
 where T.QCM_STAUS = '00'
   AND T.PRODUCT_FLAG = '801401'
   AND T.PRO_PLAN_ID_NEXT IS NULL
   AND T.JUDGE_RESULT_CODE IN ('40740701', '40740709')
    #someThing#
 GROUP BY T.JUDGE_STOVE_NO,
 T.STOVE_NO,
          T.BATCH_NO,
          T.BATCH_GROUD_NO,
          T.INPUT_MATERIAL_NO,
          T.INPUT_MATERIAL_NAME,
          T.ORDER_NO,
          T.ORDER_SEQ,
          T.ORDER_SEQ_NO,
          T.ORD_PK,
          T.ORD_LN_PK,
          T.ORD_LN_DLY_PK,
          T.CRAF_NO,
          T.CRAFT_SEQ,
          T.JUDGE_RESULT,
          T.JUDGE_MAKER,
          T.JUGDE_APPLY_CODE,
       T.JUGDE_APPLY_SEQUENO,
          T.PROCESS_CDOE,
          T.PROCESS_DESC,
          T.PRODUCCODE,
          T.PRODUCNAME,
          T.STEELCODE,
          T.STEELNAME,
          T.SPEC_CODE,
          T.SPEC_NAME,
          T.MODEL_CODE,
          T.GRADECODE,
          T.GRADENAME,
          T.STD_STYLE,
          T.STD_STYLE_DESC,
          T.PIPMEMO,
          T.MAT_STATUS,
          T.MODEL_DESC,
          T.STD_CODE,
          T.STD_NAME,
          T.ACT_DIMATER,
          T.ACT_HEIGHT,
          T.BELONG_CODE,
          T.BELONG_NAME,
          T.PLINE_CODE,
          T.PLINE_NAME,
          T.MATERIAL_NO,
          T.MATERIAL_NAME,
          T.ACT_LEN_MIN,
          T.ACT_LEN_MAX,
          T.MEMO,
          T.PRODUCT_FLAG,
          T.JUDGE_STD_NAME,
          T.TARGET,
          T.PACK_FLAG,
          T.LOT_NO,
          T.ORD_LN_PK,
          T.PRO_ORDER_ID,
          T.GX_PLAN_NO
 ]]>
</query>

<query id = "FrmBcPipeApplPro.doQueryplnSaleorder" desc = "查询合同信息">
<![CDATA[
SELECT T.*, T1.PROCESS_SEQ,SUBSTR(T1.PROCESS_SEQ, -1) PROCESS_SEQ_END
  FROM pln_saleord T, PLN_SALEORD_PROC T1
 WHERE t.PRODUCNAME NOT in (SELECT T.PRODUCNAME
                              FROM COM_BASE_PRODUCT T
                             WHERE T.PRODUC_STYLE = '405004'
                               AND T.PRODUC_TYPE = 'D')
   and t.PORDERSTATUS in ('1', '2', '3', '4')
   AND T.ORD_LN_DLY_PK = T1.ORD_LN_DLY_PK
   AND T.SPEC_NAME = ?
   AND SUBSTR(T1.PROCESS_SEQ, -1) <= ?
   AND T.ORDER_TYPE = '1'
 ]]>
</query>

<query id = "FrmBcPipeApplPro.doQueryplnSaleorder2" desc = "查询合同信息">
<![CDATA[
SELECT T.*, T1.PROCESS_SEQ, SUBSTR(T1.PROCESS_SEQ, -1) PROCESS_SEQ_END
  FROM pln_saleord T, PLN_SALEORD_PROC T1
 WHERE t.PRODUCNAME NOT in
       (SELECT T2.PRODUCNAME
          FROM COM_BASE_PRODUCT T2
         WHERE T2.PRODUC_STYLE = '405004'
           AND T2.PRODUC_TYPE = 'D')
   and t.PORDERSTATUS in ('1', '2', '3', '4')
   AND T.ORD_LN_DLY_PK = T1.ORD_LN_DLY_PK
   AND T.MATERIAL_DESC = ?
   AND SUBSTR(T1.PROCESS_SEQ, -1) <= ?
   AND T.ORDER_TYPE = '1'
 ]]>
</query>

<query id = "FrmBcPipeApplPro.QueryZgJugdeApply" desc = "查询送判数据">
<![CDATA[
select t.*
  from QCM_ZG_JUGDE_APPLY t
 WHERE 1=1
 AND T.PROCESS_CODE <> 'H' 
 AND T.VALIDFLAG = '20' 
 and t.IS_ALL_SCRAP = '6'
  ]]>
</query>

<query id = "FrmBcPipeApplPro.doQueryCic" desc = "查询是否有CIC">
<![CDATA[
SELECT COUNT(*) ACOUNT
  FROM CRAFT_ORD_DESIGN T, CRAFT_ORD_DESIGN_STD_CIC A, COM_MSC_STD_CIC B
 WHERE T.ORD_LN_PK = ?
   AND T.VALIDFLAG = '1'
   AND A.DESGIN_KEY = T.DESGIN_KEY
   AND A.SPECL_FL = '2'
   AND A.MSC_PLINE IN
       (SELECT S.INDEX_SEQ FROM PLN_SALEORD_PROC S WHERE S.ORD_LN_DLY_PK = ?)
   AND B.CIC = A.CIC
   --AND NVL(B.GRADECODE,'/') = NVL(?,'/')
 ]]>
</query>

<query id = "FrmBcPipeApplPro.doQueryPic" desc = "查询是否有PIC">
<![CDATA[
SELECT COUNT(*) ACOUNT
  FROM CRAFT_ORD_DESIGN T, CRAFT_ORD_DESIGN_STD_PIC A
 WHERE T.ORD_LN_PK = ?
   AND T.VALIDFLAG = '1'
   AND A.DESGIN_KEY = T.DESGIN_KEY
   AND A.SPECL_FL = '2'
   AND A.PROCESS_CODE = ?
   AND A.MSC_PLINE IN
       (SELECT S.INDEX_SEQ FROM PLN_SALEORD_PROC S WHERE S.ORD_LN_DLY_PK = ?)
 ]]>
</query>

<query id = "FrmBcPipeApplPro.jugdeApplyNo" desc = "生成判定单号">
<![CDATA[
 SELECT ? || '801402' || TO_CHAR(SYSDATE, 'YYYYMMDD') || '6' ||
         LPAD(NVL(MAX(SUBSTR(T.JUGDE_APPLY_CODE, 20,4)), 0) + 1, 4, 0) JUGDE_APPLY_CODE
    FROM QCM_ZG_JUGDE_APPLY T
   WHERE TRUNC(T.APPLY_TIME) = TRUNC(SYSDATE)
   AND T.IS_ALL_SCRAP = '6'
   AND T.PROCESS_CODE = ?
 ]]>
</query>

<query id = "FrmBcPipeApplPro.insertJugeApply" desc = "半成品转成品">
<![CDATA[
DECLARE
  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_JUGDE_APPLY_CODE     MAT_BC_M.JUGDE_APPLY_CODE%TYPE := ?;
  V_JUGDE_APPLY_CODE_OLD MAT_BC_M.JUGDE_APPLY_CODE%TYPE := ?;
  V_PROCESS_CODEO        QCM_ZG_JUGDE_APPLY.PROCESS_CODE%TYPE := ?;
  V_ACT_COUNT            QCM_ZG_JUGDE_APPLY.ACT_COUNT%TYPE := ?;
  V_ORD_PK               MAT_BC_M.ORD_PK%TYPE := ?; --新合同
  V_ORD_LN_PK            MAT_BC_M.ORD_LN_PK%TYPE := ?;
  V_ORD_LN_DLY_PK        MAT_BC_M.ORD_LN_DLY_PK%TYPE := ?;
  V_APPLY_NAME           QCM_ZG_JUGDE_APPLY.APPLY_NAME%TYPE := ?;
  V_GRADECODE            MAT_BC_M.GRADECODE%TYPE := ?;
  V_PROCESS_CODEO_END    QCM_ZG_JUGDE_APPLY.PROCESS_CODE%TYPE := ?; --新合同末工序
  V_BELONG_CODE_JUGDE    QCM_ZG_JUGDE_APPLY.BELONG_CODE_JUGDE%TYPE := ?; --判定后所属权
  V_BELONG_NAME_JUGDE    QCM_ZG_JUGDE_APPLY.BELONG_NAME_JUGDE%TYPE := ?;
  V_DELIVERY_STATE_CODE  QCM_ZG_JUGDE_APPLY.DELIVERY_STATE_CODE%TYPE := ?; --交货状态
  V_DELIVERY_STATE_NAME  QCM_ZG_JUGDE_APPLY.DELIVERY_STATE_NAME%TYPE := ?;
  V_BAL_YEAR_MONTH       QCM_ZG_JUGDE_APPLY.BAL_YEAR_MONTH%TYPE := ?; --结转年月
  V_MEMO                 MAT_BC_M.MEMO%TYPE := ?;
  V_JUGDE_APPLY_SEQUENO  QCM_ZG_JUGDE_APPLY.JUGDE_APPLY_SEQUENO%TYPE := NULL;
  V_PIC                  QCM_ZG_JUGDE_APPLY.PIC%TYPE := NULL;
  V_CIC                  QCM_ZG_JUGDE_APPLY.CIC%TYPE := NULL;
  V_INDEX_SEQ            PLN_SALEORD_PROC.INDEX_SEQ%TYPE := NULL;
  V_OUTSTOCK_DOC         YDM_BC_OUTLIST.OUTSTOCK_DOC%TYPE := NULL;
  V_OUTSTOCK_DOC2        YDM_BC_OUTLIST.OUTSTOCK_DOC%TYPE := NULL;
  V_INSTOCK_DOC          YDM_BC_INLIST.INSTOCK_DOC%TYPE := NULL;
  V_SUPPLY_UNIT          QCM_ZG_JUGDE_APPLY.SUPPLY_UNIT%TYPE := '120504';
  V_SUPPLY_UNIT_DESC     QCM_ZG_JUGDE_APPLY.SUPPLY_UNIT_DESC%TYPE := '江苏天淮钢管有限公司';
  v_ACT_COUNT2           MAT_BC_M.ACT_COUNT%TYPE := NULL;
  V_ICOUNT               NUMBER := 1;
  V_COUNT                NUMBER := 0;
BEGIN

  --生成申请判定顺序号
  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');

  SELECT COUNT(1)
    INTO V_COUNT
    from qcm_zg_jugde_apply
   WHERE JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
     AND BATCH_NO = V_BATCH_NO
     AND BATCH_GROUD_NO = V_BATCH_GROUD_NO
     AND PLINE_CODE = V_PLINE_CODE
     AND JUGDE_APPLY_CODE = V_JUGDE_APPLY_CODE_OLD;

  --找制程索引号
  SELECT S.INDEX_SEQ
    INTO V_INDEX_SEQ
    FROM PLN_SALEORD_PROC S
   WHERE S.ORD_LN_DLY_PK = V_ORD_LN_DLY_PK
     AND ROWNUM <= 1;
  --找CIC
  SELECT CIC
    INTO V_CIC
    FROM (SELECT A.CIC
            FROM CRAFT_ORD_DESIGN         T,
                 CRAFT_ORD_DESIGN_STD_CIC A,
                 COM_MSC_STD_CIC          B
           WHERE T.ORD_LN_PK = V_ORD_LN_PK
             AND T.VALIDFLAG = '1'
             AND A.DESGIN_KEY = T.DESGIN_KEY
             AND A.SPECL_FL = '2'
             AND A.MSC_PLINE = V_INDEX_SEQ
             AND B.CIC = A.CIC
          --AND B.GRADECODE = V_GRADECODE
           ORDER BY A.PROCESS_CODE DESC)
   WHERE ROWNUM <= 1;
  --找PIC
  SELECT A.PIC
    INTO V_PIC
    FROM CRAFT_ORD_DESIGN T, CRAFT_ORD_DESIGN_STD_PIC A
   WHERE T.ORD_LN_PK = V_ORD_LN_PK
     AND T.VALIDFLAG = '1'
     AND A.DESGIN_KEY = T.DESGIN_KEY
     AND A.SPECL_FL = '2'
     AND A.PROCESS_CODE = V_PROCESS_CODEO_END
     AND A.MSC_PLINE = V_INDEX_SEQ
     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
     AND T.BATCH_GROUD_NO = V_BATCH_GROUD_NO
     AND T.PLINE_CODE = V_PLINE_CODE
     AND T.QCM_STAUS = '00'
     AND T.PRODUCT_FLAG = '801401'
     AND T.PRO_PLAN_ID_NEXT IS NULL
     AND T.JUDGE_RESULT_CODE IN ('40740701', '40740709')
     AND T.BELONG_CODE = '002023005';

  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 T.BATCH_GROUD_NO = V_BATCH_GROUD_NO
       AND T.PLINE_CODE = V_PLINE_CODE
       AND T.QCM_STAUS = '00'
       AND T.PRODUCT_FLAG = '801401'
       AND T.PRO_PLAN_ID_NEXT IS NULL
       AND T.JUDGE_RESULT_CODE IN ('40740701', '40740709')
       AND T.BELONG_CODE = '002023005'
       AND ROWNUM = 1;
  END IF;

  --生成改判出库单号
  SELECT (SELECT S.MEMO FROM COM_BASE_INFO S WHERE S.BASECODE = '800808') ||
         OUTSTOCK_DOC
    INTO V_OUTSTOCK_DOC
    FROM (SELECT TO_CHAR(SYSDATE, 'YYMMDD') ||
                 LPAD(NVL(MAX(SUBSTR(T.OUTSTOCK_DOC, 9)), 0) + 1, 5, 0) OUTSTOCK_DOC
            FROM YDM_BC_OUTLIST T
           WHERE OUTSTOCK_SQE LIKE (SELECT S.MEMO
                                      FROM COM_BASE_INFO S
                                     WHERE S.BASECODE = '800808') ||
                 TO_CHAR(SYSDATE, 'YYMMDD') || '%');

  --生成产权出库单号
  SELECT (SELECT S.MEMO FROM COM_BASE_INFO S WHERE S.BASECODE = '800809') ||
         OUTSTOCK_DOC
    INTO V_OUTSTOCK_DOC2
    FROM (SELECT TO_CHAR(SYSDATE, 'YYMMDD') ||
                 LPAD(NVL(MAX(SUBSTR(T.OUTSTOCK_DOC, 9)), 0) + 1, 5, 0) OUTSTOCK_DOC
            FROM YDM_BC_OUTLIST T
           WHERE OUTSTOCK_SQE LIKE (SELECT S.MEMO
                                      FROM COM_BASE_INFO S
                                     WHERE S.BASECODE = '800809') ||
                 TO_CHAR(SYSDATE, 'YYMMDD') || '%');

  --生成改判入库单号
  SELECT (SELECT S.MEMO FROM COM_BASE_INFO S WHERE S.BASECODE = '800706') ||
         INSTOCK_DOC
    INTO V_INSTOCK_DOC
    FROM (SELECT TO_CHAR(SYSDATE, 'YYMMDD') ||
                 LPAD(NVL(MAX(SUBSTR(T.INSTOCK_DOC, 9)), 0) + 1, 5, 0) INSTOCK_DOC
            FROM YDM_BC_INLIST T
           WHERE T.INSTOCK_SQE LIKE (SELECT S.MEMO
                                       FROM COM_BASE_INFO S
                                      WHERE S.BASECODE = '800706') ||
                 TO_CHAR(SYSDATE, 'YYMMDD') || '%');

  FOR MYROW IN (SELECT T.ord_pk,
                       T.ord_ln_pk,
                       T.ord_ln_dly_pk,
                       T.order_no,
                       T.order_seq,
                       T.delivery_no,
                       V_BAL_YEAR_MONTH BAL_YEAR_MONTH2,
                       T.ENDGXNAME,
                       T.PRODUCCODE,
                       T.PRODUCNAME,
                       T.STEELCODE,
                       T.STEELNAME,
                       T.MATERIAL_NO,
                       T.MATERIAL_DESC,
                       T.STD_CODE,
                       T.STD_NAME,
                       T.STD_STYLE_DESC,
                       T.SPEC_CODE,
                       T.SPEC_NAME,
                       T.MODEL_CODE,
                       T.MODEL_DESC,
                       S.SALE_ORG,
                       S.SALE_ORG_DESC,
                       S1.CRAFT_NO      CRAF_NO,
                       S1.CRAFT_SEQ
                  FROM PLN_SALEORD T, SLM_ORDER_HEAD S, CRAFT_ORD_DESIGN S1
                 WHERE T.ORD_PK = V_ORD_PK
                   AND T.ORD_LN_PK = V_ORD_LN_PK
                   AND T.ORD_LN_DLY_PK = V_ORD_LN_DLY_PK
                   AND T.ORD_PK = S.ORD_PK(+)
                   AND T.ORD_LN_PK = S1.ORD_LN_PK(+)
                   AND S1.VALIDFLAG(+) = '1') LOOP
  
    FOR MYROW1 IN (SELECT *
                     FROM (SELECT T.*
                             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 NVL(T.MEMO, '/') = NVL(V_MEMO, '/')
                              AND T.QCM_STAUS = '00'
                              AND T.PRODUCT_FLAG = '801401'
                              AND T.PRO_PLAN_ID_NEXT IS NULL
                              AND T.JUDGE_RESULT_CODE IN
                                  ('40740701', '40740709')
                              AND T.BELONG_CODE = '002023005'
                            ORDER BY T.MAT_NO ASC)
                    WHERE ROWNUM <= V_ACT_COUNT) LOOP
    
      insert into ydm_bc_outlist
        (outstock_sqe,
         outstock_doc,
         outstock_type_code,
         outstock_type_name,
         mat_no,
         lot_no,
         stove_no,
         judge_stove_no,
         batch_no,
         batch_groud_no,
         material_no,
         material_name,
         produccode,
         producname,
         std_code,
         std_name,
         gradecode,
         gradename,
         steelcode,
         steelname,
         std_style,
         std_style_desc,
         spec_code,
         spec_name,
         model_code,
         model_desc,
         pro_order_no,
         pline_code,
         pline_name,
         act_dimater,
         act_height,
         act_len,
         act_len_min,
         act_len_max,
         act_count,
         act_weight,
         act_theory_weight,
         belong_code,
         belong_name,
         outstock_time,
         create_name,
         create_time,
         ord_pk,
         ord_ln_pk,
         ord_ln_dly_pk,
         /*department_code,
         department_desc,
         tar_department_code,
         tar_department_desc,*/
         order_no,
         order_seq,
         delivery_no,
         product_flag,
         mat_status,
         /*judge_std_name,
         judge_std_code,*/
         bal_year_month,
         qcm_staus,
         PROCESS_CDOE,
         PROCESS_DESC)
      values
        (V_OUTSTOCK_DOC || LPAD(V_ICOUNT, 4, 0),
         V_OUTSTOCK_DOC,
         '800808',
         '改判出库',
         MYROW1.MAT_NO,
         MYROW1.LOT_NO,
         MYROW1.STOVE_NO,
         MYROW1.JUDGE_STOVE_NO,
         MYROW1.BATCH_NO,
         MYROW1.batch_groud_no,
         MYROW1.material_no,
         MYROW1.material_name,
         MYROW1.produccode,
         MYROW1.producname,
         MYROW1.std_code,
         MYROW1.std_name,
         MYROW1.gradecode,
         MYROW1.gradename,
         MYROW1.steelcode,
         MYROW1.steelname,
         MYROW1.std_style,
         MYROW1.std_style_desc,
         MYROW1.spec_code,
         MYROW1.spec_name,
         MYROW1.model_code,
         MYROW1.model_desc,
         MYROW1.ORDER_NO || '/' || MYROW1.ORDER_SEQ,
         MYROW1.pline_code,
         MYROW1.pline_name,
         MYROW1.ACT_DIMATER,
         MYROW1.ACT_HEIGHT,
         MYROW1.act_len,
         MYROW1.act_len_min,
         MYROW1.act_len_max,
         MYROW1.act_count,
         MYROW1.act_weight,
         MYROW1.act_theory_weight,
         MYROW1.belong_code,
         MYROW1.belong_name,
         SYSDATE,
         V_APPLY_NAME,
         SYSDATE,
         MYROW1.ord_pk,
         MYROW1.ord_ln_pk,
         MYROW1.ord_ln_dly_pk,
         /*MYROW1.department_code,
         MYROW1.department_desc,
         MYROW1.tar_department_code,
         MYROW1.tar_department_desc,*/
         MYROW1.order_no,
         MYROW1.order_seq,
         MYROW1.ORDER_SEQ_NO,
         MYROW1.product_flag,
         MYROW1.mat_status,
         /* MYROW1.judge_std_name,
         MYROW1.judge_std_code,*/
         V_BAL_YEAR_MONTH,
         MYROW1.qcm_staus,
         MYROW1.PROCESS_CDOE,
         MYROW1.PROCESS_DESC);
    
      --备份材料信息，转成品          
      INSERT INTO MAT_BC_M_BACK_UP
        SELECT * FROM MAT_BC_M T WHERE T.MAT_NO = MYROW1.MAT_NO;
      UPDATE MAT_BC_M T
         SET T.PRODUCT_FLAG        = '801402',
             T.MAT_STATUS          = '80150201',
             T.ORDER_NO            = MYROW.ORDER_NO,
             T.ORDER_SEQ           = MYROW.ORDER_SEQ,
             T.ORDER_SEQ_NO        = MYROW.DELIVERY_NO,
             T.ORD_PK              = MYROW.ORD_PK,
             T.ORD_LN_PK           = MYROW.ORD_LN_PK,
             T.ORD_LN_DLY_PK       = MYROW.ORD_LN_DLY_PK,
             T.CRAF_NO             = MYROW.CRAF_NO,
             T.CRAFT_SEQ           = MYROW.CRAFT_SEQ,
             T.PRODUCCODE          = MYROW.PRODUCCODE,
             T.PRODUCNAME          = MYROW.PRODUCNAME,
             T.STEELCODE           = MYROW.STEELCODE,
             T.STEELNAME           = MYROW.STEELNAME,
             T.STD_CODE            = MYROW.STD_CODE,
             T.STD_NAME            = MYROW.STD_NAME,
             T.STD_STYLE_DESC      = MYROW.STD_STYLE_DESC,
             T.SPEC_CODE           = MYROW.SPEC_CODE,
             T.SPEC_NAME           = MYROW.SPEC_NAME,
             T.MODEL_CODE          = MYROW.MODEL_CODE,
             T.MODEL_DESC          = MYROW.MODEL_DESC,
             T.MATERIAL_NO         = MYROW.MATERIAL_NO,
             T.MATERIAL_NAME       = MYROW.MATERIAL_DESC,
             T.BELONG_CODE         = V_BELONG_CODE_JUGDE,
             T.BELONG_NAME         = V_BELONG_NAME_JUGDE,
             T.PRO_ORDER_NO        = MYROW.ORDER_NO || '/' ||
                                     MYROW.ORDER_SEQ,
             T.TARGET              = 'A',
             T.CIC                 = V_CIC,
             T.PROCESS_CDOE        = V_PROCESS_CODEO_END,
             T.PROCESS_DESC        = MYROW1.PROCESS_DESC,
             T.JUGDE_APPLY_CODE    = V_JUGDE_APPLY_CODE,
             T.JUGDE_APPLY_SEQUENO = V_JUGDE_APPLY_SEQUENO
       WHERE T.MAT_NO = MYROW1.MAT_NO;
    
      INSERT INTO YDM_BC_INLIST
        (INSTOCK_SQE,
         INSTOCK_DOC,
         INSTOCK_TYPE_CODE,
         INSTOCK_TYPE_NAME,
         MAT_NO,
         LOT_NO,
         STOVE_NO,
         JUDGE_STOVE_NO,
         BATCH_NO,
         BATCH_GROUD_NO,
         MATERIAL_NO,
         MATERIAL_NAME,
         PRODUCCODE,
         PRODUCNAME,
         STD_CODE,
         STD_NAME,
         GRADECODE,
         GRADENAME,
         STEELCODE,
         STEELNAME,
         --STD_STYLE,
         STD_STYLE_DESC,
         SPEC_CODE,
         SPEC_NAME,
         MODEL_CODE,
         MODEL_DESC,
         PRO_ORDER_NO,
         PLINE_CODE,
         PLINE_NAME,
         ACT_DIMATER,
         ACT_HEIGHT,
         ACT_LEN,
         ACT_LEN_MIN,
         ACT_LEN_MAX,
         ACT_COUNT,
         ACT_WEIGHT,
         ACT_THEORY_WEIGHT,
         BELONG_CODE,
         BELONG_NAME,
         INSTOCK_TIME,
         CREATE_NAME,
         CREATE_TIME,
         ORD_PK,
         ORD_LN_PK,
         ORD_LN_DLY_PK,
         ORDER_NO,
         ORDER_SEQ,
         DELIVERY_NO,
         PRODUCT_FLAG,
         MAT_STATUS,
         JUDGE_STD_NAME,
         IN_TIME_F,
         BAL_YEAR_MONTH,
         QCM_STAUS,
         PROCESS_CDOE,
         PROCESS_DESC)
      VALUES
        (V_INSTOCK_DOC || LPAD(V_ICOUNT, 4, 0),
         V_INSTOCK_DOC,
         '800706',
         '改判入库',
         MYROW1.MAT_NO,
         MYROW1.LOT_NO,
         MYROW1.STOVE_NO,
         MYROW1.JUDGE_STOVE_NO,
         MYROW1.BATCH_NO,
         MYROW1.BATCH_GROUD_NO,
         MYROW.MATERIAL_NO,
         MYROW.MATERIAL_DESC,
         MYROW.PRODUCCODE,
         MYROW.PRODUCNAME,
         MYROW.STD_CODE,
         MYROW.STD_NAME,
         MYROW1.GRADECODE,
         MYROW1.GRADENAME,
         MYROW.STEELCODE,
         MYROW.STEELNAME,
         --MYROW.STD_STYLE,
         MYROW.STD_STYLE_DESC,
         MYROW.SPEC_CODE,
         MYROW.SPEC_NAME,
         MYROW.MODEL_CODE,
         MYROW.MODEL_DESC,
         MYROW.ORDER_NO || '/' || MYROW.ORDER_SEQ,
         MYROW1.pline_code,
         MYROW1.pline_name,
         MYROW1.ACT_DIMATER,
         MYROW1.ACT_HEIGHT,
         MYROW1.ACT_LEN,
         MYROW1.ACT_LEN_MIN,
         MYROW1.ACT_LEN_MAX,
         MYROW1.ACT_COUNT,
         MYROW1.ACT_WEIGHT,
         MYROW1.ACT_THEORY_WEIGHT,
         MYROW1.BELONG_CODE,
         MYROW1.BELONG_NAME,
         SYSDATE,
         V_APPLY_NAME,
         SYSDATE,
         MYROW1.ORD_PK,
         MYROW1.ORD_LN_PK,
         MYROW1.ORD_LN_DLY_PK,
         MYROW1.ORDER_NO,
         MYROW1.ORDER_SEQ,
         MYROW1.ORDER_SEQ_NO,
         MYROW1.PRODUCT_FLAG,
         MYROW1.MAT_STATUS,
         MYROW1.JUDGE_STD_DES,
         SYSDATE,
         V_BAL_YEAR_MONTH,
         MYROW1.qcm_staus,
         MYROW1.PROCESS_CDOE,
         MYROW1.PROCESS_DESC);
    
      insert into ydm_bc_outlist
        (outstock_sqe,
         outstock_doc,
         outstock_type_code,
         outstock_type_name,
         mat_no,
         lot_no,
         stove_no,
         judge_stove_no,
         batch_no,
         batch_groud_no,
         material_no,
         material_name,
         produccode,
         producname,
         std_code,
         std_name,
         gradecode,
         gradename,
         steelcode,
         steelname,
         std_style,
         std_style_desc,
         spec_code,
         spec_name,
         model_code,
         model_desc,
         pro_order_no,
         pline_code,
         pline_name,
         act_dimater,
         act_height,
         act_len,
         act_len_min,
         act_len_max,
         act_count,
         act_weight,
         act_theory_weight,
         belong_code,
         belong_name,
         outstock_time,
         create_name,
         create_time,
         ord_pk,
         ord_ln_pk,
         ord_ln_dly_pk,
         /*department_code,
         department_desc,
         tar_department_code,
         tar_department_desc,*/
         order_no,
         order_seq,
         delivery_no,
         product_flag,
         mat_status,
         /*judge_std_name,
         judge_std_code,*/
         bal_year_month,
         qcm_staus,
         PROCESS_CDOE,
         PROCESS_DESC)
      values
        (V_OUTSTOCK_DOC2 || LPAD(V_ICOUNT, 4, 0),
         V_OUTSTOCK_DOC2,
         '800809',
         '产权出库',
         MYROW1.MAT_NO,
         MYROW1.LOT_NO,
         MYROW1.STOVE_NO,
         MYROW1.JUDGE_STOVE_NO,
         MYROW1.BATCH_NO,
         MYROW1.batch_groud_no,
         MYROW.MATERIAL_NO,
         MYROW.MATERIAL_DESC,
         MYROW.produccode,
         MYROW.producname,
         MYROW.std_code,
         MYROW.std_name,
         MYROW1.gradecode,
         MYROW1.gradename,
         MYROW.steelcode,
         MYROW.steelname,
         MYROW1.std_style,
         MYROW.std_style_desc,
         MYROW.spec_code,
         MYROW.spec_name,
         MYROW.model_code,
         MYROW.model_desc,
         MYROW.ORDER_NO || '/' || MYROW.ORDER_SEQ,
         MYROW1.pline_code,
         MYROW1.pline_name,
         MYROW1.ACT_DIMATER,
         MYROW1.ACT_HEIGHT,
         MYROW1.act_len,
         MYROW1.act_len_min,
         MYROW1.act_len_max,
         MYROW1.act_count,
         MYROW1.act_weight,
         MYROW1.act_theory_weight,
         MYROW1.belong_code,
         MYROW1.belong_name,
         SYSDATE,
         V_APPLY_NAME,
         SYSDATE,
         MYROW1.ord_pk,
         MYROW1.ord_ln_pk,
         MYROW1.ord_ln_dly_pk,
         /*MYROW1.department_code,
         MYROW1.department_desc,
         MYROW1.tar_department_code,
         MYROW1.tar_department_desc,*/
         MYROW1.order_no,
         MYROW1.order_seq,
         MYROW1.ORDER_SEQ_NO,
         MYROW1.product_flag,
         MYROW1.mat_status,
         /* MYROW1.judge_std_name,
         MYROW1.judge_std_code,*/
         V_BAL_YEAR_MONTH,
         MYROW1.qcm_staus,
         MYROW1.PROCESS_CDOE,
         MYROW1.PROCESS_DESC);
    
      V_ICOUNT := V_ICOUNT + 1;
    
    END LOOP;
  
    IF (V_COUNT > 0) THEN
      --新增成品送判信息
      FOR MYROW2 IN (SELECT SUM(T.ACT_COUNT) ACT_COUNT,
                            SUM(T.ACT_WEIGHT) ACT_WEIGHT,
                            SUM(T.ACT_THEORY_WEIGHT) ACT_THEORY_WEIGHT
                       FROM MAT_BC_M T
                      WHERE T.JUGDE_APPLY_CODE = V_JUGDE_APPLY_CODE
                        AND T.JUGDE_APPLY_SEQUENO = V_JUGDE_APPLY_SEQUENO) 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,
           face_result_path,
           spec_result_path,
           chem_result_path,
           phy_result_path,
           detect_result_path,
           wpressure_result_path,
           process_result_path,
           validflag,
           apply_name,
           apply_time,
           memo,
           quality_group,
           material_no,
           material_name,
           produccode,
           producname,
           steelcode,
           steelname,
           gradecode,
           gradename,
           spec_code,
           spec_name,
           model_code,
           model_desc,
           std_code,
           std_name,
           std_style,
           std_style_desc,
           craf_no,
           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,
           judge_result_code,
           judge_result,
           judge_result_time,
           judge_maker,
           if_set_zy_plan,
           testing_grade,
           testing_type,
           testing_grade1,
           testing_type1,
           detect_result_code1,
           detect_result_path1,
           ord_ln_dly_pk,
           --apply_flag,
           back_jugde_memo,
           --instock_flag,
           belong_code,
           belong_name,
           --isendgx,
           exit_temp,
           sample_news,
           act_len,
           belong_code_jugde,
           belong_name_jugde,
           gx_plan_no,
           input_weight,
           input_count,
           output_weight,
           output_count,
           bal_year_month,
           is_flag,
           is_all_scrap,
           is_carry_voer,
           stove_no,
           steel_standrad,
           pro_plan_id_next,
           gx_plan_no_next,
           lk_flag,
           judge_memo,
           judge_order,
           judge_group,
           judge_stove_no_seq,
           next_process_cdoe,
           jugde_apply_sequeno,
           audit_result,
           audit_memo,
           judge_tolresult_code,
           judge_tolresult,
           judge_tolresult_time,
           judge_tolmaker,
           judge_tolmemo,
           judge_tolorder,
           judge_tolgroup,
           audit_tolresult,
           audit_tolmemo,
           jugde_convicted,
           jugde_tolconvicted,
           --instancy_flag,
           --tol_instancy_flag,
           craft_seq,
           index_seq,
           cic,
           pic,
           sic,
           dic,
           wic,
           gic,
           heat_plan_no_next,
           check_no,
           heat_plan_no,
           delivery_state_code,
           delivery_state_name,
           load_judge_stove_no,
           zp_m_lh,
           zp_coll,
           htt_type,
           min_temp,
           htt_technology,
           notch_info,
           notch_length,
           notch_width,
           notch_depth,
           lot_no_group,
           test_pressure,
           holdtime_time,
           test_pressure_y,
           mch_watergage_result,
           mch_path_result,
           mch_chamfering_result,
           mch_twistingly_result,
           mch_dimensions_result,
           mch_visual_result,
           mch_thread_inspection_result,
           mch_remanence_result,
           mch_radioactivity_result,
           mch_bevel_result,
           angle_val,
           edge_val,
           --zbs_flag,
           testing_standar,
           drift_model_min,
           measured_end_part,
           measured_middle_part,
           measured_tail_part,
           judge_file_memo,
           judge_file_tolmemo,
           --zc_judge_condition,
           bundle_num,
           liku_process_code,
           load_batch_no,
           bundling_memo,
           zzb_flag,
           auto_judge,
           SUPPLY_UNIT,
           SUPPLY_UNIT_DESC)
          select V_JUGDE_APPLY_CODE,
                 judge_stove_no,
                 batch_no,
                 batch_groud_no,
                 V_PROCESS_CODEO_END,
                 pline_code,
                 MYROW2.ACT_COUNT,
                 MYROW2.ACT_WEIGHT,
                 MYROW2.ACT_THEORY_WEIGHT,
                 '',
                 face_result_code,
                 spec_result_code,
                 chem_result_code,
                 phy_result_code,
                 detect_result_code,
                 wpressure_result_code,
                 process_result_code,
                 face_result_path,
                 spec_result_path,
                 chem_result_path,
                 phy_result_path,
                 detect_result_path,
                 wpressure_result_path,
                 process_result_path,
                 '20',
                 V_APPLY_NAME,
                 SYSDATE,
                 memo,
                 quality_group,
                 MYROW.MATERIAL_NO,
                 MYROW.MATERIAL_DESC,
                 MYROW.PRODUCCODE,
                 MYROW.PRODUCNAME,
                 MYROW.STEELCODE,
                 MYROW.STEELNAME,
                 gradecode,
                 gradename,
                 MYROW.SPEC_CODE,
                 MYROW.SPEC_NAME,
                 MYROW.MODEL_CODE,
                 MYROW.MODEL_DESC,
                 MYROW.STD_CODE,
                 MYROW.STD_NAME,
                 std_style,
                 MYROW.STD_STYLE_DESC,
                 MYROW.CRAF_NO,
                 lot_no,
                 pline_name,
                 MYROW.ORDER_NO || '/' || MYROW.ORDER_SEQ,
                 'A',
                 process_status,
                 mat_gowhere_code,
                 mat_gowhere_name,
                 act_dimater,
                 act_height,
                 act_len_min,
                 act_len_max,
                 judge_result_code,
                 judge_result,
                 judge_result_time,
                 judge_maker,
                 if_set_zy_plan,
                 testing_grade,
                 testing_type,
                 testing_grade1,
                 testing_type1,
                 detect_result_code1,
                 detect_result_path1,
                 MYROW.ord_ln_dly_pk,
                 --apply_flag,
                 back_jugde_memo,
                 --instock_flag,
                 belong_code,
                 belong_name,
                 --isendgx,
                 exit_temp,
                 sample_news,
                 act_len,
                 NVL(MYROW.SALE_ORG, '002023005'),
                 NVL(MYROW.SALE_ORG_DESC, '制造部'),
                 gx_plan_no,
                 input_weight,
                 input_count,
                 output_weight,
                 output_count,
                 MYROW.BAL_YEAR_MONTH2,
                 '0',
                 '6',
                 '0',
                 stove_no,
                 steel_standrad,
                 pro_plan_id_next,
                 gx_plan_no_next,
                 '0',
                 judge_memo,
                 judge_order,
                 judge_group,
                 judge_stove_no_seq,
                 next_process_cdoe,
                 V_JUGDE_APPLY_SEQUENO,
                 audit_result,
                 audit_memo,
                 judge_tolresult_code,
                 judge_tolresult,
                 judge_tolresult_time,
                 judge_tolmaker,
                 judge_tolmemo,
                 judge_tolorder,
                 judge_tolgroup,
                 audit_tolresult,
                 audit_tolmemo,
                 jugde_convicted,
                 jugde_tolconvicted,
                 --instancy_flag,
                 --tol_instancy_flag,
                 MYROW.CRAFT_SEQ,
                 V_INDEX_SEQ,
                 V_CIC,
                 V_PIC,
                 sic,
                 dic,
                 wic,
                 gic,
                 heat_plan_no_next,
                 check_no,
                 heat_plan_no,
                 V_DELIVERY_STATE_CODE,
                 V_DELIVERY_STATE_NAME,
                 load_judge_stove_no,
                 zp_m_lh,
                 zp_coll,
                 htt_type,
                 min_temp,
                 htt_technology,
                 notch_info,
                 notch_length,
                 notch_width,
                 notch_depth,
                 lot_no_group,
                 test_pressure,
                 holdtime_time,
                 test_pressure_y,
                 mch_watergage_result,
                 mch_path_result,
                 mch_chamfering_result,
                 mch_twistingly_result,
                 mch_dimensions_result,
                 mch_visual_result,
                 mch_thread_inspection_result,
                 mch_remanence_result,
                 mch_radioactivity_result,
                 mch_bevel_result,
                 angle_val,
                 edge_val,
                 --zbs_flag,
                 testing_standar,
                 drift_model_min,
                 measured_end_part,
                 measured_middle_part,
                 measured_tail_part,
                 judge_file_memo,
                 judge_file_tolmemo,
                 --zc_judge_condition,
                 bundle_num,
                 liku_process_code,
                 load_batch_no,
                 bundling_memo,
                 zzb_flag,
                 auto_judge,
                 V_SUPPLY_UNIT,
                 V_SUPPLY_UNIT_DESC
            from qcm_zg_jugde_apply
           WHERE JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
             AND BATCH_NO = V_BATCH_NO
             AND BATCH_GROUD_NO = V_BATCH_GROUD_NO
             AND PLINE_CODE = V_PLINE_CODE
             AND JUGDE_APPLY_CODE = V_JUGDE_APPLY_CODE_OLD;
      
      END LOOP;
    ELSIF (V_COUNT = 0) THEN
    
      FOR MYROW3 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,
                            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,
                            NVL(MAX(T.MAT_GOWHERE_CODE), '/') MAT_GOWHERE_CODE,
                            MAX(T.MAT_GOWHERE_NAME) MAT_GOWHERE_NAME,
                            MAX(T.TESTING_GRADE) TESTING_GRADE,
                            MAX(T.TESTING_TYPE) TESTING_TYPE,
                            MAX(T.TESTING_GRADE1) TESTING_GRADE1,
                            MAX(T.TESTING_TYPE1) TESTING_TYPE1,
                            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.HEAT_PLAN_NO,
                            T.lock_liku LK_FLAG,
                            MAX(T.NEXT_PROCESS_CDOE) NEXT_PROCESS_CDOE,
                            MAX(T.ZZB_FLAG) ZZB_FLAG
                       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 NVL(T.MEMO, '/') = NVL(V_MEMO, '/')
                        AND T.QCM_STAUS = '00'
                        AND T.JUGDE_APPLY_CODE = V_JUGDE_APPLY_CODE
                      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.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,
           
           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,
           ACT_LEN,
           GX_PLAN_NO,
           BELONG_CODE_JUGDE,
           BELONG_NAME_JUGDE,
           STOVE_NO,
           STEEL_STANDRAD,
           LK_FLAG,
           NEXT_PROCESS_CDOE,
           JUGDE_APPLY_SEQUENO,
           HEAT_PLAN_NO,
           CRAFT_SEQ,
           CIC,
           PIC,
           INDEX_SEQ,
           MAT_GOWHERE_CODE,
           MAT_GOWHERE_NAME,
           VALIDFLAG,
           IS_ALL_SCRAP,
           DELIVERY_STATE_CODE,
           DELIVERY_STATE_NAME,
           SUPPLY_UNIT,
           SUPPLY_UNIT_DESC,
           BAL_YEAR_MONTH,
           LOAD_JUDGE_STOVE_NO,
           LOAD_BATCH_NO,
           JUDGE_RESULT_CODE,
           JUDGE_RESULT,
           JUDGE_RESULT_TIME)
        VALUES
          (V_JUGDE_APPLY_CODE,
           MYROW3.JUDGE_STOVE_NO,
           MYROW3.BATCH_NO,
           MYROW3.BATCH_GROUD_NO,
           V_PROCESS_CODEO_END,
           MYROW3.PLINE_CODE,
           MYROW3.ACT_COUNT,
           MYROW3.ACT_WEIGHT,
           MYROW3.ACT_THEORY_WEIGHT,
           MYROW3.PRO_ORDER_ID,
           MYROW3.FACE_RESULT_CODE,
           MYROW3.SPEC_RESULT_CODE,
           MYROW3.CHEM_RESULT_CODE,
           MYROW3.PHY_RESULT_CODE,
           MYROW3.DETECT_RESULT_CODE,
           MYROW3.WPRESSURE_RESULT_CODE,
           --?,
           V_APPLY_NAME,
           SYSDATE,
           --MYROW3.,
           '1',
           MYROW3.LOT_NO,
           MYROW3.PLINE_NAME,
           MYROW3.PRO_ORDER_NO,
           MYROW3.TARGET,
           MYROW3.PROCESS_STATUS,
           
           MYROW3.ACT_DIMATER,
           MYROW3.Act_Height,
           MYROW3.ACT_LEN_MIN,
           MYROW3.ACT_LEN_MAX,
           MYROW3.Craf_No,
           MYROW3.MATERIAL_NO,
           MYROW3.MATERIAL_NAME,
           MYROW3.PRODUCCODE,
           MYROW3.PRODUCNAME,
           MYROW3.SPEC_CODE,
           MYROW3.SPEC_NAME,
           MYROW3.STEELCODE,
           MYROW3.STEELNAME,
           MYROW3.MODEL_CODE,
           MYROW3.MODEL_DESC,
           MYROW3.STD_CODE,
           MYROW3.STD_NAME,
           MYROW3.STD_STYLE,
           MYROW3.STD_STYLE_DESC,
           MYROW3.GRADECODE,
           MYROW3.GRADENAME,
           MYROW3.TESTING_GRADE,
           MYROW3.TESTING_TYPE,
           MYROW3.TESTING_GRADE1,
           MYROW3.TESTING_TYPE1,
           CASE
             WHEN INSTR(MYROW3.ORD_LN_DLY_PK, '-', 10, 1) > 0 THEN
              SUBSTR(MYROW3.ORD_LN_DLY_PK,
                     0,
                     INSTR(MYROW3.ORD_LN_DLY_PK, '-', 10, 1) - 1)
             ELSE
              MYROW3.ORD_LN_DLY_PK
           END,
           MYROW3.BELONG_CODE,
           MYROW3.BELONG_NAME,
           MYROW3.ACT_LEN,
           MYROW3.GX_PLAN_NO,
           V_BELONG_CODE_JUGDE,
           V_BELONG_NAME_JUGDE,
           MYROW3.STOVE_NO,
           MYROW3.STEEL_STANDRAD,
           MYROW3.LK_FLAG,
           MYROW3.NEXT_PROCESS_CDOE,
           V_JUGDE_APPLY_SEQUENO,
           MYROW3.HEAT_PLAN_NO,
           MYROW3.CRAFT_SEQ,
           V_CIC,
           V_PIC,
           V_INDEX_SEQ,
           MYROW3.MAT_GOWHERE_CODE,
           MYROW3.MAT_GOWHERE_NAME,
           '20',
           '6',
           V_DELIVERY_STATE_CODE,
           V_DELIVERY_STATE_NAME,
           V_SUPPLY_UNIT,
           V_SUPPLY_UNIT_DESC,
           V_BAL_YEAR_MONTH,
           MYROW3.JUDGE_STOVE_NO,
           MYROW3.BATCH_NO,
           '40740701',
           '合格',
           SYSDATE);
      END LOOP;
    END IF;
  END LOOP;
END;

 ]]>
</query>

<query id = "FrmBcPipeApplPro.deleteQcmJudgeApply" desc = "撤销转成品">
<![CDATA[
DECLARE
  V_APPLY_FLAG QCM_ZG_JUGDE_APPLY.APPLY_FLAG%TYPE := NULL;
BEGIN
  --删除判定表
  DELETE FROM QCM_ZG_JUGDE_APPLY S
   WHERE S.JUGDE_APPLY_CODE = '#JUGDE_APPLY_CODE#'
     AND S.JUGDE_APPLY_SEQUENO = '#JUGDE_APPLY_SEQUENO#'
     AND S.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
     AND S.BATCH_NO = '#BATCH_NO#'
     AND S.BATCH_GROUD_NO = '#BATCH_GROUD_NO#';

  FOR MYROW IN (SELECT T1.*
                  FROM MAT_BC_M T, MAT_BC_M_BACK_UP T1
                 WHERE T.JUGDE_APPLY_CODE = '#JUGDE_APPLY_CODE#'
                   AND T.JUGDE_APPLY_SEQUENO = '#JUGDE_APPLY_SEQUENO#'
                   AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                   AND T.BATCH_NO = '#BATCH_NO#'
                   AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
                   AND T.MAT_NO = T1.MAT_NO) LOOP
    --还原材料表
    UPDATE MAT_BC_M T
       SET T.PRODUCT_FLAG        = MYROW.PRODUCT_FLAG,
           T.MAT_STATUS          = MYROW.MAT_STATUS,
           T.ORDER_NO            = MYROW.ORDER_NO,
           T.ORDER_SEQ           = MYROW.ORDER_SEQ,
           T.ORDER_SEQ_NO        = MYROW.ORDER_SEQ_NO,
           T.ORD_PK              = MYROW.ORD_PK,
           T.ORD_LN_PK           = MYROW.ORD_LN_PK,
           T.ORD_LN_DLY_PK       = MYROW.ORD_LN_DLY_PK,
           T.CRAF_NO             = MYROW.CRAF_NO,
           T.CRAFT_SEQ           = MYROW.CRAFT_SEQ,
           T.PRODUCCODE          = MYROW.PRODUCCODE,
           T.PRODUCNAME          = MYROW.PRODUCNAME,
           T.STEELCODE           = MYROW.STEELCODE,
           T.STEELNAME           = MYROW.STEELNAME,
           T.STD_CODE            = MYROW.STD_CODE,
           T.STD_NAME            = MYROW.STD_NAME,
           T.STD_STYLE_DESC      = MYROW.STD_STYLE_DESC,
           T.SPEC_CODE           = MYROW.SPEC_CODE,
           T.SPEC_NAME           = MYROW.SPEC_NAME,
           T.MODEL_CODE          = MYROW.MODEL_CODE,
           T.MODEL_DESC          = MYROW.MODEL_DESC,
           T.MATERIAL_NO         = MYROW.MATERIAL_NO,
           T.MATERIAL_NAME       = MYROW.material_name,
           T.BELONG_CODE         = MYROW.BELONG_CODE,
           T.BELONG_NAME         = MYROW.BELONG_NAME,
           T.TARGET              = MYROW.TARGET,
           T.CIC                 = MYROW.CIC,
           T.JUGDE_APPLY_CODE    = MYROW.JUGDE_APPLY_CODE,
           T.JUGDE_APPLY_SEQUENO = MYROW.JUGDE_APPLY_SEQUENO
     WHERE T.MAT_NO = MYROW.MAT_NO;
    --删除备份信息
    DELETE FROM MAT_BC_M_BACK_UP T1 WHERE T1.MAT_NO = MYROW.MAT_NO;
    --删除改判出库记录
    DELETE FROM YDM_BC_OUTLIST T2
     WHERE T2.MAT_NO = MYROW.MAT_NO
       AND T2.OUTSTOCK_TYPE_NAME = '改判出库';
    --删除改判入库记录
    DELETE FROM YDM_BC_INLIST T2
     WHERE T2.MAT_NO = MYROW.MAT_NO
       AND T2.INSTOCK_TYPE_NAME = '改判入库';
    --删除产权出库记录
    DELETE FROM YDM_BC_OUTLIST T2
     WHERE T2.MAT_NO = MYROW.MAT_NO
       AND T2.OUTSTOCK_TYPE_NAME = '产权出库';
  END LOOP;
END;

 ]]>
</query>


<query id = "FrmBcPipeApplPro.doQueryValidFlag" desc = "查询送判信息">
<![CDATA[
select t.*, t.rowid from QCM_ZG_JUGDE_APPLY t WHERE T.JUGDE_APPLY_CODE = ? AND T.JUGDE_APPLY_SEQUENO = ?
 ]]>
</query>

<query id = "FrmBcPipeApplPro.SelectOrderSlaOrg" desc = "查询合同所属部门">
<![CDATA[
SELECT S.SALE_ORG, S.SALE_ORG_DESC
  FROM SLM_ORDER_HEAD S, SLM_ORDER_LINE S1
 WHERE S.ORD_PK = S1.ORD_PK
   AND S1.ORD_LN_PK = ?
   AND ROWNUM = 1
 ]]>
</query>

<query id = "FrmBcPipeApplPro.updatePossWt" desc = "修改过磅重量">
	UPDATE MAT_BC_M T
   SET T.PONDER_GROSS_WT = ?, T.ACT_WEIGHT = ?
 WHERE T.MAT_NO = ?
   AND T.JUDGE_STOVE_NO = ?
   AND T.JUGDE_APPLY_CODE = ?
   AND T.BATCH_NO = ?
	</query>
	
	<query id = "FrmBcPipeApplPro.selectCount" desc = "查询该炉总支数">
	SELECT NVL(SUM(T.ACT_COUNT), 0) ACOUNT
  FROM MAT_BC_M T
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.JUGDE_APPLY_CODE = ?
   AND T.BATCH_NO = ?
   AND T.QCM_STAUS = '00'
	</query>
	<query id = "FrmBcPipeApplPro.selectMatNo" desc = "查询所有材料号">
	SELECT T.MAT_NO
  FROM MAT_BC_M T
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.JUGDE_APPLY_CODE = ?
   AND T.BATCH_NO = ?
   AND T.QCM_STAUS = '00'
	</query>
<query id = "FrmBcPipeApplPro.updateActWT" desc = "修改送判的重量">
	UPDATE QCM_ZG_JUGDE_APPLY T
   SET T.ACT_WEIGHT = ?
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.JUGDE_APPLY_CODE = ?
   AND T.BATCH_NO = ?
	</query>

</queryMap>