|
@@ -18,6 +18,7 @@ import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.concurrent.atomic.AtomicLong;
|
|
|
|
|
|
/**
|
|
|
* @Description: 用户日志业务层
|
|
@@ -47,6 +48,7 @@ public class KgFacade extends KgServiceImpl {
|
|
|
throw new CommonException(CommonErrorCode.NOT_EXISTS);
|
|
|
} else {
|
|
|
Map<String,Object> itemStyleMap = new HashMap<>();
|
|
|
+ itemStyleMap.put("display",true);
|
|
|
long nodeId = 0;
|
|
|
categories.add(new CategorieDTO("中心词"));
|
|
|
categories.add(new CategorieDTO("关系"));
|
|
@@ -77,6 +79,7 @@ public class KgFacade extends KgServiceImpl {
|
|
|
for (NextNodeDTO baseNodeDTO : baseNodeRSDTO.getENodeDTOS()) {
|
|
|
Map<String,Object> childrenItemStyleMap = new HashMap<>();
|
|
|
String symbol = "circle";
|
|
|
+ childrenItemStyleMap.put("display", true);
|
|
|
// if (baseNodeDTO.getPCount() == 0) {
|
|
|
// childrenItemStyleMap.put("color", "#808080");
|
|
|
// }
|
|
@@ -135,33 +138,62 @@ public class KgFacade extends KgServiceImpl {
|
|
|
List<TreeNodeDTO> nodes = new ArrayList<>();
|
|
|
Tree treeObj = JSONUtil.toBean(tree, Tree.class);
|
|
|
if (null != treeObj) {
|
|
|
- Map<String, Integer> treeMap = new HashMap<>();
|
|
|
- treeMap.put("根节点", 0);
|
|
|
- addTree(nodes, treeObj, treeMap, "根节点");
|
|
|
+ // 使用 AtomicLong 来生成唯一ID
|
|
|
+ AtomicLong idGenerator = new AtomicLong(0);
|
|
|
+
|
|
|
+ // 存储父节点的完整路径到ID的映射
|
|
|
+ Map<String, Long> pathIdMap = new HashMap<>();
|
|
|
+
|
|
|
+ // 根节点特殊处理
|
|
|
+ long rootId = idGenerator.getAndIncrement();
|
|
|
+ pathIdMap.put("根节点", rootId);
|
|
|
+
|
|
|
+ // 从根节点开始构建树
|
|
|
+ addTree(nodes, treeObj, pathIdMap, "根节点", idGenerator, "根节点");
|
|
|
}
|
|
|
|
|
|
treeDTO.setNodes(nodes);
|
|
|
return treeDTO;
|
|
|
}
|
|
|
|
|
|
- private void addTree(List<TreeNodeDTO> nodes, Tree treeObj, Map<String, Integer> treeMap, String pName) {
|
|
|
- if (null == treeMap.get(treeObj.getName())) {
|
|
|
- treeMap.put(treeObj.getName(), treeMap.size());
|
|
|
- }
|
|
|
-
|
|
|
- TreeNodeDTO node = new TreeNodeDTO("/images/icon.png",
|
|
|
- "/images/iconOpen.png",
|
|
|
- "/images/iconClose.png",
|
|
|
- treeMap.get(treeObj.getName()), treeObj.getName(), treeMap.get(pName));
|
|
|
+ private void addTree(List<TreeNodeDTO> nodes, Tree treeObj, Map<String, Long> pathIdMap,
|
|
|
+ String parentName, AtomicLong idGenerator, String parentPath) {
|
|
|
+ // 构建当前节点的完整路径
|
|
|
+ String currentPath = parentPath + "/" + treeObj.getName();
|
|
|
+
|
|
|
+ // 总是生成新的ID
|
|
|
+ Long currentId = idGenerator.getAndIncrement();
|
|
|
+ // 保存当前节点路径和ID的映射
|
|
|
+ pathIdMap.put(currentPath, currentId);
|
|
|
+
|
|
|
+ // 获取父节点ID
|
|
|
+ Long parentId = pathIdMap.get(parentPath);
|
|
|
+
|
|
|
+ // 判断是否为叶子节点
|
|
|
+ boolean isLeaf = CollUtil.isEmpty(treeObj.getSNode());
|
|
|
+
|
|
|
+ // 设置图标
|
|
|
+ String icon = isLeaf ? "/images/node.png" : "/images/icon.png";
|
|
|
+ String iconOpen = isLeaf ? "" : "/images/iconOpen.png";
|
|
|
+ String iconClose = isLeaf ? "" : "/images/iconClose.png";
|
|
|
+
|
|
|
+ // 创建树节点
|
|
|
+ TreeNodeDTO node = TreeNodeDTO.builder()
|
|
|
+ .id(currentId.intValue())
|
|
|
+ .pId(parentId.intValue())
|
|
|
+ .name(treeObj.getName())
|
|
|
+ .icon(icon)
|
|
|
+ .iconOpen(iconOpen)
|
|
|
+ .iconClose(iconClose)
|
|
|
+ .build();
|
|
|
+
|
|
|
nodes.add(node);
|
|
|
- if (CollUtil.isNotEmpty(treeObj.getSNode())) {
|
|
|
- for (Tree tree : treeObj.getSNode()) {
|
|
|
- addTree(nodes, tree, treeMap, treeObj.getName());
|
|
|
+
|
|
|
+ // 递归处理子节点
|
|
|
+ if (!isLeaf) {
|
|
|
+ for (Tree childTree : treeObj.getSNode()) {
|
|
|
+ addTree(nodes, childTree, pathIdMap, treeObj.getName(), idGenerator, currentPath);
|
|
|
}
|
|
|
- } else {
|
|
|
- node.setIcon("/images/node.png");
|
|
|
- node.setIconOpen("");
|
|
|
- node.setIconClose("");
|
|
|
}
|
|
|
}
|
|
|
|