123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- package com.diagbot.facade;
- import com.diagbot.dto.BaseNodeRSDTO;
- import com.diagbot.dto.Categories;
- import com.diagbot.dto.GraDTO;
- import com.diagbot.dto.GraphDTO;
- import com.diagbot.dto.GraphLabelDTO;
- import com.diagbot.dto.Link;
- 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.LinkedHashMap;
- import java.util.List;
- import java.util.Map;
- /**
- * @Description: 用户日志业务层
- * @author: gaodm
- * @time: 2018/8/6 9:11
- */
- @Component
- public class KgFacade extends KgServiceImpl {
- public GraphLabelDTO getGraphFac(KgQueryVO kgQueryVO) {
- GraphLabelDTO graphLabelDTO = new GraphLabelDTO();
- 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());
- }
- }
- }
- }
- graphLabelDTO.setAllRs(allRs);
- graphLabelDTO.setGraphDTOS(res);
- }
- return graphLabelDTO;
- }
- public TreeDTO getTreeFac(KgTreeVO kgTreeVO) {
- TreeDTO treeDTO = new TreeDTO();
- if (kgTreeVO.getType() == 1 && kgTreeVO.getSubType() == 1) {
- 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;
- }
- }
|