修审批界面无法审批:候选人式审批任务在待办全不可见(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:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -59,7 +59,9 @@ public class FlowableEngineConfig {
|
||||
|
||||
// BPMN 表达式引用的 3 个 handler bean,按原包名移植,cfg.setBeans 注册
|
||||
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("wfContextService", new WfContextService());
|
||||
cfg.setBeans(beans);
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user