|
|
@@ -32,9 +32,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -170,6 +168,17 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser>
|
|
|
List<SysDept> allDepts = sysDeptMapper.selectDeptList(null);
|
|
|
Map<Long, String> deptNameMap = allDepts.stream()
|
|
|
.collect(Collectors.toMap(SysDept::getId, SysDept::getDeptName, (a, b) -> a));
|
|
|
+ // 批量查询用户关联的角色 ID
|
|
|
+ List<Long> userIds = users.stream().map(SysUser::getId).collect(Collectors.toList());
|
|
|
+ Map<Long, List<Long>> userRoleIdMap = new HashMap<>();
|
|
|
+ if (!userIds.isEmpty()) {
|
|
|
+ List<SysUserRole> userRoles = sysUserRoleMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<SysUserRole>().in(SysUserRole::getUserId, userIds));
|
|
|
+ for (SysUserRole ur : userRoles) {
|
|
|
+ userRoleIdMap.computeIfAbsent(ur.getUserId(), k -> new ArrayList<>()).add(ur.getRoleId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
List<UserDTO> dtoList = users.stream().map(user -> {
|
|
|
UserDTO dto = new UserDTO();
|
|
|
dto.setId(user.getId());
|
|
|
@@ -184,6 +193,8 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser>
|
|
|
dto.setWecomUserId(user.getWecomUserId());
|
|
|
dto.setWecomRemindEnabled(user.getWecomRemindEnabled());
|
|
|
dto.setCreateTime(user.getCreateTime());
|
|
|
+ List<Long> roleIds = userRoleIdMap.getOrDefault(user.getId(), Collections.emptyList());
|
|
|
+ dto.setRoleIds(roleIds);
|
|
|
return dto;
|
|
|
}).collect(Collectors.toList());
|
|
|
Page<UserDTO> resultPage = new Page<>(userPage.getCurrent(), userPage.getSize(), userPage.getTotal());
|
|
|
@@ -300,6 +311,19 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser>
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
+ public void assignRoles(Long userId, List<Long> roleIds) {
|
|
|
+ sysUserRoleMapper.delete(
|
|
|
+ new LambdaQueryWrapper<SysUserRole>().eq(SysUserRole::getUserId, userId));
|
|
|
+ if (roleIds != null && !roleIds.isEmpty()) {
|
|
|
+ for (Long roleId : roleIds) {
|
|
|
+ SysUserRole userRole = new SysUserRole();
|
|
|
+ userRole.setUserId(userId);
|
|
|
+ userRole.setRoleId(roleId);
|
|
|
+ sysUserRoleMapper.insert(userRole);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public void changePassword(Long userId, String oldPassword, String newPassword) {
|
|
|
if (userId == null) {
|
|
|
throw new BusinessException("用户ID不能为空");
|