From 1a287e90e648f6f8340e75f5793ebf3d92864fe0 Mon Sep 17 00:00:00 2001
From: ZhuDongming <773644075@qq.com>
Date: Mon, 19 Aug 2019 16:54:35 +0800
Subject: [PATCH] 合并sql并修改最大值最小值计算

---
 src/main/resources/mapper/HistoryMapper.xml |   45 +++------------------------------------------
 1 files changed, 3 insertions(+), 42 deletions(-)

diff --git a/src/main/resources/mapper/HistoryMapper.xml b/src/main/resources/mapper/HistoryMapper.xml
index dba7c1e..7aec033 100644
--- a/src/main/resources/mapper/HistoryMapper.xml
+++ b/src/main/resources/mapper/HistoryMapper.xml
@@ -175,7 +175,9 @@
         SELECT
         DATE_FORMAT(time,'%Y-%m-%d %H:%i') time,
         <foreach collection="sensorKeys" separator="," item="sensorKey">
-            AVG(h.value ->'$.${sensorKey}') AS '${sensorKey}'
+            AVG(h.value ->'$.${sensorKey}') AS '${sensorKey}',
+            MIN(cast(h.value ->'$.${sensorKey}' as decimal(11,5))) AS 'min${sensorKey}',
+            MAX(cast(h.value ->'$.${sensorKey}' as decimal(11,5))) AS 'max${sensorKey}'
         </foreach>
         FROM
         history h
@@ -192,45 +194,4 @@
         time
     </select>
 
-    <select id="getSensorDataTodayMin" resultType="java.util.LinkedHashMap">
-        SELECT
-        DATE_FORMAT(time,'%Y-%m-%d %H:%i') time,
-        <foreach collection="sensorKeys" separator="," item="sensorKey">
-            MIN(h.value ->'$.${sensorKey}') AS '${sensorKey}'
-        </foreach>
-        FROM
-        history h
-        <where>
-            <if test="mac!=null">
-                and h.mac=#{mac}
-            </if>
-            and h.time >= #{startTime}
-            and h.time <![CDATA[<=]]> #{endTime}
-        </where>
-        GROUP BY
-        DATE_FORMAT(time,'%Y-%m-%d %H:%i')
-        ORDER BY
-        time
-    </select>
-
-    <select id="getSensorDataTodayMax" resultType="java.util.LinkedHashMap">
-        SELECT
-        DATE_FORMAT(time,'%Y-%m-%d %H:%i') time,
-        <foreach collection="sensorKeys" separator="," item="sensorKey">
-            MAX(h.value ->'$.${sensorKey}') AS '${sensorKey}'
-        </foreach>
-        FROM
-        history h
-        <where>
-            <if test="mac!=null">
-                and h.mac=#{mac}
-            </if>
-            and h.time >= #{startTime}
-            and h.time <![CDATA[<=]]> #{endTime}
-        </where>
-        GROUP BY
-        DATE_FORMAT(time,'%Y-%m-%d %H:%i')
-        ORDER BY
-        time
-    </select>
 </mapper>
\ No newline at end of file

--
Gitblit v1.8.0