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

    <select id="queryAlarmTimesTrend" resultType="java.lang.String">
        select
        (SELECT
        IFNULL(sum(s.report_times),0)
        FROM `asf_fire_signal_day_statistics` s
        <where>
            <if test="stationCode != null and stationCode != ''">
                and s.station_code = #{stationCode}
            </if>
            <if test="signalType != null and signalType != ''">
                and s.signal_type = #{signalType}
            </if>
            and s.collect_date = t.date
            and s.is_alarm = true
        </where>
        ) as times
        from
        (SELECT
        DATE_FORMAT(DATE( DATE_ADD( #{beginDate}, INTERVAL @s DAY )),'%Y-%m-%d') AS date,
        @s := @s + 1 AS `index`
        FROM
        mysql.help_topic,
        ( SELECT @s := 0 ) temp
        WHERE
        @s <![CDATA[<=]]>
        DATEDIFF(#{endDate},#{beginDate})) t
        GROUP BY t.date
    </select>
</mapper>
