From bbfd106f752dafbdfdfcc679a6f65a3adb906ab6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=82=96=E6=99=8B=E9=A3=9E?= <378266566@qq.com> Date: Tue, 23 Dec 2025 19:35:52 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E9=9B=86=E4=B8=AD=E5=91=8A=E8=AD=A6?= =?UTF-8?q?=E5=8E=BB=E6=8E=89=E5=81=87=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../alert/service/warn/WarnServiceImpl.java | 121 +++++++++--------- 1 file changed, 62 insertions(+), 59 deletions(-) diff --git a/yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/service/warn/WarnServiceImpl.java b/yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/service/warn/WarnServiceImpl.java index 6a46083..0d8debb 100644 --- a/yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/service/warn/WarnServiceImpl.java +++ b/yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/service/warn/WarnServiceImpl.java @@ -274,73 +274,76 @@ public class WarnServiceImpl implements WarnService { // exaHistoryReqVO.setEndTime("2023-10-28 23:00:00"); // exaHistoryReqVO.setInterval(60L); List> inputData = exaUtils.getHistory(EXA_IP, exaHistoryReqVO); + exaHistoryReqVO.setItemName(outpoint); List> outputData = exaUtils.getHistory(EXA_IP, exaHistoryReqVO); // 4. 数据校验 - if (inputData.isEmpty() || outputData.isEmpty()) { - throw exception(EXA_HISTORY_IS_EMPTY,"历史数据为空,point: " + point + ", outputPoint: " + outpoint); - } + if (inputData != null || outputData != null) { - //直接深拷贝outputData - //上限值列表 - List> upList = new ArrayList<>(outputData.size()); - for (List inner : outputData) { - upList.add(new ArrayList<>(inner)); - } - //下限值列表 - List> lowList = new ArrayList<>(outputData.size()); - for (List inner : outputData) { - lowList.add(new ArrayList<>(inner)); - } - //告警值列表 - List> errorList = new ArrayList<>(outputData.size()); - for (List inner : outputData) { - errorList.add(new ArrayList<>(inner)); - } - - // 7. 数据处理:计算上下限、误差标记 - for (int i = 0; i < outputData.size(); i++) { - List inputRow = inputData.get(i); - List outputRow = outputData.get(i); - Double inputValue = inputRow.size() > 1 ? inputRow.get(1) : null; - Double outputValue = outputRow.size() > 1 ? outputRow.get(1) : null; - // 计算上下限 - double h = (outputValue != null ? outputValue : 0) + Double.parseDouble(uplimit); - double l = (outputValue != null ? outputValue : 0) + Double.parseDouble(lowlimit); - - // ⚠️ 分别拷贝 - List upRow = new ArrayList<>(outputRow); - upRow.set(1, h); - upList.set(i, upRow); - - List lowRow = new ArrayList<>(outputRow); - lowRow.set(1, l); - lowList.set(i, lowRow); - - List errorRow = new ArrayList<>(outputRow); - - // 误差标记(1表示异常,null表示正常) - if (inputValue != null && (inputValue < l || inputValue > h)) { - errorRow.set(1, 1.0); - } else { - errorRow.set(1, null); + //直接深拷贝outputData + //上限值列表 + List> upList = new ArrayList<>(outputData.size()); + for (List inner : outputData) { + upList.add(new ArrayList<>(inner)); + } + //下限值列表 + List> lowList = new ArrayList<>(outputData.size()); + for (List inner : outputData) { + lowList.add(new ArrayList<>(inner)); + } + //告警值列表 + List> errorList = new ArrayList<>(outputData.size()); + for (List inner : outputData) { + errorList.add(new ArrayList<>(inner)); } - errorList.set(i, errorRow); - } - // 8. 组装结果对象 - AlarmTrendRespVO result = new AlarmTrendRespVO(); - result.setRealTimeList(inputData); - result.setUpList(upList); - result.setLowList(lowList); - result.setErrorList(errorList); - result.setGzpName(warnDO.getGzpName() + " " + warnDO.getUnit()); - result.setValueList(Arrays.asList(inputData, upList, lowList, errorList)); - result.setTagList(Arrays.asList("实时值", "上限值", "下限值", "告警值")); - return result; + // 7. 数据处理:计算上下限、误差标记 + for (int i = 0; i < outputData.size(); i++) { + List inputRow = inputData.get(i); + List outputRow = outputData.get(i); + Double inputValue = inputRow.size() > 1 ? inputRow.get(1) : null; + Double outputValue = outputRow.size() > 1 ? outputRow.get(1) : null; + // 计算上下限 + double h = (outputValue != null ? outputValue : 0) + Double.parseDouble(uplimit); + double l = (outputValue != null ? outputValue : 0) + Double.parseDouble(lowlimit); + + // ⚠️ 分别拷贝 + List upRow = new ArrayList<>(outputRow); + upRow.set(1, h); + upList.set(i, upRow); + + List lowRow = new ArrayList<>(outputRow); + lowRow.set(1, l); + lowList.set(i, lowRow); + + List errorRow = new ArrayList<>(outputRow); + + // 误差标记(1表示异常,null表示正常) + if (inputValue != null && (inputValue < l || inputValue > h)) { + errorRow.set(1, 1.0); + } else { + errorRow.set(1, null); + } + errorList.set(i, errorRow); + } + // 8. 组装结果对象 + AlarmTrendRespVO result = new AlarmTrendRespVO(); + result.setRealTimeList(inputData); + result.setUpList(upList); + result.setLowList(lowList); + result.setErrorList(errorList); + result.setGzpName(warnDO.getGzpName() + " " + warnDO.getUnit()); + result.setValueList(Arrays.asList(inputData, upList, lowList, errorList)); + result.setTagList(Arrays.asList("实时值", "上限值", "下限值", "告警值")); + return result; + } + else{ + log.error("getAlarmTrend error, point: {}", point); + throw exception(ALARM_TREND_FAILED, "获取告警趋势失败: 数据为空"); + } } catch (Exception e) { log.error("getAlarmTrend error", e); - throw exception(ALARM_TREND_FAILED, "获取告警趋势失败: " + e.getMessage()); + throw exception(ALARM_TREND_FAILED, "获取告警趋势失败: " + e.getMessage()); } } }