<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="上料锯切实绩操作">
	<query id="FeedResult.FeedPlanQuery" desc="上料计划行简单查询">
		
        <![CDATA[
    SELECT a.FEED_ROW_NO,
       a.SEQ,
       a.LOT_NO,
       a.STOVE_NO,
       a.JUDGE_STOVE_NO,
       a.PLINE_CODE,
       a.DB_NUM,
       a.DB_LENGTH,
       b.DB_HEIGHT,
       a.MAT_HEIGHT,
       a.MAT_TOTAL_HEIGHT,
       a.FEED_NUM,
       a.FEED_NUM_PLAN,
       a.FEED_LENGTH,
       a.USE_LENGTH,
       a.NON_USE_LENGTH,
       a.CUT_TARGET,
       a.CUT_LENGTH,
       a.CUT_WEIGHT,
       a.SCRAP_FEEDNUM,
       a.SCRAP_DBNUM,
       a.CHANGE_NUM,
       c.REMARK,
       CASE a.SAW_FALG
         WHEN '0' THEN
          '未上料'
         WHEN '1' THEN
          '已上料'
         WHEN '2' THEN
          '锯切完成'
       END AS SAW_FALG,
       a.COL_MODE,
       TO_CHAR(a.COL_TIME, 'YYYY-MM-DD HH24:MI:SS') COL_TIME,
       a.COL_USER,
       a.COL_SHIFT,
       a.COL_GROUP,
       a.pro_plan_id,
       a.gx_plan_no
  FROM MIL_FEED_PLAN a, MIL_PLAN b, MIL_FEEDSAW_RESULT c
 WHERE a.judge_stove_no(+) = b.judge_stove_no
   and b.IS_LOAD = '1'
   AND NVL(A.PRO_PLAN_ID,'/') = NVL(B.PRO_PLAN_ID,'/')
   AND NVL(A.GX_PLAN_NO,'/') = NVL(B.GX_PLAN_NO,'/')
   and a.judge_stove_no = c.judge_stove_no(+)
   AND b.node_status between ? and ?
   AND a.lot_no || '&' LIKE '%' || ? || '%'
   AND a.judge_stove_no || '&' LIKE '%' || ? || '%'
   AND a.feed_row_no || '&' LIKE '%' || ? || '%'
   AND a.PLINE_CODE = ?
 ORDER BY a.FEED_ROW_NO
        ]]>
	</query>
	
	
		<query id="FeedResult.FeedPlanQueryForFeedRowNo" desc="上料计划行简单查询">
        <![CDATA[
     SELECT a.FEED_ROW_NO,
       a.SEQ,
       a.LOT_NO,
       a.STOVE_NO,
       a.JUDGE_STOVE_NO,
       a.PLINE_CODE,
       a.DB_NUM,
       b.DB_HEIGHT,
       a.DB_LENGTH,
       a.MAT_HEIGHT,
       a.MAT_TOTAL_HEIGHT,
       a.FEED_NUM,
       a.FEED_NUM_PLAN,
       a.FEED_LENGTH,
       a.USE_LENGTH,
       a.NON_USE_LENGTH,
       a.CUT_TARGET,
       a.CUT_LENGTH,
       a.CUT_WEIGHT,
       a.SCRAP_FEEDNUM,
       a.SCRAP_DBNUM,
       c.CHANGE_NUM AS CHANGE_NUM_TOTAL,
       a.CHANGE_NUM,
       CASE a.SAW_FALG
         WHEN '0' THEN
          '未上料'
         WHEN '1' THEN
          '已上料'
         WHEN '2' THEN
          '锯切完成'
       END AS SAW_FALG,
       c.REMARK,
       a.COL_MODE,
       TO_CHAR(a.COL_TIME, 'YYYY-MM-DD HH24:MI:SS') COL_TIME,
       a.COL_USER,
       a.COL_SHIFT,
       a.COL_GROUP
  FROM MIL_FEED_PLAN a, MIL_PLAN b, MIL_FEEDSAW_RESULT c
 WHERE a.judge_stove_no = b.judge_stove_no
   AND NVL(A.PRO_PLAN_ID,'/') = NVL(B.PRO_PLAN_ID,'/')
   --AND NVL(A.PRO_PLAN_ID,'/') = NVL(C.PRO_PLAN_ID,'/')
   and a.judge_stove_no = c.judge_stove_no(+)
   and a.judge_stove_no = ?
   AND a.feed_row_no = ?
   AND A.PRO_PLAN_ID  || '&' LIKE '%' || ? || '%'
   AND A.GX_PLAN_NO  || '&' LIKE '%' || ? || '%'
        ]]>
	</query>


	<query id="FeedResult.PlanQuery" desc="轧制作业计划查询">
        <![CDATA[
       SELECT 
       ID,
       SEQ,
       STOVE_NO,
       JUDGE_STOVE_NO,
       LOT_NO,
       CONTRACT_NO,
       IMP_PROCESS,
       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,
       PRODUCER,
       PROCESS_STATUS,
       DB_LENGTH,
       DB_HEIGHT,
       ROLL_LENGTH,
       SAW_NUM,
       TARGET_LENGTH,
       FINISH_USER,
       TARGET_LIABRARY,
       VARIETIES,
       PIPE_SIZE,     
       BUCKLE_TYPE,
       LENGTH_RANGE,
       ROLL_STANDRAD,
       PIPE_SECTION,
       STEELCODE,
       STEELNAME,
       GRADECODE,
       GRADENAME,
       STEEL_STANDRAD,
       TARGET,
       BRANCH,
       TON,
       CUT_TARGET,
       CUT_LENGTH,
       CUT_WEIGHT,
       DB_NUM,
       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,
       TO_CHAR(START_TIME, 'YYYY-MM-DD HH24:MI:SS') START_TIME,
       TO_CHAR(END_TIME, 'YYYY-MM-DD HH24:MI:SS') END_TIME,
       TO_CHAR(TOM, 'YYYY-MM-DD HH24:MI:SS') TOM,
       TO_CHAR(TOC, 'YYYY-MM-DD HH24:MI:SS') TOC
 	   FROM MIL_PLAN
	   WHERE
	   LOT_NO || '&' LIKE '%' || ? || '%'
	   AND REGEXP_REPLACE(JUDGE_STOVE_NO, '-.*', '') =  REGEXP_REPLACE(?, '-.*', '')
	   AND NODE_STATUS < ? 
	   order by start_time ,id
	   
		    
        ]]>
	</query>


	<query id="FeedResult.PlanQueryForHeatNo" desc="轧制作业计划查询">
        <![CDATA[
     SELECT ID,
       T.SEQ,
       T.STOVE_NO,
       --REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') JUDGE_STOVE_NO,
       T.JUDGE_STOVE_NO,
       T.LOT_NO,
       T.CONTRACT_NO,
       T.IMP_PROCESS,
       (SELECT MAX(C.CRAFT_PATH)
          FROM CRAFT_ORD_DESIGN C
         WHERE C.CRAFT_NO = T.IMP_PROCESS
           AND C.VALIDFLAG = '1') IMP_PROCESS_PATH,
       T.PLINE_CODE,
       CASE T.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 '99' THEN
          '入库'
       END AS STATUS,
       T.OFFLINE_FLAG,
       T.PRODUCER,
       T.PROCESS_STATUS,
       T.DB_LENGTH,
       T.DB_HEIGHT,
       T.ROLL_LENGTH,
       T.SAW_NUM,
       T.FINISH_USER,
       T.TARGET_LIABRARY,
       T.VARIETIES,
       T.PIPE_SIZE,
       T.BUCKLE_TYPE,
       T.LENGTH_RANGE,
       (SELECT MAX(SUBSTR(L.STD_NAME, 1, 70) ||
                   decode(L.USE_DESC, '/', '', '', '', ',' || L.USE_DESC))
          FROM SLM_ORDER_HEAD H, SLM_ORDER_LINE L
         WHERE H.ORD_PK = L.ORD_PK
           AND H.ORDER_NO =
               SUBSTR(T.CONTRACT_NO, 1, INSTR(T.CONTRACT_NO, '/') - 1)
           AND L.ORDER_SEQ =
               SUBSTR(T.CONTRACT_NO, INSTR(T.CONTRACT_NO, '/') + 1)
           AND H.VALIDFLAG = '1'
           AND L.VALIDFLAG = '1') 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,
       CASE T.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 '99' THEN
          '入库'
       END AS NODE_STATUS,
       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,
       T.TARGET_LENGTH,
       T.CUT_HEAD_LENGTHP,
       T.CUT_TRAIL_LENGTHP,
       T.CUT_HEAD_LENGTHA,
       T.CUT_TRAIL_LENGTHA,
       T.ORDER_LENGTHA,
       T.PRO_PLAN_ID,
       T.GX_PLAN_NO,
       T.STD_STYLE,
       T.STD_STYLE_DESC,
       T.IS_LOAD,
       T1.MEMO ReMark
  FROM MIL_PLAN t, PLN_ZY_ZG_M T1
 WHERE T.JUDGE_STOVE_NO =  ?
   AND T.PRO_PLAN_ID || '&' LIKE '%' || ? || '%'
   AND T.GX_PLAN_NO || '&' LIKE '%' || ? || '%'
   AND T.ID = T1.HEAT_PLAN_NO(+)
 order by start_time, id
        ]]>
	</query>

	<query id="FeedResult.FeedRackSeqQuery" desc="上料管号队列查询">
        <![CDATA[
       SELECT SEQ,
       FEED_ROW_NO,
       MAT_NO,
       LOT_NO,
       STOVE_NO,
       JUDGE_STOVE_NO,
       STEELCODE,
       STEELNAME,
       GRADECODE,
       GRADENAME,
       PLINE_CODE,
       case STATUS
         WHEN '0' THEN
          '未生产'
         WHEN '1' THEN
          '上料'
         WHEN '2' THEN
          '锯切完成'
         WHEN '3' THEN
          '切前剔除'
         WHEN '4' THEN
          '切后剔除'
       END AS STATUS,
       TARGET_DIAMETER,
       TARGET_LENGTH,
       TARGET_HEIGHT,
       COL_DIAMETER,
       COL_LENGTH,
       COL_HEIGHT,
       DB_NUM,
       SCRAP_DBNUM,
       FIXED_LENGTH,
       TO_CHAR(FEED_TIME, 'YYYY-MM-DD HH24:MI:SS') FEED_TIME,
       TO_CHAR(END_TIME, 'YYYY-MM-DD HH24:MI:SS') END_TIME,
       REMARK,
       COL_MODE,
       TO_CHAR(COL_TIME, 'YYYY-MM-DD HH24:MI:SS') COL_TIME,
       COL_USER,
       case COL_SHIFT
         WHEN '0' THEN
          '常白班'
         WHEN '1' THEN
          '早班'
         WHEN '2' THEN
          '中班'
         WHEN '3' THEN
          '夜班'
       end as COL_SHIFT,
       case COL_GROUP
         WHEN '1' THEN
          '甲'
         WHEN '2' THEN
          '乙'
         WHEN '3' THEN
          '丙'
         WHEN '4' THEN
          '丁'
       end as COL_GROUP,
       '交班' CHANGE_NUM,
       '接班确认' BTNCHANGECOM,
       CASE CHANGE_FLAG
         WHEN '1' THEN
          '确认交班'
         WHEN '2' THEN
          '待接班确认'
       END AS CHANGE_FLAG,
       PRO_PLAN_ID,
       GX_PLAN_NO
  FROM MIL_FEED_RACK
 WHERE JUDGE_STOVE_NO = ?
   AND FEED_ROW_NO || '&' LIKE '%' || ? || '%'
        ]]>
	</query>

	<query id="FeedResult.FeedRackSeqQueryForNode" desc="上料管号队列查询">
        <![CDATA[
       SELECT 
       SEQ,
       MAT_NO,
       JUDGE_STOVE_NO,
 	   STATUS,  
       DB_NUM,
       SCRAP_DBNUM,
       COL_GROUP
 FROM MIL_FEED_RACK
 WHERE JUDGE_STOVE_NO = ?
	   
		    
        ]]>
	</query>

	<query id="FeedResult.SinglePlanQuery" desc="轧制作业计划查询 用于管号队列">
        <![CDATA[
       SELECT DB_HEIGHT,
       ROLL_LENGTH,
       SAW_NUM,
       TARGET_LENGTH,
       TARGET_LIABRARY,
       PIPE_SIZE,
       PIPE_SECTION,
       DB_NUM,
       PROCESS_STATUS,
       ID
  FROM MIL_PLAN
 WHERE REGEXP_REPLACE(JUDGE_STOVE_NO, '-.*', '') =  REGEXP_REPLACE(?, '-.*', '')
   and PRO_PLAN_ID  || '&' LIKE '%' || ? || '%'
   and GX_PLAN_NO  || '&' LIKE '%' || ? || '%'
        ]]>
	</query>

	<query id="FeedResult.SingleFeedSawResult" desc="查询上料锯切实绩表">
        <![CDATA[
       SELECT RESULT_NO,
       LOT_NO,
       STOVE_NO,
       JUDGE_STOVE_NO,
       PLINE_CODE,
       FEED_NUM,
       BEFORE_SCRAP_NUM,
       AFTER_SCRAP_NUM,
       NODE_FUR_FLAG,
       CUT_NUM,
       CUT_TARGET,
       CUT_LENGTH,
       CUT_WEIGHT,
       TO_CHAR(START_TIME, 'YYYY-MM-DD HH24:MI:SS') START_TIME,
       TO_CHAR(END_TIME, 'YYYY-MM-DD HH24:MI:SS') END_TIME,
       EXECUTIVE_PRODUCER,
       TO_CHAR(PRODUCER_TIME, 'YYYY-MM-DD HH24:MI:SS') PRODUCER_TIME,
       PRODUCER_TEL,
       REMARK,
       COL_MODE,
       TO_CHAR(COL_TIME, 'YYYY-MM-DD HH24:MI:SS') COL_TIME,
       COL_USER,
       COL_SHIFT,
       COL_GROUP
  FROM MIL_FEEDSAW_RESULT
 WHERE REGEXP_REPLACE(JUDGE_STOVE_NO, '-.*', '') =  REGEXP_REPLACE(?, '-.*', '')
   AND PRO_PLAN_ID  || '&' LIKE '%' || ? || '%'
   AND GX_PLAN_NO  || '&' LIKE '%' || ? || '%'
        ]]>
	</query>

	<query id="FeedResult.SingleFeedSawNodeResult" desc="查询上料锯切实绩表">
        <![CDATA[
       SELECT 
       b.DB_HEIGHT AS DB_HEIGHT,
       a.RESULT_NO,
       a.LOT_NO,
       a.STOVE_NO,
       a.JUDGE_STOVE_NO,
       a.PLINE_CODE,
       a.FEED_NUM,
       a.BEFORE_SCRAP_NUM,
       a.AFTER_SCRAP_NUM,
       a.NODE_FUR_FLAG,
       a.CUT_NUM,
       a.CUT_TARGET,
       a.CUT_LENGTH,
       a.CUT_WEIGHT,
       TO_CHAR(a.START_TIME, 'YYYY-MM-DD HH24:MI:SS') START_TIME,
       TO_CHAR(a.END_TIME, 'YYYY-MM-DD HH24:MI:SS') END_TIME,
       a.EXECUTIVE_PRODUCER,
       TO_CHAR(a.PRODUCER_TIME, 'YYYY-MM-DD HH24:MI:SS') PRODUCER_TIME,
       a.PRODUCER_TEL,
       a.REMARK,
       a.COL_MODE,
       TO_CHAR(a.COL_TIME, 'YYYY-MM-DD HH24:MI:SS') COL_TIME,
       a.COL_USER,
       a.COL_SHIFT,
       a.COL_GROUP,
       a.CHANGE_NUM,
       a.QA_TON
 FROM MIL_FEEDSAW_RESULT a,MIL_PLAN b
 WHERE
 		a.PLINE_CODE = ?
 	AND	a.COL_SHIFT = ?
	AND a.COL_GROUP = ?
	AND a.END_TIME BETWEEN TO_DATE(?,'YYYY-MM-DD HH24:MI:SS') AND TO_DATE(?,'YYYY-MM-DD HH24:MI:SS')
  	AND a.NODE_FUR_FLAG = '1'
  	AND  a.judge_stove_no = b.judge_stove_no
  	order by a.end_time
	   
		    
        ]]>
	</query>


	<query id="FeedResult.UpdatePlan" desc="更改主计划状态为开始锯切">
		<![CDATA[
		update mil_plan set status = '05',FEED_TIME = sysdate, LOT_SEQ = '#LOT_SEQ#'  where LOT_NO ='#LOT_NO#' and  Judge_stove_no = '#JUDGE_STOVE_NO#' and ID = '#RESULT_NO#'
		]]>
	</query>
	
	
	<query id="FeedResult.getInputWeigtht" desc="查询该炉进程表的投入量是否写入">
		<![CDATA[
		select min(t.INPUT_WEIGHT) INPUT_WEIGHT from PORT_MIL_BATCH_SAMPLE_RESULT t
		where t.judge_stove_no = ?
		]]>
	</query>
	
		<query id="FeedResult.getDbHeight" desc="得到单倍重，烧损率">
		<![CDATA[
		select a.SAW_NUM as DB_NUM,
       a.DB_HEIGHT,
       b.BURNNING_RATE,
       c.BURNINGRATE,
       d.CUT_NUM
  from mil_plan a, mil_fur_result b, mil_refur_result c, mil_saw_result d
 where a.judge_stove_no = b.judge_stove_no(+)
   and a.judge_stove_no = c.judge_stove_no(+)
   and a.judge_stove_no = d.judge_stove_no(+)
   and a.id = b.result_no(+)
   and a.id = c.result_no(+)
   and a.id = d.result_no(+)
   and a.judge_stove_no = ?
   and a.id = ?
   AND A.PRO_PLAN_ID  || '&' LIKE '%' || ? || '%'
   AND A.GX_PLAN_NO  || '&' LIKE '%' || ? || '%'
		]]>
	</query>
	
	<query id="FeedResult.QueryFeedMatNo" desc="查询上料跟踪表最大材料号">
		<![CDATA[
		SELECT MAX(MAT_NO) FROM MIL_FEED_RACK WHERE JUNDGE_STOVE_NO = ?
		]]>
	</query>
	<query id="FeedResult.QueryFURMatNo" desc="查询加热炉跟踪表最大材料号">
		<![CDATA[
		SELECT MAX(MAT_NO) FROM MIL_FUR_RACK WHERE JUNDGE_STOVE_NO = ?
		]]>
	</query>
	<query id="FeedResult.QueryFinishMatNo" desc="查询精整跟踪表最大材料号">
		<![CDATA[
		SELECT MAX(MAT_NO) FROM MIL_FINISHES_RACK WHERE JUNDGE_STOVE_NO = ?
		]]>
	</query>
	<query id="FeedResult.AddFeedResult" desc="新增上料锯切实绩">
        <![CDATA[
        INSERT INTO MIL_FEEDSAW_RESULT(
        RESULT_NO,
        LOT_NO,
        STOVE_NO,
        JUDGE_STOVE_NO,
        PLINE_CODE,
        FEED_NUM,
        BEFORE_SCRAP_NUM,
        AFTER_SCRAP_NUM,
        CUT_NUM,
        CUT_TARGET,
        CUT_LENGTH,
        CUT_WEIGHT,
        START_TIME,
        END_TIME,
        EXECUTIVE_PRODUCER,
        PRODUCER_TIME,
        PRODUCER_TEL,
        REMARK,
        COL_MODE,
        COL_TIME,
        COL_USER,
        COL_SHIFT,
        COL_GROUP)
 VALUES( 
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        SYSDATE,
        SYSDATE,
        ?,
        SYSDATE,
        ?,
        ?,
        ?,
        SYSDATE,
        ?,
        ?,
        ?)
		    
        ]]>
	</query>



	<query id="FeedResult.AddFeedRack" desc="新增上料跟踪表">
        <![CDATA[
        INSERT INTO MIL_FEED_RACK(
        MAT_NO,
        LOT_NO,
        STOVE_NO,
        JUDGE_STOVE_NO,
        PLINE_CODE,
        TARGET_DIAMETER,
        TARGET_LENGTH,
        TARGET_HEIGHT,
        DB_NUM,
        FIXED_LENGTH,
        FEED_TIME,
        COL_MODE,
        COL_TIME,
        COL_USER,
        COL_SHIFT,
        COL_GROUP,
        FEED_ROW_NO,
        STATUS,
        SEQ,
        RESULT_NO,
        PRO_PLAN_ID,
        GX_PLAN_NO)
 VALUES( 
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        SYSDATE,
        ?, 
        SYSDATE,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?)
        ]]>
	</query>

	<query id="FeedResult.AddFeedHistory" desc="新增上料跟踪历史表">
        <![CDATA[
        INSERT INTO MIL_FEED_HISTORY(
        MAT_NO,
        LOT_NO,
        STOVE_NO,
        JUDGE_STOVE_NO,
        PLINE_CODE,
        TARGET_DIAMETER,
        TARGET_LENGTH,
        TARGET_HEIGHT,
        DB_NUM,
        FIXED_LENGTH,
        FEED_TIME,
        COL_MODE,
        COL_TIME,
        COL_USER,
        COL_SHIFT,
        COL_GROUP,
        FEED_ROW_NO,
        STATUS,
        SEQ,
        DELETE_FLAG)
 VALUES( 
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        SYSDATE,
        ?, 
        SYSDATE,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?
        )
		    
        ]]>
	</query>

	<query id="FeedResult.AddFurRack" desc="新增加热炉跟踪表">
        <![CDATA[
       INSERT INTO MIL_FUR_RACK
  (MAT_NO,
   LOT_NO,
   STOVE_NO,
   JUDGE_STOVE_NO,
   PLINE_CODE,
   COL_MODE,
   COL_TIME,
   COL_USER,
   COL_SHIFT,
   COL_GROUP,
   STATUS,
   SEQ,
   RESULT_NO,
   PRO_PLAN_ID,
   GX_PLAN_NO)
VALUES
  (?, ?, ?, ?, ?, ?, SYSDATE, ?, ?, ?, ?, ?, ?, ?, ?)
		    
        ]]>
	</query>


	<query id="FeedResult.AddFurHistory" desc="新增加热炉跟踪历史表">
        <![CDATA[
       INSERT INTO MIL_FUR_HISTORY(
        MAT_NO,
        LOT_NO,
        STOVE_NO,
        JUDGE_STOVE_NO,
        PLINE_CODE,      
        COL_MODE,
        COL_TIME,
        COL_USER,
        COL_SHIFT,
        COL_GROUP,
         STATUS,
        SEQ,
        DELETE_FLAG
       )
 VALUES( 
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        SYSDATE,
        ?,
        ?,
        ?,
		?,
		?,
        ?)
		    
        ]]>
	</query>

	<query id="FeedResult.AddPerRack" desc="新增穿孔踪表">
        <![CDATA[
         INSERT INTO MIL_PERFORATION_RACK
  (MAT_NO,
   LOT_NO,
   STOVE_NO,
   JUDGE_STOVE_NO,
   PLINE_CODE,
   COL_MODE,
   COL_TIME,
   COL_USER,
   COL_GROUP,
   COL_SHIFT,
   STATUS,
   SEQ,
   RESULT_NO,
   PRO_PLAN_ID,
   GX_PLAN_NO)
VALUES
  (?, ?, ?, ?, ?, ?, SYSDATE, ?, ?, ?, ?, ?, ?, ?, ?)
        ]]>
	</query>


	<query id="FeedResult.AddPerHistory" desc="新增穿孔历史表">
        <![CDATA[
         INSERT INTO MIL_PERFORATION_HISTORY(
      
        MAT_NO,
        LOT_NO,
        STOVE_NO,
        JUDGE_STOVE_NO,
        PLINE_CODE,
         COL_MODE,
        COL_TIME,        
        COL_USER,
        COL_GROUP,
        COL_SHIFT,
        STATUS,
        SEQ,
        DELETE_FLAG,
        )
 VALUES( 
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        SYSDATE,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?)
		    
        ]]>
	</query>

	<query id="FeedResult.AddRollRack" desc="新增连轧踪表">
        <![CDATA[
        INSERT INTO MIL_ROLLING_RACK
  (MAT_NO,
   LOT_NO,
   STOVE_NO,
   JUDGE_STOVE_NO,
   PLINE_CODE,
   COL_MODE,
   COL_TIME,
   
   COL_USER,
   COL_GROUP,
   COL_SHIFT,
   STATUS,
   SEQ,
   RESULT_NO,
   PRO_PLAN_ID,
   GX_PLAN_NO)
VALUES
  (?, ?, ?, ?, ?, ?, SYSDATE, ?, ?, ?, ?, ?, ?, ?, ?)
        ]]>
	</query>

	<query id="FeedResult.AddRollHistory" desc="新增连轧历史表">
        <![CDATA[
         INSERT INTO MIL_ROLLING_HISTORY(
      
        MAT_NO,
        LOT_NO,
        STOVE_NO,
        JUDGE_STOVE_NO,
        PLINE_CODE,
        COL_MODE,
        COL_TIME,
        
        COL_USER,
        COL_GROUP,
        COL_SHIFT,
        STATUS,
        SEQ,
        DELETE_FLAG)
 VALUES( 
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        SYSDATE,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?)
		    
        ]]>
	</query>

	<query id="FeedResult.AddReFurRack" desc="新增再加热炉踪表">
        <![CDATA[
        INSERT INTO MIL_REFUR_RACK
  (MAT_NO,
   LOT_NO,
   STOVE_NO,
   JUDGE_STOVE_NO,
   PLINE_CODE,
   COL_MODE,
   COL_TIME,
   COL_USER,
   COL_GROUP,
   COL_SHIFT,
   STATUS,
   SEQ,
   RESULT_NO,
   PRO_PLAN_ID,
   GX_PLAN_NO)
VALUES
  (?, ?, ?, ?, ?, ?, SYSDATE, ?, ?, ?, ?, ?, ?, ?, ?)
        ]]>
	</query>

	<query id="FeedResult.AddReFurHistory" desc="新增再加热炉历史表">
        <![CDATA[
         INSERT INTO MIL_REFUR_HISTORY(
      
        MAT_NO,
        LOT_NO,
        STOVE_NO,
        JUDGE_STOVE_NO,
        PLINE_CODE,
         COL_MODE,
        COL_TIME,
        COL_USER,
        COL_GROUP,
        COL_SHIFT,
        STATUS,
        SEQ,
        DELETE_FLAG)
 VALUES( 
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        SYSDATE,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?)
		    
        ]]>
	</query>

	<query id="FeedResult.AddSizingRack" desc="新增定径跟踪表">
        <![CDATA[
         INSERT INTO MIL_SIZING_RACK
  (MAT_NO,
   LOT_NO,
   STOVE_NO,
   JUDGE_STOVE_NO,
   PLINE_CODE,
   COL_MODE,
   COL_TIME,
   COL_USER,
   COL_GROUP,
   COL_SHIFT,
   STATUS,
   SEQ,
   RESULT_NO,
   PRO_PLAN_ID,
   GX_PLAN_NO)
VALUES
  (?, ?, ?, ?, ?, ?, SYSDATE, ?, ?, ?, ?, ?, ?, ?, ?)
        ]]>
	</query>

	<query id="FeedResult.AddSizingHistory" desc="新增定径历史表">
        <![CDATA[
         INSERT INTO MIL_SIZING_HISTORY(
      
        MAT_NO,
        LOT_NO,
        STOVE_NO,
        JUDGE_STOVE_NO,
        PLINE_CODE,
         COL_MODE,
        COL_TIME,
        COL_USER,
        COL_GROUP,
        COL_SHIFT,
        STATUS,
        SEQ,
        DELETE_FLAG)
 VALUES( 
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        SYSDATE,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?)
		    
        ]]>
	</query>

	<query id="FeedResult.AddSawRack" desc="新增管排锯跟踪表">
        <![CDATA[
         INSERT INTO MIL_SAW_RACK
  (MAT_NO,
   LOT_NO,
   STOVE_NO,
   JUDGE_STOVE_NO,
   PLINE_CODE,
   COL_MODE,
   COL_TIME,
   COL_USER,
   COL_SHIFT,
   COL_GROUP， STATUS,
   SEQ,
   RESULT_NO,
   PRO_PLAN_ID,
   GX_PLAN_NO)
VALUES
  (?, ?, ?, ?, ?, ?, SYSDATE, ?, ?, ?, ?, ?, ?, ?, ?)
        ]]>
	</query>

	<query id="FeedResult.AddSawHistory" desc="新增管排锯历史表">
        <![CDATA[
         INSERT INTO MIL_SAW_HISTORY(
        MAT_NO,
        LOT_NO,
        STOVE_NO,
        JUDGE_STOVE_NO,
        PLINE_CODE,
        COL_MODE,
        COL_TIME,
        COL_USER,
        COL_SHIFT,
        COL_GROUP，
        STATUS,
        SEQ,
        DELETE_FLAG)
 VALUES( 
      
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        SYSDATE,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?)
        ]]>
	</query>

	<query id="FeedResult.AddTestingRack" desc="新增探伤锯跟踪表">
        <![CDATA[
         INSERT INTO MIL_TESTING_RACK
  (MAT_NO,
   LOT_NO,
   STOVE_NO,
   JUDGE_STOVE_NO,
   PLINE_CODE,
   COL_MODE,
   COL_TIME,
   COL_USER,
   COL_SHIFT,
   COL_GROUP,
   STATUS,
   SEQ,
   RESULT_NO,
   PRO_PLAN_ID,
   GX_PLAN_NO)
VALUES
  (?, ?, ?, ?, ?, ?, SYSDATE, ?, ?, ?, ?, ?, ?, ?, ?)
        ]]>
	</query>

	<query id="FeedResult.AddTestingHistory" desc="新增探伤锯历史表">
        <![CDATA[
         INSERT INTO MIL_TESTING_HISTORY(
        MAT_NO,
        LOT_NO,
        STOVE_NO,
        JUDGE_STOVE_NO,
        PLINE_CODE,
        COL_MODE,
        COL_TIME,
        COL_USER,
        COL_SHIFT,
        COL_GROUP,
        STATUS,
        SEQ,
        DELETE_FLAG)
 VALUES( 
      
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        SYSDATE,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?)
        ]]>
	</query>


	<query id="FeedResult.AddStraighRack" desc="新增矫直跟踪表">
        <![CDATA[
         INSERT INTO MIL_STRAIGH_RACK
  (MAT_NO,
   LOT_NO,
   STOVE_NO,
   JUDGE_STOVE_NO,
   PLINE_CODE,
   COL_MODE,
   COL_TIME,
   COL_USER,
   COL_SHIFT,
   COL_GROUP,
   STATUS,
   SEQ,
   RESULT_NO,
   PRO_PLAN_ID,
   GX_PLAN_NO)
VALUES
  (?, ?, ?, ?, ?, ?, SYSDATE, ?, ?, ?, ?, ?, ?, ?, ?)
        ]]>
	</query>

	<query id="FeedResult.AddStraighHistory" desc="新增矫直历史表">
        <![CDATA[
         INSERT INTO MIL_STRAIGH_HISTORY(
        MAT_NO,
        LOT_NO,
        STOVE_NO,
        JUDGE_STOVE_NO,
        PLINE_CODE,
        COL_MODE,
        COL_TIME,
        COL_USER,
        COL_SHIFT,
        COL_GROUP,
        STATUS,
        SEQ,
        DELETE_FLAG)
 VALUES( 
      
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        SYSDATE,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?)
        ]]>
	</query>

	<query id="FeedResult.AddQARack" desc="新增质检锯跟踪表">
        <![CDATA[
         INSERT INTO MIL_QA_RACK
  (MAT_NO,
   LOT_NO,
   STOVE_NO,
   JUDGE_STOVE_NO,
   PLINE_CODE,
   COL_MODE,
   COL_TIME,
   COL_USER,
   COL_SHIFT,
   COL_GROUP,
   STATUS,
   SEQ,
   RESULT_NO,
   PRO_PLAN_ID,
   GX_PLAN_NO)
VALUES
  (?, ?, ?, ?, ?, ?, SYSDATE, ?, ?, ?, ?, ?, ?, ?, ?)
        ]]>
	</query>
	<query id="FeedResult.AddSrcapSEQRack" desc="新增剔除管坯序列表">
        <![CDATA[
        INSERT INTO MIL_SLAB_SCRAP_SEQ(
        JUDGE_STOVE_NO,
        PROCESS_NO,
        SEQ,
        TIME,
        FLAG,
        REMARK,
        COL_MODE,
        COL_TIME,
        COL_USER,
        COL_SHIFT,
        COL_GROUP)
 VALUES( 
        ?,
        ?,
        ?,
        SYSDATE,
        ?,
        ?,
        ?,
        SYSDATE,
        ?,
        ?,
        ?)
		    
        ]]>
	</query>

	<query id="FeedResult.AddSrcapRack" desc="新增剔除管坯表">
        <![CDATA[
        INSERT INTO MIL_SLAB_SCRAP(
        JUDGE_STOVE_NO,
        PROCESS_NO,
        SRACP_REASON,
        MAT_NO,
        GROUP_FLAG,
        NEW_HEAT_NO,
        BEFORE_MAT_NO,
        FLAG,
        REMARK,
        COL_MODE,
        COL_TIME,
        COL_USER,
        COL_SHIFT,
        COL_GROUP)
 VALUES( 
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        SYSDATE,
        ?,
        ?,
        ?)
		    
        ]]>
	</query>

	<query id="FeedResult.UpdateFeedRowStatue" desc="修改上料行标识">
        <![CDATA[
        update MIL_FEED_PLAN t set t.SAW_FALG ='#SAW_FALG#'
        where t.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#' 

		    
        ]]>
	</query>
	<query id = "FeedResult.UpdateFeedRowStatue1" desc = "上料修改标识">
	DECLARE
BEGIN
  update MIL_FEED_PLAN t
     set t.SAW_FALG = '#SAW_FALG#'
   where t.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
     AND T.PLINE_CODE = '#PLINE_CODE#';
  INSERT INTO MIL_FEEDSAW_RESULT
    (RESULT_NO,
     LOT_NO,
     STOVE_NO,
     JUDGE_STOVE_NO,
     PLINE_CODE,
     START_TIME,
     CUT_TARGET,
     COL_MODE,
     COL_TIME,
     COL_USER,
     COL_SHIFT,
     COL_GROUP,
     PRO_PLAN_ID,
     GX_PLAN_NO)
  VALUES
    ('#RESULT_NO#',
     '#LOT_NO#',
     '#STOVE_NO#',
     '#JUDGE_STOVE_NO#',
     '#PLINE_CODE#',
     SYSDATE,
     '#CUT_TARGET#',
     '#COL_MODE#',
     SYSDATE,
     '#COL_USER#',
     '#COL_SHIFT#',
     '#COL_GROUP#',
     '#PRO_PLAN_ID#',
     '#GX_PLAN_NO#');
  update mil_plan
     set status = '05', FEED_TIME = sysdate, LOT_SEQ = '#LOT_SEQ#'
   where LOT_NO = '#LOT_NO#'
     and Judge_stove_no = '#JUDGE_STOVE_NO#'
     and ID = '#RESULT_NO#'
     AND NVL(PRO_PLAN_ID,'/') = NVL('#PRO_PLAN_ID#','/')
     AND NVL(GX_PLAN_NO,'/') = NVL('#GX_PLAN_NO#','/');
END;
	</query>
	<query id = "FeedResult.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 = '#RESULT_NO#'
 ORDER BY T.FEED_ROW_NO ASC
	</query>
	<query id = "FeedResult.SelectFeedToalWgt" desc = "查询上料总量">
SELECT NVL(SUM(T.MAT_TOTAL_HEIGHT -
               T.FEED_NUM * DECODE(T.CUT_TARGET,
                                   '返废',
                                   NVL(T.CUT_WEIGHT, 0),
                                   /*'回库',
                                   NVL(T.CUT_WEIGHT , 0),*/
                                   0)),
           0) MAT_TOTAL_HEIGHT
  FROM MIL_FEED_PLAN T
 WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
	</query>
	<query id = "FeedResult.SelectFeedToalNum" desc = "查询总支数">
	SELECT SUM(T1.ACT_COUNT) ACT_COUNT
  FROM (SELECT (T.SAW_NUM * S.DB_NUM * S.FEED_NUM) ACT_COUNT
          FROM MIL_PLAN T
          LEFT JOIN MIL_FEED_PLAN S ON T.JUDGE_STOVE_NO = S.JUDGE_STOVE_NO WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#') T1
	</query>
	
	<query id = "FeedResult.SelectProPlanID" desc = "查询轧管订单编号">
	select MAX(T.PRO_PLAN_ID) PRO_PLAN_ID, MAX(T.GX_PLAN_NO) GX_PLAN_NO
  from MIL_PLAN t
 WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND T.LOT_NO = '#LOT_NO#'
	</query>
	
	<query id = "FeedResult.SelectContractNo" desc = "查找外径壁厚">
	SELECT G.OUTDIAMETER,G.AIMWALLTHICK
  FROM MIL_PLAN T
  LEFT JOIN MIL_FEED_PLAN S ON T.JUDGE_STOVE_NO = S.JUDGE_STOVE_NO
  LEFT JOIN PLN_ORDER_ZG G ON T.CONTRACT_NO = G.ORDER_NO||'/'||G.ORDER_SEQ
 WHERE T.JUDGE_STOVE_NO = ?
 AND ROWNUM = 1
	</query>
	<query id = "FeedResult.queryMatNoM" desc = "生成材料号">
	SELECT T.M_M_MAT_NO FROM PORT_MIL_BATCH_SAMPLE_RESULT T WHERE T.JUDGE_STOVE_NO=? AND T.LOT_NO=? AND T.PLAN_ID = ? ORDER BY T.MAT_NO DESC
	</query>
	<query id = "FeedResult.insertProcess" 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,
        INPUT_WEIGHT,
        BAL_YEAR_MONTH,
        PRO_PLAN_ID,
        GX_PLAN_NO)
 VALUES( 
        ?,
        ?,
        ?,
        ?,
        '',
        ?,
        '',
        ?,
        ?,
        '0',
        '1',
        '',
        '',
        '',
        '',
        '',
        '',
        ?,
        '',
        ?,
        '1',
        TO_DATE(?,'YYYY-MM-DD HH24:MI:SS'),
        '0',
        ?,
        '0',
        '',
        '',
        ?,
        ?,
        ?,?,?)
    </query>
    <query id = "FeedResult.SelectProPlanId1" desc = "查询排产订单号、排产序号">
	    SELECT T.PRO_PLAN_ID,
       T.GX_PLAN_NO,
       T.BACK_SLAB_FLAG,
       TO_CHAR(T.START_TIME, 'YYYYMM') START_TIME
  FROM MIL_PLAN T
 WHERE T.ID = '#RESULT_NO#'
   AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND T.LOT_NO = '#LOT_NO#'
    </query>
    <query id = "insertProcess1.selectScrap" desc = "上料锯切查询剔除序号">
     <![CDATA[
    SELECT T.PROCESS_NO, T.SEQ, T.JUDGE_STOVE_NO, T.MAT_NO
  FROM MIL_SLAB_SCRAP_SEQ T
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.PRO_PLAN_ID  || '&' LIKE '%' || ? || '%'
   AND T.GX_PLAN_NO  || '&' LIKE '%' || ? || '%'
   AND T.PROCESS_NO IN ('0', '1')
   ]]>
    </query>
    <query id = "insertProcess1.UpdateFlag" desc = "上料切前剔除修改进程表">
    <![CDATA[
    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.PRO_PLAN_ID  || '&' LIKE '%' || ? || '%'
                                     AND T.GX_PLAN_NO  || '&' LIKE '%' || ? || '%'
                                     AND T.Status = '0')
                           WHERE RN = '1'
                             AND IS_SAMPLE_PIPE = '0'
                             AND INSTORE_FLAG = '0')
                   WHERE M_M_MAT_NO = ?) 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.PRO_PLAN_ID  || '&' LIKE '%' || ? || '%'
                                      AND T.GX_PLAN_NO  || '&' LIKE '%' || ? || '%'
                                      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="FeedResult.PerToolQuery" desc="穿孔工具更换实绩查询">
        <![CDATA[
       SELECT 
       GUIDE_CHANGE,      
       GUIDE_CHANGE_TIME, 
       RESULT_NO,
       PLUG_CHANGE,      
       PLUG_CHANGE_TIME,
       BAR_CHANGE,       
        BAR_CHANGE_TIME,
            TOOL_CHANGE,       
       TOOL_CHANGE_TIME,
      case COL_SHIFT 
       WHEN '0' THEN '常白班'
       WHEN '1' THEN '早班'
       WHEN '2' THEN '中班'
       WHEN '3' THEN '夜班'
                end as COL_SHIFT,
        case COL_GROUP
       WHEN '1' THEN '甲'
       WHEN '2' THEN '乙'
       WHEN '3' THEN '丙'
       WHEN '4' THEN '丁'
               end as COL_GROUP,
       COL_USER,
      TO_CHAR(CREAT_TIME, 'YYYY-MM-DD HH24:MI:SS') CREAT_TIME,
       PLINE_CODE
 FROM MIL_PER_TOOL WHERE
  1=1
       AND PLINE_CODE=?
       AND COL_SHIFT=?
       AND COL_GROUP=?
       AND CREAT_TIME BETWEEN TO_DATE(?,'YYYY-MM-DD HH24:MI:SS') AND TO_DATE(?,'YYYY-MM-DD HH24:MI:SS')

		    
        ]]>
	</query>
	
		<query id="FeedResult.RollToolQuery" desc="连轧工具更换实绩查询">
        <![CDATA[
       SELECT 
       RESULT_NO,
       MANDREL_CHANGE,
        MANDREL_CHANGE_TIME,
       ROLL_CHANGE,
        ROLL_CHANGE_TIME,
       EXMIL_CHANGE,
      EXMIL_CHANGE_TIME,
      case COL_SHIFT 
       WHEN '0' THEN '常白班'
       WHEN '1' THEN '早班'
       WHEN '2' THEN '中班'
       WHEN '3' THEN '夜班'
                end as COL_SHIFT,
       case COL_GROUP
       WHEN '1' THEN '甲'
       WHEN '2' THEN '乙'
       WHEN '3' THEN '丙'
       WHEN '4' THEN '丁'
               end as COL_GROUP,
       COL_USER,
        TO_CHAR(CREAT_TIME, 'YYYY-MM-DD HH24:MI:SS') CREAT_TIME,
       PLINE_CODE
 FROM MIL_ROLLING_TOOL where
  1=1
       AND PLINE_CODE=?
       AND COL_SHIFT=?
       AND COL_GROUP=?
       AND CREAT_TIME BETWEEN TO_DATE(?,'YYYY-MM-DD HH24:MI:SS') AND TO_DATE(?,'YYYY-MM-DD HH24:MI:SS')
 

		    
        ]]>
	</query>
	
		<query id="FeedResult.SizingToolQuery" desc="定径工具更换实绩查询">
        <![CDATA[
      SELECT 
     TO_CHAR(CREAT_TIME, 'YYYY-MM-DD HH24:MI:SS') CREAT_TIME,
       PLINE_CODE,
       RESULT_NO,
       TOOL_CHANGE,       
       TOOL_CHANGE_TIME,
     case COL_SHIFT 
       WHEN '0' THEN '常白班'
       WHEN '1' THEN '早班'
       WHEN '2' THEN '中班'
       WHEN '3' THEN '夜班'
                end as COL_SHIFT,
       case COL_GROUP
       WHEN '1' THEN '甲'
       WHEN '2' THEN '乙'
       WHEN '3' THEN '丙'
       WHEN '4' THEN '丁'
               end as COL_GROUP,
               COL_USER
 FROM MIL_SIZING_TOOL 
 WHERE
 1=1
 AND PLINE_CODE=?
       AND COL_SHIFT=?
       AND COL_GROUP=?
       AND CREAT_TIME BETWEEN TO_DATE(?,'YYYY-MM-DD HH24:MI:SS') AND TO_DATE(?,'YYYY-MM-DD HH24:MI:SS')
 
		    
        ]]>
	</query>




	<query id="FeedResult.UpdateFeedRowResult" desc="保存上料行实绩">
        <![CDATA[
         UPDATE MIL_FEED_PLAN
   		SET 
        SCRAP_DBNUM = '#SCRAP_DBNUM#',
        QUALIFIED_NUM = '#QUALIFIED_NUM#',        
        ACT_CUT_LENGTH = '#CUT_LENGTH#',
        ACT_CUT_WEIGHT = '#CUT_WEIGHT#',
        SCRAP_FEEDNUM = '#SCRAP_FEEDNUM#',
        SAW_FALG = '#SAW_FALG#',
        CHANGE_NUM = '#CHANGE_NUM#',
        REMARK = '#REMARK#'
 		WHERE
 		
 		JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
 		AND FEED_ROW_NO = '#FEED_ROW_NO#'
		    
        ]]>
	</query>
	
	
	<query id="FeedResult.FeedRowResultBack" desc="保存上料行实绩">
        <![CDATA[
         UPDATE MIL_FEED_PLAN
   		SET 
        SCRAP_DBNUM = '',
        QUALIFIED_NUM = '',        
        CUT_LENGTH = '',
        CUT_WEIGHT = '',
        SCRAP_FEEDNUM = '',
        SAW_FALG = '0',
        CHANGE_NUM = '',
        REMARK = ''
 		WHERE
 		
 		JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
		    
        ]]>
	</query>

	<query id="FeedResult.UpdateFeedSawStartTime" desc="修改锯切实绩开始时间">
        <![CDATA[
        UPDATE MIL_FEEDSAW_RESULT
   SET START_TIME = to_date('#START_TIME#', 'yyyy-MM-dd hh24:mi:ss')
 WHERE JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND NVL(PRO_PLAN_ID,'/') = NVL('#PRO_PLAN_ID#','/')
   AND NVL(GX_PLAN_NO,'/') = NVL('#GX_PLAN_NO#','/')
        ]]>
	</query>

	<query id="FeedResult.UpdateFeedRackStatue" desc="修改上料跟踪表物料状态">
        <![CDATA[
         UPDATE MIL_FEED_RACK
   		SET 
        STATUS = '2'
        
 		WHERE
 		JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
 		and FEED_ROW_NO = '#FEED_ROW_NO#'
 		AND STATUS = '1'
		    
        ]]>
	</query>

	<query id="FeedResult.UpdateFeedRowFeedNum" desc="修改上料计划表上料剔除、合格支数">
        <![CDATA[
        UPDATE MIL_FEED_PLAN
   SET FEED_NUM      = FEED_NUM - 1,
       SCRAP_FEEDNUM = SCRAP_FEEDNUM + 1,
       QUALIFIED_NUM = QUALIFIED_NUM - DB_NUM
 WHERE JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND NVL(PRO_PLAN_ID, '/') = NVL('#PRO_PLAN_ID#', '/')
   AND NVL(GX_PLAN_NO, '/') = NVL('#GX_PLAN_NO#', '/')
   AND FEED_ROW_NO = '#FEED_ROW_NO#'
        ]]>
	</query>


	<query id="FeedResult.UpdateFeedRowDBNum" desc="修改上料计划表单倍坯剔除、合格支数">
        <![CDATA[
       UPDATE MIL_FEED_PLAN
   SET SCRAP_DBNUM = SCRAP_DBNUM + 1, QUALIFIED_NUM = QUALIFIED_NUM - 1
 WHERE JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND NVL(PRO_PLAN_ID, '/') = NVL('#PRO_PLAN_ID#', '/')
   AND NVL(GX_PLAN_NO, '/') = NVL('#GX_PLAN_NO#', '/')
   AND FEED_ROW_NO = '#FEED_ROW_NO#'
        ]]>
	</query>

	<query id="FeedResult.AddFeedSawResult" desc="新增上料锯切实绩">
        <![CDATA[
          INSERT INTO MIL_FEEDSAW_RESULT(
          RESULT_NO,
        LOT_NO,
        STOVE_NO,
        JUDGE_STOVE_NO,
        PLINE_CODE,
        START_TIME,
        CUT_TARGET,
        COL_MODE,
        COL_TIME,
        COL_USER,
        COL_SHIFT,
        COL_GROUP)
 VALUES( 
        '#RESULT_NO#',
        '#LOT_NO#',
        '#STOVE_NO#',
        '#JUDGE_STOVE_NO#',
        '#PLINE_CODE#',
        SYSDATE,
        '#CUT_TARGET#',
        '#COL_MODE#',
        SYSDATE,
        '#COL_USER#',
        '#COL_SHIFT#',
        '#COL_GROUP#')
		    
        ]]>
	</query>

	<query id="FeedResult.FeedPlanTotalQuery" desc="查询对应炉号上料行所有实绩">
        <![CDATA[
        select sum(t.scrap_dbnum) AS AFTER_SCRAP_NUM,
        sum(t.scrap_feednum) AS BEFORE_SCRAP_NUM,
        sum(t.qualified_num) AS CUT_NUM,
        sum(t.act_cut_length) AS CUT_LENGTH,
        sum(t.act_cut_weight) AS CUT_WEIGHT,
        sum(t.feed_num) AS FEED_NUM
        from mil_feed_plan t 
        where t.judge_stove_no = ?
       	
		    
        ]]>
	</query>

	<query id="FeedResult.FeedResultNode" desc="锯切结炉">
        <![CDATA[
      	UPDATE MIL_FEEDSAW_RESULT
   SET FEED_NUM         = '#FEED_NUM#',
       BEFORE_SCRAP_NUM = '#BEFORE_SCRAP_NUM#',
       AFTER_SCRAP_NUM  = '#AFTER_SCRAP_NUM#',
       CUT_NUM          = '#CUT_NUM#',
       CUT_LENGTH       = '#CUT_LENGTH#',
       CUT_WEIGHT       = '#CUT_WEIGHT#',
       END_TIME         = SYSDATE,
       NODE_FUR_FLAG    = '#NODE_FUR_FLAG#',
       COL_TIME         = SYSDATE,
       COL_USER         = '#COL_USER#',
       COL_SHIFT        = '#COL_SHIFT#',
       COL_GROUP        = '#COL_GROUP#',
       QA_TON           = '#QA_TON#',
       USER_ID          = '#USER_ID#',
       REMARK           = NVL('#REMARK#','/')
 WHERE JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND NVL(PRO_PLAN_ID, '/') = NVL('#PRO_PLAN_ID#', '/')
   AND NVL(GX_PLAN_NO, '/') = NVL('#GX_PLAN_NO#', '/')
        ]]>
	</query>
	
	<!-- 
	<query id="FeedResult.FeedResultNode" desc="锯切结炉">
        <![CDATA[
      	 UPDATE MIL_FEEDSAW_RESULT
   		SET        
        FEED_NUM = '#FEED_NUM#',
        BEFORE_SCRAP_NUM = '#BEFORE_SCRAP_NUM#',
        AFTER_SCRAP_NUM = '#AFTER_SCRAP_NUM#',
        CUT_NUM = '#CUT_NUM#',
        CUT_LENGTH = '#CUT_LENGTH#',
        CUT_WEIGHT = '#CUT_WEIGHT#',
        END_TIME = SYSDATE,
        NODE_FUR_FLAG = '#NODE_FUR_FLAG#',
        COL_TIME = SYSDATE,
        COL_USER = '#COL_USER#',
        COL_SHIFT = '#COL_SHIFT#',
        COL_GROUP = '#COL_GROUP#',
        QA_TON = '#QA_TON#',
        USER_ID = '#USER_ID#',
        REMARK = '#LOT_NO#'
		 WHERE
       	JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
		    
        ]]>
	</query> -->
	
	<query id="FeedResult.UpdateMainPlanStatue" desc="锯切结炉">
        <![CDATA[
      	 UPDATE MIL_PLAN
   SET NODE_STATUS = '#STATUE#', STATUS = 10
 WHERE JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND NVL(PRO_PLAN_ID, '/') = NVL('#PRO_PLAN_ID#', '/')
   AND NVL(GX_PLAN_NO, '/') = NVL('#GX_PLAN_NO#', '/')
        ]]>   
	</query>
	
	<query id="FeedResult.UpdatePlnOrderZgS" desc="锯切结炉,回写PLN_ORDER_ZG_S">
        <![CDATA[
      	 UPDATE PLN_ORDER_ZG_S T
   SET T.BATCHED_NUM = NVL(T.BATCHED_NUM, 0) +
                       (SELECT A.CUT_NUM
                          FROM MIL_FEEDSAW_RESULT A
                         WHERE A.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'),
       T.BATCHED_WT  = NVL(T.BATCHED_WT, 0) +
                       (SELECT A.QA_TON
                          FROM MIL_FEEDSAW_RESULT A
                         WHERE A.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#')
 WHERE T.PRO_PLAN_ID || '-' || T.GX_PLAN_NO =
       (SELECT M.SEQ
          FROM MIL_PLAN M
         WHERE M.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#')
      	   
        ]]>   
	</query>
	
	<query id="FeedResult.UpdatePlnOrderZgSBack" desc="锯切结炉回退,回写PLN_ORDER_ZG_S">
        <![CDATA[
      	UPDATE PLN_ORDER_ZG_S T
   SET T.BATCHED_NUM = NVL(T.BATCHED_NUM, 0) -
                       (SELECT A.CUT_NUM
                          FROM MIL_FEEDSAW_RESULT A
                         WHERE A.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                           AND NVL(A.PRO_PLAN_ID, '/') = NVL('#PRO_PLAN_ID#', '/')
     						AND NVL(A.GX_PLAN_NO, '/') = NVL('#GX_PLAN_NO#', '/')),
       T.BATCHED_WT  = NVL(T.BATCHED_WT, 0) -
                       (SELECT A.QA_TON
                          FROM MIL_FEEDSAW_RESULT A
                         WHERE A.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                           AND NVL(A.PRO_PLAN_ID, '/') = NVL('#PRO_PLAN_ID#', '/')
                           AND NVL(A.GX_PLAN_NO, '/') = NVL('#GX_PLAN_NO#', '/'))
 WHERE T.PRO_PLAN_ID || '-' || T.GX_PLAN_NO =
       (SELECT M.SEQ
          FROM MIL_PLAN M
         WHERE M.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
           AND NVL(M.PRO_PLAN_ID, '/') = NVL('#PRO_PLAN_ID#', '/')
           AND NVL(M.GX_PLAN_NO, '/') = NVL('#GX_PLAN_NO#', '/'))
        ]]>   
	</query>
	
	<query id="FeedResult.UpdatePlnZyZgM" desc="回写虚拟炉计划表中生产状态(生产完成)">
        <![CDATA[
      	UPDATE PLN_ZY_ZG_M T SET T.PLANSTATUS = '30' 
      	WHERE T.HEAT_PLAN_NO = '#RESULT_NO#'
      	AND T.FEED_HEAT_NO = REGEXP_REPLACE('#JUDGE_STOVE_NO#', '-.*', '')
        ]]>   
	</query>
	
	<query id="FeedResult.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 = '#JUDGE_STOVE_NO#'
                   AND NVL(T.PRO_PLAN_ID, '/') = NVL('#PRO_PLAN_ID#', '/')
                   AND NVL(T.GX_PLAN_NO, '/') = NVL('#GX_PLAN_NO#', '/')
                 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>
	
	<query id="FeedResult.RollingCardQuery" desc="流通卡查询">
        <![CDATA[
      	SELECT A.AFTER_SCRAP_NUM    AS SCRAP_DBFEED,
       A.BEFORE_SCRAP_NUM   AS SCRAP_FEED,
       A.FEED_NUM           AS QUALIFIED_FEED,
       A.CUT_NUM            AS QUALIFIED_DBFEED,
       B.SCRAP_NUM          AS SCRAP_FUR,
       B.OUT_FUR_NUM        AS QUALIFIED_FUR,
       C.SCRAP_NUM          AS SCRAP_PER,
       C.PERFORATION_NUM    AS QUALIFIED_PER,
       D.SCRAP_NUM          AS SCRAP_ROLLING,
       D.QUALIFIED_NUM      AS QUALIFIED_ROLLING,
       E.SCRAP_NUM          AS SCRAP_REFUR,
       E.OUT_FUR_NUM        AS QUALIFIED_REFUR,
       G.SCRAP_NUM          AS SCRAP_SIZING,
       G.PRODUCT_NUM        AS QUALIFIED_SIZING,
       H.SCRAP_NUM          AS SCRAP_SAW_BE,
       H.CUT_NUM            AS QUALIFIED_SAW_BE,
       H.SCRAP_DBNUM        AS SCRAP_SAW,
       H.CUT_DBNUM          AS QUALIFIED_SAW,
       I.SCRAP_NUM          AS SCRAP_STRAIGHT,
       I.Qualified_Num      AS QUALIFIED_STRAIGHT,
       I.OFFLINE_NUM_TOTAL  AS OFFLINE_STRAIGHT,
       I.BACKLINE_NUM_TOTAL AS BACKLINE_STRAIGHT,
       --COALESCE(K.SCRAP_NUM,0) AS SCRAP_TESTING,
       --COALESCE(K.QUALIFIED_NUM,0) AS QUALIFIED_TESTING,
       --COALESCE(K.OFFLINE_NUM,0)   AS OFFLINE_TESTING,
       --COALESCE(K.BACKLINE_NUM,0 ) AS BACKLINE_TESTING
       K.SCRAP_NUM AS SCRAP_TESTING,
       K.QUALIFIED_NUM AS QUALIFIED_TESTING,
       K.OFFLINE_NUM + K.INSPECTIONED_OFFLINE_NUM AS OFFLINE_TESTING,
       K.BACKLINE_NUM AS BACKLINE_TESTING,
       M.QUALIFIED_BRANCH AS QUALIFIED_BRANCH,
       M.OFFLINE_QUANTITY AS OFFLINE_QUANTITY,
       M.WASTE_QUANTITY AS WASTE_QUANTITY
  FROM MIL_FEEDSAW_RESULT       A,
       MIL_FUR_RESULT           B,
       MIL_PERFORATION_RESULT   C,
       MIL_ROLLING_RESULT       D,
       MIL_REFUR_RESULT         E,
       MIL_SIZING_RESULT        G,
       MIL_SAW_RESULT           H,
       MIL_STRAIGHTENING_RESULT I
       --, MIL_ET_RESULT J
      ,
       MIL_MT_RESULT K
       --, MIL_UL_RESUL L
      ,
       mil_surface_result M
 WHERE A.JUDGE_STOVE_NO = B.JUDGE_STOVE_NO(+)
   AND A.JUDGE_STOVE_NO = C.JUDGE_STOVE_NO(+)
   AND A.JUDGE_STOVE_NO = D.JUDGE_STOVE_NO(+)
   AND A.JUDGE_STOVE_NO = E.JUDGE_STOVE_NO(+)
   AND A.JUDGE_STOVE_NO = G.JUDGE_STOVE_NO(+)
   AND A.JUDGE_STOVE_NO = H.JUDGE_STOVE_NO(+)
   AND A.JUDGE_STOVE_NO = I.JUDGE_STOVE_NO(+)
   AND A.JUDGE_STOVE_NO = K.JUDGE_STOVE_NO(+)
   
      --AND J.JUDGE_STOVE_NO = K.JUDGE_STOVE_NO (+)
      --AND K.JUDGE_STOVE_NO = L.JUDGE_STOVE_NO (+)
   AND A.JUDGE_STOVE_NO = M.JUDGE_STOVE_NO(+)
   AND A.JUDGE_STOVE_NO = ?
   AND A.PRO_PLAN_ID  || '&' LIKE '%' || ? || '%'
   AND A.GX_PLAN_NO  || '&' LIKE '%' || ? || '%'
        ]]>
	</query>
	<query id = "FeedResult.getRollingCardBackLine" desc = "返线流通卡">
	SELECT 
        I.SCRAP_NUM AS SCRAP_STRAIGHT,
        I.Qualified_Num AS QUALIFIED_STRAIGHT,
        I.OFFLINE_NUM_TOTAL AS OFFLINE_STRAIGHT,
                I.BACKLINE_NUM_TOTAL AS BACKLINE_STRAIGHT,
       
        K.SCRAP_NUM AS SCRAP_TESTING,
        K.QUALIFIED_NUM AS QUALIFIED_TESTING,
        K.OFFLINE_NUM + K.INSPECTIONED_OFFLINE_NUM  AS OFFLINE_TESTING,
        K.BACKLINE_NUM AS BACKLINE_TESTING,
        M.QUALIFIED_BRANCH AS QUALIFIED_BRANCH,
        M.OFFLINE_QUANTITY AS OFFLINE_QUANTITY,
        M.WASTE_QUANTITY AS WASTE_QUANTITY
        FROM  MIL_STRAIGHTENING_RESULT I
        , MIL_MT_RESULT K
        ,mil_surface_result M
        WHERE I.JUDGE_STOVE_NO = K.JUDGE_STOVE_NO (+)
        AND I.JUDGE_STOVE_NO = M.JUDGE_STOVE_NO(+)
        AND I.JUDGE_STOVE_NO = ?  
        AND NVL(I.PRO_PLAN_ID, '/') = NVL(?, '/')
        AND NVL(I.GX_PLAN_NO, '/') = NVL(?, '/')
	</query>
	
		<query id="FeedResult.getLotSeq" desc="查询生产批号最大流水号">
        <![CDATA[
      
        select max(lot_seq) from mil_plan where LOT_NO = ? 
      	
		    
        ]]>
	</query>
	
    <query id="FeedResult.RollingCardQuery1" desc="流通卡查询">
        <![CDATA[
      	SELECT A.AFTER_SCRAP_NUM    AS SCRAP_DBFEED,
       A.BEFORE_SCRAP_NUM   AS SCRAP_FEED,
       A.FEED_NUM           AS QUALIFIED_FEED,
       A.CUT_NUM            AS QUALIFIED_DBFEED,
       B.SCRAP_NUM          AS SCRAP_FUR,
       B.OUT_FUR_NUM        AS QUALIFIED_FUR,
       C.SCRAP_NUM          AS SCRAP_PER,
       C.PERFORATION_NUM    AS QUALIFIED_PER,
       D.SCRAP_NUM          AS SCRAP_ROLLING,
       D.QUALIFIED_NUM      AS QUALIFIED_ROLLING,
       F.SCRAP_NUM          AS SCRAP_REFUR,
       f.OUT_FUR_NUM        AS QUALIFIED_REFUR,
       G.SCRAP_NUM          AS SCRAP_SIZING,
       G.PRODUCT_NUM        AS QUALIFIED_SIZING,
       H.SCRAP_NUM          AS SCRAP_SAW_BE,
       H.CUT_NUM            AS QUALIFIED_SAW_BE,
       H.SCRAP_DBNUM        AS SCRAP_SAW,
       H.CUT_DBNUM          AS QUALIFIED_SAW,
       I.SCRAP_NUM          AS SCRAP_STRAIGHT,
       I.Qualified_Num      AS QUALIFIED_STRAIGHT,
       I.OFFLINE_NUM_TOTAL  AS OFFLINE_STRAIGHT,
       I.BACKLINE_NUM_TOTAL AS BACKLINE_STRAIGHT,
       --COALESCE(K.SCRAP_NUM,0) AS SCRAP_TESTING,      
       --COALESCE(K.QUALIFIED_NUM,0) AS QUALIFIED_TESTING,
       --COALESCE(K.OFFLINE_NUM,0)   AS OFFLINE_TESTING,
       --COALESCE(K.BACKLINE_NUM,0 ) AS BACKLINE_TESTING
       K.SCRAP_NUM AS SCRAP_TESTING,
       K.QUALIFIED_NUM AS QUALIFIED_TESTING,
       K.OFFLINE_NUM + K.INSPECTIONED_OFFLINE_NUM AS OFFLINE_TESTING,
       K.BACKLINE_NUM AS BACKLINE_TESTING,
       M.QUALIFIED_BRANCH AS QUALIFIED_BRANCH,
       M.OFFLINE_QUANTITY AS OFFLINE_QUANTITY,
       M.WASTE_QUANTITY AS WASTE_QUANTITY
  FROM MIL_FEEDSAW_RESULT       A,
       MIL_FUR_RESULT           B,
       MIL_PERFORATION_RESULT   C,
       MIL_ROLLING_RESULT       D,
       MIL_REFUR_RESULT         F,
       MIL_SIZING_RESULT        G,
       MIL_SAW_RESULT           H,
       MIL_STRAIGHTENING_RESULT I
       --, MIL_ET_RESULT J
      ,
       MIL_MT_RESULT K
       --, MIL_UL_RESUL L
      ,
       mil_surface_result M
 WHERE A.JUDGE_STOVE_NO = B.JUDGE_STOVE_NO(+)
   AND A.JUDGE_STOVE_NO = C.JUDGE_STOVE_NO(+)
   AND A.JUDGE_STOVE_NO = D.JUDGE_STOVE_NO(+)
   AND A.JUDGE_STOVE_NO = G.JUDGE_STOVE_NO(+)
   AND A.JUDGE_STOVE_NO = H.JUDGE_STOVE_NO(+)
   AND A.JUDGE_STOVE_NO = I.JUDGE_STOVE_NO(+)
   AND A.JUDGE_STOVE_NO = K.JUDGE_STOVE_NO(+)
   AND A.JUDGE_STOVE_NO = M.JUDGE_STOVE_NO(+)
   AND A.JUDGE_STOVE_NO = F.JUDGE_STOVE_NO(+)
   --AND NVL(A.PRO_PLAN_ID,'/') = NVL(B.PRO_PLAN_ID,'/')
   --AND NVL(A.PRO_PLAN_ID,'/') = NVL(C.PRO_PLAN_ID,'/')
   --AND NVL(A.PRO_PLAN_ID,'/') = NVL(D.PRO_PLAN_ID,'/')
      
   --AND NVL(A.PRO_PLAN_ID,'/') = NVL(G.PRO_PLAN_ID,'/')
   --AND NVL(A.PRO_PLAN_ID,'/') = NVL(H.PRO_PLAN_ID,'/')
   --AND NVL(A.PRO_PLAN_ID,'/') = NVL(I.PRO_PLAN_ID,'/')
   --AND NVL(A.PRO_PLAN_ID,'/') = NVL(K.PRO_PLAN_ID,'/')
   --AND NVL(A.PRO_PLAN_ID,'/') = NVL(M.PRO_PLAN_ID,'/')
   --AND NVL(A.PRO_PLAN_ID,'/') = NVL(F.PRO_PLAN_ID,'/')
      --AND J.JUDGE_STOVE_NO = K.JUDGE_STOVE_NO (+)
      --AND K.JUDGE_STOVE_NO = L.JUDGE_STOVE_NO (+)
   AND A.JUDGE_STOVE_NO = ?
   AND A.PRO_PLAN_ID  || '&' LIKE '%' || ? || '%'
   AND A.GX_PLAN_NO  || '&' LIKE '%' || ? || '%'
        ]]>
	</query>
	<query id="FeedResult.getRollingStaCard1" desc="168返线流通卡查询">
        <![CDATA[
      	SELECT 
        I.SCRAP_NUM AS SCRAP_STRAIGHT,
        I.Qualified_Num AS QUALIFIED_STRAIGHT,
        I.OFFLINE_NUM_TOTAL AS OFFLINE_STRAIGHT,
        I.BACKLINE_NUM_TOTAL AS BACKLINE_STRAIGHT,
        
        K.SCRAP_NUM AS SCRAP_TESTING,      
        K.QUALIFIED_NUM AS QUALIFIED_TESTING,
        K.OFFLINE_NUM + K.INSPECTIONED_OFFLINE_NUM  AS OFFLINE_TESTING,
        K.BACKLINE_NUM AS BACKLINE_TESTING,
        M.QUALIFIED_BRANCH AS QUALIFIED_BRANCH,
        M.OFFLINE_QUANTITY AS OFFLINE_QUANTITY,
        M.WASTE_QUANTITY AS WASTE_QUANTITY
        FROM  MIL_STRAIGHTENING_RESULT I
        , MIL_ET_RESULT K
        ,mil_surface_result M
        WHERE I.JUDGE_STOVE_NO = K.JUDGE_STOVE_NO (+)
        AND I.JUDGE_STOVE_NO = M.JUDGE_STOVE_NO (+)
        AND I.JUDGE_STOVE_NO = ?
        AND NVL(I.PRO_PLAN_ID, '/') = NVL(?, '/')
   		AND NVL(I.GX_PLAN_NO, '/') = NVL(?, '/')
        ]]>
	</query>
	<query id = "FeedResult.getRollingCard1BackLine" desc = "查询返线炉流通卡信息">
	SELECT 
        I.SCRAP_NUM AS SCRAP_STRAIGHT,
        I.Qualified_Num AS QUALIFIED_STRAIGHT,
        I.OFFLINE_NUM_TOTAL AS OFFLINE_STRAIGHT,
        I.BACKLINE_NUM_TOTAL AS BACKLINE_STRAIGHT,
        
        K.SCRAP_NUM AS SCRAP_TESTING,      
        K.QUALIFIED_NUM AS QUALIFIED_TESTING,
        K.OFFLINE_NUM + K.INSPECTIONED_OFFLINE_NUM   AS OFFLINE_TESTING,
        K.BACKLINE_NUM AS BACKLINE_TESTING,
        M.QUALIFIED_BRANCH AS QUALIFIED_BRANCH,
        M.OFFLINE_QUANTITY AS OFFLINE_QUANTITY,
        M.WASTE_QUANTITY AS WASTE_QUANTITY
        FROM  MIL_STRAIGHTENING_RESULT I
        , MIL_MT_RESULT K
        ,mil_surface_result M
        WHERE I.JUDGE_STOVE_NO = K.JUDGE_STOVE_NO (+)
        AND I.JUDGE_STOVE_NO = M.JUDGE_STOVE_NO (+)
        AND I.JUDGE_STOVE_NO = ?
        AND NVL(I.PRO_PLAN_ID, '/') = NVL(?, '/')
   		AND NVL(I.GX_PLAN_NO, '/') = NVL(?, '/')
	</query>
	<query id="FeedResult.AddScrapSlabSeq" desc="新增管号剔除序号表">
        <![CDATA[
       INSERT INTO MIL_SLAB_SCRAP_SEQ
  (JUDGE_STOVE_NO,
   PROCESS_NO,
   SEQ,
   TIME,
   FLAG,
   REMARK,
   COL_MODE,
   COL_TIME,
   COL_USER,
   COL_SHIFT,
   COL_GROUP,
   MAT_NO,
   PRO_PLAN_ID,
   GX_PLAN_NO)
VALUES
  ('#JUDGE_STOVE_NO#',
   '#PROCESS_NO#',
   '#SEQ#',
   SYSDATE,
   '#FLAG#',
   '#REMARK#',
   '#COL_MODE#',
   SYSDATE,
   '#COL_USER#',
   '#COL_SHIFT#',
   '#COL_GROUP#',
   '#MAT_NO#',
   '#PRO_PLAN_ID#',
   '#GX_PLAN_NO#')
        ]]>
	</query>

	<query id="FeedResult.UpdateFeedFeedNumStatue" desc="上料剔除后修改上料管状态">
        <![CDATA[
         UPDATE MIL_FEED_RACK
   SET STATUS = '#STATUS#', SCRAP_TIME = SYSDATE
 WHERE SEQ = '#SEQ#'
   AND JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND NVL(PRO_PLAN_ID, '/') = NVL('#PRO_PLAN_ID#', '/')
   AND NVL(GX_PLAN_NO, '/') = NVL('#GX_PLAN_NO#', '/')
   AND FEED_ROW_NO = '#FEED_ROW_NO#'
        ]]>
	</query>
	
	<query id="FeedResult.updateSlabScrapWeitgh" desc="修改废品投料量">
        <![CDATA[
        DECLARE
  V_JUDGE_STOVE_NO MIL_SLAB_SCRAP.JUDGE_STOVE_NO%type := ?;
  V_PLINE_CODE     MIL_SLAB_SCRAP.PLINE_CODE%type := ?;
  V_PRO_PLAN_ID    MIL_SLAB_SCRAP.PRO_PLAN_ID%type := ?;
  V_GX_PLAN_NO     MIL_SLAB_SCRAP.GX_PLAN_NO%type := ?;
BEGIN
  FOR MYROW IN (SELECT *
                  FROM MIL_SLAB_SCRAP T
                 WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
                   AND T.PLINE_CODE = V_PLINE_CODE
                   AND T.PRO_PLAN_ID = V_PRO_PLAN_ID
                   AND T.GX_PLAN_NO = V_GX_PLAN_NO) LOOP
  
    UPDATE MIL_SLAB_SCRAP T
       SET T.INPUT_WEIGHT =
           (SELECT SUM(P.INPUT_WEIGHT)
              FROM PORT_MIL_BATCH_SAMPLE_RESULT P
             WHERE P.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
               AND P.PLINE_CODE = V_PLINE_CODE
               AND P.M_MAT_NO = MYROW.MAT_NO)
     WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
       AND T.PLINE_CODE = V_PLINE_CODE
       AND T.PRO_PLAN_ID = V_PRO_PLAN_ID
       AND T.GX_PLAN_NO = V_GX_PLAN_NO
       AND T.MAT_NO = MYROW.MAT_NO;
  END LOOP;
END;
        ]]>
	</query>

	<query id="FeedResult.UpdateFeedDBNumStatue" desc="单倍剔除后修改上料管状态">
        <![CDATA[
         UPDATE MIL_FEED_RACK
   SET STATUS      = '#STATUS#',
       SCRAP_DBNUM = #SCRAP_DBNUM#,
       SCRAP_TIME  = SYSDATE
 WHERE SEQ = '#SEQ_FOR_UPDATE#'
   AND JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND NVL(PRO_PLAN_ID, '/') = NVL('#PRO_PLAN_ID#', '/')
   AND NVL(GX_PLAN_NO, '/') = NVL('#GX_PLAN_NO#', '/')
   AND FEED_ROW_NO = '#FEED_ROW_NO#'
        ]]>
	</query>

	<query id="FeedResult.ScrapSlabSeqQuery" desc="查询管坯剔除序号表">
        <![CDATA[
         SELECT 
      	 SEQ,
      	 TO_CHAR(TIME, 'YYYY-MM-DD HH24:MI:SS') TIME,
      	 FLAG,
      	 REMARK,
      	 COL_USER,
      	 COL_SHIFT,
     	 COL_GROUP
 		 FROM MIL_SLAB_SCRAP_SEQ
 		 WHERE
         JUDGE_STOVE_NO = ? 
         AND 
         PROCESS_NO = ?
        ]]>
	</query>

	<query id="FeedResult.UpdateFeedHistory" desc="修改上料历史表管坯状态">
        <![CDATA[
         UPDATE MIL_FEED_HISTORY
   		SET 
        STATUS = ?,
        SCRAP_DBNUM = ?
 		WHERE
		SEQ = ?  
		AND  
		JUDGE_STOVE_NO = ?
        ]]>
	</query>

	<query id="FeedResult.UpdateHistory" desc="修改历史表管坯状态">
        <![CDATA[
         UPDATE ?
   		SET 
        STATUS = '1'
 		WHERE  
		JUDGE_STOVE_NO = ?
		AND
		SEQ IN ( SELECT SEQ FROM 
		(SELECT ROWNUM AS ROW_NO ,SEQ FROM ? T WHERE T.STATUS = '0' ORDER BY SEQ)WHERE 
        ]]>
	</query>
	
	
	<query id="FeedResult.UpdateNodeRack" desc="修改跟踪表班次班组、结炉时间">
        <![CDATA[
        UPDATE MIL_FEED_RACK
   SET COL_USER  = '#COL_USER#',
       COL_SHIFT = '#COL_SHIFT#',
       COL_GROUP = '#COL_GROUP#',
       END_TIME  = sysdate
 WHERE JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND NVL(PRO_PLAN_ID, '/') = NVL('#PRO_PLAN_ID#', '/')
   AND NVL(GX_PLAN_NO, '/') = NVL('#GX_PLAN_NO#', '/')
   AND COL_SHIFT is null
   AND COL_GROUP is null
   AND END_TIME is null
        ]]>
	</query>

	<query id="FeedResult.AddScrapSlab" desc="新增坯料剔除表">
        <![CDATA[
       INSERT INTO MIL_SLAB_SCRAP(
        JUDGE_STOVE_NO,
        SEQ,
        PROCESS_NO,
        MAT_NO,
        FLAG,
        SCRAP_USER,
        TIME,
        SCRAP_SHIFT,
        SCRAP_GROUP)
 VALUES( 
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        to_date(?,'yyyy-mm-dd hh24:mi:ss'),
        ?,
        ?)
        ]]>
	</query>

	<query id="FeedResult.GetOperateResult" desc="获取IP对应的产线信息">
		SELECT
		IP_ADDRESS1,
		IP_ADDRESS2,
		IP_ADDRESS3,
		IP_ADDRESS4,
		PLINE_CODE,
		PROCESS_NO,
		OPERAT_CODE,
		OPERAT_NAME,
		REMARK
		FROM
		MIL_BASE_ADDRESS
		WHERE
		1=1
		AND IP_ADDRESS1=?
		OR IP_ADDRESS2=?
		OR IP_ADDRESS3=?
		OR IP_ADDRESS4=?
	</query>
	<query id="FeedResult.GetPCode" desc="获取PCODE">
	select t.pline_code 
	from COM_BASE_PLINE t 
	where t.department_desc=?
	</query>
    <query id="FeedResult.CheckIpAddress" desc="查询IP表对应记录">
     SELECT 
       IP_ADDRESS3,
       IP_ADDRESS4,
       IP_ADDRESS1,
       IP_ADDRESS2,
       PROCESS_NO,
       OPERAT_CODE,
       OPERAT_NAME,
       PLINE_CODE,
       REMARK
 FROM MIL_BASE_ADDRESS
 WHERE
 1=1
 AND PROCESS_NO='#PROCESS_NO#'
 AND OPERAT_CODE='#OPERAT_CODE#'
 AND PLINE_CODE='#PLINE_CODE#'
    </query>
    
    <query id="FeedResult.selectFeedRackAndProcess" desc="验证上料锯切工序 的进程表状态标识修改是否成功">
        <![CDATA[
	SELECT (SELECT NVL(SUM(T.ACT_COUNT), 0)
          FROM PORT_MIL_BATCH_SAMPLE_RESULT T
         WHERE 1 = 1
           AND T.STATUS = '1'
           AND TRIM(T.OP_PROCESS) = '0'
           AND T.JUDGE_STOVE_NO = ?
           AND T.PRO_PLAN_ID  || '&' LIKE '%' || ? || '%'
           AND T.GX_PLAN_NO  || '&' LIKE '%' || ? || '%') -
       NVL((SELECT SUM(CASE
                        WHEN A.STATUS = '3' THEN
                         A.DB_NUM
                        ELSE
                         A.SCRAP_DBNUM
                      END) * M.SAW_NUM
             FROM MIL_FEED_RACK A, MIL_PLAN M
            WHERE 1 = 1
              AND A.JUDGE_STOVE_NO = M.JUDGE_STOVE_NO
              AND A.JUDGE_STOVE_NO = ?
              AND A.PRO_PLAN_ID  || '&' LIKE '%' || ? || '%'
              AND A.GX_PLAN_NO   || '&' LIKE '%' || ? || '%'
              AND A.STATUS IN ('3', '4')
            GROUP BY M.SAW_NUM),
           0) ACT_COUNT
  FROM DUAL
        ]]>
	</query>
	
	<query id="FeedResult.updateRack" desc="防止跟踪表重复剔除管子">
        <![CDATA[
		UPDATE #NextTableName#
	   SET MAT_NO =
	       (SELECT MAT_NO
	          FROM #NextTableName#
	         WHERE JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
	           AND MAT_NO IS NOT NULL
	           AND COL_USER IS NULL
	           AND COL_SHIFT IS NULL
	           AND COL_GROUP IS NULL
	           AND ROWNUM = 1)
	 WHERE JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
	   AND SEQ = '#SEQ#'
        ]]>
	</query>
	
	<query id="FeedResult.getSingleMainPlan" desc="查询简单作业计划（上料锯切）">
        <![CDATA[
		SELECT b.CUT_NUM,
       a.ID,
       a.SEQ,
       a.STOVE_NO,
       a.JUDGE_STOVE_NO,
       REGEXP_REPLACE(A.JUDGE_STOVE_NO, '-.*', '') as JUDGE_NO,
       a.LOT_NO,
       a.CONTRACT_NO,
       a.IMP_PROCESS,
       a.PLINE_CODE,
       a.BACK_PLAN_FLAG,
       a.ORD_LN_DLY_PK,
       CASE a.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,
       a.PRODUCER,
       a.PROCESS_STATUS,
       a.DB_LENGTH,
       a.DB_HEIGHT,
       a.ROLL_LENGTH,
       a.SAW_NUM,
       a.TARGET_LENGTH,
       a.FINISH_USER,
       a.TARGET_LIABRARY,
       a.VARIETIES,
       a.PIPE_SIZE,
       a.BUCKLE_TYPE,
       a.LENGTH_RANGE,
       a.ROLL_STANDRAD,
       a.PIPE_SECTION,
       a.STEELCODE,
       a.STEELNAME,
       a.GRADECODE,
       a.GRADENAME,
       a.STEEL_STANDRAD,
       a.TARGET,
       BRANCH,
       a.TON,
       a.CUT_TARGET,
       a.CUT_LENGTH,
       a.CUT_WEIGHT,
       a.DB_NUM,
       CASE a.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
          '人工质检完成'
         WHEN '99' THEN
          '交库'
       END AS NODE_STATUS,
       Nvl((select b.NODE_FUR_FLAG
             from MIL_FEEDSAW_RESULT b
            where b.judge_stove_no = a.judge_Stove_no
            and b.result_no = a.id),
           3) AS IS_START,
       TO_CHAR(a.START_TIME, 'YYYY-MM-DD HH24:MI:SS') START_TIME,
       TO_CHAR(a.END_TIME, 'YYYY-MM-DD HH24:MI:SS') END_TIME,
       TO_CHAR(a.TOM, 'YYYY-MM-DD HH24:MI:SS') TOM,
       TO_CHAR(a.TOC, 'YYYY-MM-DD HH24:MI:SS') TOC,
       a.pro_plan_id,
       a.gx_plan_no
  FROM MIL_PLAN a, MIL_FEEDSAW_RESULT b
 WHERE a.judge_stove_no = b.judge_stove_no(+)
   and a.id = b.Result_NO(+)
   and a.BACK_PLAN_FLAG in (0, 1, 5) 
   and a.IS_LOAD = '1'
   AND A.BACK_SLAB_FLAG <> '2'
   #something#
 order by a.FEED_TIME, a.START_TIME
        ]]>
	</query>
	
	<query id="FeedResult.updateBalYearMonth" desc="修改回炉坯炉号进程表结转年月">
        <![CDATA[
		DECLARE
  V_SAW_NUM        MIL_PLAN.SAW_NUM%type := null;
  V_NUM            MIL_PLAN.SAW_NUM%type := 1;
  V_JUDGE_STOVE_NO MIL_PLAN.JUDGE_STOVE_NO%type := ?;
  V_PLINE_CODE     MIL_PLAN.PLINE_CODE%type := ?;
  V_PRO_PLAN_ID    MIL_PLAN.PRO_PLAN_ID%type := ?;
  V_GX_PLAN_NO     MIL_PLAN.GX_PLAN_NO%type := ?;
BEGIN

  SELECT T.SAW_NUM
    INTO V_SAW_NUM
    FROM MIL_PLAN T
   WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
     AND T.PLINE_CODE = V_PLINE_CODE;

  FOR MYROW IN (select t.Judge_Stove_No,
                       (select MAX(P.BAL_YEAR_MONTH)
                          from port_mil_batch_sample_result p
                         where p.judge_stove_no = t.judge_stove_no) BAL_YEAR_MONTH
                  from MIL_SLAB_SCRAP t
                 where t.group_flag = 1
                   and t.new_heat_no = V_JUDGE_STOVE_NO) LOOP
  
    UPDATE port_mil_batch_sample_result P
       SET P.BAL_YEAR_MONTH = MYROW.BAL_YEAR_MONTH
     WHERE P.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
       AND P.PLINE_CODE = V_PLINE_CODE
       AND NVL(P.PRO_PLAN_ID,'/') = NVL(V_PRO_PLAN_ID,'/')
       AND NVL(P.GX_PLAN_NO,'/') = NVL(V_GX_PLAN_NO,'/')
       AND P.SEQ BETWEEN V_SAW_NUM * (V_NUM - 1) + 1 AND V_SAW_NUM * V_NUM;
  
    V_NUM := V_NUM + 1;
  END LOOP;
END;
        ]]>
	</query>
	
	<query id="FeedResult.insertMilProcess" desc="生成进程表mil_processes数据">
        <![CDATA[
		DECLARE
  V_JUDGE_STOVE_NO MIL_PROCESSES.JUDGE_STOVE_NO%TYPE := ?;
  V_LOT_NO         MIL_PROCESSES.LOT_NO%TYPE := ?;
  V_PLINE_CODE     MIL_PROCESSES.PLINE_CODE%TYPE := ?;
  V_PRO_PLAN_ID    MIL_PROCESSES.PRO_PLAN_ID%TYPE := ?;
  V_GX_PLAN_NO     MIL_PROCESSES.GX_PLAN_NO%TYPE := ?;
  V_COUNT          MIL_PROCESSES.YJZ%TYPE := NULL;
  V_INPUT_WEIGHT   PORT_MIL_BATCH_SAMPLE_RESULT.INPUT_WEIGHT%type := null;
BEGIN
  SELECT COUNT(1)
    INTO V_COUNT
    FROM MIL_PROCESSES T
   WHERE T.JUDGE_STOVE_NO = REGEXP_REPLACE(V_JUDGE_STOVE_NO, '-.*', '')
     AND T.LOT_NO = V_LOT_NO
     AND T.PLINE_CODE = V_PLINE_CODE
     AND NVL(T.PRO_PLAN_ID, '/') = NVL(V_PRO_PLAN_ID, '/')
     AND NVL(T.GX_PLAN_NO, '/') = NVL(V_GX_PLAN_NO, '/');

  FOR MYROW IN (SELECT REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '') JUDGE_STOVE_NO,
                       T1.LOT_NO,
                       T1.ID,
                       T.PLINE_CODE,
                       (SELECT A.PLINE_NAME
                          FROM COM_BASE_PLINE A
                         WHERE A.PLINE_CODE = T.PLINE_CODE) PLINE_CODE1,
                       T1.CONTRACT_NO,
                       MAX(T1.TARGET) TARGET,
                       MAX(T1.VARIETIES) VARIETIES,
                       MAX(T1.VARIETIES_CODE) VARIETIES_CODE,
                       MAX(T1.STEELNAME) STEELNAME,
                       MAX(T1.STEELCODE) STEELCODE,
                       MAX(T1.GRADENAME) GRADENAME,
                       MAX(T1.GRADECODE) GRADECODE,
                       REPLACE(MAX(T1.PIPE_SIZE), '*', 'x') PIPE_SIZE,
                       MAX(T1.PIPE_SIZE_CODE) PIPE_SIZE_CODE,
                       MAX(T1.BUCKLE_TYPE) BUCKLE_TYPE,
                       MAX(T1.BUCKLE_TYPE_CODE) BUCKLE_TYPE_CODE,
                       MAX(T1.LENGTH_RANGE) LENGTH_RANGE,
                       MAX(T1.ROLL_STANDRAD) ROLL_STANDRAD,
                       MIN(T.START_TIME) START_TIME,
                       MAX(T1.PRO_PLAN_ID) PRO_PLAN_ID,
                       MAX(T1.GX_PLAN_NO) GX_PLAN_NO,
                       SUM(B.FEED_NUM_PLAN) SLZ,
                       SUM(B.MAT_TOTAL_HEIGHT -
                           B.FEED_NUM * DECODE(B.CUT_TARGET,
                                  '返废',
                                  NVL(round(B.CUT_WEIGHT, 3), 0),
                                  0)) SLD,
                       SUM(B.FEED_NUM_PLAN * B.DB_NUM) * MAX(T1.SAW_NUM) YJZ,
                       MAX(T1.PREDICT_TON) YJD
                  FROM MIL_FEEDSAW_RESULT T, MIL_FEED_PLAN B, MIL_PLAN T1
                 WHERE T.JUDGE_STOVE_NO = T1.JUDGE_STOVE_NO
                   AND T.JUDGE_STOVE_NO = B.JUDGE_STOVE_NO
                   AND T1.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
                   AND T1.LOT_NO = V_LOT_NO
                   AND T1.PLINE_CODE = V_PLINE_CODE
                   AND T1.PRO_PLAN_ID = V_PRO_PLAN_ID
                   AND T1.GX_PLAN_NO = V_GX_PLAN_NO
                 GROUP BY T1.JUDGE_STOVE_NO,
                          T1.LOT_NO,
                          T.PLINE_CODE,
                          T.JUDGE_STOVE_NO,
                          T.RESULT_NO,
                          T1.CONTRACT_NO,
                          T1.PRO_PLAN_ID,
                          T1.GX_PLAN_NO,
                          T1.ID,
                          T1.ORD_LN_DLY_PK) LOOP
  
    IF (V_COUNT = 0) THEN
      INSERT INTO MIL_PROCESSES
        (ID,
         JUDGE_STOVE_NO,
         LOT_NO,
         PRO_PLAN_ID,
         GX_PLAN_NO,
         PLINE_CODE,
         TARGET,
         VARIETIES,
         VARIETIES_CODE,
         STEELCODE,
         STEELNAME,
         GRADECODE,
         GRADENAME,
         PIPE_SIZE,
         PIPE_SIZE_CODE,
         BUCKLE_TYPE,
         BUCKLE_TYPE_CODE,
         FEED_TIME,
         SLZ,
         SLD,
         --YJZ,
         --YJD,
         
         CONTRACT_NO,
         BAL_YEAR_MONTH)
      VALUES
        (MYROW.ID,
         MYROW.JUDGE_STOVE_NO,
         MYROW.LOT_NO,
         MYROW.PRO_PLAN_ID,
         MYROW.GX_PLAN_NO,
         MYROW.PLINE_CODE,
         MYROW.TARGET,
         MYROW.VARIETIES,
         MYROW.VARIETIES_CODE,
         MYROW.STEELCODE,
         MYROW.STEELNAME,
         MYROW.GRADECODE,
         MYROW.GRADENAME,
         MYROW.PIPE_SIZE,
         MYROW.PIPE_SIZE_CODE,
         MYROW.BUCKLE_TYPE,
         MYROW.BUCKLE_TYPE_CODE,
         MYROW.START_TIME,
         MYROW.SLZ,
         MYROW.SLD,
         --MYROW.YJZ,
         --MYROW.YJD,
         
         MYROW.CONTRACT_NO,
         ?);
    END IF;
  END LOOP;
END;
        ]]>
	</query>
</queryMap>