<?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="com.usky.fire.mapper.AlarmFireMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.usky.fire.domain.AlarmFire">
        <id column="id" property="id" />
        <result column="device_code" property="deviceCode" />
        <result column="device_name" property="deviceName" />
        <result column="alarm_type" property="alarmType" />
        <result column="alarm_time" property="alarmTime" />
        <result column="address" property="address" />
        <result column="alarm_status" property="alarmStatus" />
        <result column="system_type" property="systemType" />
        <result column="port_num" property="portNum" />
        <result column="company_id" property="companyId" />
        <result column="company_name" property="companyName" />
        <result column="attribute_value1" property="attributeValue1" />
        <result column="attribute_value2" property="attributeValue2" />
        <result column="attribute_value3" property="attributeValue3" />
        <result column="attribute_value4" property="attributeValue4" />
        <result column="point_type" property="pointType" />
        <result column="host_num" property="hostNum" />
        <result column="loop_num" property="loopNum" />
        <result column="pt_num" property="ptNum" />
        <result column="handler" property="handler" />
        <result column="handling_time" property="handlingTime" />
        <result column="handling_content" property="handlingContent" />
        <result column="handler_phone" property="handlerPhone" />
        <result column="handling_status" property="handlingStatus" />
        <result column="false_alarm" property="falseAlarm" />
        <result column="site_photo" property="sitePhoto" />
    </resultMap>
    <select id="selectAlarmFireStatistical" resultType="com.usky.fire.service.vo.AlarmFireStatisticalVo">
        SELECT
        DATE_FORMAT(alarm_time, "%Y-%m-%d") AS alarmTime,
        count(*) AS `count`,
        sum(handling_status) AS `sum`
        FROM
        alarm_fire
        <where>
            <if test="companyIdList != null and companyIdList.size() > 0">
                AND company_id in
                <foreach item="item" collection="companyIdList" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="startDate != null and startDate != '' and startDate != null and startDate != ''">
                and  alarm_time BETWEEN  #{startDate} AND  #{endDate}
            </if>
            <if test="selectStatus == 0">
                <if test="alarmTypeList != null and alarmTypeList.size() > 0">
                    AND alarm_type in
                    <foreach item="item" collection="alarmTypeList" open="(" separator="," close=")">
                        #{item}
                    </foreach>
                </if>
            </if>
            <if test="selectStatus == 1">
                <if test="alarmTypeList != null and alarmTypeList.size() > 0">
                    AND alarm_type not in
                    <foreach item="item" collection="alarmTypeList" open="(" separator="," close=")">
                        #{item}
                    </foreach>
                </if>
            </if>

        </where>
        GROUP BY
        alarmTime
    </select>


</mapper>
