!1170 【代码优化】IOT: ThingModel 评审优化
Merge pull request !1170 from puhui999/iot
This commit is contained in:
commit
39896555f0
|
@ -5,7 +5,8 @@ import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelR
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FieldParser 类用于解析和转换物模型字段到 TDengine 字段
|
* FieldParser 类用于解析和转换物模型字段到 TDengine 字段
|
||||||
|
@ -52,10 +53,7 @@ public class FieldParser {
|
||||||
* @return 字段列表
|
* @return 字段列表
|
||||||
*/
|
*/
|
||||||
public static List<TdFieldDO> parse(ThingModelRespVO thingModel) {
|
public static List<TdFieldDO> parse(ThingModelRespVO thingModel) {
|
||||||
// TODO @puhui999:是不是使用 convertList
|
return convertList(thingModel.getModel().getProperties(), FieldParser::parse);
|
||||||
return thingModel.getModel().getProperties().stream()
|
|
||||||
.map(FieldParser::parse)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -65,13 +63,12 @@ public class FieldParser {
|
||||||
* @return 转换后的 TDengine 字段对象列表
|
* @return 转换后的 TDengine 字段对象列表
|
||||||
*/
|
*/
|
||||||
public static List<TdFieldDO> parse(List<List<Object>> rows) {
|
public static List<TdFieldDO> parse(List<List<Object>> rows) {
|
||||||
// TODO @puhui999:是不是使用 convertList
|
return convertList(rows, row -> {
|
||||||
return rows.stream().map(row -> {
|
|
||||||
String type = row.get(1).toString().toUpperCase();
|
String type = row.get(1).toString().toUpperCase();
|
||||||
// TODO @puhui999:"NCHAR" 最好枚举下
|
// TODO @puhui999:"NCHAR" 最好枚举下
|
||||||
int dataLength = "NCHAR".equals(type) ? Integer.parseInt(row.get(2).toString()) : -1;
|
int dataLength = "NCHAR".equals(type) ? Integer.parseInt(row.get(2).toString()) : -1;
|
||||||
return new TdFieldDO(row.get(0).toString(), type, dataLength);
|
return new TdFieldDO(row.get(0).toString(), type, dataLength);
|
||||||
}).collect(Collectors.toList());
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -135,12 +135,8 @@ public class IotThingModelMessageServiceImpl implements IotThingModelMessageServ
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<IotProductThingModelDO> getValidFunctionList(String productKey) {
|
private List<IotProductThingModelDO> getValidFunctionList(String productKey) {
|
||||||
// TODO @puhui999:使用 convertList 会好点哈
|
return filterList(iotProductThingModelService.getProductThingModelListByProductKey(productKey),
|
||||||
return iotProductThingModelService
|
thingModel -> IotProductThingModelTypeEnum.PROPERTY.getType().equals(thingModel.getType()));
|
||||||
.getProductThingModelListByProductKey(productKey)
|
|
||||||
.stream()
|
|
||||||
.filter(function -> IotProductThingModelTypeEnum.PROPERTY.getType().equals(function.getType()))
|
|
||||||
.toList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<TdFieldDO> filterAndCollectValidFields(Map<String, Object> params, List<IotProductThingModelDO> thingModelList, IotDeviceDO device, Long time) {
|
private List<TdFieldDO> filterAndCollectValidFields(Map<String, Object> params, List<IotProductThingModelDO> thingModelList, IotDeviceDO device, Long time) {
|
||||||
|
|
|
@ -29,10 +29,10 @@ import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
import java.util.*;
|
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.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.diffList;
|
||||||
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList;
|
||||||
import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*;
|
import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -261,9 +261,7 @@ public class IotProductThingModelServiceImpl implements IotProductThingModelServ
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// 过滤掉没有设置 ID 的对象
|
// 过滤掉没有设置 ID 的对象
|
||||||
List<IotProductThingModelDO> validUpdateList = updateList.stream()
|
List<IotProductThingModelDO> validUpdateList = filterList(updateList, thingModel -> thingModel.getId() != null);
|
||||||
.filter(func -> func.getId() != null)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
// 执行批量更新
|
// 执行批量更新
|
||||||
if (CollUtil.isNotEmpty(validUpdateList)) {
|
if (CollUtil.isNotEmpty(validUpdateList)) {
|
||||||
productThingModelMapper.updateBatch(validUpdateList);
|
productThingModelMapper.updateBatch(validUpdateList);
|
||||||
|
|
Loading…
Reference in New Issue