<?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.foreverwin.mesnac.common.mapper.ReportDataMapper">

    <select id="findInspectionTask" resultType="java.util.HashMap" parameterType="java.util.HashMap">
        SELECT 	WT.DESCRIPTION  WORK_CENTER_DESCRIPTION, C2.VALUE ITEM_NUMBER, C3.VALUE PRODUCT_MODEL,IM.ITEM ITEM, IT.DESCRIPTION ITEM_DESCRIPTION,
                ZT.SFC, ZT.OPERATION, OT.DESCRIPTION OPERATION_DESCRIPTION, ZT.RESRCE, RS.DESCRIPTION RESOURCE_DESCRIPTION, ZT.TASK_NO, ZT.CATEGORY,
                ZT."RESULT", ZT.CREATE_USER, ZNU.FULL_NAME, ZT.MODIFIED_DATE_TIME, ROWNUM SEQ,
        CASE WHEN ZT."RESULT" = 'OK' THEN N'合格' WHEN ZT."RESULT" = 'NG' THEN N'不合格' ELSE N'--' END RESULT_DESC,
        CASE WHEN ZT.CATEGORY = 'S' THEN N'首检' WHEN ZT.CATEGORY = 'Z' THEN N'自检'
        WHEN ZT.CATEGORY = 'H' THEN N'互检' WHEN ZT.CATEGORY = 'P' THEN N'专检' ELSE N'--' END CATEGORY_DESC
        FROM Z_INSPECTION_TASK ZT
        LEFT JOIN WORK_CENTER WC ON WC.SITE = ZT.SITE AND WC.WORK_CENTER = ZT.WORK_CENTER
        LEFT JOIN WORK_CENTER_T WT ON WT.WORK_CENTER_BO = WC.HANDLE AND WT.LOCALE = 'zh'
        INNER JOIN SHOP_ORDER SO ON ZT.SITE = SO.SITE AND ZT.SHOP_ORDER = SO.SHOP_ORDER
        LEFT JOIN CUSTOM_FIELDS C1 ON C1.HANDLE = SO.HANDLE AND C1."ATTRIBUTE" = 'WORK_ORDER'
        LEFT JOIN CUSTOM_FIELDS C2 ON C2.HANDLE = SO.HANDLE AND C2."ATTRIBUTE" = 'ITEM_NUMBER'
        LEFT JOIN CUSTOM_FIELDS C3 ON C3.HANDLE = SO.HANDLE AND C3."ATTRIBUTE" = 'PRODUCT_MODEL'
        INNER JOIN ITEM IM ON IM.HANDLE = SO.ITEM_BO
        LEFT JOIN ITEM_T IT ON IT.ITEM_BO = IM.HANDLE AND IT.LOCALE = 'zh'
        INNER JOIN OPERATION OP ON OP.SITE = ZT.SITE AND OP.OPERATION = ZT.OPERATION AND OP.CURRENT_REVISION = 'true'
        LEFT JOIN OPERATION_T OT ON OT.OPERATION_BO = OP.HANDLE AND OT.LOCALE = 'zh'
        INNER JOIN RESRCE RS ON RS.SITE = ZT.SITE AND RS.RESRCE = ZT.RESRCE
        LEFT JOIN Z_NWA_USER ZNU ON ZNU.SITE = ZT.SITE AND ZNU.USER_NAME = ZT.CREATE_USER
        WHERE ZT.SITE = #{site}
        <if test="workCenter != null and workCenter != ''" >
            AND WC.WORK_CENTER = #{workCenter}
        </if>
        <if test="category != null and category != ''" >
            AND ZT.CATEGORY = #{category}
        </if>
        <if test="itemNumber != null and itemNumber != ''" >
            AND C2.VALUE LIKE '%'||#{itemNumber}||'%'
        </if>
        <if test="model != null and model != ''" >
            AND C3.VALUE LIKE '%'||#{model}||'%'
        </if>
        <if test="operation != null and operation != ''" >
            AND ZT.OPERATION = #{operation}
        </if>
        <if test="resrce != null and resrce != ''" >
            AND ZT.RESRCE = #{resrce}
        </if>
        <if test="result != null and result != ''" >
            AND ZT.RESULT = #{result}
        </if>
        <if test="startFromDate != null and startFromDate != ''" >
            AND ZT.MODIFIED_DATE_TIME >= TO_DATE(#{startFromDate}, 'YYYY-MM-DD') - 8/24
        </if>
        <if test="startToDate != null and startToDate != ''" >
            AND ZT.MODIFIED_DATE_TIME &lt;= TO_DATE(#{startToDate}|| '15:59:59', 'YYYY-MM-DD HH24:MI:SS')
        </if>
    </select>

    <!--设备负荷率报表-->
    <select id="findResourceLoadRateInfo" resultType="java.util.HashMap" parameterType="java.util.HashMap" >
        WITH
            TEMP AS (
        SELECT  ZSD.PLANNED_COMP_DATE ,ZSD.PLANNED_START_DATE ,ZSD.RESRCE
        FROM Z_SFC_DISPATCH ZSD WHERE ZSD.SITE = #{site}  AND ZSD.DISPATCH_STATUS IN ('START','COMPLETE','RELEASE') ),
            Z_REPORT_DATE_TIME AS (SELECT '1000' SITE ,TO_CHAR(TO_DATE(#{startFromDate},'YYYY-MM-DD') + ROWNUM -1, 'YYYY-MM-DD') DATE_TIME,
        TO_DATE(#{startFromDate} || '00:00:00','yyyy-mm-dd hh24:mi:ss') + rownum -1 AM_START_DATE_TIME,
        TO_DATE(#{startFromDate} || '04:00:00','yyyy-mm-dd hh24:mi:ss') + rownum -1 AM_END_DATE_TIME,
        TO_DATE(#{startFromDate} || '05:00:00','yyyy-mm-dd hh24:mi:ss') + rownum -1 PM_START_DATE_TIME ,
        TO_DATE(#{startFromDate} || '09:00:00','yyyy-mm-dd hh24:mi:ss') + rownum -1 PM_END_DATE_TIME
        FROM dual CONNECT BY rownum &lt;= to_date( #{startToDate}, 'yyyy-mm-dd') - to_date( #{startFromDate}, 'yyyy-mm-dd') + 1 ) ,
        RDT AS ( SELECT R.SITE,R.RESRCE , R.DESCRIPTION RESOURCE_DESCRIPTION, DATE_TIME, DECODE(CF.VALUE,NULL,0,CF.VALUE) CAPACITY_MAN_HOUR ,  WCA.WORK_CENTER CENTER ,
        WCTA.DESCRIPTION CENTER_DESCRIPTION , WCB.WORK_CENTER , WCTB.DESCRIPTION WORK_CENTER_DESCRIPTION ,RT.RESOURCE_TYPE ,RT.DESCRIPTION RESOURCE_TYPE_DESCRIPTION
        FROM  RESRCE R
        LEFT JOIN WORK_CENTER_MEMBER WCMA ON  WCMA.WORK_CENTER_OR_RESOURCE_GBO = R.HANDLE
        LEFT JOIN WORK_CENTER WCA ON WCA.HANDLE = WCMA.WORK_CENTER_BO
        LEFT JOIN WORK_CENTER_T WCTA ON WCTA.WORK_CENTER_BO = WCA.HANDLE AND WCTA.LOCALE = 'zh'
        LEFT JOIN WORK_CENTER_MEMBER WCMB ON WCMB.WORK_CENTER_OR_RESOURCE_GBO = WCMA.WORK_CENTER_BO
        LEFT JOIN WORK_CENTER WCB ON WCB.HANDLE = WCMB.WORK_CENTER_BO
        LEFT JOIN WORK_CENTER_T WCTB ON WCTB.WORK_CENTER_BO = WCB.HANDLE AND WCTB.LOCALE = 'zh'
        LEFT JOIN CUSTOM_FIELDS CF ON CF.HANDLE = R.HANDLE AND CF."ATTRIBUTE" = 'CAPACITY_MAN_HOUR'
        LEFT JOIN Z_REPORT_DATE_TIME  ON 1=1
        LEFT JOIN RESOURCE_TYPE_RESOURCE RTR ON  RTR.RESOURCE_BO = R.HANDLE
        LEFT JOIN RESOURCE_TYPE RT ON RT.HANDLE = RTR.RESOURCE_TYPE_BO
        WHERE R.SITE = #{site}
        <if test="center != null and center != ''" >
            AND WCA.WORK_CENTER = #{center}
        </if>
        <if test="workCenter != null and workCenter != ''" >
            AND WCB.WORK_CENTER = #{workCenter}
        </if>
        <if test="resrce != null and resrce != ''" >
            AND R.RESRCE = #{resrce}
        </if>
        <if test="resourceType != null and resourceType != ''" >
            AND RT.RESOURCE_TYPE = #{resourceType}
        </if> )
        SELECT T.*,T.RATE_DATA_INT || '%' RATE_DATA FROM
        (
        SELECT RDT.* ,  ROUND((SUM( (DECODE(A.CNT,NULL,0,A.CNT) + DECODE(B.CNT,NULL,0,B.CNT) + DECODE(C.CNT,NULL,0,C.CNT) + DECODE(D.CNT,NULL,0,D.CNT)
        + DECODE(E.CNT,NULL,0,E.CNT) + DECODE(F.CNT,NULL,0,F.CNT) + DECODE(G.CNT,NULL,0,G.CNT) + DECODE(H.CNT,NULL,0,H.CNT)
        + DECODE(I.CNT,NULL,0,I.CNT) + DECODE(J.CNT,NULL,0,J.CNT) ) + DECODE(K.CNT,NULL,0,K.CNT) + DECODE(L.CNT,NULL,0,L.CNT) ) * RDT.CAPACITY_MAN_HOUR / 8),4)   PLAN_HOUR
        ,CASE WHEN RDT.CAPACITY_MAN_HOUR = 0 THEN 0
        ELSE ROUND(SUM( ( DECODE(A.CNT,NULL,0,A.CNT) + DECODE(B.CNT,NULL,0,B.CNT) + DECODE(C.CNT,NULL,0,C.CNT) + DECODE(D.CNT,NULL,0,D.CNT)
        + DECODE(E.CNT,NULL,0,E.CNT) + DECODE(F.CNT,NULL,0,F.CNT) + DECODE(G.CNT,NULL,0,G.CNT) + DECODE(H.CNT,NULL,0,H.CNT)
        + DECODE(I.CNT,NULL,0,I.CNT) + DECODE(J.CNT,NULL,0,J.CNT) + DECODE(K.CNT,NULL,0,K.CNT) + DECODE(L.CNT,NULL,0,L.CNT)
        ) ) / 8 , 4) * 100
        END RATE_DATA_INT
        FROM
             RDT
        LEFT JOIN
        (SELECT  DATE_TIME ,RESRCE , COUNT(*) * 8 CNT  FROM Z_REPORT_DATE_TIME
        LEFT JOIN TEMP ON PLANNED_START_DATE &lt;= AM_START_DATE_TIME AND PLANNED_COMP_DATE &gt;= PM_END_DATE_TIME
        GROUP BY RESRCE , DATE_TIME ) A ON A.DATE_TIME = RDT.DATE_TIME   AND A.RESRCE = RDT.RESRCE
        LEFT JOIN
        (SELECT  DATE_TIME ,RESRCE , SUM( ROUND((PLANNED_COMP_DATE - AM_START_DATE_TIME)*24, 4) ) CNT FROM Z_REPORT_DATE_TIME
        LEFT JOIN TEMP ON PLANNED_START_DATE &lt;= AM_START_DATE_TIME AND PLANNED_COMP_DATE &gt;= AM_START_DATE_TIME AND PLANNED_COMP_DATE &lt;= AM_END_DATE_TIME
        GROUP BY RESRCE , DATE_TIME ) B ON B.DATE_TIME = RDT.DATE_TIME  AND B.RESRCE = RDT.RESRCE
        LEFT JOIN
        (SELECT  DATE_TIME ,RESRCE , COUNT(*)*4 CNT FROM Z_REPORT_DATE_TIME
        LEFT JOIN TEMP ON PLANNED_START_DATE &lt;= AM_START_DATE_TIME AND PLANNED_COMP_DATE &gt;= AM_END_DATE_TIME AND PLANNED_COMP_DATE &lt; PM_START_DATE_TIME
        GROUP BY RESRCE , DATE_TIME ) C ON C.DATE_TIME = RDT.DATE_TIME  AND C.RESRCE = RDT.RESRCE
        LEFT JOIN
        (SELECT  DATE_TIME ,RESRCE , SUM( ROUND((PLANNED_COMP_DATE - AM_START_DATE_TIME)*24 - 1 , 4) ) CNT FROM Z_REPORT_DATE_TIME
        LEFT JOIN TEMP ON PLANNED_START_DATE &lt;= AM_START_DATE_TIME AND PLANNED_COMP_DATE &gt;= PM_START_DATE_TIME AND PLANNED_COMP_DATE &lt;= PM_END_DATE_TIME
        GROUP BY RESRCE , DATE_TIME ) D ON D.DATE_TIME = RDT.DATE_TIME  AND D.RESRCE = RDT.RESRCE
        LEFT JOIN
        (SELECT  DATE_TIME ,RESRCE , SUM( ROUND((PLANNED_COMP_DATE - PLANNED_START_DATE)*24 , 4) ) CNT FROM Z_REPORT_DATE_TIME
        LEFT JOIN TEMP ON PLANNED_START_DATE &gt; AM_START_DATE_TIME AND PLANNED_COMP_DATE &lt;= AM_END_DATE_TIME
        GROUP BY RESRCE , DATE_TIME ) E ON E.DATE_TIME = RDT.DATE_TIME  AND E.RESRCE = RDT.RESRCE
        LEFT JOIN
        (SELECT  DATE_TIME ,RESRCE , SUM( ROUND((AM_END_DATE_TIME - PLANNED_START_DATE)*24 , 4) ) CNT FROM Z_REPORT_DATE_TIME
        LEFT JOIN TEMP ON PLANNED_START_DATE &gt; AM_START_DATE_TIME AND PLANNED_START_DATE &lt;= AM_END_DATE_TIME AND PLANNED_COMP_DATE &gt;= AM_END_DATE_TIME AND PLANNED_COMP_DATE &lt;= PM_START_DATE_TIME
        GROUP BY RESRCE , DATE_TIME ) F ON F.DATE_TIME = RDT.DATE_TIME  AND F.RESRCE = RDT.RESRCE
        LEFT JOIN
        (SELECT  DATE_TIME ,RESRCE , SUM( ROUND((PLANNED_COMP_DATE - PLANNED_START_DATE)*24 - 1 , 4) ) CNT FROM Z_REPORT_DATE_TIME
        LEFT JOIN TEMP ON PLANNED_START_DATE &gt; AM_START_DATE_TIME AND PLANNED_START_DATE &lt;= AM_END_DATE_TIME AND PLANNED_COMP_DATE &gt;= PM_START_DATE_TIME AND PLANNED_COMP_DATE &lt; PM_END_DATE_TIME
        GROUP BY RESRCE , DATE_TIME ) G ON G.DATE_TIME = RDT.DATE_TIME  AND G.RESRCE = RDT.RESRCE
        LEFT JOIN
        (SELECT  DATE_TIME ,RESRCE , SUM( ROUND((PM_END_DATE_TIME - PLANNED_START_DATE)*24 - 1 , 4) ) CNT FROM Z_REPORT_DATE_TIME
        LEFT JOIN TEMP ON PLANNED_START_DATE &gt; AM_START_DATE_TIME AND PLANNED_START_DATE &lt;= AM_END_DATE_TIME AND PLANNED_COMP_DATE &gt;= PM_END_DATE_TIME
        GROUP BY RESRCE , DATE_TIME ) H ON H.DATE_TIME = RDT.DATE_TIME  AND H.RESRCE = RDT.RESRCE
        LEFT JOIN
        (SELECT  DATE_TIME ,RESRCE , SUM( ROUND((PLANNED_COMP_DATE - PM_START_DATE_TIME)*24 , 4) ) CNT FROM Z_REPORT_DATE_TIME
        LEFT JOIN TEMP ON PLANNED_START_DATE &gt; AM_END_DATE_TIME AND PLANNED_START_DATE &lt;= PM_START_DATE_TIME AND PLANNED_COMP_DATE &gt;= PM_START_DATE_TIME AND PLANNED_COMP_DATE &lt; PM_END_DATE_TIME
        GROUP BY RESRCE , DATE_TIME ) I ON I.DATE_TIME = RDT.DATE_TIME  AND I.RESRCE = RDT.RESRCE
        LEFT JOIN
        (SELECT  DATE_TIME ,RESRCE , COUNT(*)*4 CNT FROM Z_REPORT_DATE_TIME
        LEFT JOIN TEMP ON PLANNED_START_DATE &gt; AM_END_DATE_TIME AND PLANNED_START_DATE &lt; PM_START_DATE_TIME AND PLANNED_COMP_DATE &gt; PM_END_DATE_TIME
        GROUP BY RESRCE , DATE_TIME ) J ON J.DATE_TIME = RDT.DATE_TIME  AND J.RESRCE = RDT.RESRCE
        LEFT JOIN
        (SELECT  DATE_TIME ,RESRCE , SUM( ROUND((PLANNED_COMP_DATE - PLANNED_START_DATE)*24 , 4) ) CNT FROM Z_REPORT_DATE_TIME
        LEFT JOIN TEMP ON PLANNED_START_DATE &gt; PM_START_DATE_TIME AND PLANNED_COMP_DATE &lt; PM_END_DATE_TIME
        GROUP BY RESRCE , DATE_TIME ) K ON K.DATE_TIME = RDT.DATE_TIME  AND K.RESRCE = RDT.RESRCE
        LEFT JOIN
        (SELECT  DATE_TIME ,RESRCE , SUM( ROUND((PM_END_DATE_TIME - PLANNED_START_DATE)*24 , 4) ) CNT FROM Z_REPORT_DATE_TIME
        LEFT JOIN TEMP ON PLANNED_START_DATE &gt; PM_START_DATE_TIME AND PLANNED_START_DATE &lt; PM_END_DATE_TIME AND PLANNED_COMP_DATE &gt;= PM_END_DATE_TIME
        GROUP BY RESRCE , DATE_TIME ) L ON L.DATE_TIME = RDT.DATE_TIME  AND L.RESRCE = RDT.RESRCE
        GROUP BY RDT.SITE,RDT.RESRCE, RDT.RESOURCE_DESCRIPTION, RDT.DATE_TIME ,RDT.CAPACITY_MAN_HOUR , RDT.CENTER ,RDT.CENTER_DESCRIPTION ,RDT.WORK_CENTER ,RDT.WORK_CENTER_DESCRIPTION ,RDT.RESOURCE_TYPE ,RDT.RESOURCE_TYPE_DESCRIPTION
        ORDER BY RDT.WORK_CENTER ,RDT.RESRCE, RDT.DATE_TIME ) T
        WHERE T.SITE = #{site}
        <if test="startRate != null and startRate != ''">
            AND T.RATE_DATA_INT &gt;= #{startRate}
        </if>
        <if test="endRate != null and endRate != ''">
            AND T.RATE_DATA_INT &lt;= #{endRate}
        </if>
    </select>

    <!--设备类型负荷率报表-->
    <select id="findResourceTypeLoadRateInfo" resultType="java.util.HashMap" parameterType="java.util.HashMap" >
        WITH TEMP AS (
        SELECT  ZSD.PLANNED_COMP_DATE ,ZSD.PLANNED_START_DATE ,ZSD.RESRCE
        FROM Z_SFC_DISPATCH ZSD WHERE ZSD.SITE = #{site}  AND ZSD.DISPATCH_STATUS != 'CANCEL'
            AND ZSD.PLANNED_COMP_DATE IS NOT NULL  AND ZSD.PLANNED_START_DATE IS NOT NULL
        ),
        Z_REPORT_DATE_TIME AS (SELECT '1000' SITE ,TO_CHAR(TO_DATE(#{startFromDate},'YYYY-MM-DD') + ROWNUM -1, 'YYYY-MM-DD') DATE_TIME,
        TO_DATE(#{startFromDate} || '00:00:00','yyyy-mm-dd hh24:mi:ss') + rownum -1 AM_START_DATE_TIME,
        TO_DATE(#{startFromDate} || '04:00:00','yyyy-mm-dd hh24:mi:ss') + rownum -1 AM_END_DATE_TIME,
        TO_DATE(#{startFromDate} || '05:00:00','yyyy-mm-dd hh24:mi:ss') + rownum -1 PM_START_DATE_TIME ,
        TO_DATE(#{startFromDate} || '09:00:00','yyyy-mm-dd hh24:mi:ss') + rownum -1 PM_END_DATE_TIME
        FROM dual CONNECT BY rownum &lt;= to_date( #{startToDate}, 'yyyy-mm-dd') - to_date( #{startFromDate}, 'yyyy-mm-dd') + 1) ,
        RDT AS ( SELECT R.SITE,R.RESRCE , R.DESCRIPTION RESOURCE_DESCRIPTION, DATE_TIME, DECODE(CF.VALUE,NULL,0,CF.VALUE) CAPACITY_MAN_HOUR ,
        WCB.WORK_CENTER , WCTB.DESCRIPTION WORK_CENTER_DESCRIPTION ,RT.RESOURCE_TYPE ,RT.DESCRIPTION RESOURCE_TYPE_DESCRIPTION
        FROM  RESRCE R
        LEFT JOIN WORK_CENTER_MEMBER WCMA ON  WCMA.WORK_CENTER_OR_RESOURCE_GBO = R.HANDLE
        LEFT JOIN WORK_CENTER WCA ON WCA.HANDLE = WCMA.WORK_CENTER_BO
        LEFT JOIN WORK_CENTER_T WCTA ON WCTA.WORK_CENTER_BO = WCA.HANDLE AND WCTA.LOCALE = 'zh'
        LEFT JOIN WORK_CENTER_MEMBER WCMB ON WCMB.WORK_CENTER_OR_RESOURCE_GBO = WCMA.WORK_CENTER_BO
        LEFT JOIN WORK_CENTER WCB ON WCB.HANDLE = WCMB.WORK_CENTER_BO
        LEFT JOIN WORK_CENTER_T WCTB ON WCTB.WORK_CENTER_BO = WCB.HANDLE AND WCTB.LOCALE = 'zh'
        LEFT JOIN CUSTOM_FIELDS CF ON CF.HANDLE = R.HANDLE AND CF."ATTRIBUTE" = 'CAPACITY_MAN_HOUR'
        LEFT JOIN Z_REPORT_DATE_TIME  ON 1=1
        LEFT JOIN RESOURCE_TYPE_RESOURCE RTR ON  RTR.RESOURCE_BO = R.HANDLE
        LEFT JOIN RESOURCE_TYPE RT ON RT.HANDLE = RTR.RESOURCE_TYPE_BO
        WHERE R.SITE = #{site}
        <if test="workCenter != null and workCenter != ''" >
            AND WCB.WORK_CENTER = #{workCenter}
        </if>
        <if test="resourceType != null and resourceType != ''" >
            AND RT.RESOURCE_TYPE = #{resourceType}
        </if>)
        SELECT M.*,M.RATE_DATA_INT || '%' RATE_DATA FROM (
        SELECT T.SITE,T.RESOURCE_TYPE, T.RESOURCE_TYPE_DESCRIPTION, T.WORK_CENTER, T.WORK_CENTER_DESCRIPTION,T.DATE_TIME,
                ROUND(SUM(T.PLAN_HOUR) * SUM(T.CAPACITY_MAN_HOUR) / 8 ,4) PLAN_HOUR, SUM(T.CAPACITY_MAN_HOUR) CAPACITY_MAN_HOUR,
               CASE WHEN SUM(T.PLAN_HOUR) = 0 THEN 0 ELSE ROUND(SUM(T.PLAN_HOUR)/8,4)*100 END RATE_DATA_INT
            FROM
        (
        SELECT RDT.* , SUM( (DECODE(A.CNT,NULL,0,A.CNT) + DECODE(B.CNT,NULL,0,B.CNT) + DECODE(C.CNT,NULL,0,C.CNT) + DECODE(D.CNT,NULL,0,D.CNT)
        + DECODE(E.CNT,NULL,0,E.CNT) + DECODE(F.CNT,NULL,0,F.CNT) + DECODE(G.CNT,NULL,0,G.CNT) + DECODE(H.CNT,NULL,0,H.CNT)
        + DECODE(I.CNT,NULL,0,I.CNT) + DECODE(J.CNT,NULL,0,J.CNT) ) + DECODE(K.CNT,NULL,0,K.CNT) + DECODE(L.CNT,NULL,0,L.CNT) )  PLAN_HOUR
        FROM
             RDT
        LEFT JOIN
        (SELECT  DATE_TIME ,RESRCE , COUNT(*) * 8 CNT  FROM Z_REPORT_DATE_TIME
        LEFT JOIN TEMP ON PLANNED_START_DATE &lt;= AM_START_DATE_TIME AND PLANNED_COMP_DATE &gt;= PM_END_DATE_TIME
        GROUP BY RESRCE , DATE_TIME ) A ON A.DATE_TIME = RDT.DATE_TIME   AND A.RESRCE = RDT.RESRCE
        LEFT JOIN
        (SELECT  DATE_TIME ,RESRCE , SUM( ROUND((PLANNED_COMP_DATE - AM_START_DATE_TIME)*24, 4) ) CNT FROM Z_REPORT_DATE_TIME
        LEFT JOIN TEMP ON PLANNED_START_DATE &lt;= AM_START_DATE_TIME AND PLANNED_COMP_DATE &gt;= AM_START_DATE_TIME AND PLANNED_COMP_DATE &lt;= AM_END_DATE_TIME
        GROUP BY RESRCE , DATE_TIME ) B ON B.DATE_TIME = RDT.DATE_TIME  AND B.RESRCE = RDT.RESRCE
        LEFT JOIN
        (SELECT  DATE_TIME ,RESRCE , COUNT(*)*4 CNT FROM Z_REPORT_DATE_TIME
        LEFT JOIN TEMP ON PLANNED_START_DATE &lt;= AM_START_DATE_TIME AND PLANNED_COMP_DATE &gt;= AM_END_DATE_TIME AND PLANNED_COMP_DATE &lt; PM_START_DATE_TIME
        GROUP BY RESRCE , DATE_TIME ) C ON C.DATE_TIME = RDT.DATE_TIME  AND C.RESRCE = RDT.RESRCE
        LEFT JOIN
        (SELECT  DATE_TIME ,RESRCE , SUM( ROUND((PLANNED_COMP_DATE - AM_START_DATE_TIME)*24 - 1 , 4) ) CNT FROM Z_REPORT_DATE_TIME
        LEFT JOIN TEMP ON PLANNED_START_DATE &lt;= AM_START_DATE_TIME AND PLANNED_COMP_DATE &gt;= PM_START_DATE_TIME AND PLANNED_COMP_DATE &lt;= PM_END_DATE_TIME
        GROUP BY RESRCE , DATE_TIME ) D ON D.DATE_TIME = RDT.DATE_TIME  AND D.RESRCE = RDT.RESRCE
        LEFT JOIN
        (SELECT  DATE_TIME ,RESRCE , SUM( ROUND((PLANNED_COMP_DATE - PLANNED_START_DATE)*24 , 4) ) CNT FROM Z_REPORT_DATE_TIME
        LEFT JOIN TEMP ON PLANNED_START_DATE &gt; AM_START_DATE_TIME AND PLANNED_COMP_DATE &lt;= AM_END_DATE_TIME
        GROUP BY RESRCE , DATE_TIME ) E ON E.DATE_TIME = RDT.DATE_TIME  AND E.RESRCE = RDT.RESRCE
        LEFT JOIN
        (SELECT  DATE_TIME ,RESRCE , SUM( ROUND((AM_END_DATE_TIME - PLANNED_START_DATE)*24 , 4) ) CNT FROM Z_REPORT_DATE_TIME
        LEFT JOIN TEMP ON PLANNED_START_DATE &gt; AM_START_DATE_TIME AND PLANNED_START_DATE &lt;= AM_END_DATE_TIME AND PLANNED_COMP_DATE &gt;= AM_END_DATE_TIME AND PLANNED_COMP_DATE &lt;= PM_START_DATE_TIME
        GROUP BY RESRCE , DATE_TIME ) F ON F.DATE_TIME = RDT.DATE_TIME  AND F.RESRCE = RDT.RESRCE
        LEFT JOIN
        (SELECT  DATE_TIME ,RESRCE , SUM( ROUND((PLANNED_COMP_DATE - PLANNED_START_DATE)*24 - 1 , 4) ) CNT FROM Z_REPORT_DATE_TIME
        LEFT JOIN TEMP ON PLANNED_START_DATE &gt; AM_START_DATE_TIME AND PLANNED_START_DATE &lt;= AM_END_DATE_TIME AND PLANNED_COMP_DATE &gt;= PM_START_DATE_TIME AND PLANNED_COMP_DATE &lt; PM_END_DATE_TIME
        GROUP BY RESRCE , DATE_TIME ) G ON G.DATE_TIME = RDT.DATE_TIME  AND G.RESRCE = RDT.RESRCE
        LEFT JOIN
        (SELECT  DATE_TIME ,RESRCE , SUM( ROUND((PM_END_DATE_TIME - PLANNED_START_DATE)*24 - 1 , 4) ) CNT FROM Z_REPORT_DATE_TIME
        LEFT JOIN TEMP ON PLANNED_START_DATE &gt; AM_START_DATE_TIME AND PLANNED_START_DATE &lt;= AM_END_DATE_TIME AND PLANNED_COMP_DATE &gt;= PM_END_DATE_TIME
        GROUP BY RESRCE , DATE_TIME ) H ON H.DATE_TIME = RDT.DATE_TIME  AND H.RESRCE = RDT.RESRCE
        LEFT JOIN
        (SELECT  DATE_TIME ,RESRCE , SUM( ROUND((PLANNED_COMP_DATE - PM_START_DATE_TIME)*24 , 4) ) CNT FROM Z_REPORT_DATE_TIME
        LEFT JOIN TEMP ON PLANNED_START_DATE &gt; AM_END_DATE_TIME AND PLANNED_START_DATE &lt;= PM_START_DATE_TIME AND PLANNED_COMP_DATE &gt;= PM_START_DATE_TIME AND PLANNED_COMP_DATE &lt; PM_END_DATE_TIME
        GROUP BY RESRCE , DATE_TIME ) I ON I.DATE_TIME = RDT.DATE_TIME  AND I.RESRCE = RDT.RESRCE
        LEFT JOIN
        (SELECT  DATE_TIME ,RESRCE , COUNT(*)*4 CNT FROM Z_REPORT_DATE_TIME
        LEFT JOIN TEMP ON PLANNED_START_DATE &gt; AM_END_DATE_TIME AND PLANNED_START_DATE &lt; PM_START_DATE_TIME AND PLANNED_COMP_DATE &gt; PM_END_DATE_TIME
        GROUP BY RESRCE , DATE_TIME ) J ON J.DATE_TIME = RDT.DATE_TIME  AND J.RESRCE = RDT.RESRCE
        LEFT JOIN
        (SELECT  DATE_TIME ,RESRCE , SUM( ROUND((PLANNED_COMP_DATE - PLANNED_START_DATE)*24 , 4) ) CNT FROM Z_REPORT_DATE_TIME
        LEFT JOIN TEMP ON PLANNED_START_DATE &gt; PM_START_DATE_TIME AND PLANNED_COMP_DATE &lt; PM_END_DATE_TIME
        GROUP BY RESRCE , DATE_TIME ) K ON K.DATE_TIME = RDT.DATE_TIME  AND K.RESRCE = RDT.RESRCE
        LEFT JOIN
        (SELECT  DATE_TIME ,RESRCE , SUM( ROUND((PM_END_DATE_TIME - PLANNED_START_DATE)*24 , 4) ) CNT FROM Z_REPORT_DATE_TIME
        LEFT JOIN TEMP ON PLANNED_START_DATE &gt; PM_START_DATE_TIME AND PLANNED_START_DATE &lt; PM_END_DATE_TIME AND PLANNED_COMP_DATE &gt;= PM_END_DATE_TIME
        GROUP BY RESRCE , DATE_TIME ) L ON L.DATE_TIME = RDT.DATE_TIME  AND L.RESRCE = RDT.RESRCE
        GROUP BY RDT.SITE,RDT.RESRCE, RDT.RESOURCE_DESCRIPTION, RDT.DATE_TIME ,RDT.CAPACITY_MAN_HOUR , RDT.WORK_CENTER ,RDT.WORK_CENTER_DESCRIPTION ,RDT.RESOURCE_TYPE ,RDT.RESOURCE_TYPE_DESCRIPTION
        ) T
        GROUP BY T.RESOURCE_TYPE, T.RESOURCE_TYPE_DESCRIPTION, T.WORK_CENTER, T.WORK_CENTER_DESCRIPTION,T.SITE,T.DATE_TIME ) M
        WHERE M.SITE = #{site}
        <if test="startRate != null and startRate != ''">
            AND M.RATE_DATA_INT &gt;= #{startRate}
        </if>
        <if test="endRate != null and endRate != ''">
            AND M.RATE_DATA_INT &lt;= #{endRate}
        </if>
        ORDER BY M.WORK_CENTER,M.RESOURCE_TYPE,M.DATE_TIME
    </select>

    <!--设备维修数据统计报表-->
    <select id="findResourceRepairDataStatInfo" resultType="java.util.HashMap" parameterType="java.util.HashMap" >

    </select>

    <!--每日生产状态报表-->
    <select id="findProductStateInfo" resultType="java.util.HashMap" parameterType="java.util.HashMap" >
        SELECT CFB.VALUE ITEM_NUMBER , ZSD.SHOP_ORDER , I.ITEM , IT.DESCRIPTION ITEM_DESCRIPTION , S.QTY PLAN_QTY ,CFA.VALUE WORK_ORDER ,
               ZSD.SFC , ZSD.WORK_CENTER , WCT.DESCRIPTION  WORK_CENTER_DESCRIPTION , RU.ROUTER_TYPE , ZSD.STEP_ID , ZSD.OPERATION ,
               OT.DESCRIPTION OPERATION_DESCRIPTION, ZSD.RESRCE , R.DESCRIPTION RESOURCE_DESCRIPTION , ZSD.DISPATCH_STATUS OPERATION_STATUS ,
               ZSD.PROD_HOURS ,ZSD.ACTUAL_PROD_HOURS , ZSD.PLANNED_START_DATE , ZSD.PLANNED_COMP_DATE , ZSD.ACTUAL_START_DATE , ZSD.ACTUAL_COMPLETE_DATE
        FROM Z_SFC_DISPATCH ZSD
            LEFT JOIN SHOP_ORDER SO ON SO.SHOP_ORDER = ZSD.SHOP_ORDER
            LEFT JOIN CUSTOM_FIELDS CFA ON CFA.HANDLE = SO.HANDLE AND CFA."ATTRIBUTE" = 'WORK_ORDER'
            LEFT JOIN CUSTOM_FIELDS CFB ON CFB.HANDLE = SO.HANDLE AND CFB."ATTRIBUTE" = 'ITEM_NUMBER'
            LEFT JOIN SFC S ON S.SFC = ZSD.SFC
            LEFT JOIN ITEM I ON I.HANDLE = S.ITEM_BO
            LEFT JOIN ITEM_T IT ON IT.ITEM_BO = S.ITEM_BO
            LEFT JOIN WORK_CENTER WC ON WC.WORK_CENTER = ZSD.WORK_CENTER
            LEFT JOIN WORK_CENTER_T WCT ON WCT.WORK_CENTER_BO = WC.HANDLE
            LEFT JOIN OPERATION O ON O.OPERATION = ZSD.OPERATION
            LEFT JOIN OPERATION_T OT ON OT.OPERATION_BO = O.HANDLE
            LEFT JOIN RESRCE R ON R.RESRCE = ZSD.RESRCE
            LEFT JOIN ROUTER RU ON RU.HANDLE = ZSD.ROUTER_BO
            LEFT JOIN RESRCE R ON R.RESRCE = ZSD.RESRCE AND R.SITE = ZSD.SITE
            LEFT JOIN CUSTOM_FIELDS CF ON CF.HANDLE = R.HANDLE AND CF."ATTRIBUTE" = 'CHECK_USR'
        WHERE ZSD.SITE = #{site}
        <if test="itemNumber != null and itemNumber != ''" >
            AND CFB.VALUE LIKE '%'||#{itemNumber}||'%'
        </if>
        <if test="workOrder != null and workOrder != ''" >
            AND CFA.VALUE LIKE '%'||#{workOrder}||'%'
        </if>
        <if test="shopOrder != null and shopOrder != ''" >
            AND ZSD.SHOP_ORDER = #{shopOrder}
        </if>
        <if test="workCenter != null and workCenter != ''" >
            AND ZSD.WORK_CENTER = #{workCenter}
        </if>
        <if test="resrce != null and resrce != ''" >
            AND ZSD.RESRCE = #{resrce}
        </if>
        <if test="checkUsr != null and checkUsr != ''" >
            AND CF.VALUE = #{checkUsr}
        </if>
        <if test="operation != null and operation != ''" >
            AND ZSD.OPERATION = #{operation}
        </if>
        <if test="item != null and item != ''" >
            AND I.ITEM = #{item}
        </if>
        <if test="sfc != null and sfc != ''" >
            AND ZSD.SFC = #{sfc}
        </if>
        <if test="routerType != null and routerType != ''" >
            <choose>
                <when test="routerType != 'OTHER'.toString()">
                    AND RU.ROUTER_TYPE = #{routerType}
                </when>
                <otherwise>
                    AND RU.ROUTER_TYPE != 'C'
                </otherwise>
            </choose>
        </if>
        <if test="operationStatus != null and operationStatus != ''" >
            <choose>
                <when test="operationStatus != 'OTHER'.toString()">
                    AND ZSD.DISPATCH_STATUS = #{operationStatus}
                </when>
                <otherwise>
                    AND ZSD.DISPATCH_STATUS != 'START' AND ZSD.DISPATCH_STATUS != 'COMPLETE' AND ZSD.DISPATCH_STATUS != 'CANCEL'
                </otherwise>
            </choose>
        </if>
        <if test="startFromDate != null and startFromDate != ''" >
            AND ZSD.PLANNED_START_DATE >= TO_DATE(#{startFromDate}, 'YYYY-MM-DD') - 8/24
        </if>
        <if test="startToDate != null and startToDate != ''" >
            AND ZSD.PLANNED_COMP_DATE &lt;= TO_DATE(#{startToDate}|| '15:59:59', 'YYYY-MM-DD HH24:MI:SS')
        </if>
        <if test="actualStartFromDate != null and actualStartFromDate != ''" >
            AND ZSD.ACTUAL_START_DATE >= TO_DATE(#{actualStartFromDate}, 'YYYY-MM-DD') - 8/24
        </if>
        <if test="actualStartToDate != null and actualStartToDate != ''" >
            AND ZSD.ACTUAL_COMPLETE_DATE &lt;= TO_DATE(#{actualStartToDate}|| '15:59:59', 'YYYY-MM-DD HH24:MI:SS')
        </if>
    </select>


    <!--清空日期表-->
    <delete id="deleteAllReportDateTime">
        DELETE FROM Z_REPORT_DATE_TIME
    </delete>
    <!--插入日期数据-->
    <insert id="insertReportDateTime" >
        INSERT INTO Z_REPORT_DATE_TIME (SITE,DATE_TIME,START_DATE_TIME,END_DATE_TIME)
        <foreach collection="list" item="reportDateTime" index="index" open="(" separator=" union all " close=")" >
            SELECT  #{reportDateTime.site, jdbcType=NVARCHAR},
            #{reportDateTime.dateTime, jdbcType=NVARCHAR},
            #{reportDateTime.startDateTime, jdbcType=DATE},
            #{reportDateTime.endDateTime, jdbcType=DATE}
            FROM DUAL
        </foreach>
    </insert>

    <!--创建数据日期表-->
    <insert id="insertReportDateTimeByStartToDate"  >
        INSERT INTO Z_REPORT_DATE_TIME
        SELECT '1000' SITE ,TO_CHAR(TO_DATE(#{startFromDate},'YYYY-MM-DD') + ROWNUM -1, 'YYYY-MM-DD') DATE_TIME,
        TO_DATE(#{startFromDate} || '00:00:00','yyyy-mm-dd hh24:mi:ss') + rownum -1 AM_START_DATE_TIME,
        TO_DATE(#{startFromDate} || '04:00:00','yyyy-mm-dd hh24:mi:ss') + rownum -1 AM_END_DATE_TIME,
        TO_DATE(#{startFromDate} || '05:00:00','yyyy-mm-dd hh24:mi:ss') + rownum -1 PM_START_DATE_TIME ,
        TO_DATE(#{startFromDate} || '09:00:00','yyyy-mm-dd hh24:mi:ss') + rownum -1 PM_END_DATE_TIME
        FROM dual CONNECT BY rownum &lt;= to_date( #{startToDate}, 'yyyy-mm-dd') - to_date( #{startFromDate}, 'yyyy-mm-dd') + 1
    </insert>


    <select id="findInspectionTaskDetail" resultType="java.util.HashMap" parameterType="java.util.HashMap">
        SELECT ROWNUM SEQ, A.SITE, A.TASK_NO, A.DESCRIPTION, A.RESULT CHECK_RESULT, A.CREATE_USER CHECK_USER, A.CREATED_DATE_TIME CHECK_DATE, C.INSPECTION_ITEM_NO, C.DESCRIPTION, D.PARAM_NO, D.DESCRIPTION PARAM_DESC, D.INSPECTION_METHOD, D.MIN_VALUE, D.STANDARD_VALUE, D.MAX_VALUE, B.CHECK_VALUES, B."RESULT"
        FROM Z_INSPECTION_TASK A
        LEFT JOIN Z_INSPECTION_ITEM C ON A.INSPECTION_ITEM_BO = C.HANDLE
        INNER JOIN Z_INSPECTION_TASK_DETAIL B ON A.HANDLE = B.TASK_BO
        LEFT JOIN Z_INSPECTION_ITEM_DETAIL D ON B.INSPECTION_ITEM_DETAIL_BO = D.HANDLE AND C.HANDLE = D.INSPECTION_ITEM_BO
        WHERE A.SITE = #{site} AND A.TASK_NO = #{taskNo}
    </select>

    <select id="findWorkShopPassRate" resultType="java.util.HashMap" parameterType="java.util.HashMap">
        SELECT DESCRIPTION WORK_CENTER_DESCRIPTION, "MONTH",sum(NG_QTY) NC_QTY, sum(OK_QTY) OK_QTY,sum(CHECK_QTY) CHECK_QTY,round(sum(OK_QTY)*100/sum(DISPATCH_QTY),2)||'% ' OK_RATE FROM
        (
        SELECT  CASE WHEN ROW_NUMBER() OVER(PARTITION BY zit.sfc ,zit.OPERATION,zit.STEP_ID ORDER BY zit.CREATED_DATE_TIME DESC)=1 AND zit."RESULT"='OK' THEN 0
        WHEN ROW_NUMBER() OVER(PARTITION BY zit.sfc ,zit.OPERATION,zit.STEP_ID ORDER BY zit.CREATED_DATE_TIME DESC)=1 AND zit."RESULT"='NG' THEN TO_NUMBER(zab.NC_QTY)
        ELSE 0 END NG_QTY , TO_CHAR(zit.CREATED_DATE_TIME,'YYYY-MM') "MONTH",
        CASE WHEN ROW_NUMBER() OVER(PARTITION BY zit.sfc ,zit.OPERATION,zit.STEP_ID ORDER BY zit.CREATED_DATE_TIME DESC)=1 AND zit."RESULT"='OK' THEN zsd.DISPATCH_QTY
        WHEN ROW_NUMBER() OVER(PARTITION BY zit.sfc ,zit.OPERATION,zit.STEP_ID ORDER BY zit.CREATED_DATE_TIME DESC)=1 AND zit."RESULT"='NG' THEN 0
        ELSE 0 END OK_QTY
        ,ZSD.DISPATCH_QTY, WT.DESCRIPTION,
        ROW_NUMBER() OVER(PARTITION BY zit.sfc ,zit.OPERATION,zit.STEP_ID ORDER BY zit.CREATED_DATE_TIME DESC) seq,
        zit."RESULT",COUNT(ZIT.HANDLE) check_qty, zit.sfc ,zit.OPERATION,zit.STEP_ID FROM Z_INSPECTION_TASK zit
        JOIN sfc S ON  S.SFC=zit.SFC AND  s.SITE=zit.SITE
        JOIN Z_SFC_DISPATCH ZSD ON  ZSD.SFC=zit.SFC AND  ZSD.SITE=zit.SITE AND zit.STEP_ID=ZSD.STEP_ID
        JOIN WORK_CENTER WC ON WC.SITE = zit.SITE AND WC.WORK_CENTER = zit.WORK_CENTER
        LEFT JOIN WORK_CENTER_T WT ON WT.WORK_CENTER_BO = WC.HANDLE AND WT.LOCALE = 'zh'
        LEFT JOIN Z_ABNORMAL_BILL ZAB ON zit.SFC=ZAB.SFC AND zit.SITE=ZAB.SITE AND zit.STEP_ID=ZAB.STEP_ID AND zab."TYPE"='Z'
        WHERE  zit.SITE= #{site} AND zit.CATEGORY='P' AND zit.STATUS='COMPLETE'
        <if test="workCenter != null and workCenter != ''" >
            AND zit.WORK_CENTER = #{workCenter}
        </if>
        <if test="startFromDate != null and startFromDate != ''" >
            AND TO_CHAR(zit.CREATED_DATE_TIME,'YYYY-MM') >=#{startFromDate}
        </if>
        <if test="startToDate != null and startToDate != ''" >
            AND TO_CHAR(zit.CREATED_DATE_TIME,'YYYY-MM') &lt;= #{startToDate}
        </if>
        GROUP BY zit."RESULT",zit.sfc ,zit.OPERATION,zit.STEP_ID, zit.CREATED_DATE_TIME,zit.RESRCE,zab.NC_QTY, WT.DESCRIPTION,ZSD.DISPATCH_QTY
        ) GROUP BY DESCRIPTION, "MONTH"
        ORDER BY DESCRIPTION,"MONTH"

    </select>

    <select id="findCheckUserPassRate" resultType="java.util.HashMap" parameterType="java.util.HashMap">
        SELECT DESCRIPTION WORK_CENTER_DESCRIPTION, FULL_NAME,"MONTH",sum(NG_QTY) NC_QTY, sum(CHECK_QTY) CHECK_QTY FROM
            (
            SELECT  CASE WHEN ROW_NUMBER() OVER(PARTITION BY zit.sfc ,zit.OPERATION,zit.STEP_ID ORDER BY zit.CREATED_DATE_TIME DESC)=1 AND zit."RESULT"='OK' THEN 0
            WHEN ROW_NUMBER() OVER(PARTITION BY zit.sfc ,zit.OPERATION,zit.STEP_ID ORDER BY zit.CREATED_DATE_TIME DESC)=1 AND zit."RESULT"='NG' THEN TO_NUMBER(zab.NC_QTY)
            ELSE 0 END NG_QTY , TO_CHAR(zit.CREATED_DATE_TIME,'YYYY-MM') "MONTH"
            , WT.DESCRIPTION,ZNU.FULL_NAME,
            ROW_NUMBER() OVER(PARTITION BY zit.sfc ,zit.OPERATION,zit.STEP_ID ORDER BY zit.CREATED_DATE_TIME DESC) seq,
             zit."RESULT",COUNT(ZIT.HANDLE) check_qty, zit.sfc ,zit.OPERATION,zit.STEP_ID FROM Z_INSPECTION_TASK zit
            JOIN sfc S ON  S.SFC=zit.SFC AND  s.SITE=zit.SITE
            JOIN Z_SFC_DISPATCH ZSD ON  ZSD.SFC=zit.SFC AND  ZSD.SITE=zit.SITE AND zit.STEP_ID=ZSD.STEP_ID
            JOIN WORK_CENTER WC ON WC.SITE = zit.SITE AND WC.WORK_CENTER = zit.WORK_CENTER
            LEFT JOIN WORK_CENTER_T WT ON WT.WORK_CENTER_BO = WC.HANDLE AND WT.LOCALE = 'zh'
            LEFT JOIN Z_ABNORMAL_BILL ZAB ON zit.SFC=ZAB.SFC AND zit.SITE=ZAB.SITE AND zit.STEP_ID=ZAB.STEP_ID AND zab."TYPE"='Z'
            LEFT JOIN Z_NWA_USER ZNU ON  ZNU.USER_NAME = ZIT.MODIFY_USER
            WHERE  zit.SITE= #{site} AND zit.CATEGORY='P' AND zit.STATUS='COMPLETE'
            <if test="workCenter != null and workCenter != ''" >
                AND zit.WORK_CENTER = #{workCenter}
            </if>
            <if test="startFromDate != null and startFromDate != ''" >
                AND TO_CHAR(zit.CREATED_DATE_TIME,'YYYY-MM') >=#{startFromDate}
            </if>
            <if test="startToDate != null and startToDate != ''" >
                AND TO_CHAR(zit.CREATED_DATE_TIME,'YYYY-MM') &lt;= #{startToDate}
            </if>
            <if test="userId != null and userId != ''" >
                AND ZIT.MODIFY_USER = #{userId}
            </if>
            GROUP BY zit."RESULT",zit.sfc ,zit.OPERATION,zit.STEP_ID, zit.CREATED_DATE_TIME,zit.RESRCE,zab.NC_QTY, ZNU.FULL_NAME,WT.DESCRIPTION
            ) GROUP BY DESCRIPTION, "MONTH",FULL_NAME
            ORDER BY DESCRIPTION,"MONTH"
    </select>

    <select id="findUserPassRate" resultType="java.util.HashMap" parameterType="java.util.HashMap">
        SELECT ZNU.FULL_NAME,DUTY_USER,DESCRIPTION WORK_CENTER_DESCRIPTION, "MONTH",sum(NG_QTY) NC_QTY, sum(OK_QTY) OK_QTY,sum(CHECK_QTY) CHECK_QTY,round(sum(OK_QTY)*100/sum(DISPATCH_QTY),2)||'% ' OK_RATE FROM
        (
        SELECT  CASE WHEN ROW_NUMBER() OVER(PARTITION BY zit.sfc ,zit.OPERATION,zit.STEP_ID ORDER BY zit.CREATED_DATE_TIME DESC)=1 AND zit."RESULT"='OK' THEN 0
        WHEN ROW_NUMBER() OVER(PARTITION BY zit.sfc ,zit.OPERATION,zit.STEP_ID ORDER BY zit.CREATED_DATE_TIME DESC)=1 AND zit."RESULT"='NG' THEN TO_NUMBER(zab.NC_QTY)
        ELSE 0 END NG_QTY , TO_CHAR(zit.CREATED_DATE_TIME,'YYYY-MM') "MONTH",
        CASE WHEN ROW_NUMBER() OVER(PARTITION BY zit.sfc ,zit.OPERATION,zit.STEP_ID ORDER BY zit.CREATED_DATE_TIME DESC)=1 AND zit."RESULT"='OK' THEN zsd.DISPATCH_QTY
        WHEN ROW_NUMBER() OVER(PARTITION BY zit.sfc ,zit.OPERATION,zit.STEP_ID ORDER BY zit.CREATED_DATE_TIME DESC)=1 AND zit."RESULT"='NG' THEN 0
        ELSE 0 END OK_QTY,E.EMPLOYEE,ZABD.DUTY_USER
        ,ZSD.DISPATCH_QTY, WT.DESCRIPTION,
        ROW_NUMBER() OVER(PARTITION BY zit.sfc ,zit.OPERATION,zit.STEP_ID ORDER BY zit.CREATED_DATE_TIME DESC) seq,
        zit."RESULT",COUNT(ZIT.HANDLE) check_qty, zit.sfc ,zit.OPERATION,zit.STEP_ID FROM Z_INSPECTION_TASK zit
        JOIN sfc S ON  S.SFC=zit.SFC AND  s.SITE=zit.SITE
        JOIN Z_SFC_DISPATCH ZSD ON  ZSD.SFC=zit.SFC AND  ZSD.SITE=zit.SITE AND zit.STEP_ID=ZSD.STEP_ID
        JOIN WORK_CENTER WC ON WC.SITE = zit.SITE AND WC.WORK_CENTER = zit.WORK_CENTER
        JOIN (
        SELECT HANDLE,
        REGEXP_SUBSTR(EMPLOYEE, '[^,]+', 1, l) AS EMPLOYEE
        FROM Z_SFC_DISPATCH c,
        (SELECT LEVEL l FROM DUAL CONNECT BY LEVEL &lt;= 5)
        WHERE l &lt;= LENGTH(EMPLOYEE) -  LENGTH(REPLACE(EMPLOYEE, ',')) + 1) E ON ZSD.HANDLE=E.HANDLE
        LEFT JOIN WORK_CENTER_T WT ON WT.WORK_CENTER_BO = WC.HANDLE AND WT.LOCALE = 'zh'
        LEFT JOIN Z_ABNORMAL_BILL ZAB ON zit.SFC=ZAB.SFC AND zit.SITE=ZAB.SITE AND zit.STEP_ID=ZAB.STEP_ID AND zab."TYPE"='Z'
        LEFT JOIN Z_ABNORMAL_BILL_DISPOSE ZABD ON ZAB.HANDLE=ZABD.ABNORMAL_BILL_BO
        WHERE  zit.SITE= #{site} AND zit.CATEGORY='P' AND zit.STATUS='COMPLETE'
        <if test="workCenter != null and workCenter != ''" >
            AND zit.WORK_CENTER = #{workCenter}
        </if>
        <if test="startFromDate != null and startFromDate != ''" >
            AND TO_CHAR(zit.CREATED_DATE_TIME,'YYYY-MM') >=#{startFromDate}
        </if>
        <if test="startToDate != null and startToDate != ''" >
            AND TO_CHAR(zit.CREATED_DATE_TIME,'YYYY-MM') &lt;= #{startToDate}
        </if>
        <if test="userId != null and userId != ''" >
            AND E.EMPLOYEE = #{userId}
        </if>
        GROUP BY zit."RESULT",zit.sfc ,zit.OPERATION,zit.STEP_ID, zit.CREATED_DATE_TIME,zit.RESRCE,zab.NC_QTY, WT.DESCRIPTION,ZSD.DISPATCH_QTY,E.EMPLOYEE,ZABD.DUTY_USER
        ) D
        LEFT JOIN Z_NWA_USER ZNU ON ZNU.USER_NAME = D.EMPLOYEE
        GROUP BY DESCRIPTION, "MONTH",ZNU.FULL_NAME,DUTY_USER
        ORDER BY DESCRIPTION,"MONTH"
    </select>
</mapper>