Search in sources :

Example 21 with SysRole

use of com.ruoyi.system.api.domain.SysRole in project RuoYi-Cloud-Plus by JavaLionLi.

the class SysUserController method getInfo.

/**
 * 根据用户编号获取详细信息
 */
@ApiOperation("根据用户编号获取详细信息")
@SaCheckPermission("system:user:query")
@GetMapping(value = { "/", "/{userId}" })
public R<Map<String, Object>> getInfo(@PathVariable(value = "userId", required = false) Long userId) {
    userService.checkUserDataScope(userId);
    Map<String, Object> ajax = new HashMap<>();
    List<SysRole> roles = roleService.selectRoleAll();
    ajax.put("roles", LoginHelper.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
    ajax.put("posts", postService.selectPostAll());
    if (ObjectUtil.isNotNull(userId)) {
        SysUser sysUser = userService.selectUserById(userId);
        ajax.put("user", sysUser);
        ajax.put("postIds", postService.selectPostListByUserId(userId));
        ajax.put("roleIds", sysUser.getRoles().stream().map(SysRole::getRoleId).collect(Collectors.toList()));
    }
    return R.ok(ajax);
}
Also used : R(com.ruoyi.common.core.domain.R) Log(com.ruoyi.common.log.annotation.Log) SysRole(com.ruoyi.system.api.domain.SysRole) java.util(java.util) SysUserImportListener(com.ruoyi.system.listener.SysUserImportListener) BCrypt(cn.dev33.satoken.secure.BCrypt) ObjectUtil(cn.hutool.core.util.ObjectUtil) RequiredArgsConstructor(lombok.RequiredArgsConstructor) ArrayUtils(org.apache.commons.lang3.ArrayUtils) BeanUtil(cn.hutool.core.bean.BeanUtil) TableDataInfo(com.ruoyi.common.mybatis.core.page.TableDataInfo) LoginHelper(com.ruoyi.common.satoken.utils.LoginHelper) ApiOperation(io.swagger.annotations.ApiOperation) BaseController(com.ruoyi.common.core.web.controller.BaseController) ExcelUtil(com.ruoyi.common.excel.utils.ExcelUtil) SysUserExportVo(com.ruoyi.system.domain.vo.SysUserExportVo) ISysRoleService(com.ruoyi.system.service.ISysRoleService) SysDept(com.ruoyi.system.api.domain.SysDept) Api(io.swagger.annotations.Api) BusinessType(com.ruoyi.common.log.enums.BusinessType) ISysPermissionService(com.ruoyi.system.service.ISysPermissionService) SysUserImportVo(com.ruoyi.system.domain.vo.SysUserImportVo) Validated(org.springframework.validation.annotation.Validated) ApiImplicitParam(io.swagger.annotations.ApiImplicitParam) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) StringUtils(com.ruoyi.common.core.utils.StringUtils) SysUser(com.ruoyi.system.api.domain.SysUser) Collectors(java.util.stream.Collectors) ISysUserService(com.ruoyi.system.service.ISysUserService) ExcelResult(com.ruoyi.common.excel.core.ExcelResult) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) MultipartFile(org.springframework.web.multipart.MultipartFile) UserConstants(com.ruoyi.common.core.constant.UserConstants) ISysPostService(com.ruoyi.system.service.ISysPostService) PageQuery(com.ruoyi.common.mybatis.core.page.PageQuery) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) SaCheckPermission(cn.dev33.satoken.annotation.SaCheckPermission) SysUser(com.ruoyi.system.api.domain.SysUser) SysRole(com.ruoyi.system.api.domain.SysRole) ApiOperation(io.swagger.annotations.ApiOperation) SaCheckPermission(cn.dev33.satoken.annotation.SaCheckPermission)

Example 22 with SysRole

use of com.ruoyi.system.api.domain.SysRole in project RuoYi-Cloud-Plus by JavaLionLi.

the class SysUserController method authRole.

/**
 * 根据用户编号获取授权角色
 */
@ApiOperation("根据用户编号获取授权角色")
@SaCheckPermission("system:user:query")
@GetMapping("/authRole/{userId}")
public R<Map<String, Object>> authRole(@PathVariable("userId") Long userId) {
    Map<String, Object> ajax = new HashMap<>();
    SysUser user = userService.selectUserById(userId);
    List<SysRole> roles = roleService.selectRolesByUserId(userId);
    ajax.put("user", user);
    ajax.put("roles", LoginHelper.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
    return R.ok(ajax);
}
Also used : R(com.ruoyi.common.core.domain.R) Log(com.ruoyi.common.log.annotation.Log) SysRole(com.ruoyi.system.api.domain.SysRole) java.util(java.util) SysUserImportListener(com.ruoyi.system.listener.SysUserImportListener) BCrypt(cn.dev33.satoken.secure.BCrypt) ObjectUtil(cn.hutool.core.util.ObjectUtil) RequiredArgsConstructor(lombok.RequiredArgsConstructor) ArrayUtils(org.apache.commons.lang3.ArrayUtils) BeanUtil(cn.hutool.core.bean.BeanUtil) TableDataInfo(com.ruoyi.common.mybatis.core.page.TableDataInfo) LoginHelper(com.ruoyi.common.satoken.utils.LoginHelper) ApiOperation(io.swagger.annotations.ApiOperation) BaseController(com.ruoyi.common.core.web.controller.BaseController) ExcelUtil(com.ruoyi.common.excel.utils.ExcelUtil) SysUserExportVo(com.ruoyi.system.domain.vo.SysUserExportVo) ISysRoleService(com.ruoyi.system.service.ISysRoleService) SysDept(com.ruoyi.system.api.domain.SysDept) Api(io.swagger.annotations.Api) BusinessType(com.ruoyi.common.log.enums.BusinessType) ISysPermissionService(com.ruoyi.system.service.ISysPermissionService) SysUserImportVo(com.ruoyi.system.domain.vo.SysUserImportVo) Validated(org.springframework.validation.annotation.Validated) ApiImplicitParam(io.swagger.annotations.ApiImplicitParam) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) StringUtils(com.ruoyi.common.core.utils.StringUtils) SysUser(com.ruoyi.system.api.domain.SysUser) Collectors(java.util.stream.Collectors) ISysUserService(com.ruoyi.system.service.ISysUserService) ExcelResult(com.ruoyi.common.excel.core.ExcelResult) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) MultipartFile(org.springframework.web.multipart.MultipartFile) UserConstants(com.ruoyi.common.core.constant.UserConstants) ISysPostService(com.ruoyi.system.service.ISysPostService) PageQuery(com.ruoyi.common.mybatis.core.page.PageQuery) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) SaCheckPermission(cn.dev33.satoken.annotation.SaCheckPermission) SysUser(com.ruoyi.system.api.domain.SysUser) SysRole(com.ruoyi.system.api.domain.SysRole) ApiOperation(io.swagger.annotations.ApiOperation) SaCheckPermission(cn.dev33.satoken.annotation.SaCheckPermission)

Example 23 with SysRole

use of com.ruoyi.system.api.domain.SysRole in project RuoYi-Cloud-Plus by JavaLionLi.

the class SysRoleServiceImpl method deleteRoleByIds.

/**
 * 批量删除角色信息
 *
 * @param roleIds 需要删除的角色ID
 * @return 结果
 */
@Override
@Transactional(rollbackFor = Exception.class)
public int deleteRoleByIds(Long[] roleIds) {
    for (Long roleId : roleIds) {
        checkRoleAllowed(new SysRole(roleId));
        checkRoleDataScope(roleId);
        SysRole role = selectRoleById(roleId);
        if (countUserRoleByRoleId(roleId) > 0) {
            throw new ServiceException(String.format("%1$s已分配,不能删除", role.getRoleName()));
        }
    }
    List<Long> ids = Arrays.asList(roleIds);
    // 删除角色与菜单关联
    roleMenuMapper.delete(new LambdaQueryWrapper<SysRoleMenu>().in(SysRoleMenu::getRoleId, ids));
    // 删除角色与部门关联
    roleDeptMapper.delete(new LambdaQueryWrapper<SysRoleDept>().in(SysRoleDept::getRoleId, ids));
    return baseMapper.deleteBatchIds(ids);
}
Also used : ServiceException(com.ruoyi.common.core.exception.ServiceException) SysRole(com.ruoyi.system.api.domain.SysRole) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) Transactional(org.springframework.transaction.annotation.Transactional)

Example 24 with SysRole

use of com.ruoyi.system.api.domain.SysRole in project RuoYi-Cloud-Plus by JavaLionLi.

the class SysRoleServiceImpl method selectRolesByUserId.

/**
 * 根据用户ID查询角色
 *
 * @param userId 用户ID
 * @return 角色列表
 */
@Override
public List<SysRole> selectRolesByUserId(Long userId) {
    List<SysRole> userRoles = baseMapper.selectRolePermissionByUserId(userId);
    List<SysRole> roles = selectRoleAll();
    for (SysRole role : roles) {
        for (SysRole userRole : userRoles) {
            if (role.getRoleId().longValue() == userRole.getRoleId().longValue()) {
                role.setFlag(true);
                break;
            }
        }
    }
    return roles;
}
Also used : SysRole(com.ruoyi.system.api.domain.SysRole)

Aggregations

SysRole (com.ruoyi.system.api.domain.SysRole)24 UserConstants (com.ruoyi.common.core.constant.UserConstants)6 R (com.ruoyi.common.core.domain.R)6 ServiceException (com.ruoyi.common.core.exception.ServiceException)6 StringUtils (com.ruoyi.common.core.utils.StringUtils)6 BaseController (com.ruoyi.common.core.web.controller.BaseController)6 Log (com.ruoyi.common.log.annotation.Log)6 BusinessType (com.ruoyi.common.log.enums.BusinessType)6 SysUser (com.ruoyi.system.api.domain.SysUser)6 ISysPermissionService (com.ruoyi.system.service.ISysPermissionService)6 ISysPostService (com.ruoyi.system.service.ISysPostService)6 ISysRoleService (com.ruoyi.system.service.ISysRoleService)6 ISysUserService (com.ruoyi.system.service.ISysUserService)6 IOException (java.io.IOException)6 Collectors (java.util.stream.Collectors)6 HttpServletResponse (javax.servlet.http.HttpServletResponse)6 ArrayUtils (org.apache.commons.lang3.ArrayUtils)6 Validated (org.springframework.validation.annotation.Validated)6 MultipartFile (org.springframework.web.multipart.MultipartFile)6 ExcelUtil (com.ruoyi.common.core.utils.poi.ExcelUtil)4