报警调整

This commit is contained in:
tiger_zhou 2023-08-18 16:58:34 +08:00
parent 4b92f68541
commit fcbfbf683c
11 changed files with 216 additions and 195 deletions

View File

@ -3,7 +3,10 @@ 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.BlueAlertListener;
import club.joylink.xiannccda.ats.warn.DeviceAlertEvent;
import club.joylink.xiannccda.ats.warn.BlueDisplayAlertEvent;
import club.joylink.xiannccda.ats.warn.SwitchAndTrackLedAlertEvent;
import club.joylink.xiannccda.ats.warn.SwitchLostAlertEvent;
import club.joylink.xiannccda.ats.warn.SwitchLostAlertListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
@ -15,25 +18,26 @@ import org.springframework.stereotype.Component;
public class AlertEmitJob implements ApplicationRunner {
@Autowired
private TrainDelayAlertMonitoringTask trainDelayAlertMonitoringTask;
@Autowired
private BlueAlertListener blueAlertListener;
@Autowired
private PlatformDoorAlertMonitoringTask platformDoorAlertMonitoringTask;
@Autowired
private SwitchLostAlertMonitoringTask switchAlertMonitoringTask;
private SwitchLostAlertMonitoringTask lostAlertMonitoringTask2;
@Autowired
private AxleSwitchTrackLedAlertListener axleSwitchTrackAlertListener2;
private AxleSwitchTrackLedAlertListener axleSwitchTrackLedAlertListener2;
@Autowired
private BlueAlertListener blueAlertListener2;
@Autowired
private SwitchLostAlertListener switchLostAlertListener;
@Override
public void run(ApplicationArguments args) throws Exception {
AlertManager alertManager = AlertManager.getDefault();
//报警源
// alertManager.addTask(trainDelayAlertMonitoringTask);
// alertManager.addTask(platformDoorAlertMonitoringTask);
alertManager.addTask(this.switchAlertMonitoringTask);
alertManager.on(this.blueAlertListener, DeviceAlertEvent.class);
alertManager.on(this.axleSwitchTrackAlertListener2, DeviceAlertEvent.class);
// alertManager.addTask(this.switchAlertMonitoringTask);
// alertManager.on(this.blueAlertListener, DeviceAlertEvent.class);
// alertManager.on(this.axleSwitchTrackAlertListener2, DeviceAlertEvent.class);
alertManager.addTask(this.lostAlertMonitoringTask2);
alertManager.on(this.axleSwitchTrackLedAlertListener2, SwitchAndTrackLedAlertEvent.class);
alertManager.on(this.blueAlertListener2, BlueDisplayAlertEvent.class);
alertManager.on(this.switchLostAlertListener, SwitchLostAlertEvent.class);
}
}

View File

@ -3,19 +3,13 @@ package club.joylink.xiannccda.alert;
import club.joylink.xiannccda.alert.core.AlertManager;
import club.joylink.xiannccda.alert.core.AlertMonitoringTask;
import club.joylink.xiannccda.alert.util.AlertUtil;
import club.joylink.xiannccda.ats.message.collect.DeviceDataRepository;
import club.joylink.xiannccda.ats.message.collect.DeviceDataRepository.DataTypeEnum;
import club.joylink.xiannccda.ats.message.collect.datasource.DeviceStatusData;
import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType;
import club.joylink.xiannccda.dto.protos.DeviceStatusProto;
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Switch;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.google.protobuf.GeneratedMessageV3.Builder;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Map;
import java.util.Objects;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import org.springframework.stereotype.Component;
@ -28,11 +22,22 @@ public class SwitchLostAlertMonitoringTask implements AlertMonitoringTask {
this.alertDetailFactory = alertDetailFactory;
}
private final static String DEVICE_TYPE_NAME = DeviceStatusProto.Switch.getDescriptor().getName();
private final static String DEVICE_TYPE_NAME = Switch.getDescriptor().getName();
Map<String, Switch.Builder> deviceMap = new ConcurrentHashMap<>();
public void putSwitchIfNotExist(Switch.Builder switchBuilder) {
if (!deviceMap.containsKey(switchBuilder.getId())) {
deviceMap.put(switchBuilder.getId(), switchBuilder);
}
}
public void removeSwitch(Switch.Builder switchBuilder) {
AlertManager alertManager = AlertManager.getDefault();
deviceMap.remove(switchBuilder.getId());
alertManager.removeAlterDevice(String.valueOf(switchBuilder.getLineId()), DEVICE_TYPE_NAME, switchBuilder.getId());
}
@Override
public String getName() {
@ -49,32 +54,16 @@ public class SwitchLostAlertMonitoringTask implements AlertMonitoringTask {
@Override
public void run() {
AlertManager alertManager = AlertManager.getDefault();
DeviceStatusData deviceStatusData = DeviceDataRepository.findDataSouce(AlertManager.LINE_ID, DataTypeEnum.DEVICE);
Map<String, Builder> builderMap = deviceStatusData.getAllDeviceMap().get(DEVICE_TYPE_NAME);
if (CollectionUtils.isEmpty(builderMap)) {
return;
}
for (Builder value : builderMap.values()) {
Switch.Builder switchBuild = (Switch.Builder) value;
boolean isTurning = switchBuild.getIpSingleSwitchStusLocked() && switchBuild.getIpSingleSwitchStusLostIndication();
Switch.Builder savedSwitchBuild = deviceMap.get(switchBuild.getId());
if (isTurning) {
if (Objects.isNull(savedSwitchBuild)) {
deviceMap.put(switchBuild.getId(), switchBuild.clone());
} else {
boolean saveTurning = savedSwitchBuild.getIpSingleSwitchStusLocked() && savedSwitchBuild.getIpSingleSwitchStusLostIndication();
if (saveTurning && this.remainTimeOut(switchBuild.getTimestamp(), 10)) {
//失表超时
if (alertManager.putAlterDevice(AlertManager.LINE_ID, DEVICE_TYPE_NAME, savedSwitchBuild.getId())) {
NccAlertInfo alertInfo = this.createAlterTip(switchBuild, AlertManager.LINE_ID);
alertManager.emit(alertInfo);
}
}
for (Entry<String, Switch.Builder> builderEntry : deviceMap.entrySet()) {
String key = builderEntry.getKey();
Switch.Builder savedSwitchBuild = builderEntry.getValue();
boolean saveTurning = savedSwitchBuild.getIpSingleSwitchStusLocked() && savedSwitchBuild.getIpSingleSwitchStusLostIndication();
if (saveTurning && this.remainTimeOut(savedSwitchBuild.getTimestamp(), 10)) {
//失表超时
if (alertManager.putAlterDevice(AlertManager.LINE_ID, DEVICE_TYPE_NAME, savedSwitchBuild.getId())) {
NccAlertInfo alertInfo = this.createAlterTip(savedSwitchBuild, AlertManager.LINE_ID);
alertManager.emit(alertInfo);
}
} else if (Objects.nonNull(savedSwitchBuild)) {
deviceMap.remove(savedSwitchBuild.getId());
alertManager.removeAlterDevice(AlertManager.LINE_ID, DEVICE_TYPE_NAME, savedSwitchBuild.getId());
}
}
}

View File

@ -21,6 +21,15 @@ import lombok.extern.slf4j.Slf4j;
public class AlertManager extends EventEmitter {
private static final Map<String, AlertManager> MANAGER_MAP = new ConcurrentHashMap<>();
/**
* 保存已经报警的设备
* <p>
* row = lineid
* <p>
* column = 设备类型也可是自定义的类型
* <p>
* val = 设备code
*/
private static final Table<String, String, List<String>> DEVICE_ALTER_TABLE = Tables.synchronizedTable(HashBasedTable.create());
/**
* 报警监控任务(循环监测式报警)
@ -42,6 +51,13 @@ public class AlertManager extends EventEmitter {
return getInstance("default");
}
public int getAlertDeviceCount(String lineId, String deviceType) {
List<String> deviceNames = DEVICE_ALTER_TABLE.get(lineId, deviceType);
if (CollectionUtils.isEmpty(deviceNames)) {
return 0;
}
return deviceNames.size();
}
public boolean putAlterDevice(String lineId, String deviceType, String deviceName) {
List<String> deviceNames = DEVICE_ALTER_TABLE.get(lineId, deviceType);

View File

@ -1,10 +1,15 @@
package club.joylink.xiannccda.ats.message.collect.convertor;
import club.joylink.xiannccda.alert.core.AlertManager;
import club.joylink.xiannccda.ats.message.MessageData;
import club.joylink.xiannccda.ats.message.MessageId;
import club.joylink.xiannccda.ats.message.collect.DeviceDataRepository.DataTypeEnum;
import club.joylink.xiannccda.ats.warn.BlueDisplayAlertEvent;
import club.joylink.xiannccda.ats.warn.DeviceAlertEvent;
import club.joylink.xiannccda.ats.warn.SwitchAndTrackLedAlertEvent;
import club.joylink.xiannccda.ats.warn.SwitchLostAlertEvent;
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Rtu;
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Switch;
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Track;
import com.google.protobuf.GeneratedMessageV3.Builder;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
@ -25,6 +30,16 @@ public class DeviceChangeStatusConvertor extends DefaultConvertor {
@Override
protected void eventHandle(List<Builder> builders) {
AlertManager alertManager = AlertManager.getDefault();
alertManager.emit(new DeviceAlertEvent<List<Builder>>(builders));
for (Builder builder : builders) {
if (builder instanceof Rtu.Builder rtuBuild) {
alertManager.emit(new BlueDisplayAlertEvent(rtuBuild));
} else if (builder instanceof Track.Builder trackBuild) {
alertManager.emit(new SwitchAndTrackLedAlertEvent(trackBuild));
} else if (builder instanceof Switch.Builder switchBuild) {
alertManager.emit(new SwitchAndTrackLedAlertEvent(switchBuild));
alertManager.emit(new SwitchLostAlertEvent(switchBuild));
}
}
// alertManager.emit(new DeviceAlertEvent<List<Builder>>(builders));
}
}

View File

@ -19,14 +19,13 @@ import com.google.protobuf.GeneratedMessageV3.Builder;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.List;
import java.util.Objects;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
@Component
public class AxleSwitchTrackLedAlertListener implements AlertSourceEventListener<DeviceAlertEvent<List<Builder>>> {
public class AxleSwitchTrackLedAlertListener implements AlertSourceEventListener<SwitchAndTrackLedAlertEvent> {
private AlertDetailFactory alertDetailFactory;
@ -35,32 +34,27 @@ public class AxleSwitchTrackLedAlertListener implements AlertSourceEventListener
}
@Override
public void accept(DeviceAlertEvent<List<Builder>> event) {
List<Builder> listBuild = event.getSource();
for (Builder o : listBuild) {
boolean isSwitchOrTrack = (o instanceof Switch.Builder || o instanceof Track.Builder);
if (isSwitchOrTrack) {
Integer lineId = DeviceStatusDataOperate.findFieldVal(o, "lineId", Integer.class);
String id = DeviceStatusDataOperate.findFieldVal(o, "id", String.class);
if (Objects.isNull(lineId)) {
continue;
}
String sectionCode = LineGraphicDataRepository.findSectionFromLogicCode(lineId, id);
if (StringUtils.isEmpty(sectionCode)) {
continue;
}
Section section = LineGraphicDataRepository.getDeviceByCode(lineId, sectionCode, Section.class);
if (section.getTurning()) {
continue;
}
TrainDataSource trainDataSource = DeviceDataRepository.findDataSouce(lineId.toString(), DataTypeEnum.TRAIN);
String trainGroupId = trainDataSource.findTrainForDeviceName(id);
if (o instanceof Switch.Builder switchBuilder) {
this.switchHandle(switchBuilder, trainGroupId, section);
} else if (o instanceof Track.Builder trackBuilder) {
this.trackHandle(trackBuilder, trainGroupId, section);
}
}
public void accept(SwitchAndTrackLedAlertEvent event) {
GeneratedMessageV3.Builder o = event.getSource();
Integer lineId = DeviceStatusDataOperate.findFieldVal(o, "lineId", Integer.class);
String id = DeviceStatusDataOperate.findFieldVal(o, "id", String.class);
if (Objects.isNull(lineId)) {
return;
}
String sectionCode = LineGraphicDataRepository.findSectionFromLogicCode(lineId, id);
if (StringUtils.isEmpty(sectionCode)) {
return;
}
Section section = LineGraphicDataRepository.getDeviceByCode(lineId, sectionCode, Section.class);
if (section.getTurning()) {
return;
}
TrainDataSource trainDataSource = DeviceDataRepository.findDataSouce(lineId.toString(), DataTypeEnum.TRAIN);
String trainGroupId = trainDataSource.findTrainForDeviceName(id);
if (o instanceof Switch.Builder switchBuilder) {
this.switchHandle(switchBuilder, trainGroupId, section);
} else if (o instanceof Track.Builder trackBuilder) {
this.trackHandle(trackBuilder, trainGroupId, section);
}
}
@ -76,20 +70,31 @@ public class AxleSwitchTrackLedAlertListener implements AlertSourceEventListener
this.emit(ledRed, trackBuild, section, AlertType.AXLE_LED_RED);
}
private void emit(boolean light, GeneratedMessageV3.Builder build, Section section, AlertType alertType) {
private void emit(boolean light, Builder build, Section section, AlertType alertType) {
AlertManager alertManager = AlertManager.getDefault();
Integer lineId = DeviceStatusDataOperate.findFieldVal(build, "lineId", Integer.class);
Integer rtuId = DeviceStatusDataOperate.findFieldVal(build, "rtuId", Integer.class);
String id = DeviceStatusDataOperate.findFieldVal(build, "id", String.class);
Long timestemp = DeviceStatusDataOperate.findFieldVal(build, "timestamp", Long.class);
String alertTypeName = String.format("%s-%s-%s", alertType.name(), lineId, rtuId);
String alertTypeMostName = String.format("%s-%s", alertTypeName, "counter");
if (light) {
if (alertManager.putAlterDevice(lineId.toString(), alertType.name(), id)) {
if (alertManager.putAlterDevice(lineId.toString(), alertTypeName, id)) {
LocalDateTime createTime = LocalDateTime.ofInstant(Instant.ofEpochSecond(timestemp), ZoneId.of("+8"));
NccAlertInfo alertInfo = this.alertDetailFactory.getAlertDetail(createTime, alertType, lineId, false, section);
alertInfo.setAlertLocation(AlertUtil.findLocationByRtuCode(id).orElse(null));
alertManager.emit(alertInfo);
//TODO 检查对应的类型下数量是否超过阈值超过阈值及达到大范围报警
if (alertManager.getAlertDeviceCount(lineId.toString(), alertTypeName) > 3
&& alertManager.putAlterDevice(lineId.toString(), alertTypeMostName, alertTypeMostName)) {
AlertType mostType = alertType == AlertType.AXLE_LED_RED ? AlertType.AXLE_LED_RED_MOST : AlertType.AXLE_LED_ORANGE_MOST;
}
}
} else {
alertManager.removeAlterDevice(lineId.toString(), alertType.name(), id);
alertManager.removeAlterDevice(lineId.toString(), alertTypeName, id);
// alertManager.removeAlterDevice(lineId.toString(), alertTypeCounterName, alertTypeName);
}
}
}

View File

@ -1,83 +0,0 @@
package club.joylink.xiannccda.ats.warn;
import club.joylink.xiannccda.alert.AlertDetailFactory;
import club.joylink.xiannccda.alert.NccAlertInfo;
import club.joylink.xiannccda.alert.core.AlertManager;
import club.joylink.xiannccda.alert.core.AlertSourceEventListener;
import club.joylink.xiannccda.alert.util.AlertUtil;
import club.joylink.xiannccda.ats.cache.LineGraphicDataRepository;
import club.joylink.xiannccda.ats.message.collect.DeviceDataRepository;
import club.joylink.xiannccda.ats.message.collect.DeviceDataRepository.DataTypeEnum;
import club.joylink.xiannccda.ats.message.collect.datasource.TrainDataSource;
import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType;
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Track;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Section;
import club.joylink.xiannccda.repository.IAlertTipRepository;
import com.google.protobuf.GeneratedMessageV3;
import com.google.protobuf.GeneratedMessageV3.Builder;
import com.google.protobuf.MessageOrBuilder;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.List;
import java.util.Objects;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
@Component
public class AxleTrackAlertListener implements AlertSourceEventListener<DeviceAlertEvent<List<GeneratedMessageV3.Builder>>> {
private IAlertTipRepository alertTipRepository;
private AlertDetailFactory alertDetailFactory;
public AxleTrackAlertListener(IAlertTipRepository alertTipRepository, AlertDetailFactory alertDetailFactory) {
this.alertTipRepository = alertTipRepository;
this.alertDetailFactory = alertDetailFactory;
}
private NccAlertInfo createAlterTip(Track.Builder trackBuild, Section section, AlertType alertType) {
LocalDateTime createTime = LocalDateTime.ofInstant(Instant.ofEpochSecond(trackBuild.getTimestamp()), ZoneId.of("+8"));
NccAlertInfo alertInfo = this.alertDetailFactory.getAlertDetail(createTime, alertType, trackBuild.getLineId(), false, section);
alertInfo.setAlertLocation(AlertUtil.findLocationByRtuCode(trackBuild.getId()).orElse(null));
return alertInfo;
}
@Override
public void accept(DeviceAlertEvent<List<Builder>> event) {
List<GeneratedMessageV3.Builder> listBuild = event.getSource();
for (GeneratedMessageV3.Builder o : listBuild) {
if (o instanceof Track.Builder trackBuild) {
String sectionCode = LineGraphicDataRepository.findSectionFromLogicCode(trackBuild.getLineId(), trackBuild.getId());
if (StringUtils.isEmpty(sectionCode)) {
continue;
}
Section section = LineGraphicDataRepository.getDeviceByCode(trackBuild.getLineId(), sectionCode, Section.class);
if (section.getTurning()) {
continue;
}
TrainDataSource trainDataSource = DeviceDataRepository.findDataSouce(String.valueOf(trackBuild.getLineId()), DataTypeEnum.TRAIN);
String trainGroupId = trainDataSource.findTrainForDeviceName(trackBuild.getId());
// 告知占用未cbtc占用没有列车
boolean ledRed = trackBuild.getCiOccupied() && !trackBuild.getCbtcOccupied() && Objects.isNull(trainGroupId);
boolean orange = trackBuild.getAtcInvalid();
this.emit(ledRed, trackBuild, section, AlertType.AXLE_LED_RED);
}
}
}
private void emit(boolean light, Track.Builder trackBuild, Section section, AlertType alertType) {
AlertManager alertManager = AlertManager.getDefault();
if (light) {
if (alertManager.putAlterDevice(String.valueOf(trackBuild.getLineId()), alertType.name(), trackBuild.getId())) {
NccAlertInfo alertInfo = this.createAlterTip(trackBuild, section, alertType);
alertManager.emit(alertInfo);
}
} else {
alertManager.removeAlterDevice(String.valueOf(trackBuild.getLineId()), alertType.name(), trackBuild.getId());
}
}
}

View File

@ -6,41 +6,28 @@ import club.joylink.xiannccda.alert.core.AlertManager;
import club.joylink.xiannccda.alert.core.AlertSourceEventListener;
import club.joylink.xiannccda.alert.util.AlertUtil;
import club.joylink.xiannccda.ats.cache.LineGraphicDataRepository;
import club.joylink.xiannccda.ats.message.collect.DeviceDataRepository;
import club.joylink.xiannccda.ats.message.collect.DeviceDataRepository.DataTypeEnum;
import club.joylink.xiannccda.ats.message.collect.datasource.TrainDataSource;
import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType;
import club.joylink.xiannccda.dto.protos.DeviceStatusProto;
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Rtu;
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Track;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Section;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Station;
import club.joylink.xiannccda.repository.IAlertTipRepository;
import com.google.common.base.Strings;
import com.google.protobuf.GeneratedMessageV3.Builder;
import com.google.protobuf.MessageOrBuilder;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.List;
import java.util.Objects;
import java.util.stream.Stream;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class BlueAlertListener implements AlertSourceEventListener<DeviceAlertEvent<List<Builder>>> {
public class BlueAlertListener implements AlertSourceEventListener<BlueDisplayAlertEvent> {
private IAlertTipRepository alertTipRepository;
@Autowired
private AlertDetailFactory alertDetailFactory;
public BlueAlertListener(IAlertTipRepository alertTipRepository, AlertDetailFactory alertDetailFactory) {
this.alertTipRepository = alertTipRepository;
this.alertDetailFactory = alertDetailFactory;
}
private final static String DEVICE_TYPE_NAME = DeviceStatusProto.Rtu.getDescriptor().getName();
private final static String DEVICE_TYPE_NAME = Rtu.getDescriptor().getName();
private NccAlertInfo createAlterTip(Rtu.Builder rtuBuild, String lineId, MessageOrBuilder mb) {
@ -52,23 +39,19 @@ public class BlueAlertListener implements AlertSourceEventListener<DeviceAlertEv
}
@Override
public void accept(DeviceAlertEvent<List<Builder>> event) {
List<Builder> listBuild = event.getSource();
public void accept(BlueDisplayAlertEvent event) {
Rtu.Builder rtu = event.getSource();
AlertManager alertManager = AlertManager.getDefault();
for (Builder o : listBuild) {
if (o instanceof Rtu.Builder rtu) {
if (rtu.getIpRtuStusDown()) {
if (alertManager.putAlterDevice(String.valueOf(rtu.getLineId()), DEVICE_TYPE_NAME, rtu.getId())) {
String rtuName = Strings.padStart(rtu.getId(), 2, '0');
Stream<Station> stream = LineGraphicDataRepository.getDevices(Integer.parseInt(AlertManager.LINE_ID), Station.class);
Station station = stream.filter(Station::getConcentrationStations).filter(d -> StringUtils.equals(d.getCode(), rtuName)).findFirst().get();
NccAlertInfo alertInfo = this.createAlterTip(rtu, AlertManager.LINE_ID, station);
alertManager.emit(alertInfo);
}
} else {
alertManager.removeAlterDevice(AlertManager.LINE_ID, DEVICE_TYPE_NAME, rtu.getId());
}
if (rtu.getIpRtuStusDown()) {
if (alertManager.putAlterDevice(String.valueOf(rtu.getLineId()), DEVICE_TYPE_NAME, rtu.getId())) {
String rtuName = Strings.padStart(rtu.getId(), 2, '0');
Stream<Station> stream = LineGraphicDataRepository.getDevices(Integer.parseInt(AlertManager.LINE_ID), Station.class);
Station station = stream.filter(Station::getConcentrationStations).filter(d -> StringUtils.equals(d.getCode(), rtuName)).findFirst().get();
NccAlertInfo alertInfo = this.createAlterTip(rtu, AlertManager.LINE_ID, station);
alertManager.emit(alertInfo);
}
} else {
alertManager.removeAlterDevice(AlertManager.LINE_ID, DEVICE_TYPE_NAME, rtu.getId());
}
}
}

View File

@ -0,0 +1,11 @@
package club.joylink.xiannccda.ats.warn;
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Rtu;
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Rtu.Builder;
public class BlueDisplayAlertEvent extends DeviceAlertEvent<Rtu.Builder> {
public BlueDisplayAlertEvent(Builder source) {
super(source);
}
}

View File

@ -0,0 +1,11 @@
package club.joylink.xiannccda.ats.warn;
import com.google.protobuf.GeneratedMessageV3;
import com.google.protobuf.GeneratedMessageV3.Builder;
public class SwitchAndTrackLedAlertEvent extends DeviceAlertEvent<GeneratedMessageV3.Builder> {
public SwitchAndTrackLedAlertEvent(Builder source) {
super(source);
}
}

View File

@ -0,0 +1,11 @@
package club.joylink.xiannccda.ats.warn;
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Switch;
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Switch.Builder;
public class SwitchLostAlertEvent extends DeviceAlertEvent<Switch.Builder> {
public SwitchLostAlertEvent(Builder source) {
super(source);
}
}

View File

@ -0,0 +1,59 @@
package club.joylink.xiannccda.ats.warn;
import club.joylink.xiannccda.alert.AlertDetailFactory;
import club.joylink.xiannccda.alert.NccAlertInfo;
import club.joylink.xiannccda.alert.SwitchLostAlertMonitoringTask;
import club.joylink.xiannccda.alert.core.AlertManager;
import club.joylink.xiannccda.alert.core.AlertSourceEventListener;
import club.joylink.xiannccda.alert.util.AlertUtil;
import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType;
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Switch;
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Track;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Section;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class SwitchLostAlertListener implements AlertSourceEventListener<SwitchLostAlertEvent> {
@Autowired
private AlertDetailFactory alertDetailFactory;
@Autowired
private SwitchLostAlertMonitoringTask monitoringTask2;
private NccAlertInfo createAlterTip(Track.Builder trackBuild, Section section, AlertType alertType) {
LocalDateTime createTime = LocalDateTime.ofInstant(Instant.ofEpochSecond(trackBuild.getTimestamp()), ZoneId.of("+8"));
NccAlertInfo alertInfo = this.alertDetailFactory.getAlertDetail(createTime, alertType, trackBuild.getLineId(), false, section);
alertInfo.setAlertLocation(AlertUtil.findLocationByRtuCode(trackBuild.getId()).orElse(null));
return alertInfo;
}
@Override
public void accept(SwitchLostAlertEvent event) {
Switch.Builder switchBuild = event.getSource();
boolean isTurning = switchBuild.getIpSingleSwitchStusLocked() && switchBuild.getIpSingleSwitchStusLostIndication();
if (isTurning) {
this.monitoringTask2.putSwitchIfNotExist(switchBuild);
} else {
this.monitoringTask2.removeSwitch(switchBuild);
}
}
private void emit(boolean light, Track.Builder trackBuild, Section section, AlertType alertType) {
AlertManager alertManager = AlertManager.getDefault();
if (light) {
if (alertManager.putAlterDevice(String.valueOf(trackBuild.getLineId()), alertType.name(), trackBuild.getId())) {
NccAlertInfo alertInfo = this.createAlterTip(trackBuild, section, alertType);
alertManager.emit(alertInfo);
}
} else {
alertManager.removeAlterDevice(String.valueOf(trackBuild.getLineId()), alertType.name(), trackBuild.getId());
}
}
}