<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc = "回退记录">
<query id = "FrmCancelAll.doQueryOutList" desc = "查询倒运记录">
<![CDATA[
 SELECT 
       T.OUTSTOCK_DOC,
       T.OUTSTOCK_TYPE_CODE,
       T.OUTSTOCK_TYPE_NAME,
       T.LOT_NO,
       T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       T.BATCH_GROUD_NO,
       T.MATERIAL_NO,
       T.MATERIAL_NAME,
       T.PRODUCCODE,
       T.PRODUCNAME,
       T.STD_CODE,
       T.STD_NAME,
       T.GRADECODE,
       T.GRADENAME,
       T.STEELCODE,
       T.STEELNAME,
       T.STD_STYLE,
       T.STD_STYLE_DESC,
       T.SPEC_CODE,
       T.SPEC_NAME,
       T.MODEL_CODE,
       T.MODEL_DESC,
       T.PRO_ORDER_NO,
       T.PLINE_CODE,
       T.PLINE_NAME,
       T.ACT_DIMATER,
       T.ACT_HEIGHT,
       T.ACT_LEN,
       T.ACT_LEN_MIN,
       T.ACT_LEN_MAX,
       SUM(T.ACT_COUNT)ACT_COUNT,
       SUM(T.ACT_WEIGHT)ACT_WEIGHT,
       T.BELONG_CODE,
       T.BELONG_NAME
 FROM YDM_BC_OUTLIST T
 WHERE T.JUDGE_STOVE_NO = ?
 AND T.BELONG_CODE NOT IN('100101','100102','100103')
 AND T.OUTSTOCK_TYPE_CODE = '800803'
 AND T.BATCH_NO <>'X'
 GROUP BY 
 T.OUTSTOCK_DOC,
       T.OUTSTOCK_TYPE_CODE,
       T.OUTSTOCK_TYPE_NAME,
       T.LOT_NO,
       T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       T.BATCH_GROUD_NO,
       T.MATERIAL_NO,
       T.MATERIAL_NAME,
       T.PRODUCCODE,
       T.PRODUCNAME,
       T.STD_CODE,
       T.STD_NAME,
       T.GRADECODE,
       T.GRADENAME,
       T.STEELCODE,
       T.STEELNAME,
       T.STD_STYLE,
       T.STD_STYLE_DESC,
       T.SPEC_CODE,
       T.SPEC_NAME,
       T.MODEL_CODE,
       T.MODEL_DESC,
       T.PRO_ORDER_NO,
       T.PLINE_CODE,
       T.PLINE_NAME,
       T.ACT_DIMATER,
       T.ACT_HEIGHT,
       T.ACT_LEN,
       T.ACT_LEN_MIN,
       T.ACT_LEN_MAX,
       T.BELONG_CODE,
       T.BELONG_NAME
       ]]>
</query>
<query id = "FrmCancelAll.doQueryJugde" desc = "查询是否申请判定">
SELECT NVL(SUM(T.ACT_COUNT), 0) ACOUNT
  FROM QCM_ZG_JUGDE_APPLY T
 WHERE T.IS_FLAG = 0
   AND T.JUDGE_STOVE_NO = ?
</query>
<query id = "FrmCancelAll.doQueryInstoreRs" desc = "查询交库点是否结炉">
SELECT T.NODE_FUR_FLAG FROM MIL_INSTORE_RESULT T WHERE T.JUDGE_STOVE_NO = ?
</query>
<query id = "FrmCancelAll.cancelAll" desc = "一键撤销">
<![CDATA[
DECLARE
  V_ZG_MAT_NO   MAT_BC_M.ZG_MAT_NO%TYPE := NULL;
  V_ZG_STOVE_NO PORT_MIL_BATCH_SAMPLE_RESULT.JUDGE_STOVE_NO%TYPE := NULL;
  V_CANCEL_NO MIL_CANCEL_LOG.CANCEL_NO%TYPE :=NULL;
BEGIN
   INSERT INTO MIL_CANCEL_LOG(
        OUTSTOCK_DOC,
        JUDGE_STOVE_NO,
        BATCH_NO,
        BATCH_GROUD_NO,
        ACT_COUNT,
        DELETE_NAME,
        DELETE_TIME,
        CANCEL_NO,
        PLINE_CODE)
 VALUES( 
        '#OUTSTOCK_DOC#',
        '#JUDGE_STOVE_NO#',
        '#BATCH_NO#',
        '#BATCH_GROUD_NO#',
        '#ACT_COUNT#',
        '#DELETE_NAME#',
        SYSDATE,
        TO_CHAR(SYSDATE,'YYYYMMDDHHMMSS'),
        '#PLINE_CODE#');
  FOR MYROW IN (SELECT *
                  FROM (SELECT T.MAT_NO,T.ACT_WEIGHT
                          FROM YDM_BC_OUTLIST T
                         WHERE T.OUTSTOCK_DOC = '#OUTSTOCK_DOC#'
                           AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                           AND T.BATCH_NO = '#BATCH_NO#'
                           AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
                         ORDER BY T.MAT_NO DESC)
                 WHERE ROWNUM <= #ACT_COUNT#) LOOP
    SELECT T.ZG_MAT_NO, T.ZG_STOVE_SQE
      INTO V_ZG_MAT_NO, V_ZG_STOVE_NO
      FROM MAT_BC_M T
     WHERE T.MAT_NO = MYROW.MAT_NO;             
    UPDATE MIL_INSTORE_RESULT T SET T.QUALIFIED_NUM = TO_NUMBER(T.QUALIFIED_NUM)- TO_NUMBER('1'),T.QUALIFIED_TONS = TO_NUMBER(T.QUALIFIED_TONS) -
                              TO_NUMBER(MYROW.ACT_WEIGHT),T.NODE_FUR_FLAG  = '0' WHERE T.JUDGE_STOVE_NO = V_ZG_STOVE_NO; 
    DELETE FROM YDM_BC_INLIST T WHERE T.MAT_NO = MYROW.MAT_NO AND T.INSTOCK_TYPE_CODE <> '800709';
    
    --UPDATE PORT_MIL_BATCH_SAMPLE_RESULT T
     --  SET T.INSTORE_FLAG = '0'
     --WHERE T.JUDGE_STOVE_NO = V_ZG_STOVE_NO
      -- AND T.MAT_NO = V_ZG_MAT_NO;
    UPDATE MIL_PLAN T SET T.NODE_STATUS = '96' WHERE T.JUDGE_STOVE_NO = V_ZG_STOVE_NO;
    DELETE FROM MAT_BC_M T WHERE T.MAT_NO = MYROW.MAT_NO;
    DELETE FROM YDM_BC_BUTTRESS S WHERE S.MAT_NO = MYROW.MAT_NO;
    DELETE FROM YDM_BC_OUTLIST T WHERE T.MAT_NO = MYROW.MAT_NO;
    
  END LOOP;
END;
]]>
</query>
</queryMap>