<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="非计划确认判定">
    <query id="QcmZgJugdeXs.query" desc="查询数据">
        <![CDATA[
        SELECT
            T.*,
            L.LEN_DESC,
            H.CUSTOMER_NM,
           round( T.ACT_LEN / T.ACT_COUNT,3) ACT_LEN_AVG,
            (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = D.DELIVERY_STATUS) DELIVERY_STATUS,
            D.DELVRY_QTY ORDER_QTY,
            S.CHARGE_NUM,
            H.SALE_ORG_DESC,
            H.SALE_AREA_DESC,
            H.CREATE_NAME,
            (
            SELECT
                CASE
                    WHEN L.ORDER_UNIT = '吨' THEN
                        SUM( Q.ACT_WEIGHT )
                    WHEN L.ORDER_UNIT = '米' THEN
                        SUM( Q.ACT_LEN )
                    ELSE
                        round(SUM( Q.ACT_LEN ) / 0.3048,3)
                END ACT_WEIGHT
            FROM
                QCM_ZG_JUGDE_APPLY Q
            WHERE
                Q.TARGET = 'A'
                AND Q.ORD_LN_DLY_PK  = T.ORD_LN_DLY_PK
            GROUP BY
                Q.ORD_LN_DLY_PK
            ) PDL,
            (
            SELECT
                CASE
                    WHEN L.ORDER_UNIT = '吨' THEN
                        SUM( Q.ACT_WEIGHT )
                    WHEN L.ORDER_UNIT = '米' THEN
                        SUM( Q.ACT_LEN )
                    ELSE
                        round(SUM( Q.ACT_LEN ) / 0.3048,3)
                END ACT_WEIGHT
            FROM
                QCM_ZG_JUGDE_APPLY Q
            WHERE
                Q.TARGET = 'A'
                AND Q.ORD_LN_DLY_PK  = T.ORD_LN_DLY_PK
                AND Q.INSTOCK_FLAG = '0'
            GROUP BY
                Q.ORD_LN_DLY_PK
            ) WPDL,
            (
            SELECT
                CASE
                    WHEN L.ORDER_UNIT = '吨' THEN
                        SUM( Q.ACT_WEIGHT )
                    WHEN L.ORDER_UNIT = '米' THEN
                        SUM( Q.ACT_LEN )
                    ELSE
                        round(SUM( Q.ACT_LEN ) / 0.3048,3)
                END ACT_WEIGHT
            FROM
                QCM_ZG_JUGDE_APPLY Q
            WHERE
                Q.TARGET = 'A'
                AND Q.ORD_LN_DLY_PK  = T.ORD_LN_DLY_PK
                AND Q.INSTOCK_FLAG = '1'
            GROUP BY
                Q.ORD_LN_DLY_PK
            ) YPDL,
            (SELECT
                STORAGE_NAME
            FROM
                MAT_BC_M M
                LEFT JOIN YDM_BC_BUTTRESS Y ON M.MAT_NO = Y.MAT_NO
                LEFT JOIN YDM_BS_STORAGE L ON Y.STORAGE_NO = L.STORAGE_NO
            WHERE
                M.JUGDE_APPLY_CODE = T.JUGDE_APPLY_CODE
                AND ROWNUM =1) STORAGE_NAME,
                (SELECT
                LOCATION_NAME
            FROM
                MAT_BC_M M
                LEFT JOIN YDM_BC_BUTTRESS Y ON M.MAT_NO = Y.MAT_NO
                LEFT JOIN YDM_BS_LOCATION L ON Y.LOCATION_NO = L.LOCATION_NO
            WHERE
                M.JUGDE_APPLY_CODE = T.JUGDE_APPLY_CODE
                AND ROWNUM =1) LOCATION_NAME,
            DECODE(T.LENGTH_TYPE,'0','超量','1','长尺','2','短尺','超量')LENGTH_TYPE,
            L.DELVRY_RANGE_MIN || L.DELVRY_RANGE_TPE || '-' ||  L.DELVRY_RANGE_MAX|| L.DELVRY_RANGE_TPE AS DELVRY_RANGE_MIN,
            L.ORDER_UNIT,
            TO_CHAR(T.APPLY_TIME,'YYYY-MM-DD') APPLY_TIME,
            D.DELIVERY_NO,
            round( D.DELVRY_QTY + D.DELVRY_QTY * (L.DELVRY_RANGE_MAX / 100),3) DELVRY_QTY_RANGE,
            (select min(A.create_time) create_time
          from QCM_JUGDE_APPLY_LOG A
         where t.jugde_apply_code = A.jugde_apply_code
           and t.judge_stove_no = A.judge_stove_no
           and t.batch_no = A.batch_no
           and t.batch_groud_no = A.batch_groud_no
           and t.pline_code = A.pline_code
           and A.LOG_TYPE = '1') FIRST_APPLY_TIME
        FROM
            QCM_ZG_JUGDE_APPLY T
            LEFT JOIN SLM_ORDER_LINE_DELIVERY D ON T.ORD_LN_DLY_PK = D.ORD_LN_DLY_PK
            LEFT JOIN SLM_ORDER_LINE L ON D.ORD_LN_PK = L.ORD_LN_PK
            LEFT JOIN SLM_ORDER_HEAD H ON L.ORD_PK = H.ORD_PK
            LEFT JOIN PLN_SALEORD S ON S.ORD_LN_DLY_PK = D.ORD_LN_DLY_PK
        WHERE
            T.IN_MOLD = '801701'
            AND T.TARGET = 'A'
            AND T.SUPPLY_UNIT = '120501' AND (T.VALIDFLAG = '00' OR T.XS_FLAG = {4})
            AND ({0} IS NULL OR T.JUDGE_STOVE_NO LIKE '%' || {0} || '%')
            AND ((({4} = '0' AND ({1} IS NULL OR T.APPLY_TIME >= TO_DATE( {1}, 'YYYY-MM-DD HH24:MI:SS' )))
            AND ({4} = '0' AND ({2} IS NULL OR T.APPLY_TIME <= TO_DATE( {2}, 'YYYY-MM-DD HH24:MI:SS' ))))
            OR (({4} = '1' AND ({2} IS NULL OR T.CONFIRM_DATE <= TO_DATE( {2}, 'YYYY-MM-DD HH24:MI:SS' )))
            AND ({4} = '1' AND ({1} IS NULL OR T.CONFIRM_DATE >= TO_DATE( {1}, 'YYYY-MM-DD HH24:MI:SS' )))))
            AND ({3} IS NULL OR H.ORDER_NO LIKE '%' || {3} || '%')
            AND T.XS_FLAG IN ({4})
        ]]>
    </query>

    <query id="QcmZgJugdeXs.Update" desc="修改">
        <![CDATA[
             UPDATE QCM_ZG_JUGDE_APPLY T
               SET
                    XS_FLAG = '#XS_FLAG#',
                    CONFIRM_NAME = '#CONFIRM_NAME#',
                    CONFIRM_DATE = SYSDATE
             WHERE
                 T.JUGDE_APPLY_CODE = '#JUGDE_APPLY_CODE#'
                 AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                 AND T.BATCH_NO = '#BATCH_NO#'
                 AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
                 AND T.IN_MOLD = '801701'
         ]]>
    </query>
    
    <query id="QcmZgJugdeXs.UpdateRemark" desc="修改备注">
        <![CDATA[
        
             UPDATE QCM_ZG_JUGDE_APPLY T
               SET
                    REMARK = '#REMARK#'
             WHERE
                 T.JUGDE_APPLY_CODE = '#JUGDE_APPLY_CODE#'
                 AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                 AND T.BATCH_NO = '#BATCH_NO#'
                 AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
                 AND T.IN_MOLD = '801701'
         ]]>
    </query>




    <query id="QcmZgJugdeXs.queryInList" desc="查询数据">
        <![CDATA[
        SELECT
            T.*,
            (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = T.IN_MOLD) IN_MOLD,
            (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = T.IN_TYPE) IN_TYPE
        FROM
            YDM_ZC_INLIST T
        WHERE
            ({0} IS NULL OR T.JUDGE_STOVE_NO = {0})
            AND ({1} IS NULL OR T.INSTOCK_TIME >= TO_DATE( {1}, 'YYYY-MM-DD HH24:MI:SS' ))
            AND ({2} IS NULL OR T.INSTOCK_TIME <= TO_DATE( {2}, 'YYYY-MM-DD HH24:MI:SS' ))
            AND ({3} IS NULL OR T.BAL_YEAR_MONTH = {3})
            AND ({4} IS NULL OR T.IN_MOLD = {4} OR T.IN_MOLD IS NULL)
            AND ({5} IS NULL OR T.IN_TYPE = {5} OR T.IN_TYPE IS NULL)
            AND T.SUPPLY_UNIT_CODE = '120501'
        ]]>
    </query>

    <query id="QcmZgJugdeXs.queryMatList" desc="查询数据">
        <![CDATA[
        SELECT
            T.*,
            (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = T.IN_MOLD) IN_MOLD,
            (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = T.IN_TYPE) IN_TYPE
        FROM
            MAT_ZC_M T
        WHERE
            ({0} IS NULL OR T.JUDGE_STOVE_NO = {0} )
            AND ({1} IS NULL OR T.INSTOCK_TIME >= TO_DATE( {1}, 'YYYY-MM-DD HH24:MI:SS' ))
            AND ({2} IS NULL OR T.INSTOCK_TIME <= TO_DATE( {2}, 'YYYY-MM-DD HH24:MI:SS' ))
            AND ({3} IS NULL OR T.BAL_YEAR_MONTH = {3})
            AND ({4} IS NULL OR T.IN_MOLD = {4} OR T.IN_MOLD IS NULL)
            AND ({5} IS NULL OR T.IN_TYPE = {5} OR T.IN_TYPE IS NULL)
            AND T.SUPPLY_UNIT_CODE = '120501'
        ]]>
    </query>

    <query id="QcmZgJugdeXs.queryOutList" desc="查询数据">
        <![CDATA[
        SELECT
            T.*,
            (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = T.IN_MOLD) IN_MOLD,
            (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = T.IN_TYPE) IN_TYPE
        FROM
            YDM_ZC_LOADVEHICLE_MAT T
            LEFT JOIN SLM_ORDER_HEAD H ON T.ORD_PK = H.ORD_PK
        WHERE
            ({0} IS NULL OR T.JUDGE_STOVE_NO = {0} )
            AND ({1} IS NULL OR T.SEN_TIME >= TO_DATE( {1}, 'YYYY-MM-DD HH24:MI:SS' ))
            AND ({2} IS NULL OR T.SEN_TIME <= TO_DATE( {2}, 'YYYY-MM-DD HH24:MI:SS' ))
            AND ({3} IS NULL OR T.BAL_YEAR_MONTH = {3})
            AND ({4} IS NULL OR T.IN_MOLD = {4} OR T.IN_MOLD IS NULL)
            AND ({5} IS NULL OR T.IN_TYPE = {5} OR T.IN_TYPE IS NULL)
            AND H.SUPPLY_UNIT = '120501'
        ]]>
    </query>

    <query id="QcmZgJugdeXs.UpdateInList" desc="修改">
        <![CDATA[
              UPDATE YDM_ZC_INLIST T
               SET
                    IN_MOLD = {0},
                    IN_TYPE = {1}
             WHERE
                 INSTOCK_SQE = {2}
                 AND BAL_YEAR_MONTH = {3}
                 AND MAT_NO = {4}
         ]]>
    </query>

    <query id="QcmZgJugdeXs.UpdateMatList" desc="修改">
        <![CDATA[
              UPDATE MAT_ZC_M T
               SET
                    IN_MOLD = {0},
                    IN_TYPE = {1}
             WHERE
               MAT_NO = {2}
         ]]>
    </query>

    <query id="QcmZgJugdeXs.UpdateOutList" desc="修改">
        <![CDATA[
              UPDATE YDM_ZC_LOADVEHICLE_MAT T
               SET
                    IN_MOLD = {0},
                    IN_TYPE = {1}
             WHERE
                 LOADVEHICLE_SQE = {2}
                 AND BAL_YEAR_MONTH = {3}
                 AND MAT_NO = {4}
         ]]>
    </query>
</queryMap>