【8.1.0】【role】更新登录用户获取角色的方法

pull/60/head
fengshuonan 2024-01-17 17:15:06 +08:00
parent 4192ca6b04
commit 8f2013dc8e
2 changed files with 14 additions and 6 deletions

View File

@ -153,10 +153,6 @@ public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUs
@Override
public List<Long> getUserRoleIdListCurrentCompany(Long userId, Long companyId) {
if (ObjectUtil.isEmpty(companyId)) {
return this.getUserRoleIdList(userId);
}
// 先从缓存查找用户的角色
List<SysUserRole> cachedRoleList = userRoleCache.get(userId.toString());
if (ObjectUtil.isNotEmpty(cachedRoleList)) {
@ -274,6 +270,11 @@ public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUs
Set<Long> baseRoleIdList = paramRoles.stream().filter(i -> RoleTypeEnum.SYSTEM_ROLE.getCode().equals(i.getRoleType()) && i.getRoleCompanyId() == null).map(SysUserRole::getRoleId)
.collect(Collectors.toSet());
// 没传当前公司id则只返回最基本的角色
if (ObjectUtil.isEmpty(userCurrentCompanyId)) {
return new ArrayList<>(baseRoleIdList);
}
// 2. 获取用户当前登录公司下的角色id集合
Set<Long> currentCompanyRoleIdList = paramRoles.stream()
.filter(i -> RoleTypeEnum.COMPANY_ROLE.getCode().equals(i.getRoleType())

View File

@ -258,8 +258,15 @@ public class UserIndexInfoService {
Long userId = loginUser.getUserId();
// 获取用户的角色集合
List<Long> roleIdList = sysUserRoleServiceApi.getUserRoleIdList(userId);
List<Long> roleIdList = null;
// 获取用户当前公司下的角色集合
List<Long> userCurrentCompanyList = userIndexInfo.getUserOrgInfoList().stream().filter(IndexUserOrgInfo::getCurrentSelectFlag).map(IndexUserOrgInfo::getCompanyId).collect(Collectors.toList());
if (ObjectUtil.isEmpty(userCurrentCompanyList)) {
roleIdList = sysUserRoleServiceApi.getUserRoleIdListCurrentCompany(userId, null);
} else {
roleIdList = sysUserRoleServiceApi.getUserRoleIdListCurrentCompany(userId, userCurrentCompanyList.get(0));
}
if (ObjectUtil.isEmpty(roleIdList)) {
userIndexInfo.setPermissionCodeList(new HashSet<>());