Commit ce919d12d1b079ace85c70004bd6553053b76667
1 parent
89fb71e8
【代码评审】IoT:tdengine 操作
Showing
5 changed files
with
5 additions
and
7 deletions
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceDataController.java
| ... | ... | @@ -31,6 +31,7 @@ public class IotDeviceDataController { |
| 31 | 31 | @Resource |
| 32 | 32 | private IotDeviceDataService deviceDataService; |
| 33 | 33 | |
| 34 | + // TODO @浩浩:这里的 /latest-list,包括方法名。 | |
| 34 | 35 | @GetMapping("/latest") |
| 35 | 36 | @Operation(summary = "获取设备属性最新数据") |
| 36 | 37 | public CommonResult<List<IotDeviceDataRespVO>> getLatestDeviceProperties(@Valid IotDeviceDataPageReqVO deviceDataReqVO) { |
| ... | ... | @@ -38,6 +39,7 @@ public class IotDeviceDataController { |
| 38 | 39 | return success(BeanUtils.toBean(list, IotDeviceDataRespVO.class)); |
| 39 | 40 | } |
| 40 | 41 | |
| 42 | + // TODO @浩浩:这里的 /history-page 包括方法名。 | |
| 41 | 43 | @GetMapping("/history") |
| 42 | 44 | @Operation(summary = "获取设备属性历史数据") |
| 43 | 45 | public CommonResult<PageResult<IotTimeDataRespVO>> getHistoryDeviceProperties(@Valid IotDeviceDataPageReqVO deviceDataReqVO) { | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/tdengine/TdEngineDDLMapper.java
| ... | ... | @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.iot.dal.tdengine; |
| 3 | 3 | import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore; |
| 4 | 4 | import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.TdTableDO; |
| 5 | 5 | import com.baomidou.dynamic.datasource.annotation.DS; |
| 6 | -import com.baomidou.mybatisplus.annotation.InterceptorIgnore; | |
| 7 | 6 | import org.apache.ibatis.annotations.Mapper; |
| 8 | 7 | import org.apache.ibatis.annotations.Param; |
| 9 | 8 | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceDataServiceImpl.java
| ... | ... | @@ -133,7 +133,7 @@ public class IotDeviceDataServiceImpl implements IotDeviceDataService { |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | private static String getDeviceTableName(String productKey, String deviceName) { |
| 136 | - return String.format(IotConstants.DEVICE_TABLE_NAME_FORMAT, productKey, deviceName); | |
| 136 | + return String.format(IotConstants.DEVICE_TABLE_NAME_FORMAT, productKey, deviceName); | |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | } |
| 140 | 140 | \ No newline at end of file | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceServiceImpl.java
| ... | ... | @@ -139,13 +139,13 @@ public class IotDeviceServiceImpl implements IotDeviceService { |
| 139 | 139 | * @return 生成的 MQTT Password |
| 140 | 140 | */ |
| 141 | 141 | private String generateMqttPassword() { |
| 142 | + // TODO @浩浩:这里的 StrUtil 随机字符串? | |
| 142 | 143 | SecureRandom secureRandom = new SecureRandom(); |
| 143 | 144 | byte[] passwordBytes = new byte[32]; // 256 位的随机数 |
| 144 | 145 | secureRandom.nextBytes(passwordBytes); |
| 145 | 146 | return Base64.getUrlEncoder().withoutPadding().encodeToString(passwordBytes); |
| 146 | 147 | } |
| 147 | 148 | |
| 148 | - | |
| 149 | 149 | /** |
| 150 | 150 | * 生成唯一的 DeviceName |
| 151 | 151 | * | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/tdengine/IotThingModelMessageServiceImpl.java
| ... | ... | @@ -66,8 +66,7 @@ public class IotThingModelMessageServiceImpl implements IotThingModelMessageServ |
| 66 | 66 | if (IotDeviceStatusEnum.INACTIVE.getStatus().equals(device.getStatus())) { |
| 67 | 67 | createDeviceTable(device.getDeviceType(), device.getProductKey(), device.getDeviceName(), device.getDeviceKey()); |
| 68 | 68 | iotDeviceService.updateDeviceStatus(new IotDeviceStatusUpdateReqVO() |
| 69 | - .setId(device.getId()) | |
| 70 | - .setStatus(IotDeviceStatusEnum.ONLINE.getStatus())); | |
| 69 | + .setId(device.getId()).setStatus(IotDeviceStatusEnum.ONLINE.getStatus())); | |
| 71 | 70 | } |
| 72 | 71 | |
| 73 | 72 | // 2. 获取设备属性并进行物模型校验,过滤非物模型属性 |
| ... | ... | @@ -77,7 +76,6 @@ public class IotThingModelMessageServiceImpl implements IotThingModelMessageServ |
| 77 | 76 | return; |
| 78 | 77 | } |
| 79 | 78 | |
| 80 | - | |
| 81 | 79 | // 3. 过滤并收集有效的属性字段,缓存设备属性 |
| 82 | 80 | List<TdFieldDO> schemaFieldValues = filterAndCollectValidFields(params, functionList, device, thingModelMessage.getTime()); |
| 83 | 81 | if (schemaFieldValues.size() == 1) { // 仅有时间字段,无需保存 |
| ... | ... | @@ -165,7 +163,6 @@ public class IotThingModelMessageServiceImpl implements IotThingModelMessageServ |
| 165 | 163 | // 2.1 过滤出 TAG 类型的字段 |
| 166 | 164 | List<Map<String, Object>> taggedNotesList = CollectionUtils.filterList(maps, map -> TAG_NOTE.equals(map.get(NOTE))); |
| 167 | 165 | |
| 168 | - | |
| 169 | 166 | // 2.2 解析字段信息 |
| 170 | 167 | tagsFieldValues = FieldParser.parse(taggedNotesList.stream() |
| 171 | 168 | .map(map -> List.of(map.get("field"), map.get("type"), map.get("length"))) | ... | ... |