bug
This commit is contained in:
parent
2dfe968f16
commit
fc864d4b1c
@ -66,8 +66,9 @@ public class AutoCollectService {
|
||||
private static final String REDIS_EQUIP_PREFIX = "dry_equipment:";
|
||||
// 前端 MQTT 推送主题
|
||||
private static final String FRONTEND_TOPIC = "equipment/data_update";
|
||||
// 设备总数(30台)
|
||||
private static final int TOTAL_EQUIPMENT = 30;
|
||||
|
||||
private static final int TOTAL_EQUIPMENT = 26; // 干燥机1-26台
|
||||
private static final int TOTAL_DEW_EQUIPMENT = 4; // 露点机1-4台
|
||||
// 时间格式化器
|
||||
private static final DateTimeFormatter DATETIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
// 参数编码常量
|
||||
@ -284,36 +285,64 @@ public class AutoCollectService {
|
||||
/**
|
||||
* 从Redis读取干燥机温度数据
|
||||
*/
|
||||
/**
|
||||
* 从Redis读取干燥机温度数据(1-26台,无数据显示0)
|
||||
*/
|
||||
private List<EquipmentScreenDTO.DryingDTO> buildFrontendDataList() {
|
||||
List<EquipmentScreenDTO.DryingDTO> result = new ArrayList<>();
|
||||
|
||||
// 遍历30台设备(001-030)
|
||||
// 遍历1-26台干燥机(001-026)
|
||||
for (int i = 1; i <= TOTAL_EQUIPMENT; i++) {
|
||||
String equipmentId = String.format("%03d", i); // 设备ID:001-030
|
||||
String equipmentId = String.format("%03d", i); // 格式化设备ID:001-026
|
||||
DryEquipmentInfo equipmentInfo = equipmentInfoCache.get(equipmentId);
|
||||
|
||||
// 构造默认设备信息(缓存中无数据时使用)
|
||||
if (equipmentInfo == null) {
|
||||
log.warn("【前端推送任务】设备ID{}无对应信息,跳过", equipmentId);
|
||||
continue;
|
||||
log.warn("【前端推送任务】干燥机{}无缓存信息,使用默认配置", equipmentId);
|
||||
equipmentInfo = new DryEquipmentInfo();
|
||||
equipmentInfo.setEquipmentCode("EQ-DRY-" + equipmentId); // 编码:EQ-DRY-001
|
||||
equipmentInfo.setEquipmentName("干燥机" + equipmentId); // 名称:干燥机001
|
||||
equipmentInfo.setRuleCode("");
|
||||
equipmentInfo.setSetTem("0"); // 默认设定温度0
|
||||
}
|
||||
|
||||
// 从Redis读取该设备的最新数据(Key格式:dry_equipment:001:TEMP)
|
||||
String redisKey = REDIS_EQUIP_PREFIX + equipmentId + ":TEMP";
|
||||
// 读取Redis温度数据
|
||||
String redisKey = REDIS_EQUIP_PREFIX + equipmentId + ":" + PARAM_TEMP;
|
||||
MqttDataHandler.EquipmentData redisData = (MqttDataHandler.EquipmentData) redisTemplate.opsForValue().get(redisKey);
|
||||
|
||||
// 增加redisData空判断,避免传递null
|
||||
if (redisData == null) {
|
||||
log.debug("【前端推送任务】设备ID{}无Redis数据,跳过", equipmentId);
|
||||
continue;
|
||||
// 构造DryingDTO,无数据填0
|
||||
EquipmentScreenDTO.DryingDTO dbData = new EquipmentScreenDTO.DryingDTO();
|
||||
EquipmentScreenDTO.ParamDTO paramDTO = new EquipmentScreenDTO.ParamDTO();
|
||||
|
||||
// 基础信息
|
||||
dbData.setEquipmentCode(equipmentInfo.getEquipmentCode());
|
||||
dbData.setEquipmentName(equipmentInfo.getEquipmentName());
|
||||
dbData.setEquipmentType("1"); // 干燥机类型标识
|
||||
dbData.setStatus("1"); // 默认运行中
|
||||
|
||||
// 温度值:有数据显示实际值,无数据填0
|
||||
if (redisData != null && redisData.getValue() != null) {
|
||||
dbData.setDataValue(String.valueOf(redisData.getValue()));
|
||||
} else {
|
||||
dbData.setDataValue("0");
|
||||
}
|
||||
|
||||
// 转换为DryingDTO
|
||||
EquipmentScreenDTO.DryingDTO dbData = convertToDryingDTO(redisData);
|
||||
if (dbData == null) {
|
||||
log.debug("【前端推送任务】设备ID{}数据转换失败,跳过", equipmentId);
|
||||
continue;
|
||||
}
|
||||
// 设定温度:无值填0
|
||||
dbData.setSetTem(equipmentInfo.getSetTem() != null ? equipmentInfo.getSetTem() : "0");
|
||||
|
||||
// 报警判断
|
||||
// 阈值:无规则填0
|
||||
String ruleCode = equipmentInfo.getRuleCode();
|
||||
DryParamThreshold rule = ruleCache.get(ruleCode);
|
||||
if (rule != null) {
|
||||
paramDTO.minValue = rule.getMinValue() != null ? rule.getMinValue() : "0";
|
||||
paramDTO.maxValue = rule.getMaxValue() != null ? rule.getMaxValue() : "0";
|
||||
} else {
|
||||
paramDTO.minValue = "0";
|
||||
paramDTO.maxValue = "0";
|
||||
}
|
||||
dbData.setParamDTO(paramDTO);
|
||||
|
||||
// 报警判断(0值是否报警按规则处理)
|
||||
judgeAlarm(dbData);
|
||||
|
||||
result.add(dbData);
|
||||
@ -325,36 +354,74 @@ public class AutoCollectService {
|
||||
/**
|
||||
* 从Redis读取露点机数据
|
||||
*/
|
||||
/**
|
||||
* 从Redis读取露点机数据(1-4台,无数据显示0)
|
||||
*/
|
||||
private List<EquipmentScreenDTO.DrynessDTO> buildDrynessDataList() {
|
||||
List<EquipmentScreenDTO.DrynessDTO> result = new ArrayList<>();
|
||||
|
||||
// 遍历34台设备(001-04)
|
||||
for (int i = 1; i <= 4; i++) {
|
||||
String equipmentId = String.format("%03d", i); // 设备ID:001-004
|
||||
// 遍历1-4台露点机(001-004)
|
||||
for (int i = 1; i <= TOTAL_DEW_EQUIPMENT; i++) {
|
||||
String equipmentId = String.format("%03d", i); // 格式化设备ID:001-004
|
||||
DryEquipmentInfo equipmentInfo = equipmentInfoCache.get(equipmentId);
|
||||
|
||||
// 构造默认设备信息(缓存中无数据时使用)
|
||||
if (equipmentInfo == null) {
|
||||
log.warn("【露点数据】设备ID{}无对应信息,跳过", equipmentId);
|
||||
continue;
|
||||
log.warn("【露点数据】露点机{}无缓存信息,使用默认配置", equipmentId);
|
||||
equipmentInfo = new DryEquipmentInfo();
|
||||
equipmentInfo.setEquipmentCode("EQ-DEW-" + equipmentId); // 编码:EQ-DEW-001
|
||||
equipmentInfo.setEquipmentName("露点机" + equipmentId); // 名称:露点机001
|
||||
equipmentInfo.setRuleCode("");
|
||||
equipmentInfo.setSetTem("0"); // 默认设定温度0
|
||||
}
|
||||
|
||||
// 读取露点Redis数据(Key:dry_equipment:001:DEW)
|
||||
// 读取Redis数据(露点+温度)
|
||||
String dewRedisKey = REDIS_EQUIP_PREFIX + equipmentId + ":" + PARAM_DEW;
|
||||
MqttDataHandler.EquipmentData dewRedisData = (MqttDataHandler.EquipmentData) redisTemplate.opsForValue().get(dewRedisKey);
|
||||
|
||||
// 至少有一个数据才处理(温度或露点)
|
||||
if (dewRedisData == null) {
|
||||
log.debug("【露点数据】设备ID{}无露点数据,跳过", equipmentId);
|
||||
continue;
|
||||
String tempRedisKey = REDIS_EQUIP_PREFIX + equipmentId + ":" + PARAM_TEMP;
|
||||
MqttDataHandler.EquipmentData tempRedisData = (MqttDataHandler.EquipmentData) redisTemplate.opsForValue().get(tempRedisKey);
|
||||
|
||||
// 构造DrynessDTO,无数据填0
|
||||
EquipmentScreenDTO.DrynessDTO drynessDTO = new EquipmentScreenDTO.DrynessDTO();
|
||||
EquipmentScreenDTO.ParamDTO paramDTO = new EquipmentScreenDTO.ParamDTO();
|
||||
|
||||
// 基础信息
|
||||
drynessDTO.setEquipmentCode(equipmentInfo.getEquipmentCode());
|
||||
drynessDTO.setEquipmentName(equipmentInfo.getEquipmentName());
|
||||
drynessDTO.setEquipmentType("2"); // 露点机类型标识
|
||||
drynessDTO.setStatus("1"); // 默认运行中
|
||||
|
||||
// 设定温度:无值填0
|
||||
drynessDTO.setSetTem(equipmentInfo.getSetTem() != null ? equipmentInfo.getSetTem() : "0");
|
||||
|
||||
// 露点值:有数据显示实际值,无数据填0
|
||||
if (dewRedisData != null && dewRedisData.getValue() != null) {
|
||||
drynessDTO.setDewValue(String.valueOf(dewRedisData.getValue()));
|
||||
} else {
|
||||
drynessDTO.setDewValue("0");
|
||||
}
|
||||
|
||||
// 转换为DrynessDTO
|
||||
EquipmentScreenDTO.DrynessDTO drynessDTO = convertToDrynessDTO(dewRedisData, equipmentInfo);
|
||||
if (drynessDTO == null) {
|
||||
log.debug("【露点数据】设备ID{}数据转换失败,跳过", equipmentId);
|
||||
continue;
|
||||
// 温度值:有数据显示实际值,无数据填0
|
||||
if (tempRedisData != null && tempRedisData.getValue() != null) {
|
||||
drynessDTO.setTempValue(String.valueOf(tempRedisData.getValue()));
|
||||
} else {
|
||||
drynessDTO.setTempValue("0");
|
||||
}
|
||||
|
||||
// 露点报警判断
|
||||
// 阈值:无规则填0
|
||||
String ruleCode = equipmentInfo.getRuleCode();
|
||||
DryParamThreshold rule = ruleCache.get(ruleCode);
|
||||
if (rule != null) {
|
||||
paramDTO.minValue = rule.getMinValue() != null ? rule.getMinValue() : "0";
|
||||
paramDTO.maxValue = rule.getMaxValue() != null ? rule.getMaxValue() : "0";
|
||||
} else {
|
||||
paramDTO.minValue = "0";
|
||||
paramDTO.maxValue = "0";
|
||||
}
|
||||
drynessDTO.setParamDTO(paramDTO);
|
||||
|
||||
// 报警判断(0值是否报警按规则处理)
|
||||
judgeDrynessAlarm(drynessDTO, equipmentInfo);
|
||||
|
||||
result.add(drynessDTO);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user