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

This commit is contained in:
smallNorthLee 2025-03-12 22:42:32 +08:00
parent 42eb89b243
commit 23844b930c
2 changed files with 13 additions and 11 deletions

View File

@ -907,16 +907,9 @@ public class BpmnModelUtils {
* @return 符合条件的路径
*/
private static SequenceFlow findMatchSequenceFlowByExclusiveGateway(Gateway gateway, Map<String, Object> 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()));

View File

@ -558,12 +558,21 @@ public class BpmTaskServiceImpl implements BpmTaskService {
taskService.addComment(task.getId(), task.getProcessInstanceId(), BpmCommentTypeEnum.APPROVE.getType(),
BpmCommentTypeEnum.APPROVE.formatComment(reqVO.getReason()));
// 2.3 调用 BPM complete 去完成任务
// 如果流程变量前端传空需要从历史实例中获取原因前端表单如果在当前节点无可编辑的字段时variables一定会为空
// 场景一A节点发起B节点表单无可编辑字段审批通过时C节点需要流程变量获取下一个执行节点但因为B节点无可编辑的字段variables为空流程可能出现问题
// 场景二A节点发起B节点只有某一个字段可编辑比如day但C节点需要多个节点比如workday在发起时填写因为B节点只有day的编辑权限在审批后variables会缺少work的值
// 历史中的变量值
Map<String, Object> variables = new HashMap<>(instance.getProcessVariables());
// 如果变量值不为空则覆盖历史变量
if (CollUtil.isNotEmpty(reqVO.getVariables())) {
variables.putAll(reqVO.getVariables());
}
// 校验并处理 APPROVE_USER_SELECT 当前审批人选择下一节点审批人的逻辑
Map<String, Object> variables = validateAndSetNextAssignees(task.getTaskDefinitionKey(), reqVO.getVariables(),
Map<String, Object> resVariables = validateAndSetNextAssignees(task.getTaskDefinitionKey(), variables,
bpmnModel, reqVO.getNextAssignees(), instance);
// 完成任务
runtimeService.setVariables(task.getProcessInstanceId(), variables);
taskService.complete(task.getId(), variables, true);
runtimeService.setVariables(task.getProcessInstanceId(), resVariables);
taskService.complete(task.getId(), resVariables, true);
// 加签专属处理加签任务
handleParentTaskIfSign(task.getParentTaskId());