From f4454c96c58aa326b4ea7a9d50b0c310df4a0558 Mon Sep 17 00:00:00 2001 From: joylink_zhangsai <1021828630@qq.com> Date: Tue, 25 Jul 2023 09:56:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=8A=A5=E8=AD=A6=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E7=BA=A7=E5=88=AB=EF=BC=88=E5=88=97=E8=BD=A6=E5=BB=B6?= =?UTF-8?q?=E8=AF=AF2=E5=88=86=E9=92=9FIII=E7=BA=A7=EF=BC=8C=E5=85=B6?= =?UTF-8?q?=E4=BD=99=E9=83=BD=E6=98=AFI=E7=BA=A7=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xiannccda/alert/AlertListenerJob.java | 3 +- .../joylink/xiannccda/alert/NccAlertInfo.java | 28 +++++++++++++++++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/main/java/club/joylink/xiannccda/alert/AlertListenerJob.java b/src/main/java/club/joylink/xiannccda/alert/AlertListenerJob.java index c462a38..852fb76 100644 --- a/src/main/java/club/joylink/xiannccda/alert/AlertListenerJob.java +++ b/src/main/java/club/joylink/xiannccda/alert/AlertListenerJob.java @@ -40,9 +40,8 @@ public class AlertListenerJob implements ApplicationRunner { @Override public void accept(AlertDetail event) { String id = String.valueOf(idGenerator.getAndIncrement()); - String level = "III"; LocalDateTime alertTime = event.getAlertTime(); - NccAlertInfo nccAlertInfo = new NccAlertInfo<>(id, level, alertTime, event); + NccAlertInfo nccAlertInfo = new NccAlertInfo<>(id, alertTime, event); alertManager.emit(nccAlertInfo); } }); diff --git a/src/main/java/club/joylink/xiannccda/alert/NccAlertInfo.java b/src/main/java/club/joylink/xiannccda/alert/NccAlertInfo.java index 3a968f7..e224911 100644 --- a/src/main/java/club/joylink/xiannccda/alert/NccAlertInfo.java +++ b/src/main/java/club/joylink/xiannccda/alert/NccAlertInfo.java @@ -1,18 +1,26 @@ package club.joylink.xiannccda.alert; import club.joylink.xiannccda.alert.core.AlertInfo; +import club.joylink.xiannccda.exception.BusinessExceptionAssertEnum; import java.time.LocalDateTime; -import lombok.AllArgsConstructor; import lombok.Getter; +import lombok.NonNull; -@AllArgsConstructor public class NccAlertInfo implements AlertInfo { + private String id; private String level; private LocalDateTime alertTime; @Getter private D detail; + public NccAlertInfo(@NonNull String id, @NonNull LocalDateTime alertTime, @NonNull D detail) { + this.id = id; + this.alertTime = alertTime; + this.detail = detail; + this.level = getLevelFromDetail(); + } + @Override public String getId() { return id; @@ -32,4 +40,20 @@ public class NccAlertInfo implements AlertInfo { public String getInfo() { return ""; } + + private String getLevelFromDetail() { + switch (detail.getAlertType()) { + case UNKNOWN, UNRECOGNIZED -> { + throw BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.exception(); + } + case TRAIN_DELAY_2 -> { + return "III"; + } + case BLUE_DISPLAY, PLATFORM_DOOR_CANNOT_CLOSE, PLATFORM_DOOR_CANNOT_OPEN, + PLATFORM_DOOR_WITHOUT_LOCKED_SIGNAL, TRAIN_DELAY_10 -> { + return "I"; + } + default -> throw new IllegalStateException("Unexpected value: " + detail.getAlertType()); + } + } }