fix(admin): 修复管理员用户管理中的部门查询和用户信息显示问题

- 在部门查询条件中添加hasChild=true限制,确保只查询有子部门的部门
- 为convert和getChildren方法添加adminUsers参数以支持用户信息转换
- 实现在AdminUserVO中显示创建者和更新者的用户名信息
- 更新用户信息转换逻辑以正确映射创建者和更新者姓名
This commit is contained in:
曹鹏飞 2026-06-02 15:25:09 +08:00
parent df7c40912c
commit fb0294fe97
2 changed files with 42 additions and 12 deletions

View File

@ -146,6 +146,7 @@ public class AdminUserController extends ControllerBase {
.update();
VUtils.trueThrowBusinessError(departmentService.lambdaQuery()
.eq(TBaseDepartment::getId, request.getDepartmentId())
.eq(TBaseDepartment::isHasChild,true)
.eq(TBaseDepartment::isHasManager, true)
.exists()
)

View File

@ -93,6 +93,7 @@ public class AdminUserServiceImpl extends ServiceImpl<AdminUserMapper, AdminUser
public AdminUser add(AccountAddRequest request) {
VUtils.trueThrowBusinessError(departmentService.lambdaQuery()
.eq(TBaseDepartment::getId, request.getDepartmentId())
.eq(TBaseDepartment::isHasChild,true)
.eq(TBaseDepartment::isHasManager, true)
.exists()
)
@ -491,8 +492,8 @@ public class AdminUserServiceImpl extends ServiceImpl<AdminUserMapper, AdminUser
if (CollectionUtil.isEmpty(roots)) {
return Collections.emptyList();
}
List<AdminUserVO> rootUserVOS = convert(roots, department, positions, roleMaps, roles);
getChildren(rootUserVOS.get(0), departments, adminUsers, positions, roleMaps, roles);
List<AdminUserVO> rootUserVOS = convert(roots, department, positions, roleMaps, roles, adminUsers);
getChildren(rootUserVOS.get(0), departments, adminUsers, positions, roleMaps, roles, adminUsers);
for (int index = 1, size = rootUserVOS.size(); index < size; index++) {
rootUserVOS.get(index).setChildren(rootUserVOS.get(0).getChildren());
}
@ -522,8 +523,8 @@ public class AdminUserServiceImpl extends ServiceImpl<AdminUserMapper, AdminUser
.filter(u -> rootDepartments.stream()
.map(TBaseDepartment::getId).anyMatch(dt -> Objects.equals(u.getDepartmentId(), dt))
).collect(Collectors.toList());
List<AdminUserVO> rootUserVOS = convert1(rootUsers, departments, positions, roleMaps, roles);
rootUserVOS.forEach(uvo -> getChildren1(uvo, departments, adminUsers, searchUsers, positions, roleMaps, roles));
List<AdminUserVO> rootUserVOS = convert1(rootUsers, departments, positions, roleMaps, roles, adminUsers);
rootUserVOS.forEach(uvo -> getChildren1(uvo, departments, adminUsers, searchUsers, positions, roleMaps, roles, adminUsers));
return rootUserVOS;
}
}
@ -538,7 +539,7 @@ public class AdminUserServiceImpl extends ServiceImpl<AdminUserMapper, AdminUser
}
private void getChildren1(AdminUserVO user, List<TBaseDepartment> departments, List<AdminUser> users, List<AdminUser> searchUsers
, List<TBasePosition> positions, List<AdminUserRoleMap> roleMaps, List<AdminRole> roles) {
, List<TBasePosition> positions, List<AdminUserRoleMap> roleMaps, List<AdminRole> roles, List<AdminUser> adminUsers) {
List<TBaseDepartment> cdepartments = departments.stream()
.filter(d -> Objects.equals(d.getDeptParentId(), user.getDepartmentId()))
.collect(Collectors.toList());
@ -553,9 +554,9 @@ public class AdminUserServiceImpl extends ServiceImpl<AdminUserMapper, AdminUser
.collect(Collectors.toList());
}
if (CollectionUtil.isNotEmpty(csers)) {
List<AdminUserVO> cuserVOS = convert(csers, department, positions, roleMaps, roles);
List<AdminUserVO> cuserVOS = convert(csers, department, positions, roleMaps, roles, adminUsers);
user.getChildren().addAll(cuserVOS);
getChildren(cuserVOS.get(0), departments, users, positions, roleMaps, roles);
getChildren(cuserVOS.get(0), departments, users, positions, roleMaps, roles, adminUsers);
for (int index = 1, size = cuserVOS.size(); index < size; index++) {
cuserVOS.get(index).setChildren(cuserVOS.get(0).getChildren());
}
@ -576,10 +577,24 @@ public class AdminUserServiceImpl extends ServiceImpl<AdminUserMapper, AdminUser
}
private List<AdminUserVO> convert1(List<AdminUser> users, List<TBaseDepartment> departments, List<TBasePosition> positions
, List<AdminUserRoleMap> roleMaps, List<AdminRole> roles) {
, List<AdminUserRoleMap> roleMaps, List<AdminRole> roles, List<AdminUser> adminUsers) {
return users.stream()
.map(user -> {
AdminUserVO vo = Convert.convert(AdminUserVO.class, user);
vo.setCreateBy(
adminUsers.stream()
.filter(u -> Objects.equals(u.getId(), user.getCreateBy()))
.findFirst()
.map(AdminUser::getUserName)
.orElse("")
);
vo.setUpdateBy(
adminUsers.stream()
.filter(u -> Objects.equals(u.getId(), user.getUpdateBy()))
.findFirst()
.map(AdminUser::getUserName)
.orElse("")
);
TBasePosition position = positions.stream()
.filter(p -> Objects.equals(p.getId(), user.getTitleId()))
.findFirst()
@ -605,10 +620,24 @@ public class AdminUserServiceImpl extends ServiceImpl<AdminUserMapper, AdminUser
}
private List<AdminUserVO> convert(List<AdminUser> users, TBaseDepartment department, List<TBasePosition> positions
, List<AdminUserRoleMap> roleMaps, List<AdminRole> roles) {
, List<AdminUserRoleMap> roleMaps, List<AdminRole> roles, List<AdminUser> adminUsers) {
return users.stream()
.map(user -> {
AdminUserVO vo = Convert.convert(AdminUserVO.class, user);
vo.setCreateBy(
adminUsers.stream()
.filter(u -> Objects.equals(u.getId(), user.getCreateBy()))
.findFirst()
.map(AdminUser::getUserName)
.orElse("")
);
vo.setUpdateBy(
adminUsers.stream()
.filter(u -> Objects.equals(u.getId(), user.getUpdateBy()))
.findFirst()
.map(AdminUser::getUserName)
.orElse("")
);
TBasePosition position = positions.stream()
.filter(p -> Objects.equals(p.getId(), user.getTitleId()))
.findFirst()
@ -630,7 +659,7 @@ public class AdminUserServiceImpl extends ServiceImpl<AdminUserMapper, AdminUser
}
private void getChildren(AdminUserVO user, List<TBaseDepartment> departments, List<AdminUser> users
, List<TBasePosition> positions, List<AdminUserRoleMap> roleMaps, List<AdminRole> roles) {
, List<TBasePosition> positions, List<AdminUserRoleMap> roleMaps, List<AdminRole> roles, List<AdminUser> adminUsers) {
List<TBaseDepartment> cdepartments = departments.stream()
.filter(d -> Objects.equals(d.getDeptParentId(), user.getDepartmentId()))
.collect(Collectors.toList());
@ -640,9 +669,9 @@ public class AdminUserServiceImpl extends ServiceImpl<AdminUserMapper, AdminUser
.filter(u -> Objects.equals(u.getDepartmentId(), department.getId()))
.collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(csers)) {
List<AdminUserVO> cuserVOS = convert(csers, department, positions, roleMaps, roles);
List<AdminUserVO> cuserVOS = convert(csers, department, positions, roleMaps, roles, adminUsers);
user.getChildren().addAll(cuserVOS);
getChildren(cuserVOS.get(0), departments, users, positions, roleMaps, roles);
getChildren(cuserVOS.get(0), departments, users, positions, roleMaps, roles, adminUsers);
for (int index = 1, size = cuserVOS.size(); index < size; index++) {
cuserVOS.get(index).setChildren(cuserVOS.get(0).getChildren());
}