Sfoglia il codice sorgente

解决合并冲突--gz-en-bash

zhangenzhi 1 anno fa
parent
commit
c7bed428ca
37 ha cambiato i file con 1114 aggiunte e 223 eliminazioni
  1. 0 0
      data.json
  2. 14 4
      pom.xml
  3. 8 9
      src/main/java/com/pavis/backend/slim/common/utils/CommonUtils.java
  4. 183 0
      src/main/java/com/pavis/backend/slim/common/utils/FileUtils.java
  5. 31 0
      src/main/java/com/pavis/backend/slim/framework/config/MyMetaObjectHandler.java
  6. 1 1
      src/main/java/com/pavis/backend/slim/framework/config/SecurityConfig.java
  7. 3 0
      src/main/java/com/pavis/backend/slim/framework/web/domain/BaseEntity.java
  8. 38 13
      src/main/java/com/pavis/backend/slim/project/system/client/AlgKgClient.java
  9. 35 36
      src/main/java/com/pavis/backend/slim/project/system/controller/AnnotationController.java
  10. 6 14
      src/main/java/com/pavis/backend/slim/project/system/controller/SysFileController.java
  11. 42 9
      src/main/java/com/pavis/backend/slim/project/system/controller/SysKgController.java
  12. 28 4
      src/main/java/com/pavis/backend/slim/project/system/domain/EntityLabelsRelation.java
  13. 10 0
      src/main/java/com/pavis/backend/slim/project/system/domain/SysKg.java
  14. 2 0
      src/main/java/com/pavis/backend/slim/project/system/domain/annotation/AnnotationEntity.java
  15. 12 0
      src/main/java/com/pavis/backend/slim/project/system/domain/annotation/AnnotationEntityRelation.java
  16. 3 0
      src/main/java/com/pavis/backend/slim/project/system/domain/annotation/ConvertDocToTxt.java
  17. 1 1
      src/main/java/com/pavis/backend/slim/project/system/domain/annotation/ConvertDocToTxtAlg.java
  18. 3 9
      src/main/java/com/pavis/backend/slim/project/system/domain/annotation/DelAnnotation.java
  19. 31 0
      src/main/java/com/pavis/backend/slim/project/system/domain/annotation/ExportAnnotationData.java
  20. 26 0
      src/main/java/com/pavis/backend/slim/project/system/domain/annotation/ExportSchemaData.java
  21. 64 0
      src/main/java/com/pavis/backend/slim/project/system/domain/annotation/ExportSysEntity.java
  22. 1 1
      src/main/java/com/pavis/backend/slim/project/system/domain/annotation/UniversalGgraphToAlg.java
  23. 6 1
      src/main/java/com/pavis/backend/slim/project/system/service/AnnotationListService.java
  24. 43 0
      src/main/java/com/pavis/backend/slim/project/system/service/EntityLablesRelationService.java
  25. 4 1
      src/main/java/com/pavis/backend/slim/project/system/service/EntityLablesSpanService.java
  26. 11 1
      src/main/java/com/pavis/backend/slim/project/system/service/GenerateGraphService.java
  27. 11 2
      src/main/java/com/pavis/backend/slim/project/system/service/SysFileService.java
  28. 55 3
      src/main/java/com/pavis/backend/slim/project/system/service/SysKgService.java
  29. 33 49
      src/main/java/com/pavis/backend/slim/project/system/service/impl/AnnotationListServiceImpl.java
  30. 200 33
      src/main/java/com/pavis/backend/slim/project/system/service/impl/EntityLabelsRelationServiceImpl.java
  31. 16 11
      src/main/java/com/pavis/backend/slim/project/system/service/impl/EntityLabelsSpanServiceImpl.java
  32. 64 13
      src/main/java/com/pavis/backend/slim/project/system/service/impl/GenerateGraphServiceImpl.java
  33. 30 4
      src/main/java/com/pavis/backend/slim/project/system/service/impl/SysFileServiceImpl.java
  34. 1 1
      src/main/java/com/pavis/backend/slim/project/system/service/impl/SysKbFileServiceImpl.java
  35. 95 0
      src/main/java/com/pavis/backend/slim/project/system/service/impl/SysKgServiceImpl.java
  36. 1 1
      src/main/resources/application-ghj.yml
  37. 2 2
      src/main/resources/application.yml

File diff suppressed because it is too large
+ 0 - 0
data.json


+ 14 - 4
pom.xml

@@ -165,11 +165,21 @@
             <version>${junit.version}</version>
         </dependency>
         <dependency>
-            <groupId>MavenRepository.MavenRepository.junit</groupId>
-            <artifactId>junit</artifactId>
-            <version>4.13.2</version>
-            <scope>test</scope>
+            <groupId>com.google.code.gson</groupId>
+            <artifactId>gson</artifactId>
+            <version>2.9.1</version>
+        </dependency>
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>fastjson</artifactId>
+            <version>2.0.9</version>
         </dependency>
+        <!--<dependency>-->
+        <!--    <groupId>MavenRepository.MavenRepository.junit</groupId>-->
+        <!--    <artifactId>junit</artifactId>-->
+        <!--    <version>4.13.2</version>-->
+        <!--    <scope>test</scope>-->
+        <!--</dependency>-->
     </dependencies>
 
     <dependencyManagement>

+ 8 - 9
src/main/java/com/pavis/backend/slim/common/utils/CommonUtils.java

@@ -20,10 +20,11 @@ public class CommonUtils {
 
     /**
      * 判断当前数据是否是一个JSON。
+     *
      * @param jsonStr
      * @return
      */
-    public static Boolean isJson(String jsonStr){
+    public static Boolean isJson(String jsonStr) {
         try {
             JSONObject jsonObject = JSON.parseObject(jsonStr);
             if (jsonObject != null) {
@@ -32,7 +33,7 @@ public class CommonUtils {
                 log.info("该jsonStr不是一个JSON对象");
             }
         } catch (Exception e) {
-            log.info("ex -> 该jsonStr不是一个JSON对象:{}",e);
+            log.info("ex -> 该jsonStr不是一个JSON对象:{}", e);
             e.printStackTrace();
         }
         return false;
@@ -40,21 +41,22 @@ public class CommonUtils {
 
     /**
      * 判断当前数据是否是一个JSONArray。
+     *
      * @param jsonStr
      * @return
      */
-    public static Boolean isJsonArray(String jsonStr){
+    public static Boolean isJsonArray(String jsonStr) {
         try {
             Object json = JSON.parse(jsonStr);
             if (json instanceof JSONArray) {
-                log.info("该jsonStr是一个JSONArray对象");
+                log.info("该jsonArrayStr是一个JSONArray对象");
                 JSONArray jsonArray = (JSONArray) json;
                 return true;
             } else {
-                log.info("该jsonStr不是一个JSONArray对象");
+                log.info("该jsonArrayStr不是一个JSONArray对象");
             }
         } catch (Exception e) {
-            log.info("ex -> 该jsonStr不是一个JSONArray对象:{}",e);
+            log.info("ex -> 该jsonStr不是一个JSONArray对象:{}", e);
             e.printStackTrace();
         }
         return false;
@@ -75,7 +77,4 @@ public class CommonUtils {
         return false;
     }
 
-    public static void main(String[] args) {
-        checkMd5("test1001.docx","saf");
-    }
 }

+ 183 - 0
src/main/java/com/pavis/backend/slim/common/utils/FileUtils.java

@@ -3,18 +3,39 @@ package com.pavis.backend.slim.common.utils;
 import cn.hutool.core.util.ArrayUtil;
 import cn.hutool.core.util.IdUtil;
 import cn.hutool.core.util.StrUtil;
+import com.alibaba.fastjson2.util.IOUtils;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
 import com.pavis.backend.slim.common.constant.Constant;
+import com.pavis.backend.slim.project.system.domain.annotation.ExportSysEntity;
+import com.pavis.backend.slim.project.system.domain.annotation.ToAnnotation;
 import com.pavis.backend.slim.project.system.domain.vo.TreeFile;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.net.URLEncoder;
 import java.util.List;
 import java.util.Objects;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 
 /**
  * @author semi
  * @create 2023-04-28 15:44
  */
+@Slf4j
 public class FileUtils {
 
     /**
@@ -130,4 +151,166 @@ public class FileUtils {
                 .peek((m) -> m.setChildList(getChildrens(m, all)))
                 .collect(Collectors.toList());
     }
+
+    // 标注数据写入txt,。
+    public static String annotationDataToTxt(String data, String fileName, String filePath, HttpServletRequest request, HttpServletResponse response) throws IOException {
+        log.info("-----------------------> filePath:{}", filePath);
+        BufferedWriter bufferedWriter = null;
+        try {
+            FileWriter fileWriter = new FileWriter(filePath); // 指定文件名和路径
+            bufferedWriter = new BufferedWriter(fileWriter);
+
+            bufferedWriter.write(data);
+            bufferedWriter.newLine();
+
+            bufferedWriter.close();
+            log.info("数据已成功写入到txt中。");
+        } catch (IOException e) {
+            log.info("标注数据写入txt文件异常:{}", e);
+        } finally {
+            IOUtils.close(bufferedWriter);
+        }
+        toDownload(fileName, filePath, request, response);
+        return filePath;
+    }
+
+    /**
+     * 标注数据写入json文件中。
+     *
+     * @param datas
+     * @param fileName
+     * @param filePath
+     * @param request
+     * @param response
+     * @return
+     * @throws IOException
+     */
+    public static String annotationDataToJson(List<ToAnnotation> datas, String fileName, String filePath, HttpServletRequest request, HttpServletResponse response) throws IOException {
+        ObjectMapper mapper = new ObjectMapper();
+        mapper.enable(SerializationFeature.INDENT_OUTPUT); // 启用输出缩进
+        String annotationDatasToJson = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(datas);
+        log.info("annotationDatasToJson:{}", annotationDatasToJson);
+        // 写入文件
+        File file = new File(filePath);
+        try {
+            mapper.writeValue(file, datas);
+            // mapper.writeValue(file, annotationDatasToJson);
+            log.info("数据已成功写入到json中。");
+        } catch (IOException e) {
+            e.printStackTrace();
+            log.info("标注数据写入json文件异常 ex:{}", e);
+        }
+        log.info("file size:{}", file.length());
+        toDownload(fileName, filePath, request, response);
+        return filePath;
+    }
+
+    /**
+     * 读取json文件,并返回读取的结果string。
+     *
+     * @param filePath
+     * @return
+     */
+    public static String readJson(String filePath) {
+        ObjectMapper mapper = new ObjectMapper();
+        mapper.enable(SerializationFeature.INDENT_OUTPUT);
+
+        String readJsonStr = "";
+        try {
+            File jsonFile = new File(filePath);
+            Reader reader = new InputStreamReader(new FileInputStream(jsonFile), "utf-8");
+            int num = 0;
+            StringBuffer sb = new StringBuffer();
+            while ((num = reader.read()) != -1) {
+                sb.append((char) num);
+            }
+            reader.close();
+            readJsonStr = sb.toString();
+            // readJsonStr = StringUtils.replace(readJsonStr, "\"[", "[");
+            // readJsonStr = StringUtils.replace(readJsonStr, "]\"", "]");
+            // readJsonStr = dealStr(readJsonStr);
+            // readJsonStr = StringUtils.remove(readJsonStr,"\\r\\n\\");
+            // readJsonStr = StringUtils.remove(readJsonStr,"\\r\\n");
+            // readJsonStr = StringUtils.replace(readJsonStr,"\\\"","\"");
+            log.info("readJsonStr:{}", readJsonStr);
+            return readJsonStr;
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            log.info("读取标注数据json文件异常 ex:{}", ex);
+            return null;
+        }
+    }
+
+    /**
+     * 图谱schema数据导出至json文件。
+     *
+     * @param datas
+     * @param fileName
+     * @param filePath
+     * @param request
+     * @param response
+     * @return
+     * @throws IOException
+     */
+    public static String kgSchemaDataToJson(ExportSysEntity datas, String fileName, String filePath, HttpServletRequest request, HttpServletResponse response) throws IOException {
+        ObjectMapper mapper = new ObjectMapper();
+        mapper.enable(SerializationFeature.INDENT_OUTPUT); // 启用输出缩进
+        String annotationDatasToJson = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(datas);
+        log.info("kgSchemaDatasToJson:{}", annotationDatasToJson);
+        // 写入文件
+        File file = new File(filePath);
+        try {
+            mapper.writeValue(file, datas);
+            // mapper.writeValue(file, annotationDatasToJson);
+            log.info("图谱schema数据已成功写入到json中。");
+        } catch (IOException e) {
+            e.printStackTrace();
+            log.info("图谱schema数据写入json文件异常 ex:{}", e);
+        }
+        log.info("file size:{}", file.length());
+        toDownload(fileName, filePath, request, response);
+        return filePath;
+    }
+
+    public static String dealStr(String str) {
+        String destStr = "";
+        if (str != null) {
+            Pattern p = Pattern.compile("\\s*|\t|\r|\n");
+            Matcher m = p.matcher(str);
+            destStr = m.replaceAll("");
+        }
+        return destStr;
+    }
+
+    public static void toDownload(String fileName, String filePath, HttpServletRequest request, HttpServletResponse response) throws IOException {
+        log.info("export 标注数据至txt/json start...");
+        try (
+                InputStream inputStream = new FileInputStream(new File(filePath));
+                OutputStream outputStream = response.getOutputStream()
+        ) {
+            response.reset();
+            response.addHeader("Access-Control-Allow-Origin", "*");
+            response.addHeader("Access-Control-Expose-Headers", "Content-Disposition");
+            response.setContentType("application/octet-stream; charset=UTF-8");
+            if (request.getHeader("User-Agent").toLowerCase().indexOf("firefox") > 0) {
+                log.info("fireFox");
+                response.setHeader("Content-Disposition", "attachment;filename*=UTF-8''" + new String((fileName).getBytes("UTF-8"), "ISO8859-1"));
+            } else if (request.getHeader("User-Agent").toUpperCase().indexOf("MSIE") > 0) {
+                // IE
+                log.info("IE");
+                response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
+            } else {
+                log.info("chrome");
+                response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
+            }
+            response.flushBuffer();
+            org.apache.commons.compress.utils.IOUtils.copy(inputStream, outputStream);
+            outputStream.flush();
+            log.info("export 标注数据至txt/json end...");
+        } catch (Exception ex) {
+            log.info("export 标注数据至txt/json error:{}", ex);
+            response.getWriter().write("标注数据至txt/json失败原因: " + ex.getMessage());
+            ex.printStackTrace();
+        }
+    }
 }

+ 31 - 0
src/main/java/com/pavis/backend/slim/framework/config/MyMetaObjectHandler.java

@@ -0,0 +1,31 @@
+package com.pavis.backend.slim.framework.config;
+
+import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.ibatis.reflection.MetaObject;
+import org.springframework.stereotype.Component;
+
+import java.util.Date;
+
+/**
+ * @version: java version 1.8
+ * @Author: Guan H.J.
+ * @description:
+ * @date: 2023-11-16 13:51
+ */
+@Component
+@Slf4j
+public class MyMetaObjectHandler implements MetaObjectHandler {
+    @Override
+    public void insertFill(MetaObject metaObject) {
+        log.info("start insert fill createTime");
+        this.setFieldValByName("createTime",new Date(),metaObject);
+        this.setFieldValByName("updateTime",new Date(),metaObject);
+    }
+
+    @Override
+    public void updateFill(MetaObject metaObject) {
+        log.info("start update fill updateTime");
+        this.setFieldValByName("updateTime",new Date(),metaObject);
+    }
+}

+ 1 - 1
src/main/java/com/pavis/backend/slim/framework/config/SecurityConfig.java

@@ -128,7 +128,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
                 .antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
                 .antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll()
                 // todo ghj 算法接收标注信息测试接口,临时使用,后期需要删除。
-                .antMatchers("/annotation/testGenerateKgGraph","/annotation/convertToTxt","/annotation/universalGgraphToAlg","/annotation/generateKgGraphResult").permitAll()
+                .antMatchers("/annotation/testGenerateKgGraph","/annotation/convertToTxt","/annotation/universalGgraphToAlg","/annotation/generateKgGraphResult","/annotation/toUpText").permitAll()
                 // 除上面外的所有请求全部需要鉴权认证
                 .anyRequest().authenticated()
                 .and()

+ 3 - 0
src/main/java/com/pavis/backend/slim/framework/web/domain/BaseEntity.java

@@ -1,5 +1,6 @@
 package com.pavis.backend.slim.framework.web.domain;
 
+import com.baomidou.mybatisplus.annotation.FieldFill;
 import com.baomidou.mybatisplus.annotation.FieldStrategy;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.fasterxml.jackson.annotation.JsonFormat;
@@ -35,6 +36,7 @@ public class BaseEntity implements Serializable {
      * 创建时间
      */
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @TableField(fill = FieldFill.INSERT)
     private Date createTime;
 
     /**
@@ -46,6 +48,7 @@ public class BaseEntity implements Serializable {
      * 更新时间
      */
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @TableField(fill = FieldFill.INSERT_UPDATE)
     private Date updateTime;
 
     /**

+ 38 - 13
src/main/java/com/pavis/backend/slim/project/system/client/AlgKgClient.java

@@ -1,10 +1,15 @@
 package com.pavis.backend.slim.project.system.client;
 
 import com.alibaba.fastjson2.JSONArray;
+import com.alibaba.fastjson2.JSONObject;
 import com.pavis.backend.slim.framework.config.AlgKgConfig;
+import com.pavis.backend.slim.project.system.domain.annotation.AnnotationToAlg;
+import com.pavis.backend.slim.project.system.domain.annotation.SchemaImport;
+import com.pavis.backend.slim.project.system.domain.annotation.UniversalGgraphToAlg;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.http.MediaType;
 import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
 
 import java.util.Map;
 
@@ -22,40 +27,43 @@ public interface AlgKgClient {
     /**
      * 发送标注数据给算法服务,生成图谱。状态为200,调用下一个接口:入参kgId、fileIds等。
      * url: http://192.168.1.150:12000/labels/import
-     *
-     * @param data
+     *  入参:{"kgId":"","annotationDatas":[{"text":"","textFront":"","entities":[{}],"relations":[{}]}]}
+     *  出参:ok。
+     * @param annotationToAlg
      * @return
      */
-    // @PostMapping(value = "/annotation/testGenerateKgGraph",produces = {MediaType.APPLICATION_JSON_VALUE},
     @PostMapping(value = "/labels/import", produces = {MediaType.APPLICATION_JSON_VALUE},
             consumes = "application/json")
-    String sendToAlgForGenerateKgGraph(String data);
+    String sendToAlgForGenerateKgGraph(@RequestBody AnnotationToAlg annotationToAlg);
 
     /**
      * todo 调用此算法服务获取taskId。
-     * 入参:kgId、fielIds、type[true 通用;false 标注。]
-     * @param data
+     * 入参:{kgId、fielIds:[]、taskType[true 通用;false 标注。]}
+     * 出参:{"taskId":""}
+     * @param universalGgraphToAlg
      * @return
      */
     @PostMapping(value = "/graph/create_graph", produces = {MediaType.APPLICATION_JSON_VALUE},
             consumes = "application/json")
-    String afterSendAnnotationToGetTaskId(String data);
+    String afterSendAnnotationToGetTaskId(@RequestBody UniversalGgraphToAlg universalGgraphToAlg);
 
     /**
      * todo 调用此算法服务获取taskId。
-     * 入参:kgId、fielIds、type[true 通用;false 标注。]
-     * @param data
+     * 入参:{kgId、entityList:实体属性、relationList:关系属性。}
+     * 出参:ok。
+     * @param schemaImport
      * @return
      */
     @PostMapping(value = "/schema/import", produces = {MediaType.APPLICATION_JSON_VALUE},
             consumes = "application/json")
-    String sendEntityRelationToAlg(String data);
+    String sendEntityRelationToAlg(@RequestBody SchemaImport schemaImport);
 
 
 
     /**
      * 发送文档需转换为txt的数据给算法服务。
-     *
+     *  入参:{"files":[{"fileId":"","objectKey":"","identifier":""}]}
+     *  出参:无需关注。
      * @param data
      * @return
      */
@@ -66,23 +74,40 @@ public interface AlgKgClient {
     /**
      * 算法解析txt文本内容返回结果
      * 根据fileIds获取算法解析的txt文本内容。即去标注时,选择文档去标注时,调用。
+     * 入参:{"fileIds":[]}
+     * 出参:[{"errorCode":"","fileId":"","text":""}]
      * @param data
      * @return
      */
     @PostMapping(value = "/data_import/batch_read", produces = {MediaType.APPLICATION_JSON_VALUE},
             consumes="application/json")
-    String getAlgTxt(String data);
+    JSONArray getAlgTxt(String data);
 
     /**
      * 传本地上传的文件,调用算法实时获取文本内容。
+     * 入参:{"file":"","fileId":""}
+     * 出参:[{"errorCode":"","fileId":"","text":""}]
      * @param params
      * @return
      */
     @PostMapping(value = "/data_import/upload_file",
             consumes = MediaType.MULTIPART_FORM_DATA_VALUE,
-            produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
+            // produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
+    produces = MediaType.APPLICATION_JSON_VALUE)
     JSONArray getAlgTxtByFile(Map<String, ?> params);
 
+    /**
+     * 通知算法停止生成图谱。
+     * 入参:{"taskId":""}
+     * 出参:{'status': boolean}。true 取消成功;false 取消失败。
+     * @param data
+     * @return
+     */
+    @PostMapping(value = "/graph/stop_graph", produces = {MediaType.APPLICATION_JSON_VALUE},
+            consumes="application/json")
+    JSONObject stopGraphToAlg(String data);
+
+
 
     /**
      * todo 通用知识图谱构建,即图谱下无实体、关系数据。-----> 暂未对接。

File diff suppressed because it is too large
+ 35 - 36
src/main/java/com/pavis/backend/slim/project/system/controller/AnnotationController.java


+ 6 - 14
src/main/java/com/pavis/backend/slim/project/system/controller/SysFileController.java

@@ -1,30 +1,25 @@
 package com.pavis.backend.slim.project.system.controller;
 
-import cn.hutool.core.io.resource.InputStreamResource;
 import com.pavis.backend.slim.framework.config.MinioConfig;
 import com.pavis.backend.slim.framework.minio.MinioStorage;
 import com.pavis.backend.slim.framework.web.domain.AjaxResult;
 import com.pavis.backend.slim.project.system.domain.SysFile;
-import com.pavis.backend.slim.project.system.minio.MinioFileUtil;
 import com.pavis.backend.slim.project.system.service.SysFileService;
 import com.pavis.backend.slim.project.system.service.SysKbService;
-import io.minio.GetObjectArgs;
-import io.minio.GetObjectResponse;
 import io.minio.MinioClient;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.ResponseEntity;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.multipart.MultipartFile;
 
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.InputStream;
-
 /**
  * @author semi
  * @create 2023-04-24 14:09
@@ -38,9 +33,6 @@ public class SysFileController {
     @Autowired
     private MinioConfig minioFileUtil;
 
-    @Autowired
-    private SysKbService sysKbService;
-
     @Autowired
     MinioStorage storage;
 

+ 42 - 9
src/main/java/com/pavis/backend/slim/project/system/controller/SysKgController.java

@@ -1,5 +1,6 @@
 package com.pavis.backend.slim.project.system.controller;
 
+import com.alibaba.fastjson2.JSON;
 import com.pavis.backend.slim.framework.web.domain.AjaxResult;
 import com.pavis.backend.slim.project.system.domain.SysEntity;
 import com.pavis.backend.slim.project.system.domain.SysEntityAll;
@@ -8,26 +9,28 @@ import com.pavis.backend.slim.project.system.domain.SysEntityRelation;
 import com.pavis.backend.slim.project.system.domain.SysFile;
 import com.pavis.backend.slim.project.system.domain.SysKg;
 import com.pavis.backend.slim.project.system.domain.algorithm.AlgSpO;
+import com.pavis.backend.slim.project.system.domain.annotation.ExportSchemaData;
 import com.pavis.backend.slim.project.system.domain.front.FileKey;
-import com.pavis.backend.slim.project.system.domain.front.InKgParameter;
-import com.pavis.backend.slim.project.system.domain.front.KgReturn;
 import com.pavis.backend.slim.project.system.service.SysEntityService;
 import com.pavis.backend.slim.project.system.service.SysKgService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
-import io.swagger.annotations.ApiModel;
-import io.swagger.annotations.ApiModelProperty;
 import io.swagger.annotations.ApiOperation;
-import org.checkerframework.checker.units.qual.A;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
 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.RequestParam;
+import org.springframework.web.bind.annotation.ResponseBody;
 import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
 import java.util.List;
 
 /**
@@ -37,6 +40,7 @@ import java.util.List;
 @RestController
 @Api("图谱接口")
 @RequestMapping("/kg")
+@Slf4j
 public class SysKgController {
     @Autowired
     private SysKgService kgService;
@@ -146,23 +150,52 @@ public class SysKgController {
 
     @ApiOperation("查询实例列表")
     @PostMapping("/selEntityInstance")
-    public AjaxResult selEntityAll(@RequestBody FileKey keyEntityNce){
+    public AjaxResult selEntityAll(@RequestBody FileKey keyEntityNce) {
         return AjaxResult.success(kgService.selEntityInstance(keyEntityNce));
     }
 
     @ApiOperation("查询实例关系列表")
     @PostMapping("/selEntityRelation")
-    public AjaxResult selEntityRelation(@RequestBody FileKey keyEntityNce){
+    public AjaxResult selEntityRelation(@RequestBody FileKey keyEntityNce) {
         return AjaxResult.success(kgService.selEntityRelation(keyEntityNce));
     }
 
     @ApiOperation("图谱更新")
     @PostMapping("/updateKg")
-    public AjaxResult updateKg(@RequestBody SysKg sysKg){
+    public AjaxResult updateKg(@RequestBody SysKg sysKg) {
         return AjaxResult.success(kgService.updateKg(sysKg));
     }
 
+    /**
+     * 图谱schema的导出。
+     */
+    @PostMapping("/exportSchema")
+    @ApiOperation("图谱schema的导出")
+    @ResponseBody
+    public void exportSchema(@RequestBody ExportSchemaData exportSchemaData, HttpServletRequest request, HttpServletResponse response) throws IOException {
+        log.info("export KgSchema param --> kgId:{}", JSON.toJSONString(exportSchemaData));
+        kgService.exportSchema(exportSchemaData, request, response);
+    }
 
+    /**
+     * 图谱schema的导入。
+     */
+    @PostMapping("/importSchema")
+    @ApiOperation("图谱schema的导入")
+    @ResponseBody
+    public AjaxResult importSchema(String kgId, @RequestParam("file") MultipartFile file) throws IOException {
+        log.info("import KgSchema param --> kgId:{},fileName:{}", JSON.toJSONString(kgId), file.getOriginalFilename());
+        if (null != kgId && StringUtils.isNotEmpty(kgId)) {
+            if (!file.isEmpty()) {
+                // return AjaxResult.success("标注数据导入成功!", entityLablesRelationService.importDataBase(kgId,file));
+                return AjaxResult.success("标注数据导入成功!", kgService.importSchema(kgId, file));
+            } else {
+                return AjaxResult.error("文件不能为空");
+            }
+        } else {
+            return AjaxResult.error(1001, "参数不能为空");
+        }
+    }
     @ApiOperation("实例新增或更新")
     @PostMapping("/insOrUpdEnIce")
     public AjaxResult insOrUpdEnIce(@RequestBody SysEntityInstance sysEntityInstance){

+ 28 - 4
src/main/java/com/pavis/backend/slim/project/system/domain/EntityLabelsRelation.java

@@ -46,17 +46,41 @@ public class EntityLabelsRelation extends BaseEntity {
     private String fileId;
 
     /**
-     * start标注长度
+     * start标注长度ID
      */
-    @ApiModelProperty(value = "start标注长度,必填",required = true)
+    @ApiModelProperty(value = "start标注长度ID,必填",required = true)
     private String fromId;
 
     /**
-     * end标注长度
+     * start标注名称。
      */
-    @ApiModelProperty(value = "end标注长度,必填",required = true)
+    @ApiModelProperty(value = "start标注名称,必填",required = true)
+    private String fromName;
+
+    /**
+     * start标注类型。
+     */
+    @ApiModelProperty(value = "start标注类型,必填",required = true)
+    private String fromType;
+
+    /**
+     * end标注长度ID
+     */
+    @ApiModelProperty(value = "end标注长度ID,必填",required = true)
     private String toId;
 
+    /**
+     * end标注名称
+     */
+    @ApiModelProperty(value = "end标注名称,必填",required = true)
+    private String toName;
+
+    /**
+     * end标注类型
+     */
+    @ApiModelProperty(value = "end标注类型,必填",required = true)
+    private String toType;
+
     /**
      * 标注实体关系类型ID。
      */

+ 10 - 0
src/main/java/com/pavis/backend/slim/project/system/domain/SysKg.java

@@ -67,6 +67,8 @@ public class SysKg extends BaseEntity {
     @ApiModelProperty("生成图谱失败的原因")
     @TableField("generate_graph_reason")
     private String generateGraphReason;
+    @TableField("cancel_status")
+    private Integer cancelStatus;
 
 
     public String getKgId() {
@@ -149,6 +151,14 @@ public class SysKg extends BaseEntity {
         this.generateGraphReason = generateGraphReason;
     }
 
+    public Integer getCancelStatus() {
+        return cancelStatus;
+    }
+
+    public void setCancelStatus(Integer cancelStatus) {
+        this.cancelStatus = cancelStatus;
+    }
+
     @Override
     public String toString() {
         return "SysKg{" +

+ 2 - 0
src/main/java/com/pavis/backend/slim/project/system/domain/annotation/AnnotationEntity.java

@@ -49,4 +49,6 @@ public class AnnotationEntity {
     // 唯一标识ID。
     @ApiModelProperty("唯一标识ID")
     private String uuid;
+    // @ApiModelProperty("前端标注的实体数据")
+    // private String textFront;
 }

+ 12 - 0
src/main/java/com/pavis/backend/slim/project/system/domain/annotation/AnnotationEntityRelation.java

@@ -31,9 +31,19 @@ public class AnnotationEntityRelation {
     // 开始实体ID。
     @ApiModelProperty("开始实体ID")
     private String fromId;
+    // 开始实体ID。
+    @ApiModelProperty("开始实体名称")
+    private String fromName;
+    @ApiModelProperty(value = "start标注类型,必填",required = true)
+    private String fromType;
     // 结束实体ID。
     @ApiModelProperty("结束实体ID")
     private String toId;
+    // 结束实体ID。
+    @ApiModelProperty("结束实体名称")
+    private String toName;
+    @ApiModelProperty(value = "end标注类型,必填",required = true)
+    private String toType;
     // 标签实体关系的类型即id,如:13。
     @ApiModelProperty("标签实体关系的类型即id,如:13。")
     private String relationId;
@@ -49,4 +59,6 @@ public class AnnotationEntityRelation {
     // 唯一标识ID。
     @ApiModelProperty("唯一标识ID")
     private String uuid;
+    // @ApiModelProperty("前端标注的实体数据")
+    // private String textFront;
 }

+ 3 - 0
src/main/java/com/pavis/backend/slim/project/system/domain/annotation/ConvertDocToTxt.java

@@ -28,4 +28,7 @@ public class ConvertDocToTxt {
     // 文件md5值。
     @ApiModelProperty("文件md5值")
     private String identifier;
+
+    @ApiModelProperty("文件状态,true 新增 false 更新")
+    private Boolean isNew;
 }

+ 1 - 1
src/main/java/com/pavis/backend/slim/project/system/domain/annotation/ConvertDocToTxtAlg.java

@@ -12,7 +12,7 @@ import java.util.List;
 /**
  * @version: java version 1.8
  * @Author: Guan H.J.
- * @description: 文档数据发送给算法获取文档转换后的txt文本内容。
+ * @description: 文档数据发送给算法获取文档转换后的txt文本内容。---> todo 由于调整了N个版本,经讨论 此版本暂时弃用。
  * @date: 2023-11-01 14:04
  */
 @Builder

+ 3 - 9
src/main/java/com/pavis/backend/slim/project/system/domain/annotation/DelAnnotation.java

@@ -24,18 +24,12 @@ public class DelAnnotation {
     @ApiModelProperty("删除的标签类型,1 实体 0 关系")
     private String delType;
 
-    /**
-     * 图谱ID。
-     */
-    @ApiModelProperty(value = "图谱ID",required = true)
+    @ApiModelProperty(value = "图谱ID", required = true)
     private String kgId;
 
-    /**
-     * 文档ID。
-     */
-    @ApiModelProperty(value = "文档ID",required = true)
+    @ApiModelProperty(value = "文档ID", required = true)
     private String fileId;
 
-    @ApiModelProperty("图谱ID")
+    @ApiModelProperty("实体和实体关系主键ID")
     private List<String> ids;
 }

+ 31 - 0
src/main/java/com/pavis/backend/slim/project/system/domain/annotation/ExportAnnotationData.java

@@ -0,0 +1,31 @@
+package com.pavis.backend.slim.project.system.domain.annotation;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import lombok.experimental.SuperBuilder;
+
+import java.util.List;
+
+/**
+ * @version: java version 1.8
+ * @Author: Guan H.J.
+ * @description: 导出标注数据入参。
+ * @date: 2023-11-16 13:18
+ */
+@SuperBuilder
+@Getter
+@Setter
+@AllArgsConstructor
+@NoArgsConstructor
+public class ExportAnnotationData {
+    // 图谱ID。
+    @ApiModelProperty("图谱ID")
+    private String kgId;
+    // 该图谱下的所有文档ID列表。
+    @ApiModelProperty("该图谱下的所有待导出的文档ID列表")
+    private List<String> fileIds;
+
+}

+ 26 - 0
src/main/java/com/pavis/backend/slim/project/system/domain/annotation/ExportSchemaData.java

@@ -0,0 +1,26 @@
+package com.pavis.backend.slim.project.system.domain.annotation;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import lombok.experimental.SuperBuilder;
+
+/**
+ * @version: java version 1.8
+ * @Author: Guan H.J.
+ * @description: 前端导出图谱schema入参。
+ * @date: 2023-11-21 13:18
+ */
+@SuperBuilder
+@Getter
+@Setter
+@AllArgsConstructor
+@NoArgsConstructor
+public class ExportSchemaData {
+    // 图谱ID。
+    @ApiModelProperty("图谱ID")
+    private String kgId;
+
+}

+ 64 - 0
src/main/java/com/pavis/backend/slim/project/system/domain/annotation/ExportSysEntity.java

@@ -0,0 +1,64 @@
+package com.pavis.backend.slim.project.system.domain.annotation;
+
+import com.alibaba.fastjson2.JSONArray;
+import com.baomidou.mybatisplus.annotation.TableField;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+/**
+ * @version: java version 1.8
+ * @Author: Guan H.J.
+ * @description: 导出图谱schema数据。
+ * @date: 2023-11-23 14:04
+ */
+@Builder
+@Getter
+@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+public class ExportSysEntity {
+
+    private static final long serialVersionUID = 1L;
+    /**
+     * 主键id
+     */
+    @ApiModelProperty("主键id")
+    // @TableId(value = "entity_all_id",type = IdType.ASSIGN_UUID)
+    private String entityAllId;
+    /**
+     * 图谱ID
+     */
+    @ApiModelProperty("图谱ID")
+    private String kgId;
+    /**
+     * 图谱实体集合
+     */
+    @ApiModelProperty("图谱实体集合(不动)")
+    private JSONArray entityAll;
+    /**
+     * 图谱实体展示集合
+     */
+    @ApiModelProperty("图谱实体展示集合(修改)")
+    private JSONArray entityKgAll;
+    /**
+     * 实体关系集合
+     */
+    @ApiModelProperty("实体关系集合")
+    private JSONArray relationAll;
+    /**
+     * 实体关系展示集合
+     */
+    @ApiModelProperty("实体关系展示集合")
+    private JSONArray relationKgAll;
+
+    /**
+     * 实体id
+     */
+    @TableField(exist = false)
+    private String entityId;
+
+}

+ 1 - 1
src/main/java/com/pavis/backend/slim/project/system/domain/annotation/UniversalGgraphToAlg.java

@@ -12,7 +12,7 @@ import java.util.List;
 /**
  * @version: java version 1.8
  * @Author: Guan H.J.
- * @description:
+ * @description: 通用图谱数据入参。
  * @date: 2023-11-02 13:18
  */
 @SuperBuilder

+ 6 - 1
src/main/java/com/pavis/backend/slim/project/system/service/AnnotationListService.java

@@ -20,6 +20,7 @@ public interface AnnotationListService extends IService<AnnotationList> {
 
     /**
      * 获取数据标注列表页。
+     *
      * @param annotationListParam
      * @return
      */
@@ -27,6 +28,7 @@ public interface AnnotationListService extends IService<AnnotationList> {
 
     /**
      * 删除标注数据列表。
+     *
      * @param ids
      * @return
      */
@@ -34,6 +36,7 @@ public interface AnnotationListService extends IService<AnnotationList> {
 
     /**
      * 导入数据集接口。
+     *
      * @param importAnnotationDataset
      * @return
      */
@@ -41,13 +44,15 @@ public interface AnnotationListService extends IService<AnnotationList> {
 
     /**
      * 导入本地数据集接口。
+     *
      * @param file
      * @return
      */
-    Boolean importLocalAnnotationDataset(String kgId,MultipartFile file);
+    Boolean importLocalAnnotationDataset(String kgId, MultipartFile file);
 
     /**
      * 保存前端标注的实体数据html。
+     *
      * @param annotationFront
      * @return
      */

+ 43 - 0
src/main/java/com/pavis/backend/slim/project/system/service/EntityLablesRelationService.java

@@ -2,10 +2,18 @@ package com.pavis.backend.slim.project.system.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.pavis.backend.slim.project.system.domain.EntityLabelsRelation;
+import com.pavis.backend.slim.project.system.domain.annotation.AnnotationData;
 import com.pavis.backend.slim.project.system.domain.annotation.AnnotationEntityRelation;
 import com.pavis.backend.slim.project.system.domain.annotation.AnnotationToAlg;
+import com.pavis.backend.slim.project.system.domain.annotation.ConvertAlgRes;
+import com.pavis.backend.slim.project.system.domain.annotation.ExportAnnotationData;
 import com.pavis.backend.slim.project.system.domain.annotation.ToAnnotation;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
 import java.util.List;
 
 /**
@@ -17,6 +25,7 @@ import java.util.List;
 public interface EntityLablesRelationService extends IService<EntityLabelsRelation> {
     /**
      * 文档标注数据存储接口-实体关系。
+     *
      * @param relation
      * @return
      */
@@ -24,6 +33,7 @@ public interface EntityLablesRelationService extends IService<EntityLabelsRelati
 
     /**
      * 去标注页面,获取文本信息、知识库实体信息、知识库实体间关系信息、历史标注实体信息、历史标注实体间关系信息。
+     *
      * @param kgId
      * @param fileId
      * @return
@@ -32,12 +42,14 @@ public interface EntityLablesRelationService extends IService<EntityLabelsRelati
 
     /**
      * 根据图谱id和文档id获取历史标注实体关系信息数据列表。
+     *
      * @return
      */
     List<AnnotationEntityRelation> getAnnotationEntityRelationByKgIdAndFileId(String kgId, String fileId);
 
     /**
      * 生成图谱,根据kgId获取text、标注实体数据列表、标注实体关系数据列表等数据给算法。
+     *
      * @param kgId
      * @return
      */
@@ -45,8 +57,39 @@ public interface EntityLablesRelationService extends IService<EntityLabelsRelati
 
     /**
      * 根据主键ID删除该标注数据关系。
+     *
      * @param id
      * @return
      */
     Boolean delRelById(Long id);
+
+    /**
+     * 根据图谱ID、文档ID获取标注数据。
+     *
+     * @param fileIds
+     * @param kgId
+     * @return
+     */
+    List<AnnotationData> getAnnotationDatas(List<String> fileIds, String kgId);
+
+    /**
+     * 标注数据导出。
+     */
+    void exportDataBase(ExportAnnotationData exportAnnotationData, HttpServletRequest request, HttpServletResponse response) throws IOException;
+
+    /**
+     * 标注数据导入。
+     *
+     * @param kgId
+     * @param file
+     * @return
+     */
+    Boolean importDataBase(String kgId, MultipartFile file);
+
+    /**
+     * 算法通知后端更新文本内容。
+     *
+     * @param convertAlgRes
+     */
+    void toUpText(@RequestBody ConvertAlgRes convertAlgRes);
 }

+ 4 - 1
src/main/java/com/pavis/backend/slim/project/system/service/EntityLablesSpanService.java

@@ -17,6 +17,7 @@ public interface EntityLablesSpanService extends IService<EntityLabelsSpan> {
 
     /**
      * 文档标注数据存储接口-实体。
+     *
      * @param entity
      * @return
      */
@@ -24,12 +25,14 @@ public interface EntityLablesSpanService extends IService<EntityLabelsSpan> {
 
     /**
      * 根据图谱id和文档id获取历史标注实体信息数据列表。
+     *
      * @return
      */
-    List<AnnotationEntity> getAnnotationEntityByKgIdAndFileId(String kgId,String fileId);
+    List<AnnotationEntity> getAnnotationEntityByKgIdAndFileId(String kgId, String fileId);
 
     /**
      * 删除标注的实体/实体关系数据。
+     *
      * @param delAnnotation
      * @return
      */

+ 11 - 1
src/main/java/com/pavis/backend/slim/project/system/service/GenerateGraphService.java

@@ -14,15 +14,25 @@ import org.springframework.web.bind.annotation.RequestBody;
 public interface GenerateGraphService extends IService<GenerateGraph> {
     /**
      * 算法通知后端更新生成图谱结果接口。
+     *
      * @param genGraphResult
      */
     void generateKgGraphResult(@RequestBody GenerateGraphResult genGraphResult);
 
     /**
      * 生成一条生成图谱的结果记录。
+     *
      * @param taskId
      * @param kgId
      * @return
      */
-    Boolean createGenerateKgGraphResult(String taskId,String kgId,Boolean isGenerate);
+    Boolean createGenerateKgGraphResult(String taskId, String kgId, Boolean isGenerate);
+
+    /**
+     * 前端传入知识库id,后端调用算法停止生成图谱。 后端请求算法--->入参taskId。
+     *
+     * @param kgId
+     * @return
+     */
+    Boolean stopGraphByTaskId(String kgId);
 }

+ 11 - 2
src/main/java/com/pavis/backend/slim/project/system/service/SysFileService.java

@@ -98,6 +98,7 @@ public interface SysFileService extends IService<SysFile> {
 
     /**
      * 根据文档id,获取文档的文本内容。
+     *
      * @param fileId
      * @return
      */
@@ -106,10 +107,11 @@ public interface SysFileService extends IService<SysFile> {
     /**
      * 文档转换成txt:调用算法文档转换txt接口,并保存文本内容。
      */
-    void convertToTxt(List<String> fileIds);
+    void convertToTxt(List<String> fileIds, Boolean isNew);
 
     /**
      * 通用解析算法返回值,即文档转txt。
+     *
      * @param convertToTxtResTmp
      */
     void dealAlgTxtRes(String convertToTxtResTmp);
@@ -117,5 +119,12 @@ public interface SysFileService extends IService<SysFile> {
     /**
      * 知识库上传文档时,调用算法去解析文档内容为txt。
      */
-    void convertfileToTxtByAlg(SysFile sysFile);
+    void convertfileToTxtByAlg(SysFile sysFile, Boolean isNew);
+
+    /**
+     * 根据文件id更新text解析内容。
+     *
+     * @param fileId
+     */
+    void upFileTextContentByFileId(String fileId, String textContent);
 }

+ 55 - 3
src/main/java/com/pavis/backend/slim/project/system/service/SysKgService.java

@@ -8,11 +8,16 @@ import com.pavis.backend.slim.project.system.domain.SysEntityInstance;
 import com.pavis.backend.slim.project.system.domain.SysEntityRelation;
 import com.pavis.backend.slim.project.system.domain.SysKg;
 import com.pavis.backend.slim.project.system.domain.algorithm.AlgSpO;
+import com.pavis.backend.slim.project.system.domain.annotation.ExportSchemaData;
 import com.pavis.backend.slim.project.system.domain.front.ClutterReturn;
 import com.pavis.backend.slim.project.system.domain.front.FileKey;
 import com.pavis.backend.slim.project.system.domain.front.InKgParameter;
 import com.pavis.backend.slim.project.system.domain.front.KgReturn;
+import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
 import java.util.List;
 
 /**
@@ -31,13 +36,15 @@ public interface SysKgService extends IService<SysKg> {
 
     /**
      * 图谱列表
+     *
      * @param
-     * @return  返回图谱list
+     * @return 返回图谱list
      */
     List<SysKg> list(SysKg kg);
 
     /**
      * 所有知识库的树结构
+     *
      * @return
      */
     List listKg();
@@ -46,12 +53,14 @@ public interface SysKgService extends IService<SysKg> {
 
     /**
      * 删除图谱,可批量
+     *
      * @param list
      */
-    Integer delectKg(List<String>list);
+    Integer delectKg(List<String> list);
 
     /**
      * 返回图谱数据结构
+     *
      * @param kgId
      * @return
      */
@@ -59,6 +68,7 @@ public interface SysKgService extends IService<SysKg> {
 
     /**
      * 实体,实体关系创建接口
+     *
      * @param inKgParameter 前端传参数据
      * @return 前端所需要的返参数据
      */
@@ -66,6 +76,7 @@ public interface SysKgService extends IService<SysKg> {
 
     /**
      * 实体,实体关系创建时,将前端所有数据纹丝不动的全部保存到数据库中 -->sys_entity_all
+     *
      * @param sysEntityAll 前端传参数据
      * @return 前端所需要的返参数据
      */
@@ -74,6 +85,7 @@ public interface SysKgService extends IService<SysKg> {
 
     /**
      * 查询实体,实体关系数据,数据库中表 -->sys_entity_all
+     *
      * @param kgId 图谱id
      * @return 实体实例关系的数据集合
      */
@@ -82,6 +94,7 @@ public interface SysKgService extends IService<SysKg> {
 
     /**
      * 实例新增或更新接口
+     *
      * @param sysEntityInstance 实例详情
      * @return 实例详情
      */
@@ -89,12 +102,14 @@ public interface SysKgService extends IService<SysKg> {
 
     /**
      * 删除实例 -->可单个删除,也可多个删除
+     *
      * @param entityNceList 实例主键的id集合
      */
     void delEntNce(List<String> entityNceList);
 
     /**
      * 查询实例集合
+     *
      * @param keyEntityNce 公共查询类
      * @return 实例列表
      */
@@ -102,6 +117,7 @@ public interface SysKgService extends IService<SysKg> {
 
     /**
      * 查询实例集合
+     *
      * @param keyEntityRelation 公共查询类
      * @return 实例列表
      */
@@ -109,6 +125,7 @@ public interface SysKgService extends IService<SysKg> {
 
     /**
      * 根据kgId获取文档列表。
+     *
      * @param kgId
      * @return
      */
@@ -116,22 +133,53 @@ public interface SysKgService extends IService<SysKg> {
 
     /**
      * 根据kgId更新解析、训练、抽取状态。
+     *
      * @param kgId
      * @param finalStatus
      * @param finalReason
      * @return
      */
-    Boolean updateGrapgStatus(String kgId,Integer graphStatus,Integer annotationStatus,Integer finalStatus,String finalReason);
+    Boolean updateGrapgStatus(String kgId, Integer graphStatus, Integer annotationStatus, Integer finalStatus, String finalReason);
 
     /**
      * 图谱更新
+     *
      * @param sysKg 图谱详情
      * @return 图谱详情
      */
     SysKg updateKg(SysKg sysKg);
 
+    /**
+     * 停止生成图谱状态更新。
+     *
+     * @param kgId
+     * @return
+     */
+    Boolean stopGraph(String kgId);
+
+    /**
+     * 导出图谱schema。
+     *
+     * @param exportSchemaData
+     * @param request
+     * @param response
+     * @throws IOException
+     */
+    void exportSchema(ExportSchemaData exportSchemaData, HttpServletRequest request, HttpServletResponse response) throws IOException;
+
+    /**
+     * 导入图谱schema。
+     *
+     * @param kgId
+     * @param file
+     * @return
+     * @throws IOException
+     */
+    SysEntityAll importSchema(String kgId, MultipartFile file) throws IOException;
+
     /**
      * 实例新增或更新
+     *
      * @param sysEntityInstance
      * @return
      */
@@ -139,6 +187,7 @@ public interface SysKgService extends IService<SysKg> {
 
     /**
      * 实例新增或更新
+     *
      * @param fileKey
      * @return
      */
@@ -146,12 +195,14 @@ public interface SysKgService extends IService<SysKg> {
 
     /**
      * 删除实例关系
+     *
      * @param fileKey
      */
     void delEntRlation(FileKey fileKey);
 
     /**
      * 查询实体关系下的实例关系
+     *
      * @param fileKey
      * @return
      */
@@ -159,6 +210,7 @@ public interface SysKgService extends IService<SysKg> {
 
     /**
      * 新增或更新实例关系
+     *
      * @param sysEntityRelation
      */
     void insOrUpdRelation(SysEntityRelation sysEntityRelation);

+ 33 - 49
src/main/java/com/pavis/backend/slim/project/system/service/impl/AnnotationListServiceImpl.java

@@ -19,6 +19,7 @@ import com.pavis.backend.slim.project.system.domain.annotation.ImportAnnotationD
 import com.pavis.backend.slim.project.system.domain.annotation.ImportDataset;
 import com.pavis.backend.slim.project.system.mapper.AnnotationListMapper;
 import com.pavis.backend.slim.project.system.service.AnnotationListService;
+import com.pavis.backend.slim.project.system.service.SysFileService;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.commons.lang3.StringUtils;
@@ -46,15 +47,19 @@ public class AnnotationListServiceImpl extends ServiceImpl<AnnotationListMapper,
     @Autowired
     private AlgKgClient algKgClient;
 
+    @Autowired
+    private SysFileService sysFileService;
+
     @Override
     public PageInfo getAnnotationLists(AnnotationListParam annotationListParam) {
         List<AnnotationList> annotationLists = baseMapper.selectAnnotationList(annotationListParam);
         // 获取txt文本内容为空,向算法请求txt文本内容并更新。
         if (!CollectionUtils.isEmpty(annotationLists)) {
-            // 过滤出textContent为空的数据。
+            // 过滤出textContent为空的数据,调用算法获取textContent的值
             toAlgTxt(annotationLists);
             annotationLists = baseMapper.selectAnnotationList(annotationListParam);
         }
+        log.info("annotationLists:{}", annotationLists.size());
         PageHelper.startPage(annotationListParam.getPageNum(), annotationListParam.getPageSize());
         PageInfo page = new PageInfo(annotationLists);
         return page;
@@ -80,7 +85,9 @@ public class AnnotationListServiceImpl extends ServiceImpl<AnnotationListMapper,
             if (1 == importAnnotationDataset.getImportType()) {
                 annotationList.setParseStatus(1);
                 annotationList.setAnnotationStatus(0);
-                // 判重处理。
+                // annotationList.setCreateTime(DateUtil.date());
+                annotationList.setCreateBy(SecurityUtils.getUsername());
+                // 判重处理。todo 经讨论,暂时不需要判重。
                 // List<AnnotationList> annotations = baseMapper.selectList(new QueryWrapper<AnnotationList>().lambda().eq(AnnotationList::getKgId, importAnnotationDataset.getKgId())
                 //         .eq(AnnotationList::getFileId, importDataset.getFileId()));
                 // if (!CollectionUtils.isEmpty(annotations)){
@@ -127,9 +134,7 @@ public class AnnotationListServiceImpl extends ServiceImpl<AnnotationListMapper,
         // 设置基本信息,创建人、创建时间等。
         // annotationList.setUserId(SecurityUtils.getUserId());
         annotationList.setCreateBy(SecurityUtils.getUsername());
-        annotationList.setCreateTime(DateUtil.date());
         annotationList.setUpdateBy(SecurityUtils.getUsername());
-        annotationList.setUpdateTime(DateUtil.date());
         Map<String, Object> algMap = new HashMap<>();
         algMap.put("file", file);
         algMap.put("fileId", annotationList.getFileId());
@@ -139,7 +144,7 @@ public class AnnotationListServiceImpl extends ServiceImpl<AnnotationListMapper,
         List<AnnotationList> annotationLists = new ArrayList<>();
         annotationLists.add(annotationList);
         try {
-            dealAlgToTxtRes(algTxtByFile.toString(), annotationLists, false);
+            dealAlgToTxtRes(algTxtByFile, annotationLists, false);
             return true;
         } catch (Exception ex) {
             log.info("算法本地文件转txt异常 ex:{}", ex);
@@ -150,7 +155,7 @@ public class AnnotationListServiceImpl extends ServiceImpl<AnnotationListMapper,
     @Override
     public Boolean saveAnnotation(AnnotationFront annotationFront) {
         List<AnnotationList> annotationLists = baseMapper.selectList(new QueryWrapper<AnnotationList>().lambda().eq(AnnotationList::getKgId, annotationFront.getKgId()).eq(AnnotationList::getFileId, annotationFront.getFileId()));
-        if(annotationLists.size() > 0){
+        if (annotationLists.size() > 0) {
             for (AnnotationList annotationList : annotationLists) {
                 annotationList.setTextFront(annotationFront.getTextFront());
                 int upRes = baseMapper.updateById(annotationList);
@@ -169,21 +174,23 @@ public class AnnotationListServiceImpl extends ServiceImpl<AnnotationListMapper,
         List<AnnotationList> hasNullTexts = annotationLists.stream().filter(wmy -> null == wmy.getTextContent()).collect(Collectors.toList());
         log.info("hasNullTexts:{}", hasNullTexts.size());
         List<String> fileIds = hasNullTexts.stream().map(wmy -> wmy.getFileId()).collect(Collectors.toList());
-        // 调用算法获取txt文本内容。
-        Map<String, Object> algMap = new HashMap<>();
-        algMap.put("fileIds", fileIds);
-        log.info("algMap:{}", JSON.toJSONString(algMap));
-        String algTxtTmp = algKgClient.getAlgTxt(JSON.toJSONString(algMap));
-        dealAlgToTxtRes(algTxtTmp, hasNullTexts, true);
-        log.info("实时调用算法获取txt文本内容结束");
+        if (!CollectionUtils.isEmpty(fileIds)) {
+            // 调用算法获取txt文本内容。
+            Map<String, Object> algMap = new HashMap<>();
+            algMap.put("fileIds", fileIds);
+            log.info("algMap:{}", JSON.toJSONString(algMap));
+            JSONArray algTxtTmp = algKgClient.getAlgTxt(JSON.toJSONString(algMap));
+            dealAlgToTxtRes(algTxtTmp, hasNullTexts, true);
+            log.info("实时调用算法获取txt文本内容结束");
+        }
     }
 
-    public void dealAlgToTxtRes(String algTxtTmp, List<AnnotationList> hasNullTexts, Boolean upFlag) {
-        if (null != algTxtTmp && StringUtils.isNotEmpty(algTxtTmp) && CommonUtils.isJsonArray(algTxtTmp)) {
+    public void dealAlgToTxtRes(JSONArray algTxtTmp, List<AnnotationList> hasNullTexts, Boolean upFlag) {
+        if (null != algTxtTmp && StringUtils.isNotEmpty(JSON.toJSONString(algTxtTmp)) && CommonUtils.isJsonArray(JSON.toJSONString(algTxtTmp))) {
             // 解析算法返回数据。
             try {
-                List<ConvertAlgRes> convertAlgRes = JSONArray.parseArray(algTxtTmp, ConvertAlgRes.class);
-                log.info("解析算法返回数据convertAlgRes:{}",JSON.toJSONString(convertAlgRes));
+                List<ConvertAlgRes> convertAlgRes = JSONArray.parseArray(algTxtTmp.toString(), ConvertAlgRes.class);
+                log.info("解析算法返回数据convertAlgRes:{}", JSON.toJSONString(convertAlgRes));
                 if (!CollectionUtils.isEmpty(convertAlgRes)) {
                     for (ConvertAlgRes algRes : convertAlgRes) {
                         if (null != algRes.getErrorCode() && "0".equals(algRes.getErrorCode())) {
@@ -197,10 +204,16 @@ public class AnnotationListServiceImpl extends ServiceImpl<AnnotationListMapper,
                                         // true 更新textContent.
                                         int updateText = baseMapper.updateById(hasNullText);
                                         log.info("更新文本内容结果updateText:{}", updateText);
+                                        // 更新sysfile的textcontent值。
+                                        sysFileService.upFileTextContentByFileId(hasNullText.getFileId(), algRes.getText());
                                     } else {
                                         // false 新增textContent
+                                        hasNullText.setParseStatus(1);
+                                        hasNullText.setCreateBy(SecurityUtils.getUsername());
                                         int saveRes = baseMapper.insert(hasNullText);
                                         log.info("新增文本内容结果updateText:{}", saveRes);
+                                        // 更新sysfile的textcontent值。
+                                        sysFileService.upFileTextContentByFileId(hasNullText.getFileId(), algRes.getText());
                                     }
                                 }
                             }
@@ -208,9 +221,11 @@ public class AnnotationListServiceImpl extends ServiceImpl<AnnotationListMapper,
                             if (null != algRes.getErrorCode() && "-1".equals(algRes.getErrorCode()) && false == upFlag) {
                                 for (AnnotationList hasNullText : hasNullTexts) {
                                     hasNullText.setParseStatus(-1);
-                                    // hasNullText.setUserId(SecurityUtils.getUserId());
+                                    hasNullText.setCreateBy(SecurityUtils.getUsername());
                                     int saveRes = baseMapper.insert(hasNullText);
                                     log.info("解析出错 新增文本内容结果updateText:{}", saveRes);
+                                    // 更新sysfile的textcontent值。
+                                    sysFileService.upFileTextContentByFileId(hasNullText.getFileId(), algRes.getText());
                                 }
                             }
                             log.info("获取算法解析txt文本内容返回结果 TXT未解析成功:{}", JSON.toJSONString(algRes));
@@ -227,35 +242,4 @@ public class AnnotationListServiceImpl extends ServiceImpl<AnnotationListMapper,
         }
     }
 
-    public void dealAlgToTxtResByLocal(String algTxtTmp, AnnotationList annotationList) {
-        if (null != algTxtTmp && StringUtils.isNotEmpty(algTxtTmp) && CommonUtils.isJsonArray(algTxtTmp)) {
-            // 解析算法返回数据。
-            try {
-                List<ConvertAlgRes> convertAlgRes = JSONArray.parseArray(algTxtTmp, ConvertAlgRes.class);
-                if (!CollectionUtils.isEmpty(convertAlgRes)) {
-                    for (ConvertAlgRes algRes : convertAlgRes) {
-                        if (null != algRes.getErrorCode() && "0".equals(algRes.getErrorCode())) {
-                            // 调用算法接口成功,并且解析txt文件成功,将文本内容更新至sysFile的textContent字段中。
-
-                            // for (AnnotationList hasNullText : hasNullTexts) {
-                            //     if (algRes.getFileId().equals(hasNullText.getFileId())) {
-                            //         hasNullText.setTextContent(algRes.getText());
-                            //         int updateText = baseMapper.updateById(hasNullText);
-                            //         log.info("更新文本内容结果updateText:{}", updateText);
-                            //     }
-                            // }
-                        } else {
-                            log.info("获取算法解析txt文本内容返回结果 TXT未解析成功:{}", JSON.toJSONString(algRes));
-                        }
-                    }
-                } else {
-                    log.info("获取算法解析txt文本内容返回结果 返回数据为NULL ex convertAlgRes:{}", JSON.toJSONString(convertAlgRes));
-                }
-            } catch (Exception ex) {
-                log.info("获取算法解析txt文本内容返回结果 返回数据异常 NOT JSONArray ex:{}", JSON.toJSONString(algTxtTmp));
-            }
-        } else {
-            log.info("获取算法解析txt文本内容返回结果接口异常 ex convertToTxtResTmp:{}", algTxtTmp);
-        }
-    }
 }

+ 200 - 33
src/main/java/com/pavis/backend/slim/project/system/service/impl/EntityLabelsRelationServiceImpl.java

@@ -1,27 +1,33 @@
 package com.pavis.backend.slim.project.system.service.impl;
 
-import cn.hutool.core.date.DateUtil;
 import com.alibaba.fastjson2.JSON;
 import com.alibaba.fastjson2.JSONArray;
 import com.alibaba.fastjson2.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.pavis.backend.slim.common.utils.CommonUtils;
+import com.pavis.backend.slim.common.utils.FileUtils;
 import com.pavis.backend.slim.common.utils.SecurityUtils;
 import com.pavis.backend.slim.project.system.client.AlgKgClient;
+import com.pavis.backend.slim.project.system.domain.AnnotationList;
 import com.pavis.backend.slim.project.system.domain.EntityForAlg;
 import com.pavis.backend.slim.project.system.domain.EntityLabelsRelation;
+import com.pavis.backend.slim.project.system.domain.EntityLabelsSpan;
 import com.pavis.backend.slim.project.system.domain.SysEntity;
 import com.pavis.backend.slim.project.system.domain.SysRelation;
 import com.pavis.backend.slim.project.system.domain.annotation.AnnotationData;
 import com.pavis.backend.slim.project.system.domain.annotation.AnnotationEntity;
 import com.pavis.backend.slim.project.system.domain.annotation.AnnotationEntityRelation;
 import com.pavis.backend.slim.project.system.domain.annotation.AnnotationToAlg;
+import com.pavis.backend.slim.project.system.domain.annotation.ConvertAlgRes;
+import com.pavis.backend.slim.project.system.domain.annotation.ExportAnnotationData;
 import com.pavis.backend.slim.project.system.domain.annotation.RelationForAlg;
 import com.pavis.backend.slim.project.system.domain.annotation.SchemaImport;
 import com.pavis.backend.slim.project.system.domain.annotation.ToAnnotation;
 import com.pavis.backend.slim.project.system.domain.annotation.UniversalGgraphToAlg;
+import com.pavis.backend.slim.project.system.mapper.AnnotationListMapper;
 import com.pavis.backend.slim.project.system.mapper.EntityLabelsRelationMapper;
+import com.pavis.backend.slim.project.system.service.AnnotationListService;
 import com.pavis.backend.slim.project.system.service.EntityLablesRelationService;
 import com.pavis.backend.slim.project.system.service.EntityLablesSpanService;
 import com.pavis.backend.slim.project.system.service.GenerateGraphService;
@@ -33,11 +39,18 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
+import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.File;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * @version: java version 1.8
@@ -70,28 +83,48 @@ public class EntityLabelsRelationServiceImpl extends ServiceImpl<EntityLabelsRel
     @Autowired
     private GenerateGraphService generateGraphService;
 
+    @Autowired
+    private AnnotationListMapper annotationListMapper;
+
+    @Value("${pavis.profile}")
+    private String filePath;
+
+    @Autowired
+    private AnnotationListService annotationListService;
+
     @Override
     public EntityLabelsRelation saveAnnotationRelation(AnnotationEntityRelation relation) {
+        log.info("新增关系数据:{}", JSON.toJSONString(relation));
         EntityLabelsRelation entityLabelsRelation = new EntityLabelsRelation();
         BeanUtils.copyProperties(relation, entityLabelsRelation);
         // 设置基本信息,创建人、创建时间等。
         entityLabelsRelation.setUserId(SecurityUtils.getUserId());
         entityLabelsRelation.setCreateBy(SecurityUtils.getUsername());
-        entityLabelsRelation.setCreateTime(DateUtil.date());
-        int insert = baseMapper.insert(entityLabelsRelation);
-        log.info("标注的实体信息存储结果res:{},entityLabelsRelation:{}", insert, JSON.toJSONString(entityLabelsRelation));
+        // 新增。
+        // int insertRes = baseMapper.insert(entityLabelsRelation);
+        // log.info("标注的实体信息存储结果res:{},entityLabelsRelation:{}", insertRes, JSON.toJSONString(entityLabelsRelation));
+        // 存在id更新,无id新增。todo 家辉需要调整,才修改逻辑的。
+        boolean modRes = saveOrUpdate(entityLabelsRelation);
+        log.info("标注的实体信息存储结果res:{},entityLabelsRelation:{}", modRes, JSON.toJSONString(entityLabelsRelation));
+        // // 更新标注数据。todo 前端反馈暂时先不在此处加逻辑了。
+        // log.info("结束更新前端标注textFront数据");
+        // AnnotationFront annotationFront = AnnotationFront.builder().kgId(relation.getKgId()).fileId(relation.getFileId()).textFront(relation.getTextFront()).build();
+        // log.info("关系:{}",JSON.toJSONString(annotationFront));
+        // Boolean upAnnotation = annotationListService.saveAnnotation(annotationFront);
+        // log.info("结束更新前端标注textFront数据 upAnnotation:{}",upAnnotation);
         return entityLabelsRelation;
     }
 
     @Override
     public ToAnnotation toAnnotation(String kgId, String fileId) {
-
         // 1.根据fileId获取文本信息text、历史标注的实体信息列表、历史标注的实体间关系信息列表。
         // List<TreeFile> treeFiles = sysFileService.listTreeFiles(kgId);
         // log.info("获取知识库下的文档信息treeFiles:{}",JSON.toJSONString(treeFiles));
-        String fileTextContent = sysFileService.getFileTextContent(fileId);
-        if (null != fileTextContent && StringUtils.isNotBlank(fileTextContent)) {
-            log.info("文本内容不为空:{}", fileTextContent);
+        // String fileTextContent = sysFileService.getFileTextContent(fileId);
+        List<AnnotationList> annotationLists = annotationListMapper.selectList(new QueryWrapper<AnnotationList>().lambda().eq(AnnotationList::getKgId, kgId).eq(AnnotationList::getFileId, fileId));
+        // log.info("fileTextContent:{}",fileTextContent);
+        if (!CollectionUtils.isEmpty(annotationLists) && null != annotationLists.get(0).getTextContent() && StringUtils.isNotBlank(annotationLists.get(0).getTextContent())) {
+            // log.info("文本内容不为空:{}", annotationLists.get(0).getTextContent());
             // 1.1 获取历史标注实体信息数据列表。
             List<AnnotationEntity> entities = entityLablesSpanService.getAnnotationEntityByKgIdAndFileId(kgId, fileId);
             // 1.2 获取历史标注实体间关系数据列表。
@@ -101,11 +134,11 @@ public class EntityLabelsRelationServiceImpl extends ServiceImpl<EntityLabelsRel
             List<SysEntity> entityLists = sysEntityService.getEntityByKgId(kgId);
             // 3.根据kgId获取知识库下的所有实体间关系信息列表。
             List<SysRelation> relationLists = sysRelationService.getRelationByKgId(kgId);
-            ToAnnotation toAnnotation = ToAnnotation.builder().text(fileTextContent).entities(entities).relations(relations)
+            ToAnnotation toAnnotation = ToAnnotation.builder().text(annotationLists.get(0).getTextContent()).textFront(annotationLists.get(0).getTextFront()).entities(entities).relations(relations)
                     .entityList(entityLists).relationList(relationLists).build();
             return toAnnotation;
         }
-        return null;
+        return new ToAnnotation();
     }
 
     @Override
@@ -118,7 +151,8 @@ public class EntityLabelsRelationServiceImpl extends ServiceImpl<EntityLabelsRel
             annotationEntityRelation = new AnnotationEntityRelation();
             BeanUtils.copyProperties(entityLabelsRelation, annotationEntityRelation);
             annotationEntityRelation.setId(Long.valueOf(entityLabelsRelation.getId()));
-            // 处理个别字段,fileId是string类型的。
+            annotationEntityRelation.setFromId(entityLabelsRelation.getFromId());
+            annotationEntityRelation.setToId(entityLabelsRelation.getToId());
             annotationEntityRelations.add(annotationEntityRelation);
         }
         return annotationEntityRelations;
@@ -133,7 +167,6 @@ public class EntityLabelsRelationServiceImpl extends ServiceImpl<EntityLabelsRel
         // 2. 判断该图谱是否创建实体和关系数据。即是否有图schema.
         if (CollectionUtils.isEmpty(selEntityByKgId)) {
             // 2.1 如果该图谱的未创建实体和关系数据,则调用算法另一个服务,入参为:fileIds列表、kgId。
-            // String universalGgraphToAlgRes = "";
             try {
                 // todo 临时弃用,改用下面的接口,直接调用获取taskId。
                 // universalGgraphToAlgRes = algKgClient.universalGgraphToAlg(JSON.toJSONString(universalGgraphToAlg));
@@ -142,7 +175,7 @@ public class EntityLabelsRelationServiceImpl extends ServiceImpl<EntityLabelsRel
                 // todo 直接调用算法获取taskId,type=true。返回json{"taskId":""}。生成一条记录。
                 log.info("生成图谱接口 ---->无图schema 通用图谱调用中...");
                 UniversalGgraphToAlg universalGgraphToAlg = UniversalGgraphToAlg.builder().kgId(kgId).fileIds(fileIds).taskType(true).build();
-                String getTaskIdRes = algKgClient.afterSendAnnotationToGetTaskId(JSON.toJSONString(universalGgraphToAlg));
+                String getTaskIdRes = algKgClient.afterSendAnnotationToGetTaskId(universalGgraphToAlg);
                 createGenerateGraph(getTaskIdRes, kgId, true, 0, 0);
             } catch (Exception ex) {
                 ex.printStackTrace();
@@ -153,33 +186,39 @@ public class EntityLabelsRelationServiceImpl extends ServiceImpl<EntityLabelsRel
             log.info("生成图谱接口 ---->有图schema 判断是否存在标注数据...");
             // 2.2 用户在图模型创建了实体和关系,即存在图schema数据。先请求schema/import,返回OK,再判断是否有标注数据。
             List<EntityForAlg> entityForAlgs = JSONArray.parseArray(selEntityByKgId.get(0).getEntityAll(), EntityForAlg.class);
-            log.info("有图schema的实体信息:{}",JSON.toJSONString(entityForAlgs));
+            log.info("有图schema的实体信息:{}", JSON.toJSONString(entityForAlgs));
             String relationAll = selEntityByKgId.get(0).getRelationAll();
             List<RelationForAlg> relationForAlgs = JSONArray.parseArray(relationAll, RelationForAlg.class);
-            log.info("有图schema的实体间关系信息:{}",JSON.toJSONString(relationForAlgs));
+            log.info("有图schema的实体间关系信息:{}", JSON.toJSONString(relationForAlgs));
             SchemaImport schemaImport = SchemaImport.builder().kgId(kgId).entityList(entityForAlgs).relationList(relationForAlgs).build();
-            log.info("调用算法服务的schemaImport服务发送实体和关系属性数据:{}",JSON.toJSONString(schemaImport));
-            String schemaImportRes = algKgClient.sendEntityRelationToAlg(JSON.toJSONString(schemaImport));
-            log.info("调用算法服务的schemaImport服务发送实体和关系属性数据结果 schemaImportRes:{}",JSON.toJSONString(schemaImportRes));
-            if ("ok".equals(schemaImportRes)){
+            log.info("调用算法服务的schemaImport服务发送实体和关系属性数据:{}", JSON.toJSONString(schemaImport));
+            String schemaImportRes = algKgClient.sendEntityRelationToAlg(schemaImport);
+            log.info("调用算法服务的schemaImport服务发送实体和关系属性数据结果 schemaImportRes:{}", JSON.toJSONString(schemaImportRes));
+            if ("ok".equals(schemaImportRes)) {
                 // 2.2 todo 当前版本已弃用: 如果该图谱的创建了实体和关系数据,则调用算法的生成图谱服务,即入参为:text、实体标注数据列表、实体关系标注数据列表。
                 // 获取标注数据: 如果图谱有实体关系数据,且标注了数据,则发送标注的数据给算法;如果该文档未被标注则不发送。如果仅有实体关系数据,所有文档均未被标注,也发送,只不过标注数据为空。
-                List<AnnotationData> annotationDatas = getAnnotationDatas(fileIds,kgId);
+                List<AnnotationData> annotationDatas = getAnnotationDatas(fileIds, kgId);
                 // 3.判断是否存在标注数据:有标注数据:请求labels/import,返回OK,继续调用获取taskId;
                 AnnotationToAlg annotationToAlg = AnnotationToAlg.builder().kgId(kgId).annotationDatas(annotationDatas).build();// 算法所需数据结构。
+                log.info("is json annotationToAlg:{}", CommonUtils.isJson(JSON.toJSONString(annotationToAlg)));
                 log.info("标注数据待发送至算法数据结构annotationToAlg:{}", JSON.toJSONString(annotationToAlg));
+                log.info("----------------------------------------------------");
                 if (!CollectionUtils.isEmpty(annotationDatas) && annotationDatas.get(0).getEntities().size() > 0) {
                     log.info("有图schema 有标注数据");
                     // 3.1 有标注数据:请求/labels/import,返回OK,继续调用/graph/create_graph获取taskId;
                     // todo 3.1.1 发送数据给算法。
                     String algRes = null;
                     try {
-                        algRes = algKgClient.sendToAlgForGenerateKgGraph(JSON.toJSONString(annotationToAlg));
+                        // algRes = algKgClient.sendToAlgForGenerateKgGraph(JSON.toJSONString(annotationToAlg));
+                        log.info("调用算法标注服务前入参:{}", JSONArray.toJSONString(annotationToAlg));
+                        // algRes = algKgClient.sendToAlgForGenerateKgGraph(JSONArray.toJSONString(annotationToAlg));
+                        algRes = algKgClient.sendToAlgForGenerateKgGraph(annotationToAlg);
+
                         log.info("该图谱存在实体关系数据时发送标注数据列表,调用算法生成知识图谱接口返回algRes:{}", algRes);
                         if (null != algRes && "ok".equals(algRes)) {
                             // todo 调用算法获取taskId,type=false。返回json{"taskId":""}。生成一条记录。状态为200.才调用。
                             UniversalGgraphToAlg universalGgraphToAlg = UniversalGgraphToAlg.builder().kgId(kgId).fileIds(fileIds).taskType(false).build();
-                            String getTaskIdRes = algKgClient.afterSendAnnotationToGetTaskId(JSON.toJSONString(universalGgraphToAlg));
+                            String getTaskIdRes = algKgClient.afterSendAnnotationToGetTaskId(universalGgraphToAlg);
                             createGenerateGraph(getTaskIdRes, kgId, false, 1, annotationDatas.size() > 0 ? 1 : 0);
                         }
                     } catch (Exception ex) {
@@ -190,7 +229,7 @@ public class EntityLabelsRelationServiceImpl extends ServiceImpl<EntityLabelsRel
                     // 3.2 无标注数据:请求graph/create_graph获取taskId。
                     log.info("有图schema 但无标注数据");
                     UniversalGgraphToAlg universalGgraphToAlg = UniversalGgraphToAlg.builder().kgId(kgId).fileIds(fileIds).taskType(false).build();
-                    String getTaskIdRes = algKgClient.afterSendAnnotationToGetTaskId(JSON.toJSONString(universalGgraphToAlg));
+                    String getTaskIdRes = algKgClient.afterSendAnnotationToGetTaskId(universalGgraphToAlg);
                     createGenerateGraph(getTaskIdRes, kgId, false, 0, 0);
                 }
                 return annotationToAlg;
@@ -199,17 +238,31 @@ public class EntityLabelsRelationServiceImpl extends ServiceImpl<EntityLabelsRel
         }
     }
 
+
+    @Override
+    public Boolean delRelById(Long id) {
+        EntityLabelsRelation entityLabelsRelation = baseMapper.selectById(id);
+        if (null != entityLabelsRelation) {
+            int del = baseMapper.deleteById(id);
+            return del > 0 ? true : false;
+        }
+        return false;
+    }
+
     /**
      * 获取标注数据。
+     *
      * @param fileIds
+     * @param kgId
      * @return
      */
-    public List<AnnotationData> getAnnotationDatas(List<String> fileIds,String kgId){
+    @Override
+    public List<AnnotationData> getAnnotationDatas(List<String> fileIds, String kgId) {
         List<AnnotationData> annotationDatas = new ArrayList<>();// 图谱下的所有文档标注信息。
         for (String fileId : fileIds) {
             String fileTextContent = sysFileService.getFileTextContent(fileId);
             if (null != fileTextContent && StringUtils.isNotBlank(fileTextContent)) {
-                log.info("文本内容不为空:{}", fileTextContent);
+                // log.info("文本内容不为空:{}", fileTextContent);
                 log.info("--->fileId:{}", fileId);
                 // 获取历史标注实体信息数据列表,即知识库下的实体标注信息列表。
                 List<AnnotationEntity> entities = entityLablesSpanService.getAnnotationEntityByKgIdAndFileId(kgId, fileId);
@@ -228,13 +281,128 @@ public class EntityLabelsRelationServiceImpl extends ServiceImpl<EntityLabelsRel
     }
 
     @Override
-    public Boolean delRelById(Long id) {
-        EntityLabelsRelation entityLabelsRelation = baseMapper.selectById(id);
-        if (null != entityLabelsRelation) {
-            int del = baseMapper.deleteById(id);
-            return del > 0 ? true : false;
+    public void exportDataBase(ExportAnnotationData exportAnnotationData, HttpServletRequest request, HttpServletResponse response) throws IOException {
+        // 1. 首先根据kgId获取图谱构建的实体、关系数据。
+        List<SysEntity> selEntityByKgId = sysEntityService.getEntityByKgId(exportAnnotationData.getKgId());
+        List<String> fileIds = exportAnnotationData.getFileIds();
+        // 2.2 用户在图模型创建了实体和关系,即存在图schema数据。先请求schema/import,返回OK,再判断是否有标注数据。
+        List<EntityForAlg> entityForAlgs = JSONArray.parseArray(selEntityByKgId.get(0).getEntityAll(), EntityForAlg.class);
+        log.info("有图schema的实体信息:{}", JSON.toJSONString(entityForAlgs));
+        String relationAll = selEntityByKgId.get(0).getRelationAll();
+        List<RelationForAlg> relationForAlgs = JSONArray.parseArray(relationAll, RelationForAlg.class);
+        log.info("有图schema的实体间关系信息:{}", JSON.toJSONString(relationForAlgs));
+        List<AnnotationData> annotationDatas = getAnnotationDatas(fileIds, exportAnnotationData.getKgId());
+        log.info("待导出的标注数据 annotationDatas:{}", JSON.toJSONString(annotationDatas));
+        List<ToAnnotation> annotations = new ArrayList<>();
+        for (String fileId : exportAnnotationData.getFileIds()) {
+            annotations.add(toAnnotation(exportAnnotationData.getKgId(), fileId));
+        }
+        log.info("待导出的标注数据 annotations:{}", JSON.toJSONString(annotations));
+
+        String fileType = ".json";
+        String fileName = FileUtils.genFileName(exportAnnotationData.getKgId() + "-" + System.currentTimeMillis()) + fileType;
+        String finalPath = filePath + fileName;
+        finalPath = FileUtils.annotationDataToJson(annotations, fileName, finalPath, request, response);
+        log.info("写入文件路径 path:{}", finalPath);
+    }
+
+    @Override
+    public Boolean importDataBase(String kgId, MultipartFile file) {
+        String finalPath = filePath + file.getOriginalFilename();
+        try {
+            file.transferTo(new File(finalPath));
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            log.info("标注数据导入写入文件异常 ex:{}", ex);
+        }
+        String readJsonStr = FileUtils.readJson(finalPath);
+        List<ToAnnotation> annotationDatas = new ArrayList<>();
+        if (null != readJsonStr && CommonUtils.isJsonArray(readJsonStr)) {
+            annotationDatas = JSONArray.parseArray(readJsonStr, ToAnnotation.class);
+        }
+        log.info("read res:{}", JSON.toJSONString(annotationDatas));
+
+        if (!CollectionUtils.isEmpty(annotationDatas)) {
+            // 数据不为空,执行导入操作。
+            List<AnnotationList> annotationLists = new ArrayList<>();
+            AnnotationList annotationList;
+            for (ToAnnotation annotationData : annotationDatas) {
+                // 解析entities、relations数据写入entity_labels_span、entity_labels_relation表中。
+                List<AnnotationEntity> entities = annotationData.getEntities();
+                if (!CollectionUtils.isEmpty(entities)) {
+                    EntityLabelsSpan entityLabelsSpan;
+                    List<EntityLabelsSpan> entityLabelsSpans = new ArrayList<>();
+                    for (AnnotationEntity entity : entities) {
+                        entityLabelsSpan = new EntityLabelsSpan();
+                        BeanUtils.copyProperties(entity, entityLabelsSpan);
+                        entityLabelsSpan.setKgId(kgId);
+                        entityLabelsSpans.add(entityLabelsSpan);
+                    }
+                    log.info("导入标注的实体数据:{}", entityLabelsSpans.size());
+                    // todo 暂时搁置:保存实体数据至数据库。
+
+                } else {
+                    log.info("暂无标注的实体数据需要导入。");
+                }
+                List<AnnotationEntityRelation> relations = annotationData.getRelations();
+                if (!CollectionUtils.isEmpty(relations)) {
+                    List<EntityLabelsRelation> entityLabelsRelations = new ArrayList<>();
+                    EntityLabelsRelation entityLabelsRelation;
+                    for (AnnotationEntityRelation relation : relations) {
+                        entityLabelsRelation = new EntityLabelsRelation();
+                        BeanUtils.copyProperties(relation, entityLabelsRelation);
+                        entityLabelsRelation.setKgId(kgId);
+                        entityLabelsRelations.add(entityLabelsRelation);
+                    }
+                    log.info("导入标注的实体关系数据:{}", entityLabelsRelations.size());
+                    // todo 暂时搁置:保存实体关系数据至数据库。
+
+                } else {
+                    log.info("暂无标注的实体关系数据需要导入。");
+                }
+
+                // 解析entityList、relationList数据,根据kgId获取实体数据写入sys_entity;根据kgId获取实体关系数据写入sys_relation表中。kgId记得更新为当前图谱ID。
+                if (!CollectionUtils.isEmpty(annotationData.getEntityList())) {
+                    String selKgId = annotationData.getEntityList().get(0).getKgId();
+                    List<SysEntity> selEntities = sysEntityService.getEntityByKgId(selKgId);
+                    List<SysEntity> upSelEntities = selEntities.stream().map(wmy -> {
+                        wmy.setKgId(kgId);
+                        wmy.setCreateBy(SecurityUtils.getUsername());
+                        return wmy;
+                    }).collect(Collectors.toList());
+                    // todo 暂时搁置:插入实体数据。
+
+                }
+                if (!CollectionUtils.isEmpty(annotationData.getRelationList())) {
+                    String selKgId = annotationData.getRelationList().get(0).getKgId();
+                    List<SysRelation> selRelations = sysRelationService.getRelationByKgId(selKgId);
+                    List<SysRelation> upSelRelations = selRelations.stream().map(wmy -> {
+                        wmy.setKgId(kgId);
+                        wmy.setCreateBy(SecurityUtils.getUsername());
+                        return wmy;
+                    }).collect(Collectors.toList());
+                    // todo 暂时搁置:插入实体关系数据。
+
+                }
+                // 解析text、textfront写入annotitionlist表。
+                annotationList = AnnotationList.builder().textContent(annotationData.getText()).textFront(annotationData.getTextFront())
+                        .build();
+                annotationLists.add(annotationList);
+            }
+        } else {
+            log.info("待导入数据为空,不执行导入操作");
+        }
+        return null;
+    }
+
+    @Override
+    public void toUpText(ConvertAlgRes convertAlgRes) {
+        if (null != convertAlgRes.getText() && StringUtils.isNotBlank(convertAlgRes.getText())) {
+            sysFileService.upFileTextContentByFileId(convertAlgRes.getFileId(), convertAlgRes.getText());
+            log.info("收到算法解析的text内容,并进行更新。");
+        } else {
+            log.info("算法解析的text文本内容为空,不做更新操作。");
         }
-        return false;
     }
 
     /**
@@ -248,8 +416,7 @@ public class EntityLabelsRelationServiceImpl extends ServiceImpl<EntityLabelsRel
     public Boolean createGenerateGraph(String getTaskIdRes, String kgId, Boolean isGenerate, Integer graphStatus, Integer annotationStatus) {
         // 更新图谱的状态为进行中。
         Boolean upRes = sysKgService.updateGrapgStatus(kgId, graphStatus, annotationStatus, 2, "进行中");
-        log.info("更新图谱的状态为进行中:{}", upRes);
-        log.info("调用算法获取taskId:{}", getTaskIdRes);
+        log.info("更新图谱的状态为进行中 upRes:{},任务ID getTaskIdRes:{}", upRes, getTaskIdRes);
         if (CommonUtils.isJson(getTaskIdRes)) {
             JSONObject taskObj = JSON.parseObject(getTaskIdRes);
             if (taskObj.containsKey("taskId")) {

+ 16 - 11
src/main/java/com/pavis/backend/slim/project/system/service/impl/EntityLabelsSpanServiceImpl.java

@@ -1,6 +1,5 @@
 package com.pavis.backend.slim.project.system.service.impl;
 
-import cn.hutool.core.date.DateUtil;
 import com.alibaba.fastjson2.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -13,6 +12,7 @@ import com.pavis.backend.slim.project.system.domain.annotation.DelAnnotation;
 import com.pavis.backend.slim.project.system.mapper.EntityLabelsRelationMapper;
 import com.pavis.backend.slim.project.system.mapper.EntityLabelsSpanMapper;
 import com.pavis.backend.slim.project.system.mapper.SysKgMapper;
+import com.pavis.backend.slim.project.system.service.AnnotationListService;
 import com.pavis.backend.slim.project.system.service.EntityLablesSpanService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
@@ -33,16 +33,15 @@ import java.util.List;
 @Service
 @Slf4j
 public class EntityLabelsSpanServiceImpl extends ServiceImpl<EntityLabelsSpanMapper, EntityLabelsSpan> implements EntityLablesSpanService {
-
-    // @Autowired
-    // private EntityLabelsSpanMapper entityLabelsSpanMapper;
-
     @Autowired
     private EntityLabelsRelationMapper entityLabelsRelationMapper;
 
     @Resource
     private SysKgMapper sysKgMapper;
 
+    @Autowired
+    private AnnotationListService annotationListService;
+
     @Override
     public EntityLabelsSpan saveAnnotationEntity(AnnotationEntity entity) {
         // 将前端传过来的实体信息进行存储,备注:不对实体信息做判重信息。
@@ -51,9 +50,12 @@ public class EntityLabelsSpanServiceImpl extends ServiceImpl<EntityLabelsSpanMap
         // 设置基本信息,创建人、创建时间等。
         entityLabelsSpan.setUserId(SecurityUtils.getUserId());
         entityLabelsSpan.setCreateBy(SecurityUtils.getUsername());
-        entityLabelsSpan.setCreateTime(DateUtil.date());
-        int insert = baseMapper.insert(entityLabelsSpan);
-        log.info("标注的实体信息存储结果res:{},entityLabelsSpan:{}",insert, JSON.toJSONString(entityLabelsSpan));
+        // 新增。
+        // int insertRes = baseMapper.insert(entityLabelsSpan);
+        // log.info("标注的实体信息存储结果res:{},entityLabelsSpan:{}",insertRes, JSON.toJSONString(entityLabelsSpan));
+        // 存在id更新,无id新增。
+        boolean modRes = saveOrUpdate(entityLabelsSpan);
+        log.info("标注的实体信息存储结果res:{},entityLabelsSpan:{}",modRes, JSON.toJSONString(entityLabelsSpan));
         // 更新标注状态。
         SysKg sysKg = sysKgMapper.selectById(entity.getKgId());
         if (null != sysKg){
@@ -61,6 +63,12 @@ public class EntityLabelsSpanServiceImpl extends ServiceImpl<EntityLabelsSpanMap
             int upRes = sysKgMapper.updateById(sysKg);
             log.info("更新图谱的标注状态annotationStatus:{}",upRes);
         }
+        // // 更新标注数据。todo 前端反馈暂时先不在此处加逻辑了。
+        // log.info("开始更新前端标注textFront数据");
+        // AnnotationFront annotationFront = AnnotationFront.builder().kgId(entity.getKgId()).fileId(entity.getFileId()).textFront(entity.getTextFront()).build();
+        // log.info("实体:{}",JSON.toJSONString(annotationFront));
+        // Boolean upAnnotation = annotationListService.saveAnnotation(annotationFront);
+        // log.info("结束更新前端标注textFront数据 upAnnotation:{}",upAnnotation);
         return entityLabelsSpan;
     }
 
@@ -74,7 +82,6 @@ public class EntityLabelsSpanServiceImpl extends ServiceImpl<EntityLabelsSpanMap
             annotationEntity = new AnnotationEntity();
             BeanUtils.copyProperties(entityLabelsSpan,annotationEntity);
             annotationEntity.setId(Long.valueOf(entityLabelsSpan.getId()));
-            // 处理个别字段,fileId是string类型的。
             annotationEntities.add(annotationEntity);
         }
         return annotationEntities;
@@ -96,7 +103,6 @@ public class EntityLabelsSpanServiceImpl extends ServiceImpl<EntityLabelsSpanMap
             List<Integer> delRels = new ArrayList<>();
             List<Integer> delEntities = new ArrayList<>();
             for (String id : delAnnotation.getIds()) {
-                // EntityLabelsSpan entityLabelsSpan = baseMapper.selectById(id);
                 List<EntityLabelsRelation> entityLabelsRelations = entityLabelsRelationMapper.selectList(new QueryWrapper<EntityLabelsRelation>().lambda().eq(EntityLabelsRelation::getKgId, delAnnotation.getKgId()).eq(EntityLabelsRelation::getFileId, delAnnotation.getFileId()).eq(EntityLabelsRelation::getFromId, id).or().eq(EntityLabelsRelation::getToId, id));
                 log.info("***entityLabelsRelations:{}",JSON.toJSONString(entityLabelsRelations));
                 if (!CollectionUtils.isEmpty(entityLabelsRelations)){
@@ -112,7 +118,6 @@ public class EntityLabelsSpanServiceImpl extends ServiceImpl<EntityLabelsSpanMap
                     }
                 }else {
                     // 不存在关系,直接删除实体。
-                    // 删除实体。
                     int delEntitieRes = baseMapper.deleteById(id);
                     delEntities.add(delEntitieRes);
                 }

+ 64 - 13
src/main/java/com/pavis/backend/slim/project/system/service/impl/GenerateGraphServiceImpl.java

@@ -1,9 +1,13 @@
 package com.pavis.backend.slim.project.system.service.impl;
 
-import cn.hutool.core.date.DateUtil;
+import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.pavis.backend.slim.common.utils.CommonUtils;
 import com.pavis.backend.slim.common.utils.SecurityUtils;
+import com.pavis.backend.slim.framework.web.domain.BaseEntity;
+import com.pavis.backend.slim.project.system.client.AlgKgClient;
 import com.pavis.backend.slim.project.system.domain.GenerateGraph;
 import com.pavis.backend.slim.project.system.domain.annotation.GenerateGraphResult;
 import com.pavis.backend.slim.project.system.mapper.GenerateGraphMapper;
@@ -14,7 +18,9 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * @version: java version 1.8
@@ -29,6 +35,8 @@ public class GenerateGraphServiceImpl extends ServiceImpl<GenerateGraphMapper, G
     @Autowired
     private SysKgService sysKgService;
 
+    @Autowired
+    private AlgKgClient algKgClient;
 
     @Override
     public void generateKgGraphResult(GenerateGraphResult genGraphResult) {
@@ -39,24 +47,24 @@ public class GenerateGraphServiceImpl extends ServiceImpl<GenerateGraphMapper, G
                 // 更新状态。
                 for (GenerateGraph graph : generateGraphs) {
                     // 更新解析状态:0 未解析 2 解析中 -1 解析失败 1 解析成功。
-                    if ("解析".equals(genGraphResult.getTaskName())){
+                    if ("解析".equals(genGraphResult.getTaskName())) {
                         graph = toUpParse(graph, genGraphResult);
-                    }else if ("训练".equals(genGraphResult.getTaskName())){
+                    } else if ("训练".equals(genGraphResult.getTaskName())) {
                         graph = toUpTrain(graph, genGraphResult);
-                    }else if ("抽取".equals(genGraphResult.getTaskName())){
+                    } else if ("抽取".equals(genGraphResult.getTaskName())) {
                         graph = toUpExtract(graph, genGraphResult);
                     }
                     int upRes = baseMapper.updateById(graph);
                     log.info("算法生成知识图谱-:{},更新结果:{}", genGraphResult.getTaskName(), upRes);
                     // 更新图谱的状态:图模型状态 0 无图模型 1 有图模型;是否标注状态 0 未标注  1 已标注;生成图谱的状态 0 未生成 1 已生成。
                     if (graph.getParseTaskStatus() == -1) {
-                        sysKgService.updateGrapgStatus(graph.getKgId(), null,null, graph.getParseTaskStatus(), "解析失败");
+                        sysKgService.updateGrapgStatus(graph.getKgId(), null, null, graph.getParseTaskStatus(), "解析失败");
                     } else if (graph.getTrainTaskStatus() == -1) {
-                        sysKgService.updateGrapgStatus(graph.getKgId(), null,null, graph.getTrainTaskStatus(), "训练失败");
+                        sysKgService.updateGrapgStatus(graph.getKgId(), null, null, graph.getTrainTaskStatus(), "训练失败");
                     } else if (graph.getExtractTaskStatus() == -1) {
-                        sysKgService.updateGrapgStatus(graph.getKgId(), null,null, graph.getExtractTaskStatus(), "抽取失败");
+                        sysKgService.updateGrapgStatus(graph.getKgId(), null, null, graph.getExtractTaskStatus(), "抽取失败");
                     } else if (graph.getExtractTaskStatus() == 1) {
-                        sysKgService.updateGrapgStatus(graph.getKgId(), null,null, graph.getExtractTaskStatus(), "抽取成功");
+                        sysKgService.updateGrapgStatus(graph.getKgId(), null, null, graph.getExtractTaskStatus(), "抽取成功");
                     }
                 }
             }
@@ -69,14 +77,57 @@ public class GenerateGraphServiceImpl extends ServiceImpl<GenerateGraphMapper, G
         GenerateGraph generateGraph = GenerateGraph.builder().taskId(taskId).kgId(kgId).taskType(String.valueOf(isGenerate)).parseTaskName("解析").parseTaskStatus(2)
                 .trainTaskName("训练").trainTaskStatus(isGenerate == true ? 1 : 2).extractTaskName("抽取").extractTaskStatus(2).build();
         generateGraph.setCreateBy(SecurityUtils.getUsername());
-        generateGraph.setCreateTime(DateUtil.date());
         generateGraph.setUpdateBy(SecurityUtils.getUsername());
-        generateGraph.setUpdateTime(DateUtil.date());
         int insert = baseMapper.insert(generateGraph);
         log.info("算法新增生成图谱记录:{}", insert);
         return insert > 0 ? true : false;
     }
 
+    @Override
+    public Boolean stopGraphByTaskId(String kgId) {
+        List<GenerateGraph> generateGraphs = baseMapper.selectList(new QueryWrapper<GenerateGraph>().lambda().eq(GenerateGraph::getKgId, kgId).orderByDesc(BaseEntity::getCreateTime));
+        if (!CollectionUtils.isEmpty(generateGraphs)) {
+            String taskId = generateGraphs.get(0).getTaskId();
+            Map<String, Object> taskMap = new HashMap<>();
+            taskMap.put("taskId", taskId);
+            log.info("通知算法停止生成图谱入参 taskMap:{}", JSON.toJSONString(taskMap));
+            JSONObject algRes = new JSONObject();
+            try {
+                algRes = algKgClient.stopGraphToAlg(JSON.toJSONString(taskMap));
+                log.info("通知算法停止生成图谱返回结果 algRes:{}", JSON.toJSONString(algRes));
+            } catch (Exception ex) {
+                log.info("通知算法停止生成图谱返回结果异常 ex:{}", ex);
+            }
+            if (null != algRes && CommonUtils.isJson(JSON.toJSONString(algRes))) {
+                if ("true".equals(algRes.get("status").toString())) {
+                    log.info("算法取消成功 algRes:{}", JSON.toJSONString(algRes));
+                    // 更新状态为取消:解析、训练、抽取。
+                    generateGraphs.get(0).setParseTaskStatus(-2);
+                    generateGraphs.get(0).setParseTaskReason("取消");
+                    generateGraphs.get(0).setTrainTaskStatus(-2);
+                    generateGraphs.get(0).setTrainTaskReason("取消");
+                    generateGraphs.get(0).setExtractTaskStatus(-2);
+                    generateGraphs.get(0).setExtractTaskReason("取消");
+                    int upStatus = baseMapper.updateById(generateGraphs.get(0));
+                    log.info("更新停止生成图谱状态结果 upStatus:{}", upStatus);
+                    if (upStatus > 0) {
+                        // 更新syskg状态。
+                        Boolean stopStatus = sysKgService.stopGraph(kgId);
+                        log.info("取消生成图谱状态结果 stopStatus:{}", stopStatus);
+                        return stopStatus;
+                    }
+                } else {
+                    log.info("算法取消失败 algRes:{}", JSON.toJSONString(algRes));
+                }
+            } else {
+                log.info("通知算法停止生成图谱返回结果 为空:{}", JSON.toJSONString(algRes));
+            }
+        } else {
+            log.info("图谱不存在,取消失败");
+        }
+        return false;
+    }
+
     /**
      * 处理解析状态。
      *
@@ -145,7 +196,7 @@ public class GenerateGraphServiceImpl extends ServiceImpl<GenerateGraphMapper, G
                 graph.setExtractTaskReason("因第一步骤解析失败");
             }
         }
-        if ("true".equals(graph.getTaskType())){
+        if ("true".equals(graph.getTaskType())) {
             // 通用图谱训练状态永远为成功。
             graph.setTrainTaskName("训练");
             graph.setTrainTaskStatus(1);
@@ -203,7 +254,7 @@ public class GenerateGraphServiceImpl extends ServiceImpl<GenerateGraphMapper, G
                 graph.setExtractTaskReason("因第二步骤训练失败");
             }
         }
-        if ("true".equals(graph.getTaskType())){
+        if ("true".equals(graph.getTaskType())) {
             // 通用图谱训练状态永远为成功。
             graph.setTrainTaskName("训练");
             graph.setTrainTaskStatus(1);
@@ -247,7 +298,7 @@ public class GenerateGraphServiceImpl extends ServiceImpl<GenerateGraphMapper, G
                 graph.setExtractTaskReason("抽取失败");
             }
         }
-        if ("true".equals(graph.getTaskType())){
+        if ("true".equals(graph.getTaskType())) {
             // 通用图谱训练状态永远为成功。
             graph.setTrainTaskName("训练");
             graph.setTrainTaskStatus(1);

+ 30 - 4
src/main/java/com/pavis/backend/slim/project/system/service/impl/SysFileServiceImpl.java

@@ -15,10 +15,12 @@ import com.pavis.backend.slim.common.utils.FileUtils;
 import com.pavis.backend.slim.common.utils.SecurityUtils;
 import com.pavis.backend.slim.framework.minio.MinioStorage;
 import com.pavis.backend.slim.project.system.client.AlgKgClient;
+import com.pavis.backend.slim.project.system.domain.AnnotationList;
 import com.pavis.backend.slim.project.system.domain.SysFile;
 import com.pavis.backend.slim.project.system.domain.annotation.ConvertAlgRes;
 import com.pavis.backend.slim.project.system.domain.annotation.ConvertDocToTxt;
 import com.pavis.backend.slim.project.system.domain.vo.TreeFile;
+import com.pavis.backend.slim.project.system.mapper.AnnotationListMapper;
 import com.pavis.backend.slim.project.system.mapper.SysFileMapper;
 import com.pavis.backend.slim.project.system.service.SysFileService;
 import lombok.extern.slf4j.Slf4j;
@@ -30,6 +32,7 @@ import org.springframework.util.CollectionUtils;
 import org.springframework.util.StreamUtils;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.ByteArrayOutputStream;
@@ -62,6 +65,9 @@ public class SysFileServiceImpl extends ServiceImpl<SysFileMapper, SysFile> impl
     @Autowired
     private AlgKgClient algKgClient;
 
+    @Resource
+    private AnnotationListMapper annotationListMapper;
+
     @Override
     public SysFile uploadFile(MultipartFile file) {
         SysFile sysFile = uploadFile(file, "", Constant.DIR_SEP, false);
@@ -300,14 +306,14 @@ public class SysFileServiceImpl extends ServiceImpl<SysFileMapper, SysFile> impl
     }
 
     @Override
-    public void convertToTxt(List<String> fileIds) {
+    public void convertToTxt(List<String> fileIds,Boolean isNew) {
         List<SysFile> sysFiles = baseMapper.selectList(new QueryWrapper<SysFile>().lambda().in(SysFile::getFileId, fileIds));
         if (!CollectionUtils.isEmpty(sysFiles)) {
             List<ConvertDocToTxt> convertDocToTxts = new ArrayList<>();
             for (SysFile sysFile : sysFiles) {
                 // 三个条件均不为空时,才调用算法获取文档转换成txt结果。
                 if (null != sysFile && null != sysFile.getObjectKey() && null != sysFile.getIdentifier()) {
-                    convertDocToTxts.add(ConvertDocToTxt.builder().fileId(sysFile.getFileId()).objectKey(sysFile.getObjectKey()).identifier(sysFile.getIdentifier()).build());
+                    convertDocToTxts.add(ConvertDocToTxt.builder().fileId(sysFile.getFileId()).objectKey(sysFile.getObjectKey()).identifier(sysFile.getIdentifier()).isNew(isNew).build());
                 }
             }
             if (!CollectionUtils.isEmpty(convertDocToTxts)) {
@@ -356,11 +362,11 @@ public class SysFileServiceImpl extends ServiceImpl<SysFileMapper, SysFile> impl
 
     @Async
     @Override
-    public void convertfileToTxtByAlg(SysFile sysFile) {
+    public void convertfileToTxtByAlg(SysFile sysFile,Boolean isNew) {
         List<ConvertDocToTxt> convertDocToTxts = new ArrayList<>();
         // 三个条件均不为空时,才调用算法获取文档转换成txt结果。
         if (null != sysFile && null != sysFile.getObjectKey() && null != sysFile.getIdentifier()) {
-            convertDocToTxts.add(ConvertDocToTxt.builder().fileId(sysFile.getFileId()).objectKey(sysFile.getObjectKey()).identifier(sysFile.getIdentifier()).build());
+            convertDocToTxts.add(ConvertDocToTxt.builder().fileId(sysFile.getFileId()).objectKey(sysFile.getObjectKey()).identifier(sysFile.getIdentifier()).isNew(isNew).build());
         }
         if (!CollectionUtils.isEmpty(convertDocToTxts)) {
             Map<String, Object> algMap = new HashMap<>();
@@ -375,6 +381,26 @@ public class SysFileServiceImpl extends ServiceImpl<SysFileMapper, SysFile> impl
         }
     }
 
+    @Override
+    public void upFileTextContentByFileId(String fileId,String textContent) {
+        SysFile sysFile = baseMapper.selectById(fileId);
+        if (null != sysFile){
+            sysFile.setTextContent(textContent);
+            int upRes = baseMapper.updateById(sysFile);
+            log.info("更新文档解析txt的文本内容:{}",upRes);
+            List<AnnotationList> annotationLists = annotationListMapper.selectList(new QueryWrapper<AnnotationList>().lambda().eq(AnnotationList::getFileId, fileId));
+            if (!CollectionUtils.isEmpty(annotationLists)){
+                for (AnnotationList annotationList : annotationLists) {
+                    annotationList.setTextContent(textContent);
+                    annotationList.setParseStatus(1);
+                    int upAnnotationRes = annotationListMapper.updateById(annotationList);
+                    log.info("更新标注列表的文本内容 upAnnotationRes:{}",JSON.toJSONString(upAnnotationRes));
+                }
+            }else {
+                log.info("暂未使用该文档进行标注,无需更新。");
+            }
+        }
+    }
 
 
     /**

+ 1 - 1
src/main/java/com/pavis/backend/slim/project/system/service/impl/SysKbFileServiceImpl.java

@@ -53,7 +53,7 @@ public class SysKbFileServiceImpl extends ServiceImpl<SysKbFileMapper, SysKbFile
         log.info("知识库文档上传接口kbFile:{}", JSON.toJSONString(kbFile));
         // todo 为知识库添加文档时,需要调用算法去做文档转换txt。无需关注算法返回。
         log.info("开始调用算法的【文档转txt】接口");
-        fileService.convertfileToTxtByAlg(sysFile);
+        fileService.convertfileToTxtByAlg(sysFile,true);
         log.info("结束调用算法的【文档转txt】接口");
         return sysFile;
     }

+ 95 - 0
src/main/java/com/pavis/backend/slim/project/system/service/impl/SysKgServiceImpl.java

@@ -3,12 +3,16 @@ package com.pavis.backend.slim.project.system.service.impl;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.crypto.digest.MD5;
 import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONArray;
+import com.alibaba.fastjson2.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import com.pavis.backend.slim.common.constant.Hodgepodge;
+import com.pavis.backend.slim.common.utils.CommonUtils;
+import com.pavis.backend.slim.common.utils.FileUtils;
 import com.pavis.backend.slim.common.utils.SecurityUtils;
 import com.pavis.backend.slim.project.system.client.HttpClientUtil;
 import com.pavis.backend.slim.project.system.domain.SysEntity;
@@ -22,6 +26,8 @@ import com.pavis.backend.slim.project.system.domain.SysKgEntity;
 import com.pavis.backend.slim.project.system.domain.SysKgRelation;
 import com.pavis.backend.slim.project.system.domain.SysRelation;
 import com.pavis.backend.slim.project.system.domain.algorithm.AlgSpO;
+import com.pavis.backend.slim.project.system.domain.annotation.ExportSchemaData;
+import com.pavis.backend.slim.project.system.domain.annotation.ExportSysEntity;
 import com.pavis.backend.slim.project.system.domain.front.ClutterReturn;
 import com.pavis.backend.slim.project.system.domain.front.FileKey;
 import com.pavis.backend.slim.project.system.domain.front.InKgParameter;
@@ -45,10 +51,17 @@ import com.pavis.backend.slim.project.system.service.SysKgService;
 import com.pavis.backend.slim.project.system.service.SysRelationService;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.File;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Date;
@@ -102,6 +115,9 @@ public class SysKgServiceImpl extends ServiceImpl<SysKgMapper, SysKg> implements
     @Value("${algorithm.creat.url}")
     private String url;
 
+    @Value("${pavis.profile}")
+    private String filePath;
+
     @Override
     public SysKg create(SysKg kg) {
         kg.setCreateBy(SecurityUtils.getUsername());
@@ -111,6 +127,7 @@ public class SysKgServiceImpl extends ServiceImpl<SysKgMapper, SysKg> implements
         kg.setGraphStatus(0);
         kg.setAnnotationStatus(0);
         kg.setGenerateGraphStatus(0);
+        kg.setCancelStatus(0);
         // 存储kg信息
         baseMapper.insert(kg);
         // 处理前端传过来的文件字段--fileIds
@@ -176,6 +193,7 @@ public class SysKgServiceImpl extends ServiceImpl<SysKgMapper, SysKg> implements
                 .eq("user_id", SecurityUtils.getUserId())
                 .orderByDesc("create_time")
         );
+
     }
 
     @Override
@@ -247,6 +265,8 @@ public class SysKgServiceImpl extends ServiceImpl<SysKgMapper, SysKg> implements
                         sysEntityRelation.setEnd((String) map.get("o"));
                         sysEntityRelation.setEndId(oCopy);
                         sysEntityRelation.setEntityRelation(map.get("sType") + "-" + map.get("pType") + "-" + map.get("oType"));
+                        // 设置基本信息,创建人、创建时间等。
+                        sysEntityRelation.setCreateTime(DateUtil.date());
                         sysEntityRelationMapper.insert(sysEntityRelation);
                     }
                 }
@@ -670,6 +690,7 @@ public class SysKgServiceImpl extends ServiceImpl<SysKgMapper, SysKg> implements
             }
             sysKg.setGenerateGraphStatus(finalStatus);
             sysKg.setGenerateGraphReason(finalReason);
+            sysKg.setCancelStatus(0);
             int upRes = baseMapper.updateById(sysKg);
             log.info("更新生成图谱的状态:{}", upRes);
             return upRes > 0 ? true : false;
@@ -685,6 +706,80 @@ public class SysKgServiceImpl extends ServiceImpl<SysKgMapper, SysKg> implements
     }
 
     @Override
+    public Boolean stopGraph(String kgId) {
+        SysKg sysKg = baseMapper.selectById(kgId);
+        if (null != sysKg) {
+            sysKg.setCancelStatus(-2);
+            // 如果前状态是2,则之前状态需要做下更新: 生成过图谱.
+            if (sysKg.getGenerateGraphStatus() == 2) {
+                log.info("前状态为进行中,需要做下更新。");
+                // List<SysEntity> entityByKgId = sysEntityService.getEntityByKgId(kgId);
+                List<SysEntityInstance> sysEntityInstances = sysEntityInstanceMapper.selectList(new QueryWrapper<SysEntityInstance>().lambda().eq(SysEntityInstance::getKgId, kgId));
+                if (!CollectionUtils.isEmpty(sysEntityInstances)) {
+                    sysKg.setGenerateGraphStatus(1);
+                    sysKg.setGenerateGraphReason("有图谱数据则成功");
+                } else {
+                    sysKg.setGenerateGraphStatus(0);
+                    sysKg.setGenerateGraphReason("无图谱数据则默认值0");
+                }
+            }
+            int upCancelStatus = baseMapper.updateById(sysKg);
+            log.info("SysKg更新取消状态:{}", upCancelStatus);
+            return upCancelStatus > 0 ? true : false;
+        }
+        return false;
+    }
+
+    @Override
+    public void exportSchema(ExportSchemaData exportSchemaData, HttpServletRequest request, HttpServletResponse response) throws IOException {
+        SysEntityAll sysEntityAll = selEntityAll(exportSchemaData.getKgId());
+        sysEntityAll.setKgId(exportSchemaData.getKgId());
+        log.info("待导出的图谱schema数据 sysEntityAll:{}", JSON.toJSONString(sysEntityAll));
+        if (null != sysEntityAll){
+            ExportSysEntity exportSysEntity = new ExportSysEntity();
+            BeanUtils.copyProperties(sysEntityAll,exportSysEntity);
+            exportSysEntity.setEntityAll(JSONArray.parseArray(sysEntityAll.getEntityAll()));
+            exportSysEntity.setEntityKgAll(JSONArray.parseArray(sysEntityAll.getEntityKgAll()));
+            exportSysEntity.setRelationAll(JSONArray.parseArray(sysEntityAll.getRelationAll()));
+            exportSysEntity.setRelationKgAll(JSONArray.parseArray(sysEntityAll.getRelationKgAll()));
+            String fileType = ".json";
+            String fileName = FileUtils.genFileName(exportSchemaData.getKgId() + "-" + System.currentTimeMillis()) + fileType;
+            String finalPath = filePath + fileName;
+            finalPath = FileUtils.kgSchemaDataToJson(exportSysEntity, fileName, finalPath, request, response);
+            log.info("图谱schema数据写入文件路径 path:{}", finalPath);
+        }
+
+    }
+
+    @Override
+    public SysEntityAll importSchema(String kgId, MultipartFile file) throws IOException {
+        String finalPath = filePath + file.getOriginalFilename();
+        try {
+            file.transferTo(new File(finalPath));
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            log.info("图谱schema数据导入写入文件异常 ex:{}", ex);
+        }
+        String readJsonStr = FileUtils.readJson(finalPath);
+        SysEntityAll sysEntityAll = new SysEntityAll();
+        if (null != readJsonStr && CommonUtils.isJson(readJsonStr)) {
+            sysEntityAll = JSONObject.parseObject(readJsonStr, SysEntityAll.class);
+            log.info("read 图谱schema数据 res:{}", JSON.toJSONString(sysEntityAll));
+        }
+
+        if (null != sysEntityAll) {
+            SysEntity sysEntity = new SysEntity();
+            BeanUtils.copyProperties(sysEntityAll, sysEntity);
+            sysEntity.setKgId(kgId);
+            log.info("待导入的图谱shcema数据 sysEntity:{}", JSON.toJSONString(sysEntity));
+            SysEntityAll entityKg = createEntityKg(sysEntity);
+            log.info("插入导入的图谱schema数据 sysEntity:{}", JSON.toJSONString(sysEntity));
+            return entityKg;
+        } else {
+            log.info("无待导入的图谱schema数据。");
+        }
+        return null;
+    }
     public SysEntityInstance insOrUpdEnIce(SysEntityInstance sysEntityInstance) {
         log.info("******接口(insOrUpdEnIce)--->入参(sysEntityInstance):{}", JSON.toJSONString(sysEntityInstance));
         String s = md5Check(MD5.create().digestHex16(sysEntityInstance.getName()), sysEntityInstance.getKgId());

+ 1 - 1
src/main/resources/application-ghj.yml

@@ -3,7 +3,7 @@ server:
 # 通用配置
 pavis:
   # 需要换成自己开发环境本地的地址
-  profile: F:\ghj\spic\upload\
+  profile: F:\ghj\01-sql\export\
 #minio配置
 minio:
 #  #对象存储服务的URL

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

@@ -1,7 +1,7 @@
 spring:
   profiles:
-#    active: ghj
-    active: local
+    active: ghj
+#    active: local
   # 国际化资源文件路径
   messages:
     basename: i18n/messages

Some files were not shown because too many files changed in this diff