<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="质量申请放行">
	<query id="JdgQcmGpPassApply.insert" desc="新增记录">
		<![CDATA[
INSERT INTO QCM_GP_PASS_APPLY
  (PASS_APPLY_NO,
   PASS_APPLY_SEQ,
   JUGDE_APPLY_CODE,
   JUGDE_APPLY_SQE,
   MULTIPLE_NUM,
   JUDGE_STOVE_NO,
   STOVE_NO,
   GRADECODE,
   GRADENAME,
   ACT_COUNT,
   ACT_DIMATER,
   LEN_GP_SINGLE,
   FACE_RESULT_CODE,
   CHEM_RESULT_CODE,
   PHY_RESULT_CODE,
   DETECT_RESULT_CODE,
   JUDGE_RESULT_CODE,
   MEMO,
   ACT_THEORY_WEIGHT,
   PRO_ORDER_NO,
   PLINE_CODE,
   PLINE_NAME,
   PRO_PLAN_ID,
   GX_PLAN_NO,
   PRO_PLAN_ID_NEXT,
   GX_PLAN_NO_NEXT,
   PASS_APPLY_NAME,
   PASS_APPLY_TIME,
   UNIT_CODE,
   UNIT_DESC,
   TYPE)
VALUES
  ('#PASS_APPLY_NO#',
   '#PASS_APPLY_SEQ#',
   '#JUGDE_APPLY_CODE#',
   '#JUGDE_APPLY_SQE#',
   '#MULTIPLE_NUM#',
   '#JUDGE_STOVE_NO#',
   '#STOVE_NO#',
   '#GRADECODE#',
   '#GRADENAME#',
   '#ACT_COUNT#',
   '#ACT_DIMATER#',
   '#LEN_GP_SINGLE#',
   '#FACE_RESULT_CODE#',
   '#CHEM_RESULT_CODE#',
   '#PHY_RESULT_CODE#',
   '#DETECT_RESULT_CODE#',
   '#JUDGE_RESULT_CODE#',
   '#MEMO#',
   '#ACT_THEORY_WEIGHT#',
   '#PRO_ORDER_NO#',
   '#PLINE_CODE#',
   '#PLINE_NAME#',
   '#PRO_PLAN_ID#',
   '#GX_PLAN_NO#',
   '#PRO_PLAN_ID_NEXT#',
   '#GX_PLAN_NO_NEXT#',
   '#PASS_APPLY_NAME#',
   SYSDATE,
   '#UNIT_CODE#',
   (SELECT T.DEPARTNAME
  FROM CORE_APP_DEPARTMENT T
 WHERE T.DEPARTID = '#PASS_APPLY_UNIT_CODE#'),
   '#TYPE#')
		]]>
	</query>
	
	<query id="QcmGpPassApplyDAL.GetMaxPk" desc="获取最大主键">
        <![CDATA[
SELECT 'FX' || TO_CHAR(SYSDATE, 'YYYYMMDD') ||
       LPAD(NVL(SUBSTR(MAX(T.PASS_APPLY_NO), 11), 0) + 1, 5, '0') MAX_VALUE
  FROM QCM_GP_PASS_APPLY T
 WHERE T.PASS_APPLY_NO LIKE 'FX' || TO_CHAR(SYSDATE, 'YYYYMMDD') || '%'
        ]]>
    </query>
    
    <query id="QcmGpPassApplyDAL.GetMaxSeq" desc="获取最大序号">
        <![CDATA[
SELECT LPAD(NVL(MAX(T.PASS_APPLY_SEQ), 0) + 1, 3, '0') FROM QCM_GP_PASS_APPLY T WHERE T.PASS_APPLY_NO = {0}
        ]]>
    </query>
    
    <query id="QcmGpPassApplyDAL.GetGpApplyCnt" desc="获取管坯申请判定数">
        <![CDATA[
SELECT COUNT(1)
  FROM QCM_GP_PASS_APPLY T
 WHERE T.JUGDE_APPLY_CODE = {0}
   AND T.JUGDE_APPLY_SQE = {1}
   AND T.MULTIPLE_NUM = {2}
   AND T.JUDGE_STOVE_NO = {3}
   AND T.VALIDFLAG = '1'
        ]]>
    </query>
    
    <query id="QcmGpPassApplyDAL.query" desc="查询">
        <![CDATA[
SELECT 'False' CHK,
       A.PASS_APPLY_NO,
       A.PASS_APPLY_SEQ,
       A.JUGDE_APPLY_CODE,
       A.JUGDE_APPLY_SQE,
       A.JUDGE_STOVE_NO,
       A.STOVE_NO,
       MIN(A.GRADECODE) GRADECODE,
       MIN(A.GRADENAME) GRADENAME,
       MIN(A.FACE_RESULT_CODE) FACE_RESULT_CODE,
       MIN(A.CHEM_RESULT_CODE) CHEM_RESULT_CODE,
       MIN(A.PHY_RESULT_CODE) PHY_RESULT_CODE,
       MIN(A.DETECT_RESULT_CODE) DETECT_RESULT_CODE,
       MIN(A.JUDGE_RESULT_CODE) JUDGE_RESULT_CODE,
       MIN(B.BASENAME) FACE_RESULT_DESC,
       MIN(C.BASENAME) CHEM_RESULT_DESC,
       MIN(D.BASENAME) PHY_RESULT_DESC,
       MIN(E.BASENAME) DETECT_RESULT_DESC,
       MIN(F.BASENAME) JUDGE_RESULT_DESC,
       MIN(A.MEMO) MEMO,
       MIN(A.PLINE_CODE) ,
       MIN(A.PLINE_NAME) PLINE_NAME,
       MIN(A.PRO_PLAN_ID) PRO_PLAN_ID,
       MIN(A.PRO_PLAN_ID_NEXT) PRO_PLAN_ID_NEXT,
       MIN(A.AUDIT_NAME) AUDIT_NAME,
       TO_CHAR(MIN(A.AUDIT_TIME), 'YYYY-MM-DD HH24:MI:SS') AUDIT_TIME,
       NVL(MIN(G1.BASENAME),
           DECODE(MIN(A.AUDIT_RESULT), '1', '审核通过', '0', '审核不通过')) AUDIT_RESULT,
       MIN(A.AUDIT_MEMO) AUDIT_MEMO,
       MIN(A.AUDIT_NAME2) AUDIT_NAME2,
       TO_CHAR(MIN(A.AUDIT_TIME2), 'YYYY-MM-DD HH24:MI:SS') AUDIT_TIME2,
       NVL(MIN(G2.BASENAME),
           DECODE(MIN(A.AUDIT_RESULT2), '1', '审核通过', '0', '审核不通过')) AUDIT_RESULT2,
       MIN(A.AUDIT_MEMO2) AUDIT_MEMO2,
       MIN(A.PASS_APPLY_NAME) PASS_APPLY_NAME,
       TO_CHAR(MIN(A.PASS_APPLY_TIME), 'YYYY-MM-DD HH24:MI:SS') PASS_APPLY_TIME,
       MIN(A.DELETE_NAME) DELETE_NAME,
       TO_CHAR(MIN(A.DELETE_TIME), 'YYYY-MM-DD HH24:MI:SS') DELETE_TIME,
       MIN(A.VALIDFLAG) VALIDFLAG,
       DECODE(MIN(A.VALIDFLAG), '1', '有效', '0', '无效') VALIDFLAG_DESC,
       MIN(A.UNIT_CODE) UNIT_CODE,
       MIN(A.UNIT_DESC) UNIT_DESC,
       DECODE(MIN(A.TYPE), '1', '紧急放行', '质量放行') TYPE
  FROM QCM_GP_PASS_APPLY A
  LEFT JOIN COM_BASE_INFO B
    ON B.BASECODE = A.FACE_RESULT_CODE
  LEFT JOIN COM_BASE_INFO C
    ON C.BASECODE = A.CHEM_RESULT_CODE
  LEFT JOIN COM_BASE_INFO D
    ON D.BASECODE = A.PHY_RESULT_CODE
  LEFT JOIN COM_BASE_INFO E
    ON E.BASECODE = A.DETECT_RESULT_CODE
  LEFT JOIN COM_BASE_INFO F
    ON F.BASECODE = A.JUDGE_RESULT_CODE
  LEFT JOIN COM_BASE_INFO G1
    ON G1.BASECODE = A.AUDIT_RESULT
  LEFT JOIN COM_BASE_INFO G2
    ON G2.BASECODE = A.AUDIT_RESULT2
 WHERE ({0} IS NULL OR A.STOVE_NO LIKE '%' || {0} || '%')
   AND ({1} IS NULL OR A.JUDGE_STOVE_NO LIKE '%' || {1} || '%')
   AND ({2} IS NULL OR
       A.PASS_APPLY_TIME >= TO_DATE({2}, 'YYYY-MM-DD HH24:MI:SS'))
   AND ({3} IS NULL OR
       A.PASS_APPLY_TIME <= TO_DATE({3}, 'YYYY-MM-DD HH24:MI:SS'))
   AND A.VALIDFLAG IN ('1', {4})
 GROUP BY A.JUGDE_APPLY_CODE,
          A.JUGDE_APPLY_SQE,
          A.STOVE_NO,
          A.JUDGE_STOVE_NO
        ]]>
    </query>
    
    <query id="QcmGpPassApplyDAL.auditeQuery" desc="查询">
        <![CDATA[
SELECT T2.*,
       CASE
         WHEN T2.ORD_LN_PK IS NULL THEN
          (SELECT NVL(T3.UPDATE_NAME, T3.CREATE_NAME)
             FROM COM_MSC_STD_CIC T3
            WHERE T3.CIC = T2.CIC AND ROWNUM <= 1 )
         ELSE
          (SELECT NVL(T3.DELETE_NAME, NVL(T5.UPDATE_NAME, T5.CREATE_NAME))
             FROM CRAFT_ORD_DESIGN        T3,
                  CRAFT_ORD_DESIGN_MSC_PL T4,
                  COM_MSC_BACKLOG         T5,
                  CRAFT_ORD_DESIGN_MSC    T6
            WHERE T3.ORD_LN_PK = T2.ORD_LN_PK
              AND T3.CRAFT_SEQ = T2.CRAFT_SEQ
              AND T4.DESGIN_KEY = T3.DESGIN_KEY
              AND T5.MSC_PLINE = T4.MSC_PLINE
              AND T5.MSC = T6.MSC
              AND T6.DESGIN_KEY = T3.DESGIN_KEY
              AND ROWNUM <= 1)
       END CRAFT_NAME,
       CASE
         WHEN T2.ORD_LN_PK IS NULL THEN
          (SELECT T5.DEPARTNAME
             FROM COM_MSC_STD_CIC     T3,
                  CORE_APP_USER       T4,
                  CORE_APP_DEPARTMENT T5
            WHERE T3.CIC = T2.CIC
              AND T4.USERNAME = T3.CREATE_NAME
              AND T4.DEPTID = T5.DEPARTID AND ROWNUM <= 1 )
         ELSE
          (SELECT T5.UNIT_DESC_PROCESS
             FROM CRAFT_ORD_DESIGN T3, CRAFT_ORD_DESIGN_MSC T4, COM_MSC T5
            WHERE T3.ORD_LN_PK = T2.ORD_LN_PK
              AND T3.CRAFT_SEQ = T2.CRAFT_SEQ
              AND T4.DESGIN_KEY = T3.DESGIN_KEY
              AND T5.MSC = T4.MSC)
       END CRAFT_UNIT_NAME
  FROM (SELECT T.*,
               (SELECT FIRST_VALUE(G1.CRAFT_SEQ) OVER(PARTITION BY G1.PRO_PLAN_ID ORDER BY G1.GX_PLAN_NO)
                  FROM PLN_ORDER_ZG_S G1
                 WHERE (T.PRO_PLAN_ID_NEXT IS NOT NULL AND
                       T.PRO_PLAN_ID_NEXT LIKE 'ZG%' AND
                       G1.PRO_PLAN_ID = T.PRO_PLAN_ID_NEXT OR
                       T.PRO_PLAN_ID_NEXT IS NOT NULL AND
                       G1.GPREQ_ID = T.PRO_PLAN_ID_NEXT OR
                       T.PRO_PLAN_ID_NEXT IS NULL AND
                       G1.GPREQ_ID = T.PRO_PLAN_ID)
                   AND ROWNUM <= 1) CRAFT_SEQ,
               (SELECT FIRST_VALUE(G2.ORD_LN_PK) OVER(PARTITION BY G1.PRO_PLAN_ID ORDER BY G1.GX_PLAN_NO)
                  FROM PLN_ORDER_ZG_S G1, PLN_SALEORD G2
                 WHERE (T.PRO_PLAN_ID_NEXT IS NOT NULL AND
                       T.PRO_PLAN_ID_NEXT LIKE 'ZG%' AND
                       G1.PRO_PLAN_ID = T.PRO_PLAN_ID_NEXT OR
                       T.PRO_PLAN_ID_NEXT IS NOT NULL AND
                       G1.GPREQ_ID = T.PRO_PLAN_ID_NEXT OR
                       T.PRO_PLAN_ID_NEXT IS NULL AND
                       G1.GPREQ_ID = T.PRO_PLAN_ID)
                   AND G2.ORD_LN_DLY_PK = G1.ORD_LN_DLY_PK
                   AND ROWNUM <= 1) ORD_LN_PK,
               (SELECT G1.CIC
                  FROM PLN_REQINF_GP G1, PLN_SALEORD G2
                 WHERE G1.GPREQ_ID = T.PRO_PLAN_ID
                   AND ROWNUM <= 1) CIC
          FROM (SELECT 'False' CHK,
                       A.PASS_APPLY_NO,
                       A.JUGDE_APPLY_CODE,
                       A.JUGDE_APPLY_SQE,
                       A.JUDGE_STOVE_NO,
                       A.STOVE_NO,
                       MIN(A.GRADECODE) GRADECODE,
                       MIN(A.GRADENAME) GRADENAME,
                       MIN(A.FACE_RESULT_CODE) FACE_RESULT_CODE,
                       MIN(A.CHEM_RESULT_CODE) CHEM_RESULT_CODE,
                       MIN(A.PHY_RESULT_CODE) PHY_RESULT_CODE,
                       MIN(A.DETECT_RESULT_CODE) DETECT_RESULT_CODE,
                       MIN(A.JUDGE_RESULT_CODE) JUDGE_RESULT_CODE,
                       MIN(B.BASENAME) FACE_RESULT_DESC,
                       MIN(C.BASENAME) CHEM_RESULT_DESC,
                       MIN(D.BASENAME) PHY_RESULT_DESC,
                       MIN(E.BASENAME) DETECT_RESULT_DESC,
                       MIN(F.BASENAME) JUDGE_RESULT_DESC,
                       MIN(A.MEMO) MEMO,
                       MIN(A.PLINE_CODE),
                       MIN(A.PLINE_NAME) PLINE_NAME,
                       MIN(A.PRO_PLAN_ID) PRO_PLAN_ID,
                       MIN(A.PRO_PLAN_ID_NEXT) PRO_PLAN_ID_NEXT,
                       MIN(A.AUDIT_NAME) AUDIT_NAME,
                       TO_CHAR(MIN(A.AUDIT_TIME), 'YYYY-MM-DD HH24:MI:SS') AUDIT_TIME,
                       NVL(MIN(G1.BASENAME),
                           DECODE(MIN(A.AUDIT_RESULT),
                                  '1',
                                  '审核通过',
                                  '0',
                                  '审核不通过')) AUDIT_RESULT,
                       MIN(A.AUDIT_MEMO) AUDIT_MEMO,
                       MIN(A.AUDIT_NAME2) AUDIT_NAME2,
                       TO_CHAR(MIN(A.AUDIT_TIME2), 'YYYY-MM-DD HH24:MI:SS') AUDIT_TIME2,
                       NVL(MIN(G2.BASENAME),
                           DECODE(MIN(A.AUDIT_RESULT2),
                                  '1',
                                  '审核通过',
                                  '0',
                                  '审核不通过')) AUDIT_RESULT2,
                       MIN(A.AUDIT_MEMO2) AUDIT_MEMO2,
                       MIN(A.PASS_APPLY_NAME) PASS_APPLY_NAME,
                       TO_CHAR(MIN(A.PASS_APPLY_TIME),
                               'YYYY-MM-DD HH24:MI:SS') PASS_APPLY_TIME,
                       MIN(A.DELETE_NAME) DELETE_NAME,
                       TO_CHAR(MIN(A.DELETE_TIME), 'YYYY-MM-DD HH24:MI:SS') DELETE_TIME,
                       MIN(A.VALIDFLAG) VALIDFLAG,
                       DECODE(MIN(A.VALIDFLAG), '1', '有效', '0', '无效') VALIDFLAG_DESC,
                       MIN(A.UNIT_CODE) UNIT_CODE,
                       MIN(A.UNIT_DESC) UNIT_DESC,
                       DECODE(MIN(A.TYPE), '1', '紧急放行', '质量放行') TYPE
                  FROM QCM_GP_PASS_APPLY A
                  LEFT JOIN COM_BASE_INFO B
                    ON B.BASECODE = A.FACE_RESULT_CODE
                  LEFT JOIN COM_BASE_INFO C
                    ON C.BASECODE = A.CHEM_RESULT_CODE
                  LEFT JOIN COM_BASE_INFO D
                    ON D.BASECODE = A.PHY_RESULT_CODE
                  LEFT JOIN COM_BASE_INFO E
                    ON E.BASECODE = A.DETECT_RESULT_CODE
                  LEFT JOIN COM_BASE_INFO F
                    ON F.BASECODE = A.JUDGE_RESULT_CODE
                  LEFT JOIN COM_BASE_INFO G1
                    ON G1.BASECODE = A.AUDIT_RESULT
                    AND A.AUDIT_RESULT NOT IN ('0', '1')
                  LEFT JOIN COM_BASE_INFO G2
                    ON G2.BASECODE = A.AUDIT_RESULT2
                    AND A.AUDIT_RESULT2 NOT IN ('0', '1')
                    LEFT JOIN QCM_GP_JUDGE_APPLY  H
                    ON H.JUGDE_APPLY_CODE = A.JUGDE_APPLY_CODE
                 WHERE ({0} IS NULL OR A.STOVE_NO LIKE '%' || {0} || '%')
                   AND ({1} IS NULL OR
                       A.JUDGE_STOVE_NO LIKE '%' || {1} || '%')
                   AND ({2} IS NULL OR A.PASS_APPLY_TIME >=
                       TO_DATE({2}, 'YYYY-MM-DD HH24:MI:SS'))
                   AND ({3} IS NULL OR A.PASS_APPLY_TIME <=
                       TO_DATE({3}, 'YYYY-MM-DD HH24:MI:SS'))
                   AND ({4} IS NULL OR
                       {4} = '2' AND ({5} IN ('Quality1', 'Urgent1') AND
                       A.AUDIT_RESULT IS NULL OR
                       {5} IN ('Quality2', 'Urgent2') AND
                       A.AUDIT_RESULT2 IS NULL) OR
                       ({5} IN ('Quality1', 'Urgent1') AND
                       A.AUDIT_RESULT = {4} OR
                       {5} IN ('Quality2', 'Urgent2') AND
                       A.AUDIT_RESULT2 = {4}))
                   AND ({5} IN ('Quality1', 'Quality2') AND A.TYPE = '0' OR
                       {5} IN ('Urgent1', 'Urgent2') AND A.TYPE = '1' OR
                       {5} IS NULL)
                   AND A.VALIDFLAG IN ('1', {6})
                   AND H.SUPPLY_UNIT_CODE = {9}
                 GROUP BY A.PASS_APPLY_NO,
                          A.JUGDE_APPLY_CODE,
                          A.JUGDE_APPLY_SQE,
                          A.STOVE_NO,
                          A.JUDGE_STOVE_NO) T) T2
 WHERE (T2.ORD_LN_PK IS NOT NULL AND EXISTS
        (SELECT 1
           FROM CRAFT_ORD_DESIGN T3, CRAFT_ORD_DESIGN_MSC T4, COM_MSC T5
          WHERE T3.ORD_LN_PK = T2.ORD_LN_PK
            AND T3.CRAFT_SEQ = T2.CRAFT_SEQ
            AND T4.DESGIN_KEY = T3.DESGIN_KEY
            AND T5.MSC = T4.MSC
            AND ({5} <> 'Quality1' OR {5} IS NULL OR {7} = 'admin' OR
                {7} = T3.DELETE_NAME OR T5.UNIT_CODE_PROCESS IN {8})) OR
        T2.ORD_LN_PK IS NULL AND EXISTS
        (SELECT 1
           FROM COM_MSC_STD_CIC T3, CORE_APP_USER T4
          WHERE T3.CREATE_NAME = T4.USERNAME
            AND ({5} <> 'Quality1' OR {5} IS NULL OR {7} = 'admin' OR
                T4.DEPTID IN {8})))
        ]]>
    </query>
    
    <query id="QcmGpPassApplyDAL.auditeQuery2" desc="查询">
        <![CDATA[
SELECT 'False' CHK,
       A.PASS_APPLY_NO,
       A.PASS_APPLY_SEQ,
       A.JUGDE_APPLY_CODE,
       A.JUGDE_APPLY_SQE,
       A.MULTIPLE_NUM,
       A.JUDGE_STOVE_NO,
       A.STOVE_NO,
       A.GRADECODE,
       A.GRADENAME,
       A.ACT_COUNT,
       A.ACT_DIMATER,
       A.LEN_GP_SINGLE,
       A.FACE_RESULT_CODE,
       A.CHEM_RESULT_CODE,
       A.PHY_RESULT_CODE,
       A.DETECT_RESULT_CODE,
       A.JUDGE_RESULT_CODE,
       B.BASENAME FACE_RESULT_DESC,
       C.BASENAME CHEM_RESULT_DESC,
       D.BASENAME PHY_RESULT_DESC,
       E.BASENAME DETECT_RESULT_DESC,
       F.BASENAME JUDGE_RESULT_DESC,
       A.MEMO,
       A.ACT_THEORY_WEIGHT,
       A.PRO_ORDER_NO,
       A.PLINE_CODE,
       A.PLINE_NAME,
       A.PRO_PLAN_ID,
       A.GX_PLAN_NO,
       A.PRO_PLAN_ID_NEXT,
       A.GX_PLAN_NO_NEXT,
       A.AUDIT_NAME,
       TO_CHAR(A.AUDIT_TIME, 'YYYY-MM-DD HH24:MI:SS') AUDIT_TIME,
       DECODE(A.AUDIT_RESULT, '1', '审核通过', '0', '审核不通过') AUDIT_RESULT,
       A.AUDIT_MEMO,
       A.AUDIT_NAME2,
       TO_CHAR(A.AUDIT_TIME2, 'YYYY-MM-DD HH24:MI:SS') AUDIT_TIME2,
       DECODE(A.AUDIT_RESULT2, '1', '审核通过', '0', '审核不通过') AUDIT_RESULT2,
       A.AUDIT_MEMO2,
       A.PASS_APPLY_NAME,
       TO_CHAR(A.PASS_APPLY_TIME, 'YYYY-MM-DD HH24:MI:SS') PASS_APPLY_TIME,
       A.DELETE_NAME,
       TO_CHAR(A.DELETE_TIME, 'YYYY-MM-DD HH24:MI:SS') DELETE_TIME,
       A.VALIDFLAG,
       DECODE(A.VALIDFLAG, '1', '有效', '0', '无效') VALIDFLAG_DESC,
       A.UNIT_CODE,
       A.UNIT_DESC,
       DECODE(A.TYPE, '1', '紧急放行', '质量放行') TYPE,
       CASE
         WHEN A.PRO_PLAN_ID_NEXT LIKE 'ZG%' THEN
          (SELECT H.CRAFT_PATH
             FROM PLN_ORDER_ZG_S F, PLN_SALEORD G, CRAFT_ORD_DESIGN H
            WHERE F.PRO_PLAN_ID = A.PRO_PLAN_ID_NEXT
              AND F.GX_PLAN_NO = A.GX_PLAN_NO_NEXT
              AND G.ORD_LN_DLY_PK = F.ORD_LN_DLY_PK
              AND H.ORD_LN_PK = G.ORD_LN_PK
              AND H.CRAFT_SEQ = F.CRAFT_SEQ
              AND ROWNUM <= 1)
         WHEN A.PRO_PLAN_ID_NEXT IS NOT NULL THEN
          (SELECT H.CRAFT_PATH
             FROM PLN_ORDER_ZG_S F, PLN_SALEORD G, CRAFT_ORD_DESIGN H
            WHERE F.GPREQ_ID = A.PRO_PLAN_ID_NEXT
              AND G.ORD_LN_DLY_PK = F.ORD_LN_DLY_PK
              AND H.ORD_LN_PK = G.ORD_LN_PK
              AND H.CRAFT_SEQ = F.CRAFT_SEQ
              AND ROWNUM <= 1)
         ELSE
          (SELECT H.CRAFT_PATH
             FROM PLN_ORDER_ZG_S F, PLN_SALEORD G, CRAFT_ORD_DESIGN H
            WHERE F.GPREQ_ID = A.PRO_PLAN_ID
              AND G.ORD_LN_DLY_PK = F.ORD_LN_DLY_PK
              AND H.ORD_LN_PK = G.ORD_LN_PK
              AND H.CRAFT_SEQ = F.CRAFT_SEQ
              AND ROWNUM <= 1)
       END CRAFT_PATH,
       CASE
         WHEN A.PRO_PLAN_ID_NEXT LIKE 'ZG%' THEN
          (SELECT F.CRAFT_FILE_NO
             FROM PLN_ORDER_ZG_S F
            WHERE F.PRO_PLAN_ID = A.PRO_PLAN_ID_NEXT
              AND F.GX_PLAN_NO = A.GX_PLAN_NO_NEXT
              AND ROWNUM <= 1)
         WHEN A.PRO_PLAN_ID_NEXT IS NOT NULL THEN
          (SELECT F.CRAFT_FILE_NO
             FROM PLN_ORDER_ZG_S F
            WHERE F.GPREQ_ID = A.PRO_PLAN_ID_NEXT
              AND ROWNUM <= 1)
         ELSE
          (SELECT F.CRAFT_FILE_NO
             FROM PLN_ORDER_ZG_S F
            WHERE F.GPREQ_ID = A.PRO_PLAN_ID
              AND ROWNUM <= 1)
       END CRAFT_NO
  FROM QCM_GP_PASS_APPLY A
  LEFT JOIN COM_BASE_INFO B
    ON B.BASECODE = A.FACE_RESULT_CODE
  LEFT JOIN COM_BASE_INFO C
    ON C.BASECODE = A.CHEM_RESULT_CODE
  LEFT JOIN COM_BASE_INFO D
    ON D.BASECODE = A.PHY_RESULT_CODE
  LEFT JOIN COM_BASE_INFO E
    ON E.BASECODE = A.DETECT_RESULT_CODE
  LEFT JOIN COM_BASE_INFO F
    ON F.BASECODE = A.JUDGE_RESULT_CODE
 WHERE ({0} IS NULL OR A.STOVE_NO LIKE '%' || {0} || '%')
   AND ({1} IS NULL OR A.JUDGE_STOVE_NO LIKE '%' || {1} || '%')
   AND ({2} IS NULL OR
       A.PASS_APPLY_TIME >= TO_DATE({2}, 'YYYY-MM-DD HH24:MI:SS'))
   AND ({3} IS NULL OR
       A.PASS_APPLY_TIME <= TO_DATE({3}, 'YYYY-MM-DD HH24:MI:SS'))
   AND ({4} IS NULL OR ({4} = '2' AND A.AUDIT_RESULT2 IS NULL AND A.AUDIT_RESULT = '1') OR
       A.AUDIT_RESULT2 = {4})
   AND A.TYPE = {5}
   AND A.VALIDFLAG = '1'
        ]]>
    </query>
	
	<query id="QcmGpPassApplyDAL.updateValidflag" desc="更新有效标志">
        <![CDATA[
UPDATE QCM_GP_PASS_APPLY T
   SET T.VALIDFLAG = {1}, T.DELETE_NAME = {2}, T.DELETE_TIME = SYSDATE
 WHERE T.PASS_APPLY_NO = {0}
        ]]>
    </query>
    
    <query id="QcmGpPassApplyDAL.queryByPk" desc="通过主键查询">
        <![CDATA[
SELECT *
   FROM QCM_GP_PASS_APPLY T
  WHERE T.PASS_APPLY_NO = {0}
    AND T.PASS_APPLY_SEQ = {1}
        ]]>
    </query>
    
    <query id="QcmGpPassApplyDAL.queryByPassApplyNo" desc="通过放行单号查询">
        <![CDATA[
SELECT *
   FROM QCM_GP_PASS_APPLY T
  WHERE T.PASS_APPLY_NO = {0}
 
        ]]>
    </query>
    
    <query id="QcmGpPassApplyDAL.queryByPassApplyNo1" desc="通过放行单号查询">
        <![CDATA[
SELECT *
   FROM QCM_GP_PASS_APPLY T
  WHERE T.PASS_APPLY_NO = {0}
   AND T.AUDIT_NAME IS  NULL
        ]]>
    </query>
    
    <query id="QcmGpPassApplyDAL.updateAudite" desc="修改审核人">
        <![CDATA[
UPDATE QCM_GP_PASS_APPLY T
    SET T.AUDIT_NAME   = {1},
        T.AUDIT_TIME   = SYSDATE,
        T.AUDIT_RESULT = {2},
        T.AUDIT_MEMO   = {3}
  WHERE T.PASS_APPLY_NO = {0}
        ]]>
    </query>
    
    <query id="QcmGpPassApplyDAL.updateAudite2" desc="修改审核人2">
        <![CDATA[
UPDATE QCM_GP_PASS_APPLY T
    SET T.AUDIT_NAME2   = {1},
        T.AUDIT_TIME2   = SYSDATE,
        T.AUDIT_RESULT2 = {2},
        T.AUDIT_MEMO2   = {3}
  WHERE T.PASS_APPLY_NO = {0}
        ]]>
    </query>
    
    <query id="QcmGpPassApplyDAL.queryCntByGpJudgeApplyPk" desc="通过管坯申请判定主键查询">
        <![CDATA[
SELECT COUNT(1)
  FROM QCM_GP_PASS_APPLY T
 WHERE T.JUGDE_APPLY_CODE = {0}
   AND T.JUGDE_APPLY_SQE = {1}
   AND T.JUDGE_STOVE_NO = {2}
   AND T.VALIDFLAG = '1'
        ]]>
    </query>
    
     <query id="QcmGpPassApplyDAL.queryByGpJudgeApplyPkNew" desc="通过管坯申请判定主键查询">
        <![CDATA[
SELECT *
  FROM QCM_GP_PASS_APPLY T
 WHERE T.JUGDE_APPLY_CODE = {0}
   AND T.JUGDE_APPLY_SQE = {1}
   AND T.JUDGE_STOVE_NO = {2}
   AND T.AUDIT_RESULT='1'
        ]]>
    </query>
    
    <query id="QcmGpPassApplyDAL.queryByGpJudgeApplyPk" desc="通过管坯申请判定主键查询">
        <![CDATA[
SELECT *
  FROM QCM_GP_PASS_APPLY T
 WHERE T.JUGDE_APPLY_CODE = {0}
   AND T.JUGDE_APPLY_SQE = {1}
   AND T.JUDGE_STOVE_NO = {2}
   AND T.VALIDFLAG = '1'
        ]]>
    </query>
    
    <query id="QcmGpPassApplyDAL.queryByGpJudgeApplyByType" desc="通过管坯申请判定主键查询">
        <![CDATA[
SELECT *
  FROM QCM_GP_PASS_APPLY T
 WHERE T.JUGDE_APPLY_CODE = {0}
   AND T.JUGDE_APPLY_SQE = {1}
   AND T.JUDGE_STOVE_NO = {2}
   AND T.TYPE='0'
   AND T.VALIDFLAG = '1'
        ]]>
    </query>
    
    <query id="QcmGpPassApplyDAL.queryPlanByOrdNo" desc="通过管坯申请判定主键查询">
        <![CDATA[
	select t.produce_sort 
		from pln_saleord t  
		where t.order_no=substr({0},0,length({0})-4) 
		and t.order_seq=substr({0},length({0})-2,length({0}))

        ]]>
    </query>
    
    <query id="QcmGpPassApplyDAL.updateValidflagByJudgeStoveNo" desc="更新有效标志">
        <![CDATA[
UPDATE QCM_GP_PASS_APPLY T
   SET T.VALIDFLAG = {1}, T.DELETE_NAME = {2}, T.DELETE_TIME = SYSDATE
 WHERE T.JUDGE_STOVE_NO = {0}
 AND T.JUGDE_APPLY_CODE = {3}
 AND T.JUGDE_APPLY_SQE = {4}
 AND T.VALIDFLAG = '1'
        ]]>
    </query>
    
    <query id="QcmGpPassApplyDAL.updateJudgeResult" desc="修改综合判定结果">
        <![CDATA[
UPDATE QCM_GP_PASS_APPLY T
   SET T.JUDGE_RESULT_CODE = {1}
 WHERE T.JUDGE_STOVE_NO = {0}
   AND T.VALIDFLAG = '1'
        ]]>
    </query>
    
    <query id="QcmGpPassApplyDAL.getGpPassApplyMemo" desc="获取放行备注、审核备注">
        <![CDATA[
SELECT T.JUDGE_STOVE_NO, T.MEMO, T.AUDIT_MEMO, T.AUDIT_MEMO2
  FROM QCM_GP_PASS_APPLY T
 WHERE T.STOVE_NO = {0}
   AND T.VALIDFLAG = '1'
        ]]>
    </query>

    <query id="QcmGpPassApplyDAL.getPassResultByJudgeStoveNo" desc="通过判定炉号获取放行信息">
        <![CDATA[
SELECT T.AUDIT_RESULT2
      FROM QCM_GP_PASS_APPLY T
     WHERE T.JUDGE_STOVE_NO = {0}
       AND T.VALIDFLAG = '1'
       AND T.TYPE = '0'
        ]]>
    </query>
</queryMap>