<?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.device.dao.ibatis.DeviceStatDaoImpl">
    <!-- 获取统计列表 -->
    <select id="getStatList" parameterType="paramDto" resultMap="DeviceStatEntity-Map">
        select
        <!-- 获取分组字段 -->
        <if test="groupList != null and !groupList.isEmpty()">
            <foreach collection="groupList" open="" close="" index="index" item="item">
                ${item},
            </foreach>
        </if>
        id,
        siteId,
        createTime,
        year,
        month,
        day,
        <!-- 设备总数-->
        max(IFNULL(a.deviceTotalCount, 0)) deviceTotalCount,
        <!-- 新增减少设备数量-->
        ROUND(avg(IFNULL(a.deviceAddCount,0)),0) deviceAddCount,
        <!-- 监控站点数量-->
        max(IFNULL(a.siteTotalCount, 0)) siteTotalCount,
        <!-- 昨日新增站点数量-->
        ROUND(avg(IFNULL(a.siteAddCount,0)),0) siteAddCount,
        <!-- 在线设备数量-->
        max(IFNULL(a.deviceOnlineCount,0)) deviceOnlineCount,
        <!-- 在线率-->
        ROUND(avg(IFNULL(a.deviceOnlineRatio,0.00)),2) deviceOnlineRatio,
        <!-- 停用设备数量-->
        max(IFNULL(a.deviceStopCount,0)) deviceStopCount,
        <!-- 停用率-->
        ROUND(avg(IFNULL(a.deviceStopRatio,0.00)),2) deviceStopRatio,
        <!-- 离线设备数量-->
        max(IFNULL(a.deviceOfflineCount,0)) deviceOfflineCount,
        <!-- 离线率-->
        ROUND(avg(IFNULL(a.deviceOfflineRatio,0.00)),2) deviceOfflineRatio,
        <!-- 未激活设备数量-->
        max(IFNULL(a.deviceUnActiveCount,0)) deviceUnActiveCount,
        <!-- 未激活率-->
        ROUND(avg(IFNULL(a.deviceUnActiveRatio,0.00)),2) deviceUnActiveRatio,
        <!-- 告警数量-->
        sum(IFNULL(a.alarmTotalCount,0)) alarmTotalCount,
        ROUND(avg(IFNULL(a.alarmAddCount,0)),0) alarmAddCount,
        <!-- 消息推送数量-->
        sum(IFNULL(a.pushTotalCount,0)) pushTotalCount,
        ROUND(avg(IFNULL(a.pushAddCount,0)),0) pushAddCount,
        sum(IFNULL(a.uploadMessageTotalCount,0)) uploadMessageTotalCount,
        sum(IFNULL(a.downloadMessageTotalCount,0)) downloadMessageTotalCount

        from mortals_xhx_device_stat as a
        <trim suffixOverrides="where" suffix="">
            where
            <trim prefixOverrides="and" prefix="">
                <include refid="_condition_"/>
            </trim>
        </trim>
        <include refid="_group_by_"/>
        <include refid="_orderCols_"/>
    </select>
</mapper>