<?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">
|
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>
|
|
<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>
|
FROM
|
history h
|
WHERE
|
h.time >= #{start}
|
AND h.time <![CDATA[<]]> #{end}
|
group by
|
h.mac
|
</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>
|
FROM
|
history h
|
WHERE
|
h.time >= #{start}
|
AND h.time <![CDATA[<]]> #{end}
|
group by
|
h.mac,DATE_FORMAT(time,'%Y-%m-%dT%H:%i')
|
</select>
|
|
</mapper>
|