Files
sionrui/yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/device/IotDeviceMessageMapper.xml

124 lines
3.7 KiB
XML
Raw Normal View History

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