|
|
|
|
@ -126,6 +126,7 @@ import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*;
|
|
|
|
|
// 获取设备模型属性分页数据
|
|
|
|
|
PageResult<DeviceModelAttributeDO> pageResult = deviceModelAttributeMapper.selectPage(pageReqVO);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// // 获取所有属性类型并构建映射
|
|
|
|
|
// List<DeviceAttributeTypeDO> attributeTypes = deviceAttributeTypeMapper.selectList();
|
|
|
|
|
// Map<Long, String> typeNameMap = attributeTypes.stream()
|
|
|
|
|
@ -158,6 +159,30 @@ import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
List<DeviceModelAttributeRespVO> list = respPageResult.getList();
|
|
|
|
|
if (CollUtil.isEmpty(list)) {
|
|
|
|
|
return respPageResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 收集 attributeType
|
|
|
|
|
Set<String> typeIds = list.stream()
|
|
|
|
|
.map(DeviceModelAttributeRespVO::getAttributeType)
|
|
|
|
|
.filter(Objects::nonNull)
|
|
|
|
|
.collect(Collectors.toSet());
|
|
|
|
|
|
|
|
|
|
if (CollUtil.isEmpty(typeIds)) {
|
|
|
|
|
return respPageResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 查询并转成 id -> code
|
|
|
|
|
Map<Long, String> typeCodeMap = deviceAttributeTypeMapper.selectBatchIds(typeIds)
|
|
|
|
|
.stream()
|
|
|
|
|
.collect(Collectors.toMap(DeviceAttributeTypeDO::getId, DeviceAttributeTypeDO::getCode));
|
|
|
|
|
|
|
|
|
|
// 赋值
|
|
|
|
|
list.forEach(item ->
|
|
|
|
|
item.setAttributeTypeCode(typeCodeMap.get(Long.valueOf(item.getAttributeType())))
|
|
|
|
|
);
|
|
|
|
|
// respPageResult.getList().forEach(item -> {
|
|
|
|
|
// String typeName = typeNameMap.get(item.getAttributeType());
|
|
|
|
|
// if (typeName != null) {
|
|
|
|
|
@ -245,8 +270,12 @@ import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*;
|
|
|
|
|
|
|
|
|
|
// 2. 构建点位类型名称到ID的映射
|
|
|
|
|
List<DeviceAttributeTypeDO> attributeTypes = deviceAttributeTypeMapper.selectList();
|
|
|
|
|
Map<String, String> typeNameToIdMap = attributeTypes.stream()
|
|
|
|
|
.collect(Collectors.toMap(DeviceAttributeTypeDO::getName, type -> String.valueOf(type.getId())));
|
|
|
|
|
Map<String, String> typeCodeToIdMap = attributeTypes.stream()
|
|
|
|
|
.collect(Collectors.toMap(DeviceAttributeTypeDO::getCode, type -> String.valueOf(type.getId())));
|
|
|
|
|
|
|
|
|
|
Map<String, String> typeCodeToNameMap = attributeTypes.stream()
|
|
|
|
|
.collect(Collectors.toMap(DeviceAttributeTypeDO::getCode, DeviceAttributeTypeDO::getName));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 3. 初始化返回 VO - 完全复刻 User 的 builder 方式,使用 LinkedHashMap 保持顺序
|
|
|
|
|
@ -262,20 +291,20 @@ import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*;
|
|
|
|
|
importAttribute.setDeviceModelId(deviceModelId);
|
|
|
|
|
|
|
|
|
|
// 4.2 处理点位类型转换
|
|
|
|
|
String typeName = importAttribute.getTypeName();
|
|
|
|
|
String code = importAttribute.getTypeCode();
|
|
|
|
|
|
|
|
|
|
// 不能为空
|
|
|
|
|
if (StringUtils.isBlank(typeName)) {
|
|
|
|
|
if (StringUtils.isBlank(code)) {
|
|
|
|
|
respVO.getFailureCodes().put(importAttribute.getAttributeCode(), "点位类型名称不能为空");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// 必须存在于数据库类型列表中(防止乱填)
|
|
|
|
|
if (!typeNameToIdMap.containsKey(typeName)) {
|
|
|
|
|
if (!typeCodeToIdMap.containsKey(code)) {
|
|
|
|
|
respVO.getFailureCodes().put(importAttribute.getAttributeCode(),
|
|
|
|
|
"点位类型名称不存在: " + typeName);
|
|
|
|
|
"点位类型名称不存在: " + code);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
String attributeTypeId = typeNameToIdMap.get(typeName);
|
|
|
|
|
String attributeTypeId = typeCodeToIdMap.get(code);
|
|
|
|
|
// 设置点位类型ID
|
|
|
|
|
importAttribute.setAttributeType(attributeTypeId);
|
|
|
|
|
|
|
|
|
|
@ -335,7 +364,7 @@ import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*;
|
|
|
|
|
// 不存在 → 新增
|
|
|
|
|
DeviceModelAttributeDO deviceModelAttribute =
|
|
|
|
|
BeanUtils.toBean(importAttribute, DeviceModelAttributeDO.class);
|
|
|
|
|
deviceModelAttribute.setTypeName(typeName);
|
|
|
|
|
deviceModelAttribute.setTypeName(typeCodeToNameMap.get(code));
|
|
|
|
|
|
|
|
|
|
deviceModelAttributeMapper.insert(deviceModelAttribute);
|
|
|
|
|
respVO.getCreateCodes().add(importAttribute.getAttributeCode());
|
|
|
|
|
@ -348,7 +377,7 @@ import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*;
|
|
|
|
|
if (existAttribute == null) {
|
|
|
|
|
DeviceModelAttributeDO deviceModelAttribute =
|
|
|
|
|
BeanUtils.toBean(importAttribute, DeviceModelAttributeDO.class);
|
|
|
|
|
deviceModelAttribute.setTypeName(typeName);
|
|
|
|
|
deviceModelAttribute.setTypeName(typeCodeToNameMap.get(code));
|
|
|
|
|
|
|
|
|
|
deviceModelAttributeMapper.insert(deviceModelAttribute);
|
|
|
|
|
respVO.getCreateCodes().add(importAttribute.getAttributeCode());
|
|
|
|
|
@ -359,7 +388,7 @@ import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*;
|
|
|
|
|
DeviceModelAttributeDO updateAttribute =
|
|
|
|
|
BeanUtils.toBean(importAttribute, DeviceModelAttributeDO.class);
|
|
|
|
|
updateAttribute.setId(existAttribute.getId());
|
|
|
|
|
updateAttribute.setTypeName(typeName);
|
|
|
|
|
updateAttribute.setTypeName(typeCodeToNameMap.get(code));
|
|
|
|
|
|
|
|
|
|
deviceModelAttributeMapper.updateById(updateAttribute);
|
|
|
|
|
respVO.getUpdateCodes().add(importAttribute.getAttributeCode());
|
|
|
|
|
|