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 7de56279766ff7a064f6c474b7d12e80afdc1bb7..f1de6a864091b1e82e64cba95d8d4d828663e923 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 580c81c22a7521b9241d73357acfbecdbd419f3e..35725e357fb79f484c29e542caf424dde080fc51 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 08f657af6a7c9526ab52c4881df11c57062a9952..ecae7f4109c518a925be691fcf61295e23f2fcbd 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 5db921a6ee9caef727da8894330c5b07157044f1..3c3199deebf85e484ac3aeffc88ee3e53a467509 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<>();