use of com.albedo.java.modules.sys.cache.MenuCacheKeyBuilder 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.modules.sys.cache.MenuCacheKeyBuilder 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;
});
}
Aggregations