Blame view

yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/device/IotDeviceMessageMapper.xml 3.69 KB
8a7e1464   alwayssuper   feat:simulator
1
2
3
4
  <?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">
66b42367   YunaiV   reactor:【IoT 物联网】...
5
  <mapper namespace="cn.iocoder.yudao.module.iot.dal.tdengine.IotDeviceMessageMapper">
8a7e1464   alwayssuper   feat:simulator
6
  
66b42367   YunaiV   reactor:【IoT 物联网】...
7
8
      <update id="createSTable">
          CREATE STABLE IF NOT EXISTS device_message (
ac624b74   YunaiV   feat:【IoT 物联网】重新实...
9
10
              ts TIMESTAMP,
              id NCHAR(50),
ac624b74   YunaiV   feat:【IoT 物联网】重新实...
11
              report_time TIMESTAMP,
66b42367   YunaiV   reactor:【IoT 物联网】...
12
13
14
              tenant_id BIGINT,
              server_id NCHAR(50),
              upstream BOOL,
c3499af5   YunaiV   reactor:【IoT 物联网】...
15
              reply BOOL,
f5c2ee2a   YunaiV   feat:【IoT 物联网】设备消...
16
              identifier NCHAR(100),
66b42367   YunaiV   reactor:【IoT 物联网】...
17
18
19
20
              request_id NCHAR(50),
              method NCHAR(100),
              params NCHAR(2048),
              data NCHAR(2048),
c3499af5   YunaiV   reactor:【IoT 物联网】...
21
22
              code INT,
              msg NCHAR(256)
ac624b74   YunaiV   feat:【IoT 物联网】重新实...
23
          ) TAGS (
66b42367   YunaiV   reactor:【IoT 物联网】...
24
              device_id BIGINT
ac624b74   YunaiV   feat:【IoT 物联网】重新实...
25
          )
8a7e1464   alwayssuper   feat:simulator
26
27
      </update>
  
66b42367   YunaiV   reactor:【IoT 物联网】...
28
29
      <select id="showSTable" resultType="String">
          SHOW STABLES LIKE 'device_message'
8089f3a3   YunaiV   【功能优化】IoT:
30
31
      </select>
  
8a7e1464   alwayssuper   feat:simulator
32
      <insert id="insert">
66b42367   YunaiV   reactor:【IoT 物联网】...
33
          INSERT INTO device_message_${deviceId} (
33fed798   YunaiV   reactor:【IoT 物联网】...
34
              ts, id, report_time, tenant_id, server_id,
f5c2ee2a   YunaiV   feat:【IoT 物联网】设备消...
35
36
              upstream, reply, identifier, request_id, method,
              params, data, code, msg
ac624b74   YunaiV   feat:【IoT 物联网】重新实...
37
          )
66b42367   YunaiV   reactor:【IoT 物联网】...
38
39
          USING device_message
          TAGS (#{deviceId})
8a7e1464   alwayssuper   feat:simulator
40
          VALUES (
c3499af5   YunaiV   reactor:【IoT 物联网】...
41
              NOW, #{id}, #{reportTime}, #{tenantId},  #{serverId},
f5c2ee2a   YunaiV   feat:【IoT 物联网】设备消...
42
43
              #{upstream}, #{reply}, #{identifier}, #{requestId}, #{method}, 
              #{params}, #{data}, #{code}, #{msg}
8a7e1464   alwayssuper   feat:simulator
44
45
46
          )
      </insert>
  
66b42367   YunaiV   reactor:【IoT 物联网】...
47
      <select id="selectPage" resultType="cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceMessageDO">
c3499af5   YunaiV   reactor:【IoT 物联网】...
48
          SELECT ts, id, report_time, tenant_id, server_id,
f5c2ee2a   YunaiV   feat:【IoT 物联网】设备消...
49
50
                 upstream, reply, identifier, request_id, method, 
                 params, data, code, msg
66b42367   YunaiV   reactor:【IoT 物联网】...
51
          FROM device_message_${reqVO.deviceId}
6aad4545   alwayssuper   [功能添加]:物模型日志表查询与创...
52
          <where>
66b42367   YunaiV   reactor:【IoT 物联网】...
53
54
              <if test="reqVO.method != null and reqVO.method != ''">
                  AND method = #{reqVO.method}
6aad4545   alwayssuper   [功能添加]:物模型日志表查询与创...
55
              </if>
66b42367   YunaiV   reactor:【IoT 物联网】...
56
57
58
              <if test="reqVO.upstream != null">
                  AND upstream = #{reqVO.upstream}
              </if>
f5c2ee2a   YunaiV   feat:【IoT 物联网】设备消...
59
60
61
62
63
64
              <if test="reqVO.reply != null">
                  AND reply = #{reqVO.reply}
              </if>
              <if test="reqVO.identifier != null and reqVO.identifier != ''">
                  AND identifier = #{reqVO.identifier}
              </if>
6aad4545   alwayssuper   [功能添加]:物模型日志表查询与创...
65
66
          </where>
          ORDER BY ts DESC
6aad4545   alwayssuper   [功能添加]:物模型日志表查询与创...
67
68
      </select>
  
f5c2ee2a   YunaiV   feat:【IoT 物联网】设备消...
69
70
71
72
73
74
75
76
77
78
79
80
81
      <select id="selectListByRequestIdsAndReply" resultType="cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceMessageDO">
          SELECT ts, id, report_time, tenant_id, server_id,
                 upstream, reply, identifier, request_id, method, 
                 params, data, code, msg
          FROM device_message_${deviceId}
          WHERE reply = #{reply}
          AND request_id IN
          <foreach collection="requestIds" item="requestId" open="(" close=")" separator=",">
              #{requestId}
          </foreach>
          ORDER BY ts DESC
      </select>
  
8daa2131   alwayssuper   [fix]:iot home count
82
83
      <select id="selectCountByCreateTime" resultType="Long">
          SELECT COUNT(*)
66b42367   YunaiV   reactor:【IoT 物联网】...
84
          FROM device_message
8daa2131   alwayssuper   [fix]:iot home count
85
86
87
88
89
90
91
          <where>
              <if test="createTime != null">
                  AND ts >= #{createTime}
              </if>
          </where>
      </select>
  
d70c6986   YunaiV   feat:【IoT 物联网】设备消...
92
      <select id="selectDeviceMessageCountGroupByDate" resultType="java.util.Map">
ac624b74   YunaiV   feat:【IoT 物联网】重新实...
93
          SELECT
d70c6986   YunaiV   feat:【IoT 物联网】设备消...
94
95
96
97
              TIMETRUNCATE(ts, 1h) AS time,
              SUM(CASE WHEN upstream = true THEN 1 ELSE 0 END) AS upstream_count,
              SUM(CASE WHEN upstream = false THEN 1 ELSE 0 END) AS downstream_count
          FROM device_message
8daa2131   alwayssuper   [fix]:iot home count
98
99
100
101
102
103
104
          <where>
              <if test="startTime != null">
                  AND ts >= #{startTime}
              </if>
              <if test="endTime != null">
                  AND ts &lt;= #{endTime}
              </if>
8daa2131   alwayssuper   [fix]:iot home count
105
          </where>
b3398019   alwayssuper   fix:iot首页统计中存在的TD...
106
          GROUP BY TIMETRUNCATE(ts, 1h)
8daa2131   alwayssuper   [fix]:iot home count
107
108
      </select>
  
33fed798   YunaiV   reactor:【IoT 物联网】...
109
  </mapper>