jinpengyong
2022-01-06 45ece9986a39a01081fab9b224966e1f297d383d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?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="getAlarmData" resultType="java.util.LinkedHashMap">
        SELECT
        json_search ( json, 'all', '1' ) '1',
        json_search ( json, 'all', '2' ) '2',
        json_search ( json, 'all', '3' ) '3'
        FROM
        alarm_${yearAndMonth}
        WHERE
        time >= #{start}
        AND time <![CDATA[<]]> #{end}
        AND    mac =#{mac}
    </select>
 
    <select id="getMacs" resultType="java.lang.String">
        SELECT
        mac
        FROM
        alarm_${yearAndMonth}
        where
        time >= #{start}
        AND time <![CDATA[<]]> #{end}
        GROUP BY
        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 IF NOT EXISTS `alarm_${yearAndMonth}` (
        `mac` varchar(30) 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>