@mldong/jeeflow 1.8.32 → 1.8.33

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 CHANGED
@@ -125,3 +125,18 @@ export declare function mergeAgents(actors: string[], agents: Map<string, string
125
125
  * '1' / 'ALL' / 'COUNTERSIGN'(大小写不敏感)→ 会签。
126
126
  * 设计器属性面板保存 'ALL' 字符串符合 Java 契约,引擎必须兼容 */
127
127
  export declare function isCountersign(v: any): boolean;
128
+ /**
129
+ * 解析期待完成时间(逐字移植 Java `FlowUtil.processTime` / C# `FlowUtil.ProcessTime`,本栈原先没有)。
130
+ *
131
+ * 三档语义,**顺序不能变**:
132
+ * 1. `args` 里存在键名等于 expr 原串的项 ⇒ 取该项的值:Date / 毫秒时间戳 / `"yyyy-MM-dd HH:mm:ss"`
133
+ * → 该时刻;字符串解析失败 → **null**(不是 now);其它类型(布尔/数组/对象/小数)→ **落穿**到下面两档
134
+ * (Java/C# 都是落穿,不许当"解析失败"提前 return null)。
135
+ * 2. 否则 expr 以 `s`/`m`/`h`/`d` 结尾且前缀是整数 ⇒ now + N 秒/分/时/天(`d` 走**日历加天**,不乘 86400 秒)。
136
+ * 3. 否则把 expr 本身按 `"yyyy-MM-dd HH:mm:ss"` 解析 → 时刻;失败 → null。
137
+ *
138
+ * ⚠️ 任何一档都不得退回 now()——"算不出来就写当前时间"正是 issues/126 的病灶(建单即逾期,逾期统计恒失真)。
139
+ *
140
+ * @param now 取时基准=**本栈写 createTime 用的同一个 Date**(本栈无时钟槽,与 Java 直接用系统钟同档)
141
+ */
142
+ export declare function processTime(expr: string, args: Record<string, any> | undefined, now: Date): Date | null;
package/dist/engine.js CHANGED
@@ -272,6 +272,12 @@ export class EngineImpl {
272
272
  const eff = mergeAgents([actors[lc + 1]], await this.surrogateAgents([actors[lc + 1]], pn));
273
273
  if (eff.length > 1)
274
274
  nt.actorIds = eff;
275
+ // issues/126 案 A · **第五处写点**:这一支绕过 createTask helper 直建任务行,所以必须显式补一次
276
+ // ——基准侧 boot2 的串行推进是回调 createCountersignTask(ProcessTaskServiceImpl:485,
277
+ // 内含 :524 那处到期写)⇒ 基准形状里"推进出的第二/第三位成员"同样带到期时间;
278
+ // 不补就是"首成员有到期、后续没有"(对齐 Java CountersignHandler.applyNodeExpireTime @ cb541d4)。
279
+ // 变量源=实例变量(与建单同档),取时基准=本行 createTime 用的同一个 now。
280
+ applyNodeExpireTime(nt, curNode.properties?.expireTime, inst.variables, now);
275
281
  await this.repo.saveTask(nt);
276
282
  // TASK_CREATE:顺序会签推进新任务落库后 fire(对齐 Java CreateTaskHandler / Rust)
277
283
  await this.fireEvent({ type: EventType.TaskCreate, instanceId: inst.id, taskId: nt.id, nodeId: curNode.id, operator });
@@ -415,9 +421,15 @@ export class EngineImpl {
415
421
  let actor = isFirst ? String(his.variables?.u_userId ?? '') || inst.operator : his.actorId;
416
422
  if (!actor)
417
423
  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);
424
+ // 取时基准只取一次:本行 createTime 与 expire_time 共用同一个 Date(写点内不另起时钟)
425
+ const now = new Date();
426
+ const nt = inst.createTask(this.nextId(), prev.id, prev.text.value, actor, his.createUser ?? '', prev.properties?.form ?? '', now, his.parentTaskId ?? '0', isFirst, his.performType);
419
427
  // 复活行只带数据类键:tf_*(上次表单提交)与 csv_*/会签簿记都是"上次提交"的残留
420
428
  nt.variables = { ...lineageVars(his.variables), isFirstTaskNode: isFirst };
429
+ // issues/126 案 A · 回退新建写点:表达式取**被回退掉的那个节点**(=当前节点)的 expireTime,
430
+ // 变量源用随行拷贝那份(boot2 的 hisVariable)——两点都与 Java rejectTask 逐字一致。
431
+ // 取时基准 now 同时是本行 createTime 的值,勿另起时钟(否则同行 create→expire 差值带偏差)。
432
+ applyNodeExpireTime(nt, findNode(flow, task.taskName)?.properties?.expireTime, nt.variables, now);
421
433
  const agents = await this.surrogateAgents([actor], await this.surrogateProcessName(flow, inst));
422
434
  const eff = mergeAgents([actor], agents);
423
435
  if (eff.length > 1)
@@ -460,6 +472,10 @@ export class EngineImpl {
460
472
  const ct = node.properties?.countersignType;
461
473
  const now = new Date();
462
474
  const form = node.properties?.form ?? '';
475
+ // issues/126 案 A:与 createTask 同一把尺子。本函数当前**零调用者**(issues/121 P2 把回退改成血缘版后
476
+ // 就没人调它了),按 §1.9 第 1 条口径"接线但不为它造测试"——接线是为了将来复活时不再漏。
477
+ const expireExpr = node.properties?.expireTime;
478
+ const expireArgs = inst.variables;
463
479
  if (isCountersign(node.properties?.performType) && ct) {
464
480
  switch (ct) {
465
481
  case 'PARALLEL':
@@ -469,6 +485,7 @@ export class EngineImpl {
469
485
  const eff = mergeAgents([actor], agents);
470
486
  if (eff.length > 1)
471
487
  nt.actorIds = eff;
488
+ applyNodeExpireTime(nt, expireExpr, expireArgs, now);
472
489
  await this.repo.saveTask(nt);
473
490
  await this.fireEvent({ type: EventType.TaskCreate, instanceId: inst.id, taskId: nt.id, nodeId: node.id, operator });
474
491
  }
@@ -483,6 +500,7 @@ export class EngineImpl {
483
500
  const eff = mergeAgents([actors[0]], agents);
484
501
  if (eff.length > 1)
485
502
  nt.actorIds = eff;
503
+ applyNodeExpireTime(nt, expireExpr, expireArgs, now);
486
504
  await this.repo.saveTask(nt);
487
505
  await this.fireEvent({ type: EventType.TaskCreate, instanceId: inst.id, taskId: nt.id, nodeId: node.id, operator });
488
506
  return;
@@ -493,6 +511,7 @@ export class EngineImpl {
493
511
  const eff = mergeAgents([actor], agents);
494
512
  if (eff.length > 1)
495
513
  nt.actorIds = eff;
514
+ applyNodeExpireTime(nt, expireExpr, expireArgs, now);
496
515
  await this.repo.saveTask(nt);
497
516
  await this.fireEvent({ type: EventType.TaskCreate, instanceId: inst.id, taskId: nt.id, nodeId: node.id, operator });
498
517
  }
@@ -503,6 +522,7 @@ export class EngineImpl {
503
522
  const nt = inst.createTask(this.nextId(), node.id, node.text.value, effActors[0], operator, form, now, parentId, isFirst);
504
523
  if (effActors.length > 1)
505
524
  nt.actorIds = effActors;
525
+ applyNodeExpireTime(nt, expireExpr, expireArgs, now);
506
526
  await this.repo.saveTask(nt);
507
527
  await this.fireEvent({ type: EventType.TaskCreate, instanceId: inst.id, taskId: nt.id, nodeId: node.id, operator });
508
528
  }
@@ -631,6 +651,10 @@ export class EngineImpl {
631
651
  const ct = node.properties?.countersignType;
632
652
  const now = new Date();
633
653
  const form = node.properties?.form ?? '';
654
+ // issues/126 案 A:节点到期表达式(properties.expireTime)+ 实例变量 + 本函数取时基准 now
655
+ // —— 三处写点(串行首位 / 并行全员 / 普通建单)共用 applyNodeExpireTime 这一把尺子
656
+ const expireExpr = node.properties?.expireTime;
657
+ const expireArgs = inst.variables;
634
658
  if (isCountersign(node.properties?.performType) && ct) {
635
659
  switch (ct) {
636
660
  case 'PARALLEL':
@@ -639,6 +663,7 @@ export class EngineImpl {
639
663
  const eff = mergeAgents([actor], agents);
640
664
  if (eff.length > 1)
641
665
  nt.actorIds = eff;
666
+ applyNodeExpireTime(nt, expireExpr, expireArgs, now); // 并行会签全员
642
667
  await this.repo.saveTask(nt);
643
668
  // TASK_CREATE:任务落库后逐个 fire(会签多任务逐个,对齐 Java CreateTaskHandler)
644
669
  await this.fireEvent({ type: EventType.TaskCreate, instanceId: inst.id, taskId: nt.id, nodeId: node.id, operator });
@@ -656,6 +681,7 @@ export class EngineImpl {
656
681
  const eff = mergeAgents([actors[0]], agents);
657
682
  if (eff.length > 1)
658
683
  nt.actorIds = eff;
684
+ applyNodeExpireTime(nt, expireExpr, expireArgs, now); // 串行会签首位成员
659
685
  await this.repo.saveTask(nt);
660
686
  await this.fireEvent({ type: EventType.TaskCreate, instanceId: inst.id, taskId: nt.id, nodeId: node.id, operator });
661
687
  return;
@@ -666,6 +692,7 @@ export class EngineImpl {
666
692
  const eff = mergeAgents([actor], agents);
667
693
  if (eff.length > 1)
668
694
  nt.actorIds = eff;
695
+ applyNodeExpireTime(nt, expireExpr, expireArgs, now); // 未配会签类型=全员预创建,与并行同档
669
696
  await this.repo.saveTask(nt);
670
697
  await this.fireEvent({ type: EventType.TaskCreate, instanceId: inst.id, taskId: nt.id, nodeId: node.id, operator });
671
698
  }
@@ -677,6 +704,7 @@ export class EngineImpl {
677
704
  const nt = inst.createTask(this.nextId(), node.id, node.text.value, effActors[0], operator, form, now, parentId, isFirst);
678
705
  if (effActors.length > 1)
679
706
  nt.actorIds = effActors;
707
+ applyNodeExpireTime(nt, expireExpr, expireArgs, now); // 普通建单
680
708
  await this.repo.saveTask(nt);
681
709
  await this.fireEvent({ type: EventType.TaskCreate, instanceId: inst.id, taskId: nt.id, nodeId: node.id, operator });
682
710
  }
@@ -875,3 +903,99 @@ function filterFieldByPerm(args, node) {
875
903
  }
876
904
  return out;
877
905
  }
906
+ // ─── issues/126 案 A · 任务行到期时间(expire_time)求值与写入 ────────────────────
907
+ /** 绝对时刻格式 "yyyy-MM-dd HH:mm:ss"(Java SimpleDateFormat / C# TimeFormat 同串) */
908
+ const ABS_TIME_RE = /^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/;
909
+ /** 按 "yyyy-MM-dd HH:mm:ss" 严格解析(本地时区);不合规/越界一律 null。
910
+ * 越界判据取 C# 的 TryParseExact(拒 13 月 / 25 时),不取 Java 的 SimpleDateFormat 宽松进位——
911
+ * 本案的硬要求是"解析不出 ⇒ 这一列留空",宽松进位会把误配的值算成一个真时刻。 */
912
+ function parseAbsTime(s) {
913
+ const m = ABS_TIME_RE.exec(s);
914
+ if (!m)
915
+ return null;
916
+ const [, ys, mos, ds, hs, mis, ss] = m;
917
+ const mo = Number(mos), d = Number(ds), h = Number(hs), mi = Number(mis), sec = Number(ss);
918
+ if (mo < 1 || mo > 12 || d < 1 || d > 31 || h > 23 || mi > 59 || sec > 59)
919
+ return null;
920
+ const dt = new Date(Number(ys), mo - 1, d, h, mi, sec, 0);
921
+ // 2 月 30 日这类"字段合法但日历上不存在"的值会被 JS 进位,回读校验挡掉
922
+ if (dt.getMonth() !== mo - 1 || dt.getDate() !== d)
923
+ return null;
924
+ return dt;
925
+ }
926
+ /** 相对档前缀取整:必须是**纯整数**且落在 int32 内(C# int.TryParse 同判据),否则返回 null ⇒ 落穿。
927
+ * 与 Java 的差异是故意的:Java 的 Integer.parseInt 遇 "xh" 会抛异常**打断建单**,
928
+ * owner 2026-09-28 定的口径是按 C# 落穿→NULL(配置写错不该让流程卡死);要改回"跟 Java 一样抛"必须八栈同批改。 */
929
+ function intPrefix(s) {
930
+ if (!/^[-+]?\d+$/.test(s))
931
+ return null;
932
+ const n = Number(s);
933
+ return Number.isSafeInteger(n) && Math.abs(n) <= 2147483647 ? n : null;
934
+ }
935
+ /**
936
+ * 解析期待完成时间(逐字移植 Java `FlowUtil.processTime` / C# `FlowUtil.ProcessTime`,本栈原先没有)。
937
+ *
938
+ * 三档语义,**顺序不能变**:
939
+ * 1. `args` 里存在键名等于 expr 原串的项 ⇒ 取该项的值:Date / 毫秒时间戳 / `"yyyy-MM-dd HH:mm:ss"`
940
+ * → 该时刻;字符串解析失败 → **null**(不是 now);其它类型(布尔/数组/对象/小数)→ **落穿**到下面两档
941
+ * (Java/C# 都是落穿,不许当"解析失败"提前 return null)。
942
+ * 2. 否则 expr 以 `s`/`m`/`h`/`d` 结尾且前缀是整数 ⇒ now + N 秒/分/时/天(`d` 走**日历加天**,不乘 86400 秒)。
943
+ * 3. 否则把 expr 本身按 `"yyyy-MM-dd HH:mm:ss"` 解析 → 时刻;失败 → null。
944
+ *
945
+ * ⚠️ 任何一档都不得退回 now()——"算不出来就写当前时间"正是 issues/126 的病灶(建单即逾期,逾期统计恒失真)。
946
+ *
947
+ * @param now 取时基准=**本栈写 createTime 用的同一个 Date**(本栈无时钟槽,与 Java 直接用系统钟同档)
948
+ */
949
+ export function processTime(expr, args, now) {
950
+ const a = args ?? {};
951
+ // ① 变量档:优先于相对档(args 里真有个键叫 "2h" 时取变量值)
952
+ if (Object.prototype.hasOwnProperty.call(a, expr)) {
953
+ const v = a[expr];
954
+ if (v instanceof Date)
955
+ return new Date(v.getTime());
956
+ if (typeof v === 'number' && Number.isSafeInteger(v))
957
+ return new Date(v);
958
+ if (typeof v === 'string')
959
+ return parseAbsTime(v);
960
+ // 其它类型 ⇒ 落穿
961
+ }
962
+ if (expr.trim() === '')
963
+ return null;
964
+ // ② 相对档
965
+ const n = intPrefix(expr.slice(0, -1));
966
+ if (n !== null) {
967
+ switch (expr.charAt(expr.length - 1)) {
968
+ case 's': return new Date(now.getTime() + n * 1000);
969
+ case 'm': return new Date(now.getTime() + n * 60000);
970
+ case 'h': return new Date(now.getTime() + n * 3600000);
971
+ case 'd': {
972
+ const d = new Date(now.getTime());
973
+ d.setDate(d.getDate() + n); // 日历加天(跨夏令时/月末按天进位,对齐 Java Calendar.add)
974
+ return d;
975
+ }
976
+ default: break;
977
+ }
978
+ }
979
+ // ③ 绝对档
980
+ return parseAbsTime(expr);
981
+ }
982
+ /**
983
+ * issues/126 案 A · 任务行 expire_time 的**唯一**写入口(五处写点共用同一把尺子):
984
+ * 普通建单 / 串行会签首位成员 / 并行会签全员 / 回退新建 / 串行会签推进出的下一位成员。
985
+ *
986
+ * 节点没配(undefined / null / 空串 / 纯空白)⇒ **该列保持空**:不写 now()、不写 ''、不写 0
987
+ * (owner 2026-09-28 口径,对齐 boot2 `if(StrUtil.isNotEmpty(expireTime))` 的先判再写)。
988
+ *
989
+ * 变量源两档:建单路径=**实例变量**(boot2 的 `execution.getArgs()`),
990
+ * 回退新建=**随行拷贝那份变量**(boot2 的 `hisVariable`)。搞混会让"表达式是个变量名"这一档跨栈得到不同答案。
991
+ */
992
+ function applyNodeExpireTime(task, expr, args, now) {
993
+ if (!task)
994
+ return;
995
+ const s = expr == null ? '' : String(expr);
996
+ if (s.trim() === '')
997
+ return;
998
+ const at = processTime(s, args, now);
999
+ if (at)
1000
+ task.expireTime = at;
1001
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mldong/jeeflow",
3
- "version": "1.8.32",
3
+ "version": "1.8.33",
4
4
  "description": "jeeflow workflow engine — Node.js / TypeScript implementation",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",