于紫祥_1901
2020-12-23 e745dd38c5a413eaa000c7c5434621fbcd1800d5
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
<?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.HistoryFiveMinutelyMapper">
    <select id="getFiveMinutesDataByMacsAndTime" resultType="map">
        SELECT h.mac,h.time,json->'$.${sensorKey}' as #{sensorKey}
        from history_five_minutely_${yearAndMonth} h
        where time = #{time} and mac IN
        <foreach collection="macs" separator="," open="(" close=")" item="mac">
            #{mac}
        </foreach>
    </select>
 
    <select id="getFiveMinutesDataByMac" resultType="java.util.LinkedHashMap">
        select
        <foreach collection="sensorKeys" separator="," item="sensorKey">
          json->'$.${sensorKey}' AS '${sensorKey}'
        </foreach>
        FROM
        history_five_minutely_${yearAndMonth} h
        where  h.time = #{time}
        and h.mac = #{mac}
    </select>
 
    <select id="getFiveMinutesSersorDataByMacsAndTime" resultType="map">
        SELECT h.mac,h.time,
        <foreach collection="sensorKeys" separator="," item="sensorKey">
            json->'$.${sensorKey}' AS '${sensorKey}'
        </foreach>
        from history_five_minutely_${yearAndMonth} h
        where time = #{time} and mac IN
        <foreach collection="macs" separator="," open="(" close=")" item="mac">
            #{mac}
        </foreach>
    </select>
 
    <select id="getFiveMinutesDataByMacsAndTimeSolt" resultType="map">
        select h.mac,h.time,
        <foreach collection="sensorKeys" separator="," item="sensorKey">
            json->'$.${sensorKey}' AS '${sensorKey}'
        </foreach>
        FROM history_five_minutely_${yearAndMonth} h
        WHERE mac IN
        <foreach collection="macs" separator="," open="(" close=")" item="mac">
            #{mac}
        </foreach>
        AND time BETWEEN #{startTime} AND #{endTime}
        ORDER BY h.time DESC
        LIMIT #{macNumber}
    </select>
</mapper>