feat: 当前部门出现在最顶部
This commit is contained in:
parent
ac57acc4b2
commit
c667ab6f30
|
@ -14,7 +14,6 @@ import com.ruoyi.database.domain.ApprovalProcess;
|
|||
import com.ruoyi.database.domain.BaseAddressInfo;
|
||||
import com.ruoyi.database.domain.BusinessTripApproval;
|
||||
import com.ruoyi.database.domain.dto.ApprovaltBusinessDto;
|
||||
import com.ruoyi.database.domain.dto.ApprovaltDto;
|
||||
import com.ruoyi.database.domain.gwglLog;
|
||||
import com.ruoyi.database.service.ApprovalProcessService;
|
||||
import com.ruoyi.database.service.BaseAddressInfoService;
|
||||
|
@ -22,7 +21,6 @@ import com.ruoyi.database.service.BusinessTripApprovalService;
|
|||
import com.ruoyi.database.service.gwglLogService;
|
||||
import com.ruoyi.system.service.ISysDeptService;
|
||||
import com.ruoyi.system.service.ISysUserService;
|
||||
import com.sun.org.apache.xpath.internal.operations.Bool;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
@ -148,7 +146,7 @@ public class BusinessTripApprovalController extends BaseController {
|
|||
@GetMapping("/userList")
|
||||
@ApiOperation("查询用户人员列表")
|
||||
public AjaxResult applyList() {
|
||||
List<SysUser> sysUsers = sysUserService.selectList();
|
||||
/*List<SysUser> sysUsers = sysUserService.selectList();
|
||||
List<SysDept> sysDepts = sysDeptService.selectDeptList(new SysDept());
|
||||
sysDepts = sysDepts.stream()
|
||||
.filter(dept -> dept.getDeptId() != 131000) // 过滤掉id为131000的部门
|
||||
|
@ -158,7 +156,103 @@ public class BusinessTripApprovalController extends BaseController {
|
|||
for (SysUser user : sysUsers) {
|
||||
deptUsersMap.computeIfAbsent(user.getDeptId(), k -> new ArrayList<>()).add(user);
|
||||
}
|
||||
return AjaxResult.success(buildTree(depts, deptUsersMap));
|
||||
return AjaxResult.success(buildTree(depts, deptUsersMap));*/
|
||||
|
||||
// 获取当前用户ID
|
||||
// 获取当前用户ID
|
||||
Long userId = getLoginUser().getUser().getUserId();
|
||||
// 查询用户和部门
|
||||
List<SysUser> sysUsers = sysUserService.selectList();
|
||||
List<SysDept> sysDepts = sysDeptService.selectDeptList(new SysDept());
|
||||
sysDepts = sysDepts.stream()
|
||||
.filter(dept -> dept.getDeptId() != 131000) // 过滤掉id为131000的部门
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 构建部门树
|
||||
List<SysDept> depts = sysDeptService.buildDeptTree(sysDepts);
|
||||
|
||||
// 查找当前用户所在部门
|
||||
SysUser currentUser = sysUsers.stream()
|
||||
.filter(user -> user.getUserId().equals(userId))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
Long currentDeptId = currentUser != null ? currentUser.getDeptId() : null;
|
||||
|
||||
// 构建用户映射
|
||||
Map<Long, List<SysUser>> deptUsersMap = new HashMap<>();
|
||||
for (SysUser user : sysUsers) {
|
||||
deptUsersMap.computeIfAbsent(user.getDeptId(), k -> new ArrayList<>()).add(user);
|
||||
}
|
||||
|
||||
// 构建树结构
|
||||
List<TreeSelect> treeList = new ArrayList<>();
|
||||
|
||||
// 在最外层顶部添加当前部门资源(如果找到)
|
||||
if (currentDeptId != null) {
|
||||
SysDept currentDept = findDeptById(depts, currentDeptId);
|
||||
if (currentDept != null) {
|
||||
TreeSelect currentDeptNode = buildDeptNode(currentDept, deptUsersMap);
|
||||
treeList.add(currentDeptNode);
|
||||
}
|
||||
}
|
||||
|
||||
// 保持原有部门树结构不变
|
||||
treeList.addAll(buildTree(depts, deptUsersMap));
|
||||
|
||||
return AjaxResult.success(treeList);
|
||||
}
|
||||
|
||||
private TreeSelect buildDeptNode(SysDept dept, Map<Long, List<SysUser>> deptUsersMap) {
|
||||
TreeSelect treeSelect = new TreeSelect();
|
||||
treeSelect.setId(dept.getDeptId());
|
||||
treeSelect.setLabel(dept.getDeptName());
|
||||
|
||||
// 添加部门下的用户
|
||||
List<TreeSelect> children = new ArrayList<>();
|
||||
List<SysUser> users = deptUsersMap.getOrDefault(dept.getDeptId(), Collections.emptyList());
|
||||
for (SysUser user : users) {
|
||||
TreeSelect userNode = new TreeSelect();
|
||||
userNode.setLabel(user.getNickName());
|
||||
userNode.setId(user.getUserId());
|
||||
userNode.setDictId(dept.getDeptId());
|
||||
userNode.setDictName(dept.getDeptName());
|
||||
children.add(userNode);
|
||||
}
|
||||
|
||||
// 递归添加所有子部门
|
||||
for (SysDept child : dept.getChildren()) {
|
||||
children.add(buildDeptNode(child, deptUsersMap));
|
||||
}
|
||||
|
||||
if (!children.isEmpty()) {
|
||||
treeSelect.setChildren(children);
|
||||
}
|
||||
|
||||
return treeSelect;
|
||||
}
|
||||
private SysDept findDeptById(List<SysDept> depts, Long deptId) {
|
||||
for (SysDept dept : depts) {
|
||||
SysDept found = findDeptInTree(dept, deptId);
|
||||
if (found != null) {
|
||||
return found;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// 辅助方法:在部门树中递归查找指定ID的部门
|
||||
private SysDept findDeptInTree(SysDept dept, Long deptId) {
|
||||
if (dept.getDeptId().equals(deptId)) {
|
||||
return dept;
|
||||
}
|
||||
for (SysDept child : dept.getChildren()) {
|
||||
SysDept found = findDeptInTree(child, deptId);
|
||||
if (found != null) {
|
||||
return found;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue