【缺陷修复】 流程预测时,不能计算流程表达式时,返回空列表,避免流程无法进行下去

This commit is contained in:
jason 2024-12-10 13:27:46 +08:00
parent de9dc24523
commit d237b17280
1 changed files with 15 additions and 2 deletions

View File

@ -4,10 +4,14 @@ import cn.hutool.core.convert.Convert;
import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateStrategy; import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateStrategy;
import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum; import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum;
import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils; import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils;
import com.google.common.collect.Sets;
import lombok.extern.slf4j.Slf4j;
import org.flowable.bpmn.model.BpmnModel; import org.flowable.bpmn.model.BpmnModel;
import org.flowable.common.engine.api.FlowableException;
import org.flowable.engine.delegate.DelegateExecution; import org.flowable.engine.delegate.DelegateExecution;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -17,6 +21,7 @@ import java.util.Set;
* @author 芋道源码 * @author 芋道源码
*/ */
@Component @Component
@Slf4j
public class BpmTaskCandidateExpressionStrategy implements BpmTaskCandidateStrategy { public class BpmTaskCandidateExpressionStrategy implements BpmTaskCandidateStrategy {
@Override @Override
@ -38,8 +43,16 @@ public class BpmTaskCandidateExpressionStrategy implements BpmTaskCandidateStrat
@Override @Override
public Set<Long> calculateUsersByActivity(BpmnModel bpmnModel, String activityId, String param, public Set<Long> calculateUsersByActivity(BpmnModel bpmnModel, String activityId, String param,
Long startUserId, String processDefinitionId, Map<String, Object> processVariables) { Long startUserId, String processDefinitionId, Map<String, Object> processVariables) {
Object result = FlowableUtils.getExpressionValue(processVariables, param); Map<String, Object> variables = processVariables == null ? new HashMap<>() : processVariables;
return Convert.toSet(Long.class, result); try {
Object result = FlowableUtils.getExpressionValue(variables, param);
return Convert.toSet(Long.class, result);
} catch (FlowableException ex) {
// 预测未运行的节点时候表达式如果包含 execution 或者不存在的流程变量会抛异常
log.warn("[calculateUsersByActivity][表达式({}) 变量({}) 解析报错", param, variables, ex);
// 不能预测候选人返回空列表, 避免流程无法进行
return Sets.newHashSet();
}
} }
} }