diff --git a/docs/plans/2026-06-25-审批闭环-实施计划.md b/docs/plans/2026-06-25-审批闭环-实施计划.md new file mode 100644 index 0000000..0f079e1 --- /dev/null +++ b/docs/plans/2026-06-25-审批闭环-实施计划.md @@ -0,0 +1,209 @@ +# 审批闭环 — 完整实施计划(2026-06-25) + +> 目标:把 EIP4 审批从「单人串行主链路已 live」推进到「动作类型齐全 + 流程可视化 + 流程监控 + 端到端真实流转」的生产可用闭环。 +> +> 现状权威依据:`ApprovalController.java`(gateway)/ `FlowController.java`、`CandidateController.java`(flowable-service)/ `FlowableClient.java`(gateway client)/ `ApprovalDrawer.tsx`、`TodoPage.tsx`(web)实读核实;进度矩阵见 `docs/项目进度与路线-总览-2026-06-21.md` §A2/B3/B4。 + +--- + +## 0. 现状基线(核实于 2026-06-25) + +### ✅ 已实现并 live(WfTemplate 数据驱动审批主链路) +- 动作:`approve`(complete + 回写 SYS_DATASTATUS 3/2)、`reject`(终止 + 回写 4)、`reback`(退回发起 + 回写 5)、`agent`(委托)。 +- 界面:`ApprovalDrawer`(只读业务表单 + 流程轨迹时间线 + 动态按钮 + 审批意见);业务表单走统一 sys_page_schema editform 解析;load 脚本保真层执行(4s 超时守护);action servicename 服务器侧按 buttonId 重解析后执行。 +- 入口:228 个 sys_page_schema 含 `openApprovalDrawer` 按钮接线(mock e2e 1/1)。 +- 提交审批桥:`ProcessCoreServiceBridge`(startWorkflow)已实证起真实 flowable 实例。 + +### 🟡 引擎/Client 层已具备、仅缺 gateway 动作接线 + UI 按钮(关键发现:比想象中近) +> 这些**不需要动引擎**,引擎与 `FlowableClient` 方法都已存在并测过: +- `FlowableClient.withdraw(pi, comment)` ← flowable-service `POST /api/flow/process/{pi}/withdraw`(发起人撤回) +- `FlowableClient.terminateProcessInstance(pi, comment)` ← `POST /process/{pi}/terminate`(强制结束) +- flowable-service `POST /process/{pi}/suspend` / `/activate`(挂起/激活,client 侧尚无封装方法) +- `FlowableClient.started(...)` ← `GET /process/started`(我发起的流程列表) +- `FlowableClient.deleteHistoricProcessInstance(pi)` ← `POST /process/{pi}/delete-history` +- `trace` / `traceByBusiness`(轨迹)已用于 ApprovalDrawer。 + +### ❌ 完全缺失 +1. 动作类型:**协办/加签 `assist`**、**转阅/抄送 `circulated`** —— `ApprovalController.java:227` 直接 `badRequest`。**会签**(多实例并行 + 结果聚合)无任何处理。 +2. **BPMN 流程图查看** —— 现仅文本轨迹,无图形化高亮当前节点。 +3. **流程定义 Modeler(B3)** —— 完全未起步。 +4. **「我发起的流程」页 / 流程监控页** —— web 无对应 page(仅 `TodoPage`);撤回/结束按钮无 UI。 +5. **审批待办组件 B4** —— UI/UE 组件骨架未补完。 + +### 🔒 外部阻塞(非代码能力问题) +- 客户真实 BPMN 部署:新提交走通用流 `EIP4_DEFAULT_APPROVAL`,无 `form_key` → 降级默认按钮。全数据驱动 + 候选人计算需客户部署真实 BPMN(`form_key` 指 WfTemplate)。dev act 流程库不可达。 +- `reject`/`reback`/action-servicename 写流:仅 wired + 单测,未对真实迁移数据跑 mutation(数据安全自限)。 + +--- + +## 1. 范围分层与优先级 + +| 层 | 内容 | 外部依赖 | 工作量 | 价值 | +|----|------|---------|--------|------| +| **P0**(立即可做) | 协办/加签 `assist`、转阅/抄送 `circulated` 动作落地 | 无 | 中 | 高(补齐审批语义完整性) | +| **P1**(接线打磨) | 流程监控按钮(撤回/结束/挂起)接线 + 「我发起的流程」页 | 无 | 小-中 | 高(引擎已就绪,最后一公里) | +| **P1**(可视化) | BPMN 流程图查看(bpmn-js 高亮当前节点) | 无(用已部署 bpmn) | 中 | 高(审批可视化刚需) | +| **P2**(验证闭环) | 真实流转 / 候选人计算 / 写流对真实记录的端到端验收 | **客户 BPMN** | 中 | 高(但卡外部) | +| **P3**(大工程) | 会签(多实例聚合)+ 流程定义 Modeler(B3) | 部分卡 S1 | 大 | 中(按客户诉求排期) | + +> 建议交付顺序:**P0 → P1 监控接线 → P1 BPMN 图 → P2(客户 BPMN 到位后)→ P3**。P0/P1 共约 4 个可独立交付的增量,互不阻塞,均不依赖外部。 + +--- + +## 2. 分阶段任务 + +### 阶段 A — 协办/加签 `assist`(P0) + +**语义对账(先做,不可跳过)**:核对老系统 `TaskProcessServiceImpl` 中 assist 的真实行为。预期两种之一: +- (a) **加签**:当前任务保留,给目标人新增一个并行/串行待办(`addCandidateUser` 或动态加 task),目标人办完回到原审批人; +- (b) **协办**:把当前任务的 candidate 增加目标人,任一人可办。 +> WfTemplate 数据里 assist 仅 2 例 —— **务必先 SQL 取这 2 例的 xml + servicename,确认是 (a) 还是 (b)**,不要凭猜实现。 + +**改动**: +- flowable-service `FlowController`:新增 `POST /api/flow/tasks/{taskId}/assist`(入参 targetUserId、comment)。用 `TaskService.addCandidateUser` 或 `runtimeService` 动态加签,按语义对账结果实现。CHAR(36) 补白对齐既有 `TrimmingCandidateUsersHandler` 口径。 +- `FlowableClient`:加 `assist(taskId, targetUserId, comment)`。 +- `ApprovalController.action`:`case "assist"` → 新 `assist(taskId, req)` 方法(替换当前 400)。 +- 单测:FlowController assist 1 + ApprovalController dispatch 1。 + +**验收**:真实/构造任务加签后,目标人 todo 出现该任务;办理后流程状态正确。 +**风险**:加签的「办完回到谁」依赖 BPMN 结构;若客户 BPMN 不可达,先用 dev 构造流程验证机制,标注真实流待客户库。 + +--- + +### 阶段 B — 转阅/抄送 `circulated`(P0) + +**语义对账**:circulated 仅 2 例。老系统转阅通常是**只读知会**(不阻塞流程):给目标人发一条「抄送待阅」记录,目标人可见单据但无审批动作。核实是否落 `act_ru_identitylink`(type=participant)或独立抄送表。 + +**改动**: +- flowable-service `FlowController`:`POST /api/flow/tasks/{taskId}/circulate`(targetUserIds[]、comment)。实现 = 加 participant identityLink + 写抄送记录(若老系统有抄送表,迁移对齐;否则用 identityLink + 历史评论)。 +- `FlowableClient`:`circulate(taskId, targetUserIds, comment)`。 +- `ApprovalController.action`:`case "circulated"` → `circulate(...)`。 +- 「抄送给我的」列表:复用 `TodoController` 加 `GET /api/tasks/circulated?user=`(查 participant identityLink)。**前端可暂缓**,先保证动作不报 400。 +- 单测:circulate 1 + dispatch 1。 + +**验收**:转阅后目标人能在「抄送给我」看到只读单据;原审批流不受影响继续。 +**风险**:抄送列表入口是新页面,P0 只交付动作 + 后端列表端点,前端页面归 B4。 + +--- + +### 阶段 C — 流程监控按钮接线(P1)✅ 实施时核实:已完成(无需重做) + +> **2026-06-25 实施勘探更正**:本阶段在 06-21 矩阵里被标为「缺监控按钮」,实测**后端 + amis 页全部已存在**(进度文档 framework P2 那批 `57c3412…d218c2b` 已交付,当时计划按旧矩阵误判): +> - `GET /api/workflow/process/started-amis`(我的发起)+ `monitor-amis`(流程监控)列表端点 —— 各被 1 个 `sys_page_schema` 页引用。 +> - 我的发起页(`0db4af06…`)含**撤回**按钮 → `POST /api/workflow/process/{pi}/withdraw`(回写 SYS_DATASTATUS=5)。 +> - 流程监控页(`9f3b5a8b…`)含**强制结束**按钮 → `/terminate`(回写=6 作废)+ **高级处理脚本** `/advanced-script`(带 RCE 守卫,仅非生产 profile)+ `/delete-history`。 +> - 语义正确:发起人撤回自己的、管理员监控结束别人的。 +> +> **结论**:阶段 C 无需实现。残留仅 suspend/activate(挂起/激活)未在 gateway 暴露——价值低,暂不做;监控页缺「流程图/轨迹」按钮归入阶段 D。 +> +> ~~原计划(引擎 + client 已全有,只缺 gateway 动作端点 + UI)~~ —— 实际 gateway 端点也已就绪。 + +**改动**: +- `FlowableClient`:补 `suspend(pi)` / `activate(pi)`(其余 withdraw/terminate/started 已有)。 +- gateway 新 `ProcessMonitorController`(或并入 ApprovalController): + - `POST /api/process/{pi}/withdraw`(发起人撤回,回写 SYS_DATASTATUS) + - `POST /api/process/{pi}/terminate`(强制结束,超管/管理员权限校验,回写状态) + - `POST /api/process/{pi}/suspend` / `/activate` + - 权限:撤回限发起人本人;结束/挂起限管理员角色(复用 JWT 角色)。 +- web 新 `StartedProcessPage.tsx`(「我发起的流程」):列表走 `started`,行内「撤回」按钮 + 流程轨迹抽屉(复用 ApprovalDrawer 只读模式 + historyMeta 端点,已存在)。 +- 单测:ProcessMonitorController 4(每动作 1)+ 权限拒绝 1;前端 vitest 列表渲染 1。 + +**验收**:发起人撤回未审任务 → 状态回写 + todo 消失;管理员强制结束运行流程 → 实例 ended。 +**风险**:撤回/结束对真实客户数据是破坏性操作,**只对 dev 构造流程跑实际 mutation**,真实库标注待客户授权。 + +--- + +### 阶段 D — BPMN 流程图查看(P1) + +**方案**:bpmn-js 前端渲染 + 后端给 XML & 当前活动节点(业界标准,比服务端出图灵活,可高亮 + 缩放)。 + +**改动**: +- flowable-service:`GET /api/flow/process/{pi}/bpmn-xml` → 用 `RepositoryService.getProcessModel(procDefId)` 返 BPMN XML 字符串;`GET /api/flow/process/{pi}/active-activities` → `runtimeService.getActiveActivityIds(pi)`(高亮用,已有 RuntimeService)。历史流程取 `HistoricActivityInstance` 标记走过的节点。 +- `FlowableClient`:`bpmnXml(pi)` / `activeActivities(pi)`。 +- gateway:`GET /api/process/{pi}/diagram`(聚合 xml + active + history 节点)。 +- web:引入 `bpmn-js`(NavigatedViewer),新 `ProcessDiagram.tsx`,在 ApprovalDrawer 加「流程图」Tab;高亮当前节点(绿)、走过节点(灰)。 +- 单测:diagram 端点 2;前端组件渲染 smoke 1。 + +**验收**:打开任一运行中流程,流程图正确渲染并高亮当前停留节点。 +**风险**:迁移的是 activiti5 流程定义,bpmn-js 需 BPMN 2.0 XML;若部分老流程是 activiti5 私有格式,需确认 `getProcessModel` 返的是标准 BPMN 2.0(flowable 部署后通常是)。先用一条已部署流程验证格式兼容性。 + +--- + +### 阶段 E — 端到端真实流转验收(P2,卡客户 BPMN) + +**前置①(外部)**:客户提供并部署真实 BPMN(form_key 指 WfTemplate)。到位后: +- 真实流转:提交 → 候选人计算(`CandidateController` + `OrgDirectory` 已就绪)→ 多级审批 → approve/reject/reback 实际推进。 +- 写流:对**测试租户/沙箱记录**(非生产迁移数据)跑 reject/reback/action-servicename 实际 mutation,验证回写与服务流副作用。 +- 候选人对账:用 `CandidateController` 对真实组织库批量核对解析结果(P3 报告口径)。 + +**验收**:一条客户真实审批流从提交到归档全程在 EIP4 走通,状态/候选人/表单全部正确。 +**阻塞**:无客户 BPMN 则只能 dev 构造流程验机制,标注「机制已验,真实流待客户库」。 + +--- + +### 阶段 F — 会签 + 流程定义 Modeler(P3,大工程,按客户诉求排期) + +- **会签**:BPMN 多实例(multi-instance)任务,多人并行/串行审批,按比例/全票聚合结果。需引擎多实例支持 + 聚合变量 + UI 显示「3/5 已审批」。**先确认客户是否真有会签节点**(WfTemplate action type 分布里无独立会签 type,可能藏在 BPMN 结构,需核实)。 +- **流程定义 Modeler(B3)**:bpmn-js + bpmn-js-properties-panel 在线编辑 BPMN,存 flowable 部署。**卡 S1 拍板**(是否自研 vs 用 flowable-modeler 嵌入)。工作量最大,建议独立 design。 + +--- + +## 3. 红线与约束(贯穿全程) +1. **不碰 view_template.xml / 153 bespoke**;审批是框架级通用能力。 +2. **破坏性引擎动作(撤回/结束/加签/写流)只对 dev 构造数据跑实际 mutation**,真实迁移数据需用户显式授权。 +3. **servicename 服务器侧按 buttonId 重解析,不信前端直传**(沿用 `ApprovalController.runActionServiceIfAny` 既有口径,防注入)。 +4. **CHAR(36) 补白 / 候选人补白对齐既有 handler**(`TrimmingCandidateUsersHandler`、`EngineContextBinder` 归一化),避免身份不匹配。 +5. **不自我批准**:实现后走 `code-reviewer` + 真库/dev e2e 验证,作者与评审分离。 +6. e2e 端口坑:五环 jar = 8094(`playwright.fivering.config.ts`),标准 dev = 8093;psql 查业务表设 `PGOPTIONS='-c search_path=eip3'`。 + +--- + +## 4. 外部依赖与待拍板 +- **【外部】客户真实 BPMN 部署** → 阻塞阶段 E 全部、阶段 A/B 的真实流验证。 +- **【S1 拍板】流程定义 Modeler 自研 vs 嵌入 flowable-modeler**(阶段 F)。 +- **【待核实】会签是否为客户真实诉求**(数据里无独立 type,先核实再排期)。 + +--- + +## 5. 执行进度(2026-06-25/26 本会话,按 P0→P3 顺序) + +### 波1 ✅ 已实现 + 对抗审查收口 + 单测绿 + **live 验证通过**:阶段 A(assist 协办)+ 阶段 B(circulated 转阅) +- 语义对账(红线)已做:SQL 取 view_wftemplate 那 2+2 例(全空 servicename)+ 读老 `ProcessCoreServiceImpl.createSubTask/createNewTask` 坐实语义(协办=建独立子任务、转阅=建只读知会任务)。 +- 后端 flowable-service `POST /tasks/{id}/assist`+`/circulate`;gateway `FlowableClient.assist/circulate` + `ApprovalController` 分派把 400 改真实;前端 `ApprovalDrawer` 多选人弹窗 `MultiUserForm`。 +- **对抗代码审查(code-reviewer)揪出 1 HIGH + 3 MEDIUM,已修**: + - 【HIGH 已修+live证】协办/转阅是独立任务(无 processInstanceId/formKey),审批渲染原取不到 businessKey/formKey → 协办人/转阅人看不到业务单据。修法=`approvalContext` 对独立任务**沿 parentTaskId 回溯父任务**取 businessKey+formKey(兼防 `processInstanceId(null)` 崩 500);circulate/assist 子任务 `setFormKey(父formKey)`。 + - 【MEDIUM 已修】assist 补父任务 404 守卫(与 circulate 对称);派发 `MAX_FANOUT=50` 上限;assist/circulate 加 `@Transactional` 整批原子。 + - 【LOW】转阅改 `setFormKey` 而非 description(FormKeyResolver 直接命中);javadoc 与实现对齐。 +- 单测:flowable-service FlowControllerTest 21 + ProcessDiagramControllerTest 3 全绿;gateway ApprovalControllerActionTest 5 全绿;前端 tsc 干净 + vitest 83/83。 +- **live e2e(8089+8093 新 jar,真引擎)**:① POST assist/circulated 各返 `count:1`(不再 400);② 子任务 approval-context **回溯出父流程 businessKey=probe-bk-1 + processInstanceId**(HIGH 修复实证);③ 子任务**进目标用户待办**(assignee 匹配无补白问题,reviewer Open Question 实证排除);④ 测试产物已清理。 + +### 波2 ✅ 核实即完成:阶段 C(流程监控) +后端 + amis 页早已存在(见上文阶段 C 更正),无需重做。 + +### 波3 ✅ 已实现 + 单测绿 + **live 验证通过**:阶段 D(BPMN 流程图) +- 后端 flowable-service 新 `ProcessDiagramController` `GET /process/{pi}/diagram`(返 bpmnXml + activeActivityIds + finishedActivityIds,只读,运行/历史双路取 procDefId);gateway `FlowableClient.diagram` + `TodoController GET /api/workflow/process/{pi}/diagram` 转发。 +- 前端新 `src/api/diagram.ts` + `src/components/ProcessDiagram.tsx`(bpmn-js NavigatedViewer,中文节点走浏览器字体,当前节点绿/已走过灰高亮);`ApprovalDrawer` 加「查看流程图」按需展开段。bpmn-js 依赖已装,build ✓(5104 模块)。 +- 单测 ProcessDiagramControllerTest 3 绿。**live e2e**:真实带 DI 的迁移实例(PI=511732)返 `bpmnXml=7586 chars / 含 BPMNDiagram 布局 / 当前节点 sid-… / 已走过 4 节点` → bpmn-js 可渲染。 + +### 阶段 E(P2)⏸ 外部阻塞 +真实流转/候选人/写流端到端 —— 需客户 BPMN(dev `EIP4_DEFAULT_APPROVAL` 通用流无 form_key)。注:`eip4flow` 库有 1512 流程定义/9441 实例可读,故**只读类**(流程图/轨迹)已能 live;写类真实流转仍待客户 BPMN。 + +### 阶段 F(P3)— 会签 ✅ 已实现+live;Modeler ⏸ 待 S1 +**会签更正(2026-06-26,用户确认是客户真实诉求)**:先前「阻塞/待核实」判断**错误**——会签不是 WfTemplate 的按钮 type,而是 **BPMN 多实例(multiInstance)节点结构**,故按钮 type 分布看不出。核实结果: +- 迁移库 28/1512 流程定义含 `multiInstanceLoopCharacteristics`;其中 **4 个真实业务流程**:安全技术交底(集合 type=`user`)、总包合同交底/招投标工程评审流程/施工技术交底(集合 type=`scriptUser`)。 +- **引擎机制本就全在**:flowable 原生多实例(并行任务+`completionCondition` 聚合) + `multiInstanceUsersHandler` bean 已移植并在 `FlowableEngineConfig` 注册 + 每个会签人走现有 `approve`。故 `user` 类型会签早已能跑。**会签从不是外部阻塞**。 +- **真正缺口**:`CandidateUsersHandler` 的 **`scriptUser`(JUEL 脚本)候选人解析分支当初故意没移植**("精简边界" WARN 降级,26 处)。3/4 真实会签流程用 scriptUser(`${APPLYUSERS}`) → 办理人解析返空 → 会签节点被跳过(日志实锤 WARN)。 +- **已修复**:`CandidateUsersHandler` 实现 scriptUser 分支 = 单变量 `${VAR}` 直读流程变量、复杂表达式回退 flowable 表达式管理器对 execution 求值、结果按 List/数组/逗号分号串/单值归一为去重 userId 列表。单测 8(`CandidateUsersScriptUserTest`);flowable-service 全量 56 绿无回归。 +- **live e2e**:起「招投标工程评审流程」(APPLYUSERS=3人) → 会签节点**生成 3 条并行任务**(修复前 0 条被跳过);完成 **1/3 不推进**(剩 2)、完成 **3/3 聚合推进**到下一节点(完成条件 `nrOfCompletedInstances/nrOfInstances==1` 全票);测试实例已清理。 + +**剩 Modeler ⏸**:流程定义 BPMN 在线 Modeler(B3,自研 vs 嵌入 flowable-modeler)仍卡 S1 拍板。 + +**会签残留(跟踪项,非阻断)**:① 会签进度显示("已会签 N/M 人")未做,可从多实例执行的 `nrOfInstances/nrOfCompletedInstances` 取,属 UX 增强;② scriptUser 复杂表达式回退依赖命令上下文,已 try/catch 安全降级;③ 真实 APPLYUSERS 由业务表单/前序步骤设置,本次用 start 变量模拟。 + +### 残留(非阻断,跟踪项) +- 协办/转阅目标用户用文本输入(与现有「转办」DelegateForm 同款),无真实用户存在性校验 → 错填 userId 会建不可见任务。**与现有转办行为一致**,建议后续统一接用户 picker(同时惠及转办)。 +- 协办/转阅按钮在 WfTemplate 均无 servicename(已核实),故 `runActionServiceIfAny` 对其为 no-op,安全。 + +**改动文件**(全部在 flowable-service + platform-flow-gateway + eip4-web,未触及其他模块;platform-report/legacy-core 的失败测试是它处 WIP/JDK 环境问题,与本次无关): +- 后端:`FlowController.java`、`Requests.java`、`ProcessDiagramController.java`(新)、`FlowableClient.java`、`ApprovalController.java`、`GatewayRequests.java`、`TodoController.java` + 3 测试 +- 前端:`approval.ts`、`ApprovalDrawer.tsx`、`diagram.ts`(新)、`ProcessDiagram.tsx`(新)、`package.json`(bpmn-js) diff --git a/flowable-service/src/main/java/com/dsasp/server/wf/user/assignee/CandidateUsersHandler.java b/flowable-service/src/main/java/com/dsasp/server/wf/user/assignee/CandidateUsersHandler.java index 6e7dda7..c3cb1cb 100644 --- a/flowable-service/src/main/java/com/dsasp/server/wf/user/assignee/CandidateUsersHandler.java +++ b/flowable-service/src/main/java/com/dsasp/server/wf/user/assignee/CandidateUsersHandler.java @@ -86,11 +86,11 @@ public class CandidateUsersHandler { ? WfTypes.INITIATORLEADER : WfTypes.INITIATORDEPARTMANAGER; users = directory.assignmentUser(t, userProperty.getContent(), beforeUser, null); }else if(WfTypes.SCRIPTUSER.equals(userProperty.getType())){ - // 原版经 ScriptingEngines.evaluate(content,"juel",execution) 求值; - // 独立服务不内置服务流脚本引擎(精简边界),WARN 降级,报告登记。 - log.warn("candidateUsersHandler: scriptUser(JUEL 脚本)分支独立服务暂未接入,跳过该项" - + "(影响面≈0.5%/26 处;命中则该任务无此类候选人,生产可监控)"); - users = new ArrayList(); + // scriptUser:content 为 JUEL 表达式(会签等多实例办理人集合多用此类型,绝大多数形如 ${VARNAME}, + // 如招投标/总包合同/施工技术交底会签的 ${APPLYUSERS})。原版经服务流脚本引擎求值;此处优先按 + // 单变量名直读流程变量(稳,无命令上下文依赖),复杂表达式回退 flowable 表达式管理器对 execution 求值, + // 结果按 List/数组/逗号分隔串/单值归一为 userId 列表。修复前此分支 WARN 降级返空 → 这类会签节点无办理人被跳过。 + users = resolveScriptUsers(runtimeService, processInstanceId, execution, userProperty.getContent()); }else if(WfTypes.PROJECTROLETYPE.equals(userProperty.getType())){ users = directory.getUsersByProjectRole(projectId, userProperty.getContent()); } @@ -207,6 +207,93 @@ public class CandidateUsersHandler { } } + /** {@code ${VAR}} 单变量名匹配(会签 scriptUser 绝大多数为此形态)。 */ + private static final java.util.regex.Pattern SINGLE_VAR = + java.util.regex.Pattern.compile("\\$\\{\\s*([A-Za-z_][A-Za-z0-9_]*)\\s*\\}"); + + /** + * scriptUser 类型办理人解析:content 为 JUEL 表达式。绝大多数(含会签 {@code ${APPLYUSERS}})是单变量名, + * 优先直读该流程变量(稳,无命令上下文依赖);非单变量的复杂表达式回退 flowable 表达式管理器对 execution 求值。 + * 结果按 List/数组/逗号分号(全/半角)分隔串/单值归一为去重 userId 列表;解析不出返回空(安全降级)。 + */ + protected List resolveScriptUsers(RuntimeService runtimeService, String processInstanceId, + Object execution, String content) { + if (content == null || content.isBlank()) { + return new ArrayList(); + } + Object value = null; + String varName = singleVarName(content); + if (varName != null && runtimeService != null && processInstanceId != null) { + value = getVariable(runtimeService, processInstanceId, varName); + } + if (value == null) { + value = evalExpression(execution, content); + } + List users = coerceUserList(value); + if (users.isEmpty()) { + log.warn("candidateUsersHandler: scriptUser 表达式解析出空候选人 content={}(检查流程变量是否已设置)", content); + } + return users; + } + + /** 单变量表达式 {@code ${VAR}} → 变量名;非单变量(复杂表达式/含运算)返回 null。 */ + static String singleVarName(String content) { + if (content == null) { + return null; + } + java.util.regex.Matcher m = SINGLE_VAR.matcher(content.trim()); + return m.matches() ? m.group(1) : null; + } + + /** 把表达式求值结果归一为去重 userId 列表:支持 Collection/数组/逗号分号(全角半角)分隔串/单值。 */ + static List coerceUserList(Object value) { + List out = new ArrayList(); + if (value == null) { + return out; + } + if (value instanceof java.util.Collection col) { + for (Object o : col) { + addUser(out, o); + } + } else if (value instanceof Object[] arr) { + for (Object o : arr) { + addUser(out, o); + } + } else if (value instanceof String s) { + for (String part : s.split("[,;,;\\s]+")) { + addUser(out, part); + } + } else { + addUser(out, value); + } + return out; + } + + private static void addUser(List out, Object o) { + if (o == null) { + return; + } + String s = o.toString().trim(); + if (!s.isEmpty() && !out.contains(s)) { + out.add(s); + } + } + + /** 复杂 JUEL 表达式回退:命令上下文内经 flowable 表达式管理器对 execution(VariableScope)求值。 */ + private Object evalExpression(Object execution, String content) { + try { + if (execution instanceof org.flowable.variable.api.delegate.VariableScope vs) { + var pec = org.flowable.engine.impl.context.Context.getProcessEngineConfiguration(); + if (pec != null) { + return pec.getExpressionManager().createExpression(content).getValue(vs); + } + } + } catch (Exception e) { + log.warn("candidateUsersHandler: scriptUser 复杂表达式求值失败 content={}: {}", content, e.toString()); + } + return null; + } + private static boolean isEmpty(String s) { return s == null || s.trim().isEmpty(); } diff --git a/flowable-service/src/main/java/com/eip4/flowservice/api/FlowController.java b/flowable-service/src/main/java/com/eip4/flowservice/api/FlowController.java index d2d2f17..1681585 100644 --- a/flowable-service/src/main/java/com/eip4/flowservice/api/FlowController.java +++ b/flowable-service/src/main/java/com/eip4/flowservice/api/FlowController.java @@ -40,6 +40,8 @@ public class FlowController { /** 默认审批流程 key:命名流程定义未部署时回退到此,保「提交审批」闭环可走(dev 无客户 BPMN 时)。 */ private static final String DEFAULT_APPROVAL_KEY = "EIP4_DEFAULT_APPROVAL"; private static final int STATUS_PROCESSING = 2; + /** 协办/转阅单次最多派发人数(防滥用刷任务,对齐人工选人场景的合理上限)。 */ + private static final int MAX_FANOUT = 50; private static final Set WITHDRAW_COMMENT_WHITELIST = Set.of("回退", "主动召回", "更换任务处理人员"); @@ -437,6 +439,143 @@ public class FlowController { return ResponseEntity.ok(t != null ? TaskDto.of(t) : null); } + @PostMapping("/tasks/{taskId}/assist") + @org.springframework.transaction.annotation.Transactional + @Operation(summary = "协办(加签)", + description = "对齐老 ProcessCoreServiceImpl.createSubTask:为每个目标用户建一条独立子任务" + + "(assignee=该用户,parentTaskId=当前任务,name=协办,formKey=父任务formKey 以便协办人渲染业务单据),父任务记意见。" + + "子任务进协办人待办,办毕各自 complete,不阻断主任务办理。父任务不存在 → 404,targetUserIds 为空 → 400,超 " + + MAX_FANOUT + " 人 → 400。整批 @Transactional 原子。") + public ResponseEntity> assist(@PathVariable String taskId, + @RequestBody(required = false) Requests.ActionRequest req) { + List userIds = targetUserIds(req); + ResponseEntity> bad = validateFanout(userIds, "协办"); + if (bad != null) { + return bad; + } + var parent = taskService.createTaskQuery().taskId(taskId).singleResult(); + if (parent == null) { + return ResponseEntity.notFound().build(); + } + // 协办子任务也带 formKey(取父任务 formKey),使协办人打开能渲染同一业务单据。 + String formKey = formKeyResolver.resolve(parent.getFormKey(), + parent.getProcessDefinitionId(), parent.getTaskDefinitionKey()); + addCommentIfPresent(taskId, parent, req == null ? null : req.comment); + for (String userId : userIds) { + org.flowable.task.api.Task sub = taskService.newTask(); + sub.setAssignee(userId); + sub.setParentTaskId(taskId); + sub.setName("协办"); + if (formKey != null) { + sub.setFormKey(formKey); + } + taskService.saveTask(sub); + } + Map r = new java.util.LinkedHashMap<>(); + r.put("assisted", true); + r.put("count", userIds.size()); + r.put("taskId", taskId); + return ResponseEntity.ok(r); + } + + @PostMapping("/tasks/{taskId}/circulate") + @org.springframework.transaction.annotation.Transactional + @Operation(summary = "转阅(抄送)", + description = "对齐老 ProcessCoreServiceImpl.createNewTask:为每个目标用户建一条只读转阅任务" + + "(name=转阅,assignee=该用户,parentTaskId=当前任务,formKey=父任务formKey 以便转阅人渲染同一业务单据)。" + + "转阅不阻断、不推进主流程。父任务不存在 → 404,targetUserIds 为空 → 400,超 " + MAX_FANOUT + + " 人 → 400。整批 @Transactional 原子。") + public ResponseEntity> circulate(@PathVariable String taskId, + @RequestBody(required = false) Requests.ActionRequest req) { + List userIds = targetUserIds(req); + ResponseEntity> bad = validateFanout(userIds, "转阅"); + if (bad != null) { + return bad; + } + var parent = taskService.createTaskQuery().taskId(taskId).singleResult(); + if (parent == null) { + return ResponseEntity.notFound().build(); + } + String formKey = formKeyResolver.resolve(parent.getFormKey(), + parent.getProcessDefinitionId(), parent.getTaskDefinitionKey()); + addCommentIfPresent(taskId, parent, req == null ? null : req.comment); + for (String userId : userIds) { + org.flowable.task.api.Task copy = taskService.newTask(); + copy.setName("转阅"); + copy.setAssignee(userId); + // 用 setFormKey(而非塞 description)使审批渲染路径 FormKeyResolver 直接命中。 + if (formKey != null) { + copy.setFormKey(formKey); + } + copy.setParentTaskId(taskId); + taskService.saveTask(copy); + } + Map r = new java.util.LinkedHashMap<>(); + r.put("circulated", true); + r.put("count", userIds.size()); + r.put("taskId", taskId); + return ResponseEntity.ok(r); + } + + /** 协办/转阅派发人数校验:空 → 400「需指定」;超 {@link #MAX_FANOUT} → 400。合法返回 null。 */ + private ResponseEntity> validateFanout(List userIds, String verb) { + if (userIds.isEmpty()) { + return ResponseEntity.badRequest().body(errorBody(verb + "需指定 targetUserIds")); + } + if (userIds.size() > MAX_FANOUT) { + return ResponseEntity.badRequest().body(errorBody(verb + "人数超过上限 " + MAX_FANOUT)); + } + return null; + } + + /** 协办/转阅目标用户:优先 targetUserIds 列表,回退单个 targetUserId;去空白去重。 */ + private static List targetUserIds(Requests.ActionRequest req) { + java.util.LinkedHashSet set = new java.util.LinkedHashSet<>(); + if (req != null && req.targetUserIds != null) { + for (String u : req.targetUserIds) { + if (u != null && !u.isBlank()) { + set.add(u.trim()); + } + } + } + if (req != null && req.targetUserId != null && !req.targetUserId.isBlank()) { + set.add(req.targetUserId.trim()); + } + return new java.util.ArrayList<>(set); + } + + /** 父任务存在且意见非空时记入流程评论(对齐老 addComment:用父任务的 processInstanceId)。 */ + private void addCommentIfPresent(String taskId, org.flowable.task.api.Task parent, String comment) { + if (parent != null && comment != null && !comment.isBlank()) { + taskService.addComment(taskId, parent.getProcessInstanceId(), comment); + } + } + + /** 父任务回溯出的业务上下文(供协办/转阅独立任务渲染同一业务单据)。 */ + private record ParentContext(String processInstanceId, String formKey, + String processDefinitionId, String taskDefinitionKey) { + } + + /** 按 parentTaskId 取父任务的业务上下文:运行库优先,否则历史库;都查不到返回 null。 */ + private ParentContext resolveParentContext(String parentTaskId) { + var p = taskService.createTaskQuery().taskId(parentTaskId).singleResult(); + if (p != null) { + return new ParentContext(p.getProcessInstanceId(), p.getFormKey(), + p.getProcessDefinitionId(), p.getTaskDefinitionKey()); + } + HistoricTaskInstance hp = historyService.createHistoricTaskInstanceQuery() + .taskId(parentTaskId).singleResult(); + if (hp != null) { + return new ParentContext(hp.getProcessInstanceId(), hp.getFormKey(), + hp.getProcessDefinitionId(), hp.getTaskDefinitionKey()); + } + return null; + } + + private static boolean isBlank(String s) { + return s == null || s.isBlank(); + } + @GetMapping("/tasks/{taskId}/approval-context") @Operation(summary = "任务审批上下文", description = "聚合返回 WfTemplate 驱动审批界面所需事实:formKey(=view_wftemplate_id,经 FormKeyResolver 历史回补)、" @@ -453,13 +592,48 @@ public class FlowController { dto.processDefinitionId = t.getProcessDefinitionId(); dto.taskDefinitionKey = t.getTaskDefinitionKey(); dto.suspended = t.isSuspended(); - dto.formKey = formKeyResolver.resolve(t.getFormKey(), t.getProcessDefinitionId(), t.getTaskDefinitionKey()); - dto.startFormKey = startFormKeyResolver.resolve(t.getProcessDefinitionId()); - ProcessInstance pi = runtimeService.createProcessInstanceQuery() - .processInstanceId(t.getProcessInstanceId()).singleResult(); - if (pi != null) { - dto.businessKey = pi.getBusinessKey(); - dto.ended = false; + + String formKeyRaw = t.getFormKey(); + String procDefId = t.getProcessDefinitionId(); + String taskDefKey = t.getTaskDefinitionKey(); + String pid = t.getProcessInstanceId(); + + // 协办/转阅是独立任务(无 processInstanceId/businessKey):沿 parentTaskId 回溯父任务取业务上下文, + // 使协办人/转阅人打开能渲染同一业务单据。同时避免下面用 null pid 查 runtime 抛 IllegalArgument。 + if (isBlank(pid) && !isBlank(t.getParentTaskId())) { + ParentContext pc = resolveParentContext(t.getParentTaskId()); + if (pc != null) { + pid = pc.processInstanceId(); + if (isBlank(formKeyRaw)) { + formKeyRaw = pc.formKey(); + } + if (isBlank(procDefId)) { + procDefId = pc.processDefinitionId(); + } + if (isBlank(taskDefKey)) { + taskDefKey = pc.taskDefinitionKey(); + } + dto.processInstanceId = pid; // 让前端轨迹/business-data 能定位父流程 + } + } + + dto.formKey = formKeyResolver.resolve(formKeyRaw, procDefId, taskDefKey); + dto.startFormKey = startFormKeyResolver.resolve(procDefId); + if (!isBlank(pid)) { + ProcessInstance pi = runtimeService.createProcessInstanceQuery() + .processInstanceId(pid).singleResult(); + if (pi != null) { + dto.businessKey = pi.getBusinessKey(); + dto.ended = false; + } else { + // 父流程可能已进历史(协办/转阅后主流程已结束) + var hpi = historyService.createHistoricProcessInstanceQuery() + .processInstanceId(pid).singleResult(); + if (hpi != null) { + dto.businessKey = hpi.getBusinessKey(); + dto.ended = hpi.getEndTime() != null; + } + } } return ResponseEntity.ok(dto); } diff --git a/flowable-service/src/main/java/com/eip4/flowservice/api/ProcessDiagramController.java b/flowable-service/src/main/java/com/eip4/flowservice/api/ProcessDiagramController.java new file mode 100644 index 0000000..0ac2459 --- /dev/null +++ b/flowable-service/src/main/java/com/eip4/flowservice/api/ProcessDiagramController.java @@ -0,0 +1,128 @@ +package com.eip4.flowservice.api; + +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import org.flowable.engine.HistoryService; +import org.flowable.engine.RepositoryService; +import org.flowable.engine.RuntimeService; +import org.flowable.engine.history.HistoricProcessInstance; +import org.flowable.engine.runtime.ProcessInstance; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.ResponseEntity; +import org.springframework.util.StreamUtils; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; + +/** + * 流程图(BPMN)查看端点:返回流程定义的 BPMN 2.0 XML + 当前/历史活动节点,供前端 bpmn-js 渲染并高亮。 + * + *

迁移的 1512 个流程定义中 1501(99.3%)含 BPMNDI 布局段,bpmn-js 可直接据此排版。 + * 节点名为中文 → 用前端 bpmn-js(浏览器字体)而非服务端出图(PNG 中文易乱码且需服务器字体)。

+ * + *

只读:仅查询引擎,不改任何流程/任务/业务数据。运行中实例取运行库 procDefId 与当前节点; + * 已结束实例回退历史库取 procDefId(无当前节点)。实例不存在返回 {@code found=false}(前端降级)。

+ */ +@RestController +@RequestMapping("/api/flow") +@Tag(name = "流程图", description = "BPMN XML + 当前/历史节点(bpmn-js 渲染高亮)") +public class ProcessDiagramController { + + private static final Logger log = LoggerFactory.getLogger(ProcessDiagramController.class); + + private final RepositoryService repositoryService; + private final RuntimeService runtimeService; + private final HistoryService historyService; + + public ProcessDiagramController(RepositoryService repositoryService, RuntimeService runtimeService, + HistoryService historyService) { + this.repositoryService = repositoryService; + this.runtimeService = runtimeService; + this.historyService = historyService; + } + + @GetMapping("/process/{processInstanceId}/diagram") + @Operation(summary = "流程图数据", + description = "返回 {found, bpmnXml, activeActivityIds(当前停留), finishedActivityIds(已走过)}。" + + "运行中实例取运行库 procDefId + getActiveActivityIds;已结束取历史库 procDefId(无当前节点);" + + "实例不存在 found=false。bpmnXml = repositoryService.getProcessModel(procDefId)。") + public ResponseEntity> diagram(@PathVariable String processInstanceId) { + Map resp = new LinkedHashMap<>(); + resp.put("processInstanceId", processInstanceId); + + // procDefId:运行库优先(含当前活动节点),否则历史库(已结束) + ProcessInstance pi = runtimeService.createProcessInstanceQuery() + .processInstanceId(processInstanceId).singleResult(); + String procDefId = pi != null ? pi.getProcessDefinitionId() : null; + boolean running = pi != null; + if (procDefId == null) { + HistoricProcessInstance hpi = historyService.createHistoricProcessInstanceQuery() + .processInstanceId(processInstanceId).singleResult(); + procDefId = hpi != null ? hpi.getProcessDefinitionId() : null; + } + if (procDefId == null) { + resp.put("found", false); + resp.put("activeActivityIds", List.of()); + resp.put("finishedActivityIds", List.of()); + return ResponseEntity.ok(resp); + } + + String bpmnXml = readProcessModel(procDefId); + if (bpmnXml == null) { + resp.put("found", false); + resp.put("activeActivityIds", List.of()); + resp.put("finishedActivityIds", List.of()); + return ResponseEntity.ok(resp); + } + + // 当前停留节点(仅运行中实例有) + List active = running ? safeActiveActivityIds(processInstanceId) : List.of(); + // 已走过的历史节点 + List finished = historyService.createHistoricActivityInstanceQuery() + .processInstanceId(processInstanceId).finished().list().stream() + .map(a -> a.getActivityId()) + .filter(id -> id != null && !id.isBlank()) + .distinct() + .collect(Collectors.toList()); + + resp.put("found", true); + resp.put("bpmnXml", bpmnXml); + resp.put("activeActivityIds", active); + resp.put("finishedActivityIds", finished); + return ResponseEntity.ok(resp); + } + + /** 读流程定义 BPMN XML(getProcessModel 返回部署的 BPMN 资源流)。读失败返回 null(前端降级)。 */ + private String readProcessModel(String procDefId) { + try (InputStream is = repositoryService.getProcessModel(procDefId)) { + if (is == null) { + return null; + } + return StreamUtils.copyToString(is, StandardCharsets.UTF_8); + } catch (Exception e) { + log.warn("[流程图] 读取 BPMN 失败 procDefId={}: {}", procDefId, e.toString()); + return null; + } + } + + /** getActiveActivityIds 对已结束/不存在实例会抛异常 → 包裹降级为空。 */ + private List safeActiveActivityIds(String processInstanceId) { + try { + List ids = runtimeService.getActiveActivityIds(processInstanceId); + return ids == null ? List.of() : ids; + } catch (RuntimeException e) { + log.debug("[流程图] 取当前节点降级 pi={}: {}", processInstanceId, e.toString()); + return List.of(); + } + } +} diff --git a/flowable-service/src/main/java/com/eip4/flowservice/api/Requests.java b/flowable-service/src/main/java/com/eip4/flowservice/api/Requests.java index f4b6281..5a16cea 100644 --- a/flowable-service/src/main/java/com/eip4/flowservice/api/Requests.java +++ b/flowable-service/src/main/java/com/eip4/flowservice/api/Requests.java @@ -39,8 +39,10 @@ public final class Requests { public static class ActionRequest { /** 审批意见(记入流程评论)。 */ public String comment; - /** 目标用户(转办/协办/转阅用;reject/reback 不需要)。 */ + /** 目标用户(转办用;reject/reback 不需要)。 */ public String targetUserId; + /** 多目标用户(协办/转阅:老系统用 MultiSelectField 选多人,每人各建一条子/转阅任务)。 */ + public java.util.List targetUserIds; } /** diff --git a/flowable-service/src/test/java/com/dsasp/server/wf/user/assignee/CandidateUsersScriptUserTest.java b/flowable-service/src/test/java/com/dsasp/server/wf/user/assignee/CandidateUsersScriptUserTest.java new file mode 100644 index 0000000..a2a9166 --- /dev/null +++ b/flowable-service/src/test/java/com/dsasp/server/wf/user/assignee/CandidateUsersScriptUserTest.java @@ -0,0 +1,64 @@ +package com.dsasp.server.wf.user.assignee; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.Arrays; +import java.util.List; + +import org.junit.jupiter.api.Test; + +/** + * scriptUser 会签办理人解析的纯函数单测(同包以访问包级 helper): + * 单变量名提取 + 求值结果归一为 userId 列表。修复前 scriptUser 分支 WARN 降级返空, + * 致招投标/总包合同/施工技术交底等会签节点(集合用 ${APPLYUSERS})无办理人被跳过。 + */ +class CandidateUsersScriptUserTest { + + @Test + void singleVarName_提取简单变量() { + assertThat(CandidateUsersHandler.singleVarName("${APPLYUSERS}")).isEqualTo("APPLYUSERS"); + assertThat(CandidateUsersHandler.singleVarName(" ${ APPLYUSERS } ")).isEqualTo("APPLYUSERS"); + } + + @Test + void singleVarName_复杂表达式返回null() { + assertThat(CandidateUsersHandler.singleVarName("${a + b}")).isNull(); + assertThat(CandidateUsersHandler.singleVarName("${users[0]}")).isNull(); + assertThat(CandidateUsersHandler.singleVarName("ADMIN")).isNull(); + assertThat(CandidateUsersHandler.singleVarName(null)).isNull(); + } + + @Test + void coerceUserList_支持List() { + assertThat(CandidateUsersHandler.coerceUserList(List.of("u1", "u2"))) + .containsExactly("u1", "u2"); + } + + @Test + void coerceUserList_支持数组() { + assertThat(CandidateUsersHandler.coerceUserList(new String[] { "u1", "u2" })) + .containsExactly("u1", "u2"); + } + + @Test + void coerceUserList_逗号分号全角半角分隔串() { + assertThat(CandidateUsersHandler.coerceUserList("u1,u2; u3,u4;u5")) + .containsExactly("u1", "u2", "u3", "u4", "u5"); + } + + @Test + void coerceUserList_单值() { + assertThat(CandidateUsersHandler.coerceUserList("ADMIN")).containsExactly("ADMIN"); + } + + @Test + void coerceUserList_去重去空白() { + assertThat(CandidateUsersHandler.coerceUserList(Arrays.asList(" u1 ", "u1", "", "u2", null))) + .containsExactly("u1", "u2"); + } + + @Test + void coerceUserList_null返回空() { + assertThat(CandidateUsersHandler.coerceUserList(null)).isEmpty(); + } +} diff --git a/flowable-service/src/test/java/com/eip4/flowservice/api/FlowControllerTest.java b/flowable-service/src/test/java/com/eip4/flowservice/api/FlowControllerTest.java index b1e1731..af90ed4 100644 --- a/flowable-service/src/test/java/com/eip4/flowservice/api/FlowControllerTest.java +++ b/flowable-service/src/test/java/com/eip4/flowservice/api/FlowControllerTest.java @@ -330,4 +330,129 @@ class FlowControllerTest { .andExpect(status().isOk()) .andExpect(org.springframework.test.web.servlet.result.MockMvcResultMatchers.content().string("1509")); } + + // ---------------------------------------------------------------- 协办(assist) / 转阅(circulate) + + @Test + void 协办缺少目标用户返回400() throws Exception { + mvc.perform(post("/api/flow/tasks/task-9/assist") + .contentType("application/json") + .content("{\"comment\":\"请协助\"}")) + .andExpect(status().isBadRequest()); + } + + @Test + void 协办为每个目标用户建子任务并记意见() throws Exception { + // 父任务查得(取 processInstanceId 记意见) + when(taskService.createTaskQuery()).thenReturn(taskQuery); + when(taskQuery.taskId("task-9")).thenReturn(taskQuery); + Task parent = org.mockito.Mockito.mock(Task.class); + when(parent.getProcessInstanceId()).thenReturn("pi-9"); + when(taskQuery.singleResult()).thenReturn(parent); + // 每次 newTask() 返回一个新子任务桩 + Task sub = org.mockito.Mockito.mock(Task.class); + when(taskService.newTask()).thenReturn(sub); + + mvc.perform(post("/api/flow/tasks/task-9/assist") + .contentType("application/json") + .content("{\"comment\":\"请协助\",\"targetUserIds\":[\"u-a\",\"u-b\"]}")) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.assisted").value(true)) + .andExpect(jsonPath("$.count").value(2)); + + // 两个子任务:各设受托人/父任务/名称「协办」后保存 + verify(sub).setAssignee("u-a"); + verify(sub).setAssignee("u-b"); + verify(sub, org.mockito.Mockito.times(2)).setParentTaskId("task-9"); + verify(sub, org.mockito.Mockito.times(2)).setName("协办"); + verify(taskService, org.mockito.Mockito.times(2)).saveTask(sub); + verify(taskService).addComment("task-9", "pi-9", "请协助"); + } + + @Test + void 转阅为每个目标用户建转阅任务并存formKey() throws Exception { + when(taskService.createTaskQuery()).thenReturn(taskQuery); + when(taskQuery.taskId("task-10")).thenReturn(taskQuery); + Task parent = org.mockito.Mockito.mock(Task.class); + when(parent.getProcessInstanceId()).thenReturn("pi-10"); + when(parent.getFormKey()).thenReturn("wf-tpl-77"); // FormKeyResolver: 原始非空直接返回 + when(taskQuery.singleResult()).thenReturn(parent); + Task copy = org.mockito.Mockito.mock(Task.class); + when(taskService.newTask()).thenReturn(copy); + + mvc.perform(post("/api/flow/tasks/task-10/circulate") + .contentType("application/json") + .content("{\"comment\":\"请阅\",\"targetUserIds\":[\"u-c\"]}")) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.circulated").value(true)) + .andExpect(jsonPath("$.count").value(1)); + + verify(copy).setName("转阅"); + verify(copy).setAssignee("u-c"); + verify(copy).setFormKey("wf-tpl-77"); // 用 setFormKey 而非 description,审批渲染 FormKeyResolver 直接命中 + verify(copy).setParentTaskId("task-10"); + verify(taskService).saveTask(copy); + } + + @Test + void 转阅父任务不存在返回404() throws Exception { + when(taskService.createTaskQuery()).thenReturn(taskQuery); + when(taskQuery.taskId("nope")).thenReturn(taskQuery); + when(taskQuery.singleResult()).thenReturn(null); + + mvc.perform(post("/api/flow/tasks/nope/circulate") + .contentType("application/json") + .content("{\"targetUserIds\":[\"u-c\"]}")) + .andExpect(status().isNotFound()); + } + + @Test + void 协办独立任务approvalContext回溯父任务取业务上下文() throws Exception { + // 协办/转阅建的是独立任务:无 processInstanceId,有 parentTaskId。审批上下文须回溯父任务取 businessKey/formKey, + // 否则协办人/转阅人打开看不到业务单据(code review HIGH 修复点)。 + when(taskService.createTaskQuery()).thenReturn(taskQuery); + Task sub = org.mockito.Mockito.mock(Task.class); + when(sub.getName()).thenReturn("协办"); + when(sub.getProcessInstanceId()).thenReturn(null); + when(sub.getParentTaskId()).thenReturn("parent-1"); + when(sub.getFormKey()).thenReturn(null); + TaskQuery subQuery = org.mockito.Mockito.mock(TaskQuery.class); + when(taskQuery.taskId("sub-1")).thenReturn(subQuery); + when(subQuery.singleResult()).thenReturn(sub); + // 父任务:真实流程任务,带 processInstanceId/formKey + Task parent = org.mockito.Mockito.mock(Task.class); + when(parent.getProcessInstanceId()).thenReturn("pi-1"); + when(parent.getFormKey()).thenReturn("wf-77"); + when(parent.getProcessDefinitionId()).thenReturn("def-1"); + when(parent.getTaskDefinitionKey()).thenReturn("node-a"); + TaskQuery parentQuery = org.mockito.Mockito.mock(TaskQuery.class); + when(taskQuery.taskId("parent-1")).thenReturn(parentQuery); + when(parentQuery.singleResult()).thenReturn(parent); + // 父流程实例 businessKey + when(runtimeService.createProcessInstanceQuery()).thenReturn(processInstanceQuery); + when(processInstanceQuery.processInstanceId("pi-1")).thenReturn(processInstanceQuery); + ProcessInstance pi = org.mockito.Mockito.mock(ProcessInstance.class); + when(pi.getBusinessKey()).thenReturn("BK-1"); + when(processInstanceQuery.singleResult()).thenReturn(pi); + + mvc.perform(get("/api/flow/tasks/sub-1/approval-context")) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.found").value(true)) + .andExpect(jsonPath("$.formKey").value("wf-77")) + .andExpect(jsonPath("$.businessKey").value("BK-1")) + .andExpect(jsonPath("$.processInstanceId").value("pi-1")); + } + + @Test + void 协办超过上限返回400() throws Exception { + StringBuilder ids = new StringBuilder("["); + for (int i = 0; i < 51; i++) { + ids.append(i == 0 ? "" : ",").append("\"u").append(i).append("\""); + } + ids.append("]"); + mvc.perform(post("/api/flow/tasks/t/assist") + .contentType("application/json") + .content("{\"targetUserIds\":" + ids + "}")) + .andExpect(status().isBadRequest()); + } } diff --git a/flowable-service/src/test/java/com/eip4/flowservice/api/ProcessDiagramControllerTest.java b/flowable-service/src/test/java/com/eip4/flowservice/api/ProcessDiagramControllerTest.java new file mode 100644 index 0000000..8b21fcb --- /dev/null +++ b/flowable-service/src/test/java/com/eip4/flowservice/api/ProcessDiagramControllerTest.java @@ -0,0 +1,120 @@ +package com.eip4.flowservice.api; + +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import java.io.ByteArrayInputStream; +import java.nio.charset.StandardCharsets; +import java.util.List; + +import org.flowable.engine.HistoryService; +import org.flowable.engine.RepositoryService; +import org.flowable.engine.RuntimeService; +import org.flowable.engine.history.HistoricActivityInstance; +import org.flowable.engine.history.HistoricActivityInstanceQuery; +import org.flowable.engine.history.HistoricProcessInstance; +import org.flowable.engine.history.HistoricProcessInstanceQuery; +import org.flowable.engine.runtime.ProcessInstance; +import org.flowable.engine.runtime.ProcessInstanceQuery; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; + +/** + * 流程图端点薄层单测:mock 引擎,验证 BPMN XML 透出 + 当前/历史节点收敛 + 实例不存在降级。 + */ +@ExtendWith(MockitoExtension.class) +class ProcessDiagramControllerTest { + + @Mock RepositoryService repositoryService; + @Mock RuntimeService runtimeService; + @Mock HistoryService historyService; + @Mock ProcessInstanceQuery processInstanceQuery; + @Mock HistoricProcessInstanceQuery historicProcessInstanceQuery; + @Mock HistoricActivityInstanceQuery historicActivityInstanceQuery; + + MockMvc mvc; + + @BeforeEach + void setUp() { + ProcessDiagramController controller = new ProcessDiagramController(repositoryService, runtimeService, historyService); + mvc = MockMvcBuilders.standaloneSetup(controller).build(); + } + + @Test + void 运行中流程返回XML与当前及历史节点() throws Exception { + ProcessInstance pi = org.mockito.Mockito.mock(ProcessInstance.class); + when(pi.getProcessDefinitionId()).thenReturn("def-1"); + when(runtimeService.createProcessInstanceQuery()).thenReturn(processInstanceQuery); + when(processInstanceQuery.processInstanceId("pi-1")).thenReturn(processInstanceQuery); + when(processInstanceQuery.singleResult()).thenReturn(pi); + when(runtimeService.getActiveActivityIds("pi-1")).thenReturn(List.of("task_b")); + + String xml = ""; + when(repositoryService.getProcessModel("def-1")) + .thenReturn(new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8))); + + HistoricActivityInstance a1 = org.mockito.Mockito.mock(HistoricActivityInstance.class); + when(a1.getActivityId()).thenReturn("task_a"); + when(historyService.createHistoricActivityInstanceQuery()).thenReturn(historicActivityInstanceQuery); + when(historicActivityInstanceQuery.processInstanceId("pi-1")).thenReturn(historicActivityInstanceQuery); + when(historicActivityInstanceQuery.finished()).thenReturn(historicActivityInstanceQuery); + when(historicActivityInstanceQuery.list()).thenReturn(List.of(a1)); + + mvc.perform(get("/api/flow/process/pi-1/diagram")) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.found").value(true)) + .andExpect(jsonPath("$.bpmnXml").value(xml)) + .andExpect(jsonPath("$.activeActivityIds[0]").value("task_b")) + .andExpect(jsonPath("$.finishedActivityIds[0]").value("task_a")); + } + + @Test + void 已结束流程走历史取XML无当前节点() throws Exception { + // 运行库查不到 + when(runtimeService.createProcessInstanceQuery()).thenReturn(processInstanceQuery); + when(processInstanceQuery.processInstanceId("pi-2")).thenReturn(processInstanceQuery); + when(processInstanceQuery.singleResult()).thenReturn(null); + // 历史库查得 procDefId + HistoricProcessInstance hpi = org.mockito.Mockito.mock(HistoricProcessInstance.class); + when(hpi.getProcessDefinitionId()).thenReturn("def-2"); + when(historyService.createHistoricProcessInstanceQuery()).thenReturn(historicProcessInstanceQuery); + when(historicProcessInstanceQuery.processInstanceId("pi-2")).thenReturn(historicProcessInstanceQuery); + when(historicProcessInstanceQuery.singleResult()).thenReturn(hpi); + + String xml = ""; + when(repositoryService.getProcessModel("def-2")) + .thenReturn(new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8))); + when(historyService.createHistoricActivityInstanceQuery()).thenReturn(historicActivityInstanceQuery); + when(historicActivityInstanceQuery.processInstanceId("pi-2")).thenReturn(historicActivityInstanceQuery); + when(historicActivityInstanceQuery.finished()).thenReturn(historicActivityInstanceQuery); + when(historicActivityInstanceQuery.list()).thenReturn(List.of()); + + mvc.perform(get("/api/flow/process/pi-2/diagram")) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.found").value(true)) + .andExpect(jsonPath("$.bpmnXml").value(xml)) + .andExpect(jsonPath("$.activeActivityIds").isEmpty()); + } + + @Test + void 实例不存在返回found_false不报错() throws Exception { + when(runtimeService.createProcessInstanceQuery()).thenReturn(processInstanceQuery); + when(processInstanceQuery.processInstanceId(eq("nope"))).thenReturn(processInstanceQuery); + when(processInstanceQuery.singleResult()).thenReturn(null); + when(historyService.createHistoricProcessInstanceQuery()).thenReturn(historicProcessInstanceQuery); + when(historicProcessInstanceQuery.processInstanceId("nope")).thenReturn(historicProcessInstanceQuery); + when(historicProcessInstanceQuery.singleResult()).thenReturn(null); + + mvc.perform(get("/api/flow/process/nope/diagram")) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.found").value(false)); + } +} diff --git a/platform-flow-gateway/src/main/java/com/eip4/platform/flowgateway/client/FlowableClient.java b/platform-flow-gateway/src/main/java/com/eip4/platform/flowgateway/client/FlowableClient.java index 8cd99c5..e9405ae 100644 --- a/platform-flow-gateway/src/main/java/com/eip4/platform/flowgateway/client/FlowableClient.java +++ b/platform-flow-gateway/src/main/java/com/eip4/platform/flowgateway/client/FlowableClient.java @@ -170,6 +170,36 @@ public class FlowableClient { Map.of("delegateUserId", delegateUserId), Void.class); } + /** + * 协办(加签):为每个 userId 建一条子任务。对应 flowable-service + * {@code POST /api/flow/tasks/{taskId}/assist}。 + */ + @SuppressWarnings("unchecked") + public Map assist(String taskId, List userIds, String comment) { + return post("协办", "/api/flow/tasks/" + taskId + "/assist", + actionBody(userIds, comment), Map.class); + } + + /** + * 转阅(抄送):为每个 userId 建一条只读转阅任务。对应 flowable-service + * {@code POST /api/flow/tasks/{taskId}/circulate}。 + */ + @SuppressWarnings("unchecked") + public Map circulate(String taskId, List userIds, String comment) { + return post("转阅", "/api/flow/tasks/" + taskId + "/circulate", + actionBody(userIds, comment), Map.class); + } + + /** 协办/转阅请求体:targetUserIds(必) + comment(可空)。 */ + private static Map actionBody(List userIds, String comment) { + Map body = new java.util.LinkedHashMap<>(); + body.put("targetUserIds", userIds == null ? List.of() : userIds); + if (comment != null && !comment.isBlank()) { + body.put("comment", comment); + } + return body; + } + /** * 查流程实例(供办理后判定是否结束以回写业务状态)。 * 实例不存在(404)返回 null;运行中 {@code ended=false},已结束 {@code ended=true}。 @@ -184,6 +214,18 @@ public class FlowableClient { .body(ProcessInstanceDto.class)); } + /** + * 流程图数据(BPMN XML + 当前/历史节点)。对应 flowable-service + * {@code GET /api/flow/process/{processInstanceId}/diagram}。供前端 bpmn-js 渲染高亮。 + */ + @SuppressWarnings("unchecked") + public Map diagram(String processInstanceId) { + return execute("流程图", () -> restClient.get() + .uri("/api/flow/process/{id}/diagram", processInstanceId) + .retrieve() + .body(Map.class)); + } + /** 按发起人查询历史流程实例。对应 flowable-service {@code GET /api/flow/process/started}。 */ public List started(String startedBy, int firstResult, int maxResults) { return execute("发起流程列表", () -> restClient.get() diff --git a/platform-flow-gateway/src/main/java/com/eip4/platform/flowgateway/web/ApprovalController.java b/platform-flow-gateway/src/main/java/com/eip4/platform/flowgateway/web/ApprovalController.java index 2ad5675..49b7117 100644 --- a/platform-flow-gateway/src/main/java/com/eip4/platform/flowgateway/web/ApprovalController.java +++ b/platform-flow-gateway/src/main/java/com/eip4/platform/flowgateway/web/ApprovalController.java @@ -203,7 +203,8 @@ public class ApprovalController { @Operation(summary = "审批动作分派(按 WfTemplate 按钮 type)", description = "approve=complete+回写 SYS_DATASTATUS(结束 3/未结束 2);reject=终止流程+回写 4;" - + "reback=退回发起+回写 5;agent=委托给 targetUserId。协办/转阅暂未实现(返回 400)。") + + "reback=退回发起+回写 5;agent=委托给 targetUserId;assist=协办(为 targetUserIds 各建子任务);" + + "circulated=转阅(为 targetUserIds 各建只读转阅任务)。") @PostMapping("/api/task/{taskId}/action") public ResponseEntity> action(@PathVariable String taskId, @RequestBody GatewayRequests.ApprovalActionRequest req) { @@ -224,7 +225,8 @@ public class ApprovalController { case "reject" -> reject(taskId, req); case "reback" -> reback(taskId, req); case "agent" -> agent(taskId, req); - case "assist", "circulated" -> badRequest("暂不支持「" + labelOf(type) + "」,请用转办(agent)"); + case "assist" -> assist(taskId, req); + case "circulated" -> circulate(taskId, req); default -> badRequest("未知审批动作: " + type); }; } @@ -364,6 +366,50 @@ public class ApprovalController { return ResponseEntity.ok(r); } + /** 协办(加签):为每个目标用户建一条子任务(引擎 createSubTask),不阻断主任务。 */ + private ResponseEntity> assist(String taskId, GatewayRequests.ApprovalActionRequest req) { + List users = targetUsers(req); + if (users.isEmpty()) { + return badRequest("协办需指定 targetUserIds"); + } + Map engine = flowableClient.assist(taskId, users, req.comment); + Map r = ok("assist"); + r.put("assisted", true); + r.put("count", engine != null ? engine.get("count") : users.size()); + r.put("targetUserIds", users); + return ResponseEntity.ok(r); + } + + /** 转阅(抄送):为每个目标用户建一条只读转阅任务(引擎 createNewTask),不推进主流程。 */ + private ResponseEntity> circulate(String taskId, GatewayRequests.ApprovalActionRequest req) { + List users = targetUsers(req); + if (users.isEmpty()) { + return badRequest("转阅需指定 targetUserIds"); + } + Map engine = flowableClient.circulate(taskId, users, req.comment); + Map r = ok("circulated"); + r.put("circulated", true); + r.put("count", engine != null ? engine.get("count") : users.size()); + r.put("targetUserIds", users); + return ResponseEntity.ok(r); + } + + /** 协办/转阅目标用户:优先 targetUserIds 列表,回退单个 targetUserId;去空白去重。 */ + private static List targetUsers(GatewayRequests.ApprovalActionRequest req) { + java.util.LinkedHashSet set = new java.util.LinkedHashSet<>(); + if (req.targetUserIds != null) { + for (String u : req.targetUserIds) { + if (u != null && !u.isBlank()) { + set.add(u.trim()); + } + } + } + if (req.targetUserId != null && !req.targetUserId.isBlank()) { + set.add(req.targetUserId.trim()); + } + return new ArrayList<>(set); + } + // ---------------------------------------------------------------- 小工具 /** 直接回写业务状态(reject/reback 是显式终态转移,不走单调守卫)。businessKey 空则不写。 */ @@ -476,8 +522,4 @@ public class ApprovalController { Object v = m == null ? null : m.get(key); return v == null ? null : String.valueOf(v); } - - private static String labelOf(String type) { - return "assist".equals(type) ? "协办" : "转阅"; - } } diff --git a/platform-flow-gateway/src/main/java/com/eip4/platform/flowgateway/web/GatewayRequests.java b/platform-flow-gateway/src/main/java/com/eip4/platform/flowgateway/web/GatewayRequests.java index 81c31ed..40cb5d3 100644 --- a/platform-flow-gateway/src/main/java/com/eip4/platform/flowgateway/web/GatewayRequests.java +++ b/platform-flow-gateway/src/main/java/com/eip4/platform/flowgateway/web/GatewayRequests.java @@ -50,8 +50,10 @@ public final class GatewayRequests { /** WfTemplate 按钮 id:服务器侧据此重解析该按钮的 servicename(自定义服务流)并执行,不信前端直传服务名。 */ public String buttonId; public String comment; - /** 转办/协办/转阅的目标用户。 */ + /** 转办的目标用户(单人)。 */ public String targetUserId; + /** 协办/转阅的目标用户(多人,老系统用 MultiSelectField 选多人,各建一条子/转阅任务)。 */ + public java.util.List targetUserIds; public String businessKey; public String processInstanceId; public String tableName; diff --git a/platform-flow-gateway/src/main/java/com/eip4/platform/flowgateway/web/TodoController.java b/platform-flow-gateway/src/main/java/com/eip4/platform/flowgateway/web/TodoController.java index 00cd2cf..1092594 100644 --- a/platform-flow-gateway/src/main/java/com/eip4/platform/flowgateway/web/TodoController.java +++ b/platform-flow-gateway/src/main/java/com/eip4/platform/flowgateway/web/TodoController.java @@ -359,6 +359,12 @@ public class TodoController { return ResponseEntity.ok(nodes); } + @Operation(summary = "流程图(BPMN)", description = "透传 flowable-service:返回流程定义 BPMN XML + 当前/历史活动节点,供前端 bpmn-js 渲染并高亮当前停留节点") + @GetMapping("/api/workflow/process/{processInstanceId}/diagram") + public ResponseEntity> diagram(@PathVariable String processInstanceId) { + return ResponseEntity.ok(flowableClient.diagram(processInstanceId)); + } + @Operation(summary = "委托任务", description = "将任务委托给指定用户(delegateUserId),assignee 变受托人,owner 记原办理人") @PostMapping("/api/task/{id}/delegate") public ResponseEntity> delegate(@PathVariable String id, diff --git a/platform-flow-gateway/src/test/java/com/eip4/platform/flowgateway/ApprovalControllerActionTest.java b/platform-flow-gateway/src/test/java/com/eip4/platform/flowgateway/ApprovalControllerActionTest.java new file mode 100644 index 0000000..6f93f2b --- /dev/null +++ b/platform-flow-gateway/src/test/java/com/eip4/platform/flowgateway/ApprovalControllerActionTest.java @@ -0,0 +1,108 @@ +package com.eip4.platform.flowgateway; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoInteractions; +import static org.mockito.Mockito.when; + +import java.util.List; +import java.util.Map; + +import org.junit.jupiter.api.Test; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import com.dsasp.server.common.core.service.FlowExcuteService; +import com.eip4.platform.flowgateway.aggregate.BusinessRecordLoader; +import com.eip4.platform.flowgateway.aggregate.BusinessSummaryService; +import com.eip4.platform.flowgateway.aggregate.WfTemplateService; +import com.eip4.platform.flowgateway.client.FlowableClient; +import com.eip4.platform.flowgateway.web.ApprovalController; +import com.eip4.platform.flowgateway.web.GatewayRequests; +import com.eip4.platform.flowgateway.writeback.StatusWriteback; +import com.eip4.platform.metadata.flow.UserColumnResolver; + +/** + * 审批动作分派单测:聚焦协办(assist)/转阅(circulated)新接线——按 type 转调 FlowableClient, + * targetUserIds 列表归一(去空白去重、回退单值),无目标用户 → 400。 + */ +class ApprovalControllerActionTest { + + private final FlowableClient flowableClient = mock(FlowableClient.class); + private final WfTemplateService wfTemplateService = mock(WfTemplateService.class); + private final BusinessSummaryService businessSummaryService = mock(BusinessSummaryService.class); + private final StatusWriteback statusWriteback = mock(StatusWriteback.class); + private final FlowExcuteService flowExcuteService = mock(FlowExcuteService.class); + private final BusinessRecordLoader businessRecordLoader = mock(BusinessRecordLoader.class); + private final UserColumnResolver userColumnResolver = mock(UserColumnResolver.class); + private final ApprovalController controller = new ApprovalController(flowableClient, wfTemplateService, + businessSummaryService, statusWriteback, flowExcuteService, businessRecordLoader, userColumnResolver); + + private GatewayRequests.ApprovalActionRequest req(String type) { + GatewayRequests.ApprovalActionRequest r = new GatewayRequests.ApprovalActionRequest(); + r.actionType = type; + return r; + } + + @Test + void assist_buildsSubTasksForEachUser() { + GatewayRequests.ApprovalActionRequest r = req("assist"); + r.targetUserIds = List.of("u-a", "u-b"); + r.comment = "请协助"; + when(flowableClient.assist("t1", List.of("u-a", "u-b"), "请协助")) + .thenReturn(Map.of("count", 2)); + + ResponseEntity> resp = controller.action("t1", r); + + assertThat(resp.getStatusCode().is2xxSuccessful()).isTrue(); + assertThat(resp.getBody()).containsEntry("action", "assist") + .containsEntry("assisted", true) + .containsEntry("count", 2); + verify(flowableClient).assist("t1", List.of("u-a", "u-b"), "请协助"); + } + + @Test + void circulated_buildsReadonlyTasksForEachUser() { + GatewayRequests.ApprovalActionRequest r = req("circulated"); + r.targetUserIds = List.of("u-c"); + when(flowableClient.circulate("t2", List.of("u-c"), null)) + .thenReturn(Map.of("count", 1)); + + ResponseEntity> resp = controller.action("t2", r); + + assertThat(resp.getStatusCode().is2xxSuccessful()).isTrue(); + assertThat(resp.getBody()).containsEntry("action", "circulated") + .containsEntry("circulated", true) + .containsEntry("count", 1); + verify(flowableClient).circulate("t2", List.of("u-c"), null); + } + + @Test + void assist_dedupesAndFallsBackToSingleTargetUserId() { + GatewayRequests.ApprovalActionRequest r = req("assist"); + r.targetUserIds = List.of(" u-a ", "u-a"); // 去空白后重复 + r.targetUserId = "u-z"; // 单值并入 + when(flowableClient.assist("t3", List.of("u-a", "u-z"), null)) + .thenReturn(Map.of("count", 2)); + + ResponseEntity> resp = controller.action("t3", r); + + assertThat(resp.getStatusCode().is2xxSuccessful()).isTrue(); + verify(flowableClient).assist("t3", List.of("u-a", "u-z"), null); + } + + @Test + void assist_withoutTargets_returns400() { + ResponseEntity> resp = controller.action("t4", req("assist")); + assertThat(resp.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST); + verifyNoInteractions(flowableClient); + } + + @Test + void circulated_withoutTargets_returns400() { + ResponseEntity> resp = controller.action("t5", req("circulated")); + assertThat(resp.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST); + verifyNoInteractions(flowableClient); + } +}