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


     <select id="getAlarmEventList" resultType="com.yeejoin.amos.boot.module.jxiop.biz.dto.EquipAlarmEventDto">
        SELECT
	     * 
        FROM
	    equip_alarm_event a
	    JOIN ( SELECT sequence_nbr FROM equip_alarm_event 
	    <where>
	        <if test="gatewayId != null and gatewayId != ''">
	           AND gateway_id = #{gatewayId}
	        </if>
            <if test="equipIndex!= null and equipIndex != ''">
               AND equip_index = #{equipIndex}
            </if>
            <if test="frontModule!= null and frontModule != ''">
               AND front_module = #{frontModule}
            </if>
            AND #{time} &lt;= created_time
        </where>
	    ORDER BY created_time DESC LIMIT #{current}, #{size} ) b ON a.sequence_nbr = b.sequence_nbr
    </select>



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

    <select id="getOldDataBySort" resultType="com.yeejoin.amos.boot.module.jxiop.biz.entity.EquipAlarmEvent">
        select
        *
        from
        equip_alarm_event
        <where>
            <if test="sort != null and sort != ''">
                sort = #{sort}
            </if>
            AND gateway_id = #{gatewayId}
        </where>
    </select>
</mapper>
