!1280 fix: 解决审批节点表单无可编辑字段时,variables流程变量值为空,流程节点流转异常问题

Merge pull request !1280 from SamllNorth_Lee/feature/bpm
This commit is contained in:
芋道源码 2025-03-15 08:36:14 +00:00 committed by Gitee
commit 4e2ebe0c66
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 32 additions and 31 deletions

View File

@ -21,6 +21,7 @@ import org.flowable.bpmn.converter.BpmnXMLConverter;
import org.flowable.bpmn.model.Process;
import org.flowable.bpmn.model.*;
import org.flowable.common.engine.api.FlowableException;
import org.flowable.common.engine.impl.javax.el.PropertyNotFoundException;
import org.flowable.common.engine.impl.util.io.BytesStreamSource;
import org.flowable.engine.impl.el.FixedValue;
@ -907,17 +908,9 @@ public class BpmnModelUtils {
* @return 符合条件的路径
*/
private static SequenceFlow findMatchSequenceFlowByExclusiveGateway(Gateway gateway, Map<String, Object> variables) {
// TODO 表单无可编辑字段时variables为空流程走向会出现问题比如流程审批过程中无需要修改的字段值
// TODO @小北是不是还是保证编辑的时候如果计算下一个节点还是 variables 是完整体而不是空的可以微信讨论下
SequenceFlow matchSequenceFlow;
if (CollUtil.isNotEmpty(variables)) {
matchSequenceFlow = CollUtil.findOne(gateway.getOutgoingFlows(),
SequenceFlow matchSequenceFlow = CollUtil.findOne(gateway.getOutgoingFlows(),
flow -> ObjUtil.notEqual(gateway.getDefaultFlow(), flow.getId())
&& (evalConditionExpress(variables, flow.getConditionExpression())));
} else {
matchSequenceFlow = CollUtil.findOne(gateway.getOutgoingFlows(),
flow -> ObjUtil.notEqual(gateway.getDefaultFlow(), flow.getId()));
}
if (matchSequenceFlow == null) {
matchSequenceFlow = CollUtil.findOne(gateway.getOutgoingFlows(),
flow -> ObjUtil.equal(gateway.getDefaultFlow(), flow.getId()));
@ -1014,6 +1007,11 @@ public class BpmnModelUtils {
Object result = FlowableUtils.getExpressionValue(variables, expression);
return Boolean.TRUE.equals(result);
} catch (FlowableException ex) {
// TODO @芋艿 临时方案解决流程变量中不包含条件表达式时报错问题如果expression 的计算可能不依赖于 variablesgetExpressionValue方法应该需要重构
if (ex.getCause() instanceof PropertyNotFoundException){
log.error("[evalConditionExpress][条件表达式({}) 变量({}) 解析报错]", expression, variables, ex);
return Boolean.FALSE;
}
// 为什么使用 info 日志原因是expression 如果从 variables 取不到值会报错实际这种情况下可以忽略
log.info("[evalConditionExpress][条件表达式({}) 变量({}) 解析报错]", expression, variables, ex);
return Boolean.FALSE;

View File

@ -248,16 +248,15 @@ public class BpmModelServiceImpl implements BpmModelService {
throw exception(MODEL_DEPLOY_FAIL_BPMN_USER_TASK_NAME_NOT_EXISTS, userTask.getId());
}
});
// TODO @小北是不是可以 UserTask firUserTask = CollUtil.get(userTasks, BpmModelTypeEnum.BPMN.getType().equals(type) ? 0 : 1)然后最好判空极端情况下 usertask 哈哈哈哈
// 3. 校验第一个用户任务节点的规则类型是否为审批人自选
Map<Integer, UserTask> userTaskMap = new HashMap<>();
// BPMN 设计器校验第一个用户任务节点
userTaskMap.put(BpmModelTypeEnum.BPMN.getType(), userTasks.get(0));
// SIMPLE 设计器第一个节点固定为发起人所以校验第二个用户任务节点
userTaskMap.put(BpmModelTypeEnum.SIMPLE.getType(), userTasks.get(1));
Integer candidateStrategy = parseCandidateStrategy(userTaskMap.get(type));
// 3. 校验第一个用户任务节点的规则类型是否为审批人自选BPMN 设计器校验第一个用户任务节点SIMPLE 设计器第一个节点固定为发起人所以校验第二个用户任务节点
UserTask firUserTask = CollUtil.get(userTasks, BpmModelTypeEnum.BPMN.getType().equals(type) ? 0 : 1);
// 4. 极端情况下无多个用户任务节点比如发起人-抄送节点
if (firUserTask == null){
return;
}
Integer candidateStrategy = parseCandidateStrategy(firUserTask);
if (Objects.equals(candidateStrategy, BpmTaskCandidateStrategyEnum.APPROVE_USER_SELECT.getStrategy())) {
throw exception(MODEL_DEPLOY_FAIL_FIRST_USER_TASK_CANDIDATE_STRATEGY_ERROR, userTaskMap.get(type).getName());
throw exception(MODEL_DEPLOY_FAIL_FIRST_USER_TASK_CANDIDATE_STRATEGY_ERROR, firUserTask.getName());
}
}

View File

@ -557,11 +557,24 @@ public class BpmTaskServiceImpl implements BpmTaskService {
// 2.2 添加评论
taskService.addComment(task.getId(), task.getProcessInstanceId(), BpmCommentTypeEnum.APPROVE.getType(),
BpmCommentTypeEnum.APPROVE.formatComment(reqVO.getReason()));
// 2.3 校验并处理 APPROVE_USER_SELECT 当前审批人选择下一节点审批人的逻辑
Map<String, Object> variables = validateAndSetNextAssignees(task.getTaskDefinitionKey(), reqVO.getVariables(),
// 如果流程变量前端传空需要从历史实例中获取原因前端表单如果在当前节点无可编辑的字段时variables一定会为空
// 场景一A节点发起B节点表单无可编辑字段审批通过时C节点需要流程变量获取下一个执行节点但因为B节点无可编辑的字段variables为空流程可能出现问题
// 场景二A节点发起B节点只有某一个字段可编辑比如day但C节点需要多个节点比如workday在发起时填写因为B节点只有day的编辑权限在审批后variables会缺少work的值
// 3.1 设置流程变量
Map<String, Object> processVariables = new HashMap<>();
// 3.2 获取历史中流程变量
if (CollUtil.isNotEmpty(instance.getProcessVariables())) {
processVariables.putAll(instance.getProcessVariables());
}
// 3.3 合并前端传递的流程变量以前端为准
if (CollUtil.isNotEmpty(reqVO.getVariables())) {
processVariables.putAll(reqVO.getVariables());
}
// 3.4 校验并处理 APPROVE_USER_SELECT 当前审批人选择下一节点审批人的逻辑
Map<String, Object> variables = validateAndSetNextAssignees(task.getTaskDefinitionKey(), processVariables,
bpmnModel, reqVO.getNextAssignees(), instance);
runtimeService.setVariables(task.getProcessInstanceId(), variables);
// 2.4 调用 BPM complete 去完成任务
// 4 调用 BPM complete 去完成任务
taskService.complete(task.getId(), variables, true);
// 加签专属处理加签任务
@ -600,9 +613,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
}
processVariables = FlowableUtils.getStartUserSelectAssignees(processInstance.getProcessVariables());
// 特殊如果当前节点已经存在审批人则不允许覆盖
// TODO @小北不用改通过 if return让逻辑更简洁一点虽然会多判断一次 processVariables但是 if else 层级更少
if (processVariables != null
&& CollUtil.isNotEmpty(processVariables.get(nextFlowNode.getId()))) {
if (processVariables != null && CollUtil.isNotEmpty(processVariables.get(nextFlowNode.getId()))) {
continue;
}
// 设置 PROCESS_INSTANCE_VARIABLE_START_USER_SELECT_ASSIGNEES
@ -622,13 +633,6 @@ public class BpmTaskServiceImpl implements BpmTaskService {
processVariables = FlowableUtils.getApproveUserSelectAssignees(processInstance.getProcessVariables());
if (processVariables == null) {
processVariables = new HashMap<>();
} else {
List<Long> approveUserSelectAssignee = processVariables.get(nextFlowNode.getId());
// 特殊如果当前节点已经存在审批人则不允许覆盖
// TODO @小北这种应该可以覆盖呢
if (CollUtil.isNotEmpty(approveUserSelectAssignee)) {
continue;
}
}
// 设置 PROCESS_INSTANCE_VARIABLE_APPROVE_USER_SELECT_ASSIGNEES
processVariables.put(nextFlowNode.getId(), assignees);