This commit is contained in:
weizhihong 2023-07-25 11:12:14 +08:00
commit 7f21bb2281
2 changed files with 27 additions and 4 deletions

View File

@ -40,9 +40,8 @@ public class AlertListenerJob implements ApplicationRunner {
@Override @Override
public void accept(AlertDetail event) { public void accept(AlertDetail event) {
String id = String.valueOf(idGenerator.getAndIncrement()); String id = String.valueOf(idGenerator.getAndIncrement());
String level = "III";
LocalDateTime alertTime = event.getAlertTime(); LocalDateTime alertTime = event.getAlertTime();
NccAlertInfo<AlertDetail> nccAlertInfo = new NccAlertInfo<>(id, level, alertTime, event); NccAlertInfo<AlertDetail> nccAlertInfo = new NccAlertInfo<>(id, alertTime, event);
alertManager.emit(nccAlertInfo); alertManager.emit(nccAlertInfo);
} }
}); });

View File

@ -1,18 +1,26 @@
package club.joylink.xiannccda.alert; package club.joylink.xiannccda.alert;
import club.joylink.xiannccda.alert.core.AlertInfo; import club.joylink.xiannccda.alert.core.AlertInfo;
import club.joylink.xiannccda.exception.BusinessExceptionAssertEnum;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import lombok.NonNull;
@AllArgsConstructor
public class NccAlertInfo<D extends AlertDetail> implements AlertInfo { public class NccAlertInfo<D extends AlertDetail> implements AlertInfo {
private String id; private String id;
private String level; private String level;
private LocalDateTime alertTime; private LocalDateTime alertTime;
@Getter @Getter
private D detail; 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 @Override
public String getId() { public String getId() {
return id; return id;
@ -32,4 +40,20 @@ public class NccAlertInfo<D extends AlertDetail> implements AlertInfo {
public String getInfo() { public String getInfo() {
return ""; 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());
}
}
} }