
1. DeviceDataApi => IotDeviceUpstreamApi,并新建 upstream 包 2. ThingModelMessage => IotDeviceMessage 设备消息 3. 基于 spring event 异步消费 IotDeviceMessage,并实现 IotDeviceLogMessageConsumer 记录日志
77 lines
2.6 KiB
XML
77 lines
2.6 KiB
XML
<?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">
|
|
CREATE STABLE IF NOT EXISTS device_log (
|
|
ts TIMESTAMP,
|
|
id NCHAR(50),
|
|
product_key NCHAR(50),
|
|
device_name NCHAR(50),
|
|
type NCHAR(50),
|
|
identifier NCHAR(255),
|
|
content NCHAR(1024),
|
|
report_time TIMESTAMP
|
|
) TAGS (
|
|
device_key NCHAR(50)
|
|
)
|
|
</update>
|
|
|
|
<select id="showDeviceLogSTable" resultType="String">
|
|
SHOW STABLES LIKE 'device_log'
|
|
</select>
|
|
|
|
<insert id="insert">
|
|
INSERT INTO device_log_${deviceKey} (ts, id, product_key, device_name, type, identifier, content, report_time)
|
|
USING device_log
|
|
TAGS ('${deviceKey}')
|
|
VALUES (
|
|
NOW,
|
|
#{id},
|
|
#{productKey},
|
|
#{deviceName},
|
|
#{type},
|
|
#{identifier},
|
|
#{content},
|
|
#{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>
|
|
|
|
<!-- TODO 芋艿:看看能不能复用 mybatis-plus 的 selectCount 方法 -->
|
|
<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>
|
|
|
|
</mapper> |