From 2aadd4dab59803fc8fb9e09f83c4b9acad2d4c38 Mon Sep 17 00:00:00 2001 From: tiger_zhou Date: Thu, 28 Dec 2023 13:44:47 +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 | 10 -- .../convertor/DeviceInitConvertor.java | 11 -- .../warn/lost/SwitchLostAlertListener.java | 38 ----- .../lost/SwitchLostAlertMonitoringTask2.java | 145 ------------------ .../lost/SwitchLostMostAlertListener.java | 95 ------------ 5 files changed, 299 deletions(-) delete mode 100644 src/main/java/club/joylink/xiannccda/ats/warn/lost/SwitchLostAlertListener.java delete mode 100644 src/main/java/club/joylink/xiannccda/ats/warn/lost/SwitchLostAlertMonitoringTask2.java delete mode 100644 src/main/java/club/joylink/xiannccda/ats/warn/lost/SwitchLostMostAlertListener.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 ec3c8c1..193ab0e 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 @@ -17,14 +17,4 @@ public class DeviceChangeStatusConvertor extends DefaultConvertor { return DataTypeEnum.DEVICE; } - /*@Override - protected void eventHandle(List builders) { - AlertManager alertManager = AlertManager.getDefault(); - for (Builder builder : builders) { - - if (builder instanceof Switch.Builder switchBuild) { - alertManager.emit(new SwitchLostAlertEvent(switchBuild)); - } - } - }*/ } 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 c0f8947..6be008e 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 @@ -17,15 +17,4 @@ public class DeviceInitConvertor extends DefaultConvertor { return DataTypeEnum.DEVICE; } - /*@Override - protected void eventHandle(List builders) { - AlertManager alertManager = AlertManager.getDefault(); - for (Builder builder : builders) { - - if (builder instanceof Switch.Builder switchBuild) { - - alertManager.emit(new SwitchLostAlertEvent(switchBuild)); - } - } - }*/ } diff --git a/src/main/java/club/joylink/xiannccda/ats/warn/lost/SwitchLostAlertListener.java b/src/main/java/club/joylink/xiannccda/ats/warn/lost/SwitchLostAlertListener.java deleted file mode 100644 index 50d3343..0000000 --- a/src/main/java/club/joylink/xiannccda/ats/warn/lost/SwitchLostAlertListener.java +++ /dev/null @@ -1,38 +0,0 @@ -package club.joylink.xiannccda.ats.warn.lost; - -import club.joylink.xiannccda.alert.core.AlertSourceEventListener; -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; - - -//@Component -@Deprecated -public class SwitchLostAlertListener implements AlertSourceEventListener { - - @Autowired -// private SwitchLostAlertMonitoringTask monitoringTask2; - private SwitchLostAlertMonitoringTask2 monitoringTask2; - - - @Override - public void accept(SwitchLostAlertEvent event) { - Switch.Builder switchBuild = event.getSource(); - boolean isLost = switchBuild.getIpSingleSwitchStusLostIndication(); - if (isLost) { - this.monitoringTask2.putSwitchIfNotExist(switchBuild); - } else { - this.monitoringTask2.removeSwitch(switchBuild); - } - } - - public static class SwitchLostAlertEvent extends DeviceAlertEvent { - - public SwitchLostAlertEvent(Builder source) { - super(source); - } - } - -} diff --git a/src/main/java/club/joylink/xiannccda/ats/warn/lost/SwitchLostAlertMonitoringTask2.java b/src/main/java/club/joylink/xiannccda/ats/warn/lost/SwitchLostAlertMonitoringTask2.java deleted file mode 100644 index 18dde08..0000000 --- a/src/main/java/club/joylink/xiannccda/ats/warn/lost/SwitchLostAlertMonitoringTask2.java +++ /dev/null @@ -1,145 +0,0 @@ -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.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; -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; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Objects; -import java.util.Optional; -import java.util.concurrent.ConcurrentHashMap; -import lombok.extern.slf4j.Slf4j; - -//@Component -@Deprecated -@Slf4j -public class SwitchLostAlertMonitoringTask2 implements AlertMonitoringTask { - - private DeviceGuardConfigService configService; - - private AlertInfoService alertInfoService; - - public SwitchLostAlertMonitoringTask2(DeviceGuardConfigService configService, AlertInfoService alertInfoService) { - - this.configService = configService; - this.alertInfoService = alertInfoService; - } - - - private final AlertManager alertManager = AlertManager.getDefault(); - private final AlertDataSource alertDataSource = AlertDataSource.getInstance(); - - private final Map deviceCodeMap = new ConcurrentHashMap<>(); - - public void putSwitchIfNotExist(Builder switchBuilder) { - if (!this.deviceCodeMap.containsKey(switchBuilder.getId())) { - log.info("线路[{}] 道岔[{}] 添加到道岔失表监控中... 设备状态参数[{}]", switchBuilder.getLineId(), switchBuilder.getId(), switchBuilder.getIpSingleSwitchStusLostIndication()); - deviceCodeMap.put(switchBuilder.getId(), switchBuilder.getLineId()); - } - } - - public void removeSwitch(Builder switchBuilder) { - String switchPutName = this.getDefaultName(AlertType.SWITCH_LOST, switchBuilder.getLineId(), switchBuilder.getRtuId()); - log.info("线路[{}] 道岔[{}] 从监控中移除... 设备状态参数[{}]", switchBuilder.getLineId(), switchBuilder.getId(), switchBuilder); - deviceCodeMap.remove(switchBuilder.getId()); - alertDataSource.removeAlterDevice(switchBuilder.getLineId(), switchPutName, switchBuilder.getId()); - - Optional turnoutOpt = LineGraphicDataRepository.getDeviceOptByCode(switchBuilder.getLineId(), switchBuilder.getId(), Turnout.class); - Turnout turnout = turnoutOpt.orElse(null); - if (Objects.nonNull(turnout)) { - log.info("道岔失表未找到地图对应的设备 线路[{}],道岔code[{}]", switchBuilder.getLineId(), switchBuilder.getId()); - - //大面积失表移除 - alertManager.emit(new SwitchLostMostEvent(switchBuilder, false, turnout)); - } - - } - - @Override - public String getName() { - return "SWITCH_LOST_ALTER"; - } - - private String getDefaultName(AlertType alertType, Integer lineId, Integer rtuId) { - return String.format("%s-%s-%s", alertType.name(), lineId, rtuId); - } - - - private Switch.Builder findSwitchDevice(String deviceCode, Integer lineId) { - DeviceStatusData deviceDataSource = DeviceDataRepository.findDataSouce(lineId.toString(), DataTypeEnum.DEVICE); - Map switchBuildMap = deviceDataSource.getAllDeviceMap().get(Switch.getDescriptor().getName()); - if (CollectionUtils.isEmpty(switchBuildMap)) { - return null; - } - GeneratedMessageV3.Builder msgBuild = switchBuildMap.get(deviceCode); - if (msgBuild instanceof Switch.Builder switchs) { - return switchs; - } else { - return null; - } - } - - private void checkDevice(Switch.Builder switchBuild, Turnout turnout, Integer lineId, GuardConfig guardConfig) { - - boolean saveIsLost = switchBuild.getIpSingleSwitchStusLostIndication(); - boolean timeOver = this.timeOver(switchBuild.getReceiveTime(), guardConfig.getSwitchLostTimes()); - String switchPutName = this.getDefaultName(AlertType.SWITCH_LOST, lineId, switchBuild.getRtuId()); - if (saveIsLost && timeOver) { - //失表超时 - if (alertDataSource.putAlterDevice(lineId, switchPutName, switchBuild.getId())) { - log.info("道岔失表超时,准备报警 线路[{}] 设备[{}] 接受时间[{}] 发送时间[{}] 对应地图设备id[{}]" - , lineId, switchBuild.getId(), switchBuild.getReceiveTime(), switchBuild.getTimestamp(), turnout.getCommon().getId()); - String alertMsg = String.format("设备[%s]失表", switchBuild.getId()); - NccAlertInfo alertInfo = this.alertInfoService.createAlert2(Optional.empty(), AlertType.SWITCH_LOST, switchBuild, alertMsg, String.valueOf(turnout.getCommon().getId()), - AlertDeviceType.DEVICE_TYPE_SWITCH, false); - alertManager.emit(alertInfo); - alertManager.emit(new SwitchLostMostEvent(switchBuild, true, turnout)); - } - this.deviceCodeMap.remove(switchBuild.getId()); - } else if (!saveIsLost) { - this.removeSwitch(switchBuild); - } - } - - @Override - public void run() { - for (Entry entry : this.deviceCodeMap.entrySet()) { - String deviceCode = entry.getKey(); - Integer lineId = entry.getValue(); - Switch.Builder switchBuild = this.findSwitchDevice(deviceCode, lineId); - if (Objects.isNull(switchBuild)) { - this.deviceCodeMap.remove(deviceCode); - continue; - } - - Optional turnoutOpt = LineGraphicDataRepository.getDeviceOptByCode(lineId, deviceCode, Turnout.class); - Turnout turnout = turnoutOpt.orElse(null); - if (Objects.isNull(turnout)) { - log.info("道岔失表未找到地图对应的设备 线路[{}],道岔code[{}]", lineId, deviceCode); - this.deviceCodeMap.remove(deviceCode); - continue; - } - GuardConfig guardConfig = configService.getGuardConfig(lineId); - this.checkDevice(switchBuild, turnout, lineId, guardConfig); - } - - } - - -} diff --git a/src/main/java/club/joylink/xiannccda/ats/warn/lost/SwitchLostMostAlertListener.java b/src/main/java/club/joylink/xiannccda/ats/warn/lost/SwitchLostMostAlertListener.java deleted file mode 100644 index a7ace05..0000000 --- a/src/main/java/club/joylink/xiannccda/ats/warn/lost/SwitchLostMostAlertListener.java +++ /dev/null @@ -1,95 +0,0 @@ -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.AlertSourceEventListener; -import club.joylink.xiannccda.ats.cache.LineGraphicDataRepository; -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; -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 club.joylink.xiannccda.vo.AreaConfigVO; -import com.google.common.collect.Lists; -import java.util.List; -import java.util.Optional; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; - - -//@Component -@Deprecated -@Slf4j -public class SwitchLostMostAlertListener implements AlertSourceEventListener { - - private final AlertInfoService alertInfoService; - private final DeviceGuardConfigService configService; - - public SwitchLostMostAlertListener(AlertInfoService alertInfoService, DeviceGuardConfigService configService) { - this.alertInfoService = alertInfoService; - this.configService = configService; - } - - private final AlertManager alertManager = AlertManager.getDefault(); - private final AlertDataSource alertDataSource = AlertDataSource.getInstance(); - - private List findDeviceIdFormCode(Integer lineId, List deviceCodes) { - List list = Lists.newArrayList(); - for (String deviceCode : deviceCodes) { - Turnout turnout = LineGraphicDataRepository.getDeviceByCode(lineId, deviceCode, Turnout.class); - list.add(turnout.getCommon().getId()); - } - return list; - } - - @Override - public void accept(SwitchLostMostEvent event) { - Switch.Builder switchBuild = event.getSource(); - Integer lineId = switchBuild.getLineId(); - Turnout turnout = event.turnout; - GuardConfig guardConfig = configService.getGuardConfig(lineId); - Optional alertInfoMostOpt = this.alertInfoService.findAreaDevice(AlertType.SWITCH_LOST_MOST, AlertDeviceType.DEVICE_TYPE_SWITCH, turnout.getCommon().getId(), - switchBuild.getLineId()); - String mostName = alertInfoMostOpt.map(AreaConfigVO::getAreaName).orElse(null); - if (StringUtils.isEmpty(mostName)) { - if (log.isDebugEnabled()) { - log.info("线路[{}] 设备[{}] 未找到大面失表的区域配置", lineId, switchBuild.getId()); - } - return; - } - if (event.alert) { - //检测大面积失表 - boolean isMost = alertDataSource.needMostShow(lineId, mostName, guardConfig.getSwitchLostMostNums()); - alertDataSource.putAlterDevice(lineId, mostName, switchBuild.getId()); - if (!isMost && alertDataSource.needMostShow(lineId, mostName, guardConfig.getSwitchLostMostNums())) { - String warnDevices = alertDataSource.findAllWarnDevice(lineId, mostName); - this.findDeviceIdFormCode(lineId, alertDataSource.findAllWarnDeviceForList(lineId, mostName)); - String alertMsg = String.format("%s-大面积失表设备[%s]", mostName, warnDevices); - NccAlertInfo alertInfo = this.alertInfoService.createAlert2(alertInfoMostOpt, AlertType.SWITCH_LOST_MOST, switchBuild, alertMsg, warnDevices, - AlertDeviceType.DEVICE_TYPE_SWITCH, false); - alertManager.emit(alertInfo); - } - } else { - alertDataSource.removeAlterDevice(lineId, mostName, switchBuild.getId()); - } - } - - public static class SwitchLostMostEvent extends DeviceAlertEvent { - - private boolean alert; - - private Turnout turnout; - - public SwitchLostMostEvent(Builder source, boolean alert, Turnout turnout) { - super(source); - this.alert = alert; - this.turnout = turnout; - } - } -}