use of com.besscroft.aurora.mall.common.entity.AuthRole in project aurora-mall by besscroft.
the class RoleServiceTest method addRole.
@Test
void addRole() {
AuthRole role = AuthRole.builder().name("单元测试角色").description("单元测试专用").createTime(LocalDateTime.now()).status(0).sort(10L).del(1).build();
boolean b = roleService.addRole(role);
assertTrue(b, "新增角色失败!");
}
use of com.besscroft.aurora.mall.common.entity.AuthRole in project aurora-mall by besscroft.
the class RoleServiceTest method getRoleById.
@Test
void getRoleById() throws JsonProcessingException {
Long roleId = 1L;
AuthRole role = roleService.getRoleById(roleId);
assertNotNull(role, "获取角色详情失败!");
LOGGER.info("角色详情:{}", objectMapper.writeValueAsString(role));
}
use of com.besscroft.aurora.mall.common.entity.AuthRole 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.AuthRole in project aurora-mall by besscroft.
the class UserServiceImpl method loadUserByUsername.
@Override
public UserDto loadUserByUsername(String username) {
AuthUser authUser = this.baseMapper.selectAuthUserByUsername(username);
if (authUser != null) {
List<AuthRole> authRoles = authRoleMapper.selectAuthRoleListByAdminId(authUser.getId());
UserDto userDto = new UserDto();
BeanUtils.copyProperties(authUser, userDto);
if (CollUtil.isNotEmpty(authRoles)) {
List<String> roleStrList = authRoles.stream().map(item -> item.getId() + "_" + item.getName()).collect(Collectors.toList());
userDto.setRoles(roleStrList);
}
return userDto;
}
return null;
}
use of com.besscroft.aurora.mall.common.entity.AuthRole in project aurora-mall by besscroft.
the class UserServiceImpl method getUserInfo.
@Override
@Transactional(rollbackFor = Exception.class)
public Map<String, Object> getUserInfo() {
AuthUser currentAdmin = getCurrentAdmin();
Map<String, Object> data = menuService.getTreeListById(currentAdmin.getId());
data.put("username", currentAdmin.getNickName());
data.put("icon", currentAdmin.getIcon());
List<AuthRole> roleList = getRoleList(currentAdmin.getId());
if (CollUtil.isNotEmpty(roleList)) {
List<String> roles = roleList.stream().map(AuthRole::getName).collect(Collectors.toList());
data.put("roles", roles);
}
// 设置登录时间
setLoginTime(LocalDateTime.now(), currentAdmin.getId());
return data;
}
Aggregations