use of com.besscroft.aurora.mall.common.entity.AuthResource in project aurora-mall by besscroft.
the class ResourceServiceTest method addResource.
@Test
void addResource() {
AuthResource authResource = AuthResource.builder().name("测试资源").url("baodu.com").description("测试专用资源").createTime(LocalDateTime.now()).categoryId(1L).build();
boolean b = resourceService.addResource(authResource);
assertTrue(b, "新增资源失败!");
}
use of com.besscroft.aurora.mall.common.entity.AuthResource in project aurora-mall by besscroft.
the class ResourceServiceTest method getResourceById.
@Test
void getResourceById() throws JsonProcessingException {
Long resourceId = 1L;
AuthResource resource = resourceService.getResourceById(resourceId);
assertNotNull(resource, "获取资源详情失败!");
LOGGER.info("资源详情:{}", objectMapper.writeValueAsString(resource));
}
use of com.besscroft.aurora.mall.common.entity.AuthResource in project aurora-mall by besscroft.
the class ResourceServiceImpl method getAllResourceTree.
@Override
public List<ResourceParam> getAllResourceTree() {
List<ResourceParam> list = new ArrayList<>();
List<AuthResourceSort> resourceSorts = authResourceSortMapper.selectList(new QueryWrapper<>());
resourceSorts.forEach(r -> {
ResourceParam resourceParam = new ResourceParam();
QueryWrapper<AuthResource> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("category_id", r.getId());
List<AuthResource> resources = this.baseMapper.selectList(queryWrapper);
resourceParam.setName(r.getCategoryName());
resourceParam.setDisabled(true);
resourceParam.setChildren(resources);
list.add(resourceParam);
});
return list;
}
use of com.besscroft.aurora.mall.common.entity.AuthResource 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;
}
use of com.besscroft.aurora.mall.common.entity.AuthResource in project aurora-mall by besscroft.
the class ResourceServiceTest method updateResource.
@Test
void updateResource() {
AuthResource authResource = AuthResource.builder().id(1000L).name("测试资源").url("baodu.com").description("测试专用资源").createTime(LocalDateTime.now()).categoryId(1L).build();
boolean b = resourceService.updateResource(authResource);
assertTrue(b, "更新资源失败!");
}
Aggregations