Commit 9ee57dce2481ad902cacc7d74bcb3b8d2ed90ee4
Committed by
YunaiV
1 parent
47c093ad
feat(iot): 为设备消息和属性添加时间戳处理
Showing
4 changed files
with
8 additions
and
3 deletions
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/message/IotDeviceMessageServiceImpl.java
| ... | ... | @@ -95,6 +95,9 @@ public class IotDeviceMessageServiceImpl implements IotDeviceMessageService { |
| 95 | 95 | if (messageDO.getData() != null) { |
| 96 | 96 | messageDO.setData(JsonUtils.toJsonString(messageDO.getData())); |
| 97 | 97 | } |
| 98 | + if (messageDO.getTs() == null) { | |
| 99 | + messageDO.setTs(System.currentTimeMillis()); | |
| 100 | + } | |
| 98 | 101 | try { |
| 99 | 102 | deviceMessageMapper.insert(messageDO); |
| 100 | 103 | } catch (Exception ex) { | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/property/IotDevicePropertyServiceImpl.java
| ... | ... | @@ -179,7 +179,9 @@ public class IotDevicePropertyServiceImpl implements IotDevicePropertyService { |
| 179 | 179 | log.error("[saveDeviceProperty][消息({}) 没有合法的属性]", message); |
| 180 | 180 | } else { |
| 181 | 181 | // 2.1 保存设备属性【数据】 |
| 182 | - devicePropertyMapper.insert(device, properties, LocalDateTimeUtil.toEpochMilli(message.getReportTime())); | |
| 182 | + devicePropertyMapper.insert(device, properties, | |
| 183 | + System.currentTimeMillis(), | |
| 184 | + LocalDateTimeUtil.toEpochMilli(message.getReportTime())); | |
| 183 | 185 | |
| 184 | 186 | // 2.2 保存设备属性【日志】 |
| 185 | 187 | Map<String, IotDevicePropertyDO> properties2 = convertMap(properties.entrySet(), Map.Entry::getKey, entry -> | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/device/IotDeviceMessageMapper.xml
| ... | ... | @@ -38,7 +38,7 @@ |
| 38 | 38 | USING device_message |
| 39 | 39 | TAGS (#{deviceId}) |
| 40 | 40 | VALUES ( |
| 41 | - NOW, #{id}, #{reportTime}, #{tenantId}, #{serverId}, | |
| 41 | + #{ts}, #{id}, #{reportTime}, #{tenantId}, #{serverId}, | |
| 42 | 42 | #{upstream}, #{reply}, #{identifier}, #{requestId}, #{method}, |
| 43 | 43 | #{params}, #{data}, #{code}, #{msg} |
| 44 | 44 | ) | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/device/IotDevicePropertyMapper.xml