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.IotDeviceLogDataMapper">
|
|
|
|
|
|
|
|
|
|
<!-- 创建设备日志超级表 初始化只创建一次-->
|
|
|
|
|
<update id="createDeviceLogSTable">
|
2025-01-06 11:04:39 +08:00
|
|
|
|
CREATE STABLE device_log (
|
2025-01-09 12:36:30 +08:00
|
|
|
|
ts TIMESTAMP,
|
|
|
|
|
id NCHAR(50),
|
|
|
|
|
product_key NCHAR(50),
|
|
|
|
|
type NCHAR(50),
|
|
|
|
|
<!-- TODO @super:下划线 sub_type -->
|
|
|
|
|
subType NCHAR(50),
|
|
|
|
|
content NCHAR(1024),
|
|
|
|
|
report_time TIMESTAMP
|
|
|
|
|
) TAGS (
|
|
|
|
|
device_key NCHAR(50)
|
|
|
|
|
)
|
2025-01-05 22:56:13 +08:00
|
|
|
|
</update>
|
|
|
|
|
|
|
|
|
|
<!-- 创建设备日志子表 讨论:TDengine 在子表不存在的情况下 可在数据插入时 自动建表 要不要去掉创建子表的逻辑 由第一次插入数据时自动创建-->
|
|
|
|
|
<update id="createDeviceLogTable">
|
|
|
|
|
CREATE TABLE device_log_${deviceKey} USING device_log TAGS('${deviceKey}')
|
|
|
|
|
</update>
|
|
|
|
|
|
|
|
|
|
<!-- 插入设备日志数据 在子表不存在的情况下 可在数据插入时 自动建表 -->
|
|
|
|
|
<insert id="insert">
|
|
|
|
|
INSERT INTO device_log_${log.deviceKey} (ts, id, product_key, type, subType, content, report_time)
|
|
|
|
|
USING device_log
|
|
|
|
|
TAGS ('${log.deviceKey}')
|
|
|
|
|
VALUES (
|
|
|
|
|
#{log.ts},
|
|
|
|
|
#{log.id},
|
|
|
|
|
#{log.productKey},
|
|
|
|
|
#{log.type},
|
|
|
|
|
#{log.subType},
|
|
|
|
|
#{log.content},
|
|
|
|
|
#{log.reportTime}
|
|
|
|
|
)
|
|
|
|
|
</insert>
|
|
|
|
|
|
2025-01-06 16:43:37 +08:00
|
|
|
|
<select id="selectPage" resultType="cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceLogDO">
|
|
|
|
|
SELECT ts, id, device_key, product_key, type, subType, content, report_time
|
|
|
|
|
FROM device_log_${reqVO.deviceKey}
|
|
|
|
|
<where>
|
|
|
|
|
<if test="reqVO.type != null and reqVO.type != ''">
|
|
|
|
|
AND type = #{reqVO.type}
|
|
|
|
|
</if>
|
|
|
|
|
<if test="reqVO.subType != null and reqVO.subType != ''">
|
|
|
|
|
AND subType = #{reqVO.subType}
|
|
|
|
|
</if>
|
|
|
|
|
<if test="reqVO.createTime != null">
|
|
|
|
|
AND ts BETWEEN #{reqVO.createTime[0]} AND #{reqVO.createTime[1]}
|
|
|
|
|
</if>
|
|
|
|
|
</where>
|
|
|
|
|
ORDER BY ts DESC
|
|
|
|
|
LIMIT #{reqVO.pageSize} OFFSET #{reqVO.pageNo}
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
<select id="selectCount" resultType="Long">
|
|
|
|
|
SELECT COUNT(*)
|
|
|
|
|
FROM device_log_${reqVO.deviceKey}
|
|
|
|
|
<where>
|
|
|
|
|
<if test="reqVO.type != null and reqVO.type != ''">
|
|
|
|
|
AND type = #{reqVO.type}
|
|
|
|
|
</if>
|
|
|
|
|
<if test="reqVO.subType != null and reqVO.subType != ''">
|
|
|
|
|
AND subType = #{reqVO.subType}
|
|
|
|
|
</if>
|
|
|
|
|
<if test="reqVO.createTime != null">
|
|
|
|
|
AND ts BETWEEN #{reqVO.createTime[0]} AND #{reqVO.createTime[1]}
|
|
|
|
|
</if>
|
|
|
|
|
</where>
|
|
|
|
|
</select>
|
|
|
|
|
|
2025-01-05 22:56:13 +08:00
|
|
|
|
</mapper>
|