<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="轧管测量实绩">
<query id="FrmMeasureResultZG.doQuery" desc="查询">
        <![CDATA[
SELECT T.ID,
       REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') JUDGE_STOVE_NO,
       T.LOT_NO,
       T.CONTRACT_NO,
       --T1.BATCH_NO,
       T.PLINE_CODE,
       T2.PLINE_NAME,
       T.VARIETIES,
       T.BUCKLE_TYPE,
       T.PIPE_SIZE,
       T.GRADENAME,
       T.STEELNAME,
       T.PRO_PLAN_ID,
       T.GX_PLAN_NO,
       T.STD_STYLE,
       T.ROLL_STANDRAD,
       T.PRODUCE_STANDRAD,
       (SELECT SUM(M.PRO_NUM)
          FROM MIL_MEASURE_RESULT M
         WHERE M.HEAT_PLAN_NO = T.ID
           AND M.JUDGE_STOVE_NO = REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '')
        /*AND M.BATCH_NO = T1.BATCH_NO*/
        ) PRO_NUM,
       (SELECT SUM(M.PRO_WT)
          FROM MIL_MEASURE_RESULT M
         WHERE M.HEAT_PLAN_NO = T.ID
           AND M.JUDGE_STOVE_NO = REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '')
        /*AND M.BATCH_NO = T1.BATCH_NO*/
        ) PRO_WT,
       (SELECT COUNT(DISTINCT R.MAT_NO)
          FROM RTD_MEASURE_POSDATA R
         WHERE R.JUDGE_STOVE_NO = REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '')
              --AND R.BATCH_NO = T1.BATCH_NO
           AND R.PLINE_CODE = T.PLINE_CODE
           AND R.FLAG = '00') Measure_Count
  FROM MIL_PLAN T, /* PORT_MIL_BATCH_SAMPLE_RESULT T1,*/ COM_BASE_PLINE T2
 WHERE SUBSTR(T.JUDGE_STOVE_NO, -1) = '1'
   --AND T.PRT_FLAG = '1'
   --AND T.TARGET = 'A'
   AND T.PLINE_CODE = T2.PLINE_CODE
/*AND T.ID = T1.PLAN_ID
AND REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')*/
--AND  REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '')  = '104205'
#someThing#
 GROUP BY T.ID,
          REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', ''),
          --T1.BATCH_NO,
          T.LOT_NO,
          T.CONTRACT_NO,
          T.PLINE_CODE,
          T2.PLINE_NAME,
          T.VARIETIES,
          T.BUCKLE_TYPE,
          T.PIPE_SIZE,
          T.GRADENAME,
          T.STEELNAME,
          T.PRO_PLAN_ID,
          T.GX_PLAN_NO,
          T.STD_STYLE,
          T.ROLL_STANDRAD,
          T.PRODUCE_STANDRAD
        ]]>
	</query>
	
	<query id="FrmMeasureResultZG.geRtdMeasurePosdata2" desc="">
		<![CDATA[
SELECT T.*,   DENSE_RANK() OVER(PARTITION BY JUDGE_STOVE_NO, BATCH_NO, TO_NUMBER(MAT_NO) ORDER BY MAT_NO_CX ASC, MSAUER_DATE DESC, KEY_ID DESC) RK
  FROM RTD_MEASURE_POSDATA T
 WHERE 1=1
		]]>
	</query>
	
	<query id="FrmMeasureResultZG.doQueryMilMeasureResult" desc="查询量测点实绩">
        <![CDATA[
select result_no,
       heat_plan_no,
       pro_plan_id,
       gx_plan_no,
       lot_no,
       judge_stove_no,
       batch_no,
       stove_no,
       pline_code,
       pline_name,
       if_monitor_rcl,
       prdcr_no,
       producer,
       producer_time,
       outnum_cut,
       pro_num,
       pro_wt,
       pro_year_month_day,
       bal_year_month,
       decode(pro_shift, '1', '早', '2', '中', '3', '晚') pro_shift,
       decode(pro_group, '1', '甲', '2', '乙', '3', '丙', '4', '丁') pro_group,
       create_time,
       pro_user,
       pro_time,
       pr_provider,
       pr_type,
       use_pc,
       use_ar,
       ar_count,
       special_drift,
       cc_count,
       is_paint,
       paint_type,
       paint_lot,
       flag,
       pro_end_time,
       memo
  from MIL_MEASURE_RESULT t
 WHERE T.HEAT_PLAN_NO = ?
   AND T.JUDGE_STOVE_NO = ?
   AND T.PLINE_CODE = ?
        ]]>
	</query>
	<query id="FrmMeasureResultZG.queryMilplan" desc="查询计划信息">
        <![CDATA[
select t.*, T1.PLINE_NAME
  from MIL_PLAN t, COM_BASE_PLINE T1
 WHERE T.PLINE_CODE = T1.PLINE_CODE
   AND T.ID = ?
   AND REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = ?
        ]]>
	</query>
	<query id="FrmMeasureResultZG.doQueryPortMilBatchSampleResult" desc="查询进程表数据">
        <![CDATA[
select T.MAT_NO,
       T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       T1.PLINE_NAME,
       DECODE(T.IS_SAMPLE_PIPE, '1', '是', '否') IS_SAMPLE_PIPE,
       T.MEASURE_LEN,
       T.MEASURE_WEIGHT,
       T.MEASURING_SEQ,
       DECODE(T.STATUS,
              '0',
              '合格',
              '1',
              '热轧废',
              '2',
              '精整废',
              '3',
              '离线',
              '6',
              '委外废') STATUS,
       T.MAT_INFO,
       T.ACT_COUNT,
       NVL(T.ACT_THEORY_WEIGHT_BAK, T.ACT_THEORY_WEIGHT) ACT_THEORY_WEIGHT,
       DECODE(T.MEASURING_FLAG, '1', '已匹配', '0', '未匹配') MEASURING_FLAG
  from PORT_MIL_BATCH_SAMPLE_RESULT t, COM_BASE_PLINE T1
 WHERE T.PLINE_CODE = T1.PLINE_CODE
   AND T.STATUS <> '4'
   AND T.PLAN_ID = ?
   AND REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = ?
   AND T.PLINE_CODE = ?
        ]]>
	</query>
	<query id="FrmMeasureResultZG.DoAddMeasureData" desc="Excel导入">
		<![CDATA[
    INSERT INTO RTD_MEASURE_POSDATA
  (KEY_ID,
   PLINE_CODE,
   PLINE_NAME,
   JUDGE_STOVE_NO,
   BATCH_NO,
   MAT_NO,
   /*ACT_LEN,*/
   ACT_WEIGHT,
   FLAG,
   MAT_INFO,
   PRO_ORDER_NO,
   CREATE_USER)
VALUES
  ((SELECT 'M' || TO_CHAR(SYSDATE, 'yyyyMMDD') ||
          LPAD(NVL(MAX(TO_NUMBER(SUBSTR(KEY_ID, LENGTH(KEY_ID) - 5))), 0) + 1,
               6,
               '0') KEY_ID
     FROM RTD_MEASURE_POSDATA
    WHERE KEY_ID LIKE 'M' || TO_CHAR(SYSDATE, 'yyyyMMDD') || '______'),
   '#PLINE_CODE#',
   '#PLINE_NAME#',
   '#JUDGE_STOVE_NO#',
   '#BATCH_NO#',
   '#MAT_NO#',
   /* '#ACT_LEN#',*/
   '#ACT_WEIGHT#',
   '#FLAG#',
   '#MAT_INFO#',
   '#PRO_ORDER_NO#',
   '#CREATE_USER#')
        ]]>
	</query>
	<query id="FrmMeasureResultZG.doSaveMeasuringSeq" desc="保存喷印管号">
        <![CDATA[
DECLARE
  V_HEAT_PLAN_NO      PLN_ZY_ZG_M.HEAT_PLAN_NO%type := ?;
  V_JUDGE_STOVE_NO    PORT_MIL_BATCH_SAMPLE_RESULT.JUDGE_STOVE_NO%type := ?;
  V_PLINE_CODE        PORT_MIL_BATCH_SAMPLE_RESULT.PLINE_CODE%type := ?;
  V_MEASURING_SEQ     PORT_MIL_BATCH_SAMPLE_RESULT.MEASURING_SEQ%type := ?;
  V_MEASURING_SEQ_LEN PORT_MIL_BATCH_SAMPLE_RESULT.MEASURING_SEQ%type := ?;
  V_NUM               PORT_MIL_BATCH_SAMPLE_RESULT.MEASURING_SEQ%type := NULL;
BEGIN
  V_NUM := V_MEASURING_SEQ;
  FOR MYROW IN (SELECT *
                  FROM PORT_MIL_BATCH_SAMPLE_RESULT T
                 WHERE T.MEASURING_SEQ IS NOT NULL
                   AND T.STATUS = '0'
                   AND T.PLAN_ID = V_HEAT_PLAN_NO
                   AND REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = V_JUDGE_STOVE_NO
                   AND T.PLINE_CODE = V_PLINE_CODE) LOOP
  
    UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T
       SET T.MEASURING_SEQ = V_NUM
     WHERE T.MEASURING_SEQ IS NOT NULL
       AND T.STATUS = '0'
       AND T.PLAN_ID = V_HEAT_PLAN_NO
       AND REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = V_JUDGE_STOVE_NO
       AND T.PLINE_CODE = V_PLINE_CODE
       AND T.MAT_NO = MYROW.MAT_NO;
    V_NUM := V_NUM + V_MEASURING_SEQ_LEN;
  END LOOP;
END;
        ]]>
	</query>
	<query id="FrmMeasureResultZG.doSaveMatInfo" desc="发送喷印信息">
        <![CDATA[
DECLARE
  V_HEAT_PLAN_NO   PLN_ZY_ZG_M.HEAT_PLAN_NO%type := ?;
  V_JUDGE_STOVE_NO PORT_MIL_BATCH_SAMPLE_RESULT.JUDGE_STOVE_NO%type := ?;
  V_PLINE_CODE     PORT_MIL_BATCH_SAMPLE_RESULT.PLINE_CODE%type := ?;
  V_MAT_INFO_START PORT_MIL_BATCH_SAMPLE_RESULT.MAT_INFO%type := ?;
  V_MAT_INFO_END   PORT_MIL_BATCH_SAMPLE_RESULT.MAT_INFO%type := ?;

BEGIN
  UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T
     SET T.MAT_INFO = V_MAT_INFO_START || ' ' ||
                      TO_CHAR(T.MEASURING_SEQ, 'FM0000') || ' ' ||
                      V_MAT_INFO_END
   WHERE T.MEASURING_SEQ IS NOT NULL
     AND T.STATUS = '0'
     AND T.PLAN_ID = V_HEAT_PLAN_NO
     AND REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = V_JUDGE_STOVE_NO
     AND T.PLINE_CODE = V_PLINE_CODE;
END;
        ]]>
	</query>
	<query id="FrmMeasureResultZG.queryResultNo" desc="获取最大实绩编号">
        <![CDATA[
SELECT ? || TO_CHAR(SYSDATE, 'yyyyMMDD') ||
         LPAD(NVL(MAX(TO_NUMBER(SUBSTR(RESULT_NO, LENGTH(RESULT_NO) - 5))),
                  0) + 1,
              6,
              '0') RESULT_NO
    FROM  MIL_MEASURE_RESULT
   WHERE RESULT_NO LIKE ? || TO_CHAR(SYSDATE, 'yyyyMMDD') || '______'
        ]]>
	</query>
	<query id="FrmMeasureResultZG.queryProWt" desc="获取重量">
        <![CDATA[
select SUM(T.MEASURE_WEIGHT) MEASURE_WEIGHT from PORT_MIL_BATCH_SAMPLE_RESULT t WHERE T.MEASURE_RESULT_NO = ?
        ]]>
	</query>
	<query id="FrmMeasureResultZG.updatePort" desc="更新管号队列">
        <![CDATA[
DECLARE
  V_HEAT_PLAN_NO      PLN_ZY_ZG_M.HEAT_PLAN_NO%type := ?;
  V_JUDGE_STOVE_NO    PORT_MIL_BATCH_SAMPLE_RESULT.JUDGE_STOVE_NO%type := ?;
  V_BATCH_NO          PORT_MIL_BATCH_SAMPLE_RESULT.BATCH_NO%type := ?;
  V_PLINE_CODE        PORT_MIL_BATCH_SAMPLE_RESULT.PLINE_CODE%type := ?;
  V_PRO_NUM           MIL_MEASURE_RESULT.PRO_NUM%type := ?;
  V_MEASURE_RESULT_NO PORT_MIL_BATCH_SAMPLE_RESULT.MEASURE_RESULT_NO%type := ?;
BEGIN

  FOR MYROW IN (SELECT *
                  FROM PORT_MIL_BATCH_SAMPLE_RESULT T
                 WHERE T.MEASURING_SEQ IS NULL
                   AND T.STATUS = '0'
                   AND T.PLAN_ID = V_HEAT_PLAN_NO
                   AND REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') =
                       V_JUDGE_STOVE_NO
                   AND DECODE(V_BATCH_NO, '', '/', T.BATCH_NO) =
                       DECODE(V_BATCH_NO, '', '/', V_BATCH_NO)
                   AND T.PLINE_CODE = V_PLINE_CODE
                   AND ROWNUM <= V_PRO_NUM) LOOP
  
    FOR MYROW1 IN (SELECT *
                     FROM RTD_MEASURE_POSDATA T1
                    WHERE T1.FLAG = '00'
                      AND T1.MAT_NO_CX IS NULL
                      AND T1.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
                      AND DECODE(V_BATCH_NO, '', '/', T1.BATCH_NO) =
                          DECODE(V_BATCH_NO, '', '/', V_BATCH_NO)
                      AND T1.PLINE_CODE = V_PLINE_CODE
                      AND T1.KEY_ID =
                          (SELECT MIN(T1.KEY_ID)
                             FROM RTD_MEASURE_POSDATA T1
                            WHERE T1.FLAG = '00'
                              AND T1.MAT_NO_CX IS NULL
                              AND T1.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
                              AND DECODE(V_BATCH_NO, '', '/', T1.BATCH_NO) =
                                  DECODE(V_BATCH_NO, '', '/', V_BATCH_NO)
                              AND T1.PLINE_CODE = V_PLINE_CODE)) LOOP
    
      UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T
         SET T.MEASURING_FLAG        = '1',
             T.MEASURING_SEQ         = MYROW1.MAT_NO,
             T.MEASURE_LEN           = MYROW1.ACT_LEN / 1000,
             T.MEASURE_WEIGHT        = MYROW1.ACT_WEIGHT / 1000,
             T.ACT_THEORY_WEIGHT_BAK = T.ACT_THEORY_WEIGHT,
            --T.ACT_THEORY_WEIGHT     = MYROW1.ACT_WEIGHT / 1000,
             T.MAT_INFO              = MYROW1.MAT_INFO,
             T.MEASURE_RESULT_NO     = V_MEASURE_RESULT_NO
       WHERE T.MEASURING_SEQ IS NULL
         AND T.STATUS = '0'
         AND T.PLAN_ID = V_HEAT_PLAN_NO
         AND REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = V_JUDGE_STOVE_NO
         AND T.PLINE_CODE = V_PLINE_CODE
         AND T.MAT_NO = MYROW.MAT_NO;
    
      UPDATE RTD_MEASURE_POSDATA T1
         SET T1.MAT_NO_CX = MYROW.MAT_NO
       WHERE T1.KEY_ID = MYROW1.KEY_ID;
    
      /*UPDATE MAT_BC_M
         SET ACT_LEN         = MYROW1.ACT_LEN / 1000,
             ACT_WEIGHT      = MYROW1.ACT_WEIGHT / 1000,
             PONDER_GROSS_WT = MYROW1.ACT_WEIGHT / 1000
       WHERE ZG_MAT_NO = MYROW.MAT_NO;*/
    END LOOP;
  END LOOP;
END;
        ]]>
	</query>
	
	<query id="FrmMeasureResultZG.AddResult" desc="增加实绩">
		<![CDATA[
  INSERT INTO MIL_MEASURE_RESULT
  (RESULT_NO,
   HEAT_PLAN_NO,
   BATCH_NO,
   PLINE_CODE,
   PLINE_NAME,
   IF_MONITOR_RCL,
   PRDCR_NO,
   PRODUCER,
   PRODUCER_TIME,
   OUTNUM_CUT,
   PRO_NUM,
   PRO_WT,
   FAIL_NUM,
   FAIL_WT,
   PRO_SHIFT,
   PRO_GROUP,
   PRO_USER,
   PRO_TIME,
   JUDGE_STOVE_NO,
   
   PR_PROVIDER,
   PR_TYPE,
   USE_PC,
   USE_AR,
   AR_COUNT,
   SPECIAL_DRIFT,
   CC_COUNT,
   IS_PAINT,
   PAINT_TYPE,
   PAINT_LOT,
   FLAG,
   PRO_END_TIME,
   MEMO)
VALUES
  ('#RESULT_NO#',
   '#HEAT_PLAN_NO#',
   '#BATCH_NO#',
   '#PLINE_CODE#',
   (SELECT C.PLINE_NAME
      FROM COM_BASE_PLINE C
     WHERE C.PLINE_CODE = '#PLINE_CODE#'),
   '#IF_MONITOR_RCL#',
   '#PRDCR_NO#',
   '#PRODUCER#',
   '#PRODUCER_TIME#',
   '#OUTNUM_CUT#',
   '#PRO_NUM#',
   '#PRO_WT#',
   '#FAIL_NUM#',
   '#FAIL_WT#',
   '#PRO_SHIFT#',
   '#PRO_GROUP#',
   '#PRO_USER#',
   TO_DATE('#PRO_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
   '#JUDGE_STOVE_NO#',
   
   '#PR_PROVIDER#',
   '#PR_TYPE#',
   '#USE_PC#',
   '#USE_AR#',
   '#AR_COUNT#',
   '#SPECIAL_DRIFT#',
   '#CC_COUNT#',
   '#IS_PAINT#',
   '#PAINT_TYPE#',
   '#PAINT_LOT#',
   '#FLAG#',
   TO_DATE('#PRO_END_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
   '#MEMO#')
			]]>
	</query>
	<query id="FrmMeasureResultZG.DeleteResult" desc="删除实绩">
        <![CDATA[
DECLARE
  V_RESULT_NO      MIL_MEASURE_RESULT.RESULT_NO%type := ?;
  V_HEAT_PLAN_NO   PLN_ZY_ZG_M.HEAT_PLAN_NO%type := ?;
  V_JUDGE_STOVE_NO PORT_MIL_BATCH_SAMPLE_RESULT.JUDGE_STOVE_NO%type := ?;
  V_PLINE_CODE     PORT_MIL_BATCH_SAMPLE_RESULT.PLINE_CODE%type := ?;
BEGIN
  FOR MYROW IN (SELECT *
                  FROM PORT_MIL_BATCH_SAMPLE_RESULT T
                 WHERE T.MEASURING_SEQ IS NOT NULL
                   AND T.PLAN_ID = V_HEAT_PLAN_NO
                   AND REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') =
                       V_JUDGE_STOVE_NO
                   AND T.MEASURE_RESULT_NO = V_RESULT_NO
                   AND T.PLINE_CODE = V_PLINE_CODE) LOOP
  
    UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T
       SET T.MEASURING_FLAG        = '0',
           T.MEASURING_SEQ         = '',
           T.MEASURE_LEN           = '',
           T.MEASURE_WEIGHT        = '',
           T.MAT_INFO              = '',
           T.MEASURE_RESULT_NO     = '',
           --T.ACT_THEORY_WEIGHT     = T.ACT_THEORY_WEIGHT_BAK,
           T.ACT_THEORY_WEIGHT_BAK = ''
     WHERE T.MEASURING_SEQ IS NOT NULL
       AND T.STATUS = '0'
       AND T.PLAN_ID = V_HEAT_PLAN_NO
       AND REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = V_JUDGE_STOVE_NO
       AND T.MEASURE_RESULT_NO = V_RESULT_NO
       AND T.PLINE_CODE = V_PLINE_CODE
       AND T.MAT_NO = MYROW.MAT_NO;
  
    UPDATE RTD_MEASURE_POSDATA T1
       SET T1.MAT_NO_CX = ''
     WHERE T1.MAT_NO_CX = MYROW.MAT_NO;
  
    /*UPDATE MAT_BC_M
       SET ACT_LEN         = MYROW.ORDER_LENGTH,
           ACT_WEIGHT      = MYROW.ACT_THEORY_WEIGHT,
           PONDER_GROSS_WT = ''
     WHERE ZG_MAT_NO = MYROW.MAT_NO;*/
  END LOOP;
  DELETE FROM MIL_MEASURE_RESULT T WHERE T.RESULT_NO = V_RESULT_NO;
END;
        ]]>
	</query>
	
	<query id="FrmMeasureResultZG.UpdateFlag" desc="">
		<![CDATA[
       UPDATE RTD_MEASURE_POSDATA SET FLAG =? , MAT_NO_CX = ?  WHERE KEY_ID = ?
        ]]>
	</query>
	<query id="FrmMeasureResultZG.getRtdMeasurePosdataEntityByID" desc="查询">
		<![CDATA[
SELECT KEY_ID,
                               PLINE_CODE,
                               PLINE_NAME,
                               JUDGE_STOVE_NO,
                               BATCH_NO,
                               MAT_NO,
                               ACT_LEN / 1000 ACT_LEN,
                               ACT_WEIGHT / 1000 ACT_WEIGHT,
                               ORD_PK,
                               ORD_LN_PK,
                               ORD_LN_DLY_PK,
                               ORDER_NO,
                               ORDER_SEQ,
                               ORDER_SEQ_NO,
                               PRO_PLAN_ID,
                               GX_PLAN_NO,
                               PRO_BC,
                               PRO_BZ,
                               BAL_YEAR_MONTH,
                               MSAUER_DATE,
                               FLAG,
                               MAT_NO_CX
  FROM RTD_MEASURE_POSDATA WHERE KEY_ID = ?
        ]]>
	</query>
	<query id="FrmMeasureResultZG.GetExitsRtdData" desc="">
		<![CDATA[
      	SELECT * FROM RTD_MEASURE_POSDATA  WHERE mat_no_cx = ?  AND FLAG ='00'
        ]]>
	</query>
	<query id="FrmMeasureResultZG.queryMatCount" desc="查询未匹配的支数">
		<![CDATA[
      	SELECT COUNT(1) MatCount
  FROM RTD_MEASURE_POSDATA T
 WHERE T.FLAG = '00'
   AND T.MAT_NO_CX IS NULL
   AND T.JUDGE_STOVE_NO = ?
   AND T.PLINE_CODE = ?
        ]]>
	</query>
	<query id="FrmMeasureResultZG.queryProcessCount" desc="查询进程表未匹配的支数">
		<![CDATA[
      	SELECT COUNT(1) MatCount
  FROM PORT_MIL_BATCH_SAMPLE_RESULT T
 WHERE T.MEASURING_SEQ IS NULL
   AND T.STATUS = '0'
   AND REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = ?
   AND T.PLINE_CODE = ?
        ]]>
	</query>
	
	<query id = "FrmMeasureResultZG.selectCount" desc = "查询送判支数">
	SELECT COUNT(1) ACOUNT
  FROM PORT_MIL_BATCH_SAMPLE_RESULT T
 WHERE T.JUGDE_APPLY_CODE IS NOT NULL
   AND T.MEASURE_RESULT_NO = ?
   AND T.PLAN_ID = ?
	</query>
	<query id = "FrmMeasureResultZG.selectMatNo" desc = "查询材料号">
	SELECT DISTINCT T.MAT_NO
  FROM PORT_MIL_BATCH_SAMPLE_RESULT T
 WHERE T.JUGDE_APPLY_CODE IS NULL
   AND T.MEASURE_RESULT_NO = ?
   AND T.PLAN_ID = ?
	</query>
	
	<query id = "FrmMeasureResultZG.updateProWt" desc = "回报重量">
DECLARE
  V_INPUT_WEIGHT      PORT_MIL_BATCH_SAMPLE_RESULT.INPUT_WEIGHT%TYPE := NULL; --平均值
  V_INPUT_WEIGHT1     PORT_MIL_BATCH_SAMPLE_RESULT.INPUT_WEIGHT%TYPE := NULL; --余数
  V_ACT_WEIGHT        PORT_MIL_BATCH_SAMPLE_RESULT.INPUT_WEIGHT%TYPE := ?;
  V_ACT_COUNT         PORT_MIL_BATCH_SAMPLE_RESULT.ACT_COUNT%TYPE := ?;
  V_MEASURE_RESULT_NO PORT_MIL_BATCH_SAMPLE_RESULT.MEASURE_RESULT_NO%TYPE := ?;
  V_PLINE_CODE        PORT_MIL_BATCH_SAMPLE_RESULT.PLINE_CODE%TYPE := ?;
  V_HEAT_PLAN_NO      PLN_ZY_ZG_M.HEAT_PLAN_NO%TYPE := ?;

BEGIN
  SELECT TRUNC(V_ACT_WEIGHT / V_ACT_COUNT, 3)
    INTO V_INPUT_WEIGHT
    FROM DUAL;

  SELECT V_ACT_WEIGHT - V_ACT_COUNT * V_INPUT_WEIGHT
    INTO V_INPUT_WEIGHT1
    FROM DUAL;

  FOR MYROW IN (SELECT T.*
                  FROM PORT_MIL_BATCH_SAMPLE_RESULT T
                 WHERE T.PLINE_CODE = V_PLINE_CODE
                   AND T.STATUS IN ('0', '3')
                   AND T.PLAN_ID = V_HEAT_PLAN_NO
                   AND T.MEASURE_RESULT_NO = MEASURE_RESULT_NO) LOOP
  
    IF (V_INPUT_WEIGHT1 >= 0.001) THEN
      V_INPUT_WEIGHT1 := V_INPUT_WEIGHT1 - 0.001;
      UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T
         SET T.ACT_THEORY_WEIGHT = V_INPUT_WEIGHT + 0.001,
             T.MEASURE_WEIGHT    = V_INPUT_WEIGHT + 0.001
       WHERE T.JUDGE_STOVE_NO = MYROW.JUDGE_STOVE_NO
         AND T.MAT_NO = MYROW.MAT_NO
         AND T.MEASURE_RESULT_NO = MYROW.MEASURE_RESULT_NO;
    
      UPDATE RTD_MEASURE_POSDATA T
         SET T.ACT_WEIGHT = 1000 * (V_INPUT_WEIGHT + 0.001)
       WHERE T.MAT_NO_CX = MYROW.MAT_NO
         AND T.FLAG = '00'
         AND T.PLINE_CODE = V_PLINE_CODE;
    
      UPDATE MAT_BC_M T
         SET T.ACT_WEIGHT      = V_INPUT_WEIGHT + 0.001,
             T.PONDER_GROSS_WT = V_INPUT_WEIGHT + 0.001
       WHERE T.ZG_MAT_NO = MYROW.MAT_NO
         AND T.QCM_STAUS = '00'
         AND T.PLINE_CODE = V_PLINE_CODE;
    ELSE
      UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T
         SET T.ACT_THEORY_WEIGHT = V_INPUT_WEIGHT,
             T.MEASURE_WEIGHT    = V_INPUT_WEIGHT
       WHERE T.JUDGE_STOVE_NO = MYROW.JUDGE_STOVE_NO
         AND T.MAT_NO = MYROW.MAT_NO
         AND T.MEASURE_RESULT_NO = MYROW.MEASURE_RESULT_NO;
    
      UPDATE RTD_MEASURE_POSDATA T
         SET T.ACT_WEIGHT = 1000 * V_INPUT_WEIGHT
       WHERE T.MAT_NO_CX = MYROW.MAT_NO
         AND T.FLAG = '00'
         AND T.PLINE_CODE = V_PLINE_CODE;
    
      UPDATE MAT_BC_M T
         SET T.ACT_WEIGHT      = V_INPUT_WEIGHT,
             T.PONDER_GROSS_WT = V_INPUT_WEIGHT
       WHERE T.ZG_MAT_NO = MYROW.MAT_NO
         AND T.QCM_STAUS = '00'
         AND T.PLINE_CODE = V_PLINE_CODE;
    END IF;
  END LOOP;
END;

	</query>
	<query id = "FrmMeasureResultZG.updateMeasureResult" desc = "回报测量点实绩重量">
	UPDATE MIL_MEASURE_RESULT T SET T.PRO_WT = ? WHERE T.RESULT_NO = ?
	</query>
	
	<query id="FrmMeasureResultZG.Doupdate" desc="清除异常数据">
		<![CDATA[
DECLARE
  V_HEAT_PLAN_NO PLN_ZY_ZG_M.HEAT_PLAN_NO%type := ?;
BEGIN
  FOR MYROW IN (SELECT *
                  FROM RTD_MEASURE_POSDATA T1
                 WHERE T1.FLAG = '00'
                   AND T1.MAT_NO_CX IS NOT NULL
                   AND T1.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                   AND DECODE('#BATCH_NO#', '', '/', T1.BATCH_NO) =
                       DECODE('#BATCH_NO#', '', '/', '#BATCH_NO#')
                   AND T1.PLINE_CODE = '#PLINE_CODE#'
                   AND T1.MAT_NO_CX NOT IN
                       (SELECT T.MAT_NO
                          FROM PORT_MIL_BATCH_SAMPLE_RESULT T
                         WHERE T.PLAN_ID = V_HEAT_PLAN_NO)) LOOP
    UPDATE RTD_MEASURE_POSDATA T1
       SET T1.MAT_NO_CX   = '',
           T1.MSAUER_DATE = SYSDATE,
           T1.CREATE_DATA = SYSDATE
     WHERE T1.KEY_ID = MYROW.KEY_ID;
  END LOOP;
END;
        ]]>
	</query>
</queryMap>
