<?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.dept.dao.ibatis.DeptPerformStatDaoImpl">
    <!-- 按天top10 -->
    <select id="getDaySummaryList" parameterType="com.mortals.xhx.module.dept.model.vo.DeptSummaryTopQuery" resultType="com.mortals.xhx.module.dept.model.DeptPerformStatEntity">
        SELECT * FROM (
            SELECT
                `year`,
                `month`,
                `day`,
                deptId,
                deptName,
                SUM(totalScore) AS totalScore
            FROM
                mortals_xhx_dept_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
                deptId,
                `year`,
                `month`,
                `day`
        ) AS a ORDER BY totalScore DESC LIMIT 10
    </select>

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

    <!-- 按年top10 -->
    <select id="getYearSummaryList" parameterType="com.mortals.xhx.module.dept.model.vo.DeptSummaryTopQuery" resultType="com.mortals.xhx.module.dept.model.DeptPerformStatEntity">
        SELECT * FROM (
        SELECT
        `year`,
        deptId,
        deptName,
        SUM(totalScore) AS totalScore
        FROM
        mortals_xhx_dept_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
        deptId,
        `year`
        ) AS a ORDER BY totalScore DESC LIMIT 10
    </select>

</mapper>