<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="质量申请放行">
    <query id="JdgQcmZcPassFlow.getByPassApplyNo" desc="获取放行信息">
        <![CDATA[
SELECT T.AUDIT_STEP,
       DECODE(T.AUDIT_RESULT, '0', '审核不通过', '1', '审核通过', T2.BASENAME) AUDIT_RESULT,
       DECODE(T3.DEPARTNAME, '工艺科', '工艺相关科室', T3.DEPARTNAME) AUDIT_UNIT,
       T.AUDIT_NAME,
       TO_CHAR(T.AUDIT_TIME, 'YYYY-MM-DD HH24:MI:SS') AUDIT_TIME,
       T.AUDIT_MEMO,
       DECODE(T.AUDIT_RESULT, NULL, NULL, '√') IS_AUDIT
  FROM QCM_ZC_PASS_FLOW T
  LEFT JOIN COM_BASE_INFO T2
    ON T2.BASECODE = T.AUDIT_RESULT
  LEFT JOIN CORE_APP_DEPARTMENT T3
    ON T3.DEPARTID = T.AUDIT_UNIT
 WHERE T.PASS_APPLY_NO = {0}
 ORDER BY T.AUDIT_STEP
        ]]>
    </query>
    
    <query id="JdgQcmZcPassFlow.getCrtAuditStep" desc="获取当前审核步骤">
        <![CDATA[
SELECT T.AUDIT_STEP, T.AUDIT_RESULT
  FROM QCM_ZC_PASS_FLOW T
 WHERE T.PASS_APPLY_NO = {0}
   AND T.CRT_AUDIT_STEP = '1'
        ]]>
    </query>
    
    <query id="JdgQcmZcPassFlow.getMaxAuditStep" desc="获取最大审核步骤">
        <![CDATA[
SELECT MAX(T.AUDIT_STEP) AUDIT_STEP
     FROM QCM_ZC_PASS_FLOW T
    WHERE T.PASS_APPLY_NO = {0}
        ]]>
    </query>
    
    <query id="JdgQcmZcPassFlow.getAuditCnt" desc="获取是否有审核步骤">
        <![CDATA[
SELECT COUNT(1) COUNT FROM QCM_ZC_PASS_FLOW T WHERE T.PASS_APPLY_NO = {0}
        ]]>
    </query>
    
    <query id="JdgQcmZcPassFlow.insert" desc="新增审核流程">
        <![CDATA[
INSERT INTO QCM_ZC_PASS_FLOW
  (PASS_APPLY_NO, AUDIT_STEP, AUDIT_UNIT, CRT_AUDIT_STEP)
VALUES
  ({0}, {1}, {2}, {3})
        ]]>
    </query>
    
    <query id="JdgQcmZcPassFlow.setAuditResult" desc="修改审核结果">
        <![CDATA[
UPDATE QCM_ZC_PASS_FLOW T
     SET T.AUDIT_RESULT   = {2},
         T.AUDIT_NAME     = {3},
         T.AUDIT_TIME     = SYSDATE,
         T.AUDIT_MEMO     = {4},
         T.CRT_AUDIT_STEP = {5},
         T.AUDIT_USER_ID = {6}
   WHERE T.PASS_APPLY_NO = {0}
     AND T.AUDIT_STEP = {1}
        ]]>
    </query>
    
    <query id="JdgQcmZcPassFlow.clearAuditResult" desc="清除审核结果">
        <![CDATA[
UPDATE QCM_ZC_PASS_FLOW T
     SET T.AUDIT_RESULT   = NULL,
         T.AUDIT_NAME     = NULL,
         T.AUDIT_TIME     = NULL,
         T.AUDIT_MEMO     = NULL,
         T.CRT_AUDIT_STEP = {2},
         T.AUDIT_USER_ID = NULL
   WHERE T.PASS_APPLY_NO = {0}
     AND T.AUDIT_STEP = {1}
        ]]>
    </query>
    
    <query id="JdgQcmZcPassFlow.setCrtAuditStep" desc="修改审核结果">
        <![CDATA[
UPDATE QCM_ZC_PASS_FLOW T
     SET T.CRT_AUDIT_STEP = {2}
   WHERE T.PASS_APPLY_NO = {0}
     AND T.AUDIT_STEP = {1}
        ]]>
    </query>
</queryMap>