allen 2 anni fa
parent
commit
7129aa623d
25 ha cambiato i file con 420 aggiunte e 109 eliminazioni
  1. 19 6
      kgraph-admin/src/main/java/com/kgraph/web/controller/CaseDocController.java
  2. 18 6
      kgraph-admin/src/main/java/com/kgraph/web/controller/RandomDocController.java
  3. 19 6
      kgraph-admin/src/main/java/com/kgraph/web/controller/TechnologyDocController.java
  4. 19 6
      kgraph-admin/src/main/java/com/kgraph/web/controller/TextbookDocController.java
  5. 2 2
      kgraph-admin/src/main/resources/application.yml
  6. 16 0
      kgraph-common/src/main/java/com/kgraph/common/service/IFileService.java
  7. 22 0
      kgraph-common/src/main/java/com/kgraph/common/service/impl/FileServiceImpl.java
  8. 71 7
      kgraph-common/src/main/java/com/kgraph/common/utils/file/FileUtils.java
  9. 1 1
      kgraph-common/src/main/java/com/kgraph/common/utils/file/MimeTypeUtils.java
  10. 5 1
      kgraph-graph/src/main/java/com/kgraph/graph/neo4j/DTO/KgDocDTO.java
  11. 1 1
      kgraph-graph/src/main/java/com/kgraph/graph/neo4j/controller/KgController.java
  12. 2 2
      kgraph-graph/src/main/java/com/kgraph/graph/neo4j/seavice/impl/KgServiceImpl.java
  13. 18 22
      kgraph-graph/src/main/java/com/kgraph/graph/suport/controller/ExtractKnowledgeSubTaskController.java
  14. 63 0
      kgraph-graph/src/main/java/com/kgraph/graph/suport/controller/ExtractResultController.java
  15. 19 4
      kgraph-graph/src/main/java/com/kgraph/graph/suport/controller/UploadManageController.java
  16. 39 18
      kgraph-graph/src/main/java/com/kgraph/graph/suport/domain/ExtractResult.java
  17. 40 13
      kgraph-graph/src/main/java/com/kgraph/graph/suport/service/impl/ExtractKnowledgeSubTaskServiceImpl.java
  18. 2 7
      kgraph-graph/src/main/java/com/kgraph/graph/suport/utils/SupportUtils.java
  19. 11 6
      kgraph-graph/src/main/resources/mapper/extract/ExtractResultMapper.xml
  20. 2 0
      kgraph-system/src/main/java/com/kgraph/system/mapper/SysDictDataMapper.java
  21. 2 0
      kgraph-system/src/main/java/com/kgraph/system/service/ISysDictDataService.java
  22. 4 0
      kgraph-system/src/main/java/com/kgraph/system/service/impl/SysDictDataServiceImpl.java
  23. 3 0
      kgraph-system/src/main/resources/mapper/system/SysDictDataMapper.xml
  24. 4 1
      sql/system.sql
  25. 18 0
      sql/update20230426.sql

+ 19 - 6
kgraph-admin/src/main/java/com/kgraph/web/controller/CaseDocController.java

@@ -1,7 +1,11 @@
 package com.kgraph.web.controller;
 
+import java.io.IOException;
 import java.util.List;
 import javax.servlet.http.HttpServletResponse;
+
+import com.kgraph.common.service.IFileService;
+import com.kgraph.common.utils.file.FileUtils;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -34,6 +38,9 @@ public class CaseDocController extends BaseController
     @Autowired
     private ICaseDocService caseDocService;
 
+    @Autowired
+    private IFileService fileService;
+
     /**
      * 查询案例列表
      */
@@ -75,9 +82,12 @@ public class CaseDocController extends BaseController
     @PreAuthorize("@ss.hasPermi('doc:case:add')")
     @Log(title = "案例", businessType = BusinessType.INSERT)
     @PostMapping
-    public AjaxResult add(@RequestBody CaseDoc caseDoc)
-    {
-        return toAjax(caseDocService.insertCaseDoc(caseDoc));
+    public AjaxResult add(@RequestBody CaseDoc caseDoc) throws IOException {
+        int rows = caseDocService.insertCaseDoc(caseDoc);
+        if (rows > 0) {
+            fileService.copyFileToESPath(FileUtils.getFileRealPath(caseDoc.getFilePath()));
+        }
+        return toAjax(rows);
     }
 
     /**
@@ -86,9 +96,12 @@ public class CaseDocController extends BaseController
     @PreAuthorize("@ss.hasPermi('doc:case:edit')")
     @Log(title = "案例", businessType = BusinessType.UPDATE)
     @PutMapping
-    public AjaxResult edit(@RequestBody CaseDoc caseDoc)
-    {
-        return toAjax(caseDocService.updateCaseDoc(caseDoc));
+    public AjaxResult edit(@RequestBody CaseDoc caseDoc) throws IOException {
+        int rows = caseDocService.updateCaseDoc(caseDoc);
+        if (rows > 0) {
+            fileService.copyFileToESPath(FileUtils.getFileRealPath(caseDoc.getFilePath()));
+        }
+        return toAjax(rows);
     }
 
     /**

+ 18 - 6
kgraph-admin/src/main/java/com/kgraph/web/controller/RandomDocController.java

@@ -1,7 +1,11 @@
 package com.kgraph.web.controller;
 
+import java.io.IOException;
 import java.util.List;
 import javax.servlet.http.HttpServletResponse;
+
+import com.kgraph.common.service.IFileService;
+import com.kgraph.common.utils.file.FileUtils;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -34,6 +38,8 @@ public class RandomDocController extends BaseController
     @Autowired
     private IRandomDocService randomDocService;
 
+    @Autowired
+    private IFileService fileService;
     /**
      * 查询随机资料列表
      */
@@ -75,9 +81,12 @@ public class RandomDocController extends BaseController
     @PreAuthorize("@ss.hasPermi('doc:radmon:add')")
     @Log(title = "随机资料", businessType = BusinessType.INSERT)
     @PostMapping
-    public AjaxResult add(@RequestBody RandomDoc randomDoc)
-    {
-        return toAjax(randomDocService.insertRandomDoc(randomDoc));
+    public AjaxResult add(@RequestBody RandomDoc randomDoc) throws IOException {
+        int rows = randomDocService.insertRandomDoc(randomDoc);
+        if (rows > 0) {
+            fileService.copyFileToESPath(FileUtils.getFileRealPath(randomDoc.getFilePath()));
+        }
+        return toAjax(rows);
     }
 
     /**
@@ -86,9 +95,12 @@ public class RandomDocController extends BaseController
     @PreAuthorize("@ss.hasPermi('doc:radmon:edit')")
     @Log(title = "随机资料", businessType = BusinessType.UPDATE)
     @PutMapping
-    public AjaxResult edit(@RequestBody RandomDoc randomDoc)
-    {
-        return toAjax(randomDocService.updateRandomDoc(randomDoc));
+    public AjaxResult edit(@RequestBody RandomDoc randomDoc) throws IOException {
+        int rows = randomDocService.updateRandomDoc(randomDoc);
+        if (rows > 0) {
+            fileService.copyFileToESPath(FileUtils.getFileRealPath(randomDoc.getFilePath()));
+        }
+        return toAjax(rows);
     }
 
     /**

+ 19 - 6
kgraph-admin/src/main/java/com/kgraph/web/controller/TechnologyDocController.java

@@ -1,7 +1,11 @@
 package com.kgraph.web.controller;
 
+import java.io.IOException;
 import java.util.List;
 import javax.servlet.http.HttpServletResponse;
+
+import com.kgraph.common.service.IFileService;
+import com.kgraph.common.utils.file.FileUtils;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -34,6 +38,9 @@ public class TechnologyDocController extends BaseController
     @Autowired
     private ITechnologyDocService technologyDocService;
 
+    @Autowired
+    private IFileService fileService;
+
     /**
      * 查询技术通报列表
      */
@@ -75,9 +82,12 @@ public class TechnologyDocController extends BaseController
     @PreAuthorize("@ss.hasPermi('doc:tech:add')")
     @Log(title = "技术通报", businessType = BusinessType.INSERT)
     @PostMapping
-    public AjaxResult add(@RequestBody TechnologyDoc technologyDoc)
-    {
-        return toAjax(technologyDocService.insertTechnologyDoc(technologyDoc));
+    public AjaxResult add(@RequestBody TechnologyDoc technologyDoc) throws IOException {
+        int rows = technologyDocService.insertTechnologyDoc(technologyDoc);
+        if (rows > 0) {
+            fileService.copyFileToESPath(FileUtils.getFileRealPath(technologyDoc.getFilePath()));
+        }
+        return toAjax(rows);
     }
 
     /**
@@ -86,9 +96,12 @@ public class TechnologyDocController extends BaseController
     @PreAuthorize("@ss.hasPermi('doc:tech:edit')")
     @Log(title = "技术通报", businessType = BusinessType.UPDATE)
     @PutMapping
-    public AjaxResult edit(@RequestBody TechnologyDoc technologyDoc)
-    {
-        return toAjax(technologyDocService.updateTechnologyDoc(technologyDoc));
+    public AjaxResult edit(@RequestBody TechnologyDoc technologyDoc) throws IOException {
+        int rows = technologyDocService.updateTechnologyDoc(technologyDoc);
+        if (rows > 0) {
+            fileService.copyFileToESPath(FileUtils.getFileRealPath(technologyDoc.getFilePath()));
+        }
+        return toAjax(rows);
     }
 
     /**

+ 19 - 6
kgraph-admin/src/main/java/com/kgraph/web/controller/TextbookDocController.java

@@ -1,7 +1,11 @@
 package com.kgraph.web.controller;
 
+import java.io.IOException;
 import java.util.List;
 import javax.servlet.http.HttpServletResponse;
+
+import com.kgraph.common.service.IFileService;
+import com.kgraph.common.utils.file.FileUtils;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -34,6 +38,9 @@ public class TextbookDocController extends BaseController
     @Autowired
     private ITextbookDocService textbookDocService;
 
+    @Autowired
+    private IFileService fileService;
+
     /**
      * 查询教材列表
      */
@@ -75,9 +82,12 @@ public class TextbookDocController extends BaseController
     @PreAuthorize("@ss.hasPermi('doc:textbook:add')")
     @Log(title = "教材", businessType = BusinessType.INSERT)
     @PostMapping
-    public AjaxResult add(@RequestBody TextbookDoc textbookDoc)
-    {
-        return toAjax(textbookDocService.insertTextbookDoc(textbookDoc));
+    public AjaxResult add(@RequestBody TextbookDoc textbookDoc) throws IOException {
+        int rows = textbookDocService.insertTextbookDoc(textbookDoc);
+        if (rows > 0) {
+            fileService.copyFileToESPath(FileUtils.getFileRealPath(textbookDoc.getFilePath()));
+        }
+        return toAjax(rows);
     }
 
     /**
@@ -86,9 +96,12 @@ public class TextbookDocController extends BaseController
     @PreAuthorize("@ss.hasPermi('doc:textbook:edit')")
     @Log(title = "教材", businessType = BusinessType.UPDATE)
     @PutMapping
-    public AjaxResult edit(@RequestBody TextbookDoc textbookDoc)
-    {
-        return toAjax(textbookDocService.updateTextbookDoc(textbookDoc));
+    public AjaxResult edit(@RequestBody TextbookDoc textbookDoc) throws IOException {
+        int rows = textbookDocService.updateTextbookDoc(textbookDoc);
+        if (rows > 0) {
+            fileService.copyFileToESPath(FileUtils.getFileRealPath(textbookDoc.getFilePath()));
+        }
+        return toAjax(rows);
     }
 
     /**

+ 2 - 2
kgraph-admin/src/main/resources/application.yml

@@ -91,9 +91,9 @@ spring:
         max-wait: -1ms
   data:
     neo4j:
-      uri: bolt://47.108.150.237:10087
+      uri: bolt://localhost:7687
       username: neo4j
-      password: neo4j
+      password: 123456
 
 # token配置
 token:

+ 16 - 0
kgraph-common/src/main/java/com/kgraph/common/service/IFileService.java

@@ -0,0 +1,16 @@
+package com.kgraph.common.service;
+
+import com.kgraph.common.config.KgraphConfig;
+import com.kgraph.common.utils.file.FileUtils;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.stereotype.Service;
+
+import java.io.IOException;
+
+public interface IFileService {
+
+    public static final String ES_PATH = KgraphConfig.getProfile() + "/ElasticSearchFile";
+
+    void copyFileToESPath(String filePath) throws IOException;
+
+}

+ 22 - 0
kgraph-common/src/main/java/com/kgraph/common/service/impl/FileServiceImpl.java

@@ -0,0 +1,22 @@
+package com.kgraph.common.service.impl;
+
+import com.kgraph.common.service.IFileService;
+import com.kgraph.common.utils.file.FileUtils;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.stereotype.Service;
+
+import java.io.IOException;
+
+@Service
+public class FileServiceImpl implements IFileService {
+
+    /**
+     * 复制上传的路径到esPath
+     * @param filePath 文件路径
+     */
+    @Async
+    @Override
+    public void copyFileToESPath(String filePath) throws IOException {
+        FileUtils.copyFileUsingFileChannels(filePath, IFileService.ES_PATH + "/" + FileUtils.getFileNameByPath(filePath));
+    }
+}

+ 71 - 7
kgraph-common/src/main/java/com/kgraph/common/utils/file/FileUtils.java

@@ -1,13 +1,8 @@
 package com.kgraph.common.utils.file;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.UnsupportedEncodingException;
+import java.io.*;
 import java.net.URLEncoder;
+import java.nio.channels.FileChannel;
 import java.nio.charset.StandardCharsets;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -29,6 +24,9 @@ public class FileUtils
 {
     public static String FILENAME_PATTERN = "[a-zA-Z0-9_\\-\\|\\.\\u4e00-\\u9fa5]+";
 
+    // 设置每个数据块的大小 8 MB
+    public static final long CHUNK_SIZE = 8 * 1024 * 1024;
+
     /**
      * 输出指定文件的byte数组
      * 
@@ -303,4 +301,70 @@ public class FileUtils
         return filePaths[filePaths.length-1];
     }
 
+    public static void copyFileUsingFileChannels(String sourcePath, String destPath) throws IOException {
+
+        // 创建目标目录
+        File targetDir = new File(destPath).getParentFile();
+        if (targetDir != null && !targetDir.exists()) {
+            targetDir.mkdirs();
+        }
+
+        // 检查源文件和目标路径是否存在
+        File sourceFile = new File(sourcePath);
+        if (!sourceFile.exists() || !sourceFile.isFile()) {
+            throw new FileNotFoundException("Source file does not exist or is not a file: " + sourcePath);
+        }
+
+        File targetFile = new File(destPath);
+        if (targetFile.isDirectory()) {
+            targetFile = new File(targetFile, sourceFile.getName());
+        }
+
+        try (
+                // 创建 FileInputStream 和 FileOutputStream 对象
+                FileInputStream fis = new FileInputStream(sourceFile);
+                FileOutputStream fos = new FileOutputStream(targetFile);
+                // 从 FileInputStream 和 FileOutputStream 对象中获取 FileChannel 实例
+                FileChannel sourceChannel = fis.getChannel();
+                FileChannel targetChannel = fos.getChannel()
+        ) {
+            // 获取源文件的大小
+            long fileSize = sourceChannel.size();
+            long transferredBytes = 0;
+
+            // 使用循环将数据分块传输
+            while (transferredBytes < fileSize) {
+                long remainingBytes = fileSize - transferredBytes;
+                long bytesToTransfer = Math.min(CHUNK_SIZE, remainingBytes);
+                targetChannel.transferFrom(sourceChannel, transferredBytes, bytesToTransfer);
+                transferredBytes += bytesToTransfer;
+            }
+        }
+    }
+
+    public static String getFileRealPath(String filePath) {
+        String realFileName = FileUtils.getFileNameByPath(filePath);
+        if (filePath.startsWith(KgraphConfig.UPLOAD_HEAD_PATH)) {
+            filePath = filePath.substring(KgraphConfig.UPLOAD_HEAD_PATH_LENGTH);
+        }
+        return KgraphConfig.getUploadPath() + filePath;
+    }
+
+    public static void writeJsonToFile(String json, String filePath) throws IOException {
+        // 创建文件对象
+        File file = new File(filePath);
+
+        // 如果文件不存在,则创建文件
+        if (!file.exists()) {
+            file.createNewFile();
+        }
+
+        try (FileWriter writer = new FileWriter(file)) {
+            writer.write(json);
+            writer.flush();
+        } catch (IOException e) {
+            // 异常处理
+            throw new RuntimeException("json 写入异常");
+        }
+    }
 }

+ 1 - 1
kgraph-common/src/main/java/com/kgraph/common/utils/file/MimeTypeUtils.java

@@ -36,7 +36,7 @@ public class MimeTypeUtils
             // 视频格式
             "mp4", "avi", "rmvb",
             // pdf
-            "pdf" };
+            "pdf", "json", "csv" };
 
     public static String getExtension(String prefix)
     {

+ 5 - 1
kgraph-graph/src/main/java/com/kgraph/graph/neo4j/DTO/KgDocDTO.java

@@ -6,8 +6,12 @@ import java.util.List;
 
 @Data
 public class KgDocDTO {
+    public static final String SENTENCE = "sentence";
+    public static final String EXTRACT = "extract";
+
     private DocInfo docInfo;
-    private List<KgDTO> knowledgeList;
+    private String resultType;
+    private String resultPath;
     private Integer code;
     private String msg;
 }

+ 1 - 1
kgraph-graph/src/main/java/com/kgraph/graph/neo4j/controller/KgController.java

@@ -88,6 +88,6 @@ public class KgController extends BaseController {
 
     @GetMapping("/question")
     public AjaxResult question(@RequestParam("text") String question) {
-        return AjaxResult.success(kgService.question(question));
+        return AjaxResult.success("success", kgService.question(question));
     }
 }

+ 2 - 2
kgraph-graph/src/main/java/com/kgraph/graph/neo4j/seavice/impl/KgServiceImpl.java

@@ -146,13 +146,13 @@ public class KgServiceImpl implements IKgService {
             url = remoteData.getRemark();
         }
         try {
-            BaseResponse response = restTemplate.getForObject(url, BaseResponse.class);
+            BaseResponse response = restTemplate.getForObject(url+"?question="+question, 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("系统异常,请稍后再试");
+                return response.getMsg();
             } else {
                 logger.info("question success,url:{}, data:{}" , url, response.getData());
                 return response.getData().toString();

+ 18 - 22
kgraph-graph/src/main/java/com/kgraph/graph/suport/controller/ExtractKnowledgeSubTaskController.java

@@ -107,32 +107,28 @@ public class ExtractKnowledgeSubTaskController extends BaseController
         return toAjax(extractKnowledgeSubTaskService.deleteExtractKnowledgeSubTaskByIds(ids));
     }
 
-//    @PostMapping("/saveKnowledge")
-//    public AjaxResult saveKnowledge(@RequestBody KgDocDTO kgDocDTO){
-//        logger.info("saveKnowledge 方法调用成功,kgDocDTO: {}", kgDocDTO);
-//        if(kgDocDTO == null){
-//            return AjaxResult.error("无效payload");
-//        }
-//
-//        if(kgDocDTO.getDocInfo() == null || kgDocDTO.getDocInfo().getDocId() == null){
-//            return AjaxResult.error("文件信息不能为null");
-//        }
-//
-//        if(CollectionUtils.isEmpty(kgDocDTO.getKnowledgeList())){
-////            return AjaxResult.error("没有数据");
-//            logger.info("kgDocDTO 没有数据.");
-//        }
-//        extractKnowledgeSubTaskService.saveKnowledge(kgDocDTO);
-//        return AjaxResult.success();
-//    }
-
     @PostMapping("/saveKnowledge")
-    public AjaxResult saveKnowledge(@RequestBody JSONObject extractResult){
-        logger.info("saveKnowledge 方法调用成功,extractResult: {}", extractResult);
-        extractKnowledgeSubTaskService.saveKnowledge(extractResult);
+    public AjaxResult saveKnowledge(@RequestBody KgDocDTO kgDocDTO){
+        logger.info("saveKnowledge 方法调用成功,kgDocDTO: {}", kgDocDTO);
+        if(kgDocDTO == null){
+            return AjaxResult.error("无效payload");
+        }
+
+        if(kgDocDTO.getDocInfo() == null || kgDocDTO.getDocInfo().getDocId() == null){
+            return AjaxResult.error("文件信息不能为null");
+        }
+
+        extractKnowledgeSubTaskService.saveKnowledge(kgDocDTO);
         return AjaxResult.success();
     }
 
+//    @PostMapping("/saveKnowledge")
+//    public AjaxResult saveKnowledge(@RequestBody JSONObject extractResult){
+//        logger.info("saveKnowledge 方法调用成功,extractResult: {}", extractResult);
+//        extractKnowledgeSubTaskService.saveKnowledge(extractResult);
+//        return AjaxResult.success();
+//    }
+
     @PostMapping("/approve/{id}/{status}")
     public AjaxResult approveSubTask(@PathVariable("id") Long id, @PathVariable("status") String status, @RequestBody ExtractResult extractResult){
         extractKnowledgeSubTaskService.approveSubTask(id, status, extractResult);

+ 63 - 0
kgraph-graph/src/main/java/com/kgraph/graph/suport/controller/ExtractResultController.java

@@ -1,7 +1,18 @@
 package com.kgraph.graph.suport.controller;
 
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.List;
 import javax.servlet.http.HttpServletResponse;
+
+import com.alibaba.fastjson2.JSONArray;
+import com.alibaba.fastjson2.JSONObject;
+import com.kgraph.common.utils.StringUtils;
+import com.kgraph.common.utils.file.FileUtils;
+import com.kgraph.system.service.ISysDictDataService;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -34,6 +45,9 @@ public class ExtractResultController extends BaseController
     @Autowired
     private IExtractResultService extractResultService;
 
+    @Autowired
+    private ISysDictDataService dictDataService;
+
     /**
      * 查询抽取结果信息列表
      */
@@ -111,4 +125,53 @@ public class ExtractResultController extends BaseController
     {
         return toAjax(extractResultService.deleteExtractResultByIds(ids));
     }
+
+    @GetMapping("/getResult")
+    public AjaxResult getResult(String filePath) throws IOException {
+        if (!FileUtils.checkAllowDownload(filePath)) {
+            throw new RuntimeException(StringUtils.format("文件名称({})非法,不允许下载。 ", filePath));
+        }
+        String realFileName = FileUtils.getFileNameByPath(filePath);
+
+        String parentPath = dictDataService.getValueByTypeAndValue("kg_algorithm", "resultPath");
+        String filePathFinal = filePath;
+        if (StringUtils.isNotEmpty(parentPath)) {
+            filePathFinal = parentPath + filePathFinal;
+        }
+        Path path = Paths.get(filePathFinal);
+        String data = new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
+        return AjaxResult.success("success", data);
+    }
+
+    /**
+     * 获取抽取结果信息详细信息
+     */
+    @PreAuthorize("@ss.hasPermi('extract:result:query')")
+    @GetMapping(value = "/getSentence/{id}")
+    public AjaxResult getSentence(@PathVariable("id") Long subtaskId) throws IOException {
+        ExtractResult result = extractResultService.getResultBySubTaskId(subtaskId);
+        String sentencePath = result.getSentence();
+        if(StringUtils.isNotEmpty(sentencePath)){
+            String data = (String) getResult(sentencePath).get(AjaxResult.DATA_TAG);
+            JSONArray jsonArray = JSONArray.parseArray(data);
+            return success(jsonArray);
+        }
+        return error("没有生成分句结果");
+    }
+
+    /**
+     * 获取抽取结果信息详细信息
+     */
+    @PreAuthorize("@ss.hasPermi('extract:result:query')")
+    @GetMapping(value = "/getResult/{id}")
+    public AjaxResult getResult(@PathVariable("id") Long subtaskId) throws IOException {
+        ExtractResult result = extractResultService.getResultBySubTaskId(subtaskId);
+        String resultPath = result.getResult();
+        if(StringUtils.isNotEmpty(resultPath)){
+            String data = (String) getResult(resultPath).get(AjaxResult.DATA_TAG);
+            JSONObject jsonObject = JSONObject.parseObject(data);
+            return success(jsonObject);
+        }
+        return error("没有生成抽取结果");
+    }
 }

+ 19 - 4
kgraph-graph/src/main/java/com/kgraph/graph/suport/controller/UploadManageController.java

@@ -1,10 +1,12 @@
 package com.kgraph.graph.suport.controller;
 
+import java.io.IOException;
 import java.util.List;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import com.kgraph.common.config.KgraphConfig;
+import com.kgraph.common.service.IFileService;
 import com.kgraph.common.utils.StringUtils;
 import com.kgraph.common.utils.file.FileUtils;
 import org.springframework.http.MediaType;
@@ -33,6 +35,9 @@ public class UploadManageController extends BaseController
     @Autowired
     private IUploadManageService uploadManageService;
 
+    @Autowired
+    private IFileService fileService;
+
     /**
      * 查询上传管理列表
      */
@@ -76,7 +81,13 @@ public class UploadManageController extends BaseController
     @PostMapping
     public AjaxResult add(@RequestBody UploadManage uploadManage) throws Exception {
         uploadManage.setCreateBy(getUsername());
-        return toAjax(uploadManageService.insertUploadManage(uploadManage));
+        int rows = uploadManageService.insertUploadManage(uploadManage);
+        // 把文件复制到ES处理的目录下
+        if (rows > 0) {
+            fileService.copyFileToESPath(FileUtils.getFileRealPath(uploadManage.getFilePath()));
+        }
+
+        return toAjax(rows);
     }
 
     /**
@@ -85,10 +96,14 @@ public class UploadManageController extends BaseController
     @PreAuthorize("@ss.hasPermi('upload:uploadManage:edit')")
     @Log(title = "上传管理", businessType = BusinessType.UPDATE)
     @PutMapping
-    public AjaxResult edit(@RequestBody UploadManage uploadManage)
-    {
+    public AjaxResult edit(@RequestBody UploadManage uploadManage) throws IOException {
         uploadManage.setUpdateBy(getUsername());
-        return toAjax(uploadManageService.updateUploadManage(uploadManage));
+        int rows = uploadManageService.updateUploadManage(uploadManage);
+        // 把文件复制到ES处理的目录下
+        if (rows > 0) {
+            fileService.copyFileToESPath(FileUtils.getFileRealPath(uploadManage.getFilePath()));
+        }
+        return toAjax(rows);
     }
 
     /**

+ 39 - 18
kgraph-graph/src/main/java/com/kgraph/graph/suport/domain/ExtractResult.java

@@ -7,7 +7,7 @@ import com.kgraph.common.core.domain.BaseEntity;;
 
 /**
  * 抽取结果信息对象 t_extract_result
- * 
+ *
  * @author Allen
  * @date 2023-04-20
  */
@@ -22,48 +22,69 @@ public class ExtractResult extends BaseEntity
     @Excel(name = "子任务id")
     private Long subTaskId;
 
-    /** 抽取结果集 */
-    @Excel(name = "抽取结果集")
+    /** 分句结果 */
+    @Excel(name = "分句结果路径")
+    private String sentence;
+
+    /** 抽取结果路径 */
+    @Excel(name = "抽取结果路径")
     private String result;
 
-    public void setId(Long id) 
+    private String resultData;
+
+    public void setId(Long id)
     {
         this.id = id;
     }
 
-    public Long getId() 
+    public Long getId()
     {
         return id;
     }
-    public void setSubTaskId(Long subTaskId) 
+    public void setSubTaskId(Long subTaskId)
     {
         this.subTaskId = subTaskId;
     }
 
-    public Long getSubTaskId() 
+    public Long getSubTaskId()
     {
         return subTaskId;
     }
-    public void setResult(String result) 
+    public void setSentence(String sentence)
+    {
+        this.sentence = sentence;
+    }
+
+    public String getSentence()
+    {
+        return sentence;
+    }
+    public void setResult(String result)
     {
         this.result = result;
     }
 
-    public String getResult() 
+    public String getResult()
     {
         return result;
     }
 
+    public String getResultData() {
+        return resultData;
+    }
+
+    public void setResultData(String resultData) {
+        this.resultData = resultData;
+    }
+
     @Override
     public String toString() {
-        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
-            .append("id", getId())
-            .append("subTaskId", getSubTaskId())
-            .append("result", getResult())
-            .append("createBy", getCreateBy())
-            .append("createTime", getCreateTime())
-            .append("updateBy", getUpdateBy())
-            .append("updateTime", getUpdateTime())
-            .toString();
+        return "ExtractResult{" +
+                "id=" + id +
+                ", subTaskId=" + subTaskId +
+                ", sentence='" + sentence + '\'' +
+                ", result='" + result + '\'' +
+                ", resultData='" + resultData + '\'' +
+                '}';
     }
 }

+ 40 - 13
kgraph-graph/src/main/java/com/kgraph/graph/suport/service/impl/ExtractKnowledgeSubTaskServiceImpl.java

@@ -5,6 +5,7 @@ import com.alibaba.fastjson2.JSONObject;
 import com.kgraph.common.core.domain.BaseResponse;
 import com.kgraph.common.core.domain.entity.SysDictData;
 import com.kgraph.common.utils.DateUtils;
+import com.kgraph.common.utils.file.FileUtils;
 import com.kgraph.graph.neo4j.DTO.DocInfo;
 import com.kgraph.graph.neo4j.DTO.KgDTO;
 import com.kgraph.graph.neo4j.DTO.KgDocDTO;
@@ -28,6 +29,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.client.RestTemplate;
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
@@ -199,13 +201,20 @@ public class ExtractKnowledgeSubTaskServiceImpl implements IExtractKnowledgeSubT
         // 更新子任务状态
         extractKnowledgeSubTaskMapper.updateSubTaskStatusById(id, status, null, null);
 
-        // save resultJson
-        extractResultService.updateExtractResult(extractResult);
-        String result = extractResult.getResult();
-        JSONObject extractResultJson = JSONObject.parseObject(result);
-
-        // 审批 则同步到图数据库
+        // 审批 则同步到图数据库 保存json
         if (ExtractKnowledgeSubTask.REVIEWED.equals(status)) {
+
+            // save resultJson
+            String resultPath = sysDictDataService.getValueByTypeAndValue("kg_algorithm", "resultPath");
+            String result = extractResult.getResultData();
+
+            try {
+                FileUtils.writeJsonToFile(result,resultPath+extractResult.getResult());
+            } catch (Exception e) {
+                logger.error("抽取结果保存失败");
+            }
+
+            JSONObject extractResultJson = JSONObject.parseObject(result);
             JSONArray knowledgeList = extractResultJson.getJSONArray("knowledgeList");
             List<KgDTO> list = new ArrayList<>(knowledgeList.size());
             for (int i = 0; i < knowledgeList.size(); i++) {
@@ -263,16 +272,34 @@ public class ExtractKnowledgeSubTaskServiceImpl implements IExtractKnowledgeSubT
     }
 
     private void processSuccess(KgDocDTO kgDocDTO) {
-        // 更新状态
-        List<TripletInfo> tripletInfoList = new ArrayList<>(kgDocDTO.getKnowledgeList().size());
         Long subTaskId = kgDocDTO.getDocInfo().getSubTaskId();
-        for (KgDTO kgDTO : kgDocDTO.getKnowledgeList()) {
-            TripletInfo tripletInfo = TripletInfo.buildByKgDocDTO(kgDTO, subTaskId);
-            tripletInfoList.add(tripletInfo);
+        String dictValue = sysDictDataService.getValueByTypeAndValue("kg_algorithm","resultPath");
+        ExtractResult extractResultDb = extractResultService.getResultBySubTaskId(subTaskId);
+        String resultPath = kgDocDTO.getResultPath();
+        if(StringUtils.isNotBlank(resultPath) && StringUtils.isNotBlank(dictValue)){
+            resultPath = resultPath.replace(dictValue,"");
+        }
+        if(extractResultDb == null) {
+            ExtractResult extractResult = new ExtractResult();
+            extractResult.setSubTaskId(subTaskId);
+            if (KgDocDTO.EXTRACT.equals(kgDocDTO.getResultType())) {
+                extractResult.setResult(resultPath);
+            } else {
+                extractResult.setSentence(resultPath);
+            }
+            extractResultService.insertExtractResult(extractResult);
+        } else {
+            if (KgDocDTO.EXTRACT.equals(kgDocDTO.getResultType())) {
+                extractResultDb.setResult(resultPath);
+            } else {
+                extractResultDb.setSentence(resultPath);
+            }
+            extractResultService.updateExtractResult(extractResultDb);
         }
-        tripletInfoService.createList(tripletInfoList);
         // 更新task状态
-        updateSubTaskStatusById(subTaskId, ExtractKnowledgeSubTask.TO_BE_REVIEWED, kgDocDTO.getMsg());
+        if(KgDocDTO.EXTRACT.equals(kgDocDTO.getResultType())){
+            updateSubTaskStatusById(subTaskId, ExtractKnowledgeSubTask.TO_BE_REVIEWED, kgDocDTO.getMsg());
+        }
     }
 
     public void updateSubTaskStatusById(Long subTaskId, String status, String msg) {

+ 2 - 7
kgraph-graph/src/main/java/com/kgraph/graph/suport/utils/SupportUtils.java

@@ -10,6 +10,8 @@ import java.io.File;
 import java.io.IOException;
 import java.util.*;
 
+import static com.kgraph.common.utils.file.FileUtils.getFileRealPath;
+
 public class SupportUtils {
 
     public static final int NUM_IN_LINE_PDF_SEED = 40;
@@ -30,13 +32,6 @@ public class SupportUtils {
         }
     };
 
-    public static String getFileRealPath(String filePath) {
-        String realFileName = FileUtils.getFileNameByPath(filePath);
-        if (filePath.startsWith(KgraphConfig.UPLOAD_HEAD_PATH)) {
-            filePath = filePath.substring(KgraphConfig.UPLOAD_HEAD_PATH_LENGTH);
-        }
-        return KgraphConfig.getUploadPath() + filePath;
-    }
 
     public static String pdfToText(String filePath) throws IOException {
         String fileRealPath = getFileRealPath(filePath);

+ 11 - 6
kgraph-graph/src/main/resources/mapper/extract/ExtractResultMapper.xml

@@ -3,10 +3,11 @@
 PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.kgraph.graph.suport.mapper.ExtractResultMapper">
-    
+
     <resultMap type="ExtractResult" id="ExtractResultResult">
         <result property="id"    column="id"    />
         <result property="subTaskId"    column="sub_task_id"    />
+        <result property="sentence"    column="sentence"    />
         <result property="result"    column="result"    />
         <result property="createBy"    column="create_by"    />
         <result property="createTime"    column="create_time"    />
@@ -15,26 +16,28 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </resultMap>
 
     <sql id="selectExtractResultVo">
-        select id, sub_task_id, result, create_by, create_time, update_by, update_time from t_extract_result
+        select id, sub_task_id, sentence, result, create_by, create_time, update_by, update_time from t_extract_result
     </sql>
 
     <select id="selectExtractResultList" parameterType="ExtractResult" resultMap="ExtractResultResult">
         <include refid="selectExtractResultVo"/>
-        <where>  
+        <where>
             <if test="subTaskId != null "> and sub_task_id = #{subTaskId}</if>
+            <if test="sentence != null  and sentence != ''"> and sentence = #{sentence}</if>
             <if test="result != null  and result != ''"> and result = #{result}</if>
         </where>
     </select>
-    
+
     <select id="selectExtractResultById" parameterType="Long" resultMap="ExtractResultResult">
         <include refid="selectExtractResultVo"/>
         where id = #{id}
     </select>
-        
+
     <insert id="insertExtractResult" parameterType="ExtractResult" useGeneratedKeys="true" keyProperty="id">
         insert into t_extract_result
         <trim prefix="(" suffix=")" suffixOverrides=",">
             <if test="subTaskId != null">sub_task_id,</if>
+            <if test="sentence != null">sentence,</if>
             <if test="result != null">result,</if>
             <if test="createBy != null">create_by,</if>
             <if test="createTime != null">create_time,</if>
@@ -43,6 +46,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
          </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="subTaskId != null">#{subTaskId},</if>
+            <if test="sentence != null">#{sentence},</if>
             <if test="result != null">#{result},</if>
             <if test="createBy != null">#{createBy},</if>
             <if test="createTime != null">#{createTime},</if>
@@ -55,6 +59,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         update t_extract_result
         <trim prefix="SET" suffixOverrides=",">
             <if test="subTaskId != null">sub_task_id = #{subTaskId},</if>
+            <if test="sentence != null">sentence = #{sentence},</if>
             <if test="result != null">result = #{result},</if>
             <if test="createBy != null">create_by = #{createBy},</if>
             <if test="createTime != null">create_time = #{createTime},</if>
@@ -69,7 +74,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </delete>
 
     <delete id="deleteExtractResultByIds" parameterType="String">
-        delete from t_extract_result where id in 
+        delete from t_extract_result where id in
         <foreach item="id" collection="array" open="(" separator="," close=")">
             #{id}
         </foreach>

+ 2 - 0
kgraph-system/src/main/java/com/kgraph/system/mapper/SysDictDataMapper.java

@@ -95,4 +95,6 @@ public interface SysDictDataMapper
     public int updateDictDataType(@Param("oldDictType") String oldDictType, @Param("newDictType") String newDictType);
 
     public SysDictData getDictDataByTypeAndValue(@Param("dictType") String dictType, @Param("dictValue") String value);
+
+    public String getValueByTypeAndValue(@Param("dictType") String dictType, @Param("dictLabel") String dictLabel);
 }

+ 2 - 0
kgraph-system/src/main/java/com/kgraph/system/service/ISysDictDataService.java

@@ -60,4 +60,6 @@ public interface ISysDictDataService
     public int updateDictData(SysDictData dictData);
 
     public SysDictData getDictDataByTypeAndValue(String dictType, String value);
+
+    public String getValueByTypeAndValue(String dictType, String dictLabel);
 }

+ 4 - 0
kgraph-system/src/main/java/com/kgraph/system/service/impl/SysDictDataServiceImpl.java

@@ -114,4 +114,8 @@ public class SysDictDataServiceImpl implements ISysDictDataService
     public SysDictData getDictDataByTypeAndValue(String dictType, String value) {
         return dictDataMapper.getDictDataByTypeAndValue(dictType, value);
     }
+    @Override
+    public String getValueByTypeAndValue(String dictType, String dictLabel) {
+        return dictDataMapper.getValueByTypeAndValue(dictType, dictLabel);
+    }
 }

+ 3 - 0
kgraph-system/src/main/resources/mapper/system/SysDictDataMapper.xml

@@ -125,6 +125,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		<include refid="selectDictDataVo"/>
 			WHERE dict_type = #{dictType} AND dict_value = #{dictValue}
 	</select>
+	<select id="getValueByTypeAndValue" resultType="String">
+		select dict_value from sys_dict_data WHERE dict_type = #{dictType} AND dict_label = #{dictLabel}
+	</select>
 
 
 </mapper> 

+ 4 - 1
sql/system.sql

@@ -1900,10 +1900,13 @@ IF
 CREATE TABLE t_extract_result (
 	id BIGINT ( 20 ) NOT NULL auto_increment COMMENT '编号',
 	sub_task_id BIGINT ( 20 ) NOT NULL COMMENT '子任务id',
-	result TEXT COMMENT '抽取结果集',
+	sentence VARCHAR ( 512 ) COMMENT '分句结果',
+	result VARCHAR ( 512 ) COMMENT '抽取结果路径',
 	create_by VARCHAR ( 64 ) DEFAULT '' COMMENT '创建者',
 	create_time datetime COMMENT '创建时间',
 	update_by VARCHAR ( 64 ) DEFAULT '' COMMENT '更新者',
 	update_time datetime COMMENT '更新时间',
 PRIMARY KEY ( id )
 ) ENGINE = INNODB auto_increment = 1 COMMENT = '抽取结果信息';
+
+-- 添加数据字典kg_algorithm

+ 18 - 0
sql/update20230426.sql

@@ -0,0 +1,18 @@
+use kgraph;
+
+DROP TABLE
+IF
+	EXISTS t_extract_result;
+CREATE TABLE t_extract_result (
+	id BIGINT ( 20 ) NOT NULL auto_increment COMMENT '编号',
+	sub_task_id BIGINT ( 20 ) NOT NULL COMMENT '子任务id',
+	sentence VARCHAR ( 512 ) COMMENT '分句结果',
+	result VARCHAR ( 512 ) COMMENT '抽取结果路径',
+	create_by VARCHAR ( 64 ) DEFAULT '' COMMENT '创建者',
+	create_time datetime COMMENT '创建时间',
+	update_by VARCHAR ( 64 ) DEFAULT '' COMMENT '更新者',
+	update_time datetime COMMENT '更新时间',
+PRIMARY KEY ( id )
+) ENGINE = INNODB auto_increment = 1 COMMENT = '抽取结果信息';
+
+commit;