diff --git a/src/main/java/neatlogic/module/cmdb/api/cicatalog/ListCiCatalogAndCiForTreeApi.java b/src/main/java/neatlogic/module/cmdb/api/cicatalog/ListCiCatalogAndCiForTreeApi.java index 3a02dbecedb4fa995053c27865e9196193e944bc..77dab803b13c5864bfbc4e90b24766a6c79eb82c 100644 --- a/src/main/java/neatlogic/module/cmdb/api/cicatalog/ListCiCatalogAndCiForTreeApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/cicatalog/ListCiCatalogAndCiForTreeApi.java @@ -66,6 +66,7 @@ public class ListCiCatalogAndCiForTreeApi extends PrivateApiComponentBase { } } } + List noCatalogCiNodeList = new ArrayList<>(); List ciNodeList = new ArrayList<>(); List ciList = ciMapper.getAllCi(null); for (CiVo ciVo : ciList) { @@ -74,21 +75,23 @@ public class ListCiCatalogAndCiForTreeApi extends PrivateApiComponentBase { continue; } } + CiCatalogNodeVo ciNode = new CiCatalogNodeVo(); + ciNode.setId(ciVo.getId()); + ciNode.setName(ciVo.getLabel() + "(" + ciVo.getName() + ")"); + ciNode.setParentId(ciVo.getCatalogId()); + ciNode.setType(CiCatalogNodeVo.CI); if (ciVo.getCatalogId() == null) { + noCatalogCiNodeList.add(ciNode); continue; } CiCatalogNodeVo node = id2NodeMap.get(ciVo.getCatalogId()); if (node == null) { + noCatalogCiNodeList.add(ciNode); continue; } if (StringUtils.isNotBlank(keyword)) { matchKeywordCiCatalogNodeList.add(node); } - CiCatalogNodeVo ciNode = new CiCatalogNodeVo(); - ciNode.setId(ciVo.getId()); - ciNode.setName(ciVo.getLabel() + "(" + ciVo.getName() + ")"); - ciNode.setParentId(ciVo.getCatalogId()); - ciNode.setType(CiCatalogNodeVo.CI); ciNodeList.add(ciNode); } List catalogList = new ArrayList<>(); @@ -116,6 +119,9 @@ public class ListCiCatalogAndCiForTreeApi extends PrivateApiComponentBase { parent.addChild(node); } } + for (CiCatalogNodeVo node : noCatalogCiNodeList) { + rootNode.addChild(node); + } return rootNode.getChildren(); } diff --git a/src/main/java/neatlogic/module/cmdb/api/cicatalog/ListCiCatalogForTreeApi.java b/src/main/java/neatlogic/module/cmdb/api/cicatalog/ListCiCatalogForTreeApi.java index 5c5b424f0457a90896c65dba2358aba2e7622a0a..f27234518a75eddcd9b2f4bd39c895d80d98e653 100644 --- a/src/main/java/neatlogic/module/cmdb/api/cicatalog/ListCiCatalogForTreeApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/cicatalog/ListCiCatalogForTreeApi.java @@ -3,16 +3,20 @@ package neatlogic.module.cmdb.api.cicatalog; 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.cicatalog.CiCatalogNodeVo; import neatlogic.framework.cmdb.dto.cicatalog.CiCatalogVo; 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.service.cicatalog.CiCatalogService; import org.apache.commons.collections4.CollectionUtils; 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; import java.util.stream.Collectors; @@ -22,6 +26,9 @@ import java.util.stream.Collectors; @OperationType(type = OperationTypeEnum.SEARCH) public class ListCiCatalogForTreeApi extends PrivateApiComponentBase { + @Resource + private CiMapper ciMapper; + @Resource private CiCatalogService ciCatalogService; @@ -50,6 +57,21 @@ public class ListCiCatalogForTreeApi extends PrivateApiComponentBase { parent.addChild(node); } } + Map> catalogId2CiListMap = new HashMap<>(); + List ciList = ciMapper.getAllCi(null); + for (CiVo ciVo : ciList) { + if (ciVo.getCatalogId() != null) { + catalogId2CiListMap.computeIfAbsent(ciVo.getCatalogId(), key -> new ArrayList<>()).add(ciVo); + } + } + for (CiCatalogNodeVo node : allNodeList) { + List ciVoList = catalogId2CiListMap.get(node.getId()); + if (CollectionUtils.isNotEmpty(ciVoList)) { + Integer childrenCount = node.getChildrenCount(); + childrenCount = childrenCount + ciVoList.size(); + node.setChildrenCount(childrenCount); + } + } return rootNode.getChildren(); }