<?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.AlarmMapper">
|
<select id="getAvgAlarmData" resultType="java.util.LinkedHashMap">
|
SELECT
|
a.mac,
|
max(a.state) state
|
<foreach collection="sensorKeys" open="," separator="," item="sensorKey">
|
AVG(a.json->'$.${sensorKey}[0]') AS '${sensorKey}'
|
</foreach>
|
FROM
|
alarm_${yearAndMonth} a
|
WHERE
|
a.time >= #{start}
|
AND a.time <![CDATA[<]]> #{end}
|
AND a.mac in
|
<foreach collection="macs" open="(" separator="," close=")"
|
item="mac">
|
#{mac}
|
</foreach>
|
group by
|
a.mac
|
</select>
|
|
<insert id="insertAlarmDaily">
|
insert into
|
alarm_daily
|
values
|
<foreach collection="list" item="item" separator=",">
|
(#{item.mac},#{item.json},#{item.state},#{item.time})
|
</foreach>
|
</insert>
|
|
<update id="createTable">
|
CREATE TABLE `alarm_${yearAndMonth}` (
|
`mac` varchar(20) CHARACTER SET utf8 DEFAULT NULL,
|
`json` json DEFAULT NULL,
|
`state` int(2) DEFAULT NULL,
|
`time` datetime DEFAULT NULL,
|
KEY `_idx_time` (`time`) USING BTREE,
|
KEY `_idx_mac` (`mac`) USING BTREE)
|
ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC;
|
</update>
|
</mapper>
|