|
|
|
|
@ -136,26 +136,60 @@ public class ProcessAlertServiceImpl implements IProcessAlertService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (alertType != null) {
|
|
|
|
|
// 生成预警记录
|
|
|
|
|
ProcessAlert alert = new ProcessAlert();
|
|
|
|
|
alert.setAlertCode("ALERT-" + sdf.format(now) + "-" + (alertCount + 1));
|
|
|
|
|
alert.setAlertType("参数超限");
|
|
|
|
|
alert.setAlertLevel(param.getAlertLevel() != null ? param.getAlertLevel() : "1");
|
|
|
|
|
alert.setDeviceCode(param.getDeviceCode());
|
|
|
|
|
alert.setDeviceName(param.getDeviceName());
|
|
|
|
|
alert.setParamCode(param.getParamCode());
|
|
|
|
|
alert.setParamName(param.getParamName());
|
|
|
|
|
alert.setAlertContent(param.getParamName() + alertType + ",当前值:" + paramValueStr + ",阈值:" + thresholdValue);
|
|
|
|
|
alert.setAlertValue(paramValueStr);
|
|
|
|
|
alert.setThresholdValue(thresholdValue);
|
|
|
|
|
alert.setAlertTime(latestVal.getCollectTime() != null ? latestVal.getCollectTime() : now);
|
|
|
|
|
alert.setAlertStatus("0");
|
|
|
|
|
alert.setIsFlag("1");
|
|
|
|
|
alert.setCreateTime(now);
|
|
|
|
|
// 检查是否已存在未处理的预警(去重)
|
|
|
|
|
ProcessAlert existingAlert = processAlertMapper.selectUnhandledAlert(
|
|
|
|
|
param.getDeviceCode(),
|
|
|
|
|
param.getParamCode()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
insertProcessAlert(alert);
|
|
|
|
|
alertCount++;
|
|
|
|
|
log.info("生成预警: {}", alert.getAlertContent());
|
|
|
|
|
if (existingAlert != null) {
|
|
|
|
|
// 已存在未处理的预警,更新预警值和时间
|
|
|
|
|
existingAlert.setAlertValue(paramValueStr);
|
|
|
|
|
existingAlert.setAlertTime(latestVal.getCollectTime() != null ? latestVal.getCollectTime() : now);
|
|
|
|
|
existingAlert.setAlertContent(param.getParamName() + alertType + ",当前值:" + paramValueStr + ",阈值:" + thresholdValue);
|
|
|
|
|
updateProcessAlert(existingAlert);
|
|
|
|
|
log.info("更新未处理预警: {}", existingAlert.getAlertContent());
|
|
|
|
|
} else {
|
|
|
|
|
// 查询最新预警(包含已处理)
|
|
|
|
|
ProcessAlert latestAlert = processAlertMapper.selectLatestAlert(
|
|
|
|
|
param.getDeviceCode(),
|
|
|
|
|
param.getParamCode()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// 如果存在已处理的预警,检查预警冷却时间(5分钟)
|
|
|
|
|
if (latestAlert != null && "2".equals(latestAlert.getAlertStatus())) {
|
|
|
|
|
long timeDiff = now.getTime() - latestAlert.getAlertTime().getTime();
|
|
|
|
|
long cooldownMinutes = 5; // 预警冷却时间5分钟
|
|
|
|
|
|
|
|
|
|
if (timeDiff < cooldownMinutes * 60 * 1000) {
|
|
|
|
|
// 还在冷却期内,不生成新预警
|
|
|
|
|
log.debug("预警冷却期内,跳过: deviceCode={}, paramCode={}",
|
|
|
|
|
param.getDeviceCode(), param.getParamCode());
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 生成新的预警记录
|
|
|
|
|
ProcessAlert alert = new ProcessAlert();
|
|
|
|
|
alert.setAlertCode("ALERT-" + sdf.format(now) + "-" + (alertCount + 1));
|
|
|
|
|
alert.setAlertType("参数超限");
|
|
|
|
|
alert.setAlertLevel(param.getAlertLevel() != null ? param.getAlertLevel() : "1");
|
|
|
|
|
alert.setDeviceCode(param.getDeviceCode());
|
|
|
|
|
alert.setDeviceName(param.getDeviceName());
|
|
|
|
|
alert.setParamCode(param.getParamCode());
|
|
|
|
|
alert.setParamName(param.getParamName());
|
|
|
|
|
alert.setAlertContent(param.getParamName() + alertType + ",当前值:" + paramValueStr + ",阈值:" + thresholdValue);
|
|
|
|
|
alert.setAlertValue(paramValueStr);
|
|
|
|
|
alert.setThresholdValue(thresholdValue);
|
|
|
|
|
alert.setAlertTime(latestVal.getCollectTime() != null ? latestVal.getCollectTime() : now);
|
|
|
|
|
alert.setAlertStatus("0");
|
|
|
|
|
alert.setIsFlag("1");
|
|
|
|
|
alert.setCreateTime(now);
|
|
|
|
|
|
|
|
|
|
insertProcessAlert(alert);
|
|
|
|
|
alertCount++;
|
|
|
|
|
log.info("生成新预警: {}", alert.getAlertContent());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
|
log.warn("参数值无法转换为数字: paramCode={}, value={}", param.getParamCode(), paramValueStr);
|
|
|
|
|
@ -167,4 +201,33 @@ public class ProcessAlertServiceImpl implements IProcessAlertService {
|
|
|
|
|
|
|
|
|
|
return alertCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int batchMarkAsProcessed(Long[] alertIds, String handleUser) {
|
|
|
|
|
if (alertIds == null || alertIds.length == 0) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
|
Date now = DateUtils.getNowDate();
|
|
|
|
|
|
|
|
|
|
for (Long alertId : alertIds) {
|
|
|
|
|
try {
|
|
|
|
|
ProcessAlert alert = processAlertMapper.selectProcessAlertByAlertId(alertId);
|
|
|
|
|
if (alert != null && !"2".equals(alert.getAlertStatus())) {
|
|
|
|
|
alert.setAlertStatus("2"); // 已处理
|
|
|
|
|
alert.setHandleUser(handleUser);
|
|
|
|
|
alert.setHandleTime(now);
|
|
|
|
|
alert.setHandleResult("批量标记为已处理");
|
|
|
|
|
processAlertMapper.updateProcessAlert(alert);
|
|
|
|
|
count++;
|
|
|
|
|
log.info("批量标记预警已处理: alertId={}, alertCode={}", alertId, alert.getAlertCode());
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("标记预警已处理失败: alertId={}", alertId, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|