完成用户的角色分配,妥妥的。睡觉~
This commit is contained in:
@@ -59,6 +59,22 @@ public interface SysPermissionService {
|
||||
*/
|
||||
void assignRoleMenu(Long roleId, Set<Long> menuIds);
|
||||
|
||||
/**
|
||||
* 获得用户拥有的角色编号集合
|
||||
*
|
||||
* @param userId 用户编号
|
||||
* @return 角色编号集合
|
||||
*/
|
||||
Set<Long> listUserRoleIs(Long userId);
|
||||
|
||||
/**
|
||||
* 设置用户角色
|
||||
*
|
||||
* @param userId 角色编号
|
||||
* @param roleIds 角色编号集合
|
||||
*/
|
||||
void assignUserRole(Long userId, Set<Long> roleIds);
|
||||
|
||||
/**
|
||||
* 设置角色的数据权限
|
||||
*
|
||||
|
||||
@@ -6,6 +6,7 @@ import cn.iocoder.dashboard.modules.system.controller.permission.vo.role.SysRole
|
||||
import cn.iocoder.dashboard.modules.system.controller.permission.vo.role.SysRoleUpdateReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission.SysRoleDO;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -30,6 +31,14 @@ public interface SysRoleService {
|
||||
*/
|
||||
SysRoleDO getRoleFromCache(Long id);
|
||||
|
||||
/**
|
||||
* 获得角色列表
|
||||
*
|
||||
* @param statuses 筛选的状态。允许空,空时不筛选
|
||||
* @return 角色列表
|
||||
*/
|
||||
List<SysRoleDO> listRoles(@Nullable Collection<Integer> statuses);
|
||||
|
||||
/**
|
||||
* 获得角色数组,从缓存中
|
||||
*
|
||||
|
||||
@@ -142,6 +142,29 @@ public class SysPermissionServiceImpl implements SysPermissionService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Long> listUserRoleIs(Long userId) {
|
||||
return CollectionUtils.convertSet(userRoleMapper.selectListByUserId(userId),
|
||||
SysUserRoleDO::getRoleId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void assignUserRole(Long userId, Set<Long> roleIds) {
|
||||
// 获得角色拥有角色编号
|
||||
Set<Long> dbRoleIds = CollectionUtils.convertSet(userRoleMapper.selectListByUserId(userId),
|
||||
SysUserRoleDO::getRoleId);
|
||||
// 计算新增和删除的角色编号
|
||||
Collection<Long> createRoleIds = CollUtil.subtract(roleIds, dbRoleIds);
|
||||
Collection<Long> deleteMenuIds = CollUtil.subtract(dbRoleIds, roleIds);
|
||||
// 执行新增和删除。对于已经授权的角色,不用做任何处理
|
||||
if (!CollectionUtil.isEmpty(createRoleIds)) {
|
||||
userRoleMapper.insertList(userId, createRoleIds);
|
||||
}
|
||||
if (!CollectionUtil.isEmpty(deleteMenuIds)) {
|
||||
userRoleMapper.deleteListByUserIdAndRoleIdIds(userId, deleteMenuIds);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void assignRoleDataScope(Long roleId, Integer dataScope, Set<Long> dataScopeDeptIds) {
|
||||
roleService.updateRoleDataScope(roleId, dataScope, dataScopeDeptIds);
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
@@ -71,6 +72,11 @@ public class SysRoleServiceImpl implements SysRoleService {
|
||||
return roleCache.get(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysRoleDO> listRoles(@Nullable Collection<Integer> statuses) {
|
||||
return roleMapper.selectListByStatus(statuses);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysRoleDO> listRolesFromCache(Collection<Long> ids) {
|
||||
if (CollectionUtil.isEmpty(ids)) {
|
||||
|
||||
Reference in New Issue
Block a user