<?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="me.zhengjie.modules.system.mapper.DashboardMapper">

    <select id="getPieChatData" resultType="me.zhengjie.modules.system.domain.dto.DashboardDataVo">
        select t.text, t.value from (
            select CONCAT(d.brand, ' | ', d.model) text, count(cl.id) value from bus_device d LEFT JOIN bus_command_log cl on d.id = cl.device_id GROUP BY d.id ORDER BY value desc
        ) t limit 10
    </select>

    <select id="getCardData" resultType="me.zhengjie.modules.system.domain.dto.DashboardDataVo">
        select 'user' text, count(*) value from sys_user
        UNION ALL
        select 'dept' text, count(*) value from sys_dept
        UNION ALL
        select 'role' text, count(*) value from sys_role
        UNION ALL
        select 'law' text, count(*) value from bus_user
    </select>

    <select id="getLineChartData" resultType="me.zhengjie.modules.system.domain.dto.DashboardDataVo">
        <if test="type == 'user'">
            select '前一天' text, count(1) value from sys_user where DATE(create_time) = CURDATE() - INTERVAL 1 DAY UNION ALL
            select '前两天' text, count(1) value from sys_user where DATE(create_time) = CURDATE() - INTERVAL 2 DAY UNION ALL
            select '前三天' text, count(1) value from sys_user where DATE(create_time) = CURDATE() - INTERVAL 3 DAY UNION ALL
            select '前四天' text, count(1) value from sys_user where DATE(create_time) = CURDATE() - INTERVAL 4 DAY UNION ALL
            select '前五天' text, count(1) value from sys_user where DATE(create_time) = CURDATE() - INTERVAL 5 DAY UNION ALL
            select '前六天' text, count(1) value from sys_user where DATE(create_time) = CURDATE() - INTERVAL 6 DAY UNION ALL
            select '前七天' text, count(1) value from sys_user where DATE(create_time) = CURDATE() - INTERVAL 7 DAY
        </if>
        <if test="type == 'dept'">
            select '前一天' text, count(1) value from sys_dict where DATE(create_time) = CURDATE() - INTERVAL 1 DAY UNION ALL
            select '前两天' text, count(1) value from sys_dict where DATE(create_time) = CURDATE() - INTERVAL 2 DAY UNION ALL
            select '前三天' text, count(1) value from sys_dict where DATE(create_time) = CURDATE() - INTERVAL 3 DAY UNION ALL
            select '前四天' text, count(1) value from sys_dict where DATE(create_time) = CURDATE() - INTERVAL 4 DAY UNION ALL
            select '前五天' text, count(1) value from sys_dict where DATE(create_time) = CURDATE() - INTERVAL 5 DAY UNION ALL
            select '前六天' text, count(1) value from sys_dict where DATE(create_time) = CURDATE() - INTERVAL 6 DAY UNION ALL
            select '前七天' text, count(1) value from sys_dict where DATE(create_time) = CURDATE() - INTERVAL 7 DAY
        </if>
        <if test="type == 'role'">
            select '前一天' text, count(1) value from sys_role where DATE(create_time) = CURDATE() - INTERVAL 1 DAY UNION ALL
            select '前两天' text, count(1) value from sys_role where DATE(create_time) = CURDATE() - INTERVAL 2 DAY UNION ALL
            select '前三天' text, count(1) value from sys_role where DATE(create_time) = CURDATE() - INTERVAL 3 DAY UNION ALL
            select '前四天' text, count(1) value from sys_role where DATE(create_time) = CURDATE() - INTERVAL 4 DAY UNION ALL
            select '前五天' text, count(1) value from sys_role where DATE(create_time) = CURDATE() - INTERVAL 5 DAY UNION ALL
            select '前六天' text, count(1) value from sys_role where DATE(create_time) = CURDATE() - INTERVAL 6 DAY UNION ALL
            select '前七天' text, count(1) value from sys_role where DATE(create_time) = CURDATE() - INTERVAL 7 DAY
        </if>
        <if test="type == 'law'">
            select '前一天' text, count(1) value from bus_command_log where DATE(create_time) = CURDATE() - INTERVAL 1 DAY UNION ALL
            select '前两天' text, count(1) value from bus_command_log where DATE(create_time) = CURDATE() - INTERVAL 2 DAY UNION ALL
            select '前三天' text, count(1) value from bus_command_log where DATE(create_time) = CURDATE() - INTERVAL 3 DAY UNION ALL
            select '前四天' text, count(1) value from bus_command_log where DATE(create_time) = CURDATE() - INTERVAL 4 DAY UNION ALL
            select '前五天' text, count(1) value from bus_command_log where DATE(create_time) = CURDATE() - INTERVAL 5 DAY UNION ALL
            select '前六天' text, count(1) value from bus_command_log where DATE(create_time) = CURDATE() - INTERVAL 6 DAY UNION ALL
            select '前七天' text, count(1) value from bus_command_log where DATE(create_time) = CURDATE() - INTERVAL 7 DAY
        </if>
    </select>

</mapper>