<?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.equipmanage.mapper.EquipmentSystemSourceStatisticsMapper">

    <select id="getEquipmentSystemSourceStatisticsCount"
            resultType="com.yeejoin.equipmanage.common.entity.vo.MainIotMonitorItemVo">
        SELECT
        wlesst.id,
        wlws.id as sourceId,
        wlws.name title,
        wlesst.status status,
         ( select id from wl_equipment_specific_alarm
            where equipment_specific_id =  wlesst.equipment_specific_id
          order by confirm_type asc,equipment_specific_index_key desc,create_date desc
            limit 1) as alamId,
        ( select confirm_type from wl_equipment_specific_alarm
            where equipment_specific_id =  wlesst.equipment_specific_id
            order by confirm_type asc,equipment_specific_index_key desc,create_date desc
            limit 1) as confirmType,
       ( select create_date from wl_equipment_specific_alarm
        where equipment_specific_id =  wlesst.equipment_specific_id
        order by confirm_type asc,equipment_specific_index_key desc,create_date desc
        limit 1) as `time`
        FROM
            wl_equipment_system_source_statistics wlesst
            LEFT JOIN f_fire_fighting_system fffs ON find_in_set(fffs.id,wlesst.system_id)
            left join wl_warehouse_structure wlws on wlesst.source_id = wlws.id
            left join wl_equipment_specific_alarm as ala on ala.equipment_specific_id  = wlesst.equipment_specific_id
            where fffs.id=#{id}
--             group by sourceId
            order by  wlesst.update_time desc
    </select>
    <select id="getEquipmentAlarmSystemList" resultType="com.yeejoin.equipmanage.common.entity.vo.MainIotMonitorItemVo">
        SELECT
            wlesst.id,
            wlesst.equipment_specific_id AS speId,
            wlws.id AS sourceId,
            wlws.NAME title,
            wlesst.`status`,
            ( SELECT id FROM wl_equipment_specific_alarm WHERE equipment_specific_id = wlesst.equipment_specific_id ORDER BY confirm_type ASC, equipment_specific_index_key DESC, create_date DESC LIMIT 1 ) AS alamId,
            ( SELECT confirm_type FROM wl_equipment_specific_alarm WHERE equipment_specific_id = wlesst.equipment_specific_id ORDER BY confirm_type ASC, equipment_specific_index_key DESC, create_date DESC LIMIT 1 ) AS confirmType
        FROM
            wl_equipment_system_source_statistics wlesst
            LEFT JOIN f_fire_fighting_system fffs ON find_in_set(fffs.id,wlesst.system_id)
            LEFT JOIN wl_warehouse_structure wlws ON wlesst.source_id = wlws.id
            LEFT JOIN wl_equipment_specific_alarm AS ala ON ala.equipment_specific_id = wlesst.equipment_specific_id
        WHERE wlesst.source_id=#{areaId}
            and wlesst.system_id=#{systemId}
        ORDER BY
            wlesst.update_time DESC
    </select>
    <select id="getBingspeId" resultType="String">
        select point_in_scene from wl_source_scene where source_id =#{id}
    </select>
</mapper>
