!1170 【代码优化】IOT: ThingModel 评审优化

Merge pull request !1170 from puhui999/iot
This commit is contained in:
芋道源码 2024-12-24 01:28:58 +00:00 committed by Gitee
commit 39896555f0
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 9 additions and 18 deletions

View File

@ -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());
});
}
/**

View File

@ -135,12 +135,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) {

View File

@ -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);