From a62d65a9b8b7471c720bdb360e6f2121a8ce5dd4 Mon Sep 17 00:00:00 2001
From: 疯狂的狮子li <15040126243@163.com>
Date: 星期四, 09 十二月 2021 11:48:55 +0800
Subject: [PATCH] fix 修复 TreeBuildUtils 顶节点不为 0 问题

---
 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java |   17 ++++++++++-------
 1 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java
index 0a2f8e6..c730926 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java
@@ -59,7 +59,11 @@
      */
     @Override
     public List<Tree<Long>> buildDeptTreeSelect(List<SysDept> depts) {
-        return TreeBuildUtils.build(depts, (dept, tree) ->
+        if (CollUtil.isEmpty(depts)) {
+            return CollUtil.newArrayList();
+        }
+        Long parentId = depts.get(0).getParentId();
+        return TreeBuildUtils.build(depts, parentId, (dept, tree) ->
             tree.setId(dept.getDeptId())
                 .setParentId(dept.getParentId())
                 .setName(dept.getDeptName())
@@ -73,7 +77,7 @@
      * @return 閫変腑閮ㄩ棬鍒楄〃
      */
     @Override
-    public List<Integer> selectDeptListByRoleId(Long roleId) {
+    public List<Long> selectDeptListByRoleId(Long roleId) {
         SysRole role = roleMapper.selectById(roleId);
         return baseMapper.selectDeptListByRoleId(roleId, role.isDeptCheckStrictly());
     }
@@ -111,8 +115,7 @@
     @Override
     public boolean hasChildByDeptId(Long deptId) {
         long result = count(new LambdaQueryWrapper<SysDept>()
-            .eq(SysDept::getParentId, deptId)
-            .last("limit 1"));
+            .eq(SysDept::getParentId, deptId));
         return result > 0;
     }
 
@@ -138,11 +141,11 @@
     @Override
     public String checkDeptNameUnique(SysDept dept) {
         Long deptId = StringUtils.isNull(dept.getDeptId()) ? -1L : dept.getDeptId();
-        SysDept info = getOne(new LambdaQueryWrapper<SysDept>()
+        long count = count(new LambdaQueryWrapper<SysDept>()
             .eq(SysDept::getDeptName, dept.getDeptName())
             .eq(SysDept::getParentId, dept.getParentId())
-            .last("limit 1"));
-        if (StringUtils.isNotNull(info) && info.getDeptId().longValue() != deptId.longValue()) {
+            .ne(SysDept::getDeptId, deptId));
+        if (count > 0) {
             return UserConstants.NOT_UNIQUE;
         }
         return UserConstants.UNIQUE;

--
Gitblit v1.9.3