fix:修复已知bug

liutao_branch
HuangHuiKang 2 weeks ago
parent f1dd991cde
commit 827dd9a071

@ -41,7 +41,7 @@ public class DeviceRespVO {
private String deviceType;
@Schema(description = "状态", example = "1")
@ExcelProperty(value = "连接状态", converter = DictConvert.class)
// @ExcelProperty(value = "连接状态", converter = DictConvert.class)
@DictFormat("iot_gateway_status") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
private String status;
@ -66,7 +66,7 @@ public class DeviceRespVO {
private Long offLineDuration;
@Schema(description = "最后上线时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("最后上线时间")
// @ExcelProperty("最后上线时间")
private LocalDateTime lastOnlineTime;
@Schema(description = "备注", example = "你说的对")
@ -92,19 +92,19 @@ public class DeviceRespVO {
private String protocol;
@Schema(description = "采集周期", example = "30")
@ExcelProperty("采集周期")
// @ExcelProperty("采集周期")
private Double sampleCycle;
@Schema(description = "端点url", example = "opc.tcp://127.0.0.1:48401")
@ExcelProperty("端点url")
// @ExcelProperty("端点url")
private String url;
@Schema(description = "用户名", example = "admin")
@ExcelProperty("用户名")
// @ExcelProperty("用户名")
private String username;
@Schema(description = "密码", example = "1234")
@ExcelProperty("密码")
// @ExcelProperty("密码")
private String password;
@Schema(description = "运行状态")
@ -124,5 +124,6 @@ public class DeviceRespVO {
private Long org;
@Schema(description = "mqtt订阅主题")
@ExcelProperty("mqtt订阅主题")
private String topic;
}

@ -24,7 +24,6 @@ public class DeviceContactModelRespVO {
private String attributeName;
@Schema(description = "点位类型", example = "1")
@ExcelProperty("点位类型")
private String attributeType;
@Schema(description = "数据类型", example = "1")
@ -48,7 +47,7 @@ public class DeviceContactModelRespVO {
private String remark;
@Schema(description = "采集设备模型id", requiredMode = Schema.RequiredMode.REQUIRED, example = "13862")
@ExcelProperty("采集设备模型id")
// @ExcelProperty("采集设备模型id")
private Long deviceModelId;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ -60,6 +59,7 @@ public class DeviceContactModelRespVO {
private int sort;
@Schema(description = "采集点类型名称", example = "1")
@ExcelProperty("点位类型")
private String typeName;

@ -138,7 +138,7 @@ public class DeviceModelAttributeController {
.attributeCode("temperature_001")
.attributeName("温度")
// .attributeType("1")
.typeName("报警信息")
.typeCode("SBCS")
.dataType("float")
.address("AI0")
.dataUnit("s")
@ -149,7 +149,7 @@ public class DeviceModelAttributeController {
.attributeCode("humidity_001")
.attributeName("湿度")
// .attributeType("2")
.typeName("能源参数")
.typeCode("PROC")
.dataType("double")
.address("AI1")
.dataUnit("s")

@ -33,8 +33,8 @@ public class DeviceModelAttributeImportExcelVO {
@ExcelIgnore
private String attributeType;
@ExcelProperty("点位类型名称")
private String typeName;
@ExcelProperty("点位类型编码")
private String typeCode;
@ExcelProperty(value = "数据类型") // 对应 User 的 "用户性别"
// , converter = DictConvert.class

@ -25,6 +25,10 @@ public class DeviceModelAttributeRespVO {
@ExcelProperty("点位名称")
private String attributeName;
@Schema(description = "采集点位类型编码", example = "1")
@ExcelProperty("采集点位类型编码")
private String attributeTypeCode;
@Schema(description = "点位类型", example = "1")
@ExcelProperty("点位类型")
private String attributeType;
@ -66,5 +70,4 @@ public class DeviceModelAttributeRespVO {
private LocalDateTime createTime;
}

@ -58,6 +58,6 @@ public class TimeConverterUtil {
*
*/
public static String getPercentString(double value) {
return formatDouble(value, 2) + "%";
return formatDouble(value * 100, 2) + "%";
}
}

@ -32,7 +32,7 @@ public interface DeviceModelAttributeService {
/**
* -
*
* @param id
* @param idList
*/
void deleteDeviceModelAttribute(List<Long> idList );

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

@ -32,6 +32,10 @@ public class CriticalComponentExcelVO {
@ExcelProperty("描述")
private String description;
@Schema(description = "数量", example = "2")
@ExcelProperty("数量")
private Integer count;
@Schema(description = "备注")
@ExcelProperty("备注")
private String remark;
@ -41,4 +45,6 @@ public class CriticalComponentExcelVO {
@ColumnWidth(20)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime createTime;
}

@ -34,5 +34,7 @@ public class CriticalComponentPageReqVO extends PageParam {
@Schema(description = "id集合导出用")
private String ids;
@Schema(description = "数量", example = "2")
private Integer count;
}

@ -38,4 +38,7 @@ public class CriticalComponentRespVO {
@ColumnWidth(20)
private LocalDateTime createTime;
@Schema(description = "数量", example = "2")
private Integer count;
}

@ -26,4 +26,8 @@ public class CriticalComponentSaveReqVO {
@Schema(description = "备注", example = "你说的对")
private String remark;
@Schema(description = "数量", example = "2")
private Integer count;
}

@ -43,5 +43,9 @@ public class CriticalComponentDO extends BaseDO {
*
*/
private String remark;
/**
*
*/
private Integer count;
}
Loading…
Cancel
Save