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,6 +11,7 @@ import java.util.function.*;
11 import java.util.stream.Collectors; 11 import java.util.stream.Collectors;
12 import java.util.stream.Stream; 12 import java.util.stream.Stream;
13 13
  14 +import static cn.hutool.core.convert.Convert.toCollection;
14 import static java.util.Arrays.asList; 15 import static java.util.Arrays.asList;
15 16
16 /** 17 /**
@@ -335,4 +336,17 @@ public class CollectionUtils { @@ -335,4 +336,17 @@ public class CollectionUtils {
335 return list.stream().filter(Objects::nonNull).flatMap(Collection::stream).collect(Collectors.toList()); 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 \ No newline at end of file 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 package cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.strategy.form; 1 package cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.strategy.form;
2 2
3 -import cn.hutool.core.convert.Convert;  
4 import cn.hutool.core.lang.Assert; 3 import cn.hutool.core.lang.Assert;
  4 +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
5 import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateStrategy; 5 import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateStrategy;
6 import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.strategy.user.BpmTaskCandidateUserStrategy; 6 import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.strategy.user.BpmTaskCandidateUserStrategy;
7 import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum; 7 import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum;
@@ -33,7 +33,7 @@ public class BpmTaskCandidateFormUserStrategy implements BpmTaskCandidateStrateg @@ -33,7 +33,7 @@ public class BpmTaskCandidateFormUserStrategy implements BpmTaskCandidateStrateg
33 @Override 33 @Override
34 public Set<Long> calculateUsersByTask(DelegateExecution execution, String param) { 34 public Set<Long> calculateUsersByTask(DelegateExecution execution, String param) {
35 Object result = execution.getVariable(param); 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 @Override 39 @Override
@@ -41,7 +41,7 @@ public class BpmTaskCandidateFormUserStrategy implements BpmTaskCandidateStrateg @@ -41,7 +41,7 @@ public class BpmTaskCandidateFormUserStrategy implements BpmTaskCandidateStrateg
41 String param, Long startUserId, String processDefinitionId, 41 String param, Long startUserId, String processDefinitionId,
42 Map<String, Object> processVariables) { 42 Map<String, Object> processVariables) {
43 Object result = processVariables == null ? null : processVariables.get(param); 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 package cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.strategy.other; 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 import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateStrategy; 4 import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateStrategy;
5 import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum; 5 import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum;
6 import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils; 6 import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils;
@@ -37,7 +37,7 @@ public class BpmTaskCandidateExpressionStrategy implements BpmTaskCandidateStrat @@ -37,7 +37,7 @@ public class BpmTaskCandidateExpressionStrategy implements BpmTaskCandidateStrat
37 @Override 37 @Override
38 public Set<Long> calculateUsersByTask(DelegateExecution execution, String param) { 38 public Set<Long> calculateUsersByTask(DelegateExecution execution, String param) {
39 Object result = FlowableUtils.getExpressionValue(execution, param); 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 @Override 43 @Override
@@ -46,7 +46,7 @@ public class BpmTaskCandidateExpressionStrategy implements BpmTaskCandidateStrat @@ -46,7 +46,7 @@ public class BpmTaskCandidateExpressionStrategy implements BpmTaskCandidateStrat
46 Map<String, Object> variables = processVariables == null ? new HashMap<>() : processVariables; 46 Map<String, Object> variables = processVariables == null ? new HashMap<>() : processVariables;
47 try { 47 try {
48 Object result = FlowableUtils.getExpressionValue(variables, param); 48 Object result = FlowableUtils.getExpressionValue(variables, param);
49 - return Convert.toSet(Long.class, result); 49 + return CollectionUtils.toLinkedHashSet(Long.class, result);
50 } catch (FlowableException ex) { 50 } catch (FlowableException ex) {
51 // 预测未运行的节点时候,表达式如果包含 execution 或者不存在的流程变量会抛异常, 51 // 预测未运行的节点时候,表达式如果包含 execution 或者不存在的流程变量会抛异常,
52 log.warn("[calculateUsersByActivity][表达式({}) 变量({}) 解析报错", param, variables, ex); 52 log.warn("[calculateUsersByActivity][表达式({}) 变量({}) 解析报错", param, variables, ex);