<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "mybatis-3-mapper.dtd">
<mapper namespace="com.mortals.xhx.module.staff.dao.ibatis.StaffPerformStatDaoImpl">
    <!-- 按天top10 -->
    <select id="getDaySummaryList" parameterType="com.mortals.xhx.module.staff.model.vo.StaffSummaryTopQuery" resultType="com.mortals.xhx.module.staff.model.StaffPerformStatEntity">
        SELECT * FROM (
            SELECT
                `year`,
                `month`,
                `day`,
                staffId,
                staffName,
                SUM(totalScore) AS totalScore
            FROM
                mortals_xhx_staff_perform_stat
            WHERE 1=1
            <if test="year != null">
                AND `year` = #{year}
            </if>
            <if test="month != null">
                AND `month` = #{month}
            </if>
            <if test="day != null">
                AND `day` = #{day}
            </if>
            GROUP BY
                staffId,
                `year`,
                `month`,
                `day`
        ) AS a ORDER BY totalScore DESC LIMIT 10
    </select>

    <!-- 按月top10 -->
    <select id="getMonthSummaryList" parameterType="com.mortals.xhx.module.staff.model.vo.StaffSummaryTopQuery" resultType="com.mortals.xhx.module.staff.model.StaffPerformStatEntity">
        SELECT * FROM (
            SELECT
                `year`,
                `month`,
                staffId,
                staffName,
                SUM(totalScore) AS totalScore
            FROM
                mortals_xhx_staff_perform_stat
            WHERE 1=1
            <if test="year != null">
                AND `year` = #{year}
            </if>
            <if test="month != null">
                AND `month` = #{month}
            </if>
            GROUP BY
                staffId,
                `year`,
                `month`
        ) AS a ORDER BY totalScore DESC LIMIT 10
    </select>

    <!-- 按年top10 -->
    <select id="getYearSummaryList" parameterType="com.mortals.xhx.module.staff.model.vo.StaffSummaryTopQuery" resultType="com.mortals.xhx.module.staff.model.StaffPerformStatEntity">
        SELECT * FROM (
            SELECT
                `year`,
                staffId,
                staffName,
                SUM(totalScore) AS totalScore
            FROM
                mortals_xhx_staff_perform_stat
            WHERE 1=1
            <if test="year != null">
                AND `year` = #{year}
            </if>
            GROUP BY
                staffId,
                `year`
        ) AS a ORDER BY totalScore DESC LIMIT 10
    </select>

    <!-- 按天异常分值统计 -->
    <select id="getDayExceptionList" parameterType="com.mortals.xhx.module.staff.model.vo.StaffSummaryTopQuery" resultType="com.mortals.xhx.module.staff.model.StaffPerformStatEntity">
        SELECT
            `year`,
            `month`,
            `day`,
            SUM(attendScoreAdd) AS attendScoreAdd,
            SUM(attendScoreSub) AS attendScoreSub,
            SUM(reviewScoreAdd) AS reviewScoreAdd,
            SUM(reviewScoreSub) AS reviewScoreSub,
            SUM(complainScoreAdd) AS complainScoreAdd,
            SUM(complainScoreSub) AS complainScoreSub,
            SUM(goworkScoreAdd) AS goworkScoreAdd,
            SUM(goworkScoreSub) AS goworkScoreSub,
            SUM(effectScoreAdd) AS effectScoreAdd,
            SUM(effectScoreSub) AS effectScoreSub,
            SUM(otherScoreAdd) AS otherScoreAdd,
            SUM(otherScoreSub) AS otherScoreSub
        FROM
            mortals_xhx_staff_perform_stat
        WHERE 1=1
        <if test="year != null">
            AND `year` = #{year}
        </if>
        <if test="month != null">
            AND `month` = #{month}
        </if>
        <if test="day != null">
            AND `day` = #{day}
        </if>
        GROUP BY
            `year`,
            `month`,
            `day`
    </select>

    <!-- 按月异常分值统计 -->
    <select id="getMonthExceptionList" parameterType="com.mortals.xhx.module.staff.model.vo.StaffSummaryTopQuery" resultType="com.mortals.xhx.module.staff.model.StaffPerformStatEntity">
        SELECT
            `year`,
            `month`,
            SUM(attendScoreAdd) AS attendScoreAdd,
            SUM(attendScoreSub) AS attendScoreSub,
            SUM(reviewScoreAdd) AS reviewScoreAdd,
            SUM(reviewScoreSub) AS reviewScoreSub,
            SUM(complainScoreAdd) AS complainScoreAdd,
            SUM(complainScoreSub) AS complainScoreSub,
            SUM(goworkScoreAdd) AS goworkScoreAdd,
            SUM(goworkScoreSub) AS goworkScoreSub,
            SUM(effectScoreAdd) AS effectScoreAdd,
            SUM(effectScoreSub) AS effectScoreSub,
            SUM(otherScoreAdd) AS otherScoreAdd,
            SUM(otherScoreSub) AS otherScoreSub
        FROM
            mortals_xhx_staff_perform_stat
        WHERE 1=1
        <if test="year != null">
            AND `year` = #{year}
        </if>
        <if test="month != null">
            AND `month` = #{month}
        </if>
        GROUP BY
            `year`,
            `month`
    </select>

    <!-- 按年异常分值统计 -->
    <select id="getYearExceptionList" parameterType="com.mortals.xhx.module.staff.model.vo.StaffSummaryTopQuery" resultType="com.mortals.xhx.module.staff.model.StaffPerformStatEntity">
        SELECT
            `year`,
            SUM(attendScoreAdd) AS attendScoreAdd,
            SUM(attendScoreSub) AS attendScoreSub,
            SUM(reviewScoreAdd) AS reviewScoreAdd,
            SUM(reviewScoreSub) AS reviewScoreSub,
            SUM(complainScoreAdd) AS complainScoreAdd,
            SUM(complainScoreSub) AS complainScoreSub,
            SUM(goworkScoreAdd) AS goworkScoreAdd,
            SUM(goworkScoreSub) AS goworkScoreSub,
            SUM(effectScoreAdd) AS effectScoreAdd,
            SUM(effectScoreSub) AS effectScoreSub,
            SUM(otherScoreAdd) AS otherScoreAdd,
            SUM(otherScoreSub) AS otherScoreSub
        FROM
            mortals_xhx_staff_perform_stat
        WHERE 1=1
        <if test="year != null">
            AND `year` = #{year}
        </if>
        GROUP BY
            `year`
    </select>

</mapper>