<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc = "申请判定管理">
<query id="FrmVrpApplyNew.getQueryRemark" desc="获取备注">
    <![CDATA[
    SELECT TO_CHAR(wm_concat(ACT_COUNT||'支:'||PIPMEMO)) Remark FROM (
 SELECT
  SUM(A.ACT_COUNT) ACT_COUNT,A.PIPMEMO
 FROM MAT_BC_M A WHERE A.JUDGE_STOVE_NO=? AND A.HEAT_PLAN_NO=?  AND A.PIPMEMO IS NOT NULL GROUP BY PIPMEMO)
     ]]>
</query>

<query id="FrmVrpApplyNew.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 = "FrmVrpApplyNew.doQueryMat" desc = "查询炉信息">
<![CDATA[
SELECT M.LOT_NO,
       M.JUDGE_STOVE_NO,
       M.PROCESS_CDOE,
       M.NEXT_PROCESS_CDOE,
       M.JUGDE_APPLY_CODE,
       (SELECT SUM(Q.ACT_COUNT)
          FROM QCM_ZG_JUGDE_APPLY Q
         WHERE Q.JUDGE_STOVE_NO = M.JUDGE_STOVE_NO
           AND Q.PLINE_CODE = M.PLINE_CODE
           AND Q.PROCESS_CODE = M.PROCESS_CDOE) SPZ,
       
       (SELECT SUM(S.ACT_COUNT)
          FROM MIL_INSPECTION S
         WHERE S.JUDGE_STOVE_NO = M.JUDGE_STOVE_NO
           AND S.HEAT_PLAN_NO = M.HEAT_PLAN_NO
           AND S.VALIDFLAG = '1') BJZ,
       (SELECT SUM(S.ACT_COUNT)
          FROM MIL_INSPECTION S
         WHERE S.JUDGE_STOVE_NO = M.JUDGE_STOVE_NO
           AND S.HEAT_PLAN_NO = M.HEAT_PLAN_NO
           AND S.VALIDFLAG = '1'
           AND S.INSPECTION_FLAG > 1) YJZ,
       (SELECT SUM(S.ACT_COUNT)
          FROM MIL_INSPECTION S
         WHERE S.JUDGE_STOVE_NO = M.JUDGE_STOVE_NO
           AND S.HEAT_PLAN_NO = M.HEAT_PLAN_NO
           AND S.VALIDFLAG = '1'
           AND S.RECHECK = '1') XCJZ,
       (SELECT SUM(S.ACT_COUNT)
          FROM MIL_INSPECTION S
         WHERE S.JUDGE_STOVE_NO = M.JUDGE_STOVE_NO
           AND S.HEAT_PLAN_NO = M.HEAT_PLAN_NO
           AND S.VALIDFLAG = '1'
           AND S.RECHECK = '2') YCJZ,
           (SELECT DECODE(MIN(S.INSPECTION_FLAG),
                      '0',
                      '待抽',
                      '1',
                      '待检',
                      '2',
                      '已检',
                      '3',
                      '免检')
          FROM MIL_INSPECTION S
         WHERE S.JUDGE_STOVE_NO = M.JUDGE_STOVE_NO
           AND S.HEAT_PLAN_NO = M.HEAT_PLAN_NO
           AND S.VALIDFLAG = '1') INSPECTION_FLAG,
           
       MAX(M.MATERIAL_NO) MATERIAL_NO,
       MAX(M.MATERIAL_NAME) MATERIAL_NAME,
       MAX(M.PRODUCCODE) PRODUCCODE,
       MAX(M.PRODUCNAME) PRODUCNAME,
       MAX(M.STEELCODE) STEELCODE,
       MAX(M.STEELNAME) STEELNAME,
       MAX(M.GRADECODE) GRADECODE,
       MAX(M.GRADENAME) GRADENAME,
       MAX(M.SPEC_CODE) SPEC_CODE,
       MAX(M.SPEC_NAME) SPEC_NAME,
       MAX(M.MODEL_CODE) MODEL_CODE,
       MAX(M.MODEL_DESC) MODEL_DESC,
       MAX(M.STD_CODE) STD_CODE,
       MAX(M.STD_NAME) STD_NAME,
       MAX(M.STD_STYLE) STD_STYLE,
       MAX(M.STD_STYLE_DESC) STD_STYLE_DESC,
       MAX(M.PLINE_CODE) PLINE_CODE,
       MAX(M.PLINE_NAME) PLINE_NAME,
       MAX(M.ACT_DIMATER) ACT_DIMATER,
       MAX(M.ACT_HEIGHT) ACT_HEIGHT,
       MAX(M.ACT_LEN_MIN) ACT_LEN_MIN,
       MAX(M.ACT_LEN_MAX) ACT_LEN_MAX,
       SUM(M.ACT_COUNT) ACT_COUNT,
       ROUND(SUM(M.ACT_WEIGHT),3) ACT_WEIGHT,
       MAX(M.BELONG_CODE) BELONG_CODE,
       MAX(M.BELONG_NAME) BELONG_NAME,
       SUM(M.PONDER_GROSS_COUNT) PONDER_GROSS_COUNT,
       ROUND(SUM(M.PONDER_GROSS_WT), 3) PONDER_GROSS_WT,
       MAX(M.TARGET) TARGET,
       M.HEAT_PLAN_NO,
       M.HEAT_PLAN_NO_OLD,
       MAX(M.HEAT_PLAN_NO_NEXT) HEAT_PLAN_NO_NEXT,
       MAX(M.JUDGE_RESULT_CODE) JUDGE_RESULT_CODE,
       MAX(M.JUDGE_FLAG) JUDGE_FLAG,
       MAX(M.HTT_TYPE) HTT_TYPE,
       MAX(M.MIN_TEMP) MIN_TEMP,
       MAX(M.HTT_TECHNOLOGY) HTT_TECHNOLOGY,
       MAX(M.NOTCH_INFO) NOTCH_INFO,
       MAX(M.NOTCH_LENGTH) NOTCH_LENGTH,
       MAX(M.NOTCH_WIDTH) NOTCH_WIDTH,
       MAX(M.NOTCH_DEPTH) NOTCH_DEPTH,
       MAX(M.TEST_PRESSURE) TEST_PRESSURE,
       MAX(M.HOLDTIME_TIME) HOLDTIME_TIME,
       MAX(M.TEST_PRESSURE_Y) TEST_PRESSURE_Y,
       MAX(M.MCH_WATERGAGE_RESULT) MCH_WATERGAGE_RESULT,
       MAX(M.MCH_PATH_RESULT) MCH_PATH_RESULT,
       MAX(M.MCH_CHAMFERING_RESULT) MCH_CHAMFERING_RESULT,
       MAX(M.MCH_TWISTINGLY_RESULT) MCH_TWISTINGLY_RESULT,
       MAX(M.MCH_DIMENSIONS_RESULT) MCH_DIMENSIONS_RESULT,
       MAX(M.MCH_VISUAL_RESULT) MCH_VISUAL_RESULT,
       MAX(M.MCH_THREAD_INSPECTION_RESULT) MCH_THREAD_INSPECTION_RESULT,
       MAX(M.MCH_REMANENCE_RESULT) MCH_REMANENCE_RESULT,
       MAX(M.MCH_RADIOACTIVITY_RESULT) MCH_RADIOACTIVITY_RESULT,
       MAX(M.MCH_BEVEL_RESULT) MCH_BEVEL_RESULT,
       MAX(M.ANGLE_VAL) ANGLE_VAL,
       MAX(M.EDGE_VAL) EDGE_VAL,
       MAX(M.DRIFT_MODEL_MIN) DRIFT_MODEL_MIN,
       MAX(M.DRIFT_MODEL_MIN2) DRIFT_MODEL_MIN2,
       MAX(M.DRIFT_MODEL_LEN) DRIFT_MODEL_LEN,
       MAX(M.DRIFT_MODEL_LEN2) DRIFT_MODEL_LEN2,
       MAX(M.MEASURED_END_PART) MEASURED_END_PART,
       MAX(M.MEASURED_MIDDLE_PART) MEASURED_MIDDLE_PART,
       MAX(M.MEASURED_TAIL_PART) MEASURED_TAIL_PART,
       MAX(M.DETECT_RESULT_CODE) DETECT_RESULT_CODE,
       MAX(M.TESTING_STANDAR) TESTING_STANDAR,
       MAX(M.TESTING_GRADE) TESTING_GRADE,
       MAX(M.TESTING_TYPE) TESTING_TYPE
       FROM
(
SELECT T.LOT_NO,
       T.JUDGE_STOVE_NO,
       T.PROCESS_CDOE,
       T.NEXT_PROCESS_CDOE,
       T.JUGDE_APPLY_CODE,
       MAX(T.MATERIAL_NO) MATERIAL_NO,
       MAX(T.MATERIAL_NAME) MATERIAL_NAME,
       MAX(T.PRODUCCODE) PRODUCCODE,
       MAX(T.PRODUCNAME) PRODUCNAME,
       MAX(T.STEELCODE) STEELCODE,
       MAX(T.STEELNAME) STEELNAME,
       MAX(T.GRADECODE) GRADECODE,
       MAX(T.GRADENAME) GRADENAME,
       MAX(T.SPEC_CODE) SPEC_CODE,
       MAX(T.SPEC_NAME) SPEC_NAME,
       MAX(T.MODEL_CODE) MODEL_CODE,
       MAX(T.MODEL_DESC) MODEL_DESC,
       MAX(T.STD_CODE) STD_CODE,
       MAX(T.STD_NAME) STD_NAME,
       MAX(T.STD_STYLE) STD_STYLE,
       MAX(T.STD_STYLE_DESC) STD_STYLE_DESC,
       MAX(T.PLINE_CODE) PLINE_CODE,
       MAX(T.PLINE_NAME) PLINE_NAME,
       MAX(T.ACT_DIMATER) ACT_DIMATER,
       MAX(T.ACT_HEIGHT) ACT_HEIGHT,
       MAX(T.ACT_LEN_MIN) ACT_LEN_MIN,
       MAX(T.ACT_LEN_MAX) ACT_LEN_MAX,
       SUM(T.ACT_COUNT) ACT_COUNT,
       ROUND(SUM(T.ACT_WEIGHT),3) ACT_WEIGHT,
       MAX(T.BELONG_CODE) BELONG_CODE,
       MAX(T.BELONG_NAME) BELONG_NAME,
       SUM(CASE
             WHEN T.PONDER_GROSS_WT > 0 THEN
              1
             ELSE
              0
           END) PONDER_GROSS_COUNT,
       ROUND(SUM(T.PONDER_GROSS_WT), 3) PONDER_GROSS_WT,
       MAX(T.TARGET) TARGET,
       T.HEAT_PLAN_NO,
       T.HEAT_PLAN_NO_OLD,
       MAX(T.HEAT_PLAN_NO_NEXT) HEAT_PLAN_NO_NEXT,
       MAX(T2.JUDGE_RESULT_CODE) JUDGE_RESULT_CODE,
       DECODE(MAX(T1.JUDGE_RESULT_CODE),
              NULL,
              '未判',
              DECODE(MAX(T2.JUDGE_RESULT_CODE), '1', '部分已判', '已判')) JUDGE_FLAG,
       MAX(T1.HTT_TYPE) HTT_TYPE,
       MAX(T1.MIN_TEMP) MIN_TEMP,
       MAX(T1.HTT_TECHNOLOGY) HTT_TECHNOLOGY,
       MAX(T1.NOTCH_INFO) NOTCH_INFO,
       MAX(T1.NOTCH_LENGTH) NOTCH_LENGTH,
       MAX(T1.NOTCH_WIDTH) NOTCH_WIDTH,
       MAX(T1.NOTCH_DEPTH) NOTCH_DEPTH,
       MAX(T1.TEST_PRESSURE) TEST_PRESSURE,
       MAX(T1.HOLDTIME_TIME) HOLDTIME_TIME,
       MAX(T1.TEST_PRESSURE_Y) TEST_PRESSURE_Y,
       MAX(T1.MCH_WATERGAGE_RESULT) MCH_WATERGAGE_RESULT,
       MAX(T1.MCH_PATH_RESULT) MCH_PATH_RESULT,
       MAX(T1.MCH_CHAMFERING_RESULT) MCH_CHAMFERING_RESULT,
       MAX(T1.MCH_TWISTINGLY_RESULT) MCH_TWISTINGLY_RESULT,
       MAX(T1.MCH_DIMENSIONS_RESULT) MCH_DIMENSIONS_RESULT,
       MAX(T1.MCH_VISUAL_RESULT) MCH_VISUAL_RESULT,
       MAX(T1.MCH_THREAD_INSPECTION_RESULT) MCH_THREAD_INSPECTION_RESULT,
       MAX(T1.MCH_REMANENCE_RESULT) MCH_REMANENCE_RESULT,
       MAX(T1.MCH_RADIOACTIVITY_RESULT) MCH_RADIOACTIVITY_RESULT,
       MAX(T1.MCH_BEVEL_RESULT) MCH_BEVEL_RESULT,
       MAX(T1.ANGLE_VAL) ANGLE_VAL,
       MAX(T1.EDGE_VAL) EDGE_VAL,
       MAX(T1.DRIFT_MODEL_MIN) DRIFT_MODEL_MIN,
       MAX(T1.DRIFT_MODEL_MIN2) DRIFT_MODEL_MIN2,
       MAX(T1.DRIFT_MODEL_LEN) DRIFT_MODEL_LEN,
       MAX(T1.DRIFT_MODEL_LEN2) DRIFT_MODEL_LEN2,
       MAX(T1.MEASURED_END_PART) MEASURED_END_PART,
       MAX(T1.MEASURED_MIDDLE_PART) MEASURED_MIDDLE_PART,
       MAX(T1.MEASURED_TAIL_PART) MEASURED_TAIL_PART,
       MAX(T1.DETECT_RESULT_CODE) DETECT_RESULT_CODE,
       MAX(T1.TESTING_STANDAR) TESTING_STANDAR,
       MAX(T1.TESTING_GRADE) TESTING_GRADE,
       MAX(T1.TESTING_TYPE) TESTING_TYPE
  FROM MAT_BC_M T
  LEFT JOIN (SELECT MAX(JUDGE_RESULT_CODE) JUDGE_RESULT_CODE,
                    MAX(T1.HTT_TYPE) HTT_TYPE,
                    MAX(T1.MIN_TEMP) MIN_TEMP,
                    MAX(T1.HTT_TECHNOLOGY) HTT_TECHNOLOGY,
                    MAX(T1.NOTCH_INFO) NOTCH_INFO,
                    MAX(T1.NOTCH_LENGTH) NOTCH_LENGTH,
                    MAX(T1.NOTCH_WIDTH) NOTCH_WIDTH,
                    MAX(T1.NOTCH_DEPTH) NOTCH_DEPTH,
                    MAX(T1.TEST_PRESSURE) TEST_PRESSURE,
                    MAX(T1.HOLDTIME_TIME) HOLDTIME_TIME,
                    MAX(T1.TEST_PRESSURE_Y) TEST_PRESSURE_Y,
                    MAX(T1.MCH_WATERGAGE_RESULT) MCH_WATERGAGE_RESULT,
                    MAX(T1.MCH_PATH_RESULT) MCH_PATH_RESULT,
                    MAX(T1.MCH_CHAMFERING_RESULT) MCH_CHAMFERING_RESULT,
                    MAX(T1.MCH_TWISTINGLY_RESULT) MCH_TWISTINGLY_RESULT,
                    MAX(T1.MCH_DIMENSIONS_RESULT) MCH_DIMENSIONS_RESULT,
                    MAX(T1.MCH_VISUAL_RESULT) MCH_VISUAL_RESULT,
                    MAX(T1.MCH_THREAD_INSPECTION_RESULT) MCH_THREAD_INSPECTION_RESULT,
                    MAX(T1.MCH_REMANENCE_RESULT) MCH_REMANENCE_RESULT,
                    MAX(T1.MCH_RADIOACTIVITY_RESULT) MCH_RADIOACTIVITY_RESULT,
                    MAX(T1.MCH_BEVEL_RESULT) MCH_BEVEL_RESULT,
                    MAX(T1.ANGLE_VAL) ANGLE_VAL,
                    MAX(T1.EDGE_VAL) EDGE_VAL,
                    MAX(T1.DRIFT_MODEL_MIN) DRIFT_MODEL_MIN,
                    MAX(T1.DRIFT_MODEL_MIN2) DRIFT_MODEL_MIN2,
                    MAX(T1.DRIFT_MODEL_LEN) DRIFT_MODEL_LEN,
                    MAX(T1.DRIFT_MODEL_LEN2) DRIFT_MODEL_LEN2,
                    MAX(T1.MEASURED_END_PART) MEASURED_END_PART,
                    MAX(T1.MEASURED_MIDDLE_PART) MEASURED_MIDDLE_PART,
                    MAX(T1.MEASURED_TAIL_PART) MEASURED_TAIL_PART,
                    MAX(T1.TESTING_GRADE) TESTING_GRADE,
                    MAX(T1.TESTING_TYPE) TESTING_TYPE,
                    MAX(T1.TESTING_STANDAR) TESTING_STANDAR,
                    MAX(DECODE(T1.DETECT_RESULT_CODE,
                               '40740401',
                               '合格',
                               '40740402',
                               '不合格')) DETECT_RESULT_CODE,
                    JUGDE_APPLY_CODE
               FROM QCM_ZG_JUGDE_APPLY T1
              GROUP BY JUGDE_APPLY_CODE) t1
    ON T.JUGDE_APPLY_CODE = T1.JUGDE_APPLY_CODE
  LEFT JOIN (SELECT MIN(nvl(JUDGE_RESULT_CODE, '1')) JUDGE_RESULT_CODE,
                    JUGDE_APPLY_CODE
               FROM QCM_ZG_JUGDE_APPLY T1
              GROUP BY JUGDE_APPLY_CODE) t2
    ON T.JUGDE_APPLY_CODE = T2.JUGDE_APPLY_CODE
 WHERE 1 = 1
   AND T.QCM_STAUS = '00'
   AND T.PROCESS_CDOE <> 'D'
   AND (NVL(T.HEAT_PLAN_NO_NEXT, '/') <> T.HEAT_PLAN_NO)
#INSTOCK_TIME#
 #JUDGE_STOVE_NO# 
 #JUGDE_APPLY_CODE#
 #JUDGE_RESULT_CODE# 
 #PROCESS_CDOE#
 #BELONG_CODE# 
 #GROUP_BY#
UNION ALL
SELECT T.LOT_NO,
       T.JUDGE_STOVE_NO,
       T.PROCESS_CDOE,
       T.NEXT_PROCESS_CDOE,
       T.JUGDE_APPLY_CODE,
       MAX(T.MATERIAL_NO) MATERIAL_NO,
       MAX(T.MATERIAL_NAME) MATERIAL_NAME,
       MAX(T.PRODUCCODE) PRODUCCODE,
       MAX(T.PRODUCNAME) PRODUCNAME,
       MAX(T.STEELCODE) STEELCODE,
       MAX(T.STEELNAME) STEELNAME,
       MAX(T.GRADECODE) GRADECODE,
       MAX(T.GRADENAME) GRADENAME,
       MAX(T.SPEC_CODE) SPEC_CODE,
       MAX(T.SPEC_NAME) SPEC_NAME,
       MAX(T.MODEL_CODE) MODEL_CODE,
       MAX(T.MODEL_DESC) MODEL_DESC,
       MAX(T.STD_CODE) STD_CODE,
       MAX(T.STD_NAME) STD_NAME,
       MAX(T.STD_STYLE) STD_STYLE,
       MAX(T.STD_STYLE_DESC) STD_STYLE_DESC,
       MAX(T.PLINE_CODE) PLINE_CODE,
       MAX(T.PLINE_NAME) PLINE_NAME,
       MAX(T.ACT_DIMATER) ACT_DIMATER,
       MAX(T.ACT_HEIGHT) ACT_HEIGHT,
       MAX(T.ACT_LEN_MIN) ACT_LEN_MIN,
       MAX(T.ACT_LEN_MAX) ACT_LEN_MAX,
       SUM(T.ACT_COUNT) ACT_COUNT,
       ROUND(SUM(T.ACT_WEIGHT), 3) ACT_WEIGHT,
       MAX(T.BELONG_CODE) BELONG_CODE,
       MAX(T.BELONG_NAME) BELONG_NAME,
       SUM(CASE
             WHEN T.PONDER_GROSS_WT > 0 THEN
              1
             ELSE
              0
           END) PONDER_GROSS_COUNT,
       ROUND(SUM(T.PONDER_GROSS_WT),3) PONDER_GROSS_WT,
       MAX(T.TARGET) TARGET,
       T.HEAT_PLAN_NO,
       T.HEAT_PLAN_NO_OLD,
       MAX(T.HEAT_PLAN_NO_NEXT) HEAT_PLAN_NO_NEXT,
       MAX(T2.JUDGE_RESULT_CODE) JUDGE_RESULT_CODE,
       DECODE(MAX(T1.JUDGE_RESULT_CODE),
              NULL,
              '未判',
              DECODE(MAX(T2.JUDGE_RESULT_CODE), '1', '部分已判', '已判')) JUDGE_FLAG,
       MAX(T1.HTT_TYPE) HTT_TYPE,
       MAX(T1.MIN_TEMP) MIN_TEMP,
       MAX(T1.HTT_TECHNOLOGY) HTT_TECHNOLOGY,
       MAX(T1.NOTCH_INFO) NOTCH_INFO,
       MAX(T1.NOTCH_LENGTH) NOTCH_LENGTH,
       MAX(T1.NOTCH_WIDTH) NOTCH_WIDTH,
       MAX(T1.NOTCH_DEPTH) NOTCH_DEPTH,
       MAX(T1.TEST_PRESSURE) TEST_PRESSURE,
       MAX(T1.HOLDTIME_TIME) HOLDTIME_TIME,
       MAX(T1.TEST_PRESSURE_Y) TEST_PRESSURE_Y,
       MAX(T1.MCH_WATERGAGE_RESULT) MCH_WATERGAGE_RESULT,
       MAX(T1.MCH_PATH_RESULT) MCH_PATH_RESULT,
       MAX(T1.MCH_CHAMFERING_RESULT) MCH_CHAMFERING_RESULT,
       MAX(T1.MCH_TWISTINGLY_RESULT) MCH_TWISTINGLY_RESULT,
       MAX(T1.MCH_DIMENSIONS_RESULT) MCH_DIMENSIONS_RESULT,
       MAX(T1.MCH_VISUAL_RESULT) MCH_VISUAL_RESULT,
       MAX(T1.MCH_THREAD_INSPECTION_RESULT) MCH_THREAD_INSPECTION_RESULT,
       MAX(T1.MCH_REMANENCE_RESULT) MCH_REMANENCE_RESULT,
       MAX(T1.MCH_RADIOACTIVITY_RESULT) MCH_RADIOACTIVITY_RESULT,
       MAX(T1.MCH_BEVEL_RESULT) MCH_BEVEL_RESULT,
       MAX(T1.ANGLE_VAL) ANGLE_VAL,
       MAX(T1.EDGE_VAL) EDGE_VAL,
       MAX(T1.DRIFT_MODEL_MIN) DRIFT_MODEL_MIN,
       MAX(T1.DRIFT_MODEL_MIN2) DRIFT_MODEL_MIN2,
       MAX(T1.DRIFT_MODEL_LEN) DRIFT_MODEL_LEN,
       MAX(T1.DRIFT_MODEL_LEN2) DRIFT_MODEL_LEN2,
       MAX(T1.MEASURED_END_PART) MEASURED_END_PART,
       MAX(T1.MEASURED_MIDDLE_PART) MEASURED_MIDDLE_PART,
       MAX(T1.MEASURED_TAIL_PART) MEASURED_TAIL_PART,
       MAX(T1.DETECT_RESULT_CODE) DETECT_RESULT_CODE,
       MAX(T1.TESTING_STANDAR) TESTING_STANDAR,
       MAX(T1.TESTING_GRADE) TESTING_GRADE,
       MAX(T1.TESTING_TYPE) TESTING_TYPE
  FROM MAT_BC_BACKUP T
  LEFT JOIN (SELECT MAX(JUDGE_RESULT_CODE) JUDGE_RESULT_CODE,
                    MAX(T1.HTT_TYPE) HTT_TYPE,
                    MAX(T1.MIN_TEMP) MIN_TEMP,
                    MAX(T1.HTT_TECHNOLOGY) HTT_TECHNOLOGY,
                    MAX(T1.NOTCH_INFO) NOTCH_INFO,
                    MAX(T1.NOTCH_LENGTH) NOTCH_LENGTH,
                    MAX(T1.NOTCH_WIDTH) NOTCH_WIDTH,
                    MAX(T1.NOTCH_DEPTH) NOTCH_DEPTH,
                    MAX(T1.TEST_PRESSURE) TEST_PRESSURE,
                    MAX(T1.HOLDTIME_TIME) HOLDTIME_TIME,
                    MAX(T1.TEST_PRESSURE_Y) TEST_PRESSURE_Y,
                    MAX(T1.MCH_WATERGAGE_RESULT) MCH_WATERGAGE_RESULT,
                    MAX(T1.MCH_PATH_RESULT) MCH_PATH_RESULT,
                    MAX(T1.MCH_CHAMFERING_RESULT) MCH_CHAMFERING_RESULT,
                    MAX(T1.MCH_TWISTINGLY_RESULT) MCH_TWISTINGLY_RESULT,
                    MAX(T1.MCH_DIMENSIONS_RESULT) MCH_DIMENSIONS_RESULT,
                    MAX(T1.MCH_VISUAL_RESULT) MCH_VISUAL_RESULT,
                    MAX(T1.MCH_THREAD_INSPECTION_RESULT) MCH_THREAD_INSPECTION_RESULT,
                    MAX(T1.MCH_REMANENCE_RESULT) MCH_REMANENCE_RESULT,
                    MAX(T1.MCH_RADIOACTIVITY_RESULT) MCH_RADIOACTIVITY_RESULT,
                    MAX(T1.MCH_BEVEL_RESULT) MCH_BEVEL_RESULT,
                    MAX(T1.ANGLE_VAL) ANGLE_VAL,
                    MAX(T1.EDGE_VAL) EDGE_VAL,
                    MAX(T1.DRIFT_MODEL_MIN) DRIFT_MODEL_MIN,
                    MAX(T1.DRIFT_MODEL_MIN2) DRIFT_MODEL_MIN2,
                    MAX(T1.DRIFT_MODEL_LEN) DRIFT_MODEL_LEN,
                    MAX(T1.DRIFT_MODEL_LEN2) DRIFT_MODEL_LEN2,
                    MAX(T1.MEASURED_END_PART) MEASURED_END_PART,
                    MAX(T1.MEASURED_MIDDLE_PART) MEASURED_MIDDLE_PART,
                    MAX(T1.MEASURED_TAIL_PART) MEASURED_TAIL_PART,
                    MAX(T1.TESTING_GRADE) TESTING_GRADE,
                    MAX(T1.TESTING_TYPE) TESTING_TYPE,
                    MAX(T1.TESTING_STANDAR) TESTING_STANDAR,
                    MAX(DECODE(T1.DETECT_RESULT_CODE,
                               '40740401',
                               '合格',
                               '40740402',
                               '不合格')) DETECT_RESULT_CODE,
                    JUGDE_APPLY_CODE
               FROM QCM_ZG_JUGDE_APPLY T1
              GROUP BY JUGDE_APPLY_CODE) t1
    ON T.JUGDE_APPLY_CODE = T1.JUGDE_APPLY_CODE
  LEFT JOIN (SELECT MIN(nvl(JUDGE_RESULT_CODE, '1')) JUDGE_RESULT_CODE,
                    JUGDE_APPLY_CODE
               FROM QCM_ZG_JUGDE_APPLY T1
              GROUP BY JUGDE_APPLY_CODE) t2
    ON T.JUGDE_APPLY_CODE = T2.JUGDE_APPLY_CODE
 WHERE 1 = 1
   AND T.JUGDE_APPLY_CODE IS NOT NULL
   AND T.QCM_STAUS = '00'
   AND T.PROCESS_CDOE <> 'D'
   AND (NVL(T.HEAT_PLAN_NO_NEXT, '/') <> T.HEAT_PLAN_NO)
#INSTOCK_TIME#
 #JUDGE_STOVE_NO# 
 #JUGDE_APPLY_CODE#
 #JUDGE_RESULT_CODE# 
 #PROCESS_CDOE#
 #BELONG_CODE# 
 #GROUP_BY#) M
  GROUP BY M.HEAT_PLAN_NO_OLD,M.HEAT_PLAN_NO,M.LOT_NO,M.JUDGE_STOVE_NO,M.PROCESS_CDOE,M.NEXT_PROCESS_CDOE,M.PLINE_CODE,M.JUGDE_APPLY_CODE
 ]]>
</query>
<query id = "FrmVrpApplyNew.doQueryJudgeBath" desc = "查询详细炉批信息">
<![CDATA[
 SELECT 
       T.JUGDE_APPLY_CODE,
       T.LOT_NO,
       T.STOVE_NO,
       T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       T.BATCH_GROUD_NO,
       MAX(T.CODE_JG_BL) CODE_JG_BL,
       MAX(T.LIKU_PROCESS_CODE) LIKU_PROCESS_CODE,
       MAX(T.CIC) CIC,
    MAX(T.ACT_LEN_MIN) || '-' ||    MAX(T.ACT_LEN_MAX)  GROUP_LENGTH,
       SUM(T.ACT_THEORY_WEIGHT) ACT_THEORY_WEIGHT,
       MAX(T.JUDGE_RESULT_TIME) JUDGE_RESULT_TIME,
       MAX(T.MATERIAL_NO)MATERIAL_NO,
       MAX(T.MATERIAL_NAME)MATERIAL_NAME,
       MAX(T.PRODUCCODE)PRODUCCODE,
       MAX(T.PRODUCNAME)PRODUCNAME,
       MAX(T.STEELCODE)STEELCODE,
       MAX(T.STEELNAME)STEELNAME,
       MAX(T.GRADECODE)GRADECODE,
       MAX(T.GRADENAME)GRADENAME,
       MAX(T.SPEC_CODE)SPEC_CODE,
       MAX(T.SPEC_NAME)SPEC_NAME,
       MAX(T.MODEL_CODE)MODEL_CODE,
       MAX(T.MODEL_DESC)MODEL_DESC,
       MAX(T.STD_CODE)STD_CODE,
       MAX(T.STD_NAME)STD_NAME,
       MAX(T.STD_STYLE)STD_STYLE,
       MAX(T.STD_STYLE_DESC)STD_STYLE_DESC,
       MAX(T.PRO_ORDER_NO)PRO_ORDER_NO,
       MAX(T.PRO_ORDER_ID)PRO_ORDER_ID,
       MAX(T.order_seq_no) order_seq_no,
       MAX(T.ORD_LN_PK)ORD_LN_PK,
       MAX(T.GX_PLAN_NO)GX_PLAN_NO,
       MAX(T.CRAF_NO)CRAF_NO,
       MAX(T.PROCESS_CDOE)PROCESS_CDOE,
       MAX(T.PROCESS_DESC)PROCESS_DESC,
       MAX(T.NEXT_PROCESS_CDOE)NEXT_PROCESS_CDOE,
       MAX(T.NEXT_PROCESS_DESC)NEXT_PROCESS_DESC,
       MAX(T.LIKU_PROCESS_CODE) LIKU_PROCESS_CODE,
       MAX(T.PLINE_CODE)PLINE_CODE,
       MAX(T.PLINE_NAME)PLINE_NAME,
       MAX(T.ACT_DIMATER)ACT_DIMATER,
       MAX(T.ACT_HEIGHT)ACT_HEIGHT,
       SUM(T.ACT_LEN)ACT_LEN,
       MAX(T.ACT_LEN_MIN)ACT_LEN_MIN,
       MAX(T.ACT_LEN_MAX)ACT_LEN_MAX,
       SUM(T.ACT_COUNT)ACT_COUNT,
       ROUND(SUM(T.ACT_WEIGHT), 3) ACT_WEIGHT,
       ROUND(SUM(T.PONDER_GROSS_WT),3) PONDER_GROSS_WT,
       MAX(T.BELONG_CODE)BELONG_CODE,
       MAX(T.BELONG_NAME)BELONG_NAME,
       MAX(T.JUGDE_APPLY_CODE)JUGDE_APPLY_CODE,
       MAX(DECODE(T.LOCK_LIKU,'0','正常','1','利库','2','精整利库'))LOCK_LIKU,
       MAX(T.PRODUCT_FLAG)PRODUCT_FLAG,
       MAX(T.ORD_LN_DLY_PK)ORD_LN_DLY_PK,
       MAX(T.TARGET)TARGET,
       --T.HEAT_PLAN_NO,
       T.HEAT_PLAN_NO,
       T.HEAT_PLAN_NO_OLD,
       MAX(T.GX_PLAN_NO)GX_PLAN_NO,
       MAX(T.CRAFT_SEQ)CRAFT_SEQ,
       T.PRO_PLAN_ID_NEXT,
       T.GX_PLAN_NO_NEXT,
       T.JUGDE_APPLY_SEQUENO,
       T.HEAT_PLAN_NO_NEXT,
      t.LENGTH_TYPE,
       MAX(T1.ORDER_UNIT) ORDER_UNIT,
       MAX(T1.ORDERWEIGHT) ORDERWEIGHT,
       MAX(T1.PAYDOWN_WT_MAX) PAYDOWN_WT_MAX,
       MAX(T1.ORDER_WT_MAX_SHORT) ORDER_WT_MAX_SHORT,
       MAX(T1.ORDER_WT_MAX_LONG) ORDER_WT_MAX_LONG,
       MAX(T1.ACT_LEN) ACT_LEN1,
       MAX(T1.ACT_WEIGHT) ACT_WEIGHT1,
       MAX(T1.ACT_WEIGHT_L) ACT_WEIGHT_L,
       MAX(T1.ACT_WEIGHT_S) ACT_WEIGHT_S,
       MAX(T1.ACT_LEN2) ACT_LEN2,
       MAX(T1.ACT_WEIGHT2) ACT_WEIGHT2,
       CASE WHEN MAX(T1.RECEIV_NM) IN('天津腾飞钢管有限公司','沈阳腾飞钢铁经销有限公司','天津宝仓物流有限公司','天津市安利金属制造有限公司') OR MAX(T1.SUPPLY_UNIT)> 120501
         THEN '801703'
         WHEN MAX(T1.CUSTOMER_NM) IN('天津腾飞钢管有限公司','沈阳腾飞钢铁经销有限公司','天津宝仓物流有限公司','天津市安利金属制造有限公司')  
         THEN '801703'
         WHEN MAX(T1.STLMT_UNIT_NM) IN('天津腾飞钢管有限公司','沈阳腾飞钢铁经销有限公司','天津宝仓物流有限公司','天津市安利金属制造有限公司')  
         THEN '801703'
         WHEN (select MAX(t5.PORDERSTATUS) from pln_saleord t5 where t5.ord_ln_dly_pk =T.ord_ln_dly_pk)>=5 
             THEN '801701'
         WHEN MAX(NVL(T1.SHORTEST,0))>0 AND (CASE WHEN MAX(T1.ORDER_UNIT) ='英尺' THEN 3.2808 *MAX(T.ACT_LEN_MIN) ELSE  1*MAX(T.ACT_LEN_MIN) END) < MAX(NVL(T1.SHORTEST,0))
             THEN '801701'
               WHEN MAX(NVL(T1.LONGEST,0))>0 AND (CASE WHEN MAX(T1.ORDER_UNIT) ='英尺' THEN 3.2808 *MAX(T.ACT_LEN_MAX) ELSE  1*MAX(T.ACT_LEN_MAX) END)  > MAX(NVL(T1.LONGEST,0))
             THEN '801701'
           ELSE
             CASE WHEN MAX(T1.ORDER_UNIT) = '吨' THEN
       CASE
         --缴库量上限 < 累计送判吨（按计划入）+ 单支重量
           WHEN  MAX(T1.PAYDOWN_WT_MAX) < MAX(T1.ACT_WEIGHT2) + ROUND(ROUND(SUM(T.ACT_WEIGHT), 3)/SUM(T.ACT_COUNT),3）
             THEN '801701'
               WHEN T.LENGTH_TYPE = '1'  AND  MAX(T1.ORDER_WT_MAX_LONG) <  MAX(T1.ACT_WEIGHT_L) + ROUND(ROUND(SUM(T.ACT_WEIGHT), 3)/SUM(T.ACT_COUNT),3）
             THEN '801701'
               WHEN T.LENGTH_TYPE = '2'  AND  MAX(T1.ORDER_WT_MAX_SHORT) <  MAX(T1.ACT_WEIGHT_S) + ROUND(ROUND(SUM(T.ACT_WEIGHT), 3)/SUM(T.ACT_COUNT),3）
             THEN '801701'
               ELSE
                 '801703'
               END
               
                WHEN MAX(T1.ORDER_UNIT) IN( '米' ,'英尺') THEN
                 CASE
         --缴库量上限 < 累计送判吨（按计划入）+ 单支重量
           WHEN  MAX(T1.PAYDOWN_WT_MAX) < MAX(T1.ACT_LEN2) + ROUND(ROUND(SUM(T.ACT_LEN), 3)/SUM(T.ACT_COUNT),3）
             THEN '801701'
               WHEN T.LENGTH_TYPE = '1'  AND  MAX(T1.ORDER_WT_MAX_LONG) <  MAX(T1.ACT_LEN_L) + ROUND(ROUND(SUM(T.ACT_LEN), 3)/SUM(T.ACT_COUNT),3）
             THEN '801701'
               WHEN T.LENGTH_TYPE = '2'  AND  MAX(T1.ORDER_WT_MAX_SHORT) <  MAX(T1.ACT_LEN_S) + ROUND(ROUND(SUM(T.ACT_LEN), 3)/SUM(T.ACT_COUNT),3）
             THEN '801701'
               ELSE
                 '801703'
               END
              END
             END IN_MOLD,
             
            NVL( CASE WHEN MAX(T1.RECEIV_NM) IN('天津腾飞钢管有限公司','沈阳腾飞钢铁经销有限公司','天津宝仓物流有限公司','天津市安利金属制造有限公司') OR MAX(T1.SUPPLY_UNIT)> 120501
         THEN SUM(T.ACT_COUNT)
         WHEN MAX(T1.CUSTOMER_NM) IN('天津腾飞钢管有限公司','沈阳腾飞钢铁经销有限公司','天津宝仓物流有限公司','天津市安利金属制造有限公司') 
         THEN SUM(T.ACT_COUNT)
         WHEN MAX(T1.STLMT_UNIT_NM) IN('天津腾飞钢管有限公司','沈阳腾飞钢铁经销有限公司','天津宝仓物流有限公司','天津市安利金属制造有限公司') 
         THEN SUM(T.ACT_COUNT)
           ELSE
             CASE WHEN MAX(T1.ORDER_UNIT) = '吨' THEN
               CASE WHEN T.LENGTH_TYPE = '0' AND MAX(T1.PAYDOWN_WT_MAX) -  MAX(T1.ACT_WEIGHT2) > 0 THEN
                 FLOOR((MAX(T1.PAYDOWN_WT_MAX) -  MAX(T1.ACT_WEIGHT2))/(ROUND(SUM(T.ACT_WEIGHT), 3)/SUM(T.ACT_COUNT)))
                 WHEN T.LENGTH_TYPE = '1' AND MAX(T1.ORDER_WT_MAX_LONG) -  MAX(T1.ACT_WEIGHT_L)  > 0 THEN
                  FLOOR(LEAST((MAX(T1.ORDER_WT_MAX_LONG) -  MAX(T1.ACT_WEIGHT_L)),(MAX(T1.PAYDOWN_WT_MAX) -  MAX(T1.ACT_WEIGHT2)))/(ROUND(SUM(T.ACT_WEIGHT), 3)/SUM(T.ACT_COUNT)))
                 WHEN T.LENGTH_TYPE = '2' AND MAX(T1.ORDER_WT_MAX_SHORT) -  MAX(T1.ACT_WEIGHT_S)  > 0 THEN
                  FLOOR(LEAST((MAX(T1.ORDER_WT_MAX_SHORT) -  MAX(T1.ACT_WEIGHT_S)),(MAX(T1.PAYDOWN_WT_MAX) -  MAX(T1.ACT_WEIGHT2)))/(ROUND(SUM(T.ACT_WEIGHT), 3)/SUM(T.ACT_COUNT)))
                   END
               WHEN MAX(T1.ORDER_UNIT) IN( '米' ,'英尺') THEN
                 CASE WHEN T.LENGTH_TYPE = '0' AND MAX(T1.PAYDOWN_WT_MAX) -  MAX(T1.ACT_LEN2) > 0 THEN
                 FLOOR((MAX(T1.PAYDOWN_WT_MAX) -  MAX(T1.ACT_LEN2))/(ROUND(SUM(T.ACT_LEN), 3)/SUM(T.ACT_COUNT)))
                 WHEN T.LENGTH_TYPE = '1' AND MAX(T1.ORDER_WT_MAX_LONG) -  MAX(T1.ACT_LEN_L)  > 0 THEN
                  FLOOR(LEAST((MAX(T1.ORDER_WT_MAX_LONG) -  MAX(T1.ACT_LEN_L)),(MAX(T1.PAYDOWN_WT_MAX) -  MAX(T1.ACT_LEN2)))/(ROUND(SUM(T.ACT_LEN), 3)/SUM(T.ACT_COUNT)))
                 WHEN T.LENGTH_TYPE = '2' AND MAX(T1.ORDER_WT_MAX_SHORT) -  MAX(T1.ACT_WEIGHT_S)  > 0 THEN
                  FLOOR(LEAST((MAX(T1.ORDER_WT_MAX_SHORT) -  MAX(T1.ACT_LEN_S)),(MAX(T1.PAYDOWN_WT_MAX) -  MAX(T1.ACT_LEN2)))/(ROUND(SUM(T.ACT_LEN), 3)/SUM(T.ACT_COUNT)))
                   END
                   END
                 END,0) KSPZ
 FROM MAT_BC_M T
 LEFT JOIN QCM_ZC_APPLY T1
    ON T.ORD_LN_DLY_PK = T1.ORD_LN_DLY_PK
 WHERE  T.HEAT_PLAN_NO = ?
 AND T.JUDGE_STOVE_NO = ?
 AND T.QCM_STAUS = '00'
 #JUGDE_APPLY_CODE#
 #JUGDE_APPLY_CODE2#
 #GROUP_BY#
 union
 SELECT 
       T.JUGDE_APPLY_CODE,
       T.LOT_NO,
       T.STOVE_NO,
       T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       T.BATCH_GROUD_NO,
       MAX(T.CODE_JG_BL) CODE_JG_BL,
       MAX(T.LIKU_PROCESS_CODE) LIKU_PROCESS_CODE,
       MAX(T.CIC) CIC,
    MAX(T.ACT_LEN_MIN) || '-' ||    MAX(T.ACT_LEN_MAX)  GROUP_LENGTH,
       SUM(T.ACT_THEORY_WEIGHT) ACT_THEORY_WEIGHT,
       MAX(T.JUDGE_RESULT_TIME) JUDGE_RESULT_TIME,
       MAX(T.MATERIAL_NO)MATERIAL_NO,
       MAX(T.MATERIAL_NAME)MATERIAL_NAME,
       MAX(T.PRODUCCODE)PRODUCCODE,
       MAX(T.PRODUCNAME)PRODUCNAME,
       MAX(T.STEELCODE)STEELCODE,
       MAX(T.STEELNAME)STEELNAME,
       MAX(T.GRADECODE)GRADECODE,
       MAX(T.GRADENAME)GRADENAME,
       MAX(T.SPEC_CODE)SPEC_CODE,
       MAX(T.SPEC_NAME)SPEC_NAME,
       MAX(T.MODEL_CODE)MODEL_CODE,
       MAX(T.MODEL_DESC)MODEL_DESC,
       MAX(T.STD_CODE)STD_CODE,
       MAX(T.STD_NAME)STD_NAME,
       MAX(T.STD_STYLE)STD_STYLE,
       MAX(T.STD_STYLE_DESC)STD_STYLE_DESC,
       MAX(T.PRO_ORDER_NO)PRO_ORDER_NO,
       MAX(T.PRO_ORDER_ID)PRO_ORDER_ID,
       MAX(T.order_seq_no) order_seq_no,
       MAX(T.ORD_LN_PK)ORD_LN_PK,
       MAX(T.GX_PLAN_NO)GX_PLAN_NO,
       MAX(T.CRAF_NO)CRAF_NO,
       MAX(T.PROCESS_CDOE)PROCESS_CDOE,
       MAX(T.PROCESS_DESC)PROCESS_DESC,
       MAX(T.NEXT_PROCESS_CDOE)NEXT_PROCESS_CDOE,
       MAX(T.NEXT_PROCESS_DESC)NEXT_PROCESS_DESC,
       MAX(T.LIKU_PROCESS_CODE) LIKU_PROCESS_CODE,
       MAX(T.PLINE_CODE)PLINE_CODE,
       MAX(T.PLINE_NAME)PLINE_NAME,
       MAX(T.ACT_DIMATER)ACT_DIMATER,
       MAX(T.ACT_HEIGHT)ACT_HEIGHT,
       SUM(T.ACT_LEN)ACT_LEN,
       MAX(T.ACT_LEN_MIN)ACT_LEN_MIN,
       MAX(T.ACT_LEN_MAX)ACT_LEN_MAX,
       SUM(T.ACT_COUNT)ACT_COUNT,
       ROUND(SUM(T.ACT_WEIGHT), 3) ACT_WEIGHT,
       ROUND(SUM(T.PONDER_GROSS_WT),3) PONDER_GROSS_WT,
       MAX(T.BELONG_CODE)BELONG_CODE,
       MAX(T.BELONG_NAME)BELONG_NAME,
       MAX(T.JUGDE_APPLY_CODE)JUGDE_APPLY_CODE,
       MAX(DECODE(T.LOCK_LIKU,'0','正常','1','利库','2','精整利库'))LOCK_LIKU,
       MAX(T.PRODUCT_FLAG)PRODUCT_FLAG,
       MAX(T.ORD_LN_DLY_PK)ORD_LN_DLY_PK,
       MAX(T.TARGET)TARGET,
       --T.HEAT_PLAN_NO,
       T.HEAT_PLAN_NO,
       T.HEAT_PLAN_NO_OLD,
       MAX(T.GX_PLAN_NO)GX_PLAN_NO,
       MAX(T.CRAFT_SEQ)CRAFT_SEQ,
       T.PRO_PLAN_ID_NEXT,
       T.GX_PLAN_NO_NEXT,
       T.JUGDE_APPLY_SEQUENO,
       T.HEAT_PLAN_NO_NEXT,
     t.LENGTH_TYPE,
       MAX(T1.ORDER_UNIT) ORDER_UNIT,
       MAX(T1.ORDERWEIGHT) ORDERWEIGHT,
       MAX(T1.PAYDOWN_WT_MAX) PAYDOWN_WT_MAX,
       MAX(T1.ORDER_WT_MAX_SHORT) ORDER_WT_MAX_SHORT,
       MAX(T1.ORDER_WT_MAX_LONG) ORDER_WT_MAX_LONG,
       MAX(T1.ACT_LEN) ACT_LEN1,
       MAX(T1.ACT_WEIGHT) ACT_WEIGHT1,
       MAX(T1.ACT_WEIGHT_L) ACT_WEIGHT_L,
       MAX(T1.ACT_WEIGHT_S) ACT_WEIGHT_S,
       MAX(T1.ACT_LEN2) ACT_LEN2,
       MAX(T1.ACT_WEIGHT2) ACT_WEIGHT2,
       CASE WHEN MAX(T1.RECEIV_NM) IN('天津腾飞钢管有限公司','沈阳腾飞钢铁经销有限公司','天津宝仓物流有限公司','天津市安利金属制造有限公司') OR MAX(T1.SUPPLY_UNIT)> 120501
         THEN '801703'
         WHEN MAX(T1.CUSTOMER_NM) IN('天津腾飞钢管有限公司','沈阳腾飞钢铁经销有限公司','天津宝仓物流有限公司','天津市安利金属制造有限公司')  
         THEN '801703'
         WHEN MAX(T1.STLMT_UNIT_NM) IN('天津腾飞钢管有限公司','沈阳腾飞钢铁经销有限公司','天津宝仓物流有限公司','天津市安利金属制造有限公司')  
         THEN '801703'
         WHEN (select MAX(t5.PORDERSTATUS) from pln_saleord t5 where t5.ord_ln_dly_pk =T.ord_ln_dly_pk)>=5 
             THEN '801701'
         WHEN MAX(NVL(T1.SHORTEST,0))>0 AND (CASE WHEN MAX(T1.ORDER_UNIT) ='英尺' THEN 3.2808 *MAX(T.ACT_LEN_MIN) ELSE  1*MAX(T.ACT_LEN_MIN) END) < MAX(NVL(T1.SHORTEST,0))
             THEN '801701'
               WHEN MAX(NVL(T1.LONGEST,0))>0 AND (CASE WHEN MAX(T1.ORDER_UNIT) ='英尺' THEN 3.2808 *MAX(T.ACT_LEN_MAX) ELSE  1*MAX(T.ACT_LEN_MAX) END)  > MAX(NVL(T1.LONGEST,0))
             THEN '801701'
           ELSE
             CASE WHEN MAX(T1.ORDER_UNIT) = '吨' THEN
       CASE
         --缴库量上限 < 累计送判吨（按计划入）+ 单支重量
           WHEN  MAX(T1.PAYDOWN_WT_MAX) < MAX(T1.ACT_WEIGHT2) + ROUND(ROUND(SUM(T.ACT_WEIGHT), 3)/SUM(T.ACT_COUNT),3）
             THEN '801701'
               WHEN T.LENGTH_TYPE = '1'  AND  MAX(T1.ORDER_WT_MAX_LONG) <  MAX(T1.ACT_WEIGHT_L) + ROUND(ROUND(SUM(T.ACT_WEIGHT), 3)/SUM(T.ACT_COUNT),3）
             THEN '801701'
               WHEN T.LENGTH_TYPE = '2'  AND  MAX(T1.ORDER_WT_MAX_SHORT) <  MAX(T1.ACT_WEIGHT_S) + ROUND(ROUND(SUM(T.ACT_WEIGHT), 3)/SUM(T.ACT_COUNT),3）
             THEN '801701'
               ELSE
                 '801703'
               END
               
                WHEN MAX(T1.ORDER_UNIT) IN( '米' ,'英尺') THEN
                 CASE
         --缴库量上限 < 累计送判吨（按计划入）+ 单支重量
           WHEN  MAX(T1.PAYDOWN_WT_MAX) < MAX(T1.ACT_LEN2) + ROUND(ROUND(SUM(T.ACT_LEN), 3)/SUM(T.ACT_COUNT),3）
             THEN '801701'
               WHEN T.LENGTH_TYPE = '1'  AND  MAX(T1.ORDER_WT_MAX_LONG) <  MAX(T1.ACT_LEN_L) + ROUND(ROUND(SUM(T.ACT_LEN), 3)/SUM(T.ACT_COUNT),3）
             THEN '801701'
               WHEN T.LENGTH_TYPE = '2'  AND  MAX(T1.ORDER_WT_MAX_SHORT) <  MAX(T1.ACT_LEN_S) + ROUND(ROUND(SUM(T.ACT_LEN), 3)/SUM(T.ACT_COUNT),3）
             THEN '801701'
               ELSE
                 '801703'
               END
              END
             END IN_MOLD,
             
           NVL(  CASE WHEN MAX(T1.RECEIV_NM) IN('天津腾飞钢管有限公司','沈阳腾飞钢铁经销有限公司','天津宝仓物流有限公司','天津市安利金属制造有限公司') OR MAX(T1.SUPPLY_UNIT)> 120501
         THEN SUM(T.ACT_COUNT)
         WHEN MAX(T1.CUSTOMER_NM) IN('天津腾飞钢管有限公司','沈阳腾飞钢铁经销有限公司','天津宝仓物流有限公司','天津市安利金属制造有限公司') 
         THEN SUM(T.ACT_COUNT)
         WHEN MAX(T1.STLMT_UNIT_NM) IN('天津腾飞钢管有限公司','沈阳腾飞钢铁经销有限公司','天津宝仓物流有限公司','天津市安利金属制造有限公司') 
         THEN SUM(T.ACT_COUNT)
           ELSE
             CASE WHEN MAX(T1.ORDER_UNIT) = '吨' THEN
               CASE WHEN T.LENGTH_TYPE = '0' AND MAX(T1.PAYDOWN_WT_MAX) -  MAX(T1.ACT_WEIGHT2) > 0 THEN
                 FLOOR((MAX(T1.PAYDOWN_WT_MAX) -  MAX(T1.ACT_WEIGHT2))/(ROUND(SUM(T.ACT_WEIGHT), 3)/SUM(T.ACT_COUNT)))
                 WHEN T.LENGTH_TYPE = '1' AND MAX(T1.ORDER_WT_MAX_LONG) -  MAX(T1.ACT_WEIGHT_L)  > 0 THEN
                  FLOOR(LEAST((MAX(T1.ORDER_WT_MAX_LONG) -  MAX(T1.ACT_WEIGHT_L)),(MAX(T1.PAYDOWN_WT_MAX) -  MAX(T1.ACT_WEIGHT2)))/(ROUND(SUM(T.ACT_WEIGHT), 3)/SUM(T.ACT_COUNT)))
                 WHEN T.LENGTH_TYPE = '2' AND MAX(T1.ORDER_WT_MAX_SHORT) -  MAX(T1.ACT_WEIGHT_S)  > 0 THEN
                  FLOOR(LEAST((MAX(T1.ORDER_WT_MAX_SHORT) -  MAX(T1.ACT_WEIGHT_S)),(MAX(T1.PAYDOWN_WT_MAX) -  MAX(T1.ACT_WEIGHT2)))/(ROUND(SUM(T.ACT_WEIGHT), 3)/SUM(T.ACT_COUNT)))
                   END
               WHEN MAX(T1.ORDER_UNIT) IN( '米' ,'英尺') THEN
                 CASE WHEN T.LENGTH_TYPE = '0' AND MAX(T1.PAYDOWN_WT_MAX) -  MAX(T1.ACT_LEN2) > 0 THEN
                 FLOOR((MAX(T1.PAYDOWN_WT_MAX) -  MAX(T1.ACT_LEN2))/(ROUND(SUM(T.ACT_LEN), 3)/SUM(T.ACT_COUNT)))
                 WHEN T.LENGTH_TYPE = '1' AND MAX(T1.ORDER_WT_MAX_LONG) -  MAX(T1.ACT_LEN_L)  > 0 THEN
                  FLOOR(LEAST((MAX(T1.ORDER_WT_MAX_LONG) -  MAX(T1.ACT_LEN_L)),(MAX(T1.PAYDOWN_WT_MAX) -  MAX(T1.ACT_LEN2)))/(ROUND(SUM(T.ACT_LEN), 3)/SUM(T.ACT_COUNT)))
                 WHEN T.LENGTH_TYPE = '2' AND MAX(T1.ORDER_WT_MAX_SHORT) -  MAX(T1.ACT_WEIGHT_S)  > 0 THEN
                  FLOOR(LEAST((MAX(T1.ORDER_WT_MAX_SHORT) -  MAX(T1.ACT_LEN_S)),(MAX(T1.PAYDOWN_WT_MAX) -  MAX(T1.ACT_LEN2)))/(ROUND(SUM(T.ACT_LEN), 3)/SUM(T.ACT_COUNT)))
                   END
                   END
                 END,0) KSPZ
 FROM MAT_BC_BACKUP T
 LEFT JOIN QCM_ZC_APPLY T1
    ON T.ORD_LN_DLY_PK = T1.ORD_LN_DLY_PK
 WHERE T.HEAT_PLAN_NO = ? 
 AND T.JUDGE_STOVE_NO = ?
    AND T.JUGDE_APPLY_CODE IS NOT NULL
 AND T.QCM_STAUS = '00'
 #JUGDE_APPLY_CODE#
 #JUGDE_APPLY_CODE2#
 #GROUP_BY#
 ]]>
</query>
<query id = "FrmVrpApplyNew.doQueryJudgeBathCount" desc = "查询详细炉批信息">
 SELECT 
  COUNT(*) COUNT
 FROM MAT_BC_M T
 WHERE T.HEAT_PLAN_NO = ?
 AND T.JUDGE_STOVE_NO = ?
 AND T.QCM_STAUS = '00'
</query>
<query id = "FrmVrpApplyNew.doQueryHttData" desc = "查询热处理槽长槽宽槽深">
SELECT MAX(T.NOTCH_LENGTH) NOTCH_LENGTH, MAX(T.NOTCH_WIDTH) NOTCH_WIDTH, MAX(T.NOTCH_DEPTH) NOTCH_DEPTH
  FROM HTT_CRACK_DETECTION_ET T
 WHERE 1 = 1
</query>
<query id = "insertProssWt.updateProWgt" 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.BATCH_NO = ?
   AND NVL(T.heat_plan_no_next, '/') = NVL(?, '/')
   AND NVL(T.BATCH_GROUD_NO, '/') = NVL(?, '/')
   AND NVL(T.LOT_NO, '/') = NVL(?, '/')
   AND T.QCM_STAUS = '00'
</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.BATCH_NO = ?
   AND NVL(T.heat_plan_no_next, '/') = NVL(?, '/')
   AND NVL(T.BATCH_GROUD_NO, '/') = NVL(?, '/')
   AND NVL(T.PRO_ORDER_NO, '/') = NVL(?, '/')
   AND NVL(T.LOT_NO, '/') = NVL(?, '/')
   AND T.QCM_STAUS = '00'
   AND T.JUGDE_APPLY_CODE IS NULL
 group by t.heat_plan_no_next
	</query>
	
	
	<query id = "FrmVrpApplyNew.SelectOrderJg" desc = "查询接箍合同是否有数据">
SELECT COUNT(*) COUNT FROM PLN_ZY_JG_MIDDLE T WHERE T.ORD_LN_DLY_PK = '#ORD_LN_DLY_PK#'
	</query>
	
	<query id = "FrmVrpApplyNew.SelectOrderJgLiao" desc = "查询接箍料">
select COUNT(*) COUNT　from pln_zy_jgx_m t,pln_order_jg  t1 where  t.ord_ln_dly_pk=t1.ord_ln_dly_pk and t.ORD_LN_DLY_PK = '#ORD_LN_DLY_PK#'
	</query>
	
	<query id = "FrmVrpApplyNew.SelectDealJg" desc = "查询接箍合同是否有数据">
SELECT COUNT(*) COUNT
  FROM COUPLING_MAT_DEAL T
 WHERE T.DEAL_TYPE_CODE = '800801'
   AND T.ORD_LN_DLY_PK = '#ORD_LN_DLY_PK#'
	</query>
	
	<query id = "FrmVrpApplyNew.SelectOrderJgCount" desc = "查询接箍合同是否有数据">
	SELECT COUNT(*) COUNT
  FROM PLN_ORDER_JG T, PLN_ZY_JG_M T1, PLN_ZY_JG_WORKBILL T2
 WHERE T.PRO_PLAN_ID_S = T1.PRO_PLAN_ID
   AND T1.HEAT_PLAN_NO = T2.HEAT_PLAN_NO
   AND T2.ZY_BILL_STATUS NOT IN ('0', '1')
   AND T.ORD_LN_DLY_PK = '#ORD_LN_DLY_PK#'
	</query>
	
	<query id = "FrmVrpApplyNew.SelectOrderJgData" desc = "查询接箍合同是否有数据">
	SELECT COUNT(*) COUNT
  FROM PLN_ORDER_JG T
 WHERE  T.ORD_LN_DLY_PK = '#ORD_LN_DLY_PK#'
	</query>
	
	<query id = "FrmVrpApplyNew.doQueryWt" desc = "查询回磅重量">
	SELECT NVL(SUM(T.PONDER_GROSS_WT),0) PONDER_GROSS_WT FROM MAT_BC_M T WHERE 1 = 1 AND T.QCM_STAUS = '00' AND T.JUGDE_APPLY_CODE IS NULL AND T.PLINE_CODE IN('C018','C075') 
	</query>
	<query id = "FrmVrpApplyNew.doQueryQcmApply" desc = "查询判定表热处理状态">
	SELECT T.HTT_TYPE, T.MIN_TEMP, T.HTT_TECHNOLOGY,T.NOTCH_INFO,T.NOTCH_LENGTH,T.NOTCH_WIDTH,T.NOTCH_DEPTH FROM QCM_ZG_JUGDE_APPLY T WHERE 1 = 1
	</query>
		<query id = "FrmVrpApplyNew.doQueryProcess" desc = "查询镦拔扩二级工序">		
SELECT T.PROCESS_CODE_C
  FROM PLN_ZY_DBK_M T
 WHERE 1=1
	</query>
	<query id = "FrmVrpApplyNew.getQueryProcessRcl" desc = "查询热处理二级工序">		
SELECT T.PROCESS_CODE_C
  FROM PLN_ZY_RCL_M T
 WHERE 1=1
	</query>
	<query id = "FrmVrpApplyNew.getQueryProcessJgx" desc = "查询加工线二级工序">		
SELECT T.PROCESS_CODE_C
  FROM PLN_ZY_JGX_M T
 WHERE 1=1
	</query>
		<query id = "FrmVrpApplyNew.doQueryProcessDesc" desc = "查询镦拔扩二级工序">		
SELECT T.PROCESS_CODE_C
  FROM PLN_ZY_DBK_M T
 WHERE 1=1 
	</query>
		<query id = "FrmVrpApplyNew.doQueryProcessRclDesc" desc = "查询热处理二级工序">		
SELECT T.PROCESS_CODE_C
  FROM PLN_ZY_RCL_M T
 WHERE 1=1 
	</query>

    <query id = "FrmVrpApplyNew.SelectMchResultD" desc = "查询拧接从表">
        SELECT NVL(COUNT(*), 0) COUNT
        FROM MCH_TWISTINGLY_RESULT_D T
        WHERE 1 = 1
        AND T.JUDGE_STOVE_NO = ?
        AND T.BATCH_NO = ?
        AND NVL(COUPLING_NUM, 0) - NVL(JUDGE_NUM, 0) > 0

    </query>


    <query id = "FrmVrpApplyNew.SelectMchResultD2" desc = "查询拧接从表">
        SELECT NVL(COUNT(*), 0) COUNT
        FROM MCH_TWISTINGLY_RESULT_D T
        WHERE 1 = 1
        AND T.HEAT_PLAN_NO = ?
        AND T.JUDGE_STOVE_NO = ?
        AND T.BATCH_NO = ?
        AND NVL(COUPLING_NUM, 0) - NVL(JUDGE_NUM, 0) > 0

    </query>
	
		<query id = "FrmVrpApplyNew.SelectMchResultMatchOdd" desc = "查询拧接从表">		
SELECT NVL(count(*),'0') count
  FROM MCH_TWISTINGLY_RESULT_D T
 WHERE 1=1 
 AND T.JUDGE_STOVE_NO = ?
	</query>
	
	<query id = "FrmVrpApplyNew.SelectMchResultDdeal" desc = "查询拧接从表交易单号">		
SELECT T.DEAL_ORDE
  FROM MCH_TWISTINGLY_RESULT_D T
 WHERE 1=1 
  AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#' AND T.batch_no = TRIM('#BATCH_NO#')
	</query>
	
	<query id = "FrmVrpApplyNew.SelectProducType" desc = "查询品名类型">		
select T.PRODUC_TYPE from COM_BASE_PRODUCT t WHERE T.PRODUCNAME = '#PRODUCNAME#'
	</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.BATCH_NO = ?
   AND T.QCM_STAUS = '00'
   AND T.JUGDE_APPLY_CODE IS NULL
   AND NVL(T.heat_plan_no_next, '/') = NVL(?, '/')
   AND NVL(T.BATCH_GROUD_NO, '/') = NVL(?, '/')
   AND NVL(T.PRO_ORDER_NO, '/') = NVL(?, '/')
   AND NVL(T.LOT_NO, '/') = NVL(?, '/')
	</query>
		<query id = "FrmVrpApplyNew.doQueryStorage" desc = "查询存储位置">
	SELECT T1.STORAGE_NO,T1.STORAGE_NAME
  FROM YDM_BC_BUTTRESS T, YDM_BS_STORAGE T1
 WHERE T.STORAGE_NO = T1.STORAGE_NO
	</query>
		<query id = "FrmVrpApplyNew.doQueryBsStorage" desc = "查询存储">
	SELECT T.STORAGE_NAME
  FROM YDM_BS_STORAGE T
 WHERE 1 = 1  
	</query>
	
	<query id = "FrmVrpApplyNew.doQueryTestingGrade" desc = "根据快速检索码查基础信息">
	SELECT T.BASENAME,T.BASECODE  FROM COM_BASE_INFO T WHERE T.SORTCODE = ?
	</query>
	<query id = "FrmVrpApplyNew.jugdeApplyNo" desc = "申请判定单号">
        SELECT '#PLINE_CODE#'||'#PRODUCT_FLAG#' || TO_CHAR(SYSDATE, 'yyyyMMDD') ||
        LPAD(NVL(MAX(TO_NUMBER(SUBSTR(JUGDE_APPLY_CODE, LENGTH(JUGDE_APPLY_CODE) - 5))),
        0) + 1,
        6,
        '0') JUGDE_APPLY_CODE
        FROM  QCM_ZG_JUGDE_APPLY
        WHERE JUGDE_APPLY_CODE LIKE '#PLINE_CODE#'||'#PRODUCT_FLAG#' || TO_CHAR(SYSDATE, 'yyyyMMDD') || '______'
	</query>
		<query id = "FrmVrpApplyNew.getQueryPlnRclM" desc = "查询热处理是否下发">
	SELECT NVL(COUNT(*),0) COUNT FROM PLN_ZY_RCL_M WHERE PLANSTATUS NOT IN ('00','10')
	</query>
		<query id = "FrmVrpApplyNew.getQueryPlnJgx" desc = "查询加工线是否下发">
	SELECT NVL(COUNT(*),0) COUNT FROM PLN_ZY_JGX_M WHERE PLANSTATUS NOT IN ('00','10')
	</query>
	<query id = "FrmVrpApplyNew.getQueryPlnJg" desc = "查询接箍是否下发">
	SELECT NVL(COUNT(*),0) COUNT FROM PLN_ZY_JG_M WHERE PLANSTATUS NOT IN ('00','10')
	</query>
	<query id = "FrmVrpApplyNew.SelectJudegNo" desc = "查询最大序号">
SELECT T.JUGDE_APPLY_CODE
  FROM QCM_ZG_JUGDE_APPLY T
 WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND T.PROCESS_CODE = '#PROCESS_CDOE#'
   AND T.IS_FLAG = '0'
   AND T.IS_ALL_SCRAP = '0'
   GROUP BY T.JUGDE_APPLY_CODE
</query>
<query id = "FrmVrpApplyNew.SelectJudegNoSequenNo" desc = "查询申请判定顺序号">
SELECT NVL(MAX(T.JUGDE_APPLY_SEQUENO),0)+1 JUGDE_APPLY_SEQUENO
  FROM QCM_ZG_JUGDE_APPLY T
 WHERE T.JUGDE_APPLY_CODE = ?
</query>
<query id = "FrmVrpApplyNew.SelectFaceResultPath" desc = "查询表检报告路径">
SELECT S.FACE_RESULT_PATH,S.HEAT_PLAN_NO
  FROM VRP_COM_INFO S
 WHERE S.HEAT_PLAN_NO = '#HEAT_PLAN_NO_OLD#'
   AND S.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND S.PLINE_CODE = '#PLINE_CODE#'
   AND S.STATION_CODE IN('650106','650404','650504','650604','650704')
</query>
<query id = "FrmVrpApplyNew.SelectDeteceResultPath" desc = "查询探伤报告路径">
SELECT MIN(T.REPORT_PATH) REPORT_PATH
  FROM HTT_CRACK_DETECTION_PARA T
 WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO_OLD#'
 AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
 AND T.batch_no = TRIM('#BATCH_NO#')
   AND T.REPORT_PATH IS NOT NULL
</query>
<query id = "FrmVrpApplyNew.QueryCode" desc = "查询申请判定数据刷新">
SELECT SUM(COUNT) COUNT FROM
(SELECT COUNT(*) COUNT
                  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.QCM_STAUS = '00'
                   AND T.JUGDE_APPLY_CODE IS NULL
                   UNION
                   SELECT COUNT(*) COUNT
                  FROM MAT_BC_BACKUP 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.QCM_STAUS = '00'
                   AND T.JUGDE_APPLY_CODE IS NULL
                 )
</query>
<query id = "FrmVrpApplyNew.SelectNodeFlagVrp" desc = "查询结炉状态">
SELECT T.*
  FROM PLN_ZY_DBK_M T
 WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO_OLD#'
</query>

<query id = "FrmVrpApplyNew.SelectNodeFlagVrpLiku" desc = "查询结炉状态">
SELECT T.*
  FROM PLN_ZY_DBK_M T
 WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
   AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
</query>
<query id = "FrmVrpApplyNew.SelectNodePortEntity" desc = "查询管号队列检验编号">
SELECT T.CHECK_NO
  FROM PORT_htt_BATCH_SAMPLE_RESULT T
 WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO_OLD#'
   AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND T.PHY_BATCH_NO = '#BATCH_NO#'
   AND T.IS_SAMPLE_PIPE = '1'
   GROUP BY T.CHECK_NO
</query>
<query id = "FrmVrpApplyNew.SelectNodeFlagHtt" desc = "查询结炉状态">
SELECT T.*
  FROM PLN_ZY_RCL_M T
 WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO_OLD#'
</query>
<query id = "FrmVrpApplyNew.SelectNodeFlagHttLiku" desc = "查询结炉状态">
SELECT T.*
  FROM PLN_ZY_RCL_M T
 WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
   AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
</query>
<query id = "FrmVrpApplyNew.SelectNodeFlagMch" desc = "查询结炉状态">
SELECT T.*
  FROM PLN_ZY_JGX_M T
 WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO_OLD#'
</query>
<query id = "FrmVrpApplyNew.SelectNodeFlagMchLiku" desc = "查询结炉状态">
SELECT T.*
  FROM PLN_ZY_JGX_M T
 WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
   AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
</query>

<query id = "FrmVrpApplyNew.SelectNodeFlagMchLikuD" desc = "查询轧管计划表里主制程索引号">
SELECT T.*
  FROM pln_zy_zg_m T
 WHERE  T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#' AND T.IF_MATCH_ODD = '6'
</query>
<query id = "FrmVrpApplyNew.insertJugdeApply" desc = "插入申请判定表">
    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_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,
   MAT_GOWHERE_CODE,
   MAT_GOWHERE_NAME,
   ACT_DIMATER,
   ACT_HEIGHT,
   ACT_LEN_MIN,
   ACT_LEN_MAX,
   ORD_LN_DLY_PK,
   APPLY_FLAG,
   INSTOCK_FLAG,
   BELONG_CODE,
   BELONG_NAME,
   ISENDGX,
   ACT_LEN,
   BELONG_CODE_JUGDE,
   BELONG_NAME_JUGDE,
   GX_PLAN_NO,
   BAL_YEAR_MONTH,
   STOVE_NO,
   STEEL_STANDRAD,
   PRO_PLAN_ID_NEXT,
   GX_PLAN_NO_NEXT,
   LK_FLAG,
   JUGDE_APPLY_SEQUENO,
   TARGET,
   CRAFT_SEQ,
   INDEX_SEQ,
   CIC,
   PIC,
   SIC,
   DIC,
   WIC,
   GIC,
   FACE_RESULT_CODE,
   SPEC_RESULT_CODE,
   CHEM_RESULT_CODE,
   PHY_RESULT_CODE,
   DETECT_RESULT_CODE,
   WPRESSURE_RESULT_CODE,
   PROCESS_RESULT_CODE,
   CHECK_NO,
   HEAT_PLAN_NO_NEXT,
   HEAT_PLAN_NO,
   NEXT_PROCESS_CDOE,
   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,
   TESTING_GRADE,
   TESTING_TYPE,
   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,
   INPUT_WEIGHT,
   INPUT_COUNT,
   OUTPUT_WEIGHT,
   OUTPUT_COUNT,
   TESTING_STANDAR,
   DRIFT_MODEL_MIN,
   DRIFT_MODEL_MIN2,
   DRIFT_MODEL_LEN,
   DRIFT_MODEL_LEN2,
   MEASURED_END_PART,
   MEASURED_MIDDLE_PART,
   MEASURED_TAIL_PART,
   LIKU_PROCESS_CODE,
   SUPPLY_UNIT,
   SUPPLY_UNIT_DESC,
   length_type,
   IN_MOLD)
VALUES
  ('#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_PATH#',
   '#SPEC_RESULT_PATH#',
   '#CHEM_RESULT_PATH#',
   '#PHY_RESULT_PATH#',
   '#DETECT_RESULT_PATH#',
   '#WPRESSURE_RESULT_PATH#',
   '#PROCESS_RESULT_PATH#',
   '#VALIDFLAG#',
   '#APPLY_NAME#',
   TO_DATE('#APPLY_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
   '#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#',
   NVL('#MAT_GOWHERE_CODE#', '\'),
   NVL('#MAT_GOWHERE_NAME#', '\'),
   '#ACT_DIMATER#',
   '#ACT_HEIGHT#',
   '#ACT_LEN_MIN#',
   '#ACT_LEN_MAX#',
   '#ORD_LN_DLY_PK#',
   '#APPLY_FLAG#',
   '#INSTOCK_FLAG#',
   '#BELONG_CODE#',
   '#BELONG_NAME#',
   '#ISENDGX#',
   '#ACT_LEN#',
   '#BELONG_CODE_JUGDE#',
   '#BELONG_NAME_JUGDE#',
   '#GX_PLAN_NO#',
   '',
   '#STOVE_NO#',
   '#STEEL_STANDRAD#',
   '#PRO_PLAN_ID_NEXT#',
   '#GX_PLAN_NO_NEXT#',
   '#LK_FLAG#',
   '#JUGDE_APPLY_SEQUENO#',
   '#TARGET#',
   '#CRAFT_SEQ#',
   '#INDEX_SEQ#',
   '#CIC#',
   '#PIC#',
   '#SIC#',
   '#DIC#',
   '#WIC#',
   '#GIC#',
   '#FACE_RESULT_CODE#',
   '#SPEC_RESULT_CODE#',
   '#CHEM_RESULT_CODE#',
   '#PHY_RESULT_CODE#',
   '#DETECT_RESULT_CODE#',
   '#WPRESSURE_RESULT_CODE#',
   '#PROCESS_RESULT_CODE#',
   '#CHECK_NO#',
   '#HEAT_PLAN_NO_NEXT#',
   '#HEAT_PLAN_NO#',
   '#NEXT_PROCESS_CDOE#',
   '#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#',
   '#TESTING_GRADE#',
   '#TESTING_TYPE#',
   '#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#',
   '#INPUT_WEIGHT#',
   '#INPUT_COUNT#',
   '#OUTPUT_WEIGHT#',
   '#OUTPUT_COUNT#',
   '#TESTING_STANDAR#',
   '#DRIFT_MODEL_MIN#',
   '#DRIFT_MODEL_MIN2#',
   '#DRIFT_MODEL_LEN#',
   '#DRIFT_MODEL_LEN2#',
   '#MEASURED_END_PART#',
   '#MEASURED_MIDDLE_PART#',
   '#MEASURED_TAIL_PART#',
   '#LIKU_PROCESS_CODE#',
   '#SUPPLY_UNIT#',
   '#SUPPLY_UNIT_DESC#',
   (select decode('#LENGTH_TYPE#',
                  '长尺',
                  1,
                  '短尺',
                  2,
                  '正尺',
                  0,
                  '#LENGTH_TYPE#')
      from dual),
   '#IN_MOLD#')
</query>
<query id = "FrmVrpApplyNew.insertJugdeApplyLog" desc = "写入判定日志">
	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>


<query id = "FrmVrpApplyNew.updateMatBcJugdeApplyCode" desc = "修改库存申请判定单号">
<![CDATA[
  DECLARE
  V_COUNT NUMBER := 1;
BEGIN
  FOR MYROW IN (SELECT *
                  FROM (SELECT T.MAT_NO,
                               T.PLINE_CODE,
                               T.GX_PLAN_NO_NEXT,
                               T.CREATE_TIME
                          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 NVL(T.PRO_ORDER_ID, '/') =
                               NVL('#PRO_ORDER_ID#', '/')
                           AND NVL(T.GX_PLAN_NO, '/') =
                               NVL('#GX_PLAN_NO#', '/')
                           AND NVL(T.HEAT_PLAN_NO, '/') =
                               NVL('#HEAT_PLAN_NO#', '/')
                           AND NVL(T.LENGTH_TYPE, '/') =
                               NVL('#LENGTH_TYPE#', '/')
                           AND T.QCM_STAUS = '00'
                           AND T.JUGDE_APPLY_CODE IS NULL
                        UNION
                        SELECT T.MAT_NO,
                               T.PLINE_CODE,
                               T.GX_PLAN_NO_NEXT,
                               T.CREATE_TIME
                          FROM MAT_BC_BACKUP 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 NVL(T.PRO_ORDER_ID, '/') =
                               NVL('#PRO_ORDER_ID#', '/')
                           AND NVL(T.GX_PLAN_NO, '/') =
                               NVL('#GX_PLAN_NO#', '/')
                           AND NVL(T.HEAT_PLAN_NO, '/') =
                               NVL('#HEAT_PLAN_NO#', '/')
                           AND NVL(T.LENGTH_TYPE, '/') =
                               NVL('#LENGTH_TYPE#', '/')
                           AND T.QCM_STAUS = '00'
                           AND T.JUGDE_APPLY_CODE IS NULL
                         ORDER BY MAT_NO ASC)
                 WHERE ROWNUM <= '#ACT_COUNT#'
                 ORDER BY MAT_NO ASC) LOOP
    UPDATE MAT_BC_M T
       SET T.JUGDE_APPLY_CODE    = '#JUGDE_APPLY_CODE#',
           T.JUGDE_APPLY_SEQUENO = '#JUGDE_APPLY_SEQUENO#',
           T.JUGDE_APPLY_TIME    = TO_DATE('#APPLY_TIME#',
                                           'YYYY-MM-DD HH24:MI:SS')
     WHERE T.MAT_NO = MYROW.MAT_NO
       AND T.PLINE_CODE = MYROW.PLINE_CODE
       AND NVL(T.GX_PLAN_NO_NEXT, '/') = NVL(MYROW.GX_PLAN_NO_NEXT, '/');
    UPDATE MAT_BC_BACKUP T
       SET T.JUGDE_APPLY_CODE    = '#JUGDE_APPLY_CODE#',
           T.JUGDE_APPLY_SEQUENO = '#JUGDE_APPLY_SEQUENO#',
           T.JUGDE_APPLY_TIME    = TO_DATE('#APPLY_TIME#',
                                           'YYYY-MM-DD HH24:MI:SS')
     WHERE T.MAT_NO = MYROW.MAT_NO
       AND T.PLINE_CODE = MYROW.PLINE_CODE
       AND NVL(T.GX_PLAN_NO_NEXT, '/') = NVL(MYROW.GX_PLAN_NO_NEXT, '/');
    IF ('#PROCESS_CODE#' = 'E') THEN
      UPDATE PORT_VRP_BATCH_SAMPLE_RESULT S
         SET S.JUGDE_APPLY_CODE    = '#JUGDE_APPLY_CODE#',
             S.JUGDE_APPLY_SEQUENO = '#JUGDE_APPLY_SEQUENO#',
             S.TR_FLAG             = '1'
       WHERE S.MAT_NO = MYROW.MAT_NO
         AND (JUGDE_APPLY_CODE IS NULL OR NOT EXISTS
              (SELECT 1
                 FROM QCM_ZG_JUGDE_APPLY
                WHERE JUGDE_APPLY_CODE = S.JUGDE_APPLY_CODE
                  AND JUDGE_STOVE_NO = S.JUDGE_STOVE_NO
                  AND BATCH_NO = S.PHY_BATCH_NO));
    ELSIF ('#PROCESS_CODE#' = 'F') THEN
      UPDATE PORT_HTT_BATCH_SAMPLE_RESULT S
         SET S.JUGDE_APPLY_CODE    = '#JUGDE_APPLY_CODE#',
             S.JUGDE_APPLY_SEQUENO = '#JUGDE_APPLY_SEQUENO#',
             S.TR_FLAG             = '1'
       WHERE S.MAT_NO = MYROW.MAT_NO
         AND (JUGDE_APPLY_CODE IS NULL OR NOT EXISTS
              (SELECT 1
                 FROM QCM_ZG_JUGDE_APPLY
                WHERE JUGDE_APPLY_CODE = S.JUGDE_APPLY_CODE
                  AND JUDGE_STOVE_NO = S.JUDGE_STOVE_NO
                  AND BATCH_NO = S.PHY_BATCH_NO));
    ELSIF ('#PROCESS_CODE#' = 'G') THEN
      UPDATE PORT_MCH_BATCH_SAMPLE_RESULT S
         SET S.JUGDE_APPLY_CODE    = '#JUGDE_APPLY_CODE#',
             S.JUGDE_APPLY_SEQUENO = '#JUGDE_APPLY_SEQUENO#'
       WHERE S.MAT_NO = MYROW.MAT_NO
         AND (JUGDE_APPLY_CODE IS NULL OR NOT EXISTS
              (SELECT 1
                 FROM QCM_ZG_JUGDE_APPLY
                WHERE JUGDE_APPLY_CODE = S.JUGDE_APPLY_CODE
                  AND JUDGE_STOVE_NO = S.JUDGE_STOVE_NO
                  AND BATCH_NO = S.PHY_BATCH_NO));
    END IF;
  
    IF ('#JudgeWithCoupling#' IS NOT NULL AND
       '#BatchNoWithCoupling#' IS NOT NULL) THEN
      SELECT COUNT(1)
        INTO V_COUNT
        FROM MCH_TWISTINGLY_RESULT_D T
       WHERE 1 = 1
         AND T.JUDGE_STOVE_NO = '#JudgeWithCoupling#'
         AND T.BATCH_NO = '#BatchNoWithCoupling#'
         AND NVL(COUPLING_NUM, 0) - NVL(JUDGE_NUM, 0) > 0;
    
      IF (V_COUNT > 0) THEN
        FOR MYROW1 IN (SELECT *
                         FROM MCH_TWISTINGLY_RESULT_D T
                        WHERE 1 = 1
                          AND T.JUDGE_STOVE_NO = '#JudgeWithCoupling#'
                          AND T.BATCH_NO = '#BatchNoWithCoupling#'
                          AND NVL(COUPLING_NUM, 0) - NVL(JUDGE_NUM, 0) > 0
                          AND ROWNUM = 1) LOOP
        
          INSERT INTO MCH_TWISTINGLY_JUDGE
            (JUGDE_APPLY_CODE,
             JUGDE_APPLY_SEQUENO,
             JUDGE_STOVE_NO,
             BATCH_NO,
             MAT_NO,
             RESULT_NO,
             SEQ,
             COUPLING_STOVE_NO,
             LOT_NO)
          VALUES
            ('#JUGDE_APPLY_CODE#',
             '#JUGDE_APPLY_SEQUENO#',
             '#JUDGE_STOVE_NO#',
             '#BATCH_NO#',
             MYROW.MAT_NO,
             MYROW1.RESULT_NO,
             MYROW1.SEQ,
             MYROW1.COUPLING_STOVE_NO,
             MYROW1.LOT_NO);
        
          UPDATE MCH_TWISTINGLY_RESULT_D
             SET JUDGE_NUM = NVL(JUDGE_NUM, 0) + 1
           WHERE RESULT_NO = MYROW1.RESULT_NO
             AND SEQ = MYROW1.SEQ;
        END LOOP;
      END IF;
    END IF;
  END LOOP;
END;

]]>
</query>

<query id = "FrmVrpApplyNew.updateLoad" desc = "判定表写上料炉号、上料批号">
DECLARE
  V_JUDGE_STOVE_NO QCM_ZG_JUGDE_APPLY.JUDGE_STOVE_NO%type := '#JUDGE_STOVE_NO#';
  V_PROCESS_CODE   QCM_ZG_JUGDE_APPLY.PROCESS_CODE%type := '#PROCESS_CODE#';
BEGIN
  FOR MYROW IN (SELECT T.*, M.HEAT_PLAN_NO_OLD, M.ZZB_FLAG ZZB_FLAG2
                  FROM QCM_ZG_JUGDE_APPLY T,
                       (SELECT DISTINCT M.PROCESS_CDOE,
                                        M.JUDGE_STOVE_NO,
                                        M.BATCH_NO,
                                        NVL(M.HEAT_PLAN_NO_OLD,
                                            M.HEAT_PLAN_NO) HEAT_PLAN_NO_OLD,
                                        M.ZZB_FLAG
                          FROM MAT_BC_M M
                         WHERE M.PROCESS_CDOE = V_PROCESS_CODE
                           AND M.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
                        UNION ALL
                        SELECT DISTINCT M.PROCESS_CDOE,
                                        M.JUDGE_STOVE_NO,
                                        M.BATCH_NO,
                                        NVL(M.HEAT_PLAN_NO_OLD,
                                            M.HEAT_PLAN_NO) HEAT_PLAN_NO_OLD,
                                        M.ZZB_FLAG
                          FROM MAT_BC_BACKUP M
                         WHERE M.PROCESS_CDOE = V_PROCESS_CODE
                           AND M.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO) M
                 WHERE T.PROCESS_CODE = V_PROCESS_CODE
                   AND T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
                   AND T.PROCESS_CODE = M.PROCESS_CDOE
                   AND T.BATCH_NO = M.BATCH_NO
                   AND T.JUDGE_STOVE_NO = M.JUDGE_STOVE_NO) LOOP
  
    IF (V_PROCESS_CODE = 'E') THEN
      UPDATE QCM_ZG_JUGDE_APPLY T
         SET T.LOAD_JUDGE_STOVE_NO =
              (SELECT MAX(E.FEED_HEAT_NO)
                 FROM PORT_VRP_BATCH_SAMPLE_RESULT E
                WHERE /*E.HEAT_PLAN_NO = MYROW.HEAT_PLAN_NO_OLD
                                                                                                           AND*/
                E.JUDGE_STOVE_NO = MYROW.JUDGE_STOVE_NO
             AND E.PHY_BATCH_NO = MYROW.BATCH_NO),
             T.LOAD_BATCH_NO      =
              (SELECT MAX(E.BATCH_NO)
                 FROM PORT_VRP_BATCH_SAMPLE_RESULT E
                WHERE /*E.HEAT_PLAN_NO = MYROW.HEAT_PLAN_NO_OLD
                                                                                                           AND*/
                E.JUDGE_STOVE_NO = MYROW.JUDGE_STOVE_NO
             AND E.PHY_BATCH_NO = MYROW.BATCH_NO),
             T.ZZB_FLAG            = MYROW.ZZB_FLAG2
       WHERE T.HEAT_PLAN_NO = MYROW.HEAT_PLAN_NO
         AND T.JUDGE_STOVE_NO = MYROW.JUDGE_STOVE_NO
         AND T.BATCH_NO = MYROW.BATCH_NO;
    ELSIF (V_PROCESS_CODE = 'F') THEN
      UPDATE QCM_ZG_JUGDE_APPLY T
         SET T.LOAD_JUDGE_STOVE_NO =
              (SELECT MAX(E.FEED_HEAT_NO)
                 FROM PORT_HTT_BATCH_SAMPLE_RESULT E
                WHERE /*E.HEAT_PLAN_NO = MYROW.HEAT_PLAN_NO_OLD
                                                                                                           AND*/
                E.JUDGE_STOVE_NO = MYROW.JUDGE_STOVE_NO
             AND E.PHY_BATCH_NO = MYROW.BATCH_NO),
             T.LOAD_BATCH_NO       = CASE
                                       WHEN MYROW.ZP_M_LH IS NULL THEN
                                        (SELECT MAX(E.BATCH_NO)
                                           FROM PORT_HTT_BATCH_SAMPLE_RESULT E
                                          WHERE /*E.HEAT_PLAN_NO = MYROW.HEAT_PLAN_NO_OLD
                                                                                                                                                                                                                                             AND*/
                                          E.JUDGE_STOVE_NO = MYROW.JUDGE_STOVE_NO
                                       AND E.PHY_BATCH_NO = MYROW.BATCH_NO)
                                       ELSE
                                        SUBSTR(MYROW.ZP_M_LH, -5)
                                     END,
             T.ZZB_FLAG            = MYROW.ZZB_FLAG2
       WHERE T.HEAT_PLAN_NO = MYROW.HEAT_PLAN_NO
         AND T.JUDGE_STOVE_NO = MYROW.JUDGE_STOVE_NO
         AND T.BATCH_NO = MYROW.BATCH_NO;
    ELSIF (V_PROCESS_CODE = 'G') THEN
      UPDATE QCM_ZG_JUGDE_APPLY T
         SET T.LOAD_JUDGE_STOVE_NO =
             (SELECT MAX(E.FEED_HEAT_NO)
                FROM PORT_MCH_BATCH_SAMPLE_RESULT E
               WHERE DECODE(MYROW.LK_FLAG, '0', E.HEAT_PLAN_NO, '/') =
                     DECODE(MYROW.LK_FLAG, '0', MYROW.HEAT_PLAN_NO_OLD, '/')
                 AND E.JUDGE_STOVE_NO = MYROW.JUDGE_STOVE_NO
                 AND E.PHY_BATCH_NO = MYROW.BATCH_NO),
             T.LOAD_BATCH_NO       = CASE
                                       WHEN MYROW.ZP_M_LH IS NULL THEN
                                        (SELECT MAX(E.BATCH_NO)
                                           FROM PORT_MCH_BATCH_SAMPLE_RESULT E
                                          WHERE DECODE(MYROW.LK_FLAG, '0', E.HEAT_PLAN_NO, '/') =
                                                DECODE(MYROW.LK_FLAG, '0', MYROW.HEAT_PLAN_NO_OLD, '/')
                                            AND E.JUDGE_STOVE_NO = MYROW.JUDGE_STOVE_NO
                                            AND E.PHY_BATCH_NO = MYROW.BATCH_NO)
                                       ELSE
                                        SUBSTR(MYROW.ZP_M_LH, -5)
                                     END,
             T.BUNDLING_MEMO      =
             (SELECT MAX(M.MEMO)
                FROM MCH_BUNDLING_RESULT M
               WHERE DECODE(MYROW.LK_FLAG, '0', M.HEAT_PLAN_NO, '/') =
                     DECODE(MYROW.LK_FLAG, '0', MYROW.HEAT_PLAN_NO_OLD, '/')
                 AND M.JUDGE_STOVE_NO = MYROW.JUDGE_STOVE_NO
                 AND M.BATCH_NO = MYROW.BATCH_NO),
             T.ZZB_FLAG            = MYROW.ZZB_FLAG2
       WHERE T.HEAT_PLAN_NO = MYROW.HEAT_PLAN_NO
         AND T.JUDGE_STOVE_NO = MYROW.JUDGE_STOVE_NO
         AND T.BATCH_NO = MYROW.BATCH_NO;
    END IF;
  END LOOP;

  --同步成品未判的库存与送判表重量,长度
  FOR MYROW2 IN (SELECT T.JUGDE_APPLY_CODE,
                        T.JUGDE_APPLY_SEQUENO,
                        T.JUDGE_STOVE_NO,
                        T.BATCH_NO,
                        T.BATCH_GROUD_NO,
                        T.PROCESS_CODE,
                        SUM(M.ACT_COUNT) ACT_COUNT,
                        SUM(M.ACT_WEIGHT) ACT_WEIGHT,
                        SUM(M.ACT_LEN) ACT_LEN
                   FROM QCM_ZG_JUGDE_APPLY T, MAT_BC_M M
                  WHERE T.PROCESS_CODE = V_PROCESS_CODE
                    AND T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
                    AND T.PROCESS_CODE = M.PROCESS_CDOE
                    AND T.BATCH_NO = M.BATCH_NO
                    AND T.JUDGE_STOVE_NO = M.JUDGE_STOVE_NO
                    AND T.BATCH_GROUD_NO = M.BATCH_GROUD_NO
                    AND T.JUGDE_APPLY_CODE = M.JUGDE_APPLY_CODE
                    AND T.JUGDE_APPLY_SEQUENO = M.JUGDE_APPLY_SEQUENO
                    AND T.VALIDFLAG = '00'
                    AND T.TARGET = 'A'
                  GROUP BY T.JUGDE_APPLY_CODE,
                           T.JUGDE_APPLY_SEQUENO,
                           T.JUDGE_STOVE_NO,
                           T.BATCH_NO,
                           T.PROCESS_CODE,
                           T.BATCH_GROUD_NO) LOOP
    UPDATE QCM_ZG_JUGDE_APPLY T
       SET T.ACT_WEIGHT = MYROW2.ACT_WEIGHT, T.ACT_LEN = MYROW2.ACT_LEN
     WHERE T.PROCESS_CODE = MYROW2.PROCESS_CODE
       AND T.BATCH_NO = MYROW2.BATCH_NO
       AND T.JUDGE_STOVE_NO = MYROW2.JUDGE_STOVE_NO
       AND T.BATCH_GROUD_NO = MYROW2.BATCH_GROUD_NO
       AND T.JUGDE_APPLY_CODE = MYROW2.JUGDE_APPLY_CODE
       AND T.JUGDE_APPLY_SEQUENO = MYROW2.JUGDE_APPLY_SEQUENO
       AND T.ACT_COUNT = MYROW2.ACT_COUNT
       AND T.VALIDFLAG = '00'
       AND T.TARGET = 'A';
  END LOOP;
  --更新成品送判量统计表
  SET_QCM_ZC_APPLY2('#ORD_LN_DLY_PK#');
END;
</query>

<query id = "FrmVrpApplyNew.SelectPlineBelong" desc = "获取现有产线所属权">
SELECT S.DEPARTMENT_CODE FROM COM_BASE_PLINE S WHERE S.PLINE_CODE = '#PLINE_CODE#'
</query>

<query id = "FrmVrpApplyNew.doQueryHttType" desc = "获取热处理类型">
select T.SORT_CODE
  from COM_BASE_PROCESS_C t
 WHERE T.PROCESS_CDOE_C = (select T1.PROCESS_CODE_C
                             from PLN_ZY_RCL_M T1
                            where 1 =1                          
</query>
<query id = "FrmVrpApplyNew.doQueryHttTemp" desc = "获取热处理温度工艺制度">
    SELECT
    CASE
    WHEN T.LOW_TEMP IS NULL
    THEN ''
    ELSE MAX(T.LOW_TEMP) || '℃' END LHEAT_EXIT_TEMP,
    CASE
    WHEN T.HTT_TECHNOLOGY IS NOT NULL THEN T.HTT_TECHNOLOGY
    WHEN T1.HTT_TECHNOLOGY IS NOT NULL THEN T1.HTT_TECHNOLOGY
    WHEN T.LHEAT_EXIT_TEMP IS NULL AND T1.HHEAT_EXIT_TEMP IS NOT NULL
    THEN T1.HHEAT_EXIT_TEMP || '℃' || '×' || T1.TOTAL_TIME || 'min'  ||  T1.COOLING_TYPE
    WHEN T1.HHEAT_EXIT_TEMP IS NULL AND T.LHEAT_EXIT_TEMP IS NOT NULL
    THEN T.LHEAT_EXIT_TEMP || '℃' || '×' || T.TOTAL_TIME || 'min' || T.COOLING_TYPE
    WHEN T.LHEAT_EXIT_TEMP IS NULL AND T1.HHEAT_EXIT_TEMP IS NULL
    THEN ''
    ELSE T1.HHEAT_EXIT_TEMP || '℃' || '×' || T1.TOTAL_TIME || 'min' || T1.COOLING_TYPE ||  '+' ||T.LHEAT_EXIT_TEMP || '℃' || '×' || T.TOTAL_TIME || 'min' || T.COOLING_TYPE END HEAT_EXIT_TEMP,
    MAX(T.CREATE_TIME),MAX(T1.CREATE_TIME)
    FROM HTT_LHEAT_RESULT T,HTT_HHEAT_RESULT T1
    WHERE T.HEAT_PLAN_NO = T1.HEAT_PLAN_NO
    AND T.PLINE_CODE = T1.PLINE_CODE
    AND T1.CREATE_TIME = (SELECT MAX(T2.CREATE_TIME) FROM HTT_HHEAT_RESULT T2 WHERE #HEAT_PLAN_NO# and #PLINE_CODE#)
    AND T.CREATE_TIME = (SELECT MAX(T2.CREATE_TIME) FROM HTT_LHEAT_RESULT T2 WHERE #HEAT_PLAN_NO# and #PLINE_CODE#)
    AND #LHEAT_PLAN_NO#
    and #LPLINE_CODE#
    GROUP BY T.HTT_TECHNOLOGY,T1.HTT_TECHNOLOGY, T.LHEAT_EXIT_TEMP,t1.total_time,t.total_time,t.LOW_TEMP,
    T1.HHEAT_EXIT_TEMP,T.COOLING_TYPE,T1.COOLING_TYPE
</query>
<query id = "FrmVrpApplyNew.QueryMatbcmPiece" desc = "查询交库后库存表支数">
SELECT NVL(SUM(REAL_OUTDOUBLE_NUM),0) REAL_OUTDOUBLE_NUM FROM (
SELECT NVL(SUM(T.ACT_COUNT), 0) REAL_OUTDOUBLE_NUM
  FROM MAT_BC_M T
 WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
   AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND T.QCM_STAUS = '00'
   AND T.PROCESS_CDOE = 'F'
UNION
SELECT NVL(SUM(T.ACT_COUNT), 0) REAL_OUTDOUBLE_NUM
  FROM MAT_BC_BACKUP T
 WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
   AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND T.QCM_STAUS = '00'
   AND T.PROCESS_CDOE = 'F')
</query>
<query id = "FrmVrpApplyNew.doQueryHttTempTech" desc = "获取热处理温度工艺制度">
SELECT T.MIN_TEMP,T.HTT_TECHNOLOGY FROM qcm_zg_jugde_apply T WHERE 1 =1 AND #LHEAT_PLAN_NO# AND #LPLINE_CODE#
</query>
<query id = "FrmVrpApplyNew.SelectZgJudgeNoE" desc = "查询组炉号">
SELECT T.GROUP_ID,
CASE 
  WHEN T.ZP_BATCH_NO IS NULL
    THEN T.ZP_JUDGE_STOVE_NO
      ELSE T.ZP_JUDGE_STOVE_NO || '+' || T.ZP_BATCH_NO END ZP_M_LH
FROM VRP_OFFLINE_RESULT T WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO_OLD#' AND T.GROUP_LOG = '1'
</query>
<query id = "FrmVrpApplyNew.SelectJudgeNoE" desc = "查询组炉前炉号">
SELECT 
      LISTAGG(DECODE(T.BATCH_NO,
                     '',T.JUDGE_STOVE_NO,T.JUDGE_STOVE_NO || '+' || T.BATCH_NO), ',') WITHIN GROUP(ORDER BY T.BATCH_NO) ZP_COLL
              FROM VRP_GROUP_RESULT T WHERE T.GROUP_ID = ?
</query>
<query id = "FrmVrpApplyNew.SelectZgJudgeNoF" desc = "查询主炉号">
SELECT T.GROUP_ID,
       CASE
         WHEN T.ZP_BATCH_NO IS NULL THEN
          T.ZP_JUDGE_STOVE_NO
         ELSE
          T.ZP_JUDGE_STOVE_NO || '+' || T.ZP_BATCH_NO
       END ZP_M_LH
  FROM HTT_OFFLINE_RESULT T
 WHERE T.GROUP_LOG = '1'
   AND (NVL(T.HEAT_PLAN_NO, '/') = NVL('#HEAT_PLAN_NO_OLD#', '/') OR
       NVL(T.ZY_BATCH_ID1, '/') = NVL('#HEAT_PLAN_NO_OLD#', '/'))
</query>
<query id = "FrmVrpApplyNew.QueryVrpPortFailPiece" desc = "查询各实绩废品和">
select NVL(SUM(T.ACT_COUNT), 0) ACT_COUNT
  from PORT_VRP_BATCH_SAMPLE_RESULT t
 WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO_OLD#'
   AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND ((T.MAT_STATUS = '00' and t.instore_flag='0')
   or t.mat_status = '20')
</query>
<query id = "FrmVrpApplyNew.SelectJudgeNoF" desc = "查询组炉前炉号">
SELECT 
      LISTAGG(DECODE(T.BATCH_NO,
                     '',T.JUDGE_STOVE_NO,T.JUDGE_STOVE_NO || '+' || T.BATCH_NO), ',') WITHIN GROUP(ORDER BY T.BATCH_NO) ZP_COLL
              FROM HTT_GROUP_RESULT T WHERE T.GROUP_ID = ?
</query>
<query id = "FrmVrpApplyNew.SelectZgJudgeNoG" desc = "查询组炉号">
SELECT T.GROUP_ID,
CASE 
  WHEN T.ZP_BATCH_NO IS NULL
    THEN T.ZP_JUDGE_STOVE_NO
      ELSE T.ZP_JUDGE_STOVE_NO || '+' || T.ZP_BATCH_NO END ZP_M_LH
FROM MCH_OFFLINE_RESULT T WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO_OLD#' AND T.GROUP_LOG = '1'
</query>
<query id = "FrmVrpApplyNew.SelectJudgeNoG" desc = "查询组炉前炉号">
SELECT 
      LISTAGG(DECODE(T.BATCH_NO,
                     '',T.JUDGE_STOVE_NO,T.JUDGE_STOVE_NO || '+' || T.BATCH_NO), ',') WITHIN GROUP(ORDER BY T.BATCH_NO) ZP_COLL
              FROM MCH_GROUP_RESULT T WHERE T.GROUP_ID = ?
</query>
<query id = "FrmVrpApplyNew.SelectMatchOddJudgeNo" desc = "查询原来的炉号">
SELECT T.JUDGE_STOVE_NO,t.BATCH_NO FROM MCH_GROUP_RESULT T WHERE T.GROUP_ID = ?
</query>

<query id = "FrmVrpApplyNew.SelectGroupResultE" desc = "查询组炉号">
 SELECT 
CASE 
  WHEN T.ZP_BATCH_NO IS NULL
    THEN T.ZP_JUDGE_STOVE_NO
       ELSE T.ZP_JUDGE_STOVE_NO || '+' || T.ZP_BATCH_NO END ZP_M_LH,
         CASE 
           WHEN T.BATCH_NO IS NULL
             THEN LISTAGG(T.JUDGE_STOVE_NO, ',') WITHIN GROUP(ORDER BY T.JUDGE_STOVE_NO || T.BATCH_NO) 
               ELSE LISTAGG(T.JUDGE_STOVE_NO || '+' || T.BATCH_NO, ',') WITHIN GROUP(ORDER BY T.JUDGE_STOVE_NO || T.BATCH_NO) END ZP_COLL
  FROM VRP_GROUP_RESULT T
 WHERE T.ZP_JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
 GROUP BY T.ZP_JUDGE_STOVE_NO, T.ZP_BATCH_NO,T.BATCH_NO
</query>
<query id = "FrmVrpApplyNew.SelectGroupResultF" desc = "查询组炉号">
 SELECT 
CASE 
  WHEN T.ZP_BATCH_NO IS NULL
    THEN T.ZP_JUDGE_STOVE_NO
       ELSE T.ZP_JUDGE_STOVE_NO || '+' || T.ZP_BATCH_NO END ZP_M_LH,
         CASE 
           WHEN T.BATCH_NO IS NULL
             THEN LISTAGG(T.JUDGE_STOVE_NO, ',') WITHIN GROUP(ORDER BY T.JUDGE_STOVE_NO || T.BATCH_NO) 
               ELSE LISTAGG(T.JUDGE_STOVE_NO || '+' || T.BATCH_NO, ',') WITHIN GROUP(ORDER BY T.JUDGE_STOVE_NO || T.BATCH_NO) END ZP_COLL
  FROM HTT_GROUP_RESULT T
 WHERE T.ZP_JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
 GROUP BY T.ZP_JUDGE_STOVE_NO, T.ZP_BATCH_NO,T.BATCH_NO
</query>
<query id = "FrmVrpApplyNew.SelectGroupResultG" desc = "查询组炉号">
 SELECT 
CASE 
  WHEN T.ZP_BATCH_NO IS NULL
    THEN T.ZP_JUDGE_STOVE_NO
       ELSE T.ZP_JUDGE_STOVE_NO || '+' || T.ZP_BATCH_NO END ZP_M_LH,
         CASE 
           WHEN T.BATCH_NO IS NULL
             THEN LISTAGG(T.JUDGE_STOVE_NO, ',') WITHIN GROUP(ORDER BY T.JUDGE_STOVE_NO || T.BATCH_NO) 
               ELSE LISTAGG(T.JUDGE_STOVE_NO || '+' || T.BATCH_NO, ',') WITHIN GROUP(ORDER BY T.JUDGE_STOVE_NO || T.BATCH_NO) END ZP_COLL
  FROM MCH_GROUP_RESULT T
 WHERE T.ZP_JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
 GROUP BY T.ZP_JUDGE_STOVE_NO, T.ZP_BATCH_NO,T.BATCH_NO
</query>
<query id = "FrmVrpApplyNew.SelectCraftNo" desc = "查找工艺文件号">
SELECT T.CRAFT_SEQ, T.CRAFT_FILE_NO,T.INDEX_SEQ
  FROM PLN_ZY_DBK_M T
 WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO_OLD#'
   AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
</query>
<query id = "FrmVrpApplyNew.SelectCraftNoRcl" desc = "查找工艺文件号">
SELECT T.CRAFT_SEQ, T.CRAFT_FILE_NO,T.INDEX_SEQ
  FROM PLN_ZY_RCL_M T
 WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO_OLD#'
   AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
</query>
<query id = "FrmVrpApplyNew.SelectCraftNoRcl2" desc = "查找工艺文件号">
SELECT T.CRAFT_SEQ, T.CRAFT_FILE_NO,T.INDEX_SEQ
  FROM PLN_ZY_RCL_M T
 WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
</query>

    <query id = "FrmVrpApplyNew.SelectCrackType" desc = "查找探伤类型">
        SELECT REPLACE(DBMS_LOB.SUBSTR(WMSYS.WM_CONCAT(DISTINCT DECODE(REPORT_NO,
        '4',
        'ET',
        'UT')),
        400),
        ',',
        '+') TESTING_TYPE
        FROM HTT_CRACK_DETECTION_PARA
        WHERE HEAT_PLAN_NO = '#HEAT_PLAN_NO_OLD#'
        AND BATCH_NO = '#BATCH_NO#'

    </query>

    <query id = "FrmVrpApplyNew.SelectCrackGade" desc = "查找探伤类型">
        SELECT REPLACE(DBMS_LOB.SUBSTR(WMSYS.WM_CONCAT(DISTINCT TESTING_GRAGE),
        400),
        ',',
        '+') TESTING_GRAGE
        FROM (SELECT LONGITUDINAL_EXTERNAL TESTING_GRAGE
        FROM HTT_CRACK_DETECTION_PARA
        WHERE HEAT_PLAN_NO = '#HEAT_PLAN_NO_OLD#'
        AND BATCH_NO = '#BATCH_NO#'
        AND LONGITUDINAL_EXTERNAL IS NOT NULL
        AND LONGITUDINAL_EXTERNAL != '/'
        UNION
        SELECT ACCPETANCE_LEVEL TESTING_GRAGE
        FROM HTT_CRACK_DETECTION_PARA
        WHERE HEAT_PLAN_NO = '#HEAT_PLAN_NO_OLD#'
        AND BATCH_NO = '#BATCH_NO#'
        AND ACCPETANCE_LEVEL IS NOT NULL
        AND ACCPETANCE_LEVEL  != '/')
    </query>
    
     <query id = "FrmVrpApplyNew.SelectQcmZcCheck" desc = "查找是否有重新热处理">
       SELECT COUNT(*) COUNT
  FROM QCM_ZC_CHECKCONSIGN T
 WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND T.BATCH_NO = '#BATCH_NO#'
   AND T.PROCESS_CODE = 'F'
   AND T.CYCLES_FLAG = '1'
    </query>

<query id = "FrmVrpApplyNew.SelectCraftNoJgx" desc = "查找工艺文件号">
SELECT T.CRAFT_SEQ, T.CRAFT_FILE_NO,T.INDEX_SEQ
  FROM PLN_ZY_JGX_M T
 WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO_OLD#'
   AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
</query>
<query id = "FrmVrpApplyNew.SelectDesignKey" desc = "查找designKey">
<![CDATA[
    SELECT T.DESGIN_KEY
   FROM CRAFT_ORD_DESIGN T
  WHERE T.CRAFT_NO =
        (SELECT MAX(CRAFT_NO)
           FROM CRAFT_ORD_DESIGN
          WHERE CRAFT_NO like SUBSTR(?, 1, LENGTH(?) - 1) || '%'
          AND VALIDFLAG <> '0')
          AND T.VALIDFLAG <> '0'
          AND T.VALIDFLAG <> '5'
          ORDER BY T.CRAFT_NO_V DESC
]]>
</query>
<query id = "FrmVrpApplyNew.QueryVrpPortPiece" desc = "查询各实绩废品和">
select NVL(SUM(T.ACT_COUNT), 0) ACT_COUNT
  from PORT_HTT_BATCH_SAMPLE_RESULT t
 WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO_OLD#'
   AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND ((T.MAT_STATUS = '00' and t.instore_flag='0')
   or t.mat_status = '20')
</query>

<query id = "FrmVrpApplyNew.QueryMchPortPiece" desc = "查询各实绩废品和">
select NVL(SUM(T.ACT_COUNT), 0) ACT_COUNT
  from PORT_MCH_BATCH_SAMPLE_RESULT t
 WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO_OLD#'
   AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND ((T.MAT_STATUS = '00' and t.instore_flag='0')
   or t.mat_status = '20')
</query>


    <query id = "FrmVrpApplyNew.QueryErrorWtCount" desc = "查询与管号队列重量不匹配支数">
        SELECT COUNT(1) COUNT
        FROM PORT_MCH_BATCH_SAMPLE_RESULT P, MAT_BC_M T
        WHERE P.MAT_NO = T.MAT_NO
        AND P.JUDGE_STOVE_NO = T.JUDGE_STOVE_NO
        AND P.PHY_BATCH_NO = T.BATCH_NO
        AND 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.PRO_ORDER_ID = '#PRO_ORDER_ID#'
        AND T.GX_PLAN_NO = '#GX_PLAN_NO#'
        AND T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
        AND T.QCM_STAUS = '00'
        AND T.JUGDE_APPLY_CODE IS NULL
        AND T.ACT_WEIGHT != P.ACT_WEIGHT
        AND P.INSTORE_FLAG = '1'
        AND P.JUGDE_APPLY_CODE IS NULL
    </query>

    <query id = "FrmVrpApplyNew.CheckStatus" desc = "查询各实绩废品和">
        select NVL(MIN(T.BESIDE_STATUS), '00') BESIDE_STATUS
        from PLN_ZY_JGX_C t
        WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
        AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
        AND BATCH_NO = '#BATCH_NO#'
    </query>


<query id = "FrmVrpApplyNew.SelectBaseCode" desc = "查找交货状态">
SELECT T.BASECODE, T.BASENAME
  FROM COM_BASE_INFO T
 WHERE T.BASECODE = (SELECT GET_DELIVERY_STATE(?,
                                               ?) SORTCODE
                       FROM DUAL)
                       AND T.SORTCODE='4100'
</query>
<query id = "FrmVrpApplyNew.SelectBaseCode1" desc = "查找交货状态">
SELECT T.BASECODE, T.BASENAME
  FROM COM_BASE_INFO T
 WHERE T.BASECODE = (SELECT GET_SHIPPED_STATE(?,?,?) SORTCODE
                       FROM DUAL)
                       AND T.SORTCODE='4100'
</query>
<query id = "FrmVrpApplyNew.SelectBaseCode2" desc = "短节、附件 的交货状态取备料交货状态">
SELECT T.BASECODE, T.BASENAME
  FROM COM_BASE_INFO T
 WHERE T.BASECODE =
       (SELECT GET_SHIPPED_STATE((SELECT MAX(T.DESGIN_KEY_BL)
                                   FROM CRAFT_ORD_DESIGN_MSC_BL T
                                  WHERE T.DESGIN_KEY = ?),
                                 NVL((select MAX(T1.MSC_PLINE)
                                       from CRAFT_ORD_DESIGN_MSC_PL_STI t1,
                                            CRAFT_ORD_DESIGN_MSC_BL     T2
                                      WHERE T1.DESGIN_KEY = T2.DESGIN_KEY_BL
                                        AND T2.DESGIN_KEY = ?),
                                     '000001'),
                                 ?) SORTCODE
          FROM DUAL)
   AND T.SORTCODE = '4100'
</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 OR
       S1.ORD_LN_PK = T.ORD_LN_PK)
   AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND T.PLINE_CODE = '#PLINE_CODE#'
   AND T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
   AND ROWNUM = 1
</query>
<query id = "FrmVrpApplyNew.SelectNextPlineBelong" desc = "查询下工序产线部门">
SELECT P.DEPARTMENT_CODE,P.DEPARTMENT_DESC
  FROM (SELECT S.ORD_LN_DLY_PK, S.PLN_DIVIDE_ID
          FROM PLN_ZY_DBK_M T, PLN_ORDER_DBK_S S
         WHERE T.PRO_PLAN_ID = S.PRO_PLAN_ID
           AND T.GX_PLAN_NO = S.GX_PLAN_NO
           AND T.HEAT_PLAN_NO = '#HEAT_PLAN_NO_OLD#'
           AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#') E,
       #PLAN# F,
       COM_BASE_PLINE P
 WHERE E.ORD_LN_DLY_PK = F.ORD_LN_DLY_PK
   AND E.PLN_DIVIDE_ID = F.PLN_DIVIDE_ID
   AND F.PLINE_CODE = P.PLINE_CODE
   AND ROWNUM = 1
</query>
<query id = "FrmVrpApplyNew.SelectValueFlag" desc = "查询判定状态">
SELECT T.VALIDFLAG,T.INSTOCK_FLAG
  FROM QCM_ZG_JUGDE_APPLY T
 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.PLINE_CODE = '#PLINE_CODE#'
   AND T.IS_ALL_SCRAP = '0'
</query>
<query id = "FrmVrpApplyNew.SelectValueFlagData" desc = "查询判定状态">
SELECT T.VALIDFLAG,T.INSTOCK_FLAG
  FROM QCM_ZG_JUGDE_APPLY T
 WHERE T.IS_ALL_SCRAP = '0'
</query>
<query id = "FrmVrpApplyNew.deleteQcmJudgeApply" desc = "撤销申请判定">
DECLARE
  V_APPLY_FLAG QCM_ZG_JUGDE_APPLY.APPLY_FLAG%TYPE := NULL;
    V_COUNT NUMBER :=0;
BEGIN
  SELECT T.APPLY_FLAG
    INTO V_APPLY_FLAG
    FROM QCM_ZG_JUGDE_APPLY T
   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.PLINE_CODE = '#PLINE_CODE#'
     AND NVL(T.LOT_NO,'/') = NVL('#LOT_NO#','/')
     AND T.IS_ALL_SCRAP = '0';
  FOR MYROW IN (SELECT *
                  FROM MAT_BC_M T
                 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.PLINE_CODE = '#PLINE_CODE#'
                   AND NVL(T.LOT_NO,'/') = NVL('#LOT_NO#','/')
                UNION
                SELECT *
                  FROM MAT_BC_BACKUP T
                 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.PLINE_CODE = '#PLINE_CODE#'
                   AND NVL(T.LOT_NO,'/') = NVL('#LOT_NO#','/')) LOOP
    UPDATE MAT_BC_M S
       SET S.JUGDE_APPLY_CODE    = '',
           S.JUGDE_APPLY_TIME    = '',
           S.JUGDE_APPLY_SEQUENO = ''
     WHERE S.MAT_NO = MYROW.MAT_NO
       AND S.PLINE_CODE = MYROW.PLINE_CODE;
    UPDATE MAT_BC_BACKUP S
       SET S.JUGDE_APPLY_CODE    = '',
           S.JUGDE_APPLY_TIME    = '',
           S.JUGDE_APPLY_SEQUENO = ''
     WHERE S.MAT_NO = MYROW.MAT_NO
       AND S.PLINE_CODE = MYROW.PLINE_CODE;
    DELETE FROM MAT_BC_QCMTRACK S
     WHERE S.MAT_NO = MYROW.MAT_NO
       AND S.PROCESS_CDOE = MYROW.PROCESS_CDOE;

    IF ('#PROCESS_CDOE#' = 'E') THEN
    UPDATE PORT_VRP_BATCH_SAMPLE_RESULT S
    SET S.JUGDE_APPLY_CODE = '', S.TR_FLAG = '0'
    WHERE S.MAT_NO = MYROW.MAT_NO
    AND S.JUGDE_APPLY_CODE = '#JUGDE_APPLY_CODE#';
    ELSIF ('#PROCESS_CDOE#' = 'F') THEN
    UPDATE PORT_HTT_BATCH_SAMPLE_RESULT S
    SET S.JUGDE_APPLY_CODE = '', S.TR_FLAG = '0'
    WHERE S.MAT_NO = MYROW.MAT_NO
    AND S.JUGDE_APPLY_CODE = '#JUGDE_APPLY_CODE#';
    ELSIF ('#PROCESS_CDOE#' = 'G') THEN
    UPDATE PORT_MCH_BATCH_SAMPLE_RESULT S
    SET S.JUGDE_APPLY_CODE = ''
    WHERE S.MAT_NO = MYROW.MAT_NO
    AND S.JUGDE_APPLY_CODE = '#JUGDE_APPLY_CODE#';
    END IF;



    SELECT COUNT(1)
    INTO V_COUNT
    FROM MCH_TWISTINGLY_JUDGE T
    WHERE T.JUGDE_APPLY_CODE = '#JUGDE_APPLY_CODE#'
    AND T.JUGDE_APPLY_SEQUENO = '#JUGDE_APPLY_SEQUENO#'
    AND T.MAT_NO = MYROW.MAT_NO;

    IF (V_COUNT > 0) THEN
    FOR MYROW1 IN (SELECT *
    FROM MCH_TWISTINGLY_JUDGE T
    WHERE T.JUGDE_APPLY_CODE = '#JUGDE_APPLY_CODE#'
    AND T.JUGDE_APPLY_SEQUENO =
    '#JUGDE_APPLY_SEQUENO#'
    AND T.MAT_NO = MYROW.MAT_NO
    AND ROWNUM = 1) LOOP

    DELETE FROM MCH_TWISTINGLY_JUDGE T
    WHERE T.JUGDE_APPLY_CODE = '#JUGDE_APPLY_CODE#'
    AND T.JUGDE_APPLY_SEQUENO = '#JUGDE_APPLY_SEQUENO#'
    AND T.MAT_NO = MYROW.MAT_NO;

    UPDATE MCH_TWISTINGLY_RESULT_D
    SET JUDGE_NUM = NVL(JUDGE_NUM, 0) - 1
    WHERE RESULT_NO = MYROW1.RESULT_NO
    AND SEQ = MYROW1.SEQ;

    END LOOP;

    END IF;


    END LOOP;
  IF (V_APPLY_FLAG = '1') THEN
    UPDATE QCM_ZG_JUGDE_APPLY T
       SET T.IS_FLAG = '1'
     WHERE T.JUGDE_APPLY_CODE = '#JUGDE_APPLY_CODE#'
       AND T.JUGDE_APPLY_SEQUENO = '#JUGDE_APPLY_SEQUENO#'
       AND NVL(T.GX_PLAN_NO_NEXT, '/') = NVL('#GX_PLAN_NO_NEXT#', '/')
       AND 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#';
  ELSE
    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 NVL(S.GX_PLAN_NO_NEXT, '/') = NVL('#GX_PLAN_NO_NEXT#', '/')
       AND S.BATCH_NO = '#BATCH_NO#'
       AND S.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
       AND S.PLINE_CODE = '#PLINE_CODE#';
  END IF;

  DELETE FROM QCM_ADD_ASK Q
   WHERE Q.JUGDE_APPLY_CODE = '#JUGDE_APPLY_CODE#'
     AND Q.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#';

--更新成品送判量统计表
  SET_QCM_ZC_APPLY2('#ORD_LN_DLY_PK#');

END;
</query>
<query id = "FrmVrpApplyNew.insertMatQcmBack" desc = "插入质量跟踪表">
DECLARE
BEGIN
  FOR MYROW IN (SELECT *
                  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'
                   AND T.PLINE_CODE = '#PLINE_CODE#'
                   AND T.JUGDE_APPLY_CODE = '#JUGDE_APPLY_CODE#' 
                   AND T.JUGDE_APPLY_SEQUENO = '#JUGDE_APPLY_SEQUENO#'
                   AND T.LOT_NO = '#LOT_NO#'
                   UNION
                   SELECT *
                  FROM MAT_BC_BACKUP 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'
                   AND T.PLINE_CODE = '#PLINE_CODE#'
                   AND T.JUGDE_APPLY_CODE = '#JUGDE_APPLY_CODE#' 
                   AND T.JUGDE_APPLY_SEQUENO = '#JUGDE_APPLY_SEQUENO#'
                   AND T.LOT_NO = '#LOT_NO#'
                 ) LOOP
    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
      (MYROW.MAT_NO,
       MYROW.PROCESS_CDOE,
       MYROW.STOVE_NO,
       MYROW.JUDGE_STOVE_NO,
       MYROW.BATCH_NO,
       MYROW.GRADECODE,
       MYROW.GRADENAME,
       MYROW.MATERIAL_NO,
       MYROW.MATERIAL_NAME,
       '#JUGDE_APPLY_CODE#',
       TO_DATE('#APPLY_TIME#','YYYY-MM-DD HH24:MI:SS'),
       '#APPLY_NAME#');
  END LOOP;
END;
</query>

<query id = "FrmVrpApplyNew.SelectIsWic" desc = "查询是否有水压要求">
SELECT COUNT(1) ACOUNT
  FROM CRAFT_ORD_DESIGN_MSC_PL_PRC T, CRAFT_ORD_DESIGN_STD_WIC W
 WHERE T.DESGIN_KEY = W.DESGIN_KEY
   AND T.MSC_PLINE = W.MSC_PLINE
   and t.PROCESS_CODE = W.PROCESS_CODE
   AND W.SPECL_FL = '2'
   AND T.PROCESS_CODE = ?
   AND T.DESGIN_KEY = ?
</query>

<query id = "FrmVrpApplyNew.doQueryWicValue" desc = "查询水压">
select t.*
  from MCH_WATERGAGE_RESULT t
 WHERE T.HEAT_PLAN_NO = ?
   AND T.JUDGE_STOVE_NO = ?
</query>

<query id = "FrmVrpApplyNew.doQueryMchPathResult" desc = "查询加工通径结果">
select MAX(T.DRIFT_MODEL_MIN) DRIFT_MODEL_MIN,
       MAX(T.DRIFT_MODEL_MIN2) DRIFT_MODEL_MIN2,
       MAX(T.DRIFT_MODEL_LEN) DRIFT_MODEL_LEN,
       MAX(T.DRIFT_MODEL_LEN2) DRIFT_MODEL_LEN2,
       MIN(T2.MEASURED_END_PART) MEASURED_END_PART,
       MIN(T2.MEASURED_MIDDLE_PART) MEASURED_MIDDLE_PART,
       MIN(T2.MEASURED_TAIL_PART) MEASURED_TAIL_PART,
       COUNT(1) ACOUNT
  from MCH_PATH_RESULT t, MCH_PATH_RESULT_D T2
 WHERE T.HEAT_PLAN_NO = T2.HEAT_PLAN_NO(+)
   AND T.HEAT_PLAN_NO = ?
   AND T.JUDGE_STOVE_NO = ?
</query>

<query id = "FrmVrpApplyNew.doQueryMchChamferingResult" desc = "查询加工倒棱结果">
select t.*
  from MCH_CHAMFERING_RESULT t
 WHERE T.HEAT_PLAN_NO = ?
   AND T.JUDGE_STOVE_NO = ?
</query>

<query id = "FrmVrpApplyNew.doQueryMchTwistinglyResult" desc = "查询加工拧接结果">
select t.*
  from MCH_TWISTINGLY_RESULT t
 WHERE T.HEAT_PLAN_NO = ?
   AND T.JUDGE_STOVE_NO = ?
</query>

<query id = "FrmVrpApplyNew.doQueryHttCrackDetectionEt" desc = "查询探伤结果">
<![CDATA[
SELECT listagg(TESTING_GRADE, ',') within GROUP(order by TESTING_GRADE) over(partition by '') TESTING_GRADE,
       listagg(TESTING_TYPE, ',') within GROUP(order by TESTING_GRADE) over(partition by '') TESTING_TYPE
  FROM (select DISTINCT T.TESTING_GRADE, T.TESTING_TYPE
          from HTT_CRACK_DETECTION_ET t
         WHERE T.HEAT_PLAN_NO = ?
           AND T.JUDGE_STOVE_NO = ?
           AND T.PROCESS_CODE = ?)
 ]]>
</query>

<query id = "FrmVrpApplyNew.SelectQcmZgData" desc = "查询送判表支数">
SELECT SUM(T.ACT_COUNT) ACT_COUNT
  FROM QCM_ZG_JUGDE_APPLY T
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.PLINE_CODE = ?
   AND T.PROCESS_CODE = 'F'
</query>

<query id = "FrmVrpApplyNew.SelectTestingStandar" desc = "查询探伤标准">
<![CDATA[
SELECT WMSYS.WM_CONCAT(DISTINCT T2.STANDARD_NAME) TESTING_STANDAR
  FROM HTT_CRACK_DETECTION_PARA T1, HTT_CRACK_DETECTION_STANDARD T2
 WHERE T1.STANDARD_ID = T2.STANDARD_ID
   AND T1.HEAT_PLAN_NO = '#HEAT_PLAN_NO_OLD#'
 ]]>
</query>

<query id = "FrmVrpApplyNew.SelectInputCountVrp" desc = "查询镦拔扩投料量">
<![CDATA[
select SUM(S.ACT_COUNT) ACT_COUNT,
       SUM(NVL(S.ACT_THEORY_WEIGHT, S.ACT_WEIGHT)) ACT_WEIGHT
  from PLN_ZY_DBK_M T,PORT_VRP_BATCH_SAMPLE_RESULT S
 WHERE T.HEAT_PLAN_NO = S.HEAT_PLAN_NO
  AND T.HEAT_PLAN_NO = '#HEAT_PLAN_NO_OLD#'
 --AND T.PRO_PLAN_ID = '#PRO_ORDER_ID#'
 --AND T.GX_PLAN_NO = '#GX_PLAN_NO#'
 AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
 AND S.PHY_BATCH_NO = '#BATCH_NO#'
 ]]>
</query>

<query id = "FrmVrpApplyNew.SelectInputCountHtt" desc = "查询热处理投料量">
<![CDATA[
select SUM(S.ACT_COUNT) ACT_COUNT,
       SUM(NVL(S.ACT_THEORY_WEIGHT, S.ACT_WEIGHT)) ACT_WEIGHT
       --SUM(NVL(S.ACT_WEIGHT, S.ACT_THEORY_WEIGHT)) ACT_WEIGHT
  from PLN_ZY_RCL_M T,PORT_HTT_BATCH_SAMPLE_RESULT S
 WHERE T.HEAT_PLAN_NO = S.HEAT_PLAN_NO
 --AND T.PRO_PLAN_ID = '#PRO_ORDER_ID#'
 AND T.HEAT_PLAN_NO = '#HEAT_PLAN_NO_OLD#'
 --AND T.GX_PLAN_NO = '#GX_PLAN_NO#'
 AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
 AND S.PROCESS_SEQ = '1'
 AND S.PHY_BATCH_NO = '#BATCH_NO#'
 ]]>
</query>

<query id = "FrmVrpApplyNew.SelectInputCountMch" desc = "查询加工投料量">
<![CDATA[
select SUM(S.ACT_COUNT) ACT_COUNT,
       SUM(NVL(S.ACT_THEORY_WEIGHT, S.ACT_WEIGHT)) ACT_WEIGHT
       --SUM(NVL(S.ACT_WEIGHT, S.ACT_THEORY_WEIGHT)) ACT_WEIGHT
  from PLN_ZY_JGX_M T,PORT_MCH_BATCH_SAMPLE_RESULT S
 WHERE T.HEAT_PLAN_NO = S.HEAT_PLAN_NO
 --AND T.PRO_PLAN_ID = '#PRO_ORDER_ID#'
  AND T.HEAT_PLAN_NO = '#HEAT_PLAN_NO_OLD#'
 --AND T.GX_PLAN_NO = '#GX_PLAN_NO#'
 AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
 AND S.PHY_BATCH_NO = '#BATCH_NO#'
 ]]>
</query>

<query id = "FrmVrpApplyNew.SelectBatchNoVrp" desc = "查询镦拔扩已送判的批号">
<![CDATA[
select T.*
  from QCM_ZG_JUGDE_APPLY T
 WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
   AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND T.PROCESS_CODE = 'E'
 ]]>
</query>

<query id = "FrmVrpApplyNew.SelectBatchNoHtt" desc = "查询热处理已送判的批号">
<![CDATA[
select T.*
  from QCM_ZG_JUGDE_APPLY T
 WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
   AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND T.PROCESS_CODE = 'F'
 ]]>
</query>

<query id = "FrmVrpApplyNew.SelectBatchNoMch" desc = "查询加工已送判的批号">
<![CDATA[
select T.*
  from QCM_ZG_JUGDE_APPLY T
 WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
   AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND T.PROCESS_CODE = 'G'
 ]]>
</query>

<query id = "FrmVrpApplyNew.SelectInputCount" desc = "查询">
<![CDATA[
select *
  from QCM_ZG_JUGDE_APPLY t
 WHERE T.PLINE_CODE = '#PLINE_CODE#'
   AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND T.HEAT_PLAN_NO = '#HEAT_PLAN_NO_OLD#'
   AND T.BATCH_NO = '#BATCH_NO#'
   AND T.PROCESS_CODE = '#PROCESS_CDOE#'
   AND T.INPUT_COUNT > 0
 ]]>
</query>

<query id = "FrmVrpApplyNew.doQueryQcmZgApplyData" desc = "查询加工线前紧急放行数据">
<![CDATA[
SELECT  T.*
  FROM QCM_ZG_JUGDE_APPLY T
 WHERE T.INSTANCY_FLAG = '1'
   AND (T.JUDGE_RESULT is null OR T.JUDGE_RESULT = '不合格')
 ]]>
</query>

<query id = "FrmVrpApplyNew.doQueryQcmZgApplyData2" desc = "查询加工线前紧急放行数据">
<![CDATA[
SELECT  T.*
  FROM QCM_ZG_JUGDE_APPLY T
 WHERE T.INSTANCY_FLAG = '1'
 ]]>
</query>
<query id = "FrmVrpApplyNew.SelectJudegApplyCount" desc = "查询是否已送判定过">
SELECT COUNT(1) ACOUNT
  FROM QCM_ZG_JUGDE_APPLY T
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.PROCESS_CODE = ?
   AND T.IS_FLAG = '0'
   AND T.IS_ALL_SCRAP IN ('0', '1')
</query>

<query id = "FrmVrpApplyNew.SelectCount" desc = "查询上工序不合格数据">
<![CDATA[
 SELECT COUNT(1) ACOUNT
  FROM QCM_ZG_JUGDE_APPLY T
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.PROCESS_CODE <> ?
   AND T.BATCH_NO = ?
   AND T.IS_FLAG = '0'
   AND T.IS_ALL_SCRAP = '0'
   AND T.JUDGE_RESULT_CODE NOT IN ('40740701', '40740707', '40740709')
    ]]>
</query>
<query id = "FrmVrpApplyNew.SelectIsGroupE" desc = "查询炉计划标识">
SELECT T.IF_MATCH_ODD FROM PLN_ZY_DBK_M T WHERE T.HEAT_PLAN_NO = ? AND T.JUDGE_STOVE_NO = ?
</query>
<query id = "FrmVrpApplyNew.SelectIsGroupF" desc = "查询炉计划标识">
SELECT T.IF_MATCH_ODD FROM PLN_ZY_RCL_M T WHERE T.HEAT_PLAN_NO = ? AND T.JUDGE_STOVE_NO = ?
</query>
<query id = "FrmVrpApplyNew.SelectIsGroupG" desc = "查询炉计划标识">
SELECT T.IF_MATCH_ODD FROM PLN_ZY_JGX_M T WHERE T.HEAT_PLAN_NO = ? AND T.JUDGE_STOVE_NO = ?
</query>
<query id = "FrmVrpApplyNew.SelectHeatPlanNoVrp" desc = "查询炉计划ID订单下">
SELECT T.HEAT_PLAN_NO
  FROM PLN_ZY_DBK_M T
 WHERE T.PRO_PLAN_ID = '#PRO_PLAN_ID#'
   AND T.GX_PLAN_NO = '#GX_PLAN_NO#'
   AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND T.IF_MATCH_ODD IN('0','1')
</query>
<query id= "FrmVrpApplyNew.SelectHeatPlanNoHtt" desc = "查询热处理炉计划ID">
SELECT T.HEAT_PLAN_NO
  FROM PLN_ZY_RCL_M T
 WHERE T.PRO_PLAN_ID = '#PRO_PLAN_ID#'
   AND T.GX_PLAN_NO = '#GX_PLAN_NO#'
   AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND T.IF_MATCH_ODD IN('0','1')
</query>
<query id= "FrmVrpApplyNew.SelectHeatPlanNoMch" desc = "查询热处理炉计划ID">
SELECT T.HEAT_PLAN_NO
  FROM PLN_ZY_JGX_M T
 WHERE T.PRO_PLAN_ID = '#PRO_PLAN_ID#'
   AND T.GX_PLAN_NO = '#GX_PLAN_NO#'
   AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND T.IF_MATCH_ODD IN('0','1')
</query>
<query id = "FrmVrpApplyNew.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 = "FrmVrpApplyNew.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,
                              SLM_ORDER_LINE_DELIVERY D
                        WHERE A.ORD_PK = B.ORD_PK
                          AND B.ORD_PK = D.ORD_PK
                          AND B.ORD_LN_PK = D.ORD_LN_PK
                          AND C.ORD_LN_PK = B.ORD_LN_PK
                          AND C.VALIDFLAG = '1'
                          AND D.ORD_LN_DLY_PK = ?)
  ]]>
</query>

<query id = "FrmVrpApplyNew.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,
        BUNDLE_NUM)
 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,
        '#BUNDLE_NUM#')
  ]]>
</query>

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

<query id = "FrmVrpApplyNew.updateBundleNum" desc = "回报捆数">
<![CDATA[
DECLARE
  V_JUGDE_APPLY_CODE QCM_ADD_ASK.JUGDE_APPLY_CODE%type := ?;
  V_JUDGE_STOVE_NO   QCM_ADD_ASK.JUDGE_STOVE_NO%type := ?;
  V_BUNDLE_NUM       QCM_ADD_ASK.BUNDLE_NUM%type := 0;
BEGIN
  SELECT T.BUNDLE_NUM
    INTO V_BUNDLE_NUM
    FROM QCM_ADD_ASK T
   WHERE T.JUGDE_APPLY_CODE = V_JUGDE_APPLY_CODE
     AND T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
     AND T.BUNDLE_NUM > 0;

  IF (V_BUNDLE_NUM > 0) THEN
    UPDATE QCM_ZG_JUGDE_APPLY T
       SET T.BUNDLE_NUM = V_BUNDLE_NUM
     WHERE T.JUGDE_APPLY_CODE = V_JUGDE_APPLY_CODE
       AND T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO;
  END IF;
END;
  ]]>
</query>

    <query id = "FrmVrpApplyNew.DoUpdateJudge1" desc = "">
        <![CDATA[

       UPDATE  QCM_ZG_JUGDE_APPLY SET    TESTING_GRADE=? , TESTING_TYPE=?,  TESTING_STANDAR=?         WHERE JUGDE_APPLY_CODE=?
  ]]>
    </query>

    <query id = "FrmVrpApplyNew.DoUpdateJudge2" desc = "">
        <![CDATA[
       UPDATE QCM_ZBS_CRAFT_RESULT SET TESTING_GRADE=? , TESTING_TYPE=?,  TESTING_STANDAR=?       WHERE zbs_id IN (       SELECT ZBS_ID FROM QCM_ZBS_INFO I,QCM_ZG_JUGDE_APPLY Q WHERE
       I.JUDGE_STOVE_NO = Q.JUDGE_STOVE_NO AND I.BATCH_NO =Q.BATCH_NO AND Q.JUGDE_APPLY_CODE =?) AND PROCESS_CODE = 'G'
  ]]>
    </query>

    <query id = "FrmVrpApplyNew.DoUpdateJudge3" desc = "">
        <![CDATA[

       UPDATE  QCM_ZG_JUGDE_APPLY SET    NOTCH_LENGTH=? , NOTCH_WIDTH=?,  NOTCH_DEPTH=?,
                 HTT_TYPE = ?,MIN_TEMP=?,HTT_TECHNOLOGY=?
           WHERE JUGDE_APPLY_CODE=?
  ]]>
    </query>

    <query id = "FrmVrpApplyNew.DoUpdateJudge4" desc = "">
        <![CDATA[
       UPDATE QCM_ZBS_CRAFT_RESULT SET NOTCH_LENGTH=? , NOTCH_WIDTH=?,  NOTCH_DEPTH=?,
                 HTT_TYPE = ?,MIN_TEMP=?,HTT_TECHNOLOGY=?
                       WHERE zbs_id IN (       SELECT ZBS_ID FROM QCM_ZBS_INFO I,QCM_ZG_JUGDE_APPLY Q WHERE
       I.JUDGE_STOVE_NO = Q.JUDGE_STOVE_NO AND I.BATCH_NO =Q.BATCH_NO AND Q.JUGDE_APPLY_CODE =?) AND PROCESS_CODE = 'F'
  ]]>
    </query>


    <query id = "FrmVrpApplyNew.doCheckIsMeasure" desc = "">
        <![CDATA[
SELECT COUNT(1) COUNT FROM PORT_MCH_BATCH_SAMPLE_RESULT P,  MAT_BC_M T
                 WHERE P.MAT_NO = T.MAT_NO
                    AND P.JUDGE_STOVE_NO = T.JUDGE_STOVE_NO
                   AND P.PHY_BATCH_NO = T.BATCH_NO
                     AND 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.PRO_ORDER_ID = '#PRO_ORDER_ID#'
                   AND T.GX_PLAN_NO = '#GX_PLAN_NO#'
                   AND T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
                   AND T.QCM_STAUS = '00'
                   AND T.JUGDE_APPLY_CODE IS NULL
                   AND P.TR_FLAG = '0'
  ]]>
    </query>

    <query id = "FrmVrpApplyNew.SelectUnFinalCheckCount" desc = "未经过复检的管号支">
        SELECT COUNT(DISTINCT T.MAT_NO ) COUNT
        FROM MAT_BC_M T LEFT JOIN   MCH_FINAL_CHECK_RESULT_MAT_NO D ON T.MAT_NO = D.MAT_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.PLINE_CODE = '#PLINE_CODE#'
        AND T.PRO_ORDER_ID = '#PRO_ORDER_ID#'
        AND T.GX_PLAN_NO = '#GX_PLAN_NO#'
        AND T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
        AND T.QCM_STAUS = '00'
        AND T.JUGDE_APPLY_CODE IS NULL
        AND D.MAT_NO IS NULL
    </query>


    <query id = "FrmVrpApplyNew.SelectUnCheckTreatmentCount" desc = "未经过复检的管号支">

        SELECT COUNT(1) COUNT FROM mch_final_check_result_d d,mch_final_check_treatment t WHERE t.result_no = d.result_no AND
        mat_No IN( SELECT mat_No  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.PRO_ORDER_ID = '#PRO_ORDER_ID#'
        AND T.GX_PLAN_NO = '#GX_PLAN_NO#'
        AND T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
        AND T.QCM_STAUS = '00'
        AND T.JUGDE_APPLY_CODE IS NULL)
        AND APPROVAL_STATUS != '2'
    </query>
    
    <query id = "FrmVrpApplyNew.SelectMatbc" desc = "查询材料在不在材料表">
SELECT SUM(T.ACT_COUNT) ACOUNT
  FROM MAT_BC_M T
 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.PLINE_CODE = '#PLINE_CODE#'
</query>
 <query id = "FrmVrpApplyNew.SelectPassApply" desc = "查询是否已紧急放行">
SELECT COUNT(1) ACOUNT
  FROM QCM_BC_PASS_APPLY T
 WHERE T.JUGDE_APPLY_CODE = '#JUGDE_APPLY_CODE#'
   AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND T.BATCH_NO = '#BATCH_NO#'
   AND T.VALIDFLAG = '1'
</query>
<!--<query id = "FrmVrpApplyNew.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.QCM_STAUS = '00'
   AND T.JUDGE_STOVE_NO = ?
   AND T.PROCESS_CDOE = ?
   AND ROWNUM = 1
</query>

-->
<query id = "FrmVrpApplyNew.selectSupplyUnit" desc= "查询制造商按产线">
SELECT C.SUPPLY_UNIT_CODE SUPPLY_UNIT, C.SUPPLY_UNIT SUPPLY_UNIT_DESC
  FROM MAT_BC_M T, COM_BASE_PLINE C
 WHERE T.PLINE_CODE = C.PLINE_CODE
   AND T.QCM_STAUS = '00'
   AND T.JUDGE_STOVE_NO = ?
   AND T.PROCESS_CDOE = ?
   AND ROWNUM = 1
</query>

<query id = "FrmVrpApplyNew.DoKpFlag" desc = "标识空跑">
<![CDATA[
UPDATE QCM_ZG_JUGDE_APPLY T
   SET T.KP_FLAG = DECODE('#KP_FLAG#', '1', '', '1')
 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.PLINE_CODE = '#PLINE_CODE#'
  ]]>
</query>

<query id = "FrmVrpApplyNew.SelectCarryVoerStatus" desc = "查询是否结转">
<![CDATA[
SELECT T.IS_CARRY_VOER
  FROM QCM_ZG_JUGDE_APPLY T
 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.PLINE_CODE = '#PLINE_CODE#'
  ]]>
</query>

	<query id = "FrmVrpApplyNew.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 = "FrmVrpApplyNew.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必检 3免检

  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 T.VALIDFLAG = '1';

  --类型（0-普通品种，1-特殊品种）
  SELECT CASE
           WHEN ('#GRADENAME#' = '20' OR '#STEELNAME#' = '20') AND
                (INSTR('#STD_NAME#', '8162') > 0 OR
                INSTR('#STD_NAME#', '8163') > 0 OR
                INSTR('#STD_NAME#', '3087') > 0) THEN
            '0'
           ELSE
            '1'
         END
    INTO V_TYPE
    FROM DUAL;

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

  --查钢种
  IF (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#';
  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#';
  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#';
  END IF;

  --需要复检
  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)
      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,
             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
        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 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.TARGET = 'A'
             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#'
             AND T1.TARGET = 'A');

  --找库存信息
  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.TARGET = 'A'
     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;

  --报检支吨
  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)
    VALUES
      (V_INSPECTION_NO,
       '1',
       '#HEAT_PLAN_NO#',
       V_ZY_BATCH_ID,
       '#JUDGE_STOVE_NO#',
       '#BATCH_NO#',
       V_FLAG,
       '',
       '#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);
  
    --增加子表
    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 = 'D'
                      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 = "FrmVrpApplyNew.doQueryPlineCodeBM" desc = "">
	<![CDATA[
select COUNT(1) ACOUNT from COM_BASE_PLINE t WHERE   INSTR(T.DEPARTMENT_DESC_P,'轧管') > 0
 ]]>
</query>

</queryMap>