Browse Source

获取图谱接口

gaodm 5 năm trước cách đây
mục cha
commit
1b54457e36

+ 18 - 0
ltkg-service/src/main/java/com/diagbot/dto/GraphLabelDTO.java

@@ -0,0 +1,18 @@
+package com.diagbot.dto;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.List;
+
+/**
+ * @Description:
+ * @author: gaodm
+ * @time: 2020/3/16 15:06
+ */
+@Getter
+@Setter
+public class GraphLabelDTO {
+    private List<String> allLabel;
+    private List<GraphDTO> graphDTOS;
+}

+ 40 - 0
ltkg-service/src/main/java/com/diagbot/facade/KgFacade.java

@@ -1,8 +1,19 @@
 package com.diagbot.facade;
 
+import com.diagbot.dto.BaseNodeDTO;
+import com.diagbot.dto.BaseNodeRSDTO;
+import com.diagbot.dto.GraphDTO;
+import com.diagbot.dto.GraphLabelDTO;
+import com.diagbot.exception.CommonErrorCode;
+import com.diagbot.exception.CommonException;
 import com.diagbot.service.impl.KgServiceImpl;
+import com.diagbot.util.ListUtil;
+import com.diagbot.vo.KgQueryVO;
 import org.springframework.stereotype.Component;
 
+import java.util.ArrayList;
+import java.util.List;
+
 /**
  * @Description: 用户日志业务层
  * @author: gaodm
@@ -10,4 +21,33 @@ import org.springframework.stereotype.Component;
  */
 @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> allLabel = new ArrayList<>();
+            for (GraphDTO graphDTO : res) {
+                if (!allLabel.contains(graphDTO.getLabel())) {
+                    allLabel.add(graphDTO.getLabel());
+                }
+                if (ListUtil.isNotEmpty(graphDTO.getENodeRSDTOS())) {
+                    for (BaseNodeRSDTO baseNodeRSDTO : graphDTO.getENodeRSDTOS()) {
+                        if (ListUtil.isNotEmpty(baseNodeRSDTO.getENodeDTOS())) {
+                            for (BaseNodeDTO baseNodeDTO : baseNodeRSDTO.getENodeDTOS()) {
+                                if (!allLabel.contains(baseNodeDTO.getLabel())) {
+                                    allLabel.add(baseNodeDTO.getLabel());
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+            graphLabelDTO.setAllLabel(allLabel);
+            graphLabelDTO.setGraphDTOS(res);
+        }
+        return graphLabelDTO;
+    }
 }

+ 3 - 2
ltkg-service/src/main/java/com/diagbot/web/KgController.java

@@ -2,6 +2,7 @@ package com.diagbot.web;
 
 import com.diagbot.annotation.SysLogger;
 import com.diagbot.dto.GraphDTO;
+import com.diagbot.dto.GraphLabelDTO;
 import com.diagbot.dto.NodeDTO;
 import com.diagbot.dto.RespDTO;
 import com.diagbot.facade.KgFacade;
@@ -42,8 +43,8 @@ public class KgController {
     @ApiOperation(value = "获取图谱", notes = "获取图谱")
     @PostMapping("/getGraph")
     @SysLogger("getGraph")
-    public RespDTO<List<GraphDTO>> getGraph(@RequestBody @Valid KgQueryVO kgQueryVO) {
-        return RespDTO.onSuc(kgFacade.getGraph(kgQueryVO));
+    public RespDTO<GraphLabelDTO> getGraph(@RequestBody @Valid KgQueryVO kgQueryVO) {
+        return RespDTO.onSuc(kgFacade.getGraphFac(kgQueryVO));
     }
 
     @ApiOperation(value = "获取分类", notes = "获取分类")