<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc = "质检下线组炉批管理"> 
<query id = "FrmFurnace.doQueryOffLine" desc = "查询下线数据">
<![CDATA[
SELECT T.JUDGE_STOVE_NO,
     T.LOT_NO,
     T.DIAMETER,
     T.THICKNESS,
     T.LENGTH,
     T.PLINE_CODE,
     S.STEELCODE,
     S.STEELNAME,
     S.GRADECODE,
     S.GRADENAME,
     S.SIMPLE_LOT_NO,
     SUM(S.OFFLINE_NUM) OFFLINE_NUM,
     SUM(S.ZP_HEIGHT) ZP_HEIGHT,
     S.ZP_STANDRADCODE,
     S.ZP_STANDRAD,
     S.ZP_LENGTH_MAX,
     S.ZP_LENGTH_MIN,
     DECODE(S.GROUP_FLAG,'0','未组批','1','已组批')ZP_FLAG
FROM MIL_OFFLINE_RESLUT T, MIL_QA_RACK S
WHERE T.Judge_Stove_No = S.Judge_Stove_No
 AND T.OFFLINE_PRO = 'ZJ'
 AND S.GROUP_FLAG = '0'
 AND T.LOT_NO= S.LOT_NO
 AND T.JUDGE_STOVE_NO || '&' LIKE ('%' || ? || '%')
 AND T.LOT_NO  || '&' LIKE ('%' || ? || '%')
 ]]>
</query>
<query id = "FrmFurnace.doQueryOffGroup" desc = "查询组炉实绩">
<![CDATA[
 SELECT 
       MAX(OLD_ZP_JUDGE_STOVE_NO),
       MAX(OLD_ZP_LOT_NO),
       MAX(OLD_ZP_STANDRAD),
       MAX(OLD_ZP_STEEL),
       MAX(OLD_ZP_GRADE),
       MAX(OLD_ZP_LENGTH),
       MAX(OLD_ZP_LENGTH_MAX),
       MAX(OLD_ZP_LENGTH_MIN),
       DIAMETER,
       THICKNESS,
       MAX(OLD_DIAMETER),
       MAX(OLD_THICKNESS),
       VARIETIES,
       MAX(OLD_VARIETIES),
       PLINE_CODE,
       ZP_JUDGE_STOVE_NO,
       ZP_LOT_NO,
       SUM(ZP_COUNT) ZP_COUNT,
       QUALIFIED_NUM,
       SCRAP_NUM,
       ZP_STANDRAD,
       ZP_STEEL,
       ZP_GRADE,
       ZP_LENGTH,
       SUM(ZP_HEIGHT) ZP_HEIGHT,
       ZP_LENGTH_MAX,
       ZP_LEVEL,
       ZP_LENGTH_MIN,
       ZP_SIZE,
       ZP_M_LH,
       ZP_S_LH,
       ZP_M_PH,
       MAX(TO_CHAR(ZP_TIME, 'YYYY-MM-DD HH24:MI:SS')) ZP_TIME,
       REMARK,
       COL_USER,
       COL_SHIFT,
       COL_GROUP,
       SIMPLE_LOT_NO,
       MAX(OLD_SIMPLE_LOT_NO)OLD_SIMPLE_LOT_NO
 FROM MIL_OFFLINE_GROUP
 WHERE ZP_JUDGE_STOVE_NO || '&' LIKE ('%' || ? || '%')
 AND ZP_LOT_NO || '&' LIKE ('%' || ? || '%')
 ]]>
</query>
<query id = "doFurnace.insertOffGroup" desc = "写履历表">
<![CDATA[
DECLARE
  v_time mil_offline_reslut.offline_time%type := sysdate;
BEGIN
  FOR MYROW IN (Select *
                  from (SELECT T.*,
                               S.STEELCODE,
                               S.STEELNAME,
                               S.GRADECODE,
                               S.GRADENAME,
                               S.SIMPLE_LOT_NO,
                               S.ZP_STANDRADCODE,
                               S.ZP_STANDRAD,
                               S.ZP_LENGTH_MAX,
                               S.ZP_LENGTH_MIN,
                               s.varieties,
                               s.mat_no
                          FROM mil_offline_reslut T, mil_qa_rack s
                         WHERE T.Judge_Stove_No = s.Judge_Stove_No
                           AND T.JUDGE_STOVE_NO = ?
                           AND T.Lot_No = ?
                           AND NVL(S.ZP_LENGTH_MIN, 0) = NVL(?, 0)
                           AND NVL(S.ZP_LENGTH_MAX, 0) = NVL(?, 0)
                           AND NVL(T.LENGTH, 0) = NVL(?, 0)
                           AND s.GROUP_FLAG = '0'
                         ORDER BY T.MAT_NO DESC)
                 where rownum < ?) LOOP
    INSERT INTO MIL_OFFLINE_GROUP
      (OLD_ZP_JUDGE_STOVE_NO,
       OLD_ZP_LOT_NO,
       OLD_ZP_STANDRAD,
       OLD_ZP_STEEL,
       OLD_ZP_GRADE,
       OLD_ZP_LENGTH,
       OLD_ZP_LENGTH_MAX,
       OLD_ZP_LENGTH_MIN,
       DIAMETER,
       THICKNESS,
       OLD_DIAMETER,
       OLD_THICKNESS,
       VARIETIES,
       OLD_VARIETIES,
       PLINE_CODE,
       ZP_JUDGE_STOVE_NO,
       ZP_LOT_NO,
       ZP_COUNT,
       QUALIFIED_NUM,
       SCRAP_NUM,
       ZP_STANDRAD,
       ZP_STEEL,
       ZP_GRADE,
       ZP_LENGTH,
       ZP_HEIGHT,
       ZP_LENGTH_MAX,
       ZP_LEVEL,
       ZP_LENGTH_MIN,
       ZP_SIZE,
       ZP_M_LH,
       ZP_S_LH,
       ZP_M_PH,
       ZP_TIME,
       REMARK,
       COL_USER,
       COL_SHIFT,
       COL_GROUP,
       MAT_NO,
       SIMPLE_LOT_NO,
       OLD_SIMPLE_LOT_NO)
    VALUES
      (myrow.judge_stove_no,
       myrow.lot_no,
       myrow.zp_standrad,
       myrow.steelname,
       myrow.gradename,
       myrow.length,
       myrow.zp_length_max,
       myrow.zp_length_min,
       ?,
       ?,
       myrow.diameter,
       myrow.thickness,
       ?,
       myrow.varieties,
       myrow.pline_code,
       ?,
       ?,
       myrow.offline_num,
       '',
       '',
       ?,
       ?,
       ?,
       ?,
       myrow.zp_height,
       ?,
       '',
       ?,
       '',
       ?,
       ?,
       ?,
       v_time,
       '',
       ?,
       ?,
       ?,
       myrow.mat_no,
       ?,
       myrow.simple_lot_no);
       update mil_qa_rack  t set t.judge_stove_no = ?,t.lot_no = ?,t.simple_lot_no = ?,t.GROUP_FLAG = '1' where t.mat_no = myrow.mat_no;
  END LOOP;
END;
 ]]>
</query>
<!-- update mil_offline_reslut t
   set t.ZP_FLAG = '1', t.judge_stove_no = ?, t.lot_no = ?
 where t.mat_no = myrow.mat_no; -->
<query id = "FrmFurnace.doCancelFurnace" desc = "撤销组炉">
<![CDATA[
DECLARE
BEGIN
  FOR MYROW IN (SELECT T.* FROM MIL_OFFLINE_GROUP T
                         WHERE T.ZP_JUDGE_STOVE_NO = ?
                           AND T.ZP_LOT_NO = ?
                           AND NVL(T.ZP_LENGTH_MIN, 0) = NVL(?, 0)
                           AND NVL(T.ZP_LENGTH_MAX, 0) = NVL(?, 0)
                         ORDER BY T.MAT_NO DESC) LOOP
       
       UPDATE MIL_QA_RACK  T SET T.JUDGE_STOVE_NO = MYROW.OLD_ZP_JUDGE_STOVE_NO,T.LOT_NO = MYROW.OLD_ZP_LOT_NO,T.SIMPLE_LOT_NO = MYROW.OLD_SIMPLE_LOT_NO WHERE T.MAT_NO = MYROW.MAT_NO;
       DELETE MIL_OFFLINE_GROUP T WHERE T.MAT_NO = MYROW.MAT_NO;
  END LOOP;
END;
]]>
</query>
<!-- UPDATE MIL_OFFLINE_RESLUT T SET T.ZP_FLAG = '0',T.JUDGE_STOVE_NO = MYROW.OLD_ZP_JUDGE_STOVE_NO,T.LOT_NO = MYROW.OLD_ZP_LOT_NO WHERE T.MAT_NO = MYROW.MAT_NO; -->
<query id = "FrmFurnace.getQuerySimpleNo" desc= "生成性能批号">
<![CDATA[
SELECT Lpad(NVL(MAX(t.simple_lot_no), 0) + 1, 4, 0)
      FROM mil_qa_rack T
     WHERE T.JUDGE_STOVE_NO = ? and t.lot_no = ?
     ]]>
</query>
</queryMap>