<?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.jcs.api.mapper.AlertCalledMapper">

    <select id="queryAlertStatusCount" resultType="java.util.Map">
        SELECT
            count( 1 ) calledCount,
            sum( CASE WHEN alert_status = 1 THEN 1 ELSE 0 END ) finishedCount,
            sum( CASE WHEN alert_type_code = 230 THEN 1 ELSE 0 END ) majorAlertCount
        FROM
            jc_alert_called
        WHERE 1 = 1
        <if test="beginDate != null and beginDate != ''">
            and call_time >= #{beginDate}
        </if>
        <if test="endDate != null and endDate != ''">
            and call_time <![CDATA[ <= ]]> #{endDate}
        </if>
    </select>


    <select id="alertCalledListByAlertStatus" resultType="com.yeejoin.amos.boot.module.jcs.api.dto.AlertCalledZhDto">
        SELECT
        a.sequence_nbr sequenceNbr,
        a.alert_stage alertStage,
        a.call_time callTime,
        a.rescue_grid rescueGrid,
        a.alert_type alertType,
        a.alert_type_code alarmTypeCode,
        a.unit_involved unitInvolved,
        a.trapped_num trappedNum,
        a.casualties_num casualtiesNum,
        a.address ,
        a.coordinate_x longitude,
        a.coordinate_y latitude,
        CASE a.response_level_code
        WHEN '243' THEN '一级'
        WHEN '244' THEN '二级'
        WHEN '245' THEN '三级'
        ELSE '' END  responseLevelCode
        FROM jc_alert_called a
        where  a.is_delete=0
        AND a.coordinate_x IS NOT NULL
        AND a.coordinate_y IS NOT NULL
        <if test='par.status==0'>
            and  a.alert_status =0
        </if>
        <if test='par.status==1'>
            and  a.alert_status =1
        </if>
        <if test='par.address!=null and  par.address!="" '>
            and  a.address  like CONCAT('%',#{par.address},'%')
        </if>
        <if test='par.whether24!=false'>
            and  a.call_time &gt;= (NOW() - interval 24 hour)
        </if>
         ORDER BY  a.call_time DESC
        <if test='pageNum!=null and pageSize !=null'>
            limit #{pageNum},#{pageSize}
        </if>
    </select>


    <select id="alertCalledListByAlertStatusCount" resultType="Integer">
        SELECT
        COUNT(*)
        FROM jc_alert_called a
        where  a.is_delete=0
        AND a.coordinate_x IS NOT NULL
        AND a.coordinate_y IS NOT NULL
        <if test='par.status==0'>
            and  a.alert_status =0
        </if>
        <if test='par.status==1'>
            and  a.alert_status =1
        </if>
        <if test='par.address!=null and  par.address!="" '>
            and  a.address  like CONCAT('%',#{par.address},'%')
        </if>
        <if test='par.whether24!=false'>
            and  a.call_time &gt;= (NOW() - interval 24 hour)
        </if>

    </select>



    <select id="AlertCalledcountTime" resultType="Integer">

        select COUNT(*)  from jc_alert_called where is_delete=0

        <if test='type==1'>
        and YEAR(call_time)=YEAR(NOW())
        </if>
        <if test='type==2'>
        and DATE_FORMAT( call_time, '%Y%m' ) = DATE_FORMAT( CURDATE( ) , '%Y%m' )
        </if>
        <if test='type==3'>
        and to_days(call_time) = to_days(now());
        </if>
        <if test='type==4'>
        and TO_DAYS( NOW( ) ) - TO_DAYS( call_time) = 1
        </if>

    </select>


    <select id="getTodayAlertCalled" resultType="com.yeejoin.amos.boot.module.jcs.api.dto.AlertCalledTodyDto">

        select
            jc_alert_called.alarm_type alarmType,
            jc_alert_called.address,
            jc_alert_called.call_time  callTime
            from jc_alert_called where is_delete=0
           and to_days(call_time) = to_days(now())
           ORDER BY  call_time  DESC

    </select>


</mapper>
