Commit cfb8c8c0 by zhangkb

维度树节点添加tagType和dimensionType值返回

parent c54e3f6e
...@@ -133,7 +133,8 @@ public class TagService { ...@@ -133,7 +133,8 @@ public class TagService {
} }
List<JsonNode> nodes = new ArrayList<>(); List<JsonNode> nodes = new ArrayList<>();
tags.forEach(p -> { tags.forEach(p -> {
JsonNode node = new JsonNode(p.getPath(), p.getId(), p.getPath(), p.getIdPath()); JsonNode node = new JsonNode(p.getPath(), p.getId(),
p.getPath(), p.getIdPath(),p.getTagType(),p.getDimensionType());
nodes.add(node); nodes.add(node);
}); });
//自定拼接成树结构 //自定拼接成树结构
......
package com.keymobile.tagmanager.util; package com.keymobile.tagmanager.util;
import java.util.List; import java.util.List;
public class JsonTreeHelper { public class JsonTreeHelper {
public static class JsonNode { public static class JsonNode {
public String text; public String text;
public JsonNode[] children; public JsonNode[] children;
public String nodeId; public String nodeId;
public String tagType; public String tagType;
public String path; public String path;
public String idPath; public String idPath;
public String dimensionType;
public JsonNode(String text) {
this.text = text; public JsonNode(String text) {
} this.text = text;
}
public JsonNode(String text, String nodeId, String path) {
this.text = text; public JsonNode(String text, String nodeId, String path) {
this.path = path; this.text = text;
this.nodeId = nodeId; this.path = path;
} this.nodeId = nodeId;
}
public JsonNode(String text, String nodeId, String path, String idPath) {
this.text = text; public JsonNode(String text, String nodeId, String path, String idPath) {
this.path = path; this.text = text;
this.nodeId = nodeId; this.path = path;
this.idPath = idPath; this.nodeId = nodeId;
} this.idPath = idPath;
}
public void addChild(JsonNode child) {
if (children == null) { public JsonNode(String text, String nodeId, String path,
children = new JsonNode[] { child }; String idPath,String tagType,String dimensionType) {
} else { this.text = text;
JsonNode[] origin = children; this.path = path;
children = new JsonNode[origin.length + 1]; this.nodeId = nodeId;
for (int i = 0; i < origin.length; i++) { this.idPath = idPath;
children[i] = origin[i]; this.tagType = tagType;
} this.dimensionType = dimensionType;
children[origin.length] = child; }
}
} public void addChild(JsonNode child) {
if (children == null) {
public int getChildSize() { children = new JsonNode[] { child };
if (children == null) } else {
return 0; JsonNode[] origin = children;
else children = new JsonNode[origin.length + 1];
return children.length; for (int i = 0; i < origin.length; i++) {
} children[i] = origin[i];
} }
children[origin.length] = child;
public static JsonNode toJsonTree(List<JsonNode> jsonNodes, String separator) { }
JsonNode root = new JsonNode("root"); }
for (JsonNode jsonNode : jsonNodes) {
JsonNode current = root; public int getChildSize() {
String[] parts = jsonNode.text.split(separator); if (children == null)
for (String part : parts) { return 0;
JsonNode subNode = null; else
if (current.getChildSize() == 0) { return children.length;
subNode = new JsonNode(part, jsonNode.nodeId, jsonNode.path, jsonNode.idPath); }
current.addChild(subNode); }
} else {
for (JsonNode node : current.children) { public static JsonNode toJsonTree(List<JsonNode> jsonNodes, String separator) {
if (node.text.equals(part)) JsonNode root = new JsonNode("root");
subNode = node; for (JsonNode jsonNode : jsonNodes) {
} JsonNode current = root;
if (subNode == null) { String[] parts = jsonNode.text.split(separator);
subNode = new JsonNode(part, jsonNode.nodeId, jsonNode.path, jsonNode.idPath); for (String part : parts) {
current.addChild(subNode); JsonNode subNode = null;
} if (current.getChildSize() == 0) {
} subNode = new JsonNode(part, jsonNode.nodeId, jsonNode.path, jsonNode.idPath);
current = subNode; current.addChild(subNode);
} } else {
} for (JsonNode node : current.children) {
return root; if (node.text.equals(part))
} subNode = node;
}
if (subNode == null) {
} subNode = new JsonNode(part, jsonNode.nodeId, jsonNode.path, jsonNode.idPath);
current.addChild(subNode);
}
}
current = subNode;
}
}
return root;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment