|
@@ -139,15 +139,6 @@ public class PartyRoleProviderService {
|
|
|
po.setParentId(res.getParentId());
|
|
po.setParentId(res.getParentId());
|
|
|
resourcesList.add(po);
|
|
resourcesList.add(po);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- //应用pageName过滤
|
|
|
|
|
- if(StringUtils.isNotBlank(pageName)){
|
|
|
|
|
- resourcesList = resourcesList.stream()
|
|
|
|
|
- .filter(r -> validResources.stream()
|
|
|
|
|
- .filter(v -> v.getId().equals(r.getId()))
|
|
|
|
|
- .anyMatch(v -> v.getDisplayName().contains(pageName)))
|
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
//如果没有查询到角色或资源,则直接返回
|
|
//如果没有查询到角色或资源,则直接返回
|
|
|
if(CollectionUtils.isEmpty(roleList) || CollectionUtils.isEmpty(resourcesList)){
|
|
if(CollectionUtils.isEmpty(roleList) || CollectionUtils.isEmpty(resourcesList)){
|
|
@@ -164,6 +155,47 @@ public class PartyRoleProviderService {
|
|
|
}
|
|
}
|
|
|
List<PagePermissionMenuVO> result = getChildNode("0", allMenuList);
|
|
List<PagePermissionMenuVO> result = getChildNode("0", allMenuList);
|
|
|
allMenuList = getFlatMenuList("",result);
|
|
allMenuList = getFlatMenuList("",result);
|
|
|
|
|
+
|
|
|
|
|
+ //应用pageName过滤(匹配的资源及其所有父级)
|
|
|
|
|
+ if(StringUtils.isNotBlank(pageName)){
|
|
|
|
|
+ //构建id到displayName的映射
|
|
|
|
|
+ Map<String, String> idToDisplayNameMap = new HashMap<>();
|
|
|
|
|
+ for(ResourceDO res : validResources){
|
|
|
|
|
+ idToDisplayNameMap.put(res.getId(), res.getDisplayName());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //找出所有匹配的资源ID
|
|
|
|
|
+ Set<String> matchedIds = new HashSet<>();
|
|
|
|
|
+ for(PagePermissionMenuVO menu : allMenuList){
|
|
|
|
|
+ String displayName = idToDisplayNameMap.get(menu.getId());
|
|
|
|
|
+ if(displayName != null && displayName.contains(pageName)){
|
|
|
|
|
+ matchedIds.add(menu.getId());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //构建id到menu的映射
|
|
|
|
|
+ Map<String, PagePermissionMenuVO> idToMenuMap = new HashMap<>();
|
|
|
|
|
+ for(PagePermissionMenuVO menu : allMenuList){
|
|
|
|
|
+ idToMenuMap.put(menu.getId(), menu);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //收集匹配资源及其所有父级
|
|
|
|
|
+ Set<String> resultIds = new HashSet<>();
|
|
|
|
|
+ for(String matchedId : matchedIds){
|
|
|
|
|
+ resultIds.add(matchedId);
|
|
|
|
|
+ //向上查找所有父级
|
|
|
|
|
+ PagePermissionMenuVO current = idToMenuMap.get(matchedId);
|
|
|
|
|
+ while(current != null && !"0".equals(current.getParentId())){
|
|
|
|
|
+ resultIds.add(current.getParentId());
|
|
|
|
|
+ current = idToMenuMap.get(current.getParentId());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //过滤出结果
|
|
|
|
|
+ allMenuList = allMenuList.stream()
|
|
|
|
|
+ .filter(menu -> resultIds.contains(menu.getId()))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
//对页面资源进行分页处理
|
|
//对页面资源进行分页处理
|
|
|
if(null != request.getRequestPage() && request.getRequestPage().getPageNo()>0 && request.getRequestPage().getLimit()>0){
|
|
if(null != request.getRequestPage() && request.getRequestPage().getPageNo()>0 && request.getRequestPage().getLimit()>0){
|
|
@@ -369,10 +401,37 @@ public class PartyRoleProviderService {
|
|
|
// 3. 在内存中构建有效资源树,过滤父级不显示的,生成 displayName 和 sortPath
|
|
// 3. 在内存中构建有效资源树,过滤父级不显示的,生成 displayName 和 sortPath
|
|
|
List<ResourceDO> validResources = buildValidResources(rawResources);
|
|
List<ResourceDO> validResources = buildValidResources(rawResources);
|
|
|
|
|
|
|
|
- // 4. 应用资源名称过滤
|
|
|
|
|
|
|
+ // 4. 应用资源名称过滤(匹配的资源及其所有父级)
|
|
|
if (StringUtils.isNotBlank(pageName)) {
|
|
if (StringUtils.isNotBlank(pageName)) {
|
|
|
|
|
+ //找出所有匹配的资源ID
|
|
|
|
|
+ Set<String> matchedIds = new HashSet<>();
|
|
|
|
|
+ for(ResourceDO res : validResources){
|
|
|
|
|
+ if(res.getDisplayName().contains(pageName)){
|
|
|
|
|
+ matchedIds.add(res.getId());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //构建id到ResourceDO的映射
|
|
|
|
|
+ Map<String, ResourceDO> idToResourceMap = new HashMap<>();
|
|
|
|
|
+ for(ResourceDO res : validResources){
|
|
|
|
|
+ idToResourceMap.put(res.getId(), res);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //收集匹配资源及其所有父级
|
|
|
|
|
+ Set<String> resultIds = new HashSet<>();
|
|
|
|
|
+ for(String matchedId : matchedIds){
|
|
|
|
|
+ resultIds.add(matchedId);
|
|
|
|
|
+ //向上查找所有父级
|
|
|
|
|
+ ResourceDO current = idToResourceMap.get(matchedId);
|
|
|
|
|
+ while(current != null && StringUtils.isNotBlank(current.getParentId()) && !"0".equals(current.getParentId())){
|
|
|
|
|
+ resultIds.add(current.getParentId());
|
|
|
|
|
+ current = idToResourceMap.get(current.getParentId());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //过滤出结果
|
|
|
validResources = validResources.stream()
|
|
validResources = validResources.stream()
|
|
|
- .filter(r -> r.getDisplayName().contains(pageName))
|
|
|
|
|
|
|
+ .filter(r -> resultIds.contains(r.getId()))
|
|
|
.collect(Collectors.toList());
|
|
.collect(Collectors.toList());
|
|
|
}
|
|
}
|
|
|
|
|
|