<?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.ruoyi.system.mapper.So2Mapper">

    <select id="queryDeviceStatic" resultType="java.util.Map">
        select t1.name point, count(d.id) count
        from monitor_point t1
            left join device d
        on t1.id = d.monitor_point_id
        where d.type = 0
        group by t1.id;
    </select>

    <select id="queryDeviceCount" resultType="java.lang.Integer">
        select count(1)
        from device
        where type = 0
    </select>

    <select id="queryDeviceList" resultType="com.ruoyi.system.domain.DeviceBo">
        select d.id                                 as deviceId,
               d.name                               as name,
               '光谱'                                 as deviceType,
               t1.name                                 monitorName,
               case online_status
                   when 0 then '在线'
                   when 1 then '离线'
                   end                                 status,
               CONCAT(d.longitude, ',', d.latitude) as latilongti,
               update_time                          as updateTime,
               'so2_alert'                          as source
        from device d
                 left join monitor_point t1
                           on t1.id = d.monitor_point_id
        where d.type = 0
    </select>

    <select id="queryById" resultType="java.util.Map">
        select id,
               monitor_point_id                              monitorPointId,
               mmsi,
               no2_concentration                             no2Concentration,
               so2_concentration                             so2Concentration,
               co2_concentration                             co2Concentration,
               so2_percent                                   so2Percent,
               device_id                                     deviceId,
               date_format(create_time, '%Y-%m-%d %H:%i:%s') createTime
        from common_record
        where id = #{id}
    </select>
</mapper>