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 42600fc..538d174 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 @@ -35,6 +35,9 @@ import io.swagger.v3.oas.annotations.tags.Tag; @Tag(name = "工作流", description = "Flowable 待办/已办/发起/办理/挂起激活/委托 薄封装") public class FlowController { + /** 默认审批流程 key:命名流程定义未部署时回退到此,保「提交审批」闭环可走(dev 无客户 BPMN 时)。 */ + private static final String DEFAULT_APPROVAL_KEY = "EIP4_DEFAULT_APPROVAL"; + private final TaskService taskService; private final RuntimeService runtimeService; private final HistoryService historyService; @@ -197,7 +200,16 @@ public class FlowController { if (req.processDefinitionId != null && !req.processDefinitionId.isBlank()) { pi = runtimeService.startProcessInstanceById(req.processDefinitionId, req.businessKey, req.variables); } else if (req.processDefinitionKey != null && !req.processDefinitionKey.isBlank()) { - pi = runtimeService.startProcessInstanceByKey(req.processDefinitionKey, req.businessKey, req.variables); + try { + pi = runtimeService.startProcessInstanceByKey(req.processDefinitionKey, req.businessKey, req.variables); + } catch (org.flowable.common.engine.api.FlowableObjectNotFoundException nf) { + // 命名流程定义未部署(dev 无客户审批 BPMN)→ 回退默认审批流程, + // 让「提交审批」仍生成可办理任务、走通审批闭环;生产部署客户 BPMN 后不触发。 + org.slf4j.LoggerFactory.getLogger(FlowController.class).warn( + "[起流回退] 流程定义 key={} 未部署,回退默认审批 {}(部署对应 BPMN 后此回退消失)", + req.processDefinitionKey, DEFAULT_APPROVAL_KEY); + pi = runtimeService.startProcessInstanceByKey(DEFAULT_APPROVAL_KEY, req.businessKey, req.variables); + } } else { return ResponseEntity.badRequest().build(); } diff --git a/flowable-service/src/main/java/com/eip4/flowservice/config/FlowableEngineConfig.java b/flowable-service/src/main/java/com/eip4/flowservice/config/FlowableEngineConfig.java index 0174387..4523d3e 100644 --- a/flowable-service/src/main/java/com/eip4/flowservice/config/FlowableEngineConfig.java +++ b/flowable-service/src/main/java/com/eip4/flowservice/config/FlowableEngineConfig.java @@ -59,7 +59,9 @@ public class FlowableEngineConfig { // BPMN 表达式引用的 3 个 handler bean,按原包名移植,cfg.setBeans 注册 Map beans = new HashMap<>(); - beans.put("candidateUsersHandler", new CandidateUsersHandler()); + // 用 com.eip4 包装类替换:trim 保真层从 CHAR 列取的候选 user id 的尾随空格补白, + // 否则 flowable taskCandidateUser 精确匹配不到补白 id → 候选人式审批任务在待办全不可见。 + beans.put("candidateUsersHandler", new com.eip4.flowservice.wf.TrimmingCandidateUsersHandler()); beans.put("multiInstanceUsersHandler", new MultiInstanceUsersHandler()); beans.put("wfContextService", new WfContextService()); cfg.setBeans(beans); diff --git a/flowable-service/src/main/java/com/eip4/flowservice/wf/TrimmingCandidateUsersHandler.java b/flowable-service/src/main/java/com/eip4/flowservice/wf/TrimmingCandidateUsersHandler.java new file mode 100644 index 0000000..0bbafee --- /dev/null +++ b/flowable-service/src/main/java/com/eip4/flowservice/wf/TrimmingCandidateUsersHandler.java @@ -0,0 +1,37 @@ +package com.eip4.flowservice.wf; + +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +import com.dsasp.server.wf.user.assignee.CandidateUsersHandler; + +/** + * 候选人解析器包装:规范化(trim)保真层返回的候选 user id。 + * + *

根因(dogfooding 实测):保真层 {@link CandidateUsersHandler} 从业务库 CHAR(36) 列 + * 取用户 id,短 id(如管理员 {@code "ADMIN"})带尾随空格补白({@code "ADMIN" + 31 空格})。 + * Flowable 把它原样写入 {@code ACT_RU_IDENTITYLINK.user_id_},而 {@code taskCandidateUser("ADMIN")} + * 是精确匹配 → 匹配不到补白值 → 候选人式审批任务在待办里全不可见,审批界面看似"无法审批"。 + * + *

本类在 com.eip4 层包装(不改保真层 com.dsasp),把候选 id trim 后交给 flowable。 + * 真实用户 id 是 36 位 UUID(正好满列宽、无补白),不受影响;仅修正短 id 的补白。 + * + *

经 {@code FlowableEngineConfig} 以 bean 名 {@code candidateUsersHandler} 注册, + * BPMN 表达式 {@code ${candidateUsersHandler.getCandidateUsers(...)}} 透明走到本类。 + */ +public class TrimmingCandidateUsersHandler extends CandidateUsersHandler { + + @Override + public List getCandidateUsers(Object execution, String expression) { + List raw = super.getCandidateUsers(execution, expression); + if (raw == null) { + return null; + } + return raw.stream() + .filter(Objects::nonNull) + .map(String::trim) + .filter(s -> !s.isEmpty()) + .collect(Collectors.toList()); + } +} diff --git a/flowable-service/src/main/resources/processes-samples/eip4_default_approval.bpmn20.xml b/flowable-service/src/main/resources/processes-samples/eip4_default_approval.bpmn20.xml new file mode 100644 index 0000000..10088e3 --- /dev/null +++ b/flowable-service/src/main/resources/processes-samples/eip4_default_approval.bpmn20.xml @@ -0,0 +1,12 @@ + + + + + + + + + + diff --git a/platform-flow-gateway/src/main/java/com/eip4/platform/flowgateway/aggregate/TodoAggregator.java b/platform-flow-gateway/src/main/java/com/eip4/platform/flowgateway/aggregate/TodoAggregator.java index f6989fa..0516176 100644 --- a/platform-flow-gateway/src/main/java/com/eip4/platform/flowgateway/aggregate/TodoAggregator.java +++ b/platform-flow-gateway/src/main/java/com/eip4/platform/flowgateway/aggregate/TodoAggregator.java @@ -45,7 +45,10 @@ public class TodoAggregator { * @param candidateGroups 候选组(JWT roles 驱动的候选组待办) */ public List todo(String userId, List candidateGroups, int firstResult, int maxResults) { - List tasks = flowableClient.todo(userId, candidateGroups, null, firstResult, maxResults); + // candidateUser=userId:客户审批 BPMN 普遍用 candidateUsers(候选人解析把当前用户设为候选用户、 + // assignee 留空)。原传 null 漏掉这一维度 → 候选人式审批任务在待办里全不可见 → 看似"无法审批"。 + // 我的待办 = 指派给我的 ∪ 我(组)候选的 ∪ 我(用户)候选的(flowable-service todo OR 块承接)。 + List tasks = flowableClient.todo(userId, candidateGroups, userId, firstResult, maxResults); return aggregate(tasks); } diff --git a/platform-flow-gateway/src/test/java/com/eip4/platform/flowgateway/PageTemplateMappingTest.java b/platform-flow-gateway/src/test/java/com/eip4/platform/flowgateway/PageTemplateMappingTest.java index 02cb42d..55329a1 100644 --- a/platform-flow-gateway/src/test/java/com/eip4/platform/flowgateway/PageTemplateMappingTest.java +++ b/platform-flow-gateway/src/test/java/com/eip4/platform/flowgateway/PageTemplateMappingTest.java @@ -4,7 +4,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Mockito.when; import java.util.List; @@ -126,7 +125,7 @@ class PageTemplateMappingTest { @Test void 聚合_有模板条目pageUrl正确填充() { - when(flowableClient.todo(eq("U1"), any(), isNull(), anyInt(), anyInt())) + when(flowableClient.todo(eq("U1"), any(), eq("U1"), anyInt(), anyInt())) .thenReturn(List.of(task("T1", "BK-1"))); when(businessSummaryService.summarize("BK-1")) .thenReturn(new BusinessSummaryService.Summary("PM_PAYMENTAPPLY", Map.of("TITLE", "付款单"))); @@ -144,7 +143,7 @@ class PageTemplateMappingTest { @Test void 聚合_无模板映射_pageUrl为null且reason含表名() { - when(flowableClient.todo(eq("U1"), any(), isNull(), anyInt(), anyInt())) + when(flowableClient.todo(eq("U1"), any(), eq("U1"), anyInt(), anyInt())) .thenReturn(List.of(task("T2", "BK-2"))); when(businessSummaryService.summarize("BK-2")) .thenReturn(new BusinessSummaryService.Summary("OA_UNKNOWN_TABLE", Map.of())); @@ -162,7 +161,7 @@ class PageTemplateMappingTest { @Test void 聚合_businessTable为null_pageUrl为null且reason含提示() { - when(flowableClient.todo(eq("U1"), any(), isNull(), anyInt(), anyInt())) + when(flowableClient.todo(eq("U1"), any(), eq("U1"), anyInt(), anyInt())) .thenReturn(List.of(task("T3", "BK-MISSING"))); when(businessSummaryService.summarize("BK-MISSING")) .thenReturn(BusinessSummaryService.Summary.EMPTY); @@ -179,7 +178,7 @@ class PageTemplateMappingTest { @Test void 聚合_有模板与无模板条目共存_优雅降级() { - when(flowableClient.todo(eq("U1"), any(), isNull(), anyInt(), anyInt())) + when(flowableClient.todo(eq("U1"), any(), eq("U1"), anyInt(), anyInt())) .thenReturn(List.of(task("T4", "BK-4"), task("T5", "BK-5"))); when(businessSummaryService.summarize("BK-4")) .thenReturn(new BusinessSummaryService.Summary("PM_PAYMENTAPPLY", Map.of("TITLE", "付款单"))); diff --git a/platform-flow-gateway/src/test/java/com/eip4/platform/flowgateway/TodoAggregatorTest.java b/platform-flow-gateway/src/test/java/com/eip4/platform/flowgateway/TodoAggregatorTest.java index 90325e8..b0d8270 100644 --- a/platform-flow-gateway/src/test/java/com/eip4/platform/flowgateway/TodoAggregatorTest.java +++ b/platform-flow-gateway/src/test/java/com/eip4/platform/flowgateway/TodoAggregatorTest.java @@ -4,7 +4,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Mockito.when; import java.util.List; @@ -51,7 +50,7 @@ class TodoAggregatorTest { @Test void 待办拼接业务摘要_businessKey连到业务表标题字段() { - when(flowableClient.todo(eq("U1"), any(), isNull(), anyInt(), anyInt())) + when(flowableClient.todo(eq("U1"), any(), eq("U1"), anyInt(), anyInt())) .thenReturn(List.of(task("T1", "BK-1"))); when(businessSummaryService.summarize("BK-1")) .thenReturn(new BusinessSummaryService.Summary("ORDER_ENTITY", Map.of("TITLE", "某交底单"))); @@ -69,7 +68,7 @@ class TodoAggregatorTest { @Test void 待办摘要拼不到_优雅降级为仅流程字段() { - when(flowableClient.todo(eq("U1"), any(), isNull(), anyInt(), anyInt())) + when(flowableClient.todo(eq("U1"), any(), eq("U1"), anyInt(), anyInt())) .thenReturn(List.of(task("T2", "BK-MISSING"))); when(businessSummaryService.summarize("BK-MISSING")) .thenReturn(BusinessSummaryService.Summary.EMPTY); @@ -99,9 +98,20 @@ class TodoAggregatorTest { assertThat(items.get(0).businessTable).isEqualTo("ORDER_ENTITY"); } + @Test + void 待办查询_候选用户维度传当前userId_候选人式审批任务可见() { + // 根因(dogfooding):客户审批 BPMN 用 candidateUsers(候选人解析器把当前用户设为候选用户, + // assignee 为空),原实现 candidateUser 传 null → 候选人式任务全不可见 → 审批界面没任务=无法审批。 + org.mockito.ArgumentCaptor candUser = org.mockito.ArgumentCaptor.forClass(String.class); + when(flowableClient.todo(eq("U1"), any(), candUser.capture(), anyInt(), anyInt())) + .thenReturn(List.of()); + aggregator.todo("U1", List.of("ROLE_A"), 0, 50); + assertThat(candUser.getValue()).isEqualTo("U1"); + } + @Test void 空待办列表返回空聚合() { - when(flowableClient.todo(any(), any(), isNull(), anyInt(), anyInt())).thenReturn(List.of()); + when(flowableClient.todo(any(), any(), any(), anyInt(), anyInt())).thenReturn(List.of()); assertThat(aggregator.todo("U1", List.of(), 0, 50)).isEmpty(); } }