Commit cf3a13d4ff3ffbaa89f7c8e649676dbfb4045d24

Authored by YunaiV
1 parent a9bb5534

fix:【BPM】修复多实例使用 LinkedHashSet 保持顺序

yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java
... ... @@ -11,6 +11,7 @@ import java.util.function.*;
11 11 import java.util.stream.Collectors;
12 12 import java.util.stream.Stream;
13 13  
  14 +import static cn.hutool.core.convert.Convert.toCollection;
14 15 import static java.util.Arrays.asList;
15 16  
16 17 /**
... ... @@ -335,4 +336,17 @@ public class CollectionUtils {
335 336 return list.stream().filter(Objects::nonNull).flatMap(Collection::stream).collect(Collectors.toList());
336 337 }
337 338  
  339 + /**
  340 + * 转换为 LinkedHashSet
  341 + *
  342 + * @param <T> 元素类型
  343 + * @param elementType 集合中元素类型
  344 + * @param value 被转换的值
  345 + * @return {@link LinkedHashSet}
  346 + */
  347 + @SuppressWarnings("unchecked")
  348 + public static <T> LinkedHashSet<T> toLinkedHashSet(Class<T> elementType, Object value) {
  349 + return (LinkedHashSet<T>) toCollection(LinkedHashSet.class, elementType, value);
  350 + }
  351 +
338 352 }
339 353 \ No newline at end of file
... ...
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/strategy/form/BpmTaskCandidateFormUserStrategy.java
1 1 package cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.strategy.form;
2 2  
3   -import cn.hutool.core.convert.Convert;
4 3 import cn.hutool.core.lang.Assert;
  4 +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
5 5 import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateStrategy;
6 6 import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.strategy.user.BpmTaskCandidateUserStrategy;
7 7 import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum;
... ... @@ -33,7 +33,7 @@ public class BpmTaskCandidateFormUserStrategy implements BpmTaskCandidateStrateg
33 33 @Override
34 34 public Set<Long> calculateUsersByTask(DelegateExecution execution, String param) {
35 35 Object result = execution.getVariable(param);
36   - return Convert.toSet(Long.class, result);
  36 + return CollectionUtils.toLinkedHashSet(Long.class, result);
37 37 }
38 38  
39 39 @Override
... ... @@ -41,7 +41,7 @@ public class BpmTaskCandidateFormUserStrategy implements BpmTaskCandidateStrateg
41 41 String param, Long startUserId, String processDefinitionId,
42 42 Map<String, Object> processVariables) {
43 43 Object result = processVariables == null ? null : processVariables.get(param);
44   - return Convert.toSet(Long.class, result);
  44 + return CollectionUtils.toLinkedHashSet(Long.class, result);
45 45 }
46 46  
47 47 }
... ...
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/strategy/other/BpmTaskCandidateExpressionStrategy.java
1 1 package cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.strategy.other;
2 2  
3   -import cn.hutool.core.convert.Convert;
  3 +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
4 4 import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateStrategy;
5 5 import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum;
6 6 import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils;
... ... @@ -37,7 +37,7 @@ public class BpmTaskCandidateExpressionStrategy implements BpmTaskCandidateStrat
37 37 @Override
38 38 public Set<Long> calculateUsersByTask(DelegateExecution execution, String param) {
39 39 Object result = FlowableUtils.getExpressionValue(execution, param);
40   - return Convert.toSet(Long.class, result);
  40 + return CollectionUtils.toLinkedHashSet(Long.class, result);
41 41 }
42 42  
43 43 @Override
... ... @@ -46,7 +46,7 @@ public class BpmTaskCandidateExpressionStrategy implements BpmTaskCandidateStrat
46 46 Map<String, Object> variables = processVariables == null ? new HashMap<>() : processVariables;
47 47 try {
48 48 Object result = FlowableUtils.getExpressionValue(variables, param);
49   - return Convert.toSet(Long.class, result);
  49 + return CollectionUtils.toLinkedHashSet(Long.class, result);
50 50 } catch (FlowableException ex) {
51 51 // 预测未运行的节点时候,表达式如果包含 execution 或者不存在的流程变量会抛异常,
52 52 log.warn("[calculateUsersByActivity][表达式({}) 变量({}) 解析报错", param, variables, ex);
... ...