reactor:【IoT 物联网】重新梳理下行消息的逻辑(未测试,用于相互 review 作用)

This commit is contained in:
YunaiV
2025-06-11 09:56:59 +08:00
parent 4ea6e08f99
commit 66b42367cb
48 changed files with 734 additions and 1536 deletions

View File

@@ -2,51 +2,62 @@
<!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.IotDeviceLogMapper">
<mapper namespace="cn.iocoder.yudao.module.iot.dal.tdengine.IotDeviceMessageMapper">
<update id="createDeviceLogSTable">
CREATE STABLE IF NOT EXISTS device_log (
<update id="createSTable">
CREATE STABLE IF NOT EXISTS device_message (
ts TIMESTAMP,
id NCHAR(50),
message_id NCHAR(50),
type NCHAR(50),
identifier NCHAR(255),
content NCHAR(1024),
code INT,
report_time TIMESTAMP,
tenant_id BIGINT
device_id BIGINT,
tenant_id BIGINT,
server_id NCHAR(50),
upstream BOOL,
request_id NCHAR(50),
method NCHAR(100),
params NCHAR(2048),
data NCHAR(2048),
code INT
) TAGS (
product_key NCHAR(50),
device_name NCHAR(50)
device_id BIGINT
)
</update>
<select id="showDeviceLogSTable" resultType="String">
SHOW STABLES LIKE 'device_log'
<select id="showSTable" resultType="String">
SHOW STABLES LIKE 'device_message'
</select>
<insert id="insert">
INSERT INTO device_log_${productKey}_${deviceName} (
ts, id, message_id, type, identifier,
content, code, report_time, tenant_id
INSERT INTO device_message_${deviceId} (
ts, id, report_time, device_id, tenant_id,
server_id, upstream, request_id, method, params,
data, code
)
USING device_log
TAGS ('${productKey}', '${deviceName}')
USING device_message
TAGS (#{deviceId})
VALUES (
NOW, #{id}, #{messageId}, #{type}, #{identifier},
#{content}, #{code}, #{reportTime}, #{tenantId}
#{ts}, #{id}, #{reportTime}, #{deviceId}, #{tenantId},
#{serverId}, #{upstream}, #{requestId}, #{method}, #{params},
#{data}, #{code}
)
</insert>
<select id="selectPage" resultType="cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceLogDO">
SELECT ts, id, device_key, product_key, type, identifier, content, report_time
FROM device_log_${productKey}_${deviceName}
<select id="selectPage" resultType="cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceMessageDO">
SELECT ts, id, report_time, device_id, tenant_id, server_id, upstream,
request_id, method, params, data, code
FROM device_message_${reqVO.deviceId}
<where>
<if test="reqVO.type != null and reqVO.type != ''">
AND type = #{reqVO.type}
<if test="reqVO.method != null and reqVO.method != ''">
AND method = #{reqVO.method}
</if>
<if test="reqVO.identifier != null and reqVO.identifier != ''">
AND identifier LIKE CONCAT('%',#{reqVO.identifier},'%')
<if test="reqVO.upstream != null">
AND upstream = #{reqVO.upstream}
</if>
<if test="reqVO.startTime != null">
AND ts >= #{reqVO.startTime}
</if>
<if test="reqVO.endTime != null">
AND ts &lt;= #{reqVO.endTime}
</if>
</where>
ORDER BY ts DESC
@@ -54,7 +65,7 @@
<select id="selectCountByCreateTime" resultType="Long">
SELECT COUNT(*)
FROM device_log
FROM device_message
<where>
<if test="createTime != null">
AND ts >= #{createTime}
@@ -68,11 +79,11 @@
COUNT(*) as data
FROM
<choose>
<when test="deviceKey != null and deviceKey != ''">
device_log_${deviceKey}
<when test="deviceId != null">
device_message_${deviceId}
</when>
<otherwise>
device_log
device_message
</otherwise>
</choose>
<where>
@@ -82,9 +93,7 @@
<if test="endTime != null">
AND ts &lt;= #{endTime}
</if>
AND (
identifier IN ('online', 'offline', 'pull', 'progress', 'report', 'register', 'register_sub')
)
AND upstream = true
</where>
GROUP BY TIMETRUNCATE(ts, 1h)
ORDER BY time ASC
@@ -96,11 +105,11 @@
COUNT(*) as data
FROM
<choose>
<when test="deviceKey != null and deviceKey != ''">
device_log_${deviceKey}
<when test="deviceId != null">
device_message_${deviceId}
</when>
<otherwise>
device_log
device_message
</otherwise>
</choose>
<where>
@@ -110,10 +119,10 @@
<if test="endTime != null">
AND ts &lt;= #{endTime}
</if>
AND identifier IN ('set', 'get', 'upgrade', 'unregister_sub', 'topology_add')
AND upstream = false
</where>
GROUP BY TIMETRUNCATE(ts, 1h)
ORDER BY time ASC
</select>
</mapper>
</mapper>