Search in sources :

Example 41 with SysRole

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

the class DataScopeAspect method dataScopeFilter.

/**
 * 数据范围过滤
 *
 * @param joinPoint 切点
 * @param user 用户
 * @param userAlias 别名
 */
public static void dataScopeFilter(JoinPoint joinPoint, SysUser user, String deptAlias, String userAlias) {
    StringBuilder sqlString = new StringBuilder();
    for (SysRole role : user.getRoles()) {
        String dataScope = role.getDataScope();
        if (DATA_SCOPE_ALL.equals(dataScope)) {
            sqlString = new StringBuilder();
            break;
        } else if (DATA_SCOPE_CUSTOM.equals(dataScope)) {
            sqlString.append(StringUtils.format(" OR {}.dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id = {} ) ", deptAlias, role.getRoleId()));
        } else if (DATA_SCOPE_DEPT.equals(dataScope)) {
            sqlString.append(StringUtils.format(" OR {}.dept_id = {} ", deptAlias, user.getDeptId()));
        } else if (DATA_SCOPE_DEPT_AND_CHILD.equals(dataScope)) {
            sqlString.append(StringUtils.format(" OR {}.dept_id IN ( SELECT dept_id FROM sys_dept WHERE dept_id = {} or find_in_set( {} , ancestors ) )", deptAlias, user.getDeptId(), user.getDeptId()));
        } else if (DATA_SCOPE_SELF.equals(dataScope)) {
            if (StringUtils.isNotBlank(userAlias)) {
                sqlString.append(StringUtils.format(" OR {}.user_id = {} ", userAlias, user.getUserId()));
            } else {
                // 数据权限为仅本人且没有userAlias别名不查询任何数据
                sqlString.append(" OR 1=0 ");
            }
        }
    }
    if (StringUtils.isNotBlank(sqlString.toString())) {
        Object params = joinPoint.getArgs()[0];
        if (StringUtils.isNotNull(params) && params instanceof BaseEntity) {
            BaseEntity baseEntity = (BaseEntity) params;
            baseEntity.getParams().put(DATA_SCOPE, " AND (" + sqlString.substring(4) + ")");
        }
    }
}
Also used : SysRole(com.ruoyi.common.core.domain.entity.SysRole) BaseEntity(com.ruoyi.common.core.domain.BaseEntity)

Example 42 with SysRole

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

the class DataScopeAspect method dataScopeFilter.

/**
 * 数据范围过滤
 *
 * @param joinPoint 切点
 * @param user 用户
 * @param userAlias 别名
 */
public static void dataScopeFilter(JoinPoint joinPoint, SysUser user, String deptAlias, String userAlias) {
    StringBuilder sqlString = new StringBuilder();
    for (SysRole role : user.getRoles()) {
        String dataScope = role.getDataScope();
        if (DATA_SCOPE_ALL.equals(dataScope)) {
            sqlString = new StringBuilder();
            break;
        } else if (DATA_SCOPE_CUSTOM.equals(dataScope)) {
            sqlString.append(StringUtils.format(" OR {}.dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id = {} ) ", deptAlias, role.getRoleId()));
        } else if (DATA_SCOPE_DEPT.equals(dataScope)) {
            sqlString.append(StringUtils.format(" OR {}.dept_id = {} ", deptAlias, user.getDeptId()));
        } else if (DATA_SCOPE_DEPT_AND_CHILD.equals(dataScope)) {
            sqlString.append(StringUtils.format(" OR {}.dept_id IN ( SELECT dept_id FROM sys_dept WHERE dept_id = {} or find_in_set( {} , ancestors ) )", deptAlias, user.getDeptId(), user.getDeptId()));
        } else if (DATA_SCOPE_SELF.equals(dataScope)) {
            if (StringUtils.isNotBlank(userAlias)) {
                sqlString.append(StringUtils.format(" OR {}.user_id = {} ", userAlias, user.getUserId()));
            } else {
                // 数据权限为仅本人且没有userAlias别名不查询任何数据
                sqlString.append(" OR 1=0 ");
            }
        }
    }
    if (StringUtils.isNotBlank(sqlString.toString())) {
        Object params = joinPoint.getArgs()[0];
        if (StringUtils.isNotNull(params) && params instanceof BaseEntity) {
            BaseEntity baseEntity = (BaseEntity) params;
            baseEntity.getParams().put(DATA_SCOPE, " AND (" + sqlString.substring(4) + ")");
        }
    }
}
Also used : SysRole(com.ruoyi.common.core.domain.entity.SysRole) BaseEntity(com.ruoyi.common.core.domain.BaseEntity)

Example 43 with SysRole

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

the class SysRoleServiceImpl method selectRolePermissionByUserId.

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

Example 44 with SysRole

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

the class SysRoleServiceImpl method checkRoleNameUnique.

/**
 * 校验角色名称是否唯一
 *
 * @param role 角色信息
 * @return 结果
 */
@Override
public String checkRoleNameUnique(SysRole role) {
    Long roleId = StringUtils.isNull(role.getRoleId()) ? -1L : role.getRoleId();
    SysRole info = roleMapper.checkRoleNameUnique(role.getRoleName());
    if (StringUtils.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue()) {
        return UserConstants.NOT_UNIQUE;
    }
    return UserConstants.UNIQUE;
}
Also used : 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