<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc = "处理整炉废、白条">
<query id = "FrmScrapStoveApplyDescion.doQueryMata" desc = "查询已经上料了炉计划(整炉废信息)">
<![CDATA[
SELECT T.PRO_PLAN_ID,
       T.GX_PLAN_NO,
       T.LOT_NO,
       T.CONTRACT_NO,
       T.VARIETIES,
       T.PIPE_SIZE,
       T.BUCKLE_TYPE,
       T.STEELNAME,
       T.GRADENAME,
       T.ROLL_STANDRAD,
       T.STD_STYLE_DESC,
       T.IMP_PROCESS,
       T.PROCESS_STATUS,
       T.TARGET,
       --SUBSTR(S.JUDGE_STOVE_NO, 0, 6) JUDGE_STOVE_NO,
       S.JUDGE_STOVE_NO,
       S.ACT_COUNT,
       S.ACT_WEIGHT,
       S.INPUT_WEIGHT,
       T.PLINE_CODE
  FROM MIL_PLAN T,
       (SELECT T1.JUDGE_STOVE_NO,
               T1.PLAN_ID,
               SUM(T1.ACT_COUNT) ACT_COUNT,
               SUM(T1.ACT_THEORY_WEIGHT) ACT_WEIGHT,
               SUM(T1.INPUT_WEIGHT) INPUT_WEIGHT
          FROM PORT_MIL_BATCH_SAMPLE_RESULT T1
         WHERE T1.GROUP_FLAG = '0'
           AND T1.BAL_YEAR_MONTH = ?
           AND REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '') || '&' LIKE
               '%' || ? || '%'
           AND T1.PLINE_CODE = ?
           AND T1.STATUS IN ('1', '2', '6', '7')
           AND T1.JUDGE_STOVE_NO NOT IN
               (SELECT DISTINCT T2.JUDGE_STOVE_NO
                  FROM PORT_MIL_BATCH_SAMPLE_RESULT T2
                 WHERE T2.GROUP_FLAG = '0'
                   AND T2.BAL_YEAR_MONTH = ?
                   AND REGEXP_REPLACE(T2.JUDGE_STOVE_NO, '-.*', '') || '&' LIKE
                       '%' || ? || '%'
                   AND T2.PLINE_CODE = ?
                   AND T2.STATUS = '0')
         GROUP BY T1.JUDGE_STOVE_NO, T1.PLAN_ID) S
 WHERE T.JUDGE_STOVE_NO = S.JUDGE_STOVE_NO
   AND T.ID = S.PLAN_ID
  ]]>
</query>

<query id = "FrmScrapStoveApplyDescion.doQueryMataLG" desc = "查询整炉废数据(炼钢)">
<![CDATA[
SELECT DECODE(T.PRODUCT_FLAG,
              '801401',
              '在制品',
              '801402',
              '成品',
              '801403',
              '商品') PRODUCT_FLAG,
       DECODE(T.MAT_STATUS,
              '80150101',
              '材料产出待判',
              '80150102',
              '材料产出(已判定)',
              '80150103',
              '材料已编计划',
              '80150104',
              '材料待处理',
              '80150105',
              '材料加工',
              '80150201',
              '材料产出待判（未综合判定）',
              '80150202',
              '材料产出（已综合判定）') MAT_STATUS,
       DECODE(T.HANGING_FLAG, '0', '否', '1', '是') HANGING_FLAG,
       
       T.STOVE_NO,
       T.JUDGE_STOVE_NO,
       T.GROUD_NO,
       T.MATERIAL_NO,
       T.MATERIAL_NAME,
       T.GRADECODE,
       T.GRADENAME,
       T.STD_CODE,
       T.STD_NAME,
       T.PRO_ORDER_NO,
       T.PLINE_CODE,
       T.PLINE_NAME,
       T.DIMATER,
       T.ACT_LEN,
       T.FIX_NUM,
       T.FIX_LEN,
       SUM(T.ACT_COUNT) ACT_COUNT,
       SUM(T.ACT_WEIGHT) ACT_WEIGHT,
       T.BELONG_CODE,
       T.BELONG_NAME,
       (SELECT C.STORAGE_NAME
          FROM YDM_BS_STORAGE C
         WHERE C.STORAGE_NO = S.STORAGE_NO) STORAGE_NAME,
       S.STORAGE_NO,
       DECODE(T.QCM_STAUS,
              '00',
              '合格',
              '11',
              '待处理',
              '22',
              '废品',
              '10',
              '处理合格',
              '12',
              '处理判废') QCM_STAUS,
       
       DECODE(T.GPTYPE, '1', '铸坯', '2', '锻坯') GPTYPE,
       T.FURNACENO,
       T.SEQUENCENO,
       S.LOCATION_NO,
       S.LARY_NO,
       S.LOCATION_NAME,
       T.HEAT_PLAN_NO_NEXT,
       T.PRO_PLAN_ID_ZG,
       T.GX_PLAN_NO_ZG,
       T.BAL_YEAR_MONTH,
       MAX(TO_CHAR(T.INSTOCK_TIME, 'YYYY-MM-DD HH:MM:SS')) INSTOCK_TIME,
       DECODE(T.INSTANCY_FLAG, '0', '否', '1', '是') INSTANCY_FLAG,
       (SELECT T1.BASENAME
          FROM COM_BASE_INFO T1
         WHERE T1.BASECODE = T.JUDGE_RESULT_CODE) JUDGE_RESULT_CODE
  FROM MAT_GP_M T, YDM_GP_BUTTRESS S
 WHERE T.MAT_NO = S.MAT_NO
   AND T.QCM_STAUS = '22'
   AND T.PRODUCT_FLAG = '801401'
   AND T.JUGDE_APPLY_CODE IS NULL
   AND T.JUDGE_STOVE_NO || '&' LIKE '%' || ? || '%'
   AND T.BAL_YEAR_MONTH = ?
   AND T.EF_PLINE_CODE = ?
 GROUP BY T.STOVE_NO,
          T.JUDGE_STOVE_NO,
          T.MATERIAL_NO,
          T.MATERIAL_NAME,
          T.GROUD_NO,
          T.FURNACENO,
          T.SEQUENCENO,
          T.GRADECODE,
          T.GRADENAME,
          T.STD_CODE,
          T.STD_NAME,
          T.PRO_ORDER_NO,
          T.PLINE_CODE,
          T.PLINE_NAME,
          T.QCM_STAUS,
          T.GPTYPE,
          T.JUDGE_RESULT_CODE,
          T.DIMATER,
          T.ACT_LEN,
          T.FIX_NUM,
          T.FIX_LEN,
          T.PRODUCT_FLAG,
          T.MAT_STATUS,
          S.STORAGE_NO,
          T.BELONG_CODE,
          T.BELONG_NAME,
          S.LOCATION_NO,
          S.LARY_NO,
          S.LOCATION_NAME,
          T.HANGING_FLAG,
          T.INSTANCY_FLAG,
          T.BAL_YEAR_MONTH,
          T.HEAT_PLAN_NO_NEXT,
          T.PRO_PLAN_ID_ZG,
          T.GX_PLAN_NO_ZG

  ]]>
</query>
<!-- 
AND NOT EXISTS
  (SELECT *
          FROM QCM_ZG_JUGDE_APPLY S1
         WHERE S1.JUDGE_STOVE_NO = SUBSTR(S.JUDGE_STOVE_NO,0,6)
           AND S1.IS_FLAG ='0'
           AND S1.IS_ALL_SCRAP IN('0','1')
 -->
<query id = "FrmScrapStoveApplyDescion.doQueryBTMata" desc = "查询可以打白条信息">
<![CDATA[
SELECT MAX(F.LOT_NO) LOT_NO,
       MAX(F.CONTRACT_NO) CONTRACT_NO,
       MAX(F.VARIETIES) VARIETIES,
       MAX(F.PIPE_SIZE) PIPE_SIZE,
       MAX(F.BUCKLE_TYPE) BUCKLE_TYPE,
       MAX(F.STEELNAME) STEELNAME,
       MAX(F.GRADENAME) GRADENAME,
       MAX(F.ROLL_STANDRAD) ROLL_STANDRAD,
       MAX(F.STD_STYLE_DESC) STD_STYLE_DESC,
       MAX(F.IMP_PROCESS) IMP_PROCESS,
       MAX(F.PROCESS_STATUS) PROCESS_STATUS,
       MAX(F.TARGET) TARGET,
       MAX(F.PRO_PLAN_ID) PRO_PLAN_ID,
       MAX(F.GX_PLAN_NO) GX_PLAN_NO,
       F.JUDGE_STOVE_NO,
       SUM(F.ACT_COUNT) ACT_COUNT,
       SUM(F.ACT_WEIGHT) ACT_WEIGHT,
       SUM(F.INPUT_WEIGHT)INPUT_WEIGHT,
       MAX(F.PLINE_CODE) PLINE_CODE
  FROM (SELECT T.LOT_NO,
               T.CONTRACT_NO,
               T.VARIETIES,
               T.PIPE_SIZE,
               T.BUCKLE_TYPE,
               T.STEELNAME,
               T.GRADENAME,
               T.ROLL_STANDRAD,
               T.STD_STYLE_DESC,
               T.IMP_PROCESS,
               T.PROCESS_STATUS,
               T.TARGET,
               T.PRO_PLAN_ID,
               T.GX_PLAN_NO,
               REGEXP_REPLACE(S.JUDGE_STOVE_NO, '-.*', '') JUDGE_STOVE_NO,
               S.ACT_COUNT,
               S.ACT_WEIGHT,
               S.INPUT_WEIGHT,
               T.PLINE_CODE
          FROM MIL_PLAN T,
               (SELECT T1.JUDGE_STOVE_NO,
                       T1.PLAN_ID,
                       SUM(T1.ACT_COUNT) ACT_COUNT,
                       SUM(T1.ACT_THEORY_WEIGHT) ACT_WEIGHT,
                       SUM(T1.INPUT_WEIGHT)INPUT_WEIGHT
                  FROM PORT_MIL_BATCH_SAMPLE_RESULT T1
                 WHERE T1.BAL_YEAR_MONTH = ?
                   AND T1.JUDGE_STOVE_NO || '&' LIKE  ? || '%'
                   AND SUBSTR(T1.JUDGE_STOVE_NO,-3) = '-01'
                   AND T1.PLINE_CODE = ?
                 GROUP BY T1.JUDGE_STOVE_NO, T1.PLAN_ID) S
         WHERE T.JUDGE_STOVE_NO = S.JUDGE_STOVE_NO
           AND T.ID = S.PLAN_ID
           AND T.NODE_STATUS = '99'
           AND T.TARGET IN('B','C')) F
 WHERE NOT EXISTS (SELECT *
          FROM QCM_ZG_JUGDE_APPLY S1
         WHERE F.JUDGE_STOVE_NO = S1.JUDGE_STOVE_NO
           AND S1.VALIDFLAG = '20'
           AND S1.IS_FLAG = '0')
           GROUP BY F.JUDGE_STOVE_NO
  ]]>
</query>
<query id = "FrmScrapStoveApplyDescion.doQueryQcmMata" desc = "查询整炉废、白条信息">
<![CDATA[
SELECT 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,
       DECODE(IS_ALL_SCRAP,'1','整炉废','2','白条')IS_ALL_SCRAP,
       IS_CARRY_VOER
  FROM QCM_ZG_JUGDE_APPLY T
   WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') || '&' LIKE '%' || ? || '%'
   AND PLINE_CODE = ?
   AND IS_ALL_SCRAP IN('1','2')
           ]]>
</query>

<query id = "FrmScrapStoveApplyDescion.doQueryQcmMataLG" desc = "查询整炉废信息（炼钢)">
<![CDATA[
select jugde_apply_code,
       jugde_apply_sqe,
       stove_no,
       cast_no,
       ccmid,
       judge_stove_no,
       batch_groud_no,
       process_code,
       pline_code,
       len_gp_single,
       multiple_num,
       act_count,
       act_dimater,
       act_len,
       act_weight,
       act_theory_weight,
       face_result_code,
       spec_result_code,
       chem_result_code,
       phy_result_code,
       detect_result_code,
       face_result_path,
       spec_result_path,
       chem_result_path,
       phy_result_path,
       detect_result_path,
       material_no,
       material_name,
       gradecode,
       gradename,
       std_code,
       std_name,
       pline_name,
       pro_order_no,
       mat_gowhere_code,
       mat_gowhere_name,
       judge_result_code,
       judge_result,
       judge_result_time,
       judge_maker,
       if_set_zy_plan,
       ord_ln_dly_pk,
       apply_flag,
       back_jugde_memo,
       validflag,
       apply_name,
       apply_time,
       memo,
       bal_year_month,
       is_flag,
       
       pro_plan_id,
       gx_plan_no,
       gpreq_id,
       belong_code_jugde,
       belong_name_jugde,
       furnaceno,
       sequenceno,
       craft_no,
       isendgx,
       gptype,
       pro_plan_id_next,
       gx_plan_no_next,
       jugde_apply_sequeno,
       produccode,
       producname,
       apply_shift,
       apply_group,
       final_user,
       final_user_desc,
       steel_standrad,
       instancy_flag,
       if_monitor_lg,
       cx_flag_chem,
       judge_memo,
       judge_order,
       judge_group,
       plan_route,
       lk_flag,
       audit_result,
       audit_memo,
       audit_result2,
       audit_memo2,
       old_gradecode,
       old_gradename,
       old_cic,
       judge_stove_no_lg,
       ef_pline_code,
       ef_pline_name,
       is_carry_voer,
       chem_db_rpt_flag,
       cic,
       DECODE(IS_ALL_SCRAP, '1', '整炉废', '2', '白条') IS_ALL_SCRAP,
       heat_plan_no_next,
       auto_judge
  from qcm_gp_judge_apply T
 WHERE T.IS_ALL_SCRAP = '1'
   AND T.JUDGE_STOVE_NO || '&' LIKE '%' || ? || '%'
   AND T.EF_PLINE_CODE = ?

           ]]>
</query>
<query id = "FrmScrapStoveApplyDescion.doDecisionScrap" desc = "整炉废插入判定表">
 INSERT INTO QCM_ZG_JUGDE_APPLY
  (JUGDE_APPLY_CODE,
   JUDGE_STOVE_NO,
   BATCH_NO,
   BATCH_GROUD_NO,
   PLINE_CODE,
   ACT_COUNT,
   ACT_WEIGHT,
   ACT_THEORY_WEIGHT,
   PRO_ORDER_ID,
   VALIDFLAG,
   APPLY_NAME,
   APPLY_TIME,
   PRODUCNAME,
   STEELNAME,
   GRADENAME,
   SPEC_NAME,
   MODEL_DESC,
   STD_NAME,
   STD_STYLE_DESC,
   CRAF_NO,
   LOT_NO,
   PLINE_NAME,
   PRO_ORDER_NO,
   TARGET,
   PROCESS_STATUS,
   ORD_LN_DLY_PK,
   APPLY_FLAG,
   BELONG_CODE,
   BELONG_NAME,
   BELONG_CODE_JUGDE,
   BELONG_NAME_JUGDE,
   GX_PLAN_NO,
   INPUT_WEIGHT,
   INPUT_COUNT,
   OUTPUT_WEIGHT,
   OUTPUT_COUNT,
   BAL_YEAR_MONTH,
   IS_ALL_SCRAP,
   PROCESS_CODE,
   QUALITY_GROUP,
   MAT_GOWHERE_CODE,
   MAT_GOWHERE_NAME,
   JUDGE_STOVE_NO_SEQ,
   JUDGE_RESULT_CODE,
   JUDGE_RESULT,
   JUDGE_RESULT_TIME,
   JUDGE_MAKER,
   JUDGE_TOLRESULT_CODE,
   JUDGE_TOLRESULT,
   --JUDGE_TOLMAKER,
   JUDGE_TOLRESULT_TIME,
   SUPPLY_UNIT,
   SUPPLY_UNIT_DESC)
VALUES
  ('#JUGDE_APPLY_CODE#',
   '#JUDGE_STOVE_NO#',
   '#BATCH_NO#',
   '#BATCH_GROUD_NO#',
   '#PLINE_CODE#',
   '#ACT_COUNT#',
   '#ACT_WEIGHT#',
   '#ACT_THEORY_WEIGHT#',
   '#PRO_ORDER_ID#',
   '#VALIDFLAG#',
   '#APPLY_NAME#',
   SYSDATE,
   '#PRODUCNAME#',
   '#STEELNAME#',
   '#GRADENAME#',
   '#SPEC_NAME#',
   '#MODEL_DESC#',
   '#STD_NAME#',
   '#STD_STYLE_DESC#',
   '#CRAF_NO#',
   '#LOT_NO#',
   '#PLINE_NAME#',
   '#PRO_ORDER_NO#',
   '#TARGET#',
   '#PROCESS_STATUS#',
   '#ORD_LN_DLY_PK#',
   '#APPLY_FLAG#',
   '#BELONG_CODE#',
   '#BELONG_NAME#',
   '#BELONG_CODE_JUGDE#',
   '#BELONG_NAME_JUGDE#',
   '#GX_PLAN_NO#',
   '#INPUT_WEIGHT#',
   '#INPUT_COUNT#',
   '#OUTPUT_WEIGHT#',
   '#OUTPUT_COUNT#',
   '#BAL_YEAR_MONTH#',
   '#IS_ALL_SCRAP#',
   'D',
   '1',
   '1',
   '',
   '#JUDGE_STOVE_NO_SEQ#',
   '#JUDGE_RESULT_CODE#',
   '#JUDGE_RESULT#',
   SYSDATE,
   '#JUDGE_MAKER#',
   '#JUDGE_TOLRESULT_CODE#',
   '#JUDGE_TOLRESULT#',
   --'#JUDGE_TOLMAKER#',
   TO_DATE('#JUDGE_TOLRESULT_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
   (SELECT C.SUPPLY_UNIT_CODE
      FROM COM_BASE_PLINE C
     WHERE C.PLINE_CODE = '#PLINE_CODE#'),
   (SELECT C.SUPPLY_UNIT
      FROM COM_BASE_PLINE C
     WHERE C.PLINE_CODE = '#PLINE_CODE#'))
</query>
<query id = "FrmScrapStoveApplyDescion.SelectScrapInput" desc = "查询投料量(废)">
<![CDATA[
SELECT COUNT(1)INPUT_COUNT,SUM(INPUT_WEIGHT)INPUT_WEIGHT
  FROM (SELECT S.M_MAT_NO,SUM(S.INPUT_WEIGHT)INPUT_WEIGHT
          FROM PORT_MIL_BATCH_SAMPLE_RESULT S
         WHERE S.JUDGE_STOVE_NO = ? || '-01'
         AND S.TR_FLAG = '0'
         GROUP BY S.M_MAT_NO
         ORDER BY S.M_MAT_NO)
                        ]]>
</query>
<query id = "FrmScrapStoveApplyDescion.SelectScrapInput1" 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>
<query id = "FrmScrapStoveApplyDescion.cancelScrapMata" desc = "撤销整炉送判">
DELETE FROM QCM_ZG_JUGDE_APPLY T WHERE T.JUGDE_APPLY_CODE = '#JUGDE_APPLY_CODE#' AND T.IS_ALL_SCRAP = '#IS_ALL_SCRAP#'
</query>
<query id = "insertWhiteBank.selectInstore" desc = "查询下线实绩表">
<![CDATA[
SELECT COUNT(1)ACOUNT FROM MIL_INSTORE_RESULT T WHERE T.JUDGE_STOVE_NO || '&' LIKE '%' || ? || '%'
]]>
</query>
<query id = "FrmScrapStoveApplyDescion.selectMaxBalYearMoth" desc = "查询期初表最大结转年月">
SELECT MAX(T.BAL_YEAR_MONTH) BAL_YEAR_MONTH,to_char(to_date(MAX(t.BAL_YEAR_MONTH), 'YYYY-MM'), 'yyyy-MM') as B_BAL_YEAR_MONTH FROM YDM_ZC_INITIAL_ZG T
</query>

<query id = "FrmInOnlineStore.updatePlanStatus" desc = "更新炉计划状态">
UPDATE PLN_ZY_ZG_M T
   SET T.PLANSTATUS = ?
 WHERE T.PRO_PLAN_ID = ?
   AND T.GX_PLAN_NO = ?
   AND T.FEED_HEAT_NO = REGEXP_REPLACE(?, '-.*', '')
</query>
</queryMap>