Search in sources :

Example 1 with RoleResourceRelation

use of com.besscroft.aurora.mall.common.model.RoleResourceRelation in project aurora-mall by besscroft.

the class ResourceServiceImpl method initRoleResourceMap.

@Override
public Map<String, List<String>> initRoleResourceMap() {
    Map<String, List<String>> RoleResourceMap = new TreeMap<>();
    List<AuthResource> authResourceList = this.baseMapper.selectAll();
    List<AuthRole> authRoleList = authRoleMapper.selectAll();
    List<RoleResourceRelation> roleResourceRelationList = roleResourceRelationMapper.selectAll();
    for (AuthResource resource : authResourceList) {
        Set<Long> roleIds = roleResourceRelationList.stream().filter(item -> item.getResourceId().equals(resource.getId())).map(RoleResourceRelation::getRoleId).collect(Collectors.toSet());
        List<String> roleNames = authRoleList.stream().filter(item -> roleIds.contains(item.getId())).map(item -> AuthConstants.AUTHORITY_PREFIX + item.getId() + "_" + item.getName()).collect(Collectors.toList());
        // key为访问路径/资源路径,value为角色
        RoleResourceMap.put("/" + applicationName + resource.getUrl(), roleNames);
    }
    redisTemplate.delete(AuthConstants.PERMISSION_RULES_KEY);
    redisTemplate.opsForHash().putAll(AuthConstants.PERMISSION_RULES_KEY, RoleResourceMap);
    return RoleResourceMap;
}
Also used : java.util(java.util) ResourceParam(com.besscroft.aurora.mall.admin.domain.param.ResourceParam) NotPermissionException(com.besscroft.aurora.mall.common.exception.NotPermissionException) RequiredArgsConstructor(lombok.RequiredArgsConstructor) LocalDateTime(java.time.LocalDateTime) RoleResourceRelationMapper(com.besscroft.aurora.mall.admin.mapper.RoleResourceRelationMapper) ResourceService(com.besscroft.aurora.mall.admin.service.ResourceService) Value(org.springframework.beans.factory.annotation.Value) RoleResourceRelation(com.besscroft.aurora.mall.common.model.RoleResourceRelation) Service(org.springframework.stereotype.Service) RedisTemplate(org.springframework.data.redis.core.RedisTemplate) AuthResourceSortMapper(com.besscroft.aurora.mall.admin.mapper.AuthResourceSortMapper) SystemConstants(com.besscroft.aurora.mall.common.constant.SystemConstants) AuthResourceSort(com.besscroft.aurora.mall.common.entity.AuthResourceSort) AuthRole(com.besscroft.aurora.mall.common.entity.AuthRole) ServiceImpl(com.baomidou.mybatisplus.extension.service.impl.ServiceImpl) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) AuthConstants(com.besscroft.aurora.mall.common.constant.AuthConstants) PageHelper(com.github.pagehelper.PageHelper) Collectors(java.util.stream.Collectors) AuthResource(com.besscroft.aurora.mall.common.entity.AuthResource) Slf4j(lombok.extern.slf4j.Slf4j) AuthRoleMapper(com.besscroft.aurora.mall.admin.mapper.AuthRoleMapper) AuthResourceMapper(com.besscroft.aurora.mall.admin.mapper.AuthResourceMapper) Transactional(org.springframework.transaction.annotation.Transactional) AuthRole(com.besscroft.aurora.mall.common.entity.AuthRole) AuthResource(com.besscroft.aurora.mall.common.entity.AuthResource) RoleResourceRelation(com.besscroft.aurora.mall.common.model.RoleResourceRelation)

Aggregations

QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)1 ServiceImpl (com.baomidou.mybatisplus.extension.service.impl.ServiceImpl)1 ResourceParam (com.besscroft.aurora.mall.admin.domain.param.ResourceParam)1 AuthResourceMapper (com.besscroft.aurora.mall.admin.mapper.AuthResourceMapper)1 AuthResourceSortMapper (com.besscroft.aurora.mall.admin.mapper.AuthResourceSortMapper)1 AuthRoleMapper (com.besscroft.aurora.mall.admin.mapper.AuthRoleMapper)1 RoleResourceRelationMapper (com.besscroft.aurora.mall.admin.mapper.RoleResourceRelationMapper)1 ResourceService (com.besscroft.aurora.mall.admin.service.ResourceService)1 AuthConstants (com.besscroft.aurora.mall.common.constant.AuthConstants)1 SystemConstants (com.besscroft.aurora.mall.common.constant.SystemConstants)1 AuthResource (com.besscroft.aurora.mall.common.entity.AuthResource)1 AuthResourceSort (com.besscroft.aurora.mall.common.entity.AuthResourceSort)1 AuthRole (com.besscroft.aurora.mall.common.entity.AuthRole)1 NotPermissionException (com.besscroft.aurora.mall.common.exception.NotPermissionException)1 RoleResourceRelation (com.besscroft.aurora.mall.common.model.RoleResourceRelation)1 PageHelper (com.github.pagehelper.PageHelper)1 LocalDateTime (java.time.LocalDateTime)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 RequiredArgsConstructor (lombok.RequiredArgsConstructor)1