优化部门删除增加与岗位、角色关联判断

This commit is contained in:
hupeng
2020-09-01 16:52:12 +08:00
parent b61a44dafa
commit 2e7b70ed4b
3 changed files with 35 additions and 5 deletions

View File

@ -125,11 +125,13 @@ public class DeptController {
}
}
}
try {
deptService.removeByIds(deptIds);
}catch (Throwable e){
throw new BadRequestException( "所选部门中存在岗位或者角色关联,请取消关联后再试");
}
deptService.delDepts(deptIds);
// try {
// deptService.delDepts(deptIds);
// }catch (Throwable e){
// throw new BadRequestException( "所选部门中存在岗位或者角色关联,请取消关联后再试");
// }
return new ResponseEntity<>(HttpStatus.OK);
}
}

View File

@ -63,6 +63,12 @@ public interface DeptService extends BaseService<Dept>{
*/
Object buildTree(List<DeptDto> deptDtos);
/**
* 删除部门
* @param deptIds
*/
void delDepts(List<Long> deptIds);
/**
* 获取待删除的部门
* @param deptList /

View File

@ -11,12 +11,18 @@ package co.yixiang.modules.system.service.impl;
import co.yixiang.common.service.impl.BaseServiceImpl;
import co.yixiang.common.utils.QueryHelpPlus;
import co.yixiang.dozer.service.IGenerator;
import co.yixiang.exception.BadRequestException;
import co.yixiang.modules.system.domain.Dept;
import co.yixiang.modules.system.domain.Job;
import co.yixiang.modules.system.domain.RolesDepts;
import co.yixiang.modules.system.service.DeptService;
import co.yixiang.modules.system.service.dto.DeptDto;
import co.yixiang.modules.system.service.dto.DeptQueryCriteria;
import co.yixiang.modules.system.service.mapper.DeptMapper;
import co.yixiang.modules.system.service.mapper.JobMapper;
import co.yixiang.modules.system.service.mapper.RolesDeptsMapper;
import co.yixiang.utils.FileUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageInfo;
import lombok.AllArgsConstructor;
import org.springframework.data.domain.Pageable;
@ -54,6 +60,8 @@ public class DeptServiceImpl extends BaseServiceImpl<DeptMapper, Dept> implement
private final IGenerator generator;
private final DeptMapper deptMapper;
private final JobMapper jobMapper;
private final RolesDeptsMapper rolesDeptsMapper;
@Override
//@Cacheable
@ -152,6 +160,20 @@ public class DeptServiceImpl extends BaseServiceImpl<DeptMapper, Dept> implement
return map;
}
/**
* 删除部门
* @param deptIds
*/
@Override
public void delDepts(List<Long> deptIds){
int jobCount = jobMapper.selectCount(Wrappers.<Job>lambdaQuery().in(Job::getDeptId,deptIds));
int roleCount = rolesDeptsMapper.selectCount(Wrappers.<RolesDepts>lambdaQuery()
.in(RolesDepts::getDeptId,deptIds));
if(jobCount > 0) throw new BadRequestException( "所选部门中存在与岗位关联,请取消关联后再试");
if(roleCount > 0) throw new BadRequestException( "所选部门中存在与角色关联,请取消关联后再试");
this.removeByIds(deptIds);
}
/**
* 获取待删除的部门
*