<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc = "炉计划信息管理">
<query id = "FrmUpdatePlan.queryMilPlan" desc = "查询炉计划信息">
<![CDATA[
 SELECT 
       T.ID,
       T.SEQ,
       T.STOVE_NO,
       T.JUDGE_STOVE_NO,
       T.LOT_NO,
       T.CONTRACT_NO,
       T.IMP_PROCESS,
       T.PLINE_CODE,
       CASE STATUS WHEN 
       '00' THEN '上料' WHEN
       '05' THEN '开始锯切' WHEN
       '10'  THEN '锯切完成' WHEN
       '15' THEN '入炉' WHEN
       '20'  THEN '出炉' WHEN
       '25' THEN '开始穿孔' WHEN
       '30'  THEN '穿孔完成' WHEN
       '35' THEN '开始连轧' WHEN
       '40'  THEN '连轧完成' WHEN
       '45' THEN '入再加热炉' WHEN
       '50'  THEN '出再加热炉' WHEN
       '55' THEN '开始定径' WHEN
       '60'  THEN '定径完成' WHEN
       '65' THEN '开始分切' WHEN
       '70'  THEN '分切完成' WHEN
       '75' THEN '开始矫直' WHEN
       '80'	THEN '矫直完成 ' WHEN
       '85' THEN '开始探伤' WHEN
       '90'	THEN '探伤完成' WHEN	
       '95' THEN '人工质检开始' WHEN
       '99'	THEN '入库' END AS STATUS,
       T.PRODUCER,
       T.PROCESS_STATUS,
       T.DB_LENGTH,
       T.DB_HEIGHT,
       T.ROLL_LENGTH,
       T.SAW_NUM,
       T.TARGET_LENGTH,
       T.FINISH_USER,
       T.TARGET_LIABRARY,
       T.VARIETIES,
       T.PIPE_SIZE,
       T.BUCKLE_TYPE,
       T.LENGTH_RANGE,
       T.ROLL_STANDRAD,
       T.PIPE_SECTION,
       T.STEELCODE,
       T.STEELNAME,
       T.GRADECODE,
       T.GRADENAME,
       T.STEEL_STANDRAD,
       T.TARGET,
       T.BRANCH,
       T.TON,
       T.CUT_TARGET,
       T.CUT_LENGTH,
       T.CUT_WEIGHT,
       T.DB_NUM,
       TO_CHAR(T.START_TIME, 'YYYY-MM-DD HH24:MI:SS') START_TIME,
       TO_CHAR(T.END_TIME, 'YYYY-MM-DD HH24:MI:SS') END_TIME,
       TO_CHAR(T.TOM, 'YYYY-MM-DD HH24:MI:SS') TOM,
       TO_CHAR(T.TOC, 'YYYY-MM-DD HH24:MI:SS') TOC,
       CASE NODE_STATUS WHEN 
       '00' THEN '' WHEN
        '10'	THEN '锯切完成' WHEN
       '15' THEN '入炉' WHEN
       '20'	THEN '出炉' WHEN
       '25' THEN '开始穿孔' WHEN
       '30'	THEN '穿孔完成' WHEN
       '35' THEN '开始连轧' WHEN
       '40'	THEN '连轧完成' WHEN
       '45' THEN '入再加热炉' WHEN
       '50'	THEN '出再加热炉' WHEN
       '55' THEN '开始定径' WHEN
       '60'	THEN '定径完成' WHEN
       '65' THEN '开始分切' WHEN
       '70'	THEN '分切完成' WHEN
       '75' THEN '开始矫直' WHEN
       '80'	THEN '矫直完成 ' WHEN
       '85' THEN '开始探伤' WHEN
       '90'	THEN '探伤完成' WHEN	
       '96' THEN '人工质检完成'
       END AS NODE_STATUS,
       T.CUT_HEAD_LENGTHP,
       T.CUT_TRAIL_LENGTHP,
       T.CONTROL_THICKP,
       T.OFFLINE_FLAG,
       T.IS_BATCH,
       TO_CHAR(T.OFFLINE_DATE, 'YYYY-MM-DD HH24:MI:SS') OFFLINE_DATE,
       T.CUT_TYPE,
       T.ROLLING_STATUS,
       T.PRODUCE_STANDRAD,
       T.SIMPLE_PROCESS,
       T.BACK_LINE_FLAG,
       DECODE(T.BACK_PLAN_FLAG,'7','矫直返线','8','探伤返线','9','表检返线','正常计划')BACK_PLAN_FLAG,
       T.FEED_SEQ,
       TO_CHAR(T.FEED_TIME, 'YYYY-MM-DD HH24:MI:SS') FEED_TIME,
       T.LOT_SEQ,
       T.FEED_HEAT_NO,
       T.LENGTHCP,
       T.CUT_HEAD_LENGTHA,
       T.CUT_TRAIL_LENGTHA,
       T.ORDER_LENGTHA,
       T.HOT_CHECK_FLAG,
       T.BACK_SLAB_FLAG,
       TO_CHAR(T.BACK_SLAB_TIME, 'YYYY-MM-DD HH24:MI:SS') BACK_SLAB_TIME,
       T.BATCH_MAX,
       T.CODE_SAMPLE_FLAG,
       T.VARIETIES_CODE,
       T.PIPE_SIZE_CODE,
       T.BUCKLE_TYPE_CODE,
       T.ROLL_STANDRAD_CODE,
       T.STD_STYLE,
       T.STD_STYLE_DESC,
       T.PRO_PLAN_ID,
       T.GX_PLAN_NO
 FROM MIL_PLAN T
 WHERE T.JUDGE_STOVE_NO || '&' LIKE '%' || ? || '%'
 AND T.LOT_NO || '&' LIKE '%' || ? || '%'
 AND T.PLINE_CODE = ?
 AND T.BACK_PLAN_FLAG = '0'
 ]]>
</query>
<query id = "FrmUpdatePlan.doQuerySawResult" desc = "查询是否产生分切实绩">
 SELECT COUNT(1)ACOUNT
     FROM MIL_SAW_RESULT T
    WHERE T.RESULT_NO = ?
      AND T.JUDGE_STOVE_NO = ?
</query>

<query id = "FrmUpdatePlan.doQuerySamplePipe" desc = "查询是否分批取样">
SELECT COUNT(1) ACOUNT
  FROM PORT_MIL_BATCH_SAMPLE_RESULT T
 WHERE T.IS_SAMPLE_PIPE = '1'
   AND T.PLAN_ID = ?
   AND T.JUDGE_STOVE_NO = ?
</query>
<query id = "FrmUpdatePlan.updateSawNum" desc = "修改倍尺数">
DECLARE
	BEGIN
UPDATE MIL_PLAN T
   SET T.SAW_NUM = ?
 WHERE T.ID = ?
   AND T.JUDGE_STOVE_NO = ?;
   DELETE FROM PORT_MIL_BATCH_SAMPLE_RESULT T WHERE T.PLAN_ID = ? AND T.JUDGE_STOVE_NO = ?;
   END;
</query>
<query id = "FrmUpdatePlan.SelectFeedNum" desc = "查询上料行信息">
SELECT T.FEED_NUM,T.DB_NUM,S.SAW_NUM,S.PIPE_SIZE,S.TARGET_LENGTH
          FROM MIL_FEED_PLAN T,
       MIL_PLAN S
 WHERE T.JUDGE_STOVE_NO = S.JUDGE_STOVE_NO
 AND T.LOT_NO = S.LOT_NO
 AND S.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
 AND S.LOT_NO = '#LOT_NO#'
 AND S.ID = '#ID#'
 ORDER BY T.FEED_ROW_NO ASC
</query>
<query id = "FrmUpdatePlan.insertPortBacth" desc = "重新生成进程表队列">
INSERT INTO PORT_MIL_BATCH_SAMPLE_RESULT(
        PLAN_ID,
        LOT_NO,
        STOVE_NO,
        JUDGE_STOVE_NO,
        GROUP_NO,
        PLINE_CODE,
        BATCH_NO,
        SEQ,
        MAT_NO,
        IS_SAMPLE_PIPE,
        IS_VALID,
        REMARK,
        SAMPLE_PIPE_LEN,
        GET_SAMPLE_NAME,
        GET_SAMPLE_TIME,
        GET_SAMPLE_SHIFT,
        GET_SAMPLE_CLASS,
        ORDER_LENGTH,
        REAL_BATCH_NO,
        ACT_THEORY_WEIGHT,
        ACT_COUNT,
        CRATE_TIME,
        STATUS,
        M_MAT_NO,
        GROUP_FLAG,
        OP_PROCESS,
        BACK_PROCESS,
        M_M_MAT_NO)
 VALUES( 
        ?,
        ?,
        ?,
        ?,
        '',
        ?,
        '',
        ?,
        ?,
        '0',
        '1',
        '',
        '',
        '',
        '',
        '',
        '',
        ?,
        '',
        ?,
        '1',
        TO_DATE(?,'YYYY-MM-DD HH24:MI:SS'),
        '0',
        ?,
        '0',
        '',
        '',
        ?)
</query>
<query id = "FrmUpdatePlan.SelectScrapNum" desc = "查询热区所有废管">
<![CDATA[
SELECT T.PROCESS_NO, T.SEQ, T.JUDGE_STOVE_NO
  FROM MIL_SLAB_SCRAP_SEQ T
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.PROCESS_NO < 7
   ORDER BY T.PROCESS_NO ASC
   ]]>
</query>
<query id = "FrmUpdatePlan.SelectNodeStaus" desc = "查询是否已结炉">
SELECT T.NODE_FUR_FLAG FROM #RESULT# T WHERE T.JUDGE_STOVE_NO = ? 
</query>
<query id = "FrmUpdatePlan.scarpPortBacth" desc = "锯切剔管写进程表">
DECLARE
BEGIN
  IF(?=0)THEN
  FOR MYROW IN (SELECT M_M_MAT_NO
                   FROM (SELECT ROWNUM SEQ, M_M_MAT_NO
                           FROM (SELECT T.M_M_MAT_NO,
                                        T.IS_SAMPLE_PIPE,
                                        T.INSTORE_FLAG,
                                        ROW_NUMBER() OVER(PARTITION BY M_M_MAT_NO ORDER BY IS_SAMPLE_PIPE DESC,INSTORE_FLAG DESC) RN
                                   FROM PORT_MIL_BATCH_SAMPLE_RESULT T
                                  WHERE T.JUDGE_STOVE_NO = ?
                                    AND T.Status = '0'
                                    )
                          WHERE RN = '1'
                            AND IS_SAMPLE_PIPE = '0'
                            AND INSTORE_FLAG = '0')
                  WHERE SEQ = ?) LOOP
  UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T SET T.STATUS = '1',T.OP_PROCESS = ? WHERE T.JUDGE_STOVE_NO = ? AND T.M_M_MAT_NO = MYROW.M_M_MAT_NO;
  END LOOP;
  ELSIF(?=1)THEN
  FOR MYROW1 IN (SELECT M_MAT_NO
                   FROM (SELECT ROWNUM SEQ, M_MAT_NO
                           FROM (SELECT T.M_MAT_NO,
                                        T.IS_SAMPLE_PIPE,
                                        T.INSTORE_FLAG,
                                        ROW_NUMBER() OVER(PARTITION BY M_MAT_NO ORDER BY IS_SAMPLE_PIPE DESC,INSTORE_FLAG DESC) RN
                                   FROM PORT_MIL_BATCH_SAMPLE_RESULT T
                                  WHERE T.JUDGE_STOVE_NO = ?
                                    AND T.Status in ('0','1')
                                    )
                          WHERE RN = '1'
                            AND IS_SAMPLE_PIPE = '0'
                            AND INSTORE_FLAG = '0')
                  WHERE SEQ = ?) LOOP
  UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T SET T.STATUS = '1',T.OP_PROCESS = ? WHERE T.JUDGE_STOVE_NO = ? AND T.M_MAT_NO = MYROW1.M_MAT_NO;
  END LOOP;
  END IF;
END;
</query>
<query id = "FrmUpdatePlan.scarpPortBacth1" desc = "其他热区工序剔管进程表">
DECLARE
BEGIN
  FOR MYROW1 IN (SELECT M_MAT_NO
                   FROM (SELECT ROWNUM SEQ, M_MAT_NO
                           FROM (SELECT T.M_MAT_NO,
                                        T.IS_SAMPLE_PIPE,
                                        T.INSTORE_FLAG,
                                        ROW_NUMBER() OVER(PARTITION BY M_MAT_NO ORDER BY IS_SAMPLE_PIPE DESC,INSTORE_FLAG DESC) RN
                                   FROM PORT_MIL_BATCH_SAMPLE_RESULT T
                                  WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                                    AND (T.OP_PROCESS IS NULL OR
                                        T.OP_PROCESS = '#OP_PROCESS#')
                                    )
                          WHERE RN = '1'
                            AND IS_SAMPLE_PIPE = '0'
                            AND INSTORE_FLAG = '0')
                  WHERE SEQ = '#SEQ#') LOOP
  UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T SET T.STATUS = '1',T.OP_PROCESS = '#OP_PROCESS#' WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#' AND T.M_MAT_NO = MYROW1.M_MAT_NO;
 END LOOP;
END;
</query>

<query id="FrmUpdatePlan.UpdatePlanPredict" desc="锯切结炉,回写计划表中预计支吨">
        <![CDATA[
      	DECLARE
  V_INPUT_WEIGHT PORT_MIL_BATCH_SAMPLE_RESULT.INPUT_WEIGHT%type := null;
BEGIN
  FOR MYROW IN (SELECT T.JUDGE_STOVE_NO,
                       T.PRO_PLAN_ID,
                       T.GX_PLAN_NO,
                       SUM(B.FEED_NUM_PLAN * B.DB_NUM) * MAX(T1.SAW_NUM) YJZ,
                       
                       SUM(B.MAT_TOTAL_HEIGHT) *
                       (1 - NVL((select R.BURNNING_RATE
                                   from MIL_FUR_RESULT R
                                  WHERE R.JUDGE_STOVE_NO = T.JUDGE_STOVE_NO
                                    AND NVL(R.PRO_PLAN_ID, '/') =
                                        NVL(T.PRO_PLAN_ID, '/')
                                    AND NVL(R.GX_PLAN_NO, '/') =
                                        NVL(T.GX_PLAN_NO, '/')) / 100,
                                0)) -
                       DECODE(MAX(T1.CONTROL_THICKP),
                              0,
                              0,
                              (MAX(T1.CUT_HEAD_LENGTHP) +
                              MAX(T1.CUT_TRAIL_LENGTHP)) / 1000 *
                              (0.02466 * MAX(T1.CONTROL_THICKP) / 1000 * 1.02 *
                              ((SUBSTR(MAX(T1.PIPE_SIZE),
                                        1,
                                        INSTR(MAX(T1.PIPE_SIZE), '*') - 1)) *
                              (CASE
                                WHEN INSTR(MAX(T1.VARIETIES), '套管') > 0 THEN
                                 1.005
                                WHEN INSTR(MAX(T1.VARIETIES), '油管') > 0 THEN
                                 1.005
                                ELSE
                                 1
                              END) - (MAX(T1.CONTROL_THICKP) / 1000 * 1.02)) *
                              SUM(B.FEED_NUM_PLAN * B.DB_NUM))) YJD
                
                  from MIL_FEEDSAW_RESULT T, MIL_FEED_PLAN B, MIL_PLAN T1
                 WHERE T.JUDGE_STOVE_NO = T1.JUDGE_STOVE_NO
                   AND NVL(T.PRO_PLAN_ID, '/') = NVL(T1.PRO_PLAN_ID, '/')
                   AND T.JUDGE_STOVE_NO = B.JUDGE_STOVE_NO
                   AND NVL(T.PRO_PLAN_ID, '/') = NVL(B.PRO_PLAN_ID, '/')
                   AND T.JUDGE_STOVE_NO = ?
                   AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
                   AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
                 GROUP BY T.JUDGE_STOVE_NO, T.PRO_PLAN_ID, T.GX_PLAN_NO) LOOP
  
    UPDATE MIL_PLAN M
       SET M.PREDICT_PIECE = MYROW.YJZ, M.PREDICT_TON = MYROW.YJD
     WHERE M.JUDGE_STOVE_NO = MYROW.JUDGE_STOVE_NO
       AND NVL(M.PRO_PLAN_ID, '/') = NVL(MYROW.PRO_PLAN_ID, '/')
       AND NVL(M.GX_PLAN_NO, '/') = NVL(MYROW.GX_PLAN_NO, '/');
  END LOOP;
END;

        ]]>   
	</query>

	
</queryMap>