【8.1.0】【user-role】更新用户角色关联表,改为机构id

pull/60/head
fengshuonan 2024-01-17 21:58:13 +08:00
parent 720d4837ba
commit dbbd5d172d
6 changed files with 30 additions and 25 deletions

View File

@ -20,12 +20,12 @@ public interface SysUserRoleServiceApi {
List<Long> getUserRoleIdList(Long userId);
/**
* id
* id
*
* @author fengshuonan
* @since 2024-01-17 16:24
*/
List<Long> getUserRoleIdListCurrentCompany(Long userId, Long companyId);
List<Long> getUserRoleIdListCurrentCompany(Long userId, Long orgId);
/**
* idid

View File

@ -61,9 +61,9 @@ public class SysRoleDTO {
private Integer roleType;
/**
* id20
* id20
*/
@ChineseDescription("角色所属公司id当角色类型为20时传此值")
private Long roleCompanyId;
@ChineseDescription("角色所属机构id当角色类型为20时传此值")
private Long roleOrgId;
}

View File

@ -49,10 +49,10 @@ public class SysUserRole extends BaseEntity {
private Integer roleType;
/**
* id
* id
*/
@TableField(value = "role_company_id")
@ChineseDescription("角色所属公司id")
private Long roleCompanyId;
@TableField(value = "role_org_id")
@ChineseDescription("用户所属机构id")
private Long roleOrgId;
}

View File

@ -148,12 +148,12 @@ public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUs
}
@Override
public List<Long> getUserRoleIdListCurrentCompany(Long userId, Long companyId) {
public List<Long> getUserRoleIdListCurrentCompany(Long userId, Long orgId) {
// 先从缓存查找用户的角色
List<SysUserRole> cachedRoleList = userRoleCache.get(userId.toString());
if (ObjectUtil.isNotEmpty(cachedRoleList)) {
return this.getUserCompanyPermissionRole(cachedRoleList, companyId);
return this.getUserCompanyPermissionRole(cachedRoleList, orgId);
}
List<SysUserRole> sysUserRoleList = this.dbGetUserTotalRoleList(userId);
@ -163,7 +163,7 @@ public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUs
userRoleCache.put(userId.toString(), sysUserRoleList, SysConstants.DEFAULT_SYS_CACHE_TIMEOUT_SECONDS);
}
return this.getUserCompanyPermissionRole(sysUserRoleList, companyId);
return this.getUserCompanyPermissionRole(sysUserRoleList, orgId);
}
@Override
@ -249,34 +249,36 @@ public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUs
private List<SysUserRole> dbGetUserTotalRoleList(Long userId) {
LambdaQueryWrapper<SysUserRole> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(SysUserRole::getUserId, userId);
wrapper.select(SysUserRole::getRoleId, SysUserRole::getRoleCompanyId, SysUserRole::getRoleType);
wrapper.select(SysUserRole::getRoleId, SysUserRole::getRoleOrgId, SysUserRole::getRoleType);
return this.list(wrapper);
}
/**
* id
* id
* <p>
* +
* +
*
* @author fengshuonan
* @since 2024-01-17 16:16
*/
private List<Long> getUserCompanyPermissionRole(List<SysUserRole> paramRoles, Long userCurrentCompanyId) {
private List<Long> getUserCompanyPermissionRole(List<SysUserRole> paramRoles, Long userCurrentOrgId) {
// 1. 先获取最基本的用户角色,不分公司的,每个人都有的角色
Set<Long> baseRoleIdList = paramRoles.stream().filter(i -> RoleTypeEnum.SYSTEM_ROLE.getCode().equals(i.getRoleType()) && i.getRoleCompanyId() == null).map(SysUserRole::getRoleId)
Set<Long> baseRoleIdList = paramRoles.stream()
.filter(i -> RoleTypeEnum.SYSTEM_ROLE.getCode().equals(i.getRoleType()) && i.getRoleOrgId() == null)
.map(SysUserRole::getRoleId)
.collect(Collectors.toSet());
// 没传当前公司id则只返回最基本的角色
if (ObjectUtil.isEmpty(userCurrentCompanyId)) {
if (ObjectUtil.isEmpty(userCurrentOrgId)) {
return new ArrayList<>(baseRoleIdList);
}
// 2. 获取用户当前登录公司下的角色id集合
Set<Long> currentCompanyRoleIdList = paramRoles.stream()
.filter(i -> RoleTypeEnum.COMPANY_ROLE.getCode().equals(i.getRoleType())
&& i.getRoleCompanyId() != null
&& i.getRoleCompanyId().equals(userCurrentCompanyId))
&& i.getRoleOrgId() != null
&& i.getRoleOrgId().equals(userCurrentOrgId))
.map(SysUserRole::getRoleId)
.collect(Collectors.toSet());
@ -311,7 +313,7 @@ public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUs
for (SysRoleDTO sysRoleDTO : sysRoleDTOList) {
if (sysRoleDTO.getRoleId().equals(newRoleId)) {
sysUserRole.setRoleType(sysRoleDTO.getRoleType());
sysUserRole.setRoleCompanyId(sysRoleDTO.getRoleCompanyId());
sysUserRole.setRoleOrgId(sysRoleDTO.getRoleOrgId());
break;
}
}

View File

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

View File

@ -5,4 +5,4 @@ ADD COLUMN `role_company_id` bigint NULL COMMENT '角色所属公司id当角
ALTER TABLE `sys_user_role`
ADD COLUMN `role_type` tinyint NOT NULL DEFAULT 10 COMMENT '角色类型10-系统角色15-业务角色20-公司角色' AFTER `role_id`,
ADD COLUMN `role_company_id` bigint NULL DEFAULT NULL COMMENT '角色所属公司id' AFTER `role_type`;
ADD COLUMN `role_org_id` bigint NULL DEFAULT NULL COMMENT '用户所属机构id' AFTER `role_type`;