Search in sources :

Example 1 with AuthClient

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());
}
Also used : QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) RoleVO(com.haier.api.user.domain.RoleVO) AuthClientMapper(com.haier.user.dao.AuthClientMapper) AuthClient(com.haier.user.domain.AuthClient) ApplicationArguments(org.springframework.boot.ApplicationArguments) ApplicationRunner(org.springframework.boot.ApplicationRunner) Menu(com.haier.user.domain.Menu) MenuVO(com.haier.api.user.domain.MenuVO) LocalDateTime(java.time.LocalDateTime) ClientVO(com.haier.api.user.domain.ClientVO) Autowired(org.springframework.beans.factory.annotation.Autowired) Collectors(java.util.stream.Collectors) RedisService(com.haier.redis.service.RedisService) CacheConstants(com.haier.core.constant.CacheConstants) Objects(java.util.Objects) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) List(java.util.List) MenuMapper(com.haier.user.dao.MenuMapper) RoleMapper(com.haier.user.dao.RoleMapper) Role(com.haier.user.domain.Role) BeanUtils(org.springframework.beans.BeanUtils) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) AuthClient(com.haier.user.domain.AuthClient) Role(com.haier.user.domain.Role) MenuVO(com.haier.api.user.domain.MenuVO) RoleVO(com.haier.api.user.domain.RoleVO) Objects(java.util.Objects) Menu(com.haier.user.domain.Menu) ClientVO(com.haier.api.user.domain.ClientVO)

Aggregations

QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)1 ClientVO (com.haier.api.user.domain.ClientVO)1 MenuVO (com.haier.api.user.domain.MenuVO)1 RoleVO (com.haier.api.user.domain.RoleVO)1 CacheConstants (com.haier.core.constant.CacheConstants)1 RedisService (com.haier.redis.service.RedisService)1 AuthClientMapper (com.haier.user.dao.AuthClientMapper)1 MenuMapper (com.haier.user.dao.MenuMapper)1 RoleMapper (com.haier.user.dao.RoleMapper)1 AuthClient (com.haier.user.domain.AuthClient)1 Menu (com.haier.user.domain.Menu)1 Role (com.haier.user.domain.Role)1 LocalDateTime (java.time.LocalDateTime)1 List (java.util.List)1 Objects (java.util.Objects)1 Collectors (java.util.stream.Collectors)1 Slf4j (lombok.extern.slf4j.Slf4j)1 BeanUtils (org.springframework.beans.BeanUtils)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 ApplicationArguments (org.springframework.boot.ApplicationArguments)1