From bbf5e76fc21c8e9b50446ebe09dbf6dc6d480a07 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Tue, 30 Jul 2024 18:17:32 +0800 Subject: [PATCH] =?UTF-8?q?[=E4=BF=AE=E5=A4=8D]=20=E8=B5=84=E4=BA=A7?= =?UTF-8?q?=E6=B8=85=E5=8D=95-=E5=AF=BC=E5=87=BA=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1212184099520512]资产清单-导出异常 http://192.168.0.96:8090/demo/rdm.html#/bug-detail/939050947543040/939050947543057/1212184099520512 --- .../resource/ExportResourceApi.java | 39 +++++++------- .../resource/ResourceListApi.java | 53 +----------------- .../IResourceCenterResourceService.java | 12 +++++ .../ResourceCenterResourceServiceImpl.java | 54 +++++++++++++++++++ 4 files changed, 89 insertions(+), 69 deletions(-) diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ExportResourceApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ExportResourceApi.java index 7de56279..f1de6a86 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ExportResourceApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ExportResourceApi.java @@ -78,7 +78,7 @@ public class ExportResourceApi extends PrivateBinaryStreamApiComponentBase { @Override public String getName() { - return "导出资产清单列表"; + return "nmcarr.exportresourceapi.getname"; } @Override @@ -87,24 +87,25 @@ public class ExportResourceApi extends PrivateBinaryStreamApiComponentBase { } @Input({ - @Param(name = "keyword", type = ApiParamType.STRING, xss = true, desc = "模糊搜索"), - @Param(name = "typeId", type = ApiParamType.LONG, isRequired = true, desc = "类型id"), - @Param(name = "protocolIdList", type = ApiParamType.JSONARRAY, desc = "协议id列表"), - @Param(name = "stateIdList", type = ApiParamType.JSONARRAY, desc = "状态id列表"), - @Param(name = "vendorIdList", type = ApiParamType.JSONARRAY, desc = "厂商id列表"), - @Param(name = "envIdList", type = ApiParamType.JSONARRAY, desc = "环境id列表"), - @Param(name = "appSystemIdList", type = ApiParamType.JSONARRAY, desc = "应用系统id列表"), - @Param(name = "appModuleIdList", type = ApiParamType.JSONARRAY, desc = "应用模块id列表"), - @Param(name = "typeIdList", type = ApiParamType.JSONARRAY, desc = "资源类型id列表"), - @Param(name = "tagIdList", type = ApiParamType.JSONARRAY, desc = "标签id列表"), - @Param(name = "inspectStatusList", type = ApiParamType.JSONARRAY, desc = "巡检状态列表"), - @Param(name = "defaultValue", type = ApiParamType.JSONARRAY, desc = "用于回显的资源ID列表") + @Param(name = "keyword", type = ApiParamType.STRING, xss = true, desc = "common.keyword"), + @Param(name = "typeId", type = ApiParamType.LONG, isRequired = true, desc = "common.typeid"), + @Param(name = "protocolIdList", type = ApiParamType.JSONARRAY, desc = "term.cmdb.protocolidlist"), + @Param(name = "stateIdList", type = ApiParamType.JSONARRAY, desc = "term.cmdb.stateidlist"), + @Param(name = "vendorIdList", type = ApiParamType.JSONARRAY, desc = "term.cmdb.vendoridlist"), + @Param(name = "envIdList", type = ApiParamType.JSONARRAY, desc = "term.cmdb.envidlist"), + @Param(name = "appSystemIdList", type = ApiParamType.JSONARRAY, desc = "term.appsystemidlist"), + @Param(name = "appModuleIdList", type = ApiParamType.JSONARRAY, desc = "term.cmdb.appmoduleidlist"), + @Param(name = "typeIdList", type = ApiParamType.JSONARRAY, desc = "term.cmdb.typeidlist"), + @Param(name = "tagIdList", type = ApiParamType.JSONARRAY, desc = "common.tagidlist"), + @Param(name = "inspectStatusList", type = ApiParamType.JSONARRAY, desc = "term.inspect.inspectstatuslist"), + @Param(name = "searchField", type = ApiParamType.STRING, desc = "term.cmdb.searchfield"), + @Param(name = "batchSearchList", type = ApiParamType.JSONARRAY, desc = "term.cmdb.batchsearchlist"), + @Param(name = "defaultValue", type = ApiParamType.JSONARRAY, desc = "common.defaultvalue"), }) @Description(desc = "导出资产清单列表") @Override public Object myDoService(JSONObject paramObj, HttpServletRequest request, HttpServletResponse response) throws Exception { - ResourceSearchVo searchVo = JSONObject.toJavaObject(paramObj, ResourceSearchVo.class); - Long typeId = searchVo.getTypeId(); + Long typeId = paramObj.getLong("typeId"); CiVo ciVo = ciMapper.getCiById(typeId); if (ciVo == null) { throw new CiNotFoundException(typeId); @@ -129,7 +130,7 @@ public class ExportResourceApi extends PrivateBinaryStreamApiComponentBase { .withColumnList(getColumnList()); Workbook workbook = builder.build(); List resourceList = new ArrayList<>(); - JSONArray defaultValue = searchVo.getDefaultValue(); + JSONArray defaultValue = paramObj.getJSONArray("defaultValue"); if (CollectionUtils.isNotEmpty(defaultValue)) { List idList = defaultValue.toJavaList(Long.class); resourceList = resourceMapper.getResourceListByIdList(idList); @@ -139,12 +140,14 @@ public class ExportResourceApi extends PrivateBinaryStreamApiComponentBase { sheetBuilder.addData(dataMap); } } else { - List typeIdList = resourceCenterResourceService.getDownwardCiIdListByCiIdList(Arrays.asList(typeId)); - searchVo.setTypeIdList(typeIdList); + ResourceSearchVo searchVo = resourceCenterResourceService.assembleResourceSearchVo(paramObj); + resourceCenterResourceService.handleBatchSearchList(searchVo); + resourceCenterResourceService.setIpFieldAttrIdAndNameFieldAttrId(searchVo); int rowNum = resourceMapper.getResourceCount(searchVo); if (rowNum > 0) { searchVo.setPageSize(100); searchVo.setRowNum(rowNum); + resourceCenterResourceService.setIsIpFieldSortAndIsNameFieldSort(searchVo); for (int i = 1; i <= searchVo.getPageCount(); i++) { searchVo.setCurrentPage(i); List idList = resourceMapper.getResourceIdList(searchVo); 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 580c81c2..35725e35 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,13 +19,8 @@ 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.ci.AttrVo; -import neatlogic.framework.cmdb.dto.ci.CiVo; 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.ResourceEntityFieldMappingVo; -import neatlogic.framework.cmdb.dto.resourcecenter.config.ResourceEntityVo; import neatlogic.framework.cmdb.enums.group.GroupType; import neatlogic.framework.common.constvalue.ApiParamType; import neatlogic.framework.common.dto.BasePageVo; @@ -131,41 +126,7 @@ public class ResourceListApi extends PrivateApiComponentBase { searchVo = resourceCenterResourceService.assembleResourceSearchVo(jsonObj); } resourceCenterResourceService.handleBatchSearchList(searchVo); - ResourceEntityVo resourceEntityVo = resourceEntityMapper.getResourceEntityByName("scence_ipobject_detail"); - if (resourceEntityVo != null) { - ResourceEntityConfigVo config = resourceEntityVo.getConfig(); - if (config != null) { - List mappingList = config.getFieldMappingList(); - if (CollectionUtils.isNotEmpty(mappingList)) { - Long nameAttrId = null; - Long ipAttrId = null; - for (ResourceEntityFieldMappingVo mappingVo : mappingList) { - if (Objects.equals(mappingVo.getField(), "name")) { - CiVo ciVo = ciMapper.getCiByName(mappingVo.getFromCi()); - if (ciVo != null) { - AttrVo attr = attrMapper.getAttrByCiIdAndName(ciVo.getId(), mappingVo.getFromAttr()); - if (attr != null) { - nameAttrId = attr.getId(); - } - } - } else if (Objects.equals(mappingVo.getField(), "ip")) { - CiVo ciVo = ciMapper.getCiByName(mappingVo.getFromCi()); - if (ciVo != null) { - AttrVo attr = attrMapper.getAttrByCiIdAndName(ciVo.getId(), mappingVo.getFromAttr()); - if (attr != null) { - ipAttrId = attr.getId(); - } - } - } - if (nameAttrId != null && ipAttrId != null) { - break; - } - } - searchVo.setIpFieldAttrId(ipAttrId); - searchVo.setNameFieldAttrId(nameAttrId); - } - } - } + resourceCenterResourceService.setIpFieldAttrIdAndNameFieldAttrId(searchVo); if (Objects.equals(searchVo.getRowNum(), 0)) { int rowNum = 0; if (noFilterCondition(searchVo)) { @@ -178,17 +139,7 @@ public class ResourceListApi extends PrivateApiComponentBase { } searchVo.setRowNum(rowNum); } - if (StringUtils.isNotBlank(searchVo.getKeyword())) { - int ipKeywordCount = resourceMapper.getResourceCountByIpKeyword(searchVo); - if (ipKeywordCount > 0) { - searchVo.setIsIpFieldSort(1); - } else { - int nameKeywordCount = resourceMapper.getResourceCountByNameKeyword(searchVo); - if (nameKeywordCount > 0) { - searchVo.setIsNameFieldSort(1); - } - } - } + resourceCenterResourceService.setIsIpFieldSortAndIsNameFieldSort(searchVo); List idList = resourceMapper.getResourceIdList(searchVo); if (CollectionUtils.isEmpty(idList)) { return TableResultUtil.getResult(resourceList, 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 08f657af..ecae7f41 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 @@ -48,6 +48,18 @@ public interface IResourceCenterResourceService extends IResourceCenterResourceC */ void handleBatchSearchList(ResourceSearchVo resourceSearchVo); + /** + * 设置ipFieldAttrId字段和nameFieldAttrId字段 + * @param resourceSearchVo + */ + void setIpFieldAttrIdAndNameFieldAttrId(ResourceSearchVo resourceSearchVo); + + /** + * 设置isIpFieldSort字段和isNameFieldSort字段 + * @param resourceSearchVo + */ + void setIsIpFieldSortAndIsNameFieldSort(ResourceSearchVo resourceSearchVo); + /** * 查询所有后代模型的id列表 * 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 5db921a6..3c3199de 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 @@ -235,6 +235,60 @@ public class ResourceCenterResourceServiceImpl implements IResourceCenterResourc } } + @Override + public void setIpFieldAttrIdAndNameFieldAttrId(ResourceSearchVo searchVo) { + ResourceEntityVo resourceEntityVo = resourceEntityMapper.getResourceEntityByName("scence_ipobject_detail"); + if (resourceEntityVo != null) { + ResourceEntityConfigVo config = resourceEntityVo.getConfig(); + if (config != null) { + List mappingList = config.getFieldMappingList(); + if (CollectionUtils.isNotEmpty(mappingList)) { + Long nameAttrId = null; + Long ipAttrId = null; + for (ResourceEntityFieldMappingVo mappingVo : mappingList) { + if (Objects.equals(mappingVo.getField(), "name")) { + CiVo ciVo = ciMapper.getCiByName(mappingVo.getFromCi()); + if (ciVo != null) { + AttrVo attr = attrMapper.getAttrByCiIdAndName(ciVo.getId(), mappingVo.getFromAttr()); + if (attr != null) { + nameAttrId = attr.getId(); + } + } + } else if (Objects.equals(mappingVo.getField(), "ip")) { + CiVo ciVo = ciMapper.getCiByName(mappingVo.getFromCi()); + if (ciVo != null) { + AttrVo attr = attrMapper.getAttrByCiIdAndName(ciVo.getId(), mappingVo.getFromAttr()); + if (attr != null) { + ipAttrId = attr.getId(); + } + } + } + if (nameAttrId != null && ipAttrId != null) { + break; + } + } + searchVo.setIpFieldAttrId(ipAttrId); + searchVo.setNameFieldAttrId(nameAttrId); + } + } + } + } + + @Override + public void setIsIpFieldSortAndIsNameFieldSort(ResourceSearchVo searchVo) { + if (StringUtils.isNotBlank(searchVo.getKeyword())) { + int ipKeywordCount = resourceMapper.getResourceCountByIpKeyword(searchVo); + if (ipKeywordCount > 0) { + searchVo.setIsIpFieldSort(1); + } else { + int nameKeywordCount = resourceMapper.getResourceCountByNameKeyword(searchVo); + if (nameKeywordCount > 0) { + searchVo.setIsNameFieldSort(1); + } + } + } + } + @Override public List getDownwardCiIdListByCiIdList(List idList) { Set ciIdSet = new HashSet<>(); -- Gitee