From f99abcd94998485854ca18f149fecc33c24bf5de Mon Sep 17 00:00:00 2001
From: lizijie <lzjiiie@163.com>
Date: Fri, 20 Nov 2020 14:10:25 +0800
Subject: [PATCH] 校准值插入redis
---
src/main/resources/mapper/HistoryMinutelyMapper.xml | 24 ++++++++++++++++++++----
1 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/src/main/resources/mapper/HistoryMinutelyMapper.xml b/src/main/resources/mapper/HistoryMinutelyMapper.xml
index 79f0172..8512a8c 100644
--- a/src/main/resources/mapper/HistoryMinutelyMapper.xml
+++ b/src/main/resources/mapper/HistoryMinutelyMapper.xml
@@ -11,7 +11,7 @@
</foreach>
</insert>
<update id="createHistoryMinutelyTable">
- CREATE TABLE `history_minutely_${yearAndMonth}` (
+ CREATE TABLE IF NOT EXISTS `history_minutely_${yearAndMonth}` (
`mac` varchar(20) CHARACTER SET latin1 DEFAULT NULL,
`time` datetime DEFAULT NULL,
`json` json DEFAULT NULL,
@@ -25,9 +25,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_minutely_${yearAndMonth} h
--
Gitblit v1.8.0