Search in sources :

Example 11 with CacheKey

use of com.albedo.java.common.core.cache.model.CacheKey in project albedo by somowhere.

the class LogLoginServiceImpl method findLastTenDaysVisitCount.

@Override
public List<Map<String, String>> findLastTenDaysVisitCount(String account) {
    LocalDateTime tenDaysAgo = LocalDateTime.of(LocalDate.now().plusDays(-9), LocalTime.MIN);
    String tenDaysAgoStr = LocalDateTimeUtil.format(tenDaysAgo, DatePattern.NORM_DATE_FORMATTER);
    CacheKey logLoginTenDayKey = new LogLoginTenDayCacheKeyBuilder().key(tenDaysAgoStr, account);
    return cacheOps.get(logLoginTenDayKey, k -> {
        List<Map<String, String>> map = repository.findLastTenDaysVisitCount(tenDaysAgo, account);
        return map.stream().map(item -> {
            Map<String, String> kv = new HashMap<>(MapHelper.initialCapacity(map.size()));
            kv.put("loginDate", item.get("loginDate"));
            kv.put("count", String.valueOf(item.get("count")));
            return kv;
        }).collect(Collectors.toList());
    });
}
Also used : LocalDateTime(java.time.LocalDateTime) RequiredArgsConstructor(lombok.RequiredArgsConstructor) LocalDateTime(java.time.LocalDateTime) HashMap(java.util.HashMap) Supplier(java.util.function.Supplier) LogLoginDo(com.albedo.java.modules.sys.domain.LogLoginDo) LogLoginService(com.albedo.java.modules.sys.service.LogLoginService) Service(org.springframework.stereotype.Service) Map(java.util.Map) LocalTime(java.time.LocalTime) MapHelper(com.albedo.java.common.core.util.MapHelper) CacheKey(com.albedo.java.common.core.cache.model.CacheKey) com.albedo.java.modules.sys.cache(com.albedo.java.modules.sys.cache) CacheOps(com.albedo.java.plugins.cache.repository.CacheOps) BaseServiceImpl(com.albedo.java.plugins.database.mybatis.service.impl.BaseServiceImpl) Collectors(java.util.stream.Collectors) UserService(com.albedo.java.modules.sys.service.UserService) StrUtil(cn.hutool.core.util.StrUtil) List(java.util.List) UserVo(com.albedo.java.modules.sys.domain.vo.UserVo) Stream(java.util.stream.Stream) LocalDateTimeUtil(cn.hutool.core.date.LocalDateTimeUtil) LocalDate(java.time.LocalDate) Convert(cn.hutool.core.convert.Convert) LogLoginRepository(com.albedo.java.modules.sys.repository.LogLoginRepository) DatePattern(cn.hutool.core.date.DatePattern) Transactional(org.springframework.transaction.annotation.Transactional) HashMap(java.util.HashMap) Map(java.util.Map) CacheKey(com.albedo.java.common.core.cache.model.CacheKey)

Example 12 with CacheKey

use of com.albedo.java.common.core.cache.model.CacheKey in project albedo by somowhere.

the class MenuServiceImpl method findTreeByUserId.

@Override
@Transactional(readOnly = true, rollbackFor = Exception.class)
public List<MenuTree> findTreeByUserId(Long userId) {
    CacheKey cacheKey = new MenuCacheKeyBuilder().key("findTreeByUserId", userId);
    return cacheOps.get(cacheKey, (k) -> {
        // 获取符合条件的菜单
        Set<MenuVo> all = new HashSet<>();
        roleRepository.findListByUserId(userId).forEach(role -> all.addAll(findListByRoleId(role.getId())));
        List<MenuTree> menuTreeList = all.stream().filter(menuVo -> !MenuDto.TYPE_BUTTON.equals(menuVo.getType())).sorted(Comparator.comparingInt(MenuVo::getSort)).map(MenuTree::new).collect(Collectors.toList());
        return buildMenus(Lists.newArrayList(TreeUtil.buildByLoopAutoRoot(menuTreeList)));
    });
}
Also used : MenuVo(com.albedo.java.modules.sys.domain.vo.MenuVo) MenuTree(com.albedo.java.modules.sys.domain.vo.MenuTree) MenuCacheKeyBuilder(com.albedo.java.modules.sys.cache.MenuCacheKeyBuilder) MenuSortDto(com.albedo.java.modules.sys.domain.dto.MenuSortDto) MenuRepository(com.albedo.java.modules.sys.repository.MenuRepository) ObjectUtil(com.albedo.java.common.core.util.ObjectUtil) ArgumentAssert(com.albedo.java.common.core.util.ArgumentAssert) GenSchemeDto(com.albedo.java.modules.sys.domain.dto.GenSchemeDto) CollUtil(com.albedo.java.common.core.util.CollUtil) EntityExistException(com.albedo.java.common.core.exception.EntityExistException) MenuDo(com.albedo.java.modules.sys.domain.MenuDo) SysCacheUtil(com.albedo.java.modules.sys.util.SysCacheUtil) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) Service(org.springframework.stereotype.Service) CharUtil(cn.hutool.core.util.CharUtil) RoleMenuRepository(com.albedo.java.modules.sys.repository.RoleMenuRepository) RoleRepository(com.albedo.java.modules.sys.repository.RoleRepository) CacheKey(com.albedo.java.common.core.cache.model.CacheKey) Wrappers(com.baomidou.mybatisplus.core.toolkit.Wrappers) RoleMenuDo(com.albedo.java.modules.sys.domain.RoleMenuDo) Set(java.util.Set) MenuTree(com.albedo.java.modules.sys.domain.vo.MenuTree) CommonConstants(com.albedo.java.common.core.constant.CommonConstants) CacheKeyBuilder(com.albedo.java.common.core.cache.model.CacheKeyBuilder) StringUtil(com.albedo.java.common.core.util.StringUtil) Collectors(java.util.stream.Collectors) MenuVo(com.albedo.java.modules.sys.domain.vo.MenuVo) List(java.util.List) AbstractTreeCacheServiceImpl(com.albedo.java.plugins.database.mybatis.service.impl.AbstractTreeCacheServiceImpl) TreeUtil(com.albedo.java.common.core.util.tree.TreeUtil) BizException(com.albedo.java.common.core.exception.BizException) MenuDto(com.albedo.java.modules.sys.domain.dto.MenuDto) AllArgsConstructor(lombok.AllArgsConstructor) Comparator(java.util.Comparator) MenuService(com.albedo.java.modules.sys.service.MenuService) Transactional(org.springframework.transaction.annotation.Transactional) MenuCacheKeyBuilder(com.albedo.java.modules.sys.cache.MenuCacheKeyBuilder) CacheKey(com.albedo.java.common.core.cache.model.CacheKey) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Example 13 with CacheKey

use of com.albedo.java.common.core.cache.model.CacheKey in project albedo by somowhere.

the class MenuServiceImpl method findListByRoleId.

@Override
@Transactional(readOnly = true, rollbackFor = Exception.class)
public List<MenuVo> findListByRoleId(Long roleId) {
    CacheKey cacheKey = new MenuCacheKeyBuilder().key("findListByRoleId", roleId);
    return cacheOps.get(cacheKey, (k) -> {
        List<MenuVo> menuAllList = repository.findMenuVoAllList();
        List<MenuVo> menuVoList = repository.findMenuVoListByRoleId(roleId);
        List<Long> parentIdList = Lists.newArrayList();
        for (MenuVo menuVo : menuVoList) {
            if (menuVo.getParentId() != null) {
                if (!parentIdList.contains(menuVo.getParentId())) {
                    parentIdList.add(menuVo.getParentId());
                }
            }
            if (menuVo.getParentIds() != null) {
                String[] parentIds = menuVo.getParentIds().split(",");
                for (String parentId : parentIds) {
                    if (StringUtil.isNotEmpty(parentId) && !parentIdList.contains(parentId)) {
                        parentIdList.add(Long.parseLong(parentId));
                    }
                }
            }
        }
        if (ObjectUtil.isNotEmpty(parentIdList)) {
            for (Long parenId : parentIdList) {
                if (!contain(parenId, menuVoList)) {
                    MenuVo menuVo = get(parenId, menuAllList);
                    if (menuVo != null) {
                        menuVoList.add(menuVo);
                    }
                }
            }
        }
        return menuVoList;
    });
}
Also used : MenuVo(com.albedo.java.modules.sys.domain.vo.MenuVo) MenuCacheKeyBuilder(com.albedo.java.modules.sys.cache.MenuCacheKeyBuilder) CacheKey(com.albedo.java.common.core.cache.model.CacheKey) Transactional(org.springframework.transaction.annotation.Transactional)

Example 14 with CacheKey

use of com.albedo.java.common.core.cache.model.CacheKey in project albedo by somowhere.

the class ParameterServiceImpl method removeByIds.

@Override
@Transactional(rollbackFor = Exception.class)
public boolean removeByIds(Collection<?> idList) {
    if (CollectionUtils.isEmpty(idList)) {
        return true;
    }
    List<ParameterDo> parameterDoList = super.listByIds((Collection<? extends Serializable>) idList);
    if (parameterDoList.isEmpty()) {
        return true;
    }
    boolean bool = SqlHelper.retBool(getBaseMapper().deleteBatchIds(idList));
    CacheKey[] keys = parameterDoList.stream().map(item -> new ParameterKeyCacheKeyBuilder().key(item.getKey())).toArray(CacheKey[]::new);
    cacheOps.del(keys);
    parameterDoList.forEach(model -> SpringContextHolder.publishEvent(new ParameterUpdateEvent(new ParameterUpdate(model.getKey(), model.getValue(), null, ContextUtil.getTenant()))));
    return bool;
}
Also used : Wraps(com.albedo.java.plugins.database.mybatis.conditions.Wraps) CacheOps(com.albedo.java.plugins.cache.repository.CacheOps) java.util(java.util) ArgumentAssert(com.albedo.java.common.core.util.ArgumentAssert) ParameterRepository(com.albedo.java.modules.sys.repository.ParameterRepository) SpringContextHolder(com.albedo.java.common.core.util.SpringContextHolder) SqlHelper(com.baomidou.mybatisplus.extension.toolkit.SqlHelper) RequiredArgsConstructor(lombok.RequiredArgsConstructor) ParameterDo(com.albedo.java.modules.sys.domain.ParameterDo) ParameterDto(com.albedo.java.modules.sys.domain.dto.ParameterDto) DataServiceImpl(com.albedo.java.plugins.database.mybatis.service.impl.DataServiceImpl) Function(java.util.function.Function) Serializable(java.io.Serializable) ParameterUpdate(com.albedo.java.common.event.model.ParameterUpdate) CollUtil(cn.hutool.core.collection.CollUtil) StrUtil(cn.hutool.core.util.StrUtil) ParameterUpdateEvent(com.albedo.java.common.event.listener.ParameterUpdateEvent) ParameterKeyCacheKeyBuilder(com.albedo.java.modules.sys.cache.ParameterKeyCacheKeyBuilder) ParameterService(com.albedo.java.modules.sys.service.ParameterService) Service(org.springframework.stereotype.Service) CollectionUtils(com.baomidou.mybatisplus.core.toolkit.CollectionUtils) ContextUtil(com.albedo.java.common.core.context.ContextUtil) CacheKey(com.albedo.java.common.core.cache.model.CacheKey) Transactional(org.springframework.transaction.annotation.Transactional) ParameterKeyCacheKeyBuilder(com.albedo.java.modules.sys.cache.ParameterKeyCacheKeyBuilder) ParameterUpdate(com.albedo.java.common.event.model.ParameterUpdate) ParameterUpdateEvent(com.albedo.java.common.event.listener.ParameterUpdateEvent) ParameterDo(com.albedo.java.modules.sys.domain.ParameterDo) CacheKey(com.albedo.java.common.core.cache.model.CacheKey) Transactional(org.springframework.transaction.annotation.Transactional)

Example 15 with CacheKey

use of com.albedo.java.common.core.cache.model.CacheKey in project albedo by somowhere.

the class ParameterServiceImpl method getValue.

@Override
public String getValue(String key, String defVal) {
    if (StrUtil.isEmpty(key)) {
        return defVal;
    }
    Function<CacheKey, String> loader = k -> {
        ParameterDo parameterDo = getOne(Wraps.<ParameterDo>lbQ().eq(ParameterDo::getKey, key));
        return parameterDo == null ? defVal : parameterDo.getValue();
    };
    CacheKey cacheKey = new ParameterKeyCacheKeyBuilder().key(key);
    return cacheOps.get(cacheKey, loader);
}
Also used : Wraps(com.albedo.java.plugins.database.mybatis.conditions.Wraps) CacheOps(com.albedo.java.plugins.cache.repository.CacheOps) java.util(java.util) ArgumentAssert(com.albedo.java.common.core.util.ArgumentAssert) ParameterRepository(com.albedo.java.modules.sys.repository.ParameterRepository) SpringContextHolder(com.albedo.java.common.core.util.SpringContextHolder) SqlHelper(com.baomidou.mybatisplus.extension.toolkit.SqlHelper) RequiredArgsConstructor(lombok.RequiredArgsConstructor) ParameterDo(com.albedo.java.modules.sys.domain.ParameterDo) ParameterDto(com.albedo.java.modules.sys.domain.dto.ParameterDto) DataServiceImpl(com.albedo.java.plugins.database.mybatis.service.impl.DataServiceImpl) Function(java.util.function.Function) Serializable(java.io.Serializable) ParameterUpdate(com.albedo.java.common.event.model.ParameterUpdate) CollUtil(cn.hutool.core.collection.CollUtil) StrUtil(cn.hutool.core.util.StrUtil) ParameterUpdateEvent(com.albedo.java.common.event.listener.ParameterUpdateEvent) ParameterKeyCacheKeyBuilder(com.albedo.java.modules.sys.cache.ParameterKeyCacheKeyBuilder) ParameterService(com.albedo.java.modules.sys.service.ParameterService) Service(org.springframework.stereotype.Service) CollectionUtils(com.baomidou.mybatisplus.core.toolkit.CollectionUtils) ContextUtil(com.albedo.java.common.core.context.ContextUtil) CacheKey(com.albedo.java.common.core.cache.model.CacheKey) Transactional(org.springframework.transaction.annotation.Transactional) ParameterKeyCacheKeyBuilder(com.albedo.java.modules.sys.cache.ParameterKeyCacheKeyBuilder) CacheKey(com.albedo.java.common.core.cache.model.CacheKey) ParameterDo(com.albedo.java.modules.sys.domain.ParameterDo)

Aggregations

CacheKey (com.albedo.java.common.core.cache.model.CacheKey)17 Transactional (org.springframework.transaction.annotation.Transactional)12 Service (org.springframework.stereotype.Service)8 RequiredArgsConstructor (lombok.RequiredArgsConstructor)6 Convert (cn.hutool.core.convert.Convert)5 StrUtil (cn.hutool.core.util.StrUtil)5 CacheOps (com.albedo.java.plugins.cache.repository.CacheOps)5 List (java.util.List)5 ArgumentAssert (com.albedo.java.common.core.util.ArgumentAssert)4 ParameterKeyCacheKeyBuilder (com.albedo.java.modules.sys.cache.ParameterKeyCacheKeyBuilder)4 UserVo (com.albedo.java.modules.sys.domain.vo.UserVo)4 Wraps (com.albedo.java.plugins.database.mybatis.conditions.Wraps)4 LocalDate (java.time.LocalDate)4 Function (java.util.function.Function)4 Collectors (java.util.stream.Collectors)4 DatePattern (cn.hutool.core.date.DatePattern)3 LocalDateTimeUtil (cn.hutool.core.date.LocalDateTimeUtil)3 CacheKeyBuilder (com.albedo.java.common.core.cache.model.CacheKeyBuilder)3 MapHelper (com.albedo.java.common.core.util.MapHelper)3 ParameterUpdateEvent (com.albedo.java.common.event.listener.ParameterUpdateEvent)3