From 6050927edf6c00f2f06b0b0775502d38eb5b7705 Mon Sep 17 00:00:00 2001
From: jinpengyong <jpy123456>
Date: Thu, 25 Nov 2021 13:37:37 +0800
Subject: [PATCH] 陆家设备因子浓度报警邮件

---
 src/main/resources/mapper/HistoryHourlyMapper.xml |   53 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 50 insertions(+), 3 deletions(-)

diff --git a/src/main/resources/mapper/HistoryHourlyMapper.xml b/src/main/resources/mapper/HistoryHourlyMapper.xml
index d380d68..169573f 100644
--- a/src/main/resources/mapper/HistoryHourlyMapper.xml
+++ b/src/main/resources/mapper/HistoryHourlyMapper.xml
@@ -15,9 +15,25 @@
         SELECT
         h.mac,
         <foreach collection="sensorKeys" separator="," item="sensorKey">
-            AVG(json->'$.${sensorKey}[0]') AS '${sensorKey}',
-            MIN(json->'$.${sensorKey}[1]') AS 'MIN${sensorKey}',
-            MAX(json->'$.${sensorKey}[2]') AS 'MAX${sensorKey}'
+            <choose >
+                <when test="sensorKey=='e23'">
+                    ROUND((CASE    WHEN AVG(json->'$.e18[0]'*SIN((json->'$.e23[0]'/180)*PI()))<![CDATA[>]]>0 AND AVG(json->'$.e18[0]'*COS((json->'$.e23[0]'/180)*PI()))<![CDATA[>]]>0
+                    THEN ATAN(AVG(json->'$.e18[0]'*SIN((json->'$.e23[0]'/180)*PI()))/AVG(json->'$.e18[0]'*COS((json->'$.e23[0]'/180)*PI())))*180/PI()
+                    WHEN AVG(json->'$.e18[0]'*SIN((json->'$.e23[0]'/180)*PI()))>0 AND AVG(json->'$.e18[0]'*COS((json->'$.e23[0]'/180)*PI()))<![CDATA[<]]>0
+                    THEN (ATAN(AVG(json->'$.e18[0]'*SIN((json->'$.e23[0]'/180)*PI()))/AVG(json->'$.e18[0]'*COS((json->'$.e23[0]'/180)*PI())))*180/PI())+180
+                    WHEN AVG(json->'$.e18[0]'*SIN((json->'$.e23[0]'/180)*PI()))<![CDATA[<]]>0 AND AVG(json->'$.e18[0]'*COS((json->'$.e23[0]'/180)*PI()))<![CDATA[<]]>0
+                    THEN (ATAN(AVG(json->'$.e18[0]'*SIN((json->'$.e23[0]'/180)*PI()))/AVG(json->'$.e18[0]'*COS((json->'$.e23[0]'/180)*PI())))*180/PI())+180
+                    ELSE (ATAN(AVG(json->'$.e18[0]'*SIN((json->'$.e23[0]'/180)*PI()))/AVG(json->'$.e18[0]'*COS((json->'$.e23[0]'/180)*PI())))*180/PI())+360
+                    END),3) AS '${sensorKey}',
+                    MIN(json->'$.${sensorKey}[1]') AS 'MIN${sensorKey}',
+                    MAX(json->'$.${sensorKey}[2]') AS 'MAX${sensorKey}'
+                </when>
+                <otherwise>
+                    AVG(json->'$.${sensorKey}[0]') AS '${sensorKey}',
+                    MIN(json->'$.${sensorKey}[1]') AS 'MIN${sensorKey}',
+                    MAX(json->'$.${sensorKey}[2]') AS 'MAX${sensorKey}'
+                </otherwise>
+            </choose>
         </foreach>
         FROM
         history_hourly h
@@ -63,4 +79,35 @@
         </foreach>
     </insert>
 
+    <select id="getBeamByMacs" resultType="java.util.Map">
+        SELECT
+        DATE_FORMAT(h.time,#{typeFormat}) time,
+        avg(h.json->'$.e12[0]') 'beam'
+        FROM history_hourly h
+        WHERE h.json->'$.e12[0]' is not null
+        and h.mac in
+        <foreach collection="macs" open="(" separator="," close=")" item="mac">
+            #{mac}
+        </foreach>
+        and h.time in
+        <foreach collection="times" open="(" separator="," close=")" item="time">
+            #{time}
+        </foreach>
+        group by h.time
+    </select>
+
+    <select id="selectCountByMac" resultType="java.lang.Integer">
+        SELECT count(1) FROM history_hourly
+        WHERE mac = #{mac}
+        AND `time` >= #{start}
+        AND `time` <![CDATA[<]]> #{end}
+    </select>
+
+    <select id="selectDataByMac" resultType="java.lang.String">
+        select
+        json
+        from history_hourly
+        where mac = #{mac}
+        and `time` = #{time}
+    </select>
 </mapper>
\ No newline at end of file

--
Gitblit v1.8.0