From 40f6b2db91009dde5e70343de1d793c457376b49 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Wed, 19 Feb 2025 20:15:46 +0800 Subject: [PATCH 01/29] =?UTF-8?q?[=E4=BF=AE=E5=A4=8D]=20CMDB=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E6=B8=85=E5=8D=95=E6=94=B9=E6=88=90=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E5=B1=82=E7=BA=A7=E5=8F=AF=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1349157963399168]CMDB应用清单改成模型层级可配置 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1349157963399168 --- .../config/GetResourceEntityApi.java | 14 ++ .../config/SaveResourceEntityApi.java | 7 +- .../handler/ResourceViewRebuildHandler.java | 6 +- .../IResourceCenterResourceService.java | 6 +- .../ResourceCenterResourceServiceImpl.java | 202 +++++++++++++++++- 5 files changed, 215 insertions(+), 20 deletions(-) diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/GetResourceEntityApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/GetResourceEntityApi.java index 9b93b868..e46ca9a2 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/GetResourceEntityApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/GetResourceEntityApi.java @@ -19,6 +19,8 @@ import com.alibaba.fastjson.JSONObject; import neatlogic.framework.auth.core.AuthAction; import neatlogic.framework.cmdb.auth.label.CMDB; import neatlogic.framework.cmdb.dto.ci.CiVo; +import neatlogic.framework.cmdb.dto.resourcecenter.config.ResourceEntityConfigVo; +import neatlogic.framework.cmdb.dto.resourcecenter.config.ResourceEntityRelNodeVo; import neatlogic.framework.cmdb.dto.resourcecenter.config.ResourceEntityVo; import neatlogic.framework.cmdb.dto.resourcecenter.config.SceneEntityVo; import neatlogic.framework.cmdb.exception.resourcecenter.ResourceCenterResourceFoundException; @@ -27,6 +29,7 @@ import neatlogic.framework.common.dto.ValueTextVo; import neatlogic.framework.restful.annotation.*; import neatlogic.framework.restful.constvalue.OperationTypeEnum; import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; +import neatlogic.framework.util.UuidUtil; import neatlogic.module.cmdb.dao.mapper.ci.CiMapper; import neatlogic.module.cmdb.dao.mapper.resourcecenter.ResourceEntityMapper; import neatlogic.module.cmdb.utils.ResourceEntityFactory; @@ -85,6 +88,17 @@ public class GetResourceEntityApi extends PrivateApiComponentBase { CiVo ciVo = ciMapper.getCiById(resourceEntityVo.getCiId()); if (ciVo != null) { resourceEntityVo.setCi(ciVo); + ResourceEntityConfigVo config = resourceEntityVo.getConfig(); + if (config != null) { + ResourceEntityRelNodeVo relNode = config.getRelNode(); + if (relNode == null) { + relNode = new ResourceEntityRelNodeVo(); + relNode.setUuid(UuidUtil.randomUuid()); + relNode.setCiName(ciVo.getName()); + relNode.setCiLabel(ciVo.getLabel()); + config.setRelNode(relNode); + } + } } } resourceEntityVo.setLabel(sceneEntityVo.getLabel()); diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/SaveResourceEntityApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/SaveResourceEntityApi.java index 6e8f9573..b02b91f2 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/SaveResourceEntityApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/SaveResourceEntityApi.java @@ -110,14 +110,15 @@ public class SaveResourceEntityApi extends PrivateApiComponentBase { resourceEntityMapper.insertResourceEntity(resourceEntityVo); } if (!configEquals) { - String error = resourceCenterResourceService.buildResourceView(resourceEntityVo.getName(), resourceEntityVo.getConfig()); - resourceEntityVo.setError(error); - if (StringUtils.isNotBlank(error)) { + String sql = resourceCenterResourceService.buildResourceView(resourceEntityVo); +// resourceEntityVo.setError(error); + if (StringUtils.isNotBlank(resourceEntityVo.getError())) { resourceEntityVo.setStatus(Status.ERROR.getValue()); } else { resourceEntityVo.setStatus(Status.READY.getValue()); } resourceEntityMapper.updateResourceEntityStatusAndError(resourceEntityVo); + return sql; } return null; } diff --git a/src/main/java/neatlogic/module/cmdb/rebuilddatabaseview/handler/ResourceViewRebuildHandler.java b/src/main/java/neatlogic/module/cmdb/rebuilddatabaseview/handler/ResourceViewRebuildHandler.java index 6a677a59..2bd5620e 100644 --- a/src/main/java/neatlogic/module/cmdb/rebuilddatabaseview/handler/ResourceViewRebuildHandler.java +++ b/src/main/java/neatlogic/module/cmdb/rebuilddatabaseview/handler/ResourceViewRebuildHandler.java @@ -83,9 +83,9 @@ public class ResourceViewRebuildHandler implements IRebuildDataBaseView { String config = resourceEntityMapper.getResourceEntityConfigByName(resourceEntityVo.getName()); if (StringUtils.isNotBlank(config)) { resourceEntityVo.setConfigStr(config); - String error = resourceCenterResourceService.buildResourceView(resourceEntityVo.getName(), resourceEntityVo.getConfig()); - resourceEntityVo.setError(error); - if (StringUtils.isNotBlank(error)) { + String sql = resourceCenterResourceService.buildResourceView(resourceEntityVo); +// resourceEntityVo.setError(error); + if (StringUtils.isNotBlank(resourceEntityVo.getError())) { resourceEntityVo.setStatus(Status.ERROR.getValue()); } else { resourceEntityVo.setStatus(Status.READY.getValue()); diff --git a/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/IResourceCenterResourceService.java b/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/IResourceCenterResourceService.java index ecae7f41..8a022723 100644 --- a/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/IResourceCenterResourceService.java +++ b/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/IResourceCenterResourceService.java @@ -23,7 +23,6 @@ import neatlogic.framework.cmdb.dto.resourcecenter.AccountVo; import neatlogic.framework.cmdb.dto.resourcecenter.AppEnvVo; import neatlogic.framework.cmdb.dto.resourcecenter.ResourceSearchVo; import neatlogic.framework.cmdb.dto.resourcecenter.ResourceVo; -import neatlogic.framework.cmdb.dto.resourcecenter.config.ResourceEntityConfigVo; import neatlogic.framework.cmdb.dto.resourcecenter.config.ResourceEntityVo; import neatlogic.framework.cmdb.dto.tag.TagVo; @@ -150,9 +149,8 @@ public interface IResourceCenterResourceService extends IResourceCenterResourceC /** * 构建单个视图 - * @param viewName - * @param originalConfig + * @param resourceEntityVo * @return */ - String buildResourceView(String viewName, ResourceEntityConfigVo originalConfig); + String buildResourceView(ResourceEntityVo resourceEntityVo); } diff --git a/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java b/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java index affcdf7b..22528830 100644 --- a/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java +++ b/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java @@ -27,12 +27,10 @@ import neatlogic.framework.cmdb.dto.ci.CiVo; import neatlogic.framework.cmdb.dto.cientity.CiEntityVo; import neatlogic.framework.cmdb.dto.globalattr.GlobalAttrVo; import neatlogic.framework.cmdb.dto.resourcecenter.*; -import neatlogic.framework.cmdb.dto.resourcecenter.config.ResourceEntityConfigVo; -import neatlogic.framework.cmdb.dto.resourcecenter.config.ResourceEntityFieldMappingVo; -import neatlogic.framework.cmdb.dto.resourcecenter.config.ResourceEntityVo; -import neatlogic.framework.cmdb.dto.resourcecenter.config.SceneEntityVo; +import neatlogic.framework.cmdb.dto.resourcecenter.config.*; import neatlogic.framework.cmdb.dto.tag.TagVo; import neatlogic.framework.cmdb.enums.CmdbTenantConfig; +import neatlogic.framework.cmdb.enums.RelDirectionType; import neatlogic.framework.cmdb.enums.resourcecenter.AppModuleResourceType; import neatlogic.framework.cmdb.enums.resourcecenter.Status; import neatlogic.framework.cmdb.exception.ci.CiNotFoundException; @@ -687,9 +685,9 @@ public class ResourceCenterResourceServiceImpl implements IResourceCenterResourc // } String config = resourceEntityMapper.getResourceEntityConfigByName(resourceEntityVo.getName()); resourceEntityVo.setConfigStr(config); - String error = buildResourceView(resourceEntityVo.getName(), resourceEntityVo.getConfig()); - resourceEntityVo.setError(error); - if (StringUtils.isNotBlank(error)) { + String sql = buildResourceView(resourceEntityVo); +// resourceEntityVo.setError(error); + if (StringUtils.isNotBlank(resourceEntityVo.getError())) { resourceEntityVo.setStatus(Status.ERROR.getValue()); } else { resourceEntityVo.setStatus(Status.READY.getValue()); @@ -738,11 +736,17 @@ public class ResourceCenterResourceServiceImpl implements IResourceCenterResourc } @Override - public String buildResourceView(String viewName, ResourceEntityConfigVo originalConfig) { + public String buildResourceView(ResourceEntityVo resourceEntityVo) { + String viewName = resourceEntityVo.getName(); + ResourceEntityConfigVo originalConfig = resourceEntityVo.getConfig(); + String select = null; String error = StringUtils.EMPTY; try { + List relLinkList = getRelLinkListByRelNode(originalConfig.getRelNode()); + originalConfig.setRelLinkList(relLinkList); + List leftJoinList = relListCheckValidityAndFillIdData(originalConfig); ResourceEntityConfigVo config = fieldMappingCheckValidityAndFillIdData(viewName, originalConfig); - String select = null; + config.setLeftJoinList(leftJoinList); if (Objects.equals(DatasourceManager.getDatabaseId(), DatabaseVendor.TIDB.getDatabaseId())) { ResourceViewGenerateSqlUtilForTiDB resourceViewGenerateSqlUtilForTiDB = new ResourceViewGenerateSqlUtilForTiDB(config); select = resourceViewGenerateSqlUtilForTiDB.getSql(); @@ -811,9 +815,10 @@ public class ResourceCenterResourceServiceImpl implements IResourceCenterResourc schemaMapper.insertView(createTable.toString()); }).execute(); } + resourceEntityVo.setError(error); } } - return error; + return select; } /** @@ -991,6 +996,82 @@ public class ResourceCenterResourceServiceImpl implements IResourceCenterResourc } } } + } else if (Objects.equals(type, "newRel")) { + String uuid = fieldMappingVo.getUuid(); + String ciName = fieldMappingVo.getCiName(); + String attr = fieldMappingVo.getAttr(); + if (StringUtils.isBlank(attr)) { + throw new ResourceViewFieldMappingException(viewName, field, "attr", attr); + } + List relLinkList = config.getRelLinkList(); + if (CollectionUtils.isNotEmpty(relLinkList)) { + for (ResourceEntityRelLinkVo relLinkVo : relLinkList) { + if (Objects.equals(relLinkVo.getRightUuid(), uuid)) { + CiVo rightCiVo = ciMapper.getCiByName(ciName); + if (rightCiVo == null) { + throw new ResourceViewFieldMappingException(viewName, field, "ciName", ciName); + } + newFieldMappingVo.setType("rel"); + newFieldMappingVo.setDirection(relLinkVo.getDirection()); + if (Objects.equals(relLinkVo.getDirection(), RelDirectionType.FROM.getValue())) { + CiVo fromCiVo = rightCiVo; + newFieldMappingVo.setFromCi(fromCiVo.getName()); + newFieldMappingVo.setFromCiId(fromCiVo.getId()); + String fromAttr = attr; + newFieldMappingVo.setFromAttr(fromAttr); + if (!defaultAttrList.contains(fromAttr)) { + AttrVo fromAttrVo = getAttrVo(fromCiVo, fromAttr); + if (fromAttrVo == null) { + throw new ResourceViewFieldMappingException(viewName, field, "attr", attr); + } + if (fromAttrVo.getTargetCiId() != null) { + throw new ResourceViewFieldMappingException(viewName, field, "attr", attr); + } + newFieldMappingVo.setFromAttrId(fromAttrVo.getId()); + newFieldMappingVo.setFromAttrCiId(fromAttrVo.getCiId()); + } + newFieldMappingVo.setFromCiAlias(relLinkVo.getRightCiAlias()); + + String toCi = relLinkVo.getLeftCi(); + CiVo toCiVo = ciMapper.getCiByName(toCi); + newFieldMappingVo.setToCi(toCiVo.getName()); + newFieldMappingVo.setToCiId(toCiVo.getId()); + newFieldMappingVo.setToCiIsVirtual(toCiVo.getIsVirtual()); + newFieldMappingVo.setToCiAlias(relLinkVo.getLeftCiAlias()); + } else if (Objects.equals(relLinkVo.getDirection(), RelDirectionType.TO.getValue())) { + CiVo toCiVo = rightCiVo; + newFieldMappingVo.setToCi(toCiVo.getName()); + newFieldMappingVo.setToCiId(toCiVo.getId()); + newFieldMappingVo.setToCiIsVirtual(toCiVo.getIsVirtual()); + newFieldMappingVo.setToCiAlias(relLinkVo.getRightCiAlias()); + String toAttr = attr; + if (StringUtils.isBlank(toAttr)) { + newFieldMappingVo.setToAttr("_id"); + } else { + newFieldMappingVo.setToAttr(toAttr); + if (!defaultAttrList.contains(toAttr)) { + AttrVo toAttrVo = getAttrVo(toCiVo, toAttr); + if (toAttrVo == null) { + throw new ResourceViewFieldMappingException(viewName, field, "attr", attr); + } + if (toAttrVo.getTargetCiId() != null) { + throw new ResourceViewFieldMappingException(viewName, field, "attr", attr); + } + newFieldMappingVo.setToAttrId(toAttrVo.getId()); + newFieldMappingVo.setToAttrCiId(toAttrVo.getCiId()); + newFieldMappingVo.setToAttrCiName(toAttrVo.getCiName()); + } + } + String fromCi = relLinkVo.getLeftCi(); + CiVo fromCiVo = ciMapper.getCiByName(fromCi); + newFieldMappingVo.setFromCi(fromCiVo.getName()); + newFieldMappingVo.setFromCiId(fromCiVo.getId()); + newFieldMappingVo.setFromCiAlias(relLinkVo.getLeftCiAlias()); + } + break; + } + } + } } else if (Objects.equals(type, "globalAttr")) { String fromCi = fieldMappingVo.getFromCi(); if (StringUtils.isBlank(fromCi)) { @@ -1034,6 +1115,107 @@ public class ResourceCenterResourceServiceImpl implements IResourceCenterResourc return newConfig; } + private List getRelLinkListByRelNode(ResourceEntityRelNodeVo relNode) { + List relLinkList = new ArrayList<>(); + if (relNode != null) { + Map> map = new HashMap<>(); + List children = relNode.getChildren(); + if (CollectionUtils.isNotEmpty(children)) { + for (ResourceEntityRelNodeVo child : children) { + addRelLinkListByRelNode(relLinkList, relNode, child, map); + } + } + } + return relLinkList; + } + + private void addRelLinkListByRelNode(List relLinkList, ResourceEntityRelNodeVo leftNode, ResourceEntityRelNodeVo rightNode, Map> map) { + { + ResourceEntityRelLinkVo relLinkVo = new ResourceEntityRelLinkVo(); + { + Map relNodeAliasMap = map.computeIfAbsent(leftNode.getCiName(), key -> new HashMap<>()); + int size = relNodeAliasMap.size(); + String alias = relNodeAliasMap.get(leftNode); + if (alias == null) { + if (size == 0) { + alias = StringUtils.EMPTY; + } else { + alias = "alias_" + (size + 1); + } + relNodeAliasMap.put(leftNode, alias); + } + relLinkVo.setLeftCi(leftNode.getCiName()); + relLinkVo.setLeftCiAlias(alias); + } + { + Map relNodeAliasMap = map.computeIfAbsent(rightNode.getCiName(), key -> new HashMap<>()); + int size = relNodeAliasMap.size(); + String alias = relNodeAliasMap.get(rightNode); + if (alias == null) { + if (size == 0) { + alias = StringUtils.EMPTY; + } else { + alias = "_alias_" + (size + 1); + } + relNodeAliasMap.put(rightNode, alias); + } + relLinkVo.setRightCi(rightNode.getCiName()); + relLinkVo.setRightCiAlias(alias); + relLinkVo.setRightUuid(rightNode.getUuid()); + } + relLinkVo.setDirection(rightNode.getDirection()); + relLinkList.add(relLinkVo); + } + List children = rightNode.getChildren(); + if (CollectionUtils.isNotEmpty(children)) { + for (ResourceEntityRelNodeVo child : children) { + addRelLinkListByRelNode(relLinkList, rightNode, child, map); + } + } + } + + private List relListCheckValidityAndFillIdData(ResourceEntityConfigVo config) { + List resultList = new ArrayList<>(); + List relLinkList = config.getRelLinkList(); + if (CollectionUtils.isNotEmpty(relLinkList)) { + for (ResourceEntityRelLinkVo linkVo : relLinkList) { + String leftCi = linkVo.getLeftCi(); + String rightCi = linkVo.getRightCi(); + CiVo leftCiVo = ciMapper.getCiByName(leftCi); + if (leftCiVo == null) { + throw new CiNotFoundException(leftCi); + } + CiVo rightCiVo = ciMapper.getCiByName(rightCi); + if (rightCiVo == null) { + throw new CiNotFoundException(rightCi); + } + String direction = linkVo.getDirection(); + if (Objects.equals(direction, RelDirectionType.FROM.getValue())) { + ResourceEntityLeftJoinVo leftJoinVo = new ResourceEntityLeftJoinVo(); + leftJoinVo.setDirection(direction); + leftJoinVo.setFromCi(rightCiVo.getName()); + leftJoinVo.setFromCiId(rightCiVo.getId()); + leftJoinVo.setFromCiAlias(linkVo.getRightCiAlias()); + leftJoinVo.setToCi(leftCiVo.getName()); + leftJoinVo.setToCiId(leftCiVo.getId()); + leftJoinVo.setToCiAlias(linkVo.getLeftCiAlias()); + resultList.add(leftJoinVo); + } else if (Objects.equals(direction, RelDirectionType.TO.getValue())) { + ResourceEntityLeftJoinVo leftJoinVo = new ResourceEntityLeftJoinVo(); + leftJoinVo.setDirection(direction); + leftJoinVo.setFromCi(leftCiVo.getName()); + leftJoinVo.setFromCiId(leftCiVo.getId()); + leftJoinVo.setFromCiAlias(linkVo.getLeftCiAlias()); + leftJoinVo.setToCi(rightCiVo.getName()); + leftJoinVo.setToCiId(rightCiVo.getId()); + leftJoinVo.setToCiAlias(linkVo.getRightCiAlias()); + resultList.add(leftJoinVo); + } + } + } + return resultList; + } + private AttrVo getAttrVo(CiVo ciVo, String attrName) { List upwardCiList = ciMapper.getUpwardCiListByLR(ciVo.getLft(), ciVo.getRht()); for (CiVo ci : upwardCiList) { -- Gitee From 3339536f99a02d4bb8978c406bcaf736cdb1821c Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Wed, 19 Feb 2025 20:18:02 +0800 Subject: [PATCH 02/29] =?UTF-8?q?[=E4=BF=AE=E5=A4=8D]=20CMDB=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E6=B8=85=E5=8D=95=E6=94=B9=E6=88=90=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E5=B1=82=E7=BA=A7=E5=8F=AF=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1349157963399168]CMDB应用清单改成模型层级可配置 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1349157963399168 --- .../resource/ResourceCenterResourceServiceImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java b/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java index 22528830..5f407678 100644 --- a/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java +++ b/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java @@ -744,7 +744,7 @@ public class ResourceCenterResourceServiceImpl implements IResourceCenterResourc try { List relLinkList = getRelLinkListByRelNode(originalConfig.getRelNode()); originalConfig.setRelLinkList(relLinkList); - List leftJoinList = relListCheckValidityAndFillIdData(originalConfig); + List leftJoinList = getLeftJoinList(originalConfig); ResourceEntityConfigVo config = fieldMappingCheckValidityAndFillIdData(viewName, originalConfig); config.setLeftJoinList(leftJoinList); if (Objects.equals(DatasourceManager.getDatabaseId(), DatabaseVendor.TIDB.getDatabaseId())) { @@ -1174,7 +1174,7 @@ public class ResourceCenterResourceServiceImpl implements IResourceCenterResourc } } - private List relListCheckValidityAndFillIdData(ResourceEntityConfigVo config) { + private List getLeftJoinList(ResourceEntityConfigVo config) { List resultList = new ArrayList<>(); List relLinkList = config.getRelLinkList(); if (CollectionUtils.isNotEmpty(relLinkList)) { -- Gitee From cd89232375894f293ba3423a10a667501cecee31 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Thu, 20 Feb 2025 10:28:05 +0800 Subject: [PATCH 03/29] =?UTF-8?q?[=E4=BF=AE=E5=A4=8D]=20CMDB=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E6=B8=85=E5=8D=95=E6=94=B9=E6=88=90=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E5=B1=82=E7=BA=A7=E5=8F=AF=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1349157963399168]CMDB应用清单改成模型层级可配置 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1349157963399168 --- .../cmdb/utils/ResourceEntityViewBuilder.java | 1451 ----------------- 1 file changed, 1451 deletions(-) delete mode 100644 src/main/java/neatlogic/module/cmdb/utils/ResourceEntityViewBuilder.java diff --git a/src/main/java/neatlogic/module/cmdb/utils/ResourceEntityViewBuilder.java b/src/main/java/neatlogic/module/cmdb/utils/ResourceEntityViewBuilder.java deleted file mode 100644 index 66cbd6e6..00000000 --- a/src/main/java/neatlogic/module/cmdb/utils/ResourceEntityViewBuilder.java +++ /dev/null @@ -1,1451 +0,0 @@ -/*Copyright (C) 2024 深圳极向量科技有限公司 All Rights Reserved. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see .*/ - -package neatlogic.module.cmdb.utils; - -import neatlogic.framework.asynchronization.threadlocal.TenantContext; -import neatlogic.framework.asynchronization.threadlocal.UserContext; -import neatlogic.framework.cmdb.dto.ci.AttrVo; -import neatlogic.framework.cmdb.dto.ci.CiVo; -import neatlogic.framework.cmdb.dto.resourcecenter.config.*; -import neatlogic.framework.cmdb.enums.RelDirectionType; -import neatlogic.framework.cmdb.enums.resourcecenter.JoinType; -import neatlogic.framework.cmdb.enums.resourcecenter.Status; -import neatlogic.framework.cmdb.enums.resourcecenter.ViewType; -import neatlogic.framework.cmdb.exception.attr.AttrNotFoundException; -import neatlogic.framework.cmdb.exception.ci.CiNotFoundException; -import neatlogic.framework.cmdb.exception.resourcecenter.ResourceCenterConfigIrregularException; -import neatlogic.framework.cmdb.exception.resourcecenter.ResourceCenterResourceFoundException; -import neatlogic.framework.cmdb.exception.resourcecenter.ResourceCenterViewConfigException; -import neatlogic.framework.cmdb.utils.SceneEntityGenerateSqlUtil; -import neatlogic.framework.dao.mapper.DataBaseViewInfoMapper; -import neatlogic.framework.dao.mapper.SchemaMapper; -import neatlogic.framework.dto.DataBaseViewInfoVo; -import neatlogic.framework.transaction.core.EscapeTransactionJob; -import neatlogic.framework.util.Md5Util; -import neatlogic.module.cmdb.dao.mapper.resourcecenter.ResourceEntityMapper; -import neatlogic.module.cmdb.service.ci.CiService; -import net.sf.jsqlparser.expression.Alias; -import net.sf.jsqlparser.expression.StringValue; -import net.sf.jsqlparser.expression.operators.conditional.AndExpression; -import net.sf.jsqlparser.expression.operators.relational.EqualsTo; -import net.sf.jsqlparser.schema.Column; -import net.sf.jsqlparser.schema.Table; -import net.sf.jsqlparser.statement.create.table.ColDataType; -import net.sf.jsqlparser.statement.create.table.ColumnDefinition; -import net.sf.jsqlparser.statement.create.table.CreateTable; -import net.sf.jsqlparser.statement.select.*; -import net.sf.jsqlparser.util.SelectUtils; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.collections4.ListUtils; -import org.apache.commons.lang3.StringUtils; -import org.dom4j.Document; -import org.dom4j.DocumentException; -import org.dom4j.DocumentHelper; -import org.dom4j.Element; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import java.util.*; -import java.util.stream.Collectors; - -@Deprecated -@Component -public class ResourceEntityViewBuilder { - private final static Logger logger = LoggerFactory.getLogger(ResourceEntityViewBuilder.class); - - private final static List defaultAttrList = Arrays.asList("_id", "_uuid", "_name", "_fcu", "_fcd", "_lcu", "_lcd", "_inspectStatus", "_inspectTime", "_monitorStatus", "_monitorTime", "_typeId", "_typeName", "_typeLabel"); - - private ResourceEntityVo resourceEntityVo; - - private SceneEntityVo sceneEntityVo; - - private String type; - - private final Map ciMap = new HashMap<>(); - private static SchemaMapper schemaMapper; - private static DataBaseViewInfoMapper dataBaseViewInfoMapper; - private static CiService ciService; - private static ResourceEntityMapper resourceEntityMapper; - - - @Autowired - public ResourceEntityViewBuilder( - SchemaMapper _schemaMapper, - CiService _ciService, - ResourceEntityMapper _resourceEntityMapper, - DataBaseViewInfoMapper _dataBaseViewInfoMapper) { - schemaMapper = _schemaMapper; - resourceEntityMapper = _resourceEntityMapper; - ciService = _ciService; - dataBaseViewInfoMapper = _dataBaseViewInfoMapper; - } - - private CiVo getCiByName(String ciName) { - if (!ciMap.containsKey(ciName)) { - CiVo ciVo = ciService.getCiByName(ciName); - ciMap.put(ciName, ciVo); - } - return ciMap.get(ciName); - } - - - private List getAllChildElement(Element fromElement, String elementName) { - List elementList = fromElement.elements(); - List returnList = new ArrayList<>(); - if (CollectionUtils.isNotEmpty(elementList)) { - for (Element element : elementList) { - if (element.getName().equalsIgnoreCase(elementName)) { - returnList.add(element); - } - List tmpElementList = getAllChildElement(element, elementName); - if (CollectionUtils.isNotEmpty(tmpElementList)) { - returnList.addAll(tmpElementList); - } - } - } - return returnList; - } - - public ResourceEntityViewBuilder(ResourceEntityVo resourceEntity) { - try { - String name = resourceEntity.getName(); - String xml = ""; - String description = resourceEntity.getDescription(); - this.type = ""; - Document document = DocumentHelper.parseText(xml); - Element root = document.getRootElement(); - if (Objects.equals(type, ViewType.RESOURCE.getValue())) { - List resourceEntityVoList = ResourceEntityFactory.getResourceEntityList(); - for (ResourceEntityVo entity : resourceEntityVoList) { - if (Objects.equals(entity.getName(), name)) { - resourceEntityVo = createResourceEntityVo(entity); -// resourceEntityVo.setXml(xml); - } - } - if (resourceEntityVo == null) { - throw new ResourceCenterResourceFoundException(name); - } - convertToResourceEntityVo(root); - } else if (Objects.equals(type, ViewType.SCENE.getValue())) { - List sceneEntityList = ResourceEntityFactory.getSceneEntityList(); - for (SceneEntityVo sceneEntity : sceneEntityList) { - if (Objects.equals(sceneEntity.getName(), name)) { - sceneEntityVo = new SceneEntityVo(); - sceneEntityVo.setName(name); - sceneEntityVo.setLabel(sceneEntity.getLabel()); - resourceEntityVo = new ResourceEntityVo(); - resourceEntityVo.setName(name); - resourceEntityVo.setDescription(description); -// resourceEntityVo.setXml(xml); - } - } - if (sceneEntityVo == null) { - throw new ResourceCenterResourceFoundException(name); - } - convertToSceneEntityVo(root); - } - } catch (DocumentException e) { - throw new ResourceCenterConfigIrregularException(e); - } - } - - /** - * 将标签内容转换成ResourceEntityVo - * @param resourceElement - * @return - */ - private void convertToResourceEntityVo(Element resourceElement) { - Map> elementMap = new HashMap<>(); - try { - String viewName = resourceEntityVo.getName(); - String ciName = resourceElement.attributeValue("ci"); - if (StringUtils.isBlank(ciName)) { - throw new ResourceCenterConfigIrregularException(viewName, "ci"); - } - CiVo ciVo = getCiByName(ciName); - if (ciVo == null) { - throw new CiNotFoundException(ciName); - } - resourceEntityVo.setCi(ciVo); - resourceEntityVo.setJoinList(null); - if (CollectionUtils.isNotEmpty(resourceEntityVo.getAttrList())) { - //分析属性 - for (ResourceEntityAttrVo attr : resourceEntityVo.getAttrList()) { - if (!elementMap.containsKey(viewName + "_attr")) { - elementMap.put(viewName + "_attr", getAllChildElement(resourceElement, "attr")); - } - List attrElementList = elementMap.get(viewName + "_attr"); - Optional attrOp = attrElementList.stream().filter(e -> e.attributeValue("field").equalsIgnoreCase(attr.getField())).findFirst(); - if (attrOp.isPresent()) { - Element attrElement = attrOp.get(); - String attrName = attrElement.attributeValue("attr"); - String attrCiName = attrElement.attributeValue("ci"); - CiVo attrCiVo = null; - if (StringUtils.isNotBlank(attrCiName)) { - attrCiVo = getCiByName(attrCiName); - if (attrCiVo == null) { - throw new CiNotFoundException(attrCiName); - } - } - if (StringUtils.isNotBlank(attrName)) { - attr.setAttr(attrName); - if (attrCiVo == null) { - checkAttrIsExists(ciVo, attrName); - attr.setCiId(ciVo.getId()); - attr.setCiName(ciName); - attr.setTableAlias(viewName); - } else { - checkAttrIsExists(attrCiVo, attrName); - attr.setCiName(attrCiName); - attr.setCiId(attrCiVo.getId()); - attr.setCi(attrCiVo); - attr.setTableAlias("target_cientity_" + attrCiName.toLowerCase(Locale.ROOT)); - } - - if (!attrName.startsWith("_")) { - AttrVo attrVo = getCiByName(attr.getCiName()).getAttrByName(attrName); - if (attrVo == null) { - throw new AttrNotFoundException(attr.getCiName(), attrName); - } - attr.setAttrId(attrVo.getId()); - } - } else if (attrElement.getParent().getName().equalsIgnoreCase("join")) { - if (attrCiVo != null) { - attr.setAttr("_id"); - attr.setCiId(attrCiVo.getId()); - attr.setCi(attrCiVo); - attr.setCiName(attrCiName); - attr.setTableAlias("target_cientity_" + attrCiName.toLowerCase(Locale.ROOT)); - } else { - throw new ResourceCenterConfigIrregularException(viewName, "attr", attr.getField(), "ci"); - } - } else { - throw new ResourceCenterConfigIrregularException(viewName, "attr", attr.getField(), "attr"); - } - } else { - if (!elementMap.containsKey(viewName + "_rel")) { - elementMap.put(viewName + "_rel", getAllChildElement(resourceElement, "rel")); - } - List relElementList = elementMap.get(viewName + "_rel"); - Optional relOp = relElementList.stream().filter(e -> e.attributeValue("field").equalsIgnoreCase(attr.getField())).findFirst(); - if (relOp.isPresent()) { - Element attrElement = relOp.get(); - String attrCiName = attrElement.attributeValue("ci"); - CiVo attrCiVo = null; - if (StringUtils.isNotBlank(attrCiName)) { - attrCiVo = getCiByName(attrCiName); - if (attrCiVo == null) { - throw new CiNotFoundException(attrCiName); - } - } - if (attrCiVo != null) { - attr.setAttr("_id"); - attr.setCiId(attrCiVo.getId()); - attr.setCi(attrCiVo); - attr.setCiName(attrCiName); - attr.setTableAlias("target_cientity_" + attrCiName.toLowerCase(Locale.ROOT)); - } else { - throw new ResourceCenterConfigIrregularException(viewName, "rel", attr.getField(), "ci"); - } - } else { - throw new ResourceCenterConfigIrregularException(viewName, "attr或rel", attr.getField()); - } - } - } - //分析连接查询 - Element joinElement = resourceElement.element("join"); - if (joinElement != null) { - List attrElementList = joinElement.elements("attr"); - if (CollectionUtils.isNotEmpty(attrElementList)) { - for (Element attrElement : attrElementList) { - String attrCiName = attrElement.attributeValue("ci"); - String attrFieldName = attrElement.attributeValue("field"); - String joinAttrName = attrElement.attributeValue("joinAttrName"); - if (StringUtils.isBlank(joinAttrName)) { - throw new ResourceCenterConfigIrregularException(viewName, "attr", attrFieldName, "joinAttrName"); - } - checkAttrIsExists(ciVo, joinAttrName); - if (StringUtils.isNotBlank(attrCiName)) { - CiVo joinCiVo = getCiByName(attrCiName); - if (joinCiVo == null) { - throw new CiNotFoundException(attrCiName); - } - ResourceEntityJoinVo joinVo = new ResourceEntityJoinVo(JoinType.ATTR); - joinVo.setCi(joinCiVo); - joinVo.setCiName(joinCiVo.getName()); - joinVo.setField(attrFieldName); - joinVo.setJoinAttrName(joinAttrName); - resourceEntityVo.addJoin(joinVo); - } - } - } - - List relElementList = joinElement.elements("rel"); - if (CollectionUtils.isNotEmpty(relElementList)) { - for (Element relElement : relElementList) { - String relCiName = relElement.attributeValue("ci"); - String relFieldName = relElement.attributeValue("field"); - String relDirection = relElement.attributeValue("direction"); - if (StringUtils.isNotBlank(relCiName)) { - CiVo joinCiVo = getCiByName(relCiName); - if (joinCiVo == null) { - throw new CiNotFoundException(relCiName); - } - ResourceEntityJoinVo joinVo = new ResourceEntityJoinVo(JoinType.REL); - joinVo.setCi(joinCiVo); - joinVo.setCiName(joinCiVo.getName()); - joinVo.setField(relFieldName); - if (StringUtils.isNotBlank(relDirection)) { - joinVo.setDirection(relDirection); - } - resourceEntityVo.addJoin(joinVo); - } - } - } - } - } - resourceEntityVo.setStatus(Status.PENDING.getValue()); - } catch (Exception ex) { - resourceEntityVo.setStatus(Status.ERROR.getValue()); - resourceEntityVo.setError(ex.getMessage()); - } - } -// /** -// * 将标签内容转换成SceneEntityVo -// * @param resourceElement -// * @return -// */ -// private void convertToSceneEntityVo(Element resourceElement) { -// Map> elementMap = new HashMap<>(); -// try { -// String viewName = sceneEntityVo.getName(); -// String ciName = resourceElement.attributeValue("ci"); -// if (StringUtils.isBlank(ciName)) { -// throw new ResourceCenterConfigIrregularException(viewName, "ci"); -// } -// CiVo ciVo = getCiByName(ciName); -// if (ciVo == null) { -// throw new CiNotFoundException(ciName); -// } -// sceneEntityVo.setCi(ciVo); -// resourceEntityVo.setCiId(ciVo.getId()); -// Map attToCiJoinMap = new HashMap<>(); -// Map relFromCiJoinMap = new HashMap<>(); -// Map relToCiJoinMap = new HashMap<>(); -// //分析连接查询 -// List sceneEntityJoinList = new ArrayList<>(); -// sceneEntityVo.setJoinList(sceneEntityJoinList); -// //先分析标签内容,因为后面分析标签时需要从标签中补充默认信息 -// List joinElementList = resourceElement.elements("join"); -// for (Element joinElement : joinElementList) { -// List attrElementList = joinElement.elements("attr"); -// if (CollectionUtils.isNotEmpty(attrElementList)) { -// for (Element attrElement : attrElementList) { -// SceneEntityJoinVo joinVo = convertToSceneEntityJoinVo(viewName, attrElement, JoinType.ATTR); -// String toCi = joinVo.getToCi(); -// if (StringUtils.isBlank(toCi)) { -// throw new ResourceCenterConfigIrregularException(viewName, "join->attr", joinVo.getField(), "toCi"); -// } -// CiVo toCiVo = getCiByName(toCi); -// if (toCiVo == null) { -// throw new CiNotFoundException(toCi); -// } -// joinVo.setToCiVo(toCiVo); -// String fromCi = joinVo.getFromCi(); -// if (StringUtils.isBlank(fromCi)) { -// fromCi = ciName; -// } -// CiVo fromCiVo = getCiByName(fromCi); -// if (fromCiVo == null) { -// throw new CiNotFoundException(ciName); -// } -// joinVo.setFromCiVo(fromCiVo); -// String fromAttr = joinVo.getFromAttr(); -// if (StringUtils.isNotBlank(fromAttr)) { -// if (!fromAttr.startsWith("_")) { -// AttrVo attrVo = fromCiVo.getAttrByName(fromAttr); -// if (attrVo == null) { -// throw new AttrNotFoundException(fromCi, fromAttr); -// } -// joinVo.setFromAttrVo(attrVo); -// } -// } else if (attrElement.getParent().getName().equalsIgnoreCase("join")) { -// joinVo.setFromAttr("_id"); -// } else { -// throw new ResourceCenterConfigIrregularException(viewName, "attr", joinVo.getField(), "fromAttr"); -// } -// if (!sceneEntityJoinList.contains(joinVo)) { -// sceneEntityJoinList.add(joinVo); -// } -// attToCiJoinMap.put(toCi, joinVo); -// } -// } -// -// List relElementList = joinElement.elements("rel"); -// if (CollectionUtils.isNotEmpty(relElementList)) { -// for (Element relElement : relElementList) { -// SceneEntityJoinVo joinVo = convertToSceneEntityJoinVo(viewName, relElement, JoinType.REL); -// if (Objects.equals(joinVo.getDirection(), RelDirectionType.FROM.getValue())) { -// String toCi = joinVo.getToCi(); -// if (StringUtils.isBlank(toCi)) { -// throw new ResourceCenterConfigIrregularException(viewName, "join->rel", joinVo.getField(), "toCi"); -// } -// CiVo toCiVo = getCiByName(toCi); -// if (toCiVo == null) { -// throw new CiNotFoundException(toCi); -// } -// joinVo.setToCiVo(toCiVo); -// String fromCi = joinVo.getFromCi(); -// if (StringUtils.isBlank(fromCi)) { -// fromCi = ciName; -// } -// CiVo fromCiVo = getCiByName(fromCi); -// if (fromCiVo == null) { -// throw new CiNotFoundException(fromCi); -// } -// joinVo.setFromCiVo(fromCiVo); -// relToCiJoinMap.put(toCi, joinVo); -// } else { -// String fromCi = joinVo.getFromCi(); -// if (StringUtils.isBlank(fromCi)) { -// throw new ResourceCenterConfigIrregularException(viewName, "join->rel", joinVo.getField(), "fromCi"); -// } -// CiVo fromCiVo = getCiByName(fromCi); -// if (fromCiVo == null) { -// throw new CiNotFoundException(fromCi); -// } -// joinVo.setFromCiVo(fromCiVo); -// String toCi = joinVo.getToCi(); -// if (StringUtils.isBlank(toCi)) { -// toCi = ciName; -// } -// CiVo toCiVo = getCiByName(toCi); -// if (toCiVo == null) { -// throw new CiNotFoundException(toCi); -// } -// joinVo.setToCiVo(toCiVo); -// relFromCiJoinMap.put(fromCi, joinVo); -// } -// if (!sceneEntityJoinList.contains(joinVo)) { -// sceneEntityJoinList.add(joinVo); -// } -// } -// } -// } -// //分析属性 -// { -// List attrElementList = elementMap.get(viewName + "_attr"); -// if (attrElementList == null) { -// attrElementList = getAllChildElement(resourceElement, "attr"); -// elementMap.put(viewName + "_attr", attrElementList); -// } -// List sceneEntityAttrList = new ArrayList<>(); -// sceneEntityVo.setAttrList(sceneEntityAttrList); -// for (Element attrElement : attrElementList) { -// SceneEntityAttrVo entityAttrVo = convertToSceneEntityAttrVo(viewName, attrElement, JoinType.ATTR); -// String fromCi = entityAttrVo.getFromCi(); -// if (StringUtils.isBlank(fromCi)) { -// fromCi = ciName; -// } -// CiVo fromCiVo = getCiByName(fromCi); -// if (fromCiVo == null) { -// throw new CiNotFoundException(fromCi); -// } -// entityAttrVo.setFromCiVo(fromCiVo); -// String fromAttr = entityAttrVo.getFromAttr(); -// if (StringUtils.isNotBlank(fromAttr)) { -// if (!fromAttr.startsWith("_")) { -// AttrVo attrVo = fromCiVo.getAttrByName(fromAttr); -// if (attrVo == null) { -// throw new AttrNotFoundException(fromCi, fromAttr); -// } -// entityAttrVo.setFromAttrVo(attrVo); -// } -// } else if (attrElement.getParent().getName().equalsIgnoreCase("join")) { -// entityAttrVo.setFromAttr("_id"); -// } -// String toCi = entityAttrVo.getToCi(); -// if (StringUtils.isNotBlank(toCi)) { -// entityAttrVo.setJoinType(JoinType.ATTR); -// CiVo toCiVo = getCiByName(toCi); -// if (toCiVo == null) { -// throw new CiNotFoundException(toCi); -// } -// entityAttrVo.setToCiVo(toCiVo); -// String toAttr = entityAttrVo.getToAttr(); -// if (StringUtils.isNotBlank(toAttr)) { -// if (!toAttr.startsWith("_")) { -// AttrVo attrVo = toCiVo.getAttrByName(toAttr); -// if (attrVo == null) { -// throw new AttrNotFoundException(toCi, toAttr); -// } -// entityAttrVo.setToAttrVo(attrVo); -// } -// } else if (attrElement.getParent().getName().equalsIgnoreCase("join")) { -// entityAttrVo.setToAttr("_id"); -// } else { -// throw new ResourceCenterConfigIrregularException(viewName, "attr", entityAttrVo.getField(), "toAttr"); -// } -// Integer toCiIsVirtual = toCiVo.getIsVirtual(); -// if (Objects.equals(toCiIsVirtual, 1)) { -// entityAttrVo.setToAttrCiId(toCiVo.getId()); -// entityAttrVo.setToAttrCiName(toCiVo.getName()); -// } -// if (StringUtils.isBlank(fromAttr)) { -// SceneEntityJoinVo joinVo = attToCiJoinMap.get(toCi); -// if (joinVo != null) { -// entityAttrVo.setFromCiVo(joinVo.getFromCiVo()); -// entityAttrVo.setFromAttrVo(joinVo.getFromAttrVo()); -// } -// } -// } -// if (!sceneEntityAttrList.contains(entityAttrVo)) { -// sceneEntityAttrList.add(entityAttrVo); -// } -// } -// List relElementList = elementMap.get(viewName + "_rel"); -// if (relElementList == null) { -// relElementList = getAllChildElement(resourceElement, "rel"); -// elementMap.put(viewName + "_rel", relElementList); -// } -// for (Element relElement : relElementList) { -// SceneEntityAttrVo entityAttrVo = convertToSceneEntityAttrVo(viewName, relElement, JoinType.REL); -// entityAttrVo.setJoinType(JoinType.REL); -// String fromCi = entityAttrVo.getFromCi(); -// String toCi = entityAttrVo.getToCi(); -// if (StringUtils.isBlank(fromCi) && StringUtils.isBlank(toCi)) { -// throw new ResourceCenterConfigIrregularException(viewName, "rel", entityAttrVo.getField(), "fromCi或toCi"); -// } -// String direction = entityAttrVo.getDirection(); -// if (StringUtils.isBlank(direction)) { -// if (StringUtils.isNotBlank(fromCi) && StringUtils.isNotBlank(toCi)) { -// direction = RelDirectionType.FROM.getValue(); -// } else if (StringUtils.isNotBlank(fromCi)) { -// direction = RelDirectionType.TO.getValue(); -// } else if (StringUtils.isNotBlank(toCi)) { -// direction = RelDirectionType.FROM.getValue(); -// } -// entityAttrVo.setDirection(direction); -// } -// if (Objects.equals(RelDirectionType.FROM.getValue(), direction)) { -// if (StringUtils.isBlank(toCi)) { -// throw new ResourceCenterConfigIrregularException(viewName, "rel", entityAttrVo.getField(), "toCi"); -// } -// CiVo toCiVo = getCiByName(toCi); -// if (toCiVo == null) { -// throw new CiNotFoundException(toCi); -// } -// entityAttrVo.setToCiVo(toCiVo); -// if (StringUtils.isBlank(fromCi)) { -// SceneEntityJoinVo joinVo = relToCiJoinMap.get(toCi); -// entityAttrVo.setFromCiVo(joinVo.getFromCiVo()); -// } else { -// CiVo fromCiVo = getCiByName(fromCi); -// if (fromCiVo == null) { -// throw new CiNotFoundException(fromCi); -// } -// entityAttrVo.setFromCiVo(fromCiVo); -// } -// } else if (Objects.equals(RelDirectionType.TO.getValue(), direction)) { -// if (StringUtils.isBlank(fromCi)) { -// throw new ResourceCenterConfigIrregularException(viewName, "rel", entityAttrVo.getField(), "fromCi"); -// } -// CiVo fromCiVo = getCiByName(fromCi); -// if (fromCiVo == null) { -// throw new CiNotFoundException(fromCi); -// } -// entityAttrVo.setFromCiVo(fromCiVo); -// if (StringUtils.isBlank(toCi)) { -// SceneEntityJoinVo joinVo = relFromCiJoinMap.get(fromCi); -// entityAttrVo.setToCiVo(joinVo.getToCiVo()); -// } else { -// CiVo toCiVo = getCiByName(toCi); -// if (toCiVo == null) { -// throw new CiNotFoundException(toCi); -// } -// entityAttrVo.setToCiVo(toCiVo); -// } -// } -// -// if (Objects.equals(RelDirectionType.TO.getValue(), direction)) { -// String fromAttr = entityAttrVo.getFromAttr(); -// if (StringUtils.isNotBlank(fromAttr)) { -// if (!fromAttr.startsWith("_")) { -// CiVo fromCiVo = entityAttrVo.getFromCiVo(); -// AttrVo attrVo = fromCiVo.getAttrByName(fromAttr); -// if (attrVo == null) { -// throw new AttrNotFoundException(fromCi, fromAttr); -// } -// entityAttrVo.setFromAttrVo(attrVo); -// } -// } else if (relElement.getParent().getName().equalsIgnoreCase("join")) { -// entityAttrVo.setFromAttr("_id"); -// } else { -// throw new ResourceCenterConfigIrregularException(viewName, "rel", entityAttrVo.getField(), "fromAttr"); -// } -// } else { -// String toAttr = entityAttrVo.getToAttr(); -// if (StringUtils.isNotBlank(toAttr)) { -// if (!toAttr.startsWith("_")) { -// CiVo toCiVo = entityAttrVo.getToCiVo(); -// AttrVo attrVo = toCiVo.getAttrByName(toAttr); -// if (attrVo == null) { -// throw new AttrNotFoundException(toCi, toAttr); -// } -// entityAttrVo.setToAttrVo(attrVo); -// } -// } else if (relElement.getParent().getName().equalsIgnoreCase("join")) { -// entityAttrVo.setToAttr("_id"); -// } else { -// throw new ResourceCenterConfigIrregularException(viewName, "rel", entityAttrVo.getField(), "toAttr"); -// } -// } -// if (!sceneEntityAttrList.contains(entityAttrVo)) { -// sceneEntityAttrList.add(entityAttrVo); -// } -// } -// } -// sceneEntityVo.setStatus(Status.PENDING.getValue()); -// } catch (Exception ex) { -// sceneEntityVo.setStatus(Status.ERROR.getValue()); -// sceneEntityVo.setError(ex.getMessage()); -// } -// } - - /** - * 解析join->attr元素 - * @param attrElement 元素信息 - * @param viewName 视图名称 - * @param ciName ci模型名称 - * @return 返回SceneEntityJoinVo对象 - */ - private SceneEntityJoinVo parseJoinAttrElement(Element attrElement, String viewName, String ciName) { - SceneEntityJoinVo joinVo = convertToSceneEntityJoinVo(viewName, attrElement, JoinType.ATTR); - String toCi = joinVo.getToCi(); - if (StringUtils.isBlank(toCi)) { - throw new ResourceCenterConfigIrregularException(viewName, "join->attr", joinVo.getField(), "toCi"); - } - CiVo toCiVo = getCiByName(toCi); - if (toCiVo == null) { - throw new CiNotFoundException(toCi); - } - joinVo.setToCiVo(toCiVo); - String fromCi = joinVo.getFromCi(); - if (StringUtils.isBlank(fromCi)) { - fromCi = ciName; - } - CiVo fromCiVo = getCiByName(fromCi); - if (fromCiVo == null) { - throw new CiNotFoundException(ciName); - } - joinVo.setFromCiVo(fromCiVo); - String fromAttr = joinVo.getFromAttr(); - if (StringUtils.isNotBlank(fromAttr)) { - if (!fromAttr.startsWith("_")) { - AttrVo attrVo = fromCiVo.getAttrByName(fromAttr); - if (attrVo == null) { - throw new AttrNotFoundException(fromCi, fromAttr); - } - joinVo.setFromAttrVo(attrVo); - } - } else if (attrElement.getParent().getName().equalsIgnoreCase("join")) { - joinVo.setFromAttr("_id"); - } else { - throw new ResourceCenterConfigIrregularException(viewName, "attr", joinVo.getField(), "fromAttr"); - } - return joinVo; - } - - /** - * 解析join->rel元素 - * @param relElement 元素信息 - * @param viewName 视图名称 - * @param ciName ci模型名称 - * @return 返回SceneEntityJoinVo对象 - */ - private SceneEntityJoinVo parseJoinRelElement(Element relElement, String viewName, String ciName) { - SceneEntityJoinVo joinVo = convertToSceneEntityJoinVo(viewName, relElement, JoinType.REL); - if (Objects.equals(joinVo.getDirection(), RelDirectionType.FROM.getValue())) { - String toCi = joinVo.getToCi(); - if (StringUtils.isBlank(toCi)) { - throw new ResourceCenterConfigIrregularException(viewName, "join->rel", joinVo.getField(), "toCi"); - } - CiVo toCiVo = getCiByName(toCi); - if (toCiVo == null) { - throw new CiNotFoundException(toCi); - } - joinVo.setToCiVo(toCiVo); - String fromCi = joinVo.getFromCi(); - if (StringUtils.isBlank(fromCi)) { - fromCi = ciName; - } - CiVo fromCiVo = getCiByName(fromCi); - if (fromCiVo == null) { - throw new CiNotFoundException(fromCi); - } - joinVo.setFromCiVo(fromCiVo); - } else { - String fromCi = joinVo.getFromCi(); - if (StringUtils.isBlank(fromCi)) { - throw new ResourceCenterConfigIrregularException(viewName, "join->rel", joinVo.getField(), "fromCi"); - } - CiVo fromCiVo = getCiByName(fromCi); - if (fromCiVo == null) { - throw new CiNotFoundException(fromCi); - } - joinVo.setFromCiVo(fromCiVo); - String toCi = joinVo.getToCi(); - if (StringUtils.isBlank(toCi)) { - toCi = ciName; - } - CiVo toCiVo = getCiByName(toCi); - if (toCiVo == null) { - throw new CiNotFoundException(toCi); - } - joinVo.setToCiVo(toCiVo); - } - return joinVo; - } - - /** - * 解析attr元素 - * @param attrElement 元素信息 - * @param viewName 视图名称 - * @param ciName ci模型名称 - * @param attToCiJoinMap 属性join信息映射 - * @return 返回SceneEntityAttrVo对象 - */ - private SceneEntityAttrVo parseAttrElement(Element attrElement, String viewName, String ciName, Map attToCiJoinMap) { - SceneEntityAttrVo entityAttrVo = convertToSceneEntityAttrVo(viewName, attrElement, JoinType.ATTR); - String fromCi = entityAttrVo.getFromCi(); - if (StringUtils.isBlank(fromCi)) { - fromCi = ciName; - } - CiVo fromCiVo = getCiByName(fromCi); - if (fromCiVo == null) { - throw new CiNotFoundException(fromCi); - } - entityAttrVo.setFromCiVo(fromCiVo); - String fromAttr = entityAttrVo.getFromAttr(); - if (StringUtils.isNotBlank(fromAttr)) { - if (!fromAttr.startsWith("_")) { - AttrVo attrVo = fromCiVo.getAttrByName(fromAttr); - if (attrVo == null) { - throw new AttrNotFoundException(fromCi, fromAttr); - } - entityAttrVo.setFromAttrVo(attrVo); - } - } else if (attrElement.getParent().getName().equalsIgnoreCase("join")) { - entityAttrVo.setFromAttr("_id"); - } - String toCi = entityAttrVo.getToCi(); - if (StringUtils.isNotBlank(toCi)) { - entityAttrVo.setJoinType(JoinType.ATTR); - CiVo toCiVo = getCiByName(toCi); - if (toCiVo == null) { - throw new CiNotFoundException(toCi); - } - entityAttrVo.setToCiVo(toCiVo); - String toAttr = entityAttrVo.getToAttr(); - if (StringUtils.isNotBlank(toAttr)) { - if (!toAttr.startsWith("_")) { - AttrVo attrVo = toCiVo.getAttrByName(toAttr); - if (attrVo == null) { - throw new AttrNotFoundException(toCi, toAttr); - } - entityAttrVo.setToAttrVo(attrVo); - } - } else if (attrElement.getParent().getName().equalsIgnoreCase("join")) { - entityAttrVo.setToAttr("_id"); - } else { - throw new ResourceCenterConfigIrregularException(viewName, "attr", entityAttrVo.getField(), "toAttr"); - } - Integer toCiIsVirtual = toCiVo.getIsVirtual(); - if (Objects.equals(toCiIsVirtual, 1)) { - entityAttrVo.setToAttrCiId(toCiVo.getId()); - entityAttrVo.setToAttrCiName(toCiVo.getName()); - } - if (StringUtils.isBlank(fromAttr)) { - SceneEntityJoinVo joinVo = attToCiJoinMap.get(toCi); - if (joinVo == null) { - throw new ResourceCenterConfigIrregularException(viewName, "attr", entityAttrVo.getField(), "fromAttr"); - } - entityAttrVo.setFromCiVo(joinVo.getFromCiVo()); - entityAttrVo.setFromAttrVo(joinVo.getFromAttrVo()); - } - } - return entityAttrVo; - } - - /** - * 解析attr元素 - * @param relElement 元素信息 - * @param viewName 视图名称 - * @param relFromCiJoinMap 上游关系join信息映射 - * @param relToCiJoinMap 下游关系join信息映射 - * @return 返回SceneEntityAttrVo对象 - */ - private SceneEntityAttrVo parseRelElement(Element relElement, String viewName, Map relFromCiJoinMap, Map relToCiJoinMap) { - SceneEntityAttrVo entityAttrVo = convertToSceneEntityAttrVo(viewName, relElement, JoinType.REL); - entityAttrVo.setJoinType(JoinType.REL); - String fromCi = entityAttrVo.getFromCi(); - String toCi = entityAttrVo.getToCi(); - if (StringUtils.isBlank(fromCi) && StringUtils.isBlank(toCi)) { - throw new ResourceCenterConfigIrregularException(viewName, "rel", entityAttrVo.getField(), "fromCi或toCi"); - } - String direction = entityAttrVo.getDirection(); - if (StringUtils.isBlank(direction)) { - if (StringUtils.isNotBlank(fromCi) && StringUtils.isNotBlank(toCi)) { - direction = RelDirectionType.FROM.getValue(); - } else if (StringUtils.isNotBlank(fromCi)) { - direction = RelDirectionType.TO.getValue(); - } else if (StringUtils.isNotBlank(toCi)) { - direction = RelDirectionType.FROM.getValue(); - } - entityAttrVo.setDirection(direction); - } - if (Objects.equals(RelDirectionType.FROM.getValue(), direction)) { - if (StringUtils.isBlank(toCi)) { - throw new ResourceCenterConfigIrregularException(viewName, "rel", entityAttrVo.getField(), "toCi"); - } - CiVo toCiVo = getCiByName(toCi); - if (toCiVo == null) { - throw new CiNotFoundException(toCi); - } - entityAttrVo.setToCiVo(toCiVo); - if (StringUtils.isBlank(fromCi)) { - SceneEntityJoinVo joinVo = relToCiJoinMap.get(toCi); - entityAttrVo.setFromCiVo(joinVo.getFromCiVo()); - } else { - CiVo fromCiVo = getCiByName(fromCi); - if (fromCiVo == null) { - throw new CiNotFoundException(fromCi); - } - entityAttrVo.setFromCiVo(fromCiVo); - } - } else if (Objects.equals(RelDirectionType.TO.getValue(), direction)) { - if (StringUtils.isBlank(fromCi)) { - throw new ResourceCenterConfigIrregularException(viewName, "rel", entityAttrVo.getField(), "fromCi"); - } - CiVo fromCiVo = getCiByName(fromCi); - if (fromCiVo == null) { - throw new CiNotFoundException(fromCi); - } - entityAttrVo.setFromCiVo(fromCiVo); - if (StringUtils.isBlank(toCi)) { - SceneEntityJoinVo joinVo = relFromCiJoinMap.get(fromCi); - entityAttrVo.setToCiVo(joinVo.getToCiVo()); - } else { - CiVo toCiVo = getCiByName(toCi); - if (toCiVo == null) { - throw new CiNotFoundException(toCi); - } - entityAttrVo.setToCiVo(toCiVo); - } - } - - if (Objects.equals(RelDirectionType.TO.getValue(), direction)) { - String fromAttr = entityAttrVo.getFromAttr(); - if (StringUtils.isNotBlank(fromAttr)) { - if (!fromAttr.startsWith("_")) { - CiVo fromCiVo = entityAttrVo.getFromCiVo(); - AttrVo attrVo = fromCiVo.getAttrByName(fromAttr); - if (attrVo == null) { - throw new AttrNotFoundException(fromCi, fromAttr); - } - entityAttrVo.setFromAttrVo(attrVo); - } - } else if (relElement.getParent().getName().equalsIgnoreCase("join")) { - entityAttrVo.setFromAttr("_id"); - } else { - throw new ResourceCenterConfigIrregularException(viewName, "rel", entityAttrVo.getField(), "fromAttr"); - } - } else { - String toAttr = entityAttrVo.getToAttr(); - if (StringUtils.isNotBlank(toAttr)) { - if (!toAttr.startsWith("_")) { - CiVo toCiVo = entityAttrVo.getToCiVo(); - AttrVo attrVo = toCiVo.getAttrByName(toAttr); - if (attrVo == null) { - throw new AttrNotFoundException(toCi, toAttr); - } - entityAttrVo.setToAttrVo(attrVo); - } - } else if (relElement.getParent().getName().equalsIgnoreCase("join")) { - entityAttrVo.setToAttr("_id"); - } else { - throw new ResourceCenterConfigIrregularException(viewName, "rel", entityAttrVo.getField(), "toAttr"); - } - } - return entityAttrVo; - } - - /** - * 按顺序将标签内容转换成SceneEntityVo - * @param sceneElement - * @return - */ - private void convertToSceneEntityVo(Element sceneElement) { - try { - String viewName = sceneEntityVo.getName(); - String ciName = sceneElement.attributeValue("ci"); - if (StringUtils.isBlank(ciName)) { - throw new ResourceCenterConfigIrregularException(viewName, "ci"); - } - CiVo ciVo = getCiByName(ciName); - if (ciVo == null) { - throw new CiNotFoundException(ciName); - } - sceneEntityVo.setCi(ciVo); - resourceEntityVo.setCiId(ciVo.getId()); - List sceneEntityAttrList = new ArrayList<>(); - sceneEntityVo.setAttrList(sceneEntityAttrList); - Map attToCiJoinMap = new HashMap<>(); - Map relFromCiJoinMap = new HashMap<>(); - Map relToCiJoinMap = new HashMap<>(); - List elementList = sceneElement.elements(); - for (Element element : elementList) { - String name = element.getName(); - if ("join".equals(name)) { - List attrElementList = element.elements("attr"); - if (CollectionUtils.isNotEmpty(attrElementList)) { - for (Element attrElement : attrElementList) { - SceneEntityJoinVo joinVo = parseJoinAttrElement(attrElement, viewName, ciName); - attToCiJoinMap.put(joinVo.getToCi(), joinVo); - SceneEntityAttrVo entityAttrVo = parseAttrElement(attrElement, viewName, ciName, attToCiJoinMap); - if (!sceneEntityAttrList.contains(entityAttrVo)) { - sceneEntityAttrList.add(entityAttrVo); - } - } - } - List relElementList = element.elements("rel"); - if (CollectionUtils.isNotEmpty(relElementList)) { - for (Element relElement : relElementList) { - SceneEntityJoinVo joinVo = parseJoinRelElement(relElement, viewName, ciName); - if (Objects.equals(joinVo.getDirection(), RelDirectionType.FROM.getValue())) { - relToCiJoinMap.put(joinVo.getToCi(), joinVo); - } else { - relFromCiJoinMap.put(joinVo.getFromCi(), joinVo); - } - SceneEntityAttrVo entityAttrVo = parseRelElement(relElement, viewName, relFromCiJoinMap, relToCiJoinMap); - if (!sceneEntityAttrList.contains(entityAttrVo)) { - sceneEntityAttrList.add(entityAttrVo); - } - } - } - } else if ("attr".equals(name)) { - SceneEntityAttrVo entityAttrVo = parseAttrElement(element, viewName, ciName, attToCiJoinMap); - if (!sceneEntityAttrList.contains(entityAttrVo)) { - sceneEntityAttrList.add(entityAttrVo); - } - } else if ("rel".equals(name)) { - SceneEntityAttrVo entityAttrVo = parseRelElement(element, viewName, relFromCiJoinMap, relToCiJoinMap); - if (!sceneEntityAttrList.contains(entityAttrVo)) { - sceneEntityAttrList.add(entityAttrVo); - } - } - } - List definedFieldList = sceneEntityAttrList.stream().map(SceneEntityAttrVo::getField).collect(Collectors.toList()); - List declaredFieldList = ResourceEntityFactory.getFieldNameListByViewName(viewName); - List undefinedFieldList = ListUtils.removeAll(declaredFieldList, definedFieldList); - if (CollectionUtils.isNotEmpty(undefinedFieldList)) { - throw new ResourceCenterViewConfigException(viewName, String.join(",", undefinedFieldList)); - } - sceneEntityVo.setStatus(Status.PENDING.getValue()); - } catch (Exception ex) { - sceneEntityVo.setStatus(Status.ERROR.getValue()); - sceneEntityVo.setError(ex.getMessage()); - } - } - - /** - * 将标签内容转换成SceneEntityAttrVo - * @param element - * @return - */ - private SceneEntityAttrVo convertToSceneEntityAttrVo(String viewName, Element element, JoinType joinType) { - String field = element.attributeValue("field"); -// String resource = element.attributeValue("resource"); - if (StringUtils.isBlank(field)) { - throw new ResourceCenterConfigIrregularException(viewName, joinType, "field"); - } - List fieldList = ResourceEntityFactory.getFieldNameListByViewName(viewName); - if (!fieldList.contains(field)) { - throw new ResourceCenterResourceFoundException(viewName, field); - } -// if (StringUtils.isBlank(resource)) { -// throw new ResourceCenterConfigIrregularException(viewName, joinType, "resource"); -// } -// checkResourceAndField(resource, field); - String direction = element.attributeValue("direction"); - String fromCi = element.attributeValue("fromCi"); - String toCi = element.attributeValue("toCi"); - String fromAttr = element.attributeValue("fromAttr"); - String toAttr = element.attributeValue("toAttr"); - SceneEntityAttrVo attrVo = new SceneEntityAttrVo(); - attrVo.setField(field); -// attrVo.setResource(resource); - attrVo.setDirection(direction); - attrVo.setFromCi(fromCi); - attrVo.setToCi(toCi); - attrVo.setFromAttr(fromAttr); - attrVo.setToAttr(toAttr); - return attrVo; - } - - /** - * 将标签内容转换成SceneEntityJoinVo - * @param viewName - * @param element - * @param joinType - * @return - */ - private SceneEntityJoinVo convertToSceneEntityJoinVo(String viewName, Element element, JoinType joinType) { - String field = element.attributeValue("field"); -// String resource = element.attributeValue("resource"); - if (StringUtils.isBlank(field)) { - throw new ResourceCenterConfigIrregularException(viewName, joinType, "field"); - } - List fieldList = ResourceEntityFactory.getFieldNameListByViewName(viewName); - if (!fieldList.contains(field)) { - throw new ResourceCenterResourceFoundException(viewName, field); - } -// if (StringUtils.isBlank(resource)) { -// throw new ResourceCenterConfigIrregularException(viewName, joinType, "resource"); -// } -// checkResourceAndField(resource, field); - String direction = element.attributeValue("direction"); - String fromCi = element.attributeValue("fromCi"); - String toCi = element.attributeValue("toCi"); - String fromAttr = element.attributeValue("fromAttr"); - String toAttr = element.attributeValue("toAttr"); - SceneEntityJoinVo joinVo = new SceneEntityJoinVo(joinType); - joinVo.setField(field); -// joinVo.setResource(resource); - joinVo.setDirection(direction); - joinVo.setFromCi(fromCi); - joinVo.setToCi(toCi); - joinVo.setFromAttr(fromAttr); - joinVo.setToAttr(toAttr); - return joinVo; - } - - /** - * 检查resource和field是否合格 - * @param resource - * @param field - */ - @Deprecated - private void checkResourceAndField(String resource, String field) { - List resourceEntityList = ResourceEntityFactory.getResourceEntityList(); - Optional optionalEntity = resourceEntityList.stream().filter(e -> Objects.equals(e.getName(), resource)).findFirst(); - if (!optionalEntity.isPresent()) { - throw new ResourceCenterResourceFoundException(resource); - } - ResourceEntityVo resourceEntityVo = optionalEntity.get(); - Set attrList = resourceEntityVo.getAttrList(); - if (CollectionUtils.isEmpty(attrList)) { - throw new ResourceCenterResourceFoundException(resource, field); - } - Optional optionalAttr = attrList.stream().filter(e -> Objects.equals(e.getField(), field)).findFirst(); - if (!optionalAttr.isPresent()) { - throw new ResourceCenterResourceFoundException(resource, field); - } - } - private ResourceEntityVo createResourceEntityVo(ResourceEntityVo resourceEntityVo) { - ResourceEntityVo resourceEntity = new ResourceEntityVo(); - resourceEntity.setName(resourceEntityVo.getName()); - resourceEntity.setLabel(resourceEntityVo.getLabel()); - Set attrList = resourceEntityVo.getAttrList(); - if (CollectionUtils.isNotEmpty(attrList)) { - for (ResourceEntityAttrVo resourceEntityAttrVo : attrList) { - ResourceEntityAttrVo attrVo = new ResourceEntityAttrVo(); - attrVo.setField(resourceEntityAttrVo.getField()); - resourceEntity.addAttr(attrVo); - } - } - return resourceEntity; - } - /** - * 检查模型中是否存在对应属性 - * @param ciVo - * @param attrName - */ - private boolean checkAttrIsExists(CiVo ciVo, String attrName) { - if (defaultAttrList.contains(attrName)) { - return true; - } - List attrList = ciVo.getAttrList(); - if (CollectionUtils.isNotEmpty(attrList)) { - for (AttrVo attrVo : attrList) { - if (Objects.equals(attrVo.getName(), attrName)) { - return true; - } - } - } - throw new AttrNotFoundException(ciVo.getName(), attrName); - } - - - public void buildView() { - if (Objects.equals(type, ViewType.RESOURCE.getValue())) { - buildResource(); - } else if (Objects.equals(type, ViewType.SCENE.getValue())) { - buildScene(); - } - } - - private void buildResource() { - if (StringUtils.isNotBlank(resourceEntityVo.getError())) { - resourceEntityVo.setStatus(Status.ERROR.getValue()); - resourceEntityMapper.updateResourceEntityStatusAndError(resourceEntityVo); - return; - } - Table mainTable = new Table(); - mainTable.setSchemaName(TenantContext.get().getDbName()); - mainTable.setName("cmdb_cientity"); - mainTable.setAlias(new Alias("ci_base")); - Select select = SelectUtils.buildSelectFromTableAndSelectItems(mainTable); - SelectBody selectBody = select.getSelectBody(); - PlainSelect plainSelect = (PlainSelect) selectBody; - - - plainSelect.addJoins(new Join() - .withRightItem(new SubSelect() - .withSelectBody(buildSubSelectForCi(resourceEntityVo.getCi()).getSelectBody()) - .withAlias(new Alias(resourceEntityVo.getName().toLowerCase(Locale.ROOT)))) - .addOnExpression(new EqualsTo().withLeftExpression(new Column() - .withTable(new Table("ci_base")) - .withColumnName("id")) - .withRightExpression(new Column() - .withTable(new Table(resourceEntityVo.getName())) - .withColumnName("id")))); - - if (CollectionUtils.isNotEmpty(resourceEntityVo.getAttrList())) { - for (ResourceEntityAttrVo entityAttr : resourceEntityVo.getAttrList()) { - SelectExpressionItem selectItem = new SelectExpressionItem(); - if (entityAttr.getAttr().startsWith("_")) { - selectItem.setExpression(new Column(entityAttr.getTableAlias() + "." + entityAttr.getAttr().substring(1))); - } else if (entityAttr.getAttrId() != null) { - selectItem.setExpression(new Column(entityAttr.getTableAlias() + ".`" + entityAttr.getAttrId() + "`")); - } - selectItem.setAlias(new Alias(entityAttr.getField().toLowerCase(Locale.ROOT))); - plainSelect.addSelectItems(selectItem); - } - } - - if (CollectionUtils.isNotEmpty(resourceEntityVo.getJoinList())) { - List joinList = new ArrayList<>(); - for (ResourceEntityJoinVo entityJoin : resourceEntityVo.getJoinList()) { - if (entityJoin.getJoinType() == JoinType.ATTR) { - plainSelect.addJoins(new Join() - //.withLeft(true) - .withRightItem(new Table() - .withName("cmdb_attrentity") - .withSchemaName(TenantContext.get().getDbName()) - .withAlias(new Alias("cmdb_attrentity_" + entityJoin.getField().toLowerCase(Locale.ROOT)))) - .addOnExpression(new EqualsTo() - .withLeftExpression(new Column() - .withTable(new Table("ci_base")) - .withColumnName("id")) - .withRightExpression(new Column() - .withTable(new Table("cmdb_attrentity_" + entityJoin.getField().toLowerCase(Locale.ROOT))) - .withColumnName("from_cientity_id")))); - if (StringUtils.isNotBlank(entityJoin.getJoinAttrName())) { - plainSelect.addJoins(new Join() - .withRightItem(new Table() - .withName("cmdb_attr") - .withSchemaName(TenantContext.get().getDbName()) - .withAlias(new Alias("cmdb_attr_" + entityJoin.getJoinAttrName().toLowerCase(Locale.ROOT))) - ).addOnExpression(new AndExpression() - .withLeftExpression(new EqualsTo() - .withLeftExpression(new Column() - .withTable(new Table("cmdb_attr_" + entityJoin.getJoinAttrName().toLowerCase(Locale.ROOT))) - .withColumnName("id")) - .withRightExpression(new Column() - .withTable(new Table("cmdb_attrentity_" + entityJoin.getField().toLowerCase(Locale.ROOT))) - .withColumnName("attr_id"))) - .withRightExpression(new EqualsTo() - .withLeftExpression(new Column() - .withTable(new Table("cmdb_attr_" + entityJoin.getJoinAttrName().toLowerCase(Locale.ROOT))) - .withColumnName("name")) - .withRightExpression(new StringValue(entityJoin.getJoinAttrName())))) - ); - } - plainSelect.addJoins(new Join() - //.withLeft(true) - .withRightItem(new SubSelect() - .withSelectBody(buildSubSelectForCi(entityJoin.getCi()).getSelectBody()) - .withAlias(new Alias("target_cientity_" + entityJoin.getCi().getName().toLowerCase(Locale.ROOT))) - ).addOnExpression(new EqualsTo() - .withLeftExpression(new Column() - .withTable(new Table("cmdb_attrentity_" + entityJoin.getField())) - .withColumnName("to_cientity_id")) - .withRightExpression(new Column() - .withTable(new Table("target_cientity_" + entityJoin.getCi().getName().toLowerCase(Locale.ROOT))) - .withColumnName("id")))); - } else if (entityJoin.getJoinType() == JoinType.REL) { - plainSelect.addJoins(new Join() - .withRightItem(new Table() - .withName("cmdb_relentity") - .withSchemaName(TenantContext.get().getDbName()) - .withAlias(new Alias("cmdb_relentity_" + entityJoin.getField().toLowerCase(Locale.ROOT)))) - .addOnExpression(new EqualsTo() - .withLeftExpression(new Column() - .withTable(new Table("ci_base")) - .withColumnName("id")) - .withRightExpression(new Column() - .withTable(new Table("cmdb_relentity_" + entityJoin.getField().toLowerCase(Locale.ROOT))) - .withColumnName(entityJoin.getDirection().equals(RelDirectionType.FROM.getValue()) ? "from_cientity_id" : "to_cientity_id")))); - - plainSelect.addJoins(new Join() - .withRightItem(new SubSelect() - .withSelectBody(buildSubSelectForCi(entityJoin.getCi()).getSelectBody()) - .withAlias(new Alias("target_cientity_" + entityJoin.getCi().getName().toLowerCase(Locale.ROOT))) - ).addOnExpression(new EqualsTo() - .withLeftExpression(new Column() - .withTable(new Table("cmdb_relentity_" + entityJoin.getField().toLowerCase(Locale.ROOT))) - .withColumnName(entityJoin.getDirection().equals(RelDirectionType.FROM.getValue()) ? "to_cientity_id" : "from_cientity_id")) - .withRightExpression(new Column() - .withTable(new Table("target_cientity_" + entityJoin.getCi().getName().toLowerCase(Locale.ROOT))) - .withColumnName("id")))); - } - } - if (CollectionUtils.isNotEmpty(joinList)) { - plainSelect.addJoins(joinList); - } - } - - String viewName = resourceEntityVo.getName(); - String selectSql = select.toString(); - String md5 = Md5Util.encryptMD5(selectSql); - String tableType = schemaMapper.checkTableOrViewIsExists(TenantContext.get().getDataDbName(), viewName); - if (tableType != null) { - if (Objects.equals(tableType, "SYSTEM VIEW")) { - return; - } else if (Objects.equals(tableType, "VIEW")) { - DataBaseViewInfoVo dataBaseViewInfoVo = dataBaseViewInfoMapper.getDataBaseViewInfoByViewName(viewName); - if (dataBaseViewInfoVo != null) { - if (Objects.equals(md5, dataBaseViewInfoVo.getMd5())) { - return; - } - } - } - } - - try { - EscapeTransactionJob.State s = new EscapeTransactionJob(() -> { - if (Objects.equals(tableType, "BASE TABLE")) { - schemaMapper.deleteTable(TenantContext.get().getDataDbName() + "." + viewName); - } - String sql = "CREATE OR REPLACE VIEW " + TenantContext.get().getDataDbName() + "." + viewName + " AS " + selectSql; - if (logger.isDebugEnabled()) { - logger.debug(sql); - } - schemaMapper.insertView(sql); - }).execute(); - if (s.isSucceed()) { - resourceEntityVo.setError(""); - resourceEntityVo.setStatus(Status.READY.getValue()); - DataBaseViewInfoVo dataBaseViewInfoVo = new DataBaseViewInfoVo(); - dataBaseViewInfoVo.setViewName(viewName); - dataBaseViewInfoVo.setMd5(md5); - dataBaseViewInfoVo.setLcu(UserContext.get().getUserUuid()); - dataBaseViewInfoMapper.insertDataBaseViewInfo(dataBaseViewInfoVo); - } else { - resourceEntityVo.setError(s.getError()); - resourceEntityVo.setStatus(Status.ERROR.getValue()); - } - } catch (Exception ex) { - resourceEntityVo.setError(ex.getMessage()); - resourceEntityVo.setStatus(Status.ERROR.getValue()); - Table table = new Table(); - table.setName(viewName); - table.setSchemaName(TenantContext.get().getDataDbName()); - List columnDefinitions = new ArrayList<>(); - Set attrList = resourceEntityVo.getAttrList(); - for (ResourceEntityAttrVo attrVo : attrList) { - ColumnDefinition columnDefinition = new ColumnDefinition(); - columnDefinition.setColumnName(attrVo.getField()); - columnDefinition.setColDataType(new ColDataType("int")); - columnDefinitions.add(columnDefinition); - } - CreateTable createTable = new CreateTable(); - createTable.setTable(table); - createTable.setColumnDefinitions(columnDefinitions); - createTable.setIfNotExists(true); - EscapeTransactionJob.State s = new EscapeTransactionJob(() -> { - schemaMapper.insertView(createTable.toString()); - }).execute(); - } finally { - resourceEntityMapper.updateResourceEntityStatusAndError(resourceEntityVo); - } - } - private void buildScene() { - //创建场景视图 - ResourceEntityVo resourceEntityVo = new ResourceEntityVo(); - resourceEntityVo.setName(sceneEntityVo.getName()); - resourceEntityVo.setLabel(sceneEntityVo.getLabel()); - resourceEntityVo.setCiId(sceneEntityVo.getCiId()); - if (StringUtils.isNotBlank(sceneEntityVo.getError())) { - resourceEntityVo.setError(sceneEntityVo.getError()); - resourceEntityVo.setStatus(Status.ERROR.getValue()); - resourceEntityMapper.updateResourceEntityStatusAndError(resourceEntityVo); - return; - } - String viewName = sceneEntityVo.getName(); - SceneEntityGenerateSqlUtil sceneEntityGenerateSqlUtil = new SceneEntityGenerateSqlUtil(sceneEntityVo); - String selectSql = sceneEntityGenerateSqlUtil.getSql(); - String md5 = Md5Util.encryptMD5(selectSql); - String tableType = schemaMapper.checkTableOrViewIsExists(TenantContext.get().getDataDbName(), viewName); - if (tableType != null) { - if (Objects.equals(tableType, "SYSTEM VIEW")) { - return; - } else if (Objects.equals(tableType, "VIEW")) { - DataBaseViewInfoVo dataBaseViewInfoVo = dataBaseViewInfoMapper.getDataBaseViewInfoByViewName(viewName); - if (dataBaseViewInfoVo != null) { - // md5相同就不用更新视图了 - if (Objects.equals(md5, dataBaseViewInfoVo.getMd5())) { - return; - } - } - } - } - try { - - EscapeTransactionJob.State s = new EscapeTransactionJob(() -> { - if (Objects.equals(tableType, "BASE TABLE")) { - schemaMapper.deleteTable(TenantContext.get().getDataDbName() + "." + viewName); - } - String sql = "CREATE OR REPLACE VIEW " + TenantContext.get().getDataDbName() + "." + viewName + " AS " + selectSql; - if (logger.isDebugEnabled()) { - logger.debug(sql); - } - schemaMapper.insertView(sql); - }).execute(); - if (s.isSucceed()) { - resourceEntityVo.setError(""); - resourceEntityVo.setStatus(Status.READY.getValue()); - DataBaseViewInfoVo dataBaseViewInfoVo = new DataBaseViewInfoVo(); - dataBaseViewInfoVo.setViewName(viewName); - dataBaseViewInfoVo.setMd5(md5); - dataBaseViewInfoVo.setLcu(UserContext.get().getUserUuid()); - dataBaseViewInfoMapper.insertDataBaseViewInfo(dataBaseViewInfoVo); - } else { - resourceEntityVo.setError(s.getError()); - resourceEntityVo.setStatus(Status.ERROR.getValue()); - } - - } catch (Exception ex) { - resourceEntityVo.setError(ex.getMessage()); - resourceEntityVo.setStatus(Status.ERROR.getValue()); - if (Objects.equals(tableType, "VIEW")) { - schemaMapper.deleteView(TenantContext.get().getDataDbName() + "." + viewName); - } - List fieldNameList = ResourceEntityFactory.getFieldNameListByViewName(viewName); - Table table = new Table(); - table.setName(viewName); - table.setSchemaName(TenantContext.get().getDataDbName()); - List columnDefinitions = new ArrayList<>(); - for (String columnName : fieldNameList) { - ColumnDefinition columnDefinition = new ColumnDefinition(); - columnDefinition.setColumnName(columnName); - columnDefinition.setColDataType(new ColDataType("int")); - columnDefinitions.add(columnDefinition); - } - CreateTable createTable = new CreateTable(); - createTable.setTable(table); - createTable.setColumnDefinitions(columnDefinitions); - createTable.setIfNotExists(true); - EscapeTransactionJob.State s = new EscapeTransactionJob(() -> { - schemaMapper.insertView(createTable.toString()); - }).execute(); - } finally { - resourceEntityMapper.updateResourceEntityStatusAndError(resourceEntityVo); - } - } - private Select buildSubSelectForCi(CiVo ciVo) { - if (CollectionUtils.isNotEmpty(ciVo.getUpwardCiList())) { - Table mainTable = new Table(); - mainTable.setSchemaName(TenantContext.get().getDbName()); - mainTable.setName("cmdb_cientity"); - mainTable.setAlias(new Alias("ci_base")); - Select select = SelectUtils.buildSelectFromTableAndSelectItems(mainTable); - SelectBody selectBody = select.getSelectBody(); - PlainSelect plainSelect = (PlainSelect) selectBody; - //内置属性统一在这里添加 - plainSelect.addSelectItems(new SelectExpressionItem(new Column("id").withTable(new Table("ci_base")))); - plainSelect.addSelectItems(new SelectExpressionItem(new Column("uuid").withTable(new Table("ci_base")))); - plainSelect.addSelectItems(new SelectExpressionItem(new Column("name").withTable(new Table("ci_base")))); - plainSelect.addSelectItems(new SelectExpressionItem(new Column("fcu").withTable(new Table("ci_base")))); - plainSelect.addSelectItems(new SelectExpressionItem(new Column("fcd").withTable(new Table("ci_base")))); - plainSelect.addSelectItems(new SelectExpressionItem(new Column("lcu").withTable(new Table("ci_base")))); - plainSelect.addSelectItems(new SelectExpressionItem(new Column("lcd").withTable(new Table("ci_base")))); - plainSelect.addSelectItems(new SelectExpressionItem(new Column("inspect_status").withTable(new Table("ci_base"))).withAlias(new Alias("inspectStatus"))); - plainSelect.addSelectItems(new SelectExpressionItem(new Column("inspect_time").withTable(new Table("ci_base"))).withAlias(new Alias("inspectTime"))); - plainSelect.addSelectItems(new SelectExpressionItem(new Column("monitor_status").withTable(new Table("ci_base"))).withAlias(new Alias("monitorStatus"))); - plainSelect.addSelectItems(new SelectExpressionItem(new Column("monitor_time").withTable(new Table("ci_base"))).withAlias(new Alias("monitorTime"))); - - - plainSelect.addSelectItems(new SelectExpressionItem(new Column("id").withTable(new Table("ci_info"))).withAlias(new Alias("typeId"))); - plainSelect.addSelectItems(new SelectExpressionItem(new Column("name").withTable(new Table("ci_info"))).withAlias(new Alias("typeName"))); - plainSelect.addSelectItems(new SelectExpressionItem(new Column("label").withTable(new Table("ci_info"))).withAlias(new Alias("typeLabel"))); - for (AttrVo attrVo : ciVo.getAttrList()) { - if (attrVo.getTargetCiId() == null) { - plainSelect.addSelectItems(new SelectExpressionItem(new Column("`" + attrVo.getId() + "`").withTable(new Table("cmdb_" + attrVo.getCiId())))); - } - } - - plainSelect.addJoins(new Join() - .withRightItem(new Table() - .withName("cmdb_ci") - .withAlias(new Alias("ci_info")) - .withSchemaName(TenantContext.get().getDbName())) - .withOnExpression(new EqualsTo() - .withLeftExpression(new Column() - .withTable(new Table("ci_base")) - .withColumnName("ci_id")) - .withRightExpression(new Column() - .withTable(new Table("ci_info")) - .withColumnName("id")))); - - //生成主SQL,需要join所有父模型数据表 - for (CiVo ci : ciVo.getUpwardCiList()) { - plainSelect.addJoins(new Join() - .withRightItem(new Table() - .withName("cmdb_" + ci.getId()) - .withSchemaName(TenantContext.get().getDataDbName()) - .withAlias(new Alias("cmdb_" + ci.getId()))) - .withOnExpression(new EqualsTo() - .withLeftExpression(new Column() - .withTable(new Table("ci_base")) - .withColumnName("id")) - .withRightExpression(new Column() - .withTable(new Table("cmdb_" + ci.getId())) - .withColumnName("cientity_id")))); - - } - return select; - } else { - Table mainTable = new Table(); - mainTable.setSchemaName(TenantContext.get().getDataDbName()); - mainTable.setName("cmdb_" + ciVo.getId()); - return SelectUtils.buildSelectFromTable(mainTable); - } - } -} -- Gitee From d3153fe3e6f65a735d36cffa94efe96f369ae28f Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Thu, 20 Feb 2025 16:56:09 +0800 Subject: [PATCH 04/29] =?UTF-8?q?[=E4=BF=AE=E5=A4=8D]=20CMDB=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E6=B8=85=E5=8D=95=E6=94=B9=E6=88=90=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E5=B1=82=E7=BA=A7=E5=8F=AF=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1349157963399168]CMDB应用清单改成模型层级可配置 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1349157963399168 --- .../app/AppResourceListApi.java | 121 +++++++++++ .../mapper/resourcecenter/ResourceMapper.java | 2 + .../mapper/resourcecenter/ResourceMapper.xml | 9 + .../DefaultResourceCenterDataSourceImpl.java | 194 ++++++++++++++++++ .../IResourceCenterResourceService.java | 2 + .../ResourceCenterResourceServiceImpl.java | 43 ++++ .../changelog/2025-02-20/neatlogic_tenant.sql | 9 + .../cmdb/changelog/2025-02-20/version.json | 12 ++ .../resources/cmdb/sqlscript/ddl.sql | 13 ++ 9 files changed, 405 insertions(+) create mode 100644 src/main/java/neatlogic/module/cmdb/api/resourcecenter/app/AppResourceListApi.java create mode 100644 src/main/java/neatlogic/module/cmdb/resourcecenter/datasource/handler/DefaultResourceCenterDataSourceImpl.java create mode 100644 src/main/resources/neatlogic/resources/cmdb/changelog/2025-02-20/neatlogic_tenant.sql create mode 100644 src/main/resources/neatlogic/resources/cmdb/changelog/2025-02-20/version.json diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/app/AppResourceListApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/app/AppResourceListApi.java new file mode 100644 index 00000000..e03629c7 --- /dev/null +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/app/AppResourceListApi.java @@ -0,0 +1,121 @@ +/*Copyright (C) 2024 深圳极向量科技有限公司 All Rights Reserved. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see .*/ + +package neatlogic.module.cmdb.api.resourcecenter.app; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.auth.core.AuthAction; +import neatlogic.framework.cmdb.auth.label.CMDB_BASE; +import neatlogic.framework.cmdb.dto.ci.CiVo; +import neatlogic.framework.cmdb.dto.resourcecenter.ResourceSearchVo; +import neatlogic.framework.cmdb.exception.ci.CiNotFoundException; +import neatlogic.framework.cmdb.exception.resourcecenter.AppModuleNotFoundException; +import neatlogic.framework.cmdb.exception.resourcecenter.AppSystemNotFoundException; +import neatlogic.framework.cmdb.resourcecenter.datasource.core.IResourceCenterDataSource; +import neatlogic.framework.cmdb.resourcecenter.datasource.core.ResourceCenterDataSourceFactory; +import neatlogic.framework.common.constvalue.ApiParamType; +import neatlogic.framework.exception.type.ParamNotExistsException; +import neatlogic.framework.restful.annotation.*; +import neatlogic.framework.restful.constvalue.OperationTypeEnum; +import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; +import neatlogic.module.cmdb.dao.mapper.ci.CiMapper; +import neatlogic.module.cmdb.dao.mapper.cientity.CiEntityMapper; +import neatlogic.module.cmdb.service.resourcecenter.resource.IResourceCenterResourceService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; + +/** + * @author linbq + * @since 2021/6/17 11:54 + **/ +@Service +@AuthAction(action = CMDB_BASE.class) +@OperationType(type = OperationTypeEnum.SEARCH) +public class AppResourceListApi extends PrivateApiComponentBase { + + @Resource + private IResourceCenterResourceService resourceCenterResourceService; + + @Resource + private CiEntityMapper ciEntityMapper; + + @Resource + private CiMapper ciMapper; + + private IResourceCenterDataSource resourceCenterDataSource = ResourceCenterDataSourceFactory.getResourceCenterDataSource(); + + @Override + public String getToken() { + return "resourcecenter/app/resource/list"; + } + + @Override + public String getName() { + return "查询应用中资源列表"; + } + + @Override + public String getConfig() { + return null; + } + + @Input({ + @Param(name = "appSystemId", type = ApiParamType.LONG, desc = "应用id"), + @Param(name = "appModuleId", type = ApiParamType.LONG, desc = "应用模块id"), + @Param(name = "envId", type = ApiParamType.LONG, desc = "环境id,envId=-2表示无配置环境"), + @Param(name = "typeId", type = ApiParamType.LONG, desc = "类型id"), + @Param(name = "currentPage", type = ApiParamType.INTEGER, desc = "当前页"), + @Param(name = "pageSize", type = ApiParamType.INTEGER, desc = "每页数据条目") + }) + @Output({ + @Param(name = "tableList", type = ApiParamType.JSONARRAY, desc = "资源环境列表") + }) + @Description(desc = "查询资源环境列表") + @Override + public Object myDoService(JSONObject paramObj) throws Exception { + JSONObject resultObj = new JSONObject(); + ResourceSearchVo searchVo = paramObj.toJavaObject(ResourceSearchVo.class); + if (searchVo.getAppSystemId() == null && searchVo.getAppModuleId() == null) { + throw new ParamNotExistsException("应用id(appSystemId)", "应用模块id(appModuleId)"); + } + Long appSystemId = paramObj.getLong("appSystemId"); + Long appModuleId = paramObj.getLong("appModuleId"); + Long envId = paramObj.getLong("envId"); + Long typeId = paramObj.getLong("typeId"); + Integer currentPage = paramObj.getInteger("currentPage"); + Integer pageSize = paramObj.getInteger("pageSize"); + if (appSystemId != null && ciEntityMapper.getCiEntityBaseInfoById(appSystemId) == null) { + throw new AppSystemNotFoundException(appSystemId); + } + if (appModuleId != null && ciEntityMapper.getCiEntityBaseInfoById(appModuleId) == null) { + throw new AppModuleNotFoundException(appModuleId); + } + List typeIdList = new ArrayList<>(); + if (typeId != null) { + CiVo ciVo = ciMapper.getCiById(typeId); + if (ciVo == null) { + throw new CiNotFoundException(typeId); + } + typeIdList.add(typeId); + } + JSONArray tableList = resourceCenterDataSource.getAppResourceList(appSystemId, appModuleId, envId, typeIdList, currentPage, pageSize); + resultObj.put("tableList", tableList); + return resultObj; + } +} diff --git a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.java b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.java index e46a2e0b..9544f13d 100644 --- a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.java +++ b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.java @@ -214,4 +214,6 @@ public interface ResourceMapper extends IResourceCrossoverMapper { List getOsResourceListByResourceIdList(List resourceIdList); List getResourceTypeIdListByAuth(ResourceSearchVo searchVo); + + String getApplicationListDisplayConfig(); } diff --git a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.xml b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.xml index acd8afab..ad8de3eb 100644 --- a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.xml +++ b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.xml @@ -2102,4 +2102,13 @@ along with this program. If not, see .--> + + diff --git a/src/main/java/neatlogic/module/cmdb/resourcecenter/datasource/handler/DefaultResourceCenterDataSourceImpl.java b/src/main/java/neatlogic/module/cmdb/resourcecenter/datasource/handler/DefaultResourceCenterDataSourceImpl.java new file mode 100644 index 00000000..99cd744e --- /dev/null +++ b/src/main/java/neatlogic/module/cmdb/resourcecenter/datasource/handler/DefaultResourceCenterDataSourceImpl.java @@ -0,0 +1,194 @@ +/* + * Copyright (C) 2025 深圳极向量科技有限公司 All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package neatlogic.module.cmdb.resourcecenter.datasource.handler; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.cmdb.dto.ci.CiVo; +import neatlogic.framework.cmdb.dto.resourcecenter.ResourceSearchVo; +import neatlogic.framework.cmdb.dto.resourcecenter.ResourceTypeVo; +import neatlogic.framework.cmdb.dto.resourcecenter.ResourceVo; +import neatlogic.framework.cmdb.resourcecenter.datasource.core.IResourceCenterDataSource; +import neatlogic.framework.cmdb.resourcecenter.datasource.core.Ordered; +import neatlogic.framework.util.TableResultUtil; +import neatlogic.module.cmdb.dao.mapper.ci.CiMapper; +import neatlogic.module.cmdb.dao.mapper.cientity.CiEntityMapper; +import neatlogic.module.cmdb.dao.mapper.resourcecenter.ResourceMapper; +import neatlogic.module.cmdb.service.resourcecenter.resource.IResourceCenterResourceService; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.MapUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.*; + +@Component +public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataSource { + + @Resource + private CiMapper ciMapper; + + @Resource + private CiEntityMapper ciEntityMapper; + + @Resource + private ResourceMapper resourceMapper; + + @Resource + private IResourceCenterResourceService resourceCenterResourceService; + @Override + public Ordered getOrdered() { + return Ordered.LOWEST_PRECEDENCE; + } + + @Override + public JSONArray getAppResourceList(Long appSystemId, Long appModuleId, Long envId, List resourceTypeIdList, Integer currentPage, Integer pageSize) { + JSONArray tableList = new JSONArray(); + String configStr = resourceMapper.getApplicationListDisplayConfig(); + if (StringUtils.isBlank(configStr)) { + JSONObject config = JSONObject.parseObject(configStr); + if (MapUtils.isNotEmpty(config)) { + JSONArray tableArray = config.getJSONArray("tableList"); + if (CollectionUtils.isNotEmpty(tableArray)) { + List ciNameList = new ArrayList<>(); + Map ciName2TheadListMap = new HashMap<>(); + for (int i = 0; i < tableArray.size(); i++) { + JSONObject tableObj = tableArray.getJSONObject(i); + if (MapUtils.isNotEmpty(tableObj)) { + String ciName = tableObj.getString("ciName"); + JSONArray theadList = tableObj.getJSONArray("theadList"); + ciName2TheadListMap.put(ciName, theadList); + ciNameList.add(ciName); + } + } + if (CollectionUtils.isNotEmpty(ciNameList)) { + List resourceCiVoList = ciMapper.getCiListByNameList(ciNameList); + if (CollectionUtils.isNotEmpty(resourceTypeIdList)) { + ResourceSearchVo searchVo = new ResourceSearchVo(); + searchVo.setAppSystemIdList(Collections.singletonList(appSystemId)); + if (appModuleId != null) { + searchVo.setAppModuleIdList(Collections.singletonList(appModuleId)); + } + if (envId != null) { + searchVo.setEnvIdList(Collections.singletonList(envId)); + } + searchVo.setCurrentPage(currentPage); + searchVo.setPageSize(pageSize); + List ciList = ciMapper.getAllCi(resourceTypeIdList); + for (CiVo ciVo : ciList) { + String resourceTypeName = getResourceTypeName(resourceCiVoList, ciVo); + if (StringUtils.isNotBlank(resourceTypeName)) { + ResourceTypeVo resourceTypeVo = new ResourceTypeVo(ciVo.getId(), ciVo.getParentCiId(), ciVo.getLabel(), ciVo.getName()); + searchVo.setTypeIdList(Collections.singletonList(ciVo.getId())); + resourceCenterResourceService.assembleResourceSearchVo(searchVo, false); + List resourceList = getResourceList(searchVo); + if (CollectionUtils.isNotEmpty(resourceList)) { + JSONObject tableObj = TableResultUtil.getResult(ciName2TheadListMap.get(resourceTypeName), resourceList, searchVo); + tableObj.put("type", resourceTypeVo); + tableList.add(tableObj); + } + } + } + } + } + } + } + } + return tableList; + } + + @Override + public List getResourceList(ResourceSearchVo searchVo) { + List resourceList = new ArrayList<>(); + List idList = resourceMapper.getResourceIdList(searchVo); + if (CollectionUtils.isNotEmpty(idList)) { + resourceList = resourceMapper.getResourceListByIdList(idList); + if (Objects.equals(searchVo.getRowNum(), 0)) { + int rowNum = 0; + if (noFilterCondition(searchVo)) { + rowNum = resourceMapper.getAllResourceCount(searchVo); + } else { + rowNum = resourceMapper.getResourceCount(searchVo); + } + searchVo.setRowNum(rowNum); + } + } + return resourceList; + } + + /** + * 判断是否有过滤条件 + * @param searchVo + * @return + */ + private boolean noFilterCondition(ResourceSearchVo searchVo) { + if (StringUtils.isNotBlank(searchVo.getKeyword())) { + return false; + } + if (CollectionUtils.isNotEmpty(searchVo.getBatchSearchList())) { + return false; + } + if (CollectionUtils.isNotEmpty(searchVo.getStateIdList())) { + return false; + } + if (CollectionUtils.isNotEmpty(searchVo.getVendorIdList())) { + return false; + } + if (CollectionUtils.isNotEmpty(searchVo.getEnvIdList())) { + return false; + } + if (searchVo.getExistNoEnv()) { + return false; + } + if (CollectionUtils.isNotEmpty(searchVo.getAppSystemIdList())) { + return false; + } + if (CollectionUtils.isNotEmpty(searchVo.getAppModuleIdList())) { + return false; + } + if (CollectionUtils.isNotEmpty(searchVo.getDefaultValue())) { + return false; + } + if (CollectionUtils.isNotEmpty(searchVo.getIdList())) { + return false; + } + if (CollectionUtils.isNotEmpty(searchVo.getInspectStatusList())) { + return false; + } + if (CollectionUtils.isNotEmpty(searchVo.getProtocolIdList())) { + return false; + } + if (CollectionUtils.isNotEmpty(searchVo.getTagIdList())) { + return false; + } + if (CollectionUtils.isNotEmpty(searchVo.getInspectJobPhaseNodeStatusList())) { + return false; + } + return true; + } + + public String getResourceTypeName(List resourceCiVoList, CiVo resourceCiVo) { + for (CiVo ciVo : resourceCiVoList) { + if (ciVo.getLft() <= resourceCiVo.getLft() && ciVo.getRht() >= resourceCiVo.getRht()) { + return ciVo.getName(); + } + } + return null; + } +} diff --git a/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/IResourceCenterResourceService.java b/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/IResourceCenterResourceService.java index 8a022723..73fd13bb 100644 --- a/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/IResourceCenterResourceService.java +++ b/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/IResourceCenterResourceService.java @@ -41,6 +41,8 @@ public interface IResourceCenterResourceService extends IResourceCenterResourceC ResourceSearchVo assembleResourceSearchVo(JSONObject jsonObj,boolean isIncludeSon); + void assembleResourceSearchVo(ResourceSearchVo searchVo, boolean isIncludeSon); + /** * 处理批量搜索关键字 * @param resourceSearchVo diff --git a/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java b/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java index 5f407678..8ff882ba 100644 --- a/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java +++ b/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java @@ -205,6 +205,49 @@ public class ResourceCenterResourceServiceImpl implements IResourceCenterResourc return searchVo; } + @Override + public void assembleResourceSearchVo(ResourceSearchVo searchVo, boolean isIncludeSon) { + boolean isHasAuth = AuthActionChecker.check(CI_MODIFY.class, CIENTITY_MODIFY.class); + Long typeId = searchVo.getTypeId(); + List typeIdList = new ArrayList<>(); + if (CollectionUtils.isNotEmpty(searchVo.getTypeIdList())) { + typeIdList.addAll(searchVo.getTypeIdList()); + } + if (typeId != null && !typeIdList.contains(typeId)) { + typeIdList.add(typeId); + } + if (CollectionUtils.isNotEmpty(typeIdList)) { + Set authedCiIdSet = new HashSet<>(); + Set ciIdSet = new HashSet<>(); + for (Long ciId : typeIdList) { + CiVo ciVo = ciMapper.getCiById(ciId); + if (ciVo == null) { + throw new CiNotFoundException(ciId); + } + if (!isHasAuth) { + List authedCiList; + authedCiList = ciMapper.getDownwardCiEntityQueryCiListByLR(ciVo.getLft(), ciVo.getRht(), UserContext.get().getAuthenticationInfoVo(), searchVo.getIsHasAuth()); + if (CollectionUtils.isNotEmpty(authedCiList)) { + if (isIncludeSon) { + List inCludeSonCiList = ciMapper.getBatchDownwardCiListByCiList(authedCiList); + Set ciIdList = inCludeSonCiList.stream().map(CiVo::getId).collect(Collectors.toSet()); + authedCiIdSet.addAll(ciIdList); + } else { + authedCiIdSet.addAll(authedCiList.stream().map(CiVo::getId).collect(Collectors.toSet())); + } + } + } + List ciList = ciMapper.getDownwardCiListByLR(ciVo.getLft(), ciVo.getRht()); + List ciIdList = ciList.stream().map(CiVo::getId).collect(Collectors.toList()); + ciIdSet.addAll(ciIdList); + + } + searchVo.setAuthedTypeIdList(new ArrayList<>(authedCiIdSet)); + searchVo.setTypeIdList(new ArrayList<>(ciIdSet)); + } + searchVo.setIsHasAuth(AuthActionChecker.check(CI_MODIFY.class, CIENTITY_MODIFY.class) || Objects.equals("0", ConfigManager.getConfig(CmdbTenantConfig.IS_RESOURCECENTER_AUTH))); + } + @Override public void handleBatchSearchList(ResourceSearchVo searchVo) { List batchSearchList = searchVo.getBatchSearchList(); diff --git a/src/main/resources/neatlogic/resources/cmdb/changelog/2025-02-20/neatlogic_tenant.sql b/src/main/resources/neatlogic/resources/cmdb/changelog/2025-02-20/neatlogic_tenant.sql new file mode 100644 index 00000000..ffb42f3f --- /dev/null +++ b/src/main/resources/neatlogic/resources/cmdb/changelog/2025-02-20/neatlogic_tenant.sql @@ -0,0 +1,9 @@ +CREATE TABLE IF NOT EXISTS `cmdb_resourcecenter_applicationlist_display` ( + `id` BIGINT NOT NULL COMMENT '主键ID', + `appSystemId` BIGINT COMMENT '应用系统ID', + `appModuleId` BIGINT COMMENT '应用模块ID', + `envId` BIGINT COMMENT '环境ID', + `config` LONGTEXT NOT NULL COMMENT '配置信息', + PRIMARY KEY (`id`), + UNIQUE INDEX `uk` (`appSystemId`, `appModuleId`, `envId`) +) ENGINE = INNODB CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci; \ No newline at end of file diff --git a/src/main/resources/neatlogic/resources/cmdb/changelog/2025-02-20/version.json b/src/main/resources/neatlogic/resources/cmdb/changelog/2025-02-20/version.json new file mode 100644 index 00000000..de376c04 --- /dev/null +++ b/src/main/resources/neatlogic/resources/cmdb/changelog/2025-02-20/version.json @@ -0,0 +1,12 @@ +{ + "content": [ + { + "type": "新增功能", + "detail": [ + { + "msg": "1、CMDB应用清单改成模型层级可配置" + } + ] + } + ] +} diff --git a/src/main/resources/neatlogic/resources/cmdb/sqlscript/ddl.sql b/src/main/resources/neatlogic/resources/cmdb/sqlscript/ddl.sql index a2c83ecb..00cb24b7 100644 --- a/src/main/resources/neatlogic/resources/cmdb/sqlscript/ddl.sql +++ b/src/main/resources/neatlogic/resources/cmdb/sqlscript/ddl.sql @@ -951,6 +951,19 @@ CREATE TABLE `cmdb_resourcecenter_account_tag` CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = 'cmdb_resourcecenter_account_tag'; +-- ---------------------------- +-- Table structure for cmdb_resourcecenter_applicationlist_display +-- ---------------------------- +CREATE TABLE IF NOT EXISTS `cmdb_resourcecenter_applicationlist_display` ( + `id` BIGINT NOT NULL COMMENT '主键ID', + `appSystemId` BIGINT COMMENT '应用系统ID', + `appModuleId` BIGINT COMMENT '应用模块ID', + `envId` BIGINT COMMENT '环境ID', + `config` LONGTEXT NOT NULL COMMENT '配置信息', + PRIMARY KEY (`id`), + UNIQUE INDEX `uk` (`appSystemId`, `appModuleId`, `envId`) +) ENGINE = INNODB CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci; + -- ---------------------------- -- Table structure for cmdb_resourcecenter_config -- ---------------------------- -- Gitee From c33f532ff709a73de827bfb490c0c152c7a71de0 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Thu, 20 Feb 2025 20:27:35 +0800 Subject: [PATCH 05/29] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E5=B7=A1=E6=A3=80-=E5=BA=94=E7=94=A8=E5=B7=A1=E6=A3=80?= =?UTF-8?q?=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1360903792984064]应用巡检-应用巡检异常 http://192.168.0.96:8090/demo/rdm.html#/bug-detail/939050947543040/939050947543057/1360903792984064 --- .../config/GetApplicationListDisplayApi.java | 61 +++++++++++++++ .../config/GetAssetListDisplayApi.java | 61 +++++++++++++++ .../config/ListAssetListAllTheadApi.java | 58 ++++++++++++++ .../config/SaveApplicationListDisplayApi.java | 74 ++++++++++++++++++ .../config/SaveAssertListDisplayApi.java | 77 +++++++++++++++++++ .../resourcecenter/ResourceEntityMapper.java | 10 +++ .../resourcecenter/ResourceEntityMapper.xml | 58 ++++++++++++++ .../mapper/resourcecenter/ResourceMapper.java | 2 - .../mapper/resourcecenter/ResourceMapper.xml | 9 --- .../DefaultResourceCenterDataSourceImpl.java | 12 ++- .../changelog/2025-02-20/neatlogic_tenant.sql | 16 +++- .../resources/cmdb/sqlscript/ddl.sql | 19 ++++- 12 files changed, 435 insertions(+), 22 deletions(-) create mode 100644 src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/GetApplicationListDisplayApi.java create mode 100644 src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/GetAssetListDisplayApi.java create mode 100644 src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/ListAssetListAllTheadApi.java create mode 100644 src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/SaveApplicationListDisplayApi.java create mode 100644 src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/SaveAssertListDisplayApi.java diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/GetApplicationListDisplayApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/GetApplicationListDisplayApi.java new file mode 100644 index 00000000..970f6b87 --- /dev/null +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/GetApplicationListDisplayApi.java @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2025 深圳极向量科技有限公司 All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package neatlogic.module.cmdb.api.resourcecenter.config; + +import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.auth.core.AuthAction; +import neatlogic.framework.cmdb.auth.label.RESOURCECENTER_MODIFY; +import neatlogic.framework.cmdb.dto.resourcecenter.ApplicationListDisplayVo; +import neatlogic.framework.restful.annotation.Description; +import neatlogic.framework.restful.annotation.Input; +import neatlogic.framework.restful.annotation.OperationType; +import neatlogic.framework.restful.annotation.Output; +import neatlogic.framework.restful.constvalue.OperationTypeEnum; +import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; +import neatlogic.module.cmdb.dao.mapper.resourcecenter.ResourceEntityMapper; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; + +@Service +@AuthAction(action = RESOURCECENTER_MODIFY.class) +@OperationType(type = OperationTypeEnum.OPERATE) +public class GetApplicationListDisplayApi extends PrivateApiComponentBase { + + @Resource + private ResourceEntityMapper resourceEntityMapper; + + @Override + public String getName() { + return "获取应用清单显示设置"; + } + + @Input({}) + @Output({}) + @Description(desc = "获取应用清单显示设置") + @Override + public Object myDoService(JSONObject paramObj) throws Exception { + ApplicationListDisplayVo applicationListDisplayVo = resourceEntityMapper.getApplicationListDisplay(); + return applicationListDisplayVo; + } + + @Override + public String getToken() { + return "resourcecenter/applicationlist/display/get"; + } +} diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/GetAssetListDisplayApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/GetAssetListDisplayApi.java new file mode 100644 index 00000000..ca0e87b8 --- /dev/null +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/GetAssetListDisplayApi.java @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2025 深圳极向量科技有限公司 All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package neatlogic.module.cmdb.api.resourcecenter.config; + +import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.auth.core.AuthAction; +import neatlogic.framework.cmdb.auth.label.RESOURCECENTER_MODIFY; +import neatlogic.framework.cmdb.dto.resourcecenter.AssetListDisplayVo; +import neatlogic.framework.restful.annotation.Description; +import neatlogic.framework.restful.annotation.Input; +import neatlogic.framework.restful.annotation.OperationType; +import neatlogic.framework.restful.annotation.Output; +import neatlogic.framework.restful.constvalue.OperationTypeEnum; +import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; +import neatlogic.module.cmdb.dao.mapper.resourcecenter.ResourceEntityMapper; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; + +@Service +@AuthAction(action = RESOURCECENTER_MODIFY.class) +@OperationType(type = OperationTypeEnum.OPERATE) +public class GetAssetListDisplayApi extends PrivateApiComponentBase { + + @Resource + private ResourceEntityMapper resourceEntityMapper; + + @Override + public String getName() { + return "获取资产清单显示设置"; + } + + @Input({}) + @Output({}) + @Description(desc = "获取资产清单显示设置") + @Override + public Object myDoService(JSONObject paramObj) throws Exception { + AssetListDisplayVo assetListDisplayVo = resourceEntityMapper.getAssetListDisplay(); + return assetListDisplayVo; + } + + @Override + public String getToken() { + return "resourcecenter/assetlist/display/get"; + } +} diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/ListAssetListAllTheadApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/ListAssetListAllTheadApi.java new file mode 100644 index 00000000..14d3cda5 --- /dev/null +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/ListAssetListAllTheadApi.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2025 深圳极向量科技有限公司 All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package neatlogic.module.cmdb.api.resourcecenter.config; + +import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.auth.core.AuthAction; +import neatlogic.framework.cmdb.auth.label.RESOURCECENTER_MODIFY; +import neatlogic.framework.common.dto.ValueTextVo; +import neatlogic.framework.restful.annotation.Description; +import neatlogic.framework.restful.annotation.Input; +import neatlogic.framework.restful.annotation.OperationType; +import neatlogic.framework.restful.annotation.Output; +import neatlogic.framework.restful.constvalue.OperationTypeEnum; +import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; +import neatlogic.framework.util.TableResultUtil; +import neatlogic.module.cmdb.utils.ResourceEntityFactory; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +@AuthAction(action = RESOURCECENTER_MODIFY.class) +@OperationType(type = OperationTypeEnum.OPERATE) +public class ListAssetListAllTheadApi extends PrivateApiComponentBase { + @Override + public String getName() { + return "获取资产清单所有表头列表"; + } + + @Input({}) + @Output({}) + @Description(desc = "获取资产清单所有表头列表") + @Override + public Object myDoService(JSONObject paramObj) throws Exception { + List fieldList = ResourceEntityFactory.getFieldListByViewName("scence_ipobject_detail"); + return TableResultUtil.getResult(fieldList); + } + + @Override + public String getToken() { + return "resourcecenter/assetlist/theadlist"; + } +} diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/SaveApplicationListDisplayApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/SaveApplicationListDisplayApi.java new file mode 100644 index 00000000..551d6dd6 --- /dev/null +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/SaveApplicationListDisplayApi.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2025 深圳极向量科技有限公司 All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package neatlogic.module.cmdb.api.resourcecenter.config; + +import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.auth.core.AuthAction; +import neatlogic.framework.cmdb.auth.label.RESOURCECENTER_MODIFY; +import neatlogic.framework.cmdb.dto.resourcecenter.ApplicationListDisplayVo; +import neatlogic.framework.common.constvalue.ApiParamType; +import neatlogic.framework.restful.annotation.*; +import neatlogic.framework.restful.constvalue.OperationTypeEnum; +import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; +import neatlogic.framework.util.SnowflakeUtil; +import neatlogic.module.cmdb.dao.mapper.resourcecenter.ResourceEntityMapper; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; + +@Service +@AuthAction(action = RESOURCECENTER_MODIFY.class) +@OperationType(type = OperationTypeEnum.OPERATE) +@Transactional +public class SaveApplicationListDisplayApi extends PrivateApiComponentBase { + + @Resource + private ResourceEntityMapper resourceEntityMapper; + + @Override + public String getName() { + return "保存应用清单显示设置"; + } + + @Input({ + @Param(name = "id", type = ApiParamType.LONG, desc = "common.id"), + @Param(name = "config", type = ApiParamType.JSONOBJECT, isRequired = true, desc = "common.config") + }) + @Output({}) + @Description(desc = "保存应用清单显示设置") + @Override + public Object myDoService(JSONObject paramObj) throws Exception { + Long id = paramObj.getLong("id"); + JSONObject config = paramObj.getJSONObject("config"); + ApplicationListDisplayVo applicationListDisplayVo = new ApplicationListDisplayVo(); + if (id != null) { + applicationListDisplayVo.setId(id); + } else { + applicationListDisplayVo.setId(SnowflakeUtil.uniqueLong()); + } + applicationListDisplayVo.setConfig(config); + resourceEntityMapper.insertApplicationListDisplay(applicationListDisplayVo); + return null; + } + + @Override + public String getToken() { + return "resourcecenter/applicationlist/display/save"; + } +} diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/SaveAssertListDisplayApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/SaveAssertListDisplayApi.java new file mode 100644 index 00000000..9e25a848 --- /dev/null +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/SaveAssertListDisplayApi.java @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2025 深圳极向量科技有限公司 All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package neatlogic.module.cmdb.api.resourcecenter.config; + +import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.auth.core.AuthAction; +import neatlogic.framework.cmdb.auth.label.RESOURCECENTER_MODIFY; +import neatlogic.framework.cmdb.dto.resourcecenter.AssetListDisplayVo; +import neatlogic.framework.common.constvalue.ApiParamType; +import neatlogic.framework.restful.annotation.*; +import neatlogic.framework.restful.constvalue.OperationTypeEnum; +import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; +import neatlogic.framework.util.SnowflakeUtil; +import neatlogic.module.cmdb.dao.mapper.resourcecenter.ResourceEntityMapper; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; + +@Service +@AuthAction(action = RESOURCECENTER_MODIFY.class) +@OperationType(type = OperationTypeEnum.OPERATE) +@Transactional +public class SaveAssertListDisplayApi extends PrivateApiComponentBase { + + @Resource + private ResourceEntityMapper resourceEntityMapper; + + @Override + public String getName() { + return "保存资产清单显示设置"; + } + + @Input({ + @Param(name = "id", type = ApiParamType.LONG, desc = "common.id"), + @Param(name = "rootCiName", type = ApiParamType.STRING, isRequired = true, desc = "根模型名称"), + @Param(name = "config", type = ApiParamType.JSONOBJECT, isRequired = true, desc = "common.config") + }) + @Output({}) + @Description(desc = "保存资产清单显示设置") + @Override + public Object myDoService(JSONObject paramObj) throws Exception { + Long id = paramObj.getLong("id"); + String rootCiName = paramObj.getString("rootCiName"); + JSONObject config = paramObj.getJSONObject("config"); + AssetListDisplayVo assetListDisplayVo = new AssetListDisplayVo(); + if (id != null) { + assetListDisplayVo.setId(id); + } else { + assetListDisplayVo.setId(SnowflakeUtil.uniqueLong()); + } + assetListDisplayVo.setRootCiName(rootCiName); + assetListDisplayVo.setConfig(config); + resourceEntityMapper.insertAssetListDisplay(assetListDisplayVo); + return null; + } + + @Override + public String getToken() { + return "resourcecenter/assetlist/display/save"; + } +} diff --git a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceEntityMapper.java b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceEntityMapper.java index 6ff88f4a..457f3436 100644 --- a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceEntityMapper.java +++ b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceEntityMapper.java @@ -16,6 +16,8 @@ along with this program. If not, see .*/ package neatlogic.module.cmdb.dao.mapper.resourcecenter; import neatlogic.framework.cmdb.crossover.IResourceEntityCrossoverMapper; +import neatlogic.framework.cmdb.dto.resourcecenter.ApplicationListDisplayVo; +import neatlogic.framework.cmdb.dto.resourcecenter.AssetListDisplayVo; import neatlogic.framework.cmdb.dto.resourcecenter.ResourceSearchVo; import neatlogic.framework.cmdb.dto.resourcecenter.config.ResourceEntityVo; import org.apache.ibatis.annotations.Param; @@ -36,10 +38,18 @@ public interface ResourceEntityMapper extends IResourceEntityCrossoverMapper { List> getResourceEntityViewDataList(@Param("name") String name, @Param("startNum") int startNum, @Param("pageSize") int pageSize); + ApplicationListDisplayVo getApplicationListDisplay(); + + AssetListDisplayVo getAssetListDisplay(); + void insertResourceEntity(ResourceEntityVo resourceEntityVo); void insertResourceTypeCi(Long ciId); + int insertApplicationListDisplay(ApplicationListDisplayVo applicationListDisplayVo); + + int insertAssetListDisplay(AssetListDisplayVo assetListDisplayVo); + void updateResourceEntity(ResourceEntityVo resourceEntityVo); void updateResourceEntityStatusAndError(ResourceEntityVo resourceEntityVo); diff --git a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceEntityMapper.xml b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceEntityMapper.xml index ce866d57..b1019ffc 100644 --- a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceEntityMapper.xml +++ b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceEntityMapper.xml @@ -51,6 +51,28 @@ along with this program. If not, see .--> LIMIT #{startNum}, #{pageSize} + + + + INSERT INTO cmdb_resourcecenter_entity (`name`, `label`, `status`, `error`, `init_time`, `ci_id`, `config`, `description`) @@ -82,6 +104,42 @@ along with this program. If not, see .--> VALUES (#{value}) + + INSERT INTO `cmdb_resourcecenter_applicationlist_display` ( + `id`, + `app_system_id`, + `app_module_id`, + `env_id`, + `config` + ) + VALUES + ( + #{id}, + #{appSystemId}, + #{appModuleId}, + #{envId}, + #{configStr, typeHandler=CompressHandler} + ) + ON DUPLICATE KEY UPDATE + `config` = #{configStr, typeHandler=CompressHandler} + + + + INSERT INTO `cmdb_resourcecenter_assetlist_display` ( + `id`, + `root_ci_name`, + `config` + ) + VALUES + ( + #{id}, + #{rootCiName}, + #{configStr, typeHandler=CompressHandler} + ) + ON DUPLICATE KEY UPDATE + `config` = #{configStr, typeHandler=CompressHandler} + + UPDATE cmdb_resourcecenter_entity diff --git a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.java b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.java index 9544f13d..e46a2e0b 100644 --- a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.java +++ b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.java @@ -214,6 +214,4 @@ public interface ResourceMapper extends IResourceCrossoverMapper { List getOsResourceListByResourceIdList(List resourceIdList); List getResourceTypeIdListByAuth(ResourceSearchVo searchVo); - - String getApplicationListDisplayConfig(); } diff --git a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.xml b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.xml index ad8de3eb..acd8afab 100644 --- a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.xml +++ b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.xml @@ -2102,13 +2102,4 @@ along with this program. If not, see .--> - - diff --git a/src/main/java/neatlogic/module/cmdb/resourcecenter/datasource/handler/DefaultResourceCenterDataSourceImpl.java b/src/main/java/neatlogic/module/cmdb/resourcecenter/datasource/handler/DefaultResourceCenterDataSourceImpl.java index 99cd744e..b6f755f4 100644 --- a/src/main/java/neatlogic/module/cmdb/resourcecenter/datasource/handler/DefaultResourceCenterDataSourceImpl.java +++ b/src/main/java/neatlogic/module/cmdb/resourcecenter/datasource/handler/DefaultResourceCenterDataSourceImpl.java @@ -20,6 +20,7 @@ package neatlogic.module.cmdb.resourcecenter.datasource.handler; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import neatlogic.framework.cmdb.dto.ci.CiVo; +import neatlogic.framework.cmdb.dto.resourcecenter.ApplicationListDisplayVo; import neatlogic.framework.cmdb.dto.resourcecenter.ResourceSearchVo; import neatlogic.framework.cmdb.dto.resourcecenter.ResourceTypeVo; import neatlogic.framework.cmdb.dto.resourcecenter.ResourceVo; @@ -28,6 +29,7 @@ import neatlogic.framework.cmdb.resourcecenter.datasource.core.Ordered; import neatlogic.framework.util.TableResultUtil; import neatlogic.module.cmdb.dao.mapper.ci.CiMapper; import neatlogic.module.cmdb.dao.mapper.cientity.CiEntityMapper; +import neatlogic.module.cmdb.dao.mapper.resourcecenter.ResourceEntityMapper; import neatlogic.module.cmdb.dao.mapper.resourcecenter.ResourceMapper; import neatlogic.module.cmdb.service.resourcecenter.resource.IResourceCenterResourceService; import org.apache.commons.collections4.CollectionUtils; @@ -50,8 +52,12 @@ public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataS @Resource private ResourceMapper resourceMapper; + @Resource + private ResourceEntityMapper resourceEntityMapper; + @Resource private IResourceCenterResourceService resourceCenterResourceService; + @Override public Ordered getOrdered() { return Ordered.LOWEST_PRECEDENCE; @@ -60,9 +66,9 @@ public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataS @Override public JSONArray getAppResourceList(Long appSystemId, Long appModuleId, Long envId, List resourceTypeIdList, Integer currentPage, Integer pageSize) { JSONArray tableList = new JSONArray(); - String configStr = resourceMapper.getApplicationListDisplayConfig(); - if (StringUtils.isBlank(configStr)) { - JSONObject config = JSONObject.parseObject(configStr); + ApplicationListDisplayVo applicationListDisplay = resourceEntityMapper.getApplicationListDisplay(); + if (applicationListDisplay != null) { + JSONObject config = applicationListDisplay.getConfig(); if (MapUtils.isNotEmpty(config)) { JSONArray tableArray = config.getJSONArray("tableList"); if (CollectionUtils.isNotEmpty(tableArray)) { diff --git a/src/main/resources/neatlogic/resources/cmdb/changelog/2025-02-20/neatlogic_tenant.sql b/src/main/resources/neatlogic/resources/cmdb/changelog/2025-02-20/neatlogic_tenant.sql index ffb42f3f..683c6b75 100644 --- a/src/main/resources/neatlogic/resources/cmdb/changelog/2025-02-20/neatlogic_tenant.sql +++ b/src/main/resources/neatlogic/resources/cmdb/changelog/2025-02-20/neatlogic_tenant.sql @@ -1,9 +1,17 @@ CREATE TABLE IF NOT EXISTS `cmdb_resourcecenter_applicationlist_display` ( `id` BIGINT NOT NULL COMMENT '主键ID', - `appSystemId` BIGINT COMMENT '应用系统ID', - `appModuleId` BIGINT COMMENT '应用模块ID', - `envId` BIGINT COMMENT '环境ID', + `app_system_id` BIGINT COMMENT '应用系统ID', + `app_module_id` BIGINT COMMENT '应用模块ID', + `env_id` BIGINT COMMENT '环境ID', `config` LONGTEXT NOT NULL COMMENT '配置信息', PRIMARY KEY (`id`), - UNIQUE INDEX `uk` (`appSystemId`, `appModuleId`, `envId`) + UNIQUE INDEX `uk` (`app_system_id`, `app_module_id`, `env_id`) +) ENGINE = INNODB CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci; + +CREATE TABLE IF NOT EXISTS `cmdb_resourcecenter_assetlist_display` ( + `id` BIGINT NOT NULL COMMENT '主键ID', + `root_ci_name` VARCHAR (100) NOT NULL COMMENT '根模型名称', + `config` LONGTEXT NOT NULL COMMENT '配置', + PRIMARY KEY (`id`), + UNIQUE INDEX `uk` (`root_ci_name`) ) ENGINE = INNODB CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci; \ No newline at end of file diff --git a/src/main/resources/neatlogic/resources/cmdb/sqlscript/ddl.sql b/src/main/resources/neatlogic/resources/cmdb/sqlscript/ddl.sql index 00cb24b7..455edd9f 100644 --- a/src/main/resources/neatlogic/resources/cmdb/sqlscript/ddl.sql +++ b/src/main/resources/neatlogic/resources/cmdb/sqlscript/ddl.sql @@ -956,12 +956,23 @@ CREATE TABLE `cmdb_resourcecenter_account_tag` -- ---------------------------- CREATE TABLE IF NOT EXISTS `cmdb_resourcecenter_applicationlist_display` ( `id` BIGINT NOT NULL COMMENT '主键ID', - `appSystemId` BIGINT COMMENT '应用系统ID', - `appModuleId` BIGINT COMMENT '应用模块ID', - `envId` BIGINT COMMENT '环境ID', + `app_system_id` BIGINT COMMENT '应用系统ID', + `app_module_id` BIGINT COMMENT '应用模块ID', + `env_id` BIGINT COMMENT '环境ID', `config` LONGTEXT NOT NULL COMMENT '配置信息', PRIMARY KEY (`id`), - UNIQUE INDEX `uk` (`appSystemId`, `appModuleId`, `envId`) + UNIQUE INDEX `uk` (`app_system_id`, `app_module_id`, `env_id`) +) ENGINE = INNODB CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci; + +-- ---------------------------- +-- Table structure for cmdb_resourcecenter_applicationlist_display +-- ---------------------------- +CREATE TABLE IF NOT EXISTS `cmdb_resourcecenter_assetlist_display` ( + `id` BIGINT NOT NULL COMMENT '主键ID', + `root_ci_name` VARCHAR (100) NOT NULL COMMENT '根模型名称', + `config` LONGTEXT NOT NULL COMMENT '配置', + PRIMARY KEY (`id`), + UNIQUE INDEX `uk` (`root_ci_name`) ) ENGINE = INNODB CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci; -- ---------------------------- -- Gitee From 1c1eb9887cd91389af01fef88c69e05d81a4f66f Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Fri, 21 Feb 2025 18:05:29 +0800 Subject: [PATCH 06/29] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20CMDB=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E6=B8=85=E5=8D=95=E6=94=B9=E6=88=90=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E5=B1=82=E7=BA=A7=E5=8F=AF=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1349157963399168]CMDB应用清单改成模型层级可配置 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1349157963399168 --- .../app/AppResourceListApi.java | 8 +- .../config/SaveApplicationListDisplayApi.java | 7 +- .../config/SaveAssertListDisplayApi.java | 26 +- .../resourcetype/ResourceTypeListTreeApi.java | 73 +++++ .../resourcetype/ResourceTypeTreeApi.java | 245 ++++++++--------- .../resourcecenter/ResourceEntityMapper.xml | 8 +- .../DefaultResourceCenterDataSourceImpl.java | 258 +++++++++++++++++- .../cmdb/utils/ResourceEntityFactory.java | 14 + 8 files changed, 488 insertions(+), 151 deletions(-) create mode 100644 src/main/java/neatlogic/module/cmdb/api/resourcecenter/resourcetype/ResourceTypeListTreeApi.java diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/app/AppResourceListApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/app/AppResourceListApi.java index e03629c7..ce749412 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/app/AppResourceListApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/app/AppResourceListApi.java @@ -33,7 +33,6 @@ import neatlogic.framework.restful.constvalue.OperationTypeEnum; import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; import neatlogic.module.cmdb.dao.mapper.ci.CiMapper; import neatlogic.module.cmdb.dao.mapper.cientity.CiEntityMapper; -import neatlogic.module.cmdb.service.resourcecenter.resource.IResourceCenterResourceService; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -49,17 +48,12 @@ import java.util.List; @OperationType(type = OperationTypeEnum.SEARCH) public class AppResourceListApi extends PrivateApiComponentBase { - @Resource - private IResourceCenterResourceService resourceCenterResourceService; - @Resource private CiEntityMapper ciEntityMapper; @Resource private CiMapper ciMapper; - private IResourceCenterDataSource resourceCenterDataSource = ResourceCenterDataSourceFactory.getResourceCenterDataSource(); - @Override public String getToken() { return "resourcecenter/app/resource/list"; @@ -114,6 +108,8 @@ public class AppResourceListApi extends PrivateApiComponentBase { } typeIdList.add(typeId); } + + IResourceCenterDataSource resourceCenterDataSource = ResourceCenterDataSourceFactory.getResourceCenterDataSource(); JSONArray tableList = resourceCenterDataSource.getAppResourceList(appSystemId, appModuleId, envId, typeIdList, currentPage, pageSize); resultObj.put("tableList", tableList); return resultObj; diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/SaveApplicationListDisplayApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/SaveApplicationListDisplayApi.java index 551d6dd6..c788520b 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/SaveApplicationListDisplayApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/SaveApplicationListDisplayApi.java @@ -60,7 +60,12 @@ public class SaveApplicationListDisplayApi extends PrivateApiComponentBase { if (id != null) { applicationListDisplayVo.setId(id); } else { - applicationListDisplayVo.setId(SnowflakeUtil.uniqueLong()); + ApplicationListDisplayVo applicationListDisplay = resourceEntityMapper.getApplicationListDisplay(); + if (applicationListDisplay != null) { + applicationListDisplayVo.setId(applicationListDisplay.getId()); + } else { + applicationListDisplayVo.setId(SnowflakeUtil.uniqueLong()); + } } applicationListDisplayVo.setConfig(config); resourceEntityMapper.insertApplicationListDisplay(applicationListDisplayVo); diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/SaveAssertListDisplayApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/SaveAssertListDisplayApi.java index 9e25a848..ddfc568a 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/SaveAssertListDisplayApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/SaveAssertListDisplayApi.java @@ -20,17 +20,22 @@ package neatlogic.module.cmdb.api.resourcecenter.config; import com.alibaba.fastjson.JSONObject; import neatlogic.framework.auth.core.AuthAction; import neatlogic.framework.cmdb.auth.label.RESOURCECENTER_MODIFY; +import neatlogic.framework.cmdb.dto.ci.CiVo; import neatlogic.framework.cmdb.dto.resourcecenter.AssetListDisplayVo; +import neatlogic.framework.cmdb.exception.ci.CiNotFoundException; import neatlogic.framework.common.constvalue.ApiParamType; import neatlogic.framework.restful.annotation.*; import neatlogic.framework.restful.constvalue.OperationTypeEnum; import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; import neatlogic.framework.util.SnowflakeUtil; +import neatlogic.module.cmdb.dao.mapper.ci.CiMapper; import neatlogic.module.cmdb.dao.mapper.resourcecenter.ResourceEntityMapper; +import org.apache.commons.collections4.CollectionUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.util.List; @Service @AuthAction(action = RESOURCECENTER_MODIFY.class) @@ -41,6 +46,9 @@ public class SaveAssertListDisplayApi extends PrivateApiComponentBase { @Resource private ResourceEntityMapper resourceEntityMapper; + @Resource + private CiMapper ciMapper; + @Override public String getName() { return "保存资产清单显示设置"; @@ -62,10 +70,26 @@ public class SaveAssertListDisplayApi extends PrivateApiComponentBase { if (id != null) { assetListDisplayVo.setId(id); } else { - assetListDisplayVo.setId(SnowflakeUtil.uniqueLong()); + AssetListDisplayVo assetListDisplay = resourceEntityMapper.getAssetListDisplay(); + if (assetListDisplay != null) { + assetListDisplayVo.setId(assetListDisplay.getId()); + } else { + assetListDisplayVo.setId(SnowflakeUtil.uniqueLong()); + } } assetListDisplayVo.setRootCiName(rootCiName); assetListDisplayVo.setConfig(config); + CiVo ciVo = ciMapper.getCiByName(rootCiName); + if (ciVo == null) { + throw new CiNotFoundException(rootCiName); + } + List ciIdList = resourceEntityMapper.getAllResourceTypeCiIdList(); + if (!ciIdList.contains(ciVo.getId())) { + if (CollectionUtils.isNotEmpty(ciIdList)) { + resourceEntityMapper.deleteResourceTypeCi(); + } + resourceEntityMapper.insertResourceTypeCi(ciVo.getId()); + } resourceEntityMapper.insertAssetListDisplay(assetListDisplayVo); return null; } diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resourcetype/ResourceTypeListTreeApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resourcetype/ResourceTypeListTreeApi.java new file mode 100644 index 00000000..1f19008a --- /dev/null +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resourcetype/ResourceTypeListTreeApi.java @@ -0,0 +1,73 @@ +/*Copyright (C) $today.year 深圳极向量科技有限公司 All Rights Reserved. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see .*/ + +package neatlogic.module.cmdb.api.resourcecenter.resourcetype; + +import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.auth.core.AuthAction; +import neatlogic.framework.cmdb.auth.label.CMDB; +import neatlogic.framework.cmdb.dto.resourcecenter.ResourceTypeVo; +import neatlogic.framework.cmdb.resourcecenter.datasource.core.IResourceCenterDataSource; +import neatlogic.framework.cmdb.resourcecenter.datasource.core.ResourceCenterDataSourceFactory; +import neatlogic.framework.common.constvalue.ApiParamType; +import neatlogic.framework.restful.annotation.*; +import neatlogic.framework.restful.constvalue.OperationTypeEnum; +import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; +import neatlogic.framework.util.TableResultUtil; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 查询资源类型树列表接口 + * + * @author linbq + * @since 2021/5/27 16:14 + **/ +@Service +@AuthAction(action = CMDB.class) +@OperationType(type = OperationTypeEnum.SEARCH) +public class ResourceTypeListTreeApi extends PrivateApiComponentBase { + + @Override + public String getToken() { + return "resourcecenter/resourcetype/listtree"; + } + + @Override + public String getName() { + return "查询所有资产类型列表树"; + } + + @Override + public String getConfig() { + return null; + } + + @Input({ + @Param(name = "keyword", type = ApiParamType.STRING, desc = "common.keyword") + }) + @Output({ + @Param(explode = ResourceTypeVo[].class, desc = "common.tbodylist") + }) + @Description(desc = "nmcarr.resourcetypetreeapi.getname") + @Override + public Object myDoService(JSONObject jsonObj) throws Exception { + String keyword = jsonObj.getString("keyword"); + IResourceCenterDataSource resourceCenterDataSource = ResourceCenterDataSourceFactory.getResourceCenterDataSource(); + List tbodyList = resourceCenterDataSource.getResourceTypeListTree(keyword); + return TableResultUtil.getResult(tbodyList); + } +} diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resourcetype/ResourceTypeTreeApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resourcetype/ResourceTypeTreeApi.java index 77de6aa6..d4d2cc7b 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resourcetype/ResourceTypeTreeApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resourcetype/ResourceTypeTreeApi.java @@ -16,28 +16,17 @@ along with this program. If not, see .*/ package neatlogic.module.cmdb.api.resourcecenter.resourcetype; import com.alibaba.fastjson.JSONObject; -import neatlogic.framework.asynchronization.threadlocal.UserContext; import neatlogic.framework.auth.core.AuthAction; import neatlogic.framework.cmdb.auth.label.CMDB; -import neatlogic.framework.cmdb.dto.ci.CiVo; -import neatlogic.framework.cmdb.dto.resourcecenter.ResourceSearchVo; import neatlogic.framework.cmdb.dto.resourcecenter.ResourceTypeVo; +import neatlogic.framework.cmdb.resourcecenter.datasource.core.IResourceCenterDataSource; +import neatlogic.framework.cmdb.resourcecenter.datasource.core.ResourceCenterDataSourceFactory; import neatlogic.framework.common.constvalue.ApiParamType; import neatlogic.framework.restful.annotation.*; import neatlogic.framework.restful.constvalue.OperationTypeEnum; import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; -import neatlogic.module.cmdb.dao.mapper.ci.CiMapper; -import neatlogic.module.cmdb.dao.mapper.resourcecenter.ResourceEntityMapper; -import neatlogic.module.cmdb.dao.mapper.resourcecenter.ResourceMapper; -import neatlogic.module.cmdb.service.resourcecenter.resource.IResourceCenterResourceService; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; -import javax.annotation.Resource; -import java.util.*; -import java.util.stream.Collectors; - /** * 查询资源类型树列表接口 * @@ -49,18 +38,6 @@ import java.util.stream.Collectors; @OperationType(type = OperationTypeEnum.SEARCH) public class ResourceTypeTreeApi extends PrivateApiComponentBase { - @Resource - private CiMapper ciMapper; - - @Resource - private ResourceEntityMapper resourceEntityMapper; - - @Resource - private ResourceMapper resourceMapper; - - @Resource - private IResourceCenterResourceService resourceCenterResourceService; - @Override public String getToken() { return "resourcecenter/resourcetype/tree"; @@ -86,113 +63,115 @@ public class ResourceTypeTreeApi extends PrivateApiComponentBase { @Override public Object myDoService(JSONObject jsonObj) throws Exception { String keyword = jsonObj.getString("keyword"); - if (StringUtils.isNotBlank(keyword)) { - keyword = keyword.toLowerCase(); - } - List resultList = new ArrayList<>(); - List authCiVoList = new ArrayList<>(); - List ciIdList = resourceEntityMapper.getAllResourceTypeCiIdList(); - jsonObj.put("typeIdList", ciIdList); - ResourceSearchVo searchVo = resourceCenterResourceService.assembleResourceSearchVo(jsonObj, false); - //先找出所有有权限的配置项的模型idList - if (!searchVo.getIsHasAuth()) { - Set authCiIdList = ciMapper.getAllAuthCi(UserContext.get().getAuthenticationInfoVo()).stream().map(CiVo::getId).collect(Collectors.toSet()); - authCiIdList.addAll(resourceMapper.getResourceTypeIdListByAuth(searchVo)); - if (CollectionUtils.isEmpty(authCiIdList)) { - return resultList; - } - authCiVoList = ciMapper.getCiByIdList(new ArrayList<>(authCiIdList)); - } - - - if (CollectionUtils.isNotEmpty(ciIdList)) { - List ciVoList = ciMapper.getCiByIdList(ciIdList); - ciVoList.sort(Comparator.comparing(CiVo::getLft)); - for (CiVo ciVo : ciVoList) { - Set ciList = new HashSet<>(); - List ciListTmp = ciMapper.getDownwardCiListByLR(ciVo.getLft(), ciVo.getRht()); - //过滤出所有有权限的配置项的模型idList - if (!searchVo.getIsHasAuth()) { - if (CollectionUtils.isNotEmpty(authCiVoList) && CollectionUtils.isNotEmpty(ciListTmp)) { - for (CiVo ci : ciListTmp) { - for (CiVo authCi : authCiVoList) { - if (ci.getLft() <= authCi.getLft() && ci.getRht() >= authCi.getRht()) { - ciList.add(ci); - break; - } - } - } - } - } else { - ciList = new HashSet<>(ciListTmp); - } - int size = ciList.size(); - List resourceTypeVoList = new ArrayList<>(size); - Map resourceTypeMap = new HashMap<>(size); - for (CiVo ci : ciList) { - ResourceTypeVo resourceTypeVo = new ResourceTypeVo(ci.getId(), ci.getParentCiId(), ci.getLabel(), ci.getName()); - resourceTypeMap.put(resourceTypeVo.getId(), resourceTypeVo); - resourceTypeVoList.add(resourceTypeVo); - } - if (StringUtils.isNotBlank(keyword)) { - // 建立父子关系 - for (ResourceTypeVo resourceType : resourceTypeVoList) { - if (resourceType.getParentId() != null) { - ResourceTypeVo parentResourceType = resourceTypeMap.get(resourceType.getParentId()); - if (parentResourceType != null) { - resourceType.setParent(parentResourceType); - parentResourceType.addChild(resourceType); - } - } - } - // 判断节点名称是否与关键字keyword匹配,如果匹配就将该节点及其父子节点的isKeywordMatch字段值设置为1,否则设置为0。 - for (ResourceTypeVo resourceType : resourceTypeVoList) { - if (resourceType.getLabel().toLowerCase().contains(keyword)) { - if (resourceType.getIsKeywordMatch() == null) { - resourceType.setIsKeywordMatch(1); - resourceType.setUpwardIsKeywordMatch(1); - resourceType.setDownwardIsKeywordMatch(1); - } - } else { - if (resourceType.getIsKeywordMatch() == null) { - resourceType.setIsKeywordMatch(0); - } - } - } - // 将isKeywordMatch字段值为0的节点从其父级中移除。 - Iterator iterator = resourceTypeVoList.iterator(); - while (iterator.hasNext()) { - ResourceTypeVo resourceType = iterator.next(); - if (Objects.equals(resourceType.getIsKeywordMatch(), 0)) { - ResourceTypeVo parent = resourceType.getParent(); - if (parent != null) { - parent.removeChild(resourceType); - } - iterator.remove(); - } - } - } else { - for (ResourceTypeVo resourceType : resourceTypeVoList) { - if (resourceType.getParentId() != null) { - ResourceTypeVo parentResourceType = resourceTypeMap.get(resourceType.getParentId()); - if (parentResourceType != null) { - parentResourceType.addChild(resourceType); - } - } - } - } - for (ResourceTypeVo resourceType : resourceTypeVoList) { - if (resourceType.getParentId() != null) { - ResourceTypeVo parentResourceType = resourceTypeMap.get(resourceType.getParentId()); - if (parentResourceType == null) { - resultList.add(resourceType); - } - } else { - resultList.add(resourceType); - } - } - } - } - return resultList; + IResourceCenterDataSource resourceCenterDataSource = ResourceCenterDataSourceFactory.getResourceCenterDataSource(); + return resourceCenterDataSource.getResourceTypeTree(keyword); +// if (StringUtils.isNotBlank(keyword)) { +// keyword = keyword.toLowerCase(); +// } +// List resultList = new ArrayList<>(); +// List authCiVoList = new ArrayList<>(); +// List ciIdList = resourceEntityMapper.getAllResourceTypeCiIdList(); +// jsonObj.put("typeIdList", ciIdList); +// ResourceSearchVo searchVo = resourceCenterResourceService.assembleResourceSearchVo(jsonObj, false); +// //先找出所有有权限的配置项的模型idList +// if (!searchVo.getIsHasAuth()) { +// Set authCiIdList = ciMapper.getAllAuthCi(UserContext.get().getAuthenticationInfoVo()).stream().map(CiVo::getId).collect(Collectors.toSet()); +// authCiIdList.addAll(resourceMapper.getResourceTypeIdListByAuth(searchVo)); +// if (CollectionUtils.isEmpty(authCiIdList)) { +// return resultList; +// } +// authCiVoList = ciMapper.getCiByIdList(new ArrayList<>(authCiIdList)); +// } +// +// +// if (CollectionUtils.isNotEmpty(ciIdList)) { +// List ciVoList = ciMapper.getCiByIdList(ciIdList); +// ciVoList.sort(Comparator.comparing(CiVo::getLft)); +// for (CiVo ciVo : ciVoList) { +// Set ciList = new HashSet<>(); +// List ciListTmp = ciMapper.getDownwardCiListByLR(ciVo.getLft(), ciVo.getRht()); +// //过滤出所有有权限的配置项的模型idList +// if (!searchVo.getIsHasAuth()) { +// if (CollectionUtils.isNotEmpty(authCiVoList) && CollectionUtils.isNotEmpty(ciListTmp)) { +// for (CiVo ci : ciListTmp) { +// for (CiVo authCi : authCiVoList) { +// if (ci.getLft() <= authCi.getLft() && ci.getRht() >= authCi.getRht()) { +// ciList.add(ci); +// break; +// } +// } +// } +// } +// } else { +// ciList = new HashSet<>(ciListTmp); +// } +// int size = ciList.size(); +// List resourceTypeVoList = new ArrayList<>(size); +// Map resourceTypeMap = new HashMap<>(size); +// for (CiVo ci : ciList) { +// ResourceTypeVo resourceTypeVo = new ResourceTypeVo(ci.getId(), ci.getParentCiId(), ci.getLabel(), ci.getName()); +// resourceTypeMap.put(resourceTypeVo.getId(), resourceTypeVo); +// resourceTypeVoList.add(resourceTypeVo); +// } +// if (StringUtils.isNotBlank(keyword)) { +// // 建立父子关系 +// for (ResourceTypeVo resourceType : resourceTypeVoList) { +// if (resourceType.getParentId() != null) { +// ResourceTypeVo parentResourceType = resourceTypeMap.get(resourceType.getParentId()); +// if (parentResourceType != null) { +// resourceType.setParent(parentResourceType); +// parentResourceType.addChild(resourceType); +// } +// } +// } +// // 判断节点名称是否与关键字keyword匹配,如果匹配就将该节点及其父子节点的isKeywordMatch字段值设置为1,否则设置为0。 +// for (ResourceTypeVo resourceType : resourceTypeVoList) { +// if (resourceType.getLabel().toLowerCase().contains(keyword)) { +// if (resourceType.getIsKeywordMatch() == null) { +// resourceType.setIsKeywordMatch(1); +// resourceType.setUpwardIsKeywordMatch(1); +// resourceType.setDownwardIsKeywordMatch(1); +// } +// } else { +// if (resourceType.getIsKeywordMatch() == null) { +// resourceType.setIsKeywordMatch(0); +// } +// } +// } +// // 将isKeywordMatch字段值为0的节点从其父级中移除。 +// Iterator iterator = resourceTypeVoList.iterator(); +// while (iterator.hasNext()) { +// ResourceTypeVo resourceType = iterator.next(); +// if (Objects.equals(resourceType.getIsKeywordMatch(), 0)) { +// ResourceTypeVo parent = resourceType.getParent(); +// if (parent != null) { +// parent.removeChild(resourceType); +// } +// iterator.remove(); +// } +// } +// } else { +// for (ResourceTypeVo resourceType : resourceTypeVoList) { +// if (resourceType.getParentId() != null) { +// ResourceTypeVo parentResourceType = resourceTypeMap.get(resourceType.getParentId()); +// if (parentResourceType != null) { +// parentResourceType.addChild(resourceType); +// } +// } +// } +// } +// for (ResourceTypeVo resourceType : resourceTypeVoList) { +// if (resourceType.getParentId() != null) { +// ResourceTypeVo parentResourceType = resourceTypeMap.get(resourceType.getParentId()); +// if (parentResourceType == null) { +// resultList.add(resourceType); +// } +// } else { +// resultList.add(resourceType); +// } +// } +// } +// } +// return resultList; } } diff --git a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceEntityMapper.xml b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceEntityMapper.xml index b1019ffc..bcd0b5d9 100644 --- a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceEntityMapper.xml +++ b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceEntityMapper.xml @@ -55,20 +55,21 @@ along with this program. If not, see .--> SELECT `id`, `app_system_id` AS appSystemId, - `app_module_id` AS appModuleId + `app_module_id` AS appModuleId, `env_id` AS envId, - `config` AS configStr, + `config` AS configStr FROM `cmdb_resourcecenter_applicationlist_display` WHERE `app_system_id` IS NULL AND `app_module_id` IS NULL AND `env_id` IS NULL + LIMIT 1 @@ -137,6 +138,7 @@ along with this program. If not, see .--> #{configStr, typeHandler=CompressHandler} ) ON DUPLICATE KEY UPDATE + `root_ci_name` = #{rootCiName}, `config` = #{configStr, typeHandler=CompressHandler} diff --git a/src/main/java/neatlogic/module/cmdb/resourcecenter/datasource/handler/DefaultResourceCenterDataSourceImpl.java b/src/main/java/neatlogic/module/cmdb/resourcecenter/datasource/handler/DefaultResourceCenterDataSourceImpl.java index b6f755f4..e02d5823 100644 --- a/src/main/java/neatlogic/module/cmdb/resourcecenter/datasource/handler/DefaultResourceCenterDataSourceImpl.java +++ b/src/main/java/neatlogic/module/cmdb/resourcecenter/datasource/handler/DefaultResourceCenterDataSourceImpl.java @@ -19,19 +19,24 @@ package neatlogic.module.cmdb.resourcecenter.datasource.handler; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.asynchronization.threadlocal.UserContext; import neatlogic.framework.cmdb.dto.ci.CiVo; import neatlogic.framework.cmdb.dto.resourcecenter.ApplicationListDisplayVo; import neatlogic.framework.cmdb.dto.resourcecenter.ResourceSearchVo; import neatlogic.framework.cmdb.dto.resourcecenter.ResourceTypeVo; import neatlogic.framework.cmdb.dto.resourcecenter.ResourceVo; +import neatlogic.framework.cmdb.dto.resourcecenter.config.ResourceEntityConfigVo; +import neatlogic.framework.cmdb.dto.resourcecenter.config.ResourceEntityVo; import neatlogic.framework.cmdb.resourcecenter.datasource.core.IResourceCenterDataSource; import neatlogic.framework.cmdb.resourcecenter.datasource.core.Ordered; +import neatlogic.framework.common.dto.ValueTextVo; import neatlogic.framework.util.TableResultUtil; import neatlogic.module.cmdb.dao.mapper.ci.CiMapper; import neatlogic.module.cmdb.dao.mapper.cientity.CiEntityMapper; import neatlogic.module.cmdb.dao.mapper.resourcecenter.ResourceEntityMapper; import neatlogic.module.cmdb.dao.mapper.resourcecenter.ResourceMapper; import neatlogic.module.cmdb.service.resourcecenter.resource.IResourceCenterResourceService; +import neatlogic.module.cmdb.utils.ResourceEntityFactory; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; @@ -39,6 +44,7 @@ import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.util.*; +import java.util.stream.Collectors; @Component public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataSource { @@ -70,21 +76,30 @@ public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataS if (applicationListDisplay != null) { JSONObject config = applicationListDisplay.getConfig(); if (MapUtils.isNotEmpty(config)) { - JSONArray tableArray = config.getJSONArray("tableList"); - if (CollectionUtils.isNotEmpty(tableArray)) { + JSONArray tableSettingList = config.getJSONArray("tableSettingList"); + if (CollectionUtils.isNotEmpty(tableSettingList)) { List ciNameList = new ArrayList<>(); Map ciName2TheadListMap = new HashMap<>(); - for (int i = 0; i < tableArray.size(); i++) { - JSONObject tableObj = tableArray.getJSONObject(i); + for (int i = 0; i < tableSettingList.size(); i++) { + JSONObject tableObj = tableSettingList.getJSONObject(i); if (MapUtils.isNotEmpty(tableObj)) { String ciName = tableObj.getString("ciName"); - JSONArray theadList = tableObj.getJSONArray("theadList"); - ciName2TheadListMap.put(ciName, theadList); + JSONArray fieldList = tableObj.getJSONArray("fieldList"); + ciName2TheadListMap.put(ciName, fieldList); ciNameList.add(ciName); } } if (CollectionUtils.isNotEmpty(ciNameList)) { List resourceCiVoList = ciMapper.getCiListByNameList(ciNameList); + if (CollectionUtils.isEmpty(resourceTypeIdList) && CollectionUtils.isNotEmpty(resourceCiVoList)) { + List downwardCiList = ciMapper.getBatchDownwardCiListByCiList(resourceCiVoList); + for (CiVo downwardCi : downwardCiList) { + // 找出叶子节点模型 + if (downwardCi.getRht() != null && downwardCi.getLft() != null && (downwardCi.getRht() - downwardCi.getLft() == 1)) { + resourceTypeIdList.add(downwardCi.getId()); + } + } + } if (CollectionUtils.isNotEmpty(resourceTypeIdList)) { ResourceSearchVo searchVo = new ResourceSearchVo(); searchVo.setAppSystemIdList(Collections.singletonList(appSystemId)); @@ -105,7 +120,8 @@ public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataS resourceCenterResourceService.assembleResourceSearchVo(searchVo, false); List resourceList = getResourceList(searchVo); if (CollectionUtils.isNotEmpty(resourceList)) { - JSONObject tableObj = TableResultUtil.getResult(ciName2TheadListMap.get(resourceTypeName), resourceList, searchVo); + JSONArray fieldList = ciName2TheadListMap.get(resourceTypeName); + JSONObject tableObj = TableResultUtil.getResult(getTheadList(fieldList), resourceList, searchVo); tableObj.put("type", resourceTypeVo); tableList.add(tableObj); } @@ -138,6 +154,234 @@ public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataS return resourceList; } + @Override + public List getResourceTypeTree(String keyword) { + if (StringUtils.isNotBlank(keyword)) { + keyword = keyword.toLowerCase(); + } + List resultList = new ArrayList<>(); + List ciIdList = resourceEntityMapper.getAllResourceTypeCiIdList(); + if (CollectionUtils.isEmpty(ciIdList)) { + return resultList; + } + List authCiVoList = new ArrayList<>(); + ResourceSearchVo searchVo = new ResourceSearchVo(); + searchVo.setTypeIdList(ciIdList); + resourceCenterResourceService.assembleResourceSearchVo(searchVo, false); +// jsonObj.put("typeIdList", ciIdList); +// ResourceSearchVo searchVo = resourceCenterResourceService.assembleResourceSearchVo(jsonObj, false); + //先找出所有有权限的配置项的模型idList + if (!searchVo.getIsHasAuth()) { + Set authCiIdList = ciMapper.getAllAuthCi(UserContext.get().getAuthenticationInfoVo()).stream().map(CiVo::getId).collect(Collectors.toSet()); + authCiIdList.addAll(resourceMapper.getResourceTypeIdListByAuth(searchVo)); + if (CollectionUtils.isEmpty(authCiIdList)) { + return resultList; + } + authCiVoList = ciMapper.getCiByIdList(new ArrayList<>(authCiIdList)); + } + + if (CollectionUtils.isNotEmpty(ciIdList)) { + List ciVoList = ciMapper.getCiByIdList(ciIdList); + ciVoList.sort(Comparator.comparing(CiVo::getLft)); + for (CiVo ciVo : ciVoList) { + Set ciList = new HashSet<>(); + List ciListTmp = ciMapper.getDownwardCiListByLR(ciVo.getLft(), ciVo.getRht()); + //过滤出所有有权限的配置项的模型idList + if (!searchVo.getIsHasAuth()) { + if (CollectionUtils.isNotEmpty(authCiVoList) && CollectionUtils.isNotEmpty(ciListTmp)) { + for (CiVo ci : ciListTmp) { + for (CiVo authCi : authCiVoList) { + if (ci.getLft() <= authCi.getLft() && ci.getRht() >= authCi.getRht()) { + ciList.add(ci); + break; + } + } + } + } + } else { + ciList = new HashSet<>(ciListTmp); + } + int size = ciList.size(); + List resourceTypeVoList = new ArrayList<>(size); + Map resourceTypeMap = new HashMap<>(size); + for (CiVo ci : ciList) { + ResourceTypeVo resourceTypeVo = new ResourceTypeVo(ci.getId(), ci.getParentCiId(), ci.getLabel(), ci.getName()); + resourceTypeMap.put(resourceTypeVo.getId(), resourceTypeVo); + resourceTypeVoList.add(resourceTypeVo); + } + if (StringUtils.isNotBlank(keyword)) { + // 建立父子关系 + for (ResourceTypeVo resourceType : resourceTypeVoList) { + if (resourceType.getParentId() != null) { + ResourceTypeVo parentResourceType = resourceTypeMap.get(resourceType.getParentId()); + if (parentResourceType != null) { + resourceType.setParent(parentResourceType); + parentResourceType.addChild(resourceType); + } + } + } + // 判断节点名称是否与关键字keyword匹配,如果匹配就将该节点及其父子节点的isKeywordMatch字段值设置为1,否则设置为0。 + for (ResourceTypeVo resourceType : resourceTypeVoList) { + if (resourceType.getLabel().toLowerCase().contains(keyword)) { + if (resourceType.getIsKeywordMatch() == null) { + resourceType.setIsKeywordMatch(1); + resourceType.setUpwardIsKeywordMatch(1); + resourceType.setDownwardIsKeywordMatch(1); + } + } else { + if (resourceType.getIsKeywordMatch() == null) { + resourceType.setIsKeywordMatch(0); + } + } + } + // 将isKeywordMatch字段值为0的节点从其父级中移除。 + Iterator iterator = resourceTypeVoList.iterator(); + while (iterator.hasNext()) { + ResourceTypeVo resourceType = iterator.next(); + if (Objects.equals(resourceType.getIsKeywordMatch(), 0)) { + ResourceTypeVo parent = resourceType.getParent(); + if (parent != null) { + parent.removeChild(resourceType); + } + iterator.remove(); + } + } + } else { + for (ResourceTypeVo resourceType : resourceTypeVoList) { + if (resourceType.getParentId() != null) { + ResourceTypeVo parentResourceType = resourceTypeMap.get(resourceType.getParentId()); + if (parentResourceType != null) { + parentResourceType.addChild(resourceType); + } + } + } + } + for (ResourceTypeVo resourceType : resourceTypeVoList) { + if (resourceType.getParentId() != null) { + ResourceTypeVo parentResourceType = resourceTypeMap.get(resourceType.getParentId()); + if (parentResourceType == null) { + resultList.add(resourceType); + } + } else { + resultList.add(resourceType); + } + } + } + } + return resultList; + } + + @Override + public List getResourceTypeListTree(String keyword) { + if (StringUtils.isNotBlank(keyword)) { + keyword = keyword.toLowerCase(); + } + List resultList = new ArrayList<>(); + ResourceEntityVo resourceEntityVo = resourceEntityMapper.getResourceEntityByName("scence_ipobject_detail"); + if (resourceEntityVo == null) { + return resultList; + } + ResourceEntityConfigVo config = resourceEntityVo.getConfig(); + if (config == null) { + return resultList; + } + CiVo ciVo = ciMapper.getCiByName(config.getMainCi()); + if (ciVo == null) { + return resultList; + } + + List ciList = ciMapper.getDownwardCiListByLR(ciVo.getLft(), ciVo.getRht()); + int size = ciList.size(); + List resourceTypeVoList = new ArrayList<>(size); + Map resourceTypeMap = new HashMap<>(size); + for (CiVo ci : ciList) { + ResourceTypeVo resourceTypeVo = new ResourceTypeVo(ci.getId(), ci.getParentCiId(), ci.getLabel(), ci.getName()); + resourceTypeMap.put(resourceTypeVo.getId(), resourceTypeVo); + resourceTypeVoList.add(resourceTypeVo); + } + if (StringUtils.isNotBlank(keyword)) { + // 建立父子关系 + for (ResourceTypeVo resourceType : resourceTypeVoList) { + if (resourceType.getParentId() != null) { + ResourceTypeVo parentResourceType = resourceTypeMap.get(resourceType.getParentId()); + if (parentResourceType != null) { + resourceType.setParent(parentResourceType); + parentResourceType.addChild(resourceType); + } + } + } + // 判断节点名称是否与关键字keyword匹配,如果匹配就将该节点及其父子节点的isKeywordMatch字段值设置为1,否则设置为0。 + for (ResourceTypeVo resourceType : resourceTypeVoList) { + if (resourceType.getLabel().toLowerCase().contains(keyword)) { + if (resourceType.getIsKeywordMatch() == null) { + resourceType.setIsKeywordMatch(1); + resourceType.setUpwardIsKeywordMatch(1); + resourceType.setDownwardIsKeywordMatch(1); + } + } else { + if (resourceType.getIsKeywordMatch() == null) { + resourceType.setIsKeywordMatch(0); + } + } + } + // 将isKeywordMatch字段值为0的节点从其父级中移除。 + Iterator iterator = resourceTypeVoList.iterator(); + while (iterator.hasNext()) { + ResourceTypeVo resourceType = iterator.next(); + if (Objects.equals(resourceType.getIsKeywordMatch(), 0)) { + ResourceTypeVo parent = resourceType.getParent(); + if (parent != null) { + parent.removeChild(resourceType); + } + iterator.remove(); + } + } + } else { + for (ResourceTypeVo resourceType : resourceTypeVoList) { + if (resourceType.getParentId() != null) { + ResourceTypeVo parentResourceType = resourceTypeMap.get(resourceType.getParentId()); + if (parentResourceType != null) { + parentResourceType.addChild(resourceType); + } + } + } + } + for (ResourceTypeVo resourceType : resourceTypeVoList) { + if (resourceType.getParentId() != null) { + ResourceTypeVo parentResourceType = resourceTypeMap.get(resourceType.getParentId()); + if (parentResourceType == null) { + resultList.add(resourceType); + } + } else { + resultList.add(resourceType); + } + } + return resultList; + } + + @Override + public JSONArray getTheadList(JSONArray fieldNameList) { + JSONArray theadList = new JSONArray(); + if (CollectionUtils.isNotEmpty(fieldNameList)) { + List fieldList = ResourceEntityFactory.getFieldListByViewName("scence_ipobject_detail"); + Map field2TitleMap = fieldList.stream().collect(Collectors.toMap(ValueTextVo::getValue, ValueTextVo::getText)); + List fieldAliasList = ResourceEntityFactory.getFieldAliasListByViewName("scence_ipobject_detail"); + Map field2KeyMap = fieldAliasList.stream().collect(Collectors.toMap(ValueTextVo::getValue, ValueTextVo::getText)); + for (int i = 0; i < fieldNameList.size(); i++) { + String field = fieldNameList.getString(i); + String title = field2TitleMap.get(field); + String key = field2KeyMap.get(field); + if (StringUtils.isNotBlank(key) && StringUtils.isNotBlank(title)) { + JSONObject thead = new JSONObject(); + thead.put("key", key); + thead.put("title", title); + theadList.add(thead); + } + } + } + return theadList; + } + /** * 判断是否有过滤条件 * @param searchVo diff --git a/src/main/java/neatlogic/module/cmdb/utils/ResourceEntityFactory.java b/src/main/java/neatlogic/module/cmdb/utils/ResourceEntityFactory.java index 8e88f68b..5cf7b6f1 100644 --- a/src/main/java/neatlogic/module/cmdb/utils/ResourceEntityFactory.java +++ b/src/main/java/neatlogic/module/cmdb/utils/ResourceEntityFactory.java @@ -41,6 +41,10 @@ public class ResourceEntityFactory { * 视图名称与字段列表映射关系 */ private static Map> fieldMap = new HashMap<>(); + /** + * 视图名称与字段别名列表映射关系 + */ + private static Map> fieldAliasMap = new HashMap<>(); private static List resourceEntityList = new ArrayList<>(); /** * 视图信息列表 @@ -137,6 +141,7 @@ public class ResourceEntityFactory { if (StringUtils.isNotBlank(rf.name())) { EntityField ef = field.getAnnotation(EntityField.class); fieldMap.computeIfAbsent(sceneEntityVo.getName(), key -> new ArrayList<>()).add(new ValueTextVo(rf.name(), ef.name())); + fieldAliasMap.computeIfAbsent(sceneEntityVo.getName(), key -> new ArrayList<>()).add(new ValueTextVo(rf.name(), field.getName())); } } // Annotation[] annotations = field.getDeclaredAnnotations(); @@ -171,6 +176,7 @@ public class ResourceEntityFactory { if (StringUtils.isNotBlank(rf.name())) { EntityField ef = field.getAnnotation(EntityField.class); fieldMap.computeIfAbsent(sceneEntityVo.getName(), key -> new ArrayList<>()).add(new ValueTextVo(rf.name(), ef.name())); + fieldAliasMap.computeIfAbsent(sceneEntityVo.getName(), key -> new ArrayList<>()).add(new ValueTextVo(rf.name(), field.getName())); } } } @@ -225,6 +231,14 @@ public class ResourceEntityFactory { return new ArrayList<>(fieldList); } + public static List getFieldAliasListByViewName(String viewName) { + List fieldAliasList = fieldAliasMap.get(viewName); + if (fieldAliasList == null) { + return new ArrayList<>(); + } + return new ArrayList<>(fieldAliasList); + } + public static List getViewNameList() { return new ArrayList<>(viewNameList); } -- Gitee From 1c521afe5a3adf7c1e6899406dae50147119d9d9 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Fri, 21 Feb 2025 18:34:39 +0800 Subject: [PATCH 07/29] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20CMDB=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E6=B8=85=E5=8D=95=E6=94=B9=E6=88=90=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E5=B1=82=E7=BA=A7=E5=8F=AF=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1349157963399168]CMDB应用清单改成模型层级可配置 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1349157963399168 --- .../resource/ResourceListApi.java | 92 ++++++++++++------- .../DefaultResourceCenterDataSourceImpl.java | 39 +++++--- 2 files changed, 85 insertions(+), 46 deletions(-) diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceListApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceListApi.java index 35725e35..bbe036c6 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceListApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceListApi.java @@ -19,9 +19,12 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import neatlogic.framework.auth.core.AuthAction; import neatlogic.framework.cmdb.auth.label.CMDB; +import neatlogic.framework.cmdb.dto.resourcecenter.AssetListDisplayVo; import neatlogic.framework.cmdb.dto.resourcecenter.ResourceSearchVo; import neatlogic.framework.cmdb.dto.resourcecenter.ResourceVo; import neatlogic.framework.cmdb.enums.group.GroupType; +import neatlogic.framework.cmdb.resourcecenter.datasource.core.IResourceCenterDataSource; +import neatlogic.framework.cmdb.resourcecenter.datasource.core.ResourceCenterDataSourceFactory; import neatlogic.framework.common.constvalue.ApiParamType; import neatlogic.framework.common.dto.BasePageVo; import neatlogic.framework.restful.annotation.*; @@ -39,7 +42,11 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; -import java.util.*; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; /** * 查询资源中心数据列表接口 @@ -115,8 +122,8 @@ public class ResourceListApi extends PrivateApiComponentBase { @Description(desc = "nmcarr.resourcelistapi.getname") @Override public Object myDoService(JSONObject jsonObj) throws Exception { - List resourceList = new ArrayList<>(); - List resultList = new ArrayList<>(); +// List resourceList = new ArrayList<>(); +// List resultList = new ArrayList<>(); ResourceSearchVo searchVo; JSONArray defaultValue = jsonObj.getJSONArray("defaultValue"); if (CollectionUtils.isNotEmpty(defaultValue)) { @@ -127,41 +134,46 @@ public class ResourceListApi extends PrivateApiComponentBase { } resourceCenterResourceService.handleBatchSearchList(searchVo); resourceCenterResourceService.setIpFieldAttrIdAndNameFieldAttrId(searchVo); - if (Objects.equals(searchVo.getRowNum(), 0)) { - int rowNum = 0; - if (noFilterCondition(searchVo)) { - rowNum = resourceMapper.getAllResourceCount(searchVo); - } else { - rowNum = resourceMapper.getResourceCount(searchVo); - } - if (rowNum == 0) { - return TableResultUtil.getResult(resourceList, searchVo); - } - searchVo.setRowNum(rowNum); - } - resourceCenterResourceService.setIsIpFieldSortAndIsNameFieldSort(searchVo); - List idList = resourceMapper.getResourceIdList(searchVo); - if (CollectionUtils.isEmpty(idList)) { - return TableResultUtil.getResult(resourceList, searchVo); - } - resourceList = resourceMapper.getResourceListByIdList(idList); - if (CollectionUtils.isNotEmpty(resourceList)) { - resourceCenterResourceService.addTagAndAccountInformation(resourceList); +// if (Objects.equals(searchVo.getRowNum(), 0)) { +// int rowNum = 0; +// if (noFilterCondition(searchVo)) { +// rowNum = resourceMapper.getAllResourceCount(searchVo); +// } else { +// rowNum = resourceMapper.getResourceCount(searchVo); +// } +// if (rowNum == 0) { +// return TableResultUtil.getResult(resourceList, searchVo); +// } +// searchVo.setRowNum(rowNum); +// } +// resourceCenterResourceService.setIsIpFieldSortAndIsNameFieldSort(searchVo); +// List idList = resourceMapper.getResourceIdList(searchVo); +// if (CollectionUtils.isEmpty(idList)) { +// return TableResultUtil.getResult(resourceList, searchVo); +// } +// resourceList = resourceMapper.getResourceListByIdList(idList); +// if (CollectionUtils.isNotEmpty(resourceList)) { +// resourceCenterResourceService.addTagAndAccountInformation(resourceList); +// } + IResourceCenterDataSource resourceCenterDataSource = ResourceCenterDataSourceFactory.getResourceCenterDataSource(); + List resultList = resourceCenterDataSource.getResourceList(searchVo); + if (CollectionUtils.isNotEmpty(resultList)) { + resourceCenterResourceService.addTagAndAccountInformation(resultList); } - Set typeIdList = new HashSet<>(); + Set typeIdList = resultList.stream().map(ResourceVo::getTypeId).collect(Collectors.toSet()); List canDeleteTypeIdList = new ArrayList<>(); List canEditTypeIdList = new ArrayList<>(); //排序 - for (Long id : idList) { - for (ResourceVo resourceVo : resourceList) { - if (Objects.equals(id, resourceVo.getId())) { - resultList.add(resourceVo); - typeIdList.add(resourceVo.getTypeId()); - break; - } - } - } +// for (Long id : idList) { +// for (ResourceVo resourceVo : resourceList) { +// if (Objects.equals(id, resourceVo.getId())) { +// resultList.add(resourceVo); +// typeIdList.add(resourceVo.getTypeId()); +// break; +// } +// } +// } //补充配置项权限 Set withoutCiAuthCiEntityList = new HashSet<>(); @@ -194,7 +206,19 @@ public class ResourceListApi extends PrivateApiComponentBase { resourceVo.setIsCanDelete(true); } } - return TableResultUtil.getResult(resultList, searchVo); + List fieldNameList = null; + AssetListDisplayVo assetListDisplay = resourceEntityMapper.getAssetListDisplay(); + if (assetListDisplay != null) { + JSONObject config = assetListDisplay.getConfig(); + if (config != null) { + JSONArray fieldList = config.getJSONArray("fieldList"); + if (CollectionUtils.isNotEmpty(fieldList)) { + fieldNameList = fieldList.toJavaList(String.class); + } + } + } + JSONArray theadList = resourceCenterDataSource.getTheadList(fieldNameList); + return TableResultUtil.getResult(theadList, resultList, searchVo); } /** diff --git a/src/main/java/neatlogic/module/cmdb/resourcecenter/datasource/handler/DefaultResourceCenterDataSourceImpl.java b/src/main/java/neatlogic/module/cmdb/resourcecenter/datasource/handler/DefaultResourceCenterDataSourceImpl.java index e02d5823..5128c40b 100644 --- a/src/main/java/neatlogic/module/cmdb/resourcecenter/datasource/handler/DefaultResourceCenterDataSourceImpl.java +++ b/src/main/java/neatlogic/module/cmdb/resourcecenter/datasource/handler/DefaultResourceCenterDataSourceImpl.java @@ -79,14 +79,16 @@ public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataS JSONArray tableSettingList = config.getJSONArray("tableSettingList"); if (CollectionUtils.isNotEmpty(tableSettingList)) { List ciNameList = new ArrayList<>(); - Map ciName2TheadListMap = new HashMap<>(); + Map> ciName2FieldListMap = new HashMap<>(); for (int i = 0; i < tableSettingList.size(); i++) { JSONObject tableObj = tableSettingList.getJSONObject(i); if (MapUtils.isNotEmpty(tableObj)) { String ciName = tableObj.getString("ciName"); - JSONArray fieldList = tableObj.getJSONArray("fieldList"); - ciName2TheadListMap.put(ciName, fieldList); ciNameList.add(ciName); + JSONArray fieldList = tableObj.getJSONArray("fieldList"); + if (CollectionUtils.isNotEmpty(fieldList)) { + ciName2FieldListMap.put(ciName, fieldList.toJavaList(String.class)); + } } } if (CollectionUtils.isNotEmpty(ciNameList)) { @@ -120,7 +122,7 @@ public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataS resourceCenterResourceService.assembleResourceSearchVo(searchVo, false); List resourceList = getResourceList(searchVo); if (CollectionUtils.isNotEmpty(resourceList)) { - JSONArray fieldList = ciName2TheadListMap.get(resourceTypeName); + List fieldList = ciName2FieldListMap.get(resourceTypeName); JSONObject tableObj = TableResultUtil.getResult(getTheadList(fieldList), resourceList, searchVo); tableObj.put("type", resourceTypeVo); tableList.add(tableObj); @@ -137,10 +139,19 @@ public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataS @Override public List getResourceList(ResourceSearchVo searchVo) { - List resourceList = new ArrayList<>(); + List resultList = new ArrayList<>(); List idList = resourceMapper.getResourceIdList(searchVo); if (CollectionUtils.isNotEmpty(idList)) { - resourceList = resourceMapper.getResourceListByIdList(idList); + List resourceList = resourceMapper.getResourceListByIdList(idList); + //排序 + for (Long id : idList) { + for (ResourceVo resourceVo : resourceList) { + if (Objects.equals(id, resourceVo.getId())) { + resultList.add(resourceVo); + break; + } + } + } if (Objects.equals(searchVo.getRowNum(), 0)) { int rowNum = 0; if (noFilterCondition(searchVo)) { @@ -150,8 +161,10 @@ public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataS } searchVo.setRowNum(rowNum); } + } else { + searchVo.setRowNum(0); } - return resourceList; + return resultList; } @Override @@ -360,17 +373,19 @@ public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataS } @Override - public JSONArray getTheadList(JSONArray fieldNameList) { + public JSONArray getTheadList(List fieldNameList) { JSONArray theadList = new JSONArray(); + if (CollectionUtils.isNotEmpty(fieldNameList)) { + fieldNameList = ResourceEntityFactory.getFieldNameListByViewName("scence_ipobject_detail"); + } if (CollectionUtils.isNotEmpty(fieldNameList)) { List fieldList = ResourceEntityFactory.getFieldListByViewName("scence_ipobject_detail"); Map field2TitleMap = fieldList.stream().collect(Collectors.toMap(ValueTextVo::getValue, ValueTextVo::getText)); List fieldAliasList = ResourceEntityFactory.getFieldAliasListByViewName("scence_ipobject_detail"); Map field2KeyMap = fieldAliasList.stream().collect(Collectors.toMap(ValueTextVo::getValue, ValueTextVo::getText)); - for (int i = 0; i < fieldNameList.size(); i++) { - String field = fieldNameList.getString(i); - String title = field2TitleMap.get(field); - String key = field2KeyMap.get(field); + for (String fieldName : fieldNameList) { + String title = field2TitleMap.get(fieldName); + String key = field2KeyMap.get(fieldName); if (StringUtils.isNotBlank(key) && StringUtils.isNotBlank(title)) { JSONObject thead = new JSONObject(); thead.put("key", key); -- Gitee From 20671ddaa6a252faae003f65e72aae4427910eef Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Fri, 21 Feb 2025 18:54:35 +0800 Subject: [PATCH 08/29] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20CMDB=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E6=B8=85=E5=8D=95=E6=94=B9=E6=88=90=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E5=B1=82=E7=BA=A7=E5=8F=AF=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1349157963399168]CMDB应用清单改成模型层级可配置 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1349157963399168 --- .../app/AppResourceListApi.java | 30 ++----------------- .../DefaultResourceCenterDataSourceImpl.java | 27 +++++++++++++---- 2 files changed, 25 insertions(+), 32 deletions(-) diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/app/AppResourceListApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/app/AppResourceListApi.java index ce749412..7da07f5c 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/app/AppResourceListApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/app/AppResourceListApi.java @@ -19,11 +19,7 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import neatlogic.framework.auth.core.AuthAction; import neatlogic.framework.cmdb.auth.label.CMDB_BASE; -import neatlogic.framework.cmdb.dto.ci.CiVo; import neatlogic.framework.cmdb.dto.resourcecenter.ResourceSearchVo; -import neatlogic.framework.cmdb.exception.ci.CiNotFoundException; -import neatlogic.framework.cmdb.exception.resourcecenter.AppModuleNotFoundException; -import neatlogic.framework.cmdb.exception.resourcecenter.AppSystemNotFoundException; import neatlogic.framework.cmdb.resourcecenter.datasource.core.IResourceCenterDataSource; import neatlogic.framework.cmdb.resourcecenter.datasource.core.ResourceCenterDataSourceFactory; import neatlogic.framework.common.constvalue.ApiParamType; @@ -31,11 +27,8 @@ import neatlogic.framework.exception.type.ParamNotExistsException; import neatlogic.framework.restful.annotation.*; import neatlogic.framework.restful.constvalue.OperationTypeEnum; import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; -import neatlogic.module.cmdb.dao.mapper.ci.CiMapper; -import neatlogic.module.cmdb.dao.mapper.cientity.CiEntityMapper; import org.springframework.stereotype.Service; -import javax.annotation.Resource; import java.util.ArrayList; import java.util.List; @@ -48,12 +41,6 @@ import java.util.List; @OperationType(type = OperationTypeEnum.SEARCH) public class AppResourceListApi extends PrivateApiComponentBase { - @Resource - private CiEntityMapper ciEntityMapper; - - @Resource - private CiMapper ciMapper; - @Override public String getToken() { return "resourcecenter/app/resource/list"; @@ -74,8 +61,8 @@ public class AppResourceListApi extends PrivateApiComponentBase { @Param(name = "appModuleId", type = ApiParamType.LONG, desc = "应用模块id"), @Param(name = "envId", type = ApiParamType.LONG, desc = "环境id,envId=-2表示无配置环境"), @Param(name = "typeId", type = ApiParamType.LONG, desc = "类型id"), - @Param(name = "currentPage", type = ApiParamType.INTEGER, desc = "当前页"), - @Param(name = "pageSize", type = ApiParamType.INTEGER, desc = "每页数据条目") + @Param(name = "currentPage", type = ApiParamType.INTEGER, defaultValue = "1", desc = "当前页"), + @Param(name = "pageSize", type = ApiParamType.INTEGER, defaultValue = "20", desc = "每页数据条目") }) @Output({ @Param(name = "tableList", type = ApiParamType.JSONARRAY, desc = "资源环境列表") @@ -91,24 +78,13 @@ public class AppResourceListApi extends PrivateApiComponentBase { Long appSystemId = paramObj.getLong("appSystemId"); Long appModuleId = paramObj.getLong("appModuleId"); Long envId = paramObj.getLong("envId"); - Long typeId = paramObj.getLong("typeId"); Integer currentPage = paramObj.getInteger("currentPage"); Integer pageSize = paramObj.getInteger("pageSize"); - if (appSystemId != null && ciEntityMapper.getCiEntityBaseInfoById(appSystemId) == null) { - throw new AppSystemNotFoundException(appSystemId); - } - if (appModuleId != null && ciEntityMapper.getCiEntityBaseInfoById(appModuleId) == null) { - throw new AppModuleNotFoundException(appModuleId); - } + Long typeId = paramObj.getLong("typeId"); List typeIdList = new ArrayList<>(); if (typeId != null) { - CiVo ciVo = ciMapper.getCiById(typeId); - if (ciVo == null) { - throw new CiNotFoundException(typeId); - } typeIdList.add(typeId); } - IResourceCenterDataSource resourceCenterDataSource = ResourceCenterDataSourceFactory.getResourceCenterDataSource(); JSONArray tableList = resourceCenterDataSource.getAppResourceList(appSystemId, appModuleId, envId, typeIdList, currentPage, pageSize); resultObj.put("tableList", tableList); diff --git a/src/main/java/neatlogic/module/cmdb/resourcecenter/datasource/handler/DefaultResourceCenterDataSourceImpl.java b/src/main/java/neatlogic/module/cmdb/resourcecenter/datasource/handler/DefaultResourceCenterDataSourceImpl.java index 5128c40b..d8a571df 100644 --- a/src/main/java/neatlogic/module/cmdb/resourcecenter/datasource/handler/DefaultResourceCenterDataSourceImpl.java +++ b/src/main/java/neatlogic/module/cmdb/resourcecenter/datasource/handler/DefaultResourceCenterDataSourceImpl.java @@ -27,6 +27,9 @@ import neatlogic.framework.cmdb.dto.resourcecenter.ResourceTypeVo; import neatlogic.framework.cmdb.dto.resourcecenter.ResourceVo; import neatlogic.framework.cmdb.dto.resourcecenter.config.ResourceEntityConfigVo; import neatlogic.framework.cmdb.dto.resourcecenter.config.ResourceEntityVo; +import neatlogic.framework.cmdb.exception.ci.CiNotFoundException; +import neatlogic.framework.cmdb.exception.resourcecenter.AppModuleNotFoundException; +import neatlogic.framework.cmdb.exception.resourcecenter.AppSystemNotFoundException; import neatlogic.framework.cmdb.resourcecenter.datasource.core.IResourceCenterDataSource; import neatlogic.framework.cmdb.resourcecenter.datasource.core.Ordered; import neatlogic.framework.common.dto.ValueTextVo; @@ -70,7 +73,21 @@ public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataS } @Override - public JSONArray getAppResourceList(Long appSystemId, Long appModuleId, Long envId, List resourceTypeIdList, Integer currentPage, Integer pageSize) { + public JSONArray getAppResourceList(Long appSystemId, Long appModuleId, Long envId, List typeIdList, Integer currentPage, Integer pageSize) { + if (appSystemId != null && ciEntityMapper.getCiEntityBaseInfoById(appSystemId) == null) { + throw new AppSystemNotFoundException(appSystemId); + } + if (appModuleId != null && ciEntityMapper.getCiEntityBaseInfoById(appModuleId) == null) { + throw new AppModuleNotFoundException(appModuleId); + } + if (CollectionUtils.isNotEmpty(typeIdList)) { + for (Long typeId : typeIdList) { + CiVo ciVo = ciMapper.getCiById(typeId); + if (ciVo == null) { + throw new CiNotFoundException(typeId); + } + } + } JSONArray tableList = new JSONArray(); ApplicationListDisplayVo applicationListDisplay = resourceEntityMapper.getApplicationListDisplay(); if (applicationListDisplay != null) { @@ -93,16 +110,16 @@ public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataS } if (CollectionUtils.isNotEmpty(ciNameList)) { List resourceCiVoList = ciMapper.getCiListByNameList(ciNameList); - if (CollectionUtils.isEmpty(resourceTypeIdList) && CollectionUtils.isNotEmpty(resourceCiVoList)) { + if (CollectionUtils.isEmpty(typeIdList) && CollectionUtils.isNotEmpty(resourceCiVoList)) { List downwardCiList = ciMapper.getBatchDownwardCiListByCiList(resourceCiVoList); for (CiVo downwardCi : downwardCiList) { // 找出叶子节点模型 if (downwardCi.getRht() != null && downwardCi.getLft() != null && (downwardCi.getRht() - downwardCi.getLft() == 1)) { - resourceTypeIdList.add(downwardCi.getId()); + typeIdList.add(downwardCi.getId()); } } } - if (CollectionUtils.isNotEmpty(resourceTypeIdList)) { + if (CollectionUtils.isNotEmpty(typeIdList)) { ResourceSearchVo searchVo = new ResourceSearchVo(); searchVo.setAppSystemIdList(Collections.singletonList(appSystemId)); if (appModuleId != null) { @@ -113,7 +130,7 @@ public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataS } searchVo.setCurrentPage(currentPage); searchVo.setPageSize(pageSize); - List ciList = ciMapper.getAllCi(resourceTypeIdList); + List ciList = ciMapper.getAllCi(typeIdList); for (CiVo ciVo : ciList) { String resourceTypeName = getResourceTypeName(resourceCiVoList, ciVo); if (StringUtils.isNotBlank(resourceTypeName)) { -- Gitee From 2604747dbd350a0137bb7f8c08af08f85e62d2c1 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Sat, 22 Feb 2025 14:50:35 +0800 Subject: [PATCH 09/29] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20CMDB=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E6=B8=85=E5=8D=95=E6=94=B9=E6=88=90=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E5=B1=82=E7=BA=A7=E5=8F=AF=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1349157963399168]CMDB应用清单改成模型层级可配置 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1349157963399168 --- .../app/ListAppSystemForSelectApi.java | 67 +++--- .../app/ListAppSystemForTreeApi.java | 84 ++++---- .../appenv/ListAppEnvForSelectApi.java | 75 ++++--- .../appmodule/AppModuleListApi.java | 8 +- .../ListAppModuleListForTreeApi.java | 56 +++-- .../state/ListStateForSelectApi.java | 67 +++--- .../vendor/ListVendorForSelectApi.java | 67 +++--- .../DefaultResourceCenterDataSourceImpl.java | 200 +++++++++++++++++- .../IResourceCenterResourceService.java | 2 +- .../ResourceCenterResourceServiceImpl.java | 24 +-- 10 files changed, 411 insertions(+), 239 deletions(-) diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/app/ListAppSystemForSelectApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/app/ListAppSystemForSelectApi.java index d6d3b8f1..98506b3e 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/app/ListAppSystemForSelectApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/app/ListAppSystemForSelectApi.java @@ -15,23 +15,20 @@ along with this program. If not, see .*/ package neatlogic.module.cmdb.api.resourcecenter.app; -import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import neatlogic.framework.auth.core.AuthAction; import neatlogic.framework.cmdb.auth.label.CMDB; import neatlogic.framework.cmdb.dto.resourcecenter.ResourceVo; +import neatlogic.framework.cmdb.resourcecenter.datasource.core.IResourceCenterDataSource; +import neatlogic.framework.cmdb.resourcecenter.datasource.core.ResourceCenterDataSourceFactory; import neatlogic.framework.common.constvalue.ApiParamType; import neatlogic.framework.common.dto.BasePageVo; import neatlogic.framework.restful.annotation.*; import neatlogic.framework.restful.constvalue.OperationTypeEnum; import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; import neatlogic.framework.util.TableResultUtil; -import neatlogic.module.cmdb.dao.mapper.resourcecenter.ResourceMapper; -import org.apache.commons.collections4.CollectionUtils; import org.springframework.stereotype.Service; -import javax.annotation.Resource; -import java.util.ArrayList; import java.util.List; @Service @@ -39,9 +36,6 @@ import java.util.List; @OperationType(type = OperationTypeEnum.SEARCH) public class ListAppSystemForSelectApi extends PrivateApiComponentBase { - @Resource - private ResourceMapper resourceMapper; - @Override public String getToken() { return "resourcecenter/appsystem/list/forselect"; @@ -71,32 +65,35 @@ public class ListAppSystemForSelectApi extends PrivateApiComponentBase { @Override public Object myDoService(JSONObject paramObj) throws Exception { BasePageVo searchVo = paramObj.toJavaObject(BasePageVo.class); - JSONArray defaultValue = searchVo.getDefaultValue(); - if (CollectionUtils.isNotEmpty(defaultValue)) { - List idList = defaultValue.toJavaList(Long.class); - List resourceList = resourceMapper.searchAppSystemListByIdList(idList); - return TableResultUtil.getResult(resourceList); - } else { - int rowNum = resourceMapper.searchAppSystemCount(searchVo); - if (rowNum > 0) { - searchVo.setRowNum(rowNum); - if (searchVo.getNeedPage()) { - List idList = resourceMapper.searchAppSystemIdList(searchVo); - List resourceList = resourceMapper.searchAppSystemListByIdList(idList); - return TableResultUtil.getResult(resourceList, searchVo); - } else { - List allResourceList = new ArrayList<>(); - int pageCount = searchVo.getPageCount(); - for (int currentPage = 1; currentPage <= pageCount; currentPage++) { - searchVo.setCurrentPage(currentPage); - List idList = resourceMapper.searchAppSystemIdList(searchVo); - List resourceList = resourceMapper.searchAppSystemListByIdList(idList); - allResourceList.addAll(resourceList); - } - return TableResultUtil.getResult(allResourceList, searchVo); - } - } - } - return null; + IResourceCenterDataSource resourceCenterDataSource = ResourceCenterDataSourceFactory.getResourceCenterDataSource(); + List tbodyList = resourceCenterDataSource.getAppSystemListForSelect(searchVo); + return TableResultUtil.getResult(tbodyList, searchVo); +// JSONArray defaultValue = searchVo.getDefaultValue(); +// if (CollectionUtils.isNotEmpty(defaultValue)) { +// List idList = defaultValue.toJavaList(Long.class); +// List resourceList = resourceMapper.searchAppSystemListByIdList(idList); +// return TableResultUtil.getResult(resourceList); +// } else { +// int rowNum = resourceMapper.searchAppSystemCount(searchVo); +// if (rowNum > 0) { +// searchVo.setRowNum(rowNum); +// if (searchVo.getNeedPage()) { +// List idList = resourceMapper.searchAppSystemIdList(searchVo); +// List resourceList = resourceMapper.searchAppSystemListByIdList(idList); +// return TableResultUtil.getResult(resourceList, searchVo); +// } else { +// List allResourceList = new ArrayList<>(); +// int pageCount = searchVo.getPageCount(); +// for (int currentPage = 1; currentPage <= pageCount; currentPage++) { +// searchVo.setCurrentPage(currentPage); +// List idList = resourceMapper.searchAppSystemIdList(searchVo); +// List resourceList = resourceMapper.searchAppSystemListByIdList(idList); +// allResourceList.addAll(resourceList); +// } +// return TableResultUtil.getResult(allResourceList, searchVo); +// } +// } +// } +// return null; } } diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/app/ListAppSystemForTreeApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/app/ListAppSystemForTreeApi.java index dcc095bb..4ac23c10 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/app/ListAppSystemForTreeApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/app/ListAppSystemForTreeApi.java @@ -18,33 +18,24 @@ package neatlogic.module.cmdb.api.resourcecenter.app; import com.alibaba.fastjson.JSONObject; import neatlogic.framework.auth.core.AuthAction; import neatlogic.framework.cmdb.auth.label.CMDB; -import neatlogic.framework.cmdb.dto.resourcecenter.AppModuleVo; import neatlogic.framework.cmdb.dto.resourcecenter.AppSystemVo; +import neatlogic.framework.cmdb.resourcecenter.datasource.core.IResourceCenterDataSource; +import neatlogic.framework.cmdb.resourcecenter.datasource.core.ResourceCenterDataSourceFactory; import neatlogic.framework.common.constvalue.ApiParamType; import neatlogic.framework.common.dto.BasePageVo; import neatlogic.framework.restful.annotation.*; import neatlogic.framework.restful.constvalue.OperationTypeEnum; import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; import neatlogic.framework.util.TableResultUtil; -import neatlogic.module.cmdb.dao.mapper.resourcecenter.ResourceMapper; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; -import javax.annotation.Resource; -import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; @Service @AuthAction(action = CMDB.class) @OperationType(type = OperationTypeEnum.SEARCH) public class ListAppSystemForTreeApi extends PrivateApiComponentBase { - @Resource - private ResourceMapper resourceMapper; - @Override public String getToken() { return "resourcecenter/appsystem/list/fortree"; @@ -72,42 +63,43 @@ public class ListAppSystemForTreeApi extends PrivateApiComponentBase { @Description(desc = "查询资源应用列表") @Override public Object myDoService(JSONObject paramObj) throws Exception { - List tbodyList = new ArrayList<>(); BasePageVo searchVo = paramObj.toJavaObject(BasePageVo.class); - String keyword = searchVo.getKeyword(); - int count = resourceMapper.getAppSystemIdListCountByKeyword(keyword); - if (count > 0) { - searchVo.setRowNum(count); - List appSystemIdList = resourceMapper.getAppSystemIdListByKeyword(searchVo); - if (CollectionUtils.isEmpty(appSystemIdList)) { - return TableResultUtil.getResult(tbodyList, searchVo); - } - tbodyList = resourceMapper.getAppSystemListByIdList(appSystemIdList); - List hasModuleAppSystemIdList = resourceMapper.getHasModuleAppSystemIdListByAppSystemIdList(appSystemIdList); - if (CollectionUtils.isNotEmpty(hasModuleAppSystemIdList)) { - for (AppSystemVo appSystemVo : tbodyList) { - if (hasModuleAppSystemIdList.contains(appSystemVo.getId())) { - appSystemVo.setIsHasModule(1); - } - } - } - if (StringUtils.isNotEmpty(searchVo.getKeyword())) { - List appModuleList = resourceMapper.getAppModuleListByKeywordAndAppSystemIdList(keyword, appSystemIdList); - if (CollectionUtils.isNotEmpty(appModuleList)) { - Map> appModuleMap = new HashMap<>(); - for (AppModuleVo appModuleVo : appModuleList) { - appModuleMap.computeIfAbsent(appModuleVo.getAppSystemId(), key -> new ArrayList<>()).add(appModuleVo); - } - for (AppSystemVo appSystemVo : tbodyList) { - List appModuleVoList = appModuleMap.get(appSystemVo.getId()); - if (CollectionUtils.isNotEmpty(appModuleVoList)) { - appSystemVo.setAppModuleList(appModuleVoList); - appSystemVo.setIsHasModule(1); - } - } - } - } - } + IResourceCenterDataSource resourceCenterDataSource = ResourceCenterDataSourceFactory.getResourceCenterDataSource(); + List tbodyList = resourceCenterDataSource.getAppSystemListForTree(searchVo); +// String keyword = searchVo.getKeyword(); +// int count = resourceMapper.getAppSystemIdListCountByKeyword(keyword); +// if (count > 0) { +// searchVo.setRowNum(count); +// List appSystemIdList = resourceMapper.getAppSystemIdListByKeyword(searchVo); +// if (CollectionUtils.isEmpty(appSystemIdList)) { +// return TableResultUtil.getResult(tbodyList, searchVo); +// } +// tbodyList = resourceMapper.getAppSystemListByIdList(appSystemIdList); +// List hasModuleAppSystemIdList = resourceMapper.getHasModuleAppSystemIdListByAppSystemIdList(appSystemIdList); +// if (CollectionUtils.isNotEmpty(hasModuleAppSystemIdList)) { +// for (AppSystemVo appSystemVo : tbodyList) { +// if (hasModuleAppSystemIdList.contains(appSystemVo.getId())) { +// appSystemVo.setIsHasModule(1); +// } +// } +// } +// if (StringUtils.isNotEmpty(searchVo.getKeyword())) { +// List appModuleList = resourceMapper.getAppModuleListByKeywordAndAppSystemIdList(keyword, appSystemIdList); +// if (CollectionUtils.isNotEmpty(appModuleList)) { +// Map> appModuleMap = new HashMap<>(); +// for (AppModuleVo appModuleVo : appModuleList) { +// appModuleMap.computeIfAbsent(appModuleVo.getAppSystemId(), key -> new ArrayList<>()).add(appModuleVo); +// } +// for (AppSystemVo appSystemVo : tbodyList) { +// List appModuleVoList = appModuleMap.get(appSystemVo.getId()); +// if (CollectionUtils.isNotEmpty(appModuleVoList)) { +// appSystemVo.setAppModuleList(appModuleVoList); +// appSystemVo.setIsHasModule(1); +// } +// } +// } +// } +// } return TableResultUtil.getResult(tbodyList, searchVo); } } diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/appenv/ListAppEnvForSelectApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/appenv/ListAppEnvForSelectApi.java index ffa53bb7..44006197 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/appenv/ListAppEnvForSelectApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/appenv/ListAppEnvForSelectApi.java @@ -15,23 +15,20 @@ along with this program. If not, see .*/ package neatlogic.module.cmdb.api.resourcecenter.appenv; -import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import neatlogic.framework.auth.core.AuthAction; import neatlogic.framework.cmdb.auth.label.CMDB; import neatlogic.framework.cmdb.dto.resourcecenter.ResourceVo; +import neatlogic.framework.cmdb.resourcecenter.datasource.core.IResourceCenterDataSource; +import neatlogic.framework.cmdb.resourcecenter.datasource.core.ResourceCenterDataSourceFactory; import neatlogic.framework.common.constvalue.ApiParamType; import neatlogic.framework.common.dto.BasePageVo; import neatlogic.framework.restful.annotation.*; import neatlogic.framework.restful.constvalue.OperationTypeEnum; import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; import neatlogic.framework.util.TableResultUtil; -import neatlogic.module.cmdb.dao.mapper.resourcecenter.ResourceMapper; -import org.apache.commons.collections4.CollectionUtils; import org.springframework.stereotype.Service; -import javax.annotation.Resource; -import java.util.ArrayList; import java.util.List; @Service @@ -39,9 +36,6 @@ import java.util.List; @OperationType(type = OperationTypeEnum.SEARCH) public class ListAppEnvForSelectApi extends PrivateApiComponentBase { - @Resource - private ResourceMapper resourceMapper; - @Override public String getToken() { return "resourcecenter/appenv/list/forselect"; @@ -72,36 +66,39 @@ public class ListAppEnvForSelectApi extends PrivateApiComponentBase { @Override public Object myDoService(JSONObject paramObj) throws Exception { BasePageVo searchVo = paramObj.toJavaObject(BasePageVo.class); - JSONArray defaultValue = searchVo.getDefaultValue(); - if (CollectionUtils.isNotEmpty(defaultValue)) { - List idList = defaultValue.toJavaList(Long.class); - List resourceList = resourceMapper.searchAppEnvListByIdList(idList); - return TableResultUtil.getResult(resourceList); - } else { - int rowNum = resourceMapper.searchAppEnvCount(searchVo); - if (rowNum > 0) { - searchVo.setRowNum(rowNum); - if (searchVo.getNeedPage()) { - List idList = resourceMapper.searchAppEnvIdList(searchVo); - if (CollectionUtils.isNotEmpty(idList)) { - List resourceList = resourceMapper.searchAppEnvListByIdList(idList); - return TableResultUtil.getResult(resourceList, searchVo); - } - } else { - List allResourceList = new ArrayList<>(); - int pageCount = searchVo.getPageCount(); - for (int currentPage = 1; currentPage <= pageCount; currentPage++) { - searchVo.setCurrentPage(currentPage); - List idList = resourceMapper.searchAppEnvIdList(searchVo); - if (CollectionUtils.isNotEmpty(idList)) { - List resourceList = resourceMapper.searchAppEnvListByIdList(idList); - allResourceList.addAll(resourceList); - } - } - return TableResultUtil.getResult(allResourceList, searchVo); - } - } - } - return null; + IResourceCenterDataSource resourceCenterDataSource = ResourceCenterDataSourceFactory.getResourceCenterDataSource(); + List tbodyList = resourceCenterDataSource.getAppEnvListForSelect(searchVo); + return TableResultUtil.getResult(tbodyList, searchVo); +// JSONArray defaultValue = searchVo.getDefaultValue(); +// if (CollectionUtils.isNotEmpty(defaultValue)) { +// List idList = defaultValue.toJavaList(Long.class); +// List resourceList = resourceMapper.searchAppEnvListByIdList(idList); +// return TableResultUtil.getResult(resourceList); +// } else { +// int rowNum = resourceMapper.searchAppEnvCount(searchVo); +// if (rowNum > 0) { +// searchVo.setRowNum(rowNum); +// if (searchVo.getNeedPage()) { +// List idList = resourceMapper.searchAppEnvIdList(searchVo); +// if (CollectionUtils.isNotEmpty(idList)) { +// List resourceList = resourceMapper.searchAppEnvListByIdList(idList); +// return TableResultUtil.getResult(resourceList, searchVo); +// } +// } else { +// List allResourceList = new ArrayList<>(); +// int pageCount = searchVo.getPageCount(); +// for (int currentPage = 1; currentPage <= pageCount; currentPage++) { +// searchVo.setCurrentPage(currentPage); +// List idList = resourceMapper.searchAppEnvIdList(searchVo); +// if (CollectionUtils.isNotEmpty(idList)) { +// List resourceList = resourceMapper.searchAppEnvListByIdList(idList); +// allResourceList.addAll(resourceList); +// } +// } +// return TableResultUtil.getResult(allResourceList, searchVo); +// } +// } +// } +// return null; } } diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/appmodule/AppModuleListApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/appmodule/AppModuleListApi.java index 86e1e929..0ea8e89c 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/appmodule/AppModuleListApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/appmodule/AppModuleListApi.java @@ -20,6 +20,8 @@ import neatlogic.framework.auth.core.AuthAction; import neatlogic.framework.cmdb.auth.label.CMDB; import neatlogic.framework.cmdb.dto.resourcecenter.ResourceSearchVo; import neatlogic.framework.cmdb.dto.resourcecenter.ResourceVo; +import neatlogic.framework.cmdb.resourcecenter.datasource.core.IResourceCenterDataSource; +import neatlogic.framework.cmdb.resourcecenter.datasource.core.ResourceCenterDataSourceFactory; import neatlogic.framework.common.constvalue.ApiParamType; import neatlogic.framework.common.dto.BasePageVo; import neatlogic.framework.restful.annotation.*; @@ -30,6 +32,7 @@ import neatlogic.module.cmdb.service.resourcecenter.resource.IResourceCenterReso import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.util.List; /** * @author linbq @@ -73,6 +76,9 @@ public class AppModuleListApi extends PrivateApiComponentBase { @Override public Object myDoService(JSONObject paramObj) throws Exception { ResourceSearchVo searchVo = paramObj.toJavaObject(ResourceSearchVo.class); - return TableResultUtil.getResult(resourceCenterResourceService.getAppModuleList(searchVo), searchVo); + IResourceCenterDataSource resourceCenterDataSource = ResourceCenterDataSourceFactory.getResourceCenterDataSource(); + List tbodyList = resourceCenterDataSource.getAppModuleList(searchVo); + return TableResultUtil.getResult(tbodyList, searchVo); +// return TableResultUtil.getResult(resourceCenterResourceService.getAppModuleList(searchVo), searchVo); } } diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/appmodule/ListAppModuleListForTreeApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/appmodule/ListAppModuleListForTreeApi.java index 6a58ddf2..1a99808f 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/appmodule/ListAppModuleListForTreeApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/appmodule/ListAppModuleListForTreeApi.java @@ -19,27 +19,19 @@ import com.alibaba.fastjson.JSONObject; import neatlogic.framework.auth.core.AuthAction; import neatlogic.framework.cmdb.auth.label.CMDB; import neatlogic.framework.cmdb.dto.resourcecenter.AppModuleVo; +import neatlogic.framework.cmdb.resourcecenter.datasource.core.IResourceCenterDataSource; +import neatlogic.framework.cmdb.resourcecenter.datasource.core.ResourceCenterDataSourceFactory; import neatlogic.framework.common.constvalue.ApiParamType; import neatlogic.framework.restful.annotation.*; import neatlogic.framework.restful.constvalue.OperationTypeEnum; import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; -import neatlogic.module.cmdb.dao.mapper.resourcecenter.ResourceMapper; -import org.apache.commons.collections4.CollectionUtils; import org.springframework.stereotype.Service; -import javax.annotation.Resource; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - @Service @AuthAction(action = CMDB.class) @OperationType(type = OperationTypeEnum.SEARCH) public class ListAppModuleListForTreeApi extends PrivateApiComponentBase { - @Resource - private ResourceMapper resourceMapper; - @Override public String getToken() { return "resourcecenter/appmodule/list/fortree"; @@ -65,26 +57,28 @@ public class ListAppModuleListForTreeApi extends PrivateApiComponentBase { @Override public Object myDoService(JSONObject paramObj) throws Exception { Long appSystemId = paramObj.getLong("appSystemId"); - List tbodyList = resourceMapper.getAppModuleListByAppSystemId(appSystemId); - if (CollectionUtils.isNotEmpty(tbodyList)) { - Map appEnvCountMap = new HashMap<>(); - List> appEnvCountMapList = resourceMapper.getAppEnvCountMapByAppSystemIdGroupByAppModuleId(appSystemId); - for (Map map : appEnvCountMapList) { - Long count = map.get("count"); - Long appModuleId = map.get("appModuleId"); - appEnvCountMap.put(appModuleId, count); - } - for (AppModuleVo appModuleVo : tbodyList) { - Long count = appEnvCountMap.get(appModuleVo.getId()); - if (count == null) { - appModuleVo.setIsHasEnv(0); - } else if (count == 0) { - appModuleVo.setIsHasEnv(0); - } else { - appModuleVo.setIsHasEnv(1); - } - } - } - return tbodyList; + IResourceCenterDataSource resourceCenterDataSource = ResourceCenterDataSourceFactory.getResourceCenterDataSource(); + return resourceCenterDataSource.getAppModuleListForTree(appSystemId); +// List tbodyList = resourceMapper.getAppModuleListByAppSystemId(appSystemId); +// if (CollectionUtils.isNotEmpty(tbodyList)) { +// Map appEnvCountMap = new HashMap<>(); +// List> appEnvCountMapList = resourceMapper.getAppEnvCountMapByAppSystemIdGroupByAppModuleId(appSystemId); +// for (Map map : appEnvCountMapList) { +// Long count = map.get("count"); +// Long appModuleId = map.get("appModuleId"); +// appEnvCountMap.put(appModuleId, count); +// } +// for (AppModuleVo appModuleVo : tbodyList) { +// Long count = appEnvCountMap.get(appModuleVo.getId()); +// if (count == null) { +// appModuleVo.setIsHasEnv(0); +// } else if (count == 0) { +// appModuleVo.setIsHasEnv(0); +// } else { +// appModuleVo.setIsHasEnv(1); +// } +// } +// } +// return tbodyList; } } diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/state/ListStateForSelectApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/state/ListStateForSelectApi.java index 03bc5876..87b110e2 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/state/ListStateForSelectApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/state/ListStateForSelectApi.java @@ -15,23 +15,20 @@ along with this program. If not, see .*/ package neatlogic.module.cmdb.api.resourcecenter.state; -import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import neatlogic.framework.auth.core.AuthAction; import neatlogic.framework.cmdb.auth.label.CMDB; import neatlogic.framework.cmdb.dto.resourcecenter.ResourceVo; +import neatlogic.framework.cmdb.resourcecenter.datasource.core.IResourceCenterDataSource; +import neatlogic.framework.cmdb.resourcecenter.datasource.core.ResourceCenterDataSourceFactory; import neatlogic.framework.common.constvalue.ApiParamType; import neatlogic.framework.common.dto.BasePageVo; import neatlogic.framework.restful.annotation.*; import neatlogic.framework.restful.constvalue.OperationTypeEnum; import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; import neatlogic.framework.util.TableResultUtil; -import neatlogic.module.cmdb.dao.mapper.resourcecenter.ResourceMapper; -import org.apache.commons.collections4.CollectionUtils; import org.springframework.stereotype.Service; -import javax.annotation.Resource; -import java.util.ArrayList; import java.util.List; @Service @@ -39,9 +36,6 @@ import java.util.List; @OperationType(type = OperationTypeEnum.SEARCH) public class ListStateForSelectApi extends PrivateApiComponentBase { - @Resource - private ResourceMapper resourceMapper; - @Override public String getToken() { return "resourcecenter/state/list/forselect"; @@ -71,32 +65,35 @@ public class ListStateForSelectApi extends PrivateApiComponentBase { @Override public Object myDoService(JSONObject paramObj) throws Exception { BasePageVo searchVo = paramObj.toJavaObject(BasePageVo.class); - JSONArray defaultValue = searchVo.getDefaultValue(); - if (CollectionUtils.isNotEmpty(defaultValue)) { - List idList = defaultValue.toJavaList(Long.class); - List resourceList = resourceMapper.searchStateListByIdList(idList); - return TableResultUtil.getResult(resourceList); - } else { - int rowNum = resourceMapper.searchStateCount(searchVo); - if (rowNum > 0) { - searchVo.setRowNum(rowNum); - if (searchVo.getNeedPage()) { - List idList = resourceMapper.searchStateIdList(searchVo); - List resourceList = resourceMapper.searchStateListByIdList(idList); - return TableResultUtil.getResult(resourceList, searchVo); - } else { - List allResourceList = new ArrayList<>(); - int pageCount = searchVo.getPageCount(); - for (int currentPage = 1; currentPage <= pageCount; currentPage++) { - searchVo.setCurrentPage(currentPage); - List idList = resourceMapper.searchStateIdList(searchVo); - List resourceList = resourceMapper.searchStateListByIdList(idList); - allResourceList.addAll(resourceList); - } - return TableResultUtil.getResult(allResourceList, searchVo); - } - } - } - return null; + IResourceCenterDataSource resourceCenterDataSource = ResourceCenterDataSourceFactory.getResourceCenterDataSource(); + List tbodyList = resourceCenterDataSource.getStateListForSelect(searchVo); + return TableResultUtil.getResult(tbodyList, searchVo); +// JSONArray defaultValue = searchVo.getDefaultValue(); +// if (CollectionUtils.isNotEmpty(defaultValue)) { +// List idList = defaultValue.toJavaList(Long.class); +// List resourceList = resourceMapper.searchStateListByIdList(idList); +// return TableResultUtil.getResult(resourceList); +// } else { +// int rowNum = resourceMapper.searchStateCount(searchVo); +// if (rowNum > 0) { +// searchVo.setRowNum(rowNum); +// if (searchVo.getNeedPage()) { +// List idList = resourceMapper.searchStateIdList(searchVo); +// List resourceList = resourceMapper.searchStateListByIdList(idList); +// return TableResultUtil.getResult(resourceList, searchVo); +// } else { +// List allResourceList = new ArrayList<>(); +// int pageCount = searchVo.getPageCount(); +// for (int currentPage = 1; currentPage <= pageCount; currentPage++) { +// searchVo.setCurrentPage(currentPage); +// List idList = resourceMapper.searchStateIdList(searchVo); +// List resourceList = resourceMapper.searchStateListByIdList(idList); +// allResourceList.addAll(resourceList); +// } +// return TableResultUtil.getResult(allResourceList, searchVo); +// } +// } +// } +// return null; } } diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/vendor/ListVendorForSelectApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/vendor/ListVendorForSelectApi.java index b5989ec8..274852f1 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/vendor/ListVendorForSelectApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/vendor/ListVendorForSelectApi.java @@ -15,23 +15,20 @@ along with this program. If not, see .*/ package neatlogic.module.cmdb.api.resourcecenter.vendor; -import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import neatlogic.framework.auth.core.AuthAction; import neatlogic.framework.cmdb.auth.label.CMDB; import neatlogic.framework.cmdb.dto.resourcecenter.ResourceVo; +import neatlogic.framework.cmdb.resourcecenter.datasource.core.IResourceCenterDataSource; +import neatlogic.framework.cmdb.resourcecenter.datasource.core.ResourceCenterDataSourceFactory; import neatlogic.framework.common.constvalue.ApiParamType; import neatlogic.framework.common.dto.BasePageVo; import neatlogic.framework.restful.annotation.*; import neatlogic.framework.restful.constvalue.OperationTypeEnum; import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; import neatlogic.framework.util.TableResultUtil; -import neatlogic.module.cmdb.dao.mapper.resourcecenter.ResourceMapper; -import org.apache.commons.collections4.CollectionUtils; import org.springframework.stereotype.Service; -import javax.annotation.Resource; -import java.util.ArrayList; import java.util.List; @Service @@ -39,9 +36,6 @@ import java.util.List; @OperationType(type = OperationTypeEnum.SEARCH) public class ListVendorForSelectApi extends PrivateApiComponentBase { - @Resource - private ResourceMapper resourceMapper; - @Override public String getToken() { return "resourcecenter/vendor/list/forselect"; @@ -71,32 +65,35 @@ public class ListVendorForSelectApi extends PrivateApiComponentBase { @Override public Object myDoService(JSONObject paramObj) throws Exception { BasePageVo searchVo = paramObj.toJavaObject(BasePageVo.class); - JSONArray defaultValue = searchVo.getDefaultValue(); - if (CollectionUtils.isNotEmpty(defaultValue)) { - List idList = defaultValue.toJavaList(Long.class); - List resourceList = resourceMapper.searchVendorListByIdList(idList); - return TableResultUtil.getResult(resourceList); - } else { - int rowNum = resourceMapper.searchVendorCount(searchVo); - if (rowNum > 0) { - searchVo.setRowNum(rowNum); - if (searchVo.getNeedPage()) { - List idList = resourceMapper.searchVendorIdList(searchVo); - List resourceList = resourceMapper.searchVendorListByIdList(idList); - return TableResultUtil.getResult(resourceList, searchVo); - } else { - List allResourceList = new ArrayList<>(); - int pageCount = searchVo.getPageCount(); - for (int currentPage = 1; currentPage <= pageCount; currentPage++) { - searchVo.setCurrentPage(currentPage); - List idList = resourceMapper.searchVendorIdList(searchVo); - List resourceList = resourceMapper.searchVendorListByIdList(idList); - allResourceList.addAll(resourceList); - } - return TableResultUtil.getResult(allResourceList, searchVo); - } - } - } - return null; + IResourceCenterDataSource resourceCenterDataSource = ResourceCenterDataSourceFactory.getResourceCenterDataSource(); + List tbodyList = resourceCenterDataSource.getVendorListForSelect(searchVo); + return TableResultUtil.getResult(tbodyList, searchVo); +// JSONArray defaultValue = searchVo.getDefaultValue(); +// if (CollectionUtils.isNotEmpty(defaultValue)) { +// List idList = defaultValue.toJavaList(Long.class); +// List resourceList = resourceMapper.searchVendorListByIdList(idList); +// return TableResultUtil.getResult(resourceList); +// } else { +// int rowNum = resourceMapper.searchVendorCount(searchVo); +// if (rowNum > 0) { +// searchVo.setRowNum(rowNum); +// if (searchVo.getNeedPage()) { +// List idList = resourceMapper.searchVendorIdList(searchVo); +// List resourceList = resourceMapper.searchVendorListByIdList(idList); +// return TableResultUtil.getResult(resourceList, searchVo); +// } else { +// List allResourceList = new ArrayList<>(); +// int pageCount = searchVo.getPageCount(); +// for (int currentPage = 1; currentPage <= pageCount; currentPage++) { +// searchVo.setCurrentPage(currentPage); +// List idList = resourceMapper.searchVendorIdList(searchVo); +// List resourceList = resourceMapper.searchVendorListByIdList(idList); +// allResourceList.addAll(resourceList); +// } +// return TableResultUtil.getResult(allResourceList, searchVo); +// } +// } +// } +// return null; } } diff --git a/src/main/java/neatlogic/module/cmdb/resourcecenter/datasource/handler/DefaultResourceCenterDataSourceImpl.java b/src/main/java/neatlogic/module/cmdb/resourcecenter/datasource/handler/DefaultResourceCenterDataSourceImpl.java index d8a571df..2f0a30b6 100644 --- a/src/main/java/neatlogic/module/cmdb/resourcecenter/datasource/handler/DefaultResourceCenterDataSourceImpl.java +++ b/src/main/java/neatlogic/module/cmdb/resourcecenter/datasource/handler/DefaultResourceCenterDataSourceImpl.java @@ -21,10 +21,7 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import neatlogic.framework.asynchronization.threadlocal.UserContext; import neatlogic.framework.cmdb.dto.ci.CiVo; -import neatlogic.framework.cmdb.dto.resourcecenter.ApplicationListDisplayVo; -import neatlogic.framework.cmdb.dto.resourcecenter.ResourceSearchVo; -import neatlogic.framework.cmdb.dto.resourcecenter.ResourceTypeVo; -import neatlogic.framework.cmdb.dto.resourcecenter.ResourceVo; +import neatlogic.framework.cmdb.dto.resourcecenter.*; import neatlogic.framework.cmdb.dto.resourcecenter.config.ResourceEntityConfigVo; import neatlogic.framework.cmdb.dto.resourcecenter.config.ResourceEntityVo; import neatlogic.framework.cmdb.exception.ci.CiNotFoundException; @@ -32,6 +29,7 @@ import neatlogic.framework.cmdb.exception.resourcecenter.AppModuleNotFoundExcept import neatlogic.framework.cmdb.exception.resourcecenter.AppSystemNotFoundException; import neatlogic.framework.cmdb.resourcecenter.datasource.core.IResourceCenterDataSource; import neatlogic.framework.cmdb.resourcecenter.datasource.core.Ordered; +import neatlogic.framework.common.dto.BasePageVo; import neatlogic.framework.common.dto.ValueTextVo; import neatlogic.framework.util.TableResultUtil; import neatlogic.module.cmdb.dao.mapper.ci.CiMapper; @@ -414,6 +412,200 @@ public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataS return theadList; } + @Override + public List getAppSystemListForTree(BasePageVo searchVo) { + List appSystemList = new ArrayList<>(); + String keyword = searchVo.getKeyword(); + int count = resourceMapper.getAppSystemIdListCountByKeyword(keyword); + if (count > 0) { + searchVo.setRowNum(count); + List appSystemIdList = resourceMapper.getAppSystemIdListByKeyword(searchVo); + if (CollectionUtils.isEmpty(appSystemIdList)) { + return appSystemList; + } + appSystemList = resourceMapper.getAppSystemListByIdList(appSystemIdList); + List hasModuleAppSystemIdList = resourceMapper.getHasModuleAppSystemIdListByAppSystemIdList(appSystemIdList); + if (CollectionUtils.isNotEmpty(hasModuleAppSystemIdList)) { + for (AppSystemVo appSystemVo : appSystemList) { + if (hasModuleAppSystemIdList.contains(appSystemVo.getId())) { + appSystemVo.setIsHasModule(1); + } + } + } + if (StringUtils.isNotEmpty(keyword)) { + List appModuleList = resourceMapper.getAppModuleListByKeywordAndAppSystemIdList(keyword, appSystemIdList); + if (CollectionUtils.isNotEmpty(appModuleList)) { + Map> appModuleMap = new HashMap<>(); + for (AppModuleVo appModuleVo : appModuleList) { + appModuleMap.computeIfAbsent(appModuleVo.getAppSystemId(), key -> new ArrayList<>()).add(appModuleVo); + } + for (AppSystemVo appSystemVo : appSystemList) { + List appModuleVoList = appModuleMap.get(appSystemVo.getId()); + if (CollectionUtils.isNotEmpty(appModuleVoList)) { + appSystemVo.setAppModuleList(appModuleVoList); + appSystemVo.setIsHasModule(1); + } + } + } + } + } + return appSystemList; + } + + @Override + public List getAppSystemListForSelect(BasePageVo searchVo) { + List resourceList = new ArrayList<>(); + JSONArray defaultValue = searchVo.getDefaultValue(); + if (CollectionUtils.isNotEmpty(defaultValue)) { + List idList = defaultValue.toJavaList(Long.class); + resourceList = resourceMapper.searchAppSystemListByIdList(idList); + } else { + int rowNum = resourceMapper.searchAppSystemCount(searchVo); + if (rowNum > 0) { + searchVo.setRowNum(rowNum); + if (searchVo.getNeedPage()) { + List idList = resourceMapper.searchAppSystemIdList(searchVo); + resourceList = resourceMapper.searchAppSystemListByIdList(idList); + } else { + int pageCount = searchVo.getPageCount(); + for (int currentPage = 1; currentPage <= pageCount; currentPage++) { + searchVo.setCurrentPage(currentPage); + List idList = resourceMapper.searchAppSystemIdList(searchVo); + List list = resourceMapper.searchAppSystemListByIdList(idList); + resourceList.addAll(list); + } + } + } + } + return resourceList; + } + + @Override + public List getAppModuleListForTree(Long appSystemId) { + List appModuleList = resourceMapper.getAppModuleListByAppSystemId(appSystemId); + if (CollectionUtils.isNotEmpty(appModuleList)) { + Map appEnvCountMap = new HashMap<>(); + List> appEnvCountMapList = resourceMapper.getAppEnvCountMapByAppSystemIdGroupByAppModuleId(appSystemId); + for (Map map : appEnvCountMapList) { + Long count = map.get("count"); + Long appModuleId = map.get("appModuleId"); + appEnvCountMap.put(appModuleId, count); + } + for (AppModuleVo appModuleVo : appModuleList) { + Long count = appEnvCountMap.get(appModuleVo.getId()); + if (count == null) { + appModuleVo.setIsHasEnv(0); + } else if (count == 0) { + appModuleVo.setIsHasEnv(0); + } else { + appModuleVo.setIsHasEnv(1); + } + } + } + return appModuleList; + } + + @Override + public List getAppModuleList(ResourceSearchVo searchVo) { + int count = resourceMapper.searchAppModuleCount(searchVo); + if (count > 0) { + searchVo.setRowNum(count); + List idList = resourceMapper.searchAppModuleIdList(searchVo); + if (CollectionUtils.isNotEmpty(idList)) { + return resourceMapper.searchAppModule(idList); + } + } + return new ArrayList<>(); + } + + @Override + public List getAppEnvListForSelect(BasePageVo searchVo) { + List appEnvList = new ArrayList<>(); + JSONArray defaultValue = searchVo.getDefaultValue(); + if (CollectionUtils.isNotEmpty(defaultValue)) { + List idList = defaultValue.toJavaList(Long.class); + appEnvList = resourceMapper.searchAppEnvListByIdList(idList); + } else { + int rowNum = resourceMapper.searchAppEnvCount(searchVo); + if (rowNum > 0) { + searchVo.setRowNum(rowNum); + if (searchVo.getNeedPage()) { + List idList = resourceMapper.searchAppEnvIdList(searchVo); + if (CollectionUtils.isNotEmpty(idList)) { + appEnvList = resourceMapper.searchAppEnvListByIdList(idList); + } + } else { + int pageCount = searchVo.getPageCount(); + for (int currentPage = 1; currentPage <= pageCount; currentPage++) { + searchVo.setCurrentPage(currentPage); + List idList = resourceMapper.searchAppEnvIdList(searchVo); + if (CollectionUtils.isNotEmpty(idList)) { + List list = resourceMapper.searchAppEnvListByIdList(idList); + appEnvList.addAll(list); + } + } + } + } + } + return appEnvList; + } + + @Override + public List getStateListForSelect(BasePageVo searchVo) { + List stateList = new ArrayList<>(); + JSONArray defaultValue = searchVo.getDefaultValue(); + if (CollectionUtils.isNotEmpty(defaultValue)) { + List idList = defaultValue.toJavaList(Long.class); + stateList = resourceMapper.searchStateListByIdList(idList); + } else { + int rowNum = resourceMapper.searchStateCount(searchVo); + if (rowNum > 0) { + searchVo.setRowNum(rowNum); + if (searchVo.getNeedPage()) { + List idList = resourceMapper.searchStateIdList(searchVo); + stateList = resourceMapper.searchStateListByIdList(idList); + } else { + int pageCount = searchVo.getPageCount(); + for (int currentPage = 1; currentPage <= pageCount; currentPage++) { + searchVo.setCurrentPage(currentPage); + List idList = resourceMapper.searchStateIdList(searchVo); + List list = resourceMapper.searchStateListByIdList(idList); + stateList.addAll(list); + } + } + } + } + return stateList; + } + + @Override + public List getVendorListForSelect(BasePageVo searchVo) { + List vendorList = new ArrayList<>(); + JSONArray defaultValue = searchVo.getDefaultValue(); + if (CollectionUtils.isNotEmpty(defaultValue)) { + List idList = defaultValue.toJavaList(Long.class); + vendorList = resourceMapper.searchVendorListByIdList(idList); + } else { + int rowNum = resourceMapper.searchVendorCount(searchVo); + if (rowNum > 0) { + searchVo.setRowNum(rowNum); + if (searchVo.getNeedPage()) { + List idList = resourceMapper.searchVendorIdList(searchVo); + vendorList = resourceMapper.searchVendorListByIdList(idList); + } else { + int pageCount = searchVo.getPageCount(); + for (int currentPage = 1; currentPage <= pageCount; currentPage++) { + searchVo.setCurrentPage(currentPage); + List idList = resourceMapper.searchVendorIdList(searchVo); + List list = resourceMapper.searchVendorListByIdList(idList); + vendorList.addAll(list); + } + } + } + } + return vendorList; + } + /** * 判断是否有过滤条件 * @param searchVo diff --git a/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/IResourceCenterResourceService.java b/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/IResourceCenterResourceService.java index 73fd13bb..523bb6eb 100644 --- a/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/IResourceCenterResourceService.java +++ b/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/IResourceCenterResourceService.java @@ -132,7 +132,7 @@ public interface IResourceCenterResourceService extends IResourceCenterResourceC * @param searchVo resourceSearchVo * @return 模块列表 */ - List getAppModuleList(ResourceSearchVo searchVo); +// List getAppModuleList(ResourceSearchVo searchVo); /** diff --git a/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java b/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java index 8ff882ba..3e515cb1 100644 --- a/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java +++ b/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java @@ -601,18 +601,18 @@ public class ResourceCenterResourceServiceImpl implements IResourceCenterResourc } } - @Override - public List getAppModuleList(ResourceSearchVo searchVo) { - int count = resourceMapper.searchAppModuleCount(searchVo); - if (count > 0) { - searchVo.setRowNum(count); - List idList = resourceMapper.searchAppModuleIdList(searchVo); - if (CollectionUtils.isNotEmpty(idList)) { - return resourceMapper.searchAppModule(idList); - } - } - return new ArrayList<>(); - } +// @Override +// public List getAppModuleList(ResourceSearchVo searchVo) { +// int count = resourceMapper.searchAppModuleCount(searchVo); +// if (count > 0) { +// searchVo.setRowNum(count); +// List idList = resourceMapper.searchAppModuleIdList(searchVo); +// if (CollectionUtils.isNotEmpty(idList)) { +// return resourceMapper.searchAppModule(idList); +// } +// } +// return new ArrayList<>(); +// } @Override public Collection getAppEnvList(ResourceSearchVo searchVo) { -- Gitee From 84f80529047983640aacb68bd2786f222fa98369 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Mon, 24 Feb 2025 14:18:44 +0800 Subject: [PATCH 10/29] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20CMDB=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E6=B8=85=E5=8D=95=E6=94=B9=E6=88=90=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E5=B1=82=E7=BA=A7=E5=8F=AF=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1349157963399168]CMDB应用清单改成模型层级可配置 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1349157963399168 --- .../resourcecenter/config/SaveResourceEntityApi.java | 10 +++++----- .../handler/DefaultResourceCenterDataSourceImpl.java | 2 +- .../resource/ResourceCenterResourceServiceImpl.java | 1 + 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/SaveResourceEntityApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/SaveResourceEntityApi.java index b02b91f2..f2ee3da5 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/SaveResourceEntityApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/SaveResourceEntityApi.java @@ -40,7 +40,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; -import java.util.Objects; /** * @author linbq @@ -100,16 +99,17 @@ public class SaveResourceEntityApi extends PrivateApiComponentBase { boolean configEquals = false; ResourceEntityVo oldResourceEntityVo = resourceEntityMapper.getResourceEntityByName(resourceEntityVo.getName()); if (oldResourceEntityVo != null) { - configEquals = Objects.equals(resourceEntityVo.getConfigStr(), oldResourceEntityVo.getConfigStr()); - if (configEquals) { - return null; - } +// configEquals = Objects.equals(resourceEntityVo.getConfigStr(), oldResourceEntityVo.getConfigStr()); +// if (configEquals) { +// return null; +// } resourceEntityMapper.updateResourceEntityLabelAndDescription(resourceEntityVo); } else { resourceEntityVo.setStatus(Status.PENDING.getValue()); resourceEntityMapper.insertResourceEntity(resourceEntityVo); } if (!configEquals) { + resourceEntityVo.setError(null); String sql = resourceCenterResourceService.buildResourceView(resourceEntityVo); // resourceEntityVo.setError(error); if (StringUtils.isNotBlank(resourceEntityVo.getError())) { diff --git a/src/main/java/neatlogic/module/cmdb/resourcecenter/datasource/handler/DefaultResourceCenterDataSourceImpl.java b/src/main/java/neatlogic/module/cmdb/resourcecenter/datasource/handler/DefaultResourceCenterDataSourceImpl.java index 2f0a30b6..b2d38474 100644 --- a/src/main/java/neatlogic/module/cmdb/resourcecenter/datasource/handler/DefaultResourceCenterDataSourceImpl.java +++ b/src/main/java/neatlogic/module/cmdb/resourcecenter/datasource/handler/DefaultResourceCenterDataSourceImpl.java @@ -390,7 +390,7 @@ public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataS @Override public JSONArray getTheadList(List fieldNameList) { JSONArray theadList = new JSONArray(); - if (CollectionUtils.isNotEmpty(fieldNameList)) { + if (CollectionUtils.isEmpty(fieldNameList)) { fieldNameList = ResourceEntityFactory.getFieldNameListByViewName("scence_ipobject_detail"); } if (CollectionUtils.isNotEmpty(fieldNameList)) { diff --git a/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java b/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java index 3e515cb1..2fb4f69c 100644 --- a/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java +++ b/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java @@ -727,6 +727,7 @@ public class ResourceCenterResourceServiceImpl implements IResourceCenterResourc // builder.buildView(); // } String config = resourceEntityMapper.getResourceEntityConfigByName(resourceEntityVo.getName()); + resourceEntityVo.setError(null); resourceEntityVo.setConfigStr(config); String sql = buildResourceView(resourceEntityVo); // resourceEntityVo.setError(error); -- Gitee From 600f0823ac5552a62410c8f9906d15908f2ded7b Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Mon, 24 Feb 2025 14:19:30 +0800 Subject: [PATCH 11/29] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20CMDB=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E6=B8=85=E5=8D=95=E6=94=B9=E6=88=90=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E5=B1=82=E7=BA=A7=E5=8F=AF=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1349157963399168]CMDB应用清单改成模型层级可配置 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1349157963399168 --- .../api/resourcecenter/config/SaveResourceEntityApi.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/SaveResourceEntityApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/SaveResourceEntityApi.java index f2ee3da5..bb48bc50 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/SaveResourceEntityApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/SaveResourceEntityApi.java @@ -40,6 +40,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.util.Objects; /** * @author linbq @@ -99,10 +100,10 @@ public class SaveResourceEntityApi extends PrivateApiComponentBase { boolean configEquals = false; ResourceEntityVo oldResourceEntityVo = resourceEntityMapper.getResourceEntityByName(resourceEntityVo.getName()); if (oldResourceEntityVo != null) { -// configEquals = Objects.equals(resourceEntityVo.getConfigStr(), oldResourceEntityVo.getConfigStr()); -// if (configEquals) { -// return null; -// } + configEquals = Objects.equals(resourceEntityVo.getConfigStr(), oldResourceEntityVo.getConfigStr()); + if (configEquals) { + return null; + } resourceEntityMapper.updateResourceEntityLabelAndDescription(resourceEntityVo); } else { resourceEntityVo.setStatus(Status.PENDING.getValue()); -- Gitee From 5380070c526dbd8dfd0a18a09a1459ed8e29d1ba Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Tue, 11 Mar 2025 18:47:45 +0800 Subject: [PATCH 12/29] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20CMDB=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E6=B8=85=E5=8D=95=E6=94=B9=E6=88=90=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E5=B1=82=E7=BA=A7=E5=8F=AF=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1349157963399168]CMDB应用清单改成模型层级可配置 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1349157963399168 --- .../config/GetResourceEntityApi.java | 38 ++++++-- .../config/ListResourceEntityApi.java | 32 +++++++ .../ListSupportMultipleViewSceneTemplate.java | 89 +++++++++++++++++++ .../config/SaveResourceEntityApi.java | 50 ++++++++--- .../getResourceEntityViewDataListApi.java | 15 ++++ .../resourcecenter/ResourceEntityMapper.java | 2 + .../resourcecenter/ResourceEntityMapper.xml | 7 +- .../handler/ResourceViewRebuildHandler.java | 85 +++++++++++++++--- .../ResourceCenterResourceServiceImpl.java | 13 ++- .../cmdb/utils/ResourceEntityFactory.java | 30 +++++-- 10 files changed, 316 insertions(+), 45 deletions(-) create mode 100644 src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/ListSupportMultipleViewSceneTemplate.java diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/GetResourceEntityApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/GetResourceEntityApi.java index e46ca9a2..6cb2df9c 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/GetResourceEntityApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/GetResourceEntityApi.java @@ -33,6 +33,7 @@ import neatlogic.framework.util.UuidUtil; import neatlogic.module.cmdb.dao.mapper.ci.CiMapper; import neatlogic.module.cmdb.dao.mapper.resourcecenter.ResourceEntityMapper; import neatlogic.module.cmdb.utils.ResourceEntityFactory; +import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -77,13 +78,17 @@ public class GetResourceEntityApi extends PrivateApiComponentBase { public Object myDoService(JSONObject paramObj) throws Exception { String name = paramObj.getString("name"); SceneEntityVo sceneEntityVo = ResourceEntityFactory.getSceneEntityByViewName(name); - if (sceneEntityVo == null) { - throw new ResourceCenterResourceFoundException(name); - } +// if (sceneEntityVo == null) { +// throw new ResourceCenterResourceFoundException(name); +// } ResourceEntityVo resourceEntityVo = resourceEntityMapper.getResourceEntityByName(name); if (resourceEntityVo == null) { - resourceEntityVo = new ResourceEntityVo(); - resourceEntityVo.setName(sceneEntityVo.getName()); + if (sceneEntityVo != null) { + resourceEntityVo = new ResourceEntityVo(); + resourceEntityVo.setName(sceneEntityVo.getName()); + } else { + throw new ResourceCenterResourceFoundException(name); + } } else if (resourceEntityVo.getCiId() != null) { CiVo ciVo = ciMapper.getCiById(resourceEntityVo.getCiId()); if (ciVo != null) { @@ -101,10 +106,25 @@ public class GetResourceEntityApi extends PrivateApiComponentBase { } } } - resourceEntityVo.setLabel(sceneEntityVo.getLabel()); - resourceEntityVo.setDescription(sceneEntityVo.getDescription()); - List fieldList = ResourceEntityFactory.getFieldListByViewName(name); - resourceEntityVo.setFieldList(fieldList); + if (sceneEntityVo != null) { + resourceEntityVo.setLabel(sceneEntityVo.getLabel()); + resourceEntityVo.setDescription(sceneEntityVo.getDescription()); + List fieldList = ResourceEntityFactory.getFieldListByViewName(name); + resourceEntityVo.setFieldList(fieldList); + } else { + ResourceEntityConfigVo config = resourceEntityVo.getConfig(); + if (config != null) { + String sceneTemplateName = config.getSceneTemplateName(); + if (StringUtils.isNotBlank(sceneTemplateName)) { + SceneEntityVo sceneTemplate = ResourceEntityFactory.getSceneEntityByViewName(sceneTemplateName); + if (sceneTemplate == null) { + throw new ResourceCenterResourceFoundException(sceneTemplateName); + } + List fieldList = ResourceEntityFactory.getFieldListByViewName(sceneTemplateName); + resourceEntityVo.setFieldList(fieldList); + } + } + } return resourceEntityVo; } } diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/ListResourceEntityApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/ListResourceEntityApi.java index 97ce8306..62219807 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/ListResourceEntityApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/ListResourceEntityApi.java @@ -18,6 +18,7 @@ package neatlogic.module.cmdb.api.resourcecenter.config; import com.alibaba.fastjson.JSONObject; import neatlogic.framework.auth.core.AuthAction; import neatlogic.framework.cmdb.auth.label.RESOURCECENTER_MODIFY; +import neatlogic.framework.cmdb.dto.resourcecenter.config.ResourceEntityConfigVo; import neatlogic.framework.cmdb.dto.resourcecenter.config.ResourceEntityVo; import neatlogic.framework.cmdb.dto.resourcecenter.config.SceneEntityVo; import neatlogic.framework.cmdb.enums.resourcecenter.Status; @@ -98,6 +99,37 @@ public class ListResourceEntityApi extends PrivateApiComponentBase { } resultList.add(resourceEntityVo); } + // 扩展视图 + List allResourceEntityList = resourceEntityMapper.getResourceEntityList(); + for (ResourceEntityVo resourceEntityVo : allResourceEntityList) { + SceneEntityVo sceneEntityVo = ResourceEntityFactory.getSceneEntityByViewName(resourceEntityVo.getName()); + if (sceneEntityVo == null) { + String config = resourceEntityMapper.getResourceEntityConfigByName(resourceEntityVo.getName()); + if (StringUtils.isNotBlank(config)) { + ResourceEntityConfigVo resourceEntityConfigVo = JSONObject.parseObject(config, ResourceEntityConfigVo.class); + if (resourceEntityConfigVo != null) { + String sceneTemplateName = resourceEntityConfigVo.getSceneTemplateName(); + if (StringUtils.isNotBlank(sceneTemplateName)) { + SceneEntityVo sceneTemplate = ResourceEntityFactory.getSceneEntityByViewName(sceneTemplateName); + if (sceneTemplate != null) { + try { + resourceEntityMapper.getResourceEntityViewDataList(resourceEntityVo.getName(), 0, 1); + } catch (Exception e) { + resourceEntityVo.setStatus(Status.ERROR.getValue()); + String error = resourceEntityVo.getError(); + if (StringUtils.isNotBlank(error)) { + resourceEntityVo.setError(error + e.getMessage()); + } else { + resourceEntityVo.setError(e.getMessage()); + } + } + resultList.add(resourceEntityVo); + } + } + } + } + } + } return resultList; } } diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/ListSupportMultipleViewSceneTemplate.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/ListSupportMultipleViewSceneTemplate.java new file mode 100644 index 00000000..5e227312 --- /dev/null +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/ListSupportMultipleViewSceneTemplate.java @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2025 深圳极向量科技有限公司 All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package neatlogic.module.cmdb.api.resourcecenter.config; + +import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.auth.core.AuthAction; +import neatlogic.framework.cmdb.auth.label.RESOURCECENTER_MODIFY; +import neatlogic.framework.cmdb.dto.resourcecenter.config.ResourceEntityVo; +import neatlogic.framework.cmdb.dto.resourcecenter.config.SceneEntityVo; +import neatlogic.framework.common.constvalue.ApiParamType; +import neatlogic.framework.common.dto.BasePageVo; +import neatlogic.framework.common.dto.ValueTextVo; +import neatlogic.framework.common.util.PageUtil; +import neatlogic.framework.restful.annotation.*; +import neatlogic.framework.restful.constvalue.OperationTypeEnum; +import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; +import neatlogic.framework.util.TableResultUtil; +import neatlogic.module.cmdb.utils.ResourceEntityFactory; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; + +@Service +@AuthAction(action = RESOURCECENTER_MODIFY.class) +@OperationType(type = OperationTypeEnum.SEARCH) +public class ListSupportMultipleViewSceneTemplate extends PrivateApiComponentBase { + @Override + public String getName() { + return "资源中心支持创建多张视图的场景模板列表"; + } + + @Input({ + @Param(name = "keyword", type = ApiParamType.STRING, desc = "common.keyword"), + @Param(name = "currentPage", type = ApiParamType.INTEGER, defaultValue = "1", desc = "common.currentpage"), + @Param(name = "pageSize", type = ApiParamType.INTEGER, defaultValue = "20", desc = "common.pagesize") + }) + @Output({ + @Param(name = "tbodyList", explode = ResourceEntityVo[].class, desc = "common.tbodylist") + }) + @Description(desc = "资源中心支持创建多张视图的场景模板列表") + @Override + public Object myDoService(JSONObject paramObj) throws Exception { + BasePageVo basePageVo = paramObj.toJavaObject(BasePageVo.class); + List tbodyList = new ArrayList<>(); + List sceneEntityList = ResourceEntityFactory.getMultipleSceneEntityList(); + if (CollectionUtils.isNotEmpty(sceneEntityList)) { + String keyword = basePageVo.getKeyword(); + for (SceneEntityVo sceneEntityVo : sceneEntityList) { + if (StringUtils.isNotBlank(keyword)) { + if (!sceneEntityVo.getName().contains(keyword) && !sceneEntityVo.getLabel().contains(keyword)) { + continue; + } + } + ResourceEntityVo resourceEntityVo = new ResourceEntityVo(); + resourceEntityVo.setName(sceneEntityVo.getName()); + resourceEntityVo.setLabel(sceneEntityVo.getLabel()); + List fieldList = ResourceEntityFactory.getFieldListByViewName(sceneEntityVo.getName()); + resourceEntityVo.setFieldList(fieldList); + tbodyList.add(resourceEntityVo); + } + basePageVo.setRowNum(tbodyList.size()); + tbodyList = PageUtil.subList(tbodyList, basePageVo); + } + return TableResultUtil.getResult(tbodyList, basePageVo); + } + + @Override + public String getToken() { + return "resourcecenter/suportmultipleview/scenetemplate"; + } +} diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/SaveResourceEntityApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/SaveResourceEntityApi.java index bb48bc50..63800b73 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/SaveResourceEntityApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/SaveResourceEntityApi.java @@ -23,13 +23,15 @@ import neatlogic.framework.cmdb.dto.resourcecenter.config.ResourceEntityConfigVo import neatlogic.framework.cmdb.dto.resourcecenter.config.ResourceEntityVo; import neatlogic.framework.cmdb.dto.resourcecenter.config.SceneEntityVo; import neatlogic.framework.cmdb.enums.resourcecenter.Status; -import neatlogic.framework.cmdb.exception.resourcecenter.ResourceCenterResourceFoundException; +import neatlogic.framework.cmdb.exception.resourcecenter.ResourceEntityNameRepeatException; import neatlogic.framework.common.constvalue.ApiParamType; +import neatlogic.framework.dto.FieldValidResultVo; import neatlogic.framework.restful.annotation.Description; import neatlogic.framework.restful.annotation.Input; import neatlogic.framework.restful.annotation.OperationType; import neatlogic.framework.restful.annotation.Param; import neatlogic.framework.restful.constvalue.OperationTypeEnum; +import neatlogic.framework.restful.core.IValid; import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; import neatlogic.module.cmdb.dao.mapper.ci.CiMapper; import neatlogic.module.cmdb.dao.mapper.resourcecenter.ResourceEntityMapper; @@ -40,7 +42,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; -import java.util.Objects; /** * @author linbq @@ -82,28 +83,38 @@ public class SaveResourceEntityApi extends PrivateApiComponentBase { @Description(desc = "nmcarc.saveresourceentityapi.getname") @Override public Object myDoService(JSONObject paramObj) throws Exception { - ResourceEntityVo resourceEntityVo = paramObj.toJavaObject(ResourceEntityVo.class); + String name = paramObj.getString("name"); + String label = paramObj.getString("label"); + String configStr = paramObj.getString("config"); + ResourceEntityVo resourceEntityVo = new ResourceEntityVo(); + resourceEntityVo.setName(name); + resourceEntityVo.setLabel(label); + resourceEntityVo.setConfigStr(configStr); +// ResourceEntityVo resourceEntityVo = paramObj.toJavaObject(ResourceEntityVo.class); SceneEntityVo sceneEntityVo = ResourceEntityFactory.getSceneEntityByViewName(resourceEntityVo.getName()); - if (sceneEntityVo == null) { - throw new ResourceCenterResourceFoundException(resourceEntityVo.getName()); - } +// if (sceneEntityVo == null) { +// throw new ResourceCenterResourceFoundException(resourceEntityVo.getName()); +// } ResourceEntityConfigVo config = resourceEntityVo.getConfig(); String mainCi = config.getMainCi(); if (StringUtils.isNotBlank(mainCi)) { CiVo mainCiVo = ciMapper.getCiByName(mainCi); if (mainCiVo != null) { resourceEntityVo.setCiId(mainCiVo.getId()); + resourceEntityVo.setCi(mainCiVo); } } - resourceEntityVo.setDescription(sceneEntityVo.getDescription()); - resourceEntityVo.setLabel(sceneEntityVo.getLabel()); + if (sceneEntityVo != null) { + resourceEntityVo.setDescription(sceneEntityVo.getDescription()); + resourceEntityVo.setLabel(sceneEntityVo.getLabel()); + } boolean configEquals = false; ResourceEntityVo oldResourceEntityVo = resourceEntityMapper.getResourceEntityByName(resourceEntityVo.getName()); if (oldResourceEntityVo != null) { - configEquals = Objects.equals(resourceEntityVo.getConfigStr(), oldResourceEntityVo.getConfigStr()); - if (configEquals) { - return null; - } +// configEquals = Objects.equals(resourceEntityVo.getConfigStr(), oldResourceEntityVo.getConfigStr()); +// if (configEquals) { +// return null; +// } resourceEntityMapper.updateResourceEntityLabelAndDescription(resourceEntityVo); } else { resourceEntityVo.setStatus(Status.PENDING.getValue()); @@ -123,4 +134,19 @@ public class SaveResourceEntityApi extends PrivateApiComponentBase { } return null; } + + public IValid name() { + return value -> { + String name = value.getString("name"); + SceneEntityVo sceneEntityVo = ResourceEntityFactory.getSceneEntityByViewName(name); + if (sceneEntityVo != null) { + return new FieldValidResultVo(new ResourceEntityNameRepeatException(name)); + } + ResourceEntityVo resourceEntityVo = resourceEntityMapper.getResourceEntityByName(name); + if (resourceEntityVo != null) { + return new FieldValidResultVo(new ResourceEntityNameRepeatException(name)); + } + return new FieldValidResultVo(); + }; + } } diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/getResourceEntityViewDataListApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/getResourceEntityViewDataListApi.java index fe95451d..0d99d1bf 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/getResourceEntityViewDataListApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/getResourceEntityViewDataListApi.java @@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject; import neatlogic.framework.asynchronization.threadlocal.TenantContext; import neatlogic.framework.auth.core.AuthAction; import neatlogic.framework.cmdb.auth.label.CMDB; +import neatlogic.framework.cmdb.dto.resourcecenter.config.ResourceEntityConfigVo; import neatlogic.framework.common.constvalue.ApiParamType; import neatlogic.framework.common.dto.BasePageVo; import neatlogic.framework.dao.mapper.SchemaMapper; @@ -14,6 +15,8 @@ import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; import neatlogic.framework.util.TableResultUtil; import neatlogic.module.cmdb.dao.mapper.resourcecenter.ResourceEntityMapper; import neatlogic.module.cmdb.utils.ResourceEntityFactory; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -49,6 +52,18 @@ public class getResourceEntityViewDataListApi extends PrivateApiComponentBase { public Object myDoService(JSONObject paramObj) throws Exception { String name = paramObj.getString("name"); List fieldNameList = ResourceEntityFactory.getFieldNameListByViewName(name); + if (CollectionUtils.isEmpty(fieldNameList)) { + String config = resourceEntityMapper.getResourceEntityConfigByName(name); + if (StringUtils.isNotBlank(config)) { + ResourceEntityConfigVo resourceEntityConfigVo = JSONObject.parseObject(config, ResourceEntityConfigVo.class); + if (resourceEntityConfigVo != null) { + String sceneTemplateName = resourceEntityConfigVo.getSceneTemplateName(); + if (StringUtils.isNotBlank(sceneTemplateName)) { + fieldNameList = ResourceEntityFactory.getFieldNameListByViewName(sceneTemplateName); + } + } + } + } JSONArray theadList = new JSONArray(); List columnNameList = schemaMapper.getTableOrViewAllColumnNameList(TenantContext.get().getDataDbName(), name); for (String fieldName : fieldNameList) { diff --git a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceEntityMapper.java b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceEntityMapper.java index 457f3436..0e09d979 100644 --- a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceEntityMapper.java +++ b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceEntityMapper.java @@ -30,6 +30,8 @@ public interface ResourceEntityMapper extends IResourceEntityCrossoverMapper { List getResourceEntityListByNameList(List nameList); + List getResourceEntityList(); + String getResourceEntityConfigByName(String name); List getAllResourceTypeCiIdList(ResourceSearchVo searchVo); diff --git a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceEntityMapper.xml b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceEntityMapper.xml index bcd0b5d9..09980d45 100644 --- a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceEntityMapper.xml +++ b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceEntityMapper.xml @@ -32,6 +32,11 @@ along with this program. If not, see .--> + + + + + + + + - SELECT a.`id`, a.`name`, @@ -689,6 +689,18 @@ along with this program. If not, see .--> #{id} + + AND a.`app_system_id` = #{appSystemId} + + + AND a.`app_module_id` = #{appModuleId} + + + AND a.`env_id` = #{envId} + + + AND a.`env_id` is null + @@ -634,6 +640,12 @@ along with this program. If not, see .--> AND a.`env_id` is null + + AND a.`inspect_status` IN + + #{inspectStatus} + + ORDER BY a.`id` DESC LIMIT #{startNum}, #{pageSize} diff --git a/src/main/java/neatlogic/module/cmdb/resourcecenter/datasource/handler/DefaultResourceCenterDataSourceImpl.java b/src/main/java/neatlogic/module/cmdb/resourcecenter/datasource/handler/DefaultResourceCenterDataSourceImpl.java index 651091b1..93aab8d2 100644 --- a/src/main/java/neatlogic/module/cmdb/resourcecenter/datasource/handler/DefaultResourceCenterDataSourceImpl.java +++ b/src/main/java/neatlogic/module/cmdb/resourcecenter/datasource/handler/DefaultResourceCenterDataSourceImpl.java @@ -32,6 +32,7 @@ import neatlogic.framework.cmdb.exception.resourcecenter.AppModuleNotFoundExcept import neatlogic.framework.cmdb.exception.resourcecenter.AppSystemNotFoundException; import neatlogic.framework.cmdb.resourcecenter.datasource.core.IResourceCenterDataSource; import neatlogic.framework.cmdb.resourcecenter.datasource.core.Ordered; +import neatlogic.framework.common.constvalue.InspectStatus; import neatlogic.framework.common.dto.BasePageVo; import neatlogic.framework.common.dto.ValueTextVo; import neatlogic.framework.util.TableResultUtil; @@ -135,15 +136,29 @@ public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataS map.put(new ValueTextVo("inspect", "巡检状态"), (resourceVo, cacheData) -> { JSONObject resultObj = new JSONObject(); - resultObj.put("inspectStatus", resourceVo.getInspectStatus()); - resultObj.put("inspectTime", resourceVo.getInspectTime()); + if (StringUtils.isNotBlank(resourceVo.getInspectStatus())) { + JSONObject statusJson = InspectStatus.getInspectStatusJson(resourceVo.getInspectStatus()); + if (MapUtils.isNotEmpty(statusJson)) { + resultObj.putAll(statusJson); + } + } + if (resourceVo.getInspectTime() != null) { + resultObj.put("time", resourceVo.getInspectTime()); + } return resultObj; }); // map.put(new ValueTextVo("inspectTime", "巡检时间"), (resourceVo, cacheData) -> resourceVo.getInspectTime()); map.put(new ValueTextVo("monitor", "监控状态"), (resourceVo, cacheData) -> { JSONObject resultObj = new JSONObject(); - resultObj.put("monitorStatus", resourceVo.getMonitorStatus()); - resultObj.put("monitorTime", resourceVo.getMonitorTime()); + if (StringUtils.isNotBlank(resourceVo.getMonitorStatus())) { + JSONObject statusJson = InspectStatus.getInspectStatusJson(resourceVo.getMonitorStatus()); + if (MapUtils.isNotEmpty(statusJson)) { + resultObj.putAll(statusJson); + } + } + if (resourceVo.getMonitorTime() != null) { + resultObj.put("time", resourceVo.getMonitorTime()); + } return resultObj; }); // map.put(new ValueTextVo("monitorTime", "监控时间"), (resourceVo, cacheData) -> resourceVo.getMonitorTime()); @@ -575,6 +590,7 @@ public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataS virtualCiEntity.setCiName(ciVo.getName()); virtualCiEntity.setCiLabel(ciVo.getLabel()); virtualCiEntity.setCiIcon(ciVo.getIcon()); + virtualCiEntity.setIsVirtual(ciVo.getIsVirtual()); cacheData.put(virtualCiEntity.getId().toString(), virtualCiEntity); } } else { @@ -612,6 +628,7 @@ public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataS virtualCiEntity.setCiName(ciVo.getName()); virtualCiEntity.setCiLabel(ciVo.getLabel()); virtualCiEntity.setCiIcon(ciVo.getIcon()); + virtualCiEntity.setIsVirtual(ciVo.getIsVirtual()); cacheData.put(virtualCiEntity.getId().toString(), virtualCiEntity); } } else { -- Gitee From 1eeb64a0e65ccfd16c7a40dbe156f4024f7cfdc4 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Tue, 18 Mar 2025 14:32:38 +0800 Subject: [PATCH 20/29] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20CMDB=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E6=B8=85=E5=8D=95=E6=94=B9=E6=88=90=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E5=B1=82=E7=BA=A7=E5=8F=AF=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1349157963399168]CMDB应用清单改成模型层级可配置 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1349157963399168 --- .../config/SaveResourceEntityApi.java | 14 ++- .../mapper/resourcecenter/ResourceMapper.xml | 8 -- .../handler/ResourceViewRebuildHandler.java | 20 ----- .../ResourceCenterResourceServiceImpl.java | 37 -------- .../cmdb/utils/ResourceEntityFactory.java | 85 ------------------- 5 files changed, 5 insertions(+), 159 deletions(-) diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/SaveResourceEntityApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/SaveResourceEntityApi.java index 71be2115..f6869d49 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/SaveResourceEntityApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/SaveResourceEntityApi.java @@ -92,11 +92,8 @@ public class SaveResourceEntityApi extends PrivateApiComponentBase { resourceEntityVo.setLabel(label); resourceEntityVo.setConfigStr(configStr); resourceEntityVo.setDescription(description); -// ResourceEntityVo resourceEntityVo = paramObj.toJavaObject(ResourceEntityVo.class); SceneEntityVo sceneEntityVo = ResourceEntityFactory.getSceneEntityByViewName(resourceEntityVo.getName()); -// if (sceneEntityVo == null) { -// throw new ResourceCenterResourceFoundException(resourceEntityVo.getName()); -// } + ResourceEntityConfigVo config = resourceEntityVo.getConfig(); String mainCi = config.getMainCi(); if (StringUtils.isNotBlank(mainCi)) { @@ -110,7 +107,7 @@ public class SaveResourceEntityApi extends PrivateApiComponentBase { resourceEntityVo.setDescription(sceneEntityVo.getDescription()); resourceEntityVo.setLabel(sceneEntityVo.getLabel()); } - boolean configEquals = false; +// boolean configEquals = false; ResourceEntityVo oldResourceEntityVo = resourceEntityMapper.getResourceEntityByName(resourceEntityVo.getName()); if (oldResourceEntityVo != null) { // configEquals = Objects.equals(resourceEntityVo.getConfigStr(), oldResourceEntityVo.getConfigStr()); @@ -122,10 +119,9 @@ public class SaveResourceEntityApi extends PrivateApiComponentBase { resourceEntityVo.setStatus(Status.PENDING.getValue()); resourceEntityMapper.insertResourceEntity(resourceEntityVo); } - if (!configEquals) { +// if (!configEquals) { resourceEntityVo.setError(null); String sql = resourceCenterResourceService.buildResourceView(resourceEntityVo); -// resourceEntityVo.setError(error); if (StringUtils.isNotBlank(resourceEntityVo.getError())) { resourceEntityVo.setStatus(Status.ERROR.getValue()); } else { @@ -133,8 +129,8 @@ public class SaveResourceEntityApi extends PrivateApiComponentBase { } resourceEntityMapper.updateResourceEntityStatusAndError(resourceEntityVo); return sql; - } - return null; +// } +// return null; } public IValid name() { diff --git a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.xml b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.xml index 75e4d783..2959c46a 100644 --- a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.xml +++ b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.xml @@ -513,14 +513,6 @@ along with this program. If not, see .--> - diff --git a/src/main/java/neatlogic/module/cmdb/rebuilddatabaseview/handler/ResourceViewRebuildHandler.java b/src/main/java/neatlogic/module/cmdb/rebuilddatabaseview/handler/ResourceViewRebuildHandler.java index 194db9ea..428f7148 100644 --- a/src/main/java/neatlogic/module/cmdb/rebuilddatabaseview/handler/ResourceViewRebuildHandler.java +++ b/src/main/java/neatlogic/module/cmdb/rebuilddatabaseview/handler/ResourceViewRebuildHandler.java @@ -55,15 +55,6 @@ public class ResourceViewRebuildHandler implements IRebuildDataBaseView { @Override public List createViewIfNotExists() { List resultList = new ArrayList<>(); -// List sceneEntityList = ResourceEntityFactory.getSceneEntityList(); -// for (SceneEntityVo sceneEntityVo : sceneEntityList) { -// String tableType = schemaMapper.checkTableOrViewIsExists(TenantContext.get().getDataDbName(), sceneEntityVo.getName()); -// if (Objects.equals(tableType, "VIEW")) { -// continue; -// } -// ViewStatusInfo viewStatusInfo = rebuildSceneEntity(sceneEntityVo); -// resultList.add(viewStatusInfo); -// } List resourceEntityList = resourceEntityMapper.getResourceEntityList(); for (ResourceEntityVo resourceEntityVo : resourceEntityList) { String tableType = schemaMapper.checkTableOrViewIsExists(TenantContext.get().getDataDbName(), resourceEntityVo.getName()); @@ -99,11 +90,6 @@ public class ResourceViewRebuildHandler implements IRebuildDataBaseView { @Override public List createOrReplaceView() { List resultList = new ArrayList<>(); -// List sceneEntityList = ResourceEntityFactory.getSceneEntityList(); -// for (SceneEntityVo sceneEntityVo : sceneEntityList) { -// ViewStatusInfo viewStatusInfo = rebuildSceneEntity(sceneEntityVo); -// resultList.add(viewStatusInfo); -// } List resourceEntityList = resourceEntityMapper.getResourceEntityList(); for (ResourceEntityVo resourceEntityVo : resourceEntityList) { String config = resourceEntityMapper.getResourceEntityConfigByName(resourceEntityVo.getName()); @@ -133,15 +119,9 @@ public class ResourceViewRebuildHandler implements IRebuildDataBaseView { } private ViewStatusInfo rebuildSceneEntity(ResourceEntityVo resourceEntityVo) { -// ResourceEntityVo resourceEntityVo = new ResourceEntityVo(); -// resourceEntityVo.setName(sceneEntityVo.getName()); -// resourceEntityVo.setLabel(sceneEntityVo.getLabel()); -// String config = resourceEntityMapper.getResourceEntityConfigByName(resourceEntityVo.getName()); if (resourceEntityVo.getConfig() != null) { -// resourceEntityVo.setConfigStr(config); resourceEntityVo.setError(null); String sql = resourceCenterResourceService.buildResourceView(resourceEntityVo); -// resourceEntityVo.setError(error); if (StringUtils.isNotBlank(resourceEntityVo.getError())) { resourceEntityVo.setStatus(Status.ERROR.getValue()); } else { diff --git a/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java b/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java index 49f2cf73..04190d62 100644 --- a/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java +++ b/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java @@ -520,30 +520,6 @@ public class ResourceCenterResourceServiceImpl implements IResourceCenterResourc return new ArrayList<>(); }); -// searchMap.put("StorageDevice", (searchVo) -> { -// int rowNum = resourceCenterMapper.getStorageResourceCount(searchVo); -// if (rowNum > 0) { -// searchVo.setRowNum(rowNum); -// List idList = resourceCenterMapper.getStorageResourceIdList(searchVo); -// if (CollectionUtils.isNotEmpty(idList)) { -// return resourceCenterMapper.getStorageResourceListByIdList(idList, TenantContext.get().getDataDbName()); -// } -// } -// return new ArrayList<>(); -// }); -// -// searchMap.put("NetworkDevice", (searchVo) -> { -// int rowNum = resourceCenterMapper.getNetDevResourceCount(searchVo); -// if (rowNum > 0) { -// searchVo.setRowNum(rowNum); -// List idList = resourceCenterMapper.getNetDevResourceIdList(searchVo); -// if (CollectionUtils.isNotEmpty(idList)) { -// return resourceCenterMapper.getNetDevResourceListByIdList(idList, TenantContext.get().getDataDbName()); -// } -// } -// return new ArrayList<>(); -// }); - searchMap.put("APPIns", (searchVo) -> { int rowNum = resourceMapper.getIpObjectResourceCountByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(searchVo); if (rowNum > 0) { @@ -742,20 +718,10 @@ public class ResourceCenterResourceServiceImpl implements IResourceCenterResourc List viewNameList = ResourceEntityFactory.getViewNameList(); List resourceEntityList = resourceEntityMapper.getResourceEntityListByNameList(viewNameList); for (ResourceEntityVo resourceEntityVo : resourceEntityList) { -// resourceEntityVo.setError(""); -// resourceEntityVo.setStatus(Status.PENDING.getValue()); -// resourceEntityMapper.updateResourceEntityStatusAndError(resourceEntityVo); -// String xml = resourceEntityMapper.getResourceEntityXmlByName(resourceEntityVo.getName()); -// if (StringUtils.isNotBlank(xml)) { -// resourceEntityVo.setXml(xml); -// ResourceEntityViewBuilder builder = new ResourceEntityViewBuilder(resourceEntityVo); -// builder.buildView(); -// } String config = resourceEntityMapper.getResourceEntityConfigByName(resourceEntityVo.getName()); resourceEntityVo.setError(null); resourceEntityVo.setConfigStr(config); String sql = buildResourceView(resourceEntityVo); -// resourceEntityVo.setError(error); if (StringUtils.isNotBlank(resourceEntityVo.getError())) { resourceEntityVo.setStatus(Status.ERROR.getValue()); } else { @@ -1183,9 +1149,6 @@ public class ResourceCenterResourceServiceImpl implements IResourceCenterResourc } resultList.add(newFieldMappingVo); } -// if (CollectionUtils.isNotEmpty(fieldNameList)) { -// throw new ResourceViewFieldMappingException(viewName, fieldNameList); -// } newConfig.setFieldMappingList(resultList); return newConfig; } diff --git a/src/main/java/neatlogic/module/cmdb/utils/ResourceEntityFactory.java b/src/main/java/neatlogic/module/cmdb/utils/ResourceEntityFactory.java index da621ee8..3e0440ac 100644 --- a/src/main/java/neatlogic/module/cmdb/utils/ResourceEntityFactory.java +++ b/src/main/java/neatlogic/module/cmdb/utils/ResourceEntityFactory.java @@ -40,11 +40,6 @@ public class ResourceEntityFactory { * 视图名称与字段列表映射关系 */ private static Map> fieldMap = new HashMap<>(); - /** - * 视图名称与字段别名列表映射关系 - */ - private static Map> fieldAliasMap = new HashMap<>(); -// private static List resourceEntityList = new ArrayList<>(); /** * 视图信息列表 */ @@ -54,63 +49,6 @@ public class ResourceEntityFactory { */ private static List viewNameList = new ArrayList<>(); -// static { -// Reflections ref = new Reflections("neatlogic.framework.cmdb.dto.resourcecenter.entity", new TypeAnnotationsScanner(), new SubTypesScanner(true)); -// Set> classList = ref.getTypesAnnotatedWith(ResourceType.class, true); -// for (Class c : classList) { -// ResourceEntityVo resourceEntityVo = null; -// Annotation[] classAnnotations = c.getDeclaredAnnotations(); -// for (Annotation annotation : classAnnotations) { -// if (annotation instanceof ResourceType) { -// ResourceType rt = (ResourceType) annotation; -// resourceEntityVo = new ResourceEntityVo(); -// resourceEntityVo.setName(rt.name()); -// resourceEntityVo.setLabel(rt.label()); -// } -// } -// if (resourceEntityVo == null) { -// continue; -// } -// for (Field field : c.getDeclaredFields()) { -// Annotation[] annotations = field.getDeclaredAnnotations(); -// for (Annotation annotation : annotations) { -// if (annotation instanceof ResourceField) { -// ResourceField rf = (ResourceField) annotation; -// if (StringUtils.isNotBlank(rf.name())) { -// ResourceEntityAttrVo attr = new ResourceEntityAttrVo(); -// attr.setField(rf.name()); -// resourceEntityVo.addAttr(attr); -// } -// } -// } -// } -// resourceEntityVo.setType(ViewType.RESOURCE.getValue()); -// resourceEntityList.add(resourceEntityVo); -// } -// classList = ref.getTypesAnnotatedWith(ResourceTypes.class, true); -// for (Class c : classList) { -// ResourceTypes resourceTypes = c.getAnnotation(ResourceTypes.class); -// if (resourceTypes != null) { -// for (ResourceType rt : resourceTypes.value()) { -// ResourceEntityVo resourceEntityVo = new ResourceEntityVo(); -// resourceEntityVo.setName(rt.name()); -// resourceEntityVo.setLabel(rt.label()); -// for (Field field : c.getDeclaredFields()) { -// ResourceField rf = field.getAnnotation(ResourceField.class); -// if (rf != null) { -// if (StringUtils.isNotBlank(rf.name())) { -// ResourceEntityAttrVo attr = new ResourceEntityAttrVo(); -// attr.setField(rf.name()); -// resourceEntityVo.addAttr(attr); -// } -// } -// } -// resourceEntityVo.setType(ViewType.RESOURCE.getValue()); -// resourceEntityList.add(resourceEntityVo); -// } -// } -// } -// } static { Reflections ref = new Reflections("neatlogic"); Set> classList = ref.getTypesAnnotatedWith(ResourceType.class, true); @@ -141,18 +79,8 @@ public class ResourceEntityFactory { if (StringUtils.isNotBlank(rf.name())) { EntityField ef = field.getAnnotation(EntityField.class); fieldMap.computeIfAbsent(sceneEntityVo.getName(), key -> new ArrayList<>()).add(new ValueTextVo(rf.name(), ef.name())); - fieldAliasMap.computeIfAbsent(sceneEntityVo.getName(), key -> new ArrayList<>()).add(new ValueTextVo(rf.name(), field.getName())); } } -// Annotation[] annotations = field.getDeclaredAnnotations(); -// for (Annotation annotation : annotations) { -// if (annotation instanceof ResourceField) { -// ResourceField rf = (ResourceField) annotation; -// if (StringUtils.isNotBlank(rf.name())) { -// fieldMap.computeIfAbsent(sceneEntityVo.getName(), key -> new ArrayList<>()).add(new ValueTextVo(rf.name(), "aaa")); -// } -// } -// } } sceneEntityList.add(sceneEntityVo); } @@ -177,7 +105,6 @@ public class ResourceEntityFactory { if (StringUtils.isNotBlank(rf.name())) { EntityField ef = field.getAnnotation(EntityField.class); fieldMap.computeIfAbsent(sceneEntityVo.getName(), key -> new ArrayList<>()).add(new ValueTextVo(rf.name(), ef.name())); - fieldAliasMap.computeIfAbsent(sceneEntityVo.getName(), key -> new ArrayList<>()).add(new ValueTextVo(rf.name(), field.getName())); } } } @@ -192,10 +119,6 @@ public class ResourceEntityFactory { sceneEntityList.sort(Comparator.comparingInt(e -> viewNameList.indexOf(e.getName()))); } -// public static List getResourceEntityList() { -// return resourceEntityList; -// } - public static List getSceneEntityList() { List resultList = new ArrayList<>(); for (SceneEntityVo sceneEntity : sceneEntityList) { @@ -249,14 +172,6 @@ public class ResourceEntityFactory { return new ArrayList<>(fieldList); } - public static List getFieldAliasListByViewName(String viewName) { - List fieldAliasList = fieldAliasMap.get(viewName); - if (fieldAliasList == null) { - return new ArrayList<>(); - } - return new ArrayList<>(fieldAliasList); - } - public static List getViewNameList() { return new ArrayList<>(viewNameList); } -- Gitee From 2e20b8b65d5953d6d3abaf0e77792dc8ccdf1dff Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Fri, 21 Mar 2025 11:21:50 +0800 Subject: [PATCH 21/29] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20CMDB=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E6=B8=85=E5=8D=95=E6=94=B9=E6=88=90=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E5=B1=82=E7=BA=A7=E5=8F=AF=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1349157963399168]CMDB应用清单改成模型层级可配置 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1349157963399168 --- .../AppModuleResourceTypeListApi.java | 56 ++-- .../resourcecenter/AppSystemMapper.java | 4 +- .../mapper/resourcecenter/AppSystemMapper.xml | 4 +- .../mapper/resourcecenter/ResourceMapper.java | 32 +- .../mapper/resourcecenter/ResourceMapper.xml | 289 +++--------------- .../resourcecenter/ResourceTempMapper.java | 45 +++ .../resourcecenter/ResourceTempMapper.xml | 281 +++++++++++++++++ .../DefaultResourceCenterDataSourceImpl.java | 228 +++++++++++--- .../IResourceCenterResourceService.java | 18 +- .../ResourceCenterResourceServiceImpl.java | 251 ++++++++------- 10 files changed, 737 insertions(+), 471 deletions(-) create mode 100644 src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceTempMapper.java create mode 100644 src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceTempMapper.xml diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/appmodule/AppModuleResourceTypeListApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/appmodule/AppModuleResourceTypeListApi.java index fc995848..826cb1e0 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/appmodule/AppModuleResourceTypeListApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/appmodule/AppModuleResourceTypeListApi.java @@ -9,6 +9,8 @@ import neatlogic.framework.cmdb.dto.resourcecenter.ResourceSearchVo; import neatlogic.framework.cmdb.dto.resourcecenter.ResourceVo; import neatlogic.framework.cmdb.enums.resourcecenter.AppModuleResourceType; import neatlogic.framework.cmdb.exception.ci.CiNotFoundException; +import neatlogic.framework.cmdb.resourcecenter.datasource.core.IResourceCenterDataSource; +import neatlogic.framework.cmdb.resourcecenter.datasource.core.ResourceCenterDataSourceFactory; import neatlogic.framework.common.constvalue.ApiParamType; import neatlogic.framework.common.dto.BasePageVo; import neatlogic.framework.restful.annotation.*; @@ -111,28 +113,44 @@ public class AppModuleResourceTypeListApi extends PrivateApiComponentBase { for (ResourceVo envResource : envResourceList) { JSONObject returnObj = new JSONObject(); searchVo.setEnvId(envResource.getId()); - //根据模块id和环境id,获取当前环境下含有资产的 模型idList(resourceTypeIdList) - Set resourceTypeIdSet = resourceMapper.getIpObjectResourceTypeIdListByAppModuleIdAndEnvId(searchVo); - List resourceTypeIdList = new ArrayList<>(resourceTypeIdSet); - Set returnCiVoSet = new HashSet<>(); - if (CollectionUtils.isNotEmpty(resourceTypeIdSet)) { - resourceTypeIdSet = resourceMapper.getOsResourceTypeIdListByAppModuleIdAndEnvId(searchVo); - resourceTypeIdList.addAll(resourceTypeIdSet); + Set typeIdSet = new HashSet<>(); + IResourceCenterDataSource resourceCenterDataSource = ResourceCenterDataSourceFactory.getResourceCenterDataSource(); + Map> viewName2TypeIdListMap = resourceCenterDataSource.getAppResourceTypeIdListByAppSystemIdAndAppModuleIdAndEnvId(null, appModuleId, envResource.getId()); + for (Map.Entry> entry : viewName2TypeIdListMap.entrySet()) { + String viewName = entry.getKey(); + searchVo.setViewName(viewName); + typeIdSet.addAll(entry.getValue()); } - - //循环resourceTypeIdList,将其父级模型的name存在于resourceTypeNameList中的 模型 返回给前端 - if (CollectionUtils.isNotEmpty(resourceTypeIdList)) { - for (Long resourceTypeId : resourceTypeIdList) { - CiVo ciVo = allCiVoMap.get(resourceTypeId); - if (ciVo == null) { - throw new CiNotFoundException(resourceTypeId); - } - String resourceTypeName = resourceCenterResourceService.getResourceTypeName(resourceCiVoList, ciVo); - if (resourceTypeNameList.contains(resourceTypeName)) { - returnCiVoSet.add(ciVo); - } + Set returnCiVoSet = new HashSet<>(); + for (Long typeId : typeIdSet) { + CiVo ciVo = allCiVoMap.get(typeId); + if (ciVo == null) { + throw new CiNotFoundException(typeId); } + returnCiVoSet.add(ciVo); } +// //根据模块id和环境id,获取当前环境下含有资产的 模型idList(resourceTypeIdList) +// Set resourceTypeIdSet = resourceMapper.getIpObjectResourceTypeIdListByAppModuleIdAndEnvId(searchVo); +// List resourceTypeIdList = new ArrayList<>(resourceTypeIdSet); +// Set returnCiVoSet = new HashSet<>(); +// if (CollectionUtils.isNotEmpty(resourceTypeIdSet)) { +// resourceTypeIdSet = resourceMapper.getOsResourceTypeIdListByAppModuleIdAndEnvId(searchVo); +// resourceTypeIdList.addAll(resourceTypeIdSet); +// } +// +// //循环resourceTypeIdList,将其父级模型的name存在于resourceTypeNameList中的 模型 返回给前端 +// if (CollectionUtils.isNotEmpty(resourceTypeIdList)) { +// for (Long resourceTypeId : resourceTypeIdList) { +// CiVo ciVo = allCiVoMap.get(resourceTypeId); +// if (ciVo == null) { +// throw new CiNotFoundException(resourceTypeId); +// } +// String resourceTypeName = resourceCenterResourceService.getResourceTypeName(resourceCiVoList, ciVo); +// if (resourceTypeNameList.contains(resourceTypeName)) { +// returnCiVoSet.add(ciVo); +// } +// } +// } if (CollectionUtils.isNotEmpty(returnCiVoSet)) { returnObj.put("env", envResource); returnObj.put("ciVoList", returnCiVoSet); diff --git a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/AppSystemMapper.java b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/AppSystemMapper.java index 8bf9f308..c950d07d 100644 --- a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/AppSystemMapper.java +++ b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/AppSystemMapper.java @@ -16,10 +16,8 @@ along with this program. If not, see .*/ package neatlogic.module.cmdb.dao.mapper.resourcecenter; import neatlogic.framework.cmdb.crossover.IAppSystemMapper; -import neatlogic.framework.cmdb.dto.resourcecenter.entity.AppEnvironmentVo; import neatlogic.framework.cmdb.dto.resourcecenter.entity.AppModuleVo; import neatlogic.framework.cmdb.dto.resourcecenter.entity.AppSystemVo; -import org.apache.ibatis.annotations.Param; import java.util.List; @@ -37,6 +35,6 @@ public interface AppSystemMapper extends IAppSystemMapper { List getAppModuleListByIdList(List idList); - List getAppEnvListByAppSystemIdAndModuleIdList(@Param("appSystemId") Long appSystemId, @Param("appModuleIdList") List appModuleIdList); +// List getAppEnvListByAppSystemIdAndModuleIdList(@Param("appSystemId") Long appSystemId, @Param("appModuleIdList") List appModuleIdList); } diff --git a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/AppSystemMapper.xml b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/AppSystemMapper.xml index 8bcbb701..a6e5f633 100644 --- a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/AppSystemMapper.xml +++ b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/AppSystemMapper.xml @@ -59,7 +59,7 @@ along with this program. If not, see .--> - + --> diff --git a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.java b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.java index 48290194..7731b162 100644 --- a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.java +++ b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.java @@ -52,17 +52,11 @@ public interface ResourceMapper extends IResourceCrossoverMapper { List getAppResourceListByIdList(ResourceSearchVo searchVo); - int getIpObjectResourceCountByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(ResourceSearchVo searchVo); - - List getIpObjectResourceIdListByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(ResourceSearchVo searchVo); - - int getOsResourceCountByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(ResourceSearchVo searchVo); - - List getOsResourceIdListByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(ResourceSearchVo searchVo); +// List getOsResourceIdListByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(ResourceSearchVo searchVo); int getOsResourceCountByAppSystemIdAndAppModuleIdListAndEnvIdAndTypeId(ResourceSearchVo searchVo); - List getOsResourceIdListByAppSystemIdAndAppModuleIdListAndEnvIdAndTypeId(ResourceSearchVo searchVo); +// List getOsResourceIdListByAppSystemIdAndAppModuleIdListAndEnvIdAndTypeId(ResourceSearchVo searchVo); List getAppInstanceResourceListByIdList(@Param("idList") List idList); @@ -70,10 +64,6 @@ public interface ResourceMapper extends IResourceCrossoverMapper { List getAppInstanceResourceListByIdListSimple(List idList); - List getDbInstanceResourceListByIdList(List idList); - - List getOsResourceListByIdList(List idList); - Long getResourceIdByIpAndPortAndName(ResourceSearchVo searchVo); Long getResourceIdByIpAndPortAndNameWithFilter(ResourceSearchVo searchVo); @@ -90,7 +80,7 @@ public interface ResourceMapper extends IResourceCrossoverMapper { List getHasModuleAppSystemIdListByAppSystemIdList(@Param("appSystemIdList") List appSystemIdList); - List getHasEnvAppSystemIdListByAppSystemIdList(@Param("appSystemIdList") List appSystemIdList); +// List getHasEnvAppSystemIdListByAppSystemIdList(@Param("appSystemIdList") List appSystemIdList); int searchAppModuleCount(ResourceSearchVo searchVo); @@ -108,14 +98,6 @@ public interface ResourceMapper extends IResourceCrossoverMapper { List getAppModuleListByIdListSimple(@Param("idList") List idList, @Param("needOrder") boolean needOrder); - Set getIpObjectResourceTypeIdListByAppModuleIdAndEnvId(ResourceSearchVo searchVo); - - Set getOsResourceTypeIdListByAppModuleIdAndEnvId(ResourceSearchVo searchVo); - - Set getIpObjectResourceTypeIdListByAppSystemIdAndEnvId(ResourceSearchVo searchVo); - - Set getOsResourceTypeIdListByAppSystemIdAndEnvId(ResourceSearchVo searchVo); - Set getResourceAppSystemIdListByResourceId(Long id); List getResourceAppSystemListByResourceIdList(List id); @@ -205,9 +187,11 @@ public interface ResourceMapper extends IResourceCrossoverMapper { List getAppSystemListByKeyword(BasePageVo searchVo); - List getOsEnvListByAppSystemIdAndTypeId(ResourceSearchVo searchVo); +// List getOsEnvListByAppSystemIdAndTypeId(ResourceSearchVo searchVo); - List getIpObjectEnvListByAppSystemIdAndTypeId(ResourceSearchVo searchVo); +// List getIpObjectEnvListByAppSystemIdAndTypeId(ResourceSearchVo searchVo); + + List getAppEnvListByAppSystemId(Long appSystemId); List getAppEnvListByAppSystemIdAndAppModuleId(@Param("appSystemId") Long appSystemId, @Param("appModuleId") Long appModuleId); @@ -220,4 +204,6 @@ public interface ResourceMapper extends IResourceCrossoverMapper { List getOsResourceListByResourceIdList(List resourceIdList); List getResourceTypeIdListByAuth(ResourceSearchVo searchVo); + + List getAppResourceTypeIdListByViewNameAndAppSystemId(@Param("viewName") String viewName, @Param("appSystemId") Long appSystemId, @Param("appModuleId") Long appModuleId, @Param("envId") Long envId); } diff --git a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.xml b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.xml index 2959c46a..7c087273 100644 --- a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.xml +++ b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.xml @@ -707,83 +707,6 @@ along with this program. If not, see .--> - - - - - - - - - - - + --> - - - - - - - - SELECT a.`app_system_id` - FROM @{DATA_SCHEMA}.`scence_ipobject_env_appmodule_appsystem` a + FROM @{DATA_SCHEMA}.`scence_ipobject_detail` a WHERE a.`id` = #{id} @@ -1315,7 +1090,7 @@ along with this program. If not, see .--> resultType="java.lang.Long"> SELECT a.type_id - FROM @{DATA_SCHEMA}.`scence_ipobject_env_appmodule_appsystem` a + FROM @{DATA_SCHEMA}.`scence_ipobject_detail` a WHERE a.`app_system_id` = #{appSystemId} AND a.`app_module_id` = #{appModuleId} @@ -1334,7 +1109,7 @@ along with this program. If not, see .--> parameterType="neatlogic.framework.cmdb.dto.resourcecenter.ResourceVo" resultType="java.lang.Long"> SELECT a.`id` - FROM @{DATA_SCHEMA}.`scence_ipobject_env_appmodule_appsystem` a + FROM @{DATA_SCHEMA}.`scence_ipobject_detail` a WHERE a.`app_system_id` = #{appSystemId} AND a.`app_module_id` = #{appModuleId} AND a.`env_id` = #{envId} @@ -1975,15 +1750,15 @@ along with this program. If not, see .--> - + - + --> - --> + + - + --> @@ -2226,4 +2013,24 @@ along with this program. If not, see .--> + + diff --git a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceTempMapper.java b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceTempMapper.java new file mode 100644 index 00000000..21356409 --- /dev/null +++ b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceTempMapper.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2025 深圳极向量科技有限公司 All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package neatlogic.module.cmdb.dao.mapper.resourcecenter; + +import neatlogic.framework.cmdb.dto.resourcecenter.ResourceSearchVo; +import neatlogic.framework.cmdb.dto.resourcecenter.ResourceVo; + +import java.util.List; +import java.util.Set; + +public interface ResourceTempMapper { + + Set getIpObjectResourceTypeIdListByAppModuleIdAndEnvId(ResourceSearchVo searchVo); + + Set getOsResourceTypeIdListByAppModuleIdAndEnvId(ResourceSearchVo searchVo); + + Set getIpObjectResourceTypeIdListByAppSystemIdAndEnvId(ResourceSearchVo searchVo); + + Set getOsResourceTypeIdListByAppSystemIdAndEnvId(ResourceSearchVo searchVo); + + int getIpObjectResourceCountByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(ResourceSearchVo searchVo); + + List getIpObjectResourceIdListByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(ResourceSearchVo searchVo); + + int getOsResourceCountByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(ResourceSearchVo searchVo); + + List getDbInstanceResourceListByIdList(List idList); + + List getOsResourceListByIdList(List idList); +} diff --git a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceTempMapper.xml b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceTempMapper.xml new file mode 100644 index 00000000..eae77a44 --- /dev/null +++ b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceTempMapper.xml @@ -0,0 +1,281 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/neatlogic/module/cmdb/resourcecenter/datasource/handler/DefaultResourceCenterDataSourceImpl.java b/src/main/java/neatlogic/module/cmdb/resourcecenter/datasource/handler/DefaultResourceCenterDataSourceImpl.java index 93aab8d2..9a020e99 100644 --- a/src/main/java/neatlogic/module/cmdb/resourcecenter/datasource/handler/DefaultResourceCenterDataSourceImpl.java +++ b/src/main/java/neatlogic/module/cmdb/resourcecenter/datasource/handler/DefaultResourceCenterDataSourceImpl.java @@ -27,6 +27,7 @@ import neatlogic.framework.cmdb.dto.resourcecenter.*; import neatlogic.framework.cmdb.dto.resourcecenter.config.ResourceEntityConfigVo; import neatlogic.framework.cmdb.dto.resourcecenter.config.ResourceEntityFieldMappingVo; import neatlogic.framework.cmdb.dto.resourcecenter.config.ResourceEntityVo; +import neatlogic.framework.cmdb.dto.resourcecenter.config.SceneEntityVo; import neatlogic.framework.cmdb.exception.ci.CiNotFoundException; import neatlogic.framework.cmdb.exception.resourcecenter.AppModuleNotFoundException; import neatlogic.framework.cmdb.exception.resourcecenter.AppSystemNotFoundException; @@ -42,6 +43,7 @@ import neatlogic.module.cmdb.dao.mapper.globalattr.GlobalAttrMapper; import neatlogic.module.cmdb.dao.mapper.resourcecenter.ResourceEntityMapper; import neatlogic.module.cmdb.dao.mapper.resourcecenter.ResourceMapper; import neatlogic.module.cmdb.service.resourcecenter.resource.IResourceCenterResourceService; +import neatlogic.module.cmdb.utils.ResourceEntityFactory; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; @@ -78,7 +80,7 @@ public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataS @PostConstruct public void init() { - map.put(new ValueTextVo("id", "ID"), (resourceVo, cacheData) -> resourceVo.getId().toString()); + map.put(new ValueTextVo("id", "ID"), (resourceVo, cacheData) -> resourceVo.getId()); map.put(new ValueTextVo("name", "名称"), (resourceVo, cacheData) -> resourceVo.getName()); map.put(new ValueTextVo("ip", "IP地址"), (resourceVo, cacheData) -> { JSONObject resultObj = new JSONObject(); @@ -427,23 +429,15 @@ public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataS if (appModuleId != null && ciEntityCachedMapper.getCiEntityBaseInfoById(appModuleId) == null) { throw new AppModuleNotFoundException(appModuleId); } -// if (CollectionUtils.isNotEmpty(typeIdList)) { -// for (Long typeId : typeIdList) { -// CiVo ciVo = ciMapper.getCiById(typeId); -// if (ciVo == null) { -// throw new CiNotFoundException(typeId); -// } -// } -// } JSONArray tableList = new JSONArray(); + List viewNameList = new ArrayList<>(); + Map> viewName2FieldListMap = new HashMap<>(); ApplicationListDisplayVo applicationListDisplay = resourceEntityMapper.getApplicationListDisplay(); if (applicationListDisplay != null) { JSONObject config = applicationListDisplay.getConfig(); if (MapUtils.isNotEmpty(config)) { JSONArray tableSettingList = config.getJSONArray("tableSettingList"); if (CollectionUtils.isNotEmpty(tableSettingList)) { - List viewNameList = new ArrayList<>(); - Map> viewName2FieldListMap = new HashMap<>(); for (int i = 0; i < tableSettingList.size(); i++) { JSONObject tableObj = tableSettingList.getJSONObject(i); if (MapUtils.isNotEmpty(tableObj)) { @@ -458,49 +452,135 @@ public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataS } } } - if (CollectionUtils.isNotEmpty(viewNameList)) { - ResourceSearchVo searchVo = new ResourceSearchVo(); - searchVo.setAppSystemId(appSystemId); - if (appModuleId != null) { - searchVo.setAppModuleId(appModuleId); - } - if (envId != null) { - searchVo.setEnvId(envId); - } - searchVo.setCurrentPage(currentPage); - searchVo.setPageSize(pageSize); - for (String name : viewNameList) { - ResourceEntityVo resourceEntityVo = resourceEntityMapper.getResourceEntityByName(name); - if (resourceEntityVo != null) { - searchVo.setViewName(name); - int rowNum = resourceMapper.getAppResourceCount(searchVo); - if (rowNum > 0) { - searchVo.setRowNum(rowNum); - List resourceIdList = resourceMapper.getAppResourceIdList(searchVo); - if (CollectionUtils.isNotEmpty(resourceIdList)) { - searchVo.setIdList(resourceIdList); - List resourceList = resourceMapper.getAppResourceListByIdList(searchVo); - if (CollectionUtils.isNotEmpty(resourceList)) { - List fieldList = viewName2FieldListMap.get(name); - JSONArray theadList = getTheadList(fieldList); - JSONArray tbodyList = getTbodyList(fieldList, resourceList, resourceEntityVo); - JSONObject tableObj = TableResultUtil.getResult(theadList, tbodyList, searchVo); - tableObj.put("type", new JSONObject()); - tableObj.put("viewName", name); - tableObj.put("viewLabel", resourceEntityVo.getLabel()); - tableList.add(tableObj); - } - } - } - } - } + } + } + } + if (CollectionUtils.isNotEmpty(viewNameList)) { + ResourceSearchVo searchVo = new ResourceSearchVo(); + searchVo.setAppSystemId(appSystemId); + if (appModuleId != null) { + searchVo.setAppModuleId(appModuleId); + } + if (envId != null) { + searchVo.setEnvId(envId); + } + searchVo.setCurrentPage(currentPage); + searchVo.setPageSize(pageSize); + for (String name : viewNameList) { + ResourceEntityVo resourceEntityVo = resourceEntityMapper.getResourceEntityByName(name); + if (resourceEntityVo != null) { + searchVo.setViewName(name); + List resourceList = getAppResourceList(searchVo, true); + if (CollectionUtils.isNotEmpty(resourceList)) { + List fieldList = viewName2FieldListMap.get(name); + JSONArray theadList = getTheadList(fieldList); + JSONArray tbodyList = getTbodyList(fieldList, resourceList, resourceEntityVo); + JSONObject tableObj = TableResultUtil.getResult(theadList, tbodyList, searchVo); +// tableObj.put("type", new JSONObject()); + tableObj.put("viewName", name); + tableObj.put("viewLabel", resourceEntityVo.getLabel()); + tableList.add(tableObj); } } } +// ResourceSearchVo searchVo = new ResourceSearchVo(); +// searchVo.setAppSystemId(appSystemId); +// if (appModuleId != null) { +// searchVo.setAppModuleId(appModuleId); +// } +// if (envId != null) { +// searchVo.setEnvId(envId); +// } +// searchVo.setCurrentPage(currentPage); +// searchVo.setPageSize(pageSize); +// for (String name : viewNameList) { +// ResourceEntityVo resourceEntityVo = resourceEntityMapper.getResourceEntityByName(name); +// if (resourceEntityVo != null) { +// searchVo.setViewName(name); +// int rowNum = resourceMapper.getAppResourceCount(searchVo); +// if (rowNum > 0) { +// searchVo.setRowNum(rowNum); +// List resourceIdList = resourceMapper.getAppResourceIdList(searchVo); +// if (CollectionUtils.isNotEmpty(resourceIdList)) { +// searchVo.setIdList(resourceIdList); +// List resourceList = resourceMapper.getAppResourceListByIdList(searchVo); +// if (CollectionUtils.isNotEmpty(resourceList)) { +// List fieldList = viewName2FieldListMap.get(name); +// JSONArray theadList = getTheadList(fieldList); +// JSONArray tbodyList = getTbodyList(fieldList, resourceList, resourceEntityVo); +// JSONObject tableObj = TableResultUtil.getResult(theadList, tbodyList, searchVo); +// tableObj.put("type", new JSONObject()); +// tableObj.put("viewName", name); +// tableObj.put("viewLabel", resourceEntityVo.getLabel()); +// tableList.add(tableObj); +// } +// } +// } +// } +// } } return tableList; } + @Override + public List getAppResourceList(ResourceSearchVo searchVo, boolean needPage) { + List resultList = new ArrayList<>(); + int rowNum = resourceMapper.getAppResourceCount(searchVo); + if (rowNum > 0) { + searchVo.setRowNum(rowNum); + if (needPage) { + searchVo.setPageSize(100); + } + Integer pageCount = searchVo.getPageCount(); + for (int i = 1; i <= pageCount; i++) { + if (needPage && !Objects.equals(i, searchVo.getCurrentPage())) { + continue; + } + searchVo.setCurrentPage(i); + List resourceIdList = resourceMapper.getAppResourceIdList(searchVo); + if (CollectionUtils.isNotEmpty(resourceIdList)) { + searchVo.setIdList(resourceIdList); + List resourceList = resourceMapper.getAppResourceListByIdList(searchVo); + resultList.addAll(resourceList); + } + if (needPage) { + break; + } + } + } + return resultList; + } + + @Override + public List getAppResourceIdList(ResourceSearchVo searchVo, boolean needPage) { + List resultList = new ArrayList<>(); + int rowNum = resourceMapper.getAppResourceCount(searchVo); + if (rowNum > 0) { + searchVo.setRowNum(rowNum); + if (needPage) { + searchVo.setPageSize(100); + } + Integer pageCount = searchVo.getPageCount(); + for (int i = 1; i <= pageCount; i++) { + if (needPage && !Objects.equals(i, searchVo.getCurrentPage())) { + continue; + } + searchVo.setCurrentPage(i); + List resourceIdList = resourceMapper.getAppResourceIdList(searchVo); + resultList.addAll(resourceIdList); +// if (CollectionUtils.isNotEmpty(resourceIdList)) { +// searchVo.setIdList(resourceIdList); +// List resourceList = resourceMapper.getAppResourceListByIdList(searchVo); +// resultList.addAll(resourceList); +// } + if (needPage) { + break; + } + } + } + return resultList; + } + @Override public JSONArray getTbodyList(List fieldList, List resourceList, ResourceEntityVo resourceEntityVo) { JSONArray tbodyList = new JSONArray(); @@ -1107,6 +1187,13 @@ public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataS return appEnvList; } + @Override + public List getAppEnvListByAppSystemId(Long appSystemId) { + List appEnvList = resourceMapper.getAppEnvListByAppSystemId(appSystemId); + appEnvList.sort(Comparator.comparing(AppEnvVo::getSeqNo)); + return appEnvList; + } + @Override public List getStateListForSelect(BasePageVo searchVo) { List stateList = new ArrayList<>(); @@ -1163,6 +1250,51 @@ public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataS return vendorList; } + @Override + public Map> getAppResourceTypeIdListByAppSystemId(Long appSystemId) { + Map> viewName2TypeIdListMap = new HashMap<>(); + List appViewList = getAppViewList(); + if (CollectionUtils.isNotEmpty(appViewList)) { + for (ResourceEntityVo resourceEntityVo : appViewList) { + List typeIdList = resourceMapper.getAppResourceTypeIdListByViewNameAndAppSystemId(resourceEntityVo.getName(), appSystemId, null, null); + viewName2TypeIdListMap.put(resourceEntityVo.getName(), typeIdList); + } + } + return viewName2TypeIdListMap; + } + + @Override + public Map> getAppResourceTypeIdListByAppSystemIdAndAppModuleIdAndEnvId(Long appSystemId, Long appModuleId, Long envId) { + Map> viewName2TypeIdListMap = new HashMap<>(); + List appViewList = getAppViewList(); + if (CollectionUtils.isNotEmpty(appViewList)) { + for (ResourceEntityVo resourceEntityVo : appViewList) { + List typeIdList = resourceMapper.getAppResourceTypeIdListByViewNameAndAppSystemId(resourceEntityVo.getName(), appSystemId, appModuleId, envId); + viewName2TypeIdListMap.put(resourceEntityVo.getName(), typeIdList); + } + } + return viewName2TypeIdListMap; + } + + private List getAppViewList() { + List resultList = new ArrayList<>(); + List resourceEntityList = resourceEntityMapper.getResourceEntityList(); + for (ResourceEntityVo resourceEntityVo : resourceEntityList) { + SceneEntityVo sceneEntityVo = ResourceEntityFactory.getSceneEntityByViewName(resourceEntityVo.getName()); + if (sceneEntityVo == null) { + String config = resourceEntityMapper.getResourceEntityConfigByName(resourceEntityVo.getName()); + if (StringUtils.isNotBlank(config)) { + ResourceEntityConfigVo resourceEntityConfigVo = JSONObject.parseObject(config, ResourceEntityConfigVo.class); + if (Objects.equals(resourceEntityConfigVo.getSceneTemplateName(), "")) { + resourceEntityVo.setConfig(resourceEntityConfigVo); + resultList.add(resourceEntityVo); + } + } + } + } + return resultList; + } + /** * 判断是否有过滤条件 * @param searchVo @@ -1222,4 +1354,6 @@ public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataS } return null; } + + } diff --git a/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/IResourceCenterResourceService.java b/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/IResourceCenterResourceService.java index 3d761c5c..1f79af15 100644 --- a/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/IResourceCenterResourceService.java +++ b/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/IResourceCenterResourceService.java @@ -20,13 +20,11 @@ import com.alibaba.fastjson.JSONObject; import neatlogic.framework.cmdb.crossover.IResourceCenterResourceCrossoverService; import neatlogic.framework.cmdb.dto.ci.CiVo; import neatlogic.framework.cmdb.dto.resourcecenter.AccountVo; -import neatlogic.framework.cmdb.dto.resourcecenter.AppEnvVo; import neatlogic.framework.cmdb.dto.resourcecenter.ResourceSearchVo; import neatlogic.framework.cmdb.dto.resourcecenter.ResourceVo; import neatlogic.framework.cmdb.dto.resourcecenter.config.ResourceEntityVo; import neatlogic.framework.cmdb.dto.tag.TagVo; -import java.util.Collection; import java.util.List; import java.util.Map; @@ -140,13 +138,13 @@ public interface IResourceCenterResourceService extends IResourceCenterResourceC */ void addAccountInformation(List resourceList); - /** - * 获取模块列表 - * - * @param searchVo resourceSearchVo - * @return 模块列表 - */ - List getAppModuleList(ResourceSearchVo searchVo); +// /** +// * 获取模块列表 +// * +// * @param searchVo resourceSearchVo +// * @return 模块列表 +// */ +// List getAppModuleList(ResourceSearchVo searchVo); /** @@ -155,7 +153,7 @@ public interface IResourceCenterResourceService extends IResourceCenterResourceC * @param searchVo resourceSearchVo * @return 应用巡检批量巡检时的环境列表 */ - Collection getAppEnvList(ResourceSearchVo searchVo); +// Collection getAppEnvList(ResourceSearchVo searchVo); /** * 重建资源中心视图 diff --git a/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java b/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java index 04190d62..44f70580 100644 --- a/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java +++ b/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java @@ -53,10 +53,7 @@ import neatlogic.module.cmdb.dao.mapper.ci.AttrMapper; import neatlogic.module.cmdb.dao.mapper.ci.CiMapper; import neatlogic.module.cmdb.dao.mapper.cientity.CiEntityMapper; import neatlogic.module.cmdb.dao.mapper.globalattr.GlobalAttrMapper; -import neatlogic.module.cmdb.dao.mapper.resourcecenter.ResourceAccountMapper; -import neatlogic.module.cmdb.dao.mapper.resourcecenter.ResourceEntityMapper; -import neatlogic.module.cmdb.dao.mapper.resourcecenter.ResourceMapper; -import neatlogic.module.cmdb.dao.mapper.resourcecenter.ResourceTagMapper; +import neatlogic.module.cmdb.dao.mapper.resourcecenter.*; import neatlogic.module.cmdb.utils.ResourceEntityFactory; import net.sf.jsqlparser.schema.Table; import net.sf.jsqlparser.statement.create.table.ColDataType; @@ -83,6 +80,8 @@ public class ResourceCenterResourceServiceImpl implements IResourceCenterResourc @Resource ResourceMapper resourceMapper; @Resource + ResourceTempMapper resourceTempMapper; + @Resource ResourceTagMapper resourceTagMapper; @Resource ResourceAccountMapper resourceAccountMapper; @@ -451,10 +450,10 @@ public class ResourceCenterResourceServiceImpl implements IResourceCenterResourc if (ciEntityVo == null) { throw new AppModuleNotFoundException(appModuleId); } - Set resourceTypeIdSet = resourceMapper.getIpObjectResourceTypeIdListByAppModuleIdAndEnvId(searchVo); + Set resourceTypeIdSet = resourceTempMapper.getIpObjectResourceTypeIdListByAppModuleIdAndEnvId(searchVo); resourceTypeIdList.addAll(resourceTypeIdSet); if (CollectionUtils.isNotEmpty(resourceTypeIdSet)) { - resourceTypeIdSet = resourceMapper.getOsResourceTypeIdListByAppModuleIdAndEnvId(searchVo); + resourceTypeIdSet = resourceTempMapper.getOsResourceTypeIdListByAppModuleIdAndEnvId(searchVo); resourceTypeIdList.addAll(resourceTypeIdSet); } } else if (appSystemId != null) { @@ -462,10 +461,10 @@ public class ResourceCenterResourceServiceImpl implements IResourceCenterResourc if (ciEntityVo == null) { throw new AppSystemNotFoundException(appSystemId); } - Set resourceTypeIdSet = resourceMapper.getIpObjectResourceTypeIdListByAppSystemIdAndEnvId(searchVo); + Set resourceTypeIdSet = resourceTempMapper.getIpObjectResourceTypeIdListByAppSystemIdAndEnvId(searchVo); resourceTypeIdList.addAll(resourceTypeIdSet); if (CollectionUtils.isNotEmpty(resourceTypeIdSet)) { - resourceTypeIdSet = resourceMapper.getOsResourceTypeIdListByAppSystemIdAndEnvId(searchVo); + resourceTypeIdSet = resourceTempMapper.getOsResourceTypeIdListByAppSystemIdAndEnvId(searchVo); resourceTypeIdList.addAll(resourceTypeIdSet); } } @@ -497,10 +496,10 @@ public class ResourceCenterResourceServiceImpl implements IResourceCenterResourc @PostConstruct public void searchDispatcherInit() { searchMap.put("ipObject", (searchVo) -> { - int rowNum = resourceMapper.getIpObjectResourceCountByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(searchVo); + int rowNum = resourceTempMapper.getIpObjectResourceCountByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(searchVo); if (rowNum > 0) { searchVo.setRowNum(rowNum); - List idList = resourceMapper.getIpObjectResourceIdListByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(searchVo); + List idList = resourceTempMapper.getIpObjectResourceIdListByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(searchVo); if (CollectionUtils.isNotEmpty(idList)) { return resourceMapper.getResourceListByIdList(idList); } @@ -509,22 +508,22 @@ public class ResourceCenterResourceServiceImpl implements IResourceCenterResourc }); searchMap.put("OS", (searchVo) -> { - int rowNum = resourceMapper.getOsResourceCountByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(searchVo); + int rowNum = resourceTempMapper.getOsResourceCountByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(searchVo); if (rowNum > 0) { searchVo.setRowNum(rowNum); List idList = resourceMapper.getOsResourceIdListByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(searchVo); if (CollectionUtils.isNotEmpty(idList)) { - return resourceMapper.getOsResourceListByIdList(idList); + return resourceTempMapper.getOsResourceListByIdList(idList); } } return new ArrayList<>(); }); searchMap.put("APPIns", (searchVo) -> { - int rowNum = resourceMapper.getIpObjectResourceCountByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(searchVo); + int rowNum = resourceTempMapper.getIpObjectResourceCountByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(searchVo); if (rowNum > 0) { searchVo.setRowNum(rowNum); - List idList = resourceMapper.getIpObjectResourceIdListByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(searchVo); + List idList = resourceTempMapper.getIpObjectResourceIdListByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(searchVo); if (CollectionUtils.isNotEmpty(idList)) { return resourceMapper.getAppInstanceResourceListByIdList(idList); } @@ -533,12 +532,12 @@ public class ResourceCenterResourceServiceImpl implements IResourceCenterResourc }); searchMap.put("DBIns", (searchVo) -> { - int rowNum = resourceMapper.getIpObjectResourceCountByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(searchVo); + int rowNum = resourceTempMapper.getIpObjectResourceCountByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(searchVo); if (rowNum > 0) { searchVo.setRowNum(rowNum); - List idList = resourceMapper.getIpObjectResourceIdListByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(searchVo); + List idList = resourceTempMapper.getIpObjectResourceIdListByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(searchVo); if (CollectionUtils.isNotEmpty(idList)) { - return resourceMapper.getDbInstanceResourceListByIdList(idList); + return resourceTempMapper.getDbInstanceResourceListByIdList(idList); } } return new ArrayList<>(); @@ -601,116 +600,116 @@ public class ResourceCenterResourceServiceImpl implements IResourceCenterResourc } } - @Override - public List getAppModuleList(ResourceSearchVo searchVo) { - int count = resourceMapper.searchAppModuleCount(searchVo); - if (count > 0) { - searchVo.setRowNum(count); - List idList = resourceMapper.searchAppModuleIdList(searchVo); - if (CollectionUtils.isNotEmpty(idList)) { - return resourceMapper.searchAppModule(idList); - } - } - return new ArrayList<>(); - } - - @Override - public Collection getAppEnvList(ResourceSearchVo searchVo) { - CiEntityVo ciEntityVo = ciEntityMapper.getCiEntityBaseInfoById(searchVo.getAppSystemId()); - if (ciEntityVo == null) { - throw new AppSystemNotFoundException(searchVo.getAppSystemId()); - } - Set resourceTypeIdSet = resourceMapper.getIpObjectResourceTypeIdListByAppSystemIdAndEnvId(searchVo); - List resourceTypeIdList = new ArrayList<>(resourceTypeIdSet); - if (CollectionUtils.isNotEmpty(resourceTypeIdSet)) { - resourceTypeIdSet = resourceMapper.getOsResourceTypeIdListByAppSystemIdAndEnvId(searchVo); - resourceTypeIdList.addAll(resourceTypeIdSet); - } - - if (CollectionUtils.isNotEmpty(resourceTypeIdList)) { - Map returnEnvMap = new HashMap<>(); - Map> envIdModuleIdSetMap = new HashMap<>(); - Map> envIdModuleListMap = new HashMap<>(); - Map> envModuleIdCiIdSetMap = new HashMap<>(); - Map> envModuleIdCiListMap = new HashMap<>(); - List ciList = ciMapper.getAllCi(resourceTypeIdList); - List resourceCiVoList = ciMapper.getCiListByNameList(AppModuleResourceType.getNameList()); - - for (CiVo ciVo : ciList) { - List appEnvList = new ArrayList<>(); - String resourceTypeName = getResourceTypeName(resourceCiVoList, ciVo); - if (StringUtils.isBlank(resourceTypeName)) { - continue; - } - String actionKey = AppModuleResourceType.getAction(resourceTypeName); - if (StringUtils.isBlank(actionKey)) { - continue; - } - searchVo.setTypeId(ciVo.getId()); - if (actionKey.equals("OS")) { - appEnvList.addAll(resourceMapper.getOsEnvListByAppSystemIdAndTypeId(searchVo)); - } else { - appEnvList.addAll(resourceMapper.getIpObjectEnvListByAppSystemIdAndTypeId(searchVo)); - } +// @Override +// public List getAppModuleList(ResourceSearchVo searchVo) { +// int count = resourceMapper.searchAppModuleCount(searchVo); +// if (count > 0) { +// searchVo.setRowNum(count); +// List idList = resourceMapper.searchAppModuleIdList(searchVo); +// if (CollectionUtils.isNotEmpty(idList)) { +// return resourceMapper.searchAppModule(idList); +// } +// } +// return new ArrayList<>(); +// } - /*数据处理 - 1、returnEnvMap 环境List - 2、envIdModuleIdSetMap 环境id对应的 模块id列表 - 3、envModuleIdCiIdSetMap 环境id+模块id对应的 模型id列表 - */ - if (CollectionUtils.isNotEmpty(appEnvList)) { - for (AppEnvVo envVo : appEnvList) { - //未配置情况,环境id设为-2,因为id为-1的一般都是代表 所有 的意思 - if (envVo.getId() == null) { - envVo.setId(-2L); - envVo.setName("未配置"); - envVo.setSeqNo(9999); - } - Long envId = envVo.getId(); - returnEnvMap.put(envId, envVo); - List appModuleList = envVo.getAppModuleList(); - Set appModuleIdSet = appModuleList.stream().map(AppModuleVo::getId).collect(Collectors.toSet()); - if (envIdModuleIdSetMap.containsKey(envId)) { - for (AppModuleVo moduleVo : appModuleList) { - if (envIdModuleIdSetMap.get(envId).contains(moduleVo.getId())) { - List ciVoList = moduleVo.getCiList(); - for (CiVo ci : ciVoList) { - if (CollectionUtils.isNotEmpty(envModuleIdCiIdSetMap.get(envId + moduleVo.getId())) && !envModuleIdCiIdSetMap.get(envId + moduleVo.getId()).contains(ci.getId())) { - envModuleIdCiIdSetMap.get(envId + moduleVo.getId()).add(ci.getId()); - envModuleIdCiListMap.get(envId + moduleVo.getId()).add(ci); - } - } - } else { - envIdModuleIdSetMap.get(envId).add(moduleVo.getId()); - envIdModuleListMap.get(envId).add(moduleVo); - envModuleIdCiIdSetMap.put(envId + moduleVo.getId(), moduleVo.getCiList().stream().map(CiVo::getId).collect(Collectors.toSet())); - envModuleIdCiListMap.put(envId + moduleVo.getId(), moduleVo.getCiList()); - } - } - envIdModuleIdSetMap.get(envId).addAll(appModuleIdSet); - } else { - envIdModuleIdSetMap.put(envId, appModuleIdSet); - envIdModuleListMap.put(envId, appModuleList); - for (AppModuleVo moduleVo : appModuleList) { - envModuleIdCiIdSetMap.put(envId + moduleVo.getId(), moduleVo.getCiList().stream().map(CiVo::getId).collect(Collectors.toSet())); - envModuleIdCiListMap.put(envId + moduleVo.getId(), moduleVo.getCiList()); - } - } - } - } - } - for (Map.Entry entry : returnEnvMap.entrySet()) { - List appModuleVoList = envIdModuleListMap.get(entry.getKey()); - for (AppModuleVo appModuleVo : appModuleVoList) { - List ciVoList = envModuleIdCiListMap.get(entry.getKey() + appModuleVo.getId()); - appModuleVo.setCiList(ciVoList); - } - entry.getValue().setAppModuleList(appModuleVoList); - } - return returnEnvMap.values().stream().sorted(Comparator.comparing(AppEnvVo::getSeqNo)).collect(Collectors.toList()); - } - return null; - } +// @Override +// public Collection getAppEnvList(ResourceSearchVo searchVo) { +// CiEntityVo ciEntityVo = ciEntityMapper.getCiEntityBaseInfoById(searchVo.getAppSystemId()); +// if (ciEntityVo == null) { +// throw new AppSystemNotFoundException(searchVo.getAppSystemId()); +// } +// Set resourceTypeIdSet = resourceMapper.getIpObjectResourceTypeIdListByAppSystemIdAndEnvId(searchVo); +// List resourceTypeIdList = new ArrayList<>(resourceTypeIdSet); +// if (CollectionUtils.isNotEmpty(resourceTypeIdSet)) { +// resourceTypeIdSet = resourceMapper.getOsResourceTypeIdListByAppSystemIdAndEnvId(searchVo); +// resourceTypeIdList.addAll(resourceTypeIdSet); +// } +// +// if (CollectionUtils.isNotEmpty(resourceTypeIdList)) { +// Map returnEnvMap = new HashMap<>(); +// Map> envIdModuleIdSetMap = new HashMap<>(); +// Map> envIdModuleListMap = new HashMap<>(); +// Map> envModuleIdCiIdSetMap = new HashMap<>(); +// Map> envModuleIdCiListMap = new HashMap<>(); +// List ciList = ciMapper.getAllCi(resourceTypeIdList); +// List resourceCiVoList = ciMapper.getCiListByNameList(AppModuleResourceType.getNameList()); +// +// for (CiVo ciVo : ciList) { +// List appEnvList = new ArrayList<>(); +// String resourceTypeName = getResourceTypeName(resourceCiVoList, ciVo); +// if (StringUtils.isBlank(resourceTypeName)) { +// continue; +// } +// String actionKey = AppModuleResourceType.getAction(resourceTypeName); +// if (StringUtils.isBlank(actionKey)) { +// continue; +// } +// searchVo.setTypeId(ciVo.getId()); +// if (actionKey.equals("OS")) { +// appEnvList.addAll(resourceMapper.getOsEnvListByAppSystemIdAndTypeId(searchVo)); +// } else { +// appEnvList.addAll(resourceMapper.getIpObjectEnvListByAppSystemIdAndTypeId(searchVo)); +// } +// +// /*数据处理 +// 1、returnEnvMap 环境List +// 2、envIdModuleIdSetMap 环境id对应的 模块id列表 +// 3、envModuleIdCiIdSetMap 环境id+模块id对应的 模型id列表 +// */ +// if (CollectionUtils.isNotEmpty(appEnvList)) { +// for (AppEnvVo envVo : appEnvList) { +// //未配置情况,环境id设为-2,因为id为-1的一般都是代表 所有 的意思 +// if (envVo.getId() == null) { +// envVo.setId(-2L); +// envVo.setName("未配置"); +// envVo.setSeqNo(9999); +// } +// Long envId = envVo.getId(); +// returnEnvMap.put(envId, envVo); +// List appModuleList = envVo.getAppModuleList(); +// Set appModuleIdSet = appModuleList.stream().map(AppModuleVo::getId).collect(Collectors.toSet()); +// if (envIdModuleIdSetMap.containsKey(envId)) { +// for (AppModuleVo moduleVo : appModuleList) { +// if (envIdModuleIdSetMap.get(envId).contains(moduleVo.getId())) { +// List ciVoList = moduleVo.getCiList(); +// for (CiVo ci : ciVoList) { +// if (CollectionUtils.isNotEmpty(envModuleIdCiIdSetMap.get(envId + moduleVo.getId())) && !envModuleIdCiIdSetMap.get(envId + moduleVo.getId()).contains(ci.getId())) { +// envModuleIdCiIdSetMap.get(envId + moduleVo.getId()).add(ci.getId()); +// envModuleIdCiListMap.get(envId + moduleVo.getId()).add(ci); +// } +// } +// } else { +// envIdModuleIdSetMap.get(envId).add(moduleVo.getId()); +// envIdModuleListMap.get(envId).add(moduleVo); +// envModuleIdCiIdSetMap.put(envId + moduleVo.getId(), moduleVo.getCiList().stream().map(CiVo::getId).collect(Collectors.toSet())); +// envModuleIdCiListMap.put(envId + moduleVo.getId(), moduleVo.getCiList()); +// } +// } +// envIdModuleIdSetMap.get(envId).addAll(appModuleIdSet); +// } else { +// envIdModuleIdSetMap.put(envId, appModuleIdSet); +// envIdModuleListMap.put(envId, appModuleList); +// for (AppModuleVo moduleVo : appModuleList) { +// envModuleIdCiIdSetMap.put(envId + moduleVo.getId(), moduleVo.getCiList().stream().map(CiVo::getId).collect(Collectors.toSet())); +// envModuleIdCiListMap.put(envId + moduleVo.getId(), moduleVo.getCiList()); +// } +// } +// } +// } +// } +// for (Map.Entry entry : returnEnvMap.entrySet()) { +// List appModuleVoList = envIdModuleListMap.get(entry.getKey()); +// for (AppModuleVo appModuleVo : appModuleVoList) { +// List ciVoList = envModuleIdCiListMap.get(entry.getKey() + appModuleVo.getId()); +// appModuleVo.setCiList(ciVoList); +// } +// entry.getValue().setAppModuleList(appModuleVoList); +// } +// return returnEnvMap.values().stream().sorted(Comparator.comparing(AppEnvVo::getSeqNo)).collect(Collectors.toList()); +// } +// return null; +// } @Override @Deprecated -- Gitee From d33126b03400261abcfd5ecb2088df9f15123f24 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Fri, 21 Mar 2025 17:26:07 +0800 Subject: [PATCH 22/29] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20CMDB=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E6=B8=85=E5=8D=95=E6=94=B9=E6=88=90=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E5=B1=82=E7=BA=A7=E5=8F=AF=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1349157963399168]CMDB应用清单改成模型层级可配置 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1349157963399168 --- .../app/AppResourceListApi.java | 2 +- .../appmodule/AppModuleResourceListApi.java | 1 + .../config/ListResourceEntityApi.java | 27 ++- .../resourcecenter/ResourceEntityMapper.xml | 1 + .../DefaultResourceCenterDataSourceImpl.java | 54 ++--- .../IResourceCenterResourceService.java | 8 +- .../ResourceCenterResourceServiceImpl.java | 196 +++++++++--------- .../cmdb/utils/ResourceEntityFactory.java | 3 + 8 files changed, 144 insertions(+), 148 deletions(-) diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/app/AppResourceListApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/app/AppResourceListApi.java index 83127773..68263d31 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/app/AppResourceListApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/app/AppResourceListApi.java @@ -85,7 +85,7 @@ public class AppResourceListApi extends PrivateApiComponentBase { } String viewName = paramObj.getString("viewName"); IResourceCenterDataSource resourceCenterDataSource = ResourceCenterDataSourceFactory.getResourceCenterDataSource(); - JSONArray tableList = resourceCenterDataSource.getAppResourceList(appSystemId, appModuleId, envId, typeIdList, viewName, currentPage, pageSize); + JSONArray tableList = resourceCenterDataSource.getAppResourceList(appSystemId, appModuleId, envId, null, viewName, currentPage, pageSize); resultObj.put("tableList", tableList); return resultObj; } diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/appmodule/AppModuleResourceListApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/appmodule/AppModuleResourceListApi.java index 29243743..fcd7a6eb 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/appmodule/AppModuleResourceListApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/appmodule/AppModuleResourceListApi.java @@ -34,6 +34,7 @@ import javax.annotation.Resource; * @since 2021/6/17 11:54 **/ @Service +@Deprecated @AuthAction(action = CMDB_BASE.class) @OperationType(type = OperationTypeEnum.SEARCH) public class AppModuleResourceListApi extends PrivateApiComponentBase { diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/ListResourceEntityApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/ListResourceEntityApi.java index 8a945512..cf825868 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/ListResourceEntityApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/config/ListResourceEntityApi.java @@ -22,6 +22,8 @@ import neatlogic.framework.cmdb.dto.resourcecenter.config.ResourceEntityConfigVo import neatlogic.framework.cmdb.dto.resourcecenter.config.ResourceEntityVo; import neatlogic.framework.cmdb.dto.resourcecenter.config.SceneEntityVo; import neatlogic.framework.cmdb.enums.resourcecenter.Status; +import neatlogic.framework.common.util.ModuleUtil; +import neatlogic.framework.dto.module.ModuleVo; import neatlogic.framework.restful.annotation.Description; import neatlogic.framework.restful.annotation.OperationType; import neatlogic.framework.restful.annotation.Output; @@ -73,12 +75,11 @@ public class ListResourceEntityApi extends PrivateApiComponentBase { @Override public Object myDoService(JSONObject paramObj) throws Exception { List resultList = new ArrayList<>(); - List viewNameList = ResourceEntityFactory.getViewNameList(); - List resourceEntityList = resourceEntityMapper.getResourceEntityListByNameList(viewNameList); - Map resourceEntityVoMap = resourceEntityList.stream().collect(Collectors.toMap(ResourceEntityVo::getName, e -> e)); + List allResourceEntityList = resourceEntityMapper.getResourceEntityList(); + Map resourceEntityVoMap = allResourceEntityList.stream().collect(Collectors.toMap(ResourceEntityVo::getName, e -> e)); List sceneEntityList = ResourceEntityFactory.getSceneEntityList(); for (SceneEntityVo sceneEntityVo : sceneEntityList) { - ResourceEntityVo resourceEntityVo = resourceEntityVoMap.get(sceneEntityVo.getName()); + ResourceEntityVo resourceEntityVo = resourceEntityVoMap.remove(sceneEntityVo.getName()); if (resourceEntityVo == null) { resourceEntityVo = new ResourceEntityVo(); resourceEntityVo.setStatus(Status.PENDING.getValue()); @@ -87,6 +88,13 @@ public class ListResourceEntityApi extends PrivateApiComponentBase { resourceEntityVo.setLabel(sceneEntityVo.getLabel()); resourceEntityVo.setDescription(sceneEntityVo.getDescription()); resourceEntityVo.setIsMultiple(sceneEntityVo.getIsMultiple()); + resourceEntityVo.setModuleId(sceneEntityVo.getModuleId()); + ModuleVo moduleVo = ModuleUtil.getModuleById(sceneEntityVo.getModuleId()); + if (moduleVo != null) { + resourceEntityVo.setModuleName(moduleVo.getName()); + } else { + resourceEntityVo.setModuleName(sceneEntityVo.getModuleId()); + } try { resourceEntityMapper.getResourceEntityViewDataList(sceneEntityVo.getName(), 0, 1); } catch (Exception e) { @@ -101,8 +109,8 @@ public class ListResourceEntityApi extends PrivateApiComponentBase { resultList.add(resourceEntityVo); } // 扩展视图 - List allResourceEntityList = resourceEntityMapper.getResourceEntityList(); - for (ResourceEntityVo resourceEntityVo : allResourceEntityList) { + for (Map.Entry entry : resourceEntityVoMap.entrySet()) { + ResourceEntityVo resourceEntityVo = entry.getValue(); SceneEntityVo sceneEntityVo = ResourceEntityFactory.getSceneEntityByViewName(resourceEntityVo.getName()); if (sceneEntityVo == null) { String config = resourceEntityMapper.getResourceEntityConfigByName(resourceEntityVo.getName()); @@ -114,6 +122,13 @@ public class ListResourceEntityApi extends PrivateApiComponentBase { SceneEntityVo sceneTemplate = ResourceEntityFactory.getSceneEntityByViewName(sceneTemplateName); if (sceneTemplate != null) { resourceEntityVo.setIsMultiple(sceneTemplate.getIsMultiple()); + resourceEntityVo.setModuleId(sceneTemplate.getModuleId()); + ModuleVo moduleVo = ModuleUtil.getModuleById(sceneTemplate.getModuleId()); + if (moduleVo != null) { + resourceEntityVo.setModuleName(moduleVo.getName()); + } else { + resourceEntityVo.setModuleName(sceneTemplate.getModuleId()); + } try { resourceEntityMapper.getResourceEntityViewDataList(resourceEntityVo.getName(), 0, 1); } catch (Exception e) { diff --git a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceEntityMapper.xml b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceEntityMapper.xml index 09980d45..b5a64abb 100644 --- a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceEntityMapper.xml +++ b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceEntityMapper.xml @@ -35,6 +35,7 @@ along with this program. If not, see .--> - @@ -1079,11 +1079,11 @@ along with this program. If not, see .--> - .--> + + diff --git a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceTempMapper.java b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceTempMapper.java index 21356409..77f4a8c1 100644 --- a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceTempMapper.java +++ b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceTempMapper.java @@ -42,4 +42,6 @@ public interface ResourceTempMapper { List getDbInstanceResourceListByIdList(List idList); List getOsResourceListByIdList(List idList); + + List getOsResourceIdListByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(ResourceSearchVo searchVo); } diff --git a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceTempMapper.xml b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceTempMapper.xml index eae77a44..b7ec9204 100644 --- a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceTempMapper.xml +++ b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceTempMapper.xml @@ -278,4 +278,31 @@ #{id} + + \ No newline at end of file diff --git a/src/main/java/neatlogic/module/cmdb/resourcecenter/datasource/handler/DefaultResourceCenterDataSourceImpl.java b/src/main/java/neatlogic/module/cmdb/resourcecenter/datasource/handler/DefaultResourceCenterDataSourceImpl.java index 34f78f00..798c4060 100644 --- a/src/main/java/neatlogic/module/cmdb/resourcecenter/datasource/handler/DefaultResourceCenterDataSourceImpl.java +++ b/src/main/java/neatlogic/module/cmdb/resourcecenter/datasource/handler/DefaultResourceCenterDataSourceImpl.java @@ -28,7 +28,6 @@ import neatlogic.framework.cmdb.dto.resourcecenter.config.ResourceEntityConfigVo import neatlogic.framework.cmdb.dto.resourcecenter.config.ResourceEntityFieldMappingVo; import neatlogic.framework.cmdb.dto.resourcecenter.config.ResourceEntityVo; import neatlogic.framework.cmdb.dto.resourcecenter.config.SceneEntityVo; -import neatlogic.framework.cmdb.exception.ci.CiNotFoundException; import neatlogic.framework.cmdb.exception.resourcecenter.AppModuleNotFoundException; import neatlogic.framework.cmdb.exception.resourcecenter.AppSystemNotFoundException; import neatlogic.framework.cmdb.resourcecenter.datasource.core.IResourceCenterDataSource; @@ -77,13 +76,12 @@ public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataS @Resource private IResourceCenterResourceService resourceCenterResourceService; - private final Map> map = new HashMap<>();//BiFunction + private final Map> headFieldHandlerMap = new LinkedHashMap<>(); @PostConstruct public void init() { - map.put(new ValueTextVo("id", "ID"), (resourceVo, cacheData) -> resourceVo.getId()); - map.put(new ValueTextVo("name", "名称"), (resourceVo, cacheData) -> resourceVo.getName()); - map.put(new ValueTextVo("ip", "IP地址"), (resourceVo, cacheData) -> { + headFieldHandlerMap.put(new ValueTextVo("id", "ID"), (resourceVo, cacheData) -> resourceVo.getId()); + headFieldHandlerMap.put(new ValueTextVo("ip", "IP地址"), (resourceVo, cacheData) -> { JSONObject resultObj = new JSONObject(); resultObj.put("ip", resourceVo.getIp()); resultObj.put("port", resourceVo.getPort()); @@ -91,7 +89,7 @@ public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataS resultObj.put("id", resourceVo.getId()); return resultObj; }); - map.put(new ValueTextVo("ci", "模型"), (resourceVo, cacheData) -> { + headFieldHandlerMap.put(new ValueTextVo("ci", "模型"), (resourceVo, cacheData) -> { if (resourceVo.getTypeId() == null) { return null; } @@ -109,35 +107,21 @@ public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataS } return resultObj; }); - - map.put(new ValueTextVo("fcu", "创建者"), (resourceVo, cacheData) -> { - String fcu = resourceVo.getFcu(); - if (StringUtils.isNotBlank(fcu)) { - JSONObject resultObj = new JSONObject(); - resultObj.put("uuid", fcu); - resultObj.put("initType", "user"); - return resultObj; + headFieldHandlerMap.put(new ValueTextVo("name", "名称"), (resourceVo, cacheData) -> resourceVo.getName()); + headFieldHandlerMap.put(new ValueTextVo("monitor", "监控状态"), (resourceVo, cacheData) -> { + JSONObject resultObj = new JSONObject(); + if (StringUtils.isNotBlank(resourceVo.getMonitorStatus())) { + JSONObject statusJson = InspectStatus.getInspectStatusJson(resourceVo.getMonitorStatus()); + if (MapUtils.isNotEmpty(statusJson)) { + resultObj.putAll(statusJson); + } } - return null; - }); - map.put(new ValueTextVo("fcd", "创建日期"), (resourceVo, cacheData) -> resourceVo.getFcd()); - map.put(new ValueTextVo("lcu", "修改者"), (resourceVo, cacheData) -> { - String lcu = resourceVo.getLcu(); - if (StringUtils.isNotBlank(lcu)) { - JSONObject resultObj = new JSONObject(); - resultObj.put("uuid", lcu); - resultObj.put("initType", "user"); - return resultObj; + if (resourceVo.getMonitorTime() != null) { + resultObj.put("time", resourceVo.getMonitorTime()); } - return null; + return resultObj; }); - map.put(new ValueTextVo("lcd", "修改日期"), (resourceVo, cacheData) -> resourceVo.getLcd()); - - map.put(new ValueTextVo("maintenanceWindow", "维护窗口"), (resourceVo, cacheData) -> resourceVo.getMaintenanceWindow()); - map.put(new ValueTextVo("description", "描述"), (resourceVo, cacheData) -> resourceVo.getDescription()); - map.put(new ValueTextVo("networkArea", "网络区域"), (resourceVo, cacheData) -> resourceVo.getNetworkArea()); - - map.put(new ValueTextVo("inspect", "巡检状态"), (resourceVo, cacheData) -> { + headFieldHandlerMap.put(new ValueTextVo("inspect", "巡检状态"), (resourceVo, cacheData) -> { JSONObject resultObj = new JSONObject(); if (StringUtils.isNotBlank(resourceVo.getInspectStatus())) { JSONObject statusJson = InspectStatus.getInspectStatusJson(resourceVo.getInspectStatus()); @@ -150,60 +134,99 @@ public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataS } return resultObj; }); -// map.put(new ValueTextVo("inspectTime", "巡检时间"), (resourceVo, cacheData) -> resourceVo.getInspectTime()); - map.put(new ValueTextVo("monitor", "监控状态"), (resourceVo, cacheData) -> { + headFieldHandlerMap.put(new ValueTextVo("appEnvironment", "应用环境"), (resourceVo, cacheData) -> { + if (resourceVo.getEnvId() == null) { + return null; + } JSONObject resultObj = new JSONObject(); - if (StringUtils.isNotBlank(resourceVo.getMonitorStatus())) { - JSONObject statusJson = InspectStatus.getInspectStatusJson(resourceVo.getMonitorStatus()); - if (MapUtils.isNotEmpty(statusJson)) { - resultObj.putAll(statusJson); + Object obj = cacheData.get(resourceVo.getEnvId().toString()); + if (obj != null) { + if (obj instanceof GlobalAttrItemVo) { + GlobalAttrItemVo globalAttrItemVo = (GlobalAttrItemVo) obj; + resultObj.put("id", globalAttrItemVo.getId()); + resultObj.put("value", globalAttrItemVo.getValue()); + resultObj.put("attrId", globalAttrItemVo.getAttrId()); + resultObj.put("type", "globalAttr"); + } else if (obj instanceof CiEntityVo) { + CiEntityVo ciEntityVo = (CiEntityVo) obj; + resultObj = getResultObj(ciEntityVo); + resultObj.put("type", "attr"); } + } else { + resultObj.put("id", resourceVo.getEnvId()); + resultObj.put("name", resourceVo.getEnvName()); } - if (resourceVo.getMonitorTime() != null) { - resultObj.put("time", resourceVo.getMonitorTime()); + return resultObj; + }); + headFieldHandlerMap.put(new ValueTextVo("appModule", "应用模块"), (resourceVo, cacheData) -> { + if (resourceVo.getAppModuleId() == null) { + return null; + } + JSONObject resultObj = new JSONObject(); + CiEntityVo ciEntityVo = cacheData.getObject(resourceVo.getAppModuleId().toString(), CiEntityVo.class); + if (ciEntityVo != null) { + resultObj = getResultObj(ciEntityVo); + resultObj.put("abbrName", resourceVo.getAppModuleAbbrName()); + } else { + resultObj.put("id", resourceVo.getAppModuleId()); + resultObj.put("name", resourceVo.getAppModuleName()); + resultObj.put("abbrName", resourceVo.getAppModuleAbbrName()); } return resultObj; }); -// map.put(new ValueTextVo("monitorTime", "监控时间"), (resourceVo, cacheData) -> resourceVo.getMonitorTime()); - -// map.put(new ValueTextVo("port", "端口"), (resourceVo, cacheData) -> resourceVo.getPort()); - map.put(new ValueTextVo("businessGroupList", "所属部门"), (resourceVo, cacheData) -> { + headFieldHandlerMap.put(new ValueTextVo("appSystem", "应用系统"), (resourceVo, cacheData) -> { + if (resourceVo.getAppSystemId() == null) { + return null; + } + JSONObject resultObj = new JSONObject(); + CiEntityVo ciEntityVo = cacheData.getObject(resourceVo.getAppSystemId().toString(), CiEntityVo.class); + if (ciEntityVo != null) { + resultObj = getResultObj(ciEntityVo); + resultObj.put("abbrName", resourceVo.getAppSystemAbbrName()); + } else { + resultObj.put("id", resourceVo.getAppSystemId()); + resultObj.put("name", resourceVo.getAppSystemName()); + resultObj.put("abbrName", resourceVo.getAppSystemAbbrName()); + } + return resultObj; + }); + headFieldHandlerMap.put(new ValueTextVo("allIpList", "IP列表"), (resourceVo, cacheData) -> { JSONArray resultList = new JSONArray(); - List bgList = resourceVo.getBgList(); - if (CollectionUtils.isNotEmpty(bgList)) { - for (BgVo bgVo : bgList) { + List ipList = resourceVo.getAllIp(); + if (CollectionUtils.isNotEmpty(ipList)) { + for (IpVo ipVo : ipList) { JSONObject resultObj = new JSONObject(); - CiEntityVo ciEntityVo = cacheData.getObject(bgVo.getBgId().toString(), CiEntityVo.class); + CiEntityVo ciEntityVo = cacheData.getObject(ipVo.getId().toString(), CiEntityVo.class); if (ciEntityVo != null) { resultObj = getResultObj(ciEntityVo); } else { - resultObj.put("id", bgVo.getBgId()); - resultObj.put("name", bgVo.getBgName()); + resultObj.put("id", ipVo.getId()); + resultObj.put("name", ipVo.getIp()); } resultList.add(resultObj); } } return resultList; }); - map.put(new ValueTextVo("allIpList", "IP列表"), (resourceVo, cacheData) -> { + headFieldHandlerMap.put(new ValueTextVo("businessGroupList", "所属部门"), (resourceVo, cacheData) -> { JSONArray resultList = new JSONArray(); - List ipList = resourceVo.getAllIp(); - if (CollectionUtils.isNotEmpty(ipList)) { - for (IpVo ipVo : ipList) { + List bgList = resourceVo.getBgList(); + if (CollectionUtils.isNotEmpty(bgList)) { + for (BgVo bgVo : bgList) { JSONObject resultObj = new JSONObject(); - CiEntityVo ciEntityVo = cacheData.getObject(ipVo.getId().toString(), CiEntityVo.class); + CiEntityVo ciEntityVo = cacheData.getObject(bgVo.getBgId().toString(), CiEntityVo.class); if (ciEntityVo != null) { resultObj = getResultObj(ciEntityVo); } else { - resultObj.put("id", ipVo.getId()); - resultObj.put("name", ipVo.getIp()); + resultObj.put("id", bgVo.getBgId()); + resultObj.put("name", bgVo.getBgName()); } resultList.add(resultObj); } } return resultList; }); - map.put(new ValueTextVo("ownerList", "所有者"), (resourceVo, cacheData) -> { + headFieldHandlerMap.put(new ValueTextVo("ownerList", "所有者"), (resourceVo, cacheData) -> { JSONArray resultList = new JSONArray(); List ownerList = resourceVo.getOwnerList(); if (CollectionUtils.isNotEmpty(ownerList)) { @@ -221,7 +244,7 @@ public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataS } return resultList; }); - map.put(new ValueTextVo("state", "资产状态"), (resourceVo, cacheData) -> { + headFieldHandlerMap.put(new ValueTextVo("state", "资产状态"), (resourceVo, cacheData) -> { if (resourceVo.getStateId() == null) { return null; } @@ -235,7 +258,12 @@ public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataS } return resultObj; }); - map.put(new ValueTextVo("vendor", "厂商"), (resourceVo, cacheData) -> { + headFieldHandlerMap.put(new ValueTextVo("networkArea", "网络区域"), (resourceVo, cacheData) -> resourceVo.getNetworkArea()); + headFieldHandlerMap.put(new ValueTextVo("maintenanceWindow", "维护窗口"), (resourceVo, cacheData) -> resourceVo.getMaintenanceWindow()); + headFieldHandlerMap.put(new ValueTextVo("tagList", "标签"), (resourceVo, cacheData) -> resourceVo.getTagList()); + headFieldHandlerMap.put(new ValueTextVo("accountList", "账号"), (resourceVo, cacheData) -> resourceVo.getAccountList()); + headFieldHandlerMap.put(new ValueTextVo("description", "描述"), (resourceVo, cacheData) -> resourceVo.getDescription()); + headFieldHandlerMap.put(new ValueTextVo("vendor", "厂商"), (resourceVo, cacheData) -> { if (resourceVo.getVendorId() == null) { return null; } @@ -250,7 +278,7 @@ public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataS return resultObj; }); - map.put(new ValueTextVo("dataCenter", "数据中心"), (resourceVo, cacheData) -> { + headFieldHandlerMap.put(new ValueTextVo("dataCenter", "数据中心"), (resourceVo, cacheData) -> { if (resourceVo.getDataCenterId() == null) { return null; } @@ -264,64 +292,28 @@ public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataS } return resultObj; }); - map.put(new ValueTextVo("appEnvironment", "应用环境"), (resourceVo, cacheData) -> { - if (resourceVo.getEnvId() == null) { - return null; - } - JSONObject resultObj = new JSONObject(); - Object obj = cacheData.get(resourceVo.getEnvId().toString()); - if (obj != null) { - if (obj instanceof GlobalAttrItemVo) { - GlobalAttrItemVo globalAttrItemVo = (GlobalAttrItemVo) obj; - resultObj.put("id", globalAttrItemVo.getId()); - resultObj.put("value", globalAttrItemVo.getValue()); - resultObj.put("attrId", globalAttrItemVo.getAttrId()); - resultObj.put("type", "globalAttr"); - } else if (obj instanceof CiEntityVo) { - CiEntityVo ciEntityVo = (CiEntityVo) obj; - resultObj = getResultObj(ciEntityVo); - resultObj.put("type", "attr"); - } - } else { - resultObj.put("id", resourceVo.getEnvId()); - resultObj.put("name", resourceVo.getEnvName()); - } - return resultObj; - }); - map.put(new ValueTextVo("appModule", "应用模块"), (resourceVo, cacheData) -> { - if (resourceVo.getAppModuleId() == null) { - return null; - } - JSONObject resultObj = new JSONObject(); - CiEntityVo ciEntityVo = cacheData.getObject(resourceVo.getAppModuleId().toString(), CiEntityVo.class); - if (ciEntityVo != null) { - resultObj = getResultObj(ciEntityVo); - resultObj.put("abbrName", resourceVo.getAppModuleAbbrName()); - } else { - resultObj.put("id", resourceVo.getAppModuleId()); - resultObj.put("name", resourceVo.getAppModuleName()); - resultObj.put("abbrName", resourceVo.getAppModuleAbbrName()); + headFieldHandlerMap.put(new ValueTextVo("fcu", "创建者"), (resourceVo, cacheData) -> { + String fcu = resourceVo.getFcu(); + if (StringUtils.isNotBlank(fcu)) { + JSONObject resultObj = new JSONObject(); + resultObj.put("uuid", fcu); + resultObj.put("initType", "user"); + return resultObj; } - return resultObj; + return null; }); - map.put(new ValueTextVo("appSystem", "应用系统"), (resourceVo, cacheData) -> { - if (resourceVo.getAppSystemId() == null) { - return null; - } - JSONObject resultObj = new JSONObject(); - CiEntityVo ciEntityVo = cacheData.getObject(resourceVo.getAppSystemId().toString(), CiEntityVo.class); - if (ciEntityVo != null) { - resultObj = getResultObj(ciEntityVo); - resultObj.put("abbrName", resourceVo.getAppSystemAbbrName()); - } else { - resultObj.put("id", resourceVo.getAppSystemId()); - resultObj.put("name", resourceVo.getAppSystemName()); - resultObj.put("abbrName", resourceVo.getAppSystemAbbrName()); + headFieldHandlerMap.put(new ValueTextVo("fcd", "创建日期"), (resourceVo, cacheData) -> resourceVo.getFcd()); + headFieldHandlerMap.put(new ValueTextVo("lcu", "修改者"), (resourceVo, cacheData) -> { + String lcu = resourceVo.getLcu(); + if (StringUtils.isNotBlank(lcu)) { + JSONObject resultObj = new JSONObject(); + resultObj.put("uuid", lcu); + resultObj.put("initType", "user"); + return resultObj; } - return resultObj; + return null; }); - map.put(new ValueTextVo("tagList", "标签"), (resourceVo, cacheData) -> resourceVo.getTagList()); - map.put(new ValueTextVo("accountList", "账号"), (resourceVo, cacheData) -> resourceVo.getAccountList()); + headFieldHandlerMap.put(new ValueTextVo("lcd", "修改日期"), (resourceVo, cacheData) -> resourceVo.getLcd()); } private JSONObject getResultObj(CiEntityVo ciEntityVo) { @@ -340,88 +332,6 @@ public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataS return Ordered.LOWEST_PRECEDENCE; } -// @Override - private JSONArray getAppResourceList2(Long appSystemId, Long appModuleId, Long envId, List typeIdList, Integer currentPage, Integer pageSize) { - if (appSystemId != null && ciEntityCachedMapper.getCiEntityBaseInfoById(appSystemId) == null) { - throw new AppSystemNotFoundException(appSystemId); - } - if (appModuleId != null && ciEntityCachedMapper.getCiEntityBaseInfoById(appModuleId) == null) { - throw new AppModuleNotFoundException(appModuleId); - } - if (CollectionUtils.isNotEmpty(typeIdList)) { - for (Long typeId : typeIdList) { - CiVo ciVo = ciMapper.getCiById(typeId); - if (ciVo == null) { - throw new CiNotFoundException(typeId); - } - } - } - JSONArray tableList = new JSONArray(); - ApplicationListDisplayVo applicationListDisplay = resourceEntityMapper.getApplicationListDisplay(); - if (applicationListDisplay != null) { - JSONObject config = applicationListDisplay.getConfig(); - if (MapUtils.isNotEmpty(config)) { - JSONArray tableSettingList = config.getJSONArray("tableSettingList"); - if (CollectionUtils.isNotEmpty(tableSettingList)) { - List ciNameList = new ArrayList<>(); - Map> ciName2FieldListMap = new HashMap<>(); - for (int i = 0; i < tableSettingList.size(); i++) { - JSONObject tableObj = tableSettingList.getJSONObject(i); - if (MapUtils.isNotEmpty(tableObj)) { - String ciName = tableObj.getString("ciName"); - ciNameList.add(ciName); - JSONArray fieldList = tableObj.getJSONArray("fieldList"); - if (CollectionUtils.isNotEmpty(fieldList)) { - ciName2FieldListMap.put(ciName, fieldList.toJavaList(String.class)); - } - } - } - if (CollectionUtils.isNotEmpty(ciNameList)) { - List resourceCiVoList = ciMapper.getCiListByNameList(ciNameList); - if (CollectionUtils.isEmpty(typeIdList) && CollectionUtils.isNotEmpty(resourceCiVoList)) { - List downwardCiList = ciMapper.getBatchDownwardCiListByCiList(resourceCiVoList); - for (CiVo downwardCi : downwardCiList) { - // 找出叶子节点模型 - if (downwardCi.getRht() != null && downwardCi.getLft() != null && (downwardCi.getRht() - downwardCi.getLft() == 1)) { - typeIdList.add(downwardCi.getId()); - } - } - } - if (CollectionUtils.isNotEmpty(typeIdList)) { - ResourceSearchVo searchVo = new ResourceSearchVo(); - searchVo.setAppSystemIdList(Collections.singletonList(appSystemId)); - if (appModuleId != null) { - searchVo.setAppModuleIdList(Collections.singletonList(appModuleId)); - } - if (envId != null) { - searchVo.setEnvIdList(Collections.singletonList(envId)); - } - searchVo.setCurrentPage(currentPage); - searchVo.setPageSize(pageSize); - List ciList = ciMapper.getAllCi(typeIdList); - for (CiVo ciVo : ciList) { - String resourceTypeName = getResourceTypeName(resourceCiVoList, ciVo); - if (StringUtils.isNotBlank(resourceTypeName)) { - ResourceTypeVo resourceTypeVo = new ResourceTypeVo(ciVo.getId(), ciVo.getParentCiId(), ciVo.getLabel(), ciVo.getName()); - searchVo.setTypeIdList(Collections.singletonList(ciVo.getId())); - resourceCenterResourceService.assembleResourceSearchVo(searchVo, false); - List resourceList = getResourceList(searchVo); - if (CollectionUtils.isNotEmpty(resourceList)) { - List fieldList = ciName2FieldListMap.get(resourceTypeName); - JSONObject tableObj = TableResultUtil.getResult(getTheadList(fieldList), resourceList, searchVo); - tableObj.put("type", resourceTypeVo); - tableList.add(tableObj); - } - } - } - } - } - } - } - } - return tableList; - } - @Override public JSONArray getAppResourceList(@Nullable Long appSystemId, @Nullable Long appModuleId, @Nullable Long envId, @Nullable List inspectStatusList, @Nullable String viewName, @Nullable Integer currentPage, @Nullable Integer pageSize) { if (appSystemId != null && ciEntityCachedMapper.getCiEntityBaseInfoById(appSystemId) == null) { @@ -542,11 +452,6 @@ public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataS searchVo.setCurrentPage(i); List resourceIdList = resourceMapper.getAppResourceIdList(searchVo); resultList.addAll(resourceIdList); -// if (CollectionUtils.isNotEmpty(resourceIdList)) { -// searchVo.setIdList(resourceIdList); -// List resourceList = resourceMapper.getAppResourceListByIdList(searchVo); -// resultList.addAll(resourceList); -// } if (needPage) { break; } @@ -559,12 +464,11 @@ public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataS public JSONArray getTbodyList(List fieldList, List resourceList, ResourceEntityVo resourceEntityVo) { JSONArray tbodyList = new JSONArray(); Map keyMap = new HashMap<>(); - for (ValueTextVo key : map.keySet()) { + for (ValueTextVo key : headFieldHandlerMap.keySet()) { keyMap.put(key.getValue(), key); } JSONObject cacheData = new JSONObject(); cacheData.put("resourceEntityVo", resourceEntityVo); - //ci ip state vendor dataCenter appEnvironment appModule appSystem allIpList if (fieldList.contains("ci")) { List ciIdList = resourceList.stream().filter(Objects::nonNull).map(ResourceVo::getTypeId).filter(Objects::nonNull).collect(Collectors.toList()); List ciList = ciMapper.getCiByIdList(ciIdList); @@ -621,7 +525,6 @@ public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataS List ipIdList = resourceList.stream().filter(Objects::nonNull).map(ResourceVo::getAllIp).filter(Objects::nonNull).flatMap(List::stream).filter(Objects::nonNull).map(IpVo::getId).collect(Collectors.toList()); ciEntityIdSet.addAll(ipIdList); } - // businessGroupList ownerList if (fieldList.contains("ownerList")) { List userIdList = resourceList.stream().filter(Objects::nonNull).map(ResourceVo::getOwnerList).filter(Objects::nonNull).flatMap(List::stream).filter(Objects::nonNull).map(OwnerVo::getUserId).collect(Collectors.toList()); if (CollectionUtils.isNotEmpty(userIdList)) { @@ -714,7 +617,7 @@ public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataS for (String field : fieldList) { ValueTextVo key = keyMap.get(field); if (key != null) { - BiFunction biFunction = map.get(key); + BiFunction biFunction = headFieldHandlerMap.get(key); tbodyObj.put(key.getValue().toString(), biFunction.apply(resourceVo, cacheData)); } } @@ -964,27 +867,8 @@ public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataS @Override public JSONArray getTheadList(List fieldList) { JSONArray theadList = new JSONArray(); -// if (CollectionUtils.isEmpty(fieldNameList)) { -// fieldNameList = ResourceEntityFactory.getFieldNameListByViewName("scence_ipobject_detail"); -// } -// if (CollectionUtils.isNotEmpty(fieldNameList)) { -// List fieldList = ResourceEntityFactory.getFieldListByViewName("scence_ipobject_detail"); -// Map field2TitleMap = fieldList.stream().collect(Collectors.toMap(ValueTextVo::getValue, ValueTextVo::getText)); -// List fieldAliasList = ResourceEntityFactory.getFieldAliasListByViewName("scence_ipobject_detail"); -// Map field2KeyMap = fieldAliasList.stream().collect(Collectors.toMap(ValueTextVo::getValue, ValueTextVo::getText)); -// for (String fieldName : fieldNameList) { -// String title = field2TitleMap.get(fieldName); -// String key = field2KeyMap.get(fieldName); -// if (StringUtils.isNotBlank(key) && StringUtils.isNotBlank(title)) { -// JSONObject thead = new JSONObject(); -// thead.put("key", key); -// thead.put("title", title); -// theadList.add(thead); -// } -// } -// } Map keyMap = new HashMap<>(); - for (ValueTextVo key : map.keySet()) { + for (ValueTextVo key : headFieldHandlerMap.keySet()) { keyMap.put(key.getValue(), key); } for (String field : fieldList) { @@ -1001,16 +885,14 @@ public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataS @Override public List getAssertAllTheadList() { - Set keySet = map.keySet(); - List resultList = new ArrayList<>(keySet); - resultList.sort((o1, o2) -> o1.getText().compareToIgnoreCase(o2.getText())); - return resultList; + Set keySet = headFieldHandlerMap.keySet(); + return new ArrayList<>(keySet); } @Override public List getAppAssertAllTheadList() { List resultList = new ArrayList<>(); - for (ValueTextVo valueTextVo : map.keySet()) { + for (ValueTextVo valueTextVo : headFieldHandlerMap.keySet()) { if (Objects.equals(valueTextVo.getValue(), "tagList")) { continue; } @@ -1019,7 +901,6 @@ public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataS } resultList.add(valueTextVo); } - resultList.sort((o1, o2) -> o1.getText().compareToIgnoreCase(o2.getText())); return resultList; } @@ -1250,6 +1131,19 @@ public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataS return viewName2TypeIdListMap; } + @Override + public List getAppSystemIdListById(Long id) { + List appSystemIdList = new ArrayList<>(); + List appViewList = getAppViewList(); + if (CollectionUtils.isNotEmpty(appViewList)) { + for (ResourceEntityVo resourceEntityVo : appViewList) { + List list = resourceMapper.getAppSystemIdListById(resourceEntityVo.getName(), id); + appSystemIdList.addAll(list); + } + } + return appSystemIdList; + } + private List getAppViewList() { List resultList = new ArrayList<>(); List resourceEntityList = resourceEntityMapper.getResourceEntityList(); @@ -1259,7 +1153,7 @@ public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataS String config = resourceEntityMapper.getResourceEntityConfigByName(resourceEntityVo.getName()); if (StringUtils.isNotBlank(config)) { ResourceEntityConfigVo resourceEntityConfigVo = JSONObject.parseObject(config, ResourceEntityConfigVo.class); - if (Objects.equals(resourceEntityConfigVo.getSceneTemplateName(), "")) { + if (Objects.equals(resourceEntityConfigVo.getSceneTemplateName(), "scence_application_asset_list_detail")) { resourceEntityVo.setConfig(resourceEntityConfigVo); resultList.add(resourceEntityVo); } @@ -1320,14 +1214,4 @@ public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataS return true; } - public String getResourceTypeName(List resourceCiVoList, CiVo resourceCiVo) { - for (CiVo ciVo : resourceCiVoList) { - if (ciVo.getLft() <= resourceCiVo.getLft() && ciVo.getRht() >= resourceCiVo.getRht()) { - return ciVo.getName(); - } - } - return null; - } - - } diff --git a/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java b/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java index 6f456d61..da2761c9 100644 --- a/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java +++ b/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java @@ -512,7 +512,7 @@ public class ResourceCenterResourceServiceImpl implements IResourceCenterResourc int rowNum = resourceTempMapper.getOsResourceCountByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(searchVo); if (rowNum > 0) { searchVo.setRowNum(rowNum); - List idList = resourceMapper.getOsResourceIdListByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(searchVo); + List idList = resourceTempMapper.getOsResourceIdListByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(searchVo); if (CollectionUtils.isNotEmpty(idList)) { return resourceTempMapper.getOsResourceListByIdList(idList); } @@ -526,7 +526,7 @@ public class ResourceCenterResourceServiceImpl implements IResourceCenterResourc searchVo.setRowNum(rowNum); List idList = resourceTempMapper.getIpObjectResourceIdListByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(searchVo); if (CollectionUtils.isNotEmpty(idList)) { - return resourceMapper.getAppInstanceResourceListByIdList(idList); + return resourceMapper.getResourceListByIdList(idList); } } return new ArrayList<>(); diff --git a/src/main/java/neatlogic/module/cmdb/utils/ResourceEntityFactory.java b/src/main/java/neatlogic/module/cmdb/utils/ResourceEntityFactory.java index 0b79b560..5f2725dc 100644 --- a/src/main/java/neatlogic/module/cmdb/utils/ResourceEntityFactory.java +++ b/src/main/java/neatlogic/module/cmdb/utils/ResourceEntityFactory.java @@ -174,8 +174,4 @@ public class ResourceEntityFactory { } return new ArrayList<>(fieldList); } - - public static List getViewNameList() { - return new ArrayList<>(viewNameList); - } } -- Gitee From 331d2f6ab72bb12dbcd27b57b7502f50cc5f3651 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Sat, 22 Mar 2025 14:59:52 +0800 Subject: [PATCH 24/29] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20CMDB=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E6=B8=85=E5=8D=95=E6=94=B9=E6=88=90=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E5=B1=82=E7=BA=A7=E5=8F=AF=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1349157963399168]CMDB应用清单改成模型层级可配置 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1349157963399168 --- .../resource/ResourceAccountListApi.java | 2 +- .../resource/ResourceAccountSaveApi.java | 2 +- .../resource/ResourceTagSaveApi.java | 2 +- .../mapper/resourcecenter/ResourceMapper.java | 22 +- .../mapper/resourcecenter/ResourceMapper.xml | 216 ++---------------- .../resourcecenter/ResourceTempMapper.xml | 1 - 6 files changed, 20 insertions(+), 225 deletions(-) diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceAccountListApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceAccountListApi.java index 78d0dc22..1e6e4ef2 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceAccountListApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceAccountListApi.java @@ -72,7 +72,7 @@ public class ResourceAccountListApi extends PrivateApiComponentBase { @Override public Object myDoService(JSONObject paramObj) throws Exception { Long resourceId = paramObj.getLong("resourceId"); - if (resourceMapper.checkResourceIsExists(resourceId) == 0) { + if (resourceMapper.checkResourceIsExists(resourceId) == null) { throw new ResourceNotFoundException(resourceId); } String protocol = paramObj.getString("protocol"); diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceAccountSaveApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceAccountSaveApi.java index 74399382..03d4718f 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceAccountSaveApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceAccountSaveApi.java @@ -82,7 +82,7 @@ public class ResourceAccountSaveApi extends PrivateApiComponentBase { int successCount = 0; List failureReasonList = new ArrayList<>(); Long resourceId = paramObj.getLong("resourceId"); - if (resourceMapper.checkResourceIsExists(resourceId) == 0) { + if (resourceMapper.checkResourceIsExists(resourceId) == null) { throw new ResourceNotFoundException(resourceId); } // 查询该资产绑定的公有账号列表,再根据账号ID解绑 diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceTagSaveApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceTagSaveApi.java index 0a7378ba..be70651c 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceTagSaveApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceTagSaveApi.java @@ -83,7 +83,7 @@ public class ResourceTagSaveApi extends PrivateApiComponentBase { if (CollectionUtils.isEmpty(tagArray)) { return null; } - if (resourceMapper.checkResourceIsExists(resourceId) == 0) { + if (resourceMapper.checkResourceIsExists(resourceId) == null) { throw new ResourceNotFoundException(resourceId); } List tagList = tagArray.toJavaList(String.class); diff --git a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.java b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.java index 77c3d5bf..7e0f25f4 100644 --- a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.java +++ b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.java @@ -52,16 +52,8 @@ public interface ResourceMapper extends IResourceCrossoverMapper { List getAppResourceListByIdList(ResourceSearchVo searchVo); -// List getOsResourceIdListByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(ResourceSearchVo searchVo); - - int getOsResourceCountByAppSystemIdAndAppModuleIdListAndEnvIdAndTypeId(ResourceSearchVo searchVo); - // List getOsResourceIdListByAppSystemIdAndAppModuleIdListAndEnvIdAndTypeId(ResourceSearchVo searchVo); - List getAppInstanceResourceListByIdList(@Param("idList") List idList); - - List getAppInstanceResourceListByIdListAndKeyword(@Param("idList") List idList, @Param("keyword") String keyword); - List getAppInstanceResourceListByIdListSimple(List idList); Long getResourceIdByIpAndPortAndName(ResourceSearchVo searchVo); @@ -74,7 +66,7 @@ public interface ResourceMapper extends IResourceCrossoverMapper { ResourceVo getResourceById(Long id); - int checkResourceIsExists(Long id); + Long checkResourceIsExists(Long id); List checkResourceIdListIsExists(List idList); @@ -92,16 +84,12 @@ public interface ResourceMapper extends IResourceCrossoverMapper { List getAppSystemModuleIdListByAppSystemIdAndAppModuleIdList(@Param("appSystemId") Long appSystemId, @Param("appModuleIdList") JSONArray appModuleIdList); - List getAppSystemModuleIdListByAppSystemIdAndAppModuleIdListAndEnvId(@Param("appSystemId") Long appSystemId, @Param("envId") Long envId, @Param("appModuleIdList") JSONArray appModuleIdList); - List getAppModuleListByAppSystemIdList(ResourceSearchVo searchVo); List getAppModuleListByIdListSimple(@Param("idList") List idList, @Param("needOrder") boolean needOrder); // Set getResourceAppSystemIdListByResourceId(Long id); - List getResourceAppSystemListByResourceIdList(List id); - List getResourceListByResourceVoList(@Param("resourceList") List resourceList,@Param("searchVo") ResourceSearchVo searchVo); // Long getAppSystemIdByResourceId(Long id); @@ -110,10 +98,6 @@ public interface ResourceMapper extends IResourceCrossoverMapper { List getResourceIdListByAppSystemIdAndModuleIdAndEnvId(ResourceVo resourceVo); - List getAppInstanceResourceIdListByAppSystemIdAndModuleIdAndEnvId(ResourceVo resourceVo); - - Integer getAppInstanceResourceIdCountByAppSystemIdAndModuleIdAndEnvId(ResourceVo resourceVo); - /** * 根据类型和IP列表查询资源 * @@ -197,10 +181,6 @@ public interface ResourceMapper extends IResourceCrossoverMapper { List> getAppEnvCountMapByAppSystemIdGroupByAppModuleId(Long appSystemId); - List getOsResourceListenPortListByResourceIdList(List resourceIdList); - - List getSoftwareResourceListenPortListByResourceIdList(List resourceIdList); - List getOsResourceListByResourceIdList(List resourceIdList); List getResourceTypeIdListByAuth(ResourceSearchVo searchVo); diff --git a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.xml b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.xml index d730c4f4..944a9ab4 100644 --- a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.xml +++ b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.xml @@ -707,58 +707,6 @@ along with this program. If not, see .--> - - - - SELECT - a.`id`, - a.`ip`, - a.`port`, - a.`name`, - a.`type_id` - FROM @{DATA_SCHEMA}.`scence_appinstance_env_appmodule_appsystem` a - WHERE a.`id` IN - - #{id} - - - - - - - SELECT a.`id` - FROM @{DATA_SCHEMA}.`scence_ipobject_ip_port` a + FROM @{DATA_SCHEMA}.`scence_ipobject_detail` a LEFT JOIN cmdb_cientity_group ccg ON ccg.cientity_id = a.id LEFT JOIN cmdb_group_auth cga ON ccg.group_id = cga.group_id @@ -823,7 +771,7 @@ along with this program. If not, see .--> SELECT a.`id`, a.`name`, a.`ip`,a.`port`,a.`type_id`, a.`type_name`, a.`type_label` - FROM @{DATA_SCHEMA}.`scence_ipobject_ip_port` a + FROM @{DATA_SCHEMA}.`scence_ipobject_detail` a LEFT JOIN cmdb_cientity_group ccg ON ccg.cientity_id = a.id LEFT JOIN cmdb_group_auth cga ON ccg.group_id = cga.group_id @@ -854,19 +802,20 @@ along with this program. If not, see .--> - + SELECT a.`id` + FROM @{DATA_SCHEMA}.`scence_ipobject_detail` a + WHERE a.`id` = #{value} + LIMIT 1 - - --> - - - - - - SELECT a.`id`, a.`ip`, a.`name` - FROM @{DATA_SCHEMA}.`scence_ipobject_ip_port` a + FROM @{DATA_SCHEMA}.`scence_ipobject_detail` a WHERE a.`type_id` IN #{item} @@ -1249,7 +1104,7 @@ along with this program. If not, see .--> a.`port`, a.`type_name` AS typeName FROM - @{DATA_SCHEMA}.`scence_ipobject_ip_port` a + @{DATA_SCHEMA}.`scence_ipobject_detail` a WHERE a.`ip` = #{ip} @@ -1275,7 +1130,7 @@ along with this program. If not, see .--> a.`port`, a.`type_name` AS typeName FROM - @{DATA_SCHEMA}.`scence_ipobject_ip_port` a + @{DATA_SCHEMA}.`scence_ipobject_detail` a WHERE a.`ip` = #{ip} @@ -1385,7 +1240,7 @@ along with this program. If not, see .--> d.name as protocol, d.port as port FROM `cmdb_resourcecenter_resource_account` c - JOIN @{DATA_SCHEMA}.`scence_ipobject_ip_port` a ON a.id = c.resource_id + JOIN @{DATA_SCHEMA}.`scence_ipobject_detail` a ON a.id = c.resource_id JOIN `cmdb_resourcecenter_account` b ON b.id = c.account_id JOIN `cmdb_resourcecenter_account_protocol` d ON d.id = b.protocol_id @@ -1401,7 +1256,7 @@ along with this program. If not, see .--> SELECT count(DISTINCT a.id) FROM `cmdb_resourcecenter_resource_account` c - JOIN @{DATA_SCHEMA}.`scence_ipobject_ip_port` a ON a.id = c.resource_id + JOIN @{DATA_SCHEMA}.`scence_ipobject_detail` a ON a.id = c.resource_id JOIN `cmdb_resourcecenter_account` b ON b.id = c.account_id JOIN `cmdb_resourcecenter_account_protocol` d ON d.id = b.protocol_id @@ -1821,31 +1676,6 @@ along with this program. If not, see .--> AND a.`env_id` IS NOT NULL GROUP BY a.`app_module_id` - - ${conditionSql} - - SELECT a.`type_id` -- Gitee From 982c9b024b1d1c3ce4cd2403fc8370331ebc0144 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Sun, 23 Mar 2025 10:12:38 +0800 Subject: [PATCH 25/29] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20CMDB=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E6=B8=85=E5=8D=95=E6=94=B9=E6=88=90=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E5=B1=82=E7=BA=A7=E5=8F=AF=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1349157963399168]CMDB应用清单改成模型层级可配置 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1349157963399168 --- .../resourcecenter/resource/ResourceAccountListApi.java | 2 +- .../resourcecenter/resource/ResourceAccountSaveApi.java | 2 +- .../api/resourcecenter/resource/ResourceTagSaveApi.java | 2 +- .../cmdb/dao/mapper/resourcecenter/ResourceMapper.java | 4 +++- .../cmdb/dao/mapper/resourcecenter/ResourceMapper.xml | 8 +++++++- 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceAccountListApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceAccountListApi.java index 1e6e4ef2..442a62f5 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceAccountListApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceAccountListApi.java @@ -72,7 +72,7 @@ public class ResourceAccountListApi extends PrivateApiComponentBase { @Override public Object myDoService(JSONObject paramObj) throws Exception { Long resourceId = paramObj.getLong("resourceId"); - if (resourceMapper.checkResourceIsExists(resourceId) == null) { + if (resourceMapper.getResourceIdByResourceId(resourceId) == null) { throw new ResourceNotFoundException(resourceId); } String protocol = paramObj.getString("protocol"); diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceAccountSaveApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceAccountSaveApi.java index 03d4718f..d9f73e7f 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceAccountSaveApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceAccountSaveApi.java @@ -82,7 +82,7 @@ public class ResourceAccountSaveApi extends PrivateApiComponentBase { int successCount = 0; List failureReasonList = new ArrayList<>(); Long resourceId = paramObj.getLong("resourceId"); - if (resourceMapper.checkResourceIsExists(resourceId) == null) { + if (resourceMapper.getResourceIdByResourceId(resourceId) == null) { throw new ResourceNotFoundException(resourceId); } // 查询该资产绑定的公有账号列表,再根据账号ID解绑 diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceTagSaveApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceTagSaveApi.java index be70651c..15d9bd94 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceTagSaveApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceTagSaveApi.java @@ -83,7 +83,7 @@ public class ResourceTagSaveApi extends PrivateApiComponentBase { if (CollectionUtils.isEmpty(tagArray)) { return null; } - if (resourceMapper.checkResourceIsExists(resourceId) == null) { + if (resourceMapper.getResourceIdByResourceId(resourceId) == null) { throw new ResourceNotFoundException(resourceId); } List tagList = tagArray.toJavaList(String.class); diff --git a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.java b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.java index 7e0f25f4..0037a6f6 100644 --- a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.java +++ b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.java @@ -66,7 +66,9 @@ public interface ResourceMapper extends IResourceCrossoverMapper { ResourceVo getResourceById(Long id); - Long checkResourceIsExists(Long id); + int checkResourceIsExists(Long id); + + Long getResourceIdByResourceId(Long id); List checkResourceIdListIsExists(List idList); diff --git a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.xml b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.xml index 944a9ab4..542879ab 100644 --- a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.xml +++ b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.xml @@ -806,7 +806,13 @@ along with this program. If not, see .--> where a.`id` = #{value} - + SELECT COUNT(DISTINCT a.`id`) + FROM @{DATA_SCHEMA}.`scence_ipobject_detail` a + WHERE a.`id` = #{value} + + + - - diff --git a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.java b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.java index 0037a6f6..9885f27a 100644 --- a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.java +++ b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.java @@ -52,8 +52,6 @@ public interface ResourceMapper extends IResourceCrossoverMapper { List getAppResourceListByIdList(ResourceSearchVo searchVo); -// List getOsResourceIdListByAppSystemIdAndAppModuleIdListAndEnvIdAndTypeId(ResourceSearchVo searchVo); - List getAppInstanceResourceListByIdListSimple(List idList); Long getResourceIdByIpAndPortAndName(ResourceSearchVo searchVo); @@ -74,8 +72,6 @@ public interface ResourceMapper extends IResourceCrossoverMapper { List getHasModuleAppSystemIdListByAppSystemIdList(@Param("appSystemIdList") List appSystemIdList); -// List getHasEnvAppSystemIdListByAppSystemIdList(@Param("appSystemIdList") List appSystemIdList); - int searchAppModuleCount(ResourceSearchVo searchVo); List searchAppModuleIdList(ResourceSearchVo searchVo); @@ -90,12 +86,8 @@ public interface ResourceMapper extends IResourceCrossoverMapper { List getAppModuleListByIdListSimple(@Param("idList") List idList, @Param("needOrder") boolean needOrder); -// Set getResourceAppSystemIdListByResourceId(Long id); - List getResourceListByResourceVoList(@Param("resourceList") List resourceList,@Param("searchVo") ResourceSearchVo searchVo); -// Long getAppSystemIdByResourceId(Long id); - Set getResourceTypeIdListByAppSystemIdAndModuleIdAndEnvIdAndInspectStatusList(ResourceSearchVo searchVo); List getResourceIdListByAppSystemIdAndModuleIdAndEnvId(ResourceVo resourceVo); @@ -173,10 +165,6 @@ public interface ResourceMapper extends IResourceCrossoverMapper { List getAppSystemListByKeyword(BasePageVo searchVo); -// List getOsEnvListByAppSystemIdAndTypeId(ResourceSearchVo searchVo); - -// List getIpObjectEnvListByAppSystemIdAndTypeId(ResourceSearchVo searchVo); - List getAppEnvListByAppSystemId(Long appSystemId); List getAppEnvListByAppSystemIdAndAppModuleId(@Param("appSystemId") Long appSystemId, @Param("appModuleId") Long appModuleId); diff --git a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.xml b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.xml index 542879ab..2e10df83 100644 --- a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.xml +++ b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.xml @@ -839,19 +839,6 @@ along with this program. If not, see .--> - - - - - - SELECT IFNULL(a.env_id, -2) as id, IFNULL(a.env_name, '未配置') as name, @@ -1682,32 +1625,6 @@ along with this program. If not, see .--> AND a.`env_id` IS NOT NULL GROUP BY a.`app_module_id` - diff --git a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceTempMapper.java b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceTempMapper.java deleted file mode 100644 index 77f4a8c1..00000000 --- a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceTempMapper.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2025 深圳极向量科技有限公司 All Rights Reserved. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package neatlogic.module.cmdb.dao.mapper.resourcecenter; - -import neatlogic.framework.cmdb.dto.resourcecenter.ResourceSearchVo; -import neatlogic.framework.cmdb.dto.resourcecenter.ResourceVo; - -import java.util.List; -import java.util.Set; - -public interface ResourceTempMapper { - - Set getIpObjectResourceTypeIdListByAppModuleIdAndEnvId(ResourceSearchVo searchVo); - - Set getOsResourceTypeIdListByAppModuleIdAndEnvId(ResourceSearchVo searchVo); - - Set getIpObjectResourceTypeIdListByAppSystemIdAndEnvId(ResourceSearchVo searchVo); - - Set getOsResourceTypeIdListByAppSystemIdAndEnvId(ResourceSearchVo searchVo); - - int getIpObjectResourceCountByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(ResourceSearchVo searchVo); - - List getIpObjectResourceIdListByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(ResourceSearchVo searchVo); - - int getOsResourceCountByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(ResourceSearchVo searchVo); - - List getDbInstanceResourceListByIdList(List idList); - - List getOsResourceListByIdList(List idList); - - List getOsResourceIdListByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(ResourceSearchVo searchVo); -} diff --git a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceTempMapper.xml b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceTempMapper.xml deleted file mode 100644 index 0a70e883..00000000 --- a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceTempMapper.xml +++ /dev/null @@ -1,307 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/IResourceCenterResourceService.java b/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/IResourceCenterResourceService.java index f6319555..4be7d47f 100644 --- a/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/IResourceCenterResourceService.java +++ b/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/IResourceCenterResourceService.java @@ -15,10 +15,8 @@ along with this program. If not, see .*/ package neatlogic.module.cmdb.service.resourcecenter.resource; -import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import neatlogic.framework.cmdb.crossover.IResourceCenterResourceCrossoverService; -import neatlogic.framework.cmdb.dto.ci.CiVo; import neatlogic.framework.cmdb.dto.resourcecenter.AccountVo; import neatlogic.framework.cmdb.dto.resourcecenter.ResourceSearchVo; import neatlogic.framework.cmdb.dto.resourcecenter.ResourceVo; @@ -82,43 +80,6 @@ public interface IResourceCenterResourceService extends IResourceCenterResourceC */ Map> getResourceTagByResourceIdList(List idList); - /** - * 补充资产的账号信息 - * - * @param idList 资产id列表 - * @param resourceVoList 资产列表 - */ -// void addResourceAccount(List idList, List resourceVoList); - - /** - * 补充资产的标签信息 - * - * @param idList 资产id列表 - * @param resourceVoList 资产列表 - */ -// void addResourceTag(List idList, List resourceVoList); - - - /** - * 获取对应模块的应用清单列表 - * 其中清单列表有 系统 存储设备 网络设备 应用实例 应用实例集群 DB实例 DB实例集群 访问入口 - * - * @param searchVo resourceSearchVo - * @return tableList - */ - @Deprecated - JSONArray getAppModuleResourceList(ResourceSearchVo searchVo); - - /** - * 获取对应的资产类型名称 - * - * @param resourceCiVoList 模型列表 - * @param resourceCiVo 模型 - * @return 模型名称 - */ - @Deprecated - public String getResourceTypeName(List resourceCiVoList, CiVo resourceCiVo); - /** * 添加标签和账号信息 * @@ -140,29 +101,6 @@ public interface IResourceCenterResourceService extends IResourceCenterResourceC */ void addAccountInformation(List resourceList); -// /** -// * 获取模块列表 -// * -// * @param searchVo resourceSearchVo -// * @return 模块列表 -// */ -// List getAppModuleList(ResourceSearchVo searchVo); - - - /** - * 获取应用巡检批量巡检时的环境列表(环境会包含模块列表,模块还会包含模型列表) - * - * @param searchVo resourceSearchVo - * @return 应用巡检批量巡检时的环境列表 - */ -// Collection getAppEnvList(ResourceSearchVo searchVo); - - /** - * 重建资源中心视图 - * @return - */ -// List rebuildResourceEntity(); - /** * 构建单个视图 * @param resourceEntityVo diff --git a/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java b/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java index da2761c9..df52c449 100644 --- a/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java +++ b/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java @@ -15,7 +15,6 @@ along with this program. If not, see .*/ package neatlogic.module.cmdb.service.resourcecenter.resource; -import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import neatlogic.framework.asynchronization.threadlocal.TenantContext; import neatlogic.framework.asynchronization.threadlocal.UserContext; @@ -24,17 +23,13 @@ import neatlogic.framework.cmdb.auth.label.CIENTITY_MODIFY; import neatlogic.framework.cmdb.auth.label.CI_MODIFY; import neatlogic.framework.cmdb.dto.ci.AttrVo; import neatlogic.framework.cmdb.dto.ci.CiVo; -import neatlogic.framework.cmdb.dto.cientity.CiEntityVo; import neatlogic.framework.cmdb.dto.globalattr.GlobalAttrVo; import neatlogic.framework.cmdb.dto.resourcecenter.*; import neatlogic.framework.cmdb.dto.resourcecenter.config.*; import neatlogic.framework.cmdb.dto.tag.TagVo; import neatlogic.framework.cmdb.enums.CmdbTenantConfig; import neatlogic.framework.cmdb.enums.RelDirectionType; -import neatlogic.framework.cmdb.enums.resourcecenter.AppModuleResourceType; import neatlogic.framework.cmdb.exception.ci.CiNotFoundException; -import neatlogic.framework.cmdb.exception.resourcecenter.AppModuleNotFoundException; -import neatlogic.framework.cmdb.exception.resourcecenter.AppSystemNotFoundException; import neatlogic.framework.cmdb.exception.resourcecenter.ResourceViewFieldMappingException; import neatlogic.framework.cmdb.utils.ResourceViewGenerateSqlUtil; import neatlogic.framework.cmdb.utils.ResourceViewGenerateSqlUtilForTiDB; @@ -47,7 +42,6 @@ import neatlogic.framework.store.mysql.DatabaseVendor; import neatlogic.framework.store.mysql.DatasourceManager; import neatlogic.framework.transaction.core.EscapeTransactionJob; import neatlogic.framework.util.Md5Util; -import neatlogic.framework.util.TableResultUtil; import neatlogic.module.cmdb.dao.mapper.ci.AttrMapper; import neatlogic.module.cmdb.dao.mapper.ci.CiMapper; import neatlogic.module.cmdb.dao.mapper.cientity.CiEntityMapper; @@ -62,7 +56,6 @@ import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; -import javax.annotation.PostConstruct; import javax.annotation.Resource; import java.util.*; import java.util.stream.Collectors; @@ -79,8 +72,6 @@ public class ResourceCenterResourceServiceImpl implements IResourceCenterResourc @Resource ResourceMapper resourceMapper; @Resource - ResourceTempMapper resourceTempMapper; - @Resource ResourceTagMapper resourceTagMapper; @Resource ResourceAccountMapper resourceAccountMapper; @@ -106,13 +97,6 @@ public class ResourceCenterResourceServiceImpl implements IResourceCenterResourc @Resource private DataBaseViewInfoMapper dataBaseViewInfoMapper; - public static final Map> searchMap = new HashMap<>(); - - @FunctionalInterface - public interface Action { - List execute(T t); - } - @Override public ResourceSearchVo assembleResourceSearchVo(JSONObject jsonObj) { if(!jsonObj.containsKey("typeId") && !jsonObj.containsKey("typeIdList")){ @@ -427,133 +411,133 @@ public class ResourceCenterResourceServiceImpl implements IResourceCenterResourc * @param searchVo * @return */ - @Deprecated - @Override - public JSONArray getAppModuleResourceList(ResourceSearchVo searchVo) { - JSONArray tableList = new JSONArray(); - List resourceCiVoList = ciMapper.getCiListByNameList(AppModuleResourceType.getNameList()); - List resourceTypeIdList = new ArrayList<>(); - Long appSystemId = searchVo.getAppSystemId(); - Long appModuleId = searchVo.getAppModuleId(); - Long typeId = searchVo.getTypeId(); - if (typeId != null) { - CiVo ciVo = ciMapper.getCiById(typeId); - if (ciVo == null) { - throw new CiNotFoundException(typeId); - } - resourceTypeIdList.add(typeId); - } else if (CollectionUtils.isNotEmpty(searchVo.getTypeIdList())) { - resourceTypeIdList.addAll(searchVo.getTypeIdList()); - searchVo.setTypeIdList(null); - } else if (appModuleId != null) { - CiEntityVo ciEntityVo = ciEntityMapper.getCiEntityBaseInfoById(appModuleId); - if (ciEntityVo == null) { - throw new AppModuleNotFoundException(appModuleId); - } - Set resourceTypeIdSet = resourceTempMapper.getIpObjectResourceTypeIdListByAppModuleIdAndEnvId(searchVo); - resourceTypeIdList.addAll(resourceTypeIdSet); - if (CollectionUtils.isNotEmpty(resourceTypeIdSet)) { - resourceTypeIdSet = resourceTempMapper.getOsResourceTypeIdListByAppModuleIdAndEnvId(searchVo); - resourceTypeIdList.addAll(resourceTypeIdSet); - } - } else if (appSystemId != null) { - CiEntityVo ciEntityVo = ciEntityMapper.getCiEntityBaseInfoById(appSystemId); - if (ciEntityVo == null) { - throw new AppSystemNotFoundException(appSystemId); - } - Set resourceTypeIdSet = resourceTempMapper.getIpObjectResourceTypeIdListByAppSystemIdAndEnvId(searchVo); - resourceTypeIdList.addAll(resourceTypeIdSet); - if (CollectionUtils.isNotEmpty(resourceTypeIdSet)) { - resourceTypeIdSet = resourceTempMapper.getOsResourceTypeIdListByAppSystemIdAndEnvId(searchVo); - resourceTypeIdList.addAll(resourceTypeIdSet); - } - } - - if (CollectionUtils.isNotEmpty(resourceTypeIdList)) { - List ciList = ciMapper.getAllCi(resourceTypeIdList); - for (CiVo ciVo : ciList) { - ResourceTypeVo resourceTypeVo = new ResourceTypeVo(ciVo.getId(), ciVo.getParentCiId(), ciVo.getLabel(), ciVo.getName()); - String resourceTypeName = getResourceTypeName(resourceCiVoList, ciVo); - if (StringUtils.isBlank(resourceTypeName)) { - continue; - } - String actionKey = AppModuleResourceType.getAction(resourceTypeName); - if (StringUtils.isBlank(actionKey)) { - continue; - } - searchVo.setTypeId(ciVo.getId()); - List returnList = searchMap.get(actionKey).execute(searchVo); - if (CollectionUtils.isNotEmpty(returnList)) { - JSONObject tableObj = TableResultUtil.getResult(returnList, searchVo); - tableObj.put("type", resourceTypeVo); - tableList.add(tableObj); - } - } - } - return tableList; - } - - @PostConstruct - @Deprecated - public void searchDispatcherInit() { - searchMap.put("ipObject", (searchVo) -> { - int rowNum = resourceTempMapper.getIpObjectResourceCountByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(searchVo); - if (rowNum > 0) { - searchVo.setRowNum(rowNum); - List idList = resourceTempMapper.getIpObjectResourceIdListByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(searchVo); - if (CollectionUtils.isNotEmpty(idList)) { - return resourceMapper.getResourceListByIdList(idList); - } - } - return new ArrayList<>(); - }); - - searchMap.put("OS", (searchVo) -> { - int rowNum = resourceTempMapper.getOsResourceCountByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(searchVo); - if (rowNum > 0) { - searchVo.setRowNum(rowNum); - List idList = resourceTempMapper.getOsResourceIdListByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(searchVo); - if (CollectionUtils.isNotEmpty(idList)) { - return resourceTempMapper.getOsResourceListByIdList(idList); - } - } - return new ArrayList<>(); - }); - - searchMap.put("APPIns", (searchVo) -> { - int rowNum = resourceTempMapper.getIpObjectResourceCountByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(searchVo); - if (rowNum > 0) { - searchVo.setRowNum(rowNum); - List idList = resourceTempMapper.getIpObjectResourceIdListByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(searchVo); - if (CollectionUtils.isNotEmpty(idList)) { - return resourceMapper.getResourceListByIdList(idList); - } - } - return new ArrayList<>(); - }); - - searchMap.put("DBIns", (searchVo) -> { - int rowNum = resourceTempMapper.getIpObjectResourceCountByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(searchVo); - if (rowNum > 0) { - searchVo.setRowNum(rowNum); - List idList = resourceTempMapper.getIpObjectResourceIdListByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(searchVo); - if (CollectionUtils.isNotEmpty(idList)) { - return resourceTempMapper.getDbInstanceResourceListByIdList(idList); - } - } - return new ArrayList<>(); - }); +// @Deprecated +// @Override +// public JSONArray getAppModuleResourceList(ResourceSearchVo searchVo) { +// JSONArray tableList = new JSONArray(); +// List resourceCiVoList = ciMapper.getCiListByNameList(AppModuleResourceType.getNameList()); +// List resourceTypeIdList = new ArrayList<>(); +// Long appSystemId = searchVo.getAppSystemId(); +// Long appModuleId = searchVo.getAppModuleId(); +// Long typeId = searchVo.getTypeId(); +// if (typeId != null) { +// CiVo ciVo = ciMapper.getCiById(typeId); +// if (ciVo == null) { +// throw new CiNotFoundException(typeId); +// } +// resourceTypeIdList.add(typeId); +// } else if (CollectionUtils.isNotEmpty(searchVo.getTypeIdList())) { +// resourceTypeIdList.addAll(searchVo.getTypeIdList()); +// searchVo.setTypeIdList(null); +// } else if (appModuleId != null) { +// CiEntityVo ciEntityVo = ciEntityMapper.getCiEntityBaseInfoById(appModuleId); +// if (ciEntityVo == null) { +// throw new AppModuleNotFoundException(appModuleId); +// } +// Set resourceTypeIdSet = resourceTempMapper.getIpObjectResourceTypeIdListByAppModuleIdAndEnvId(searchVo); +// resourceTypeIdList.addAll(resourceTypeIdSet); +// if (CollectionUtils.isNotEmpty(resourceTypeIdSet)) { +// resourceTypeIdSet = resourceTempMapper.getOsResourceTypeIdListByAppModuleIdAndEnvId(searchVo); +// resourceTypeIdList.addAll(resourceTypeIdSet); +// } +// } else if (appSystemId != null) { +// CiEntityVo ciEntityVo = ciEntityMapper.getCiEntityBaseInfoById(appSystemId); +// if (ciEntityVo == null) { +// throw new AppSystemNotFoundException(appSystemId); +// } +// Set resourceTypeIdSet = resourceTempMapper.getIpObjectResourceTypeIdListByAppSystemIdAndEnvId(searchVo); +// resourceTypeIdList.addAll(resourceTypeIdSet); +// if (CollectionUtils.isNotEmpty(resourceTypeIdSet)) { +// resourceTypeIdSet = resourceTempMapper.getOsResourceTypeIdListByAppSystemIdAndEnvId(searchVo); +// resourceTypeIdList.addAll(resourceTypeIdSet); +// } +// } +// +// if (CollectionUtils.isNotEmpty(resourceTypeIdList)) { +// List ciList = ciMapper.getAllCi(resourceTypeIdList); +// for (CiVo ciVo : ciList) { +// ResourceTypeVo resourceTypeVo = new ResourceTypeVo(ciVo.getId(), ciVo.getParentCiId(), ciVo.getLabel(), ciVo.getName()); +// String resourceTypeName = getResourceTypeName(resourceCiVoList, ciVo); +// if (StringUtils.isBlank(resourceTypeName)) { +// continue; +// } +// String actionKey = AppModuleResourceType.getAction(resourceTypeName); +// if (StringUtils.isBlank(actionKey)) { +// continue; +// } +// searchVo.setTypeId(ciVo.getId()); +// List returnList = searchMap.get(actionKey).execute(searchVo); +// if (CollectionUtils.isNotEmpty(returnList)) { +// JSONObject tableObj = TableResultUtil.getResult(returnList, searchVo); +// tableObj.put("type", resourceTypeVo); +// tableList.add(tableObj); +// } +// } +// } +// return tableList; +// } - } - @Deprecated - public String getResourceTypeName(List resourceCiVoList, CiVo resourceCiVo) { - for (CiVo ciVo : resourceCiVoList) { - if (ciVo.getLft() <= resourceCiVo.getLft() && ciVo.getRht() >= resourceCiVo.getRht()) { - return ciVo.getName(); - } - } - return null; - } +// @PostConstruct +// @Deprecated +// public void searchDispatcherInit() { +// searchMap.put("ipObject", (searchVo) -> { +// int rowNum = resourceTempMapper.getIpObjectResourceCountByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(searchVo); +// if (rowNum > 0) { +// searchVo.setRowNum(rowNum); +// List idList = resourceTempMapper.getIpObjectResourceIdListByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(searchVo); +// if (CollectionUtils.isNotEmpty(idList)) { +// return resourceMapper.getResourceListByIdList(idList); +// } +// } +// return new ArrayList<>(); +// }); +// +// searchMap.put("OS", (searchVo) -> { +// int rowNum = resourceTempMapper.getOsResourceCountByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(searchVo); +// if (rowNum > 0) { +// searchVo.setRowNum(rowNum); +// List idList = resourceTempMapper.getOsResourceIdListByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(searchVo); +// if (CollectionUtils.isNotEmpty(idList)) { +// return resourceTempMapper.getOsResourceListByIdList(idList); +// } +// } +// return new ArrayList<>(); +// }); +// +// searchMap.put("APPIns", (searchVo) -> { +// int rowNum = resourceTempMapper.getIpObjectResourceCountByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(searchVo); +// if (rowNum > 0) { +// searchVo.setRowNum(rowNum); +// List idList = resourceTempMapper.getIpObjectResourceIdListByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(searchVo); +// if (CollectionUtils.isNotEmpty(idList)) { +// return resourceMapper.getResourceListByIdList(idList); +// } +// } +// return new ArrayList<>(); +// }); +// +// searchMap.put("DBIns", (searchVo) -> { +// int rowNum = resourceTempMapper.getIpObjectResourceCountByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(searchVo); +// if (rowNum > 0) { +// searchVo.setRowNum(rowNum); +// List idList = resourceTempMapper.getIpObjectResourceIdListByAppSystemIdAndAppModuleIdAndEnvIdAndTypeId(searchVo); +// if (CollectionUtils.isNotEmpty(idList)) { +// return resourceTempMapper.getDbInstanceResourceListByIdList(idList); +// } +// } +// return new ArrayList<>(); +// }); +// +// } +// @Deprecated +// public String getResourceTypeName(List resourceCiVoList, CiVo resourceCiVo) { +// for (CiVo ciVo : resourceCiVoList) { +// if (ciVo.getLft() <= resourceCiVo.getLft() && ciVo.getRht() >= resourceCiVo.getRht()) { +// return ciVo.getName(); +// } +// } +// return null; +// } /** * 添加标签和账号信息 @@ -601,174 +585,6 @@ public class ResourceCenterResourceServiceImpl implements IResourceCenterResourc } } -// @Override -// public List getAppModuleList(ResourceSearchVo searchVo) { -// int count = resourceMapper.searchAppModuleCount(searchVo); -// if (count > 0) { -// searchVo.setRowNum(count); -// List idList = resourceMapper.searchAppModuleIdList(searchVo); -// if (CollectionUtils.isNotEmpty(idList)) { -// return resourceMapper.searchAppModule(idList); -// } -// } -// return new ArrayList<>(); -// } - -// @Override -// public Collection getAppEnvList(ResourceSearchVo searchVo) { -// CiEntityVo ciEntityVo = ciEntityMapper.getCiEntityBaseInfoById(searchVo.getAppSystemId()); -// if (ciEntityVo == null) { -// throw new AppSystemNotFoundException(searchVo.getAppSystemId()); -// } -// Set resourceTypeIdSet = resourceMapper.getIpObjectResourceTypeIdListByAppSystemIdAndEnvId(searchVo); -// List resourceTypeIdList = new ArrayList<>(resourceTypeIdSet); -// if (CollectionUtils.isNotEmpty(resourceTypeIdSet)) { -// resourceTypeIdSet = resourceMapper.getOsResourceTypeIdListByAppSystemIdAndEnvId(searchVo); -// resourceTypeIdList.addAll(resourceTypeIdSet); -// } -// -// if (CollectionUtils.isNotEmpty(resourceTypeIdList)) { -// Map returnEnvMap = new HashMap<>(); -// Map> envIdModuleIdSetMap = new HashMap<>(); -// Map> envIdModuleListMap = new HashMap<>(); -// Map> envModuleIdCiIdSetMap = new HashMap<>(); -// Map> envModuleIdCiListMap = new HashMap<>(); -// List ciList = ciMapper.getAllCi(resourceTypeIdList); -// List resourceCiVoList = ciMapper.getCiListByNameList(AppModuleResourceType.getNameList()); -// -// for (CiVo ciVo : ciList) { -// List appEnvList = new ArrayList<>(); -// String resourceTypeName = getResourceTypeName(resourceCiVoList, ciVo); -// if (StringUtils.isBlank(resourceTypeName)) { -// continue; -// } -// String actionKey = AppModuleResourceType.getAction(resourceTypeName); -// if (StringUtils.isBlank(actionKey)) { -// continue; -// } -// searchVo.setTypeId(ciVo.getId()); -// if (actionKey.equals("OS")) { -// appEnvList.addAll(resourceMapper.getOsEnvListByAppSystemIdAndTypeId(searchVo)); -// } else { -// appEnvList.addAll(resourceMapper.getIpObjectEnvListByAppSystemIdAndTypeId(searchVo)); -// } -// -// /*数据处理 -// 1、returnEnvMap 环境List -// 2、envIdModuleIdSetMap 环境id对应的 模块id列表 -// 3、envModuleIdCiIdSetMap 环境id+模块id对应的 模型id列表 -// */ -// if (CollectionUtils.isNotEmpty(appEnvList)) { -// for (AppEnvVo envVo : appEnvList) { -// //未配置情况,环境id设为-2,因为id为-1的一般都是代表 所有 的意思 -// if (envVo.getId() == null) { -// envVo.setId(-2L); -// envVo.setName("未配置"); -// envVo.setSeqNo(9999); -// } -// Long envId = envVo.getId(); -// returnEnvMap.put(envId, envVo); -// List appModuleList = envVo.getAppModuleList(); -// Set appModuleIdSet = appModuleList.stream().map(AppModuleVo::getId).collect(Collectors.toSet()); -// if (envIdModuleIdSetMap.containsKey(envId)) { -// for (AppModuleVo moduleVo : appModuleList) { -// if (envIdModuleIdSetMap.get(envId).contains(moduleVo.getId())) { -// List ciVoList = moduleVo.getCiList(); -// for (CiVo ci : ciVoList) { -// if (CollectionUtils.isNotEmpty(envModuleIdCiIdSetMap.get(envId + moduleVo.getId())) && !envModuleIdCiIdSetMap.get(envId + moduleVo.getId()).contains(ci.getId())) { -// envModuleIdCiIdSetMap.get(envId + moduleVo.getId()).add(ci.getId()); -// envModuleIdCiListMap.get(envId + moduleVo.getId()).add(ci); -// } -// } -// } else { -// envIdModuleIdSetMap.get(envId).add(moduleVo.getId()); -// envIdModuleListMap.get(envId).add(moduleVo); -// envModuleIdCiIdSetMap.put(envId + moduleVo.getId(), moduleVo.getCiList().stream().map(CiVo::getId).collect(Collectors.toSet())); -// envModuleIdCiListMap.put(envId + moduleVo.getId(), moduleVo.getCiList()); -// } -// } -// envIdModuleIdSetMap.get(envId).addAll(appModuleIdSet); -// } else { -// envIdModuleIdSetMap.put(envId, appModuleIdSet); -// envIdModuleListMap.put(envId, appModuleList); -// for (AppModuleVo moduleVo : appModuleList) { -// envModuleIdCiIdSetMap.put(envId + moduleVo.getId(), moduleVo.getCiList().stream().map(CiVo::getId).collect(Collectors.toSet())); -// envModuleIdCiListMap.put(envId + moduleVo.getId(), moduleVo.getCiList()); -// } -// } -// } -// } -// } -// for (Map.Entry entry : returnEnvMap.entrySet()) { -// List appModuleVoList = envIdModuleListMap.get(entry.getKey()); -// for (AppModuleVo appModuleVo : appModuleVoList) { -// List ciVoList = envModuleIdCiListMap.get(entry.getKey() + appModuleVo.getId()); -// appModuleVo.setCiList(ciVoList); -// } -// entry.getValue().setAppModuleList(appModuleVoList); -// } -// return returnEnvMap.values().stream().sorted(Comparator.comparing(AppEnvVo::getSeqNo)).collect(Collectors.toList()); -// } -// return null; -// } - -// @Override -// public List rebuildResourceEntity() { -// List viewNameList = ResourceEntityFactory.getViewNameList(); -// List resourceEntityList = resourceEntityMapper.getResourceEntityListByNameList(viewNameList); -// for (ResourceEntityVo resourceEntityVo : resourceEntityList) { -// String config = resourceEntityMapper.getResourceEntityConfigByName(resourceEntityVo.getName()); -// resourceEntityVo.setError(null); -// resourceEntityVo.setConfigStr(config); -// String sql = buildResourceView(resourceEntityVo); -// if (StringUtils.isNotBlank(resourceEntityVo.getError())) { -// resourceEntityVo.setStatus(Status.ERROR.getValue()); -// } else { -// resourceEntityVo.setStatus(Status.READY.getValue()); -// } -// resourceEntityMapper.updateResourceEntityStatusAndError(resourceEntityVo); -// } -// List sceneEntityList = ResourceEntityFactory.getSceneEntityList(); -// for (SceneEntityVo sceneEntityVo : sceneEntityList) { -// String viewName = sceneEntityVo.getName(); -// String tableType = schemaMapper.checkTableOrViewIsExists(TenantContext.get().getDataDbName(), viewName); -// if (tableType == null) { -// List fieldNameList = ResourceEntityFactory.getFieldNameListByViewName(viewName); -// Table table = new Table(); -// table.setName(viewName); -// table.setSchemaName(TenantContext.get().getDataDbName()); -// List columnDefinitions = new ArrayList<>(); -// for (String columnName : fieldNameList) { -// ColumnDefinition columnDefinition = new ColumnDefinition(); -// columnDefinition.setColumnName(columnName); -// columnDefinition.setColDataType(new ColDataType("int")); -// columnDefinitions.add(columnDefinition); -// } -// CreateTable createTable = new CreateTable(); -// createTable.setTable(table); -// createTable.setColumnDefinitions(columnDefinitions); -// createTable.setIfNotExists(true); -// EscapeTransactionJob.State s = new EscapeTransactionJob(() -> { -// schemaMapper.insertView(createTable.toString()); -// }).execute(); -// } -// } -// resourceEntityList = resourceEntityMapper.getResourceEntityListByNameList(viewNameList); -// Map resourceEntityVoMap = resourceEntityList.stream().collect(Collectors.toMap(e -> e.getName(), e -> e)); -// List resultList = new ArrayList<>(); -// for (SceneEntityVo sceneEntityVo : sceneEntityList) { -// ResourceEntityVo resourceEntityVo = resourceEntityVoMap.get(sceneEntityVo.getName()); -// if (resourceEntityVo == null) { -// resourceEntityVo = new ResourceEntityVo(); -// resourceEntityVo.setName(sceneEntityVo.getName()); -// resourceEntityVo.setLabel(sceneEntityVo.getLabel()); -// resourceEntityVo.setStatus(Status.PENDING.getValue()); -// } -// resultList.add(resourceEntityVo); -// } -// return resultList; -// } - @Override public String buildResourceView(ResourceEntityVo resourceEntityVo) { String viewName = resourceEntityVo.getName(); -- Gitee From 46348391a454eac875b0ee51b5d78e049553f5a8 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Wed, 2 Apr 2025 11:43:05 +0800 Subject: [PATCH 27/29] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20CMDB=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E6=B8=85=E5=8D=95=E6=94=B9=E6=88=90=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E5=B1=82=E7=BA=A7=E5=8F=AF=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1349157963399168]CMDB应用清单改成模型层级可配置 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1349157963399168 --- .../app/ListAppSystemForSelectApi.java | 27 ------------ .../app/ListAppSystemForTreeApi.java | 34 --------------- .../appenv/ListAppEnvForSelectApi.java | 31 -------------- .../appmodule/AppModuleListApi.java | 6 --- .../AppModuleResourceTypeListApi.java | 41 ------------------- .../ListAppModuleListForTreeApi.java | 21 ---------- 6 files changed, 160 deletions(-) diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/app/ListAppSystemForSelectApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/app/ListAppSystemForSelectApi.java index 98506b3e..9ddf4eb2 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/app/ListAppSystemForSelectApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/app/ListAppSystemForSelectApi.java @@ -68,32 +68,5 @@ public class ListAppSystemForSelectApi extends PrivateApiComponentBase { IResourceCenterDataSource resourceCenterDataSource = ResourceCenterDataSourceFactory.getResourceCenterDataSource(); List tbodyList = resourceCenterDataSource.getAppSystemListForSelect(searchVo); return TableResultUtil.getResult(tbodyList, searchVo); -// JSONArray defaultValue = searchVo.getDefaultValue(); -// if (CollectionUtils.isNotEmpty(defaultValue)) { -// List idList = defaultValue.toJavaList(Long.class); -// List resourceList = resourceMapper.searchAppSystemListByIdList(idList); -// return TableResultUtil.getResult(resourceList); -// } else { -// int rowNum = resourceMapper.searchAppSystemCount(searchVo); -// if (rowNum > 0) { -// searchVo.setRowNum(rowNum); -// if (searchVo.getNeedPage()) { -// List idList = resourceMapper.searchAppSystemIdList(searchVo); -// List resourceList = resourceMapper.searchAppSystemListByIdList(idList); -// return TableResultUtil.getResult(resourceList, searchVo); -// } else { -// List allResourceList = new ArrayList<>(); -// int pageCount = searchVo.getPageCount(); -// for (int currentPage = 1; currentPage <= pageCount; currentPage++) { -// searchVo.setCurrentPage(currentPage); -// List idList = resourceMapper.searchAppSystemIdList(searchVo); -// List resourceList = resourceMapper.searchAppSystemListByIdList(idList); -// allResourceList.addAll(resourceList); -// } -// return TableResultUtil.getResult(allResourceList, searchVo); -// } -// } -// } -// return null; } } diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/app/ListAppSystemForTreeApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/app/ListAppSystemForTreeApi.java index 4ac23c10..d5728872 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/app/ListAppSystemForTreeApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/app/ListAppSystemForTreeApi.java @@ -66,40 +66,6 @@ public class ListAppSystemForTreeApi extends PrivateApiComponentBase { BasePageVo searchVo = paramObj.toJavaObject(BasePageVo.class); IResourceCenterDataSource resourceCenterDataSource = ResourceCenterDataSourceFactory.getResourceCenterDataSource(); List tbodyList = resourceCenterDataSource.getAppSystemListForTree(searchVo); -// String keyword = searchVo.getKeyword(); -// int count = resourceMapper.getAppSystemIdListCountByKeyword(keyword); -// if (count > 0) { -// searchVo.setRowNum(count); -// List appSystemIdList = resourceMapper.getAppSystemIdListByKeyword(searchVo); -// if (CollectionUtils.isEmpty(appSystemIdList)) { -// return TableResultUtil.getResult(tbodyList, searchVo); -// } -// tbodyList = resourceMapper.getAppSystemListByIdList(appSystemIdList); -// List hasModuleAppSystemIdList = resourceMapper.getHasModuleAppSystemIdListByAppSystemIdList(appSystemIdList); -// if (CollectionUtils.isNotEmpty(hasModuleAppSystemIdList)) { -// for (AppSystemVo appSystemVo : tbodyList) { -// if (hasModuleAppSystemIdList.contains(appSystemVo.getId())) { -// appSystemVo.setIsHasModule(1); -// } -// } -// } -// if (StringUtils.isNotEmpty(searchVo.getKeyword())) { -// List appModuleList = resourceMapper.getAppModuleListByKeywordAndAppSystemIdList(keyword, appSystemIdList); -// if (CollectionUtils.isNotEmpty(appModuleList)) { -// Map> appModuleMap = new HashMap<>(); -// for (AppModuleVo appModuleVo : appModuleList) { -// appModuleMap.computeIfAbsent(appModuleVo.getAppSystemId(), key -> new ArrayList<>()).add(appModuleVo); -// } -// for (AppSystemVo appSystemVo : tbodyList) { -// List appModuleVoList = appModuleMap.get(appSystemVo.getId()); -// if (CollectionUtils.isNotEmpty(appModuleVoList)) { -// appSystemVo.setAppModuleList(appModuleVoList); -// appSystemVo.setIsHasModule(1); -// } -// } -// } -// } -// } return TableResultUtil.getResult(tbodyList, searchVo); } } diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/appenv/ListAppEnvForSelectApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/appenv/ListAppEnvForSelectApi.java index 44006197..34f801b2 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/appenv/ListAppEnvForSelectApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/appenv/ListAppEnvForSelectApi.java @@ -69,36 +69,5 @@ public class ListAppEnvForSelectApi extends PrivateApiComponentBase { IResourceCenterDataSource resourceCenterDataSource = ResourceCenterDataSourceFactory.getResourceCenterDataSource(); List tbodyList = resourceCenterDataSource.getAppEnvListForSelect(searchVo); return TableResultUtil.getResult(tbodyList, searchVo); -// JSONArray defaultValue = searchVo.getDefaultValue(); -// if (CollectionUtils.isNotEmpty(defaultValue)) { -// List idList = defaultValue.toJavaList(Long.class); -// List resourceList = resourceMapper.searchAppEnvListByIdList(idList); -// return TableResultUtil.getResult(resourceList); -// } else { -// int rowNum = resourceMapper.searchAppEnvCount(searchVo); -// if (rowNum > 0) { -// searchVo.setRowNum(rowNum); -// if (searchVo.getNeedPage()) { -// List idList = resourceMapper.searchAppEnvIdList(searchVo); -// if (CollectionUtils.isNotEmpty(idList)) { -// List resourceList = resourceMapper.searchAppEnvListByIdList(idList); -// return TableResultUtil.getResult(resourceList, searchVo); -// } -// } else { -// List allResourceList = new ArrayList<>(); -// int pageCount = searchVo.getPageCount(); -// for (int currentPage = 1; currentPage <= pageCount; currentPage++) { -// searchVo.setCurrentPage(currentPage); -// List idList = resourceMapper.searchAppEnvIdList(searchVo); -// if (CollectionUtils.isNotEmpty(idList)) { -// List resourceList = resourceMapper.searchAppEnvListByIdList(idList); -// allResourceList.addAll(resourceList); -// } -// } -// return TableResultUtil.getResult(allResourceList, searchVo); -// } -// } -// } -// return null; } } diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/appmodule/AppModuleListApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/appmodule/AppModuleListApi.java index 0ea8e89c..c95724fe 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/appmodule/AppModuleListApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/appmodule/AppModuleListApi.java @@ -28,10 +28,8 @@ import neatlogic.framework.restful.annotation.*; import neatlogic.framework.restful.constvalue.OperationTypeEnum; import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; import neatlogic.framework.util.TableResultUtil; -import neatlogic.module.cmdb.service.resourcecenter.resource.IResourceCenterResourceService; import org.springframework.stereotype.Service; -import javax.annotation.Resource; import java.util.List; /** @@ -43,9 +41,6 @@ import java.util.List; @OperationType(type = OperationTypeEnum.SEARCH) public class AppModuleListApi extends PrivateApiComponentBase { - @Resource - private IResourceCenterResourceService resourceCenterResourceService; - @Override public String getToken() { return "resourcecenter/appmodule/list"; @@ -79,6 +74,5 @@ public class AppModuleListApi extends PrivateApiComponentBase { IResourceCenterDataSource resourceCenterDataSource = ResourceCenterDataSourceFactory.getResourceCenterDataSource(); List tbodyList = resourceCenterDataSource.getAppModuleList(searchVo); return TableResultUtil.getResult(tbodyList, searchVo); -// return TableResultUtil.getResult(resourceCenterResourceService.getAppModuleList(searchVo), searchVo); } } diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/appmodule/AppModuleResourceTypeListApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/appmodule/AppModuleResourceTypeListApi.java index 2343757d..169c8ed7 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/appmodule/AppModuleResourceTypeListApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/appmodule/AppModuleResourceTypeListApi.java @@ -17,7 +17,6 @@ import neatlogic.framework.restful.constvalue.OperationTypeEnum; import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; import neatlogic.module.cmdb.dao.mapper.ci.CiMapper; import neatlogic.module.cmdb.dao.mapper.resourcecenter.ResourceMapper; -import neatlogic.module.cmdb.service.resourcecenter.resource.IResourceCenterResourceService; import org.apache.commons.collections4.CollectionUtils; import org.springframework.stereotype.Service; @@ -39,9 +38,6 @@ public class AppModuleResourceTypeListApi extends PrivateApiComponentBase { @Resource ResourceMapper resourceMapper; - @Resource - private IResourceCenterResourceService resourceCenterResourceService; - @Override public String getName() { return "查询当前模块各环境的需要显示的模型列表"; @@ -73,19 +69,7 @@ public class AppModuleResourceTypeListApi extends PrivateApiComponentBase { public Object myDoService(JSONObject paramObj) throws Exception { JSONArray returnArray = new JSONArray(); Long appModuleId = paramObj.getLong("appModuleId"); - //获取应用环境模型 -// CiVo envCiVo = ciMapper.getCiByName("APPEnv"); -// if (envCiVo == null) { -// throw new CiNotFoundException("APPEnv"); -// } - //获取需要采集的模型 -// List resourceTypeNameList = AppModuleResourceType.getNameList(); -// List resourceCiVoList = new ArrayList<>(); List envResourceList = new ArrayList<>(); - //获取应用环境实例list -// CiEntityVo envCiEntityVo = new CiEntityVo(); -// envCiEntityVo.setCiId(envCiVo.getId()); -// List envIdList = ciEntityMapper.getCiEntityIdByCiId(envCiEntityVo); BasePageVo search = new BasePageVo(); search.setCurrentPage(1); search.setPageSize(100); @@ -98,9 +82,6 @@ public class AppModuleResourceTypeListApi extends PrivateApiComponentBase { List allCiVoList = ciMapper.getAllCi(null); for (CiVo ci : allCiVoList) { allCiVoMap.put(ci.getId(), ci); -// if (resourceTypeNameList.contains(ci.getName())) { -// resourceCiVoList.add(ci); -// } } ResourceSearchVo searchVo = new ResourceSearchVo(); searchVo.setAppModuleId(appModuleId); @@ -128,28 +109,6 @@ public class AppModuleResourceTypeListApi extends PrivateApiComponentBase { } returnCiVoSet.add(ciVo); } -// //根据模块id和环境id,获取当前环境下含有资产的 模型idList(resourceTypeIdList) -// Set resourceTypeIdSet = resourceMapper.getIpObjectResourceTypeIdListByAppModuleIdAndEnvId(searchVo); -// List resourceTypeIdList = new ArrayList<>(resourceTypeIdSet); -// Set returnCiVoSet = new HashSet<>(); -// if (CollectionUtils.isNotEmpty(resourceTypeIdSet)) { -// resourceTypeIdSet = resourceMapper.getOsResourceTypeIdListByAppModuleIdAndEnvId(searchVo); -// resourceTypeIdList.addAll(resourceTypeIdSet); -// } -// -// //循环resourceTypeIdList,将其父级模型的name存在于resourceTypeNameList中的 模型 返回给前端 -// if (CollectionUtils.isNotEmpty(resourceTypeIdList)) { -// for (Long resourceTypeId : resourceTypeIdList) { -// CiVo ciVo = allCiVoMap.get(resourceTypeId); -// if (ciVo == null) { -// throw new CiNotFoundException(resourceTypeId); -// } -// String resourceTypeName = resourceCenterResourceService.getResourceTypeName(resourceCiVoList, ciVo); -// if (resourceTypeNameList.contains(resourceTypeName)) { -// returnCiVoSet.add(ciVo); -// } -// } -// } if (CollectionUtils.isNotEmpty(returnCiVoSet)) { returnObj.put("env", envResource); returnObj.put("ciVoList", returnCiVoSet); diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/appmodule/ListAppModuleListForTreeApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/appmodule/ListAppModuleListForTreeApi.java index 1a99808f..f32f8697 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/appmodule/ListAppModuleListForTreeApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/appmodule/ListAppModuleListForTreeApi.java @@ -59,26 +59,5 @@ public class ListAppModuleListForTreeApi extends PrivateApiComponentBase { Long appSystemId = paramObj.getLong("appSystemId"); IResourceCenterDataSource resourceCenterDataSource = ResourceCenterDataSourceFactory.getResourceCenterDataSource(); return resourceCenterDataSource.getAppModuleListForTree(appSystemId); -// List tbodyList = resourceMapper.getAppModuleListByAppSystemId(appSystemId); -// if (CollectionUtils.isNotEmpty(tbodyList)) { -// Map appEnvCountMap = new HashMap<>(); -// List> appEnvCountMapList = resourceMapper.getAppEnvCountMapByAppSystemIdGroupByAppModuleId(appSystemId); -// for (Map map : appEnvCountMapList) { -// Long count = map.get("count"); -// Long appModuleId = map.get("appModuleId"); -// appEnvCountMap.put(appModuleId, count); -// } -// for (AppModuleVo appModuleVo : tbodyList) { -// Long count = appEnvCountMap.get(appModuleVo.getId()); -// if (count == null) { -// appModuleVo.setIsHasEnv(0); -// } else if (count == 0) { -// appModuleVo.setIsHasEnv(0); -// } else { -// appModuleVo.setIsHasEnv(1); -// } -// } -// } -// return tbodyList; } } -- Gitee From aa73b358737762144c27ecd14002d8abb96e56d1 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Wed, 2 Apr 2025 11:48:41 +0800 Subject: [PATCH 28/29] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20CMDB=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E6=B8=85=E5=8D=95=E6=94=B9=E6=88=90=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E5=B1=82=E7=BA=A7=E5=8F=AF=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1349157963399168]CMDB应用清单改成模型层级可配置 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1349157963399168 --- .../resource/ResourceListApi.java | 101 ---------------- .../resourcetype/ResourceTypeTreeApi.java | 108 ------------------ .../resourcetype/SaveResourceTypeApi.java | 78 ------------- .../state/ListStateForSelectApi.java | 27 ----- .../vendor/ListVendorForSelectApi.java | 27 ----- .../resourcecenter/AppSystemMapper.java | 3 - 6 files changed, 344 deletions(-) delete mode 100644 src/main/java/neatlogic/module/cmdb/api/resourcecenter/resourcetype/SaveResourceTypeApi.java diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceListApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceListApi.java index 0d6bd500..12cdf650 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceListApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceListApi.java @@ -30,14 +30,9 @@ import neatlogic.framework.restful.annotation.*; import neatlogic.framework.restful.constvalue.OperationTypeEnum; import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; import neatlogic.framework.util.TableResultUtil; -import neatlogic.module.cmdb.dao.mapper.ci.AttrMapper; -import neatlogic.module.cmdb.dao.mapper.ci.CiMapper; -import neatlogic.module.cmdb.dao.mapper.resourcecenter.ResourceEntityMapper; -import neatlogic.module.cmdb.dao.mapper.resourcecenter.ResourceMapper; import neatlogic.module.cmdb.service.ci.CiAuthChecker; import neatlogic.module.cmdb.service.resourcecenter.resource.IResourceCenterResourceService; import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -61,18 +56,6 @@ public class ResourceListApi extends PrivateApiComponentBase { @Resource private IResourceCenterResourceService resourceCenterResourceService; - @Resource - private ResourceMapper resourceMapper; - - @Resource - private ResourceEntityMapper resourceEntityMapper; - - @Resource - private AttrMapper attrMapper; - - @Resource - private CiMapper ciMapper; - @Override public String getToken() { return "resourcecenter/resource/list"; @@ -121,8 +104,6 @@ public class ResourceListApi extends PrivateApiComponentBase { @Description(desc = "nmcarr.resourcelistapi.getname") @Override public Object myDoService(JSONObject jsonObj) throws Exception { -// List resourceList = new ArrayList<>(); -// List resultList = new ArrayList<>(); ResourceSearchVo searchVo; JSONArray defaultValue = jsonObj.getJSONArray("defaultValue"); if (CollectionUtils.isNotEmpty(defaultValue)) { @@ -133,27 +114,6 @@ public class ResourceListApi extends PrivateApiComponentBase { } resourceCenterResourceService.handleBatchSearchList(searchVo); resourceCenterResourceService.setIpFieldAttrIdAndNameFieldAttrId(searchVo); -// if (Objects.equals(searchVo.getRowNum(), 0)) { -// int rowNum = 0; -// if (noFilterCondition(searchVo)) { -// rowNum = resourceMapper.getAllResourceCount(searchVo); -// } else { -// rowNum = resourceMapper.getResourceCount(searchVo); -// } -// if (rowNum == 0) { -// return TableResultUtil.getResult(resourceList, searchVo); -// } -// searchVo.setRowNum(rowNum); -// } -// resourceCenterResourceService.setIsIpFieldSortAndIsNameFieldSort(searchVo); -// List idList = resourceMapper.getResourceIdList(searchVo); -// if (CollectionUtils.isEmpty(idList)) { -// return TableResultUtil.getResult(resourceList, searchVo); -// } -// resourceList = resourceMapper.getResourceListByIdList(idList); -// if (CollectionUtils.isNotEmpty(resourceList)) { -// resourceCenterResourceService.addTagAndAccountInformation(resourceList); -// } IResourceCenterDataSource resourceCenterDataSource = ResourceCenterDataSourceFactory.getResourceCenterDataSource(); List resultList = resourceCenterDataSource.getResourceList(searchVo); if (CollectionUtils.isNotEmpty(resultList)) { @@ -163,16 +123,6 @@ public class ResourceListApi extends PrivateApiComponentBase { Set typeIdList = resultList.stream().map(ResourceVo::getTypeId).collect(Collectors.toSet()); List canDeleteTypeIdList = new ArrayList<>(); List canEditTypeIdList = new ArrayList<>(); - //排序 -// for (Long id : idList) { -// for (ResourceVo resourceVo : resourceList) { -// if (Objects.equals(id, resourceVo.getId())) { -// resultList.add(resourceVo); -// typeIdList.add(resourceVo.getTypeId()); -// break; -// } -// } -// } //补充配置项权限 Set withoutCiAuthCiEntityList = new HashSet<>(); @@ -208,55 +158,4 @@ public class ResourceListApi extends PrivateApiComponentBase { return TableResultUtil.getResult(resultList, searchVo); } - /** - * 判断是否有过滤条件 - * @param searchVo - * @return - */ - private boolean noFilterCondition(ResourceSearchVo searchVo) { - if (StringUtils.isNotBlank(searchVo.getKeyword())) { - return false; - } - if (CollectionUtils.isNotEmpty(searchVo.getBatchSearchList())) { - return false; - } - if (CollectionUtils.isNotEmpty(searchVo.getStateIdList())) { - return false; - } - if (CollectionUtils.isNotEmpty(searchVo.getVendorIdList())) { - return false; - } - if (CollectionUtils.isNotEmpty(searchVo.getEnvIdList())) { - return false; - } - if (searchVo.getExistNoEnv()) { - return false; - } - if (CollectionUtils.isNotEmpty(searchVo.getAppSystemIdList())) { - return false; - } - if (CollectionUtils.isNotEmpty(searchVo.getAppModuleIdList())) { - return false; - } - if (CollectionUtils.isNotEmpty(searchVo.getDefaultValue())) { - return false; - } - if (CollectionUtils.isNotEmpty(searchVo.getIdList())) { - return false; - } - if (CollectionUtils.isNotEmpty(searchVo.getInspectStatusList())) { - return false; - } - if (CollectionUtils.isNotEmpty(searchVo.getProtocolIdList())) { - return false; - } - if (CollectionUtils.isNotEmpty(searchVo.getTagIdList())) { - return false; - } - if (CollectionUtils.isNotEmpty(searchVo.getInspectJobPhaseNodeStatusList())) { - return false; - } - return true; - } - } diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resourcetype/ResourceTypeTreeApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resourcetype/ResourceTypeTreeApi.java index d4d2cc7b..731a6485 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resourcetype/ResourceTypeTreeApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resourcetype/ResourceTypeTreeApi.java @@ -65,113 +65,5 @@ public class ResourceTypeTreeApi extends PrivateApiComponentBase { String keyword = jsonObj.getString("keyword"); IResourceCenterDataSource resourceCenterDataSource = ResourceCenterDataSourceFactory.getResourceCenterDataSource(); return resourceCenterDataSource.getResourceTypeTree(keyword); -// if (StringUtils.isNotBlank(keyword)) { -// keyword = keyword.toLowerCase(); -// } -// List resultList = new ArrayList<>(); -// List authCiVoList = new ArrayList<>(); -// List ciIdList = resourceEntityMapper.getAllResourceTypeCiIdList(); -// jsonObj.put("typeIdList", ciIdList); -// ResourceSearchVo searchVo = resourceCenterResourceService.assembleResourceSearchVo(jsonObj, false); -// //先找出所有有权限的配置项的模型idList -// if (!searchVo.getIsHasAuth()) { -// Set authCiIdList = ciMapper.getAllAuthCi(UserContext.get().getAuthenticationInfoVo()).stream().map(CiVo::getId).collect(Collectors.toSet()); -// authCiIdList.addAll(resourceMapper.getResourceTypeIdListByAuth(searchVo)); -// if (CollectionUtils.isEmpty(authCiIdList)) { -// return resultList; -// } -// authCiVoList = ciMapper.getCiByIdList(new ArrayList<>(authCiIdList)); -// } -// -// -// if (CollectionUtils.isNotEmpty(ciIdList)) { -// List ciVoList = ciMapper.getCiByIdList(ciIdList); -// ciVoList.sort(Comparator.comparing(CiVo::getLft)); -// for (CiVo ciVo : ciVoList) { -// Set ciList = new HashSet<>(); -// List ciListTmp = ciMapper.getDownwardCiListByLR(ciVo.getLft(), ciVo.getRht()); -// //过滤出所有有权限的配置项的模型idList -// if (!searchVo.getIsHasAuth()) { -// if (CollectionUtils.isNotEmpty(authCiVoList) && CollectionUtils.isNotEmpty(ciListTmp)) { -// for (CiVo ci : ciListTmp) { -// for (CiVo authCi : authCiVoList) { -// if (ci.getLft() <= authCi.getLft() && ci.getRht() >= authCi.getRht()) { -// ciList.add(ci); -// break; -// } -// } -// } -// } -// } else { -// ciList = new HashSet<>(ciListTmp); -// } -// int size = ciList.size(); -// List resourceTypeVoList = new ArrayList<>(size); -// Map resourceTypeMap = new HashMap<>(size); -// for (CiVo ci : ciList) { -// ResourceTypeVo resourceTypeVo = new ResourceTypeVo(ci.getId(), ci.getParentCiId(), ci.getLabel(), ci.getName()); -// resourceTypeMap.put(resourceTypeVo.getId(), resourceTypeVo); -// resourceTypeVoList.add(resourceTypeVo); -// } -// if (StringUtils.isNotBlank(keyword)) { -// // 建立父子关系 -// for (ResourceTypeVo resourceType : resourceTypeVoList) { -// if (resourceType.getParentId() != null) { -// ResourceTypeVo parentResourceType = resourceTypeMap.get(resourceType.getParentId()); -// if (parentResourceType != null) { -// resourceType.setParent(parentResourceType); -// parentResourceType.addChild(resourceType); -// } -// } -// } -// // 判断节点名称是否与关键字keyword匹配,如果匹配就将该节点及其父子节点的isKeywordMatch字段值设置为1,否则设置为0。 -// for (ResourceTypeVo resourceType : resourceTypeVoList) { -// if (resourceType.getLabel().toLowerCase().contains(keyword)) { -// if (resourceType.getIsKeywordMatch() == null) { -// resourceType.setIsKeywordMatch(1); -// resourceType.setUpwardIsKeywordMatch(1); -// resourceType.setDownwardIsKeywordMatch(1); -// } -// } else { -// if (resourceType.getIsKeywordMatch() == null) { -// resourceType.setIsKeywordMatch(0); -// } -// } -// } -// // 将isKeywordMatch字段值为0的节点从其父级中移除。 -// Iterator iterator = resourceTypeVoList.iterator(); -// while (iterator.hasNext()) { -// ResourceTypeVo resourceType = iterator.next(); -// if (Objects.equals(resourceType.getIsKeywordMatch(), 0)) { -// ResourceTypeVo parent = resourceType.getParent(); -// if (parent != null) { -// parent.removeChild(resourceType); -// } -// iterator.remove(); -// } -// } -// } else { -// for (ResourceTypeVo resourceType : resourceTypeVoList) { -// if (resourceType.getParentId() != null) { -// ResourceTypeVo parentResourceType = resourceTypeMap.get(resourceType.getParentId()); -// if (parentResourceType != null) { -// parentResourceType.addChild(resourceType); -// } -// } -// } -// } -// for (ResourceTypeVo resourceType : resourceTypeVoList) { -// if (resourceType.getParentId() != null) { -// ResourceTypeVo parentResourceType = resourceTypeMap.get(resourceType.getParentId()); -// if (parentResourceType == null) { -// resultList.add(resourceType); -// } -// } else { -// resultList.add(resourceType); -// } -// } -// } -// } -// return resultList; } } diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resourcetype/SaveResourceTypeApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resourcetype/SaveResourceTypeApi.java deleted file mode 100644 index cc2da874..00000000 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resourcetype/SaveResourceTypeApi.java +++ /dev/null @@ -1,78 +0,0 @@ -/*Copyright (C) 2024 深圳极向量科技有限公司 All Rights Reserved. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see .*/ - -package neatlogic.module.cmdb.api.resourcecenter.resourcetype; - -import com.alibaba.fastjson.JSONObject; -import neatlogic.framework.auth.core.AuthAction; -import neatlogic.framework.cmdb.auth.label.CMDB; -import neatlogic.framework.cmdb.dto.ci.CiVo; -import neatlogic.framework.cmdb.exception.ci.CiNotFoundException; -import neatlogic.framework.common.constvalue.ApiParamType; -import neatlogic.framework.restful.annotation.*; -import neatlogic.framework.restful.constvalue.OperationTypeEnum; -import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; -import neatlogic.module.cmdb.dao.mapper.ci.CiMapper; -import neatlogic.module.cmdb.dao.mapper.resourcecenter.ResourceEntityMapper; -import org.apache.commons.collections4.CollectionUtils; - -import javax.annotation.Resource; -import java.util.List; - -//@Service -@Deprecated -@AuthAction(action = CMDB.class) -@OperationType(type = OperationTypeEnum.UPDATE) -public class SaveResourceTypeApi extends PrivateApiComponentBase { - - @Resource - private ResourceEntityMapper resourceEntityMapper; - - @Resource - private CiMapper ciMapper; - - @Override - public String getName() { - return "nmcarr.saveresourcetypeapi.getname"; - } - - @Input({ - @Param(name = "ciId", type = ApiParamType.LONG, isRequired = true, desc = "term.cmdb.ciid") - }) - @Output({}) - @Description(desc = "nmcarr.saveresourcetypeapi.getname") - @Override - public Object myDoService(JSONObject paramObj) throws Exception { - Long ciId = paramObj.getLong("ciId"); - CiVo ciVo = ciMapper.getCiById(ciId); - if (ciVo == null) { - throw new CiNotFoundException(ciId); - } - List ciIdList = resourceEntityMapper.getAllResourceTypeCiIdList(); - if (ciIdList.contains(ciId)) { - return null; - } - if (CollectionUtils.isNotEmpty(ciIdList)) { - resourceEntityMapper.deleteResourceTypeCi(); - } - resourceEntityMapper.insertResourceTypeCi(ciId); - return null; - } - - @Override - public String getToken() { - return "resourcecenter/resourcetype/save"; - } -} diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/state/ListStateForSelectApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/state/ListStateForSelectApi.java index 87b110e2..96db7d21 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/state/ListStateForSelectApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/state/ListStateForSelectApi.java @@ -68,32 +68,5 @@ public class ListStateForSelectApi extends PrivateApiComponentBase { IResourceCenterDataSource resourceCenterDataSource = ResourceCenterDataSourceFactory.getResourceCenterDataSource(); List tbodyList = resourceCenterDataSource.getStateListForSelect(searchVo); return TableResultUtil.getResult(tbodyList, searchVo); -// JSONArray defaultValue = searchVo.getDefaultValue(); -// if (CollectionUtils.isNotEmpty(defaultValue)) { -// List idList = defaultValue.toJavaList(Long.class); -// List resourceList = resourceMapper.searchStateListByIdList(idList); -// return TableResultUtil.getResult(resourceList); -// } else { -// int rowNum = resourceMapper.searchStateCount(searchVo); -// if (rowNum > 0) { -// searchVo.setRowNum(rowNum); -// if (searchVo.getNeedPage()) { -// List idList = resourceMapper.searchStateIdList(searchVo); -// List resourceList = resourceMapper.searchStateListByIdList(idList); -// return TableResultUtil.getResult(resourceList, searchVo); -// } else { -// List allResourceList = new ArrayList<>(); -// int pageCount = searchVo.getPageCount(); -// for (int currentPage = 1; currentPage <= pageCount; currentPage++) { -// searchVo.setCurrentPage(currentPage); -// List idList = resourceMapper.searchStateIdList(searchVo); -// List resourceList = resourceMapper.searchStateListByIdList(idList); -// allResourceList.addAll(resourceList); -// } -// return TableResultUtil.getResult(allResourceList, searchVo); -// } -// } -// } -// return null; } } diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/vendor/ListVendorForSelectApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/vendor/ListVendorForSelectApi.java index 274852f1..80d7422a 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/vendor/ListVendorForSelectApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/vendor/ListVendorForSelectApi.java @@ -68,32 +68,5 @@ public class ListVendorForSelectApi extends PrivateApiComponentBase { IResourceCenterDataSource resourceCenterDataSource = ResourceCenterDataSourceFactory.getResourceCenterDataSource(); List tbodyList = resourceCenterDataSource.getVendorListForSelect(searchVo); return TableResultUtil.getResult(tbodyList, searchVo); -// JSONArray defaultValue = searchVo.getDefaultValue(); -// if (CollectionUtils.isNotEmpty(defaultValue)) { -// List idList = defaultValue.toJavaList(Long.class); -// List resourceList = resourceMapper.searchVendorListByIdList(idList); -// return TableResultUtil.getResult(resourceList); -// } else { -// int rowNum = resourceMapper.searchVendorCount(searchVo); -// if (rowNum > 0) { -// searchVo.setRowNum(rowNum); -// if (searchVo.getNeedPage()) { -// List idList = resourceMapper.searchVendorIdList(searchVo); -// List resourceList = resourceMapper.searchVendorListByIdList(idList); -// return TableResultUtil.getResult(resourceList, searchVo); -// } else { -// List allResourceList = new ArrayList<>(); -// int pageCount = searchVo.getPageCount(); -// for (int currentPage = 1; currentPage <= pageCount; currentPage++) { -// searchVo.setCurrentPage(currentPage); -// List idList = resourceMapper.searchVendorIdList(searchVo); -// List resourceList = resourceMapper.searchVendorListByIdList(idList); -// allResourceList.addAll(resourceList); -// } -// return TableResultUtil.getResult(allResourceList, searchVo); -// } -// } -// } -// return null; } } diff --git a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/AppSystemMapper.java b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/AppSystemMapper.java index c950d07d..a885dda7 100644 --- a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/AppSystemMapper.java +++ b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/AppSystemMapper.java @@ -34,7 +34,4 @@ public interface AppSystemMapper extends IAppSystemMapper { AppModuleVo getAppModuleById(Long id); List getAppModuleListByIdList(List idList); - -// List getAppEnvListByAppSystemIdAndModuleIdList(@Param("appSystemId") Long appSystemId, @Param("appModuleIdList") List appModuleIdList); - } -- Gitee From f21f30e134af49926bbe4ac8f159c7a3cb7add4a Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Wed, 2 Apr 2025 11:50:51 +0800 Subject: [PATCH 29/29] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20CMDB=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E6=B8=85=E5=8D=95=E6=94=B9=E6=88=90=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E5=B1=82=E7=BA=A7=E5=8F=AF=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1349157963399168]CMDB应用清单改成模型层级可配置 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1349157963399168 --- .../appmodule/AppModuleResourceListApi.java | 77 ------------------- 1 file changed, 77 deletions(-) delete mode 100644 src/main/java/neatlogic/module/cmdb/api/resourcecenter/appmodule/AppModuleResourceListApi.java diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/appmodule/AppModuleResourceListApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/appmodule/AppModuleResourceListApi.java deleted file mode 100644 index 34f33017..00000000 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/appmodule/AppModuleResourceListApi.java +++ /dev/null @@ -1,77 +0,0 @@ -/*Copyright (C) 2024 深圳极向量科技有限公司 All Rights Reserved. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see .*/ - -package neatlogic.module.cmdb.api.resourcecenter.appmodule; - -import com.alibaba.fastjson.JSONObject; -import neatlogic.framework.auth.core.AuthAction; -import neatlogic.framework.cmdb.auth.label.CMDB_BASE; -import neatlogic.framework.common.constvalue.ApiParamType; -import neatlogic.framework.restful.annotation.*; -import neatlogic.framework.restful.constvalue.OperationTypeEnum; -import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; - -/** - * @author linbq - * @since 2021/6/17 11:54 - **/ -//@Service -@Deprecated -@AuthAction(action = CMDB_BASE.class) -@OperationType(type = OperationTypeEnum.SEARCH) -public class AppModuleResourceListApi extends PrivateApiComponentBase { - -// @Resource -// private IResourceCenterResourceService resourceCenterResourceService; - - @Override - public String getToken() { - return "resourcecenter/appmodule/resource/list"; - } - - @Override - public String getName() { - return "查询应用模块中资源列表"; - } - - @Override - public String getConfig() { - return null; - } - - @Input({ - @Param(name = "appSystemId", type = ApiParamType.LONG, desc = "应用id"), - @Param(name = "appModuleId", type = ApiParamType.LONG, desc = "应用模块id"), - @Param(name = "envId", type = ApiParamType.LONG, desc = "环境id,envId=-2表示无配置环境"), - @Param(name = "typeId", type = ApiParamType.LONG, desc = "类型id"), - @Param(name = "currentPage", type = ApiParamType.INTEGER, desc = "当前页"), - @Param(name = "pageSize", type = ApiParamType.INTEGER, desc = "每页数据条目"), - @Param(name = "needPage", type = ApiParamType.BOOLEAN, desc = "是否需要分页,默认true") - }) - @Output({ - @Param(name = "tableList", type = ApiParamType.JSONARRAY, desc = "资源环境列表") - }) - @Description(desc = "查询资源环境列表") - @Override - public Object myDoService(JSONObject paramObj) throws Exception { - JSONObject resultObj = new JSONObject(); -// ResourceSearchVo searchVo = paramObj.toJavaObject(ResourceSearchVo.class); -// if (searchVo.getAppSystemId() == null && searchVo.getAppModuleId() == null) { -// throw new ParamNotExistsException("应用id(appSystemId)", "应用模块id(appModuleId)"); -// } -// resultObj.put("tableList", resourceCenterResourceService.getAppModuleResourceList(searchVo)); - return resultObj; - } -} -- Gitee