From 47a682630b8563017db497f2d0b48b3827a2ab40 Mon Sep 17 00:00:00 2001
From: skyouc
Date: 星期二, 25 三月 2025 14:25:49 +0800
Subject: [PATCH] Merge branch 'devlop' of http://47.97.1.152:5880/r/wms-master into devlop
---
rsf-common/src/main/java/com/vincent/rsf/common/utils/Utils.java | 39 +++++++++++++++++++++++++++++++++++++++
1 files changed, 39 insertions(+), 0 deletions(-)
diff --git a/rsf-common/src/main/java/com/vincent/rsf/common/utils/Utils.java b/rsf-common/src/main/java/com/vincent/rsf/common/utils/Utils.java
index 06a5b0b..008d82d 100644
--- a/rsf-common/src/main/java/com/vincent/rsf/common/utils/Utils.java
+++ b/rsf-common/src/main/java/com/vincent/rsf/common/utils/Utils.java
@@ -6,6 +6,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
+import java.util.concurrent.ThreadLocalRandom;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.Map;
@@ -46,6 +47,26 @@
}
return result;
}
+
+ public static <T, R> List<T> getAllTree(List<T> data, R parentId, Function<? super T, ? extends R> parentIdMapper, Function<? super T, ? extends R> idMapper, BiConsumer<T, List<T>> consumer) {
+ List<T> result = new ArrayList<>();
+ for (T datum : data) {
+ R dParentId = parentIdMapper.apply(datum);
+ R dId = idMapper.apply(datum);
+ if (dParentId.equals(dId)) {
+ List<T> children = toTreeData(data, dId, parentIdMapper, idMapper, consumer);
+ if (!children.isEmpty()) {
+ consumer.accept(datum, children);
+ }
+ result.add(datum);
+ }
+ if (dParentId.equals(dId)) {
+ continue;
+ }
+ }
+ return result;
+ }
+
public static <T> void treeRemove(List<T> list, String condition, Function<? super T, ? extends String> fetcher, Function<T, List<T>> childrenGetter) {
Iterator<T> iterator = list.iterator();
@@ -304,4 +325,22 @@
return processed;
}
+ public static String randomNumbers(int length) {
+ String baseString = "0123456789";
+
+ if (length < 1) {
+ length = 1;
+ }
+
+ StringBuilder sb = new StringBuilder(length);
+ int baseLength = baseString.length();
+
+ for(int i = 0; i < length; ++i) {
+ int number = ThreadLocalRandom.current().nextInt(baseLength);
+ sb.append(baseString.charAt(number));
+ }
+
+ return sb.toString();
+ }
+
}
--
Gitblit v1.9.1