公司新增部门为顶级部门

master 09
hshansha 7 months ago
parent d5080cf586
commit d08e005301

@ -192,6 +192,7 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
boolean exist = baseMapper.exists(new LambdaQueryWrapper<SysDept>() boolean exist = baseMapper.exists(new LambdaQueryWrapper<SysDept>()
.eq(SysDept::getDeptName, dept.getDeptName()) .eq(SysDept::getDeptName, dept.getDeptName())
.eq(SysDept::getParentId, dept.getParentId()) .eq(SysDept::getParentId, dept.getParentId())
.eq(SysDept::getTenantId, dept.getTenantId())
.ne(ObjectUtil.isNotNull(dept.getDeptId()), SysDept::getDeptId, dept.getDeptId())); .ne(ObjectUtil.isNotNull(dept.getDeptId()), SysDept::getDeptId, dept.getDeptId()));
return !exist; return !exist;
} }
@ -221,12 +222,16 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
*/ */
@Override @Override
public int insertDept(SysDept dept) { public int insertDept(SysDept dept) {
SysDept info = baseMapper.selectById(dept.getParentId()); if(dept.getParentId()==0L){ //新增某公司顶级部门时
// 如果父节点不为正常状态,则不允许新增子节点 dept.setAncestors(dept.getParentId().toString());
if (!UserConstants.DEPT_NORMAL.equals(info.getStatus())) { }else{
throw new ServiceException("部门停用,不允许新增"); 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); return baseMapper.insert(dept);
} }

Loading…
Cancel
Save