代码调整

This commit is contained in:
tiger_zhou 2023-09-13 15:43:50 +08:00
parent d41a47bf4c
commit 7ba60f1863
10 changed files with 106 additions and 111 deletions

View File

@ -1,28 +1,11 @@
package club.joylink.xiannccda.alert;
import club.joylink.xiannccda.alert.core.AlertManager;
import club.joylink.xiannccda.ats.warn.AxleSwitchTrackLedAlertListener;
import club.joylink.xiannccda.ats.warn.AxleSwitchTrackLedAlertListener.SwitchAndTrackLedAlertEvent;
import club.joylink.xiannccda.ats.warn.AxleSwitchTrackLedMostAlertListener;
import club.joylink.xiannccda.ats.warn.AxleSwitchTrackLedMostAlertListener.SwitchAndTrackLedMostAlertEvent;
import club.joylink.xiannccda.ats.warn.BlueAlertListener;
import club.joylink.xiannccda.ats.warn.BlueAlertListener.BlueDisplayAlertEvent;
import club.joylink.xiannccda.ats.warn.PlatformAlertMonitoringTask;
import club.joylink.xiannccda.ats.warn.SwitchLostAlertListener;
import club.joylink.xiannccda.ats.warn.SwitchLostAlertListener.SwitchLostAlertEvent;
import club.joylink.xiannccda.ats.warn.SwitchLostAlertMonitoringTask;
import club.joylink.xiannccda.ats.warn.SwitchLostMostAlertListener;
import club.joylink.xiannccda.ats.warn.SwitchLostMostAlertListener.SwitchLostMostEvent;
import club.joylink.xiannccda.ats.warn.TrainAtpCutAlertMonitoringTask;
import club.joylink.xiannccda.ats.warn.TrainModeAlertListener;
import club.joylink.xiannccda.ats.warn.TrainModeAlertListener.TrainAlertEvent;
import club.joylink.xiannccda.ats.warn.TrainReacrdAlertListener;
import club.joylink.xiannccda.ats.warn.TrainReacrdAlertListener.TrainRecordAlertEvent;
import org.springframework.beans.factory.annotation.Autowired;
import club.joylink.xiannccda.alert.core.AlertMonitoringTask;
import club.joylink.xiannccda.alert.core.AlertSourceEventListener;
import club.joylink.xiannccda.constants.SystemContext;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
@ -30,52 +13,23 @@ import org.springframework.stereotype.Component;
@Order(1)
@Component
@Slf4j
public class AlertEmitJob implements ApplicationRunner {
@Autowired
private SwitchLostAlertMonitoringTask lostAlertMonitoringTask2;
private final AlertManager alertManager = AlertManager.getDefault();
@Autowired
private AxleSwitchTrackLedAlertListener axleSwitchTrackLedAlertListener2;
@Autowired
private BlueAlertListener blueAlertListener2;
@Autowired
private SwitchLostAlertListener switchLostAlertListener;
@Autowired
private PlatformAlertMonitoringTask platformAlertMonitoringTask;
@Autowired
private TrainModeAlertListener trainModeAlertListener;
@Autowired
private TrainAtpCutAlertMonitoringTask trainAtpCutAlertMonitoringTask;
@Autowired
private TrainReacrdAlertListener trainReacrdAlertListener;
@Autowired
private AxleSwitchTrackLedMostAlertListener mostAlertListener;
@Autowired
private SwitchLostMostAlertListener lostMostAlertListener;
@Override
public void run(ApplicationArguments args) throws Exception {
AlertManager alertManager = AlertManager.getDefault();
//道岔失表任务
alertManager.addTask(this.lostAlertMonitoringTask2);
//站台屏蔽门任务
alertManager.addTask(this.platformAlertMonitoringTask);
//列车atp切除任务
alertManager.addTask(this.trainAtpCutAlertMonitoringTask);
//光带检查监听
alertManager.on(this.axleSwitchTrackLedAlertListener2, SwitchAndTrackLedAlertEvent.class);
//蓝显检测
alertManager.on(this.blueAlertListener2, BlueDisplayAlertEvent.class);
// 道岔失表监听
alertManager.on(this.switchLostAlertListener, SwitchLostAlertEvent.class);
// 列车制动监听
alertManager.on(this.trainModeAlertListener, TrainAlertEvent.class);
//列车报点监听
alertManager.on(this.trainReacrdAlertListener, TrainRecordAlertEvent.class);
alertManager.on(this.mostAlertListener, SwitchAndTrackLedMostAlertEvent.class);
alertManager.on(this.lostMostAlertListener, SwitchLostMostEvent.class);
Map<String, AlertMonitoringTask> monitoringTaskMap = SystemContext.getAppContext().getBeansOfType(AlertMonitoringTask.class);
monitoringTaskMap.forEach((k, v) -> {
log.info("加载告警定时任务 key[{}] val[{}]", k, v.getClass().getName());
alertManager.addTask(v);
});
Map<String, AlertSourceEventListener> eventListenerMap = SystemContext.getAppContext().getBeansOfType(AlertSourceEventListener.class);
eventListenerMap.forEach((k, v) -> {
log.info("加载告警监听 key[{}] val[{}]", k, v.getClass().getName());
alertManager.on(v);
});
}
}

View File

@ -44,17 +44,20 @@ public class AlertListenerJob implements ApplicationRunner {
@Override
public void accept(NccAlertInfo alertInfo) {
if (!alertInfo.isMock()) {
/*if (!alertInfo.isMock()) {
AlertRecord record = convertToRecord(alertInfo);
alertRecordRepository.save(record);
alertInfo.setId(record.getId());
} else {
alertInfo.setId(idGenerator.decrementAndGet());
}
}*/
//不论是否mock 都保存数据库
AlertRecord record = convertToRecord(alertInfo);
alertRecordRepository.save(record);
alertInfo.setId(record.getId());
nccAlertMessageServer.addMsg(alertInfo);
}
});
}
private AlertRecord convertToRecord(NccAlertInfo nccAlertInfo) {
@ -66,6 +69,7 @@ public class AlertListenerJob implements ApplicationRunner {
record.setAlertLocationId(nccAlertInfo.getAlertLocationId());
record.setAlertDeviceType(nccAlertInfo.getAlertDeviceType().name());
record.setAlertDeviceId(nccAlertInfo.getLocatorDeviceId());
record.setMock(nccAlertInfo.isMock());
// record.setAlertLocation(nccAlertInfo.getAlertLocationName());
return record;
}

View File

@ -4,7 +4,7 @@ import club.joylink.xiannccda.alert.core.AlertMonitoringTask;
import club.joylink.xiannccda.repository.IAlertTipRepository;
import org.springframework.stereotype.Component;
@Component
//@Component
public class PlatformDoorAlertMonitoringTask implements AlertMonitoringTask {
private IAlertTipRepository alertTipRepository;

View File

@ -4,7 +4,7 @@ import club.joylink.xiannccda.alert.core.AlertMonitoringTask;
import club.joylink.xiannccda.repository.IAlertTipRepository;
import org.springframework.stereotype.Component;
@Component
//@Component
public class TrainDelayAlertMonitoringTask implements AlertMonitoringTask {
private IAlertTipRepository alertTipRepository;

View File

@ -0,0 +1,66 @@
package club.joylink.xiannccda.ats.warn;
import club.joylink.xiannccda.alert.NccAlertInfo;
import club.joylink.xiannccda.alert.core.AlertDeviceType;
import club.joylink.xiannccda.alert.core.AlertManager;
import club.joylink.xiannccda.alert.core.AlertSourceEventListener;
import club.joylink.xiannccda.ats.cache.LineGraphicDataRepository;
import club.joylink.xiannccda.ats.warn.AllLineBlueAlertListener.AllLineBlueDisplayAlertEvent;
import club.joylink.xiannccda.ats.warn.BlueAlertListener.BlueDisplayAlertEvent;
import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType;
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Rtu;
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Rtu.Builder;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Station;
import club.joylink.xiannccda.entity.DeviceAreaConfig;
import club.joylink.xiannccda.service.AlertInfoService;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.google.common.base.Strings;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
@Slf4j
public class AllLineBlueAlertListener implements AlertSourceEventListener<AllLineBlueDisplayAlertEvent> {
@Autowired
private AlertInfoService alertInfoService;
private final static AlertManager alertManager = AlertManager.getDefault();
@Override
public void accept(AllLineBlueDisplayAlertEvent event) {
Rtu.Builder rtu = event.getSource();
if (alertManager.needMostShow(rtu.getLineId(), BlueAlertListener.BLUE_DISPLAY_NAME, event.allControlStationSize)
&& alertManager.putAlterDevice(rtu.getLineId(), BlueAlertListener.BLUE_DISPLAY_NAME, BlueAlertListener.ALL_BLUE_DISPLAY_VAL_FLAG)) {
NccAlertInfo alertInfo = this.alertInfoService.createAlert2(Optional.empty(), AlertType.ALL_LINE_BLUE_DISPLAY, rtu, BlueAlertListener.ALL_BLUE_DISPLAY_VAL_FLAG,
event.station.getCommon().getId(),
AlertDeviceType.DEVICE_TYPE_RTU, false);
alertManager.emit(alertInfo);
}
}
public static class AllLineBlueDisplayAlertEvent extends DeviceAlertEvent<Builder> {
private Station station;
private Integer allControlStationSize;
public AllLineBlueDisplayAlertEvent(Builder source, Station station, Integer allControlStationSize) {
super(source);
this.station = station;
this.allControlStationSize = allControlStationSize;
}
}
}

View File

@ -40,7 +40,6 @@ public class AxleSwitchTrackLedMostAlertListener implements AlertSourceEventList
private final AlertManager alertManager = AlertManager.getDefault();
public AxleSwitchTrackLedMostAlertListener(DeviceGuardConfigService configService, AlertInfoService alertInfoService) {
this.configService = configService;
this.alertInfoService = alertInfoService;
}

View File

@ -5,12 +5,12 @@ import club.joylink.xiannccda.alert.core.AlertDeviceType;
import club.joylink.xiannccda.alert.core.AlertManager;
import club.joylink.xiannccda.alert.core.AlertSourceEventListener;
import club.joylink.xiannccda.ats.cache.LineGraphicDataRepository;
import club.joylink.xiannccda.ats.warn.AllLineBlueAlertListener.AllLineBlueDisplayAlertEvent;
import club.joylink.xiannccda.ats.warn.BlueAlertListener.BlueDisplayAlertEvent;
import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType;
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Rtu;
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Rtu.Builder;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Station;
import club.joylink.xiannccda.entity.DeviceAreaConfig;
import club.joylink.xiannccda.service.AlertInfoService;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.google.common.base.Strings;
@ -26,7 +26,6 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@ -38,11 +37,10 @@ public class BlueAlertListener implements AlertSourceEventListener<BlueDisplayAl
@Autowired
private AlertInfoService alertInfoService;
private final static String BLUE_DISPLAY_NAME = Rtu.getDescriptor().getName();
private final static String ALL_BLUE_DISPLAY_VAL = "全线蓝显";
protected final static String BLUE_DISPLAY_NAME = Rtu.getDescriptor().getName();
protected final static String ALL_BLUE_DISPLAY_VAL_FLAG = "全线蓝显";
private final static AlertManager alertManager = AlertManager.getDefault();
private final static String COLL_RTU_NAME = "COLL_RTU_NAMES";
/**
* 集中站集合
* <p>
@ -59,36 +57,19 @@ public class BlueAlertListener implements AlertSourceEventListener<BlueDisplayAl
log.error("rtuId[{}] 未找到对应的集中站数据", rtu.getId());
return;
}
Optional<DeviceAreaConfig> alertInfoOpt = this.alertInfoService.findAreaDevice(AlertType.BLUE_DISPLAY, AlertDeviceType.DEVICE_TYPE_RTU, station.getCommon().getId(),
rtu.getLineId());
if (alertInfoOpt.isEmpty()) {
log.error("线路[{}] rtu[{}] 地图车站id[{}] 线路Id[{}]未找到对应的区域配置,无法蓝显", rtu.getLineId(), rtu.getId(), station.getCommon().getId(), rtu.getLineId());
return;
}
DeviceAreaConfig areaConfig = alertInfoOpt.get();
if (rtu.getIpRtuStusDown()) {
log.info("线路[{}] 车站[{}] rtu[{}] 通信中断", rtu.getLineId(), station.getName(), rtu.getId());
//保存出现蓝显的集中站
alertManager.putAlterDevice(rtu.getLineId(), COLL_RTU_NAME, rtu.getId());
//保存蓝显联锁id
if (alertManager.putAlterDevice(rtu.getLineId(), BLUE_DISPLAY_NAME, areaConfig.getId().toString())) {
String alertMsg = String.format("%s 蓝显", areaConfig.getAreaName());
NccAlertInfo alertInfo = this.alertInfoService.createAlert2(alertInfoOpt, AlertType.BLUE_DISPLAY, rtu, alertMsg, station.getCommon().getId(), AlertDeviceType.DEVICE_TYPE_RTU, false);
alertManager.emit(alertInfo);
}
int allControlStationSize = CONTROL_STATION_MAPER.get(rtu.getLineId()).size();
//查看是否全部的集中站已经蓝显
if (alertManager.needMostShow(rtu.getLineId(), COLL_RTU_NAME, allControlStationSize)
&& alertManager.putAlterDevice(rtu.getLineId(), BLUE_DISPLAY_NAME, ALL_BLUE_DISPLAY_VAL)) {
NccAlertInfo alertInfo = this.alertInfoService.createAlert2(Optional.empty(), AlertType.ALL_LINE_BLUE_DISPLAY, rtu, ALL_BLUE_DISPLAY_VAL, station.getCommon().getId(),
AlertDeviceType.DEVICE_TYPE_RTU, false);
if (alertManager.putAlterDevice(rtu.getLineId(), BLUE_DISPLAY_NAME, rtu.getId())) {
int allControlStationSize = CONTROL_STATION_MAPER.get(rtu.getLineId()).size();
String alertMsg = String.format("%s 集中站中断连接 `", station.getName());
NccAlertInfo alertInfo = this.alertInfoService.createAlert2(Optional.empty(), AlertType.BLUE_DISPLAY, rtu, alertMsg, station.getCommon().getId(), AlertDeviceType.DEVICE_TYPE_RTU, false);
alertManager.emit(alertInfo);
alertManager.emit(new AllLineBlueDisplayAlertEvent(rtu, station, allControlStationSize));
}
} else {
alertManager.removeAlterDevice(rtu.getLineId(), BLUE_DISPLAY_NAME, areaConfig.getId().toString());
alertManager.removeAlterDevice(rtu.getLineId(), COLL_RTU_NAME, rtu.getId());
alertManager.removeAlterDevice(rtu.getLineId(), BLUE_DISPLAY_NAME, ALL_BLUE_DISPLAY_VAL);
alertManager.removeAlterDevice(rtu.getLineId(), BLUE_DISPLAY_NAME, rtu.getId());
alertManager.removeAlterDevice(rtu.getLineId(), BLUE_DISPLAY_NAME, ALL_BLUE_DISPLAY_VAL_FLAG);
}
}

View File

@ -43,7 +43,7 @@ public class AlertRecord {
private String alertDeviceType;
private String alertDeviceId;
private Boolean mock;
public static final String ID = "id";
public static final String ALERT_TYPE = "alert_type";
@ -61,4 +61,5 @@ public class AlertRecord {
public static final String ALERT_DEVICE_TYPE = "alert_device_type";
public static final String ALERT_DEVICE_ID = "alert_device_id";
public static final String MOCK = "mock";
}

View File

@ -52,7 +52,7 @@ public class AlertRecordService {
}
AlertType alertType = AlertType.valueOf(tipType);
switch (alertType) {
case AXLE_LED_RED, AXLE_LED_ORANGE, SWITCH_All_LOST, SWITCH_DW_LOST, SWITCH_FW_LOST -> {
case BLUE_DISPLAY, AXLE_LED_RED, AXLE_LED_ORANGE, SWITCH_All_LOST, SWITCH_DW_LOST, SWITCH_FW_LOST -> {
List<DeviceAreaConfig> areaConfigList = this.areaConfigService.getCache(ar.getLineId(), AlertDeviceType.valueOf(ar.getAlertDeviceType()));
List<DeviceAreaConfig> findList = areaConfigList.stream().filter(d -> StringUtils.contains(d.getAlertTypes(), tipType)).filter(d -> {
String[] datas = d.getData().split(",");
@ -83,6 +83,7 @@ public class AlertRecordService {
AlertTip tip = alertTipRepository.getOne(qw, false);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(Objects.nonNull(tip), "未找到对应的决策辅助信息");
this.alertRecordRepository.update(Wrappers.lambdaUpdate(AlertRecord.class)
.set(AlertRecord::getAlertTipId, tip.getId()).set(AlertRecord::getAlarmStatus, 1)
.set(hasAreaConfigId, AlertRecord::getAlertLocationId, newAreaConfigId)

View File

@ -57,17 +57,6 @@ public class AlertTipService {
alertTipRepository.saveOrUpdate(saveEntity, updateWrapper);
}
public Optional<AlertTip> queryOne2(String alertType, Long areaConfigId) {
if (alertType == null) {
return Optional.empty();
}
LambdaQueryWrapper<AlertTip> queryWrapper = Wrappers.lambdaQuery(AlertTip.class)
.eq(AlertTip::getAlertType, alertType);
if (Objects.nonNull(areaConfigId)) {
queryWrapper.eq(AlertTip::getAreaConfigId, areaConfigId);
}
return Optional.ofNullable(alertTipRepository.getOne(queryWrapper, false));
}
public Optional<AlertTip> queryOne(String alertType, String alertLocation) {
if (alertType == null) {