From e3838b6ab53252e859dc964f494eae6dec521edc Mon Sep 17 00:00:00 2001 From: linbangquan <1437892690@qq.com> Date: Wed, 20 Dec 2023 14:43:38 +0800 Subject: [PATCH 1/2] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E5=90=8E=E7=AB=AF-C?= =?UTF-8?q?MDB-=E6=A8=A1=E5=9E=8B=E8=AF=A6=E6=83=85=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E3=80=81=E9=85=8D=E7=BD=AE=E9=A1=B9=E6=9F=A5=E8=AF=A2=E7=9A=84?= =?UTF-8?q?=E8=AF=A6=E6=83=85=E9=A1=B5=E9=9D=A2=EF=BC=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=A0=91=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1047056406249472]后端-CMDB-模型详情页面、配置项查询的详情页面,增加树目录 http://192.168.0.96:8090/demo/rdm.html#/task-detail/939050947543040/939050947543050/1047056406249472 --- .../ListCiCatalogAndCiForTreeApi.java | 133 ++++++++++-------- 1 file changed, 77 insertions(+), 56 deletions(-) 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 77dab803..f6dfc258 100644 --- a/src/main/java/neatlogic/module/cmdb/api/cicatalog/ListCiCatalogAndCiForTreeApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/cicatalog/ListCiCatalogAndCiForTreeApi.java @@ -47,82 +47,103 @@ public class ListCiCatalogAndCiForTreeApi extends PrivateApiComponentBase { @Description(desc = "nmcac.listcicatalogandcifortreeapi.getname") @Override public Object myDoService(JSONObject paramObj) throws Exception { + CiCatalogNodeVo rootNode = null; + List catalogList = new ArrayList<>(); + Map id2NodeMap = new HashMap<>(); + List noCatalogCiNodeList = new ArrayList<>(); + List ciNodeList = new ArrayList<>(); + List allNodeList = ciCatalogService.getAllCiCatalogList(); + List ciList = ciMapper.getAllCi(null); String keyword = paramObj.getString("keyword"); if (StringUtils.isNotBlank(keyword)) { keyword = keyword.toLowerCase(); - } - List allNodeList = ciCatalogService.getAllCiCatalogList(); - if (CollectionUtils.isEmpty(allNodeList)) { - return allNodeList; - } - CiCatalogNodeVo rootNode = allNodeList.get(0); - Map id2NodeMap = new HashMap<>(); - List matchKeywordCiCatalogNodeList = new ArrayList<>(); - for (CiCatalogNodeVo node : allNodeList) { - id2NodeMap.put(node.getId(), node); - if (StringUtils.isNotBlank(keyword)) { - if (node.getName().toLowerCase().contains(keyword)) { - matchKeywordCiCatalogNodeList.add(node); + List matchKeywordCiCatalogNodeList = new ArrayList<>(); + if (CollectionUtils.isNotEmpty(allNodeList)) { + rootNode = allNodeList.get(0); + for (CiCatalogNodeVo node : allNodeList) { + node.setType(CiCatalogNodeVo.CATALOG); + id2NodeMap.put(node.getId(), node); + if (node.getName().toLowerCase().contains(keyword)) { + matchKeywordCiCatalogNodeList.add(node); + } } } - } - List noCatalogCiNodeList = new ArrayList<>(); - List ciNodeList = new ArrayList<>(); - List ciList = ciMapper.getAllCi(null); - for (CiVo ciVo : ciList) { - if (StringUtils.isNotBlank(keyword)) { + for (CiVo ciVo : ciList) { if (!ciVo.getName().toLowerCase().contains(keyword) && !ciVo.getLabel().toLowerCase().contains(keyword)) { 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)) { + 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; + } matchKeywordCiCatalogNodeList.add(node); + ciNodeList.add(ciNode); } - ciNodeList.add(ciNode); - } - List catalogList = new ArrayList<>(); - for (CiCatalogNodeVo node : allNodeList) { - node.setType(CiCatalogNodeVo.CATALOG); - if (CollectionUtils.isNotEmpty(matchKeywordCiCatalogNodeList)) { + for (CiCatalogNodeVo node : allNodeList) { for (CiCatalogNodeVo matchKeywordCiCatalogNode : matchKeywordCiCatalogNodeList) { if (node.getLft() <= matchKeywordCiCatalogNode.getLft() && node.getRht() >= matchKeywordCiCatalogNode.getRht()) { catalogList.add(node); } } - } else { - catalogList.add(node); } - } - for (CiCatalogNodeVo node : catalogList) { - CiCatalogNodeVo parent = id2NodeMap.get(node.getParentId()); - if (parent != null) { - parent.addChild(node); + } else { + if (CollectionUtils.isNotEmpty(allNodeList)) { + rootNode = allNodeList.get(0); + for (CiCatalogNodeVo node : allNodeList) { + node.setType(CiCatalogNodeVo.CATALOG); + id2NodeMap.put(node.getId(), node); + catalogList.add(node); + } } - } - for (CiCatalogNodeVo node : ciNodeList) { - CiCatalogNodeVo parent = id2NodeMap.get(node.getParentId()); - if (parent != null) { - parent.addChild(node); + for (CiVo ciVo : ciList) { + 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; + } + ciNodeList.add(ciNode); } } - for (CiCatalogNodeVo node : noCatalogCiNodeList) { - rootNode.addChild(node); + + if (CollectionUtils.isNotEmpty(catalogList)) { + for (CiCatalogNodeVo node : catalogList) { + CiCatalogNodeVo parent = id2NodeMap.get(node.getParentId()); + if (parent != null) { + parent.addChild(node); + } + } + for (CiCatalogNodeVo node : ciNodeList) { + CiCatalogNodeVo parent = id2NodeMap.get(node.getParentId()); + if (parent != null) { + parent.addChild(node); + } + } + for (CiCatalogNodeVo node : noCatalogCiNodeList) { + rootNode.addChild(node); + } + return rootNode.getChildren(); + } else { + return noCatalogCiNodeList; } - return rootNode.getChildren(); } @Override -- Gitee From 8beb6e64df420206a2231387870525d59d838fa1 Mon Sep 17 00:00:00 2001 From: linbangquan <1437892690@qq.com> Date: Wed, 20 Dec 2023 14:58:39 +0800 Subject: [PATCH 2/2] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E5=90=8E=E7=AB=AF-C?= =?UTF-8?q?MDB-=E6=A8=A1=E5=9E=8B=E8=AF=A6=E6=83=85=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E3=80=81=E9=85=8D=E7=BD=AE=E9=A1=B9=E6=9F=A5=E8=AF=A2=E7=9A=84?= =?UTF-8?q?=E8=AF=A6=E6=83=85=E9=A1=B5=E9=9D=A2=EF=BC=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=A0=91=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1047056406249472]后端-CMDB-模型详情页面、配置项查询的详情页面,增加树目录 http://192.168.0.96:8090/demo/rdm.html#/task-detail/939050947543040/939050947543050/1047056406249472 --- .../api/cicatalog/ListCiCatalogAndCiForTreeApi.java | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) 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 f6dfc258..a80676b5 100644 --- a/src/main/java/neatlogic/module/cmdb/api/cicatalog/ListCiCatalogAndCiForTreeApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/cicatalog/ListCiCatalogAndCiForTreeApi.java @@ -72,11 +72,7 @@ public class ListCiCatalogAndCiForTreeApi extends PrivateApiComponentBase { if (!ciVo.getName().toLowerCase().contains(keyword) && !ciVo.getLabel().toLowerCase().contains(keyword)) { continue; } - CiCatalogNodeVo ciNode = new CiCatalogNodeVo(); - ciNode.setId(ciVo.getId()); - ciNode.setName(ciVo.getLabel() + "(" + ciVo.getName() + ")"); - ciNode.setParentId(ciVo.getCatalogId()); - ciNode.setType(CiCatalogNodeVo.CI); + CiCatalogNodeVo ciNode = new CiCatalogNodeVo(ciVo); if (ciVo.getCatalogId() == null) { noCatalogCiNodeList.add(ciNode); continue; @@ -106,11 +102,7 @@ public class ListCiCatalogAndCiForTreeApi extends PrivateApiComponentBase { } } for (CiVo ciVo : ciList) { - CiCatalogNodeVo ciNode = new CiCatalogNodeVo(); - ciNode.setId(ciVo.getId()); - ciNode.setName(ciVo.getLabel() + "(" + ciVo.getName() + ")"); - ciNode.setParentId(ciVo.getCatalogId()); - ciNode.setType(CiCatalogNodeVo.CI); + CiCatalogNodeVo ciNode = new CiCatalogNodeVo(ciVo); if (ciVo.getCatalogId() == null) { noCatalogCiNodeList.add(ciNode); continue; @@ -150,4 +142,5 @@ public class ListCiCatalogAndCiForTreeApi extends PrivateApiComponentBase { public String getToken() { return "cmdb/cicatalogandci/listtree"; } + } -- Gitee