From d08e0053017fb5646d883f0d2b3fa3b911f5e6ca Mon Sep 17 00:00:00 2001 From: hshansha Date: Fri, 23 May 2025 17:10:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=AC=E5=8F=B8=E6=96=B0=E5=A2=9E=E9=83=A8?= =?UTF-8?q?=E9=97=A8=E4=B8=BA=E9=A1=B6=E7=BA=A7=E9=83=A8=E9=97=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/service/impl/SysDeptServiceImpl.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 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 4d39778..31c670c 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 @@ -192,6 +192,7 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService { boolean exist = baseMapper.exists(new LambdaQueryWrapper() .eq(SysDept::getDeptName, dept.getDeptName()) .eq(SysDept::getParentId, dept.getParentId()) + .eq(SysDept::getTenantId, dept.getTenantId()) .ne(ObjectUtil.isNotNull(dept.getDeptId()), SysDept::getDeptId, dept.getDeptId())); return !exist; } @@ -221,12 +222,16 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService { */ @Override public int insertDept(SysDept dept) { - SysDept info = baseMapper.selectById(dept.getParentId()); - // 如果父节点不为正常状态,则不允许新增子节点 - if (!UserConstants.DEPT_NORMAL.equals(info.getStatus())) { - throw new ServiceException("部门停用,不允许新增"); + if(dept.getParentId()==0L){ //新增某公司顶级部门时 + dept.setAncestors(dept.getParentId().toString()); + }else{ + SysDept info = baseMapper.selectById(dept.getParentId()); + // 如果父节点不为正常状态,则不允许新增子节点 + if (!UserConstants.DEPT_NORMAL.equals(info.getStatus())) { + throw new ServiceException("部门停用,不允许新增"); + } + dept.setAncestors(info.getAncestors() + StringUtils.SEPARATOR + dept.getParentId()); } - dept.setAncestors(info.getAncestors() + StringUtils.SEPARATOR + dept.getParentId()); return baseMapper.insert(dept); }