This commit is contained in:
parent
49d27cfcec
commit
35e4a71cfb
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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."));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue