diff --git a/src/main/java/club/joylink/xiannccda/alert/AlertEmitJob.java b/src/main/java/club/joylink/xiannccda/alert/AlertEmitJob.java index dcfbd2f..1c87e87 100644 --- a/src/main/java/club/joylink/xiannccda/alert/AlertEmitJob.java +++ b/src/main/java/club/joylink/xiannccda/alert/AlertEmitJob.java @@ -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); + } } diff --git a/src/main/java/club/joylink/xiannccda/alert/SwitchLostAlertMonitoringTask.java b/src/main/java/club/joylink/xiannccda/alert/SwitchLostAlertMonitoringTask.java index 044275f..a3809d6 100644 --- a/src/main/java/club/joylink/xiannccda/alert/SwitchLostAlertMonitoringTask.java +++ b/src/main/java/club/joylink/xiannccda/alert/SwitchLostAlertMonitoringTask.java @@ -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 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 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 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()); - } } } diff --git a/src/main/java/club/joylink/xiannccda/alert/core/AlertManager.java b/src/main/java/club/joylink/xiannccda/alert/core/AlertManager.java index 471a8e6..934a362 100644 --- a/src/main/java/club/joylink/xiannccda/alert/core/AlertManager.java +++ b/src/main/java/club/joylink/xiannccda/alert/core/AlertManager.java @@ -21,6 +21,15 @@ import lombok.extern.slf4j.Slf4j; public class AlertManager extends EventEmitter { private static final Map MANAGER_MAP = new ConcurrentHashMap<>(); + /** + * 保存已经报警的设备 + *

+ * row = lineid + *

+ * column = 设备类型,也可是自定义的类型 + *

+ * val = 设备code + */ private static final Table> 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 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 deviceNames = DEVICE_ALTER_TABLE.get(lineId, deviceType); diff --git a/src/main/java/club/joylink/xiannccda/ats/message/collect/convertor/DeviceChangeStatusConvertor.java b/src/main/java/club/joylink/xiannccda/ats/message/collect/convertor/DeviceChangeStatusConvertor.java index ddc1485..eea1ec9 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/collect/convertor/DeviceChangeStatusConvertor.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/collect/convertor/DeviceChangeStatusConvertor.java @@ -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 builders) { AlertManager alertManager = AlertManager.getDefault(); - alertManager.emit(new DeviceAlertEvent>(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>(builders)); } } diff --git a/src/main/java/club/joylink/xiannccda/ats/warn/AxleSwitchTrackLedAlertListener.java b/src/main/java/club/joylink/xiannccda/ats/warn/AxleSwitchTrackLedAlertListener.java index e22a0e6..4b75dde 100644 --- a/src/main/java/club/joylink/xiannccda/ats/warn/AxleSwitchTrackLedAlertListener.java +++ b/src/main/java/club/joylink/xiannccda/ats/warn/AxleSwitchTrackLedAlertListener.java @@ -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>> { +public class AxleSwitchTrackLedAlertListener implements AlertSourceEventListener { private AlertDetailFactory alertDetailFactory; @@ -35,32 +34,27 @@ public class AxleSwitchTrackLedAlertListener implements AlertSourceEventListener } @Override - public void accept(DeviceAlertEvent> event) { - List 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); } + } } diff --git a/src/main/java/club/joylink/xiannccda/ats/warn/AxleTrackAlertListener.java b/src/main/java/club/joylink/xiannccda/ats/warn/AxleTrackAlertListener.java deleted file mode 100644 index da4af6c..0000000 --- a/src/main/java/club/joylink/xiannccda/ats/warn/AxleTrackAlertListener.java +++ /dev/null @@ -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>> { - - 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> event) { - - List 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()); - } - } -} diff --git a/src/main/java/club/joylink/xiannccda/ats/warn/BlueAlertListener.java b/src/main/java/club/joylink/xiannccda/ats/warn/BlueAlertListener.java index de2c12d..ccce1d1 100644 --- a/src/main/java/club/joylink/xiannccda/ats/warn/BlueAlertListener.java +++ b/src/main/java/club/joylink/xiannccda/ats/warn/BlueAlertListener.java @@ -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>> { +public class BlueAlertListener implements AlertSourceEventListener { - 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> event) { - List 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 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 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()); } } } diff --git a/src/main/java/club/joylink/xiannccda/ats/warn/BlueDisplayAlertEvent.java b/src/main/java/club/joylink/xiannccda/ats/warn/BlueDisplayAlertEvent.java new file mode 100644 index 0000000..7449867 --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/ats/warn/BlueDisplayAlertEvent.java @@ -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 { + + public BlueDisplayAlertEvent(Builder source) { + super(source); + } +} diff --git a/src/main/java/club/joylink/xiannccda/ats/warn/SwitchAndTrackLedAlertEvent.java b/src/main/java/club/joylink/xiannccda/ats/warn/SwitchAndTrackLedAlertEvent.java new file mode 100644 index 0000000..6456e72 --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/ats/warn/SwitchAndTrackLedAlertEvent.java @@ -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 { + + public SwitchAndTrackLedAlertEvent(Builder source) { + super(source); + } +} diff --git a/src/main/java/club/joylink/xiannccda/ats/warn/SwitchLostAlertEvent.java b/src/main/java/club/joylink/xiannccda/ats/warn/SwitchLostAlertEvent.java new file mode 100644 index 0000000..c5fea2f --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/ats/warn/SwitchLostAlertEvent.java @@ -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 { + + public SwitchLostAlertEvent(Builder source) { + super(source); + } +} diff --git a/src/main/java/club/joylink/xiannccda/ats/warn/SwitchLostAlertListener.java b/src/main/java/club/joylink/xiannccda/ats/warn/SwitchLostAlertListener.java new file mode 100644 index 0000000..e0017a5 --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/ats/warn/SwitchLostAlertListener.java @@ -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 { + + @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()); + } + } +}