优化机构逻辑

This commit is contained in:
阿沐 2023-10-06 15:44:12 +08:00
parent ef21f030b8
commit 7c01b8b0db
2 changed files with 69 additions and 69 deletions

View File

@ -4,7 +4,6 @@ import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import net.maku.framework.common.constant.Constant;
import net.maku.framework.common.utils.Result;
import net.maku.framework.operatelog.annotations.OperateLog;
import net.maku.framework.operatelog.enums.OperateTypeEnum;
@ -47,7 +46,7 @@ public class SysOrgController {
SysOrgVO vo = SysOrgConvert.INSTANCE.convert(entity);
// 获取上级机构名称
if (!Constant.ROOT.equals(entity.getPid())) {
if (entity.getPid() != null) {
SysOrgEntity parentEntity = sysOrgService.getById(entity.getPid());
vo.setParentName(parentEntity.getName());
}

View File

@ -1,11 +1,12 @@
package net.maku.system.service.impl;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.AllArgsConstructor;
import net.maku.framework.common.constant.Constant;
import net.maku.framework.common.exception.ServerException;
import net.maku.framework.mybatis.service.impl.BaseServiceImpl;
import net.maku.framework.common.utils.TreeUtils;
import net.maku.framework.mybatis.service.impl.BaseServiceImpl;
import net.maku.system.convert.SysOrgConvert;
import net.maku.system.dao.SysOrgDao;
import net.maku.system.dao.SysUserDao;
@ -59,13 +60,13 @@ public class SysOrgServiceImpl extends BaseServiceImpl<SysOrgDao, SysOrgEntity>
SysOrgEntity entity = SysOrgConvert.INSTANCE.convert(vo);
// 上级机构不能为自身
if(entity.getId().equals(entity.getPid())){
if (entity.getId().equals(entity.getPid())) {
throw new ServerException("上级机构不能为自身");
}
// 上级机构不能为下级
List<Long> subOrgList = getSubOrgIdList(entity.getId());
if(subOrgList.contains(entity.getPid())){
if (subOrgList.contains(entity.getPid())) {
throw new ServerException("上级机构不能为下级");
}
@ -77,13 +78,13 @@ public class SysOrgServiceImpl extends BaseServiceImpl<SysOrgDao, SysOrgEntity>
public void delete(Long id) {
// 判断是否有子机构
long orgCount = count(new QueryWrapper<SysOrgEntity>().eq("pid", id));
if(orgCount > 0){
if (orgCount > 0) {
throw new ServerException("请先删除子机构");
}
// 判断机构下面是否有用户
long userCount = sysUserDao.selectCount(new QueryWrapper<SysUserEntity>().eq("org_id", id));
if(userCount > 0){
if (userCount > 0) {
throw new ServerException("机构下面有用户,不能删除");
}
@ -107,8 +108,8 @@ public class SysOrgServiceImpl extends BaseServiceImpl<SysOrgDao, SysOrgEntity>
}
private void getTree(Long id, List<SysOrgEntity> orgList, List<Long> subIdList) {
for(SysOrgEntity org : orgList){
if (org.getPid().equals(id)){
for (SysOrgEntity org : orgList) {
if (ObjectUtil.equals(org.getPid(), id)) {
getTree(org.getId(), orgList, subIdList);
subIdList.add(org.getId());