|
@@ -1,13 +1,22 @@
|
|
|
package com.kgraph.graph.neo4j.seavice.impl;
|
|
|
|
|
|
+import com.kgraph.common.core.domain.BaseResponse;
|
|
|
+import com.kgraph.common.core.domain.entity.SysDictData;
|
|
|
+import com.kgraph.graph.neo4j.DTO.DocInfo;
|
|
|
import com.kgraph.graph.neo4j.DTO.KgDTO;
|
|
|
import com.kgraph.graph.neo4j.domain.Neo4jEntity;
|
|
|
import com.kgraph.graph.neo4j.domain.Neo4jRelation;
|
|
|
import com.kgraph.graph.neo4j.mapper.EntityRepository;
|
|
|
import com.kgraph.graph.neo4j.mapper.RelationRepository;
|
|
|
import com.kgraph.graph.neo4j.seavice.IKgService;
|
|
|
+import com.kgraph.system.service.ISysDictDataService;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -15,6 +24,11 @@ import java.util.stream.Collectors;
|
|
|
@Service
|
|
|
public class KgServiceImpl implements IKgService {
|
|
|
|
|
|
+ protected final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISysDictDataService sysDictDataService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private EntityRepository entityRepository;
|
|
|
|
|
@@ -58,7 +72,7 @@ public class KgServiceImpl implements IKgService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Iterable getAllRelationList() {
|
|
|
+ public Iterable<Neo4jRelation> getAllRelationList() {
|
|
|
return relationRepository.findAll();
|
|
|
}
|
|
|
|
|
@@ -118,4 +132,66 @@ public class KgServiceImpl implements IKgService {
|
|
|
public List<Neo4jRelation> getShortestRelationByName(String firstName, String secondName) {
|
|
|
return relationRepository.getShortestRelationByName(firstName, secondName);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String question(String question) {
|
|
|
+ HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory();
|
|
|
+ httpRequestFactory.setConnectionRequestTimeout(3000);
|
|
|
+ httpRequestFactory.setConnectTimeout(3000);
|
|
|
+ httpRequestFactory.setReadTimeout(3000);
|
|
|
+ RestTemplate restTemplate = new RestTemplate(httpRequestFactory);
|
|
|
+ String url = "http://localhost:9998/question";
|
|
|
+ SysDictData remoteData = sysDictDataService.getDictDataByTypeAndValue("kg_algorithm", "questionUrl");
|
|
|
+ if (remoteData != null && StringUtils.isNotBlank(remoteData.getRemark())) {
|
|
|
+ url = remoteData.getRemark();
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ BaseResponse response = restTemplate.getForObject(url, BaseResponse.class);
|
|
|
+ if (response == null) {
|
|
|
+ logger.error("question response is null, url:{}", url);
|
|
|
+ throw new RuntimeException("系统异常,请稍后再试");
|
|
|
+ } else if (response.getCode() != 200) {
|
|
|
+ logger.error("question request is error! errorMsg: {}", response.getMsg());
|
|
|
+ throw new RuntimeException("系统异常,请稍后再试");
|
|
|
+ } else {
|
|
|
+ logger.info("question success,url:{}, data:{}" , url, response.getData());
|
|
|
+ return response.getData().toString();
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("智能问答请求报错", e);
|
|
|
+ throw new RuntimeException("系统异常,请稍后再试");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String analysis(String path) {
|
|
|
+ HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory();
|
|
|
+ httpRequestFactory.setConnectionRequestTimeout(3000);
|
|
|
+ httpRequestFactory.setConnectTimeout(3000);
|
|
|
+ httpRequestFactory.setReadTimeout(3000);
|
|
|
+ RestTemplate restTemplate = new RestTemplate(httpRequestFactory);
|
|
|
+ String url = "http://localhost:9998/question";
|
|
|
+ SysDictData remoteData = sysDictDataService.getDictDataByTypeAndValue("kg_algorithm", "questionUrl");
|
|
|
+ if (remoteData != null && StringUtils.isNotBlank(remoteData.getRemark())) {
|
|
|
+ url = remoteData.getRemark();
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ BaseResponse response = restTemplate.getForObject(url, BaseResponse.class);
|
|
|
+ if (response == null) {
|
|
|
+ logger.error("question response is null, url:{}", url);
|
|
|
+ throw new RuntimeException("系统异常,请稍后再试");
|
|
|
+ } else if (response.getCode() != 200) {
|
|
|
+ logger.error("question request is error! errorMsg: {}", response.getMsg());
|
|
|
+ throw new RuntimeException("系统异常,请稍后再试");
|
|
|
+ } else {
|
|
|
+ logger.info("question success,url:{}, data:{}" , url, response.getData());
|
|
|
+ return response.getData().toString();
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("智能问答请求报错", e);
|
|
|
+ throw new RuntimeException("系统异常,请稍后再试");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|