@mldong/jeeflow 1.1.0 → 1.2.0
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/facade.d.ts +16 -0
- package/dist/facade.js +253 -0
- package/package.json +1 -1
package/dist/facade.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import type { ProcessExtRepository, ProcessRepository } from './spi.js';
|
|
2
2
|
import type { EngineImpl } from './engine.js';
|
|
3
|
+
export type UserSearch = (query: Record<string, any>) => Promise<[Record<string, any>[], number]> | [Record<string, any>[], number];
|
|
3
4
|
export declare class JeeflowFacade {
|
|
4
5
|
private readonly engine;
|
|
5
6
|
private readonly repo;
|
|
6
7
|
private readonly extRepo?;
|
|
8
|
+
private userSearch?;
|
|
7
9
|
constructor(engine: EngineImpl, repo: ProcessRepository, extRepo?: ProcessExtRepository | undefined);
|
|
10
|
+
setUserSearch(fn: UserSearch): this;
|
|
8
11
|
flow(action: string, args?: Record<string, any>): Promise<Record<string, any>>;
|
|
9
12
|
private dispatch;
|
|
10
13
|
private startAndExecute;
|
|
@@ -18,5 +21,18 @@ export declare class JeeflowFacade {
|
|
|
18
21
|
private designSave;
|
|
19
22
|
private surrogatePage;
|
|
20
23
|
private surrogateSave;
|
|
24
|
+
private getLastByName;
|
|
25
|
+
private highLight;
|
|
26
|
+
private collectPath;
|
|
27
|
+
private approvalRecord;
|
|
28
|
+
private getAssigneeTextData;
|
|
29
|
+
private createCCInstance;
|
|
30
|
+
private updateCCStatus;
|
|
31
|
+
private taskDetail;
|
|
32
|
+
private jumpAbleTaskNameList;
|
|
33
|
+
private candidatePage;
|
|
34
|
+
private nextTaskCandidates;
|
|
35
|
+
private taskAddActor;
|
|
36
|
+
private taskLatest;
|
|
21
37
|
private ext;
|
|
22
38
|
}
|
package/dist/facade.js
CHANGED
|
@@ -15,11 +15,17 @@ export class JeeflowFacade {
|
|
|
15
15
|
engine;
|
|
16
16
|
repo;
|
|
17
17
|
extRepo;
|
|
18
|
+
userSearch;
|
|
18
19
|
constructor(engine, repo, extRepo) {
|
|
19
20
|
this.engine = engine;
|
|
20
21
|
this.repo = repo;
|
|
21
22
|
this.extRepo = extRepo;
|
|
22
23
|
}
|
|
24
|
+
// 注入用户搜索钩子(candidatePage 无模型候选时的用户分页搜索)
|
|
25
|
+
setUserSearch(fn) {
|
|
26
|
+
this.userSearch = fn;
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
23
29
|
async flow(action, args = {}) {
|
|
24
30
|
try {
|
|
25
31
|
const data = await this.dispatch(action, args);
|
|
@@ -61,6 +67,31 @@ export class JeeflowFacade {
|
|
|
61
67
|
return this.surrogateSave(args);
|
|
62
68
|
case 'processSurrogate/remove':
|
|
63
69
|
return this.ext().removeSurrogate(toId(args.id));
|
|
70
|
+
case 'processDefine/getLastByName':
|
|
71
|
+
return this.getLastByName(args);
|
|
72
|
+
case 'processInstance/highLight':
|
|
73
|
+
return this.highLight(args);
|
|
74
|
+
case 'processInstance/approvalRecord':
|
|
75
|
+
return this.approvalRecord(args);
|
|
76
|
+
case 'processInstance/getAssigneeTextData':
|
|
77
|
+
return this.getAssigneeTextData(args);
|
|
78
|
+
case 'processInstance/createCCInstance':
|
|
79
|
+
return this.createCCInstance(args);
|
|
80
|
+
case 'processInstance/updateCCStatus':
|
|
81
|
+
return this.updateCCStatus(args);
|
|
82
|
+
case 'processInstance/ccList':
|
|
83
|
+
throw new Error('ccList 需要核心分页 SPI(pageCcInstances),当前语言 1.3.0 补齐');
|
|
84
|
+
case 'processTask/detail':
|
|
85
|
+
return this.taskDetail(args);
|
|
86
|
+
case 'processTask/jumpAbleTaskNameList':
|
|
87
|
+
return this.jumpAbleTaskNameList(args);
|
|
88
|
+
case 'processTask/candidatePage':
|
|
89
|
+
return this.candidatePage(args);
|
|
90
|
+
case 'processTask/surrogate':
|
|
91
|
+
case 'processTask/addCandidate':
|
|
92
|
+
return this.taskAddActor(args);
|
|
93
|
+
case 'processTask/latest':
|
|
94
|
+
return this.taskLatest(args);
|
|
64
95
|
default:
|
|
65
96
|
throw new Error(`未知 action: ${action}`);
|
|
66
97
|
}
|
|
@@ -299,6 +330,221 @@ export class JeeflowFacade {
|
|
|
299
330
|
}
|
|
300
331
|
return { id: surrogate.id };
|
|
301
332
|
}
|
|
333
|
+
// ── 视图端点(v1.2.0) ──────────────────────────────────────────────────
|
|
334
|
+
async getLastByName(args) {
|
|
335
|
+
const def = await this.repo.findDefineByName(String(args.processDefineName ?? ''));
|
|
336
|
+
if (!def)
|
|
337
|
+
throw new Error(`流程定义不存在: ${args.processDefineName}`);
|
|
338
|
+
return { id: def.id, name: def.name, displayName: def.displayName, type: def.type, state: def.state, version: def.version };
|
|
339
|
+
}
|
|
340
|
+
async highLight(args) {
|
|
341
|
+
const instanceId = toId(args.id);
|
|
342
|
+
const inst = await this.repo.findInstanceById(instanceId);
|
|
343
|
+
if (!inst)
|
|
344
|
+
throw new Error('流程实例不存在');
|
|
345
|
+
const active = [];
|
|
346
|
+
const history = [];
|
|
347
|
+
const edges = [];
|
|
348
|
+
const doing = await this.repo.findDoingTasks(instanceId);
|
|
349
|
+
for (const t of doing)
|
|
350
|
+
if (!active.includes(t.taskName))
|
|
351
|
+
active.push(t.taskName);
|
|
352
|
+
const his = await this.repo.findHistoryTasks(instanceId);
|
|
353
|
+
for (const t of his)
|
|
354
|
+
if (!active.includes(t.taskName) && !history.includes(t.taskName))
|
|
355
|
+
history.push(t.taskName);
|
|
356
|
+
// 路径补全:start 沿边递归(遇活跃节点停止)
|
|
357
|
+
const def = await this.repo.findDefineById(inst.defineId);
|
|
358
|
+
if (def) {
|
|
359
|
+
try {
|
|
360
|
+
const flow = JSON.parse(toStr(def.content));
|
|
361
|
+
this.collectPath(flow, 'start', '', active, history, edges, new Set());
|
|
362
|
+
}
|
|
363
|
+
catch { /* ignore */ }
|
|
364
|
+
}
|
|
365
|
+
return { activeNodeNames: active, historyNodeNames: history, historyEdgeNames: edges };
|
|
366
|
+
}
|
|
367
|
+
collectPath(flow, nodeId, edgeName, active, history, edges, visited) {
|
|
368
|
+
if (visited.has(nodeId))
|
|
369
|
+
return;
|
|
370
|
+
visited.add(nodeId);
|
|
371
|
+
if (edgeName && !edges.includes(edgeName))
|
|
372
|
+
edges.push(edgeName);
|
|
373
|
+
for (const e of flow.edges ?? []) {
|
|
374
|
+
if (e.sourceNodeId !== nodeId)
|
|
375
|
+
continue;
|
|
376
|
+
const target = (flow.nodes ?? []).find((n) => n.id === e.targetNodeId);
|
|
377
|
+
if (!target)
|
|
378
|
+
continue;
|
|
379
|
+
const tid = target.id;
|
|
380
|
+
if (!active.includes(tid) && !history.includes(tid))
|
|
381
|
+
history.push(tid);
|
|
382
|
+
if (active.includes(tid))
|
|
383
|
+
continue;
|
|
384
|
+
this.collectPath(flow, tid, e.id, active, history, edges, visited);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
async approvalRecord(args) {
|
|
388
|
+
const instanceId = toId(args.id);
|
|
389
|
+
const his = await this.repo.findHistoryTasks(instanceId);
|
|
390
|
+
return his.map(t => ({
|
|
391
|
+
taskName: t.taskName, displayName: t.displayName, taskType: t.taskType ?? null,
|
|
392
|
+
performType: t.performType ?? null, taskState: t.taskState, operator: t.actorId ?? '',
|
|
393
|
+
finishTime: t.finishTime ?? null, variable: t.variables ?? {},
|
|
394
|
+
}));
|
|
395
|
+
}
|
|
396
|
+
async getAssigneeTextData(args) {
|
|
397
|
+
const instanceId = toId(args.id);
|
|
398
|
+
const includeNodeName = args.includeNodeName !== false;
|
|
399
|
+
const rows = [];
|
|
400
|
+
const doing = await this.repo.findDoingTasks(instanceId);
|
|
401
|
+
for (const t of doing) {
|
|
402
|
+
const actors = await this.repo.findTaskActors(t.id);
|
|
403
|
+
for (const actor of actors) {
|
|
404
|
+
rows.push({ label: includeNodeName ? `${t.displayName}:${actor}` : actor, value: actor });
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
return rows;
|
|
408
|
+
}
|
|
409
|
+
async createCCInstance(args) {
|
|
410
|
+
const instanceId = toId(args.processInstanceId);
|
|
411
|
+
const operator = String(args.operator ?? 'user1');
|
|
412
|
+
const actors = toStringList2(args.actorIds);
|
|
413
|
+
if (actors.length === 0)
|
|
414
|
+
throw new Error('actorIds 缺失');
|
|
415
|
+
await this.repo.createCcInstance(instanceId, operator, ...actors);
|
|
416
|
+
}
|
|
417
|
+
async updateCCStatus(args) {
|
|
418
|
+
const instanceId = toId(args.processInstanceId);
|
|
419
|
+
const operator = String(args.operator ?? 'user1');
|
|
420
|
+
await this.repo.updateCcStatus(instanceId, operator);
|
|
421
|
+
}
|
|
422
|
+
async taskDetail(args) {
|
|
423
|
+
const taskId = toId(args.id);
|
|
424
|
+
const operator = String(args.operator ?? 'user1');
|
|
425
|
+
const task = await this.repo.findTaskById(taskId);
|
|
426
|
+
if (!task)
|
|
427
|
+
throw new Error('任务不存在');
|
|
428
|
+
const actors = await this.repo.findTaskActors(taskId);
|
|
429
|
+
const vo = {
|
|
430
|
+
id: task.id, processInstanceId: task.processInstanceId, taskName: task.taskName,
|
|
431
|
+
displayName: task.displayName, taskType: task.taskType ?? null,
|
|
432
|
+
performType: task.performType ?? null, taskState: task.taskState,
|
|
433
|
+
operator: task.actorId ?? '', formKey: task.formKey ?? '',
|
|
434
|
+
taskActorIdList: actors, executable: task.isAllowed(operator),
|
|
435
|
+
};
|
|
436
|
+
// taskModel:流程定义中对应节点
|
|
437
|
+
const inst = await this.repo.findInstanceById(task.processInstanceId);
|
|
438
|
+
if (inst) {
|
|
439
|
+
const def = await this.repo.findDefineById(inst.defineId);
|
|
440
|
+
if (def) {
|
|
441
|
+
try {
|
|
442
|
+
const flow = JSON.parse(toStr(def.content));
|
|
443
|
+
for (const n of flow.nodes ?? []) {
|
|
444
|
+
if (n.id === task.taskName) {
|
|
445
|
+
vo.taskModel = { name: n.id, displayName: n.text?.value ?? '', type: n.type };
|
|
446
|
+
break;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
catch { /* ignore */ }
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
return vo;
|
|
454
|
+
}
|
|
455
|
+
async jumpAbleTaskNameList(args) {
|
|
456
|
+
const instanceId = toId(args.processInstanceId);
|
|
457
|
+
const done = await this.repo.findDoneTasks(instanceId);
|
|
458
|
+
const rows = [];
|
|
459
|
+
const seen = new Set();
|
|
460
|
+
for (const t of done) {
|
|
461
|
+
if ((t.performType ?? 0) === 1)
|
|
462
|
+
continue; // COUNTERSIGN
|
|
463
|
+
if (!seen.has(t.taskName)) {
|
|
464
|
+
seen.add(t.taskName);
|
|
465
|
+
rows.push({ label: t.displayName, value: t.taskName });
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
return rows;
|
|
469
|
+
}
|
|
470
|
+
async candidatePage(args) {
|
|
471
|
+
const taskId = toId(args.processTaskId ?? args.id);
|
|
472
|
+
const task = await this.repo.findTaskById(taskId);
|
|
473
|
+
if (!task)
|
|
474
|
+
throw new Error('任务不存在');
|
|
475
|
+
const inst = await this.repo.findInstanceById(task.processInstanceId);
|
|
476
|
+
if (!inst)
|
|
477
|
+
throw new Error('流程实例不存在');
|
|
478
|
+
// 模型候选解析:后继任务节点的 candidateUsers 配置
|
|
479
|
+
let candidates = [];
|
|
480
|
+
const def = await this.repo.findDefineById(inst.defineId);
|
|
481
|
+
if (def) {
|
|
482
|
+
try {
|
|
483
|
+
const flow = JSON.parse(toStr(def.content));
|
|
484
|
+
candidates = this.nextTaskCandidates(flow, task.taskName);
|
|
485
|
+
}
|
|
486
|
+
catch { /* ignore */ }
|
|
487
|
+
}
|
|
488
|
+
if (candidates.length > 0) {
|
|
489
|
+
const rows = candidates.map(c => ({ userId: c, realName: c }));
|
|
490
|
+
return { rows, recordCount: rows.length };
|
|
491
|
+
}
|
|
492
|
+
// 无模型候选 → 用户分页搜索(依赖 userSearch 钩子)
|
|
493
|
+
if (!this.userSearch)
|
|
494
|
+
throw new Error('未配置 userSearch(用户搜索钩子)');
|
|
495
|
+
const [rows, total] = await this.userSearch(args);
|
|
496
|
+
return { rows, recordCount: total };
|
|
497
|
+
}
|
|
498
|
+
nextTaskCandidates(flow, taskName) {
|
|
499
|
+
const result = [];
|
|
500
|
+
const visited = new Set();
|
|
501
|
+
const collect = (node) => {
|
|
502
|
+
const v = node.properties?.candidateUsers;
|
|
503
|
+
if (v) {
|
|
504
|
+
for (const s of String(v).split(',')) {
|
|
505
|
+
const t = s.trim();
|
|
506
|
+
if (t && !result.includes(t))
|
|
507
|
+
result.push(t);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
};
|
|
511
|
+
const walk = (nodeId) => {
|
|
512
|
+
if (visited.has(nodeId))
|
|
513
|
+
return;
|
|
514
|
+
visited.add(nodeId);
|
|
515
|
+
for (const e of flow.edges ?? []) {
|
|
516
|
+
if (e.sourceNodeId !== nodeId)
|
|
517
|
+
continue;
|
|
518
|
+
const target = (flow.nodes ?? []).find((n) => n.id === e.targetNodeId);
|
|
519
|
+
if (!target)
|
|
520
|
+
continue;
|
|
521
|
+
if (target.type === 'snaker:task' || target.type === 'snaker:custom') {
|
|
522
|
+
collect(target);
|
|
523
|
+
continue;
|
|
524
|
+
}
|
|
525
|
+
if (['snaker:fork', 'snaker:join', 'snaker:decision'].includes(target.type)) {
|
|
526
|
+
walk(target.id);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
};
|
|
530
|
+
walk(taskName);
|
|
531
|
+
return result;
|
|
532
|
+
}
|
|
533
|
+
async taskAddActor(args) {
|
|
534
|
+
const taskId = toId(args.processTaskId);
|
|
535
|
+
const actors = toStringList2(args.actorIds);
|
|
536
|
+
if (actors.length === 0)
|
|
537
|
+
throw new Error('actorIds 缺失');
|
|
538
|
+
await this.repo.addTaskActor(taskId, actors);
|
|
539
|
+
}
|
|
540
|
+
async taskLatest(args) {
|
|
541
|
+
const instanceId = toId(args.processInstanceId);
|
|
542
|
+
const doing = await this.repo.findDoingTasks(instanceId);
|
|
543
|
+
if (doing.length === 0)
|
|
544
|
+
return null;
|
|
545
|
+
const t = doing[0];
|
|
546
|
+
return { id: t.id, taskName: t.taskName, displayName: t.displayName, taskState: t.taskState, operator: t.actorId ?? '' };
|
|
547
|
+
}
|
|
302
548
|
ext() {
|
|
303
549
|
if (!this.extRepo)
|
|
304
550
|
throw new Error('未配置 ProcessExtRepository(扩展仓储)');
|
|
@@ -321,6 +567,13 @@ function toId(v) {
|
|
|
321
567
|
throw new Error('id 缺失或非法');
|
|
322
568
|
return n;
|
|
323
569
|
}
|
|
570
|
+
function toStringList2(v) {
|
|
571
|
+
if (Array.isArray(v))
|
|
572
|
+
return v.map(String);
|
|
573
|
+
if (typeof v === 'string')
|
|
574
|
+
return v.split(',').map(s => s.trim()).filter(Boolean);
|
|
575
|
+
return [];
|
|
576
|
+
}
|
|
324
577
|
function toInt(v) {
|
|
325
578
|
const n = Number(v);
|
|
326
579
|
if (!Number.isFinite(n))
|