From 1b690930edcb3a2c1a0fc7de3fff1b352ca4597c Mon Sep 17 00:00:00 2001
From: 沈斌 <bluelazysb@hotmail.com>
Date: Mon, 30 Oct 2017 15:16:57 +0800
Subject: [PATCH] 代码更新

---
 src/main/resources/mapper/HistoryEntityMapper.xml |   42 ++++++++++++++++++------------------------
 1 files changed, 18 insertions(+), 24 deletions(-)

diff --git a/src/main/resources/mapper/HistoryEntityMapper.xml b/src/main/resources/mapper/HistoryEntityMapper.xml
index 5df5dd4..956888a 100644
--- a/src/main/resources/mapper/HistoryEntityMapper.xml
+++ b/src/main/resources/mapper/HistoryEntityMapper.xml
@@ -227,7 +227,7 @@
   </update>
   <select id="getMonthAverageBySensor" resultType="map">
 		SELECT
-			AVG(mac_value) monthAverage
+			AVG(mac_value) average
 		FROM
 			history
 		WHERE
@@ -238,7 +238,6 @@
   </select>
 
 	<select id="getAverageByAll" resultType="map">
-<!-- 
 		SELECT
 			h.mac_key,
 			AVG(h.mac_value) avg
@@ -261,31 +260,26 @@
 		AND h.time &lt; #{end}
 		GROUP BY
 			h.mac_key
- -->
+	</select>
 
+	<select id="getEquipmentStates" resultType="map">
 		SELECT
-			mac_key,
-			AVG(mac_value) avg
+			COUNT(state) count,
+			state
 		FROM
-			history h
-			<if test="orgIds!=null and orgIds.size > 0">
-				JOIN (
-					SELECT
-						e.mac
-					FROM
-						equipment e,
-						org_equ oe
-					WHERE
-						e.id = oe.equid
-					AND oe.orgid IN
-					<foreach collection="orgIds" item="listItem" open="(" separator="," close=")" >
-						#{listItem}
-					</foreach>
-				) e ON h.mac = e.mac
-			</if>
-			WHERE h.time &gt; #{start}
-			AND h.time &lt; #{end}
+			equipment
+		<if test="orgIds != null and orgIds.size > 0">
+			JOIN org_equ oe ON e.id = oe.equid
+			AND oe.orgid IN
+			<foreach collection="orgIds" item="listItem" open="(" separator="," close=")" >
+				#{listItem}
+			</foreach>
+		</if>
 		GROUP BY
-			mac_key
+			state
+	</select>
+
+	<select id="getMacLogByLast" resultType="string">
+		SELECT mac_log FROM logger ORDER BY time DESC LIMIT 1
 	</select>
 </mapper>
\ No newline at end of file

--
Gitblit v1.8.0