diff --git a/src/main/java/club/joylink/xiannccda/alert/NccAlertInfo.java b/src/main/java/club/joylink/xiannccda/alert/NccAlertInfo.java
index e45507e..a1abc04 100644
--- a/src/main/java/club/joylink/xiannccda/alert/NccAlertInfo.java
+++ b/src/main/java/club/joylink/xiannccda/alert/NccAlertInfo.java
@@ -104,7 +104,7 @@ public class NccAlertInfo implements AlertInfo {
}
case BLUE_DISPLAY, PLATFORM_DOOR_CANNOT_CLOSE, PLATFORM_DOOR_CANNOT_OPEN,
PLATFORM_DOOR_WITHOUT_LOCKED_SIGNAL, TRAIN_DELAY_10, SWITCH_LOST,
- SWITCH_LOST_MOST, AXLE_LED_RED, AXLE_LED_ORANGE, AXLE_LED_ORANGE_MOST, AXLE_LED_RED_MOST, TRAIN_EB_ATP -> {
+ SWITCH_LOST_MOST, AXLE_LED_RED, AXLE_LED_ORANGE, AXLE_LED_ORANGE_MOST, AXLE_LED_RED_MOST, TRAIN_EB_ATP, ALL_LINE_BLUE_DISPLAY -> {
return "I";
}
default -> throw new IllegalStateException("Unexpected value: " + alertType);
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 18f7451..b15b685 100644
--- a/src/main/java/club/joylink/xiannccda/alert/core/AlertManager.java
+++ b/src/main/java/club/joylink/xiannccda/alert/core/AlertManager.java
@@ -34,7 +34,7 @@ public class AlertManager extends EventEmitter {
*
* val = 设备code
*/
- private static final Table DEVICE_ALTER_TABLE = Tables.synchronizedTable(HashBasedTable.create());
+ private static final Table DEVICE_ALTER_TABLE = Tables.synchronizedTable(HashBasedTable.create());
/**
* 报警监控任务(循环监测式报警)
*/
@@ -56,7 +56,7 @@ public class AlertManager extends EventEmitter {
}
- public boolean putAlterDevice(String lineId, String customName, String deviceName) {
+ public boolean putAlterDevice(Integer lineId, String customName, String deviceName) {
AlertTableDetail detail = DEVICE_ALTER_TABLE.get(lineId, customName);
if (Objects.isNull(detail)) {
detail = new AlertTableDetail(false);
@@ -65,7 +65,7 @@ public class AlertManager extends EventEmitter {
return detail.add(deviceName);
}
- public void removeAlterDevice(String lineId, String customName, String deviceName) {
+ public void removeAlterDevice(Integer lineId, String customName, String deviceName) {
AlertTableDetail detail = DEVICE_ALTER_TABLE.get(lineId, customName);
if (Objects.isNull(detail)) {
detail = new AlertTableDetail(false);
@@ -74,7 +74,7 @@ public class AlertManager extends EventEmitter {
detail.remove(deviceName);
}
- public boolean needMostShow(String lineId, String customName, int val) {
+ public boolean needMostShow(Integer lineId, String customName, int val) {
if (StringUtils.isEmpty(customName)) {
return false;
}
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 82c1f3e..684fb79 100644
--- a/src/main/java/club/joylink/xiannccda/ats/warn/AxleSwitchTrackLedAlertListener.java
+++ b/src/main/java/club/joylink/xiannccda/ats/warn/AxleSwitchTrackLedAlertListener.java
@@ -105,18 +105,18 @@ public class AxleSwitchTrackLedAlertListener implements AlertSourceEventListener
String ledMostName = alertInfoMostOptional.map(DeviceAreaConfig::getAreaName).orElse(null);
if (light) {
- if (alertManager.putAlterDevice(lineId.toString(), ledName, id)) {
+ if (alertManager.putAlterDevice(lineId, ledName, id)) {
NccAlertInfo alertInfo = this.alertInfoService.createAlert2(alertInfoOptional, alertType, build, section.getCode());
alertManager.emit(alertInfo);
}
- if (Objects.nonNull(ledMostName) && alertManager.needMostShow(lineId.toString(), ledMostName, overNums)) {
+ if (Objects.nonNull(ledMostName) && alertManager.needMostShow(lineId, ledMostName, overNums)) {
NccAlertInfo alertInfoMost = this.alertInfoService.createAlert2(alertInfoOptional, alertType, build, section.getCode());
alertManager.emit(alertInfoMost);
}
} else {
- alertManager.removeAlterDevice(lineId.toString(), ledName, id);
+ alertManager.removeAlterDevice(lineId, ledName, id);
if (StringUtils.isNotEmpty(ledMostName)) {
- alertManager.removeAlterDevice(lineId.toString(), ledMostName, id);
+ alertManager.removeAlterDevice(lineId, ledMostName, id);
}
}
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 c11e8e3..bfc2281 100644
--- a/src/main/java/club/joylink/xiannccda/ats/warn/BlueAlertListener.java
+++ b/src/main/java/club/joylink/xiannccda/ats/warn/BlueAlertListener.java
@@ -1,58 +1,85 @@
package club.joylink.xiannccda.ats.warn;
-import club.joylink.xiannccda.alert.AlertDetailFactory;
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.alert.util.AlertUtil;
import club.joylink.xiannccda.ats.cache.LineGraphicDataRepository;
import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType;
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Rtu;
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 com.google.protobuf.MessageOrBuilder;
-import java.time.Instant;
-import java.time.LocalDateTime;
-import java.time.ZoneId;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.concurrent.ConcurrentHashMap;
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 BlueAlertListener implements AlertSourceEventListener {
+
@Autowired
- private AlertDetailFactory alertDetailFactory;
+ private AlertInfoService alertInfoService;
+ private final static String BLUE_DISPLAY_NAME = Rtu.getDescriptor().getName();
+ private final static String ALL_BLUE_DISPLAY_VAL = "全线蓝显";
+ private final static AlertManager alertManager = AlertManager.getDefault();
+ private final static Map> CONTROL_STATION_MAPER = new ConcurrentHashMap<>();
- private final static String DEVICE_TYPE_NAME = Rtu.getDescriptor().getName();
-
- private NccAlertInfo createAlterTip(Rtu.Builder rtuBuild, String lineId, MessageOrBuilder mb) {
-
- LocalDateTime createTime = LocalDateTime.ofInstant(Instant.ofEpochSecond(rtuBuild.getTimestamp()), ZoneId.of("+8"));
-
- NccAlertInfo alertInfo = this.alertDetailFactory.getAlertDetail(createTime, AlertType.BLUE_DISPLAY, Integer.valueOf(lineId), false, mb);
-// alertInfo.setAlertLocation(AlertUtil.findLocationByRtuCode(rtuBuild.getId()).orElse(null));
- return alertInfo;
- }
@Override
public void accept(BlueDisplayAlertEvent event) {
Rtu.Builder rtu = event.getSource();
- AlertManager alertManager = AlertManager.getDefault();
- String lineId = String.valueOf(rtu.getLineId());
+ Station station = findAllStation(rtu.getLineId(), rtu.getId());
+ if (Objects.isNull(station)) {
+ //TODO logs
+ return;
+ }
+
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(rtu.getLineId(), Station.class);
- Station station = stream.filter(Station::getConcentrationStations).filter(d -> StringUtils.equals(d.getCode(), rtuName)).findFirst().get();
- NccAlertInfo alertInfo = this.createAlterTip(rtu, lineId, station);
+ if (alertManager.putAlterDevice(rtu.getLineId(), BLUE_DISPLAY_NAME, rtu.getId())) {
+ Optional alertInfoOpt = this.alertInfoService.findAreaDevice(AlertType.BLUE_DISPLAY, AlertDeviceType.DEVICE_TYPE_RTU, station.getCommon().getId(),
+ rtu.getLineId());
+ NccAlertInfo alertInfo = this.alertInfoService.createAlert2(alertInfoOpt, AlertType.BLUE_DISPLAY, rtu, station.getName());
+ alertManager.emit(alertInfo);
+
+ }
+ int allControlStationSize = CONTROL_STATION_MAPER.get(rtu.getLineId()).size();
+ if (alertManager.needMostShow(rtu.getLineId(), BLUE_DISPLAY_NAME, 1)
+ && 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);
alertManager.emit(alertInfo);
}
} else {
- alertManager.removeAlterDevice(lineId, DEVICE_TYPE_NAME, rtu.getId());
+ alertManager.removeAlterDevice(rtu.getLineId(), BLUE_DISPLAY_NAME, rtu.getId());
+ alertManager.removeAlterDevice(rtu.getLineId(), BLUE_DISPLAY_NAME, ALL_BLUE_DISPLAY_VAL);
}
}
+
+ private static synchronized Station findAllStation(int lineId, String rtuId) {
+ if (CollectionUtils.isEmpty(CONTROL_STATION_MAPER)) {
+ Stream stream = LineGraphicDataRepository.getDevices(lineId, Station.class);
+ List stationList = stream.filter(Station::getConcentrationStations).toList();
+ CONTROL_STATION_MAPER.put(lineId, stationList);
+ }
+ List stationList = CONTROL_STATION_MAPER.get(lineId);
+ if (CollectionUtils.isEmpty(stationList)) {
+ return null;
+ }
+ String rtuName = Strings.padStart(rtuId, 2, '0');
+ Optional optionalStation = stationList.stream().filter(d -> StringUtils.equalsIgnoreCase(d.getCode(), rtuName)).findAny();
+ return optionalStation.orElse(null);
+ }
}
diff --git a/src/main/java/club/joylink/xiannccda/ats/warn/PlatformAlertMonitoringTask.java b/src/main/java/club/joylink/xiannccda/ats/warn/PlatformAlertMonitoringTask.java
index 064a543..d8d9992 100644
--- a/src/main/java/club/joylink/xiannccda/ats/warn/PlatformAlertMonitoringTask.java
+++ b/src/main/java/club/joylink/xiannccda/ats/warn/PlatformAlertMonitoringTask.java
@@ -54,7 +54,7 @@ public class PlatformAlertMonitoringTask implements AlertMonitoringTask {
public void removeSwitch(Platform.Builder platformBuild) {
platformMap.remove(platformBuild.getId());
- alertManager.removeAlterDevice(String.valueOf(platformBuild.getLineId()), CUSTOM_NAME, platformBuild.getId());
+ alertManager.removeAlterDevice(platformBuild.getLineId(), CUSTOM_NAME, platformBuild.getId());
}
@Override
@@ -66,17 +66,16 @@ public class PlatformAlertMonitoringTask implements AlertMonitoringTask {
@Override
public void run() {
for (Platform.Builder build : platformMap.values()) {
- String lineId = String.valueOf(build.getLineId());
GuardConfig guardConfig = configService.getGuardConfig(build.getLineId());
AlertType alertType = AlertType.PLATFORM_DOOR_CANNOT_OPEN;
int timeOut = guardConfig.getCanNotOpenTimes();
if (build.getPsdOpen()) {
alertType = AlertType.PLATFORM_DOOR_CANNOT_CLOSE;
timeOut = guardConfig.getCanNotCloseTimes();
- alertManager.removeAlterDevice(String.valueOf(build.getLineId()), CUSTOM_NAME, build.getId());
+ alertManager.removeAlterDevice(build.getLineId(), CUSTOM_NAME, build.getId());
}
if (this.timeOver(build.getReceiveTime(), timeOut)
- && alertManager.putAlterDevice(lineId, CUSTOM_NAME, build.getId())) {
+ && alertManager.putAlterDevice(build.getLineId(), CUSTOM_NAME, build.getId())) {
LayoutGraphicsProto.Platform platform = LineGraphicDataRepository.getDeviceByCode(build.getLineId(), build.getId(), LayoutGraphicsProto.Platform.class);
NccAlertInfo alertInfo = this.alertInfoService.createAlert(alertType, AlertDeviceType.DEVICE_TYPE_PLATFORM, platform.getCommon().getId(), build, platform.getCode());
alertManager.emit(alertInfo);
diff --git a/src/main/java/club/joylink/xiannccda/ats/warn/SwitchLostAlertMonitoringTask.java b/src/main/java/club/joylink/xiannccda/ats/warn/SwitchLostAlertMonitoringTask.java
index 25227a1..45af7b0 100644
--- a/src/main/java/club/joylink/xiannccda/ats/warn/SwitchLostAlertMonitoringTask.java
+++ b/src/main/java/club/joylink/xiannccda/ats/warn/SwitchLostAlertMonitoringTask.java
@@ -59,7 +59,7 @@ public class SwitchLostAlertMonitoringTask implements AlertMonitoringTask {
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());
+ alertManager.removeAlterDevice(switchBuilder.getLineId(), DEVICE_TYPE_NAME, switchBuilder.getId());
}
@Override
@@ -71,7 +71,7 @@ public class SwitchLostAlertMonitoringTask implements AlertMonitoringTask {
@Override
public void run() {
for (Builder savedSwitchBuild : this.deviceMap.values()) {
- String lineIdStr = String.valueOf(savedSwitchBuild.getLineId());
+// String lineIdStr = String.valueOf(savedSwitchBuild.getLineId());
GuardConfig guardConfig = configService.getGuardConfig(savedSwitchBuild.getLineId());
Turnout turnout = LineGraphicDataRepository.getDeviceByCode(savedSwitchBuild.getLineId(), savedSwitchBuild.getId(), Turnout.class);
@@ -83,7 +83,7 @@ public class SwitchLostAlertMonitoringTask implements AlertMonitoringTask {
boolean saveIsLost = savedSwitchBuild.getIpSingleSwitchStusLostIndication();
if (saveIsLost && this.timeOver(savedSwitchBuild.getReceiveTime(), guardConfig.getSwitchLostTimes())) {
//失表超时
- if (alertManager.putAlterDevice(lineIdStr, oneName, savedSwitchBuild.getId())) {
+ if (alertManager.putAlterDevice(savedSwitchBuild.getLineId(), oneName, savedSwitchBuild.getId())) {
NccAlertInfo alertInfo = this.alertInfoService.createAlert2(alertInfoOpt, AlertType.SWITCH_LOST, savedSwitchBuild, savedSwitchBuild.getId());
alertManager.emit(alertInfo);
this.deviceMap.remove(savedSwitchBuild.getId());
@@ -91,7 +91,7 @@ public class SwitchLostAlertMonitoringTask implements AlertMonitoringTask {
Optional alertInfoMostOpt = this.alertInfoService.findAreaDevice(AlertType.SWITCH_LOST_MOST, AlertDeviceType.DEVICE_TYPE_SWITCH, turnout.getCommon().getId(),
savedSwitchBuild.getLineId());
//检测大面积失表
- if (alertInfoMostOpt.isPresent() && alertManager.needMostShow(lineIdStr, alertInfoMostOpt.get().getAreaName(), guardConfig.getSwitchLostMostNums())) {
+ if (alertInfoMostOpt.isPresent() && alertManager.needMostShow(savedSwitchBuild.getLineId(), alertInfoMostOpt.get().getAreaName(), guardConfig.getSwitchLostMostNums())) {
NccAlertInfo alertInfo = this.alertInfoService.createAlert2(alertInfoMostOpt, AlertType.SWITCH_LOST_MOST, savedSwitchBuild, savedSwitchBuild.getId());
alertManager.emit(alertInfo);
diff --git a/src/main/java/club/joylink/xiannccda/ats/warn/TrainModeAlertListener.java b/src/main/java/club/joylink/xiannccda/ats/warn/TrainModeAlertListener.java
index c09bcf6..0541e73 100644
--- a/src/main/java/club/joylink/xiannccda/ats/warn/TrainModeAlertListener.java
+++ b/src/main/java/club/joylink/xiannccda/ats/warn/TrainModeAlertListener.java
@@ -31,7 +31,6 @@ public class TrainModeAlertListener implements AlertSourceEventListener