From 23b688e436a89845e92d861adb5875e625e90d9f Mon Sep 17 00:00:00 2001
From: zxl <763096477@qq.com>
Date: 星期五, 14 三月 2025 11:43:18 +0800
Subject: [PATCH] Merge branch 'dev'

---
 system/src/main/java/com/ycl/system/service/impl/SysDeptServiceImpl.java |   63 ++++++++++++++++++++-----------
 1 files changed, 40 insertions(+), 23 deletions(-)

diff --git a/system/src/main/java/com/ycl/system/service/impl/SysDeptServiceImpl.java b/system/src/main/java/com/ycl/system/service/impl/SysDeptServiceImpl.java
index 6e291af..5283434 100644
--- a/system/src/main/java/com/ycl/system/service/impl/SysDeptServiceImpl.java
+++ b/system/src/main/java/com/ycl/system/service/impl/SysDeptServiceImpl.java
@@ -6,6 +6,7 @@
 import com.ycl.common.base.Result;
 import com.ycl.common.core.domain.StringTreeSelect;
 import com.ycl.system.domain.base.BaseSelect;
+import lombok.RequiredArgsConstructor;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.ycl.common.annotation.DataScope;
@@ -29,13 +30,12 @@
  * @author ycl
  */
 @Service
+@RequiredArgsConstructor
 public class SysDeptServiceImpl implements ISysDeptService
 {
-    @Autowired
-    private SysDeptMapper deptMapper;
 
-    @Autowired
-    private SysRoleMapper roleMapper;
+    private final SysDeptMapper deptMapper;
+    private final SysRoleMapper roleMapper;
 
     /**
      * 鏌ヨ閮ㄩ棬绠$悊鏁版嵁
@@ -48,6 +48,11 @@
     public List<SysDept> selectDeptList(SysDept dept)
     {
         return deptMapper.selectDeptList(dept);
+    }
+
+    @Override
+    public List<SysDept> selectDeptListNoAuth(SysDept dept) {
+        return deptMapper.selectDeptListNoAuth(dept);
     }
 
     /**
@@ -262,13 +267,18 @@
     @Override
     public int insertDept(SysDept dept)
     {
-        SysDept info = deptMapper.selectDeptById(dept.getParentId());
-        // 濡傛灉鐖惰妭鐐逛笉涓烘甯哥姸鎬�,鍒欎笉鍏佽鏂板瀛愯妭鐐�
-        if (!UserConstants.DEPT_NORMAL.equals(info.getStatus()))
-        {
-            throw new ServiceException("閮ㄩ棬鍋滅敤锛屼笉鍏佽鏂板");
+        if (Objects.nonNull(dept.getParentId())) {
+            SysDept info = deptMapper.selectDeptById(dept.getParentId());
+            // 濡傛灉鐖惰妭鐐逛笉涓烘甯哥姸鎬�,鍒欎笉鍏佽鏂板瀛愯妭鐐�
+            if (!UserConstants.DEPT_NORMAL.equals(info.getStatus()))
+            {
+                throw new ServiceException("涓婄骇閮ㄩ棬宸插仠鐢紝涓嶅厑璁告柊澧炰笅绾ч儴闂�");
+            }
+            dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
+        } else {
+            dept.setParentId(0L);
+            dept.setAncestors("");
         }
-        dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
         return deptMapper.insertDept(dept);
     }
 
@@ -281,22 +291,23 @@
     @Override
     public int updateDept(SysDept dept)
     {
-        SysDept newParentDept = deptMapper.selectDeptById(dept.getParentId());
         SysDept oldDept = deptMapper.selectDeptById(dept.getDeptId());
-        if (StringUtils.isNotNull(newParentDept) && StringUtils.isNotNull(oldDept))
-        {
-            String newAncestors = newParentDept.getAncestors() + "," + newParentDept.getDeptId();
-            String oldAncestors = oldDept.getAncestors();
-            dept.setAncestors(newAncestors);
-            updateDeptChildren(dept.getDeptId(), newAncestors, oldAncestors);
+        if (Objects.isNull(oldDept)) {
+            throw new RuntimeException("淇敼閮ㄩ棬琚垹闄ゆ垨涓嶅瓨鍦�");
+        }
+        if (Objects.nonNull(dept.getParentId())) {
+            SysDept newParentDept = deptMapper.selectDeptById(dept.getParentId());
+            if (Objects.nonNull(newParentDept)) {
+                String newAncestors = newParentDept.getAncestors() + "," + newParentDept.getDeptId();
+                String oldAncestors = oldDept.getAncestors();
+                dept.setAncestors(newAncestors);
+                updateDeptChildren(dept.getDeptId(), newAncestors, oldAncestors);
+            }
+        } else {
+            dept.setParentId(0L);
+            dept.setAncestors("");
         }
         int result = deptMapper.updateDept(dept);
-        if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()) && StringUtils.isNotEmpty(dept.getAncestors())
-                && !StringUtils.equals("0", dept.getAncestors()))
-        {
-            // 濡傛灉璇ラ儴闂ㄦ槸鍚敤鐘舵�侊紝鍒欏惎鐢ㄨ閮ㄩ棬鐨勬墍鏈変笂绾ч儴闂�
-            updateParentDeptStatusNormal(dept);
-        }
         return result;
     }
 
@@ -414,4 +425,10 @@
         }).collect(Collectors.toList());
         return list;
     }
+
+
+    @Override
+    public List<Long> getChildIds(Long deptId) {
+        return deptMapper.getChildIds(deptId);
+    }
 }

--
Gitblit v1.8.0