mirror of https://gitee.com/stylefeng/roses
【8.1.0】【user-role】更新用户信息管理界面,用户绑定角色返回系统角色
parent
dbbd5d172d
commit
d9bbcb3fbf
|
@ -19,6 +19,14 @@ public interface SysUserRoleServiceApi {
|
|||
*/
|
||||
List<Long> getUserRoleIdList(Long userId);
|
||||
|
||||
/**
|
||||
* 获取用户系统级别的角色,用在用户管理界面,分配角色时使用
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2024/1/17 22:35
|
||||
*/
|
||||
Set<Long> getUserSystemRoleIdList(Long userId);
|
||||
|
||||
/**
|
||||
* 获取用户的当前所在机构的所有角色id列表
|
||||
*
|
||||
|
|
|
@ -25,10 +25,7 @@ import org.springframework.stereotype.Service;
|
|||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cn.stylefeng.roses.kernel.sys.modular.user.constants.UserConstants.UPDATE_USER_ROLE_EVENT;
|
||||
|
@ -147,6 +144,28 @@ public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUs
|
|||
return sysUserRoleList.stream().map(SysUserRole::getRoleId).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Long> getUserSystemRoleIdList(Long userId) {
|
||||
if (userId == null) {
|
||||
return new LinkedHashSet<>();
|
||||
}
|
||||
|
||||
// 先从缓存查找用户的角色
|
||||
List<SysUserRole> cachedRoleList = userRoleCache.get(userId.toString());
|
||||
if (ObjectUtil.isNotEmpty(cachedRoleList)) {
|
||||
return cachedRoleList.stream().filter(i -> RoleTypeEnum.SYSTEM_ROLE.getCode().equals(i.getRoleType())).map(SysUserRole::getRoleId).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
List<SysUserRole> sysUserRoleList = this.dbGetUserTotalRoleList(userId);
|
||||
|
||||
// 查询结果缓存起来
|
||||
if (ObjectUtil.isNotEmpty(sysUserRoleList)) {
|
||||
userRoleCache.put(userId.toString(), sysUserRoleList, SysConstants.DEFAULT_SYS_CACHE_TIMEOUT_SECONDS);
|
||||
}
|
||||
|
||||
return sysUserRoleList.stream().filter(i -> RoleTypeEnum.SYSTEM_ROLE.getCode().equals(i.getRoleType())).map(SysUserRole::getRoleId).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> getUserRoleIdListCurrentCompany(Long userId, Long orgId) {
|
||||
|
||||
|
@ -208,10 +227,12 @@ public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUs
|
|||
}
|
||||
|
||||
// 2. 所有系统角色id集合
|
||||
Set<Long> systemRoleIdList = roleResults.stream().filter(i -> i.getRoleType().equals(RoleTypeEnum.SYSTEM_ROLE.getCode())).map(SysRoleDTO::getRoleId).collect(Collectors.toSet());
|
||||
Set<Long> systemRoleIdList = roleResults.stream().filter(i -> i.getRoleType().equals(RoleTypeEnum.SYSTEM_ROLE.getCode())).map(SysRoleDTO::getRoleId)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
// 3. 所有当前公司角色id集合
|
||||
Set<Long> currentCompanyRoleIdList = roleResults.stream().filter(i -> i.getRoleType().equals(RoleTypeEnum.COMPANY_ROLE.getCode())).map(SysRoleDTO::getRoleId).collect(Collectors.toSet());
|
||||
Set<Long> currentCompanyRoleIdList = roleResults.stream().filter(i -> i.getRoleType().equals(RoleTypeEnum.COMPANY_ROLE.getCode())).map(SysRoleDTO::getRoleId)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
LambdaQueryWrapper<SysUserRole> queryWrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
|
|
|
@ -218,8 +218,8 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||
sysUser.setUserOrgDTOList(userOrgList);
|
||||
|
||||
// 获取用户的角色信息
|
||||
List<Long> userRoleIdList = sysUserRoleService.getUserRoleIdList(sysUser.getUserId());
|
||||
sysUser.setRoleIdList(userRoleIdList);
|
||||
Set<Long> userRoleIdList = sysUserRoleService.getUserSystemRoleIdList(sysUser.getUserId());
|
||||
sysUser.setRoleIdList(new ArrayList<>(userRoleIdList));
|
||||
|
||||
// 获取用户证书信息
|
||||
List<SysUserCertificateResponse> userCertificateList = sysUserCertificateService.getUserCertificateList(sysUser.getUserId());
|
||||
|
|
Loading…
Reference in New Issue