feat:(REQ-2699) 菜单权限支持版本号和父组件code查询
This commit is contained in:
parent
1db9878f27
commit
a85354c677
@ -1,5 +1,6 @@
|
|||||||
package cn.axzo.tyr.client.model.req;
|
package cn.axzo.tyr.client.model.req;
|
||||||
|
|
||||||
|
import cn.axzo.tyr.client.common.enums.FeatureResourceType;
|
||||||
import cn.axzo.tyr.client.common.enums.PageElementFeatureResourceRelationTypeEnum;
|
import cn.axzo.tyr.client.common.enums.PageElementFeatureResourceRelationTypeEnum;
|
||||||
import cn.axzo.tyr.client.model.base.WorkspaceOUPair;
|
import cn.axzo.tyr.client.model.base.WorkspaceOUPair;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
@ -35,6 +36,7 @@ public class ListPermissionFeatureReq {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 菜单节点的uniCode
|
* 菜单节点的uniCode
|
||||||
|
* 查询指定组件code集合里有权限的组件code
|
||||||
*/
|
*/
|
||||||
private Set<String> uniCodes;
|
private Set<String> uniCodes;
|
||||||
|
|
||||||
@ -44,4 +46,19 @@ public class ListPermissionFeatureReq {
|
|||||||
* 菜单跟页面元素绑定的类型
|
* 菜单跟页面元素绑定的类型
|
||||||
*/
|
*/
|
||||||
private Set<PageElementFeatureResourceRelationTypeEnum> pageElementTypes;
|
private Set<PageElementFeatureResourceRelationTypeEnum> pageElementTypes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 客户端版本号
|
||||||
|
*/
|
||||||
|
private Integer versionMax;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询菜单树节点类型
|
||||||
|
*/
|
||||||
|
private List<FeatureResourceType> featureResourceTypes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询父组件code下的有权限的uniCode
|
||||||
|
*/
|
||||||
|
private String parentUniCode;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -47,6 +47,17 @@ public class TreePermissionReq {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 菜单节点的uniCode
|
* 菜单节点的uniCode
|
||||||
|
* 查询指定组件code集合里有权限的组件code
|
||||||
*/
|
*/
|
||||||
private Set<String> uniCodes;
|
private Set<String> uniCodes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 客户端版本号
|
||||||
|
*/
|
||||||
|
private Integer versionMax;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询父组件code下的有权限的uniCode
|
||||||
|
*/
|
||||||
|
private String parentUniCode;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,10 +2,11 @@ package cn.axzo.tyr.server.event.inner;
|
|||||||
|
|
||||||
import cn.axzo.framework.rocketmq.Event;
|
import cn.axzo.framework.rocketmq.Event;
|
||||||
import cn.axzo.framework.rocketmq.EventConsumer;
|
import cn.axzo.framework.rocketmq.EventConsumer;
|
||||||
import cn.axzo.framework.rocketmq.EventHandler;
|
|
||||||
import cn.axzo.tyr.client.common.enums.FeatureResourceType;
|
import cn.axzo.tyr.client.common.enums.FeatureResourceType;
|
||||||
|
import cn.axzo.tyr.client.common.enums.PageElementFeatureResourceRelationTypeEnum;
|
||||||
import cn.axzo.tyr.client.model.req.PageProductFeatureRelationReq;
|
import cn.axzo.tyr.client.model.req.PageProductFeatureRelationReq;
|
||||||
import cn.axzo.tyr.client.model.req.PageSaasFeatureResourceReq;
|
import cn.axzo.tyr.client.model.req.PageSaasFeatureResourceReq;
|
||||||
|
import cn.axzo.tyr.client.model.res.PageElementResp;
|
||||||
import cn.axzo.tyr.client.model.res.SaasFeatureResourceResp;
|
import cn.axzo.tyr.client.model.res.SaasFeatureResourceResp;
|
||||||
import cn.axzo.tyr.server.event.payload.PageElementFeatureResourceUpsertPayload;
|
import cn.axzo.tyr.server.event.payload.PageElementFeatureResourceUpsertPayload;
|
||||||
import cn.axzo.tyr.server.event.payload.ProductPermissionCreatedPayload;
|
import cn.axzo.tyr.server.event.payload.ProductPermissionCreatedPayload;
|
||||||
@ -22,12 +23,12 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -144,13 +145,9 @@ public class CacheProductSaasFeatureResourceHandler implements InitializingBean
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<ProductSaasFeatureResourceCacheService.FeatureResourceDTO> featureResourceDTOS = Lists.newArrayList(ProductSaasFeatureResourceCacheService.FeatureResourceDTO.builder()
|
ProductSaasFeatureResourceCacheService.FeatureResourceDTO featureResourceDTO = from(featureResource, relation);
|
||||||
.featureId(featureResource.getId())
|
List<ProductSaasFeatureResourceCacheService.FeatureResourceDTO> featureResourceDTOS = Lists.newArrayList(featureResourceDTO);
|
||||||
.featureType(featureResource.getFeatureType())
|
|
||||||
.terminal(featureResource.getTerminal())
|
|
||||||
.uniCode(featureResource.getUniCode())
|
|
||||||
.cooperateType(relation.getDictCode())
|
|
||||||
.build());
|
|
||||||
List<ProductSaasFeatureResourceCacheService.FeatureResourceDTO> parentPermissions = featureResource.resolvePath().stream()
|
List<ProductSaasFeatureResourceCacheService.FeatureResourceDTO> parentPermissions = featureResource.resolvePath().stream()
|
||||||
.map(parentFeatureResources::get)
|
.map(parentFeatureResources::get)
|
||||||
.filter(Objects::nonNull)
|
.filter(Objects::nonNull)
|
||||||
@ -160,13 +157,7 @@ public class CacheProductSaasFeatureResourceHandler implements InitializingBean
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ProductSaasFeatureResourceCacheService.FeatureResourceDTO.builder()
|
return from(featureResource, relation);
|
||||||
.featureId(f.getId())
|
|
||||||
.featureType(f.getFeatureType())
|
|
||||||
.terminal(f.getTerminal())
|
|
||||||
.uniCode(f.getUniCode())
|
|
||||||
.cooperateType(relation.getDictCode())
|
|
||||||
.build();
|
|
||||||
})
|
})
|
||||||
.filter(Objects::nonNull)
|
.filter(Objects::nonNull)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
@ -194,6 +185,16 @@ public class CacheProductSaasFeatureResourceHandler implements InitializingBean
|
|||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ProductSaasFeatureResourceCacheService.FeatureResourceDTO from(SaasFeatureResourceResp featureResource,
|
||||||
|
SaasProductModuleFeatureRelation relation) {
|
||||||
|
return ProductSaasFeatureResourceCacheService.FeatureResourceDTO.builder()
|
||||||
|
.featureId(featureResource.getId())
|
||||||
|
.featureType(featureResource.getFeatureType())
|
||||||
|
.terminal(featureResource.getTerminal())
|
||||||
|
.uniCode(featureResource.getUniCode())
|
||||||
|
.cooperateType(relation.getDictCode())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
private Map<Long, SaasFeatureResourceResp> listSaasFeatureResource(List<SaasProductModuleFeatureRelation> productPermissions) {
|
private Map<Long, SaasFeatureResourceResp> listSaasFeatureResource(List<SaasProductModuleFeatureRelation> productPermissions) {
|
||||||
|
|
||||||
@ -209,7 +210,6 @@ public class CacheProductSaasFeatureResourceHandler implements InitializingBean
|
|||||||
// 存在pre环境更改了节点的父节点,可能导致产品没有父节点的权限,这里补齐父节点的权限
|
// 存在pre环境更改了节点的父节点,可能导致产品没有父节点的权限,这里补齐父节点的权限
|
||||||
PageSaasFeatureResourceReq pageSaasFeatureResourceReq = PageSaasFeatureResourceReq.builder()
|
PageSaasFeatureResourceReq pageSaasFeatureResourceReq = PageSaasFeatureResourceReq.builder()
|
||||||
.ids(featureIds)
|
.ids(featureIds)
|
||||||
.needFeatureCodes(true)
|
|
||||||
.build();
|
.build();
|
||||||
return saasFeatureResourceService.list(pageSaasFeatureResourceReq).stream()
|
return saasFeatureResourceService.list(pageSaasFeatureResourceReq).stream()
|
||||||
.collect(Collectors.toMap(SaasFeatureResourceResp::getId, Function.identity(), (f, s) -> s));
|
.collect(Collectors.toMap(SaasFeatureResourceResp::getId, Function.identity(), (f, s) -> s));
|
||||||
@ -230,7 +230,6 @@ public class CacheProductSaasFeatureResourceHandler implements InitializingBean
|
|||||||
// 存在pre环境更改了节点的父节点,可能导致产品没有父节点的权限,这里补齐父节点的权限
|
// 存在pre环境更改了节点的父节点,可能导致产品没有父节点的权限,这里补齐父节点的权限
|
||||||
PageSaasFeatureResourceReq pageSaasFeatureResourceReq = PageSaasFeatureResourceReq.builder()
|
PageSaasFeatureResourceReq pageSaasFeatureResourceReq = PageSaasFeatureResourceReq.builder()
|
||||||
.ids(parentIds)
|
.ids(parentIds)
|
||||||
.needFeatureCodes(true)
|
|
||||||
.build();
|
.build();
|
||||||
return saasFeatureResourceService.list(pageSaasFeatureResourceReq).stream()
|
return saasFeatureResourceService.list(pageSaasFeatureResourceReq).stream()
|
||||||
.collect(Collectors.toMap(SaasFeatureResourceResp::getId, Function.identity(), (f, s) -> s));
|
.collect(Collectors.toMap(SaasFeatureResourceResp::getId, Function.identity(), (f, s) -> s));
|
||||||
|
|||||||
@ -3,21 +3,14 @@ package cn.axzo.tyr.server.event.inner;
|
|||||||
import cn.axzo.framework.rocketmq.Event;
|
import cn.axzo.framework.rocketmq.Event;
|
||||||
import cn.axzo.framework.rocketmq.EventConsumer;
|
import cn.axzo.framework.rocketmq.EventConsumer;
|
||||||
import cn.axzo.framework.rocketmq.EventHandler;
|
import cn.axzo.framework.rocketmq.EventHandler;
|
||||||
import cn.axzo.tyr.client.model.enums.DelegatedType;
|
|
||||||
import cn.axzo.tyr.server.event.payload.SaasFeatureUpsertPayload;
|
import cn.axzo.tyr.server.event.payload.SaasFeatureUpsertPayload;
|
||||||
import cn.axzo.tyr.server.repository.dao.SaasFeatureDao;
|
import cn.axzo.tyr.server.job.CacheSaasFeatureJob;
|
||||||
import cn.axzo.tyr.server.repository.entity.SaasFeature;
|
|
||||||
import cn.axzo.tyr.server.service.SaasFeatureResourceService;
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 缓存全量权限点,因为鉴权等逻辑,需要查询免授权和权限点是否存在,数据量大,数据库压力大
|
* 缓存全量权限点,因为鉴权等逻辑,需要查询免授权和权限点是否存在,数据量大,数据库压力大
|
||||||
*/
|
*/
|
||||||
@ -28,9 +21,7 @@ public class CacheSaasFeatureHandler implements EventHandler, InitializingBean {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private EventConsumer eventConsumer;
|
private EventConsumer eventConsumer;
|
||||||
@Autowired
|
@Autowired
|
||||||
private SaasFeatureDao saasFeatureDao;
|
private CacheSaasFeatureJob cacheSaasFeatureJob;
|
||||||
@Autowired
|
|
||||||
private SaasFeatureResourceService saasFeatureResourceService;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEvent(Event event, EventConsumer.Context context) {
|
public void onEvent(Event event, EventConsumer.Context context) {
|
||||||
@ -40,28 +31,7 @@ public class CacheSaasFeatureHandler implements EventHandler, InitializingBean {
|
|||||||
if (StringUtils.isBlank(payload.getTerminal())) {
|
if (StringUtils.isBlank(payload.getTerminal())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
cacheSaasFeatureJob.cacheSaasFeature(payload.getTerminal());
|
||||||
List<SaasFeatureResourceService.SaasFeatureResourceCache> saasFeatures = saasFeatureDao.lambdaQuery()
|
|
||||||
.eq(SaasFeature::getTerminal, payload.getTerminal())
|
|
||||||
.list()
|
|
||||||
.stream()
|
|
||||||
.map(e -> SaasFeatureResourceService.SaasFeatureResourceCache.builder()
|
|
||||||
.featureId(e.getId())
|
|
||||||
.notAuth(DelegatedType.notAuth(e.getDelegatedType()))
|
|
||||||
.parentIds(e.splitPath())
|
|
||||||
.build())
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
SaasFeatureResourceService.SaasFeatureResourceDTO saasFeatureResourceDTO = SaasFeatureResourceService.SaasFeatureResourceDTO.builder()
|
|
||||||
.terminal(payload.getTerminal())
|
|
||||||
.features(saasFeatures)
|
|
||||||
.build();
|
|
||||||
SaasFeatureResourceService.StoreSaasFeatureResourceCache storeSaasFeatureResourceCache = SaasFeatureResourceService.StoreSaasFeatureResourceCache.builder()
|
|
||||||
.saasFeatureResources(Lists.newArrayList(saasFeatureResourceDTO))
|
|
||||||
.build();
|
|
||||||
saasFeatureResourceService.storeCache(storeSaasFeatureResourceCache);
|
|
||||||
|
|
||||||
|
|
||||||
log.info("end cached saasFeature handler rocketmq event: {}", event);
|
log.info("end cached saasFeature handler rocketmq event: {}", event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,20 +3,14 @@ package cn.axzo.tyr.server.event.inner;
|
|||||||
import cn.axzo.framework.rocketmq.Event;
|
import cn.axzo.framework.rocketmq.Event;
|
||||||
import cn.axzo.framework.rocketmq.EventConsumer;
|
import cn.axzo.framework.rocketmq.EventConsumer;
|
||||||
import cn.axzo.framework.rocketmq.EventHandler;
|
import cn.axzo.framework.rocketmq.EventHandler;
|
||||||
import cn.axzo.tyr.client.model.req.PageSaasFeatureResourceReq;
|
|
||||||
import cn.axzo.tyr.server.event.payload.SaasFeatureResourceUpsertPayload;
|
import cn.axzo.tyr.server.event.payload.SaasFeatureResourceUpsertPayload;
|
||||||
import cn.axzo.tyr.server.repository.entity.SaasFeatureResource;
|
import cn.axzo.tyr.server.job.CacheSaasFeatureJob;
|
||||||
import cn.axzo.tyr.server.service.SaasFeatureResourceService;
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 缓存全量权限点,因为鉴权等逻辑,需要查询免授权和权限点是否存在,数据量大,数据库压力大
|
* 缓存全量权限点,因为鉴权等逻辑,需要查询免授权和权限点是否存在,数据量大,数据库压力大
|
||||||
*/
|
*/
|
||||||
@ -27,7 +21,7 @@ public class CacheSaasFeatureResourceHandler implements EventHandler, Initializi
|
|||||||
@Autowired
|
@Autowired
|
||||||
private EventConsumer eventConsumer;
|
private EventConsumer eventConsumer;
|
||||||
@Autowired
|
@Autowired
|
||||||
private SaasFeatureResourceService saasFeatureResourceService;
|
private CacheSaasFeatureJob cacheSaasFeatureJob;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEvent(Event event, EventConsumer.Context context) {
|
public void onEvent(Event event, EventConsumer.Context context) {
|
||||||
@ -39,28 +33,7 @@ public class CacheSaasFeatureResourceHandler implements EventHandler, Initializi
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 直接查询缓存所有节点,因为修改的代码不好改
|
// 直接查询缓存所有节点,因为修改的代码不好改
|
||||||
|
cacheSaasFeatureJob.cacheSaasFeatureResource(payload.getTerminal());
|
||||||
PageSaasFeatureResourceReq pageSaasFeatureResourceReq = PageSaasFeatureResourceReq.builder()
|
|
||||||
.terminal(payload.getTerminal())
|
|
||||||
.build();
|
|
||||||
|
|
||||||
List<SaasFeatureResourceService.SaasFeatureResourceCache> saasFeatures = saasFeatureResourceService.list(pageSaasFeatureResourceReq).stream()
|
|
||||||
.map(e -> SaasFeatureResourceService.SaasFeatureResourceCache.builder()
|
|
||||||
.featureId(e.getId())
|
|
||||||
.notAuth(SaasFeatureResource.AuthType.isAllRole(e.getAuthType()))
|
|
||||||
.parentIds(e.resolvePath())
|
|
||||||
.build())
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
SaasFeatureResourceService.SaasFeatureResourceDTO saasFeatureResourceDTO = SaasFeatureResourceService.SaasFeatureResourceDTO.builder()
|
|
||||||
.terminal(payload.getTerminal())
|
|
||||||
.features(saasFeatures)
|
|
||||||
.build();
|
|
||||||
SaasFeatureResourceService.StoreSaasFeatureResourceCache storeSaasFeatureResourceCache = SaasFeatureResourceService.StoreSaasFeatureResourceCache.builder()
|
|
||||||
.saasFeatureResources(Lists.newArrayList(saasFeatureResourceDTO))
|
|
||||||
.build();
|
|
||||||
saasFeatureResourceService.storeCache(storeSaasFeatureResourceCache);
|
|
||||||
|
|
||||||
log.info("end cached saasFeatureResource handler rocketmq event: {}", event);
|
log.info("end cached saasFeatureResource handler rocketmq event: {}", event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package cn.axzo.tyr.server.job;
|
|||||||
|
|
||||||
import cn.axzo.tyr.client.model.enums.DelegatedType;
|
import cn.axzo.tyr.client.model.enums.DelegatedType;
|
||||||
import cn.axzo.tyr.client.model.req.PageSaasFeatureResourceReq;
|
import cn.axzo.tyr.client.model.req.PageSaasFeatureResourceReq;
|
||||||
|
import cn.axzo.tyr.client.model.res.PageElementResp;
|
||||||
import cn.axzo.tyr.client.model.res.SaasFeatureResourceResp;
|
import cn.axzo.tyr.client.model.res.SaasFeatureResourceResp;
|
||||||
import cn.axzo.tyr.server.repository.dao.SaasFeatureDao;
|
import cn.axzo.tyr.server.repository.dao.SaasFeatureDao;
|
||||||
import cn.axzo.tyr.server.repository.entity.SaasFeature;
|
import cn.axzo.tyr.server.repository.entity.SaasFeature;
|
||||||
@ -17,6 +18,7 @@ import org.springframework.stereotype.Component;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@ -28,6 +30,11 @@ public class CacheSaasFeatureJob extends IJobHandler {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private SaasFeatureResourceService saasFeatureResourceService;
|
private SaasFeatureResourceService saasFeatureResourceService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分组这些菜单节点没有版本号,默认为0,方便权限过滤
|
||||||
|
*/
|
||||||
|
private static final int DEFAULT_VERSION = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@XxlJob("CacheSaasFeatureJob")
|
@XxlJob("CacheSaasFeatureJob")
|
||||||
public ReturnT<String> execute(String s) throws Exception {
|
public ReturnT<String> execute(String s) throws Exception {
|
||||||
@ -40,7 +47,7 @@ public class CacheSaasFeatureJob extends IJobHandler {
|
|||||||
return ReturnT.SUCCESS;
|
return ReturnT.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cacheSaasFeature(String terminal) {
|
public void cacheSaasFeature(String terminal) {
|
||||||
Map<String, List<SaasFeatureResourceService.SaasFeatureResourceCache>> saasFeatures = saasFeatureDao.lambdaQuery()
|
Map<String, List<SaasFeatureResourceService.SaasFeatureResourceCache>> saasFeatures = saasFeatureDao.lambdaQuery()
|
||||||
.eq(StringUtils.isNotBlank(terminal), SaasFeature::getTerminal, terminal)
|
.eq(StringUtils.isNotBlank(terminal), SaasFeature::getTerminal, terminal)
|
||||||
.list()
|
.list()
|
||||||
@ -66,9 +73,10 @@ public class CacheSaasFeatureJob extends IJobHandler {
|
|||||||
saasFeatureResourceService.storeCache(storeSaasFeatureResourceCache);
|
saasFeatureResourceService.storeCache(storeSaasFeatureResourceCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cacheSaasFeatureResource(String terminal) {
|
public void cacheSaasFeatureResource(String terminal) {
|
||||||
PageSaasFeatureResourceReq pageSaasFeatureResourceReq = PageSaasFeatureResourceReq.builder()
|
PageSaasFeatureResourceReq pageSaasFeatureResourceReq = PageSaasFeatureResourceReq.builder()
|
||||||
.terminal(terminal)
|
.terminal(terminal)
|
||||||
|
.needPageElement(true)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Map<String, List<SaasFeatureResourceService.SaasFeatureResourceCache>> saasFeatureResources = saasFeatureResourceService.list(pageSaasFeatureResourceReq)
|
Map<String, List<SaasFeatureResourceService.SaasFeatureResourceCache>> saasFeatureResources = saasFeatureResourceService.list(pageSaasFeatureResourceReq)
|
||||||
@ -79,6 +87,13 @@ public class CacheSaasFeatureJob extends IJobHandler {
|
|||||||
.featureId(e.getId())
|
.featureId(e.getId())
|
||||||
.notAuth(SaasFeatureResource.AuthType.isAllRole(e.getAuthType()))
|
.notAuth(SaasFeatureResource.AuthType.isAllRole(e.getAuthType()))
|
||||||
.parentIds(e.resolvePath())
|
.parentIds(e.resolvePath())
|
||||||
|
.uniCode(e.getUniCode())
|
||||||
|
.version(Optional.ofNullable(e.getSaasPageElements())
|
||||||
|
.map(pageElement -> pageElement.stream()
|
||||||
|
.findFirst()
|
||||||
|
.map(PageElementResp::getVersion)
|
||||||
|
.orElse(DEFAULT_VERSION))
|
||||||
|
.orElse(DEFAULT_VERSION))
|
||||||
.build(), Collectors.toList())));
|
.build(), Collectors.toList())));
|
||||||
|
|
||||||
List<SaasFeatureResourceService.SaasFeatureResourceDTO> featureResources = saasFeatureResources.entrySet().stream()
|
List<SaasFeatureResourceService.SaasFeatureResourceDTO> featureResources = saasFeatureResources.entrySet().stream()
|
||||||
|
|||||||
@ -107,5 +107,13 @@ public interface SaasFeatureResourceService extends IService<SaasFeatureResource
|
|||||||
private boolean notAuth;
|
private boolean notAuth;
|
||||||
|
|
||||||
private Set<Long> parentIds;
|
private Set<Long> parentIds;
|
||||||
|
|
||||||
|
private String uniCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 客户端版本号
|
||||||
|
* 在根据版本号查询菜单树权限的时候需要
|
||||||
|
*/
|
||||||
|
private Integer version;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -69,6 +69,7 @@ import com.google.common.collect.Sets;
|
|||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
import org.apache.commons.lang3.BooleanUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -116,11 +117,9 @@ public class PermissionQueryServiceImpl implements PermissionQueryService {
|
|||||||
private final ProductModuleDao productModuleDao;
|
private final ProductModuleDao productModuleDao;
|
||||||
private final ProductFeatureRelationService productFeatureRelationService;
|
private final ProductFeatureRelationService productFeatureRelationService;
|
||||||
private final SaasFeatureResourceDao saasFeatureResourceDao;
|
private final SaasFeatureResourceDao saasFeatureResourceDao;
|
||||||
private final SaasFeatureResourceService saasFeatureResourceService;
|
|
||||||
private final SaasRoleUserRelationService saasRoleUserRelationService;
|
private final SaasRoleUserRelationService saasRoleUserRelationService;
|
||||||
private final WorkspaceProductService workspaceProductService;
|
private final WorkspaceProductService workspaceProductService;
|
||||||
private final RoleSaasFeatureResourceCacheService roleSaasFeatureResourceCacheService;
|
private final RoleSaasFeatureResourceCacheService roleSaasFeatureResourceCacheService;
|
||||||
private final ProductSaasFeatureResourceCacheService productSaasFeatureResourceCacheService;
|
|
||||||
private final TyrSaasAuthService tyrSaasAuthService;
|
private final TyrSaasAuthService tyrSaasAuthService;
|
||||||
|
|
||||||
|
|
||||||
@ -381,7 +380,7 @@ public class PermissionQueryServiceImpl implements PermissionQueryService {
|
|||||||
List<WorkspaceProductService.WorkspaceProduct> workspaceProducts = listWorkspaceProducts(treePermissionReq, featureIds);
|
List<WorkspaceProductService.WorkspaceProduct> workspaceProducts = listWorkspaceProducts(treePermissionReq, featureIds);
|
||||||
|
|
||||||
//免授权
|
//免授权
|
||||||
List<Long> authFreeFeatureIds = listNotAuthFeatures(treePermissionReq);
|
Set<Long> authFreeFeatureIds = listNotAuthFeatures(treePermissionReq);
|
||||||
|
|
||||||
//取交集确定权限
|
//取交集确定权限
|
||||||
return mixFeatureIds(saasRoleUserV2DTOS, workspaceProducts, authFreeFeatureIds);
|
return mixFeatureIds(saasRoleUserV2DTOS, workspaceProducts, authFreeFeatureIds);
|
||||||
@ -389,7 +388,7 @@ public class PermissionQueryServiceImpl implements PermissionQueryService {
|
|||||||
|
|
||||||
private Set<Long> mixFeatureIds(List<SaasRoleUserV2DTO> saasRoleUsers,
|
private Set<Long> mixFeatureIds(List<SaasRoleUserV2DTO> saasRoleUsers,
|
||||||
List<WorkspaceProductService.WorkspaceProduct> workspaceProducts,
|
List<WorkspaceProductService.WorkspaceProduct> workspaceProducts,
|
||||||
List<Long> authFreeFeatureIds) {
|
Set<Long> authFreeFeatureIds) {
|
||||||
|
|
||||||
Map<Long, WorkspaceProductService.WorkspaceProduct> workspaceProductMap = workspaceProducts.stream()
|
Map<Long, WorkspaceProductService.WorkspaceProduct> workspaceProductMap = workspaceProducts.stream()
|
||||||
.collect(Collectors.toMap(WorkspaceProductService.WorkspaceProduct::getWorkspaceId, Function.identity()));
|
.collect(Collectors.toMap(WorkspaceProductService.WorkspaceProduct::getWorkspaceId, Function.identity()));
|
||||||
@ -456,7 +455,7 @@ public class PermissionQueryServiceImpl implements PermissionQueryService {
|
|||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<SaasFeatureResourceResp> saasFeatureResources = saasFeatureResourceService.list(PageSaasFeatureResourceReq.builder()
|
List<SaasFeatureResourceResp> saasFeatureResources = featureResourceService.list(PageSaasFeatureResourceReq.builder()
|
||||||
.ids(Lists.newArrayList(allFeatureIds))
|
.ids(Lists.newArrayList(allFeatureIds))
|
||||||
.needFeatureCodes(true)
|
.needFeatureCodes(true)
|
||||||
.terminal(req.getTerminal())
|
.terminal(req.getTerminal())
|
||||||
@ -514,6 +513,8 @@ public class PermissionQueryServiceImpl implements PermissionQueryService {
|
|||||||
.personId(req.getPersonId())
|
.personId(req.getPersonId())
|
||||||
.terminal(req.getTerminal())
|
.terminal(req.getTerminal())
|
||||||
.uniCodes(req.getUniCodes())
|
.uniCodes(req.getUniCodes())
|
||||||
|
.versionMax(req.getVersionMax())
|
||||||
|
.parentUniCode(req.getParentUniCode())
|
||||||
.build();
|
.build();
|
||||||
Set<Long> featureIds = listUserPermissionFeatureIds(treePermissionReq);
|
Set<Long> featureIds = listUserPermissionFeatureIds(treePermissionReq);
|
||||||
|
|
||||||
@ -521,7 +522,8 @@ public class PermissionQueryServiceImpl implements PermissionQueryService {
|
|||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<SaasFeatureResourceResp> saasFeatureResources = saasFeatureResourceService.list(PageSaasFeatureResourceReq.builder()
|
// 使用方需要名字、icon、routerUrl等信息,放在redis就数据量比较大,后续要做成人维度的权限缓存,所以现在就查询数据库,因为有权限的权限点不多,且是主键查询
|
||||||
|
List<SaasFeatureResourceResp> saasFeatureResources = featureResourceService.list(PageSaasFeatureResourceReq.builder()
|
||||||
.ids(Lists.newArrayList(featureIds))
|
.ids(Lists.newArrayList(featureIds))
|
||||||
.needPageElement(req.getNeedPageElement())
|
.needPageElement(req.getNeedPageElement())
|
||||||
.pageElementTypes(req.getPageElementTypes())
|
.pageElementTypes(req.getPageElementTypes())
|
||||||
@ -818,27 +820,72 @@ public class PermissionQueryServiceImpl implements PermissionQueryService {
|
|||||||
return relations;
|
return relations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<SaasFeatureResourceService.SaasFeatureResourceCache> listAllFeatureResources(TreePermissionReq treePermissionReq) {
|
||||||
|
|
||||||
|
List<SaasFeatureResourceService.SaasFeatureResourceCache> allFeatureResources = featureResourceService.listCache(SaasFeatureResourceService.ListSaasFeatureResourceCache.builder()
|
||||||
|
.terminals(Sets.newHashSet(treePermissionReq.getTerminal()))
|
||||||
|
.build())
|
||||||
|
.get(treePermissionReq.getTerminal())
|
||||||
|
.stream()
|
||||||
|
.filter(f -> Objects.isNull(treePermissionReq.getVersionMax())
|
||||||
|
|| treePermissionReq.getVersionMax().compareTo(f.getVersion()) > -1)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
if (StringUtils.isBlank(treePermissionReq.getParentUniCode())) {
|
||||||
|
return allFeatureResources;
|
||||||
|
}
|
||||||
|
|
||||||
|
Optional<Long> parentId = allFeatureResources.stream()
|
||||||
|
.filter(e -> Objects.equals(e.getUniCode(), treePermissionReq.getParentUniCode()))
|
||||||
|
.map(SaasFeatureResourceService.SaasFeatureResourceCache::getFeatureId)
|
||||||
|
.findFirst();
|
||||||
|
return parentId.map(aLong -> allFeatureResources.stream()
|
||||||
|
.filter(e -> e.getParentIds().contains(aLong))
|
||||||
|
.collect(Collectors.toList()))
|
||||||
|
.orElse(Collections.emptyList());
|
||||||
|
}
|
||||||
|
|
||||||
private Set<Long> listUserPermissionFeatureIds(TreePermissionReq treePermissionReq) {
|
private Set<Long> listUserPermissionFeatureIds(TreePermissionReq treePermissionReq) {
|
||||||
|
|
||||||
List<SaasRoleUserV2DTO> saasRoleUserV2DTOS = listUserPermission(treePermissionReq);
|
List<SaasFeatureResourceService.SaasFeatureResourceCache> allFeatureResources = listAllFeatureResources(treePermissionReq);
|
||||||
|
|
||||||
|
if (CollectionUtils.isEmpty(allFeatureResources)) {
|
||||||
|
return Collections.emptySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<SaasRoleUserV2DTO> saasRoleUsers = listUserPermission(treePermissionReq);
|
||||||
|
|
||||||
|
Map<Long, List<RoleSaasFeatureResourceCacheService.SaasFeatureResourceDTO>> roleFeatureResourceMap = listRoleFeatureResource(saasRoleUsers, treePermissionReq);
|
||||||
|
|
||||||
List<WorkspaceProductService.WorkspaceProductFeatureSource> workspaceProductFeatureSources = listWorkspaceProducts(treePermissionReq);
|
List<WorkspaceProductService.WorkspaceProductFeatureSource> workspaceProductFeatureSources = listWorkspaceProducts(treePermissionReq);
|
||||||
|
|
||||||
//免授权
|
//免授权
|
||||||
List<Long> authFreeFeatureIds = listNotAuthFeatures(treePermissionReq);
|
Set<Long> authFreeFeatureIds = allFeatureResources.stream()
|
||||||
|
.filter(e -> BooleanUtils.isTrue(e.isNotAuth()))
|
||||||
|
.map(SaasFeatureResourceService.SaasFeatureResourceCache::getFeatureId)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
|
Set<Long> allFeatureIds = allFeatureResources.stream()
|
||||||
|
.map(SaasFeatureResourceService.SaasFeatureResourceCache::getFeatureId)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
//取交集确定权限
|
//取交集确定权限
|
||||||
return mixFeatureIds(saasRoleUserV2DTOS, workspaceProductFeatureSources, authFreeFeatureIds, treePermissionReq);
|
return mixFeatureIds(saasRoleUsers,
|
||||||
|
workspaceProductFeatureSources,
|
||||||
|
authFreeFeatureIds,
|
||||||
|
treePermissionReq,
|
||||||
|
roleFeatureResourceMap,
|
||||||
|
allFeatureIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Long> listNotAuthFeatures(TreePermissionReq treePermissionReq) {
|
private Set<Long> listNotAuthFeatures(TreePermissionReq treePermissionReq) {
|
||||||
PageSaasFeatureResourceReq pageSaasFeatureResourceReq = PageSaasFeatureResourceReq.builder()
|
PageSaasFeatureResourceReq pageSaasFeatureResourceReq = PageSaasFeatureResourceReq.builder()
|
||||||
.terminal(treePermissionReq.getTerminal())
|
.terminal(treePermissionReq.getTerminal())
|
||||||
.authType(FeatureResourceAuthType.ALL_ROLE.getCode())
|
.authType(FeatureResourceAuthType.ALL_ROLE.getCode())
|
||||||
.build();
|
.build();
|
||||||
return featureResourceService.list(pageSaasFeatureResourceReq).stream()
|
return featureResourceService.list(pageSaasFeatureResourceReq).stream()
|
||||||
.map(SaasFeatureResourceResp::getId)
|
.map(SaasFeatureResourceResp::getId)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<WorkspaceProductService.WorkspaceProductFeatureSource> listWorkspaceProducts(TreePermissionReq treePermissionReq) {
|
private List<WorkspaceProductService.WorkspaceProductFeatureSource> listWorkspaceProducts(TreePermissionReq treePermissionReq) {
|
||||||
@ -894,14 +941,14 @@ public class PermissionQueryServiceImpl implements PermissionQueryService {
|
|||||||
|
|
||||||
private Set<Long> mixFeatureIds(List<SaasRoleUserV2DTO> saasRoleUsers,
|
private Set<Long> mixFeatureIds(List<SaasRoleUserV2DTO> saasRoleUsers,
|
||||||
List<WorkspaceProductService.WorkspaceProductFeatureSource> workspaceProducts,
|
List<WorkspaceProductService.WorkspaceProductFeatureSource> workspaceProducts,
|
||||||
List<Long> authFreeFeatureIds,
|
Set<Long> authFreeFeatureIds,
|
||||||
TreePermissionReq treePermissionReq) {
|
TreePermissionReq treePermissionReq,
|
||||||
|
Map<Long, List<RoleSaasFeatureResourceCacheService.SaasFeatureResourceDTO>> roleFeatureResourceMap,
|
||||||
|
Set<Long> allFeatureIds) {
|
||||||
|
|
||||||
Map<Long, List<WorkspaceProductService.ProductFeatureSource>> workspaceProductMap = workspaceProducts.stream()
|
Map<Long, List<WorkspaceProductService.ProductFeatureSource>> workspaceProductMap = workspaceProducts.stream()
|
||||||
.collect(Collectors.toMap(WorkspaceProductService.WorkspaceProductFeatureSource::getWorkspaceId, WorkspaceProductService.WorkspaceProductFeatureSource::getProductFeatureSources));
|
.collect(Collectors.toMap(WorkspaceProductService.WorkspaceProductFeatureSource::getWorkspaceId, WorkspaceProductService.WorkspaceProductFeatureSource::getProductFeatureSources));
|
||||||
|
|
||||||
Map<Long, List<RoleSaasFeatureResourceCacheService.SaasFeatureResourceDTO>> roleFeatureResourceMap = listRoleFeatureResource(saasRoleUsers, treePermissionReq);
|
|
||||||
|
|
||||||
Set<Integer> featureTypes = Optional.ofNullable(treePermissionReq.getFeatureResourceTypes())
|
Set<Integer> featureTypes = Optional.ofNullable(treePermissionReq.getFeatureResourceTypes())
|
||||||
.map(e -> e.stream().map(FeatureResourceType::getCode).collect(Collectors.toSet()))
|
.map(e -> e.stream().map(FeatureResourceType::getCode).collect(Collectors.toSet()))
|
||||||
.orElseGet(Sets::newHashSet);
|
.orElseGet(Sets::newHashSet);
|
||||||
@ -914,6 +961,7 @@ public class PermissionQueryServiceImpl implements PermissionQueryService {
|
|||||||
.flatMap(Collection::stream)
|
.flatMap(Collection::stream)
|
||||||
.filter(e -> StringUtils.isBlank(treePermissionReq.getTerminal())
|
.filter(e -> StringUtils.isBlank(treePermissionReq.getTerminal())
|
||||||
|| Objects.equals(e.getTerminal(), treePermissionReq.getTerminal()))
|
|| Objects.equals(e.getTerminal(), treePermissionReq.getTerminal()))
|
||||||
|
.filter(e -> allFeatureIds.contains(e.getFeatureId()))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
if (CollectionUtils.isEmpty(productFeatureSources)) {
|
if (CollectionUtils.isEmpty(productFeatureSources)) {
|
||||||
@ -933,12 +981,12 @@ public class PermissionQueryServiceImpl implements PermissionQueryService {
|
|||||||
|
|
||||||
Set<Long> normalFeatureIds = resolveNormalRole(productFeatureSources, saasRole, roleFeatureResources);
|
Set<Long> normalFeatureIds = resolveNormalRole(productFeatureSources, saasRole, roleFeatureResources);
|
||||||
|
|
||||||
Set<Long> allFeatureIds = Sets.newHashSet();
|
Set<Long> result = Sets.newHashSet();
|
||||||
allFeatureIds.addAll(adminFeatureIds);
|
result.addAll(adminFeatureIds);
|
||||||
allFeatureIds.addAll(notAuthFeatureIds);
|
result.addAll(notAuthFeatureIds);
|
||||||
allFeatureIds.addAll(normalFeatureIds);
|
result.addAll(normalFeatureIds);
|
||||||
|
|
||||||
return allFeatureIds;
|
return result;
|
||||||
})
|
})
|
||||||
.filter(Objects::nonNull)
|
.filter(Objects::nonNull)
|
||||||
.flatMap(Collection::stream)
|
.flatMap(Collection::stream)
|
||||||
@ -981,7 +1029,7 @@ public class PermissionQueryServiceImpl implements PermissionQueryService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Set<Long> resolveNotAuthFeatureIds(List<ProductSaasFeatureResourceCacheService.FeatureResourceDTO> workspaceProduct,
|
private Set<Long> resolveNotAuthFeatureIds(List<ProductSaasFeatureResourceCacheService.FeatureResourceDTO> workspaceProduct,
|
||||||
List<Long> authFreeFeatureIds) {
|
Set<Long> authFreeFeatureIds) {
|
||||||
|
|
||||||
if (CollectionUtils.isEmpty(authFreeFeatureIds)) {
|
if (CollectionUtils.isEmpty(authFreeFeatureIds)) {
|
||||||
return Collections.emptySet();
|
return Collections.emptySet();
|
||||||
@ -1006,7 +1054,7 @@ public class PermissionQueryServiceImpl implements PermissionQueryService {
|
|||||||
|
|
||||||
private List<Long> resolveNormalRole(WorkspaceProductService.WorkspaceProduct workspaceProduct,
|
private List<Long> resolveNormalRole(WorkspaceProductService.WorkspaceProduct workspaceProduct,
|
||||||
SaasRoleUserV2DTO.SaasRole saasRole,
|
SaasRoleUserV2DTO.SaasRole saasRole,
|
||||||
List<Long> authFreeFeatureIds) {
|
Set<Long> authFreeFeatureIds) {
|
||||||
//普通角色:角色同类型的租户产品权限已分配 且角色上已分配 + 免授权
|
//普通角色:角色同类型的租户产品权限已分配 且角色上已分配 + 免授权
|
||||||
Set<Long> roleFeatureIds = Optional.ofNullable(saasRole.getPermissionRelations())
|
Set<Long> roleFeatureIds = Optional.ofNullable(saasRole.getPermissionRelations())
|
||||||
.map(e -> e.stream()
|
.map(e -> e.stream()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user