修审批界面无法审批:候选人式审批任务在待办全不可见(dogfooding)

根因二连:
1) TodoAggregator candidateUser 传 null → 客户 BPMN 用 candidateUsers(候选人解析把当前用户
   设为候选用户、assignee 空)的任务全部漏查。改传 userId(我的待办=指派∪组候选∪用户候选)。
2) 保真层从 CHAR(36) 列取的短 user id(如 ADMIN)带空格补白,flowable taskCandidateUser 精确
   匹配不到 → 候选任务不可见。com.eip4 包装 TrimmingCandidateUsersHandler trim 候选 id(不改保真层)。
附:flowable-service start 命名流程未部署→回退默认审批(dev 无客户 BPMN 仍走通审批闭环)。
实证:真实通知提交审批→公司通知任务自动现身 admin 待办(UI 4 条,办理→同意可用)。TodoAggregatorTest 5 测。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-14 11:33:37 +08:00
parent b941236a02
commit 8165b01874
7 changed files with 87 additions and 12 deletions

View File

@@ -35,6 +35,9 @@ import io.swagger.v3.oas.annotations.tags.Tag;
@Tag(name = "工作流", description = "Flowable 待办/已办/发起/办理/挂起激活/委托 薄封装") @Tag(name = "工作流", description = "Flowable 待办/已办/发起/办理/挂起激活/委托 薄封装")
public class FlowController { public class FlowController {
/** 默认审批流程 key:命名流程定义未部署时回退到此,保「提交审批」闭环可走(dev 无客户 BPMN 时)。 */
private static final String DEFAULT_APPROVAL_KEY = "EIP4_DEFAULT_APPROVAL";
private final TaskService taskService; private final TaskService taskService;
private final RuntimeService runtimeService; private final RuntimeService runtimeService;
private final HistoryService historyService; private final HistoryService historyService;
@@ -197,7 +200,16 @@ public class FlowController {
if (req.processDefinitionId != null && !req.processDefinitionId.isBlank()) { if (req.processDefinitionId != null && !req.processDefinitionId.isBlank()) {
pi = runtimeService.startProcessInstanceById(req.processDefinitionId, req.businessKey, req.variables); pi = runtimeService.startProcessInstanceById(req.processDefinitionId, req.businessKey, req.variables);
} else if (req.processDefinitionKey != null && !req.processDefinitionKey.isBlank()) { } 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 { } else {
return ResponseEntity.badRequest().build(); return ResponseEntity.badRequest().build();
} }

View File

@@ -59,7 +59,9 @@ public class FlowableEngineConfig {
// BPMN 表达式引用的 3 个 handler bean,按原包名移植,cfg.setBeans 注册 // BPMN 表达式引用的 3 个 handler bean,按原包名移植,cfg.setBeans 注册
Map<Object, Object> beans = new HashMap<>(); Map<Object, Object> 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("multiInstanceUsersHandler", new MultiInstanceUsersHandler());
beans.put("wfContextService", new WfContextService()); beans.put("wfContextService", new WfContextService());
cfg.setBeans(beans); cfg.setBeans(beans);

View File

@@ -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。
*
* <p><b>根因</b>(dogfooding 实测):保真层 {@link CandidateUsersHandler} 从业务库 CHAR(36) 列
* 取用户 id,短 id(如管理员 {@code "ADMIN"})带尾随空格补白({@code "ADMIN" + 31 空格})。
* Flowable 把它原样写入 {@code ACT_RU_IDENTITYLINK.user_id_},而 {@code taskCandidateUser("ADMIN")}
* 是精确匹配 → 匹配不到补白值 → <b>候选人式审批任务在待办里全不可见,审批界面看似"无法审批"</b>。
*
* <p>本类在 com.eip4 层包装(不改保真层 com.dsasp),把候选 id trim 后交给 flowable。
* 真实用户 id 是 36 位 UUID(正好满列宽、无补白),不受影响;仅修正短 id 的补白。
*
* <p>经 {@code FlowableEngineConfig} 以 bean 名 {@code candidateUsersHandler} 注册,
* BPMN 表达式 {@code ${candidateUsersHandler.getCandidateUsers(...)}} 透明走到本类。
*/
public class TrimmingCandidateUsersHandler extends CandidateUsersHandler {
@Override
public List<String> getCandidateUsers(Object execution, String expression) {
List<String> 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());
}
}

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:flowable="http://flowable.org/bpmn"
targetNamespace="eip4">
<process id="EIP4_DEFAULT_APPROVAL" name="默认审批流程" isExecutable="true">
<startEvent id="start"/>
<sequenceFlow id="f1" sourceRef="start" targetRef="approve"/>
<userTask id="approve" name="审批" flowable:assignee="${WFINITIATORUSERID}"/>
<sequenceFlow id="f2" sourceRef="approve" targetRef="end"/>
<endEvent id="end"/>
</process>
</definitions>

View File

@@ -45,7 +45,10 @@ public class TodoAggregator {
* @param candidateGroups 候选组(JWT roles 驱动的候选组待办) * @param candidateGroups 候选组(JWT roles 驱动的候选组待办)
*/ */
public List<TodoItem> todo(String userId, List<String> candidateGroups, int firstResult, int maxResults) { public List<TodoItem> todo(String userId, List<String> candidateGroups, int firstResult, int maxResults) {
List<FlowTaskDto> tasks = flowableClient.todo(userId, candidateGroups, null, firstResult, maxResults); // candidateUser=userId:客户审批 BPMN 普遍用 candidateUsers(候选人解析把当前用户设为候选用户、
// assignee 留空)。原传 null 漏掉这一维度 → 候选人式审批任务在待办里全不可见 → 看似"无法审批"。
// 我的待办 = 指派给我的 ∪ 我(组)候选的 ∪ 我(用户)候选的(flowable-service todo OR 块承接)。
List<FlowTaskDto> tasks = flowableClient.todo(userId, candidateGroups, userId, firstResult, maxResults);
return aggregate(tasks); return aggregate(tasks);
} }

View File

@@ -4,7 +4,6 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import java.util.List; import java.util.List;
@@ -126,7 +125,7 @@ class PageTemplateMappingTest {
@Test @Test
void 聚合_有模板条目pageUrl正确填充() { 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"))); .thenReturn(List.of(task("T1", "BK-1")));
when(businessSummaryService.summarize("BK-1")) when(businessSummaryService.summarize("BK-1"))
.thenReturn(new BusinessSummaryService.Summary("PM_PAYMENTAPPLY", Map.of("TITLE", "付款单"))); .thenReturn(new BusinessSummaryService.Summary("PM_PAYMENTAPPLY", Map.of("TITLE", "付款单")));
@@ -144,7 +143,7 @@ class PageTemplateMappingTest {
@Test @Test
void 聚合_无模板映射_pageUrl为null且reason含表名() { 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"))); .thenReturn(List.of(task("T2", "BK-2")));
when(businessSummaryService.summarize("BK-2")) when(businessSummaryService.summarize("BK-2"))
.thenReturn(new BusinessSummaryService.Summary("OA_UNKNOWN_TABLE", Map.of())); .thenReturn(new BusinessSummaryService.Summary("OA_UNKNOWN_TABLE", Map.of()));
@@ -162,7 +161,7 @@ class PageTemplateMappingTest {
@Test @Test
void 聚合_businessTable为null_pageUrl为null且reason含提示() { 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"))); .thenReturn(List.of(task("T3", "BK-MISSING")));
when(businessSummaryService.summarize("BK-MISSING")) when(businessSummaryService.summarize("BK-MISSING"))
.thenReturn(BusinessSummaryService.Summary.EMPTY); .thenReturn(BusinessSummaryService.Summary.EMPTY);
@@ -179,7 +178,7 @@ class PageTemplateMappingTest {
@Test @Test
void 聚合_有模板与无模板条目共存_优雅降级() { 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"))); .thenReturn(List.of(task("T4", "BK-4"), task("T5", "BK-5")));
when(businessSummaryService.summarize("BK-4")) when(businessSummaryService.summarize("BK-4"))
.thenReturn(new BusinessSummaryService.Summary("PM_PAYMENTAPPLY", Map.of("TITLE", "付款单"))); .thenReturn(new BusinessSummaryService.Summary("PM_PAYMENTAPPLY", Map.of("TITLE", "付款单")));

View File

@@ -4,7 +4,6 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import java.util.List; import java.util.List;
@@ -51,7 +50,7 @@ class TodoAggregatorTest {
@Test @Test
void 待办拼接业务摘要_businessKey连到业务表标题字段() { 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"))); .thenReturn(List.of(task("T1", "BK-1")));
when(businessSummaryService.summarize("BK-1")) when(businessSummaryService.summarize("BK-1"))
.thenReturn(new BusinessSummaryService.Summary("ORDER_ENTITY", Map.of("TITLE", "某交底单"))); .thenReturn(new BusinessSummaryService.Summary("ORDER_ENTITY", Map.of("TITLE", "某交底单")));
@@ -69,7 +68,7 @@ class TodoAggregatorTest {
@Test @Test
void 待办摘要拼不到_优雅降级为仅流程字段() { 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"))); .thenReturn(List.of(task("T2", "BK-MISSING")));
when(businessSummaryService.summarize("BK-MISSING")) when(businessSummaryService.summarize("BK-MISSING"))
.thenReturn(BusinessSummaryService.Summary.EMPTY); .thenReturn(BusinessSummaryService.Summary.EMPTY);
@@ -99,9 +98,20 @@ class TodoAggregatorTest {
assertThat(items.get(0).businessTable).isEqualTo("ORDER_ENTITY"); assertThat(items.get(0).businessTable).isEqualTo("ORDER_ENTITY");
} }
@Test
void 待办查询_候选用户维度传当前userId_候选人式审批任务可见() {
// 根因(dogfooding):客户审批 BPMN 用 candidateUsers(候选人解析器把当前用户设为候选用户,
// assignee 为空),原实现 candidateUser 传 null → 候选人式任务全不可见 → 审批界面没任务=无法审批。
org.mockito.ArgumentCaptor<String> 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 @Test
void 空待办列表返回空聚合() { 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(); assertThat(aggregator.todo("U1", List.of(), 0, 50)).isEmpty();
} }
} }