feat(approval): 会签进度("已会签 N/M") — approval-context 多实例计数
- ApprovalContextDto(flowable + gateway)加 cosign/cosignTotal/cosignCompleted - FlowController.approvalContext: fillCosign 沿执行树向上找带 nrOfInstances 的 多实例根执行,读 nrOfInstances/nrOfCompletedInstances 回填 - gateway ApprovalController.approvalMeta 透传 cosign 字段 - 单测 FlowControllerTest 会签进度回填(22 绿);live(8089)实证 cosign:true 0/2 注:gateway 端 cosign 展示当前被 platform-report 引入的上古 xerces-eip3.jar(2004) 击穿 WfTemplate XML 解析所阻(AbstractMethodError on DocumentBuilderFactory.setFeature, 影响全部 approve/reject 按钮解析,非本改动引入,需在 report 模块侧隔离/排除该 xerces)。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -26,4 +26,10 @@ public class ApprovalContextDto {
|
||||
public boolean ended;
|
||||
/** 任务/实例是否挂起(挂起不可办理)。 */
|
||||
public boolean suspended;
|
||||
/** 是否会签(BPMN 多实例)任务:true 时下面三个计数有效,前端显「已会签 N/M」。 */
|
||||
public boolean cosign;
|
||||
/** 会签总人数(多实例 nrOfInstances)。 */
|
||||
public int cosignTotal;
|
||||
/** 会签已完成人数(多实例 nrOfCompletedInstances)。 */
|
||||
public int cosignCompleted;
|
||||
}
|
||||
|
||||
@@ -576,6 +576,31 @@ public class FlowController {
|
||||
return s == null || s.isBlank();
|
||||
}
|
||||
|
||||
/**
|
||||
* 会签(BPMN 多实例)进度:沿执行树从任务执行向上找带 {@code nrOfInstances} 局部变量的多实例根执行,
|
||||
* 读总人数/已完成数填入 dto(前端显「已会签 N/M」)。非多实例任务找不到 → 不改 dto(cosign=false)。
|
||||
*/
|
||||
private void fillCosign(ApprovalContextDto dto, String executionId) {
|
||||
String execId = executionId;
|
||||
for (int depth = 0; depth < 12 && !isBlank(execId); depth++) {
|
||||
Map<String, Object> locals;
|
||||
try {
|
||||
locals = runtimeService.getVariablesLocal(execId);
|
||||
} catch (RuntimeException e) {
|
||||
return;
|
||||
}
|
||||
if (locals != null && locals.get("nrOfInstances") instanceof Number total) {
|
||||
dto.cosign = true;
|
||||
dto.cosignTotal = total.intValue();
|
||||
dto.cosignCompleted = locals.get("nrOfCompletedInstances") instanceof Number done
|
||||
? done.intValue() : 0;
|
||||
return;
|
||||
}
|
||||
var exec = runtimeService.createExecutionQuery().executionId(execId).singleResult();
|
||||
execId = exec != null ? exec.getParentId() : null;
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/tasks/{taskId}/approval-context")
|
||||
@Operation(summary = "任务审批上下文",
|
||||
description = "聚合返回 WfTemplate 驱动审批界面所需事实:formKey(=view_wftemplate_id,经 FormKeyResolver 历史回补)、"
|
||||
@@ -592,6 +617,7 @@ public class FlowController {
|
||||
dto.processDefinitionId = t.getProcessDefinitionId();
|
||||
dto.taskDefinitionKey = t.getTaskDefinitionKey();
|
||||
dto.suspended = t.isSuspended();
|
||||
fillCosign(dto, t.getExecutionId());
|
||||
|
||||
String formKeyRaw = t.getFormKey();
|
||||
String procDefId = t.getProcessDefinitionId();
|
||||
|
||||
@@ -443,6 +443,40 @@ class FlowControllerTest {
|
||||
.andExpect(jsonPath("$.processInstanceId").value("pi-1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void 会签任务approvalContext回填会签进度() throws Exception {
|
||||
// 会签(多实例)任务:approval-context 沿执行树向上找带 nrOfInstances 的多实例根执行,回填进度
|
||||
when(taskService.createTaskQuery()).thenReturn(taskQuery);
|
||||
when(taskQuery.taskId("mi-1")).thenReturn(taskQuery);
|
||||
Task t = org.mockito.Mockito.mock(Task.class);
|
||||
when(t.getProcessInstanceId()).thenReturn("pi-mi");
|
||||
when(t.getExecutionId()).thenReturn("exec-leaf");
|
||||
when(taskQuery.singleResult()).thenReturn(t);
|
||||
// fillCosign:叶执行无 nrOfInstances → 向上到根执行命中
|
||||
when(runtimeService.getVariablesLocal("exec-leaf")).thenReturn(java.util.Map.of());
|
||||
when(runtimeService.getVariablesLocal("exec-root"))
|
||||
.thenReturn(java.util.Map.of("nrOfInstances", 3, "nrOfCompletedInstances", 1));
|
||||
var execQuery = org.mockito.Mockito.mock(org.flowable.engine.runtime.ExecutionQuery.class);
|
||||
when(runtimeService.createExecutionQuery()).thenReturn(execQuery);
|
||||
when(execQuery.executionId("exec-leaf")).thenReturn(execQuery);
|
||||
org.flowable.engine.runtime.Execution leaf = org.mockito.Mockito.mock(org.flowable.engine.runtime.Execution.class);
|
||||
when(leaf.getParentId()).thenReturn("exec-root");
|
||||
when(execQuery.singleResult()).thenReturn(leaf);
|
||||
// 业务实例查不到(聚焦会签字段),走 PI null 分支
|
||||
when(runtimeService.createProcessInstanceQuery()).thenReturn(processInstanceQuery);
|
||||
when(processInstanceQuery.processInstanceId("pi-mi")).thenReturn(processInstanceQuery);
|
||||
when(processInstanceQuery.singleResult()).thenReturn(null);
|
||||
when(historyService.createHistoricProcessInstanceQuery()).thenReturn(historicProcessInstanceQuery);
|
||||
when(historicProcessInstanceQuery.processInstanceId("pi-mi")).thenReturn(historicProcessInstanceQuery);
|
||||
when(historicProcessInstanceQuery.singleResult()).thenReturn(null);
|
||||
|
||||
mvc.perform(get("/api/flow/tasks/mi-1/approval-context"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.cosign").value(true))
|
||||
.andExpect(jsonPath("$.cosignTotal").value(3))
|
||||
.andExpect(jsonPath("$.cosignCompleted").value(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void 协办超过上限返回400() throws Exception {
|
||||
StringBuilder ids = new StringBuilder("[");
|
||||
|
||||
@@ -19,4 +19,10 @@ public class ApprovalContextDto {
|
||||
public String businessKey;
|
||||
public boolean ended;
|
||||
public boolean suspended;
|
||||
/** 是否会签(BPMN 多实例)任务。 */
|
||||
public boolean cosign;
|
||||
/** 会签总人数。 */
|
||||
public int cosignTotal;
|
||||
/** 会签已完成人数。 */
|
||||
public int cosignCompleted;
|
||||
}
|
||||
|
||||
@@ -117,6 +117,10 @@ public class ApprovalController {
|
||||
resp.put("processInstanceId", ctx == null ? null : ctx.processInstanceId);
|
||||
resp.put("ended", ctx != null && ctx.ended);
|
||||
resp.put("suspended", ctx != null && ctx.suspended);
|
||||
// 会签(多实例)进度:前端显「已会签 N/M」
|
||||
resp.put("cosign", ctx != null && ctx.cosign);
|
||||
resp.put("cosignTotal", ctx == null ? 0 : ctx.cosignTotal);
|
||||
resp.put("cosignCompleted", ctx == null ? 0 : ctx.cosignCompleted);
|
||||
|
||||
// 业务表单页面:生效表单模板(任务/开始节点)的 pageid 命中 sys_page_schema 优先——即老审批页用的同一张页面;
|
||||
// 都没有再退该业务表标准 editform。前端据此渲染只读业务单据。
|
||||
|
||||
Reference in New Issue
Block a user