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,6 +95,9 @@ public class IotDeviceMessageServiceImpl implements IotDeviceMessageService { | ||
| 95 | if (messageDO.getData() != null) { | 95 | if (messageDO.getData() != null) { |
| 96 | messageDO.setData(JsonUtils.toJsonString(messageDO.getData())); | 96 | messageDO.setData(JsonUtils.toJsonString(messageDO.getData())); |
| 97 | } | 97 | } |
| 98 | + if (messageDO.getTs() == null) { | ||
| 99 | + messageDO.setTs(System.currentTimeMillis()); | ||
| 100 | + } | ||
| 98 | try { | 101 | try { |
| 99 | deviceMessageMapper.insert(messageDO); | 102 | deviceMessageMapper.insert(messageDO); |
| 100 | } catch (Exception ex) { | 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,7 +179,9 @@ public class IotDevicePropertyServiceImpl implements IotDevicePropertyService { | ||
| 179 | log.error("[saveDeviceProperty][消息({}) 没有合法的属性]", message); | 179 | log.error("[saveDeviceProperty][消息({}) 没有合法的属性]", message); |
| 180 | } else { | 180 | } else { |
| 181 | // 2.1 保存设备属性【数据】 | 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 | // 2.2 保存设备属性【日志】 | 186 | // 2.2 保存设备属性【日志】 |
| 185 | Map<String, IotDevicePropertyDO> properties2 = convertMap(properties.entrySet(), Map.Entry::getKey, entry -> | 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,7 +38,7 @@ | ||
| 38 | USING device_message | 38 | USING device_message |
| 39 | TAGS (#{deviceId}) | 39 | TAGS (#{deviceId}) |
| 40 | VALUES ( | 40 | VALUES ( |
| 41 | - NOW, #{id}, #{reportTime}, #{tenantId}, #{serverId}, | 41 | + #{ts}, #{id}, #{reportTime}, #{tenantId}, #{serverId}, |
| 42 | #{upstream}, #{reply}, #{identifier}, #{requestId}, #{method}, | 42 | #{upstream}, #{reply}, #{identifier}, #{requestId}, #{method}, |
| 43 | #{params}, #{data}, #{code}, #{msg} | 43 | #{params}, #{data}, #{code}, #{msg} |
| 44 | ) | 44 | ) |
yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/device/IotDevicePropertyMapper.xml
| @@ -55,7 +55,7 @@ | @@ -55,7 +55,7 @@ | ||
| 55 | </foreach> | 55 | </foreach> |
| 56 | ) | 56 | ) |
| 57 | VALUES | 57 | VALUES |
| 58 | - (NOW, #{reportTime}, | 58 | + (#{ts}, #{reportTime}, |
| 59 | <foreach item="value" collection="properties.values" separator=","> | 59 | <foreach item="value" collection="properties.values" separator=","> |
| 60 | #{value} | 60 | #{value} |
| 61 | </foreach> | 61 | </foreach> |