cjl
2023-07-26 0ce061d9ed37a6c25fff70e4734fa8cc8747237c
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
49
50
51
52
53
54
55
56
57
58
59
<?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.api.mapper.HistoryHourlyMapper">
 
    <update id="createTable" parameterType="String">
        CREATE TABLE IF NOT EXISTS `history_hourly_${timeUnits}` (
            `mac` VARCHAR (30) DEFAULT NULL COMMENT '设备mac',
            `time` datetime DEFAULT NULL COMMENT '数据时间',
            `value` json DEFAULT NULL COMMENT '数据',
            `version` INT(11) DEFAULT NULL COMMENT '型号',
            KEY `idx_mac_time` (`mac`,`time`)
            ) ENGINE=INNODB DEFAULT CHARSET=utf8 COMMENT '小时数据表'
    </update>
 
    <update id="createTableComplete" parameterType="String">
        CREATE TABLE IF NOT EXISTS `history_hourly_${timeUnits}_complete` (
            `mac` VARCHAR (30) DEFAULT NULL COMMENT '设备mac',
            `time` datetime DEFAULT NULL COMMENT '数据时间',
            `value` json DEFAULT NULL COMMENT '数据',
            KEY `idx_mac_time` (`mac`,`time`)
            ) ENGINE=INNODB DEFAULT CHARSET=utf8 COMMENT '包含最大值,最小值,平局值的小时数据表'
    </update>
 
    <insert id="insertHistoryHourly">
        INSERT INTO history_hourly_${timeUnits} VALUES
        <foreach collection="list" item="item" separator=",">
            (#{item.mac}, #{item.time}, #{item.value}, #{item.version})
        </foreach>
    </insert>
 
    <select id="selectCountByTime" resultType="java.lang.Integer">
        SELECT COUNT(1) FROM history_hourly_${timeUnits} WHERE `time` = #{time}
        <if test="mac != null">
            AND mac = #{mac}
        </if>
    </select>
 
    <select id="selectDailyData" resultType="java.util.Map">
        SELECT mac, `time`, `value`
        FROM history_hourly_${timeUnits}
        WHERE `time` <![CDATA[>=]]> #{start}
        AND `time` <![CDATA[<]]> #{end}
        <if test="list != null and list.size()!=0">
                and mac in
            <foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
    </select>
 
    <insert id="insertHistoryHourlyComplete">
        INSERT INTO
        history_hourly_${timeUnits}_complete
        VALUES
        <foreach collection="list" item="item" separator=",">
            (#{item.mac}, #{item.time}, #{item.value})
        </foreach>
    </insert>
</mapper>