<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc = "废品审核">
<query id = "FrmScrapApplyFrim.doQueryApply" desc = "查询废品信息">
SELECT 
       T.FAIL_APPROVAL_CODE,
       T.LOT_NO,
       T.STOVE_NO,
       T.JUDGE_STOVE_NO,
       T.MATERIAL_NO,
       T.MATERIAL_NAME,
       T.PRODUCCODE,
       T.PRODUCNAME,
       T.STEELCODE,
       T.STEELNAME,
       T.GRADECODE,
       T.GRADENAME,
       T.SPEC_CODE,
       T.SPEC_NAME,
       T.MODEL_CODE,
       T.MODEL_DESC,
       T.STD_CODE,
       T.STD_NAME,
       T.STD_STYLE,
       T.STD_STYLE_DESC,
       T.PRO_ORDER_NO,
       T.PROCESS_CDOE,
       T.PROCESS_DESC,
       T.PLINE_CODE,
       T.PLINE_NAME,
       T.ACT_DIMATER,
       T.ACT_HEIGHT,
       T.ACT_LEN,
       T.ACT_LEN_MIN,
       T.ACT_LEN_MAX,
       T.ACT_COUNT,
       T.ACT_WEIGHT,
       T.BELONG_CODE,
       T.BELONG_NAME,
       T.TARGET,
       T.SCRAP_REASON,
       T.BELONG_CODE_RESPONSE,
       T.BELONG_NAME_RESPONSE,
       T.CREATE_NAME,
       TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
       T.FRIM_NAME,
       TO_CHAR(T.FRIM_TIME, 'YYYY-MM-DD HH24:MI:SS') FRIM_TIME,
       DECODE(T.FRIM_FLAG,'0','未审核','1','审核通过','2','审核不通过')FRIM_FLAG,
       T.BAL_YEAR_MONTH,
       T.CRAFT_NO,
       T.CRAFT_PATH,
       DECODE(T.IS_FAST,'0','否','1','是') IS_FAST,
       T.SCRAP_DESC
 FROM YDM_BC_SCRAPFRIM T
 WHERE T.SCRAP_TYPE = '0'
</query>
<query id = "FrmScrapApplyFrim.frimScarpApply" desc = "审核成功">
DECLARE
V_PROCESS_CODE MAT_BC_M.PROCESS_CDOE%TYPE := NULL;
BEGIN
  SELECT T.PROCESS_CODE
    INTO V_PROCESS_CODE
    FROM COM_BASE_PLINE T
   WHERE T.PLINE_CODE = '#PLINE_CODE#';
  FOR MYROW IN (SELECT *
                  FROM MAT_BC_M T
                 WHERE T.FAIL_APPROVAL_CODE = '#FAIL_APPROVAL_CODE#'
                   AND T.PLINE_CODE = '#PLINE_CODE#'
                   AND T.QCM_STAUS = '22'
                   AND T.SCRAP_FRIM_FLAG = '1') LOOP
    UPDATE MAT_BC_M T
       SET T.SCRAP_FRIM_FLAG      = '2',
           T.JUDGE_RESULT_CODE    = '40740705',
           T.JUDGE_RESULT         = '废品',
           T.JUDGE_RESULT_TIME    = SYSDATE,
           T.BELONG_CODE_RESPONSE = '#BELONG_CODE_RESPONSE#',
           T.BELONG_NAME_RESPONSE = '#BELONG_NAME_RESPONSE#'
     WHERE T.MAT_NO = MYROW.MAT_NO
       AND T.PLINE_CODE = MYROW.PLINE_CODE;
       IF (V_PROCESS_CODE = 'F') THEN
      UPDATE PORT_HTT_BATCH_SAMPLE_RESULT T
         SET T.IS_FAIL_CHECK  = '1',
             T.BAL_YEAR_MONTH_FAIL = '#BAL_YEAR_MONTH#'
       WHERE T.MAT_NO = MYROW.MAT_NO
         AND T.MAT_STATUS IN ('10', '40');
    ELSIF (V_PROCESS_CODE = 'G') THEN
      UPDATE PORT_MCH_BATCH_SAMPLE_RESULT T
         SET T.IS_FAIL_CHECK  = '1',
             T.BAL_YEAR_MONTH_FAIL = '#BAL_YEAR_MONTH#'
       WHERE T.MAT_NO = MYROW.MAT_NO
         AND T.MAT_STATUS IN ('10', '40');
    ELSIF(V_PROCESS_CODE = 'E')THEN
         UPDATE PORT_VRP_BATCH_SAMPLE_RESULT T
         SET T.IS_FAIL_CHECK  = '1',
             T.BAL_YEAR_MONTH_FAIL = '#BAL_YEAR_MONTH#'
       WHERE T.MAT_NO = MYROW.MAT_NO
         AND T.MAT_STATUS IN ('10', '40');
         END IF;
  END LOOP;
  UPDATE YDM_BC_SCRAPFRIM T
     SET T.FRIM_FLAG = '1',
         T.FRIM_NAME = '#FRIM_NAME#',
         T.FRIM_TIME = SYSDATE,
         T.BAL_YEAR_MONTH = '#BAL_YEAR_MONTH#',
         T.BELONG_CODE_RESPONSE = '#BELONG_CODE_RESPONSE#',
         T.BELONG_NAME_RESPONSE = '#BELONG_NAME_RESPONSE#'
   WHERE T.FAIL_APPROVAL_CODE = '#FAIL_APPROVAL_CODE#';
END;
</query>
<query id = "FrmScrapApplyFrim.frimScarpApplyNot" desc = "审核不通过">
DECLARE
BEGIN
  FOR MYROW IN (SELECT *
                  FROM MAT_BC_M T
                 WHERE T.FAIL_APPROVAL_CODE = '#FAIL_APPROVAL_CODE#'
                   AND T.PLINE_CODE = '#PLINE_CODE#'
                   AND T.QCM_STAUS = '22'
                   AND T.SCRAP_FRIM_FLAG = '1') LOOP
    UPDATE MAT_BC_M T
       SET T.SCRAP_FRIM_FLAG      = '0',
       T.FAIL_APPROVAL_CODE = ''
     WHERE T.MAT_NO = MYROW.MAT_NO
       AND T.PLINE_CODE = MYROW.PLINE_CODE;
  END LOOP;
  UPDATE YDM_BC_SCRAPFRIM T
     SET T.FRIM_FLAG = '2',
         T.FRIM_NAME = '#FRIM_NAME#',
         T.FRIM_TIME = SYSDATE,
         T.BAL_YEAR_MONTH = '#BAL_YEAR_MONTH#'
   WHERE T.FAIL_APPROVAL_CODE = '#FAIL_APPROVAL_CODE#';
END;
</query>
<query id = "FrmScrapApplyFrim.cancelFrimScrapApply" desc = "撤销审核通过">
DECLARE
V_PROCESS_CODE MAT_BC_M.PROCESS_CDOE%TYPE := NULL;
BEGIN
  SELECT T.PROCESS_CODE
    INTO V_PROCESS_CODE
    FROM COM_BASE_PLINE T
   WHERE T.PLINE_CODE = '#PLINE_CODE#';
  FOR MYROW IN (SELECT *
                  FROM MAT_BC_M T
                 WHERE T.FAIL_APPROVAL_CODE = '#FAIL_APPROVAL_CODE#'
                   AND T.PLINE_CODE = '#PLINE_CODE#'
                   AND T.QCM_STAUS = '22'
                   AND T.SCRAP_FRIM_FLAG = '2') LOOP
    UPDATE MAT_BC_M T
       SET T.SCRAP_FRIM_FLAG      = '1',
           T.JUDGE_RESULT_CODE    = '',
           T.JUDGE_RESULT         = '',
           T.JUDGE_RESULT_TIME    = '',
           T.BELONG_CODE_RESPONSE = '',
           T.BELONG_NAME_RESPONSE = ''
     WHERE T.MAT_NO = MYROW.MAT_NO
       AND T.PLINE_CODE = MYROW.PLINE_CODE;
       IF (V_PROCESS_CODE = 'F') THEN
      UPDATE PORT_HTT_BATCH_SAMPLE_RESULT T
         SET T.IS_FAIL_CHECK  = '0',
             T.BAL_YEAR_MONTH_FAIL = ''
       WHERE T.MAT_NO = MYROW.MAT_NO
         AND T.MAT_STATUS IN ('10', '40');
    ELSIF (V_PROCESS_CODE = 'G') THEN
      UPDATE PORT_MCH_BATCH_SAMPLE_RESULT T
         SET T.IS_FAIL_CHECK  = '0',
             T.BAL_YEAR_MONTH_FAIL = ''
       WHERE T.MAT_NO = MYROW.MAT_NO
         AND T.MAT_STATUS IN ('10', '40');
    ELSIF (V_PROCESS_CODE = 'E') THEN
      UPDATE PORT_VRP_BATCH_SAMPLE_RESULT T
         SET T.IS_FAIL_CHECK  = '0',
             T.BAL_YEAR_MONTH_FAIL = ''
       WHERE T.MAT_NO = MYROW.MAT_NO
         AND T.MAT_STATUS IN ('10', '40');
         END IF;
  END LOOP;
  UPDATE YDM_BC_SCRAPFRIM T
     SET T.FRIM_FLAG = '0',
         T.FRIM_NAME = '',
         T.BELONG_CODE_RESPONSE = '',
         T.BELONG_NAME_RESPONSE = ''
   WHERE T.FAIL_APPROVAL_CODE = '#FAIL_APPROVAL_CODE#';
END;
</query>
</queryMap>