Commit 39896555f0b7f1a58e193f52d34d544da14b1fc1

Authored by 芋道源码
Committed by Gitee
2 parents e01d03ee ed901bc9

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

Merge pull request !1170 from puhui999/iot
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 @@ -5,7 +5,8 @@ import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelR
5 5
6 import java.util.HashMap; 6 import java.util.HashMap;
7 import java.util.List; 7 import java.util.List;
8 -import java.util.stream.Collectors; 8 +
  9 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
9 10
10 /** 11 /**
11 * FieldParser 类用于解析和转换物模型字段到 TDengine 字段 12 * FieldParser 类用于解析和转换物模型字段到 TDengine 字段
@@ -52,10 +53,7 @@ public class FieldParser { @@ -52,10 +53,7 @@ public class FieldParser {
52 * @return 字段列表 53 * @return 字段列表
53 */ 54 */
54 public static List<TdFieldDO> parse(ThingModelRespVO thingModel) { 55 public static List<TdFieldDO> parse(ThingModelRespVO thingModel) {
55 - // TODO @puhui999:是不是使用 convertList  
56 - return thingModel.getModel().getProperties().stream()  
57 - .map(FieldParser::parse)  
58 - .collect(Collectors.toList()); 56 + return convertList(thingModel.getModel().getProperties(), FieldParser::parse);
59 } 57 }
60 58
61 /** 59 /**
@@ -65,13 +63,12 @@ public class FieldParser { @@ -65,13 +63,12 @@ public class FieldParser {
65 * @return 转换后的 TDengine 字段对象列表 63 * @return 转换后的 TDengine 字段对象列表
66 */ 64 */
67 public static List<TdFieldDO> parse(List<List<Object>> rows) { 65 public static List<TdFieldDO> parse(List<List<Object>> rows) {
68 - // TODO @puhui999:是不是使用 convertList  
69 - return rows.stream().map(row -> { 66 + return convertList(rows, row -> {
70 String type = row.get(1).toString().toUpperCase(); 67 String type = row.get(1).toString().toUpperCase();
71 // TODO @puhui999:"NCHAR" 最好枚举下 68 // TODO @puhui999:"NCHAR" 最好枚举下
72 int dataLength = "NCHAR".equals(type) ? Integer.parseInt(row.get(2).toString()) : -1; 69 int dataLength = "NCHAR".equals(type) ? Integer.parseInt(row.get(2).toString()) : -1;
73 return new TdFieldDO(row.get(0).toString(), type, dataLength); 70 return new TdFieldDO(row.get(0).toString(), type, dataLength);
74 - }).collect(Collectors.toList()); 71 + });
75 } 72 }
76 73
77 /** 74 /**
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 @@ -135,12 +135,8 @@ public class IotThingModelMessageServiceImpl implements IotThingModelMessageServ
135 } 135 }
136 136
137 private List<IotProductThingModelDO> getValidFunctionList(String productKey) { 137 private List<IotProductThingModelDO> getValidFunctionList(String productKey) {
138 - // TODO @puhui999:使用 convertList 会好点哈  
139 - return iotProductThingModelService  
140 - .getProductThingModelListByProductKey(productKey)  
141 - .stream()  
142 - .filter(function -> IotProductThingModelTypeEnum.PROPERTY.getType().equals(function.getType()))  
143 - .toList(); 138 + return filterList(iotProductThingModelService.getProductThingModelListByProductKey(productKey),
  139 + thingModel -> IotProductThingModelTypeEnum.PROPERTY.getType().equals(thingModel.getType()));
144 } 140 }
145 141
146 private List<TdFieldDO> filterAndCollectValidFields(Map<String, Object> params, List<IotProductThingModelDO> thingModelList, IotDeviceDO device, Long time) { 142 private List<TdFieldDO> filterAndCollectValidFields(Map<String, Object> params, List<IotProductThingModelDO> thingModelList, IotDeviceDO device, Long time) {
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; @@ -29,10 +29,10 @@ import org.springframework.transaction.annotation.Transactional;
29 import org.springframework.validation.annotation.Validated; 29 import org.springframework.validation.annotation.Validated;
30 30
31 import java.util.*; 31 import java.util.*;
32 -import java.util.stream.Collectors;  
33 32
34 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; 33 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
35 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList; 34 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
  35 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList;
36 import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*; 36 import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*;
37 37
38 /** 38 /**
@@ -261,9 +261,7 @@ public class IotProductThingModelServiceImpl implements IotProductThingModelServ @@ -261,9 +261,7 @@ public class IotProductThingModelServiceImpl implements IotProductThingModelServ
261 } 261 }
262 }); 262 });
263 // 过滤掉没有设置 ID 的对象 263 // 过滤掉没有设置 ID 的对象
264 - List<IotProductThingModelDO> validUpdateList = updateList.stream()  
265 - .filter(func -> func.getId() != null)  
266 - .collect(Collectors.toList()); 264 + List<IotProductThingModelDO> validUpdateList = filterList(updateList, thingModel -> thingModel.getId() != null);
267 // 执行批量更新 265 // 执行批量更新
268 if (CollUtil.isNotEmpty(validUpdateList)) { 266 if (CollUtil.isNotEmpty(validUpdateList)) {
269 productThingModelMapper.updateBatch(validUpdateList); 267 productThingModelMapper.updateBatch(validUpdateList);