feat:(REQ-2720) 修改旧菜单树缓存,因为没有把父节点的权限存储起来,但是实际有权限

This commit is contained in:
lilong 2024-08-01 16:42:41 +08:00
parent 6e45898d3b
commit 9dc6319aea
4 changed files with 113 additions and 16 deletions

View File

@ -17,11 +17,13 @@ import cn.axzo.tyr.server.service.SaasFeatureResourceService;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@ -182,12 +184,33 @@ public class CacheProductPermissionHandler implements EventHandler, Initializing
return Collections.emptyMap();
}
// 存在pre环境更改了节点的父节点可能导致产品没有父节点的权限这里补齐父节点的权限
PageSaasFeatureResourceReq pageSaasFeatureResourceReq = PageSaasFeatureResourceReq.builder()
.ids(featureIds)
.needFeatureCodes(true)
.build();
return saasFeatureResourceService.list(pageSaasFeatureResourceReq).stream()
.collect(Collectors.toMap(SaasFeatureResourceResp::getId, Function.identity()));
List<SaasFeatureResourceResp> features = saasFeatureResourceService.list(pageSaasFeatureResourceReq);
if (CollectionUtils.isEmpty(features)) {
return Collections.emptyMap();
}
List<Long> parentIds = features.stream()
.map(SaasFeatureResourceResp::getPath)
.flatMap(path -> Arrays.stream(path.split(",")))
.filter(StringUtils::isNotBlank)
.map(Long::valueOf)
.distinct()
.collect(Collectors.toList());
List<SaasFeatureResourceResp> parentFeatures = saasFeatureResourceService.list(PageSaasFeatureResourceReq.builder()
.ids(parentIds)
.needFeatureCodes(true)
.build());
features.addAll(parentFeatures);
return features.stream()
.collect(Collectors.toMap(SaasFeatureResourceResp::getId, Function.identity(), (f, s) -> s));
}
private Map<Long, SimplePermissionPointResp> listSaasFeature(List<SaasProductModuleFeatureRelation> productPermissions) {
@ -207,6 +230,6 @@ public class CacheProductPermissionHandler implements EventHandler, Initializing
.includeParent(true)
.build())
.stream()
.collect(Collectors.toMap(SimplePermissionPointResp::getId, Function.identity()));
.collect(Collectors.toMap(SimplePermissionPointResp::getId, Function.identity(), (f, s) -> s));
}
}

View File

@ -12,7 +12,7 @@ import cn.axzo.tyr.server.repository.entity.SaasProductModuleFeatureRelation;
import cn.axzo.tyr.server.service.ProductFeatureRelationService;
import cn.axzo.tyr.server.service.ProductSaasFeatureResourceCacheService;
import cn.axzo.tyr.server.service.SaasFeatureResourceService;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.InitializingBean;
@ -20,10 +20,12 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
@ -42,6 +44,12 @@ public class CacheProductSaasFeatureResourceHandler implements EventHandler, Ini
@Autowired
private SaasFeatureResourceService saasFeatureResourceService;
public static final Set<Integer> FEATURE_RESOURCE_TYPES = Sets.newHashSet(FeatureResourceType.MENU.getCode(),
FeatureResourceType.PAGE.getCode(),
FeatureResourceType.MENU_PARTITION_GROUP.getCode(),
FeatureResourceType.GROUP.getCode(),
FeatureResourceType.APP_ENTRY.getCode());
@Override
public void onEvent(Event event, EventConsumer.Context context) {
log.info("begin cached product featureResource handler rocketmq event: {}", event);
@ -54,11 +62,6 @@ public class CacheProductSaasFeatureResourceHandler implements EventHandler, Ini
PageProductFeatureRelationReq pageProductFeatureRelationReq = PageProductFeatureRelationReq.builder()
.productModuleIds(payload.getProductModuleIds())
.type(NEW_FEATURE)
.featureResourceTypes(Lists.newArrayList(FeatureResourceType.MENU.getCode(),
FeatureResourceType.PAGE.getCode(),
FeatureResourceType.MENU_PARTITION_GROUP.getCode(),
FeatureResourceType.GROUP.getCode(),
FeatureResourceType.APP_ENTRY.getCode()))
.build();
List<SaasProductModuleFeatureRelation> productFeatures = productFeatureRelationService.list(pageProductFeatureRelationReq);
@ -146,10 +149,33 @@ public class CacheProductSaasFeatureResourceHandler implements EventHandler, Ini
return Collections.emptyMap();
}
// 存在pre环境更改了节点的父节点可能导致产品没有父节点的权限这里补齐父节点的权限
PageSaasFeatureResourceReq pageSaasFeatureResourceReq = PageSaasFeatureResourceReq.builder()
.ids(featureIds)
.needFeatureCodes(true)
.build();
return saasFeatureResourceService.list(pageSaasFeatureResourceReq).stream()
.collect(Collectors.toMap(SaasFeatureResourceResp::getId, Function.identity()));
List<SaasFeatureResourceResp> features = saasFeatureResourceService.list(pageSaasFeatureResourceReq);
if (CollectionUtils.isEmpty(features)) {
return Collections.emptyMap();
}
List<Long> parentIds = features.stream()
.map(SaasFeatureResourceResp::getPath)
.flatMap(path -> Arrays.stream(path.split(",")))
.filter(StringUtils::isNotBlank)
.map(Long::valueOf)
.distinct()
.collect(Collectors.toList());
List<SaasFeatureResourceResp> parentFeatures = saasFeatureResourceService.list(PageSaasFeatureResourceReq.builder()
.ids(parentIds)
.needFeatureCodes(true)
.build());
features.addAll(parentFeatures);
return features.stream()
.filter(e -> FEATURE_RESOURCE_TYPES.contains(e.getFeatureType()))
.collect(Collectors.toMap(SaasFeatureResourceResp::getId, Function.identity(), (f, s) -> s));
}
}

View File

@ -17,11 +17,13 @@ import cn.axzo.tyr.server.service.SaasFeatureResourceService;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@ -173,12 +175,33 @@ public class CacheRolePermissionHandler implements EventHandler, InitializingBea
return Collections.emptyMap();
}
// 存在pre环境更改了节点的父节点可能导致产品没有父节点的权限这里补齐父节点的权限
PageSaasFeatureResourceReq pageSaasFeatureResourceReq = PageSaasFeatureResourceReq.builder()
.ids(featureIds)
.needFeatureCodes(true)
.build();
return saasFeatureResourceService.list(pageSaasFeatureResourceReq).stream()
.collect(Collectors.toMap(SaasFeatureResourceResp::getId, Function.identity()));
List<SaasFeatureResourceResp> features = saasFeatureResourceService.list(pageSaasFeatureResourceReq);
if (CollectionUtils.isEmpty(features)) {
return Collections.emptyMap();
}
List<Long> parentIds = features.stream()
.map(SaasFeatureResourceResp::getPath)
.flatMap(path -> Arrays.stream(path.split(",")))
.filter(StringUtils::isNotBlank)
.map(Long::valueOf)
.distinct()
.collect(Collectors.toList());
List<SaasFeatureResourceResp> parentFeatures = saasFeatureResourceService.list(PageSaasFeatureResourceReq.builder()
.ids(parentIds)
.needFeatureCodes(true)
.build());
features.addAll(parentFeatures);
return features.stream()
.collect(Collectors.toMap(SaasFeatureResourceResp::getId, Function.identity(), (f, s) -> s));
}
private Map<Long, SimplePermissionPointResp> listSaasFeature(List<SaasRoleRes> roles) {
@ -201,6 +224,6 @@ public class CacheRolePermissionHandler implements EventHandler, InitializingBea
.includeParent(true)
.build())
.stream()
.collect(Collectors.toMap(SimplePermissionPointResp::getId, Function.identity()));
.collect(Collectors.toMap(SimplePermissionPointResp::getId, Function.identity(), (f, s) -> s));
}
}

View File

@ -20,6 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@ -28,6 +29,7 @@ import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;
import static cn.axzo.tyr.server.event.inner.CacheProductSaasFeatureResourceHandler.FEATURE_RESOURCE_TYPES;
import static cn.axzo.tyr.server.repository.entity.SaasPgroupPermissionRelation.NEW_FEATURE;
/**
@ -145,10 +147,33 @@ public class CacheRoleSaasFeatureResourceHandler implements EventHandler, Initia
return Collections.emptyMap();
}
// 存在pre环境更改了节点的父节点可能导致产品没有父节点的权限这里补齐父节点的权限
PageSaasFeatureResourceReq pageSaasFeatureResourceReq = PageSaasFeatureResourceReq.builder()
.ids(featureIds)
.needFeatureCodes(true)
.build();
return saasFeatureResourceService.list(pageSaasFeatureResourceReq).stream()
.collect(Collectors.toMap(SaasFeatureResourceResp::getId, Function.identity()));
List<SaasFeatureResourceResp> features = saasFeatureResourceService.list(pageSaasFeatureResourceReq);
if (CollectionUtils.isEmpty(features)) {
return Collections.emptyMap();
}
List<Long> parentIds = features.stream()
.map(SaasFeatureResourceResp::getPath)
.flatMap(path -> Arrays.stream(path.split(",")))
.filter(StringUtils::isNotBlank)
.map(Long::valueOf)
.distinct()
.collect(Collectors.toList());
List<SaasFeatureResourceResp> parentFeatures = saasFeatureResourceService.list(PageSaasFeatureResourceReq.builder()
.ids(parentIds)
.needFeatureCodes(true)
.build());
features.addAll(parentFeatures);
return features.stream()
.filter(e -> FEATURE_RESOURCE_TYPES.contains(e.getFeatureType()))
.collect(Collectors.toMap(SaasFeatureResourceResp::getId, Function.identity(), (f, s) -> s));
}
}