This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
package com.yunhai.userbase.event;
|
||||
|
||||
import com.yunhai.userbase.entity.ApplicationInfo;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
/**
|
||||
* 应用密钥/元数据变更事件:在 ApplicationInfoService 的 save/add/edit/delete/resetSecret 等事务内发布,
|
||||
* 由 SignKeyCacheService 的 @TransactionalEventListener(phase = AFTER_COMMIT 订阅,
|
||||
* 保证 DB 真正提交成功后再写共享 Redis / 清本地缓存,避免事务回滚导致的脏数据。
|
||||
*/
|
||||
public class ApplicationInfoCacheChangedEvent extends ApplicationEvent {
|
||||
|
||||
public enum Type {
|
||||
UPSERT, DELETE
|
||||
}
|
||||
|
||||
private final Type type;
|
||||
private final Integer appKey;
|
||||
|
||||
/**
|
||||
* 删除事件:appKey 必填;upsert 事件:可以传 entity 非空。
|
||||
*/
|
||||
private final ApplicationInfo upsertEntity;
|
||||
|
||||
public ApplicationInfoCacheChangedEvent(Object source, Type type, Integer appKey, ApplicationInfo upsertEntity) {
|
||||
super(source);
|
||||
this.type = type;
|
||||
this.appKey = appKey;
|
||||
this.upsertEntity = upsertEntity;
|
||||
}
|
||||
|
||||
public static ApplicationInfoCacheChangedEvent upsert(Object source, ApplicationInfo entity) {
|
||||
return new ApplicationInfoCacheChangedEvent(source, Type.UPSERT, entity.getAppKey(), entity);
|
||||
}
|
||||
|
||||
public static ApplicationInfoCacheChangedEvent delete(Object source, Integer appKey) {
|
||||
return new ApplicationInfoCacheChangedEvent(source, Type.DELETE, appKey, null);
|
||||
}
|
||||
|
||||
public Type getType() { return type; }
|
||||
|
||||
public Integer getAppKey() { return appKey; }
|
||||
|
||||
public ApplicationInfo getUpsertEntity() { return upsertEntity; }
|
||||
}
|
||||
Reference in New Issue
Block a user