Commit 70ada79c7a3f7c0c2e47cde5619ba94d5d57708b

Authored by 朱俊杰
1 parent 0dfce85d

修复device_channel的Id改变带来的tree查询bug

src/main/java/com/genersoft/iot/vmp/utils/node/BaseNode.java
... ... @@ -16,7 +16,7 @@ public class BaseNode<T> implements INode<T> {
16 16 /**
17 17 * 主键ID
18 18 */
19   - protected int id;
  19 + protected String channelId;
20 20  
21 21 /**
22 22 * 父节点ID
... ... @@ -50,12 +50,8 @@ public class BaseNode<T> implements INode<T> {
50 50 }
51 51  
52 52 @Override
53   - public int getId() {
54   - return id;
55   - }
56   -
57   - public void setId(int id) {
58   - this.id = id;
  53 + public String getChannelId() {
  54 + return channelId;
59 55 }
60 56  
61 57 @Override
... ... @@ -63,10 +59,6 @@ public class BaseNode<T> implements INode<T> {
63 59 return parentId;
64 60 }
65 61  
66   - public void setParentId(String parentId) {
67   - this.parentId = parentId;
68   - }
69   -
70 62 @Override
71 63 public List<T> getChildren() {
72 64 return children;
... ...
src/main/java/com/genersoft/iot/vmp/utils/node/ForestNode.java
... ... @@ -15,8 +15,8 @@ public class ForestNode extends BaseNode&lt;ForestNode&gt; {
15 15 */
16 16 private Object content;
17 17  
18   - public ForestNode(int id, String parentId, Object content) {
19   - this.id = id;
  18 + public ForestNode(String id, String parentId, Object content) {
  19 + this.channelId = id;
20 20 this.parentId = parentId;
21 21 this.content = content;
22 22 }
... ...
src/main/java/com/genersoft/iot/vmp/utils/node/ForestNodeManager.java
... ... @@ -17,15 +17,15 @@ public class ForestNodeManager&lt;T extends INode&lt;T&gt;&gt; {
17 17 /**
18 18 * 森林的所有节点
19 19 */
20   - private final ImmutableMap<Integer, T> nodeMap;
  20 + private final ImmutableMap<String, T> nodeMap;
21 21  
22 22 /**
23 23 * 森林的父节点ID
24 24 */
25   - private final Map<Integer, Object> parentIdMap = Maps.newHashMap();
  25 + private final Map<String, Object> parentIdMap = Maps.newHashMap();
26 26  
27 27 public ForestNodeManager(List<T> nodes) {
28   - nodeMap = Maps.uniqueIndex(nodes, INode::getId);
  28 + nodeMap = Maps.uniqueIndex(nodes, INode::getChannelId);
29 29 }
30 30  
31 31 /**
... ... @@ -46,7 +46,7 @@ public class ForestNodeManager&lt;T extends INode&lt;T&gt;&gt; {
46 46 *
47 47 * @param parentId 父节点ID
48 48 */
49   - public void addParentId(int parentId) {
  49 + public void addParentId(String parentId) {
50 50 parentIdMap.put(parentId, "");
51 51 }
52 52  
... ... @@ -58,7 +58,7 @@ public class ForestNodeManager&lt;T extends INode&lt;T&gt;&gt; {
58 58 public List<T> getRoot() {
59 59 List<T> roots = new ArrayList<>();
60 60 nodeMap.forEach((key, node) -> {
61   - if (node.getParentId() == null || parentIdMap.containsKey(node.getId())) {
  61 + if (node.getParentId() == null || parentIdMap.containsKey(node.getChannelId())) {
62 62 roots.add(node);
63 63 }
64 64 });
... ...
src/main/java/com/genersoft/iot/vmp/utils/node/ForestNodeMerger.java
... ... @@ -25,7 +25,7 @@ public class ForestNodeMerger {
25 25 if (node != null) {
26 26 node.getChildren().add(forestNode);
27 27 } else {
28   - forestNodeManager.addParentId(forestNode.getId());
  28 + forestNodeManager.addParentId(forestNode.getChannelId());
29 29 }
30 30 }
31 31 });
... ... @@ -37,8 +37,8 @@ public class ForestNodeMerger {
37 37 items.forEach(forestNode -> {
38 38 if (forestNode.getParentId() != null) {
39 39 INode<T> node = forestNodeManager.getTreeNodeAt(forestNode.getParentId());
40   - if (CollectionUtil.contains(parentIds, forestNode.getId())){
41   - forestNodeManager.addParentId(forestNode.getId());
  40 + if (CollectionUtil.contains(parentIds, forestNode.getChannelId())){
  41 + forestNodeManager.addParentId(forestNode.getChannelId());
42 42 } else {
43 43 if (node != null){
44 44 node.getChildren().add(forestNode);
... ...
src/main/java/com/genersoft/iot/vmp/utils/node/INode.java
... ... @@ -14,7 +14,7 @@ public interface INode&lt;T&gt; extends Serializable {
14 14 *
15 15 * @return String
16 16 */
17   - int getId();
  17 + String getChannelId();
18 18  
19 19 /**
20 20 * 父主键
... ...