use of com.hb0730.boot.admin.event.menu.MenuEvent in project boot-admin by hb0730.
the class MenuServiceImpl method updateCurrentMenu.
@Override
public boolean updateCurrentMenu() {
User currentUser = SecurityUtils.getCurrentUser();
if (null == currentUser) {
throw new LoginException(ResponseStatusEnum.USE_LOGIN_ERROR, "当前用户未登录,请登录后重试");
}
eventPublisher.publishEvent(new MenuEvent(this, currentUser.getId()));
return true;
}
use of com.hb0730.boot.admin.event.menu.MenuEvent in project boot-admin by hb0730.
the class MenuServiceImpl method getCurrentMenu.
@SneakyThrows
@Override
public List<TreeMenuDTO> getCurrentMenu() {
User currentUser = SecurityUtils.getCurrentUser();
if (null == currentUser) {
throw new LoginException(ResponseStatusEnum.USE_LOGIN_ERROR, "当前用户未登录,请登录后重试");
}
HashOperations<String, Long, List<TreeMenuDTO>> hash = redisTemplate.opsForHash();
List<TreeMenuDTO> treeMenu = hash.get(RedisConstant.MENU_KEY_PREFIX, currentUser.getId());
if (CollectionUtil.isEmpty(treeMenu)) {
eventPublisher.publishEvent(new MenuEvent(this, currentUser.getId()));
}
treeMenu = hash.get(RedisConstant.MENU_KEY_PREFIX, currentUser.getId());
if (CollectionUtil.isEmpty(treeMenu)) {
return Lists.newArrayList();
}
return treeMenu;
}
use of com.hb0730.boot.admin.event.menu.MenuEvent in project boot-admin by hb0730.
the class MenuEventListener method onApplicationEvent.
@Override
public void onApplicationEvent(@Nonnull MenuEvent event) {
Long userId = event.getUserId();
if (null == userId) {
return;
}
UserDTO user = findUserById(userId);
if (null == user) {
return;
}
//
List<TreeMenuDTO> menu = findMenuByUser(user);
if (CollectionUtils.isEmpty(menu)) {
return;
}
HashOperations<String, Long, List<TreeMenuDTO>> hash = redisTemplate.opsForHash();
hash.put(RedisConstant.MENU_KEY_PREFIX, userId, menu);
}
use of com.hb0730.boot.admin.event.menu.MenuEvent in project boot-admin by hb0730.
the class RolePermissionListener method onApplicationEvent.
@Override
@Async("threadPoolTaskExecutor")
public void onApplicationEvent(@Nonnull RolePermissionEvent event) {
Long roleId = event.getRoleId();
Set<UserDetails> onlineUser = getOnlineUserByRoleId(roleId);
if (CollectionUtils.isEmpty(onlineUser)) {
return;
}
Set<String> usernameList = onlineUser.stream().map(UserDetails::getUsername).collect(Collectors.toSet());
Map<String, UserDetails> onlineUserMap = onlineUser.stream().collect(Collectors.toMap(UserDetails::getUsername, Function.identity()));
// 用户
for (String username : usernameList) {
UserDTO userDTO = userInfoService.loadUserByUsername(username);
UserDetails details = onlineUserMap.get(username);
BeanUtil.copyProperties(userDTO, details);
// 刷新token
tokenService.refreshAccessToken((User) details);
eventPublisher.publishEvent(new MenuEvent(this, userDTO.getId()));
}
}
Aggregations