From 81dc94a70de69f45f42b8ca4b702a3a372cf81ac Mon Sep 17 00:00:00 2001
From: lizijie <lzjiiie@163.com>
Date: Tue, 24 May 2022 09:59:07 +0800
Subject: [PATCH] 去除打印
---
src/main/resources/mapper/HistoryMapper.xml | 322 +++++++++++++++++++++++++++++++++++++++--------------
1 files changed, 238 insertions(+), 84 deletions(-)
diff --git a/src/main/resources/mapper/HistoryMapper.xml b/src/main/resources/mapper/HistoryMapper.xml
index d357d6b..aa4967d 100644
--- a/src/main/resources/mapper/HistoryMapper.xml
+++ b/src/main/resources/mapper/HistoryMapper.xml
@@ -1,97 +1,113 @@
<?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">
- <resultMap id="BaseResultMap" type="com.moral.entity.History">
- <result column="mac" jdbcType="VARCHAR" property="mac" />
- <result column="value" jdbcType="OTHER" property="value" />
- <result column="time" jdbcType="TIMESTAMP" property="time" />
- <result column="version" jdbcType="INTEGER" property="version" />
- </resultMap>
- <insert id="insert" parameterType="com.moral.entity.History">
+ <resultMap id="BaseResultMap" type="com.moral.entity.History">
+ <result column="mac" jdbcType="VARCHAR" property="mac"/>
+ <result column="value" jdbcType="OTHER" property="value"/>
+ <result column="time" jdbcType="TIMESTAMP" property="time"/>
+ <result column="version" jdbcType="INTEGER" property="version"/>
+ </resultMap>
+ <insert id="insert" parameterType="com.moral.entity.History">
insert into history (mac, value, time,
version)
values (#{mac,jdbcType=VARCHAR}, #{value,jdbcType=OTHER}, #{time,jdbcType=TIMESTAMP},
#{version,jdbcType=INTEGER})
</insert>
- <insert id="insertSelective" parameterType="com.moral.entity.History">
- insert into history
- <trim prefix="(" suffix=")" suffixOverrides=",">
- <if test="mac != null">
- mac,
- </if>
- <if test="value != null">
- value,
- </if>
- <if test="time != null">
- time,
- </if>
- <if test="version != null">
- version,
- </if>
- </trim>
- <trim prefix="values (" suffix=")" suffixOverrides=",">
- <if test="mac != null">
- #{mac,jdbcType=VARCHAR},
- </if>
- <if test="value != null">
- #{value,jdbcType=OTHER},
- </if>
- <if test="time != null">
- #{time,jdbcType=TIMESTAMP},
- </if>
- <if test="version != null">
- #{version,jdbcType=INTEGER},
- </if>
- </trim>
- </insert>
- <select id="getAvgData" resultType="java.util.Map">
- SELECT
- <foreach collection="sensorKeys" separator="," item="sensorKey">
- AVG(value->'$.${sensorKey}') AS '${sensorKey}'
- </foreach>
- FROM
- history h
- WHERE
- h.time >= #{start}
- AND h.time <![CDATA[<]]> #{end}
- AND h.mac = #{mac}
- </select>
- <select id="getMaxAndMinData" resultType="java.util.Map">
- SELECT
- <foreach collection="sensorKeys" separator="," item="sensorKey">
- max(cast(h.value ->'$.${sensorKey}' as decimal(11,3))) AS 'max${sensorKey}',
- MIN(cast(h.value ->'$.${sensorKey}' as decimal(11,3))) AS 'min${sensorKey}'
- </foreach>
- FROM
- history h
- WHERE
- h.time >= #{start}
- AND h.time <![CDATA[<]]> #{end}
- AND h.mac = #{mac}
- </select>
- <select id="getMinData" resultType="java.util.Map">
- SELECT
- <foreach collection="sensorKeys" separator="," item="sensorKey">
- MIN(value->'$.${sensorKey}') AS '${sensorKey}'
- </foreach>
- FROM
- history h
- WHERE
- h.time >= #{start}
- AND h.time <![CDATA[<]]> #{end}
- AND h.mac = #{mac}
- </select>
+ <insert id="insertSelective" parameterType="com.moral.entity.History">
+ insert into history
+ <trim prefix="(" suffix=")" suffixOverrides=",">
+ <if test="mac != null">
+ mac,
+ </if>
+ <if test="value != null">
+ value,
+ </if>
+ <if test="time != null">
+ time,
+ </if>
+ <if test="version != null">
+ version,
+ </if>
+ </trim>
+ <trim prefix="values (" suffix=")" suffixOverrides=",">
+ <if test="mac != null">
+ #{mac,jdbcType=VARCHAR},
+ </if>
+ <if test="value != null">
+ #{value,jdbcType=OTHER},
+ </if>
+ <if test="time != null">
+ #{time,jdbcType=TIMESTAMP},
+ </if>
+ <if test="version != null">
+ #{version,jdbcType=INTEGER},
+ </if>
+ </trim>
+ </insert>
+ <select id="getAvgData" resultType="java.util.Map">
+ SELECT
+ <foreach collection="sensorKeys" separator="," item="sensorKey">
+ AVG(value->'$.${sensorKey}') AS '${sensorKey}'
+ </foreach>
+ FROM
+ history h
+ WHERE
+ h.time >= #{start}
+ AND h.time <![CDATA[<]]> #{end}
+ AND h.mac = #{mac}
+ </select>
+ <select id="getMaxAndMinData" resultType="java.util.Map">
+ SELECT
+ <foreach collection="sensorKeys" separator="," item="sensorKey">
+ max(cast(h.value ->'$.${sensorKey}' as decimal(11,3))) AS 'max${sensorKey}',
+ MIN(cast(h.value ->'$.${sensorKey}' as decimal(11,3))) AS 'min${sensorKey}'
+ </foreach>
+ FROM
+ history h
+ WHERE
+ h.time >= #{start}
+ AND h.time <![CDATA[<]]> #{end}
+ AND h.mac = #{mac}
+ </select>
+ <select id="getMinData" resultType="java.util.Map">
+ SELECT
+ <foreach collection="sensorKeys" separator="," item="sensorKey">
+ MIN(value->'$.${sensorKey}') AS '${sensorKey}'
+ </foreach>
+ FROM
+ history h
+ WHERE
+ h.time >= #{start}
+ AND h.time <![CDATA[<]]> #{end}
+ AND h.mac = #{mac}
+ </select>
<select id="getSensorData" resultType="java.util.LinkedHashMap">
SELECT
h.mac,
- <foreach collection="sensorKeys" separator="," item="sensorKey">
- AVG(value->'$.${sensorKey}') AS '${sensorKey}',
- MAX(cast(h.value ->'$.${sensorKey}' as decimal(11,3))) AS 'MAX${sensorKey}',
- MIN(cast(h.value ->'$.${sensorKey}' as decimal(11,3))) AS 'MIN${sensorKey}'
+ <foreach collection="sensorKeys" separator="," item="sensorKey">
+ <choose >
+ <when test="sensorKey=='e23'">
+ ROUND((CASE WHEN AVG(value->'$.e18'*SIN((value->'$.e23'/180)*PI()))<![CDATA[>]]>0 AND AVG(value->'$.e18'*COS((value->'$.e23'/180)*PI()))<![CDATA[>]]>0
+ THEN ATAN(AVG(value->'$.e18'*SIN((value->'$.e23'/180)*PI()))/AVG(value->'$.e18'*COS((value->'$.e23'/180)*PI())))*180/PI()
+ WHEN AVG(value->'$.e18'*SIN((value->'$.e23'/180)*PI()))>0 AND AVG(value->'$.e18'*COS((value->'$.e23'/180)*PI()))<![CDATA[<]]>0
+ THEN (ATAN(AVG(value->'$.e18'*SIN((value->'$.e23'/180)*PI()))/AVG(value->'$.e18'*COS((value->'$.e23'/180)*PI())))*180/PI())+180
+ WHEN AVG(value->'$.e18'*SIN((value->'$.e23'/180)*PI()))<![CDATA[<]]>0 AND AVG(value->'$.e18'*COS((value->'$.e23'/180)*PI()))<![CDATA[<]]>0
+ THEN (ATAN(AVG(value->'$.e18'*SIN((value->'$.e23'/180)*PI()))/AVG(value->'$.e18'*COS((value->'$.e23'/180)*PI())))*180/PI())+180
+ ELSE (ATAN(AVG(value->'$.e18'*SIN((value->'$.e23'/180)*PI()))/AVG(value->'$.e18'*COS((value->'$.e23'/180)*PI())))*180/PI())+360
+ END),3) AS '${sensorKey}',
+ MAX(cast(h.value ->'$.${sensorKey}' as decimal(11,3))) AS 'MAX${sensorKey}',
+ MIN(cast(h.value ->'$.${sensorKey}' as decimal(11,3))) AS 'MIN${sensorKey}'
+ </when>
+ <otherwise>
+ AVG(value->'$.${sensorKey}') AS '${sensorKey}',
+ MAX(cast(h.value ->'$.${sensorKey}' as decimal(11,3))) AS 'MAX${sensorKey}',
+ MIN(cast(h.value ->'$.${sensorKey}' as decimal(11,3))) AS 'MIN${sensorKey}'
+ </otherwise>
+ </choose>
</foreach>
FROM
- history h
+ history_${yearAndMonthDay} h
WHERE
h.time >= #{start}
AND h.time <![CDATA[<]]> #{end}
@@ -99,13 +115,103 @@
h.mac
</select>
+ <select id="getSensorDataByMac" resultType="java.util.LinkedHashMap">
+ SELECT
+ h.mac,
+ <foreach collection="sensorKeys" separator="," item="sensorKey">
+ <choose >
+ <when test="sensorKey=='e23'">
+ ROUND((CASE WHEN AVG(value->'$.e18'*SIN((value->'$.e23'/180)*PI()))<![CDATA[>]]>0 AND AVG(value->'$.e18'*COS((value->'$.e23'/180)*PI()))<![CDATA[>]]>0
+ THEN ATAN(AVG(value->'$.e18'*SIN((value->'$.e23'/180)*PI()))/AVG(value->'$.e18'*COS((value->'$.e23'/180)*PI())))*180/PI()
+ WHEN AVG(value->'$.e18'*SIN((value->'$.e23'/180)*PI()))>0 AND AVG(value->'$.e18'*COS((value->'$.e23'/180)*PI()))<![CDATA[<]]>0
+ THEN (ATAN(AVG(value->'$.e18'*SIN((value->'$.e23'/180)*PI()))/AVG(value->'$.e18'*COS((value->'$.e23'/180)*PI())))*180/PI())+180
+ WHEN AVG(value->'$.e18'*SIN((value->'$.e23'/180)*PI()))<![CDATA[<]]>0 AND AVG(value->'$.e18'*COS((value->'$.e23'/180)*PI()))<![CDATA[<]]>0
+ THEN (ATAN(AVG(value->'$.e18'*SIN((value->'$.e23'/180)*PI()))/AVG(value->'$.e18'*COS((value->'$.e23'/180)*PI())))*180/PI())+180
+ ELSE (ATAN(AVG(value->'$.e18'*SIN((value->'$.e23'/180)*PI()))/AVG(value->'$.e18'*COS((value->'$.e23'/180)*PI())))*180/PI())+360
+ END),3) AS '${sensorKey}',
+ MAX(cast(h.value ->'$.${sensorKey}' as decimal(11,3))) AS 'MAX${sensorKey}',
+ MIN(cast(h.value ->'$.${sensorKey}' as decimal(11,3))) AS 'MIN${sensorKey}'
+ </when>
+ <otherwise>
+ AVG(value->'$.${sensorKey}') AS '${sensorKey}',
+ MAX(cast(h.value ->'$.${sensorKey}' as decimal(11,3))) AS 'MAX${sensorKey}',
+ MIN(cast(h.value ->'$.${sensorKey}' as decimal(11,3))) AS 'MIN${sensorKey}'
+ </otherwise>
+ </choose>
+ </foreach>
+ FROM
+ history h
+ WHERE
+ h.time >= #{start}
+ AND h.time <![CDATA[<]]> #{end}
+ and h.mac in
+ <foreach collection="macList" index="index" item="mac" open="(" separator="," close=")">
+ #{mac}
+ </foreach>
+ group by
+ h.mac
+ </select>
+
+ <select id="getSensorDataByMacOnce" resultType="java.util.LinkedHashMap">
+ SELECT
+ h.mac,DATE_FORMAT(time,'%Y-%m-%dT%H:%i') time,
+ <foreach collection="sensorKeys" separator="," item="sensorKey">
+ <choose >
+ <when test="sensorKey=='e23'">
+ ROUND((CASE WHEN AVG(value->'$.e18'*SIN((value->'$.e23'/180)*PI()))<![CDATA[>]]>0 AND AVG(value->'$.e18'*COS((value->'$.e23'/180)*PI()))<![CDATA[>]]>0
+ THEN ATAN(AVG(value->'$.e18'*SIN((value->'$.e23'/180)*PI()))/AVG(value->'$.e18'*COS((value->'$.e23'/180)*PI())))*180/PI()
+ WHEN AVG(value->'$.e18'*SIN((value->'$.e23'/180)*PI()))>0 AND AVG(value->'$.e18'*COS((value->'$.e23'/180)*PI()))<![CDATA[<]]>0
+ THEN (ATAN(AVG(value->'$.e18'*SIN((value->'$.e23'/180)*PI()))/AVG(value->'$.e18'*COS((value->'$.e23'/180)*PI())))*180/PI())+180
+ WHEN AVG(value->'$.e18'*SIN((value->'$.e23'/180)*PI()))<![CDATA[<]]>0 AND AVG(value->'$.e18'*COS((value->'$.e23'/180)*PI()))<![CDATA[<]]>0
+ THEN (ATAN(AVG(value->'$.e18'*SIN((value->'$.e23'/180)*PI()))/AVG(value->'$.e18'*COS((value->'$.e23'/180)*PI())))*180/PI())+180
+ ELSE (ATAN(AVG(value->'$.e18'*SIN((value->'$.e23'/180)*PI()))/AVG(value->'$.e18'*COS((value->'$.e23'/180)*PI())))*180/PI())+360
+ END),3) AS '${sensorKey}',
+ MAX(cast(h.value ->'$.${sensorKey}' as decimal(11,3))) AS 'MAX${sensorKey}',
+ MIN(cast(h.value ->'$.${sensorKey}' as decimal(11,3))) AS 'MIN${sensorKey}'
+ </when>
+ <otherwise>
+ AVG(value->'$.${sensorKey}') AS '${sensorKey}',
+ MAX(cast(h.value ->'$.${sensorKey}' as decimal(11,3))) AS 'MAX${sensorKey}',
+ MIN(cast(h.value ->'$.${sensorKey}' as decimal(11,3))) AS 'MIN${sensorKey}'
+ </otherwise>
+ </choose>
+ </foreach>
+ FROM
+ history h
+ WHERE
+ h.time >= #{start}
+ AND h.time <![CDATA[<]]> #{end}
+ and h.mac in
+ <foreach collection="macList" index="index" item="mac" open="(" separator="," close=")">
+ #{mac}
+ </foreach>
+ group by
+ h.mac,DATE_FORMAT(time,'%Y-%m-%dT%H:%i')
+ </select>
+
<select id="getSensorDataOnce" resultType="java.util.LinkedHashMap">
SELECT
h.mac,DATE_FORMAT(time,'%Y-%m-%dT%H:%i') time,
- <foreach collection="sensorKeys" separator="," item="sensorKey">
- AVG(value->'$.${sensorKey}') AS '${sensorKey}',
- MAX(cast(h.value ->'$.${sensorKey}' as decimal(11,3))) AS 'MAX${sensorKey}',
- MIN(cast(h.value ->'$.${sensorKey}' as decimal(11,3))) AS 'MIN${sensorKey}'
+ <foreach collection="sensorKeys" separator="," item="sensorKey">
+ <choose >
+ <when test="sensorKey=='e23'">
+ ROUND((CASE WHEN AVG(value->'$.e18'*SIN((value->'$.e23'/180)*PI()))<![CDATA[>]]>0 AND AVG(value->'$.e18'*COS((value->'$.e23'/180)*PI()))<![CDATA[>]]>0
+ THEN ATAN(AVG(value->'$.e18'*SIN((value->'$.e23'/180)*PI()))/AVG(value->'$.e18'*COS((value->'$.e23'/180)*PI())))*180/PI()
+ WHEN AVG(value->'$.e18'*SIN((value->'$.e23'/180)*PI()))>0 AND AVG(value->'$.e18'*COS((value->'$.e23'/180)*PI()))<![CDATA[<]]>0
+ THEN (ATAN(AVG(value->'$.e18'*SIN((value->'$.e23'/180)*PI()))/AVG(value->'$.e18'*COS((value->'$.e23'/180)*PI())))*180/PI())+180
+ WHEN AVG(value->'$.e18'*SIN((value->'$.e23'/180)*PI()))<![CDATA[<]]>0 AND AVG(value->'$.e18'*COS((value->'$.e23'/180)*PI()))<![CDATA[<]]>0
+ THEN (ATAN(AVG(value->'$.e18'*SIN((value->'$.e23'/180)*PI()))/AVG(value->'$.e18'*COS((value->'$.e23'/180)*PI())))*180/PI())+180
+ ELSE (ATAN(AVG(value->'$.e18'*SIN((value->'$.e23'/180)*PI()))/AVG(value->'$.e18'*COS((value->'$.e23'/180)*PI())))*180/PI())+360
+ END),3) AS '${sensorKey}',
+ MAX(cast(h.value ->'$.${sensorKey}' as decimal(11,3))) AS 'MAX${sensorKey}',
+ MIN(cast(h.value ->'$.${sensorKey}' as decimal(11,3))) AS 'MIN${sensorKey}'
+ </when>
+ <otherwise>
+ AVG(value->'$.${sensorKey}') AS '${sensorKey}',
+ MAX(cast(h.value ->'$.${sensorKey}' as decimal(11,3))) AS 'MAX${sensorKey}',
+ MIN(cast(h.value ->'$.${sensorKey}' as decimal(11,3))) AS 'MIN${sensorKey}'
+ </otherwise>
+ </choose>
</foreach>
FROM
history h
@@ -116,4 +222,52 @@
h.mac,DATE_FORMAT(time,'%Y-%m-%dT%H:%i')
</select>
+ <select id="selectByMacAndTime" resultType="com.moral.entity.History">
+ SELECT *
+ from history
+ WHERE time = #{time} and mac in
+ <foreach collection="macList" index="index" item="mac" open="(" separator="," close=")">
+ #{mac}
+ </foreach>
+ </select>
+
+ <insert id="insertHistorySpecialTable">
+ insert into
+ history_special(mac, value, time,version)
+ SELECT * from history WHERE time>=#{startTime} and time<![CDATA[<]]>#{endTime} and mac in
+ <foreach collection="macList" index="index" item="mac" open="(" separator="," close=")">
+ #{mac}
+ </foreach>
+ </insert>
+
+ <delete id="deleteHistoryData" parameterType="java.lang.String">
+ delete from history where time < #{oldTime};
+ </delete>
+
+ <update id="deletePartition">
+ ALTER table history drop PARTITION ${p};
+ </update>
+
+ <update id="createHistoryTable" parameterType="String">
+ CREATE TABLE history_${yearMonthDay} (
+ `mac` varchar(30) DEFAULT NULL,
+ `value` json DEFAULT NULL,
+ `time` datetime DEFAULT NULL,
+ `version` int(11) DEFAULT NULL,
+ KEY `_idx_mac_time` (`mac`,`time`) USING BTREE,
+ KEY `_idx_mac` (`mac`) USING BTREE,
+ KEY `_idx_time` (`time`) USING BTREE
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC
+ </update>
+
+ <delete id="dropHistoryTable" parameterType="String">
+ drop table history_${yearMonthDay}
+ </delete>
+
+ <select id="selectLastDataByMac" resultType="com.moral.entity.History">
+ select * from history_${yearMonthDay}
+ where mac = #{mac}
+ order by time desc
+ limit 1
+ </select>
</mapper>
\ No newline at end of file
--
Gitblit v1.8.0