【代码优化】IOT: ThingModel 评审优化
This commit is contained in:
parent
b2434b7b41
commit
767a26dd70
|
@ -5,7 +5,8 @@ import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelR
|
|||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
||||
|
||||
/**
|
||||
* FieldParser 类用于解析和转换物模型字段到 TDengine 字段
|
||||
|
@ -52,10 +53,7 @@ public class FieldParser {
|
|||
* @return 字段列表
|
||||
*/
|
||||
public static List<TdFieldDO> parse(ThingModelRespVO thingModel) {
|
||||
// TODO @puhui999:是不是使用 convertList
|
||||
return thingModel.getModel().getProperties().stream()
|
||||
.map(FieldParser::parse)
|
||||
.collect(Collectors.toList());
|
||||
return convertList(thingModel.getModel().getProperties(), FieldParser::parse);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -65,13 +63,12 @@ public class FieldParser {
|
|||
* @return 转换后的 TDengine 字段对象列表
|
||||
*/
|
||||
public static List<TdFieldDO> parse(List<List<Object>> rows) {
|
||||
// TODO @puhui999:是不是使用 convertList
|
||||
return rows.stream().map(row -> {
|
||||
return convertList(rows, row -> {
|
||||
String type = row.get(1).toString().toUpperCase();
|
||||
// TODO @puhui999:"NCHAR" 最好枚举下
|
||||
int dataLength = "NCHAR".equals(type) ? Integer.parseInt(row.get(2).toString()) : -1;
|
||||
return new TdFieldDO(row.get(0).toString(), type, dataLength);
|
||||
}).collect(Collectors.toList());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -122,7 +122,7 @@ public class IotProductServiceImpl implements IotProductService {
|
|||
thingModelFunctionService.createSuperTableDataModel(id);
|
||||
// 3.2 创建物模型日志超级表数据模型
|
||||
thingModelMessageService.createSuperTable(id);
|
||||
}x
|
||||
}
|
||||
productMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,13 +7,9 @@ import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
|
|||
import cn.iocoder.yudao.module.iot.controller.admin.device.vo.device.IotDeviceStatusUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDataDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.FieldParser;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.TdFieldDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.TdTableDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.ThingModelMessage;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotProductThingModelDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.*;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotProductThingModelDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.redis.deviceData.DeviceDataRedisDAO;
|
||||
import cn.iocoder.yudao.module.iot.dal.tdengine.TdEngineDDLMapper;
|
||||
import cn.iocoder.yudao.module.iot.dal.tdengine.TdEngineDMLMapper;
|
||||
|
@ -22,8 +18,8 @@ import cn.iocoder.yudao.module.iot.enums.IotConstants;
|
|||
import cn.iocoder.yudao.module.iot.enums.device.IotDeviceStatusEnum;
|
||||
import cn.iocoder.yudao.module.iot.enums.thingmodel.IotProductThingModelTypeEnum;
|
||||
import cn.iocoder.yudao.module.iot.service.device.IotDeviceService;
|
||||
import cn.iocoder.yudao.module.iot.service.thingmodel.IotProductThingModelService;
|
||||
import cn.iocoder.yudao.module.iot.service.product.IotProductService;
|
||||
import cn.iocoder.yudao.module.iot.service.thingmodel.IotProductThingModelService;
|
||||
import cn.iocoder.yudao.module.iot.util.IotTdDatabaseUtils;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
@ -132,12 +128,8 @@ public class IotThingModelMessageServiceImpl implements IotThingModelMessageServ
|
|||
}
|
||||
|
||||
private List<IotProductThingModelDO> getValidFunctionList(String productKey) {
|
||||
// TODO @puhui999:使用 convertList 会好点哈
|
||||
return iotProductThingModelService
|
||||
.getProductThingModelListByProductKey(productKey)
|
||||
.stream()
|
||||
.filter(function -> IotProductThingModelTypeEnum.PROPERTY.getType().equals(function.getType()))
|
||||
.toList();
|
||||
return filterList(iotProductThingModelService.getProductThingModelListByProductKey(productKey),
|
||||
thingModel -> IotProductThingModelTypeEnum.PROPERTY.getType().equals(thingModel.getType()));
|
||||
}
|
||||
|
||||
private List<TdFieldDO> filterAndCollectValidFields(Map<String, Object> params, List<IotProductThingModelDO> thingModelList, IotDeviceDO device, Long time) {
|
||||
|
@ -235,9 +227,8 @@ public class IotThingModelMessageServiceImpl implements IotThingModelMessageServ
|
|||
* @param productKey 产品 Key
|
||||
* @param deviceName 设备名称
|
||||
* @param deviceKey 设备 Key
|
||||
*
|
||||
*/
|
||||
private void createThinkModelMessageDeviceTable(String productKey, String deviceName, String deviceKey){
|
||||
private void createThinkModelMessageDeviceTable(String productKey, String deviceName, String deviceKey) {
|
||||
|
||||
// 1. 获取超级表的名称、数据库名称、设备日志表名称
|
||||
String databaseName = iotTdDatabaseUtils.getDatabaseName();
|
||||
|
|
|
@ -29,10 +29,10 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList;
|
||||
import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
|
@ -261,9 +261,7 @@ public class IotProductThingModelServiceImpl implements IotProductThingModelServ
|
|||
}
|
||||
});
|
||||
// 过滤掉没有设置 ID 的对象
|
||||
List<IotProductThingModelDO> validUpdateList = updateList.stream()
|
||||
.filter(func -> func.getId() != null)
|
||||
.collect(Collectors.toList());
|
||||
List<IotProductThingModelDO> validUpdateList = filterList(updateList, thingModel -> thingModel.getId() != null);
|
||||
// 执行批量更新
|
||||
if (CollUtil.isNotEmpty(validUpdateList)) {
|
||||
productThingModelMapper.updateBatch(validUpdateList);
|
||||
|
|
Loading…
Reference in New Issue