@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/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) ──────────────────────────────────────────────────
|
|
@@ -796,7 +828,10 @@ export class JeeflowFacade {
|
|
|
796
828
|
return his.map(t => ({
|
|
797
829
|
taskName: t.taskName, displayName: t.displayName, taskType: t.taskType ?? null,
|
|
798
830
|
performType: t.performType ?? null, taskState: t.taskState, operator: t.actorId ?? '',
|
|
799
|
-
|
|
831
|
+
// issues/122:可空时间列空值出 '' 不出 null——mldong-nestjs 全局 SmartNullStripping
|
|
832
|
+
// 拦截器会把 null 值整键剥掉(本出口是对象字面量,拿不到 keepNull:fields 元数据),
|
|
833
|
+
// 出 '' 才能让键恒在,形状也与 boot2 的 record 行一致。
|
|
834
|
+
finishTime: fmtTime(t.finishTime) ?? '', variable: t.variables ?? {},
|
|
800
835
|
ext: t.variables ?? {}, // issues/15:前端读 ext.tf_approvalComment
|
|
801
836
|
}));
|
|
802
837
|
}
|
|
@@ -849,7 +884,9 @@ export class JeeflowFacade {
|
|
|
849
884
|
// 首个任务节点且 DOING → true,与 instance detail 的 activeTaskList 行语义一致
|
|
850
885
|
const tExt = { ...(task.variables ?? {}) };
|
|
851
886
|
const doing = task.taskState === TaskState.Doing;
|
|
852
|
-
|
|
887
|
+
// 先留住行上值再覆写出口,否则丢掉「缺键」这个事实就没法回退现算
|
|
888
|
+
const tRowFirst = task.variables?.isFirstTaskNode;
|
|
889
|
+
tExt.isFirstTaskNode = tRowFirst != null ? Boolean(tRowFirst) : false;
|
|
853
890
|
const vo = {
|
|
854
891
|
id: task.id, processInstanceId: task.processInstanceId, taskName: task.taskName,
|
|
855
892
|
displayName: task.displayName, taskType: task.taskType ?? null,
|
|
@@ -865,7 +902,10 @@ export class JeeflowFacade {
|
|
|
865
902
|
const def = await this.repo.findDefineById(inst.defineId);
|
|
866
903
|
if (def) {
|
|
867
904
|
vo.jsonObject = this.parseGraph(def.content); // issues/05
|
|
868
|
-
|
|
905
|
+
if (tRowFirst == null) {
|
|
906
|
+
// 存量行没有落库标记 ⇒ 回退现算(仅进行中口径)
|
|
907
|
+
tExt.isFirstTaskNode = doing && task.taskName === this.firstTaskNodeId(vo.jsonObject);
|
|
908
|
+
}
|
|
869
909
|
try {
|
|
870
910
|
const flow = JSON.parse(toStr(def.content));
|
|
871
911
|
for (const n of flow.nodes ?? []) {
|
|
@@ -987,6 +1027,70 @@ export class JeeflowFacade {
|
|
|
987
1027
|
throw new Error('actorIds 缺失');
|
|
988
1028
|
await this.repo.addTaskActor(taskId, actors);
|
|
989
1029
|
}
|
|
1030
|
+
/**
|
|
1031
|
+
* issues/115:转办(摘原人 + 换新人),区别于 surrogate 加签的"只追加"。七条契约语义(spec 06):
|
|
1032
|
+
* 只摘 fromActor 那一行 actor / toActor 追加 / 沿用同一 taskId / 留痕三件(submitType=7 槽位 +
|
|
1033
|
+
* tf_transferHistory 追加式账本 + 末跳 tf_approvalComment 文案)/ 变量合并序 实例←任务←本次 /
|
|
1034
|
+
* 四类明确报错(msg 跨栈统一)。
|
|
1035
|
+
*/
|
|
1036
|
+
async taskTransfer(args) {
|
|
1037
|
+
const taskId = toId(args.processTaskId);
|
|
1038
|
+
const operator = String(args.operator ?? '').trim();
|
|
1039
|
+
if (!operator)
|
|
1040
|
+
throw new Error('operator 必填');
|
|
1041
|
+
const fromActor = String(args.fromActor ?? '').trim();
|
|
1042
|
+
const toActor = String(args.toActor ?? '').trim();
|
|
1043
|
+
if (!fromActor)
|
|
1044
|
+
throw new Error('fromActor 必填');
|
|
1045
|
+
if (!toActor)
|
|
1046
|
+
throw new Error('toActor 必填');
|
|
1047
|
+
// 归属判据:只能转自己那一条待办;flow.auto/flow.admin 放行(对齐 isAllowed 既有约定)
|
|
1048
|
+
const lower = operator.toLowerCase();
|
|
1049
|
+
if (operator !== fromActor && lower !== KeyAutoExecute && lower !== KeyAdminID) {
|
|
1050
|
+
throw new Error('无权限转办该任务');
|
|
1051
|
+
}
|
|
1052
|
+
const task = await this.repo.findTaskById(taskId);
|
|
1053
|
+
if (!task)
|
|
1054
|
+
throw new Error('任务不存在');
|
|
1055
|
+
// 前置态:仅进行中(DOING=10)任务可转办
|
|
1056
|
+
if (task.taskState !== TaskState.Doing)
|
|
1057
|
+
throw new Error('任务非进行中,不可转办');
|
|
1058
|
+
const actors = await this.repo.findTaskActors(taskId);
|
|
1059
|
+
if (!actors.includes(fromActor))
|
|
1060
|
+
throw new Error('原办理人不是该任务参与人');
|
|
1061
|
+
if (actors.includes(toActor))
|
|
1062
|
+
throw new Error('目标人已是该任务参与人');
|
|
1063
|
+
// 摘原人(仅 fromActor 一行,会签其余成员不受影响)+ 加新人(同一 taskId,不新建任务)
|
|
1064
|
+
await this.repo.removeTaskActor(taskId, [fromActor]);
|
|
1065
|
+
await this.repo.addTaskActor(taskId, [toActor]);
|
|
1066
|
+
// 留痕三件(spec 06 clause 4,缺一不可):① 任务行 submitType=7 槽位 ② tf_transferHistory 账本
|
|
1067
|
+
// ③ 末跳可读文案 tf_approvalComment(approvalRecord 的 ext 读它)
|
|
1068
|
+
const reason = String(args.reason ?? '').trim();
|
|
1069
|
+
const now = new Date();
|
|
1070
|
+
// 账本动机:审批记录的槽位就是任务行本身,B 办结时 submitType 会被 1/2/20 覆盖——没有追加式
|
|
1071
|
+
// 账本,多跳转办只剩末跳、办结后转办事实整体消失,故本键每跳 append、永不覆盖。
|
|
1072
|
+
const history = Array.isArray(task.variables?.tf_transferHistory)
|
|
1073
|
+
? task.variables.tf_transferHistory
|
|
1074
|
+
: [];
|
|
1075
|
+
task.variables = {
|
|
1076
|
+
...(task.variables ?? {}),
|
|
1077
|
+
submitType: SUBMIT_TRANSFER,
|
|
1078
|
+
tf_transferTo: toActor,
|
|
1079
|
+
tf_transferReason: reason,
|
|
1080
|
+
// 时间格式按 spec §2.4 统一 yyyy-MM-dd HH:mm:ss(跨栈同形,前端免时区换算)
|
|
1081
|
+
tf_transferHistory: [...history, { submitType: SUBMIT_TRANSFER, fromActor, toActor, reason, time: fmtTime(now), operator }],
|
|
1082
|
+
tf_approvalComment: reason ? `${fromActor} 转办给 ${toActor}(${reason})` : `${fromActor} 转办给 ${toActor}`,
|
|
1083
|
+
};
|
|
1084
|
+
// 契约 06 §transfer 留痕⚠️:**严禁覆写 actorId/operator 列**——进行中任务该列恒无值是既有
|
|
1085
|
+
// 不变量;把被摘走的人写进去,该单撤回/终止后(离开 DOING 但列值留着)会凭空出现在
|
|
1086
|
+
// 他从没办过的「我已办」列表(pageDoneTasks 按 state <> 10 AND operator = ? 过滤,实测复现)。
|
|
1087
|
+
// 办理人由 updateUser + tf_transferHistory[].operator 承载。
|
|
1088
|
+
task.updateUser = operator;
|
|
1089
|
+
task.updateTime = now;
|
|
1090
|
+
// 仓储 updateTask 会以任务副本的 actorIds 覆写参与者(memory 语义),须同步为摘/加后的最新值
|
|
1091
|
+
task.actorIds = await this.repo.findTaskActors(taskId);
|
|
1092
|
+
await this.repo.updateTask(task);
|
|
1093
|
+
}
|
|
990
1094
|
async taskLatest(args) {
|
|
991
1095
|
const instanceId = toId(args.processInstanceId);
|
|
992
1096
|
const doing = await this.repo.findDoingTasks(instanceId);
|
|
@@ -1051,7 +1155,10 @@ export class JeeflowFacade {
|
|
|
1051
1155
|
};
|
|
1052
1156
|
const ext = { ...(t.variables ?? {}) };
|
|
1053
1157
|
const doing = t.taskState === TaskState.Doing;
|
|
1054
|
-
|
|
1158
|
+
// issues/121 P1:行上值优先(引擎建单时写入,历史行同样有效),缺键(存量行)才回退现算
|
|
1159
|
+
ext.isFirstTaskNode = t.variables?.isFirstTaskNode != null
|
|
1160
|
+
? Boolean(t.variables.isFirstTaskNode)
|
|
1161
|
+
: (doing && t.taskName === firstTaskNodeId);
|
|
1055
1162
|
vo.ext = ext;
|
|
1056
1163
|
tasks.push(vo);
|
|
1057
1164
|
if (doing)
|
|
@@ -1372,6 +1479,26 @@ function parseSurrogateTime(v) {
|
|
|
1372
1479
|
const d = new Date(s);
|
|
1373
1480
|
return isNaN(d.getTime()) ? undefined : d;
|
|
1374
1481
|
}
|
|
1482
|
+
/**
|
|
1483
|
+
* issues/116 判据 d 的写侧:委托启用位解析(processSurrogate/save 与 /update 共用)。
|
|
1484
|
+
* 契约「enabled 只有 1 生效,脏值不得默认当启用」——所以:
|
|
1485
|
+
* - 未传(null/undefined)→ 1,契约默认启用(06 §4.5 save 参数表 enabled 可省);
|
|
1486
|
+
* - 布尔 → true=1 / false=0(前端开关组件偶发传布尔,不算脏值);
|
|
1487
|
+
* - 传了但不可解析为整数('abc' / {} / NaN / 空串)→ **0 停用**落库,不抛错打断保存。
|
|
1488
|
+
* 对齐 Java `toInt(arg, 0)` / Go `parseSurrogateEnabled`;此前本栈走 `toInt(arg)`,
|
|
1489
|
+
* 脏值直接抛「数值缺失或非法」(门面 500),与其余各栈"落 0"行为分叉。
|
|
1490
|
+
*/
|
|
1491
|
+
function parseSurrogateEnabled(v) {
|
|
1492
|
+
if (v == null)
|
|
1493
|
+
return 1;
|
|
1494
|
+
if (typeof v === 'boolean')
|
|
1495
|
+
return v ? 1 : 0;
|
|
1496
|
+
const s = typeof v === 'string' ? v.trim() : v;
|
|
1497
|
+
if (s === '' || s == null)
|
|
1498
|
+
return 0;
|
|
1499
|
+
const n = Number(s);
|
|
1500
|
+
return Number.isInteger(n) ? n : 0;
|
|
1501
|
+
}
|
|
1375
1502
|
function designRowToMap(r) {
|
|
1376
1503
|
return {
|
|
1377
1504
|
id: r.id, name: r.name, displayName: r.displayName,
|
|
@@ -1409,7 +1536,10 @@ function ccRowToMap(r) {
|
|
|
1409
1536
|
/** 任务行:ext(任务变量,空回退实例变量)+ instanceExt + version */
|
|
1410
1537
|
function taskRowToMap(r) {
|
|
1411
1538
|
const instanceExt = parseVarMap(r.instanceVariable);
|
|
1412
|
-
|
|
1539
|
+
// issues/121 P1:引擎建单必写的控制键不算「任务变量非空」,否则新建任务的 ext
|
|
1540
|
+
// 永远不再回退实例变量(issues/82-3 既有契约)。
|
|
1541
|
+
const userKeys = Object.keys(r.variables ?? {}).filter(k => k !== 'isFirstTaskNode');
|
|
1542
|
+
const ext = userKeys.length > 0 ? r.variables : instanceExt;
|
|
1413
1543
|
return {
|
|
1414
1544
|
id: r.id, processInstanceId: r.processInstanceId, taskName: r.taskName,
|
|
1415
1545
|
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,8 +25,25 @@ 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 基准实现 + issues/123 的取行/裁决顺序):
|
|
30
|
+
* a. 作用域:先在该流程名作用域内取记录,该作用域**一条都没有**才兜底
|
|
31
|
+
* `process_name IS NULL OR = ''`(全流程委托);精确作用域里只要有记录就由它裁决;
|
|
32
|
+
* 然后由 `surrogateIsEffective` 裁决**这一条**:
|
|
33
|
+
* d. enabled 严格 1('1'/1 同结论,NULL 不生效)、c. 自委托过滤、
|
|
34
|
+
* b. 时间窗 start<=at<=end(任一侧 NULL = 该侧不限;`at` 传 null 则整段跳过窗比较)。
|
|
35
|
+
*
|
|
36
|
+
* ⚠️ 旧形状是 `WHERE operator=? AND enabled=1 AND surrogate<>? AND 窗口… ORDER BY id DESC LIMIT 1`
|
|
37
|
+
* ——先滤生效再取最新,等于"历史上留过一条窗内且 enabled=1 的记录就永久生效",用户随后
|
|
38
|
+
* 新建的窗外 / enabled=0 / 脏值 / 自委托记录全都判不动它(issues/123,13 栈 L2-17/L2-18 全红)。
|
|
39
|
+
* 现在 WHERE 里**不带**任何生效判据,只 `ORDER BY id DESC LIMIT 1` 取最新一条;
|
|
40
|
+
* 最新一条不生效 ⇒ 同层内不回落更旧那条,转看全流程作用域的最新一条;两层都判否才返回 null。
|
|
41
|
+
* 内存仓须给出同结论(MemoryExtRepository.getSurrogate,共用 src/surrogate-rule.ts)。
|
|
42
|
+
*/
|
|
28
43
|
getSurrogate(operator: string, processName: string, at?: Date): Promise<ProcessSurrogate | null>;
|
|
29
|
-
|
|
44
|
+
/** 该授权人在指定流程作用域内**最新的一条**委托:只排序取首行,不滤任何生效判据。
|
|
45
|
+
* processName 为 '' = 全流程委托作用域(process_name IS NULL OR = '')。 */
|
|
46
|
+
private queryNewestSurrogate;
|
|
30
47
|
private mapDesign;
|
|
31
48
|
private mapSurrogate;
|
|
32
49
|
}
|
package/dist/jdbc/ext.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// 与 shared.ts 同一套 SqlAdapter / 占位符约定;分页为单表简单过滤(filters 字段名 EQ)。
|
|
4
4
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
5
5
|
import { TsIDGenerator, rowId } from './shared.js';
|
|
6
|
+
import { surrogateIsEffective, surrogateTimeMs } from '../surrogate-rule.js';
|
|
6
7
|
const txStore = new AsyncLocalStorage();
|
|
7
8
|
export class JdbcProcessExtRepository {
|
|
8
9
|
adapter;
|
|
@@ -266,15 +267,36 @@ export class JdbcProcessExtRepository {
|
|
|
266
267
|
await this.done(conn);
|
|
267
268
|
}
|
|
268
269
|
}
|
|
270
|
+
/**
|
|
271
|
+
* 生效委托查询(issues/116 判据 a~d 基准实现 + issues/123 的取行/裁决顺序):
|
|
272
|
+
* a. 作用域:先在该流程名作用域内取记录,该作用域**一条都没有**才兜底
|
|
273
|
+
* `process_name IS NULL OR = ''`(全流程委托);精确作用域里只要有记录就由它裁决;
|
|
274
|
+
* 然后由 `surrogateIsEffective` 裁决**这一条**:
|
|
275
|
+
* d. enabled 严格 1('1'/1 同结论,NULL 不生效)、c. 自委托过滤、
|
|
276
|
+
* b. 时间窗 start<=at<=end(任一侧 NULL = 该侧不限;`at` 传 null 则整段跳过窗比较)。
|
|
277
|
+
*
|
|
278
|
+
* ⚠️ 旧形状是 `WHERE operator=? AND enabled=1 AND surrogate<>? AND 窗口… ORDER BY id DESC LIMIT 1`
|
|
279
|
+
* ——先滤生效再取最新,等于"历史上留过一条窗内且 enabled=1 的记录就永久生效",用户随后
|
|
280
|
+
* 新建的窗外 / enabled=0 / 脏值 / 自委托记录全都判不动它(issues/123,13 栈 L2-17/L2-18 全红)。
|
|
281
|
+
* 现在 WHERE 里**不带**任何生效判据,只 `ORDER BY id DESC LIMIT 1` 取最新一条;
|
|
282
|
+
* 最新一条不生效 ⇒ 同层内不回落更旧那条,转看全流程作用域的最新一条;两层都判否才返回 null。
|
|
283
|
+
* 内存仓须给出同结论(MemoryExtRepository.getSurrogate,共用 src/surrogate-rule.ts)。
|
|
284
|
+
*/
|
|
269
285
|
async getSurrogate(operator, processName, at = new Date()) {
|
|
270
|
-
const
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
286
|
+
const name = processName ?? '';
|
|
287
|
+
const ms = surrogateTimeMs(at);
|
|
288
|
+
let newest = await this.queryNewestSurrogate(operator, name);
|
|
289
|
+
if (!surrogateIsEffective(newest, operator, ms) && name) {
|
|
290
|
+
// 精确作用域判否(含池空)⇒ 仍要看全流程作用域的最新一条(条款 1.4 后半句)
|
|
291
|
+
newest = await this.queryNewestSurrogate(operator, '');
|
|
292
|
+
}
|
|
293
|
+
return surrogateIsEffective(newest, operator, ms) ? newest : null;
|
|
274
294
|
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
295
|
+
/** 该授权人在指定流程作用域内**最新的一条**委托:只排序取首行,不滤任何生效判据。
|
|
296
|
+
* processName 为 '' = 全流程委托作用域(process_name IS NULL OR = '')。 */
|
|
297
|
+
async queryNewestSurrogate(operator, processName) {
|
|
298
|
+
let sql = `SELECT ${JdbcProcessExtRepository.SURROGATE_COLS} FROM wf_process_surrogate WHERE operator = ?`;
|
|
299
|
+
const args = [operator];
|
|
278
300
|
if (!processName) {
|
|
279
301
|
sql += " AND (process_name IS NULL OR process_name = '')";
|
|
280
302
|
}
|
|
@@ -282,10 +304,6 @@ export class JdbcProcessExtRepository {
|
|
|
282
304
|
sql += ' AND process_name = ?';
|
|
283
305
|
args.push(processName);
|
|
284
306
|
}
|
|
285
|
-
if (at) {
|
|
286
|
-
sql += ' AND (start_time IS NULL OR start_time <= ?) AND (end_time IS NULL OR end_time >= ?)';
|
|
287
|
-
args.push(at, at);
|
|
288
|
-
}
|
|
289
307
|
sql += ' ORDER BY id DESC LIMIT 1';
|
|
290
308
|
const conn = await this.c();
|
|
291
309
|
try {
|
package/dist/memory-ext.d.ts
CHANGED
|
@@ -17,5 +17,22 @@ 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 + issues/123 的取行/裁决顺序,
|
|
22
|
+
* 与 JdbcProcessExtRepository.getSurrogate 同口径,同一份数据两仓必须给出同一结论):
|
|
23
|
+
* a. 作用域:先在该流程名作用域内取记录,该作用域**一条都没有**才兜底 process_name 空(全流程委托);
|
|
24
|
+
* 精确作用域里只要有记录就由它裁决,**不跨作用域回落**;
|
|
25
|
+
* b. 时间窗 start_time <= at <= end_time,任一侧为空 = 该侧不限;`at` 解析不出时刻则整段跳过窗比较
|
|
26
|
+
* (保留 `at: Date = new Date()` 显式传 null 的老语义);
|
|
27
|
+
* c. 自委托过滤 surrogate <> operator;d. enabled 只认整数 1。
|
|
28
|
+
*
|
|
29
|
+
* ⚠️ 顺序是「**先**按主键 id 取最新一条 → **再**由四判据裁决这一条」(条款 1.4 + issues/123):
|
|
30
|
+
* 反过来(先滤生效、剩下的才取最新)等于"历史上留过一条窗内委托就永久生效",
|
|
31
|
+
* 用户随后新建的窗外/停用/脏值/自委托记录全都判不动它。最新一条不生效 ⇒ 返回 null,
|
|
32
|
+
* **不回落**到更旧那条。id 显式按数值比(surrogateIdLess),不依赖 Map 插入序。
|
|
33
|
+
*/
|
|
20
34
|
getSurrogate(operator: string, processName: string, at?: Date): Promise<ProcessSurrogate | null>;
|
|
35
|
+
/** 该授权人在指定流程作用域内 id 最大(最新)的一条委托;processName 为 '' = 全流程委托作用域。
|
|
36
|
+
* **不带**任何生效判据过滤(裁决在 getSurrogate 里对这一条单独做)。 */
|
|
37
|
+
private newestSurrogateInScope;
|
|
21
38
|
}
|
package/dist/memory-ext.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// 扩展仓储内存实现(v1.1.0,测试/演示用)
|
|
2
2
|
import { matchConditions } from './memory.js';
|
|
3
|
+
import { surrogateIsEffective, surrogateTimeMs, newestOf } from './surrogate-rule.js';
|
|
3
4
|
// ═══ 条件匹配基建(issues/05-5) ═══
|
|
4
5
|
const DESIGN_FIELDS = {
|
|
5
6
|
't.id': 'id', 't.name': 'name', 't.display_name': 'displayName', 't.type': 'type',
|
|
@@ -19,6 +20,7 @@ function pickFields(row, map) {
|
|
|
19
20
|
}
|
|
20
21
|
return fields;
|
|
21
22
|
}
|
|
23
|
+
// ── 委托查询判据基建:单一事实源在 ./surrogate-rule.ts(与 SQL 仓共用,issues/116/123)──
|
|
22
24
|
export class MemoryExtRepository {
|
|
23
25
|
designs = new Map();
|
|
24
26
|
designHis = new Map();
|
|
@@ -94,20 +96,35 @@ export class MemoryExtRepository {
|
|
|
94
96
|
});
|
|
95
97
|
return [rows, rows.length];
|
|
96
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* 生效委托查询(issues/116 判据 a~d + issues/123 的取行/裁决顺序,
|
|
101
|
+
* 与 JdbcProcessExtRepository.getSurrogate 同口径,同一份数据两仓必须给出同一结论):
|
|
102
|
+
* a. 作用域:先在该流程名作用域内取记录,该作用域**一条都没有**才兜底 process_name 空(全流程委托);
|
|
103
|
+
* 精确作用域里只要有记录就由它裁决,**不跨作用域回落**;
|
|
104
|
+
* b. 时间窗 start_time <= at <= end_time,任一侧为空 = 该侧不限;`at` 解析不出时刻则整段跳过窗比较
|
|
105
|
+
* (保留 `at: Date = new Date()` 显式传 null 的老语义);
|
|
106
|
+
* c. 自委托过滤 surrogate <> operator;d. enabled 只认整数 1。
|
|
107
|
+
*
|
|
108
|
+
* ⚠️ 顺序是「**先**按主键 id 取最新一条 → **再**由四判据裁决这一条」(条款 1.4 + issues/123):
|
|
109
|
+
* 反过来(先滤生效、剩下的才取最新)等于"历史上留过一条窗内委托就永久生效",
|
|
110
|
+
* 用户随后新建的窗外/停用/脏值/自委托记录全都判不动它。最新一条不生效 ⇒ 返回 null,
|
|
111
|
+
* **不回落**到更旧那条。id 显式按数值比(surrogateIdLess),不依赖 Map 插入序。
|
|
112
|
+
*/
|
|
97
113
|
async getSurrogate(operator, processName, at = new Date()) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
continue;
|
|
104
|
-
if (s.endTime && s.endTime < at)
|
|
105
|
-
continue;
|
|
106
|
-
if (s.processName === processName && processName)
|
|
107
|
-
return { ...s };
|
|
108
|
-
if ((!s.processName || s.processName === processName) && !fallback)
|
|
109
|
-
fallback = s;
|
|
114
|
+
const name = processName ?? '';
|
|
115
|
+
const ms = surrogateTimeMs(at);
|
|
116
|
+
let hit = this.newestSurrogateInScope(operator, name);
|
|
117
|
+
if (surrogateIsEffective(hit, operator, ms) || !name) {
|
|
118
|
+
return surrogateIsEffective(hit, operator, ms) && hit ? { ...hit } : null;
|
|
110
119
|
}
|
|
111
|
-
|
|
120
|
+
// 精确作用域判否(含池空)⇒ 仍要看全流程作用域的最新一条(条款 1.4 后半句)
|
|
121
|
+
hit = this.newestSurrogateInScope(operator, '');
|
|
122
|
+
return surrogateIsEffective(hit, operator, ms) && hit ? { ...hit } : null;
|
|
123
|
+
}
|
|
124
|
+
/** 该授权人在指定流程作用域内 id 最大(最新)的一条委托;processName 为 '' = 全流程委托作用域。
|
|
125
|
+
* **不带**任何生效判据过滤(裁决在 getSurrogate 里对这一条单独做)。 */
|
|
126
|
+
newestSurrogateInScope(operator, processName) {
|
|
127
|
+
const inScope = [...this.surrogates.values()].filter(s => s.operator === operator && (processName === '' ? !s.processName : s.processName === processName));
|
|
128
|
+
return newestOf(inScope);
|
|
112
129
|
}
|
|
113
130
|
}
|
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
|
/** 是否已完成 */
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ProcessSurrogate } from './model.js';
|
|
2
|
+
/** 时间归一为毫秒:Date/毫秒数/可解析字符串均可;空值或脏值 → null(该侧不限,对齐 SQL 侧 NULL) */
|
|
3
|
+
export declare function surrogateTimeMs(v: any): number | null;
|
|
4
|
+
/** enabled 只认整数 1('1' 视作 1,与 SQL 侧 INT 列同结论);脏值('abc'/true/0/2/空)一律不启用 */
|
|
5
|
+
export declare function surrogateEnabled(v: any): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* 判据 1.4:比较两条委托的主键大小(a 是否比 b 旧)。id 是雪花数字串(19 位,已超
|
|
8
|
+
* Number 安全整数),纯数字串一律按 BigInt 比**数值**(与 SQL 侧 `ORDER BY id DESC` 同序),
|
|
9
|
+
* 非数字 id 退化为字符串序。
|
|
10
|
+
*
|
|
11
|
+
* ⚠️ 不能拿 Map 的插入序当 id 序:saveSurrogate/updateSurrogate 都接受调用方显式 id,
|
|
12
|
+
* 乱序写入(补录、导入、双仓对拍)时"取遍历到的末条"就会与 SQL 仓给出不同答案。
|
|
13
|
+
* Go 内存仓原实现正是"map 随机序取到啥算啥"被抓出来重写的(issues/116 §5)。
|
|
14
|
+
*/
|
|
15
|
+
export declare function surrogateIdLess(a: any, b: any): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* 单条裁决(规范 06 §4.5 条款 5 四判据 + issues/123):这一行委托此刻对该授权人生效吗。
|
|
18
|
+
*
|
|
19
|
+
* 调用方**必须**先按 id 选出「该授权人在该流程作用域内的最新一条」再问本函数——
|
|
20
|
+
* 本函数只裁决单条,不做多条择优(择优规则见文件头的 ①②③)。
|
|
21
|
+
*
|
|
22
|
+
* @param s 待裁决的委托行(null = 该作用域内没有记录)
|
|
23
|
+
* @param operator 授权人(判自委托:被委托人等于授权人 ⇒ 不新增、不重复)
|
|
24
|
+
* @param atMs 判定时刻(毫秒);传 null 表示不做窗口比较
|
|
25
|
+
* (保留 `getSurrogate(..., at)` 显式传 null 时整段跳过窗比较的入参语义)
|
|
26
|
+
*/
|
|
27
|
+
export declare function surrogateIsEffective(s: ProcessSurrogate | null | undefined, operator: string, atMs: number | null): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* 判据 1.4 的取行:候选里主键 id 最大(最新)的那一条,**不带**任何生效判据过滤。
|
|
30
|
+
* 空池返回 null。SQL 侧对应 `ORDER BY id DESC LIMIT 1`。
|
|
31
|
+
*/
|
|
32
|
+
export declare function newestOf<T extends {
|
|
33
|
+
id: any;
|
|
34
|
+
}>(rows: Iterable<T>): T | null;
|