【代码评审】IoT:tdengine 操作

This commit is contained in:
YunaiV 2024-12-05 21:45:48 +08:00
parent 89fb71e857
commit ce919d12d1
5 changed files with 5 additions and 7 deletions

View File

@ -31,6 +31,7 @@ public class IotDeviceDataController {
@Resource
private IotDeviceDataService deviceDataService;
// TODO @浩浩这里的 /latest-list包括方法名
@GetMapping("/latest")
@Operation(summary = "获取设备属性最新数据")
public CommonResult<List<IotDeviceDataRespVO>> getLatestDeviceProperties(@Valid IotDeviceDataPageReqVO deviceDataReqVO) {
@ -38,6 +39,7 @@ public class IotDeviceDataController {
return success(BeanUtils.toBean(list, IotDeviceDataRespVO.class));
}
// TODO @浩浩这里的 /history-page 包括方法名
@GetMapping("/history")
@Operation(summary = "获取设备属性历史数据")
public CommonResult<PageResult<IotTimeDataRespVO>> getHistoryDeviceProperties(@Valid IotDeviceDataPageReqVO deviceDataReqVO) {

View File

@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.iot.dal.tdengine;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.TdTableDO;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

View File

@ -133,7 +133,7 @@ public class IotDeviceDataServiceImpl implements IotDeviceDataService {
}
private static String getDeviceTableName(String productKey, String deviceName) {
return String.format(IotConstants.DEVICE_TABLE_NAME_FORMAT, productKey, deviceName);
return String.format(IotConstants.DEVICE_TABLE_NAME_FORMAT, productKey, deviceName);
}
}

View File

@ -139,13 +139,13 @@ public class IotDeviceServiceImpl implements IotDeviceService {
* @return 生成的 MQTT Password
*/
private String generateMqttPassword() {
// TODO @浩浩这里的 StrUtil 随机字符串
SecureRandom secureRandom = new SecureRandom();
byte[] passwordBytes = new byte[32]; // 256 位的随机数
secureRandom.nextBytes(passwordBytes);
return Base64.getUrlEncoder().withoutPadding().encodeToString(passwordBytes);
}
/**
* 生成唯一的 DeviceName
*

View File

@ -66,8 +66,7 @@ public class IotThingModelMessageServiceImpl implements IotThingModelMessageServ
if (IotDeviceStatusEnum.INACTIVE.getStatus().equals(device.getStatus())) {
createDeviceTable(device.getDeviceType(), device.getProductKey(), device.getDeviceName(), device.getDeviceKey());
iotDeviceService.updateDeviceStatus(new IotDeviceStatusUpdateReqVO()
.setId(device.getId())
.setStatus(IotDeviceStatusEnum.ONLINE.getStatus()));
.setId(device.getId()).setStatus(IotDeviceStatusEnum.ONLINE.getStatus()));
}
// 2. 获取设备属性并进行物模型校验过滤非物模型属性
@ -77,7 +76,6 @@ public class IotThingModelMessageServiceImpl implements IotThingModelMessageServ
return;
}
// 3. 过滤并收集有效的属性字段缓存设备属性
List<TdFieldDO> schemaFieldValues = filterAndCollectValidFields(params, functionList, device, thingModelMessage.getTime());
if (schemaFieldValues.size() == 1) { // 仅有时间字段无需保存
@ -165,7 +163,6 @@ public class IotThingModelMessageServiceImpl implements IotThingModelMessageServ
// 2.1 过滤出 TAG 类型的字段
List<Map<String, Object>> taggedNotesList = CollectionUtils.filterList(maps, map -> TAG_NOTE.equals(map.get(NOTE)));
// 2.2 解析字段信息
tagsFieldValues = FieldParser.parse(taggedNotesList.stream()
.map(map -> List.of(map.get("field"), map.get("type"), map.get("length")))