<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.aucma.report.mapper.GeneralReportMapper">

    <select id="inventoryRateReportList" resultType="com.aucma.report.domain.InventoryRateReport" parameterType="java.util.HashMap">
        SELECT boi.ORDER_CODE,
        boi.BEGIN_DATE,
        boi.MATERIAL_CODE,
        boi.MATERIAL_NAME,
        boi.ORDER_AMOUNT,
        NVL(boi.COMPLETE_AMOUNT, 0) COMPLETE_AMOUNT,
        ROUND(NVL(boi.COMPLETE_AMOUNT, 0) / boi.ORDER_AMOUNT * 100, 2) || '%' ORDER_RATE,
        PL.WORK_CENTER_CODE,
        PL.PRODUCT_LINE_NAME
        FROM BASE_ORDERINFO boi
        LEFT JOIN BASE_PRODUCTLINE PL ON PL.WORK_CENTER_CODE = boi.WORK_CENTER_CODE
        WHERE boi.MATERIAL_CODE LIKE '90%'
        <if test="WORK_CENTER_CODE != null and WORK_CENTER_CODE != ''">
            AND boi.WORK_CENTER_CODE = #{WORK_CENTER_CODE}
        </if>
        <if test="MATERIAL_CODE != null  and MATERIAL_CODE != ''">
            and boi.MATERIAL_CODE like concat(#{MATERIAL_CODE}, '%')
        </if>
        <if test="MATERIAL_NAME != null  and MATERIAL_NAME != ''">
            and boi.MATERIAL_NAME like concat(concat('%',#{MATERIAL_NAME}), '%')
        </if>
        <if test="ORDER_CODE != null  and ORDER_CODE != ''">
            and boi.ORDER_CODE like concat(concat('%',#{ORDER_CODE}), '%')
        </if>
        <if test="beginBeginTime != null  and beginBeginTime != '' and endBeginTime != null  and endBeginTime != ''">
            AND TO_CHAR(boi.BEGIN_DATE, 'YYYY-MM-DD') BETWEEN #{beginBeginTime} AND #{endBeginTime}
        </if>
        ORDER BY ROUND(NVL(boi.COMPLETE_AMOUNT, 0) / boi.ORDER_AMOUNT * 100, 2)
    </select>

    <select id="productionExecutionReportList" resultType="com.aucma.report.domain.ProductionExecutionReport" parameterType="java.util.HashMap">
        SELECT B2.PRODUCT_LINE_CODE,
        B2.PRODUCT_LINE_NAME,
        VMC.ORDER_CODE,
        BP.PRODUCT_LINE_CODE STATION_CODE,
        BP.PRODUCT_LINE_NAME STATION_NAME,
        VMC.MATERIAL_CODE,
        BM.MATERIAL_NAME,
        BO.MATERIAL_CODE PRODUCT_CODE,
        BO.MATERIAL_NAME PRODUCT_NAME,
        COUNT(*) COMP_AMOUNT
        FROM VIEW_MATERIAL_COMPLETION VMC
        LEFT JOIN BASE_PRODUCTLINE BP ON BP.PRODUCT_LINE_CODE = VMC.STATION_NAME
        LEFT JOIN BASE_PRODUCTLINE B2 ON B2.PRODUCT_LINE_CODE = BP.PARENT_ID
        LEFT JOIN BASE_ORDERINFO BO ON BO.ORDER_CODE = VMC.ORDER_CODE
        LEFT JOIN BASE_MATERIALINFO BM ON BM.MATERIAL_CODE = VMC.MATERIAL_CODE
        <where>
            <if test="productLineCode != null and productLineCode != ''">
                AND VMC.PRODUCT_LINE_CODE = #{productLineCode}
            </if>
            <if test="stationCode != null  and stationCode != ''">
                and VMC.STATION_NAME = #{stationCode}
            </if>
            <if test="ORDER_CODE != null  and ORDER_CODE != ''">
                and VMC.ORDER_CODE = #{ORDER_CODE}
            </if>
            <if test="PRODUCT_CODE != null  and PRODUCT_CODE != ''">
                and BO.MATERIAL_CODE like concat(#{PRODUCT_CODE}, '%')
            </if>
            <if test="PRODUCT_NAME != null  and PRODUCT_NAME != ''">
                and BO.MATERIAL_NAME like concat(concat('%', #{PRODUCT_NAME}), '%')
            </if>
            <if test="beginBeginTime != null  and beginBeginTime != '' and endBeginTime != null  and endBeginTime != ''">
                AND TO_CHAR(VMC.COMPLETE_DATE, 'YYYY-MM-DD HH24:MI:SS') BETWEEN #{beginBeginTime} AND #{endBeginTime}
            </if>
        </where>
        GROUP BY B2.PRODUCT_LINE_CODE, B2.PRODUCT_LINE_NAME, VMC.ORDER_CODE, BO.MATERIAL_CODE, BP.PRODUCT_LINE_CODE,
        BP.PRODUCT_LINE_NAME, VMC.MATERIAL_CODE, BM.MATERIAL_NAME, BO.MATERIAL_NAME
        ORDER BY B2.PRODUCT_LINE_CODE, VMC.ORDER_CODE, BP.PRODUCT_LINE_CODE
    </select>

    <select id="WIPInquiryReportList" resultType="com.aucma.report.domain.WIPInquiryReport" parameterType="java.util.HashMap">
        SELECT B2.PRODUCT_LINE_CODE,
        B2.PRODUCT_LINE_NAME,
        SD.ORDER_CODE,
        SD.MATERIAL_CODE,
        SD.MATERIAL_NAME,
        BO.MATERIAL_CODE PRODUCT_CODE,
        BO.MATERIAL_NAME PRODUCT_NAME,
        MAX(BO.ORDER_AMOUNT)    ORDER_AMOUNT,
        MAX(BO.COMPLETE_AMOUNT) COMPLETE_AMOUNT,
        COUNT(*)         COMP_AMOUNT
        FROM (
        SELECT PB.ORDER_CODE,
        BM.MATERIAL_CODE,
        BM.MATERIAL_NAME,
        VMC.MATERIAL_BARCODE,
        MAX(BE.EXECUTION_SORT) EXECUTION_SORT,
        MAX(COMPLETE_DATE)     COMPLETE_DATE
        FROM MATERIAL_COMPLETION VMC
        JOIN RECORD_INSTORE IE ON IE.STORE_CODE = 'PQK-001' AND VMC.MATERIAL_BARCODE = IE.BARCODE_CODE
        LEFT JOIN BASE_PRODUCTLINE BE ON BE.PRODUCT_LINE_CODE = VMC.STATION_NAME
        LEFT JOIN PRINT_BARCODE PB
        ON PRINT_BARTYPE = 1 AND VMC.MATERIAL_BARCODE = PB.MATERIAL_BARCODE
        LEFT JOIN BASE_MATERIALINFO BM ON BM.MATERIAL_CODE = PB.MATERIAL_CODE
        LEFT JOIN PRODUCT_OFFLINE PO ON PO.BOX_CODE = PB.MATERIAL_BARCODE
        WHERE PB.MATERIAL_BARCODE IS NOT NULL
        AND PO.BOX_CODE IS NULL
        --   AND VMC.COMPLETE_DATE > (SYSDATE - 7)
        <if test="beginStationCode != null  and beginStationCode != ''">
            AND BE.EXECUTION_SORT >= #{beginStationCode}
        </if>
        <if test="endStationCode != null  and endStationCode != ''">
            AND #{endStationCode} > BE.EXECUTION_SORT
        </if>
        GROUP BY PB.ORDER_CODE, BM.MATERIAL_CODE, BM.MATERIAL_NAME, VMC.MATERIAL_BARCODE
        ) SD
        LEFT JOIN BASE_ORDERINFO BO ON BO.ORDER_CODE = SD.ORDER_CODE
        LEFT JOIN BASE_PRODUCTLINE B2 ON B2.WORK_CENTER_CODE = BO.WORK_CENTER_CODE
        WHERE BO.ORDER_AMOUNT != BO.COMPLETE_AMOUNT
            <if test="productLineCode != null and productLineCode != ''">
                AND B2.PRODUCT_LINE_CODE = #{productLineCode}
            </if>
            <if test="ORDER_CODE != null  and ORDER_CODE != ''">
                and SD.ORDER_CODE = #{ORDER_CODE}
            </if>
            <if test="PRODUCT_CODE != null  and PRODUCT_CODE != ''">
                and BO.MATERIAL_CODE = #{PRODUCT_CODE}
            </if>
            <if test="PRODUCT_NAME != null  and PRODUCT_NAME != ''">
                and BO.MATERIAL_NAME like concat(concat('%', #{PRODUCT_NAME}), '%')
            </if>
        GROUP BY B2.PRODUCT_LINE_CODE, B2.PRODUCT_LINE_NAME, SD.ORDER_CODE, SD.MATERIAL_CODE, SD.MATERIAL_NAME,
        BO.MATERIAL_CODE, BO.MATERIAL_NAME
        ORDER BY COMP_AMOUNT DESC
    </select>

    <select id="qualityDefectsStatisticalAnalysisList"
            resultType="com.aucma.report.domain.QualityDefectsStatisticalAnalysis" parameterType="java.util.HashMap">
        SELECT FACTORY_NAME,
        PRODUCT_LINE_NAME,
        STATION_CODE,
        STATION_NAME,
        COUNT(*) INSPECTION_NUMBER,
        SUM(REWORK_NUMBER) REWORK_NUMBER,
        ROUND((1 - SUM(REWORK_NUMBER) / COUNT(*)) * 100, 2) || '%' RATE
        FROM (
        SELECT FY.FACTORY_NAME,
        BPP.PRODUCT_LINE_NAME,
        BP.PRODUCT_LINE_CODE STATION_CODE,
        BP.PRODUCT_LINE_NAME STATION_NAME,
        RQI.BAR_CODE,
        MAX(CASE WHEN RQI.TREATMENT_MEASURE = '1' THEN 1 ELSE 0 END) REWORK_NUMBER
        FROM REPORT_QUALITY_INSPECTION RQI
        LEFT JOIN BASE_PRODUCTLINE BP
        ON BP.PRODUCT_LINE_CODE = RQI.STATION_CODE
        LEFT JOIN BASE_PRODUCTLINE BPP ON BPP.PRODUCT_LINE_CODE = BP.PARENT_ID
        LEFT JOIN BASE_FACTORY FY ON FY.FACTORY_CODE = BPP.PLANT_CODE
        <where>
            <if test="PRODUCT_LINE_CODE != null  and PRODUCT_LINE_CODE != ''">
                AND BPP.PRODUCT_LINE_CODE = #{PRODUCT_LINE_CODE}
            </if>
            <if test="stationCodeList != null and stationCodeList != ''">
                AND BP.PRODUCT_LINE_CODE IN
                <foreach collection="stationCodeList" item="stationCode" open="(" separator="," close=")">
                    #{stationCode}
                </foreach>
            </if>
            <if test="beginBeginTime != null  and beginBeginTime != '' and endBeginTime != null  and endBeginTime != ''">
                AND TO_CHAR(RQI.INSPECTOR_TIME, 'YYYY-MM-DD HH24:MI:SS') BETWEEN #{beginBeginTime} AND #{endBeginTime}
            </if>
        </where>
        GROUP BY FY.FACTORY_NAME, BPP.PRODUCT_LINE_NAME, BP.PRODUCT_LINE_CODE, BP.PRODUCT_LINE_NAME,
        RQI.BAR_CODE
        )
        GROUP BY FACTORY_NAME, PRODUCT_LINE_NAME, STATION_CODE, STATION_NAME
        ORDER BY REWORK_NUMBER
    </select>
    <select id="fewerMistakesReportList" resultType="com.aucma.report.domain.FewerMistakesReport"
            parameterType="java.util.HashMap">
        SELECT FY.FACTORY_NAME,
        BPP.PRODUCT_LINE_NAME,
        TO_CHAR(RQI.INSPECTOR_TIME, 'YYYY-MM-DD') INSPECTOR_TIME,
        RQI.STATION_CODE,
        BP.PRODUCT_LINE_NAME STATION_NAME,
        GET_MATERIAL_TYPE(RQI.MATERIAL_NAME) MATERIAL_MODEL,
        RQI.QUALITY_DEFECT_CODE,
        RQI.QUALITY_DEFECT_NAME,
        COUNT(*) DEFECT_NUMBER
        FROM REPORT_QUALITY_INSPECTION RQI
        LEFT JOIN BASE_PRODUCTLINE BP ON BP.PRODUCT_LINE_CODE = RQI.STATION_CODE
        LEFT JOIN BASE_PRODUCTLINE BPP ON BPP.PRODUCT_LINE_CODE = BP.PARENT_ID
        LEFT JOIN BASE_FACTORY FY ON FY.FACTORY_CODE = BPP.PLANT_CODE
        WHERE RQI.TREATMENT_MEASURE = 1
        AND (RQI.QUALITY_DEFECT_NAME LIKE '%少%'
        OR RQI.QUALITY_DEFECT_NAME LIKE '%错%')
        <if test="PRODUCT_LINE_CODE != null  and PRODUCT_LINE_CODE != ''">
            AND BPP.PRODUCT_LINE_CODE = #{PRODUCT_LINE_CODE}
        </if>
        <if test="STATION_CODE != null  and STATION_CODE != ''">
            AND RQI.STATION_CODE = #{STATION_CODE}
        </if>
        <if test="MATERIAL_MODEL != null  and MATERIAL_MODEL != ''">
            AND RQI.MATERIAL_NAME LIKE '%' || #{MATERIAL_MODEL} || '%'
        </if>
        <if test="beginBeginTime != null  and beginBeginTime != '' and endBeginTime != null  and endBeginTime != ''">
            AND TO_CHAR(RQI.INSPECTOR_TIME, 'YYYY-MM-DD') BETWEEN #{beginBeginTime} AND #{endBeginTime}
        </if>
        GROUP BY FY.FACTORY_NAME, BPP.PRODUCT_LINE_NAME, TO_CHAR(RQI.INSPECTOR_TIME, 'YYYY-MM-DD'),
        RQI.STATION_CODE, BP.PRODUCT_LINE_NAME, GET_MATERIAL_TYPE(RQI.MATERIAL_NAME),
        RQI.QUALITY_DEFECT_CODE, RQI.QUALITY_DEFECT_NAME
        ORDER BY DEFECT_NUMBER DESC
    </select>
    <select id="qualityIssuesReportList" resultType="com.aucma.report.domain.QualityIssuesReport"
            parameterType="java.util.HashMap">
        SELECT ZSD.FACTORY_NAME,
        ZSD.PRODUCT_LINE_CODE,
        ZSD.PRODUCT_LINE_NAME,
        ZSD.MATERIAL_MODEL,
        ZSD.QUALITY_DEFECT_CODE,
        ZSD.QUALITY_DEFECT_NAME,
        COUNT(*) Q_SUM,
        CASE
        WHEN OS.OFFLINE_NUM = 0 THEN '0.00'
        ELSE TO_CHAR(ROUND(COUNT(*) / OS.OFFLINE_NUM * 100, 2), 'FM99990.00') END || '%' OFFLINE_NUM
        FROM (
        SELECT BF.FACTORY_NAME,
        PL2.PRODUCT_LINE_CODE,
        PL2.PRODUCT_LINE_NAME,
        SUBSTR(BO.MATERIAL_NAME, 1, INSTR(BO.MATERIAL_NAME, ',') - 1) MATERIAL_MODEL,
        RQI.BAR_CODE,
        RQI.QUALITY_DEFECT_CODE,
        QI.QUALITY_DEFECT_NAME
        FROM REPORT_QUALITY_INSPECTION RQI
        LEFT JOIN BASE_PRODUCTLINE PL on RQI.STATION_CODE = PL.PRODUCT_LINE_CODE
        LEFT JOIN BASE_PRODUCTLINE PL2 on PL2.PRODUCT_LINE_CODE = PL.PARENT_ID
        LEFT JOIN BASE_FACTORY BF on BF.FACTORY_CODE = PL.PLANT_CODE
        LEFT JOIN BASE_QUALITY_INSPECTION_ITEM QI on QI.QUALITY_DEFECT_CODE = RQI.QUALITY_DEFECT_CODE
        LEFT JOIN PRINT_BARCODE PB ON PB.MATERIAL_BARCODE = RQI.BAR_CODE
        LEFT JOIN BASE_ORDERINFO BO ON BO.ORDER_CODE = PB.ORDER_CODE
        WHERE RQI.TREATMENT_MEASURE = '1'
        <if test="beginBeginTime != null  and beginBeginTime != '' and endBeginTime != null  and endBeginTime != ''">
            AND TO_CHAR(RQI.INSPECTOR_TIME, 'YYYY-MM-DD HH24:MI:SS') BETWEEN #{beginBeginTime} AND #{endBeginTime}
        </if>
        <if test="STATION_CODE != null  and STATION_CODE != ''">
            AND RQI.STATION_CODE = #{STATION_CODE}
        </if>
        <if test="PRODUCT_LINE_CODE != null  and PRODUCT_LINE_CODE != ''">
            AND PL2.PRODUCT_LINE_CODE = #{PRODUCT_LINE_CODE}
        </if>
        <if test="MATERIAL_MODEL != null  and MATERIAL_MODEL != ''">
            AND RQI.MATERIAL_NAME LIKE '%' || #{MATERIAL_MODEL} || '%'
        </if>
        GROUP BY BF.FACTORY_NAME, PL2.PRODUCT_LINE_CODE, PL2.PRODUCT_LINE_NAME,
        SUBSTR(BO.MATERIAL_NAME, 1, INSTR(BO.MATERIAL_NAME, ',') - 1),
        RQI.BAR_CODE, RQI.QUALITY_DEFECT_CODE, QI.QUALITY_DEFECT_NAME
        ) ZSD
        CROSS JOIN (SELECT COUNT(*) OFFLINE_NUM
        FROM PRODUCT_OFFLINE
        <if test="beginBeginTime != null  and beginBeginTime != '' and endBeginTime != null  and endBeginTime != ''">
            WHERE TO_CHAR(PRODUCT_SCANTIME, 'YYYY-MM-DD HH24:MI:SS') BETWEEN #{beginBeginTime} AND #{endBeginTime}
        </if>
        ) OS
        GROUP BY ZSD.FACTORY_NAME, ZSD.PRODUCT_LINE_CODE, ZSD.PRODUCT_LINE_NAME,
        ZSD.MATERIAL_MODEL, ZSD.QUALITY_DEFECT_CODE, ZSD.QUALITY_DEFECT_NAME, OS.OFFLINE_NUM
        ORDER BY ZSD.PRODUCT_LINE_CODE, Q_SUM DESC
    </select>
    <select id="ScanOfflineRecordReportList" resultType="java.util.HashMap" parameterType="java.util.HashMap">
        SELECT *
        FROM VIEW_PRODUCT_OFFLINE
    </select>
    <select id="temperatureRecordReportList" resultType="java.util.HashMap" parameterType="java.util.HashMap">
        SELECT *
        FROM VIEW_RECORD_TEMPERATURE
    </select>
    <select id="pourRecordReportList" resultType="java.util.HashMap" parameterType="java.util.HashMap">
        SELECT *
        FROM VIEW_PERFUSION_RECORD
    </select>

    <select id="qualityDefectsDetailList" resultType="java.util.HashMap" parameterType="java.util.HashMap">
        WITH TotalDefects AS (
        SELECT
        COUNT(*) AS ALL_DEFECT
        FROM
        REPORT_QUALITY_INSPECTION RQI
        WHERE
        RQI.TREATMENT_MEASURE = 1
        <if test="stationCode != null  and stationCode != ''">
            AND RQI.STATION_CODE = #{stationCode}
        </if>
        <if test="beginBeginTime != null  and beginBeginTime != '' and endBeginTime != null  and endBeginTime != ''">
            AND TO_CHAR(RQI.INSPECTOR_TIME, 'YYYY-MM-DD HH24:MI:SS') BETWEEN #{beginBeginTime} AND #{endBeginTime}
        </if>
        )
        SELECT ROW_NUMBER() OVER (ORDER BY RATE) AS SEQ,
        SD.QUALITY_DEFECT_NAME,
        SD.MATERIAL_MODEL,
        SD.DEFECT_NUMBER,
        RATE
        FROM (SELECT DA.QUALITY_DEFECT_NAME,
        DA.MATERIAL_MODEL,
        COUNT(*)                                                               AS DEFECT_NUMBER,
        TO_CHAR(ROUND(COUNT(*) / TD.ALL_DEFECT * 100, 2), 'FM99990.00') || '%' AS RATE
        FROM (SELECT RQI.QUALITY_DEFECT_NAME,
        RQI.BAR_CODE,
        GET_MATERIAL_TYPE(RQI.MATERIAL_NAME) MATERIAL_MODEL,
        RQI.QUALITY_DEFECT_CODE
        FROM REPORT_QUALITY_INSPECTION RQI
        WHERE RQI.TREATMENT_MEASURE = 1
        <if test="stationCode != null  and stationCode != ''">
            AND RQI.STATION_CODE = #{stationCode}
        </if>
        <if test="beginBeginTime != null  and beginBeginTime != '' and endBeginTime != null  and endBeginTime != ''">
            AND TO_CHAR(RQI.INSPECTOR_TIME, 'YYYY-MM-DD HH24:MI:SS') BETWEEN #{beginBeginTime} AND #{endBeginTime}
        </if>
        GROUP BY RQI.QUALITY_DEFECT_NAME, RQI.BAR_CODE, GET_MATERIAL_TYPE(RQI.MATERIAL_NAME),
        RQI.QUALITY_DEFECT_CODE) DA
        CROSS JOIN TotalDefects TD
        GROUP BY DA.QUALITY_DEFECT_NAME, DA.MATERIAL_MODEL, TD.ALL_DEFECT) SD
        ORDER BY SD.MATERIAL_MODEL, DEFECT_NUMBER DESC
    </select>

    <select id="productTraceabilityReportList" resultType="com.aucma.report.domain.ProductTraceabilityReport"
            parameterType="java.util.HashMap">
        SELECT PL.PRODUCT_LINE_CODE,
        PL.PRODUCT_LINE_NAME,
        BO.ORDER_CODE,
        BO.SALEORDER_CODE,
        BO.SALEORDER_LINENUMBER,
        BO.MATERIAL_CODE,
        BO.MATERIAL_NAME,
        PO.PRODUCT_SNCODE,
        PO.BOX_CODE,
        PO.PRODUCT_SCANTIME
        FROM PRODUCT_OFFLINE PO
        LEFT JOIN BASE_ORDERINFO BO ON BO.ORDER_CODE = SUBSTR(PO.PRODUCT_ORDER_NO, -8)
        LEFT JOIN BASE_PRODUCTLINE PL ON PL.WORK_CENTER_CODE = BO.WORK_CENTER_CODE
        LEFT JOIN (SELECT BAR_CODE
        FROM REPORT_QUALITY_INSPECTION
        WHERE PROCESS_RESULT = 'KA'
        GROUP BY BAR_CODE) KA ON KA.BAR_CODE = PO.BOX_CODE
        <where>
            <if test="PRODUCT_LINE_CODE != null and PRODUCT_LINE_CODE != ''">and PO.PRODUCT_LINE_CODE =
                #{PRODUCT_LINE_CODE}
            </if>
            <if test="ORDER_CODE != null and ORDER_CODE != ''">and BO.ORDER_CODE = #{ORDER_CODE}</if>
            <if test="MATERIAL_CODE != null and MATERIAL_CODE != ''">and BO.MATERIAL_CODE = #{MATERIAL_CODE}</if>
            <if test="MATERIAL_NAME != null and MATERIAL_NAME != ''">and BO.MATERIAL_NAME LIKE '%' || #{MATERIAL_NAME}
                || '%'
            </if>
            <if test="PRODUCT_SNCODE != null and PRODUCT_SNCODE != ''">and PO.PRODUCT_SNCODE LIKE '%' ||
                #{PRODUCT_SNCODE} || '%'
            </if>
            <if test="BOX_CODE != null and BOX_CODE != ''">and PO.BOX_CODE = #{BOX_CODE}</if>
            <if test="beginBeginTime != null  and beginBeginTime != '' and endBeginTime != null  and endBeginTime != ''">
                AND TO_CHAR(PO.PRODUCT_SCANTIME, 'YYYY-MM-DD HH24:MI:SS') BETWEEN #{beginBeginTime} AND #{endBeginTime}
            </if>
            <if test="isSample != null and isSample == 1 ">
                AND SUBSTR(PO.PRODUCT_SNCODE, -4, 1) = 'A'
            </if>
            <if test="isSample != null and isSample == 2 ">
                AND SUBSTR(PO.PRODUCT_SNCODE, -4, 1) != 'A'
            </if>
            <if test="isDowngrade != null and isDowngrade == 1 ">
                AND KA.BAR_CODE IS NOT NULL
            </if>
            <if test="isDowngrade != null and isDowngrade == 2 ">
                AND KA.BAR_CODE IS NULL
            </if>
        </where>
    </select>

    <select id="productTraceabilityDetailList" resultType="java.util.HashMap">
        SELECT RQI.BAR_CODE,
               PL.EXECUTION_SORT,
               PL.PRODUCT_LINE_CODE,
               PL.PRODUCT_LINE_NAME,
               RQI.TREATMENT_MEASURE,
               RQI.PROCESS_RESULT,
               RQI.INSPECTOR_TIME,
               U.NICK_NAME USER_NAME
        FROM PRODUCT_OFFLINE PO
                 LEFT JOIN CODE_BINDING CB ON PO.BOX_CODE = CB.BOX_CODE
                 JOIN REPORT_QUALITY_INSPECTION RQI ON ((RQI.BAR_CODE = PO.BOX_CODE) OR (RQI.BAR_CODE = CB.LINER_CODE))
                 LEFT JOIN BASE_PRODUCTLINE PL on RQI.STATION_CODE = PL.PRODUCT_LINE_CODE
                 LEFT join Z_SYS_USER U on U.USER_NAME = RQI.INSPECTOR_CODE
        WHERE PO.BOX_CODE = #{BOX_CODE}
        GROUP BY RQI.BAR_CODE, PL.EXECUTION_SORT, PL.PRODUCT_LINE_CODE, PL.PRODUCT_LINE_NAME, RQI.TREATMENT_MEASURE,
                 RQI.PROCESS_RESULT, RQI.INSPECTOR_TIME, U.NICK_NAME
        ORDER BY PL.EXECUTION_SORT, RQI.INSPECTOR_TIME
    </select>

    <select id="boxTraceabilityReport" resultType="com.aucma.report.domain.BoxTraceabilityReport"
            parameterType="java.util.HashMap">
        SELECT ZSD.ORDER_CODE,
        ZSD.SALEORDER_CODE,
        ZSD.SALEORDER_LINENUMBER,
        ZSD.MATERIAL_CODE,
        ZSD.MATERIAL_MODEL,
        ZSD.ORDER_AMOUNT,
        SUM(ZSD.BEFORE_NUMBER) BEFORE_NUMBER,
        SUM(ZSD.SCAN_NUMBER) SCAN_NUMBER,
        SUM(ZSD.BEFORE_NUMBER) - SUM(ZSD.SCAN_NUMBER) DIFF_NUMBER,
        SUM(ZSD.SCRAP_NUMBER) SCRAP_NUMBER
        FROM (SELECT BO.ORDER_CODE,
        BO.SALEORDER_CODE,
        BO.SALEORDER_LINENUMBER,
        BO.MATERIAL_CODE,
        BM.MATERIAL_SPECIFICATIONS MATERIAL_MODEL,
        OM.BARCODE_CODE,
        BO.ORDER_AMOUNT,
        COUNT(*) BEFORE_NUMBER,
        MAX(CASE WHEN OL.BOX_CODE IS NULL THEN 0 ELSE 1 END) SCAN_NUMBER,
        MAX(CASE WHEN BF.BAR_CODE IS NULL THEN 0 ELSE 1 END) SCRAP_NUMBER
        FROM BASE_ORDERINFO BO
        JOIN BASE_MATERIALINFO BM ON BM.MATERIAL_CODE = BO.MATERIAL_CODE AND bm.DISPO IN ('100')
        JOIN (SELECT OI.ORDER_CODE, OI.WORK_CENTER_CODE, BC.MATERIAL_CODE, IE.BARCODE_CODE, MAX(IE.IN_STORE_TIME)
        IN_STORE_TIME
        FROM RECORD_INSTORE IE
        JOIN PRINT_BARCODE BC ON BC.MATERIAL_BARCODE = IE.BARCODE_CODE
        JOIN BASE_ORDERINFO OI ON OI.ORDER_CODE = BC.ORDER_CODE
        JOIN BASE_PRODUCTLINE PL ON PL.WORK_CENTER_CODE = OI.WORK_CENTER_CODE
        WHERE IE.STORE_CODE = 'PQK-001'
        <if test="productLineCode != null and productLineCode != ''">AND PL.PRODUCT_LINE_CODE = #{productLineCode}</if>
        <if test="beginBeginTime != null  and beginBeginTime != '' and endBeginTime != null  and endBeginTime != ''">
            AND TO_CHAR(IE.IN_STORE_TIME, 'YYYY-MM-DD HH24:MI:SS') BETWEEN #{beginBeginTime} AND #{endBeginTime}
        </if>
        <if test="productOrderNo != null and productOrderNo != ''">and BC.ORDER_CODE = #{productOrderNo}</if>
        GROUP BY OI.ORDER_CODE, OI.WORK_CENTER_CODE, BC.MATERIAL_CODE, IE.BARCODE_CODE) OM ON OM.ORDER_CODE =
        BO.ORDER_CODE
        LEFT JOIN PRODUCT_OFFLINE OL ON OL.BOX_CODE = OM.BARCODE_CODE
        LEFT JOIN (SELECT BAR_CODE, SUM(SCRAP_NUMBER) SCRAP_NUMBER
        FROM (SELECT QI.BAR_CODE,
        COUNT(*) SCRAP_NUMBER
        FROM REPORT_QUALITY_INSPECTION QI
        WHERE QI.PROCESS_RESULT = '报废重做'
        GROUP BY QI.BAR_CODE)
        GROUP BY BAR_CODE) BF ON BF.BAR_CODE = OM.BARCODE_CODE
        <where>
            <if test="productCode != null and productCode != ''">and BO.MATERIAL_CODE = #{productCode}</if>
            <if test="productModel != null and productModel != ''">and BM.MATERIAL_SPECIFICATIONS LIKE '%' ||
                #{productModel}
                || '%'
            </if>
        </where>
        GROUP BY BO.ORDER_CODE, BO.SALEORDER_CODE, BO.SALEORDER_LINENUMBER, BO.MATERIAL_CODE,
        BM.MATERIAL_SPECIFICATIONS,
        BO.ORDER_AMOUNT, OM.BARCODE_CODE) ZSD
        GROUP BY ZSD.ORDER_CODE, ZSD.SALEORDER_CODE, ZSD.SALEORDER_LINENUMBER, ZSD.MATERIAL_CODE,
        ZSD.MATERIAL_MODEL, ZSD.ORDER_AMOUNT
    </select>

    <select id="boxTraceabilityDetailReport" resultType="com.aucma.report.domain.BoxTraceabilityDetailReport"
            parameterType="java.util.HashMap">
        SELECT SD.ORDER_CODE,
        SD.SALEORDER_CODE,
        SD.SALEORDER_LINENUMBER,
        SD.MATERIAL_CODE,
        SD.MATERIAL_MODEL,
        SD.BARCODE_CODE BOX_CODE,
        SD.ORDER_AMOUNT,
        SD.BEFORE_NUMBER,
        SD.SCAN_NUMBER,
        CASE WHEN SD.SCRAP_NUMBER = 0 THEN '否' ELSE '是' END SCRAP_FLAG,
        SD.IN_STORE_TIME,
        SD.EXECUTION_SORT,
        PL.PRODUCT_LINE_NAME SCAN_SPOT
        FROM (SELECT BO.ORDER_CODE,
        BO.SALEORDER_CODE,
        BO.SALEORDER_LINENUMBER,
        OM.MATERIAL_CODE,
        BM.MATERIAL_SPECIFICATIONS AS MATERIAL_MODEL,
        OM.BARCODE_CODE,
        OM.IN_STORE_TIME,
        BO.ORDER_AMOUNT,
        COUNT(*) AS BEFORE_NUMBER,
        MAX(CASE WHEN OL.BOX_CODE IS NULL THEN 0 ELSE 1 END) AS SCAN_NUMBER,
        MAX(CASE WHEN QI.BAR_CODE IS NULL THEN 0 ELSE 1 END) AS SCRAP_NUMBER,
        MAX(PL.EXECUTION_SORT) EXECUTION_SORT
        FROM BASE_ORDERINFO BO
        JOIN BASE_MATERIALINFO BM
        ON BM.MATERIAL_CODE = BO.MATERIAL_CODE AND bm.DISPO IN ('100')
        JOIN (SELECT OI.ORDER_CODE,
        OI.WORK_CENTER_CODE,
        BC.MATERIAL_CODE,
        IE.BARCODE_CODE,
        MAX(IE.IN_STORE_TIME) IN_STORE_TIME
        FROM RECORD_INSTORE IE
        JOIN PRINT_BARCODE BC
        ON BC.MATERIAL_BARCODE = IE.BARCODE_CODE
        JOIN BASE_ORDERINFO OI ON OI.ORDER_CODE = BC.ORDER_CODE
        JOIN BASE_PRODUCTLINE PL ON PL.WORK_CENTER_CODE = OI.WORK_CENTER_CODE
        WHERE IE.STORE_CODE = 'PQK-001'
        <if test="productLineCode != null and productLineCode != ''">AND PL.PRODUCT_LINE_CODE = #{productLineCode}</if>
        <if test="beginBeginTime != null  and beginBeginTime != '' and endBeginTime != null  and endBeginTime != ''">
            AND TO_CHAR(IE.IN_STORE_TIME, 'YYYY-MM-DD HH24:MI:SS') BETWEEN #{beginBeginTime} AND #{endBeginTime}
        </if>
        <if test="productOrderNo != null and productOrderNo != ''">and BC.ORDER_CODE = #{productOrderNo}</if>
        <if test="orderCode != null and orderCode != ''">and BC.ORDER_CODE = #{orderCode}</if>
        GROUP BY OI.ORDER_CODE, OI.WORK_CENTER_CODE, BC.MATERIAL_CODE,
        IE.BARCODE_CODE) OM
        ON OM.ORDER_CODE = BO.ORDER_CODE AND OM.WORK_CENTER_CODE = BO.WORK_CENTER_CODE
        LEFT JOIN PRODUCT_OFFLINE OL ON OL.BOX_CODE = OM.BARCODE_CODE
        LEFT JOIN REPORT_QUALITY_INSPECTION QI
        ON QI.PROCESS_RESULT = '报废重做' AND QI.BAR_CODE = OM.BARCODE_CODE
        LEFT JOIN MATERIAL_COMPLETION MC
        ON MC.MATERIAL_BARCODE = OM.BARCODE_CODE
        LEFT JOIN BASE_PRODUCTLINE PL ON PL.PRODUCT_LINE_CODE = MC.STATION_NAME
        WHERE OL.BOX_CODE IS NULL
        <if test="productCode != null and productCode != ''">and BO.MATERIAL_CODE = #{productCode}</if>
        <if test="productModel != null and productModel != ''">and BM.MATERIAL_SPECIFICATIONS LIKE '%' ||
            #{productModel}
            || '%'
        </if>
        GROUP BY BO.ORDER_CODE, BO.SALEORDER_CODE, BO.SALEORDER_LINENUMBER, OM.MATERIAL_CODE,
        BM.MATERIAL_SPECIFICATIONS,
        BO.ORDER_AMOUNT, OM.BARCODE_CODE, OM.IN_STORE_TIME) SD
        LEFT JOIN BASE_PRODUCTLINE PL ON PL.EXECUTION_SORT = SD.EXECUTION_SORT
        ORDER BY PL.EXECUTION_SORT
    </select>
    <select id="repairRateReportList" resultType="com.aucma.report.domain.RepairRateReport"
            parameterType="java.util.HashMap">
        SELECT VPO.PRODUCT_SCANTIME INSPECTOR_TIME,
        NVL(RQI.QUALITY_SUM, 0) QUALITY_SUM,
        VPO.OFF_LINE_NUM,
        CASE
        WHEN NVL(OFF_LINE_NUM, 0) = 0 THEN '0.00'
        ELSE TO_CHAR(ROUND(NVL(RQI.QUALITY_SUM, 0) / NVL(OFF_LINE_NUM, 1) * 100, 2), 'FM99990.00') END ||
        '%'                     REPAIR_RATE,
        TARGET
        FROM (SELECT INSPECTOR_TIME, COUNT(*) QUALITY_SUM
              FROM (
                       SELECT TO_CHAR(RQI.INSPECTOR_TIME, 'YYYY-MM-DD') INSPECTOR_TIME, RQI.BAR_CODE
                       FROM REPORT_QUALITY_INSPECTION RQI
                       WHERE RQI.TREATMENT_MEASURE = '1'
        <if test="stationCodeList != null and stationCodeList != ''">
            AND RQI.STATION_CODE IN
            <foreach collection="stationCodeList" item="stationCode" open="(" separator="," close=")">
                #{stationCode}
            </foreach>
        </if>
        <if test="leakFlag != null">
            AND RQI.QUALITY_DEFECT_NAME LIKE '%漏%'
        </if>
        <if test="beginBeginTime != null  and beginBeginTime != '' and endBeginTime != null  and endBeginTime != ''">
            AND TO_CHAR(RQI.INSPECTOR_TIME, 'YYYY-MM-DD') BETWEEN #{beginBeginTime} AND #{endBeginTime}
        </if>
                       GROUP BY TO_CHAR(RQI.INSPECTOR_TIME, 'YYYY-MM-DD'), RQI.BAR_CODE
                   )
              GROUP BY INSPECTOR_TIME) RQI
        RIGHT JOIN (
            SELECT PRODUCT_SCANTIME, COUNT(*) OFF_LINE_NUM
            FROM (
        <if test="PRODUCT_LINE_CODE != null and PRODUCT_LINE_CODE != 'MF_01'">
                     SELECT TO_CHAR(VPO.PRODUCT_SCANTIME, 'YYYY-MM-DD') PRODUCT_SCANTIME,
                            VPO.BOX_CODE
                     FROM PRODUCT_OFFLINE VPO
                     WHERE VPO.BOX_CODE IS NOT NULL
                     AND VPO.PRODUCT_LINE_CODE = #{PRODUCT_LINE_CODE}
        <if test="beginBeginTime != null  and beginBeginTime != '' and endBeginTime != null  and endBeginTime != ''">
            AND TO_CHAR(VPO.PRODUCT_SCANTIME, 'YYYY-MM-DD') BETWEEN #{beginBeginTime} AND #{endBeginTime}
        </if>
                     GROUP BY TO_CHAR(VPO.PRODUCT_SCANTIME, 'YYYY-MM-DD'), VPO.BOX_CODE
        </if>
        <if test="PRODUCT_LINE_CODE != null and PRODUCT_LINE_CODE == 'MF_01'">
            SELECT TO_CHAR(RQI.INSPECTOR_TIME, 'YYYY-MM-DD') PRODUCT_SCANTIME, RQI.BAR_CODE BOX_CODE
            FROM REPORT_QUALITY_INSPECTION RQI
            WHERE RQI.STATION_CODE = '6303'
            <if test="beginBeginTime != null  and beginBeginTime != '' and endBeginTime != null  and endBeginTime != ''">
                AND TO_CHAR(RQI.INSPECTOR_TIME, 'YYYY-MM-DD') BETWEEN #{beginBeginTime} AND #{endBeginTime}
            </if>
            GROUP BY TO_CHAR(RQI.INSPECTOR_TIME, 'YYYY-MM-DD'), RQI.BAR_CODE
        </if>
        )
            GROUP BY PRODUCT_SCANTIME) VPO
                           ON PRODUCT_SCANTIME = RQI.INSPECTOR_TIME
                 CROSS JOIN (SELECT TO_CHAR(CUSTOM_DATA) TARGET
                             FROM BASE_CUSTOM_DATA
                             WHERE CUSTOM_CODE = 'REPAIR_RATE_' || #{PRODUCT_LINE_CODE}) TARGET
        ORDER BY VPO.PRODUCT_SCANTIME
    </select>

    <select id="boxTurnoverTraceabilityReportList" resultType="com.aucma.report.domain.BoxTurnoverTraceabilityReport"
            parameterType="java.util.HashMap">
        SELECT PL.PRODUCT_LINE_CODE,
        PL.PRODUCT_LINE_NAME,
        BO.ORDER_CODE,
        BO.SALEORDER_CODE,
        BO.SALEORDER_LINENUMBER,
        BO.MATERIAL_CODE,
        BO.MATERIAL_NAME,
        PO.PRODUCT_SNCODE,
        PB.MATERIAL_BARCODE BOX_CODE,
        PO.PRODUCT_SCANTIME,
        PB.PRINT_TIME,
        CB.LINER_CODE
        FROM PRINT_BARCODE PB
        LEFT JOIN BASE_ORDERINFO BO ON BO.ORDER_CODE = PB.ORDER_CODE
        LEFT JOIN BASE_PRODUCTLINE PL ON PL.WORK_CENTER_CODE = BO.WORK_CENTER_CODE
        LEFT JOIN PRODUCT_OFFLINE PO ON PB.MATERIAL_BARCODE = PO.BOX_CODE
        LEFT JOIN CODE_BINDING CB ON CB.BOX_CODE = PB.MATERIAL_BARCODE
        <where>
            PB.PRINT_BARTYPE = 1
            <if test="PRODUCT_LINE_CODE != null and PRODUCT_LINE_CODE != ''">and PL.PRODUCT_LINE_CODE = #{PRODUCT_LINE_CODE}
            </if>
            <if test="ORDER_CODE != null and ORDER_CODE != ''">and BO.ORDER_CODE = #{ORDER_CODE}</if>
            <if test="MATERIAL_CODE != null and MATERIAL_CODE != ''">and BO.MATERIAL_CODE = #{MATERIAL_CODE}</if>
            <if test="MATERIAL_NAME != null and MATERIAL_NAME != ''">and BO.MATERIAL_NAME LIKE '%' || #{MATERIAL_NAME}
                || '%'
            </if>
            <if test="PRODUCT_SNCODE != null and PRODUCT_SNCODE != ''">and PO.PRODUCT_SNCODE LIKE '%' ||
                #{PRODUCT_SNCODE} || '%'
            </if>
            <if test="BOX_CODE != null and BOX_CODE != ''">and PB.MATERIAL_BARCODE = #{BOX_CODE}</if>
            <if test="beginBeginTime != null  and beginBeginTime != '' and endBeginTime != null  and endBeginTime != ''">
                AND TO_CHAR(PB.PRINT_TIME, 'YYYY-MM-DD HH24:MI:SS') BETWEEN #{beginBeginTime} AND #{endBeginTime}
            </if>
        </where>
       ORDER BY PB.PRINT_TIME DESC
    </select>
    <select id="boxTurnoverTraceabilityDetailReportList"
            resultType="com.aucma.report.domain.BoxTurnoverTraceabilityDetailReport"
            parameterType="java.util.HashMap">
        SELECT PL.PRODUCT_LINE_CODE,
               PL.PRODUCT_LINE_NAME,
               BO.ORDER_CODE,
               BO.SALEORDER_CODE,
               BO.SALEORDER_LINENUMBER,
               BO.MATERIAL_CODE     PRODUCT_CODE,
               BO.MATERIAL_NAME     PRODUCT_NAME,
               PO.PRODUCT_SNCODE,
               MC.MATERIAL_BARCODE  BOX_CODE,
               PB.PRINT_TIME,
               BM.MATERIAL_CODE,
               BM.MATERIAL_NAME,
               ST.PRODUCT_LINE_CODE STATION_CODE,
               ST.PRODUCT_LINE_NAME STATION_NAME,
               MC.COMPLETE_DATE
        FROM MATERIAL_COMPLETION MC
                 LEFT JOIN PRINT_BARCODE PB ON PB.MATERIAL_BARCODE = MC.MATERIAL_BARCODE
                 LEFT JOIN BASE_MATERIALINFO BM ON BM.MATERIAL_CODE = PB.MATERIAL_CODE
                 LEFT JOIN BASE_PRODUCTLINE ST on MC.STATION_NAME = ST.PRODUCT_LINE_CODE
                 LEFT JOIN BASE_ORDERINFO BO ON BO.ORDER_CODE = PB.ORDER_CODE
                 LEFT JOIN BASE_PRODUCTLINE PL on BO.WORK_CENTER_CODE = PL.WORK_CENTER_CODE
                 LEFT JOIN PRODUCT_OFFLINE PO ON PO.BOX_CODE = PB.MATERIAL_BARCODE
        WHERE MC.MATERIAL_BARCODE = #{BOX_CODE}
        ORDER BY MC.COMPLETE_DATE
    </select>



    <select id="WIPInquiryDetailReportList" resultType="com.aucma.report.domain.WIPInquiryDetailReport"
            parameterType="java.util.HashMap">
                SELECT B2.PRODUCT_LINE_CODE,
                B2.PRODUCT_LINE_NAME,
                SD.ORDER_CODE,
                SD.MATERIAL_CODE,
                SD.MATERIAL_NAME,
                BO.MATERIAL_CODE     PRODUCT_CODE,
                BO.MATERIAL_NAME     PRODUCT_NAME,
                SD.MATERIAL_BARCODE,
                ST.PRODUCT_LINE_NAME STATION_NAME,
                SD.COMPLETE_DATE
                FROM (
                SELECT PB.ORDER_CODE,
                BM.MATERIAL_CODE,
                BM.MATERIAL_NAME,
                VMC.MATERIAL_BARCODE,
                MAX(BE.EXECUTION_SORT)                               EXECUTION_SORT,
                TO_CHAR(MAX(COMPLETE_DATE), 'YYYY-MM-DD HH24:MI:SS') COMPLETE_DATE
                FROM MATERIAL_COMPLETION VMC
                JOIN RECORD_INSTORE IE ON IE.STORE_CODE = 'PQK-001' AND VMC.MATERIAL_BARCODE = IE.BARCODE_CODE
                LEFT JOIN BASE_PRODUCTLINE BE ON BE.PRODUCT_LINE_CODE = VMC.STATION_NAME
                LEFT JOIN PRINT_BARCODE PB
                ON PRINT_BARTYPE = 1 AND VMC.MATERIAL_BARCODE = PB.MATERIAL_BARCODE
                LEFT JOIN BASE_MATERIALINFO BM ON BM.MATERIAL_CODE = PB.MATERIAL_CODE
                LEFT JOIN PRODUCT_OFFLINE PO ON PO.BOX_CODE = PB.MATERIAL_BARCODE
                WHERE PB.MATERIAL_BARCODE IS NOT NULL
                AND PO.BOX_CODE IS NULL
                --   AND VMC.COMPLETE_DATE > (SYSDATE - 7)
                <if test="beginStationCode != null  and beginStationCode != ''">
                    AND BE.EXECUTION_SORT >= #{beginStationCode}
                </if>
                <if test="endStationCode != null  and endStationCode != ''">
                    AND #{endStationCode} > BE.EXECUTION_SORT
                </if>
                GROUP BY PB.ORDER_CODE, BM.MATERIAL_CODE, BM.MATERIAL_NAME, VMC.MATERIAL_BARCODE
                ) SD
                LEFT JOIN BASE_ORDERINFO BO ON BO.ORDER_CODE = SD.ORDER_CODE
                LEFT JOIN BASE_PRODUCTLINE B2 ON B2.WORK_CENTER_CODE = BO.WORK_CENTER_CODE
                LEFT JOIN BASE_PRODUCTLINE ST ON ST.EXECUTION_SORT = SD.EXECUTION_SORT
                AND B2.PRODUCT_LINE_CODE = #{productLineCode}
                    WHERE BO.ORDER_AMOUNT != BO.COMPLETE_AMOUNT
                    <if test="productLineCode != null and productLineCode != ''">
            </if>
            <if test="ORDER_CODE != null  and ORDER_CODE != ''">
                and SD.ORDER_CODE = #{ORDER_CODE}
            </if>
            <if test="PRODUCT_CODE != null  and PRODUCT_CODE != ''">
                and BO.MATERIAL_CODE = #{PRODUCT_CODE}
            </if>
            <if test="PRODUCT_NAME != null  and PRODUCT_NAME != ''">
                and BO.MATERIAL_NAME like concat(concat('%', #{PRODUCT_NAME}), '%')
            </if>
        ORDER BY SD.COMPLETE_DATE
    </select>

    <select id="downgradeProportionReportList" resultType="com.aucma.report.domain.DowngradeProportionReport"
        parameterType="java.util.HashMap">
        WITH DT AS (SELECT #{timeSub} TIMESUB FROM DUAL)
        SELECT SUBSTR(VPO.PRODUCT_SCANTIME, 1, DT.TIMESUB) INSPECTOR_TIME,
               SUM(NVL(RQI.QUALITY_SUM, 0))                QUALITY_SUM,
               SUM(VPO.OFF_LINE_NUM) OFF_LINE_NUM,
               NVL(TO_CHAR(ROUND(SUM(NVL(QUALITY_SUM, 0)) / SUM(NVL(OFF_LINE_NUM, 0)) * 100, 2), 'FM99990.00'), '0.00') ||
               '%'                                         REPAIR_RATE,
               TARGET
        FROM (SELECT PRODUCT_SCANTIME, COUNT(*) OFF_LINE_NUM
              FROM (SELECT TO_CHAR(VPO.PRODUCT_SCANTIME, 'YYYY-MM-DD') PRODUCT_SCANTIME, VPO.BOX_CODE
                    FROM PRODUCT_OFFLINE VPO
                    WHERE VPO.BOX_CODE IS NOT NULL
        <if test="PRODUCT_LINE_CODE != null  and PRODUCT_LINE_CODE != ''">
            AND VPO.PRODUCT_LINE_CODE = #{PRODUCT_LINE_CODE}
        </if>
        <if test="beginBeginTime != null  and beginBeginTime != '' and endBeginTime != null  and endBeginTime != ''">
            AND TO_CHAR(VPO.PRODUCT_SCANTIME, 'YYYY-MM-DD') BETWEEN #{beginBeginTime} AND #{endBeginTime}
        </if>
                    GROUP BY TO_CHAR(VPO.PRODUCT_SCANTIME, 'YYYY-MM-DD'), VPO.BOX_CODE)
              GROUP BY PRODUCT_SCANTIME) VPO
                 LEFT JOIN (SELECT INSPECTOR_TIME, NVL(COUNT(*), 0) QUALITY_SUM
                            FROM (SELECT TO_CHAR(RQI.INSPECTOR_TIME, 'YYYY-MM-DD') INSPECTOR_TIME, RQI.BAR_CODE
        FROM REPORT_QUALITY_INSPECTION RQI
        LEFT JOIN BASE_PRODUCTLINE BP on RQI.STATION_CODE = BP.PRODUCT_LINE_CODE
        <if test="alarmType != null and alarmType == 1 ">
            WHERE RQI.PROCESS_RESULT = 'KA'
        </if>
        <if test="alarmType != null and alarmType == 2 ">
            WHERE RQI.PROCESS_RESULT = '报废重做'
        </if>
        <if test="PRODUCT_LINE_CODE != null  and PRODUCT_LINE_CODE != ''">
            AND BP.PARENT_ID= #{PRODUCT_LINE_CODE}
        </if>
                                  GROUP BY TO_CHAR(RQI.INSPECTOR_TIME, 'YYYY-MM-DD'), RQI.BAR_CODE)
                            GROUP BY INSPECTOR_TIME) RQI ON VPO.PRODUCT_SCANTIME = RQI.INSPECTOR_TIME
                 CROSS JOIN (SELECT TO_CHAR(CUSTOM_DATA) || '%' TARGET
                             FROM BASE_CUSTOM_DATA
                             WHERE CUSTOM_CODE = 'DOWNGRADE_RATE_' || 'CX_02')
                 CROSS JOIN DT
        GROUP BY SUBSTR(VPO.PRODUCT_SCANTIME, 1, DT.TIMESUB), TARGET
        ORDER BY INSPECTOR_TIME
    </select>
    <select id="adverseRecordYearOnYearList" resultType="com.aucma.report.domain.AdverseRecordYearOnYearReport"
            parameterType="java.util.HashMap">
        WITH YEART AS (SELECT #{year} - 1 LASTYEAR, #{year} THISYEAR FROM DUAL)
        SELECT BL.PRODUCT_LINE_CODE,
        BL.PRODUCT_LINE_NAME,
        BPS.PROCESS_CODE,
        BPS.PROCESS_NAME,
        SUM(ZSD.QUALITY_SUM)                                                                               QUALITY_SUM,
        SUM(ZSD.OFF_LINE_NUM)                                                                              OFF_LINE_NUM,
        TO_CHAR(ROUND(NVL(SUM(ZSD.QUALITY_SUM), 0) / SUM(ZSD.OFF_LINE_NUM) * 100, 2), 'FM99990.00') || '%' REPAIR_RATE,
        ZSD.INSPECTOR_MONTH
        FROM (
        SELECT SD.STATION_CODE,
        NVL(SUM(SD.ALARM_FLAG), 0) QUALITY_SUM,
        NVL(COUNT(*), 0)           OFF_LINE_NUM,
        SD.INSPECTOR_MONTH
        FROM (
        SELECT RQI.BAR_CODE,
        RQI.STATION_CODE,
        MAX(CASE WHEN RQI.TREATMENT_MEASURE = '1' THEN 1 ELSE 0 END) ALARM_FLAG,
        TO_CHAR(RQI.INSPECTOR_TIME, 'YYYY-MM')                       INSPECTOR_MONTH
        FROM REPORT_QUALITY_INSPECTION RQI
        CROSS JOIN YEART
        WHERE RQI.INSPECTOR_TIME BETWEEN to_date(YEART.LASTYEAR || '-01-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss')
        AND to_date(YEART.THISYEAR || '-12-31 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
        GROUP BY RQI.BAR_CODE, RQI.STATION_CODE, TO_CHAR(RQI.INSPECTOR_TIME, 'YYYY-MM')
        ) SD
        GROUP BY SD.STATION_CODE, SD.INSPECTOR_MONTH
        ) ZSD
        LEFT JOIN BASE_PROCESS_STATION BPS
        ON BPS.PROCESS_TYPE = 2 AND BPS.PARENT_ID LIKE '%' || ZSD.STATION_CODE || '%'
        LEFT JOIN BASE_PRODUCTLINE BL ON BL.PRODUCT_LINE_CODE = BPS.PRODUCT_LINE_CODE
        <if test="productionLine != null and productionLine != ''">
            WHERE BL.PRODUCT_LINE_CODE = #{productionLine}
        </if>
        GROUP BY BL.PRODUCT_LINE_CODE, BL.PRODUCT_LINE_NAME, BPS.PROCESS_CODE, BPS.PROCESS_NAME, ZSD.INSPECTOR_MONTH
        ORDER BY PROCESS_CODE, INSPECTOR_MONTH
    </select>

    <select id="highFaultList" resultType="com.aucma.report.domain.HighFaultReport" parameterType="java.util.HashMap">
        SELECT ZSD.FACTORY_NAME,
        ZSD.PRODUCT_LINE_CODE,
        ZSD.PRODUCT_LINE_NAME,
        ZSD.MATERIAL_MODEL,
        COUNT(*) Q_SUM
        FROM (SELECT BF.FACTORY_NAME,
        PL2.PRODUCT_LINE_CODE,
        PL2.PRODUCT_LINE_NAME,
        GET_MATERIAL_TYPE(RQI.MATERIAL_NAME) MATERIAL_MODEL,
        RQI.BAR_CODE
        FROM REPORT_QUALITY_INSPECTION RQI
        LEFT JOIN BASE_PRODUCTLINE PL on RQI.STATION_CODE = PL.PRODUCT_LINE_CODE
        LEFT JOIN BASE_PRODUCTLINE PL2 on PL2.PRODUCT_LINE_CODE = PL.PARENT_ID
        LEFT JOIN BASE_FACTORY BF on BF.FACTORY_CODE = PL.PLANT_CODE
        LEFT JOIN BASE_QUALITY_INSPECTION_ITEM QI on QI.QUALITY_DEFECT_CODE = RQI.QUALITY_DEFECT_CODE
        WHERE RQI.TREATMENT_MEASURE = '1'
        <if test="beginBeginTime != null  and beginBeginTime != '' and endBeginTime != null  and endBeginTime != ''">
            AND TO_CHAR(RQI.INSPECTOR_TIME, 'YYYY-MM-DD') BETWEEN #{beginBeginTime} AND #{endBeginTime}
        </if>
        <if test="FACTORY_CODE != null and FACTORY_CODE != ''">
            AND BF.FACTORY_CODE = #{FACTORY_CODE}
        </if>
        <if test="MATERIAL_MODEL != null and MATERIAL_MODEL != ''">
            AND RQI.MATERIAL_NAME like '%' || #{MATERIAL_MODEL} || '%'
        </if>
        <if test="PRODUCT_LINE_CODE != null  and PRODUCT_LINE_CODE != ''">
            AND PL2.PRODUCT_LINE_CODE = #{PRODUCT_LINE_CODE}
        </if>
        GROUP BY BF.FACTORY_NAME, PL2.PRODUCT_LINE_CODE, PL2.PRODUCT_LINE_NAME,
        GET_MATERIAL_TYPE(RQI.MATERIAL_NAME), RQI.BAR_CODE
        ) ZSD
        GROUP BY ZSD.FACTORY_NAME, ZSD.PRODUCT_LINE_CODE, ZSD.PRODUCT_LINE_NAME, ZSD.MATERIAL_MODEL
        ORDER BY ZSD.PRODUCT_LINE_CODE, Q_SUM DESC
    </select>

    <select id="weldLeakRateList" resultType="com.aucma.report.domain.WeldLeakRateReport" parameterType="java.util.HashMap">
        SELECT WEEK_NUMBER,
               WEEK_START,
               WEEK_END,
               NVL(COUNT(*), 0)                                                 Q_SUM,
               NVL(SUM(LEAK_SUM), 0)                                            LEAK_SUM,
               TO_CHAR(ROUND(SUM(LEAK_SUM) / COUNT(*) * 100, 2), 'FM99990.00')  REPAIR_RATE,
               CASE WHEN 'CX_02' = #{PRODUCT_LINE_CODE} THEN '二线' ELSE '一线' END PRODUCT_LINE_NAME
        FROM (
                 SELECT TO_NUMBER(COLUMN_A)                                             WEEK_NUMBER,
                        COLUMN_B                                                        WEEK_START,
                        COLUMN_C                                                        WEEK_END,
                        BAR_CODE,
                        MAX(CASE WHEN QUALITY_DEFECT_NAME LIKE '%漏%' THEN 1 ELSE 0 END) LEAK_SUM
                 FROM (SELECT COLUMN_A, COLUMN_B, COLUMN_C
                       FROM TABLE (GET_YEAR_WEEK_TIME(${year}))) WEE
                          LEFT JOIN (
                     SELECT R.BAR_CODE, R.INSPECTOR_TIME, R.QUALITY_DEFECT_NAME
                     FROM REPORT_QUALITY_INSPECTION R
                              LEFT JOIN BASE_PRODUCTLINE BP on R.STATION_CODE = BP.PRODUCT_LINE_CODE
                              LEFT JOIN BASE_PRODUCTLINE P2 on P2.PRODUCT_LINE_CODE = BP.PARENT_ID
                     WHERE P2.PRODUCT_LINE_CODE = #{PRODUCT_LINE_CODE}
                 ) RQI ON RQI.BAR_CODE LIKE 'B%' AND
                          TO_CHAR(RQI.INSPECTOR_TIME, 'YYYY-MM-DD HH24:MI:SS') > WEE.COLUMN_B AND
                          TO_CHAR(RQI.INSPECTOR_TIME, 'YYYY-MM-DD HH24:MI:SS') &lt;
                              = WEE.COLUMN_C
                 GROUP BY COLUMN_A, COLUMN_B, COLUMN_C, BAR_CODE
             )
        GROUP BY WEEK_NUMBER, WEEK_START, WEEK_END
        ORDER BY WEEK_NUMBER
    </select>

    <select id="weldLeakRateListMonth"  resultType="com.aucma.report.domain.WeldLeakRateReport" parameterType="java.util.HashMap">
        SELECT WEEK_NUMBER,
        WEEK_START,
        WEEK_END,
        NVL(COUNT(*), 0)                                                Q_SUM,
        NVL(SUM(LEAK_SUM), 0)                                           LEAK_SUM,
        TO_CHAR(ROUND(SUM(LEAK_SUM) / COUNT(*) * 100, 2), 'FM99990.00') REPAIR_RATE,
        CASE WHEN 'CX_02' = #{PRODUCT_LINE_CODE} THEN '二线' ELSE '一线' END             PRODUCT_LINE_NAME
        FROM (
        SELECT TO_NUMBER(COLUMN_A)                                             WEEK_NUMBER,
        COLUMN_B                                                        WEEK_START,
        COLUMN_C                                                        WEEK_END,
        BAR_CODE,
        MAX(CASE WHEN QUALITY_DEFECT_NAME LIKE '%漏%' THEN 1 ELSE 0 END) LEAK_SUM
        FROM (SELECT COLUMN_A, COLUMN_B, COLUMN_C
        FROM TABLE (GET_YEAR_MONTH_TIME(${year}))) WEE
        LEFT JOIN (
        SELECT R.BAR_CODE, R.INSPECTOR_TIME, R.QUALITY_DEFECT_NAME
        FROM REPORT_QUALITY_INSPECTION R
        LEFT JOIN BASE_PRODUCTLINE BP on R.STATION_CODE = BP.PRODUCT_LINE_CODE
        LEFT JOIN BASE_PRODUCTLINE P2 on P2.PRODUCT_LINE_CODE = BP.PARENT_ID
            WHERE P2.PRODUCT_LINE_CODE = #{PRODUCT_LINE_CODE}
        ) RQI ON RQI.BAR_CODE LIKE 'B%' AND
        TO_CHAR(RQI.INSPECTOR_TIME, 'YYYY-MM-DD HH24:MI:SS') > WEE.COLUMN_B AND
        TO_CHAR(RQI.INSPECTOR_TIME, 'YYYY-MM-DD HH24:MI:SS') &lt;= WEE.COLUMN_C
        GROUP BY COLUMN_A, COLUMN_B, COLUMN_C, BAR_CODE
        )
        GROUP BY WEEK_NUMBER, WEEK_START, WEEK_END
        ORDER BY WEEK_NUMBER
    </select>

    <select id="boxTraceabilityDetailReportUpdate" parameterType="java.util.HashMap"
            resultType="com.aucma.report.domain.BoxTraceabilityDetailReport"
    >
        SELECT ORDER_CODE,
               MATERIAL_CODE,
               BOX_CODE,
               MATERIAL_MODEL,
               MAX(code1000) code1000,
               MAX(code1001) code1001,
               MAX(code1002) code1002,
               MAX(code1004) code1004,
               MAX(code1005) code1005,
               MAX(code1006) code1006,
               MAX(code1007) code1007,
               MAX(code1008) code1008,
               MAX(code1009) code1009,
               MAX(code1010) code1010,
               MAX(code1011) code1011,
               MAX(code1012) code1012,
               MAX(code1020) code1020,
               MAX(code1105) code1105,
               MAX(code1109) code1109,
               MAX(code2001) code2001,
               MAX(code2002) code2002,
               MAX(code2003) code2003,
               MAX(code2005) code2005,
               MAX(code2006) code2006,
               MAX(code2007) code2007,
               MAX(code2008) code2008,
               MAX(code2009) code2009,
               MAX(code2010) code2010,
               MAX(code2011) code2011,
               MAX(code2012) code2012,
               MAX(code2013) code2013,
               MAX(code2014) code2014,
               MAX(code2015) code2015,
               MAX(code2016) code2016,
               MAX(code2020) code2020
        FROM (
                 SELECT BO.ORDER_CODE,
                        BO.SALEORDER_CODE,
                        BO.SALEORDER_LINENUMBER,
                        OM.MATERIAL_CODE,
                        BM.MATERIAL_SPECIFICATIONS                           AS MATERIAL_MODEL,
                        OM.BARCODE_CODE BOX_CODE,
                        OM.IN_STORE_TIME,
                        BO.ORDER_AMOUNT,
                        COUNT(*)                                             AS BEFORE_NUMBER,
                        MAX(CASE WHEN OL.BOX_CODE IS NULL THEN 0 ELSE 1 END) AS SCAN_NUMBER,
                        MAX(CASE WHEN QI.BAR_CODE IS NULL THEN 0 ELSE 1 END) AS SCRAP_NUMBER,
                        TO_CHAR(MC.COMPLETE_DATE, 'YYYY-MM-DD HH24:MI:SS')  COMPLETE_DATE,
                        PL.EXECUTION_SORT                                       EXECUTION_SORT,
                        PL.PRODUCT_LINE_CODE,
                        PL.PRODUCT_LINE_NAME
                 FROM BASE_ORDERINFO BO
                          JOIN BASE_MATERIALINFO BM
                               ON BM.MATERIAL_CODE = BO.MATERIAL_CODE AND bm.DISPO IN ('100')
                          JOIN (SELECT OI.ORDER_CODE,
                                       OI.WORK_CENTER_CODE,
                                       BC.MATERIAL_CODE,
                                       IE.BARCODE_CODE,
                                       MAX(IE.IN_STORE_TIME) IN_STORE_TIME
                                FROM RECORD_INSTORE IE
                                         JOIN PRINT_BARCODE BC
                                              ON BC.MATERIAL_BARCODE = IE.BARCODE_CODE
                                         JOIN BASE_ORDERINFO OI ON OI.ORDER_CODE = BC.ORDER_CODE
                                         JOIN BASE_PRODUCTLINE PL ON PL.WORK_CENTER_CODE = OI.WORK_CENTER_CODE
                                WHERE IE.STORE_CODE = 'PQK-001'
        <if test="productLineCode != null and productLineCode != ''">AND PL.PRODUCT_LINE_CODE = #{productLineCode}</if>
        <if test="beginBeginTime != null  and beginBeginTime != '' and endBeginTime != null  and endBeginTime != ''">
            AND TO_CHAR(IE.IN_STORE_TIME, 'YYYY-MM-DD HH24:MI:SS') BETWEEN #{beginBeginTime} AND #{endBeginTime}
        </if>
        <if test="productOrderNo != null and productOrderNo != ''">and BC.ORDER_CODE = #{productOrderNo}</if>
        <if test="orderCode != null and orderCode != ''">and BC.ORDER_CODE = #{orderCode}</if>
                                GROUP BY OI.ORDER_CODE, OI.WORK_CENTER_CODE, BC.MATERIAL_CODE,
                                         IE.BARCODE_CODE) OM
                               ON OM.ORDER_CODE = BO.ORDER_CODE AND OM.WORK_CENTER_CODE = BO.WORK_CENTER_CODE
                          LEFT JOIN PRODUCT_OFFLINE OL ON OL.BOX_CODE = OM.BARCODE_CODE
                          LEFT JOIN REPORT_QUALITY_INSPECTION QI ON QI.PROCESS_RESULT = '报废重做' AND QI.BAR_CODE = OM.BARCODE_CODE
                          LEFT JOIN MATERIAL_COMPLETION MC ON MC.MATERIAL_BARCODE = OM.BARCODE_CODE
                          LEFT JOIN BASE_PRODUCTLINE PL ON PL.PRODUCT_LINE_CODE = MC.STATION_NAME
                 WHERE OL.BOX_CODE IS NULL
        <if test="productCode != null and productCode != ''">and BO.MATERIAL_CODE = #{productCode}</if>
        <if test="productModel != null and productModel != ''">and BM.MATERIAL_SPECIFICATIONS LIKE '%' ||
            #{productModel}
            || '%'
        </if>
        GROUP BY BO.ORDER_CODE, BO.SALEORDER_CODE, BO.SALEORDER_LINENUMBER, OM.MATERIAL_CODE, BM.MATERIAL_SPECIFICATIONS,
        BO.ORDER_AMOUNT, OM.BARCODE_CODE, MC.COMPLETE_DATE, OM.IN_STORE_TIME, PL.EXECUTION_SORT,
        PL.PRODUCT_LINE_CODE,
        PL.PRODUCT_LINE_NAME)
        PIVOT (MAX(COMPLETE_DATE) FOR PRODUCT_LINE_CODE IN (
        '1000' as code1000,
        '1001' as code1001,
        '1002' as code1002,
        '1004' as code1004,
        '1005' as code1005,
        '1006' as code1006,
        '1007' as code1007,
        '1008' as code1008,
        '1009' as code1009,
        '1010' as code1010,
        '1011' as code1011,
        '1012' as code1012,
        '1020' as code1020,
        '1105' as code1105,
        '1109' as code1109,
        '2001' as code2001,
        '2002' as code2002,
        '2003' as code2003,
        '2005' as code2005,
        '2006' as code2006,
        '2007' as code2007,
        '2008' as code2008,
        '2009' as code2009,
        '2010' as code2010,
        '2011' as code2011,
        '2012' as code2012,
        '2013' as code2013,
        '2014' as code2014,
        '2015' as code2015,
        '2016' as code2016,
        '2020' as code2020
        ))
        GROUP BY ORDER_CODE, MATERIAL_CODE, BOX_CODE, MATERIAL_MODEL
        ORDER BY BOX_CODE
   </select>

    <select id="repairRateReportListWeek" resultType="com.aucma.report.domain.RepairRateReport"
            parameterType="java.util.HashMap">
        WITH temp_table AS (
        SELECT RQI.INSPECTOR_TIME,
        RQI.QUALITY_SUM,
        VPO.OFF_LINE_NUM,
        CASE
        WHEN NVL(OFF_LINE_NUM, 0) = 0 THEN '0.00'
        ELSE TO_CHAR(ROUND(QUALITY_SUM / NVL(OFF_LINE_NUM, 0) * 100, 2), 'FM99990.00') || '%' END REPAIR_RATE,
        TARGET
        FROM (
        SELECT INSPECTOR_TIME, COUNT(*) QUALITY_SUM
        FROM (
        SELECT TO_CHAR(RQI.INSPECTOR_TIME, 'YYYY-MM-DD') INSPECTOR_TIME, RQI.BAR_CODE
        FROM REPORT_QUALITY_INSPECTION RQI
        WHERE RQI.TREATMENT_MEASURE = '1'
        <if test="stationCodeList != null and stationCodeList != ''">
            AND RQI.STATION_CODE IN
            <foreach collection="stationCodeList" item="stationCode" open="(" separator="," close=")">
                #{stationCode}
            </foreach>
        </if>
        <if test="leakFlag != null">
            AND RQI.QUALITY_DEFECT_NAME LIKE '%漏%'
        </if>
        <if test="beginBeginTime != null  and beginBeginTime != '' and endBeginTime != null  and endBeginTime != ''">
            AND TO_CHAR(RQI.INSPECTOR_TIME, 'YYYY-MM-DD') BETWEEN #{beginBeginTime} AND #{endBeginTime}
        </if>
        GROUP BY TO_CHAR(RQI.INSPECTOR_TIME, 'YYYY-MM-DD'), RQI.BAR_CODE
        )
        GROUP BY INSPECTOR_TIME
        ) RQI
        LEFT JOIN (
        SELECT PRODUCT_SCANTIME, COUNT(*) OFF_LINE_NUM
        FROM (
        <if test="PRODUCT_LINE_CODE != null and PRODUCT_LINE_CODE != 'MF_01'">
            SELECT TO_CHAR(VPO.PRODUCT_SCANTIME, 'YYYY-MM-DD') PRODUCT_SCANTIME,
            VPO.BOX_CODE
            FROM PRODUCT_OFFLINE VPO
            WHERE VPO.BOX_CODE IS NOT NULL
            AND VPO.PRODUCT_LINE_CODE = #{PRODUCT_LINE_CODE}
            <if test="beginBeginTime != null  and beginBeginTime != '' and endBeginTime != null  and endBeginTime != ''">
                AND TO_CHAR(VPO.PRODUCT_SCANTIME, 'YYYY-MM-DD') BETWEEN #{beginBeginTime} AND #{endBeginTime}
            </if>
            GROUP BY TO_CHAR(VPO.PRODUCT_SCANTIME, 'YYYY-MM-DD'), VPO.BOX_CODE
        </if>
        <if test="PRODUCT_LINE_CODE != null and PRODUCT_LINE_CODE == 'MF_01'">
            SELECT TO_CHAR(RQI.INSPECTOR_TIME, 'YYYY-MM-DD') PRODUCT_SCANTIME, RQI.BAR_CODE BOX_CODE
            FROM REPORT_QUALITY_INSPECTION RQI
            WHERE RQI.STATION_CODE = '6303'
            <if test="beginBeginTime != null  and beginBeginTime != '' and endBeginTime != null  and endBeginTime != ''">
                AND TO_CHAR(RQI.INSPECTOR_TIME, 'YYYY-MM-DD') BETWEEN #{beginBeginTime} AND #{endBeginTime}
            </if>
            GROUP BY TO_CHAR(RQI.INSPECTOR_TIME, 'YYYY-MM-DD'), RQI.BAR_CODE
        </if>
        )
        GROUP BY PRODUCT_SCANTIME
        ) VPO
        ON PRODUCT_SCANTIME = RQI.INSPECTOR_TIME
        CROSS JOIN (SELECT TO_CHAR(CUSTOM_DATA) TARGET
        FROM BASE_CUSTOM_DATA
        WHERE CUSTOM_CODE = 'REPAIR_RATE_' || 'CX_02') TARGET
        )
        SELECT COLUMN_A ,INSPECTOR_TIME,NVL(QUALITY_SUM, 0) QUALITY_SUM, NVL(OFF_LINE_NUM, 0) OFF_LINE_NUM,REPAIR_RATE,TARGET
        FROM TABLE (GET_YEAR_WEEK_TIME(${year})) WEE
        LEFT JOIN temp_table A ON A.INSPECTOR_TIME BETWEEN WEE.COLUMN_B AND COLUMN_C
        WHERE INSPECTOR_TIME IS NOT NULL
    </select>
    <select id="repairRateReportListMONTH" resultType="com.aucma.report.domain.RepairRateReport"
            parameterType="java.util.HashMap">
        WITH temp_table AS (
        SELECT RQI.INSPECTOR_TIME,
        RQI.QUALITY_SUM,
        VPO.OFF_LINE_NUM,
        CASE
        WHEN NVL(OFF_LINE_NUM, 0) = 0 THEN '0.00'
        ELSE TO_CHAR(ROUND(QUALITY_SUM / NVL(OFF_LINE_NUM, 0) * 100, 2), 'FM99990.00') || '%' END REPAIR_RATE,
        TARGET
        FROM (
        SELECT INSPECTOR_TIME, COUNT(*) QUALITY_SUM
        FROM (
        SELECT TO_CHAR(RQI.INSPECTOR_TIME, 'YYYY-MM-DD') INSPECTOR_TIME, RQI.BAR_CODE
        FROM REPORT_QUALITY_INSPECTION RQI
        WHERE RQI.TREATMENT_MEASURE = '1'
        <if test="stationCodeList != null and stationCodeList != ''">
            AND RQI.STATION_CODE IN
            <foreach collection="stationCodeList" item="stationCode" open="(" separator="," close=")">
                #{stationCode}
            </foreach>
        </if>
        <if test="leakFlag != null">
            AND RQI.QUALITY_DEFECT_NAME LIKE '%漏%'
        </if>
        <if test="beginBeginTime != null  and beginBeginTime != '' and endBeginTime != null  and endBeginTime != ''">
            AND TO_CHAR(RQI.INSPECTOR_TIME, 'YYYY-MM-DD') BETWEEN #{beginBeginTime} AND #{endBeginTime}
        </if>
        GROUP BY TO_CHAR(RQI.INSPECTOR_TIME, 'YYYY-MM-DD'), RQI.BAR_CODE
        )
        GROUP BY INSPECTOR_TIME
        ) RQI
        LEFT JOIN (
        SELECT PRODUCT_SCANTIME, COUNT(*) OFF_LINE_NUM
        FROM (
        <if test="PRODUCT_LINE_CODE != null and PRODUCT_LINE_CODE != 'MF_01'">
            SELECT TO_CHAR(VPO.PRODUCT_SCANTIME, 'YYYY-MM-DD') PRODUCT_SCANTIME,
            VPO.BOX_CODE
            FROM PRODUCT_OFFLINE VPO
            WHERE VPO.BOX_CODE IS NOT NULL
            AND VPO.PRODUCT_LINE_CODE = #{PRODUCT_LINE_CODE}
            <if test="beginBeginTime != null  and beginBeginTime != '' and endBeginTime != null  and endBeginTime != ''">
                AND TO_CHAR(VPO.PRODUCT_SCANTIME, 'YYYY-MM-DD') BETWEEN #{beginBeginTime} AND #{endBeginTime}
            </if>
            GROUP BY TO_CHAR(VPO.PRODUCT_SCANTIME, 'YYYY-MM-DD'), VPO.BOX_CODE
        </if>
        <if test="PRODUCT_LINE_CODE != null and PRODUCT_LINE_CODE == 'MF_01'">
            SELECT TO_CHAR(RQI.INSPECTOR_TIME, 'YYYY-MM-DD') PRODUCT_SCANTIME, RQI.BAR_CODE BOX_CODE
            FROM REPORT_QUALITY_INSPECTION RQI
            WHERE RQI.STATION_CODE = '6303'
            <if test="beginBeginTime != null  and beginBeginTime != '' and endBeginTime != null  and endBeginTime != ''">
                AND TO_CHAR(RQI.INSPECTOR_TIME, 'YYYY-MM-DD') BETWEEN #{beginBeginTime} AND #{endBeginTime}
            </if>
            GROUP BY TO_CHAR(RQI.INSPECTOR_TIME, 'YYYY-MM-DD'), RQI.BAR_CODE
        </if>
        )
        GROUP BY PRODUCT_SCANTIME
        ) VPO
        ON PRODUCT_SCANTIME = RQI.INSPECTOR_TIME
        CROSS JOIN (SELECT TO_CHAR(CUSTOM_DATA) TARGET
        FROM BASE_CUSTOM_DATA
        WHERE CUSTOM_CODE = 'REPAIR_RATE_' || 'CX_02') TARGET
        )
        SELECT COLUMN_A ,INSPECTOR_TIME,NVL(QUALITY_SUM, 0) QUALITY_SUM, NVL(OFF_LINE_NUM, 0) OFF_LINE_NUM,REPAIR_RATE,TARGET
        FROM TABLE (GET_YEAR_MONTH_TIME(${year})) WEE
        LEFT JOIN temp_table A ON A.INSPECTOR_TIME BETWEEN WEE.COLUMN_B AND COLUMN_C
        WHERE INSPECTOR_TIME IS NOT NULL

    </select>

    <select id="codeBandingReportList" resultType="com.aucma.report.domain.codeBanding"
            parameterType="java.util.HashMap">
    SELECT BP.PRODUCT_LINE_CODE,                           -- 产线编号
        BP.PRODUCT_LINE_NAME,                           -- 产线名称
        BO.ORDER_CODE,                                  --SAP订单编号
        CB.BOX_CODE,                                    -- 箱体码
        GET_MATERIAL_TYPE(P1.MATERIAL_NAME) BOX_NAME,   -- 箱体型号
        CB.LINER_CODE,                                  -- 内胆码
        GET_MATERIAL_TYPE(P2.MATERIAL_NAME) LINER_NAME, -- 内胆型号
        CB.RECORD_TIME1,                                -- 壳胆绑定时间
        CB.PRODUCT_CODE,                                -- 产品SN码
        CB.RECORD_TIME2                                 -- 产品SN码绑定时间
        FROM CODE_BINDING CB
         LEFT JOIN PRINT_BARCODE P1 ON P1.MATERIAL_BARCODE = CB.BOX_CODE
         LEFT JOIN BASE_ORDERINFO BO ON BO.ORDER_CODE = P1.ORDER_CODE
         LEFT JOIN BASE_PRODUCTLINE BP on BO.WORK_CENTER_CODE = BP.WORK_CENTER_CODE
         LEFT JOIN PRINT_BARCODE P2 ON P2.MATERIAL_BARCODE = CB.LINER_CODE
        <where>
        <if test="productLineCode != null  and productLineCode != ''">
            AND BP.PRODUCT_LINE_CODE = #{productLineCode}
        </if>
        <if test="boxCode != null  and boxCode != ''">
            AND CB.BOX_CODE = #{boxCode}
        </if>
        <if test="orderCode != null  and orderCode != ''">
            AND BO.ORDER_CODE = #{orderCode}
        </if>
        <if test="BOX_NAME != null  and BOX_NAME != ''">
            AND P1.MATERIAL_NAME like '%' || #{BOX_NAME} || '%'
        </if>
        <if test="linerCode != null  and linerCode != ''">
            AND CB.LINER_CODE = #{linerCode}
        </if>
        <if test="recordBeginTime!=null  and recordBeginTime != '' and recordEndTime != null  and recordEndTime != ''">
            AND TO_CHAR(CB.RECORD_TIME1, 'YYYY-MM-DD HH-mm-ss') BETWEEN #{recordBeginTime} AND #{recordEndTime}
        </if>
        </where>
        ORDER BY RECORD_TIME1 DESC

    </select>
<!--    <select id="materialReportList" resultType="com.aucma.report.domain.MaterialReport" parameterType="java.util.HashMap">-->
<!--        SELECT-->
<!--        bp.PRODUCT_LINE_NAME AS product_line_name,-->
<!--        mc.MATERIAL_CODE AS material_code,-->
<!--        mc.MATERIAL_NAME AS material_name,-->
<!--        SUM(CASE WHEN mc.STATION_NAME = '1008' THEN 1 ELSE 0 END) AS mes_sn_binding_count,-->
<!--        SUM(CASE WHEN mc.STATION_NAME = '1009' THEN 1 ELSE 0 END) AS finished_product_scan_count,-->
<!--        SUM(CASE WHEN mc.STATION_NAME = '1010' THEN 1 ELSE 0 END) AS finished_product_piling_count-->
<!--        FROM-->
<!--        MATERIAL_COMPLETION mc-->
<!--        LEFT JOIN-->
<!--        BASE_PRODUCTLINE bp ON mc.PRODUCT_LINE_CODE = bp.PRODUCT_LINE_CODE-->
<!--        LEFT JOIN-->
<!--        BASE_MATERIALINFO m ON mc.MATERIAL_CODE = m.MATERIAL_CODE-->
<!--        <where>-->
<!--            <if test="productLineName != null and productLineName != ''">-->
<!--                AND bp.PRODUCT_LINE_NAME = #{productLineName}-->
<!--            </if>-->
<!--            <if test="recordBeginTime != null and recordBeginTime != '' and recordEndTime != null and recordEndTime != ''">-->
<!--                AND TO_CHAR(mc.COMPLETE_DATE, 'YYYY-MM-DD HH-mm-ss') BETWEEN #{recordBeginTime} AND #{recordEndTime}-->
<!--            </if>-->
<!--        </where>-->
<!--        GROUP BY-->
<!--        bp.PRODUCT_LINE_NAME, mc.MATERIAL_CODE, mc.MATERIAL_NAME-->
<!--        ORDER BY-->
<!--        bp.PRODUCT_LINE_NAME, mc.MATERIAL_CODE-->
<!--    </select>-->
    <select id="materialReportList" resultType="com.aucma.report.domain.MaterialReport" parameterType="java.util.HashMap">
        SELECT
        bp.PRODUCT_LINE_NAME  AS product_line_name,
        mc.MATERIAL_CODE AS material_code,
        mc.MATERIAL_NAME AS material_name,
        SUM(CASE
        WHEN mc.STATION_NAME IN ('1008', '1108') THEN 1
        ELSE 0
        END) AS mes_sn_binding_count,
        SUM(CASE
        WHEN mc.STATION_NAME IN ('1009', '1109') THEN 1
        ELSE 0
        END) AS finished_product_scan_count,
        SUM(CASE
        WHEN mc.STATION_NAME IN ('1010', '1110') THEN 1
        ELSE 0
        END) AS finished_product_piling_count
        FROM
        MATERIAL_COMPLETION mc
        LEFT JOIN
        BASE_PRODUCTLINE bp ON mc.PRODUCT_LINE_CODE = bp.PRODUCT_LINE_CODE
        LEFT JOIN
        BASE_MATERIALINFO m ON mc.MATERIAL_CODE = m.MATERIAL_CODE
        <where>
            <if test="productLineName != null and productLineName != ''">
                AND (
                (mc.STATION_NAME IN ('1008', '1009', '1010') AND #{productLineName} = '二线')
                OR (mc.STATION_NAME IN ('1108', '1109', '1110') AND #{productLineName} = '一线')
                )
            </if>
            <if test="recordBeginTime != null and recordBeginTime != '' and recordEndTime != null and recordEndTime != ''">
                AND TO_CHAR(mc.COMPLETE_DATE, 'YYYY-MM-DD HH24:MI:SS') BETWEEN #{recordBeginTime} AND #{recordEndTime}
            </if>
        </where>
        GROUP BY
        bp.PRODUCT_LINE_NAME,
        mc.MATERIAL_CODE,
        mc.MATERIAL_NAME
        ORDER BY
        mc.MATERIAL_CODE
    </select>
</mapper>
