|
@@ -1,8 +1,12 @@
|
|
|
package com.diagbot.facade;
|
|
|
|
|
|
+import com.diagbot.dto.BaseNodeDTO;
|
|
|
import com.diagbot.dto.BaseNodeRSDTO;
|
|
|
+import com.diagbot.dto.CategorieDTO;
|
|
|
+import com.diagbot.dto.GNodeDTO;
|
|
|
import com.diagbot.dto.GraphDTO;
|
|
|
import com.diagbot.dto.GraphLabelDTO;
|
|
|
+import com.diagbot.dto.LinkDTO;
|
|
|
import com.diagbot.dto.TreeDTO;
|
|
|
import com.diagbot.exception.CommonErrorCode;
|
|
|
import com.diagbot.exception.CommonException;
|
|
@@ -14,7 +18,9 @@ import com.diagbot.vo.KgTreeVO;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* @Description: 用户日志业务层
|
|
@@ -26,26 +32,66 @@ public class KgFacade extends KgServiceImpl {
|
|
|
|
|
|
public GraphLabelDTO getGraphFac(KgQueryVO kgQueryVO) {
|
|
|
GraphLabelDTO graphLabelDTO = new GraphLabelDTO();
|
|
|
+ List<CategorieDTO> categories = new ArrayList<>();
|
|
|
+ List<GNodeDTO> node = new ArrayList<>();
|
|
|
+ List<LinkDTO> links = new ArrayList<>();
|
|
|
List<GraphDTO> res = this.getGraph(kgQueryVO);
|
|
|
if (ListUtil.isEmpty(res)) {
|
|
|
throw new CommonException(CommonErrorCode.NOT_EXISTS);
|
|
|
} else {
|
|
|
- List<String> allRs = new ArrayList<>();
|
|
|
- for (GraphDTO graphDTO : res) {
|
|
|
- if (ListUtil.isNotEmpty(graphDTO.getENodeRSDTOS())) {
|
|
|
- for (BaseNodeRSDTO baseNodeRSDTO : graphDTO.getENodeRSDTOS()) {
|
|
|
- if (!allRs.contains(baseNodeRSDTO.getRType())) {
|
|
|
- allRs.add(baseNodeRSDTO.getRType());
|
|
|
+ Integer nodeId = 0;
|
|
|
+ categories.add(new CategorieDTO("中心词"));
|
|
|
+ categories.add(new CategorieDTO("关系"));
|
|
|
+ Map<String, Integer> cMap = new HashMap<>();
|
|
|
+ cMap.put("中心词", 0);
|
|
|
+ cMap.put("关系", 1);
|
|
|
+
|
|
|
+ GraphDTO graphDTO = res.get(0);
|
|
|
+ GNodeDTO gNodeDTO
|
|
|
+ = new GNodeDTO(0, graphDTO.getName(), nodeId, "circle", 50);
|
|
|
+ nodeId++;
|
|
|
+ node.add(gNodeDTO);
|
|
|
+ if (ListUtil.isNotEmpty(graphDTO.getENodeRSDTOS())) {
|
|
|
+ Integer rsId = 2;
|
|
|
+ for (BaseNodeRSDTO baseNodeRSDTO : graphDTO.getENodeRSDTOS()) {
|
|
|
+ if (null == cMap.get(baseNodeRSDTO.getRType())) {
|
|
|
+ cMap.put(baseNodeRSDTO.getRType(), rsId);
|
|
|
+ categories.add(new CategorieDTO(baseNodeRSDTO.getRType()));
|
|
|
+ rsId++;
|
|
|
+ }
|
|
|
+ GNodeDTO nNodeDTO
|
|
|
+ = new GNodeDTO(1, "", nodeId, "diamond", 10);
|
|
|
+ node.add(nNodeDTO);
|
|
|
+ links.add(new LinkDTO(gNodeDTO.getName(), nNodeDTO.getName(), baseNodeRSDTO.getRType()));
|
|
|
+ nodeId++;
|
|
|
+ if (ListUtil.isNotEmpty(baseNodeRSDTO.getENodeDTOS())) {
|
|
|
+ for (BaseNodeDTO baseNodeDTO : baseNodeRSDTO.getENodeDTOS()) {
|
|
|
+ GNodeDTO eNodeDTO
|
|
|
+ = new GNodeDTO(cMap.get(baseNodeRSDTO.getRType()), baseNodeDTO.getName(), nodeId, random(), 28);
|
|
|
+ nodeId++;
|
|
|
+ node.add(eNodeDTO);
|
|
|
+ links.add(new LinkDTO(nNodeDTO.getName(), eNodeDTO.getName(), ""));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- graphLabelDTO.setAllRs(allRs);
|
|
|
- graphLabelDTO.setGraphDTOS(res);
|
|
|
+ graphLabelDTO.setCategories(categories);
|
|
|
+ graphLabelDTO.setNode(node);
|
|
|
+ graphLabelDTO.setLinks(links);
|
|
|
}
|
|
|
+
|
|
|
return graphLabelDTO;
|
|
|
}
|
|
|
|
|
|
+ private String random() {
|
|
|
+ //先随机产生一个下标再获取元素
|
|
|
+ String random = "";
|
|
|
+ String[] doc = { "circle", "diamond" };
|
|
|
+ int index = (int) (Math.random() * doc.length);
|
|
|
+ random = doc[index];
|
|
|
+ return random;
|
|
|
+ }
|
|
|
+
|
|
|
public TreeDTO getTreeFac(KgTreeVO kgTreeVO) {
|
|
|
TreeDTO treeDTO = new TreeDTO();
|
|
|
if (kgTreeVO.getType() == 1 && kgTreeVO.getSubType() == 1) {
|