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

    <select id="queryDangerList" resultType="com.yeejoin.amos.boot.module.ccs.api.dto.FireLatentDangerDto">
        select
        d.id,
        d.danger_name,
        d.danger_state,
        d.danger_state_name,
        d.danger_level,
        d.danger_level_name,
        s.name as station_name,
        d.station_code,
        d.discovery_date,
        d.lng,
        d.lat,
        s.lng as stationLng,
        s.lat as stationLat
        from
        asf_fire_latent_danger d,
        asf_fire_station_info s
        where d.station_code = s.code
        and s.status = false
        <if test="stationCode != null and stationCode != ''">
            and d.station_code = #{stationCode}
        </if>
        order by d.discovery_date desc
        <if test="top != null">
            limit ${top}
        </if>
    </select>
    <select id="dangerStateGroupMap" resultType="java.util.Map">
        SELECT
        d.danger_state as dangerState,
        count(1) as num
        FROM `asf_fire_latent_danger` d
        <where>
            <if test="stationCode != null and stationCode != ''">
                d.station_code = #{stationCode}
            </if>
        </where>
        GROUP BY d.danger_state
    </select>
</mapper>
