|
|
|
@ -3,9 +3,12 @@ package cn.iocoder.yudao.module.alert.service.warn; |
|
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
|
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
|
|
|
import cn.iocoder.yudao.framework.common.util.json.JsonUtils; |
|
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
|
|
|
import cn.iocoder.yudao.module.alert.controller.admin.exa.vo.EXAHistoryReqVO; |
|
|
|
import cn.iocoder.yudao.module.alert.controller.admin.instant.vo.InstantSaveReqVO; |
|
|
|
import cn.iocoder.yudao.module.alert.controller.admin.model.vo.ModelVersionPageReqVO; |
|
|
|
import cn.iocoder.yudao.module.alert.controller.admin.warn.vo.AlarmTrendRespVO; |
|
|
|
import cn.iocoder.yudao.module.alert.controller.admin.warn.vo.WarnPageReqVO; |
|
|
|
import cn.iocoder.yudao.module.alert.controller.admin.warn.vo.WarnRespVO; |
|
|
|
import cn.iocoder.yudao.module.alert.controller.admin.warn.vo.WarnSaveReqVO; |
|
|
|
@ -32,11 +35,15 @@ import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.cache.annotation.CacheEvict; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.web.bind.annotation.RequestParam; |
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.net.URISyntaxException; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
import java.time.temporal.ChronoUnit; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.List; |
|
|
|
import java.util.regex.Matcher; |
|
|
|
import java.util.regex.Pattern; |
|
|
|
@ -244,4 +251,96 @@ public class WarnServiceImpl implements WarnService { |
|
|
|
return alarmLevelMapper.selectList(); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public AlarmTrendRespVO getAlarmTrend(Long id,EXAHistoryReqVO exaHistoryReqVO) { |
|
|
|
try { |
|
|
|
// 1. 查询预警配置信息
|
|
|
|
WarnDO warnDO = warnMapper.selectByWarnId(id); |
|
|
|
if (warnDO == null) { |
|
|
|
throw exception(WARN_NOT_EXISTS,"未找到预警配置信息,warnId: " + id); |
|
|
|
} |
|
|
|
|
|
|
|
// 2. 提取必要参数
|
|
|
|
String point = warnDO.getPointId(); |
|
|
|
String outpoint = warnDO.getOutputPoint(); |
|
|
|
String uplimit = warnDO.getUplimit(); |
|
|
|
String lowlimit = warnDO.getLowlimit(); |
|
|
|
|
|
|
|
EXAUtils exaUtils = new EXAUtils(); |
|
|
|
exaHistoryReqVO.setItemName(point); |
|
|
|
// 3. 获取历史数据
|
|
|
|
exaHistoryReqVO.setItemName("SYG1_10BBA20ECMS501"); |
|
|
|
exaHistoryReqVO.setStartTime("2023-10-28 17:00:00"); |
|
|
|
exaHistoryReqVO.setEndTime("2023-10-28 23:00:00"); |
|
|
|
exaHistoryReqVO.setInterval(60L); |
|
|
|
List<List<Double>> inputData = exaUtils.getHistory(EXA_IP, exaHistoryReqVO); |
|
|
|
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); |
|
|
|
} |
|
|
|
|
|
|
|
//直接深拷贝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); |
|
|
|
} |
|
|
|
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; |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
log.error("getAlarmTrend error", e); |
|
|
|
throw exception(ALARM_TREND_FAILED, "获取告警趋势失败: " + e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|