Преглед на файлове

新增部门时,未选择上级部门处理

shiqian преди 4 години
родител
ревизия
b0761a2583
променени са 1 файла, в които са добавени 12 реда и са изтрити 6 реда
  1. 12 6
      boman-modules/boman-system/src/main/java/com/boman/system/service/impl/SysDeptServiceImpl.java

+ 12 - 6
boman-modules/boman-system/src/main/java/com/boman/system/service/impl/SysDeptServiceImpl.java

@@ -198,13 +198,19 @@ public class SysDeptServiceImpl implements ISysDeptService
     @Override
     public int insertDept(SysDept dept)
     {
-        SysDept info = deptMapper.selectDeptById(dept.getParentId());
-        // 如果父节点不为正常状态,则不允许新增子节点
-        if (!UserConstants.DEPT_NORMAL.equals(info.getStatus()))
-        {
-            throw new CustomException("部门停用,不允许新增");
+        SysDept parent = deptMapper.selectDeptById(dept.getParentId());
+        String ancestors = "0";
+        // 新增部门时,未选择上级部门处理
+        if (parent != null) {
+            // 如果父节点不为正常状态,则不允许新增子节点
+            if (!UserConstants.DEPT_NORMAL.equals(parent.getStatus()))
+            {
+                throw new CustomException("部门停用,不允许新增");
+            }
+            ancestors = parent.getAncestors() + "," + dept.getParentId();
         }
-        dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
+
+        dept.setAncestors(ancestors);
         return deptMapper.insertDept(dept);
     }