<?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.AlarmElectricalFireMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.usky.fire.domain.AlarmElectricalFire">
        <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="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="selectElectricalFireStatistical" 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
        ${table}
        <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>
        </where>
        GROUP BY
        alarmTime
    </select>

    <select id="alarmCount" resultType="com.usky.fire.service.vo.DataCountVo">
        SELECT
        handling_status as id,
        count(*) AS listCount
        FROM
        ${table}
        <where>
            <if test="companyId != null and companyId != '' ">
                company_id = #{companyId}
            </if>
        </where>
        GROUP BY
        handling_status
    </select>

    <select id="alarmFireCount" resultType="com.usky.fire.service.vo.DataCountVo">
        SELECT
        handling_status as id,
        count(*) AS listCount
        FROM
        alarm_fire
        <where>
            alarm_type not in('2','4')
            and company_id = #{companyId}
        </where>
        GROUP BY
        handling_status
    </select>

</mapper>
