From b52c1e137107abbaee8cdea45964def25c952a7f Mon Sep 17 00:00:00 2001
From: xufenglei <xufenglei>
Date: Wed, 18 Apr 2018 09:01:55 +0800
Subject: [PATCH] 饼图 功能

---
 src/main/resources/mapper/HistoryMapper.xml |   24 ++++++++++--------------
 1 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/src/main/resources/mapper/HistoryMapper.xml b/src/main/resources/mapper/HistoryMapper.xml
index 2ca98f3..620c6e0 100644
--- a/src/main/resources/mapper/HistoryMapper.xml
+++ b/src/main/resources/mapper/HistoryMapper.xml
@@ -3,13 +3,12 @@
 <mapper namespace="com.moral.mapper.HistoryMapper">
 	<select id="getAreaAllDataByAccount" resultType="java.util.LinkedHashMap">
 		SELECT
-		<if test="macKey == 'all'">
-			${queryColumns}
-		</if>	
-		<if test="macKey != 'all'">
-			d.`name`,
-			AVG( h.`value` -> ${macKey}) avg
-		</if>	
+			<if test="macKey != null">
+				d.`name`,
+			</if>	
+			<foreach  collection="sensorKeys" separator="," item="sensorKey">
+				AVG(h.`value` ->'$.${sensorKey}[0]') AS '${sensorKey}'
+			</foreach>
 		FROM
 			history h,
 			device d,
@@ -18,20 +17,17 @@
 			mp.area_code = #{areaCode} 
 			AND h.time >= #{start} 
 			AND h.time &lt; #{end}
+			AND h.mac = d.mac 
+			AND d.monitor_point_id = mp.id 
 		<if test="orgIds != null and orgIds.size &gt; 0">
 			AND mp.organization_id IN
 			<foreach  collection="orgIds" open="(" separator="," close=")" item="listItem">
 				#{listItem}
 			</foreach>
 		</if>
-			AND h.mac = d.mac 
-			AND d.monitor_point_id = mp.id 
-		<if test="macKey != 'all'">
+		<if test="macKey != null">
 			GROUP BY d.id
-			ORDER BY avg desc
+			ORDER BY ${macKey} desc
 		</if>	
 	</select>
-	
-
-	
 </mapper>
\ No newline at end of file

--
Gitblit v1.8.0