Search in sources :

Example 21 with SysRole

use of com.ruoyi.common.core.domain.entity.SysRole in project hocassian-media-matrix by hokaso.

the class SysRoleServiceImpl method deleteRoleByIds.

/**
 * 批量删除角色信息
 *
 * @param roleIds 需要删除的角色ID
 * @return 结果
 */
@Override
@Transactional
public int deleteRoleByIds(Long[] roleIds) {
    for (Long roleId : roleIds) {
        checkRoleAllowed(new SysRole(roleId));
        SysRole role = selectRoleById(roleId);
        if (countUserRoleByRoleId(roleId) > 0) {
            throw new CustomException(String.format("%1$s已分配,不能删除", role.getRoleName()));
        }
    }
    // 删除角色与菜单关联
    roleMenuMapper.deleteRoleMenu(roleIds);
    // 删除角色与部门关联
    roleDeptMapper.deleteRoleDept(roleIds);
    return roleMapper.deleteRoleByIds(roleIds);
}
Also used : SysRole(com.ruoyi.common.core.domain.entity.SysRole) CustomException(com.ruoyi.common.exception.CustomException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 22 with SysRole

use of com.ruoyi.common.core.domain.entity.SysRole in project hocassian-media-matrix by hokaso.

the class SysUserServiceImpl method selectUserRoleGroup.

/**
 * 查询用户所属角色组
 *
 * @param userName 用户名
 * @return 结果
 */
@Override
public String selectUserRoleGroup(String userName) {
    List<SysRole> list = roleMapper.selectRolesByUserName(userName);
    StringBuffer idsStr = new StringBuffer();
    for (SysRole role : list) {
        idsStr.append(role.getRoleName()).append(",");
    }
    if (StringUtils.isNotEmpty(idsStr.toString())) {
        return idsStr.substring(0, idsStr.length() - 1);
    }
    return idsStr.toString();
}
Also used : SysRole(com.ruoyi.common.core.domain.entity.SysRole)

Example 23 with SysRole

use of com.ruoyi.common.core.domain.entity.SysRole in project RuoYi-Vue-Plus by JavaLionLi.

the class SysUserController method getInfo.

/**
 * 根据用户编号获取详细信息
 */
@ApiOperation("根据用户编号获取详细信息")
@SaCheckPermission("system:user:query")
@GetMapping(value = { "/", "/{userId}" })
public R<Map<String, Object>> getInfo(@ApiParam("用户ID") @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) SysDept(com.ruoyi.common.core.domain.entity.SysDept) SysUser(com.ruoyi.common.core.domain.entity.SysUser) TableDataInfo(com.ruoyi.common.core.page.TableDataInfo) SysUserImportListener(com.ruoyi.system.listener.SysUserImportListener) BCrypt(cn.dev33.satoken.secure.BCrypt) ObjectUtil(cn.hutool.core.util.ObjectUtil) RequiredArgsConstructor(lombok.RequiredArgsConstructor) HashMap(java.util.HashMap) BeanUtil(cn.hutool.core.bean.BeanUtil) PageQuery(com.ruoyi.common.core.domain.PageQuery) ArrayList(java.util.ArrayList) SysUserExportVo(com.ruoyi.system.domain.vo.SysUserExportVo) StringUtils(com.ruoyi.common.utils.StringUtils) Map(java.util.Map) ISysRoleService(com.ruoyi.system.service.ISysRoleService) io.swagger.annotations(io.swagger.annotations) BaseController(com.ruoyi.common.core.controller.BaseController) SysUserImportVo(com.ruoyi.system.domain.vo.SysUserImportVo) Validated(org.springframework.validation.annotation.Validated) HttpServletResponse(javax.servlet.http.HttpServletResponse) LoginHelper(com.ruoyi.common.helper.LoginHelper) Collectors(java.util.stream.Collectors) BusinessType(com.ruoyi.common.enums.BusinessType) ISysUserService(com.ruoyi.system.service.ISysUserService) List(java.util.List) UserConstants(com.ruoyi.common.constant.UserConstants) Log(com.ruoyi.common.annotation.Log) ExcelUtil(com.ruoyi.common.utils.poi.ExcelUtil) ArrayUtil(cn.hutool.core.util.ArrayUtil) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) MultipartFile(org.springframework.web.multipart.MultipartFile) SysRole(com.ruoyi.common.core.domain.entity.SysRole) ISysPostService(com.ruoyi.system.service.ISysPostService) SaCheckPermission(cn.dev33.satoken.annotation.SaCheckPermission) ExcelResult(com.ruoyi.common.excel.ExcelResult) SysUser(com.ruoyi.common.core.domain.entity.SysUser) HashMap(java.util.HashMap) SysRole(com.ruoyi.common.core.domain.entity.SysRole) SaCheckPermission(cn.dev33.satoken.annotation.SaCheckPermission)

Example 24 with SysRole

use of com.ruoyi.common.core.domain.entity.SysRole in project RuoYi-Vue-Plus by JavaLionLi.

the class SysUserController method authRole.

/**
 * 根据用户编号获取授权角色
 */
@ApiOperation("根据用户编号获取授权角色")
@SaCheckPermission("system:user:query")
@GetMapping("/authRole/{userId}")
public R<Map<String, Object>> authRole(@ApiParam("用户ID") @PathVariable("userId") Long userId) {
    SysUser user = userService.selectUserById(userId);
    List<SysRole> roles = roleService.selectRolesByUserId(userId);
    Map<String, Object> ajax = new HashMap<>();
    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) SysDept(com.ruoyi.common.core.domain.entity.SysDept) SysUser(com.ruoyi.common.core.domain.entity.SysUser) TableDataInfo(com.ruoyi.common.core.page.TableDataInfo) SysUserImportListener(com.ruoyi.system.listener.SysUserImportListener) BCrypt(cn.dev33.satoken.secure.BCrypt) ObjectUtil(cn.hutool.core.util.ObjectUtil) RequiredArgsConstructor(lombok.RequiredArgsConstructor) HashMap(java.util.HashMap) BeanUtil(cn.hutool.core.bean.BeanUtil) PageQuery(com.ruoyi.common.core.domain.PageQuery) ArrayList(java.util.ArrayList) SysUserExportVo(com.ruoyi.system.domain.vo.SysUserExportVo) StringUtils(com.ruoyi.common.utils.StringUtils) Map(java.util.Map) ISysRoleService(com.ruoyi.system.service.ISysRoleService) io.swagger.annotations(io.swagger.annotations) BaseController(com.ruoyi.common.core.controller.BaseController) SysUserImportVo(com.ruoyi.system.domain.vo.SysUserImportVo) Validated(org.springframework.validation.annotation.Validated) HttpServletResponse(javax.servlet.http.HttpServletResponse) LoginHelper(com.ruoyi.common.helper.LoginHelper) Collectors(java.util.stream.Collectors) BusinessType(com.ruoyi.common.enums.BusinessType) ISysUserService(com.ruoyi.system.service.ISysUserService) List(java.util.List) UserConstants(com.ruoyi.common.constant.UserConstants) Log(com.ruoyi.common.annotation.Log) ExcelUtil(com.ruoyi.common.utils.poi.ExcelUtil) ArrayUtil(cn.hutool.core.util.ArrayUtil) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) MultipartFile(org.springframework.web.multipart.MultipartFile) SysRole(com.ruoyi.common.core.domain.entity.SysRole) ISysPostService(com.ruoyi.system.service.ISysPostService) SaCheckPermission(cn.dev33.satoken.annotation.SaCheckPermission) ExcelResult(com.ruoyi.common.excel.ExcelResult) SysUser(com.ruoyi.common.core.domain.entity.SysUser) HashMap(java.util.HashMap) SysRole(com.ruoyi.common.core.domain.entity.SysRole) SaCheckPermission(cn.dev33.satoken.annotation.SaCheckPermission)

Example 25 with SysRole

use of com.ruoyi.common.core.domain.entity.SysRole in project RuoYi-Vue-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.exception.ServiceException) SysRole(com.ruoyi.common.core.domain.entity.SysRole) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

SysRole (com.ruoyi.common.core.domain.entity.SysRole)44 SysUser (com.ruoyi.common.core.domain.entity.SysUser)15 Log (com.ruoyi.common.annotation.Log)9 UserConstants (com.ruoyi.common.constant.UserConstants)9 BaseController (com.ruoyi.common.core.controller.BaseController)9 TableDataInfo (com.ruoyi.common.core.page.TableDataInfo)9 BusinessType (com.ruoyi.common.enums.BusinessType)9 ServiceException (com.ruoyi.common.exception.ServiceException)9 StringUtils (com.ruoyi.common.utils.StringUtils)9 ExcelUtil (com.ruoyi.common.utils.poi.ExcelUtil)9 ISysPostService (com.ruoyi.system.service.ISysPostService)9 ISysRoleService (com.ruoyi.system.service.ISysRoleService)9 ISysUserService (com.ruoyi.system.service.ISysUserService)9 List (java.util.List)9 Collectors (java.util.stream.Collectors)9 Validated (org.springframework.validation.annotation.Validated)9 MultipartFile (org.springframework.web.multipart.MultipartFile)9 HttpServletResponse (javax.servlet.http.HttpServletResponse)8 SaCheckPermission (cn.dev33.satoken.annotation.SaCheckPermission)4 BCrypt (cn.dev33.satoken.secure.BCrypt)4