<?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.jxiop.biz.mapper2.AlarmEventMapper">

    <select id="getAlarmEventList" resultType="com.yeejoin.amos.boot.module.jxiop.biz.dto.AlarmEventDto">
        select
        station_name as stationName,
        event_desc as    eventDesc,
        alarm_group_name as alarmGroupName,
        event_time as  eventTime,
        (case event_movement
        WHEN 'true'	then '告警'
        WHEN 'false'	then '恢复'
        ELSE event_movement end  ) as  eventMovement
        from
        fault_alarm_event
        <where>
            <if test="gatewayId != null and gatewayId != ''">
                gateway_id = #{gatewayId}
            </if>
            <if test="stationId != null and stationId != ''">
                station_id = #{stationId}
            </if>
        </where>
        order by event_time desc
    </select>


    <select id="getLastDataBySort" resultType="java.lang.String">
        select
        sort
        from
        fault_alarm_event
        <where>
            <if test="gatewayId != null and gatewayId != ''">
                gateway_id = #{gatewayId}
            </if>
        </where>
        order by sort desc limit 1
    </select>


    <select id="getOldAlarmsBySort" resultType="java.lang.String">
        select
           event_desc
        from
            fault_alarm_event
        where
            gateway_id = #{gatewayId} and sort = #{sort}

    </select>
</mapper>
