From 2f21f293c199ae596efeff080c76dc0f285e8faa Mon Sep 17 00:00:00 2001
From: 疯狂的狮子li <15040126243@163.com>
Date: 星期四, 04 十一月 2021 10:32:18 +0800
Subject: [PATCH] update 基于 hutool 封装树构建工具 重构部门与菜单树结构返回

---
 ruoyi-common/src/main/java/com/ruoyi/common/utils/BeanCopyUtils.java |   83 +++++++++++++++++++++++------------------
 1 files changed, 47 insertions(+), 36 deletions(-)

diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/BeanCopyUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/BeanCopyUtils.java
index bea09f8..8bf40d1 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/BeanCopyUtils.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/BeanCopyUtils.java
@@ -2,6 +2,8 @@
 
 import cn.hutool.core.bean.copier.BeanCopier;
 import cn.hutool.core.bean.copier.CopyOptions;
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.ReflectUtil;
 
 import java.util.List;
@@ -14,42 +16,51 @@
  */
 public class BeanCopyUtils {
 
-	/**
-	 * 鍗曞璞″熀浜巆lass鍒涘缓鎷疯礉
-	 *
-	 * @param source      鏁版嵁鏉ユ簮瀹炰綋
-	 * @param copyOptions copy鏉′欢
-	 * @param desc        鎻忚堪瀵硅薄 杞崲鍚庣殑瀵硅薄
-	 * @return desc
-	 */
-	public static <T, V> V oneCopy(T source, CopyOptions copyOptions, Class<V> desc) {
-		V v = ReflectUtil.newInstanceIfPossible(desc);
-		return oneCopy(source, copyOptions, v);
-	}
+    /**
+     * 鍗曞璞″熀浜巆lass鍒涘缓鎷疯礉
+     *
+     * @param source      鏁版嵁鏉ユ簮瀹炰綋
+     * @param copyOptions copy鏉′欢
+     * @param desc        鎻忚堪瀵硅薄 杞崲鍚庣殑瀵硅薄
+     * @return desc
+     */
+    public static <T, V> V oneCopy(T source, CopyOptions copyOptions, Class<V> desc) {
+        V v = ReflectUtil.newInstanceIfPossible(desc);
+        return oneCopy(source, copyOptions, v);
+    }
 
-	/**
-	 * 鍗曞璞″熀浜庡璞″垱寤烘嫹璐�
-	 *
-	 * @param source      鏁版嵁鏉ユ簮瀹炰綋
-	 * @param copyOptions copy鏉′欢
-	 * @param desc        杞崲鍚庣殑瀵硅薄
-	 * @return desc
-	 */
-	public static <T, V> V oneCopy(T source, CopyOptions copyOptions, V desc) {
-		return BeanCopier.create(source, desc, copyOptions).copy();
-	}
+    /**
+     * 鍗曞璞″熀浜庡璞″垱寤烘嫹璐�
+     *
+     * @param source      鏁版嵁鏉ユ簮瀹炰綋
+     * @param copyOptions copy鏉′欢
+     * @param desc        杞崲鍚庣殑瀵硅薄
+     * @return desc
+     */
+    public static <T, V> V oneCopy(T source, CopyOptions copyOptions, V desc) {
+        if (ObjectUtil.isNull(source)) {
+            return null;
+        }
+        return BeanCopier.create(source, desc, copyOptions).copy();
+    }
 
-	/**
-	 * 鍒楄〃瀵硅薄鍩轰簬class鍒涘缓鎷疯礉
-	 *
-	 * @param sourceList  鏁版嵁鏉ユ簮瀹炰綋鍒楄〃
-	 * @param copyOptions copy鏉′欢
-	 * @param desc        鎻忚堪瀵硅薄 杞崲鍚庣殑瀵硅薄
-	 * @return desc
-	 */
-	public static <T, V> List<V> listCopy(List<T> sourceList, CopyOptions copyOptions, Class<V> desc) {
-		return sourceList.stream()
-			.map(source -> oneCopy(source, copyOptions, desc))
-			.collect(Collectors.toList());
-	}
+    /**
+     * 鍒楄〃瀵硅薄鍩轰簬class鍒涘缓鎷疯礉
+     *
+     * @param sourceList  鏁版嵁鏉ユ簮瀹炰綋鍒楄〃
+     * @param copyOptions copy鏉′欢
+     * @param desc        鎻忚堪瀵硅薄 杞崲鍚庣殑瀵硅薄
+     * @return desc
+     */
+    public static <T, V> List<V> listCopy(List<T> sourceList, CopyOptions copyOptions, Class<V> desc) {
+        if (ObjectUtil.isNull(sourceList)) {
+            return null;
+        }
+        if (CollUtil.isEmpty(sourceList)) {
+            return CollUtil.newArrayList();
+        }
+        return sourceList.stream()
+                .map(source -> oneCopy(source, copyOptions, desc))
+                .collect(Collectors.toList());
+    }
 }

--
Gitblit v1.9.3