Commit 5ae9e3f1 authored by fangxinjiang's avatar fangxinjiang

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

parent 8dcd5202
...@@ -14,6 +14,9 @@ import java.math.BigDecimal; ...@@ -14,6 +14,9 @@ import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.*; 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.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
...@@ -652,4 +655,9 @@ public class Common { ...@@ -652,4 +655,9 @@ public class Common {
} }
return errorMessageList; 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; ...@@ -22,6 +22,7 @@ import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.ehcache.impl.internal.util.ServiceUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
...@@ -235,19 +236,21 @@ public class BusinessUserController { ...@@ -235,19 +236,21 @@ public class BusinessUserController {
Set<SysMenu> all = new HashSet<>(); Set<SysMenu> all = new HashSet<>();
SecurityUtils.getRolesByClient(ClientNameConstants.CLIENT_B) SecurityUtils.getRolesByClient(ClientNameConstants.CLIENT_B)
.forEach(roleId -> all.addAll(sysMenuService.findMenuByRoleId(roleId))); .forEach(roleId -> all.addAll(sysMenuService.findMenuByRoleId(roleId)));
List<MenuTreeForVue> menuTreeList; List<MenuTreeForVue> menuTreeList = null;
if (Common.isNotNull(all)){
if (Common.isNotNull(type)) { if (Common.isNotNull(type)) {
menuTreeList = all.stream() menuTreeList = all.stream().filter(Common.distinctByKey(SysMenu::getMenuId))
.filter(menuVo -> type.equals(menuVo.getType())) .filter(menuVo -> type.equals(menuVo.getType()))
.map(MenuTreeForVue::new) .map(MenuTreeForVue::new)
.sorted(Comparator.comparingInt(MenuTreeForVue::getSort)) .sorted(Comparator.comparingInt(MenuTreeForVue::getSort))
.collect(Collectors.toList()); .collect(Collectors.toList());
} else { } else {
menuTreeList = all.stream() menuTreeList = all.stream().filter(Common.distinctByKey(SysMenu::getMenuId))
.map(MenuTreeForVue::new) .map(MenuTreeForVue::new)
.sorted(Comparator.comparingInt(MenuTreeForVue::getSort)) .sorted(Comparator.comparingInt(MenuTreeForVue::getSort))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
}
return new R<>(TreeUtil.bulid(menuTreeList, -1)); 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