From a211d2e3c0217645d5f85052c41a02c9cb1bd133 Mon Sep 17 00:00:00 2001 From: tiger_zhou Date: Thu, 28 Dec 2023 10:42:20 +0800 Subject: [PATCH] =?UTF-8?q?=E9=81=93=E5=B2=94=E5=A4=B1=E8=A1=A8=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DeviceChangeStatusConvertor.java | 22 +---- .../convertor/DeviceInitConvertor.java | 20 +---- .../warn/axle/AxleLedMostMonitorListener.java | 14 ---- .../{ => lost}/SwitchLostAlertListener.java | 11 +-- .../SwitchLostAlertMonitoringTask2.java | 11 +-- .../SwitchLostMostAlertListener.java | 11 +-- .../ats/warn/lost/SwitchLostTask.java | 82 +++++++++++++++++++ 7 files changed, 105 insertions(+), 66 deletions(-) rename src/main/java/club/joylink/xiannccda/ats/warn/{ => lost}/SwitchLostAlertListener.java (81%) rename src/main/java/club/joylink/xiannccda/ats/warn/{ => lost}/SwitchLostAlertMonitoringTask2.java (95%) rename src/main/java/club/joylink/xiannccda/ats/warn/{ => lost}/SwitchLostMostAlertListener.java (94%) create mode 100644 src/main/java/club/joylink/xiannccda/ats/warn/lost/SwitchLostTask.java 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 11cb91d..ec3c8c1 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,12 +1,7 @@ package club.joylink.xiannccda.ats.message.collect.convertor; -import club.joylink.xiannccda.alert.core.AlertManager; import club.joylink.xiannccda.ats.message.MessageId; import club.joylink.xiannccda.ats.message.collect.DeviceDataRepository.DataTypeEnum; -import club.joylink.xiannccda.ats.warn.SwitchLostAlertListener.SwitchLostAlertEvent; -import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Switch; -import com.google.protobuf.GeneratedMessageV3.Builder; -import java.util.List; import lombok.extern.slf4j.Slf4j; @Slf4j @@ -22,25 +17,14 @@ public class DeviceChangeStatusConvertor extends DefaultConvertor { return DataTypeEnum.DEVICE; } - @Override + /*@Override protected void eventHandle(List builders) { AlertManager alertManager = AlertManager.getDefault(); 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)); -// alertManager.emit(new AxleLedAlertEvent(trackBuild)); -// } else if (builder instanceof Switch.Builder switchBuild) { alertManager.emit(new SwitchLostAlertEvent(switchBuild)); -// alertManager.emit(new SwitchAndTrackLedAlertEvent(switchBuild)); -// alertManager.emit(new AxleLedAlertEvent(switchBuild)); - } /*else if (builder instanceof Platform.Builder platformBuild) { - alertManager.emit(new PlatformAlertEvent(platformBuild)); - }*/ + } } - } + }*/ } diff --git a/src/main/java/club/joylink/xiannccda/ats/message/collect/convertor/DeviceInitConvertor.java b/src/main/java/club/joylink/xiannccda/ats/message/collect/convertor/DeviceInitConvertor.java index 986aabd..c0f8947 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/collect/convertor/DeviceInitConvertor.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/collect/convertor/DeviceInitConvertor.java @@ -1,12 +1,7 @@ package club.joylink.xiannccda.ats.message.collect.convertor; -import club.joylink.xiannccda.alert.core.AlertManager; import club.joylink.xiannccda.ats.message.MessageId; import club.joylink.xiannccda.ats.message.collect.DeviceDataRepository.DataTypeEnum; -import club.joylink.xiannccda.ats.warn.SwitchLostAlertListener.SwitchLostAlertEvent; -import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Switch; -import com.google.protobuf.GeneratedMessageV3.Builder; -import java.util.List; import lombok.extern.slf4j.Slf4j; @Slf4j @@ -22,22 +17,15 @@ public class DeviceInitConvertor extends DefaultConvertor { return DataTypeEnum.DEVICE; } - @Override + /*@Override protected void eventHandle(List builders) { AlertManager alertManager = AlertManager.getDefault(); 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)); -// alertManager.emit(new AxleLedAlertEvent(trackBuild)); -// } else + if (builder instanceof Switch.Builder switchBuild) { -// alertManager.emit(new SwitchAndTrackLedAlertEvent(switchBuild)); -// alertManager.emit(new AxleLedAlertEvent(switchBuild)); + alertManager.emit(new SwitchLostAlertEvent(switchBuild)); } } - } + }*/ } diff --git a/src/main/java/club/joylink/xiannccda/ats/warn/axle/AxleLedMostMonitorListener.java b/src/main/java/club/joylink/xiannccda/ats/warn/axle/AxleLedMostMonitorListener.java index fd3d35e..eed85cc 100644 --- a/src/main/java/club/joylink/xiannccda/ats/warn/axle/AxleLedMostMonitorListener.java +++ b/src/main/java/club/joylink/xiannccda/ats/warn/axle/AxleLedMostMonitorListener.java @@ -68,19 +68,6 @@ public class AxleLedMostMonitorListener implements AlertSourceEventListener warnDeviceList = alertDataSource.findAllWarnDeviceForList(lineIdInt, customName); - /*deviceStatusList.stream().filter(d -> d.saveAlertDataSouce).forEach(d -> { - String alertMsg = String.format("出现%s设备[%s]", ledName, d.deviceCode); - - if (Objects.nonNull(areaConfigVO) && warnDeviceList.size() >= ledThreshold) { - String warnDevices = String.join(",", warnDeviceList); - alertMsg = String.format("%s-出现大面积%s设备[%s]", areaConfigVO.getAreaName(), ledName, warnDevices); - } - String alertMsg = String.format("出现%s设备[%s]", ledName, d.deviceCode); - NccAlertInfo alertInfo = this.alertInfoService.createAlert2(null, lockSource.alertType, lineIdInt, LocalDateTime.now(), alertMsg, String.valueOf(d.layoutId), - AlertDeviceType.DEVICE_TYPE_TRACK, false); - alertManager.emit(alertInfo); - });*/ - if (Objects.nonNull(areaConfigVO) && deviceStatusList.stream().anyMatch(d -> d.saveAlertDataSouce) && warnDeviceList.size() >= ledThreshold) { //发布大面积 String warnDevices = String.join(",", warnDeviceList); @@ -89,7 +76,6 @@ public class AxleLedMostMonitorListener implements AlertSourceEventListener d.saveAlertDataSouce).forEach(d -> { - log.error("---------------" + d.deviceCode); String alertMsg = String.format("出现%s设备[%s]", ledName, d.deviceCode); NccAlertInfo alertInfo = this.alertInfoService.createAlert2(null, lockSource.alertType, lineIdInt, LocalDateTime.now(), alertMsg, String.valueOf(d.layoutId), AlertDeviceType.DEVICE_TYPE_TRACK, false); diff --git a/src/main/java/club/joylink/xiannccda/ats/warn/SwitchLostAlertListener.java b/src/main/java/club/joylink/xiannccda/ats/warn/lost/SwitchLostAlertListener.java similarity index 81% rename from src/main/java/club/joylink/xiannccda/ats/warn/SwitchLostAlertListener.java rename to src/main/java/club/joylink/xiannccda/ats/warn/lost/SwitchLostAlertListener.java index 055d144..50d3343 100644 --- a/src/main/java/club/joylink/xiannccda/ats/warn/SwitchLostAlertListener.java +++ b/src/main/java/club/joylink/xiannccda/ats/warn/lost/SwitchLostAlertListener.java @@ -1,14 +1,15 @@ -package club.joylink.xiannccda.ats.warn; +package club.joylink.xiannccda.ats.warn.lost; import club.joylink.xiannccda.alert.core.AlertSourceEventListener; -import club.joylink.xiannccda.ats.warn.SwitchLostAlertListener.SwitchLostAlertEvent; +import club.joylink.xiannccda.ats.warn.DeviceAlertEvent; +import club.joylink.xiannccda.ats.warn.lost.SwitchLostAlertListener.SwitchLostAlertEvent; import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Switch; import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Switch.Builder; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; -@Component +//@Component +@Deprecated public class SwitchLostAlertListener implements AlertSourceEventListener { @Autowired @@ -27,7 +28,7 @@ public class SwitchLostAlertListener implements AlertSourceEventListener { + public static class SwitchLostAlertEvent extends DeviceAlertEvent { public SwitchLostAlertEvent(Builder source) { super(source); diff --git a/src/main/java/club/joylink/xiannccda/ats/warn/SwitchLostAlertMonitoringTask2.java b/src/main/java/club/joylink/xiannccda/ats/warn/lost/SwitchLostAlertMonitoringTask2.java similarity index 95% rename from src/main/java/club/joylink/xiannccda/ats/warn/SwitchLostAlertMonitoringTask2.java rename to src/main/java/club/joylink/xiannccda/ats/warn/lost/SwitchLostAlertMonitoringTask2.java index 123bc80..18dde08 100644 --- a/src/main/java/club/joylink/xiannccda/ats/warn/SwitchLostAlertMonitoringTask2.java +++ b/src/main/java/club/joylink/xiannccda/ats/warn/lost/SwitchLostAlertMonitoringTask2.java @@ -1,4 +1,4 @@ -package club.joylink.xiannccda.ats.warn; +package club.joylink.xiannccda.ats.warn.lost; import club.joylink.xiannccda.alert.NccAlertInfo; import club.joylink.xiannccda.alert.core.AlertDataSource; @@ -9,7 +9,7 @@ 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.DeviceStatusData; -import club.joylink.xiannccda.ats.warn.SwitchLostMostAlertListener.SwitchLostMostEvent; +import club.joylink.xiannccda.ats.warn.lost.SwitchLostMostAlertListener.SwitchLostMostEvent; import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType; import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Switch; import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Switch.Builder; @@ -19,18 +19,15 @@ import club.joylink.xiannccda.service.AlertInfoService; import club.joylink.xiannccda.service.config.DeviceGuardConfigService; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.google.protobuf.GeneratedMessageV3; -import com.google.protobuf.MessageOrBuilder; -import java.util.Collections; import java.util.Map; import java.util.Map.Entry; import java.util.Objects; import java.util.Optional; -import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Component; -@Component +//@Component +@Deprecated @Slf4j public class SwitchLostAlertMonitoringTask2 implements AlertMonitoringTask { diff --git a/src/main/java/club/joylink/xiannccda/ats/warn/SwitchLostMostAlertListener.java b/src/main/java/club/joylink/xiannccda/ats/warn/lost/SwitchLostMostAlertListener.java similarity index 94% rename from src/main/java/club/joylink/xiannccda/ats/warn/SwitchLostMostAlertListener.java rename to src/main/java/club/joylink/xiannccda/ats/warn/lost/SwitchLostMostAlertListener.java index d4eae47..a7ace05 100644 --- a/src/main/java/club/joylink/xiannccda/ats/warn/SwitchLostMostAlertListener.java +++ b/src/main/java/club/joylink/xiannccda/ats/warn/lost/SwitchLostMostAlertListener.java @@ -1,4 +1,4 @@ -package club.joylink.xiannccda.ats.warn; +package club.joylink.xiannccda.ats.warn.lost; import club.joylink.xiannccda.alert.NccAlertInfo; import club.joylink.xiannccda.alert.core.AlertDataSource; @@ -6,7 +6,8 @@ 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.SwitchLostMostAlertListener.SwitchLostMostEvent; +import club.joylink.xiannccda.ats.warn.DeviceAlertEvent; +import club.joylink.xiannccda.ats.warn.lost.SwitchLostMostAlertListener.SwitchLostMostEvent; import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType; import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Switch; import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Switch.Builder; @@ -20,10 +21,10 @@ import java.util.List; import java.util.Optional; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; -import org.springframework.stereotype.Component; -@Component +//@Component +@Deprecated @Slf4j public class SwitchLostMostAlertListener implements AlertSourceEventListener { @@ -79,7 +80,7 @@ public class SwitchLostMostAlertListener implements AlertSourceEventListener { + public static class SwitchLostMostEvent extends DeviceAlertEvent { private boolean alert; diff --git a/src/main/java/club/joylink/xiannccda/ats/warn/lost/SwitchLostTask.java b/src/main/java/club/joylink/xiannccda/ats/warn/lost/SwitchLostTask.java new file mode 100644 index 0000000..046980c --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/ats/warn/lost/SwitchLostTask.java @@ -0,0 +1,82 @@ +package club.joylink.xiannccda.ats.warn.lost; + +import club.joylink.xiannccda.alert.NccAlertInfo; +import club.joylink.xiannccda.alert.core.AlertDataSource; +import club.joylink.xiannccda.alert.core.AlertDeviceType; +import club.joylink.xiannccda.alert.core.AlertManager; +import club.joylink.xiannccda.alert.core.AlertMonitoringTask; +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.DeviceStatusData; +import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType; +import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Switch; +import club.joylink.xiannccda.dto.protos.GuardConfigProto.GuardConfig; +import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Turnout; +import club.joylink.xiannccda.service.AlertInfoService; +import club.joylink.xiannccda.service.config.DeviceGuardConfigService; +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; +import com.google.protobuf.GeneratedMessageV3.Builder; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +@Component +@Slf4j +public class SwitchLostTask implements AlertMonitoringTask { + + private DeviceGuardConfigService configService; + private AlertInfoService alertInfoService; + + public SwitchLostTask(DeviceGuardConfigService configService, AlertInfoService alertInfoService) { + this.configService = configService; + this.alertInfoService = alertInfoService; + } + + private final AlertManager alertManager = AlertManager.getDefault(); + private final AlertDataSource alertDataSource = AlertDataSource.getInstance(); + + @Override + public String getName() { + return "SWITCH_LOST_ALTER"; + } + + @Override + public void run() { + Set lineCollSet = DeviceDataRepository.getAllLines(); + if (CollectionUtils.isEmpty(lineCollSet)) { + return; + } + for (String lineId : lineCollSet) { + DeviceStatusData deviceStatusData = DeviceDataRepository.findDataSouce(lineId, DataTypeEnum.DEVICE); + Map deviceBuildMap = deviceStatusData.getAllDeviceMap().get(Switch.getDescriptor().getName()); + for (Builder deviceBuild : deviceBuildMap.values()) { + this.handle(deviceBuild); + } + } + } + + private void handle(Builder deviceBuild) { + if (deviceBuild instanceof Switch.Builder switchBuild) { + GuardConfig guardConfig = this.configService.getGuardConfig(switchBuild.getLineId()); + boolean isLost = switchBuild.getIpSingleSwitchStusLostIndication(); + if (isLost && this.timeOver(switchBuild.getReceiveTime(), guardConfig.getSwitchLostTimes())) { + Optional turnoutOpt = LineGraphicDataRepository.getDeviceOptByCode(switchBuild.getLineId(), switchBuild.getId(), Turnout.class); + String layoutId = turnoutOpt.map(d -> String.valueOf(d.getCommon().getId())).orElse(""); + if (alertDataSource.putAlterDevice(switchBuild.getLineId(), this.getName(), switchBuild.getId())) { + log.info("道岔失表超时,准备报警 线路[{}] 设备[{}] 接受时间[{}] 发送时间[{}] 对应地图设备id[{}]" + , switchBuild.getLineId(), switchBuild.getId(), switchBuild.getReceiveTime(), switchBuild.getTimestamp(), layoutId); + String alertMsg = String.format("设备[%s]失表", switchBuild.getId()); + NccAlertInfo alertInfo = this.alertInfoService.createAlert2(Optional.empty(), AlertType.SWITCH_LOST, switchBuild, alertMsg, layoutId, + AlertDeviceType.DEVICE_TYPE_SWITCH, false); + alertManager.emit(alertInfo); + } + } else { + alertDataSource.removeAlterDevice(switchBuild.getLineId(), this.getName(), switchBuild.getId()); + } + } + } + +}