<?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>
|
<sql id="Example_Where_Clause">
|
<where>
|
<foreach collection="oredCriteria" item="criteria" separator="or">
|
<if test="criteria.valid">
|
<trim prefix="(" prefixOverrides="and" suffix=")">
|
<foreach collection="criteria.criteria" item="criterion">
|
<choose>
|
<when test="criterion.noValue">
|
and ${criterion.condition}
|
</when>
|
<when test="criterion.singleValue">
|
and ${criterion.condition} #{criterion.value}
|
</when>
|
<when test="criterion.betweenValue">
|
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
|
</when>
|
<when test="criterion.listValue">
|
and ${criterion.condition}
|
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
|
#{listItem}
|
</foreach>
|
</when>
|
</choose>
|
</foreach>
|
</trim>
|
</if>
|
</foreach>
|
</where>
|
</sql>
|
<sql id="Update_By_Example_Where_Clause">
|
<where>
|
<foreach collection="example.oredCriteria" item="criteria" separator="or">
|
<if test="criteria.valid">
|
<trim prefix="(" prefixOverrides="and" suffix=")">
|
<foreach collection="criteria.criteria" item="criterion">
|
<choose>
|
<when test="criterion.noValue">
|
and ${criterion.condition}
|
</when>
|
<when test="criterion.singleValue">
|
and ${criterion.condition} #{criterion.value}
|
</when>
|
<when test="criterion.betweenValue">
|
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
|
</when>
|
<when test="criterion.listValue">
|
and ${criterion.condition}
|
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
|
#{listItem}
|
</foreach>
|
</when>
|
</choose>
|
</foreach>
|
</trim>
|
</if>
|
</foreach>
|
</where>
|
</sql>
|
<sql id="Base_Column_List">
|
mac, value, time, version
|
</sql>
|
<select id="selectByExample" parameterType="com.moral.entity.HistoryExample" resultMap="BaseResultMap">
|
select
|
<if test="distinct">
|
distinct
|
</if>
|
<include refid="Base_Column_List" />
|
from history
|
<if test="_parameter != null">
|
<include refid="Example_Where_Clause" />
|
</if>
|
<if test="orderByClause != null">
|
order by ${orderByClause}
|
</if>
|
</select>
|
<delete id="deleteByExample" parameterType="com.moral.entity.HistoryExample">
|
delete from history
|
<if test="_parameter != null">
|
<include refid="Example_Where_Clause" />
|
</if>
|
</delete>
|
<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="countByExample" parameterType="com.moral.entity.HistoryExample" resultType="java.lang.Integer">
|
select count(*) from history
|
<if test="_parameter != null">
|
<include refid="Example_Where_Clause" />
|
</if>
|
</select>
|
<update id="updateByExampleSelective" parameterType="map">
|
update history
|
<set>
|
<if test="record.mac != null">
|
mac = #{record.mac,jdbcType=VARCHAR},
|
</if>
|
<if test="record.value != null">
|
value = #{record.value,jdbcType=OTHER},
|
</if>
|
<if test="record.time != null">
|
time = #{record.time,jdbcType=TIMESTAMP},
|
</if>
|
<if test="record.version != null">
|
version = #{record.version,jdbcType=INTEGER},
|
</if>
|
</set>
|
<if test="_parameter != null">
|
<include refid="Update_By_Example_Where_Clause" />
|
</if>
|
</update>
|
<update id="updateByExample" parameterType="map">
|
update history
|
set mac = #{record.mac,jdbcType=VARCHAR},
|
value = #{record.value,jdbcType=OTHER},
|
time = #{record.time,jdbcType=TIMESTAMP},
|
version = #{record.version,jdbcType=INTEGER}
|
<if test="_parameter != null">
|
<include refid="Update_By_Example_Where_Clause" />
|
</if>
|
</update>
|
<resultMap id="BaseResultMap" type="com.moral.entity.History">
|
<result column="device_mac" jdbcType="VARCHAR" property="deviceMac" />
|
<result column="value" jdbcType="OTHER" property="value" />
|
<result column="time" jdbcType="TIMESTAMP" property="time" />
|
<result column="version" jdbcType="VARCHAR" property="version" />
|
</resultMap>
|
<sql id="Example_Where_Clause">
|
<where>
|
<foreach collection="oredCriteria" item="criteria" separator="or">
|
<if test="criteria.valid">
|
<trim prefix="(" prefixOverrides="and" suffix=")">
|
<foreach collection="criteria.criteria" item="criterion">
|
<choose>
|
<when test="criterion.noValue">
|
and ${criterion.condition}
|
</when>
|
<when test="criterion.singleValue">
|
and ${criterion.condition} #{criterion.value}
|
</when>
|
<when test="criterion.betweenValue">
|
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
|
</when>
|
<when test="criterion.listValue">
|
and ${criterion.condition}
|
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
|
#{listItem}
|
</foreach>
|
</when>
|
</choose>
|
</foreach>
|
</trim>
|
</if>
|
</foreach>
|
</where>
|
</sql>
|
<sql id="Update_By_Example_Where_Clause">
|
<where>
|
<foreach collection="example.oredCriteria" item="criteria" separator="or">
|
<if test="criteria.valid">
|
<trim prefix="(" prefixOverrides="and" suffix=")">
|
<foreach collection="criteria.criteria" item="criterion">
|
<choose>
|
<when test="criterion.noValue">
|
and ${criterion.condition}
|
</when>
|
<when test="criterion.singleValue">
|
and ${criterion.condition} #{criterion.value}
|
</when>
|
<when test="criterion.betweenValue">
|
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
|
</when>
|
<when test="criterion.listValue">
|
and ${criterion.condition}
|
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
|
#{listItem}
|
</foreach>
|
</when>
|
</choose>
|
</foreach>
|
</trim>
|
</if>
|
</foreach>
|
</where>
|
</sql>
|
<sql id="Base_Column_List">
|
device_mac, value, time, version
|
</sql>
|
<select id="selectByExample" parameterType="com.moral.entity.HistoryExample" resultMap="BaseResultMap">
|
select
|
<if test="distinct">
|
distinct
|
</if>
|
<include refid="Base_Column_List" />
|
from history
|
<if test="_parameter != null">
|
<include refid="Example_Where_Clause" />
|
</if>
|
<if test="orderByClause != null">
|
order by ${orderByClause}
|
</if>
|
</select>
|
<delete id="deleteByExample" parameterType="com.moral.entity.HistoryExample">
|
delete from history
|
<if test="_parameter != null">
|
<include refid="Example_Where_Clause" />
|
</if>
|
</delete>
|
<insert id="insert" parameterType="com.moral.entity.History">
|
insert into history (device_mac, value, time,
|
version)
|
values (#{deviceMac,jdbcType=VARCHAR}, #{value,jdbcType=OTHER}, #{time,jdbcType=TIMESTAMP},
|
#{version,jdbcType=VARCHAR})
|
</insert>
|
<insert id="insertSelective" parameterType="com.moral.entity.History">
|
insert into history
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
<if test="deviceMac != null">
|
device_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="deviceMac != null">
|
#{deviceMac,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=VARCHAR},
|
</if>
|
</trim>
|
</insert>
|
<select id="countByExample" parameterType="com.moral.entity.HistoryExample" resultType="java.lang.Integer">
|
select count(*) from history
|
<if test="_parameter != null">
|
<include refid="Example_Where_Clause" />
|
</if>
|
</select>
|
<update id="updateByExampleSelective" parameterType="map">
|
update history
|
<set>
|
<if test="record.deviceMac != null">
|
device_mac = #{record.deviceMac,jdbcType=VARCHAR},
|
</if>
|
<if test="record.value != null">
|
value = #{record.value,jdbcType=OTHER},
|
</if>
|
<if test="record.time != null">
|
time = #{record.time,jdbcType=TIMESTAMP},
|
</if>
|
<if test="record.version != null">
|
version = #{record.version,jdbcType=VARCHAR},
|
</if>
|
</set>
|
<if test="_parameter != null">
|
<include refid="Update_By_Example_Where_Clause" />
|
</if>
|
</update>
|
<update id="updateByExample" parameterType="map">
|
update history
|
set device_mac = #{record.deviceMac,jdbcType=VARCHAR},
|
value = #{record.value,jdbcType=OTHER},
|
time = #{record.time,jdbcType=TIMESTAMP},
|
version = #{record.version,jdbcType=VARCHAR}
|
<if test="_parameter != null">
|
<include refid="Update_By_Example_Where_Clause" />
|
</if>
|
</update>
|
|
<select id="getDayAQIBySensor" resultType="map">
|
SELECT
|
AVG(value -> '$.e1') e1,
|
AVG(value -> '$.e2') e2,
|
AVG(value -> '$.e10') e10,
|
AVG(value -> '$.e11') e11,
|
AVG(value -> '$.e15') e15,
|
AVG(value -> '$.e16') e16
|
FROM
|
history
|
WHERE
|
device_mac = #{mac}
|
AND time > #{start}
|
AND time < #{end}
|
</select>
|
|
<select id="getAverageByAll" resultType="map">
|
SELECT
|
<if test="macKey != null and macKey != 'all'">
|
e.name,
|
</if>
|
<if test="macKey == 'all'">
|
h.mac_key,
|
</if>
|
AVG(h.mac_value) avg
|
FROM
|
history h,
|
monitorpoint m,
|
equipment e
|
WHERE
|
m.areacode = #{areaCode}
|
AND m.id = epoint
|
AND e.mac = h.mac
|
AND h.time > #{start}
|
AND h.time < #{end}
|
<if test="orgIds != null and orgIds.size > 0">
|
<!-- JOIN org_equ oe ON e.id = oe.equid -->
|
AND e.owner_id IN
|
<foreach close=")" collection="orgIds" item="listItem" open="(" separator=",">
|
#{listItem}
|
</foreach>
|
</if>
|
<if test="macKey != null and macKey != 'all'">
|
AND h.mac_key = #{macKey}
|
GROUP BY e.id
|
ORDER BY avg
|
</if>
|
<if test="macKey == 'all'">
|
GROUP BY h.mac_key
|
</if>
|
</select>
|
</mapper>
|