Search in sources :

Example 26 with SysRole

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

the class SysRoleServiceImpl method selectRolePermissionByUserId.

/**
 * 根据用户ID查询权限
 *
 * @param userId 用户ID
 * @return 权限列表
 */
@Override
public Set<String> selectRolePermissionByUserId(Long userId) {
    List<SysRole> perms = baseMapper.selectRolePermissionByUserId(userId);
    Set<String> permsSet = new HashSet<>();
    for (SysRole perm : perms) {
        if (ObjectUtil.isNotNull(perm)) {
            permsSet.addAll(Arrays.asList(perm.getRoleKey().trim().split(",")));
        }
    }
    return permsSet;
}
Also used : SysRole(com.ruoyi.common.core.domain.entity.SysRole)

Example 27 with SysRole

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

the class SysRoleServiceImpl method checkRoleDataScope.

/**
 * 校验角色是否有数据权限
 *
 * @param roleId 角色id
 */
@Override
public void checkRoleDataScope(Long roleId) {
    if (!LoginHelper.isAdmin()) {
        SysRole role = new SysRole();
        role.setRoleId(roleId);
        List<SysRole> roles = this.selectRoleList(role);
        if (CollUtil.isEmpty(roles)) {
            throw new ServiceException("没有权限访问角色数据!");
        }
    }
}
Also used : ServiceException(com.ruoyi.common.exception.ServiceException) SysRole(com.ruoyi.common.core.domain.entity.SysRole)

Example 28 with SysRole

use of com.ruoyi.common.core.domain.entity.SysRole in project RuoYi-Flowable-Plus by KonBAI-Q.

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)

Example 29 with SysRole

use of com.ruoyi.common.core.domain.entity.SysRole in project wumei-smart by kerwincui.

the class CategoryServiceImpl method insertCategory.

/**
 * 新增产品分类
 *
 * @param category 产品分类
 * @return 结果
 */
@Override
public int insertCategory(Category category) {
    SysUser user = getLoginUser().getUser();
    List<SysRole> roles = user.getRoles();
    if (roles == null || roles.size() == 0) {
        return 0;
    }
    // 系统管理员
    if (roles.stream().anyMatch(a -> a.getRoleKey().equals("admin"))) {
        category.setIsSys(1);
    }
    category.setTenantId(user.getUserId());
    category.setTenantName(user.getUserName());
    category.setCreateTime(DateUtils.getNowDate());
    return categoryMapper.insertCategory(category);
}
Also used : SysUser(com.ruoyi.common.core.domain.entity.SysUser) SysRole(com.ruoyi.common.core.domain.entity.SysRole)

Example 30 with SysRole

use of com.ruoyi.common.core.domain.entity.SysRole in project wumei-smart by kerwincui.

the class FirmwareServiceImpl method insertFirmware.

/**
 * 新增产品固件
 *
 * @param firmware 产品固件
 * @return 结果
 */
@Override
public int insertFirmware(Firmware firmware) {
    SysUser user = getLoginUser().getUser();
    List<SysRole> roles = user.getRoles();
    if (roles == null || roles.size() == 0) {
        return 0;
    }
    // 系统管理员
    if (roles.stream().anyMatch(a -> a.getRoleKey().equals("admin"))) {
        firmware.setIsSys(1);
    }
    firmware.setTenantId(user.getUserId());
    firmware.setTenantName(user.getUserName());
    firmware.setCreateTime(DateUtils.getNowDate());
    return firmwareMapper.insertFirmware(firmware);
}
Also used : SysUser(com.ruoyi.common.core.domain.entity.SysUser) SysRole(com.ruoyi.common.core.domain.entity.SysRole)

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