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());
});
}
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)));
});
}
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;
});
}
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;
}
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);
}
Aggregations