IotDeviceLogDataMapper.xml
2.62 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?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="cn.iocoder.yudao.module.iot.dal.tdengine.IotDeviceLogDataMapper">
<update id="createDeviceLogSTable">
CREATE STABLE IF NOT EXISTS device_log (
ts TIMESTAMP,
id NCHAR(50),
product_key NCHAR(50),
type NCHAR(50),
sub_type NCHAR(50),
content NCHAR(1024),
report_time TIMESTAMP
) TAGS (
device_key NCHAR(50)
)
</update>
<insert id="insert">
INSERT INTO device_log_${log.deviceKey} (ts, id, product_key, type, subType, content, report_time)
USING device_log
TAGS ('${log.deviceKey}')
VALUES (
NOW,
#{log.id},
#{log.productKey},
#{log.type},
#{log.subType},
#{log.content},
#{log.reportTime}
)
</insert>
<select id="selectPage" resultType="cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceLogDO">
SELECT ts, id, device_key, product_key, type, sub_type, content, report_time
FROM device_log_${reqVO.deviceKey}
<where>
<if test="reqVO.type != null and reqVO.type != ''">
AND type = #{reqVO.type}
</if>
<if test="reqVO.subType != null and reqVO.subType != ''">
AND subType = #{reqVO.subType}
</if>
<if test="reqVO.createTime != null">
AND ts BETWEEN #{reqVO.createTime[0]} AND #{reqVO.createTime[1]}
</if>
</where>
ORDER BY ts DESC
LIMIT #{reqVO.pageSize} OFFSET #{reqVO.pageNo}
</select>
<select id="selectCount" resultType="Long">
SELECT COUNT(*)
FROM device_log_${reqVO.deviceKey}
<where>
<if test="reqVO.type != null and reqVO.type != ''">
AND type = #{reqVO.type}
</if>
<if test="reqVO.subType != null and reqVO.subType != ''">
AND subType = #{reqVO.subType}
</if>
<if test="reqVO.createTime != null">
AND ts BETWEEN #{reqVO.createTime[0]} AND #{reqVO.createTime[1]}
</if>
</where>
</select>
<select id="checkDeviceLogSTableExists" resultType="Object">
SHOW STABLES LIKE 'device_log'
</select>
<select id="checkDeviceLogTableExists" resultType="Object">
SHOW TABLES LIKE 'device_log_${deviceKey}'
</select>
</mapper>