@mldong/jeeflow 1.8.26 → 1.8.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/engine.d.ts +57 -4
- package/dist/engine.js +236 -90
- package/dist/facade.d.ts +7 -0
- package/dist/facade.js +148 -18
- package/dist/index.d.ts +3 -2
- package/dist/index.js +1 -0
- package/dist/jdbc/ext.d.ts +18 -1
- package/dist/jdbc/ext.js +29 -11
- package/dist/memory-ext.d.ts +17 -0
- package/dist/memory-ext.js +30 -13
- package/dist/metadata.js +1 -1
- package/dist/model.d.ts +9 -2
- package/dist/model.js +14 -4
- package/dist/surrogate-rule.d.ts +34 -0
- package/dist/surrogate-rule.js +97 -0
- package/package.json +1 -1
package/dist/engine.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ProcessInstance } from './model.js';
|
|
2
|
-
import type { ProcessRepository, UserProvider, IDGenerator, ExpressionEvaluator } from './spi.js';
|
|
2
|
+
import type { ProcessRepository, ProcessExtRepository, UserProvider, IDGenerator, ExpressionEvaluator } from './spi.js';
|
|
3
3
|
import { type EngineExtensions, type ProcessEvent } from './extensions.js';
|
|
4
4
|
import { HandlerRegistry } from './registry.js';
|
|
5
5
|
export declare const KeySubmitType = "submitType";
|
|
@@ -22,6 +22,19 @@ export interface Engine {
|
|
|
22
22
|
executeAndJumpTask(taskId: string, operator: string, args: Record<string, any>, targetTaskName?: string): Promise<ProcessInstance>;
|
|
23
23
|
executeAndJumpToFirstTaskNode(taskId: string, operator: string, args?: Record<string, any>): Promise<ProcessInstance>;
|
|
24
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* 委托代理自动生效的注入面(issues/116)——只需要 getSurrogate 一侧能力,
|
|
27
|
+
* 完整 ProcessExtRepository 天然满足;传 `{ getSurrogate: async () => null }`
|
|
28
|
+
* 即为"注册空实现"关闭形态。
|
|
29
|
+
*/
|
|
30
|
+
export type SurrogateLookup = Pick<ProcessExtRepository, 'getSurrogate'>;
|
|
31
|
+
/** 引擎委托配置(构造参数与 setSurrogateOptions 共用同一形状) */
|
|
32
|
+
export interface EngineOptions {
|
|
33
|
+
/** 委托查询源;不传 = 未配置扩展仓储 → 引擎静默跳过委托(不打断建单) */
|
|
34
|
+
surrogateRepository?: SurrogateLookup | null;
|
|
35
|
+
/** 委托自动生效开关,**默认 true(引擎内置开启)**;显式传 false → 回到"仅台账"行为 */
|
|
36
|
+
surrogateEnabled?: boolean;
|
|
37
|
+
}
|
|
25
38
|
export declare class EngineImpl implements Engine {
|
|
26
39
|
#private;
|
|
27
40
|
private repo;
|
|
@@ -30,7 +43,33 @@ export declare class EngineImpl implements Engine {
|
|
|
30
43
|
private exprEval?;
|
|
31
44
|
private ext?;
|
|
32
45
|
private registry?;
|
|
33
|
-
|
|
46
|
+
private surrogateRepo?;
|
|
47
|
+
private surrogateOn;
|
|
48
|
+
constructor(repo: ProcessRepository, userProv?: UserProvider | undefined, idGen?: IDGenerator | undefined, exprEval?: ExpressionEvaluator | undefined, opts?: EngineOptions);
|
|
49
|
+
/**
|
|
50
|
+
* issues/116:注入/摘除委托查询源(ProcessExtRepository 或任何实现 getSurrogate 的对象)。
|
|
51
|
+
* 传 null 摘除 = 关闭委托自动生效(回到"仅台账")。不影响已设置的开关。
|
|
52
|
+
*/
|
|
53
|
+
setSurrogateRepository(repo: SurrogateLookup | null): this;
|
|
54
|
+
/**
|
|
55
|
+
* issues/116:委托自动生效开关(**默认开启**)。传 false 显式关闭 → 建单不再并入代理人。
|
|
56
|
+
*/
|
|
57
|
+
setSurrogateEnabled(enabled: boolean): this;
|
|
58
|
+
/** issues/116:组合设置(与构造参数同形状),未给的字段保持现状 */
|
|
59
|
+
setSurrogateOptions(opts: EngineOptions): this;
|
|
60
|
+
/** 委托自动生效当前是否启用(只读,供集成层自检/测试用) */
|
|
61
|
+
isSurrogateEnabled(): boolean;
|
|
62
|
+
/** defineId → wf_process_define.name 缓存(仅"模型未带 name"的回落路径用得到) */
|
|
63
|
+
private defineNameCache;
|
|
64
|
+
/**
|
|
65
|
+
* issues/116 契约 1.1:委托查询的 processName **以流程模型 name 为准**
|
|
66
|
+
* (迁移基线 = 内置版 SurrogateInterceptor 取的 `execution.getProcessModel().getName()`),
|
|
67
|
+
* 模型未带 name(缺失/空串/纯空白)时才回落 `wf_process_define.name`。
|
|
68
|
+
* 正常 deploy 两者恒等(saveDeployedDefine 执行 `def.name = flow.name`),但直接落库的
|
|
69
|
+
* 定义(测试 loadFlow、集成方自带导入链路)会不一致——取错那一头,用户在内置版配的
|
|
70
|
+
* 委托迁到 jeeflow 后就不再命中。对齐 Go `EngineImpl.surrogateProcessName` 同判据同姿势。
|
|
71
|
+
*/
|
|
72
|
+
private surrogateProcessName;
|
|
34
73
|
setExtensions(ext: EngineExtensions): void;
|
|
35
74
|
setRegistry(reg: HandlerRegistry): void;
|
|
36
75
|
private interceptorCache;
|
|
@@ -51,9 +90,20 @@ export declare class EngineImpl implements Engine {
|
|
|
51
90
|
executeAndJumpTask(taskId: string, operator: string, args?: Record<string, any>, targetTaskName?: string): Promise<ProcessInstance>;
|
|
52
91
|
executeAndJumpToFirstTaskNode(taskId: string, operator: string, args?: Record<string, any>): Promise<ProcessInstance>;
|
|
53
92
|
private prepareExecuteTask;
|
|
54
|
-
private previousTaskName;
|
|
55
93
|
private isFirstTaskNode;
|
|
56
|
-
|
|
94
|
+
/**
|
|
95
|
+
* 退回上一步(血缘版,规范 04 · 退回上一步):上一步来源=当前行的 parentTaskId,
|
|
96
|
+
* 复活那条历史行;不按模型入边拓扑推(拓扑版在分支/回环流会回到本实例没走过的节点,
|
|
97
|
+
* 还会静默留下"实例 DOING 却零待办")。对外 msg 用固定中文文案、不含引擎内部码(出口统一 99999999)。
|
|
98
|
+
*/
|
|
99
|
+
private rollbackToParent;
|
|
100
|
+
/**
|
|
101
|
+
* issues/116:对每个参与人查一次生效委托(判据在仓储侧:空 processName 全流程兜底 /
|
|
102
|
+
* 时间窗 / 自委托过滤 / enabled 只认 1)。返回 actor → 代理人 映射。
|
|
103
|
+
* 未配置查询源、显式关闭、无参与人 → 空映射(= 原样参与者,不打断建单);
|
|
104
|
+
* 单条查询异常只记录不传播(委托是增强能力,建单主流程不得被拖崩)。
|
|
105
|
+
*/
|
|
106
|
+
private surrogateAgents;
|
|
57
107
|
private createTaskWithActors;
|
|
58
108
|
private loadAndCheck;
|
|
59
109
|
private executeNode;
|
|
@@ -68,6 +118,9 @@ export declare class EngineImpl implements Engine {
|
|
|
68
118
|
getUserProvider(): UserProvider | undefined;
|
|
69
119
|
private nextId;
|
|
70
120
|
}
|
|
121
|
+
/** issues/116:把代理人并入参与者集合——授权人保留、原顺序不动、代理人按参与人顺序追加、去重。
|
|
122
|
+
* 返回新数组(无代理命中时返回原数组引用,零开销)。 */
|
|
123
|
+
export declare function mergeAgents(actors: string[], agents: Map<string, string>): string[];
|
|
71
124
|
/** 会签判定(issue 42,对齐 Java ProcessTaskPerformTypeEnum.codeOf):
|
|
72
125
|
* '1' / 'ALL' / 'COUNTERSIGN'(大小写不敏感)→ 会签。
|
|
73
126
|
* 设计器属性面板保存 'ALL' 字符串符合 Java 契约,引擎必须兼容 */
|
package/dist/engine.js
CHANGED
|
@@ -17,6 +17,41 @@ export const KeyAutoExecute = 'flow.auto';
|
|
|
17
17
|
export const KeyAdminID = 'flow.admin';
|
|
18
18
|
// issue 29:自动生成标题(对齐 boot3 FlowConst.AUTO_GEN_TITLE)
|
|
19
19
|
export const KeyAutoGenTitle = 'autoGenTitle';
|
|
20
|
+
/**
|
|
21
|
+
* 照 mldong-boot2 NodeModel.canRejected:自 current 的入边回溯,命中 parent 放行;
|
|
22
|
+
* 入边来源是 fork/join/start 时**跳过该条入边、不再深入**(boot2 是 continue,不是穿越),
|
|
23
|
+
* 其余来源递归。subprocess 在 boot2 里被注释掉,等同普通节点。
|
|
24
|
+
*/
|
|
25
|
+
function canRejected(flow, currentId, parentId) {
|
|
26
|
+
for (const edge of flow.edges) {
|
|
27
|
+
if (edge.targetNodeId !== currentId)
|
|
28
|
+
continue;
|
|
29
|
+
if (edge.sourceNodeId === parentId)
|
|
30
|
+
return true;
|
|
31
|
+
const src = findNode(flow, edge.sourceNodeId);
|
|
32
|
+
if (!src)
|
|
33
|
+
continue;
|
|
34
|
+
if (src.type === TypeFork || src.type === TypeJoin || src.type === TypeStart)
|
|
35
|
+
continue;
|
|
36
|
+
if (canRejected(flow, src.id, parentId))
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
// 复活行的变量净化:剔控制类残留(submitType / taskName / tf_ 前缀 / csv_ 前缀 / 会签簿记),
|
|
42
|
+
// 保留 f_ 表单字段、u_ 用户快照、autoGenTitle、isFirstTaskNode。
|
|
43
|
+
function lineageVars(src) {
|
|
44
|
+
const out = {};
|
|
45
|
+
for (const [k, v] of Object.entries(src ?? {})) {
|
|
46
|
+
if (k === 'submitType' || k === 'taskName'
|
|
47
|
+
|| k.startsWith('tf_') || k.startsWith('csv_')
|
|
48
|
+
|| k.startsWith('loopCounter') || k.startsWith('nrOfInstances')
|
|
49
|
+
|| k.startsWith('operatorList'))
|
|
50
|
+
continue;
|
|
51
|
+
out[k] = v;
|
|
52
|
+
}
|
|
53
|
+
return out;
|
|
54
|
+
}
|
|
20
55
|
export class EngineImpl {
|
|
21
56
|
repo;
|
|
22
57
|
userProv;
|
|
@@ -24,11 +59,76 @@ export class EngineImpl {
|
|
|
24
59
|
exprEval;
|
|
25
60
|
ext;
|
|
26
61
|
registry;
|
|
27
|
-
|
|
62
|
+
// issues/116:委托代理自动生效——内置能力,注入查询源后默认开启
|
|
63
|
+
surrogateRepo;
|
|
64
|
+
surrogateOn = true;
|
|
65
|
+
constructor(repo, userProv, idGen, exprEval, opts) {
|
|
28
66
|
this.repo = repo;
|
|
29
67
|
this.userProv = userProv;
|
|
30
68
|
this.idGen = idGen;
|
|
31
69
|
this.exprEval = exprEval;
|
|
70
|
+
if (opts?.surrogateRepository !== undefined)
|
|
71
|
+
this.surrogateRepo = opts.surrogateRepository;
|
|
72
|
+
if (opts?.surrogateEnabled !== undefined)
|
|
73
|
+
this.surrogateOn = opts.surrogateEnabled;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* issues/116:注入/摘除委托查询源(ProcessExtRepository 或任何实现 getSurrogate 的对象)。
|
|
77
|
+
* 传 null 摘除 = 关闭委托自动生效(回到"仅台账")。不影响已设置的开关。
|
|
78
|
+
*/
|
|
79
|
+
setSurrogateRepository(repo) {
|
|
80
|
+
this.surrogateRepo = repo;
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* issues/116:委托自动生效开关(**默认开启**)。传 false 显式关闭 → 建单不再并入代理人。
|
|
85
|
+
*/
|
|
86
|
+
setSurrogateEnabled(enabled) {
|
|
87
|
+
this.surrogateOn = enabled;
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
/** issues/116:组合设置(与构造参数同形状),未给的字段保持现状 */
|
|
91
|
+
setSurrogateOptions(opts) {
|
|
92
|
+
if (opts.surrogateRepository !== undefined)
|
|
93
|
+
this.surrogateRepo = opts.surrogateRepository;
|
|
94
|
+
if (opts.surrogateEnabled !== undefined)
|
|
95
|
+
this.surrogateOn = opts.surrogateEnabled;
|
|
96
|
+
return this;
|
|
97
|
+
}
|
|
98
|
+
/** 委托自动生效当前是否启用(只读,供集成层自检/测试用) */
|
|
99
|
+
isSurrogateEnabled() {
|
|
100
|
+
return this.surrogateOn && this.surrogateRepo != null;
|
|
101
|
+
}
|
|
102
|
+
/** defineId → wf_process_define.name 缓存(仅"模型未带 name"的回落路径用得到) */
|
|
103
|
+
defineNameCache = new Map();
|
|
104
|
+
/**
|
|
105
|
+
* issues/116 契约 1.1:委托查询的 processName **以流程模型 name 为准**
|
|
106
|
+
* (迁移基线 = 内置版 SurrogateInterceptor 取的 `execution.getProcessModel().getName()`),
|
|
107
|
+
* 模型未带 name(缺失/空串/纯空白)时才回落 `wf_process_define.name`。
|
|
108
|
+
* 正常 deploy 两者恒等(saveDeployedDefine 执行 `def.name = flow.name`),但直接落库的
|
|
109
|
+
* 定义(测试 loadFlow、集成方自带导入链路)会不一致——取错那一头,用户在内置版配的
|
|
110
|
+
* 委托迁到 jeeflow 后就不再命中。对齐 Go `EngineImpl.surrogateProcessName` 同判据同姿势。
|
|
111
|
+
*/
|
|
112
|
+
async surrogateProcessName(flow, inst) {
|
|
113
|
+
const fromModel = typeof flow?.name === 'string' ? flow.name.trim() : '';
|
|
114
|
+
if (fromModel)
|
|
115
|
+
return fromModel;
|
|
116
|
+
if (inst?.defineId == null)
|
|
117
|
+
return '';
|
|
118
|
+
const key = String(inst.defineId);
|
|
119
|
+
const cached = this.defineNameCache.get(key);
|
|
120
|
+
if (cached !== undefined)
|
|
121
|
+
return cached;
|
|
122
|
+
let name = '';
|
|
123
|
+
try {
|
|
124
|
+
const def = await this.repo.findDefineById(inst.defineId);
|
|
125
|
+
name = typeof def?.name === 'string' ? def.name.trim() : '';
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
/* 定义读取失败按"拿不到流程名"处理:只命中全流程兜底委托,绝不打断建单(判据 4) */
|
|
129
|
+
}
|
|
130
|
+
this.defineNameCache.set(key, name);
|
|
131
|
+
return name;
|
|
32
132
|
}
|
|
33
133
|
setExtensions(ext) {
|
|
34
134
|
this.ext = ext;
|
|
@@ -161,12 +261,17 @@ export class EngineImpl {
|
|
|
161
261
|
const [actors, lc] = getCsState(vars, curNode.id);
|
|
162
262
|
if (actors && lc + 1 < actors.length) {
|
|
163
263
|
// 聚合根:创建串行会签下一步任务
|
|
164
|
-
const nt = inst.createTask(this.nextId(), curNode.id, curNode.text.value, actors[lc + 1], operator, curNode.properties?.form ?? '', now, 1);
|
|
165
|
-
nt.variables = {
|
|
264
|
+
const nt = inst.createTask(this.nextId(), curNode.id, curNode.text.value, actors[lc + 1], operator, curNode.properties?.form ?? '', now, task.id, this.isFirstTaskNode(flow, curNode), 1);
|
|
265
|
+
nt.variables = { isFirstTaskNode: nt.variables.isFirstTaskNode,
|
|
166
266
|
[`nrOfInstances_${curNode.id}`]: actors.length,
|
|
167
267
|
[`loopCounter_${curNode.id}`]: lc + 1,
|
|
168
268
|
[`operatorList_${curNode.id}`]: actors,
|
|
169
269
|
};
|
|
270
|
+
// issues/116:串行会签推进出的新任务同样并入该成员生效中的代理人
|
|
271
|
+
const pn = await this.surrogateProcessName(flow, inst);
|
|
272
|
+
const eff = mergeAgents([actors[lc + 1]], await this.surrogateAgents([actors[lc + 1]], pn));
|
|
273
|
+
if (eff.length > 1)
|
|
274
|
+
nt.actorIds = eff;
|
|
170
275
|
await this.repo.saveTask(nt);
|
|
171
276
|
// TASK_CREATE:顺序会签推进新任务落库后 fire(对齐 Java CreateTaskHandler / Rust)
|
|
172
277
|
await this.fireEvent({ type: EventType.TaskCreate, instanceId: inst.id, taskId: nt.id, nodeId: curNode.id, operator });
|
|
@@ -197,7 +302,7 @@ export class EngineImpl {
|
|
|
197
302
|
for (const node of followEdges(flow, curNode.id)) {
|
|
198
303
|
// 统一走 executeNode:结束节点也经节点执行链(拦截器/事件完整触发),
|
|
199
304
|
// executeNode 内部 TypeEnd 分支完成聚合根 finish + 事件发布
|
|
200
|
-
await this.executeNode(flow, inst, node, operator, vars);
|
|
305
|
+
await this.executeNode(flow, inst, node, operator, vars, task.id);
|
|
201
306
|
}
|
|
202
307
|
}
|
|
203
308
|
return (await this.repo.findInstanceById(inst.id));
|
|
@@ -215,16 +320,10 @@ export class EngineImpl {
|
|
|
215
320
|
async executeAndJumpTask(taskId, operator, args = {}, targetTaskName) {
|
|
216
321
|
const { task, inst, flow, vars } = await this.prepareExecuteTask(taskId, operator, args);
|
|
217
322
|
if (!targetTaskName) {
|
|
218
|
-
// issues/
|
|
219
|
-
//
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
const prev = findNode(flow, prevName);
|
|
223
|
-
if (prev) {
|
|
224
|
-
const actors = this.rollbackActors(prev, inst, task);
|
|
225
|
-
await this.createTaskWithActors(prev, inst, operator, vars, actors);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
323
|
+
// issues/121 P2:ROLLBACK 走血缘版——复活 task.parentTaskId 指的那条历史行,
|
|
324
|
+
// 参与者=该行办结人(首任务节点行取该行 u_userId)。无血缘/守卫不过显式报错,
|
|
325
|
+
// 不再像拓扑版那样"什么都不做、实例保持 DOING 却零待办"。
|
|
326
|
+
await this.rollbackToParent(flow, inst, task, operator);
|
|
228
327
|
}
|
|
229
328
|
else {
|
|
230
329
|
// issues/79:对齐 Java——目标节点不存在显式报错(前端 JUMP 无效 taskName 不再静默空操作)
|
|
@@ -236,7 +335,7 @@ export class EngineImpl {
|
|
|
236
335
|
target.properties = target.properties ?? {};
|
|
237
336
|
target.properties.assignee = inst.operator;
|
|
238
337
|
}
|
|
239
|
-
await this.executeNode(flow, inst, target, operator, vars);
|
|
338
|
+
await this.executeNode(flow, inst, target, operator, vars, task.id);
|
|
240
339
|
}
|
|
241
340
|
return (await this.repo.findInstanceById(inst.id));
|
|
242
341
|
}
|
|
@@ -250,7 +349,7 @@ export class EngineImpl {
|
|
|
250
349
|
if (node.type === TypeTask || node.type === TypeCustom) {
|
|
251
350
|
node.properties = node.properties ?? {};
|
|
252
351
|
node.properties.assignee = inst.operator;
|
|
253
|
-
await this.executeNode(flow, inst, node, operator, vars);
|
|
352
|
+
await this.executeNode(flow, inst, node, operator, vars, taskId);
|
|
254
353
|
break;
|
|
255
354
|
}
|
|
256
355
|
}
|
|
@@ -286,20 +385,6 @@ export class EngineImpl {
|
|
|
286
385
|
await this.repo.updateInstance(inst);
|
|
287
386
|
return { task, inst, flow, vars };
|
|
288
387
|
}
|
|
289
|
-
// 当前任务节点的首条输入边 source(issues/79 对齐 Java getPreviousTaskName)
|
|
290
|
-
previousTaskName(flow, taskName) {
|
|
291
|
-
const node = findNode(flow, taskName);
|
|
292
|
-
if (!node)
|
|
293
|
-
return '';
|
|
294
|
-
for (const edge of flow.edges) {
|
|
295
|
-
if (edge.targetNodeId === node.id) {
|
|
296
|
-
const src = findNode(flow, edge.sourceNodeId);
|
|
297
|
-
if (src && (src.type === TypeTask || src.type === TypeCustom))
|
|
298
|
-
return src.id;
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
return '';
|
|
302
|
-
}
|
|
303
388
|
// 是否 start 直接后继任务节点(issues/79 对齐 Java FlowUtil.isFirstTaskName)
|
|
304
389
|
isFirstTaskNode(flow, node) {
|
|
305
390
|
const start = findNodeByType(flow, TypeStart);
|
|
@@ -307,47 +392,71 @@ export class EngineImpl {
|
|
|
307
392
|
return false;
|
|
308
393
|
return flow.edges.some(e => e.sourceNodeId === start.id && e.targetNodeId === node.id);
|
|
309
394
|
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
395
|
+
/**
|
|
396
|
+
* 退回上一步(血缘版,规范 04 · 退回上一步):上一步来源=当前行的 parentTaskId,
|
|
397
|
+
* 复活那条历史行;不按模型入边拓扑推(拓扑版在分支/回环流会回到本实例没走过的节点,
|
|
398
|
+
* 还会静默留下"实例 DOING 却零待办")。对外 msg 用固定中文文案、不含引擎内部码(出口统一 99999999)。
|
|
399
|
+
*/
|
|
400
|
+
async rollbackToParent(flow, inst, task, operator) {
|
|
401
|
+
const NO_LINEAGE = '上一步任务ID为空,无法驳回至上一步处理';
|
|
402
|
+
const GUARD = '无法驳回至上一步处理,请确认上一步骤并非fork、join、suprocess以及会签任务';
|
|
403
|
+
const parentId = task.parentTaskId;
|
|
404
|
+
if (!parentId || parentId === '0')
|
|
405
|
+
throw new Error(NO_LINEAGE);
|
|
406
|
+
const his = await this.repo.findTaskById(parentId);
|
|
407
|
+
if (!his)
|
|
408
|
+
throw new Error(NO_LINEAGE);
|
|
409
|
+
const prev = findNode(flow, his.taskName);
|
|
410
|
+
if (!prev || !canRejected(flow, task.taskName, prev.id))
|
|
411
|
+
throw new Error(GUARD);
|
|
412
|
+
// 首任务节点那条由发起人提交 ⇒ 参与者取该行 u_userId;其余取该行办结人。
|
|
413
|
+
// 老行没这个键 ⇒ 按 false 处理(宁可派给该行 actorId,也不用带"仅进行中"判定的现算值)。
|
|
414
|
+
const isFirst = his.variables?.isFirstTaskNode === true;
|
|
415
|
+
let actor = isFirst ? String(his.variables?.u_userId ?? '') || inst.operator : his.actorId;
|
|
416
|
+
if (!actor)
|
|
417
|
+
throw new Error(NO_LINEAGE);
|
|
418
|
+
const nt = inst.createTask(this.nextId(), prev.id, prev.text.value, actor, his.createUser ?? '', prev.properties?.form ?? '', new Date(), his.parentTaskId ?? '0', isFirst, his.performType);
|
|
419
|
+
// 复活行只带数据类键:tf_*(上次表单提交)与 csv_*/会签簿记都是"上次提交"的残留
|
|
420
|
+
nt.variables = { ...lineageVars(his.variables), isFirstTaskNode: isFirst };
|
|
421
|
+
const agents = await this.surrogateAgents([actor], await this.surrogateProcessName(flow, inst));
|
|
422
|
+
const eff = mergeAgents([actor], agents);
|
|
423
|
+
if (eff.length > 1)
|
|
424
|
+
nt.actorIds = eff;
|
|
425
|
+
await this.repo.saveTask(nt);
|
|
426
|
+
await this.fireEvent({ type: EventType.TaskCreate, instanceId: inst.id,
|
|
427
|
+
taskId: nt.id, nodeId: prev.id, operator });
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* issues/116:对每个参与人查一次生效委托(判据在仓储侧:空 processName 全流程兜底 /
|
|
431
|
+
* 时间窗 / 自委托过滤 / enabled 只认 1)。返回 actor → 代理人 映射。
|
|
432
|
+
* 未配置查询源、显式关闭、无参与人 → 空映射(= 原样参与者,不打断建单);
|
|
433
|
+
* 单条查询异常只记录不传播(委托是增强能力,建单主流程不得被拖崩)。
|
|
434
|
+
*/
|
|
435
|
+
async surrogateAgents(actors, processName) {
|
|
436
|
+
const map = new Map();
|
|
437
|
+
const ext = this.surrogateRepo;
|
|
438
|
+
if (!ext || !this.surrogateOn || actors.length === 0)
|
|
439
|
+
return map;
|
|
440
|
+
const now = new Date();
|
|
441
|
+
for (const actor of actors) {
|
|
442
|
+
try {
|
|
443
|
+
const hit = await ext.getSurrogate(actor, processName ?? '', now);
|
|
444
|
+
const agent = typeof hit?.surrogate === 'string' ? hit.surrogate.trim() : '';
|
|
445
|
+
if (agent && agent !== actor)
|
|
446
|
+
map.set(actor, agent);
|
|
447
|
+
}
|
|
448
|
+
catch (e) {
|
|
449
|
+
console.error(`[jeeflow] 委托查询失败(跳过该参与人)actor=${actor}:`, e?.message ?? e);
|
|
342
450
|
}
|
|
343
|
-
return actors;
|
|
344
451
|
}
|
|
345
|
-
return
|
|
452
|
+
return map;
|
|
346
453
|
}
|
|
347
454
|
// 以显式参与者建任务(会签节点拆分为逐人任务,对齐 Java 会签创建语义)
|
|
348
|
-
async createTaskWithActors(node, inst, operator, vars, actors) {
|
|
455
|
+
async createTaskWithActors(node, inst, operator, vars, actors, processName = '', parentId = '0', isFirst = false) {
|
|
349
456
|
if (!actors.length)
|
|
350
457
|
return;
|
|
458
|
+
// issues/116:与 createTask 同口径——代理人并入参与者集合后随任务落库
|
|
459
|
+
const agents = await this.surrogateAgents(actors, processName);
|
|
351
460
|
const ct = node.properties?.countersignType;
|
|
352
461
|
const now = new Date();
|
|
353
462
|
const form = node.properties?.form ?? '';
|
|
@@ -356,34 +465,44 @@ export class EngineImpl {
|
|
|
356
465
|
case 'PARALLEL':
|
|
357
466
|
case '':
|
|
358
467
|
for (const actor of actors) {
|
|
359
|
-
const nt = inst.createTask(this.nextId(), node.id, node.text.value, actor, operator, form, now, 1);
|
|
468
|
+
const nt = inst.createTask(this.nextId(), node.id, node.text.value, actor, operator, form, now, parentId, isFirst, 1);
|
|
469
|
+
const eff = mergeAgents([actor], agents);
|
|
470
|
+
if (eff.length > 1)
|
|
471
|
+
nt.actorIds = eff;
|
|
360
472
|
await this.repo.saveTask(nt);
|
|
361
473
|
await this.fireEvent({ type: EventType.TaskCreate, instanceId: inst.id, taskId: nt.id, nodeId: node.id, operator });
|
|
362
474
|
}
|
|
363
475
|
return;
|
|
364
476
|
case 'SEQUENTIAL': {
|
|
365
|
-
const nt = inst.createTask(this.nextId(), node.id, node.text.value, actors[0], operator, form, now, 1);
|
|
366
|
-
nt.variables = {
|
|
477
|
+
const nt = inst.createTask(this.nextId(), node.id, node.text.value, actors[0], operator, form, now, parentId, isFirst, 1);
|
|
478
|
+
nt.variables = { isFirstTaskNode: nt.variables.isFirstTaskNode,
|
|
367
479
|
[`nrOfInstances_${node.id}`]: actors.length,
|
|
368
480
|
[`loopCounter_${node.id}`]: 0,
|
|
369
481
|
[`operatorList_${node.id}`]: actors,
|
|
370
482
|
};
|
|
483
|
+
const eff = mergeAgents([actors[0]], agents);
|
|
484
|
+
if (eff.length > 1)
|
|
485
|
+
nt.actorIds = eff;
|
|
371
486
|
await this.repo.saveTask(nt);
|
|
372
487
|
await this.fireEvent({ type: EventType.TaskCreate, instanceId: inst.id, taskId: nt.id, nodeId: node.id, operator });
|
|
373
488
|
return;
|
|
374
489
|
}
|
|
375
490
|
default:
|
|
376
491
|
for (const actor of actors) {
|
|
377
|
-
const nt = inst.createTask(this.nextId(), node.id, node.text.value, actor, operator, form, now, 1);
|
|
492
|
+
const nt = inst.createTask(this.nextId(), node.id, node.text.value, actor, operator, form, now, parentId, isFirst, 1);
|
|
493
|
+
const eff = mergeAgents([actor], agents);
|
|
494
|
+
if (eff.length > 1)
|
|
495
|
+
nt.actorIds = eff;
|
|
378
496
|
await this.repo.saveTask(nt);
|
|
379
497
|
await this.fireEvent({ type: EventType.TaskCreate, instanceId: inst.id, taskId: nt.id, nodeId: node.id, operator });
|
|
380
498
|
}
|
|
381
499
|
return;
|
|
382
500
|
}
|
|
383
501
|
}
|
|
384
|
-
const
|
|
385
|
-
|
|
386
|
-
|
|
502
|
+
const effActors = mergeAgents(actors, agents);
|
|
503
|
+
const nt = inst.createTask(this.nextId(), node.id, node.text.value, effActors[0], operator, form, now, parentId, isFirst);
|
|
504
|
+
if (effActors.length > 1)
|
|
505
|
+
nt.actorIds = effActors;
|
|
387
506
|
await this.repo.saveTask(nt);
|
|
388
507
|
await this.fireEvent({ type: EventType.TaskCreate, instanceId: inst.id, taskId: nt.id, nodeId: node.id, operator });
|
|
389
508
|
}
|
|
@@ -401,11 +520,11 @@ export class EngineImpl {
|
|
|
401
520
|
throw new Error(`instance not found`);
|
|
402
521
|
return { task, inst };
|
|
403
522
|
}
|
|
404
|
-
async executeNode(flow, inst, node, operator, vars) {
|
|
523
|
+
async executeNode(flow, inst, node, operator, vars, parentId = '0') {
|
|
405
524
|
// 任务创建(对齐 Java CreateTaskHandler:不触发节点拦截器——创建任务 ≠ 节点执行完成;
|
|
406
525
|
// 任务完成的拦截器由 executeProcessTask 显式触发,1.8.0 SYNC 同步演进)
|
|
407
526
|
if (node.type === TypeTask || node.type === TypeCustom) {
|
|
408
|
-
await this.createTask(node, inst, operator, vars);
|
|
527
|
+
await this.createTask(node, inst, operator, vars, await this.surrogateProcessName(flow, inst), parentId, this.isFirstTaskNode(flow, node));
|
|
409
528
|
return;
|
|
410
529
|
}
|
|
411
530
|
if (!(await this.firePre(node, inst)))
|
|
@@ -413,16 +532,16 @@ export class EngineImpl {
|
|
|
413
532
|
try {
|
|
414
533
|
switch (node.type) {
|
|
415
534
|
case TypeDecision:
|
|
416
|
-
return this.evaluateDecision(flow, inst, node, operator, vars);
|
|
535
|
+
return this.evaluateDecision(flow, inst, node, operator, vars, parentId);
|
|
417
536
|
case TypeFork:
|
|
418
537
|
for (const n of followEdges(flow, node.id))
|
|
419
|
-
await this.executeNode(flow, inst, n, operator, vars);
|
|
538
|
+
await this.executeNode(flow, inst, n, operator, vars, parentId);
|
|
420
539
|
return;
|
|
421
540
|
case TypeJoin: {
|
|
422
541
|
const doing = await this.repo.findDoingTasks(inst.id);
|
|
423
542
|
if (doing.length === 0)
|
|
424
543
|
for (const n of followEdges(flow, node.id))
|
|
425
|
-
await this.executeNode(flow, inst, n, operator, vars);
|
|
544
|
+
await this.executeNode(flow, inst, n, operator, vars, parentId);
|
|
426
545
|
return;
|
|
427
546
|
}
|
|
428
547
|
case TypeEnd: {
|
|
@@ -446,7 +565,7 @@ export class EngineImpl {
|
|
|
446
565
|
await this.firePost(node, inst);
|
|
447
566
|
}
|
|
448
567
|
}
|
|
449
|
-
async evaluateDecision(flow, inst, node, operator, vars) {
|
|
568
|
+
async evaluateDecision(flow, inst, node, operator, vars, parentId = '0') {
|
|
450
569
|
// 自定义决策(Registry 优先)
|
|
451
570
|
if (this.registry) {
|
|
452
571
|
const handlerName = node.properties?.decisionHandler ?? '';
|
|
@@ -459,7 +578,7 @@ export class EngineImpl {
|
|
|
459
578
|
if (edge.id === branchId) {
|
|
460
579
|
const target = findNode(flow, edge.targetNodeId);
|
|
461
580
|
if (target)
|
|
462
|
-
return this.executeNode(flow, inst, target, operator, vars);
|
|
581
|
+
return this.executeNode(flow, inst, target, operator, vars, parentId);
|
|
463
582
|
}
|
|
464
583
|
}
|
|
465
584
|
}
|
|
@@ -475,7 +594,7 @@ export class EngineImpl {
|
|
|
475
594
|
if (edge.id === branchId) {
|
|
476
595
|
const target = findNode(flow, edge.targetNodeId);
|
|
477
596
|
if (target)
|
|
478
|
-
return this.executeNode(flow, inst, target, operator, vars);
|
|
597
|
+
return this.executeNode(flow, inst, target, operator, vars, parentId);
|
|
479
598
|
}
|
|
480
599
|
}
|
|
481
600
|
}
|
|
@@ -488,7 +607,7 @@ export class EngineImpl {
|
|
|
488
607
|
if (!expr) {
|
|
489
608
|
const target = findNode(flow, edge.targetNodeId);
|
|
490
609
|
if (target)
|
|
491
|
-
return this.executeNode(flow, inst, target, operator, vars);
|
|
610
|
+
return this.executeNode(flow, inst, target, operator, vars, parentId);
|
|
492
611
|
return;
|
|
493
612
|
}
|
|
494
613
|
if (this.exprEval) {
|
|
@@ -496,16 +615,19 @@ export class EngineImpl {
|
|
|
496
615
|
if (isTruthy(result)) {
|
|
497
616
|
const target = findNode(flow, edge.targetNodeId);
|
|
498
617
|
if (target)
|
|
499
|
-
return this.executeNode(flow, inst, target, operator, vars);
|
|
618
|
+
return this.executeNode(flow, inst, target, operator, vars, parentId);
|
|
500
619
|
return;
|
|
501
620
|
}
|
|
502
621
|
}
|
|
503
622
|
}
|
|
504
623
|
}
|
|
505
|
-
async createTask(node, inst, operator, vars) {
|
|
624
|
+
async createTask(node, inst, operator, vars, processName = '', parentId = '0', isFirst = false) {
|
|
506
625
|
const actors = await this.resolveActors(node, inst, operator, vars);
|
|
507
626
|
if (!actors.length)
|
|
508
627
|
return;
|
|
628
|
+
// issues/116:参与者解析完成后、落库前应用生效委托——代理人并入参与者集合,
|
|
629
|
+
// 随任务一起 saveTask 落 wf_process_task_actor(严禁"事后 addTaskActor 补写")
|
|
630
|
+
const agents = await this.surrogateAgents(actors, processName);
|
|
509
631
|
const ct = node.properties?.countersignType;
|
|
510
632
|
const now = new Date();
|
|
511
633
|
const form = node.properties?.form ?? '';
|
|
@@ -513,7 +635,10 @@ export class EngineImpl {
|
|
|
513
635
|
switch (ct) {
|
|
514
636
|
case 'PARALLEL':
|
|
515
637
|
for (const actor of actors) {
|
|
516
|
-
const nt = inst.createTask(this.nextId(), node.id, node.text.value, actor, operator, form, now, 1);
|
|
638
|
+
const nt = inst.createTask(this.nextId(), node.id, node.text.value, actor, operator, form, now, parentId, isFirst, 1);
|
|
639
|
+
const eff = mergeAgents([actor], agents);
|
|
640
|
+
if (eff.length > 1)
|
|
641
|
+
nt.actorIds = eff;
|
|
517
642
|
await this.repo.saveTask(nt);
|
|
518
643
|
// TASK_CREATE:任务落库后逐个 fire(会签多任务逐个,对齐 Java CreateTaskHandler)
|
|
519
644
|
await this.fireEvent({ type: EventType.TaskCreate, instanceId: inst.id, taskId: nt.id, nodeId: node.id, operator });
|
|
@@ -521,19 +646,26 @@ export class EngineImpl {
|
|
|
521
646
|
return;
|
|
522
647
|
case 'SEQUENTIAL': {
|
|
523
648
|
// 顺序会签任务也是会签任务(issues/57 E29 修正:仅普通分支默认 0)
|
|
524
|
-
const nt = inst.createTask(this.nextId(), node.id, node.text.value, actors[0], operator, form, now, 1);
|
|
525
|
-
|
|
649
|
+
const nt = inst.createTask(this.nextId(), node.id, node.text.value, actors[0], operator, form, now, parentId, isFirst, 1);
|
|
650
|
+
// 会签成员列表保持原 actors(委托不新增会签成员,只在该成员的任务上并入代理人)
|
|
651
|
+
nt.variables = { isFirstTaskNode: nt.variables.isFirstTaskNode,
|
|
526
652
|
[`nrOfInstances_${node.id}`]: actors.length,
|
|
527
653
|
[`loopCounter_${node.id}`]: 0,
|
|
528
654
|
[`operatorList_${node.id}`]: actors,
|
|
529
655
|
};
|
|
656
|
+
const eff = mergeAgents([actors[0]], agents);
|
|
657
|
+
if (eff.length > 1)
|
|
658
|
+
nt.actorIds = eff;
|
|
530
659
|
await this.repo.saveTask(nt);
|
|
531
660
|
await this.fireEvent({ type: EventType.TaskCreate, instanceId: inst.id, taskId: nt.id, nodeId: node.id, operator });
|
|
532
661
|
return;
|
|
533
662
|
}
|
|
534
663
|
default:
|
|
535
664
|
for (const actor of actors) {
|
|
536
|
-
const nt = inst.createTask(this.nextId(), node.id, node.text.value, actor, operator, form, now, 1);
|
|
665
|
+
const nt = inst.createTask(this.nextId(), node.id, node.text.value, actor, operator, form, now, parentId, isFirst, 1);
|
|
666
|
+
const eff = mergeAgents([actor], agents);
|
|
667
|
+
if (eff.length > 1)
|
|
668
|
+
nt.actorIds = eff;
|
|
537
669
|
await this.repo.saveTask(nt);
|
|
538
670
|
await this.fireEvent({ type: EventType.TaskCreate, instanceId: inst.id, taskId: nt.id, nodeId: node.id, operator });
|
|
539
671
|
}
|
|
@@ -541,9 +673,10 @@ export class EngineImpl {
|
|
|
541
673
|
}
|
|
542
674
|
}
|
|
543
675
|
// 普通任务:一个任务承载全部参与者(对齐 boot3 createTask + addTaskActor,多参与者任一可办)
|
|
544
|
-
const
|
|
545
|
-
|
|
546
|
-
|
|
676
|
+
const effActors = mergeAgents(actors, agents);
|
|
677
|
+
const nt = inst.createTask(this.nextId(), node.id, node.text.value, effActors[0], operator, form, now, parentId, isFirst);
|
|
678
|
+
if (effActors.length > 1)
|
|
679
|
+
nt.actorIds = effActors;
|
|
547
680
|
await this.repo.saveTask(nt);
|
|
548
681
|
await this.fireEvent({ type: EventType.TaskCreate, instanceId: inst.id, taskId: nt.id, nodeId: node.id, operator });
|
|
549
682
|
}
|
|
@@ -648,6 +781,19 @@ export class EngineImpl {
|
|
|
648
781
|
}
|
|
649
782
|
}
|
|
650
783
|
// ─── Pure Functions ──────────────────────────────────────────────────────────
|
|
784
|
+
/** issues/116:把代理人并入参与者集合——授权人保留、原顺序不动、代理人按参与人顺序追加、去重。
|
|
785
|
+
* 返回新数组(无代理命中时返回原数组引用,零开销)。 */
|
|
786
|
+
export function mergeAgents(actors, agents) {
|
|
787
|
+
if (agents.size === 0)
|
|
788
|
+
return actors;
|
|
789
|
+
const out = [...actors];
|
|
790
|
+
for (const a of actors) {
|
|
791
|
+
const agent = agents.get(a);
|
|
792
|
+
if (agent && !out.includes(agent))
|
|
793
|
+
out.push(agent);
|
|
794
|
+
}
|
|
795
|
+
return out;
|
|
796
|
+
}
|
|
651
797
|
function findNode(flow, id) {
|
|
652
798
|
return flow.nodes.find(n => n.id === id);
|
|
653
799
|
}
|
package/dist/facade.d.ts
CHANGED
|
@@ -75,6 +75,13 @@ export declare class JeeflowFacade {
|
|
|
75
75
|
private candidatePage;
|
|
76
76
|
private nextTaskCandidates;
|
|
77
77
|
private taskAddActor;
|
|
78
|
+
/**
|
|
79
|
+
* issues/115:转办(摘原人 + 换新人),区别于 surrogate 加签的"只追加"。七条契约语义(spec 06):
|
|
80
|
+
* 只摘 fromActor 那一行 actor / toActor 追加 / 沿用同一 taskId / 留痕三件(submitType=7 槽位 +
|
|
81
|
+
* tf_transferHistory 追加式账本 + 末跳 tf_approvalComment 文案)/ 变量合并序 实例←任务←本次 /
|
|
82
|
+
* 四类明确报错(msg 跨栈统一)。
|
|
83
|
+
*/
|
|
84
|
+
private taskTransfer;
|
|
78
85
|
private taskLatest;
|
|
79
86
|
private ext;
|
|
80
87
|
private definePage;
|