From cdec9062c85f52d43e8d74e82cbcf9f8606ebb01 Mon Sep 17 00:00:00 2001
From: jinpengyong <jpy123456>
Date: Tue, 30 Jan 2024 16:39:59 +0800
Subject: [PATCH] chore:设备在线率接口提交

---
 screen-api/src/main/resources/mapper/DeviceMapper.xml |   93 +++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 91 insertions(+), 2 deletions(-)

diff --git a/screen-api/src/main/resources/mapper/DeviceMapper.xml b/screen-api/src/main/resources/mapper/DeviceMapper.xml
index 48c7c3a..996b601 100644
--- a/screen-api/src/main/resources/mapper/DeviceMapper.xml
+++ b/screen-api/src/main/resources/mapper/DeviceMapper.xml
@@ -39,8 +39,8 @@
             <foreach collection="macs" item="mac" index="index" open="(" close=")" separator=",">
                 #{mac}
             </foreach>
-        AND `time` <![CDATA[>=]]> #{start}
-        AND `time` <![CDATA[<]]> #{end}
+        AND DATE_FORMAT(`time`,'%Y-%m-%d %H') <![CDATA[>=]]> #{start}
+        AND DATE_FORMAT(`time`,'%Y-%m-%d %H') <![CDATA[<]]> #{end}
         ORDER BY `time`
     </select>
     <select id="deviceList" resultType="java.util.Map">
@@ -188,4 +188,93 @@
                     i.is_delete = 0
             ) t3
     </select>
+    <select id="deviceMacs" resultType="java.lang.String">
+        select mac from device where organization_id = #{organizationId} order by id desc
+
+    </select>
+
+    <select id="getDevices" resultType="com.moral.api.pojo.vo.device.AppDeviceVo">
+        SELECT d.id,d.`name`,d.mac,d.special_type FROM device as d
+        where 1=1
+        <if test="organizationId !=null">
+            AND organization_id = #{organizationId}
+        </if>
+           and mac LIKE "%"#{mac}"%" or `name` like "%"#{mac}"%" AND is_delete = 0
+        union
+        SELECT sd.id,sd.`name`,sd.mac,sd.special_type FROM special_device  as sd
+        WHERE 1=1
+        <if test="organizationId !=null">
+            AND organization_id = #{organizationId}
+        </if>
+          and mac LIKE "%"#{mac}"%" AND is_delete = 0
+    </select>
+
+
+    <select id="getHeatMap" resultType="com.moral.api.pojo.dto.dataDisplay.HeatMapDTO">
+        SELECT
+        d.mac as mac,
+        d.latitude as lat,
+        d.longitude as lng,
+        d.name as name,
+        (hd.value ->> #{type} ) as count,
+        hd.time
+        FROM
+        device as d
+        inner JOIN organization o on o.id = d.organization_id and o.is_delete = 0
+        <if test="organizationIds != null and organizationIds.size !=0">
+            and organization_id in
+            <foreach collection="organizationIds" item="id" index="index" open="(" close=")" separator=",">
+                #{id}
+            </foreach>
+        </if>
+        <if test="tableName !=null">
+            RIGHT join history_hourly${tableName} hd on hd.time = #{start}  and d.mac = hd.mac
+        </if>
+        <if test="tableName ==null ">
+            RIGHT join history_daily hd on hd.time = #{start}   and d.mac = hd.mac
+        </if>
+        WHERE
+         d.is_delete = 0
+        order by d.mac
+    </select>
+
+
+    <select id="getHeatMapV1" resultType="com.moral.api.pojo.dto.dataDisplay.HeatMapDTO">
+        SELECT
+        d.mac as mac,
+        d.latitude as lat,
+        d.longitude as lng,
+        d.name as name,
+        (hd.value ->> #{type} ) as count,
+        hd.time,
+        dm.group_id AS groupId
+        FROM
+        device as d
+        inner JOIN organization o on o.id = d.organization_id and o.is_delete = 0
+        <if test="organizationIds != null and organizationIds.size !=0">
+            and organization_id in
+            <foreach collection="organizationIds" item="id" index="index" open="(" close=")" separator=",">
+                #{id}
+            </foreach>
+        </if>
+        inner JOIN device_map_hierarchy as dm on d.id = dm.device_id
+        <if test="tableName !=null">
+            left join history_hourly${tableName} hd on hd.time = #{start}  and d.mac = hd.mac
+        </if>
+        <if test="tableName ==null ">
+            left join history_daily hd on hd.time = #{start}   and d.mac = hd.mac
+        </if>
+        WHERE
+        d.is_delete = 0
+        order by d.mac
+    </select>
+
+
+    <select id="getPage" resultType="com.moral.api.vo.OnlineRateVo">
+        select d.name,d.state,d.mac from device as d where organization_id=#{organizationId}
+    </select>
+
+    <select id="getList" resultType="com.moral.api.vo.OnlineRateVo">
+        select d.name,d.state,d.mac from device as d where organization_id=#{organizationId}
+    </select>
 </mapper>
\ No newline at end of file

--
Gitblit v1.8.0