From db0a266e5f0e083d03b540a70542c12a1366be05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E6=98=86=E9=B9=8F?= Date: Wed, 8 May 2024 11:31:33 +0800 Subject: [PATCH] =?UTF-8?q?feat(REQ-2186):=20=E6=94=BF=E5=8A=A1=E7=AB=AF?= =?UTF-8?q?=E8=8F=9C=E5=8D=95=E6=A0=91=E3=80=81=E9=A1=B5=E9=9D=A2=E6=9D=83?= =?UTF-8?q?=E9=99=90=E6=8E=A5=E5=8F=A3=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/PermissionQueryServiceImpl.java | 100 ++++++++++++------ 1 file changed, 69 insertions(+), 31 deletions(-) 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; }