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 | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 51 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 d718c97..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,8 +6,10 @@
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;
/**
* Created by vincent on 2023/3/14
@@ -45,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();
@@ -292,4 +314,33 @@
return snakeCaseField + (order.isEmpty() ? "" : " " + order);
}
+ public static String processTemplate(String template, Map<String, Object> params) {
+ if (template == null || params == null) {
+ return template;
+ }
+ String processed = template;
+ for (Map.Entry<String, Object> entry : params.entrySet()) {
+ processed = processed.replace("${" + entry.getKey() + "}", entry.getValue().toString());
+ }
+ 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