Ver Fonte

fix 部门节点

he2802 há 4 anos atrás
pai
commit
d53d0fe2e6

+ 10 - 5
zhongzheng-system/src/main/java/com/zhongzheng/modules/system/service/impl/SysDeptServiceImpl.java

@@ -189,12 +189,17 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
      */
     @Override
     public int insertDept(SysDept dept) {
-        SysDept info = getById(dept.getParentId());
-        // 如果父节点不为正常状态,则不允许新增子节点
-        if (!UserConstants.DEPT_NORMAL.equals(info.getStatus())) {
-            throw new CustomException("部门停用,不允许新增");
+        if(dept.getParentId()>0){
+            SysDept info = getById(dept.getParentId());
+            // 如果父节点不为正常状态,则不允许新增子节点
+            if (!UserConstants.DEPT_NORMAL.equals(info.getStatus())) {
+                throw new CustomException("部门停用,不允许新增");
+            }
+            dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
+        }else{
+            dept.setAncestors("0");
         }
-        dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
+
         return baseMapper.insert(dept);
     }