From a4f62703a87ff7669cf4f6bf2c58f9b78d2eef3d Mon Sep 17 00:00:00 2001
From: ZhuDongming <773644075@qq.com>
Date: Fri, 15 May 2020 13:31:47 +0800
Subject: [PATCH] add预测计算臭氧
---
src/main/resources/mapper/HistoryMapper.xml | 176 ++++++++++++++++++++++++++++++++--------------------------
1 files changed, 97 insertions(+), 79 deletions(-)
diff --git a/src/main/resources/mapper/HistoryMapper.xml b/src/main/resources/mapper/HistoryMapper.xml
index 823b530..19bf540 100644
--- a/src/main/resources/mapper/HistoryMapper.xml
+++ b/src/main/resources/mapper/HistoryMapper.xml
@@ -1,91 +1,91 @@
<?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">
+ <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}'
@@ -102,7 +102,7 @@
<select id="getSensorDataByMac" resultType="java.util.LinkedHashMap">
SELECT
h.mac,
- <foreach collection="sensorKeys" separator="," item="sensorKey">
+ <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}'
@@ -123,7 +123,7 @@
<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">
+ <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}'
@@ -144,7 +144,7 @@
<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">
+ <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}'
@@ -158,4 +158,22 @@
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>=DATE_SUB(#{time}, INTERVAL 1 HOUR) and time<![CDATA[<]]>#{time} and mac in
+ <foreach collection="macList" index="index" item="mac" open="(" separator="," close=")">
+ #{mac}
+ </foreach>
+ </insert>
+
</mapper>
\ No newline at end of file
--
Gitblit v1.8.0