From 5e7ecd32721f2147c55d54c77cd04957be071084 Mon Sep 17 00:00:00 2001 From: tiger_zhou Date: Mon, 28 Aug 2023 14:22:59 +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 +- .../warn/AxleSwitchTrackLedAlertListener.java | 4 +- .../xiannccda/ats/warn/BlueAlertListener.java | 4 +- .../ats/warn/PlatformAlertMonitoringTask.java | 2 +- .../warn/SwitchLostAlertMonitoringTask.java | 4 +- .../ats/warn/TrainModeAlertListener.java | 2 +- .../controller/AlertMockController.java | 16 +- .../joylink/xiannccda/dto/AlertMockDTO.java | 14 ++ .../xiannccda/service/AlertInfoService.java | 10 +- .../xiannccda/service/AlertMockService.java | 172 +++++++++++++++++- .../xiannccda/service/AlertRecordService.java | 2 +- 11 files changed, 207 insertions(+), 27 deletions(-) diff --git a/src/main/java/club/joylink/xiannccda/alert/NccAlertInfo.java b/src/main/java/club/joylink/xiannccda/alert/NccAlertInfo.java index a1abc04..d80c3b2 100644 --- a/src/main/java/club/joylink/xiannccda/alert/NccAlertInfo.java +++ b/src/main/java/club/joylink/xiannccda/alert/NccAlertInfo.java @@ -31,14 +31,14 @@ public class NccAlertInfo implements AlertInfo { public NccAlertInfo(LocalDateTime alertTime, AlertType alertType, Integer lineId, String alertObject, String locatorDeviceId, - Long alertLocationId) { + Long alertLocationId, boolean mockData) { this.alertTime = alertTime; this.alertType = alertType; this.lineId = lineId; this.alertObject = alertObject; this.locatorDeviceId = locatorDeviceId; this.alertLocationId = alertLocationId; - this.mock = false; + this.mock = mockData; this.level = buildLevel(); } 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 684fb79..325f775 100644 --- a/src/main/java/club/joylink/xiannccda/ats/warn/AxleSwitchTrackLedAlertListener.java +++ b/src/main/java/club/joylink/xiannccda/ats/warn/AxleSwitchTrackLedAlertListener.java @@ -106,11 +106,11 @@ public class AxleSwitchTrackLedAlertListener implements AlertSourceEventListener if (light) { if (alertManager.putAlterDevice(lineId, ledName, id)) { - NccAlertInfo alertInfo = this.alertInfoService.createAlert2(alertInfoOptional, alertType, build, section.getCode()); + NccAlertInfo alertInfo = this.alertInfoService.createAlert2(alertInfoOptional, alertType, build, section.getCode(), false); alertManager.emit(alertInfo); } if (Objects.nonNull(ledMostName) && alertManager.needMostShow(lineId, ledMostName, overNums)) { - NccAlertInfo alertInfoMost = this.alertInfoService.createAlert2(alertInfoOptional, alertType, build, section.getCode()); + NccAlertInfo alertInfoMost = this.alertInfoService.createAlert2(alertInfoOptional, alertType, build, section.getCode(), false); alertManager.emit(alertInfoMost); } } else { 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 0641d16..4e7d41e 100644 --- a/src/main/java/club/joylink/xiannccda/ats/warn/BlueAlertListener.java +++ b/src/main/java/club/joylink/xiannccda/ats/warn/BlueAlertListener.java @@ -51,7 +51,7 @@ public class BlueAlertListener implements AlertSourceEventListener 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()); + NccAlertInfo alertInfo = this.alertInfoService.createAlert2(alertInfoOpt, AlertType.BLUE_DISPLAY, rtu, station.getName(), false); alertManager.emit(alertInfo); } @@ -59,7 +59,7 @@ public class BlueAlertListener implements AlertSourceEventListener findDevice(@PathVariable("lineId") Integer lineId, @PathVariable("alertType") AlertType alertType) { + return this.alertMockService.findAlertType(lineId, alertType); + } + } diff --git a/src/main/java/club/joylink/xiannccda/dto/AlertMockDTO.java b/src/main/java/club/joylink/xiannccda/dto/AlertMockDTO.java index 687a962..6aef219 100644 --- a/src/main/java/club/joylink/xiannccda/dto/AlertMockDTO.java +++ b/src/main/java/club/joylink/xiannccda/dto/AlertMockDTO.java @@ -1,13 +1,27 @@ package club.joylink.xiannccda.dto; import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType; +import com.google.common.base.Joiner; import jakarta.validation.constraints.NotNull; +import java.util.List; import lombok.Data; @Data public class AlertMockDTO { + @NotNull(message = "线路id不能为null") private Integer lineId; @NotNull(message = "故障类型不能为null") private AlertType alertType; + @NotNull(message = "故障code不能为null") + private List deviceCodes; + + public String getFrist() { + return this.deviceCodes.get(0); + } + + public String getAll() { + return Joiner.on(",").join(this.deviceCodes); + } + } diff --git a/src/main/java/club/joylink/xiannccda/service/AlertInfoService.java b/src/main/java/club/joylink/xiannccda/service/AlertInfoService.java index 682fae9..e972386 100644 --- a/src/main/java/club/joylink/xiannccda/service/AlertInfoService.java +++ b/src/main/java/club/joylink/xiannccda/service/AlertInfoService.java @@ -59,23 +59,23 @@ public class AlertInfoService { return findList; } - public NccAlertInfo createAlert(AlertType alertType, AlertDeviceType dt, String layoutId, MessageOrBuilder mb, String targetDeviceCode) { + public NccAlertInfo createAlert(AlertType alertType, AlertDeviceType dt, String layoutId, MessageOrBuilder mb, String targetDeviceCode, 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); + return this.createAlert2(areaConfigOptional, alertType, mb, targetDeviceCode, mockData); } - public NccAlertInfo createAlert2(Optional areaConfigOpt, AlertType alertType, MessageOrBuilder mb, String targetDeviceCode) { + public NccAlertInfo createAlert2(Optional areaConfigOpt, AlertType alertType, MessageOrBuilder mb, String targetDeviceCode, 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); + 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()); + return new NccAlertInfo(createTime, alertType, lineId, alertObject, deviceCode, areaConfig.getId(), mockData); } /* @Deprecated diff --git a/src/main/java/club/joylink/xiannccda/service/AlertMockService.java b/src/main/java/club/joylink/xiannccda/service/AlertMockService.java index 030a8b5..52a590a 100644 --- a/src/main/java/club/joylink/xiannccda/service/AlertMockService.java +++ b/src/main/java/club/joylink/xiannccda/service/AlertMockService.java @@ -5,20 +5,35 @@ import club.joylink.xiannccda.alert.NccAlertInfo; import club.joylink.xiannccda.alert.core.AlertDeviceType; import club.joylink.xiannccda.alert.core.AlertManager; import club.joylink.xiannccda.ats.cache.LineGraphicDataRepository; +import club.joylink.xiannccda.ats.message.collect.DeviceStatusDataOperate; import club.joylink.xiannccda.dto.AlertMockDTO; import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType; import club.joylink.xiannccda.dto.protos.DeviceStatusProto; +import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Rtu; import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Switch; import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Track; import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto; +import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.LogicSection; import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Platform; import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Section; import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Station; import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Turnout; import club.joylink.xiannccda.exception.BusinessExceptionAssertEnum; +import com.google.protobuf.GeneratedMessageV3; import com.google.protobuf.MessageOrBuilder; import java.time.LocalDateTime; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.Optional; +import java.util.function.Function; +import java.util.stream.Collectors; import java.util.stream.Stream; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -40,6 +55,132 @@ public class AlertMockService { alertManager.emit(alertDetail); } + public void setAlert2(AlertMockDTO alertMockDTO) { + NccAlertInfo alertInfo = this.buildNccAlert2(alertMockDTO); + AlertManager alertManager = AlertManager.getDefault(); + alertManager.emit(alertInfo); + } + + public NccAlertInfo buildNccAlert2(AlertMockDTO dto) { + int lineId = dto.getLineId(); + switch (dto.getAlertType()) { + case BLUE_DISPLAY -> { + Optional stationOptional = LineGraphicDataRepository.getDevices(lineId, Station.class).filter(Station::getConcentrationStations) + .filter(d -> dto.getDeviceCodes().contains(d.getCode())).findAny(); + Station station = stationOptional.orElse(null); + Rtu.Builder bb = Rtu.newBuilder(); + bb.setLineId(dto.getLineId()); + bb.setTimestamp(System.currentTimeMillis() / 1000); + bb.setId(dto.getFrist()); + bb.setIpRtuStusDown(true); + return this.alertInfoService.createAlert(dto.getAlertType(), AlertDeviceType.DEVICE_TYPE_RTU, station.getCommon().getId(), bb, station.getName(), true); + } + case PLATFORM_DOOR_CANNOT_OPEN -> { + Optional pfOptional = LineGraphicDataRepository.getDevices(lineId, Platform.class).filter(d -> dto.getDeviceCodes().contains(d.getCode())).findAny(); + DeviceStatusProto.Platform.Builder platform = DeviceStatusProto.Platform.newBuilder(); + platform.setId(dto.getFrist()); + platform.setTrainberth(true); + platform.setLineId(dto.getLineId()); + platform.setTimestamp(System.currentTimeMillis() / 1000); + Platform pf = pfOptional.orElse(null); + return this.alertInfoService.createAlert(dto.getAlertType(), AlertDeviceType.DEVICE_TYPE_PLATFORM, pf.getCommon().getId(), platform, platform.getId(), true); + } + case PLATFORM_DOOR_CANNOT_CLOSE -> { + Optional pfOptional = LineGraphicDataRepository.getDevices(lineId, Platform.class).filter(d -> dto.getDeviceCodes().contains(d.getCode())).findAny(); + DeviceStatusProto.Platform.Builder platform = DeviceStatusProto.Platform.newBuilder(); + platform.setId(dto.getFrist()); + platform.setPsdOpen(true); + platform.setTrainberth(true); + platform.setLineId(dto.getLineId()); + platform.setTimestamp(System.currentTimeMillis() / 1000); + Platform pf = pfOptional.orElse(null); + return this.alertInfoService.createAlert(dto.getAlertType(), AlertDeviceType.DEVICE_TYPE_PLATFORM, pf.getCommon().getId(), platform, platform.getId(), true); + } +/* case SWITCH_LOST -> { + Optional turnoutOptional = LineGraphicDataRepository.getDevices(lineId, Turnout.class).filter(d -> dto.getDeviceCodes().contains(d.getCode())).findAny(); + Switch.Builder switchs = Switch.newBuilder(); + switchs.setId(dto.getFrist()); + switchs.setLineId(dto.getLineId()); + switchs.setTimestamp(System.currentTimeMillis() / 1000); + switchs.setIpSingleSwitchStusLostIndication(true); + switchs.setReceiveTime(System.currentTimeMillis()); + Turnout turnout = turnoutOptional.orElse(null); + NccAlertInfo alertInfo = this.alertInfoService.createAlert(dto.getAlertType(), AlertDeviceType.DEVICE_TYPE_SWITCH, turnout.getCommon().getId(), switchs, switchs.getId(), true); + }*/ + case SWITCH_LOST, SWITCH_LOST_MOST -> { + Optional turnoutOptional = LineGraphicDataRepository.getDevices(lineId, Turnout.class).filter(d -> dto.getDeviceCodes().contains(d.getCode())).findAny(); + Switch.Builder switchs = Switch.newBuilder(); + switchs.setId(dto.getFrist()); + switchs.setLineId(dto.getLineId()); + switchs.setTimestamp(System.currentTimeMillis() / 1000); + switchs.setReceiveTime(System.currentTimeMillis()); + switchs.setIpSingleSwitchStusLostIndication(true); + 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 -> { + Optional lsOptional = LineGraphicDataRepository.getDevices(lineId, LogicSection.class).filter(d -> dto.getDeviceCodes().contains(d.getCode())).findAny(); + Track.Builder track = Track.newBuilder(); + track.setId(dto.getFrist()); + track.setLineId(dto.getLineId()); + track.setTimestamp(System.currentTimeMillis() / 1000); + LogicSection ls = lsOptional.orElse(null); + return this.alertInfoService.createAlert(dto.getAlertType(), AlertDeviceType.DEVICE_TYPE_TRACK, ls.getCommon().getId(), track, dto.getAll(), true); + } + case TRAIN_EB_ATP -> { + + Optional lsOptional = LineGraphicDataRepository.getDevices(lineId, LogicSection.class).filter(d -> dto.getDeviceCodes().contains(d.getCode())).findAny(); + + Track.Builder track = Track.newBuilder(); + track.setId(dto.getFrist()); + track.setLineId(dto.getLineId()); + track.setTimestamp(System.currentTimeMillis() / 1000); + LogicSection ls = lsOptional.orElse(null); + + return this.alertInfoService.createAlert(AlertType.TRAIN_EB_ATP, AlertDeviceType.DEVICE_TYPE_TRAIN, ls.getCommon().getId(), track, "测试车组号", true); + + } + default -> throw new IllegalStateException("Unexpected value: " + dto.getAlertType()); + } + } + + public List findAlertType(int lineId, AlertType alertType) { + Collection messages = this.findDevice(lineId, alertType); + List amList = messages.stream().sorted((o1, o2) -> { + String code1 = DeviceStatusDataOperate.findFieldVal(o1, "code", String.class); + String code2 = DeviceStatusDataOperate.findFieldVal(o2, "code", String.class); + return String.CASE_INSENSITIVE_ORDER.compare(code1, code2); + }).map(d -> { + String name = DeviceStatusDataOperate.findFieldVal(d, "name", String.class); + String code = DeviceStatusDataOperate.findFieldVal(d, "code", String.class); + return new AlertMockDeviceInfo(name, code); + }).collect(Collectors.toList()); + return amList; + } + + + private Collection findDevice(int lineId, AlertType alertType) { + switch (alertType) { + case BLUE_DISPLAY -> { + return LineGraphicDataRepository.getDevices(lineId, Station.class).filter(Station::getConcentrationStations) + .collect(Collectors.toMap(d -> d.getCommon().getId(), Function.identity(), (v1, v2) -> v1)).values(); + } + case PLATFORM_DOOR_CANNOT_OPEN, PLATFORM_DOOR_CANNOT_CLOSE -> { + return LineGraphicDataRepository.getDevices(lineId, Platform.class) + .collect(Collectors.toMap(d -> d.getCommon().getId(), Function.identity(), (v1, v2) -> v1)).values(); + } + 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 -> { + return LineGraphicDataRepository.getDevices(lineId, LogicSection.class) + .collect(Collectors.toMap(d -> d.getCommon().getId(), Function.identity(), (v1, v2) -> v1)).values(); + + } + default -> throw new IllegalStateException("Unexpected value: " + alertType); + } + } + private NccAlertInfo buildNccAlert(AlertType alertType, int lineId) { MessageOrBuilder messageOrBuilder; switch (alertType) { @@ -59,7 +200,7 @@ public class AlertMockService { switchBuild.setIpSingleSwitchStusLocked(true); switchBuild.setReceiveTime(System.currentTimeMillis()); Turnout turnout = LineGraphicDataRepository.getDeviceByCode(lineId, switchBuild.getId(), Turnout.class); - NccAlertInfo alertInfo = this.alertInfoService.createAlert(AlertType.SWITCH_LOST, AlertDeviceType.DEVICE_TYPE_SWITCH, turnout.getCommon().getId(), switchBuild, switchBuild.getId()); + NccAlertInfo alertInfo = this.alertInfoService.createAlert(AlertType.SWITCH_LOST, AlertDeviceType.DEVICE_TYPE_SWITCH, turnout.getCommon().getId(), switchBuild, switchBuild.getId(), true); alertInfo.setMock(true); return alertInfo; } @@ -71,7 +212,7 @@ public class AlertMockService { track.setLineId(lineId); String sectionCode = LineGraphicDataRepository.findSectionFromLogicCode(lineId, "G0202-A"); Section section = LineGraphicDataRepository.getDeviceByCode(lineId, sectionCode, Section.class); - NccAlertInfo alertInfo = this.alertInfoService.createAlert(AlertType.SWITCH_LOST, AlertDeviceType.DEVICE_TYPE_SWITCH, section.getCommon().getId(), track, track.getId()); + NccAlertInfo alertInfo = this.alertInfoService.createAlert(AlertType.SWITCH_LOST, AlertDeviceType.DEVICE_TYPE_SWITCH, section.getCommon().getId(), track, track.getId(), true); alertInfo.setMock(true); return alertInfo; } @@ -84,7 +225,7 @@ public class AlertMockService { track.setLineId(lineId); String sectionCode = LineGraphicDataRepository.findSectionFromLogicCode(lineId, "G0202-A"); Section section = LineGraphicDataRepository.getDeviceByCode(lineId, sectionCode, Section.class); - NccAlertInfo alertInfo = this.alertInfoService.createAlert(AlertType.AXLE_LED_ORANGE, AlertDeviceType.DEVICE_TYPE_TRACK, section.getCommon().getId(), track, track.getId()); + NccAlertInfo alertInfo = this.alertInfoService.createAlert(AlertType.AXLE_LED_ORANGE, AlertDeviceType.DEVICE_TYPE_TRACK, section.getCommon().getId(), track, track.getId(), true); alertInfo.setMock(true); return alertInfo; } @@ -93,7 +234,7 @@ public class AlertMockService { platform.setLineId(lineId); platform.setId("PF02301").setReceiveTime(System.currentTimeMillis()).setTrainberth(true); LayoutGraphicsProto.Platform platform2 = LineGraphicDataRepository.getDeviceByCode(lineId, platform.getId(), LayoutGraphicsProto.Platform.class); - NccAlertInfo alertInfo = this.alertInfoService.createAlert(alertType, AlertDeviceType.DEVICE_TYPE_PLATFORM, platform2.getCommon().getId(), platform, platform.getId()); + NccAlertInfo alertInfo = this.alertInfoService.createAlert(alertType, AlertDeviceType.DEVICE_TYPE_PLATFORM, platform2.getCommon().getId(), platform, platform.getId(), true); alertInfo.setMock(true); return alertInfo; } @@ -102,16 +243,11 @@ public class AlertMockService { platform.setLineId(lineId); platform.setId("PF02301").setReceiveTime(System.currentTimeMillis()).setTrainberth(true).setPsdOpen(true); LayoutGraphicsProto.Platform platform2 = LineGraphicDataRepository.getDeviceByCode(lineId, platform.getId(), LayoutGraphicsProto.Platform.class); - NccAlertInfo alertInfo = this.alertInfoService.createAlert(alertType, AlertDeviceType.DEVICE_TYPE_PLATFORM, platform2.getCommon().getId(), platform, platform.getId()); + NccAlertInfo alertInfo = this.alertInfoService.createAlert(alertType, AlertDeviceType.DEVICE_TYPE_PLATFORM, platform2.getCommon().getId(), platform, platform.getId(), true); alertInfo.setMock(true); return alertInfo; } - /* case TRAIN_EB_ATP -> { - }*/ - /*case TRAIN_DELAY_2, TRAIN_DELAY_10 -> { - messageOrBuilder = null; - }*/ case PLATFORM_DOOR_WITHOUT_LOCKED_SIGNAL -> { Stream stream = LineGraphicDataRepository.getDevices(lineId, Platform.class); messageOrBuilder = stream.findFirst() @@ -122,4 +258,20 @@ public class AlertMockService { return alertDetailFactory.getAlertDetail(LocalDateTime.now(), alertType, lineId, true, messageOrBuilder); } + + @Data + @NoArgsConstructor + public static class AlertMockDeviceInfo { + + private String name; + private String code; + + public AlertMockDeviceInfo(String name, String code) { + this.name = name; + this.code = code; + if (StringUtils.isEmpty(name)) { + this.name = this.code; + } + } + } } diff --git a/src/main/java/club/joylink/xiannccda/service/AlertRecordService.java b/src/main/java/club/joylink/xiannccda/service/AlertRecordService.java index 8117744..e6ca800 100644 --- a/src/main/java/club/joylink/xiannccda/service/AlertRecordService.java +++ b/src/main/java/club/joylink/xiannccda/service/AlertRecordService.java @@ -38,7 +38,7 @@ public class AlertRecordService { public AlertTip confirm(Long recordId, String tipType, Long locationId) { LambdaQueryWrapper qw = Wrappers.lambdaQuery(AlertTip.class).eq(AlertTip::getAlertType, tipType); - if (Objects.nonNull(locationId)) { + if (Objects.nonNull(locationId) && locationId > 0L) { qw.eq(AlertTip::getAreaConfigId, locationId); } AlertTip tip = alertTipRepository.getOne(qw);