From a0d9d82f11f3ba7b046c4616f080ebdec1c7c403 Mon Sep 17 00:00:00 2001 From: tiger_zhou Date: Fri, 22 Dec 2023 16:41:54 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=AE=A1=E8=BD=B4=E5=91=8A?= =?UTF-8?q?=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DeviceChangeStatusConvertor.java | 7 +- .../convertor/DeviceInitConvertor.java | 7 +- .../ats/warn/AxleLedAlertListener.java | 3 +- .../ats/warn/AxleMonitoringTask.java | 131 ++++++++++++++++++ 4 files changed, 141 insertions(+), 7 deletions(-) create mode 100644 src/main/java/club/joylink/xiannccda/ats/warn/AxleMonitoringTask.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 1a3da56..fee82d4 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 @@ -36,11 +36,12 @@ public class DeviceChangeStatusConvertor extends DefaultConvertor { /* if (builder instanceof Rtu.Builder rtuBuild) { alertManager.emit(new BlueDisplayAlertEvent(rtuBuild)); } else*/ - if (builder instanceof Track.Builder trackBuild) { +// if (builder instanceof Track.Builder trackBuild) { // alertManager.emit(new SwitchAndTrackLedAlertEvent(trackBuild)); - alertManager.emit(new AxleLedAlertEvent(trackBuild)); +// alertManager.emit(new AxleLedAlertEvent(trackBuild)); - } else if (builder instanceof Switch.Builder switchBuild) { +// } else + if (builder instanceof Switch.Builder switchBuild) { alertManager.emit(new SwitchLostAlertEvent(switchBuild)); // alertManager.emit(new SwitchAndTrackLedAlertEvent(switchBuild)); alertManager.emit(new AxleLedAlertEvent(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 ff5e237..f428695 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 @@ -36,10 +36,11 @@ public class DeviceInitConvertor extends DefaultConvertor { /* if (builder instanceof Rtu.Builder rtuBuild) { alertManager.emit(new BlueDisplayAlertEvent(rtuBuild)); } else */ - if (builder instanceof Track.Builder trackBuild) { +// 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 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/AxleLedAlertListener.java b/src/main/java/club/joylink/xiannccda/ats/warn/AxleLedAlertListener.java index 59e1545..ba16911 100644 --- a/src/main/java/club/joylink/xiannccda/ats/warn/AxleLedAlertListener.java +++ b/src/main/java/club/joylink/xiannccda/ats/warn/AxleLedAlertListener.java @@ -32,7 +32,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -@Component +//@Component +@Deprecated @Slf4j public class AxleLedAlertListener implements AlertSourceEventListener { diff --git a/src/main/java/club/joylink/xiannccda/ats/warn/AxleMonitoringTask.java b/src/main/java/club/joylink/xiannccda/ats/warn/AxleMonitoringTask.java new file mode 100644 index 0000000..191594a --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/ats/warn/AxleMonitoringTask.java @@ -0,0 +1,131 @@ +package club.joylink.xiannccda.ats.warn; + +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.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.Rtu; +import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Station; +import club.joylink.xiannccda.service.AlertInfoService; +import club.joylink.xiannccda.vo.AreaConfigVO; +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; +import com.google.common.collect.Lists; +import com.google.protobuf.GeneratedMessageV3; +import java.time.LocalDateTime; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; +import lombok.Getter; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +@Component +@Slf4j +public class AxleMonitoringTask implements AlertMonitoringTask { + + private final AlertInfoService alertInfoService; + + public AxleMonitoringTask(AlertInfoService alertInfoService) { + + this.alertInfoService = alertInfoService; + } + + private final AlertManager alertManager = AlertManager.getDefault(); + + + @Override + public String getName() { + return "BULE_DISPLAY"; + } + + private final String ALL_BULE_DISPLAY_NAME = "ALL_BULE_DISPLAY"; + + private Map findRtuDeviceSource(String lineIdStr) { + DeviceStatusData deviceStatusData = DeviceDataRepository.findDataSouce(lineIdStr, DataTypeEnum.DEVICE); + if (deviceStatusData.getAllDeviceMap().isEmpty()) { + return Collections.emptyMap(); + } + Map builderMap = deviceStatusData.getAllDeviceMap().get(Rtu.getDescriptor().getName()); + if (CollectionUtils.isEmpty(builderMap)) { + return Collections.emptyMap(); + } + return builderMap; + } + + private List findRtuBuild(Integer lineId, Map builderMap) { + List collectRtuList2 = Lists.newArrayList(); + List allRtuArea = this.alertInfoService.findDevice2(AlertType.BLUE_DISPLAY, AlertDeviceType.DEVICE_TYPE_RTU, lineId); + for (AreaConfigVO areaConfigVO : allRtuArea) { + for (Integer data : areaConfigVO.getDatas()) { + Station station = LineGraphicDataRepository.getDeviceByCode(lineId, data.toString(), Station.class); + Rtu.Builder rtuBuild = (Rtu.Builder) builderMap.get(station.getCode()); + collectRtuList2.add(new RtuWarnVO(rtuBuild, station, areaConfigVO)); + } + } + return collectRtuList2; + } + + @Override + public void run() { + Set allLineSet = DeviceDataRepository.getAllLines(); + for (String lineIdStr : allLineSet) { + Integer lineId = Integer.parseInt(lineIdStr); + Map builderMap = this.findRtuDeviceSource(lineIdStr); + List collectRtuList = this.findRtuBuild(lineId, builderMap); + Map> rtuVOMapList = collectRtuList.stream().collect(Collectors.groupingBy(d -> d.areaConfigVO.getId())); + int interLockCount = rtuVOMapList.keySet().size(); + List allShutdownList = rtuVOMapList.values().stream().map(Collection::stream).map(ls -> ls.anyMatch(r -> Objects.nonNull(r.rtu) && r.rtu.getIpRtuStusDown())).toList(); + if (allShutdownList.size() == interLockCount && allShutdownList.stream().allMatch(d -> d)) { + if (alertManager.putAlterDevice(lineId, ALL_BULE_DISPLAY_NAME, "All")) { + + NccAlertInfo alertInfo = this.alertInfoService.createAlert2(null, AlertType.ALL_LINE_BLUE_DISPLAY, lineId, LocalDateTime.now(), "全线蓝线", null, + AlertDeviceType.DEVICE_TYPE_RTU, false); + alertManager.emit(alertInfo); + } + } else { + for (List rwvVOist : rtuVOMapList.values()) { + Optional rwVO = rwvVOist.stream().filter(d -> Objects.nonNull(d.rtu) && d.rtu.getIpRtuStusDown()).findAny(); + if (rwVO.isPresent()) { + RtuWarnVO rtuVO = rwVO.get(); + if (alertManager.putAlterDevice(lineId, this.getName(), rtuVO.areaConfigVO.getAreaName())) { + String alertInfoMostName = rtuVO.areaConfigVO.getAreaName(); + NccAlertInfo alertInfo = this.alertInfoService.createAlert2(rtuVO.areaConfigVO.getId(), AlertType.BLUE_DISPLAY, rtuVO.rtu, alertInfoMostName, + rtuVO.station.getCommon().getId(), + AlertDeviceType.DEVICE_TYPE_RTU, false); + alertManager.emit(alertInfo); + } + } else { + alertManager.removeAlterDevice(lineId, this.getName(), rwvVOist.get(0).areaConfigVO.getAreaName()); + alertManager.removeAlterDevice(lineId, ALL_BULE_DISPLAY_NAME, "All"); + } + } + } + } + } + + + @Getter + public static class RtuWarnVO { + + Rtu.Builder rtu; + Station station; + AreaConfigVO areaConfigVO; + + public RtuWarnVO(Rtu.Builder rtu, Station station, AreaConfigVO areaConfigVO) { + this.rtu = rtu; + this.station = station; + this.areaConfigVO = areaConfigVO; + } + } + +}