Эх сурвалжийг харах

!1170 【代码优化】IOT: ThingModel 评审优化
Merge pull request !1170 from puhui999/iot

芋道源码 7 сар өмнө
parent
commit
39896555f0

+ 5 - 8
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/tdengine/FieldParser.java

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

+ 2 - 6
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/tdengine/IotThingModelMessageServiceImpl.java

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

+ 2 - 4
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thingmodel/IotProductThingModelServiceImpl.java

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