diff --git a/tyr-server/src/main/java/cn/axzo/tyr/server/service/impl/PermissionQueryServiceImpl.java b/tyr-server/src/main/java/cn/axzo/tyr/server/service/impl/PermissionQueryServiceImpl.java index 4b935476..c256e94f 100644 --- a/tyr-server/src/main/java/cn/axzo/tyr/server/service/impl/PermissionQueryServiceImpl.java +++ b/tyr-server/src/main/java/cn/axzo/tyr/server/service/impl/PermissionQueryServiceImpl.java @@ -198,11 +198,33 @@ public class PermissionQueryServiceImpl implements PermissionQueryService { @Override public List treeProduct(TreeProductFeatureResourceReq request) { + List productFeatureRelations = getProductFeatureRelationByWorkspace(Sets.newHashSet(request.getWorkspaceId())); + if (CollectionUtil.isEmpty(productFeatureRelations)) { + return Collections.emptyList(); + } - List servicePkgDetailRes = RpcInternalUtil.rpcListProcessor(() -> servicePkgClient.getServicePkgDetailBySpaceId(Sets.newHashSet(request.getWorkspaceId())), - "查询租户的产品", - request.getWorkspaceId()) - .getData(); + List featureIds = productFeatureRelations.stream() + .map(ProductFeatureRelationVO::getFeatureId) + .distinct() + .collect(Collectors.toList()); + + List saasFeatureResources = featureResourceService.listByParentIdAndTerminalAndIds(null, request.getTerminal(), featureIds); + + if (CollectionUtil.isEmpty(saasFeatureResources)) { + return Collections.emptyList(); + } + + List collect = saasFeatureResources.stream() + .map(this::resolveProductFeatureResourceResp) + .sorted(Comparator.comparing(ProductFeatureResourceResp::getDisplayOrder)) + .collect(Collectors.toList()); + + return TreeUtil.buildTree(collect); + } + + private List getProductFeatureRelationByWorkspace(Set workspaceIds) { + List 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 featureIds = listProductFeatureRelation.getData().stream() - .map(ProductFeatureRelationVO::getFeatureId) - .distinct() - .collect(Collectors.toList()); - - List saasFeatureResources = featureResourceService.listByParentIdAndTerminalAndIds(null, request.getTerminal(), featureIds); - - List 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 permissions = featureResourceService.permissionQuery(ResourcePermissionQueryDTO.builder() - .terminals(Collections.singletonList(terminal)) - .build()); List result = new ArrayList<>(); - for (WorkspaceOUPair ow : context.getWorkspaceOUPairs()) { - List 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 permissions = featureResourceService.permissionQuery(ResourcePermissionQueryDTO.builder() + .terminals(Collections.singletonList(terminal)) + .build()); + for (WorkspaceOUPair ow : context.getWorkspaceOUPairs()) { + List 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 workspaceIds = context.getWorkspaceOUPairs().stream().map(WorkspaceOUPair::getWorkspaceId).collect(Collectors.toSet()); + List productFeatureRelations = getProductFeatureRelationByWorkspace(workspaceIds); + if (CollectionUtil.isEmpty(productFeatureRelations)) { + return result; + } + for (WorkspaceOUPair ow : context.getWorkspaceOUPairs()) { + List 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; }