2025-01-05 22:56:13 +08:00
|
|
|
<?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">
|
2025-06-11 09:56:59 +08:00
|
|
|
<mapper namespace="cn.iocoder.yudao.module.iot.dal.tdengine.IotDeviceMessageMapper">
|
2025-01-05 22:56:13 +08:00
|
|
|
|
2025-06-11 09:56:59 +08:00
|
|
|
<update id="createSTable">
|
|
|
|
|
CREATE STABLE IF NOT EXISTS device_message (
|
2025-06-01 10:51:55 +08:00
|
|
|
ts TIMESTAMP,
|
|
|
|
|
id NCHAR(50),
|
|
|
|
|
report_time TIMESTAMP,
|
2025-06-11 09:56:59 +08:00
|
|
|
tenant_id BIGINT,
|
|
|
|
|
server_id NCHAR(50),
|
|
|
|
|
upstream BOOL,
|
2025-06-11 21:31:01 +08:00
|
|
|
reply BOOL,
|
2025-06-11 09:56:59 +08:00
|
|
|
request_id NCHAR(50),
|
|
|
|
|
method NCHAR(100),
|
|
|
|
|
params NCHAR(2048),
|
|
|
|
|
data NCHAR(2048),
|
2025-06-11 21:31:01 +08:00
|
|
|
code INT,
|
|
|
|
|
msg NCHAR(256)
|
2025-06-01 10:51:55 +08:00
|
|
|
) TAGS (
|
2025-06-11 09:56:59 +08:00
|
|
|
device_id BIGINT
|
2025-06-01 10:51:55 +08:00
|
|
|
)
|
2025-01-05 22:56:13 +08:00
|
|
|
</update>
|
|
|
|
|
|
2025-06-11 09:56:59 +08:00
|
|
|
<select id="showSTable" resultType="String">
|
|
|
|
|
SHOW STABLES LIKE 'device_message'
|
2025-01-27 14:15:07 +08:00
|
|
|
</select>
|
|
|
|
|
|
2025-01-05 22:56:13 +08:00
|
|
|
<insert id="insert">
|
2025-06-11 09:56:59 +08:00
|
|
|
INSERT INTO device_message_${deviceId} (
|
2025-06-11 20:35:09 +08:00
|
|
|
ts, id, report_time, tenant_id, server_id,
|
2025-06-11 21:31:01 +08:00
|
|
|
upstream, reply, request_id, method, params,
|
|
|
|
|
data, code, msg
|
2025-06-01 10:51:55 +08:00
|
|
|
)
|
2025-06-11 09:56:59 +08:00
|
|
|
USING device_message
|
|
|
|
|
TAGS (#{deviceId})
|
2025-01-05 22:56:13 +08:00
|
|
|
VALUES (
|
2025-06-11 21:31:01 +08:00
|
|
|
NOW, #{id}, #{reportTime}, #{tenantId}, #{serverId},
|
|
|
|
|
#{upstream}, #{reply}, #{requestId}, #{method}, #{params},
|
|
|
|
|
#{data}, #{code}, #{msg}
|
2025-01-05 22:56:13 +08:00
|
|
|
)
|
|
|
|
|
</insert>
|
|
|
|
|
|
2025-06-11 09:56:59 +08:00
|
|
|
<select id="selectPage" resultType="cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceMessageDO">
|
2025-06-11 21:31:01 +08:00
|
|
|
SELECT ts, id, report_time, tenant_id, server_id,
|
|
|
|
|
upstream, reply, request_id, method, params,
|
|
|
|
|
data, code, msg
|
2025-06-11 09:56:59 +08:00
|
|
|
FROM device_message_${reqVO.deviceId}
|
2025-01-06 16:43:37 +08:00
|
|
|
<where>
|
2025-06-11 09:56:59 +08:00
|
|
|
<if test="reqVO.method != null and reqVO.method != ''">
|
|
|
|
|
AND method = #{reqVO.method}
|
2025-01-06 16:43:37 +08:00
|
|
|
</if>
|
2025-06-11 09:56:59 +08:00
|
|
|
<if test="reqVO.upstream != null">
|
|
|
|
|
AND upstream = #{reqVO.upstream}
|
|
|
|
|
</if>
|
2025-01-06 16:43:37 +08:00
|
|
|
</where>
|
|
|
|
|
ORDER BY ts DESC
|
|
|
|
|
</select>
|
|
|
|
|
|
2025-02-26 16:49:29 +08:00
|
|
|
<select id="selectCountByCreateTime" resultType="Long">
|
|
|
|
|
SELECT COUNT(*)
|
2025-06-11 09:56:59 +08:00
|
|
|
FROM device_message
|
2025-02-26 16:49:29 +08:00
|
|
|
<where>
|
|
|
|
|
<if test="createTime != null">
|
|
|
|
|
AND ts >= #{createTime}
|
|
|
|
|
</if>
|
|
|
|
|
</where>
|
|
|
|
|
</select>
|
|
|
|
|
|
2025-02-28 15:28:38 +08:00
|
|
|
<select id="selectDeviceLogUpCountByHour" resultType="java.util.Map">
|
2025-06-01 10:51:55 +08:00
|
|
|
SELECT
|
2025-02-26 16:49:29 +08:00
|
|
|
TIMETRUNCATE(ts, 1h) as time,
|
2025-06-01 10:51:55 +08:00
|
|
|
COUNT(*) as data
|
|
|
|
|
FROM
|
2025-02-26 16:49:29 +08:00
|
|
|
<choose>
|
2025-06-11 09:56:59 +08:00
|
|
|
<when test="deviceId != null">
|
|
|
|
|
device_message_${deviceId}
|
2025-02-26 16:49:29 +08:00
|
|
|
</when>
|
|
|
|
|
<otherwise>
|
2025-06-11 09:56:59 +08:00
|
|
|
device_message
|
2025-02-26 16:49:29 +08:00
|
|
|
</otherwise>
|
|
|
|
|
</choose>
|
|
|
|
|
<where>
|
|
|
|
|
<if test="startTime != null">
|
|
|
|
|
AND ts >= #{startTime}
|
|
|
|
|
</if>
|
|
|
|
|
<if test="endTime != null">
|
|
|
|
|
AND ts <= #{endTime}
|
|
|
|
|
</if>
|
2025-06-11 09:56:59 +08:00
|
|
|
AND upstream = true
|
2025-02-26 16:49:29 +08:00
|
|
|
</where>
|
|
|
|
|
GROUP BY TIMETRUNCATE(ts, 1h)
|
|
|
|
|
ORDER BY time ASC
|
|
|
|
|
</select>
|
|
|
|
|
|
2025-02-28 15:28:38 +08:00
|
|
|
<select id="selectDeviceLogDownCountByHour" resultType="java.util.Map">
|
2025-06-01 10:51:55 +08:00
|
|
|
SELECT
|
2025-02-26 16:49:29 +08:00
|
|
|
TIMETRUNCATE(ts, 1h) as time,
|
2025-06-01 10:51:55 +08:00
|
|
|
COUNT(*) as data
|
|
|
|
|
FROM
|
2025-02-26 16:49:29 +08:00
|
|
|
<choose>
|
2025-06-11 09:56:59 +08:00
|
|
|
<when test="deviceId != null">
|
|
|
|
|
device_message_${deviceId}
|
2025-02-26 16:49:29 +08:00
|
|
|
</when>
|
|
|
|
|
<otherwise>
|
2025-06-11 09:56:59 +08:00
|
|
|
device_message
|
2025-02-26 16:49:29 +08:00
|
|
|
</otherwise>
|
|
|
|
|
</choose>
|
|
|
|
|
<where>
|
|
|
|
|
<if test="startTime != null">
|
|
|
|
|
AND ts >= #{startTime}
|
|
|
|
|
</if>
|
|
|
|
|
<if test="endTime != null">
|
|
|
|
|
AND ts <= #{endTime}
|
|
|
|
|
</if>
|
2025-06-11 09:56:59 +08:00
|
|
|
AND upstream = false
|
2025-02-26 16:49:29 +08:00
|
|
|
</where>
|
|
|
|
|
GROUP BY TIMETRUNCATE(ts, 1h)
|
|
|
|
|
ORDER BY time ASC
|
|
|
|
|
</select>
|
|
|
|
|
|
2025-06-11 20:35:09 +08:00
|
|
|
</mapper>
|