Browse Source

fix:集中告警去掉假数据

pull/56/head
肖晋飞 3 weeks ago
parent
commit
bbfd106f75
  1. 121
      yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/service/warn/WarnServiceImpl.java

121
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<List<Double>> inputData = exaUtils.getHistory(EXA_IP, exaHistoryReqVO);
exaHistoryReqVO.setItemName(outpoint);
List<List<Double>> 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<List<Double>> upList = new ArrayList<>(outputData.size());
for (List<Double> inner : outputData) {
upList.add(new ArrayList<>(inner));
}
//下限值列表
List<List<Double>> lowList = new ArrayList<>(outputData.size());
for (List<Double> inner : outputData) {
lowList.add(new ArrayList<>(inner));
}
//告警值列表
List<List<Double>> errorList = new ArrayList<>(outputData.size());
for (List<Double> inner : outputData) {
errorList.add(new ArrayList<>(inner));
}
// 7. 数据处理:计算上下限、误差标记
for (int i = 0; i < outputData.size(); i++) {
List<Double> inputRow = inputData.get(i);
List<Double> 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<Double> upRow = new ArrayList<>(outputRow);
upRow.set(1, h);
upList.set(i, upRow);
List<Double> lowRow = new ArrayList<>(outputRow);
lowRow.set(1, l);
lowList.set(i, lowRow);
List<Double> 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<List<Double>> upList = new ArrayList<>(outputData.size());
for (List<Double> inner : outputData) {
upList.add(new ArrayList<>(inner));
}
//下限值列表
List<List<Double>> lowList = new ArrayList<>(outputData.size());
for (List<Double> inner : outputData) {
lowList.add(new ArrayList<>(inner));
}
//告警值列表
List<List<Double>> errorList = new ArrayList<>(outputData.size());
for (List<Double> 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<Double> inputRow = inputData.get(i);
List<Double> 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<Double> upRow = new ArrayList<>(outputRow);
upRow.set(1, h);
upList.set(i, upRow);
List<Double> lowRow = new ArrayList<>(outputRow);
lowRow.set(1, l);
lowList.set(i, lowRow);
List<Double> 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());
}
}
}

Loading…
Cancel
Save