From 2ffdd56301ef38187983f7ab6c0008a1548e15de Mon Sep 17 00:00:00 2001 From: 疯狂的狮子Li <15040126243@163.com> Date: 星期一, 04 十一月 2024 11:38:55 +0800 Subject: [PATCH] update 优化 部门树多基点展示问题 支持相同名称节点并排展示 --- ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/utils/TreeBuildUtils.java | 17 +++++++++++++++++ ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysDeptServiceImpl.java | 21 ++++++++++++++++----- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/utils/TreeBuildUtils.java b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/utils/TreeBuildUtils.java index 8e501df..2ab42cb 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/utils/TreeBuildUtils.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/utils/TreeBuildUtils.java @@ -44,6 +44,23 @@ } /** + * 鏋勫缓鏍戝舰缁撴瀯 + * + * @param <T> 杈撳叆鑺傜偣鐨勭被鍨� + * @param <K> 鑺傜偣ID鐨勭被鍨� + * @param parentId 椤剁骇鑺傜偣 + * @param list 鑺傜偣鍒楄〃锛屽叾涓寘鍚簡瑕佹瀯寤烘爲褰㈢粨鏋勭殑鎵�鏈夎妭鐐� + * @param nodeParser 瑙f瀽鍣紝鐢ㄤ簬灏嗚緭鍏ヨ妭鐐硅浆鎹负鏍戣妭鐐� + * @return 鏋勫缓濂界殑鏍戝舰缁撴瀯鍒楄〃 + */ + public static <T, K> List<Tree<K>> build(List<T> list, K parentId, NodeParser<T, K> nodeParser) { + if (CollUtil.isEmpty(list)) { + return CollUtil.newArrayList(); + } + return TreeUtil.build(list, parentId, DEFAULT_CONFIG, nodeParser); + } + + /** * 鑾峰彇鑺傜偣鍒楄〃涓墍鏈夎妭鐐圭殑鍙跺瓙鑺傜偣 * * @param <K> 鑺傜偣ID鐨勭被鍨� diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysDeptServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysDeptServiceImpl.java index 49b18b7..dcdd7fc 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysDeptServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysDeptServiceImpl.java @@ -102,11 +102,22 @@ if (CollUtil.isEmpty(depts)) { return CollUtil.newArrayList(); } - return TreeBuildUtils.build(depts, (dept, tree) -> - tree.setId(dept.getDeptId()) - .setParentId(dept.getParentId()) - .setName(dept.getDeptName()) - .setWeight(dept.getOrderNum())); + // 鑾峰彇褰撳墠鍒楄〃涓瘡涓�涓妭鐐圭殑parentId锛岀劧鍚庡湪鍒楄〃涓煡鎵炬槸鍚︽湁id涓庡叾parentId瀵瑰簲锛岃嫢鏃犲搴旓紝鍒欒〃鏄庢鏃惰妭鐐瑰垪琛ㄤ腑锛岃鑺傜偣鍦ㄥ綋鍓嶅垪琛ㄤ腑灞炰簬椤剁骇鑺傜偣 + List<Tree<Long>> treeList = CollUtil.newArrayList(); + for (SysDeptVo d : depts) { + Long parentId = d.getParentId(); + SysDeptVo sysDeptVo = depts.stream().filter(it -> it.getDeptId().longValue() == parentId).findFirst().orElse(null); + if (sysDeptVo == null) { + List<Tree<Long>> trees = TreeBuildUtils.build(depts, parentId, (dept, tree) -> + tree.setId(dept.getDeptId()) + .setParentId(dept.getParentId()) + .setName(dept.getDeptName()) + .setWeight(dept.getOrderNum())); + Tree<Long> tree = trees.stream().filter(it -> it.getId().longValue() == d.getDeptId()).findFirst().get(); + treeList.add(tree); + } + } + return treeList; } /** -- Gitblit v1.9.3