From 7756a8fda1e55ceb52a4b87c963ac4529ce2e6e7 Mon Sep 17 00:00:00 2001
From: jinpengyong <jpy123456>
Date: Wed, 03 Jun 2020 10:36:25 +0800
Subject: [PATCH] alarm_daily统计任务更新

---
 src/main/resources/mapper/AlarmMapper.xml |   22 +++++++---------------
 1 files changed, 7 insertions(+), 15 deletions(-)

diff --git a/src/main/resources/mapper/AlarmMapper.xml b/src/main/resources/mapper/AlarmMapper.xml
index 210ab59..7a7c6b0 100644
--- a/src/main/resources/mapper/AlarmMapper.xml
+++ b/src/main/resources/mapper/AlarmMapper.xml
@@ -1,25 +1,17 @@
 <?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.AlarmMapper">
-    <select id="getAvgAlarmData" resultType="java.util.LinkedHashMap">
+    <select id="getAlarmData" resultType="java.util.LinkedHashMap">
         SELECT
-        a.mac,
-        max(a.state) state
+        mac
         <foreach collection="sensorKeys" open="," separator="," item="sensorKey">
-            AVG(a.json->'$.${sensorKey}[0]') AS '${sensorKey}'
+            json->'$.${sensorKey}[0]' AS '${sensorKey}'
         </foreach>
         FROM
-        alarm_${yearAndMonth} a
+        alarm_${yearAndMonth}
         WHERE
-        a.time >= #{start}
-        AND a.time <![CDATA[<]]> #{end}
-        AND a.mac in
-        <foreach collection="macs" open="(" separator="," close=")"
-                 item="mac">
-            #{mac}
-        </foreach>
-        group by
-        a.mac
+        time >= #{start}
+        AND time <![CDATA[<]]> #{end}
     </select>
 
     <insert id="insertAlarmDaily">
@@ -32,7 +24,7 @@
     </insert>
 
     <update id="createTable">
-        CREATE TABLE `alarm_${yearAndMonth}` (
+        CREATE TABLE IF NOT EXISTS `alarm_${yearAndMonth}` (
         `mac` varchar(20) CHARACTER SET utf8 DEFAULT NULL,
         `json` json DEFAULT NULL,
         `state` int(2) DEFAULT NULL,

--
Gitblit v1.8.0