Przeglądaj źródła

有图schema&标注数据接口同算法对接联调,发现bug,解决数据传输时遇到的bug;生成图谱后,增加接口用户可取消生成图谱接口;取消生成图谱通知算法服务.

guanz 1 rok temu
rodzic
commit
a88f737d6a

+ 6 - 6
pom.xml

@@ -164,12 +164,12 @@
             <artifactId>junit</artifactId>
             <version>${junit.version}</version>
         </dependency>
-        <dependency>
-            <groupId>MavenRepository.MavenRepository.junit</groupId>
-            <artifactId>junit</artifactId>
-            <version>4.13.2</version>
-            <scope>test</scope>
-        </dependency>
+        <!--<dependency>-->
+        <!--    <groupId>MavenRepository.MavenRepository.junit</groupId>-->
+        <!--    <artifactId>junit</artifactId>-->
+        <!--    <version>4.13.2</version>-->
+        <!--    <scope>test</scope>-->
+        <!--</dependency>-->
     </dependencies>
 
     <dependencyManagement>

+ 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 通用知识图谱构建,即图谱下无实体、关系数据。-----> 暂未对接。

+ 33 - 5
src/main/java/com/pavis/backend/slim/project/system/controller/AnnotationController.java

@@ -29,9 +29,12 @@ 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.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -121,11 +124,6 @@ public class AnnotationController {
         }
     }
 
-
-
-    // 数据集的导入和导出。
-
-
     /**
      * 文档标注数据存储接口-实体。
      * 同时注意数据回显。
@@ -218,6 +216,36 @@ public class AnnotationController {
     }
 
 
+    //
+    /**
+     * 数据集的导入和导出。
+     */
+    @PostMapping("/exportDatabase")
+    @ResponseBody
+    public void exportDatabase(@RequestBody AnnotationToAlg annotationToAlg, HttpServletRequest request, HttpServletResponse response){
+        log.info("export annotationToAlg param--->:{}",JSON.toJSONString(annotationToAlg));
+        // generateGraphService.exportByExcel(annotationToAlg, request, response);
+    }
+
+    // 停止生成图谱。
+    /**
+     * 前端传入知识库id,后端调用算法停止生成图谱。
+     * 后端请求算法--->入参taskId。
+     *
+     * @return
+     */
+    @ApiOperation("停止生成图谱")
+    @ApiImplicitParam(name = "kgId", value = "图谱id")
+    @GetMapping("/stopKgGraph")
+    public AjaxResult stopKgGraph(@RequestParam("kgId") String kgId) {
+        if (null != kgId && StringUtils.isNotEmpty(kgId)) {
+            log.info("---> kgId:{}", kgId);
+            return AjaxResult.success("停止生成图谱", generateGraphService.stopGraphByTaskId(kgId));
+        }
+        return AjaxResult.error(1001, "参数不能为空");
+    }
+
+
     // ----------------------------以下接口均为模拟算法测试接口,后续可删除下列接口------------------------------------。
 
     @ApiOperation("算法 接收标注信息接口 结束后可删除")

+ 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{" +

+ 7 - 0
src/main/java/com/pavis/backend/slim/project/system/service/GenerateGraphService.java

@@ -25,4 +25,11 @@ public interface GenerateGraphService extends IService<GenerateGraph> {
      * @return
      */
     Boolean createGenerateKgGraphResult(String taskId,String kgId,Boolean isGenerate);
+
+    /**
+     * 前端传入知识库id,后端调用算法停止生成图谱。 后端请求算法--->入参taskId。
+     * @param kgId
+     * @return
+     */
+    Boolean stopGraphByTaskId(String kgId);
 }

+ 6 - 0
src/main/java/com/pavis/backend/slim/project/system/service/SysFileService.java

@@ -118,4 +118,10 @@ public interface SysFileService extends IService<SysFile> {
      * 知识库上传文档时,调用算法去解析文档内容为txt。
      */
     void convertfileToTxtByAlg(SysFile sysFile);
+
+    /**
+     * 根据文件id更新text解析内容。
+     * @param fileId
+     */
+    void upFileTextContentByFileId(String fileId,String textContent);
 }

+ 7 - 0
src/main/java/com/pavis/backend/slim/project/system/service/SysKgService.java

@@ -127,4 +127,11 @@ public interface SysKgService extends IService<SysKg> {
      * @return 图谱详情
      */
     SysKg updateKg(SysKg sysKg);
+
+    /**
+     * 停止生成图谱状态更新。
+     * @param kgId
+     * @return
+     */
+    Boolean stopGraph(String kgId);
 }

+ 28 - 6
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,6 +47,9 @@ 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);
@@ -55,6 +59,7 @@ public class AnnotationListServiceImpl extends ServiceImpl<AnnotationListMapper,
             toAlgTxt(annotationLists);
             annotationLists = baseMapper.selectAnnotationList(annotationListParam);
         }
+        log.info("annotationListsannotationLists:{}",JSON.toJSONString(annotationLists));
         PageHelper.startPage(annotationListParam.getPageNum(), annotationListParam.getPageSize());
         PageInfo page = new PageInfo(annotationLists);
         return page;
@@ -80,6 +85,8 @@ public class AnnotationListServiceImpl extends ServiceImpl<AnnotationListMapper,
             if (1 == importAnnotationDataset.getImportType()) {
                 annotationList.setParseStatus(1);
                 annotationList.setAnnotationStatus(0);
+                annotationList.setCreateTime(DateUtil.date());
+                annotationList.setCreateBy(SecurityUtils.getUsername());
                 // 判重处理。
                 // List<AnnotationList> annotations = baseMapper.selectList(new QueryWrapper<AnnotationList>().lambda().eq(AnnotationList::getKgId, importAnnotationDataset.getKgId())
                 //         .eq(AnnotationList::getFileId, importDataset.getFileId()));
@@ -139,7 +146,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);
@@ -173,19 +180,24 @@ public class AnnotationListServiceImpl extends ServiceImpl<AnnotationListMapper,
         Map<String, Object> algMap = new HashMap<>();
         algMap.put("fileIds", fileIds);
         log.info("algMap:{}", JSON.toJSONString(algMap));
-        String algTxtTmp = algKgClient.getAlgTxt(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);
+                // List<ConvertAlgRes> convertAlgRes = JSONArray.parseArray(algTxtTmp, ConvertAlgRes.class);
+                List<ConvertAlgRes> convertAlgRes = JSONArray.parseArray(algTxtTmp.toString(), ConvertAlgRes.class);
+                // List<ConvertAlgRes> convertAlgRes = algTxtTmp;
+                log.info("单独text:{}",algTxtTmp.toString());
                 log.info("解析算法返回数据convertAlgRes:{}",JSON.toJSONString(convertAlgRes));
+                log.info("解析算法返回数据convertAlgRes2:{}",convertAlgRes.toString());
                 if (!CollectionUtils.isEmpty(convertAlgRes)) {
                     for (ConvertAlgRes algRes : convertAlgRes) {
+                        log.info("algResalgResalgRes:{}",algRes.getText());
                         if (null != algRes.getErrorCode() && "0".equals(algRes.getErrorCode())) {
                             // 调用算法接口成功,并且解析txt文件成功,将文本内容更新至sysFile的textContent字段中。
                             for (AnnotationList hasNullText : hasNullTexts) {
@@ -197,10 +209,17 @@ 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.setCreateTime(DateUtil.date());
+                                        hasNullText.setCreateBy(SecurityUtils.getUsername());
                                         int saveRes = baseMapper.insert(hasNullText);
                                         log.info("新增文本内容结果updateText:{}", saveRes);
+                                        // 更新sysfile的textcontent值。
+                                        sysFileService.upFileTextContentByFileId(hasNullText.getFileId(),algRes.getText());
                                     }
                                 }
                             }
@@ -208,9 +227,12 @@ 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.setCreateTime(DateUtil.date());
+                                    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));

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

@@ -9,6 +9,7 @@ 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.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.SysEntity;
@@ -21,6 +22,7 @@ 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.EntityLablesRelationService;
 import com.pavis.backend.slim.project.system.service.EntityLablesSpanService;
@@ -70,6 +72,9 @@ public class EntityLabelsRelationServiceImpl extends ServiceImpl<EntityLabelsRel
     @Autowired
     private GenerateGraphService generateGraphService;
 
+    @Autowired
+    private AnnotationListMapper annotationListMapper;
+
     @Override
     public EntityLabelsRelation saveAnnotationRelation(AnnotationEntityRelation relation) {
         EntityLabelsRelation entityLabelsRelation = new EntityLabelsRelation();
@@ -89,9 +94,12 @@ public class EntityLabelsRelationServiceImpl extends ServiceImpl<EntityLabelsRel
         // 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 (null != fileTextContent && StringUtils.isNotBlank(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,7 +109,7 @@ 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()).entities(entities).relations(relations)
                     .entityList(entityLists).relationList(relationLists).build();
             return toAnnotation;
         }
@@ -142,7 +150,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();
@@ -159,7 +167,7 @@ public class EntityLabelsRelationServiceImpl extends ServiceImpl<EntityLabelsRel
             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));
+            String schemaImportRes = algKgClient.sendEntityRelationToAlg(schemaImport);
             log.info("调用算法服务的schemaImport服务发送实体和关系属性数据结果 schemaImportRes:{}",JSON.toJSONString(schemaImportRes));
             if ("ok".equals(schemaImportRes)){
                 // 2.2 todo 当前版本已弃用: 如果该图谱的创建了实体和关系数据,则调用算法的生成图谱服务,即入参为:text、实体标注数据列表、实体关系标注数据列表。
@@ -168,18 +176,24 @@ public class EntityLabelsRelationServiceImpl extends ServiceImpl<EntityLabelsRel
                 // 3.判断是否存在标注数据:有标注数据:请求labels/import,返回OK,继续调用获取taskId;
                 AnnotationToAlg annotationToAlg = AnnotationToAlg.builder().kgId(kgId).annotationDatas(annotationDatas).build();// 算法所需数据结构。
                 log.info("标注数据待发送至算法数据结构annotationToAlg:{}", JSON.toJSONString(annotationToAlg));
+                log.info("is json annotationToAlg:{}",CommonUtils.isJson(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 +204,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;
@@ -208,8 +222,10 @@ public class EntityLabelsRelationServiceImpl extends ServiceImpl<EntityLabelsRel
         List<AnnotationData> annotationDatas = new ArrayList<>();// 图谱下的所有文档标注信息。
         for (String fileId : fileIds) {
             String fileTextContent = sysFileService.getFileTextContent(fileId);
+            // List<AnnotationList> annotationLists = annotationListMapper.selectList(new QueryWrapper<AnnotationList>().lambda().eq(AnnotationList::getKgId, kgId).eq(AnnotationList::getFileId, fileId));
+            // fileTextContent = !CollectionUtils.isEmpty(annotationLists) ? annotationLists.get
             if (null != fileTextContent && StringUtils.isNotBlank(fileTextContent)) {
-                log.info("文本内容不为空:{}", fileTextContent);
+                // log.info("文本内容不为空:{}", fileTextContent);
                 log.info("--->fileId:{}", fileId);
                 // 获取历史标注实体信息数据列表,即知识库下的实体标注信息列表。
                 List<AnnotationEntity> entities = entityLablesSpanService.getAnnotationEntityByKgIdAndFileId(kgId, fileId);

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

@@ -1,9 +1,14 @@
 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 +19,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 +36,9 @@ public class GenerateGraphServiceImpl extends ServiceImpl<GenerateGraphMapper, G
     @Autowired
     private SysKgService sysKgService;
 
+    @Autowired
+    private AlgKgClient algKgClient;
+
 
     @Override
     public void generateKgGraphResult(GenerateGraphResult genGraphResult) {
@@ -77,6 +87,51 @@ public class GenerateGraphServiceImpl extends ServiceImpl<GenerateGraphMapper, G
         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;
+    }
+
     /**
      * 处理解析状态。
      *

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

@@ -375,6 +375,15 @@ 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);
+        }
+    }
 
 
     /**

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

@@ -76,7 +76,7 @@ public class SysKbServiceImpl extends ServiceImpl<SysKbMapper, SysKb> implements
 
     @Override
     public List<SysKb> selectByUser(Long userId) {
-        return query().eq("user_id", userId).list();
+        return query().eq("user_id", userId).orderByDesc("create_time").list();
     }
 
 

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

@@ -47,6 +47,7 @@ import org.apache.commons.lang3.StringUtils;
 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 java.util.ArrayList;
 import java.util.Arrays;
@@ -110,6 +111,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
@@ -171,7 +173,7 @@ public class SysKgServiceImpl extends ServiceImpl<SysKgMapper, SysKg> implements
 
     @Override
     public List<SysKg> list(SysKg kg) {
-        return baseMapper.selectList(new QueryWrapper<SysKg>().eq("user_id", SecurityUtils.getUserId()));
+        return baseMapper.selectList(new QueryWrapper<SysKg>().eq("user_id", SecurityUtils.getUserId()).orderByDesc("create_time"));
     }
 
     @Override
@@ -240,6 +242,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);
                     }
                 }
@@ -661,6 +665,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;
@@ -674,4 +679,29 @@ public class SysKgServiceImpl extends ServiceImpl<SysKgMapper, SysKg> implements
         baseMapper.updateById(sysKg);
         return sysKg;
     }
+
+    @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;
+    }
 }

+ 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