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

78 lines
2.6 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.IotDeviceLogDataMapper">
<update id="createDeviceLogSTable">
2025-01-12 20:13:41 +08:00
CREATE STABLE IF NOT EXISTS device_log (
ts TIMESTAMP,
id NCHAR(50),
product_key NCHAR(50),
type NCHAR(50),
sub_type NCHAR(50),
content NCHAR(1024),
report_time TIMESTAMP
) TAGS (
device_key NCHAR(50)
)
2025-01-05 22:56:13 +08:00
</update>
<insert id="insert">
2025-01-23 16:54:45 +08:00
INSERT INTO device_log_${log.deviceKey} (ts, id, product_key, type, subType, content, report_time)
2025-01-05 22:56:13 +08:00
USING device_log
TAGS ('${log.deviceKey}')
VALUES (
2025-01-20 16:31:37 +08:00
NOW,
2025-01-05 22:56:13 +08:00
#{log.id},
#{log.productKey},
#{log.type},
#{log.subType},
#{log.content},
#{log.reportTime}
)
</insert>
<select id="selectPage" resultType="cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceLogDO">
SELECT ts, id, device_key, product_key, type, sub_type, 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-24 15:56:01 +08:00
<select id="checkDeviceLogSTableExists" resultType="Object">
2025-01-20 16:31:37 +08:00
SHOW STABLES LIKE 'device_log'
2025-01-12 20:13:41 +08:00
</select>
2025-01-24 15:56:01 +08:00
<select id="checkDeviceLogTableExists" resultType="Object">
SHOW TABLES LIKE 'device_log_${deviceKey}'
</select>
2025-01-05 22:56:13 +08:00
</mapper>