From 3a46aae0a8e9e4bd3cb8dcd1185a69a74668995b Mon Sep 17 00:00:00 2001
From: kaiyu <404897439@qq.com>
Date: Tue, 15 Dec 2020 14:08:47 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 src/main/resources/mapper/HistoryMinutelyMapper.xml |   68 ++++++++++++++++++++++++++++++++++
 1 files changed, 68 insertions(+), 0 deletions(-)

diff --git a/src/main/resources/mapper/HistoryMinutelyMapper.xml b/src/main/resources/mapper/HistoryMinutelyMapper.xml
index ac1e709..252008c 100644
--- a/src/main/resources/mapper/HistoryMinutelyMapper.xml
+++ b/src/main/resources/mapper/HistoryMinutelyMapper.xml
@@ -268,4 +268,72 @@
         order by rs.monitorPointName
     </select>
 
+    <select id="get5MiutesOrHalfHourByDay" resultType="java.util.LinkedHashMap">
+        SELECT
+        <foreach collection="sensorKeys" separator="," item="sensorKey">
+            AVG(h.json->'$.${sensorKey}[0]') AS '${sensorKey}'
+        </foreach>
+        FROM
+        history_${timeUnits} h inner join
+        (select mac from device where monitor_point_id in
+        (
+        select id from monitor_point
+        where
+        <if test="areaCode != null">
+            area_code = #{areaCode}
+        </if>
+
+        <if test="cityCode != null">
+            city_code = #{cityCode}
+        </if>
+
+        <if test="provinceCode != null">
+            province_code = #{provinceCode}
+        </if>
+        )
+        and is_delete=0) m
+        on h.mac=m.mac
+        and h.time>=#{start}
+        and h.time <![CDATA[<]]> #{end}
+        ORDER BY
+        h.time
+    </select>
+
+    <select id="getMultiDeviceSensorData" resultType="java.util.Map">
+        SELECT
+        DATE_FORMAT(time, #{typeFormat}) time,
+        <foreach collection="macs" separator="," item="mac" index="index">
+            AVG(json->'$.${sensorKey}[0]') AS '${index}${sensorKey}'
+        </foreach>
+        FROM
+        history_${timeUnits}
+        WHERE
+        <foreach collection="macs" separator="," item="mac" index="index">
+            mac = #{mac}
+        </foreach>
+        AND time >= #{start}
+        AND h.time <![CDATA[<]]> #{end}
+        GROUP BY
+        DATE_FORMAT(time, #{typeFormat})
+        ORDER BY
+        time
+    </select>
+
+    <select id="getMultiDeviceSensorData1" resultType="java.util.Map">
+        SELECT *
+        from
+        <foreach collection="macs" separator="," item="mac" index="index">
+            (SELECT
+            AVG(json->'$.${sensorKey}[0]') AS '${index}${sensorKey}',
+            DATE_FORMAT(time,'%Y-%m') as time
+            FROM history_${timeUnits}
+            WHERE mac=#{mac}
+            AND time >= #{start}
+            AND time <![CDATA[<]]> #{end}
+            GROUP BY DATE_FORMAT(time,#{typeFormat})
+            ORDER BY
+            time) as t${index}
+        </foreach>
+        WHERE t1.time=t2.time
+    </select>
 </mapper>

--
Gitblit v1.8.0