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 031ba5f8fb73af1e4f9c19654e17226f8b6e8e9b..15e4602462879409a99bf87604728188d2bcdd50 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 fb84e14b92ba3654993ffa63c9da4096053bac26..435581b574411ed87d03dab8452f99dbee052134 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 b05538c2185fbbe9d7eb8c757172bb0657601bc4..6bf85f2fb9495e8b8e0e0ed0939c497c14633560 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 + + + + + +