From aaa1c8d6cbf882b50b2767d20d87609086d4e860 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E4=BF=8A=E6=9D=B0?= <502612493@qq.com> Date: Tue, 15 Mar 2022 16:31:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Ddevice=5Fchannel=E7=9A=84Id?= =?UTF-8?q?=E6=94=B9=E5=8F=98=E5=B8=A6=E6=9D=A5=E7=9A=84tree=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/genersoft/iot/vmp/utils/node/BaseNode.java | 14 +++----------- .../genersoft/iot/vmp/utils/node/ForestNode.java | 4 ++-- .../iot/vmp/utils/node/ForestNodeManager.java | 10 +++++----- .../iot/vmp/utils/node/ForestNodeMerger.java | 6 +++--- .../com/genersoft/iot/vmp/utils/node/INode.java | 2 +- 5 files changed, 14 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/utils/node/BaseNode.java b/src/main/java/com/genersoft/iot/vmp/utils/node/BaseNode.java index 7835feba..89e35a54 100644 --- a/src/main/java/com/genersoft/iot/vmp/utils/node/BaseNode.java +++ b/src/main/java/com/genersoft/iot/vmp/utils/node/BaseNode.java @@ -16,7 +16,7 @@ public class BaseNode implements INode { /** * 主键ID */ - protected int id; + protected String channelId; /** * 父节点ID @@ -50,12 +50,8 @@ public class BaseNode implements INode { } @Override - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; + public String getChannelId() { + return channelId; } @Override @@ -63,10 +59,6 @@ public class BaseNode implements INode { return parentId; } - public void setParentId(String parentId) { - this.parentId = parentId; - } - @Override public List getChildren() { return children; diff --git a/src/main/java/com/genersoft/iot/vmp/utils/node/ForestNode.java b/src/main/java/com/genersoft/iot/vmp/utils/node/ForestNode.java index 21a48df3..d983c56b 100644 --- a/src/main/java/com/genersoft/iot/vmp/utils/node/ForestNode.java +++ b/src/main/java/com/genersoft/iot/vmp/utils/node/ForestNode.java @@ -15,8 +15,8 @@ public class ForestNode extends BaseNode { */ private Object content; - public ForestNode(int id, String parentId, Object content) { - this.id = id; + public ForestNode(String id, String parentId, Object content) { + this.channelId = id; this.parentId = parentId; this.content = content; } diff --git a/src/main/java/com/genersoft/iot/vmp/utils/node/ForestNodeManager.java b/src/main/java/com/genersoft/iot/vmp/utils/node/ForestNodeManager.java index 895e6de0..affce9d1 100644 --- a/src/main/java/com/genersoft/iot/vmp/utils/node/ForestNodeManager.java +++ b/src/main/java/com/genersoft/iot/vmp/utils/node/ForestNodeManager.java @@ -17,15 +17,15 @@ public class ForestNodeManager> { /** * 森林的所有节点 */ - private final ImmutableMap nodeMap; + private final ImmutableMap nodeMap; /** * 森林的父节点ID */ - private final Map parentIdMap = Maps.newHashMap(); + private final Map parentIdMap = Maps.newHashMap(); public ForestNodeManager(List nodes) { - nodeMap = Maps.uniqueIndex(nodes, INode::getId); + nodeMap = Maps.uniqueIndex(nodes, INode::getChannelId); } /** @@ -46,7 +46,7 @@ public class ForestNodeManager> { * * @param parentId 父节点ID */ - public void addParentId(int parentId) { + public void addParentId(String parentId) { parentIdMap.put(parentId, ""); } @@ -58,7 +58,7 @@ public class ForestNodeManager> { public List getRoot() { List roots = new ArrayList<>(); nodeMap.forEach((key, node) -> { - if (node.getParentId() == null || parentIdMap.containsKey(node.getId())) { + if (node.getParentId() == null || parentIdMap.containsKey(node.getChannelId())) { roots.add(node); } }); diff --git a/src/main/java/com/genersoft/iot/vmp/utils/node/ForestNodeMerger.java b/src/main/java/com/genersoft/iot/vmp/utils/node/ForestNodeMerger.java index 062d4cd9..8df6f503 100644 --- a/src/main/java/com/genersoft/iot/vmp/utils/node/ForestNodeMerger.java +++ b/src/main/java/com/genersoft/iot/vmp/utils/node/ForestNodeMerger.java @@ -25,7 +25,7 @@ public class ForestNodeMerger { if (node != null) { node.getChildren().add(forestNode); } else { - forestNodeManager.addParentId(forestNode.getId()); + forestNodeManager.addParentId(forestNode.getChannelId()); } } }); @@ -37,8 +37,8 @@ public class ForestNodeMerger { items.forEach(forestNode -> { if (forestNode.getParentId() != null) { INode node = forestNodeManager.getTreeNodeAt(forestNode.getParentId()); - if (CollectionUtil.contains(parentIds, forestNode.getId())){ - forestNodeManager.addParentId(forestNode.getId()); + if (CollectionUtil.contains(parentIds, forestNode.getChannelId())){ + forestNodeManager.addParentId(forestNode.getChannelId()); } else { if (node != null){ node.getChildren().add(forestNode); diff --git a/src/main/java/com/genersoft/iot/vmp/utils/node/INode.java b/src/main/java/com/genersoft/iot/vmp/utils/node/INode.java index c82d6f76..27727470 100644 --- a/src/main/java/com/genersoft/iot/vmp/utils/node/INode.java +++ b/src/main/java/com/genersoft/iot/vmp/utils/node/INode.java @@ -14,7 +14,7 @@ public interface INode extends Serializable { * * @return String */ - int getId(); + String getChannelId(); /** * 父主键