浏览代码

知识库问答

zhaops 5 年之前
父节点
当前提交
3c13b76ddd

+ 5 - 1
config-server/src/main/resources/shared/ltkg-service-dev.yml

@@ -91,4 +91,8 @@ mybatis-plus:
 
 nlprel:
   server:
-    address: http://192.168.3.150:3456
+    address: http://192.168.3.150:3456
+
+qa:
+  server:
+    address: http://192.168.3.150:9999

+ 5 - 1
config-server/src/main/resources/shared/ltkg-service-local.yml

@@ -91,4 +91,8 @@ mybatis-plus:
 
 nlprel:
   server:
-    address: http://192.168.3.150:3456
+    address: http://192.168.3.150:3456
+
+qa:
+  server:
+    address: http://192.168.3.150:9999

+ 5 - 1
config-server/src/main/resources/shared/ltkg-service-pre.yml

@@ -91,4 +91,8 @@ mybatis-plus:
 
 nlprel:
   server:
-    address: http://192.168.3.150:3456
+    address: http://192.168.3.150:3456
+
+qa:
+  server:
+    address: http://192.168.3.150:9999

+ 5 - 1
config-server/src/main/resources/shared/ltkg-service-pro.yml

@@ -91,4 +91,8 @@ mybatis-plus:
 
 nlprel:
   server:
-    address: http://192.168.3.150:3456
+    address: http://192.168.3.150:3456
+
+qa:
+  server:
+    address: http://192.168.3.150:9999

+ 5 - 1
config-server/src/main/resources/shared/ltkg-service-test.yml

@@ -91,4 +91,8 @@ mybatis-plus:
 
 nlprel:
   server:
-    address: http://192.168.3.150:3456
+    address: http://192.168.3.150:3456
+
+qa:
+  server:
+    address: http://192.168.3.150:9999

+ 20 - 0
ltkg-service/src/main/java/com/diagbot/client/QAServiceClient.java

@@ -0,0 +1,20 @@
+package com.diagbot.client;
+
+import com.diagbot.client.hystrix.QAServiceHystrix;
+import com.diagbot.dto.QADTO;
+import com.diagbot.vo.QAVO;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+
+/**
+ * @Description: 知识图谱问答服务
+ * @Author:zhaops
+ * @time: 2020/5/25 11:19
+ */
+@FeignClient(name = "QA", url = "${qa.server.address}", fallback = QAServiceHystrix.class)
+public interface QAServiceClient {
+
+    @PostMapping(value = "/api/chat_bot")
+    QADTO charBot(@RequestBody QAVO qavo);
+}

+ 24 - 0
ltkg-service/src/main/java/com/diagbot/client/hystrix/QAServiceHystrix.java

@@ -0,0 +1,24 @@
+package com.diagbot.client.hystrix;
+
+import com.diagbot.client.QAServiceClient;
+import com.diagbot.dto.QADTO;
+import com.diagbot.vo.QAVO;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+import org.springframework.web.bind.annotation.RequestBody;
+
+/**
+ * @Description: 知识图谱问答服务
+ * @Author:zhaops
+ * @time: 2020/5/25 11:19
+ */
+@Component
+@Slf4j
+public class QAServiceHystrix implements QAServiceClient {
+
+    @Override
+    public QADTO charBot(@RequestBody QAVO qavo) {
+        log.error("【hystrix】调用{}异常", "charBot");
+        return null;
+    }
+}

+ 16 - 0
ltkg-service/src/main/java/com/diagbot/dto/QADTO.java

@@ -0,0 +1,16 @@
+package com.diagbot.dto;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * @Description:
+ * @Author:zhaops
+ * @time: 2020/5/25 11:24
+ */
+@Getter
+@Setter
+public class QADTO {
+    private Boolean status;
+    private String answer;
+}

+ 28 - 0
ltkg-service/src/main/java/com/diagbot/facade/QAFacade.java

@@ -0,0 +1,28 @@
+package com.diagbot.facade;
+
+import com.diagbot.client.QAServiceClient;
+import com.diagbot.dto.QADTO;
+import com.diagbot.exception.CommonErrorCode;
+import com.diagbot.exception.CommonException;
+import com.diagbot.vo.QAVO;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * @Description:
+ * @Author:zhaops
+ * @time: 2020/5/25 11:23
+ */
+@Component
+public class QAFacade {
+    @Autowired
+    private QAServiceClient qaServiceClient;
+
+    public QADTO charBot(QAVO qavo) {
+        QADTO qadto = qaServiceClient.charBot(qavo);
+        if (qadto == null || qadto.getStatus() == false) {
+            throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "调用问答服务失败");
+        }
+        return qadto;
+    }
+}

+ 15 - 0
ltkg-service/src/main/java/com/diagbot/vo/QAVO.java

@@ -0,0 +1,15 @@
+package com.diagbot.vo;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * @Description:
+ * @Author:zhaops
+ * @time: 2020/5/25 11:24
+ */
+@Getter
+@Setter
+public class QAVO {
+    private String question;
+}

+ 34 - 0
ltkg-service/src/main/java/com/diagbot/web/QAController.java

@@ -0,0 +1,34 @@
+package com.diagbot.web;
+
+import com.diagbot.annotation.SysLogger;
+import com.diagbot.dto.QADTO;
+import com.diagbot.dto.RespDTO;
+import com.diagbot.facade.QAFacade;
+import com.diagbot.vo.QAVO;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @Description:
+ * @Author:zhaops
+ * @time: 2020/5/25 11:35
+ */
+@RestController
+@RequestMapping("/qa")
+@Api(value = "知识库问答相关API", tags = { "知识库问答相关API" })
+public class QAController {
+    @Autowired
+    private QAFacade qaFacade;
+
+    @ApiOperation(value = "知识库问答[zhaops]", notes = "")
+    @PostMapping("/charBot")
+    @SysLogger("charBot")
+    public RespDTO<QADTO> charBot(@RequestBody QAVO qavo) {
+        return RespDTO.onSuc(qaFacade.charBot(qavo));
+    }
+}