feat(REQ-2186): 政务端菜单树、页面权限接口调整

This commit is contained in:
李昆鹏 2024-05-08 11:31:33 +08:00
parent e137bfee89
commit db0a266e5f

View File

@ -198,11 +198,33 @@ public class PermissionQueryServiceImpl implements PermissionQueryService {
@Override
public List<ProductFeatureResourceResp> treeProduct(TreeProductFeatureResourceReq request) {
List<ProductFeatureRelationVO> productFeatureRelations = getProductFeatureRelationByWorkspace(Sets.newHashSet(request.getWorkspaceId()));
if (CollectionUtil.isEmpty(productFeatureRelations)) {
return Collections.emptyList();
}
List<ServicePkgDetailRes> servicePkgDetailRes = RpcInternalUtil.rpcListProcessor(() -> servicePkgClient.getServicePkgDetailBySpaceId(Sets.newHashSet(request.getWorkspaceId())),
"查询租户的产品",
request.getWorkspaceId())
.getData();
List<Long> featureIds = productFeatureRelations.stream()
.map(ProductFeatureRelationVO::getFeatureId)
.distinct()
.collect(Collectors.toList());
List<SaasFeatureResource> saasFeatureResources = featureResourceService.listByParentIdAndTerminalAndIds(null, request.getTerminal(), featureIds);
if (CollectionUtil.isEmpty(saasFeatureResources)) {
return Collections.emptyList();
}
List<ProductFeatureResourceResp> collect = saasFeatureResources.stream()
.map(this::resolveProductFeatureResourceResp)
.sorted(Comparator.comparing(ProductFeatureResourceResp::getDisplayOrder))
.collect(Collectors.toList());
return TreeUtil.buildTree(collect);
}
private List<ProductFeatureRelationVO> getProductFeatureRelationByWorkspace(Set<Long> workspaceIds) {
List<ServicePkgDetailRes> servicePkgDetailRes = RpcInternalUtil.rpcListProcessor(() -> servicePkgClient.getServicePkgDetailBySpaceId(workspaceIds),
"查询租户的产品", workspaceIds).getData();
if (CollectionUtil.isEmpty(servicePkgDetailRes)) {
return Collections.emptyList();
}
@ -215,7 +237,7 @@ public class PermissionQueryServiceImpl implements PermissionQueryService {
.distinct()
.collect(Collectors.toList());
if (CollectionUtil.isEmpty(productIds)) {
log.warn("no product found for workspace :{}", request.getWorkspaceId());
log.warn("no product found for workspace :{}", workspaceIds);
return Collections.emptyList();
}
@ -227,7 +249,7 @@ public class PermissionQueryServiceImpl implements PermissionQueryService {
.distinct()
.collect(Collectors.toList());
if (CollectionUtil.isEmpty(productIds)) {
log.warn("all product is deleted for workspace :{}", request.getWorkspaceId());
log.warn("all product is deleted for workspace :{}", workspaceIds);
return Collections.emptyList();
}
@ -237,19 +259,7 @@ public class PermissionQueryServiceImpl implements PermissionQueryService {
return Collections.emptyList();
}
List<Long> featureIds = listProductFeatureRelation.getData().stream()
.map(ProductFeatureRelationVO::getFeatureId)
.distinct()
.collect(Collectors.toList());
List<SaasFeatureResource> saasFeatureResources = featureResourceService.listByParentIdAndTerminalAndIds(null, request.getTerminal(), featureIds);
List<ProductFeatureResourceResp> collect = saasFeatureResources.stream()
.map(this::resolveProductFeatureResourceResp)
.sorted(Comparator.comparing(ProductFeatureResourceResp::getDisplayOrder))
.collect(Collectors.toList());
return TreeUtil.buildTree(collect);
return listProductFeatureRelation.getData();
}
private ProductFeatureResourceResp resolveProductFeatureResourceResp(SaasFeatureResource featureResource) {
@ -352,19 +362,47 @@ public class PermissionQueryServiceImpl implements PermissionQueryService {
//TODO:@Zhan 本期没做产品权限配置这里暂时先查询所有OMS资源作为已配置产品权限
// 接口调用方用户传入端则以它为准没传入则兼容历史情况查询NT_OMS_WEB
String terminal = StringUtils.isBlank(context.getTerminal()) ? TerminalInfo.NT_OMS_WEB : context.getTerminal();
List<ResourcePermission> permissions = featureResourceService.permissionQuery(ResourcePermissionQueryDTO.builder()
.terminals(Collections.singletonList(terminal))
.build());
List<WorkspaceFeatureRelation> result = new ArrayList<>();
for (WorkspaceOUPair ow : context.getWorkspaceOUPairs()) {
List<WorkspaceFeatureRelation> owPermission = permissions.stream()
.map(p -> WorkspaceFeatureRelation.builder()
.workspaceId(ow.getWorkspaceId())
.productUnitType(SaasCooperateShipCooperateTypeEnum.OMS.code)
.featureId(p.getId())
.build())
.collect(Collectors.toList());
result.addAll(owPermission);
if (TerminalInfo.NT_OMS_WEB.equals(terminal)) {
List<ResourcePermission> permissions = featureResourceService.permissionQuery(ResourcePermissionQueryDTO.builder()
.terminals(Collections.singletonList(terminal))
.build());
for (WorkspaceOUPair ow : context.getWorkspaceOUPairs()) {
List<WorkspaceFeatureRelation> owPermission = permissions.stream()
.map(p -> WorkspaceFeatureRelation.builder()
.workspaceId(ow.getWorkspaceId())
.productUnitType(SaasCooperateShipCooperateTypeEnum.OMS.code)
.featureId(p.getId())
.build())
.collect(Collectors.toList());
result.addAll(owPermission);
}
} else {
// 其它端则查询租户的产品权限
Set<Long> workspaceIds = context.getWorkspaceOUPairs().stream().map(WorkspaceOUPair::getWorkspaceId).collect(Collectors.toSet());
List<ProductFeatureRelationVO> productFeatureRelations = getProductFeatureRelationByWorkspace(workspaceIds);
if (CollectionUtil.isEmpty(productFeatureRelations)) {
return result;
}
for (WorkspaceOUPair ow : context.getWorkspaceOUPairs()) {
List<WorkspaceFeatureRelation> owPermission = productFeatureRelations.stream()
.map(p -> {
WorkspaceFeatureRelation relation = WorkspaceFeatureRelation.builder()
.workspaceId(ow.getWorkspaceId())
.featureId(p.getFeatureId())
.productUnitType(0)
.build();
if (StringUtils.isNotBlank(p.getDictCode())) {
try {
relation.setProductUnitType(Integer.parseInt(p.getDictCode()));
} catch(Exception e){
log.warn("productDictCode to ProductUnitType error.");
}
}
return relation;
}).collect(Collectors.toList());
result.addAll(owPermission);
}
}
return result;
}