浏览代码

Merge remote-tracking branch 'origin/gz-en-base' into enen

zhangenzhi 1 年之前
父节点
当前提交
c8fbd6597d

+ 40 - 0
src/main/java/com/pavis/backend/slim/common/utils/CommonUtils.java

@@ -1,5 +1,6 @@
 package com.pavis.backend.slim.common.utils;
 
+import cn.hutool.core.date.DateUtil;
 import com.alibaba.fastjson2.JSON;
 import com.alibaba.fastjson2.JSONArray;
 import com.alibaba.fastjson2.JSONObject;
@@ -77,4 +78,43 @@ public class CommonUtils {
         return false;
     }
 
+    public static void main(String[] args) {
+        String entityStr = "[{\"name\":\"运动员\",\"id\":\"2adb14be-0e9e-456c-9554-99e917223b4c\",\"defaultName\":0,\"color\":\"#448DFF\",\"describe\":[{\"describeName\":\"名字\",\"describeType\":\"STRING\",\"notes\":\"\",\"compressedStorage\":false,\"creatingAnIndex\":false},{\"describeName\":\"国籍\",\"describeType\":\"STRING\",\"notes\":\"\",\"compressedStorage\":false,\"creatingAnIndex\":false},{\"describeName\":\"身高\",\"describeType\":\"STRING\",\"notes\":\"\",\"compressedStorage\":false,\"creatingAnIndex\":false},{\"describeName\":\"出生地\",\"describeType\":\"STRING\",\"notes\":\"\",\"compressedStorage\":false,\"creatingAnIndex\":false},{\"describeName\":\"获得\",\"describeType\":\"STRING\",\"notes\":\"\",\"compressedStorage\":false,\"creatingAnIndex\":false}],\"entityId\":\"65d28abb076b84bc9b384bce57ab28ea\",\"createTime\":1701323995933}, {\"name\":\"比赛\",\"id\":\"d25c39f7-4c6e-4155-8e9b-34a8cfca7ed2\",\"defaultName\":0,\"color\":\"#6517EB\",\"describe\":[{\"describeName\":\"名字\",\"describeType\":\"STRING\",\"notes\":\"\",\"compressedStorage\":false,\"creatingAnIndex\":false},{\"describeName\":\"赛事级别\",\"describeType\":\"STRING\",\"notes\":\"\",\"compressedStorage\":false,\"creatingAnIndex\":false},{\"describeName\":\"时间\",\"describeType\":\"STRING\",\"notes\":\"\",\"compressedStorage\":false,\"creatingAnIndex\":false}],\"entityId\":\"87561e713eac62fa4ae14aea3c84c89e\",\"createTime\":1701323995933}, {\"name\":\"荣誉\",\"id\":\"96d30cd1-474b-4a4c-9f7f-cb12714ff4ac\",\"defaultName\":0,\"color\":\"#EF0C0C\",\"describe\":[{\"describeName\":\"名字\",\"describeType\":\"STRING\",\"notes\":\"\",\"compressedStorage\":false,\"creatingAnIndex\":false},{\"describeName\":\"级别\",\"describeType\":\"STRING\",\"notes\":\"\",\"compressedStorage\":false,\"creatingAnIndex\":false}],\"entityId\":\"716af5482d843823cffb120e8af0aa17\",\"createTime\":1701324123988}]";
+        JSONArray entity = JSONArray.parseArray(entityStr);
+        // 处理前端传输的实体数据。
+        JSONArray entityFinal = dealEntityId(entity);
+        log.info("entityFinal:{}",JSON.toJSONString(entityFinal));
+
+        String relStr = "[{\"id\":\"624e0255-4d4a-4e53-9724-af979c7a9d3f\",\"relation\":\"参加\",\"start\":\"2adb14be-0e9e-456c-9554-99e917223b4c\",\"startName\":\"运动员\",\"end\":\"d25c39f7-4c6e-4155-8e9b-34a8cfca7ed2\",\"endName\":\"比赛\",\"direction\":0,\"styleEntity\":\"#EF3D3D\",\"describe\":[],\"isAt\":0,\"relationId\":\"f45e6316d258e96b733ada28df424f46\"}, {\"id\":\"c405f16e-a606-4404-bc2a-1807c1473bd9\",\"relation\":\"获得\",\"start\":\"2adb14be-0e9e-456c-9554-99e917223b4c\",\"startName\":\"运动员\",\"end\":\"96d30cd1-474b-4a4c-9f7f-cb12714ff4ac\",\"endName\":\"荣誉\",\"direction\":0,\"styleEntity\":\"#EA2182\",\"describe\":[],\"isAt\":0,\"relationId\":\"195f55d774e9b9adda80325f9a95a86b\"}]";
+        JSONArray relation = JSONArray.parseArray(relStr);
+        // 处理前端传输的实体关系数据。
+
+    }
+    public static JSONArray dealEntityId(JSONArray jsonArray){
+        // 处理所有的实体ID,设置null。
+        for (int i = 0; i < jsonArray.size(); i++) {
+            JSONObject jsonObject = JSON.parseObject(jsonArray.get(i).toString());
+            if (jsonObject.containsKey("entityId")){
+                jsonObject.put("entityId",null);
+                jsonObject.put("createTime", DateUtil.date());
+                log.info("包含entityId:{}",JSON.toJSONString(jsonObject));
+            }
+            jsonArray.set(i,jsonObject);
+        }
+        return jsonArray;
+    }
+
+    public static JSONArray dealRelationId(JSONArray jsonArray){
+        // 处理所有的实体ID,设置null。
+        for (int i = 0; i < jsonArray.size(); i++) {
+            JSONObject jsonObject = JSON.parseObject(jsonArray.get(i).toString());
+            if (jsonObject.containsKey("relationId")){
+                jsonObject.put("relationId",null);
+                log.info("包含entityId");
+            }
+            jsonArray.set(i,jsonObject);
+        }
+        return jsonArray;
+    }
+
 }

+ 11 - 0
src/main/java/com/pavis/backend/slim/project/system/controller/AnnotationController.java

@@ -271,6 +271,17 @@ public class AnnotationController {
         return AjaxResult.error(1001, "参数不能为空");
     }
 
+    @ApiOperation("用户手动解析txt文本内容接口")
+    @GetMapping("/handsToParseTxt")
+    public AjaxResult handsToParseTxt(@RequestParam("kgId") String kgId,@RequestParam("fileId") String fileId) {
+        log.info("用户手动解析txt文本内容 kgId:{},fileId:{}",kgId,fileId);
+        if (null != kgId && StringUtils.isNotEmpty(kgId) && null != fileId && StringUtils.isNotEmpty(fileId)) {
+
+            return AjaxResult.success("算法通知后端更新文本内容成功");
+        }
+        return AjaxResult.error(1001, "参数不能为空");
+    }
+
 
     // todo ----------------------------以下接口均为模拟算法测试接口,后续可删除下列接口------------------------------------。
 

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

@@ -30,7 +30,8 @@ public class RelationForAlg {
      * 关系ID
      */
     @ApiModelProperty("关系ID")
-    private Long id;
+    // private Long id;
+    private String id;
 
     /**
      * 类目/起始点类型

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

@@ -127,4 +127,14 @@ public interface SysFileService extends IService<SysFile> {
      * @param fileId
      */
     void upFileTextContentByFileId(String fileId, String textContent);
+
+
+
+    /**
+     * 手动请求算法获取txt文本内容,算法结束后通知后端更新状态。
+     * @param kgId
+     * @param fileId
+     * @return
+     */
+    Boolean handsToParseTxt(String kgId, String fileId);
 }

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

@@ -158,6 +158,7 @@ public class AnnotationListServiceImpl extends ServiceImpl<AnnotationListMapper,
         if (annotationLists.size() > 0) {
             for (AnnotationList annotationList : annotationLists) {
                 annotationList.setTextFront(annotationFront.getTextFront());
+                annotationList.setAnnotationStatus(1);
                 int upRes = baseMapper.updateById(annotationList);
                 return upRes > 0 ? true : false;
             }
@@ -241,5 +242,4 @@ public class AnnotationListServiceImpl extends ServiceImpl<AnnotationListMapper,
             log.info("获取算法解析txt文本内容返回结果接口异常 ex convertToTxtResTmp:{}", algTxtTmp);
         }
     }
-
 }

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

@@ -261,6 +261,12 @@ 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));
+            String textFront = "";
+            if (!CollectionUtils.isEmpty(annotationLists)){
+                textFront = annotationLists.get(0).getTextFront();
+            }
             if (null != fileTextContent && StringUtils.isNotBlank(fileTextContent)) {
                 // log.info("文本内容不为空:{}", fileTextContent);
                 log.info("--->fileId:{}", fileId);
@@ -272,7 +278,7 @@ public class EntityLabelsRelationServiceImpl extends ServiceImpl<EntityLabelsRel
                     // 获取历史标注实体间关系数据列表,即图谱下的实体关系标注信息列表。
                     List<AnnotationEntityRelation> relations = getAnnotationEntityRelationByKgIdAndFileId(kgId, fileId);
                     log.info("--->relations:{}", entities.size());
-                    AnnotationData annotationData = AnnotationData.builder().text(fileTextContent).entities(entities).relations(relations).build();
+                    AnnotationData annotationData = AnnotationData.builder().text(fileTextContent).textFront(textFront).entities(entities).relations(relations).build();
                     annotationDatas.add(annotationData);
                 }
             }

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

@@ -402,6 +402,33 @@ public class SysFileServiceImpl extends ServiceImpl<SysFileMapper, SysFile> impl
         }
     }
 
+    @Override
+    public Boolean handsToParseTxt(String kgId, String fileId) {
+        List<SysFile> sysFiles = baseMapper.selectList(new QueryWrapper<SysFile>().lambda().eq(SysFile::getFileId, fileId));
+        String objectKey = "";
+        String identifier = "";
+        if (!CollectionUtils.isEmpty(sysFiles)){
+            objectKey = sysFiles.get(0).getObjectKey();
+            identifier = sysFiles.get(0).getIdentifier();
+        }
+        List<ConvertDocToTxt> convertDocToTxts = new ArrayList<>();
+        convertDocToTxts.add(ConvertDocToTxt.builder().fileId(fileId).objectKey(objectKey).identifier(identifier).isNew(false).build());
+        if (!CollectionUtils.isEmpty(convertDocToTxts)) {
+            Map<String, Object> algMap = new HashMap<>();
+            algMap.put("files", convertDocToTxts);
+            try {
+                // 调用算法,获取文档转换为txt的文本内容。
+                String convertToTxtResTmp = algKgClient.convertToTxt(JSON.toJSONString(algMap));
+                dealAlgTxtRes(convertToTxtResTmp);
+            }catch (Exception ex){
+                ex.printStackTrace();
+                log.info("手动调用算法获取txt文本内容返回结果 ex:{}",ex);
+                return false;
+            }
+        }
+        return true;
+    }
+
 
     /**
      * 用户编辑的文件上传至minio中。

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

@@ -740,10 +740,12 @@ public class SysKgServiceImpl extends ServiceImpl<SysKgMapper, SysKg> implements
         if (null != sysEntityAll){
             ExportSysEntity exportSysEntity = new ExportSysEntity();
             BeanUtils.copyProperties(sysEntityAll,exportSysEntity);
-            exportSysEntity.setEntityAll(JSONArray.parseArray(sysEntityAll.getEntityAll()));
+            exportSysEntity.setEntityAll(CommonUtils.dealEntityId(JSONArray.parseArray(sysEntityAll.getEntityAll())));
             exportSysEntity.setEntityKgAll(JSONArray.parseArray(sysEntityAll.getEntityKgAll()));
-            exportSysEntity.setRelationAll(JSONArray.parseArray(sysEntityAll.getRelationAll()));
+            exportSysEntity.setRelationAll(CommonUtils.dealRelationId(JSONArray.parseArray(sysEntityAll.getRelationAll())));
             exportSysEntity.setRelationKgAll(JSONArray.parseArray(sysEntityAll.getRelationKgAll()));
+            exportSysEntity.setEntityId(null);
+
             String fileType = ".json";
             String fileName = FileUtils.genFileName(exportSchemaData.getKgId() + "-" + System.currentTimeMillis()) + fileType;
             String finalPath = filePath + fileName;
@@ -772,9 +774,26 @@ public class SysKgServiceImpl extends ServiceImpl<SysKgMapper, SysKg> implements
         if (null != sysEntityAll) {
             SysEntity sysEntity = new SysEntity();
             BeanUtils.copyProperties(sysEntityAll, sysEntity);
+            // // 处理前端存储的实体和关系数据。
+            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()));
+
+
             sysEntity.setKgId(kgId);
+            sysEntity.setEntityId(null);
+            sysEntity.setUserId(SecurityUtils.getUserId());
+            sysEntity.setCreateTime(DateUtil.date());
+            sysEntity.setEntityId("-1");
+            log.info("待导入schema的kgId:{}",kgId);
             log.info("待导入的图谱shcema数据 sysEntity:{}", JSON.toJSONString(sysEntity));
             SysEntityAll entityKg = createEntityKg(sysEntity);
+            // int insert = sysEntityMapper.insert(sysEntity);
+            // SysEntityAll entityKg = new SysEntityAll();
+            // BeanUtils.copyProperties(sysEntityAll,entityKg);
             log.info("插入导入的图谱schema数据 sysEntity:{}", JSON.toJSONString(sysEntity));
             return entityKg;
         } else {