系统支持切换单位来实时过滤业务数据的查询条件
This commit is contained in:
@@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.system.controller.admin.dept;
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.framework.tenant.core.aop.DeptVisitIgnore;
|
||||
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptListReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptRespVO;
|
||||
@@ -71,12 +72,22 @@ public class DeptController {
|
||||
|
||||
@GetMapping(value = {"/list-all-simple", "/simple-list"})
|
||||
@Operation(summary = "获取部门精简信息列表", description = "只包含被开启的部门,主要用于前端的下拉选项")
|
||||
@DeptVisitIgnore
|
||||
public CommonResult<List<DeptSimpleRespVO>> getSimpleDeptList() {
|
||||
List<DeptDO> list = deptService.getDeptList(
|
||||
new DeptListReqVO().setStatus(CommonStatusEnum.ENABLE.getStatus()));
|
||||
return success(BeanUtils.toBean(list, DeptSimpleRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping(value = {"/list-simple", "/simple-dept-list"})
|
||||
@Operation(summary = "获取部门精简信息列表(不包含当前用户归属部门的上级部门)", description = "只包含被开启的部门,主要用于前端的下拉选项")
|
||||
@DeptVisitIgnore
|
||||
public CommonResult<List<DeptSimpleRespVO>> getNoParentSimpleDeptList() {
|
||||
List<DeptDO> list = deptService.getNoParentDeptList(
|
||||
new DeptListReqVO().setStatus(CommonStatusEnum.ENABLE.getStatus()));
|
||||
return success(BeanUtils.toBean(list, DeptSimpleRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得部门信息")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
|
||||
@@ -59,6 +59,7 @@ public interface DeptService {
|
||||
* @return 部门列表
|
||||
*/
|
||||
List<DeptDO> getDeptList(DeptListReqVO reqVO);
|
||||
List<DeptDO> getNoParentDeptList(DeptListReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 获得指定编号的部门 Map
|
||||
|
||||
@@ -19,9 +19,11 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserDeptId;
|
||||
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
@@ -169,6 +171,28 @@ public class DeptServiceImpl implements DeptService {
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeptDO> getNoParentDeptList(DeptListReqVO reqVO){
|
||||
List<DeptDO> list = deptMapper.selectList(reqVO);
|
||||
// 循环过滤掉当前用户归属部门的所有上级部门
|
||||
Long loginUserDeptId = getLoginUserDeptId();
|
||||
Set<Long> parentIds = new HashSet<>();
|
||||
Map<Long, DeptDO> deptMap = list.stream().collect(Collectors.toMap(DeptDO::getId, d -> d));
|
||||
Long currentId = loginUserDeptId;
|
||||
while (currentId != null && !DeptDO.PARENT_ID_ROOT.equals(currentId)) {
|
||||
DeptDO dept = deptMap.get(currentId);
|
||||
if (dept == null) break;
|
||||
Long parentId = dept.getParentId();
|
||||
if (parentId == null || DeptDO.PARENT_ID_ROOT.equals(parentId)) break;
|
||||
parentIds.add(parentId);
|
||||
currentId = parentId;
|
||||
}
|
||||
// 过滤掉所有上级部门
|
||||
return list.stream()
|
||||
.filter(dept -> !parentIds.contains(dept.getId()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeptDO> getChildDeptList(Collection<Long> ids) {
|
||||
List<DeptDO> children = new LinkedList<>();
|
||||
|
||||
Reference in New Issue
Block a user