소스 검색

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

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);
     }