Commit ce919d12d1b079ace85c70004bd6553053b76667

Authored by YunaiV
1 parent 89fb71e8

【代码评审】IoT:tdengine 操作

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