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()); + } + } }