From cb3f36d41fede963fda0541b464eca90a06a46e2 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Tue, 17 Jun 2025 11:03:09 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96=E7=BB=84=E5=90=88=E5=B7=A5=E5=85=B7=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?=E6=89=8B=E5=8A=A8=E8=BE=93=E5=85=A5=E8=8A=82=E7=82=B9=E6=80=A7?= =?UTF-8?q?=E8=83=BD=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1444946337300480]自动化组合工具校验手动输入节点性能优化 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1444946337300480 --- .../CheckResourceInputNodeListApi.java | 77 +++++++--- .../mapper/resourcecenter/ResourceMapper.java | 6 + .../mapper/resourcecenter/ResourceMapper.xml | 133 ++++++++++++++++++ .../handler/ResourcesHandler.java | 50 ++++++- 4 files changed, 240 insertions(+), 26 deletions(-) diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/CheckResourceInputNodeListApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/CheckResourceInputNodeListApi.java index 031ba5f8..15e46024 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/CheckResourceInputNodeListApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/CheckResourceInputNodeListApi.java @@ -21,6 +21,7 @@ import com.alibaba.fastjson.JSONObject; 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.common.constvalue.ApiParamType; import neatlogic.framework.dto.condition.ConditionGroupRelVo; import neatlogic.framework.dto.condition.ConditionGroupVo; @@ -34,7 +35,9 @@ import org.apache.commons.collections4.MapUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.util.ArrayList; import java.util.List; +import java.util.Objects; @Service @AuthAction(action = CMDB.class) @@ -109,39 +112,49 @@ public class CheckResourceInputNodeListApi extends PrivateApiComponentBase { } } else { // 简单模式 + List nodeList = new ArrayList<>(); ResourceSearchVo searchVo = resourceCenterResourceService.assembleResourceSearchVo(filter); + searchVo.setCmdbGroupType(cmdbGroupType); for (int i = 0; i < inputNodeList.size(); i++) { JSONObject inputNodeObj = inputNodeList.getJSONObject(i); - ResourceSearchVo node = JSON.toJavaObject(inputNodeObj, ResourceSearchVo.class); - searchVo.setCmdbGroupType(cmdbGroupType); - searchVo.setIp(node.getIp()); - searchVo.setPort(node.getPort()); - searchVo.setName(node.getName()); - Long resourceId = resourceMapper.getResourceIdByIpAndPortAndNameWithFilter(searchVo); - if (resourceId == null) { - nonExistList.add(inputNodeObj); - } else { - existList.add(inputNodeObj); + ResourceVo node = JSON.toJavaObject(inputNodeObj, ResourceVo.class); + nodeList.add(node); + if (nodeList.size() > 100) { + searchVo.setInputNodeList(nodeList); + List resourceList = resourceMapper.getResourceListByIpAndPortAndNameWithFilter(searchVo); + existsOrNot(nodeList, resourceList, existList, nonExistList); + nodeList.clear(); } } + if (CollectionUtils.isNotEmpty(nodeList)) { + searchVo.setInputNodeList(nodeList); + List resourceList = resourceMapper.getResourceListByIpAndPortAndNameWithFilter(searchVo); + existsOrNot(nodeList, resourceList, existList, nonExistList); + nodeList.clear(); + } } } else { // 没有过滤条件 + List nodeList = new ArrayList<>(); ResourceSearchVo searchVo = resourceCenterResourceService.assembleResourceSearchVo(new JSONObject()); + searchVo.setCmdbGroupType(cmdbGroupType); for (int i = 0; i < inputNodeList.size(); i++) { JSONObject inputNodeObj = inputNodeList.getJSONObject(i); - ResourceSearchVo node = JSON.toJavaObject(inputNodeObj, ResourceSearchVo.class); - searchVo.setCmdbGroupType(cmdbGroupType); - searchVo.setIp(node.getIp()); - searchVo.setPort(node.getPort()); - searchVo.setName(node.getName()); - Long resourceId = resourceMapper.getResourceIdByIpAndPortAndName(searchVo); - if (resourceId == null) { - nonExistList.add(inputNodeObj); - } else { - existList.add(inputNodeObj); + ResourceVo node = JSON.toJavaObject(inputNodeObj, ResourceVo.class); + nodeList.add(node); + if (nodeList.size() > 100) { + searchVo.setInputNodeList(nodeList); + List resourceList = resourceMapper.getResourceListByIpAndPortAndName(searchVo); + existsOrNot(nodeList, resourceList, existList, nonExistList); + nodeList.clear(); } } + if (CollectionUtils.isNotEmpty(nodeList)) { + searchVo.setInputNodeList(nodeList); + List resourceList = resourceMapper.getResourceListByIpAndPortAndName(searchVo); + existsOrNot(nodeList, resourceList, existList, nonExistList); + nodeList.clear(); + } } JSONObject resultObj = new JSONObject(); resultObj.put("existList", existList); @@ -153,4 +166,28 @@ public class CheckResourceInputNodeListApi extends PrivateApiComponentBase { public String getToken() { return "resourcecenter/resource/inputnodelist/check"; } + + private void existsOrNot(List nodeList, List resourceList, JSONArray existList, JSONArray nonExistList) { + for (ResourceVo node : nodeList) { + boolean flag = false; + for (ResourceVo resourceVo : resourceList) { + if (Objects.equals(node.getIp(), resourceVo.getIp()) + && Objects.equals(node.getPort(), resourceVo.getPort()) + && (node.getName() == null || Objects.equals(node.getName(), resourceVo.getName())) + ) { + flag = true; + break; + } + } + JSONObject inputNodeObj = new JSONObject(); + inputNodeObj.put("ip", node.getIp()); + inputNodeObj.put("port", node.getPort()); + inputNodeObj.put("name", node.getName()); + if (flag) { + existList.add(inputNodeObj); + } else { + nonExistList.add(inputNodeObj); + } + } + } } 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 fb84e14b..435581b5 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 @@ -56,8 +56,14 @@ public interface ResourceMapper extends IResourceCrossoverMapper { Long getResourceIdByIpAndPortAndName(ResourceSearchVo searchVo); + List getResourceIdListByIpAndPortAndName(ResourceSearchVo searchVo); + + List getResourceListByIpAndPortAndName(ResourceSearchVo searchVo); + Long getResourceIdByIpAndPortAndNameWithFilter(ResourceSearchVo searchVo); + List getResourceListByIpAndPortAndNameWithFilter(ResourceSearchVo searchVo); + List getResourceByIdList(List idList); List getAuthResourceList(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 b05538c2..6bf85f2f 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 @@ -776,6 +776,90 @@ along with this program. If not, see .--> LIMIT 1 + + + + + +