<?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.yeejoin.amos.boot.module.ccs.api.mapper.FireEquipmentSignalLogMapper">

    <select id="queryAlarmLogList"
            resultType="com.yeejoin.amos.boot.module.ccs.api.dto.FireEquipmentSignalLogDto">
        select
            a.id,
            a.fire_equipment_name,
            a.fire_equipment_index_name,
            a.signal_type,
            a.signal_type_name,
            a.create_date,
            s.name as station_name,
            a.location,
            <choose>
                <when test="stationCode != null and stationCode != ''">
                    a.lat,
                    a.lng,
                </when>
                <otherwise>
                    s.lng,
                    s.lat,
                </otherwise>
            </choose>
            a.station_code,
            a.lat as sourceLat,
            a.lng as sourceLng,
            a.fire_equipment_mrid,
            a.protected_object_mrid,
            a.protected_object_name,
            a.system_names,
            s.station_charge_person,
            s.charge_person_phone,
            a.fire_building_mrid,
            s.view3d_url
        from
            asf_fire_equipment_signal_log a,
            asf_fire_station_info s
        where
        a.station_code = s.code
        and s.status = false
        <if test="stationCode != null and stationCode != ''">
            and a.station_code = #{stationCode}
        </if>
        <if test="confirmState != null and confirmState != ''">
            and a.confirm_state = #{confirmState}
        </if>
        <if test="beginDate != null and beginDate != ''">
            and DATEDIFF(a.create_date,#{beginDate}) >= 0
        </if>
        <if test="endDate != null and endDate != ''">
            and DATEDIFF(a.create_date,#{endDate}) <![CDATA[<=]]> 0
        </if>
        <if test="sourceId != null and sourceId != ''">
            and a.id = #{sourceId}
        </if>
        order by a.create_date desc
        <if test="top != null">
         limit ${top}
        </if>
    </select>
    <select id="distinctByEquipmentId" resultType="com.yeejoin.amos.boot.module.ccs.api.dto.FireEquipmentDto">
        SELECT
            distinct(ai.fire_equipment_mrid) as mrid
        FROM `asf_fire_equipment_signal_log` ai
        where
        ai.signal_report_date =#{alarmDate}
        and ai.is_alarm = true
        <if test="stationCode != null and stationCode != ''">
            and ai.station_code =#{stationCode}
        </if>
    </select>
</mapper>
