|
@@ -1,19 +1,33 @@
|
|
|
package com.diagbot.facade;
|
|
|
|
|
|
+import com.diagbot.dto.BaseNodeDTO;
|
|
|
import com.diagbot.dto.BaseNodeRSDTO;
|
|
|
+import com.diagbot.dto.CategorieDTO;
|
|
|
+import com.diagbot.dto.Categories;
|
|
|
+import com.diagbot.dto.GNodeDTO;
|
|
|
+import com.diagbot.dto.GraDTO;
|
|
|
import com.diagbot.dto.GraphDTO;
|
|
|
import com.diagbot.dto.GraphLabelDTO;
|
|
|
+import com.diagbot.dto.Link;
|
|
|
+import com.diagbot.dto.LinkDTO;
|
|
|
+import com.diagbot.dto.Node;
|
|
|
import com.diagbot.dto.TreeDTO;
|
|
|
+import com.diagbot.dto.Tu;
|
|
|
import com.diagbot.exception.CommonErrorCode;
|
|
|
import com.diagbot.exception.CommonException;
|
|
|
import com.diagbot.service.impl.KgServiceImpl;
|
|
|
+import com.diagbot.util.EntityUtil;
|
|
|
+import com.diagbot.util.FastJsonUtils;
|
|
|
import com.diagbot.util.ListUtil;
|
|
|
import com.diagbot.vo.KgQueryVO;
|
|
|
import com.diagbot.vo.KgTreeVO;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* @Description: 用户日志业务层
|
|
@@ -25,37 +39,172 @@ 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) {
|
|
|
- addNode(treeDTO);
|
|
|
+ treeDTO = FastJsonUtils.getJsonToBean(jsonStr, TreeDTO.class);
|
|
|
} else {
|
|
|
throw new CommonException(CommonErrorCode.PARAM_IS_ERROR);
|
|
|
}
|
|
|
return treeDTO;
|
|
|
}
|
|
|
|
|
|
+ private static final String jsonStr = "{\n" +
|
|
|
+ " \"icdCode\": \"1\",\n" +
|
|
|
+ " \"label\": null,\n" +
|
|
|
+ " \"name\": \"疾病\",\n" +
|
|
|
+ " \"snode\": [\n" +
|
|
|
+ " {\n" +
|
|
|
+ "\t\t\"icdCode\": \"A\",\n" +
|
|
|
+ "\t\t\"label\": \"\",\n" +
|
|
|
+ "\t\t\"name\": \"A\",\n" +
|
|
|
+ "\t\t\"snode\": [\n" +
|
|
|
+ "\t\t {\n" +
|
|
|
+ "\t\t\t\"icdCode\": \"A1\",\n" +
|
|
|
+ "\t\t\t\"label\": \"\",\n" +
|
|
|
+ "\t\t\t\"name\": \"A1\",\n" +
|
|
|
+ "\t\t\t\"snode\": [\n" +
|
|
|
+ "\t\t\t null\n" +
|
|
|
+ "\t\t\t]\n" +
|
|
|
+ "\t\t },\n" +
|
|
|
+ "\t\t {\n" +
|
|
|
+ "\t\t\t\"icdCode\": \"A2\",\n" +
|
|
|
+ "\t\t\t\"label\": \"\",\n" +
|
|
|
+ "\t\t\t\"name\": \"A2\",\n" +
|
|
|
+ "\t\t\t\"snode\": [\n" +
|
|
|
+ "\t\t\t null\n" +
|
|
|
+ "\t\t\t]\n" +
|
|
|
+ "\t\t }\n" +
|
|
|
+ "\t\t]\n" +
|
|
|
+ "\t },\n" +
|
|
|
+ "\t {\n" +
|
|
|
+ "\t\t\"icdCode\": \"B\",\n" +
|
|
|
+ "\t\t\"label\": \"\",\n" +
|
|
|
+ "\t\t\"name\": \"B\",\n" +
|
|
|
+ "\t\t\"snode\": [\n" +
|
|
|
+ "\t\t null\n" +
|
|
|
+ "\t\t]\n" +
|
|
|
+ "\t }\n" +
|
|
|
+ " ]\n" +
|
|
|
+ "}";
|
|
|
+
|
|
|
private void addNode(TreeDTO treeDTO) {
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ public GraDTO getTuFac(KgQueryVO kgQueryVO) {
|
|
|
+ GraDTO graDTO = new GraDTO();
|
|
|
+ List<Tu> tu = this.getTu(kgQueryVO);
|
|
|
+ Map<String, List<Tu>> map = EntityUtil.makeEntityListMap(tu, "rel");
|
|
|
+
|
|
|
+ List<Categories> categoriesList = new ArrayList<>();
|
|
|
+ List<Node> nodeList = new ArrayList<>();
|
|
|
+ List<Link> linksList = new ArrayList<>();
|
|
|
+
|
|
|
+ // 添加第一个节点:中心节点
|
|
|
+ Node node = new Node(0, kgQueryVO.getInputStr(), 0L, 50);
|
|
|
+ nodeList.add(node);
|
|
|
+
|
|
|
+ // 设置categories
|
|
|
+ Map<String, Integer> relMap = new LinkedHashMap<>();
|
|
|
+ int i = 0; // 设置category
|
|
|
+ Categories c1 = new Categories("中心词");
|
|
|
+ categoriesList.add(c1);
|
|
|
+ relMap.put("中心词", i++);
|
|
|
+ Categories c2 = new Categories("关系");
|
|
|
+ categoriesList.add(c2);
|
|
|
+ relMap.put("关系", i++);
|
|
|
+ Long j = 1L; // 设置节点编号
|
|
|
+ for (String key : map.keySet()) {
|
|
|
+ Categories bean = new Categories(key);
|
|
|
+ categoriesList.add(bean);
|
|
|
+ relMap.put(key, i);
|
|
|
+
|
|
|
+ // 添加关系节点
|
|
|
+ Node nodeRel = new Node(1, "", j, 10);
|
|
|
+ nodeList.add(nodeRel);
|
|
|
+
|
|
|
+ // 添加中心节点与关系的关联
|
|
|
+ Link linkRel = new Link(0L, j, key);
|
|
|
+ linksList.add(linkRel);
|
|
|
+
|
|
|
+ List<Tu> inner = map.get(key);
|
|
|
+ for (Tu t : inner) {
|
|
|
+ // 添加关系下的节点
|
|
|
+ Node nodeLabel = new Node(i, t.getSubName(), ++j, 28);
|
|
|
+ nodeList.add(nodeLabel);
|
|
|
+
|
|
|
+ // 添加关系和节点的关联
|
|
|
+ Link linkLabel = new Link(linkRel.getTarget(), j, "");
|
|
|
+ linksList.add(linkLabel);
|
|
|
+ }
|
|
|
+ i++;
|
|
|
+ j++;
|
|
|
+ }
|
|
|
+ graDTO.setCategoriesList(categoriesList);
|
|
|
+ graDTO.setNodeList(nodeList);
|
|
|
+ graDTO.setLinksList(linksList);
|
|
|
+
|
|
|
+ return graDTO;
|
|
|
+ }
|
|
|
}
|