From 9ad40d520b5f8d1ea22fbbc7acde6c7d42fde1d8 Mon Sep 17 00:00:00 2001 From: tiger_zhou Date: Tue, 29 Aug 2023 11:25:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=91=8A=E8=AD=A6=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../joylink/xiannccda/alert/NccAlertInfo.java | 4 +- .../xiannccda/alert/core/AlertManager.java | 22 +++++-- .../ats/cache/LineGraphicDataRepository.java | 4 +- .../warn/AxleSwitchTrackLedAlertListener.java | 61 +++++++++++------ .../xiannccda/ats/warn/BlueAlertListener.java | 35 +++++++--- .../ats/warn/PlatformAlertMonitoringTask.java | 24 +++++-- .../warn/SwitchLostAlertMonitoringTask.java | 45 ++++++++----- .../ats/warn/TrainModeAlertListener.java | 3 +- .../xiannccda/service/AlertInfoService.java | 66 ++++--------------- .../xiannccda/service/AlertMockService.java | 4 +- .../xiannccda/service/AlertRecordService.java | 2 +- .../config/DeviceGuardConfigService.java | 26 +------- 12 files changed, 152 insertions(+), 144 deletions(-) diff --git a/src/main/java/club/joylink/xiannccda/alert/NccAlertInfo.java b/src/main/java/club/joylink/xiannccda/alert/NccAlertInfo.java index d80c3b2..9db5f4e 100644 --- a/src/main/java/club/joylink/xiannccda/alert/NccAlertInfo.java +++ b/src/main/java/club/joylink/xiannccda/alert/NccAlertInfo.java @@ -36,7 +36,9 @@ public class NccAlertInfo implements AlertInfo { this.alertType = alertType; this.lineId = lineId; this.alertObject = alertObject; - this.locatorDeviceId = locatorDeviceId; + if (alertType != AlertType.ALL_LINE_BLUE_DISPLAY) { + this.locatorDeviceId = locatorDeviceId; + } this.alertLocationId = alertLocationId; this.mock = mockData; this.level = buildLevel(); 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 b15b685..33c247d 100644 --- a/src/main/java/club/joylink/xiannccda/alert/core/AlertManager.java +++ b/src/main/java/club/joylink/xiannccda/alert/core/AlertManager.java @@ -1,6 +1,7 @@ package club.joylink.xiannccda.alert.core; import club.joylink.xiannccda.event.EventEmitter; +import com.google.common.base.Joiner; import com.google.common.collect.HashBasedTable; import com.google.common.collect.Lists; import com.google.common.collect.Table; @@ -83,10 +84,11 @@ public class AlertManager extends EventEmitter { detail = new AlertTableDetail(false); DEVICE_ALTER_TABLE.put(lineId, customName, detail); } - if (detail.mostShower && detail.mostSize() >= val) { - //已经报警过了且超过了阈值 - return false; - } else if (detail.mostShower && detail.mostSize() < val) { +// if (detail.mostShower && detail.mostSize() >= val) { +// //已经报警过了且超过了阈值 +// return false; +// } else + if (detail.mostShower && detail.mostSize() < val) { //已经报警过了,但小于阈值 detail.setMostShower(false); return false; @@ -98,6 +100,14 @@ public class AlertManager extends EventEmitter { return false; } + public String findAllWarnDevice(Integer lineId, String customName) { + AlertTableDetail detail = DEVICE_ALTER_TABLE.get(lineId, customName); + if (Objects.isNull(detail)) { + return null; + } + return detail.getAllDeviceCodes(); + } + public static AlertManager getInstance(String id) { return MANAGER_MAP.computeIfAbsent(id, k -> new AlertManager(id)); } @@ -160,6 +170,10 @@ public class AlertManager extends EventEmitter { return true; } + public String getAllDeviceCodes() { + return Joiner.on(",").skipNulls().join(this.deviceCodes); + } + public boolean contains(String deviceCode) { return this.deviceCodes.contains(deviceCode); } diff --git a/src/main/java/club/joylink/xiannccda/ats/cache/LineGraphicDataRepository.java b/src/main/java/club/joylink/xiannccda/ats/cache/LineGraphicDataRepository.java index 8dcef4e..519ba81 100644 --- a/src/main/java/club/joylink/xiannccda/ats/cache/LineGraphicDataRepository.java +++ b/src/main/java/club/joylink/xiannccda/ats/cache/LineGraphicDataRepository.java @@ -63,7 +63,9 @@ public class LineGraphicDataRepository { private static final HashBasedTable line_id_table = HashBasedTable.create(); /** - * 区段 逻辑 对物理区段的map + * 线路id 逻辑 对物理区段的map + *

+ * 如果区段是道岔物理区段,那么key 就是对应的道岔code */ private static final Table LOGIC_SECTION_TO_SECTION_TABLE = HashBasedTable.create(); 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 325f775..82cc973 100644 --- a/src/main/java/club/joylink/xiannccda/ats/warn/AxleSwitchTrackLedAlertListener.java +++ b/src/main/java/club/joylink/xiannccda/ats/warn/AxleSwitchTrackLedAlertListener.java @@ -1,33 +1,26 @@ 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.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.ats.message.line3.device.DeviceType; -import club.joylink.xiannccda.dto.config.DeviceGuardConfigDto.GuardUnit; import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType; +import club.joylink.xiannccda.dto.protos.DeviceInfoProto; import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Switch; import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Track; import club.joylink.xiannccda.dto.protos.GuardConfigProto.GuardConfig; import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Section; +import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Section.SectionType; import club.joylink.xiannccda.entity.DeviceAreaConfig; -import club.joylink.xiannccda.entity.DeviceGuardConfig; import club.joylink.xiannccda.service.AlertInfoService; import club.joylink.xiannccda.service.config.DeviceGuardConfigService; -import club.joylink.xiannccda.service.config.Operator; import com.google.protobuf.GeneratedMessageV3; import com.google.protobuf.GeneratedMessageV3.Builder; -import java.time.Instant; -import java.time.LocalDateTime; -import java.time.ZoneId; import java.util.Map; import java.util.Objects; import java.util.Optional; @@ -48,7 +41,6 @@ public class AxleSwitchTrackLedAlertListener implements AlertSourceEventListener this.alertInfoService = alertInfoService; } - private final static String DEFAULT_NAME = AlertType.AXLE_LED_RED.name(); @Override public void accept(SwitchAndTrackLedAlertEvent event) { @@ -95,32 +87,59 @@ public class AxleSwitchTrackLedAlertListener implements AlertSourceEventListener String id = DeviceStatusDataOperate.findFieldVal(build, "id", String.class); GuardConfig guardConfig = configService.getGuardConfig(lineId); AlertType mostType = alertType == AlertType.AXLE_LED_RED ? AlertType.AXLE_LED_RED_MOST : AlertType.AXLE_LED_ORANGE_MOST; + String layoutDeviceId = this.findSectionId(lineId, section, id); int overNums = guardConfig.getRedLedMostNums(); if (mostType == AlertType.AXLE_LED_ORANGE_MOST) { overNums = guardConfig.getOrangeLedMostNums(); } - Optional alertInfoOptional = this.alertInfoService.findAreaDevice(alertType, AlertDeviceType.DEVICE_TYPE_TRACK, section.getCommon().getId(), lineId); - Optional alertInfoMostOptional = this.alertInfoService.findAreaDevice(mostType, AlertDeviceType.DEVICE_TYPE_TRACK, section.getCommon().getId(), lineId); - String ledName = alertInfoOptional.isPresent() ? alertInfoOptional.get().getAreaName() : alertType.name(); - String ledMostName = alertInfoMostOptional.map(DeviceAreaConfig::getAreaName).orElse(null); + Optional alertInfoOptional = this.alertInfoService.findAreaDevice(alertType, AlertDeviceType.DEVICE_TYPE_TRACK, layoutDeviceId, lineId); + Optional alertInfoMostOptional = this.alertInfoService.findAreaDevice(mostType, AlertDeviceType.DEVICE_TYPE_TRACK, layoutDeviceId, lineId); + String customName = this.getCustomName(alertInfoOptional, alertInfoMostOptional, alertType); + String ledName = alertType == AlertType.AXLE_LED_RED ? "红光带" : "橙光带"; if (light) { - if (alertManager.putAlterDevice(lineId, ledName, id)) { - NccAlertInfo alertInfo = this.alertInfoService.createAlert2(alertInfoOptional, alertType, build, section.getCode(), false); + if (alertManager.putAlterDevice(lineId, customName, id)) { + String alertMsg = String.format("出现%s设备[%s]", ledName, id); + NccAlertInfo alertInfo = this.alertInfoService.createAlert2(alertInfoOptional, alertType, build, alertMsg, false); alertManager.emit(alertInfo); } - if (Objects.nonNull(ledMostName) && alertManager.needMostShow(lineId, ledMostName, overNums)) { - NccAlertInfo alertInfoMost = this.alertInfoService.createAlert2(alertInfoOptional, alertType, build, section.getCode(), false); + if (alertInfoMostOptional.isPresent() && alertManager.needMostShow(lineId, customName, overNums)) { + + String warnDevices = alertManager.findAllWarnDevice(lineId, customName); + String alertMsg = String.format("%s-出现大面积%s设备[%s]", alertInfoMostOptional.get().getAreaName(), ledName, warnDevices); + NccAlertInfo alertInfoMost = this.alertInfoService.createAlert2(alertInfoOptional, mostType, build, alertMsg, false); alertManager.emit(alertInfoMost); } } else { - alertManager.removeAlterDevice(lineId, ledName, id); - if (StringUtils.isNotEmpty(ledMostName)) { - alertManager.removeAlterDevice(lineId, ledMostName, id); + alertManager.removeAlterDevice(lineId, customName, id); + if (StringUtils.isNotEmpty(customName)) { + alertManager.removeAlterDevice(lineId, customName, id); } } } + private String getCustomName(Optional alertInfoOpt, Optional alertInfoMostOpt, AlertType alertType) { + String customName = alertInfoMostOpt.map(DeviceAreaConfig::getAreaName).orElse(null); + if (StringUtils.isNotEmpty(customName)) { + return String.format("%s_%s", customName, alertType.name()); + } + return alertInfoOpt.isPresent() ? alertInfoOpt.get().getAreaName() : alertType.name(); + } + + private String findSectionId(int lineId, Section section, String deviceCode) { + if (section.getSectionType() == SectionType.TurnoutPhysical) { + return section.getCommon().getId(); + } + Map sectionMaper = LineGraphicDataRepository.getLineSectionBuild(lineId); + for (String childId : section.getChildrenList()) { + Builder builder = sectionMaper.get(childId); + String code = DeviceStatusDataOperate.findFieldVal(builder, "code", String.class); + if (StringUtils.equalsIgnoreCase(code, deviceCode) && builder instanceof DeviceInfoProto.Section.Builder section1) { + return section1.getId(); + } + } + return section.getCommon().getId(); + } } 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 4e7d41e..d396e7a 100644 --- a/src/main/java/club/joylink/xiannccda/ats/warn/BlueAlertListener.java +++ b/src/main/java/club/joylink/xiannccda/ats/warn/BlueAlertListener.java @@ -35,6 +35,12 @@ public class BlueAlertListener implements AlertSourceEventListener + * key= 线路id, val=集中站 + */ private final static Map> CONTROL_STATION_MAPER = new ConcurrentHashMap<>(); @@ -43,27 +49,36 @@ public class BlueAlertListener implements AlertSourceEventListener alertInfoOpt = this.alertInfoService.findAreaDevice(AlertType.BLUE_DISPLAY, AlertDeviceType.DEVICE_TYPE_RTU, station.getCommon().getId(), + rtu.getLineId()); + if (alertInfoOpt.isEmpty()) { + log.error("rtu[{}] 地图车站id[{}] 线路Id[{}]未找到对应的区域配置,无法蓝显", rtu.getId(), station.getCommon().getId(), rtu.getLineId()); + return; + } + DeviceAreaConfig areaConfig = alertInfoOpt.get(); if (rtu.getIpRtuStusDown()) { - 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(), false); + //保存出现蓝显的集中站 + alertManager.putAlterDevice(rtu.getLineId(), COLL_RTU_NAME, rtu.getId()); + //保存蓝显联锁id + if (alertManager.putAlterDevice(rtu.getLineId(), BLUE_DISPLAY_NAME, areaConfig.getId().toString())) { + String alertMsg = String.format("%s 蓝显", areaConfig.getAreaName()); + NccAlertInfo alertInfo = this.alertInfoService.createAlert2(alertInfoOpt, AlertType.BLUE_DISPLAY, rtu, alertMsg, false); alertManager.emit(alertInfo); - } int allControlStationSize = CONTROL_STATION_MAPER.get(rtu.getLineId()).size(); - if (alertManager.needMostShow(rtu.getLineId(), BLUE_DISPLAY_NAME, allControlStationSize) - && alertManager.putAlterDevice(rtu.getLineId(), BLUE_DISPLAY_NAME, ALL_BLUE_DISPLAY_VAL) - ) { + //查看是否全部的集中站已经蓝显 + if (alertManager.needMostShow(rtu.getLineId(), COLL_RTU_NAME, allControlStationSize) + && 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, false); alertManager.emit(alertInfo); } } else { - alertManager.removeAlterDevice(rtu.getLineId(), BLUE_DISPLAY_NAME, rtu.getId()); + alertManager.removeAlterDevice(rtu.getLineId(), BLUE_DISPLAY_NAME, areaConfig.getId().toString()); + alertManager.removeAlterDevice(rtu.getLineId(), COLL_RTU_NAME, rtu.getId()); alertManager.removeAlterDevice(rtu.getLineId(), BLUE_DISPLAY_NAME, ALL_BLUE_DISPLAY_VAL); } } 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 67ef3a5..b2b1f34 100644 --- a/src/main/java/club/joylink/xiannccda/ats/warn/PlatformAlertMonitoringTask.java +++ b/src/main/java/club/joylink/xiannccda/ats/warn/PlatformAlertMonitoringTask.java @@ -10,32 +10,34 @@ import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType; import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Platform; import club.joylink.xiannccda.dto.protos.GuardConfigProto.GuardConfig; import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto; +import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Station; import club.joylink.xiannccda.service.AlertInfoService; import club.joylink.xiannccda.service.config.DeviceGuardConfigService; +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.stereotype.Component; @Component @Slf4j public class PlatformAlertMonitoringTask implements AlertMonitoringTask { - private final AlertDetailFactory alertDetailFactory; private final DeviceGuardConfigService configService; private final AlertInfoService alertInfoService; - public PlatformAlertMonitoringTask(AlertDetailFactory alertDetailFactory, DeviceGuardConfigService configService, AlertInfoService alertInfoService) { - this.alertDetailFactory = alertDetailFactory; + public PlatformAlertMonitoringTask(DeviceGuardConfigService configService, AlertInfoService alertInfoService) { this.configService = configService; this.alertInfoService = alertInfoService; } - private AlertManager alertManager = AlertManager.getDefault(); + private final AlertManager alertManager = AlertManager.getDefault(); - - Map platformMap = new ConcurrentHashMap<>(); + private Map platformMap = new ConcurrentHashMap<>(); private final static String CUSTOM_NAME = AlertDeviceType.DEVICE_TYPE_PLATFORM.name(); public void putSwitchIfNotExist(Platform.Builder platformBuild) { @@ -62,6 +64,11 @@ public class PlatformAlertMonitoringTask implements AlertMonitoringTask { return "PLATFORM_CLOSE_OR_OPEN_ALTER"; } + private String findRefStationName(int lineId, String stationId) { + Stream stream = LineGraphicDataRepository.getDevices(lineId, Station.class); + Optional stationOptional = stream.filter(d -> StringUtils.equalsIgnoreCase(d.getCommon().getId(), stationId)).findAny(); + return stationOptional.map(Station::getName).orElse(null); + } @Override public void run() { @@ -77,7 +84,10 @@ public class PlatformAlertMonitoringTask implements AlertMonitoringTask { if (this.timeOver(build.getReceiveTime(), timeOut) && 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(), false); + String stationName = this.findRefStationName(build.getLineId(), platform.getRefStation()); + String openClose = alertType == AlertType.PLATFORM_DOOR_CANNOT_OPEN ? "打开" : "关闭"; + String alertMsg = String.format("%s-%s-屏蔽门无法%s", stationName, platform.getUp() ? "上行" : "下行", openClose); + NccAlertInfo alertInfo = this.alertInfoService.createAlert(alertType, AlertDeviceType.DEVICE_TYPE_PLATFORM, platform.getCommon().getId(), build, alertMsg, false); alertManager.emit(alertInfo); platformMap.remove(build.getId()); } 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 2359260..ea1a6d7 100644 --- a/src/main/java/club/joylink/xiannccda/ats/warn/SwitchLostAlertMonitoringTask.java +++ b/src/main/java/club/joylink/xiannccda/ats/warn/SwitchLostAlertMonitoringTask.java @@ -57,9 +57,15 @@ public class SwitchLostAlertMonitoringTask implements AlertMonitoringTask { } public void removeSwitch(Switch.Builder switchBuilder) { - AlertManager alertManager = AlertManager.getDefault(); + Turnout turnout = LineGraphicDataRepository.getDeviceByCode(switchBuilder.getLineId(), switchBuilder.getId(), Turnout.class); + Optional alertInfoOpt = this.alertInfoService.findAreaDevice(AlertType.SWITCH_LOST, AlertDeviceType.DEVICE_TYPE_SWITCH, turnout.getCommon().getId(), + switchBuilder.getLineId()); + Optional alertInfoMostOpt = this.alertInfoService.findAreaDevice(AlertType.SWITCH_LOST_MOST, AlertDeviceType.DEVICE_TYPE_SWITCH, turnout.getCommon().getId(), + switchBuilder.getLineId()); + String customName = this.getCustomName(alertInfoOpt, alertInfoMostOpt); + deviceMap.remove(switchBuilder.getId()); - alertManager.removeAlterDevice(switchBuilder.getLineId(), DEVICE_TYPE_NAME, switchBuilder.getId()); + alertManager.removeAlterDevice(switchBuilder.getLineId(), customName, switchBuilder.getId()); } @Override @@ -71,35 +77,42 @@ public class SwitchLostAlertMonitoringTask implements AlertMonitoringTask { @Override public void run() { for (Builder savedSwitchBuild : this.deviceMap.values()) { -// String lineIdStr = String.valueOf(savedSwitchBuild.getLineId()); - GuardConfig guardConfig = configService.getGuardConfig(savedSwitchBuild.getLineId()); - Turnout turnout = LineGraphicDataRepository.getDeviceByCode(savedSwitchBuild.getLineId(), savedSwitchBuild.getId(), Turnout.class); - + Integer lineId = savedSwitchBuild.getLineId(); + GuardConfig guardConfig = configService.getGuardConfig(lineId); + Turnout turnout = LineGraphicDataRepository.getDeviceByCode(lineId, savedSwitchBuild.getId(), Turnout.class); Optional alertInfoOpt = this.alertInfoService.findAreaDevice(AlertType.SWITCH_LOST, AlertDeviceType.DEVICE_TYPE_SWITCH, turnout.getCommon().getId(), savedSwitchBuild.getLineId()); - - String oneName = alertInfoOpt.isPresent() ? alertInfoOpt.get().getAreaName() : AlertType.SWITCH_LOST.name(); + Optional alertInfoMostOpt = this.alertInfoService.findAreaDevice(AlertType.SWITCH_LOST_MOST, AlertDeviceType.DEVICE_TYPE_SWITCH, turnout.getCommon().getId(), + savedSwitchBuild.getLineId()); + String customName = this.getCustomName(alertInfoOpt, alertInfoMostOpt); boolean saveIsLost = savedSwitchBuild.getIpSingleSwitchStusLostIndication(); if (saveIsLost && this.timeOver(savedSwitchBuild.getReceiveTime(), guardConfig.getSwitchLostTimes())) { //失表超时 - if (alertManager.putAlterDevice(savedSwitchBuild.getLineId(), oneName, savedSwitchBuild.getId())) { - NccAlertInfo alertInfo = this.alertInfoService.createAlert2(alertInfoOpt, AlertType.SWITCH_LOST, savedSwitchBuild, savedSwitchBuild.getId(), false); + if (alertManager.putAlterDevice(lineId, customName, savedSwitchBuild.getId())) { + String alertMsg = String.format("设备[%s]失表", savedSwitchBuild.getId()); + NccAlertInfo alertInfo = this.alertInfoService.createAlert2(alertInfoOpt, AlertType.SWITCH_LOST, savedSwitchBuild, alertMsg, false); alertManager.emit(alertInfo); this.deviceMap.remove(savedSwitchBuild.getId()); } - Optional alertInfoMostOpt = this.alertInfoService.findAreaDevice(AlertType.SWITCH_LOST_MOST, AlertDeviceType.DEVICE_TYPE_SWITCH, turnout.getCommon().getId(), - savedSwitchBuild.getLineId()); - //检测大面积失表 - 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(), false); + //检测大面积失表 + if (alertInfoMostOpt.isPresent() && alertManager.needMostShow(lineId, customName, guardConfig.getSwitchLostMostNums())) { + String warnDevices = alertManager.findAllWarnDevice(lineId, customName); + String alertMsg = String.format("%s-大面积失表设备[%s]", customName, warnDevices); + NccAlertInfo alertInfo = this.alertInfoService.createAlert2(alertInfoMostOpt, AlertType.SWITCH_LOST_MOST, savedSwitchBuild, alertMsg, false); alertManager.emit(alertInfo); } } - } } + private String getCustomName(Optional alertInfoOpt, Optional alertInfoMostOpt) { + String customName = alertInfoMostOpt.map(DeviceAreaConfig::getAreaName).orElse(null); + if (StringUtils.isEmpty(customName)) { + customName = alertInfoOpt.isPresent() ? alertInfoOpt.get().getAreaName() : AlertType.SWITCH_LOST.name(); + } + return customName; + } } 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 3f3a3bb..3d4d65d 100644 --- a/src/main/java/club/joylink/xiannccda/ats/warn/TrainModeAlertListener.java +++ b/src/main/java/club/joylink/xiannccda/ats/warn/TrainModeAlertListener.java @@ -39,7 +39,8 @@ public class TrainModeAlertListener implements AlertSourceEventListener findList = areaConfigList.stream().filter(d -> d.findAlertTypes(alertType)).toList(); - - /*LambdaQueryWrapper qw = Wrappers.lambdaQuery(DeviceAreaConfig.class); - qw.eq(DeviceAreaConfig::getDeviceType, dt.name()); - qw.eq(DeviceAreaConfig::getLineId, lineId); - qw.last(String.format(" and find_in_set('%s',%s) > 0 ", alertType.name(), DeviceAreaConfig.ALERT_TYPES)); - List areaConfigList = this.areaConfigRepository.list(qw);*/ - return findList; + return areaConfigList.stream().filter(d -> d.findAlertTypes(alertType)).toList(); } - public NccAlertInfo createAlert(AlertType alertType, AlertDeviceType dt, String layoutId, MessageOrBuilder mb, String targetDeviceCode, boolean mockData) { + public NccAlertInfo createAlert(AlertType alertType, AlertDeviceType dt, String layoutId, MessageOrBuilder mb, String alertMsg, boolean mockData) { Integer lineId = DeviceStatusDataOperate.findFieldVal(mb, "lineId", Integer.class); Optional areaConfigOptional = this.findAreaDevice(alertType, dt, layoutId, lineId); - return this.createAlert2(areaConfigOptional, alertType, mb, targetDeviceCode, mockData); + return this.createAlert2(areaConfigOptional, alertType, mb, alertMsg, mockData); } - public NccAlertInfo createAlert2(Optional areaConfigOpt, AlertType alertType, MessageOrBuilder mb, String targetDeviceCode, boolean mockData) { + public NccAlertInfo createAlert2(Optional areaConfigOpt, AlertType alertType, MessageOrBuilder mb, String alertMsg, boolean mockData) { Long timestamp = DeviceStatusDataOperate.findFieldVal(mb, "timestamp", Long.class); Integer lineId = DeviceStatusDataOperate.findFieldVal(mb, "lineId", Integer.class); String deviceCode = DeviceStatusDataOperate.findFieldVal(mb, "id", String.class); LocalDateTime createTime = LocalDateTime.ofInstant(Instant.ofEpochSecond(timestamp), ZoneId.of("+8")); - DeviceAreaConfig areaConfig = areaConfigOpt.orElse(null); - if (Objects.isNull(areaConfig)) { - return new NccAlertInfo(createTime, alertType, lineId, targetDeviceCode, deviceCode, null, mockData); - } - String alertObject = String.format("%s-设备[%s]", areaConfig.getAreaName(), targetDeviceCode); - return new NccAlertInfo(createTime, alertType, lineId, alertObject, deviceCode, areaConfig.getId(), mockData); + Long areaConfigId = areaConfigOpt.map(DeviceAreaConfig::getId).orElse(null); + return new NccAlertInfo(createTime, alertType, lineId, alertMsg, deviceCode, areaConfigId, mockData); } -/* @Deprecated - public NccAlertInfo createAlert(DeviceAreaConfig areaConfig, AlertType alertType, MessageOrBuilder mb) { - Long timestamp = DeviceStatusDataOperate.findFieldVal(mb, "timestamp", Long.class); - Integer lineId = DeviceStatusDataOperate.findFieldVal(mb, "lineId", Integer.class); - String deviceCode = DeviceStatusDataOperate.findFieldVal(mb, "id", String.class); - - Optional alertTipOptional; - - if (Objects.isNull(areaConfig)) { - alertTipOptional = this.alertTipService.queryOne2(alertType.name(), null); - } else { - alertTipOptional = this.alertTipService.queryOne2(alertType.name(), areaConfig.getId()); - } - AlertTip at = alertTipOptional.orElse(null); - LocalDateTime createTime = LocalDateTime.ofInstant(Instant.ofEpochSecond(timestamp), ZoneId.of("+8")); - - return new NccAlertInfo(createTime, alertType, Objects.nonNull(at) ? at.getId() : null, lineId, deviceCode, deviceCode, null); - }*/ public Optional findAreaDevice(AlertType alertType, AlertDeviceType dt, String layoutId, int lineId) { List areaConfigList = this.findDevice(alertType, dt, lineId); @@ -110,8 +67,7 @@ public class AlertInfoService { } for (DeviceAreaConfig areaConfig : areaConfigList) { if (areaConfig.getDeviceType() == dt) { - boolean b = Splitter.on(",").splitToStream(areaConfig.getData()).anyMatch(d -> StringUtils.equalsIgnoreCase(d, layoutId)); - if (b) { + if (Splitter.on(",").splitToStream(areaConfig.getData()).anyMatch(d -> StringUtils.equalsIgnoreCase(d, layoutId))) { return areaConfig; } } diff --git a/src/main/java/club/joylink/xiannccda/service/AlertMockService.java b/src/main/java/club/joylink/xiannccda/service/AlertMockService.java index 52a590a..b83e9de 100644 --- a/src/main/java/club/joylink/xiannccda/service/AlertMockService.java +++ b/src/main/java/club/joylink/xiannccda/service/AlertMockService.java @@ -118,7 +118,7 @@ public class AlertMockService { Turnout turnout = turnoutOptional.orElse(null); return this.alertInfoService.createAlert(dto.getAlertType(), AlertDeviceType.DEVICE_TYPE_SWITCH, turnout.getCommon().getId(), switchs, dto.getAll(), true); } - case AXLE_LED_RED, AXLE_LED_ORANGE -> { + case AXLE_LED_RED, AXLE_LED_ORANGE, AXLE_LED_ORANGE_MOST, AXLE_LED_RED_MOST -> { Optional lsOptional = LineGraphicDataRepository.getDevices(lineId, LogicSection.class).filter(d -> dto.getDeviceCodes().contains(d.getCode())).findAny(); Track.Builder track = Track.newBuilder(); track.setId(dto.getFrist()); @@ -172,7 +172,7 @@ public class AlertMockService { case SWITCH_LOST, SWITCH_LOST_MOST -> { return LineGraphicDataRepository.getDevices(lineId, Turnout.class).collect(Collectors.toMap(d -> d.getCommon().getId(), Function.identity(), (v1, v2) -> v1)).values(); } - case AXLE_LED_RED, AXLE_LED_ORANGE, TRAIN_EB_ATP -> { + case AXLE_LED_RED, AXLE_LED_ORANGE, TRAIN_EB_ATP, AXLE_LED_ORANGE_MOST, AXLE_LED_RED_MOST -> { return LineGraphicDataRepository.getDevices(lineId, LogicSection.class) .collect(Collectors.toMap(d -> d.getCommon().getId(), Function.identity(), (v1, v2) -> v1)).values(); diff --git a/src/main/java/club/joylink/xiannccda/service/AlertRecordService.java b/src/main/java/club/joylink/xiannccda/service/AlertRecordService.java index e6ca800..e31c83f 100644 --- a/src/main/java/club/joylink/xiannccda/service/AlertRecordService.java +++ b/src/main/java/club/joylink/xiannccda/service/AlertRecordService.java @@ -41,7 +41,7 @@ public class AlertRecordService { if (Objects.nonNull(locationId) && locationId > 0L) { qw.eq(AlertTip::getAreaConfigId, locationId); } - AlertTip tip = alertTipRepository.getOne(qw); + AlertTip tip = alertTipRepository.getOne(qw, false); BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(Objects.nonNull(tip), "未找到对应的决策辅助信息"); this.alertRecordRepository.update(Wrappers.lambdaUpdate(AlertRecord.class) 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 2eeb577..7cd43bd 100644 --- a/src/main/java/club/joylink/xiannccda/service/config/DeviceGuardConfigService.java +++ b/src/main/java/club/joylink/xiannccda/service/config/DeviceGuardConfigService.java @@ -1,29 +1,18 @@ package club.joylink.xiannccda.service.config; -import club.joylink.xiannccda.ats.message.line3.device.DeviceType; -import club.joylink.xiannccda.dto.config.DeviceGuardConfigDto; -import club.joylink.xiannccda.dto.config.DeviceGuardConfigDto.GuardUnit; import club.joylink.xiannccda.dto.config.DeviceGuardConfigQueryDto; -import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType; import club.joylink.xiannccda.dto.protos.GuardConfigProto.GuardConfig; import club.joylink.xiannccda.entity.DeviceGuardConfig; import club.joylink.xiannccda.exception.BusinessExceptionAssertEnum; -import club.joylink.xiannccda.exception.ExceptionAssert; import club.joylink.xiannccda.repository.IDeviceGuardConfigRepository; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; -import com.google.common.collect.HashBasedTable; -import com.google.common.collect.Table; -import java.util.Collections; -import java.util.List; -import java.util.Map; import java.util.Objects; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -57,20 +46,7 @@ public class DeviceGuardConfigService { public void saveOrUpdate(DeviceGuardConfig dto) { - /* LambdaQueryWrapper qw = Wrappers.lambdaQuery(DeviceGuardConfig.class); - qw.eq(DeviceGuardConfig::getLineId, dto.getLineId()) - .eq(DeviceGuardConfig::getConfigType, DeviceGuardConfig.CONFIG_TYPE_USER) - .eq(DeviceGuardConfig::getDeviceType, dto.getDeviceType().name()) - .eq(DeviceGuardConfig::getDeviceConfigType, dto.getConfigDeviceType()); - DeviceGuardConfig dataConfig = this.convertDB(dto); - if (Objects.nonNull(dto.getId())) { - DeviceGuardConfig guardConfig = this.configRepository.getById(dto.getId()); - BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(Objects.nonNull(guardConfig), "未找到对应的数据"); - qw.ne(DeviceGuardConfig::getId, dto.getId()); - dataConfig.setId(guardConfig.getId()); - } - Long typeCounter = this.configRepository.count(qw); - BusinessExceptionAssertEnum.UNIQUE_FIELD_REPEAT.assertTrue */ + this.configRepository.saveOrUpdate(dto); GUARD_CONFIG_CACHE.invalidateAll(); }