禅道#950问题修复

This commit is contained in:
gaoqr
2025-04-02 18:31:07 +08:00
parent 6469607b6f
commit 61acde27fa
3 changed files with 70 additions and 1 deletions
@@ -39,6 +39,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception;
@@ -133,8 +134,16 @@ public class UserController {
public CommonResult<PageResult<UserRespVO>> getDivideUser(@Valid UserPageReqVO pageReqVO) {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
return getUserPage(pageReqVO);
CommonResult<PageResult<UserRespVO>> userPage = getUserPage(pageReqVO);
List<UserRespVO> userList = userPage.getCheckedData().getList();
// 获取所有无效部门
Set<Long> allInvalidDeptIds = deptService.getAllInvalidDeptIds(pageReqVO.getOrganId());
if (CollUtil.isNotEmpty(allInvalidDeptIds)) {
userList.removeIf(u -> allInvalidDeptIds.contains(u.getDeptId()));
}
return success(new PageResult<>(userList, Long.valueOf(userList.size())));
}
@@ -120,4 +120,12 @@ public interface DeptService {
* @return
*/
List<DeptDO> removeUnowndDept(List<DeptDO> deptDOS);
/**
* 获取所有无效部门id
*
* @param organId
* @return
*/
Set<Long> getAllInvalidDeptIds(Long organId);
}
@@ -2,11 +2,14 @@ package com.cf.imes.module.system.service.dept;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.cf.imes.framework.common.enums.CommonStatusEnum;
import com.cf.imes.framework.common.exception.util.ServiceExceptionUtil;
import com.cf.imes.framework.common.util.json.JsonUtils;
import com.cf.imes.framework.common.util.object.BeanUtils;
import com.cf.imes.framework.datapermission.core.annotation.DataPermission;
import com.cf.imes.framework.organ.core.context.OrganContextHolder;
import com.cf.imes.framework.security.core.LoginUser;
import com.cf.imes.framework.security.core.util.SecurityFrameworkUtils;
import com.cf.imes.module.system.controller.admin.dept.vo.dept.DeptListReqVO;
@@ -420,4 +423,53 @@ public class DeptServiceImpl implements DeptService {
topLevelCache.put(deptDO.getId(), false);
return false; // 默认返回false
}
@Override
public Set<Long> getAllInvalidDeptIds(Long organId) {
if (ObjectUtils.isNull(organId)) {
organId = OrganContextHolder.getOrganId();
}
// 一次性加载当前 organ 下的所有部门
List<DeptDO> allDepts = deptMapper.selectList(
new LambdaQueryWrapper<DeptDO>().eq(DeptDO::getOrganId, organId)
);
// 构建 parentId → 子部门列表 的内存映射关系
Map<Long, List<DeptDO>> deptTree = allDepts.stream()
.collect(Collectors.groupingBy(DeptDO::getParentId));
Set<Long> invalidDeptIds = new HashSet<>();
// 获取所有根部门(parentId=0
List<DeptDO> topDepts = deptTree.getOrDefault(0L, Collections.emptyList());
for (DeptDO topDept : topDepts) {
collectInvalidDeptIdsOptimized(topDept,
topDept.getStatus().equals(CommonStatusEnum.DISABLE.getStatus()),
deptTree,
invalidDeptIds
);
}
return invalidDeptIds;
}
/**
* 优化后的递归方法(内存操作,无数据库查询)
*/
private void collectInvalidDeptIdsOptimized(DeptDO currentDept,
boolean parentClosed,
Map<Long, List<DeptDO>> deptTree,
Set<Long> result) {
boolean currentClosed = parentClosed ||
currentDept.getStatus().equals(CommonStatusEnum.DISABLE.getStatus());
if (currentClosed) {
result.add(currentDept.getId());
}
// 直接从内存映射中获取子部门(无需查数据库)
List<DeptDO> children = deptTree.getOrDefault(currentDept.getId(), Collections.emptyList());
for (DeptDO child : children) {
collectInvalidDeptIdsOptimized(child, currentClosed, deptTree, result);
}
}
}