【代码评审】BPM:fix: 解决审批节点表单无可编辑字段时,variables流程变量值为空,流程节点流转异常问题
This commit is contained in:
parent
4e2ebe0c66
commit
0ab54a9fe4
|
@ -191,12 +191,12 @@ public class BpmProcessDefinitionInfoDO extends BaseDO {
|
||||||
/**
|
/**
|
||||||
* 流程前置通知设置
|
* 流程前置通知设置
|
||||||
*/
|
*/
|
||||||
@TableField(typeHandler = JacksonTypeHandler.class, exist = false) // TODO @芋艿:临时注释 exist,因为要合并 master-jdk17
|
@TableField(typeHandler = JacksonTypeHandler.class)
|
||||||
private BpmModelMetaInfoVO.HttpRequestSetting processBeforeTriggerSetting;
|
private BpmModelMetaInfoVO.HttpRequestSetting processBeforeTriggerSetting;
|
||||||
/**
|
/**
|
||||||
* 流程后置通知设置
|
* 流程后置通知设置
|
||||||
*/
|
*/
|
||||||
@TableField(typeHandler = JacksonTypeHandler.class, exist = false) // TODO @芋艿:临时注释 exist,因为要合并 master-jdk17
|
@TableField(typeHandler = JacksonTypeHandler.class)
|
||||||
private BpmModelMetaInfoVO.HttpRequestSetting processAfterTriggerSetting;
|
private BpmModelMetaInfoVO.HttpRequestSetting processAfterTriggerSetting;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,6 @@ import org.flowable.bpmn.converter.BpmnXMLConverter;
|
||||||
import org.flowable.bpmn.model.Process;
|
import org.flowable.bpmn.model.Process;
|
||||||
import org.flowable.bpmn.model.*;
|
import org.flowable.bpmn.model.*;
|
||||||
import org.flowable.common.engine.api.FlowableException;
|
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.common.engine.impl.util.io.BytesStreamSource;
|
||||||
import org.flowable.engine.impl.el.FixedValue;
|
import org.flowable.engine.impl.el.FixedValue;
|
||||||
|
|
||||||
|
@ -1007,11 +1006,6 @@ public class BpmnModelUtils {
|
||||||
Object result = FlowableUtils.getExpressionValue(variables, expression);
|
Object result = FlowableUtils.getExpressionValue(variables, expression);
|
||||||
return Boolean.TRUE.equals(result);
|
return Boolean.TRUE.equals(result);
|
||||||
} catch (FlowableException ex) {
|
} catch (FlowableException ex) {
|
||||||
// TODO @芋艿 临时方案解决流程变量中不包含条件表达式时报错问题,如果expression 的计算,可能不依赖于 variables,getExpressionValue方法应该需要重构
|
|
||||||
if (ex.getCause() instanceof PropertyNotFoundException){
|
|
||||||
log.error("[evalConditionExpress][条件表达式({}) 变量({}) 解析报错]", expression, variables, ex);
|
|
||||||
return Boolean.FALSE;
|
|
||||||
}
|
|
||||||
// 为什么使用 info 日志?原因是,expression 如果从 variables 取不到值,会报错。实际这种情况下,可以忽略
|
// 为什么使用 info 日志?原因是,expression 如果从 variables 取不到值,会报错。实际这种情况下,可以忽略
|
||||||
log.info("[evalConditionExpress][条件表达式({}) 变量({}) 解析报错]", expression, variables, ex);
|
log.info("[evalConditionExpress][条件表达式({}) 变量({}) 解析报错]", expression, variables, ex);
|
||||||
return Boolean.FALSE;
|
return Boolean.FALSE;
|
||||||
|
|
|
@ -250,8 +250,7 @@ public class BpmModelServiceImpl implements BpmModelService {
|
||||||
});
|
});
|
||||||
// 3. 校验第一个用户任务节点的规则类型是否为“审批人自选”,BPMN 设计器,校验第一个用户任务节点,SIMPLE 设计器,第一个节点固定为发起人所以校验第二个用户任务节点
|
// 3. 校验第一个用户任务节点的规则类型是否为“审批人自选”,BPMN 设计器,校验第一个用户任务节点,SIMPLE 设计器,第一个节点固定为发起人所以校验第二个用户任务节点
|
||||||
UserTask firUserTask = CollUtil.get(userTasks, BpmModelTypeEnum.BPMN.getType().equals(type) ? 0 : 1);
|
UserTask firUserTask = CollUtil.get(userTasks, BpmModelTypeEnum.BPMN.getType().equals(type) ? 0 : 1);
|
||||||
// 4. 极端情况下无多个用户任务节点,比如发起人-抄送节点
|
if (firUserTask == null) {
|
||||||
if (firUserTask == null){
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Integer candidateStrategy = parseCandidateStrategy(firUserTask);
|
Integer candidateStrategy = parseCandidateStrategy(firUserTask);
|
||||||
|
|
|
@ -557,31 +557,31 @@ public class BpmTaskServiceImpl implements BpmTaskService {
|
||||||
// 2.2 添加评论
|
// 2.2 添加评论
|
||||||
taskService.addComment(task.getId(), task.getProcessInstanceId(), BpmCommentTypeEnum.APPROVE.getType(),
|
taskService.addComment(task.getId(), task.getProcessInstanceId(), BpmCommentTypeEnum.APPROVE.getType(),
|
||||||
BpmCommentTypeEnum.APPROVE.formatComment(reqVO.getReason()));
|
BpmCommentTypeEnum.APPROVE.formatComment(reqVO.getReason()));
|
||||||
// 如果流程变量前端传空,需要从历史实例中获取,原因:前端表单如果在当前节点无可编辑的字段时variables一定会为空
|
|
||||||
// 场景一:A节点发起,B节点表单无可编辑字段,审批通过时,C节点需要流程变量获取下一个执行节点,但因为B节点无可编辑的字段,variables为空,流程可能出现问题
|
// 3. 设置流程变量。如果流程变量前端传空,需要从历史实例中获取,原因:前端表单如果在当前节点无可编辑的字段时 variables 一定会为空
|
||||||
// 场景二:A节点发起,B节点只有某一个字段可编辑(比如day),但C节点需要多个节点(比如workday,在发起时填写,因为B节点只有day的编辑权限,在审批后。variables会缺少work的值)
|
// 场景一:A 节点发起,B 节点表单无可编辑字段,审批通过时,C 节点需要流程变量获取下一个执行节点,但因为 B 节点无可编辑的字段,variables 为空,流程可能出现问题。
|
||||||
// 3.1 设置流程变量
|
// 场景二:A 节点发起,B 节点只有某一个字段可编辑(比如 day),但 C 节点需要多个节点。
|
||||||
|
// (比如 work + day 变量,在发起时填写,因为 B 节点只有 day 的编辑权限,在审批后,variables 会缺少 work 的值)
|
||||||
Map<String, Object> processVariables = new HashMap<>();
|
Map<String, Object> processVariables = new HashMap<>();
|
||||||
// 3.2 获取历史中流程变量
|
if (CollUtil.isNotEmpty(instance.getProcessVariables())) { // 获取历史中流程变量
|
||||||
if (CollUtil.isNotEmpty(instance.getProcessVariables())) {
|
|
||||||
processVariables.putAll(instance.getProcessVariables());
|
processVariables.putAll(instance.getProcessVariables());
|
||||||
}
|
}
|
||||||
// 3.3 合并前端传递的流程变量,以前端为准
|
if (CollUtil.isNotEmpty(reqVO.getVariables())) { // 合并前端传递的流程变量,以前端为准
|
||||||
if (CollUtil.isNotEmpty(reqVO.getVariables())) {
|
|
||||||
processVariables.putAll(reqVO.getVariables());
|
processVariables.putAll(reqVO.getVariables());
|
||||||
}
|
}
|
||||||
// 3.4 校验并处理 APPROVE_USER_SELECT 当前审批人,选择下一节点审批人的逻辑
|
|
||||||
|
// 4. 校验并处理 APPROVE_USER_SELECT 当前审批人,选择下一节点审批人的逻辑
|
||||||
Map<String, Object> variables = validateAndSetNextAssignees(task.getTaskDefinitionKey(), processVariables,
|
Map<String, Object> variables = validateAndSetNextAssignees(task.getTaskDefinitionKey(), processVariables,
|
||||||
bpmnModel, reqVO.getNextAssignees(), instance);
|
bpmnModel, reqVO.getNextAssignees(), instance);
|
||||||
runtimeService.setVariables(task.getProcessInstanceId(), variables);
|
runtimeService.setVariables(task.getProcessInstanceId(), variables);
|
||||||
// 4 调用 BPM complete 去完成任务
|
|
||||||
|
// 5. 调用 BPM complete 去完成任务
|
||||||
taskService.complete(task.getId(), variables, true);
|
taskService.complete(task.getId(), variables, true);
|
||||||
|
|
||||||
// 【加签专属】处理加签任务
|
// 【加签专属】处理加签任务
|
||||||
handleParentTaskIfSign(task.getParentTaskId());
|
handleParentTaskIfSign(task.getParentTaskId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 校验选择的下一个节点的审批人,是否合法
|
* 校验选择的下一个节点的审批人,是否合法
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue