提交 | 用户 | 时间
|
bb2880
|
1 |
package com.iailab.module.bpm.framework.flowable.core.candidate.strategy.other; |
e7c126
|
2 |
|
H |
3 |
import cn.hutool.core.convert.Convert; |
f4f940
|
4 |
import com.google.common.collect.Sets; |
e7c126
|
5 |
import com.iailab.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateStrategy; |
H |
6 |
import com.iailab.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum; |
|
7 |
import com.iailab.module.bpm.framework.flowable.core.util.FlowableUtils; |
f4f940
|
8 |
import lombok.extern.slf4j.Slf4j; |
bb2880
|
9 |
import org.flowable.bpmn.model.BpmnModel; |
f4f940
|
10 |
import org.flowable.common.engine.api.FlowableException; |
e7c126
|
11 |
import org.flowable.engine.delegate.DelegateExecution; |
H |
12 |
import org.springframework.stereotype.Component; |
|
13 |
|
f4f940
|
14 |
import java.util.HashMap; |
bb2880
|
15 |
import java.util.Map; |
e7c126
|
16 |
import java.util.Set; |
H |
17 |
|
|
18 |
/** |
|
19 |
* 流程表达式 {@link BpmTaskCandidateStrategy} 实现类 |
|
20 |
* |
|
21 |
* @author iailab |
|
22 |
*/ |
|
23 |
@Component |
f4f940
|
24 |
@Slf4j |
e7c126
|
25 |
public class BpmTaskCandidateExpressionStrategy implements BpmTaskCandidateStrategy { |
H |
26 |
|
|
27 |
@Override |
|
28 |
public BpmTaskCandidateStrategyEnum getStrategy() { |
|
29 |
return BpmTaskCandidateStrategyEnum.EXPRESSION; |
|
30 |
} |
|
31 |
|
|
32 |
@Override |
|
33 |
public void validateParam(String param) { |
|
34 |
// do nothing 因为它基本做不了校验 |
|
35 |
} |
|
36 |
|
|
37 |
@Override |
bb2880
|
38 |
public Set<Long> calculateUsersByTask(DelegateExecution execution, String param) { |
e7c126
|
39 |
Object result = FlowableUtils.getExpressionValue(execution, param); |
H |
40 |
return Convert.toSet(Long.class, result); |
|
41 |
} |
|
42 |
|
bb2880
|
43 |
@Override |
H |
44 |
public Set<Long> calculateUsersByActivity(BpmnModel bpmnModel, String activityId, String param, |
|
45 |
Long startUserId, String processDefinitionId, Map<String, Object> processVariables) { |
f4f940
|
46 |
Map<String, Object> variables = processVariables == null ? new HashMap<>() : processVariables; |
H |
47 |
try { |
|
48 |
Object result = FlowableUtils.getExpressionValue(variables, param); |
|
49 |
return Convert.toSet(Long.class, result); |
|
50 |
} catch (FlowableException ex) { |
|
51 |
// 预测未运行的节点时候,表达式如果包含 execution 或者不存在的流程变量会抛异常, |
|
52 |
log.warn("[calculateUsersByActivity][表达式({}) 变量({}) 解析报错", param, variables, ex); |
|
53 |
// 不能预测候选人,返回空列表, 避免流程无法进行 |
|
54 |
return Sets.newHashSet(); |
|
55 |
} |
bb2880
|
56 |
} |
H |
57 |
|
e7c126
|
58 |
} |