From 106dbe94a4bcfc90fc646b0a1e017e23ad2b058b Mon Sep 17 00:00:00 2001
From: xufenglei <xufenglei>
Date: Mon, 07 May 2018 15:15:04 +0800
Subject: [PATCH] 三级警报数据

---
 src/main/resources/mapper/HistoryMapper.xml |   32 +++++++++++++++-----------------
 1 files changed, 15 insertions(+), 17 deletions(-)

diff --git a/src/main/resources/mapper/HistoryMapper.xml b/src/main/resources/mapper/HistoryMapper.xml
index 2527cdf..f7c82a8 100644
--- a/src/main/resources/mapper/HistoryMapper.xml
+++ b/src/main/resources/mapper/HistoryMapper.xml
@@ -1,15 +1,19 @@
 <?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.moral.mapper.HistoryMapper">
-	<select id="getAreaAllDataByAccount" resultType="java.util.LinkedHashMap">
+<mapper namespace="com.moral.mapper.HistoryMapper">
+	<select id="selectValueByMacAndTime" resultType="java.lang.String">
+		select `value` from history
+		where  time = #{time} and mac = #{mac}
+		limit 0,1
+	</select>
+	<select id="getAreaAllDataByAccount" resultType="java.util.Map">
 		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,
@@ -26,15 +30,9 @@
 				#{listItem}
 			</foreach>
 		</if>
-		<if test="deviceVersionId != null">
-			AND d.device_version_id = #{deviceVersionId} 
-		</if>
-		<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