use of com.haier.user.domain.AuthClient in project su-sunday-cloud by illeagalName.
the class ResourcePreloadRunner method run.
@Override
public void run(ApplicationArguments args) {
clearCache(CacheConstants.AUTHORIZATION_USER_ROLE + "*");
log.info("加载角色菜单资源开始 {}", LocalDateTime.now());
QueryWrapper<Role> roleWrapper = new QueryWrapper<>();
roleWrapper.eq("status", 0).eq("is_delete", 0);
List<Role> roles = roleMapper.selectList(roleWrapper);
roles.parallelStream().forEach(item -> {
List<Menu> menus = menuMapper.listMenusByRoleId(item.getRoleId());
RoleVO role = new RoleVO();
BeanUtils.copyProperties(item, role);
role.setMenus(menus.stream().map(Menu::getSymbol).filter(Objects::nonNull).collect(Collectors.toList()));
// 缓存起来
redisService.setObject(CacheConstants.AUTHORIZATION_USER_ROLE + role.getRoleId(), role);
});
clearCache(CacheConstants.AUTHORIZATION_USER_MENU + "*");
QueryWrapper<Menu> menuWrapper = new QueryWrapper<>();
menuWrapper.orderByAsc("parent_id", "menu_sort");
List<Menu> menus = menuMapper.selectList(menuWrapper);
menus.forEach(item -> {
MenuVO menu = new MenuVO();
BeanUtils.copyProperties(item, menu);
redisService.setObject(CacheConstants.AUTHORIZATION_USER_MENU + item.getMenuId(), menu);
});
clearCache(CacheConstants.AUTHORIZATION_USER_CLIENT + "*");
log.info("加载client资源开始 {}", LocalDateTime.now());
List<AuthClient> authClients = authClientMapper.listAuthClients();
authClients.stream().map(client -> {
ClientVO clientVO = new ClientVO();
clientVO.setClientId(client.getClientId());
clientVO.setTime(client.getAccessTokenValidity());
clientVO.setRemark(client.getRemark());
return clientVO;
}).forEach(m -> {
redisService.setObject(CacheConstants.AUTHORIZATION_USER_CLIENT + m.getClientId(), m);
});
log.info("加载资源结束 {}", LocalDateTime.now());
}
Aggregations