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-01-28 08:35:07 +08:00
|
|
|
<mapper namespace="cn.iocoder.yudao.module.iot.dal.tdengine.IotDeviceLogMapper">
|
2025-01-05 22:56:13 +08:00
|
|
|
|
|
|
|
<update id="createDeviceLogSTable">
|
2025-01-12 20:13:41 +08:00
|
|
|
CREATE STABLE IF NOT EXISTS device_log (
|
2025-01-25 11:46:26 +08:00
|
|
|
ts TIMESTAMP,
|
|
|
|
id NCHAR(50),
|
|
|
|
product_key NCHAR(50),
|
2025-01-27 14:15:07 +08:00
|
|
|
device_name NCHAR(50),
|
2025-01-25 11:46:26 +08:00
|
|
|
type NCHAR(50),
|
2025-01-27 14:15:07 +08:00
|
|
|
identifier NCHAR(255),
|
2025-01-25 11:46:26 +08:00
|
|
|
content NCHAR(1024),
|
2025-01-31 11:10:20 +08:00
|
|
|
code INT,
|
2025-01-25 11:46:26 +08:00
|
|
|
report_time TIMESTAMP
|
2025-01-09 12:36:30 +08:00
|
|
|
) TAGS (
|
|
|
|
device_key NCHAR(50)
|
|
|
|
)
|
2025-01-05 22:56:13 +08:00
|
|
|
</update>
|
|
|
|
|
2025-01-27 14:15:07 +08:00
|
|
|
<select id="showDeviceLogSTable" resultType="String">
|
|
|
|
SHOW STABLES LIKE 'device_log'
|
|
|
|
</select>
|
|
|
|
|
2025-01-05 22:56:13 +08:00
|
|
|
<insert id="insert">
|
2025-01-31 11:10:20 +08:00
|
|
|
INSERT INTO device_log_${deviceKey} (ts, id, product_key, device_name, type, identifier, content, code, report_time)
|
2025-01-05 22:56:13 +08:00
|
|
|
USING device_log
|
2025-01-27 14:15:07 +08:00
|
|
|
TAGS ('${deviceKey}')
|
2025-01-05 22:56:13 +08:00
|
|
|
VALUES (
|
2025-01-20 16:31:37 +08:00
|
|
|
NOW,
|
2025-01-27 14:15:07 +08:00
|
|
|
#{id},
|
|
|
|
#{productKey},
|
|
|
|
#{deviceName},
|
|
|
|
#{type},
|
|
|
|
#{identifier},
|
|
|
|
#{content},
|
2025-01-31 11:10:20 +08:00
|
|
|
#{code},
|
2025-01-27 14:15:07 +08:00
|
|
|
#{reportTime}
|
2025-01-05 22:56:13 +08:00
|
|
|
)
|
|
|
|
</insert>
|
|
|
|
|
2025-01-06 16:43:37 +08:00
|
|
|
<select id="selectPage" resultType="cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceLogDO">
|
2025-01-28 08:35:07 +08:00
|
|
|
SELECT ts, id, device_key, product_key, type, identifier, content, report_time
|
2025-01-06 16:43:37 +08:00
|
|
|
FROM device_log_${reqVO.deviceKey}
|
|
|
|
<where>
|
|
|
|
<if test="reqVO.type != null and reqVO.type != ''">
|
|
|
|
AND type = #{reqVO.type}
|
|
|
|
</if>
|
2025-01-28 08:35:07 +08:00
|
|
|
<if test="reqVO.identifier != null and reqVO.identifier != ''">
|
|
|
|
AND identifier LIKE CONCAT('%',#{reqVO.identifier},'%')
|
2025-01-06 16:43:37 +08:00
|
|
|
</if>
|
|
|
|
</where>
|
|
|
|
ORDER BY ts DESC
|
|
|
|
</select>
|
|
|
|
|
2025-02-26 16:49:29 +08:00
|
|
|
<select id="selectCountByCreateTime" resultType="Long">
|
|
|
|
SELECT COUNT(*)
|
|
|
|
FROM device_log
|
|
|
|
<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-02-26 16:49:29 +08:00
|
|
|
SELECT
|
|
|
|
TIMETRUNCATE(ts, 1h) as time,
|
|
|
|
COUNT(*) as data
|
|
|
|
FROM
|
|
|
|
<choose>
|
|
|
|
<when test="deviceKey != null and deviceKey != ''">
|
|
|
|
device_log_${deviceKey}
|
|
|
|
</when>
|
|
|
|
<otherwise>
|
|
|
|
device_log
|
|
|
|
</otherwise>
|
|
|
|
</choose>
|
|
|
|
<where>
|
|
|
|
<if test="startTime != null">
|
|
|
|
AND ts >= #{startTime}
|
|
|
|
</if>
|
|
|
|
<if test="endTime != null">
|
|
|
|
AND ts <= #{endTime}
|
|
|
|
</if>
|
|
|
|
AND (
|
|
|
|
identifier IN ('online', 'offline', 'pull', 'progress', 'report', 'register', 'register_sub')
|
|
|
|
)
|
|
|
|
</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-02-26 16:49:29 +08:00
|
|
|
SELECT
|
|
|
|
TIMETRUNCATE(ts, 1h) as time,
|
|
|
|
COUNT(*) as data
|
|
|
|
FROM
|
|
|
|
<choose>
|
|
|
|
<when test="deviceKey != null and deviceKey != ''">
|
|
|
|
device_log_${deviceKey}
|
|
|
|
</when>
|
|
|
|
<otherwise>
|
|
|
|
device_log
|
|
|
|
</otherwise>
|
|
|
|
</choose>
|
|
|
|
<where>
|
|
|
|
<if test="startTime != null">
|
|
|
|
AND ts >= #{startTime}
|
|
|
|
</if>
|
|
|
|
<if test="endTime != null">
|
|
|
|
AND ts <= #{endTime}
|
|
|
|
</if>
|
|
|
|
AND identifier IN ('set', 'get', 'upgrade', 'unregister_sub', 'topology_add')
|
|
|
|
</where>
|
|
|
|
GROUP BY TIMETRUNCATE(ts, 1h)
|
|
|
|
ORDER BY time ASC
|
|
|
|
</select>
|
|
|
|
|
2025-01-05 22:56:13 +08:00
|
|
|
</mapper>
|