use of com.hccake.ballcat.system.model.entity.SysRole in project ballcat by ballcat-projects.
the class SysUserServiceImpl method findUserInfo.
/**
* 通过查用户的全部信息
* @param sysUser 用户
* @return 用户信息
*/
@Override
public UserInfoDTO findUserInfo(SysUser sysUser) {
UserInfoDTO userInfoDTO = new UserInfoDTO();
userInfoDTO.setSysUser(sysUser);
// 超级管理员拥有所有角色
List<SysRole> roleList;
if (adminUserChecker.isAdminUser(sysUser)) {
roleList = sysRoleService.list();
} else {
roleList = sysUserRoleService.listRoles(sysUser.getUserId());
}
// 设置角色标识
Set<String> roleCodes = new HashSet<>();
for (SysRole role : roleList) {
roleCodes.add(role.getCode());
}
userInfoDTO.setRoles(new HashSet<>(roleList));
userInfoDTO.setRoleCodes(roleCodes);
// 设置权限列表(permission)
Set<String> permissions = new HashSet<>();
Set<SysMenu> menus = new HashSet<>();
for (String roleCode : roleCodes) {
List<SysMenu> sysMenuList = sysMenuService.listByRoleCode(roleCode);
menus.addAll(sysMenuList);
List<String> permissionList = sysMenuList.stream().map(SysMenu::getPermission).filter(StrUtil::isNotEmpty).collect(Collectors.toList());
permissions.addAll(permissionList);
}
userInfoDTO.setMenus(menus);
userInfoDTO.setPermissions(permissions);
return userInfoDTO;
}
use of com.hccake.ballcat.system.model.entity.SysRole in project ballcat by ballcat-projects.
the class SysUserController method getUserRoleIds.
/**
* 获取用户 所拥有的角色ID
* @param userId userId
*/
@GetMapping("/scope/{userId}")
@PreAuthorize("@per.hasPermission('system:user:grant')")
public R<SysUserScope> getUserRoleIds(@PathVariable("userId") Integer userId) {
List<SysRole> roleList = sysUserRoleService.listRoles(userId);
List<String> roleCodes = new ArrayList<>();
if (CollectionUtil.isNotEmpty(roleList)) {
roleList.forEach(role -> roleCodes.add(role.getCode()));
}
SysUserScope sysUserScope = new SysUserScope();
sysUserScope.setRoleCodes(roleCodes);
return R.ok(sysUserScope);
}
use of com.hccake.ballcat.system.model.entity.SysRole in project ballcat by ballcat-projects.
the class SysRoleServiceImpl method removeById.
/**
* 通过角色ID,删除角色,并清空角色菜单缓存
* @param id 角色ID
* @return boolean
*/
@Override
@Transactional(rollbackFor = Exception.class)
public boolean removeById(Serializable id) {
SysRole role = getById(id);
sysRoleMenuService.deleteByRoleCode(role.getCode());
return SqlHelper.retBool(baseMapper.deleteById(id));
}
Aggregations