Commit 5ae9e3f1 authored by fangxinjiang's avatar fangxinjiang

B端调优---人员菜单获取优化

parent 8dcd5202
......@@ -14,6 +14,9 @@ import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
......@@ -652,4 +655,9 @@ public class Common {
}
return errorMessageList;
}
public static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
Set<Object> seen = ConcurrentHashMap.newKeySet();
return t -> seen.add(keyExtractor.apply(t));
}
}
......@@ -22,6 +22,7 @@ import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.ehcache.impl.internal.util.ServiceUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
......@@ -235,19 +236,21 @@ public class BusinessUserController {
Set<SysMenu> all = new HashSet<>();
SecurityUtils.getRolesByClient(ClientNameConstants.CLIENT_B)
.forEach(roleId -> all.addAll(sysMenuService.findMenuByRoleId(roleId)));
List<MenuTreeForVue> menuTreeList;
if (Common.isNotNull(type)) {
menuTreeList = all.stream()
.filter(menuVo -> type.equals(menuVo.getType()))
.map(MenuTreeForVue::new)
.sorted(Comparator.comparingInt(MenuTreeForVue::getSort))
.collect(Collectors.toList());
} else {
menuTreeList = all.stream()
.map(MenuTreeForVue::new)
.sorted(Comparator.comparingInt(MenuTreeForVue::getSort))
.collect(Collectors.toList());
}
List<MenuTreeForVue> menuTreeList = null;
if (Common.isNotNull(all)){
if (Common.isNotNull(type)) {
menuTreeList = all.stream().filter(Common.distinctByKey(SysMenu::getMenuId))
.filter(menuVo -> type.equals(menuVo.getType()))
.map(MenuTreeForVue::new)
.sorted(Comparator.comparingInt(MenuTreeForVue::getSort))
.collect(Collectors.toList());
} else {
menuTreeList = all.stream().filter(Common.distinctByKey(SysMenu::getMenuId))
.map(MenuTreeForVue::new)
.sorted(Comparator.comparingInt(MenuTreeForVue::getSort))
.collect(Collectors.toList());
}
}
return new R<>(TreeUtil.bulid(menuTreeList, -1));
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment