This commit is contained in:
Superdandan 2024-04-07 21:55:53 +08:00
parent 49d27cfcec
commit 35e4a71cfb
2 changed files with 51 additions and 0 deletions

View File

@ -0,0 +1,28 @@
package com.chint.domain.aggregates.base;
import lombok.Data;
import java.time.LocalDateTime;
import java.util.Map;
@Data
public abstract class BaseEvent {
private Integer eventType;
private transient String eventName;
private LocalDateTime happenTime;
// 新增抽象方法获取状态码与状态名称的映射表
protected abstract Map<Integer, String> getStatusMappings();
// 实现reloadStatus方法使用状态映射表更新状态名称
public BaseEvent reloadStatus() {
Map<Integer, String> mappings = getStatusMappings();
if (mappings != null) {
this.eventName = mappings.getOrDefault(this.eventType, "未知状态");
}
return this;
}
}

View File

@ -0,0 +1,23 @@
package com.chint.domain.aggregates.base;
import java.util.Comparator;
import java.util.List;
import java.util.NoSuchElementException;
public interface EventManageable {
// 抽象方法获取事件列表
List<BaseEvent> getEvents();
// 默认方法添加事件
default void addEvent(BaseEvent event) {
getEvents().add(event);
}
// 默认方法获取最新的事件
default BaseEvent getLastEvent() {
return getEvents().stream()
.max(Comparator.comparing(BaseEvent::getHappenTime))
.orElseThrow(() -> new NoSuchElementException("No events found."));
}
}