<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="质量问题">
    <query id="QcmProblemHandling.getProblem" desc="查询判定数据">
        <![CDATA[
        SELECT * FROM (
            SELECT
                JUDGE_STOVE_NO,
                '' BATCH_NO,
                '' BATCH_GROUD_NO,
                PROCESS_CODE,
                PLINE_CODE,
                PLINE_NAME,
                PRO_ORDER_NO,
                '' ORD_LN_DLY_PK
            FROM
                QCM_GP_JUDGE_APPLY T
            WHERE
                ({0} IS NULL OR T.JUDGE_STOVE_NO LIKE '%' || {0} || '%')
                AND ({2} IS NULL OR JUDGE_RESULT_TIME >= TO_DATE( {2}, 'YYYY-MM-DD HH24:MI:SS' ))
                AND ({3} IS NULL OR JUDGE_RESULT_TIME <= TO_DATE( {3}, 'YYYY-MM-DD HH24:MI:SS' ))
                AND T.PLINE_CODE IN {1}
            UNION ALL
            SELECT
                JUDGE_STOVE_NO,
                BATCH_NO,
                BATCH_GROUD_NO,
                PROCESS_CODE,
                PLINE_CODE,
                PLINE_NAME,
                PRO_ORDER_NO,
                ORD_LN_DLY_PK
            FROM
                QCM_ZG_JUGDE_APPLY T
            WHERE
                 ({0} IS NULL OR T.JUDGE_STOVE_NO LIKE '%' || {0} || '%')
                AND ({2} IS NULL OR JUDGE_RESULT_TIME >= TO_DATE( {2}, 'YYYY-MM-DD HH24:MI:SS' ))
                AND ({3} IS NULL OR JUDGE_RESULT_TIME <= TO_DATE( {3}, 'YYYY-MM-DD HH24:MI:SS' ))
                AND T.PLINE_CODE IN {1}
            ORDER BY
                PROCESS_CODE) T
        WHERE NOT EXISTS (
        SELECT
            1
        FROM
            QCM_PROBLEM_HANDLING
        WHERE
            PROCESS_CODE = T.PROCESS_CODE
            AND (
                ( PROCESS_CODE < 'D' AND JUDGE_STOVE_NO = T.JUDGE_STOVE_NO )
                OR (
                    PROCESS_CODE >= 'D'
                    AND JUDGE_STOVE_NO = T.JUDGE_STOVE_NO
                    AND BATCH_NO = T.BATCH_NO
                    AND BATCH_GROUD_NO = T.BATCH_GROUD_NO
                    AND PLINE_CODE = T.PLINE_CODE
                    AND ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
                )
            )
        )
        ]]>
    </query>

    <query id="QcmProblemHandling.query" desc="查询数据">
        <![CDATA[
        SELECT
               T.JUDGE_STOVE_NO,
               DECODE(T.BATCH_NO,'1','',T.BATCH_NO) BATCH_NO,
               DECODE(T.BATCH_GROUD_NO,'1','',T.BATCH_GROUD_NO) BATCH_GROUD_NO,
               T.PROCESS_CODE,
               T.PLINE_CODE,
               T.PLINE_NAME,
               T.APPLY_NAME,
               TO_CHAR(T.APPLY_TIME, 'YYYY-MM-DD HH24:MI:SS') APPLY_TIME,
               T.APPLY_DESC,
               T.HANDLE_NAME,
               TO_CHAR(T.HANDLE_TIME, 'YYYY-MM-DD HH24:MI:SS') HANDLE_TIME,
               T.HANDLE_DESC,
               T.PRO_ORDER_NO,
               T.ORD_LN_DLY_PK,
               T.PROCESS_NEXT_FLAG,
               T.CONFIRM_NAME,
               TO_CHAR(T.CONFIRM_TIME, 'YYYY-MM-DD HH24:MI:SS') CONFIRM_TIME,
               T.HANDLE_RESULT
         FROM QCM_PROBLEM_HANDLING T
         WHERE
             ({0} IS NULL OR T.JUDGE_STOVE_NO LIKE '%' || {0} || '%')
            AND ({2} IS NULL OR APPLY_TIME >= TO_DATE( {2}, 'YYYY-MM-DD HH24:MI:SS' ))
            AND ({3} IS NULL OR APPLY_TIME <= TO_DATE( {3}, 'YYYY-MM-DD HH24:MI:SS' ))
            -- AND T.PLINE_CODE IN {1}
        ]]>
    </query>

    <query id="QcmProblemHandling.insert" desc="新增">
        <![CDATA[
             INSERT INTO QCM_PROBLEM_HANDLING(
                    JUDGE_STOVE_NO,
                    BATCH_NO,
                    BATCH_GROUD_NO,
                    PROCESS_CODE,
                    PLINE_CODE,
                    PLINE_NAME,
                    APPLY_NAME,
                    APPLY_TIME,
                    APPLY_DESC,
                    PRO_ORDER_NO,
                    ORD_LN_DLY_PK,
                    PROCESS_NEXT_FLAG)
             VALUES(
                    '#JUDGE_STOVE_NO#',
                    DECODE('#BATCH_NO#','','1','#BATCH_NO#'),
                    DECODE('#BATCH_GROUD_NO#','','1','#BATCH_GROUD_NO#'),
                    '#PROCESS_CODE#',
                    '#PLINE_CODE#',
                    '#PLINE_NAME#',
                    '#APPLY_NAME#',
                    SYSDATE,
                    '#APPLY_DESC#',
                    '#PRO_ORDER_NO#',
                    '#ORD_LN_DLY_PK#',
                    '#PROCESS_NEXT_FLAG#')
         ]]>
    </query>

    <query id="QcmProblemHandling.Update" desc="修改处理措施">
        <![CDATA[
              UPDATE QCM_PROBLEM_HANDLING T
               SET
                    T.HANDLE_NAME = '#HANDLE_NAME#',
                    T.HANDLE_TIME = SYSDATE,
                    T.HANDLE_DESC = '#HANDLE_DESC#',
                    T.HANDLE_RESULT = '#HANDLE_RESULT#'
             WHERE
            T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
            AND T.BATCH_NO = DECODE('#BATCH_NO#','','1','#BATCH_NO#')
            AND T.BATCH_GROUD_NO = DECODE('#BATCH_GROUD_NO#','','1','#BATCH_GROUD_NO#')
            AND T.PROCESS_CODE = '#PROCESS_CODE#'
         ]]>
    </query>

    <query id="QcmProblemHandling.UpdateConfirm" desc="修改确认人">
        <![CDATA[
              UPDATE QCM_PROBLEM_HANDLING T
               SET
                    T.CONFIRM_NAME = '#CONFIRM_NAME#',
                    T.CONFIRM_TIME = SYSDATE
             WHERE
            T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
            AND T.BATCH_NO = DECODE('#BATCH_NO#','','1','#BATCH_NO#')
            AND T.BATCH_GROUD_NO = DECODE('#BATCH_GROUD_NO#','','1','#BATCH_GROUD_NO#')
            AND T.PROCESS_CODE = '#PROCESS_CODE#'
         ]]>
    </query>

    <query id="QcmProblemHandling.Delete" desc="删除">
        <![CDATA[
            DELETE QCM_PROBLEM_HANDLING T
             WHERE
            T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
            AND T.BATCH_NO = DECODE('#BATCH_NO#','','1','#BATCH_NO#')
            AND T.BATCH_GROUD_NO = DECODE('#BATCH_GROUD_NO#','','1','#BATCH_GROUD_NO#')
            AND T.PROCESS_CODE = '#PROCESS_CODE#'
         ]]>
    </query>
</queryMap>