mirror of https://gitee.com/stylefeng/roses
【8.1.0】【user-role】更新用户角色关联表,改为机构id
parent
720d4837ba
commit
dbbd5d172d
|
@ -20,12 +20,12 @@ public interface SysUserRoleServiceApi {
|
||||||
List<Long> getUserRoleIdList(Long userId);
|
List<Long> getUserRoleIdList(Long userId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户的当前所在公司的所有角色id列表
|
* 获取用户的当前所在机构的所有角色id列表
|
||||||
*
|
*
|
||||||
* @author fengshuonan
|
* @author fengshuonan
|
||||||
* @since 2024-01-17 16:24
|
* @since 2024-01-17 16:24
|
||||||
*/
|
*/
|
||||||
List<Long> getUserRoleIdListCurrentCompany(Long userId, Long companyId);
|
List<Long> getUserRoleIdListCurrentCompany(Long userId, Long orgId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据角色id找到角色对应的用户id集合
|
* 根据角色id找到角色对应的用户id集合
|
||||||
|
|
|
@ -61,9 +61,9 @@ public class SysRoleDTO {
|
||||||
private Integer roleType;
|
private Integer roleType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 角色所属公司id,当角色类型为20时传此值
|
* 角色所属机构id,当角色类型为20时传此值
|
||||||
*/
|
*/
|
||||||
@ChineseDescription("角色所属公司id,当角色类型为20时传此值")
|
@ChineseDescription("角色所属机构id,当角色类型为20时传此值")
|
||||||
private Long roleCompanyId;
|
private Long roleOrgId;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,10 +49,10 @@ public class SysUserRole extends BaseEntity {
|
||||||
private Integer roleType;
|
private Integer roleType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 角色所属公司id
|
* 用户所属机构id
|
||||||
*/
|
*/
|
||||||
@TableField(value = "role_company_id")
|
@TableField(value = "role_org_id")
|
||||||
@ChineseDescription("角色所属公司id")
|
@ChineseDescription("用户所属机构id")
|
||||||
private Long roleCompanyId;
|
private Long roleOrgId;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -148,12 +148,12 @@ public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUs
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Long> getUserRoleIdListCurrentCompany(Long userId, Long companyId) {
|
public List<Long> getUserRoleIdListCurrentCompany(Long userId, Long orgId) {
|
||||||
|
|
||||||
// 先从缓存查找用户的角色
|
// 先从缓存查找用户的角色
|
||||||
List<SysUserRole> cachedRoleList = userRoleCache.get(userId.toString());
|
List<SysUserRole> cachedRoleList = userRoleCache.get(userId.toString());
|
||||||
if (ObjectUtil.isNotEmpty(cachedRoleList)) {
|
if (ObjectUtil.isNotEmpty(cachedRoleList)) {
|
||||||
return this.getUserCompanyPermissionRole(cachedRoleList, companyId);
|
return this.getUserCompanyPermissionRole(cachedRoleList, orgId);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<SysUserRole> sysUserRoleList = this.dbGetUserTotalRoleList(userId);
|
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);
|
userRoleCache.put(userId.toString(), sysUserRoleList, SysConstants.DEFAULT_SYS_CACHE_TIMEOUT_SECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.getUserCompanyPermissionRole(sysUserRoleList, companyId);
|
return this.getUserCompanyPermissionRole(sysUserRoleList, orgId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -249,34 +249,36 @@ public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUs
|
||||||
private List<SysUserRole> dbGetUserTotalRoleList(Long userId) {
|
private List<SysUserRole> dbGetUserTotalRoleList(Long userId) {
|
||||||
LambdaQueryWrapper<SysUserRole> wrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<SysUserRole> wrapper = new LambdaQueryWrapper<>();
|
||||||
wrapper.eq(SysUserRole::getUserId, userId);
|
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);
|
return this.list(wrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前用户登录公司的角色id集合
|
* 获取当前用户登录机构的角色id集合
|
||||||
* <p>
|
* <p>
|
||||||
* 从参数中找到当前用户登录公司的 + 用户基本的角色集合
|
* 从参数中找到当前用户登录身份机构的 + 用户基本的角色集合
|
||||||
*
|
*
|
||||||
* @author fengshuonan
|
* @author fengshuonan
|
||||||
* @since 2024-01-17 16:16
|
* @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. 先获取最基本的用户角色,不分公司的,每个人都有的角色
|
// 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());
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
// 没传当前公司id,则只返回最基本的角色
|
// 没传当前公司id,则只返回最基本的角色
|
||||||
if (ObjectUtil.isEmpty(userCurrentCompanyId)) {
|
if (ObjectUtil.isEmpty(userCurrentOrgId)) {
|
||||||
return new ArrayList<>(baseRoleIdList);
|
return new ArrayList<>(baseRoleIdList);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. 获取用户当前登录公司下的角色id集合
|
// 2. 获取用户当前登录公司下的角色id集合
|
||||||
Set<Long> currentCompanyRoleIdList = paramRoles.stream()
|
Set<Long> currentCompanyRoleIdList = paramRoles.stream()
|
||||||
.filter(i -> RoleTypeEnum.COMPANY_ROLE.getCode().equals(i.getRoleType())
|
.filter(i -> RoleTypeEnum.COMPANY_ROLE.getCode().equals(i.getRoleType())
|
||||||
&& i.getRoleCompanyId() != null
|
&& i.getRoleOrgId() != null
|
||||||
&& i.getRoleCompanyId().equals(userCurrentCompanyId))
|
&& i.getRoleOrgId().equals(userCurrentOrgId))
|
||||||
.map(SysUserRole::getRoleId)
|
.map(SysUserRole::getRoleId)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
|
@ -311,7 +313,7 @@ public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUs
|
||||||
for (SysRoleDTO sysRoleDTO : sysRoleDTOList) {
|
for (SysRoleDTO sysRoleDTO : sysRoleDTOList) {
|
||||||
if (sysRoleDTO.getRoleId().equals(newRoleId)) {
|
if (sysRoleDTO.getRoleId().equals(newRoleId)) {
|
||||||
sysUserRole.setRoleType(sysRoleDTO.getRoleType());
|
sysUserRole.setRoleType(sysRoleDTO.getRoleType());
|
||||||
sysUserRole.setRoleCompanyId(sysRoleDTO.getRoleCompanyId());
|
sysUserRole.setRoleOrgId(sysRoleDTO.getRoleOrgId());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -261,11 +261,14 @@ public class UserIndexInfoService {
|
||||||
List<Long> roleIdList = null;
|
List<Long> roleIdList = null;
|
||||||
|
|
||||||
// 获取用户当前公司下的角色集合
|
// 获取用户当前公司下的角色集合
|
||||||
List<Long> userCurrentCompanyList = userIndexInfo.getUserOrgInfoList().stream().filter(IndexUserOrgInfo::getCurrentSelectFlag).map(IndexUserOrgInfo::getCompanyId).collect(Collectors.toList());
|
List<Long> userCurrentOrgList = userIndexInfo.getUserOrgInfoList().stream()
|
||||||
if (ObjectUtil.isEmpty(userCurrentCompanyList)) {
|
.filter(IndexUserOrgInfo::getCurrentSelectFlag)
|
||||||
|
.map(IndexUserOrgInfo::getOrgId)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
if (ObjectUtil.isEmpty(userCurrentOrgList)) {
|
||||||
roleIdList = sysUserRoleServiceApi.getUserRoleIdListCurrentCompany(userId, null);
|
roleIdList = sysUserRoleServiceApi.getUserRoleIdListCurrentCompany(userId, null);
|
||||||
} else {
|
} else {
|
||||||
roleIdList = sysUserRoleServiceApi.getUserRoleIdListCurrentCompany(userId, userCurrentCompanyList.get(0));
|
roleIdList = sysUserRoleServiceApi.getUserRoleIdListCurrentCompany(userId, userCurrentOrgList.get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ObjectUtil.isEmpty(roleIdList)) {
|
if (ObjectUtil.isEmpty(roleIdList)) {
|
||||||
|
|
|
@ -5,4 +5,4 @@ ADD COLUMN `role_company_id` bigint NULL COMMENT '角色所属公司id,当角
|
||||||
|
|
||||||
ALTER TABLE `sys_user_role`
|
ALTER TABLE `sys_user_role`
|
||||||
ADD COLUMN `role_type` tinyint NOT NULL DEFAULT 10 COMMENT '角色类型:10-系统角色,15-业务角色,20-公司角色' AFTER `role_id`,
|
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`;
|
Loading…
Reference in New Issue