<?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.DeviceMessageStatDaoImpl">
    <!-- 获取统计列表 -->
    <select id="getMessageStatList" parameterType="paramDto" resultMap="DeviceMessageStatEntity-Map">
        select
        <!-- 获取分组字段 -->
        <if test="groupList != null and !groupList.isEmpty()">
            <foreach collection="groupList" open="" close="" index="index" item="item">
                ${item},
            </foreach>
        </if>
        id,
        siteId,
        productId,
        productCode,
        productName,
        createTime,
        year,
        month,
        day,
        <!-- 告警数量-->
        sum(IFNULL(a.alarmTotalCount, 0)) alarmTotalCount,
        <!-- 消息推送数量-->
        sum(IFNULL(a.pushTotalCount,0)) pushTotalCount,
        sum(IFNULL(a.uploadMessageTotalCount,0)) uploadMessageTotalCount,
        sum(IFNULL(a.downloadMessageTotalCount,0)) downloadMessageTotalCount

        from mortals_xhx_device_message_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>