区段,道岔 大范围告警调整,区域管理修改

This commit is contained in:
tiger_zhou 2023-09-11 17:23:52 +08:00
parent a606ce3b35
commit 20bcdd3545
5 changed files with 113 additions and 26 deletions

View File

@ -1,9 +1,5 @@
package club.joylink.xiannccda.alert.core;
import club.joylink.xiannccda.ats.message.line3.device.DeviceType;
import java.util.Arrays;
import lombok.Getter;
public enum AlertDeviceType {
/**

View File

@ -170,6 +170,12 @@ public class LineGraphicDataRepository {
lineGraphMap.remove(id);
}
public static MessageOrBuilder getDeviceByCodeNotException(int lineId, String code) {
MessageOrBuilder mob = line_code_table.get(lineId, code);
return mob;
}
public static MessageOrBuilder getDeviceByCode(int lineId, String code) {
MessageOrBuilder mob = line_code_table.get(lineId, code);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(mob,
@ -188,6 +194,7 @@ public class LineGraphicDataRepository {
return (T) mob;
}
@Deprecated
public static <T> T getDeviceById(int lineId, String id, Class<T> cls) {
MessageOrBuilder mob = line_id_table.get(lineId, id);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(mob,

View File

@ -21,6 +21,7 @@ import club.joylink.xiannccda.service.AlertInfoService;
import club.joylink.xiannccda.service.config.DeviceGuardConfigService;
import com.google.protobuf.GeneratedMessageV3;
import com.google.protobuf.GeneratedMessageV3.Builder;
import com.google.protobuf.MessageOrBuilder;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
@ -44,6 +45,9 @@ public class AxleSwitchTrackLedAlertListener implements AlertSourceEventListener
this.alertInfoService = alertInfoService;
}
private String getDefaultName(AlertType alertType) {
return String.format("%s", alertType.name());
}
@Override
public void accept(SwitchAndTrackLedAlertEvent event) {
@ -100,40 +104,34 @@ public class AxleSwitchTrackLedAlertListener implements AlertSourceEventListener
Optional<DeviceAreaConfig> alertInfoOptional = this.alertInfoService.findAreaDevice(alertType, AlertDeviceType.DEVICE_TYPE_TRACK, layoutDeviceId, lineId);
Optional<DeviceAreaConfig> alertInfoMostOptional = this.alertInfoService.findAreaDevice(mostType, AlertDeviceType.DEVICE_TYPE_TRACK, layoutDeviceId, lineId);
String customName = this.getCustomName(alertInfoOptional, alertInfoMostOptional, alertType);
// String customName = this.getCustomName(alertInfoOptional, alertInfoMostOptional, alertType);
String alertInfoName = alertInfoOptional.map(DeviceAreaConfig::getAreaName).orElse(this.getDefaultName(alertType));
String alertInfoMostName = alertInfoMostOptional.map(DeviceAreaConfig::getAreaName).orElse(null);
String ledName = alertType == AlertType.AXLE_LED_RED ? "红光带" : "橙光带";
if (light) {
log.info("光带检测到[{}] 线路[{}] 设备[{}] 告警[{}] 自定义名称[{}]", ledName, lineId, id, alertType.name(), customName);
if (alertManager.putAlterDevice(lineId, customName, id)) {
log.info("光带检测到[{}] 线路[{}] 设备[{}] 告警[{}] 自定义名称[{}]", ledName, lineId, id, alertType.name(), alertInfoName);
if (alertManager.putAlterDevice(lineId, alertInfoName, id)) {
String alertMsg = String.format("出现%s设备[%s]", ledName, id);
NccAlertInfo alertInfo = this.alertInfoService.createAlert2(alertInfoOptional, alertType, build, alertMsg, section.getCommon().getId(), false);
alertManager.emit(alertInfo);
}
if (alertInfoMostOptional.isPresent() && alertManager.needMostShow(lineId, customName, overNums)) {
String warnDevices = alertManager.findAllWarnDevice(lineId, customName);
if (StringUtils.isNotEmpty(alertInfoMostName) && alertManager.needMostShow(lineId, alertInfoMostName, overNums)) {
String warnDevices = alertManager.findAllWarnDevice(lineId, alertInfoMostName);
String alertMsg = String.format("%s-出现大面积%s设备[%s]", alertInfoMostOptional.get().getAreaName(), ledName, warnDevices);
NccAlertInfo alertInfoMost = this.alertInfoService.createAlert2(alertInfoOptional, mostType, build, alertMsg, section.getCommon().getId(), false);
alertManager.emit(alertInfoMost);
}
} else {
alertManager.removeAlterDevice(lineId, customName, id);
if (StringUtils.isNotEmpty(customName)) {
alertManager.removeAlterDevice(lineId, customName, id);
alertManager.removeAlterDevice(lineId, alertInfoName, id);
if (StringUtils.isNotEmpty(alertInfoMostName)) {
alertManager.removeAlterDevice(lineId, alertInfoMostName, id);
}
}
}
private String getCustomName(Optional<DeviceAreaConfig> alertInfoOpt, Optional<DeviceAreaConfig> alertInfoMostOpt, AlertType alertType) {
String customName = alertInfoMostOpt.map(DeviceAreaConfig::getAreaName).orElse(null);
if (StringUtils.isNotEmpty(customName)) {
return String.format("%s_%s", customName, alertType.name());
}
return alertInfoOpt.map(DeviceAreaConfig::getAreaName).orElse(alertType.name());
}
private String findSectionId(int lineId, Section section, String deviceCode) {
if (section.getSectionType() == SectionType.TurnoutPhysical) {
return section.getCommon().getId();

View File

@ -52,10 +52,15 @@ public class SwitchLostAlertMonitoringTask implements AlertMonitoringTask {
switchBuilder.getLineId());
Optional<DeviceAreaConfig> alertInfoMostOpt = this.alertInfoService.findAreaDevice(AlertType.SWITCH_LOST_MOST, AlertDeviceType.DEVICE_TYPE_SWITCH, turnout.getCommon().getId(),
switchBuilder.getLineId());
String customName = this.getCustomName(alertInfoOpt, alertInfoMostOpt);
log.info("线路[{}] 道岔[{}] 从监控中移除... 设备状态参数[{}]", switchBuilder.getLineId(), switchBuilder.getId(), switchBuilder);
deviceMap.remove(switchBuilder.getId());
alertManager.removeAlterDevice(switchBuilder.getLineId(), customName, switchBuilder.getId());
String alertInfoName = alertInfoOpt.map(DeviceAreaConfig::getAreaName).orElse(this.getName());
String mostName = alertInfoMostOpt.map(DeviceAreaConfig::getAreaName).orElse(null);
alertManager.removeAlterDevice(switchBuilder.getLineId(), alertInfoName, switchBuilder.getId());
if (StringUtils.isNotEmpty(mostName)) {
alertManager.removeAlterDevice(switchBuilder.getLineId(), mostName, switchBuilder.getId());
}
}
@Override
@ -63,15 +68,44 @@ public class SwitchLostAlertMonitoringTask implements AlertMonitoringTask {
return "SWITCH_LOST_ALTER";
}
private void checkDevice(Turnout turnout, Builder savedSwitchBuild) {
int lineId = savedSwitchBuild.getLineId();
GuardConfig guardConfig = configService.getGuardConfig(lineId);
Optional<DeviceAreaConfig> alertInfoOpt = this.alertInfoService.findAreaDevice(AlertType.SWITCH_LOST, AlertDeviceType.DEVICE_TYPE_SWITCH, turnout.getCommon().getId(),
savedSwitchBuild.getLineId());
Optional<DeviceAreaConfig> alertInfoMostOpt = this.alertInfoService.findAreaDevice(AlertType.SWITCH_LOST_MOST, AlertDeviceType.DEVICE_TYPE_SWITCH, turnout.getCommon().getId(),
savedSwitchBuild.getLineId());
boolean saveIsLost = savedSwitchBuild.getIpSingleSwitchStusLostIndication();
if (saveIsLost && this.timeOver(savedSwitchBuild.getReceiveTime(), guardConfig.getSwitchLostTimes())) {
log.info("道岔失表超时,准备报警 线路[{}] 设备[{}] 接受时间[{}] 对应地图设备id[{}]", lineId, savedSwitchBuild.getId(), savedSwitchBuild.getReceiveTime(), turnout.getCommon().getId());
String alertInfoName = alertInfoOpt.map(DeviceAreaConfig::getAreaName).orElse(this.getName());
//失表超时
if (alertManager.putAlterDevice(lineId, alertInfoName, savedSwitchBuild.getId())) {
String alertMsg = String.format("设备[%s]失表", savedSwitchBuild.getId());
NccAlertInfo alertInfo = this.alertInfoService.createAlert2(alertInfoOpt, AlertType.SWITCH_LOST, savedSwitchBuild, alertMsg, turnout.getCommon().getId(), false);
alertManager.emit(alertInfo);
this.deviceMap.remove(savedSwitchBuild.getId());
}
String mostName = alertInfoMostOpt.map(DeviceAreaConfig::getAreaName).orElse(null);
//检测大面积失表
if (StringUtils.isNotEmpty(mostName) && alertManager.needMostShow(lineId, mostName, guardConfig.getSwitchLostMostNums())) {
String warnDevices = alertManager.findAllWarnDevice(lineId, mostName);
String alertMsg = String.format("%s-大面积失表设备[%s]", mostName, warnDevices);
NccAlertInfo alertInfo = this.alertInfoService.createAlert2(alertInfoMostOpt, AlertType.SWITCH_LOST_MOST, savedSwitchBuild, alertMsg, turnout.getCommon().getId(), false);
alertManager.emit(alertInfo);
}
}
}
@Override
public void run() {
for (Builder savedSwitchBuild : this.deviceMap.values()) {
Integer lineId = savedSwitchBuild.getLineId();
GuardConfig guardConfig = configService.getGuardConfig(lineId);
Turnout turnout = LineGraphicDataRepository.getDeviceByCode(lineId, savedSwitchBuild.getId(), Turnout.class);
log.info("道岔失表检测 线路[{}] 设备[{}] 查找对应的地图道岔id[{}]", lineId, savedSwitchBuild.getId(), turnout.getCommon().getId());
Optional<DeviceAreaConfig> alertInfoOpt = this.alertInfoService.findAreaDevice(AlertType.SWITCH_LOST, AlertDeviceType.DEVICE_TYPE_SWITCH, turnout.getCommon().getId(),
this.checkDevice(turnout, savedSwitchBuild);
/* Optional<DeviceAreaConfig> alertInfoOpt = this.alertInfoService.findAreaDevice(AlertType.SWITCH_LOST, AlertDeviceType.DEVICE_TYPE_SWITCH, turnout.getCommon().getId(),
savedSwitchBuild.getLineId());
Optional<DeviceAreaConfig> alertInfoMostOpt = this.alertInfoService.findAreaDevice(AlertType.SWITCH_LOST_MOST, AlertDeviceType.DEVICE_TYPE_SWITCH, turnout.getCommon().getId(),
savedSwitchBuild.getLineId());
@ -95,7 +129,7 @@ public class SwitchLostAlertMonitoringTask implements AlertMonitoringTask {
NccAlertInfo alertInfo = this.alertInfoService.createAlert2(alertInfoMostOpt, AlertType.SWITCH_LOST_MOST, savedSwitchBuild, alertMsg, turnout.getCommon().getId(), false);
alertManager.emit(alertInfo);
}
}
}*/
}
}

View File

@ -1,6 +1,8 @@
package club.joylink.xiannccda.service.config;
import club.joylink.xiannccda.alert.core.AlertDeviceType;
import club.joylink.xiannccda.ats.cache.LineGraphicDataRepository;
import club.joylink.xiannccda.ats.message.collect.DeviceStatusDataOperate;
import club.joylink.xiannccda.ats.message.line3.device.DeviceType;
import club.joylink.xiannccda.dto.alertTip.AlertTipInfoDto;
import club.joylink.xiannccda.dto.config.DeviceAreaConfigDto;
@ -16,11 +18,14 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.collect.Lists;
import com.google.protobuf.MessageOrBuilder;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@ -59,8 +64,52 @@ public class DeviceAreaConfigService {
}
}
private String findDevice(Integer lineId, List<String> deviceIds) {
List<String> errorDevices = Lists.newArrayList();
for (String deviceId : deviceIds) {
MessageOrBuilder msgBuild = LineGraphicDataRepository.getDeviceByCodeNotException(lineId, deviceId);
if (Objects.nonNull(msgBuild)) {
String deviceCode = DeviceStatusDataOperate.findFieldVal(msgBuild, "code", String.class);
errorDevices.add(deviceCode);
} else {
errorDevices.add(String.format("id[%s]未找到设备", deviceId));
}
}
return Joiner.on(",").join(errorDevices);
}
private void checkDataForSql(DeviceAreaConfigDto dto, boolean isUpdate) {
LambdaQueryWrapper<DeviceAreaConfig> queryWrapper = Wrappers.lambdaQuery(DeviceAreaConfig.class);
queryWrapper.eq(DeviceAreaConfig::getDeviceType, dto.getDeviceType());
queryWrapper.ne(isUpdate, DeviceAreaConfig::getId, dto.getId());
List<String> lastSqlList = Lists.newArrayList();
for (String alertType : dto.getAlertTypes()) {
lastSqlList.add(String.format(" find_in_set('%s',%s) > 0 ", alertType, DeviceAreaConfig.ALERT_TYPES));
}
if (CollectionUtils.isNotEmpty(lastSqlList)) {
StringBuilder queryTypes = new StringBuilder(" and ( ");
queryTypes.append(Joiner.on(" or ").join(lastSqlList)).append(") ");
queryWrapper.last(queryTypes.toString());
}
List<DeviceAreaConfig> areaConfigList = this.deviceAreaConfigRepository.list(queryWrapper);
for (DeviceAreaConfig areaConfig : areaConfigList) {
List<String> dbDatas = Splitter.on(",").splitToList(areaConfig.getData());
List<String> saveDatas = Lists.newArrayList(dto.getData());
saveDatas.retainAll(dbDatas);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(CollectionUtils.isEmpty(saveDatas),
String.format("添加重复的设备区域[%s] 设备:%s", areaConfig.getAreaName(), this.findDevice(areaConfig.getLineId(), saveDatas)));
}
}
public void saveOrUpdate(DeviceAreaConfigDto dto) {
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(CollectionUtils.isNotEmpty(dto.getAlertTypes()), "绑定数据类型不能为空");
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(CollectionUtils.isNotEmpty(dto.getData()), "绑定数据不能为空");
boolean isUpdate = false;
DeviceAreaConfig areaConfig = this.convertDB(dto);
if (Objects.nonNull(dto.getId()) && dto.getId() != 0L) {
LambdaQueryWrapper<DeviceAreaConfig> qw = Wrappers.lambdaQuery(DeviceAreaConfig.class);
@ -68,7 +117,10 @@ public class DeviceAreaConfigService {
Long counter = this.deviceAreaConfigRepository.count(qw);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(counter > 0L, "未找到对应的数据");
areaConfig.setId(dto.getId());
isUpdate = true;
}
this.checkDataForSql(dto, isUpdate);
this.deviceAreaConfigRepository.saveOrUpdate(areaConfig);
AREA_CONFIG_CACHE.invalidate(dto.getLineId());
}