@mldong/jeeflow 1.8.26 → 1.8.27
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 +144 -17
- package/dist/index.d.ts +3 -2
- package/dist/index.js +1 -0
- package/dist/jdbc/ext.d.ts +8 -0
- package/dist/jdbc/ext.js +14 -3
- package/dist/memory-ext.d.ts +10 -0
- package/dist/memory-ext.js +80 -11
- package/dist/metadata.js +1 -1
- package/dist/model.d.ts +9 -2
- package/dist/model.js +14 -4
- 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 = '20010007: 上一步任务ID为空,无法驳回至上一步处理';
|
|
402
|
+
const GUARD = '20010008: 无法驳回至上一步处理,请确认上一步骤并非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;
|
package/dist/facade.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// action(boot2/boot3 端点短名)路由。返回统一结构 {code, msg, data}
|
|
5
5
|
// (code=0 成功 / 99999999 失败)。操作人约定:args.operator 显式传入。
|
|
6
6
|
import { TaskState, } from './model.js';
|
|
7
|
-
import { KeyNextNodeOperator, KeyProcessStartNextNodeOperator, isCountersign } from './engine.js';
|
|
7
|
+
import { KeyAutoExecute, KeyAdminID, KeyNextNodeOperator, KeyProcessStartNextNodeOperator, isCountersign } from './engine.js';
|
|
8
8
|
import { EventType } from './extensions.js';
|
|
9
9
|
// submitType 枚举(对齐 boot3)
|
|
10
10
|
const SUBMIT_APPLY = 0;
|
|
@@ -13,6 +13,7 @@ const SUBMIT_REJECT = 2;
|
|
|
13
13
|
const SUBMIT_ROLLBACK = 3;
|
|
14
14
|
const SUBMIT_JUMP = 4;
|
|
15
15
|
const SUBMIT_ROLLBACK_TO_OPERATOR = 6;
|
|
16
|
+
const SUBMIT_TRANSFER = 7;
|
|
16
17
|
const SUBMIT_COUNTERSIGN_DISAGREE = 20;
|
|
17
18
|
export class JeeflowFacade {
|
|
18
19
|
engine;
|
|
@@ -25,6 +26,12 @@ export class JeeflowFacade {
|
|
|
25
26
|
this.engine = engine;
|
|
26
27
|
this.repo = repo;
|
|
27
28
|
this.extRepo = extRepo;
|
|
29
|
+
// issues/116:标准装配链下「委托代理自动生效」由引擎内置并默认开启——
|
|
30
|
+
// 传入了扩展仓储就把它交给引擎(集成方无需再手工注册拦截器)。
|
|
31
|
+
// 关闭:engine.setSurrogateEnabled(false) / engine.setSurrogateRepository(null)。
|
|
32
|
+
// engine 允许为 null(纯统计门面用法),此时无引擎可装配,跳过。
|
|
33
|
+
if (extRepo && this.engine)
|
|
34
|
+
this.engine.setSurrogateRepository(extRepo);
|
|
28
35
|
}
|
|
29
36
|
/** 注入业务数据读取器(issue 30):需有 readByProcessInstance(tableName, processInstanceId) */
|
|
30
37
|
setMetaReader(reader) {
|
|
@@ -131,6 +138,8 @@ export class JeeflowFacade {
|
|
|
131
138
|
case 'processTask/surrogate':
|
|
132
139
|
case 'processTask/addCandidate':
|
|
133
140
|
return this.taskAddActor(args);
|
|
141
|
+
case 'processTask/transfer': // issues/115:转办(摘原人 + 换新人)
|
|
142
|
+
return this.taskTransfer(args);
|
|
134
143
|
case 'processTask/latest':
|
|
135
144
|
return this.taskLatest(args);
|
|
136
145
|
case 'processInstance/stats/overview':
|
|
@@ -246,26 +255,47 @@ export class JeeflowFacade {
|
|
|
246
255
|
}
|
|
247
256
|
async withdraw(args) {
|
|
248
257
|
const instanceId = toId(args.id);
|
|
258
|
+
// issues/114:operator 硬必填——严禁缺省回落 user1 等固定账号(撤回人静默记成别人,
|
|
259
|
+
// 审计链失真且不报错)。msg 跨栈统一「operator 必填」。
|
|
260
|
+
const operator = String(args.operator ?? '').trim();
|
|
261
|
+
if (!operator)
|
|
262
|
+
throw new Error('operator 必填');
|
|
249
263
|
const inst = await this.repo.findInstanceById(instanceId);
|
|
250
264
|
if (!inst)
|
|
251
265
|
throw new Error('流程实例不存在');
|
|
252
|
-
//
|
|
253
|
-
const operator = String(args.operator ?? 'user1');
|
|
266
|
+
// 撤回:全部 doing 任务置 Withdraw(30) + 实例置 30(v1.0.1:updateInstance 级联落库)
|
|
254
267
|
const now = new Date();
|
|
255
|
-
// findInstanceById 现水合 tasks(issues/110),此处仍按实例单独查 doing
|
|
256
|
-
//
|
|
257
|
-
const
|
|
268
|
+
// findInstanceById 现水合 tasks(issues/110),此处仍按实例单独查 doing 任务撤回,
|
|
269
|
+
// 且必须把聚合副本重置为仅被撤回项(见下方 inst.tasks = withdrawn),防级联回写多余任务
|
|
270
|
+
const withdrawn = [];
|
|
258
271
|
for (const t of await this.repo.findDoingTasks(instanceId)) {
|
|
259
|
-
|
|
260
|
-
|
|
272
|
+
withdrawn.push(t);
|
|
273
|
+
}
|
|
274
|
+
// issues/114 归属判据(命中任一放行,全不命中拒绝,msg 跨栈统一):
|
|
275
|
+
// 1) operator = 实例发起人——⚠️ 不可复用 isAllowed(其只判任务 actorIds + auto/admin,不查发起人)
|
|
276
|
+
// 2) operator 是该实例任一进行中任务的参与者
|
|
277
|
+
// 3) operator ∈ {flow.auto, flow.admin}(沿用 isAllowed 既有放行约定)
|
|
278
|
+
const lower = operator.toLowerCase();
|
|
279
|
+
const isSystem = lower === KeyAutoExecute || lower === KeyAdminID;
|
|
280
|
+
const isStarter = operator === String(inst.operator ?? '');
|
|
281
|
+
const isActor = withdrawn.some(t => (t.actorIds ?? []).includes(operator));
|
|
282
|
+
if (!isSystem && !isStarter && !isActor)
|
|
283
|
+
throw new Error('无权限撤回该流程实例');
|
|
284
|
+
for (const t of withdrawn) {
|
|
285
|
+
// issues/113:撤回写 Withdraw(30),不用 Abandoned(99)——99 是引擎废弃码
|
|
286
|
+
// (会签一票否决 / abandonAllDoing 用它),混用会让撤回单与废弃单在任务表里塌成同值
|
|
287
|
+
t.withdraw(now);
|
|
288
|
+
// issues/114:进行中任务的 update_user 同样回写为撤回人(与实例口径一致)
|
|
289
|
+
t.updateUser = operator;
|
|
261
290
|
}
|
|
262
291
|
// issues/53 E25:撤回状态应为 Withdraw(30) 而非 Reject(45)(对齐 Java)
|
|
263
292
|
inst.withdraw(now);
|
|
264
293
|
inst.updateUser = operator;
|
|
265
|
-
// 级联覆盖防护(issues/57
|
|
266
|
-
//
|
|
267
|
-
|
|
268
|
-
|
|
294
|
+
// 级联覆盖防护(issues/57 补正):撤回副本同步回聚合——updateInstance 级联会用
|
|
295
|
+
// 聚合内旧任务覆盖已撤回状态(memory 加载 tasks 时必现);已完成(20)/已终止(40)
|
|
296
|
+
// 任务行不在 withdrawn 内,天然不被改写
|
|
297
|
+
inst.tasks = withdrawn;
|
|
298
|
+
for (const t of withdrawn)
|
|
269
299
|
await this.repo.updateTask(t);
|
|
270
300
|
await this.repo.updateInstance(inst);
|
|
271
301
|
}
|
|
@@ -642,7 +672,9 @@ export class JeeflowFacade {
|
|
|
642
672
|
s.surrogate = String(args.surrogate ?? '');
|
|
643
673
|
s.startTime = parseSurrogateTime(args.startTime);
|
|
644
674
|
s.endTime = parseSurrogateTime(args.endTime);
|
|
645
|
-
|
|
675
|
+
// issues/116 判据 d 的**写侧**:脏值不得默认当启用(此前走 toInt 遇 'abc' 直接抛
|
|
676
|
+
// 「数值缺失或非法」→ 门面 500,与 Java toInt(x,0) / Go parseSurrogateEnabled 分叉)
|
|
677
|
+
s.enabled = parseSurrogateEnabled(args.enabled);
|
|
646
678
|
s.updateUser = operator;
|
|
647
679
|
}
|
|
648
680
|
// ── 视图端点(v1.2.0) ──────────────────────────────────────────────────
|
|
@@ -849,7 +881,9 @@ export class JeeflowFacade {
|
|
|
849
881
|
// 首个任务节点且 DOING → true,与 instance detail 的 activeTaskList 行语义一致
|
|
850
882
|
const tExt = { ...(task.variables ?? {}) };
|
|
851
883
|
const doing = task.taskState === TaskState.Doing;
|
|
852
|
-
|
|
884
|
+
// 先留住行上值再覆写出口,否则丢掉「缺键」这个事实就没法回退现算
|
|
885
|
+
const tRowFirst = task.variables?.isFirstTaskNode;
|
|
886
|
+
tExt.isFirstTaskNode = tRowFirst != null ? Boolean(tRowFirst) : false;
|
|
853
887
|
const vo = {
|
|
854
888
|
id: task.id, processInstanceId: task.processInstanceId, taskName: task.taskName,
|
|
855
889
|
displayName: task.displayName, taskType: task.taskType ?? null,
|
|
@@ -865,7 +899,10 @@ export class JeeflowFacade {
|
|
|
865
899
|
const def = await this.repo.findDefineById(inst.defineId);
|
|
866
900
|
if (def) {
|
|
867
901
|
vo.jsonObject = this.parseGraph(def.content); // issues/05
|
|
868
|
-
|
|
902
|
+
if (tRowFirst == null) {
|
|
903
|
+
// 存量行没有落库标记 ⇒ 回退现算(仅进行中口径)
|
|
904
|
+
tExt.isFirstTaskNode = doing && task.taskName === this.firstTaskNodeId(vo.jsonObject);
|
|
905
|
+
}
|
|
869
906
|
try {
|
|
870
907
|
const flow = JSON.parse(toStr(def.content));
|
|
871
908
|
for (const n of flow.nodes ?? []) {
|
|
@@ -987,6 +1024,70 @@ export class JeeflowFacade {
|
|
|
987
1024
|
throw new Error('actorIds 缺失');
|
|
988
1025
|
await this.repo.addTaskActor(taskId, actors);
|
|
989
1026
|
}
|
|
1027
|
+
/**
|
|
1028
|
+
* issues/115:转办(摘原人 + 换新人),区别于 surrogate 加签的"只追加"。七条契约语义(spec 06):
|
|
1029
|
+
* 只摘 fromActor 那一行 actor / toActor 追加 / 沿用同一 taskId / 留痕三件(submitType=7 槽位 +
|
|
1030
|
+
* tf_transferHistory 追加式账本 + 末跳 tf_approvalComment 文案)/ 变量合并序 实例←任务←本次 /
|
|
1031
|
+
* 四类明确报错(msg 跨栈统一)。
|
|
1032
|
+
*/
|
|
1033
|
+
async taskTransfer(args) {
|
|
1034
|
+
const taskId = toId(args.processTaskId);
|
|
1035
|
+
const operator = String(args.operator ?? '').trim();
|
|
1036
|
+
if (!operator)
|
|
1037
|
+
throw new Error('operator 必填');
|
|
1038
|
+
const fromActor = String(args.fromActor ?? '').trim();
|
|
1039
|
+
const toActor = String(args.toActor ?? '').trim();
|
|
1040
|
+
if (!fromActor)
|
|
1041
|
+
throw new Error('fromActor 必填');
|
|
1042
|
+
if (!toActor)
|
|
1043
|
+
throw new Error('toActor 必填');
|
|
1044
|
+
// 归属判据:只能转自己那一条待办;flow.auto/flow.admin 放行(对齐 isAllowed 既有约定)
|
|
1045
|
+
const lower = operator.toLowerCase();
|
|
1046
|
+
if (operator !== fromActor && lower !== KeyAutoExecute && lower !== KeyAdminID) {
|
|
1047
|
+
throw new Error('无权限转办该任务');
|
|
1048
|
+
}
|
|
1049
|
+
const task = await this.repo.findTaskById(taskId);
|
|
1050
|
+
if (!task)
|
|
1051
|
+
throw new Error('任务不存在');
|
|
1052
|
+
// 前置态:仅进行中(DOING=10)任务可转办
|
|
1053
|
+
if (task.taskState !== TaskState.Doing)
|
|
1054
|
+
throw new Error('任务非进行中,不可转办');
|
|
1055
|
+
const actors = await this.repo.findTaskActors(taskId);
|
|
1056
|
+
if (!actors.includes(fromActor))
|
|
1057
|
+
throw new Error('原办理人不是该任务参与人');
|
|
1058
|
+
if (actors.includes(toActor))
|
|
1059
|
+
throw new Error('目标人已是该任务参与人');
|
|
1060
|
+
// 摘原人(仅 fromActor 一行,会签其余成员不受影响)+ 加新人(同一 taskId,不新建任务)
|
|
1061
|
+
await this.repo.removeTaskActor(taskId, [fromActor]);
|
|
1062
|
+
await this.repo.addTaskActor(taskId, [toActor]);
|
|
1063
|
+
// 留痕三件(spec 06 clause 4,缺一不可):① 任务行 submitType=7 槽位 ② tf_transferHistory 账本
|
|
1064
|
+
// ③ 末跳可读文案 tf_approvalComment(approvalRecord 的 ext 读它)
|
|
1065
|
+
const reason = String(args.reason ?? '').trim();
|
|
1066
|
+
const now = new Date();
|
|
1067
|
+
// 账本动机:审批记录的槽位就是任务行本身,B 办结时 submitType 会被 1/2/20 覆盖——没有追加式
|
|
1068
|
+
// 账本,多跳转办只剩末跳、办结后转办事实整体消失,故本键每跳 append、永不覆盖。
|
|
1069
|
+
const history = Array.isArray(task.variables?.tf_transferHistory)
|
|
1070
|
+
? task.variables.tf_transferHistory
|
|
1071
|
+
: [];
|
|
1072
|
+
task.variables = {
|
|
1073
|
+
...(task.variables ?? {}),
|
|
1074
|
+
submitType: SUBMIT_TRANSFER,
|
|
1075
|
+
tf_transferTo: toActor,
|
|
1076
|
+
tf_transferReason: reason,
|
|
1077
|
+
// 时间格式按 spec §2.4 统一 yyyy-MM-dd HH:mm:ss(跨栈同形,前端免时区换算)
|
|
1078
|
+
tf_transferHistory: [...history, { submitType: SUBMIT_TRANSFER, fromActor, toActor, reason, time: fmtTime(now), operator }],
|
|
1079
|
+
tf_approvalComment: reason ? `${fromActor} 转办给 ${toActor}(${reason})` : `${fromActor} 转办给 ${toActor}`,
|
|
1080
|
+
};
|
|
1081
|
+
// 契约 06 §transfer 留痕⚠️:**严禁覆写 actorId/operator 列**——进行中任务该列恒无值是既有
|
|
1082
|
+
// 不变量;把被摘走的人写进去,该单撤回/终止后(离开 DOING 但列值留着)会凭空出现在
|
|
1083
|
+
// 他从没办过的「我已办」列表(pageDoneTasks 按 state <> 10 AND operator = ? 过滤,实测复现)。
|
|
1084
|
+
// 办理人由 updateUser + tf_transferHistory[].operator 承载。
|
|
1085
|
+
task.updateUser = operator;
|
|
1086
|
+
task.updateTime = now;
|
|
1087
|
+
// 仓储 updateTask 会以任务副本的 actorIds 覆写参与者(memory 语义),须同步为摘/加后的最新值
|
|
1088
|
+
task.actorIds = await this.repo.findTaskActors(taskId);
|
|
1089
|
+
await this.repo.updateTask(task);
|
|
1090
|
+
}
|
|
990
1091
|
async taskLatest(args) {
|
|
991
1092
|
const instanceId = toId(args.processInstanceId);
|
|
992
1093
|
const doing = await this.repo.findDoingTasks(instanceId);
|
|
@@ -1051,7 +1152,10 @@ export class JeeflowFacade {
|
|
|
1051
1152
|
};
|
|
1052
1153
|
const ext = { ...(t.variables ?? {}) };
|
|
1053
1154
|
const doing = t.taskState === TaskState.Doing;
|
|
1054
|
-
|
|
1155
|
+
// issues/121 P1:行上值优先(引擎建单时写入,历史行同样有效),缺键(存量行)才回退现算
|
|
1156
|
+
ext.isFirstTaskNode = t.variables?.isFirstTaskNode != null
|
|
1157
|
+
? Boolean(t.variables.isFirstTaskNode)
|
|
1158
|
+
: (doing && t.taskName === firstTaskNodeId);
|
|
1055
1159
|
vo.ext = ext;
|
|
1056
1160
|
tasks.push(vo);
|
|
1057
1161
|
if (doing)
|
|
@@ -1372,6 +1476,26 @@ function parseSurrogateTime(v) {
|
|
|
1372
1476
|
const d = new Date(s);
|
|
1373
1477
|
return isNaN(d.getTime()) ? undefined : d;
|
|
1374
1478
|
}
|
|
1479
|
+
/**
|
|
1480
|
+
* issues/116 判据 d 的写侧:委托启用位解析(processSurrogate/save 与 /update 共用)。
|
|
1481
|
+
* 契约「enabled 只有 1 生效,脏值不得默认当启用」——所以:
|
|
1482
|
+
* - 未传(null/undefined)→ 1,契约默认启用(06 §4.5 save 参数表 enabled 可省);
|
|
1483
|
+
* - 布尔 → true=1 / false=0(前端开关组件偶发传布尔,不算脏值);
|
|
1484
|
+
* - 传了但不可解析为整数('abc' / {} / NaN / 空串)→ **0 停用**落库,不抛错打断保存。
|
|
1485
|
+
* 对齐 Java `toInt(arg, 0)` / Go `parseSurrogateEnabled`;此前本栈走 `toInt(arg)`,
|
|
1486
|
+
* 脏值直接抛「数值缺失或非法」(门面 500),与其余各栈"落 0"行为分叉。
|
|
1487
|
+
*/
|
|
1488
|
+
function parseSurrogateEnabled(v) {
|
|
1489
|
+
if (v == null)
|
|
1490
|
+
return 1;
|
|
1491
|
+
if (typeof v === 'boolean')
|
|
1492
|
+
return v ? 1 : 0;
|
|
1493
|
+
const s = typeof v === 'string' ? v.trim() : v;
|
|
1494
|
+
if (s === '' || s == null)
|
|
1495
|
+
return 0;
|
|
1496
|
+
const n = Number(s);
|
|
1497
|
+
return Number.isInteger(n) ? n : 0;
|
|
1498
|
+
}
|
|
1375
1499
|
function designRowToMap(r) {
|
|
1376
1500
|
return {
|
|
1377
1501
|
id: r.id, name: r.name, displayName: r.displayName,
|
|
@@ -1409,7 +1533,10 @@ function ccRowToMap(r) {
|
|
|
1409
1533
|
/** 任务行:ext(任务变量,空回退实例变量)+ instanceExt + version */
|
|
1410
1534
|
function taskRowToMap(r) {
|
|
1411
1535
|
const instanceExt = parseVarMap(r.instanceVariable);
|
|
1412
|
-
|
|
1536
|
+
// issues/121 P1:引擎建单必写的控制键不算「任务变量非空」,否则新建任务的 ext
|
|
1537
|
+
// 永远不再回退实例变量(issues/82-3 既有契约)。
|
|
1538
|
+
const userKeys = Object.keys(r.variables ?? {}).filter(k => k !== 'isFirstTaskNode');
|
|
1539
|
+
const ext = userKeys.length > 0 ? r.variables : instanceExt;
|
|
1413
1540
|
return {
|
|
1414
1541
|
id: r.id, processInstanceId: r.processInstanceId, taskName: r.taskName,
|
|
1415
1542
|
displayName: r.displayName, taskType: r.taskType, performType: r.performType,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
export { EngineImpl, type Engine } from './engine.js';
|
|
1
|
+
export { EngineImpl, type Engine, type EngineOptions, type SurrogateLookup } from './engine.js';
|
|
2
2
|
export { MemoryRepository } from './memory.js';
|
|
3
|
+
export { MemoryExtRepository } from './memory-ext.js';
|
|
3
4
|
export { HandlerRegistry, type IAssignmentHandler, type IDecisionHandler, type HandlerMeta, type HandlerType } from './registry.js';
|
|
4
5
|
export { enumDict, enumDictKeys, type DictItem } from './metadata.js';
|
|
5
6
|
export * from './model.js';
|
|
6
|
-
export type { ProcessRepository, UserProvider, OrgUserProvider, IDGenerator, ExpressionEvaluator } from './spi.js';
|
|
7
|
+
export type { ProcessRepository, ProcessExtRepository, UserProvider, OrgUserProvider, IDGenerator, ExpressionEvaluator, QueryCondition } from './spi.js';
|
|
7
8
|
export { SqliteDynamicTableWriter, PersistPostInterceptor, registerPersistMeta, type DynamicTableWriter, type DefineLoader, } from './persist.js';
|
|
8
9
|
export { registerBuiltinAssignments, OperatorAssignmentHandler, FormFieldAssigneeHandler, DeptLeaderAssignmentHandler, DeptMainLeaderAssignmentHandler, ApplicantDeptLeaderAssignmentHandler, ApplicantDeptMainLeaderAssignmentHandler, TaskRoleAssigneeHandler, HANDLER_OPERATOR_ASSIGNMENT, HANDLER_FORM_FIELD_ASSIGNEE, HANDLER_DEPT_LEADER, HANDLER_DEPT_MAIN_LEADER, HANDLER_APPLICANT_DEPT_LEADER, HANDLER_APPLICANT_DEPT_MAIN_LEADER, HANDLER_TASK_ROLE_ASSIGNEE, } from './builtin.js';
|
|
9
10
|
export { JeeflowFacade } from './facade.js';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { EngineImpl } from './engine.js';
|
|
2
2
|
export { MemoryRepository } from './memory.js';
|
|
3
|
+
export { MemoryExtRepository } from './memory-ext.js';
|
|
3
4
|
export { HandlerRegistry } from './registry.js';
|
|
4
5
|
export { enumDict, enumDictKeys } from './metadata.js';
|
|
5
6
|
export * from './model.js';
|
package/dist/jdbc/ext.d.ts
CHANGED
|
@@ -25,6 +25,14 @@ export declare class JdbcProcessExtRepository implements ProcessExtRepository {
|
|
|
25
25
|
updateSurrogate(s: ProcessSurrogate): Promise<void>;
|
|
26
26
|
removeSurrogate(id: string): Promise<void>;
|
|
27
27
|
pageSurrogates(pageNum?: number, pageSize?: number, filters?: Record<string, any>, conditions?: QueryCondition[]): Promise<[ProcessSurrogate[], number]>;
|
|
28
|
+
/**
|
|
29
|
+
* 生效委托查询(issues/116 判据 a~d 基准实现):
|
|
30
|
+
* a. processName 先精确命中,未命中再兜底 process_name IS NULL OR = '' (全流程委托)
|
|
31
|
+
* b. 时间窗 start_time <= at <= end_time,任一侧 NULL = 该侧不限
|
|
32
|
+
* c. 自委托过滤 surrogate <> operator
|
|
33
|
+
* d. enabled 只认 1(INT 列,脏值进不来;NULL 也不生效)
|
|
34
|
+
* 多条命中取 id 最大(最新)一条 —— 内存仓须给出同结论(MemoryExtRepository.getSurrogate)
|
|
35
|
+
*/
|
|
28
36
|
getSurrogate(operator: string, processName: string, at?: Date): Promise<ProcessSurrogate | null>;
|
|
29
37
|
private querySurrogate;
|
|
30
38
|
private mapDesign;
|
package/dist/jdbc/ext.js
CHANGED
|
@@ -266,10 +266,21 @@ export class JdbcProcessExtRepository {
|
|
|
266
266
|
await this.done(conn);
|
|
267
267
|
}
|
|
268
268
|
}
|
|
269
|
+
/**
|
|
270
|
+
* 生效委托查询(issues/116 判据 a~d 基准实现):
|
|
271
|
+
* a. processName 先精确命中,未命中再兜底 process_name IS NULL OR = '' (全流程委托)
|
|
272
|
+
* b. 时间窗 start_time <= at <= end_time,任一侧 NULL = 该侧不限
|
|
273
|
+
* c. 自委托过滤 surrogate <> operator
|
|
274
|
+
* d. enabled 只认 1(INT 列,脏值进不来;NULL 也不生效)
|
|
275
|
+
* 多条命中取 id 最大(最新)一条 —— 内存仓须给出同结论(MemoryExtRepository.getSurrogate)
|
|
276
|
+
*/
|
|
269
277
|
async getSurrogate(operator, processName, at = new Date()) {
|
|
270
|
-
const
|
|
271
|
-
if (
|
|
272
|
-
|
|
278
|
+
const name = processName ?? '';
|
|
279
|
+
if (name) {
|
|
280
|
+
const hit = await this.querySurrogate(operator, name, at);
|
|
281
|
+
if (hit)
|
|
282
|
+
return hit;
|
|
283
|
+
}
|
|
273
284
|
return this.querySurrogate(operator, '', at);
|
|
274
285
|
}
|
|
275
286
|
async querySurrogate(operator, processName, at) {
|
package/dist/memory-ext.d.ts
CHANGED
|
@@ -17,5 +17,15 @@ export declare class MemoryExtRepository implements ProcessExtRepository {
|
|
|
17
17
|
updateSurrogate(s: ProcessSurrogate): Promise<void>;
|
|
18
18
|
removeSurrogate(id: string): Promise<void>;
|
|
19
19
|
pageSurrogates(_pageNum?: number, _pageSize?: number, filters?: Record<string, any>, conditions?: QueryCondition[]): Promise<[ProcessSurrogate[], number]>;
|
|
20
|
+
/**
|
|
21
|
+
* 生效委托查询(issues/116 判据 a~d,与 JdbcProcessExtRepository.getSurrogate 同口径,
|
|
22
|
+
* 同一份数据两仓必须给出同一结论):
|
|
23
|
+
* a. processName 先精确命中,未命中再兜底空 process_name(全流程委托)
|
|
24
|
+
* b. 时间窗 start_time <= at <= end_time,任一侧为空 = 该侧不限
|
|
25
|
+
* c. 自委托过滤:surrogate <> operator
|
|
26
|
+
* d. enabled 只认整数 1,脏值不当启用
|
|
27
|
+
* 多条命中取**主键 id 最大**(判据 1.4,对齐 SQL 侧 `ORDER BY id DESC LIMIT 1`;
|
|
28
|
+
* 显式比 id,不依赖 Map 插入序,见 surrogateIdLess)
|
|
29
|
+
*/
|
|
20
30
|
getSurrogate(operator: string, processName: string, at?: Date): Promise<ProcessSurrogate | null>;
|
|
21
31
|
}
|
package/dist/memory-ext.js
CHANGED
|
@@ -19,6 +19,47 @@ function pickFields(row, map) {
|
|
|
19
19
|
}
|
|
20
20
|
return fields;
|
|
21
21
|
}
|
|
22
|
+
// ── 委托查询判据基建(issues/116 判据 b/d,与 SQL 仓同口径)─────────────────
|
|
23
|
+
/** 时间归一为毫秒:Date/毫秒数/可解析字符串均可;空值或脏值 → null(该侧不限,对齐 SQL 侧 NULL) */
|
|
24
|
+
function surrogateTimeMs(v) {
|
|
25
|
+
if (v == null || v === '')
|
|
26
|
+
return null;
|
|
27
|
+
if (v instanceof Date)
|
|
28
|
+
return Number.isNaN(v.getTime()) ? null : v.getTime();
|
|
29
|
+
if (typeof v === 'number')
|
|
30
|
+
return Number.isNaN(v) ? null : v;
|
|
31
|
+
if (typeof v === 'string') {
|
|
32
|
+
// 兼容 'yyyy-MM-dd HH:mm:ss'(Safari/Node 对空格分隔不统一,转 T 再解)
|
|
33
|
+
const n = Date.parse(v.trim().replace(' ', 'T'));
|
|
34
|
+
return Number.isNaN(n) ? null : n;
|
|
35
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
/** enabled 只认整数 1('1' 视作 1,与 SQL 侧 INT 列同结论);脏值('abc'/true/0/2/空)一律不启用 */
|
|
39
|
+
function surrogateEnabled(v) {
|
|
40
|
+
if (typeof v === 'number')
|
|
41
|
+
return v === 1;
|
|
42
|
+
if (typeof v === 'string') {
|
|
43
|
+
const s = v.trim();
|
|
44
|
+
return s !== '' && Number.isInteger(Number(s)) && Number(s) === 1;
|
|
45
|
+
}
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* 判据 1.4:比较两条委托的主键大小(a 是否比 b 旧)。id 是雪花数字串(19 位,已超
|
|
50
|
+
* Number 安全整数),纯数字串一律按 BigInt 比**数值**(与 SQL 侧 `ORDER BY id DESC` 同序),
|
|
51
|
+
* 非数字 id 退化为字符串序。
|
|
52
|
+
*
|
|
53
|
+
* ⚠️ 不能拿 Map 的插入序当 id 序:saveSurrogate/updateSurrogate 都接受调用方显式 id,
|
|
54
|
+
* 乱序写入(补录、导入、双仓对拍)时"取遍历到的末条"就会与 SQL 仓给出不同答案。
|
|
55
|
+
* Go 内存仓原实现正是"map 随机序取到啥算啥"被抓出来重写的(issues/116 §5)。
|
|
56
|
+
*/
|
|
57
|
+
function surrogateIdLess(a, b) {
|
|
58
|
+
const sa = String(a ?? ''), sb = String(b ?? '');
|
|
59
|
+
if (/^\d+$/.test(sa) && /^\d+$/.test(sb))
|
|
60
|
+
return BigInt(sa) < BigInt(sb);
|
|
61
|
+
return sa < sb;
|
|
62
|
+
}
|
|
22
63
|
export class MemoryExtRepository {
|
|
23
64
|
designs = new Map();
|
|
24
65
|
designHis = new Map();
|
|
@@ -94,20 +135,48 @@ export class MemoryExtRepository {
|
|
|
94
135
|
});
|
|
95
136
|
return [rows, rows.length];
|
|
96
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* 生效委托查询(issues/116 判据 a~d,与 JdbcProcessExtRepository.getSurrogate 同口径,
|
|
140
|
+
* 同一份数据两仓必须给出同一结论):
|
|
141
|
+
* a. processName 先精确命中,未命中再兜底空 process_name(全流程委托)
|
|
142
|
+
* b. 时间窗 start_time <= at <= end_time,任一侧为空 = 该侧不限
|
|
143
|
+
* c. 自委托过滤:surrogate <> operator
|
|
144
|
+
* d. enabled 只认整数 1,脏值不当启用
|
|
145
|
+
* 多条命中取**主键 id 最大**(判据 1.4,对齐 SQL 侧 `ORDER BY id DESC LIMIT 1`;
|
|
146
|
+
* 显式比 id,不依赖 Map 插入序,见 surrogateIdLess)
|
|
147
|
+
*/
|
|
97
148
|
async getSurrogate(operator, processName, at = new Date()) {
|
|
98
|
-
|
|
149
|
+
const name = processName ?? '';
|
|
150
|
+
const now = surrogateTimeMs(at);
|
|
151
|
+
let exact = null;
|
|
152
|
+
let global = null;
|
|
99
153
|
for (const s of this.surrogates.values()) {
|
|
100
|
-
if (s.operator !== operator
|
|
101
|
-
continue;
|
|
102
|
-
if (s.startTime && s.startTime > at)
|
|
154
|
+
if (s.operator !== operator)
|
|
103
155
|
continue;
|
|
104
|
-
if (s.
|
|
105
|
-
continue;
|
|
106
|
-
if (s.
|
|
107
|
-
|
|
108
|
-
if (
|
|
109
|
-
|
|
156
|
+
if (s.surrogate === operator)
|
|
157
|
+
continue; // c 自委托过滤
|
|
158
|
+
if (!surrogateEnabled(s.enabled))
|
|
159
|
+
continue; // d enabled 只认 1
|
|
160
|
+
if (now != null) { // b 时间窗(空 = 不限)
|
|
161
|
+
const start = surrogateTimeMs(s.startTime);
|
|
162
|
+
const end = surrogateTimeMs(s.endTime);
|
|
163
|
+
if (start != null && start > now)
|
|
164
|
+
continue;
|
|
165
|
+
if (end != null && end < now)
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
const bucket = (name && s.processName === name) ? 'exact' : (!s.processName ? 'global' : '');
|
|
169
|
+
if (!bucket)
|
|
170
|
+
continue; // a 异流程名的行既非精确也非兜底
|
|
171
|
+
const cur = bucket === 'exact' ? exact : global;
|
|
172
|
+
if (cur == null || surrogateIdLess(cur.id, s.id)) {
|
|
173
|
+
if (bucket === 'exact')
|
|
174
|
+
exact = s;
|
|
175
|
+
else
|
|
176
|
+
global = s;
|
|
177
|
+
}
|
|
110
178
|
}
|
|
111
|
-
|
|
179
|
+
const hit = exact ?? global; // a 精确优先,其次全流程兜底
|
|
180
|
+
return hit ? { ...hit } : null;
|
|
112
181
|
}
|
|
113
182
|
}
|
package/dist/metadata.js
CHANGED
|
@@ -15,7 +15,7 @@ const DICTS = {
|
|
|
15
15
|
wf_process_submit_type: [
|
|
16
16
|
{ value: '0', label: '发起申请' }, { value: '1', label: '同意申请' }, { value: '2', label: '拒绝申请' },
|
|
17
17
|
{ value: '3', label: '退回上一步' }, { value: '4', label: '跳转' }, { value: '5', label: '重新提交' },
|
|
18
|
-
{ value: '6', label: '退回发起人' }, { value: '20', label: '
|
|
18
|
+
{ value: '6', label: '退回发起人' }, { value: '7', label: '转办' }, { value: '20', label: '会签拒绝' },
|
|
19
19
|
],
|
|
20
20
|
wf_process_task_state: [
|
|
21
21
|
{ value: '10', label: '进行中' }, { value: '20', label: '已完成' }, { value: '30', label: '已撤回' },
|
package/dist/model.d.ts
CHANGED
|
@@ -108,6 +108,8 @@ export declare enum SubmitType {
|
|
|
108
108
|
Jump = 4,
|
|
109
109
|
ReApply = 5,
|
|
110
110
|
RollbackToOperator = 6,
|
|
111
|
+
/** issues/115:转办留痕(processTask/transfer 用,不走 execute) */
|
|
112
|
+
Transfer = 7,
|
|
111
113
|
CountersignDisagree = 20
|
|
112
114
|
}
|
|
113
115
|
/** 任务类型(wf_process_task_type) */
|
|
@@ -165,8 +167,11 @@ export declare class ProcessInstance {
|
|
|
165
167
|
getDoneTasks(): ProcessTask[];
|
|
166
168
|
/** 所有任务是否都已完成(join 合并判断) */
|
|
167
169
|
isAllTasksFinished(): boolean;
|
|
168
|
-
/**
|
|
169
|
-
|
|
170
|
+
/** 建单不变量(issues/121 P1):本工厂必写 parentTaskId(发起 execution 无当前任务时传字符 0)
|
|
171
|
+
* 与行级 isFirstTaskNode;两参无默认值,漏传即编译不过,不留静默漏写路径。
|
|
172
|
+
*
|
|
173
|
+
* 创建任务(子实体工厂)——performType:0 普通 / 1 会签(issues/52 E24 落库对齐 Java) */
|
|
174
|
+
createTask(id: string, taskName: string, displayName: string, actor: string, operator: string, formKey: string, now: Date, parentId: string, isFirst: boolean, performType?: number): ProcessTask;
|
|
170
175
|
}
|
|
171
176
|
export declare class ProcessTask {
|
|
172
177
|
id: string;
|
|
@@ -192,6 +197,8 @@ export declare class ProcessTask {
|
|
|
192
197
|
finish(operator: string, vars: Record<string, any>, now: Date): void;
|
|
193
198
|
/** 废弃任务 */
|
|
194
199
|
abandon(now: Date): void;
|
|
200
|
+
/** 随实例撤回任务(区别于 abandon:撤回是发起人主动收回,废弃是引擎清理) */
|
|
201
|
+
withdraw(now: Date): void;
|
|
195
202
|
/** 是否进行中 */
|
|
196
203
|
isDoing(): boolean;
|
|
197
204
|
/** 是否已完成 */
|
package/dist/model.js
CHANGED
|
@@ -43,6 +43,8 @@ export var SubmitType;
|
|
|
43
43
|
SubmitType[SubmitType["Jump"] = 4] = "Jump";
|
|
44
44
|
SubmitType[SubmitType["ReApply"] = 5] = "ReApply";
|
|
45
45
|
SubmitType[SubmitType["RollbackToOperator"] = 6] = "RollbackToOperator";
|
|
46
|
+
/** issues/115:转办留痕(processTask/transfer 用,不走 execute) */
|
|
47
|
+
SubmitType[SubmitType["Transfer"] = 7] = "Transfer";
|
|
46
48
|
SubmitType[SubmitType["CountersignDisagree"] = 20] = "CountersignDisagree";
|
|
47
49
|
})(SubmitType || (SubmitType = {}));
|
|
48
50
|
/** 任务类型(wf_process_task_type) */
|
|
@@ -149,14 +151,17 @@ export class ProcessInstance {
|
|
|
149
151
|
isAllTasksFinished() {
|
|
150
152
|
return !this.tasks.some(t => t.isDoing());
|
|
151
153
|
}
|
|
152
|
-
/**
|
|
153
|
-
|
|
154
|
+
/** 建单不变量(issues/121 P1):本工厂必写 parentTaskId(发起 execution 无当前任务时传字符 0)
|
|
155
|
+
* 与行级 isFirstTaskNode;两参无默认值,漏传即编译不过,不留静默漏写路径。
|
|
156
|
+
*
|
|
157
|
+
* 创建任务(子实体工厂)——performType:0 普通 / 1 会签(issues/52 E24 落库对齐 Java) */
|
|
158
|
+
createTask(id, taskName, displayName, actor, operator, formKey, now, parentId, isFirst, performType = 0) {
|
|
154
159
|
const task = new ProcessTask({
|
|
155
160
|
id, processInstanceId: this.id,
|
|
156
161
|
taskName, displayName, taskState: TaskState.Doing,
|
|
157
162
|
actorId: '', actorIds: [actor],
|
|
158
|
-
taskType: 0, performType, formKey,
|
|
159
|
-
variables: {},
|
|
163
|
+
taskType: 0, performType, formKey, parentTaskId: parentId,
|
|
164
|
+
variables: { isFirstTaskNode: isFirst },
|
|
160
165
|
createTime: now, updateTime: now, createUser: operator, updateUser: operator,
|
|
161
166
|
});
|
|
162
167
|
this.tasks.push(task);
|
|
@@ -200,6 +205,11 @@ export class ProcessTask {
|
|
|
200
205
|
this.taskState = TaskState.Abandoned;
|
|
201
206
|
this.updateTime = now;
|
|
202
207
|
}
|
|
208
|
+
/** 随实例撤回任务(区别于 abandon:撤回是发起人主动收回,废弃是引擎清理) */
|
|
209
|
+
withdraw(now) {
|
|
210
|
+
this.taskState = TaskState.Withdraw;
|
|
211
|
+
this.updateTime = now;
|
|
212
|
+
}
|
|
203
213
|
/** 是否进行中 */
|
|
204
214
|
isDoing() { return this.taskState === TaskState.Doing; }
|
|
205
215
|
/** 是否已完成 */
|