Commit e444ff4a by zhangkb

标签数每个节点添加子节点数量标识

parent 4bcb8658
...@@ -144,7 +144,8 @@ public class TagService { ...@@ -144,7 +144,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(), JsonNode node = new JsonNode(p.getPath(), p.getId(),
p.getPath(), p.getIdPath(),p.getTagType(),p.getDimensionType()); p.getPath(), p.getIdPath(),p.getTagType(),p.getDimensionType(),
this.getChildCountByTagId(p.getId()));
nodes.add(node); nodes.add(node);
}); });
//自定拼接成树结构 //自定拼接成树结构
...@@ -182,7 +183,7 @@ public class TagService { ...@@ -182,7 +183,7 @@ 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()); ,p.getTagType(),p.getDimensionType(),this.getChildCountByTagId(p.getId()));
nodes.add(node); nodes.add(node);
}); });
JsonNode root = JsonTreeHelper.toJsonTree(nodes, Constants.TAG_PATH_SEPARATOR); JsonNode root = JsonTreeHelper.toJsonTree(nodes, Constants.TAG_PATH_SEPARATOR);
...@@ -300,7 +301,7 @@ public class TagService { ...@@ -300,7 +301,7 @@ 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()); ,p.getTagType(),p.getDimensionType(),this.getChildCountByTagId(p.getId()));
nodes.add(node); nodes.add(node);
}); });
JsonNode root = JsonTreeHelper.toJsonTree(nodes, Constants.TAG_PATH_SEPARATOR); JsonNode root = JsonTreeHelper.toJsonTree(nodes, Constants.TAG_PATH_SEPARATOR);
...@@ -881,7 +882,12 @@ public class TagService { ...@@ -881,7 +882,12 @@ public class TagService {
return false; return false;
} }
//author:zhangkb time:2020-3-5 desc:根据标签id获取标签子节点数量
public int getChildCountByTagId(String tagId) {
List<Tag> dirs = mongoOperations.find(new Query().addCriteria(Criteria.where("idPath")
.regex("^"+tagId+Constants.TAG_PATH_SEPARATOR)), Tag.class);
return dirs.size();
}
......
...@@ -13,6 +13,7 @@ public class JsonTreeHelper { ...@@ -13,6 +13,7 @@ public class JsonTreeHelper {
public String path; public String path;
public String idPath; public String idPath;
public String dimensionType; public String dimensionType;
public int childCount;//author:zhangkb time:2020-3-5 desc:添加标签子标签数量字段
public JsonNode(String text) { public JsonNode(String text) {
this.text = text; this.text = text;
...@@ -41,6 +42,17 @@ public class JsonTreeHelper { ...@@ -41,6 +42,17 @@ public class JsonTreeHelper {
this.dimensionType = dimensionType; this.dimensionType = dimensionType;
} }
public JsonNode(String text, String nodeId, String path,
String idPath,String tagType,String dimensionType,int childCount) {
this.text = text;
this.path = path;
this.nodeId = nodeId;
this.idPath = idPath;
this.tagType = tagType;
this.dimensionType = dimensionType;
this.childCount = childCount;
}
public void addChild(JsonNode child) { public void addChild(JsonNode child) {
if (children == null) { if (children == null) {
children = new JsonNode[] { child }; children = new JsonNode[] { child };
......
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