diff --git a/src/main/java/club/joylink/xiannccda/alert/AlertEmitJob.java b/src/main/java/club/joylink/xiannccda/alert/AlertEmitJob.java index 1c87e87..6218e5a 100644 --- a/src/main/java/club/joylink/xiannccda/alert/AlertEmitJob.java +++ b/src/main/java/club/joylink/xiannccda/alert/AlertEmitJob.java @@ -7,6 +7,7 @@ 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 club.joylink.xiannccda.ats.warn.SwitchLostAlertMonitoringTask; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; 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 3e1ff69..9d41aab 100644 --- a/src/main/java/club/joylink/xiannccda/alert/core/AlertManager.java +++ b/src/main/java/club/joylink/xiannccda/alert/core/AlertManager.java @@ -1,13 +1,13 @@ package club.joylink.xiannccda.alert.core; import club.joylink.xiannccda.event.EventEmitter; -import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.google.common.collect.HashBasedTable; +import com.google.common.collect.Lists; import com.google.common.collect.Table; import com.google.common.collect.Tables; -import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; @@ -30,7 +30,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()); /** * 报警监控任务(循环监测式报警) */ @@ -41,7 +41,7 @@ public class AlertManager extends EventEmitter { ScheduledExecutorService Executor = Executors.newScheduledThreadPool(1); boolean started = false; final int interval = 100; // 执行器默认间隔,单位ms - + private AlertManager(String id) { super(id); @@ -51,33 +51,25 @@ 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; + + public boolean putAlterDevice(String lineId, String customName, String deviceName) { + AlertTableDetail detail = DEVICE_ALTER_TABLE.get(lineId, customName); + if (Objects.isNull(detail)) { + detail = new AlertTableDetail(false); + DEVICE_ALTER_TABLE.put(lineId, customName, detail); } - return deviceNames.size(); + return detail.add(deviceName); } - public boolean putAlterDevice(String lineId, String deviceType, String deviceName) { - List deviceNames = DEVICE_ALTER_TABLE.get(lineId, deviceType); - if (CollectionUtils.isEmpty(deviceNames)) { - deviceNames = new ArrayList<>(); - DEVICE_ALTER_TABLE.put(lineId, deviceType, deviceNames); + public void removeAlterDevice(String lineId, String customName, String deviceName) { + AlertTableDetail detail = DEVICE_ALTER_TABLE.get(lineId, customName); + if (Objects.isNull(detail)) { + detail = new AlertTableDetail(false); + DEVICE_ALTER_TABLE.put(lineId, customName, detail); } - if (deviceNames.contains(deviceName)) { - return false; - } - deviceNames.add(deviceName); - return true; + detail.remove(deviceName); } - public void removeAlterDevice(String lineId, String deviceType, String deviceName) { - List deviceNames = DEVICE_ALTER_TABLE.get(lineId, deviceType); - if (CollectionUtils.isNotEmpty(deviceNames)) { - deviceNames.remove(deviceName); - } - } public static AlertManager getInstance(String id) { return MANAGER_MAP.computeIfAbsent(id, k -> new AlertManager(id)); @@ -115,4 +107,31 @@ public class AlertManager extends EventEmitter { 0, interval, TimeUnit.MILLISECONDS); } } + + public static class AlertTableDetail { + + public AlertTableDetail(boolean shower) { + this.mostShower = shower; + this.deviceCodes = Lists.newArrayList(); + } + + private boolean mostShower; + private List deviceCodes; + + public boolean add(String deviceCode) { + if (this.contains(deviceCode)) { + this.deviceCodes.add(deviceCode); + return true; + } + return false; + } + + public boolean contains(String deviceCode) { + return this.deviceCodes.contains(deviceCode); + } + + public void remove(String deviceCode) { + this.deviceCodes.remove(deviceCode); + } + } } diff --git a/src/main/java/club/joylink/xiannccda/ats/warn/PlatformAlertEvent.java b/src/main/java/club/joylink/xiannccda/ats/warn/PlatformAlertEvent.java new file mode 100644 index 0000000..1d9f44e --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/ats/warn/PlatformAlertEvent.java @@ -0,0 +1,12 @@ +package club.joylink.xiannccda.ats.warn; + +import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Platform; +import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Platform.Builder; +import com.google.protobuf.GeneratedMessageV3; + +public class PlatformAlertEvent extends DeviceAlertEvent { + + public PlatformAlertEvent(Builder source) { + super(source); + } +} diff --git a/src/main/java/club/joylink/xiannccda/ats/warn/PlatformAlertListener.java b/src/main/java/club/joylink/xiannccda/ats/warn/PlatformAlertListener.java new file mode 100644 index 0000000..13b383f --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/ats/warn/PlatformAlertListener.java @@ -0,0 +1,43 @@ +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.DeviceStatusDataOperate; +import club.joylink.xiannccda.ats.message.collect.datasource.TrainDataSource; +import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType; +import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Platform; +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 com.google.protobuf.GeneratedMessageV3.Builder; +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.util.Objects; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; + + +@Component +public class PlatformAlertListener implements AlertSourceEventListener { + + private AlertDetailFactory alertDetailFactory; + + public PlatformAlertListener(AlertDetailFactory alertDetailFactory) { + this.alertDetailFactory = alertDetailFactory; + } + + + @Override + public void accept(PlatformAlertEvent event) { + Platform.Builder platformBuild = event.getSource(); + + + } +} diff --git a/src/main/java/club/joylink/xiannccda/ats/warn/SwitchLostAlertListener.java b/src/main/java/club/joylink/xiannccda/ats/warn/SwitchLostAlertListener.java index 34f1b75..14d797e 100644 --- a/src/main/java/club/joylink/xiannccda/ats/warn/SwitchLostAlertListener.java +++ b/src/main/java/club/joylink/xiannccda/ats/warn/SwitchLostAlertListener.java @@ -1,18 +1,8 @@ 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; @@ -29,8 +19,8 @@ public class SwitchLostAlertListener implements AlertSourceEventListener configMaper = configService.getGuardConfig(savedSwitchBuild.getLineId(), DeviceType.DEVICE_TYPE_SWITCH); + DeviceGuardConfig guardConfig = configMaper.get(ConfigDeviceType.SWITCH_LOST); + + boolean saveIsLost = savedSwitchBuild.getIpSingleSwitchStusLostIndication(); + if (saveIsLost && guardConfig.getDeviceOperator().contrast(guardConfig.getDeviceUnit(), savedSwitchBuild.getReceiveTime(), guardConfig.getVal())) { //失表超时 String lineIdStr = String.valueOf(savedSwitchBuild.getLineId()); if (alertManager.putAlterDevice(lineIdStr, DEVICE_TYPE_NAME, savedSwitchBuild.getId())) { diff --git a/src/main/java/club/joylink/xiannccda/dto/config/DeviceGuardConfigDto.java b/src/main/java/club/joylink/xiannccda/dto/config/DeviceGuardConfigDto.java index 2db2257..b4e8696 100644 --- a/src/main/java/club/joylink/xiannccda/dto/config/DeviceGuardConfigDto.java +++ b/src/main/java/club/joylink/xiannccda/dto/config/DeviceGuardConfigDto.java @@ -32,6 +32,6 @@ public class DeviceGuardConfigDto { } public enum ConfigDeviceType { - SWITCH_LOST, SWITCH_LOST_MOST, AXLE_LED_RED_MOST + SWITCH_LOST, SWITCH_LOST_MOST, AXLE_LED_RED, AXLE_LED_RED_MOST, AXLE_LED_ORANGE, AXLE_LED_ORANGE_MOST } } diff --git a/src/main/java/club/joylink/xiannccda/service/config/DeviceGuardConfigService.java b/src/main/java/club/joylink/xiannccda/service/config/DeviceGuardConfigService.java index e71aaab..86f5939 100644 --- a/src/main/java/club/joylink/xiannccda/service/config/DeviceGuardConfigService.java +++ b/src/main/java/club/joylink/xiannccda/service/config/DeviceGuardConfigService.java @@ -77,6 +77,7 @@ public class DeviceGuardConfigService { public Page page(DeviceGuardConfigQueryDto queryDTO) { LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(DeviceGuardConfig.class); + queryWrapper.eq(DeviceGuardConfig::getConfigType, DeviceGuardConfig.CONFIG_TYPE_USER); if (Objects.nonNull(queryDTO.getLineId())) { queryWrapper.eq(DeviceGuardConfig::getLineId, queryDTO.getLineId()); diff --git a/src/main/java/club/joylink/xiannccda/service/config/Operator.java b/src/main/java/club/joylink/xiannccda/service/config/Operator.java index 851c240..542096f 100644 --- a/src/main/java/club/joylink/xiannccda/service/config/Operator.java +++ b/src/main/java/club/joylink/xiannccda/service/config/Operator.java @@ -6,7 +6,7 @@ public enum Operator { GT { @Override - public boolean contrastTimes(GuardUnit unit, int source, int val) { + public boolean contrast(GuardUnit unit, Long source, int val) { if (unit == GuardUnit.NUMS) { return source > val; } else if (unit == GuardUnit.TIMES) { @@ -17,7 +17,7 @@ public enum Operator { }, GE { @Override - public boolean contrastTimes(GuardUnit unit, int source, int val) { + public boolean contrast(GuardUnit unit, Long source, int val) { if (unit == GuardUnit.NUMS) { return source >= val; } else if (unit == GuardUnit.TIMES) { @@ -28,7 +28,7 @@ public enum Operator { }, LT { @Override - public boolean contrastTimes(GuardUnit unit, int source, int val) { + public boolean contrast(GuardUnit unit, Long source, int val) { if (unit == GuardUnit.NUMS) { return source < val; } else if (unit == GuardUnit.TIMES) { @@ -39,6 +39,6 @@ public enum Operator { }, ; - public abstract boolean contrastTimes(GuardUnit unit, int source, int val); + public abstract boolean contrast(GuardUnit unit, Long source, int val); } diff --git a/src/test/java/club/joylink/xiannccda/config/DataConfigTest.java b/src/test/java/club/joylink/xiannccda/config/DataConfigTest.java index fc24bb4..fc869f0 100644 --- a/src/test/java/club/joylink/xiannccda/config/DataConfigTest.java +++ b/src/test/java/club/joylink/xiannccda/config/DataConfigTest.java @@ -23,14 +23,8 @@ public class DataConfigTest { @Test public void test() { - InitData initData = new InitData(); - initData.setDeviceType(DeviceType.DEVICE_TYPE_TRACK); - List refs = Lists.newArrayList(); - refs.add(new DeviceRef(ConfigDeviceType.SWITCH_LOST, new Oper(Operator.LT, GuardUnit.TIMES))); - refs.add(new DeviceRef(ConfigDeviceType.SWITCH_LOST_MOST, new Oper(Operator.GE, GuardUnit.NUMS))); - initData.setRefs(refs); - System.out.println(JSON.toJSONString(initData, Feature.WriteEnumsUsingName)); + //道岔失表 DeviceGuardConfig guardConfig = new DeviceGuardConfig(); guardConfig.setLineId(3); guardConfig.setDeviceType(DeviceType.DEVICE_TYPE_SWITCH); @@ -39,6 +33,7 @@ public class DataConfigTest { guardConfig.setDeviceConfigType(ConfigDeviceType.SWITCH_LOST); guardConfig.setConfigType(DeviceGuardConfig.CONFIG_TYPE_INIT); + //大面积道岔失表 DeviceGuardConfig guardConfig2 = new DeviceGuardConfig(); guardConfig2.setLineId(3); guardConfig2.setDeviceType(DeviceType.DEVICE_TYPE_SWITCH); @@ -47,49 +42,47 @@ public class DataConfigTest { guardConfig2.setDeviceConfigType(ConfigDeviceType.SWITCH_LOST_MOST); guardConfig2.setConfigType(DeviceGuardConfig.CONFIG_TYPE_INIT); + //红灯带 DeviceGuardConfig guardConfig3 = new DeviceGuardConfig(); guardConfig3.setLineId(3); guardConfig3.setDeviceType(DeviceType.DEVICE_TYPE_TRACK); guardConfig3.setDeviceOperator(Operator.GE); guardConfig3.setDeviceUnit(GuardUnit.NUMS); - guardConfig3.setDeviceConfigType(ConfigDeviceType.AXLE_LED_RED_MOST); + guardConfig3.setDeviceConfigType(ConfigDeviceType.AXLE_LED_RED); guardConfig3.setConfigType(DeviceGuardConfig.CONFIG_TYPE_INIT); + //大面积红灯带 + DeviceGuardConfig guardConfig4 = new DeviceGuardConfig(); + guardConfig4.setLineId(3); + guardConfig4.setDeviceType(DeviceType.DEVICE_TYPE_TRACK); + guardConfig4.setDeviceOperator(Operator.GE); + guardConfig4.setDeviceUnit(GuardUnit.NUMS); + guardConfig4.setDeviceConfigType(ConfigDeviceType.AXLE_LED_RED_MOST); + guardConfig4.setConfigType(DeviceGuardConfig.CONFIG_TYPE_INIT); + + DeviceGuardConfig guardConfig5 = new DeviceGuardConfig(); + guardConfig5.setLineId(3); + guardConfig5.setDeviceType(DeviceType.DEVICE_TYPE_TRACK); + guardConfig5.setDeviceOperator(Operator.GE); + guardConfig5.setDeviceUnit(GuardUnit.NUMS); + guardConfig5.setDeviceConfigType(ConfigDeviceType.AXLE_LED_ORANGE); + guardConfig5.setConfigType(DeviceGuardConfig.CONFIG_TYPE_INIT); + //大面积红灯带 + DeviceGuardConfig guardConfig6 = new DeviceGuardConfig(); + guardConfig6.setLineId(3); + guardConfig6.setDeviceType(DeviceType.DEVICE_TYPE_TRACK); + guardConfig6.setDeviceOperator(Operator.GE); + guardConfig6.setDeviceUnit(GuardUnit.NUMS); + guardConfig6.setDeviceConfigType(ConfigDeviceType.AXLE_LED_ORANGE_MOST); + guardConfig6.setConfigType(DeviceGuardConfig.CONFIG_TYPE_INIT); + this.iDeviceGuardConfigRepository.save(guardConfig); this.iDeviceGuardConfigRepository.save(guardConfig2); this.iDeviceGuardConfigRepository.save(guardConfig3); + this.iDeviceGuardConfigRepository.save(guardConfig4); + this.iDeviceGuardConfigRepository.save(guardConfig5); + this.iDeviceGuardConfigRepository.save(guardConfig6); + } - - @Data - public static class InitData { - - private DeviceType deviceType; - private List refs; - } - - @Data - private static class DeviceRef { - - public DeviceRef(ConfigDeviceType deviceConfig, Oper opers) { - this.deviceConfig = deviceConfig; - this.opers = opers; - } - - private ConfigDeviceType deviceConfig; - - private Oper opers; - } - - @Data - private static class Oper { - - public Oper(Operator operator, GuardUnit unit) { - this.operator = operator; - this.unit = unit; - } - - private Operator operator; - private GuardUnit unit; - } }