部门增删改查
This commit is contained in:
parent
be4adbe00b
commit
d379f79869
@ -37,8 +37,8 @@ public class SysDeptController {
|
||||
/**
|
||||
* 根据部门编号获取详细信息
|
||||
*/
|
||||
@GetMapping(value = "/dept/{deptId}")
|
||||
public R<DeptVO> getInfo(@PathVariable Long deptId) {
|
||||
@GetMapping(value = "/dept/details/{deptId}")
|
||||
public R<DeptVO> getInfo(@PathVariable("deptId") Long deptId) {
|
||||
DeptVO dept = sysDeptService.getDeptInfo(deptId);
|
||||
return R.ok(dept);
|
||||
}
|
||||
@ -64,7 +64,7 @@ public class SysDeptController {
|
||||
/**
|
||||
* 修改部门
|
||||
*/
|
||||
@PutMapping("/dept/{deptId}")
|
||||
@PostMapping("/dept/{deptId}")
|
||||
public R<Void> edit(@PathVariable("deptId") Long deptId, @RequestBody UpdateDeptDTO updateCommand) {
|
||||
updateCommand.setDeptId(deptId);
|
||||
sysDeptService.updateDept(updateCommand);
|
||||
@ -74,8 +74,8 @@ public class SysDeptController {
|
||||
/**
|
||||
* 删除部门
|
||||
*/
|
||||
@DeleteMapping("/dept/{deptId}")
|
||||
public R<Void> remove(@PathVariable @NotNull Long deptId) {
|
||||
@PostMapping("/dept/del/{deptId}")
|
||||
public R<Void> remove(@PathVariable("deptId") @NotNull Long deptId) {
|
||||
sysDeptService.removeDept(deptId);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@ -14,9 +14,11 @@ import com.agileboot.system.dept.entity.SysDept;
|
||||
import com.agileboot.system.dept.mapper.SysDeptMapper;
|
||||
import com.agileboot.system.dept.service.ISysDeptService;
|
||||
import com.agileboot.system.dept.vo.DeptVO;
|
||||
import com.agileboot.system.user.service.ISysUserService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
@ -24,7 +26,11 @@ import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> implements ISysDeptService {
|
||||
|
||||
private final ISysUserService userService;
|
||||
|
||||
@Override
|
||||
public List<DeptVO> getDeptList(DeptQuery query) {
|
||||
List<SysDept> list = super.list(query.toQueryWrapper());
|
||||
@ -112,7 +118,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||
if (this.hasChildrenDept(entity.getDeptId(), null)) {
|
||||
throw new BizException(ErrorCode.Business.DEPT_EXIST_CHILD_DEPT_NOT_ALLOW_DELETE);
|
||||
}
|
||||
if (this.isDeptAssignedToUsers(entity.getDeptId())) {
|
||||
if (userService.checkDeptAssignedToUsers(entity.getDeptId())) {
|
||||
throw new BizException(ErrorCode.Business.DEPT_EXIST_LINK_USER_NOT_ALLOW_DELETE);
|
||||
}
|
||||
super.removeById(deptId);
|
||||
@ -144,10 +150,4 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||
);
|
||||
return super.exists(queryWrapper);
|
||||
}
|
||||
|
||||
private boolean isDeptAssignedToUsers(Long deptId) {
|
||||
LambdaQueryWrapper<SysDept> queryWrapper = Wrappers.lambdaQuery(SysDept.class)
|
||||
.eq(SysDept::getDeptId, deptId);
|
||||
return super.exists(queryWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,4 +38,6 @@ public interface ISysUserService {
|
||||
void updateBatchRoleId(Long roleId, List<Long> userIds);
|
||||
|
||||
void deleteBatchRoleId(List<Long> userIds);
|
||||
|
||||
boolean checkDeptAssignedToUsers(Long deptId);
|
||||
}
|
||||
|
||||
@ -191,4 +191,11 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
.in(SysUser::getUserId, userIds);
|
||||
super.update(updateWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkDeptAssignedToUsers(Long deptId) {
|
||||
LambdaQueryWrapper<SysUser> queryWrapper = Wrappers.lambdaQuery(SysUser.class)
|
||||
.eq(SysUser::getDeptId, deptId);
|
||||
return super.exists(queryWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user