Local review candidate only. Explicitly selected inherited prerequisites and prior repair patches; unrelated WIP and independent MQ fixes are excluded. No push or deployment authorized.
96 lines
3.9 KiB
Java
96 lines
3.9 KiB
Java
package com.yunhai.flowcenter.engine;
|
||
|
||
import lombok.Getter;
|
||
import lombok.RequiredArgsConstructor;
|
||
|
||
import java.util.HashMap;
|
||
import java.util.Map;
|
||
|
||
/**
|
||
* 引擎关键状态变迁事件(概览 §5.2 v1.1 增补):事务内发布,AFTER_COMMIT 后由
|
||
* CallbackDispatcher(回调给业务方)与 UserMsgNotifier(通知人)消费——引擎本身不知道
|
||
* 也不依赖任何业务方的存在。携带 instanceId 而非实体快照:监听方在提交后按需重读(含最新 version)。
|
||
*/
|
||
@Getter
|
||
@RequiredArgsConstructor
|
||
public class FlowEvent {
|
||
|
||
public enum Type {
|
||
/** 代发起/重提成功(instance=10) */
|
||
SUBMITTED("flow.submitted"),
|
||
/** 任一审批任务创建(并行会签每个任务各发一条,data 带 n/m 汇总) */
|
||
TASK_CREATED("flow.task.created"),
|
||
/** 任一任务被办理(同意/拒绝各发一条,进度同步用) */
|
||
TASK_HANDLED("flow.task.handled"),
|
||
/** END 激活,instance=20 */
|
||
COMPLETED("flow.completed"),
|
||
/** END_REJECTED,instance=30 */
|
||
REJECTED("flow.rejected"),
|
||
/** 提交人撤回,instance=40 */
|
||
WITHDRAWN("flow.withdrawn"),
|
||
/** 办理人退回上游节点(办件仍在途,instance 仍=10) */
|
||
RETURNED("flow.returned"),
|
||
/** 办理人移交办理权给他人(任务换人,办件仍在途) */
|
||
TRANSFERRED("flow.transferred"),
|
||
/** NOTIFY 抄送(逐接收人一条,瞬时放行不建任务;data 带 ccId/ccUserId/ccUserName) */
|
||
CC_SENT("flow.cc.sent"),
|
||
/** CONDITION 判断落定(订阅制,供业务侧审计"为什么走了这条线";data 带 nodeId/nodeName/routerKey/outlet) */
|
||
ROUTE_DECIDED("flow.route.decided"),
|
||
/** 催办(仅 UserMsg 通道,非回调事件枚举) */
|
||
URGE("flow.urge");
|
||
|
||
private final String code;
|
||
|
||
Type(String code) {
|
||
this.code = code;
|
||
}
|
||
|
||
public String getCode() {
|
||
return code;
|
||
}
|
||
|
||
public static Type ofCode(String code) {
|
||
for (Type t : values()) {
|
||
if (t.code.equals(code)) {
|
||
return t;
|
||
}
|
||
}
|
||
return null;
|
||
}
|
||
}
|
||
|
||
private final Type type;
|
||
private final Long instanceId;
|
||
/** 任务事件带 taskId(SUBMITTED 等办件级事件为 null) */
|
||
private final Long taskId;
|
||
/** 操作人 id(谁导致本事件;回调信封提升为 operatorUserId)。可空:语义见《子应用接入流程中心规范.md》§6.4 */
|
||
private final Integer operatorId;
|
||
/** 操作人姓名快照。可空 */
|
||
private final String operatorName;
|
||
/** 事件明细(result/opinion/rejectNode/task.created 的 n/m 等),可为空 */
|
||
private final Map<String, Object> data;
|
||
private Map<String, Object> roundIdentity;
|
||
|
||
public void captureRoundIdentity(Integer round, String requestToken) {
|
||
if (roundIdentity != null) return;
|
||
Map<String, Object> identity = new HashMap<>();
|
||
identity.put("applyRound", round);
|
||
identity.put("requestToken", requestToken);
|
||
roundIdentity = java.util.Collections.unmodifiableMap(identity);
|
||
}
|
||
|
||
public static FlowEvent of(Type type, Long instanceId) {
|
||
return new FlowEvent(type, instanceId, null, null, null, new HashMap<>());
|
||
}
|
||
|
||
public static FlowEvent of(Type type, Long instanceId, Long taskId, Map<String, Object> data) {
|
||
return new FlowEvent(type, instanceId, taskId, null, null, data == null ? new HashMap<>() : data);
|
||
}
|
||
|
||
public static FlowEvent of(Type type, Long instanceId, Long taskId,
|
||
Integer operatorId, String operatorName, Map<String, Object> data) {
|
||
return new FlowEvent(type, instanceId, taskId, operatorId, operatorName,
|
||
data == null ? new HashMap<>() : data);
|
||
}
|
||
}
|