瀏覽代碼

实体名称修改后相应的标注数据的实体名称亦修改;去标注接口调整

guanz 1 年之前
父節點
當前提交
97435da9ee

+ 4 - 1
src/main/java/com/pavis/backend/slim/common/utils/CommonUtils.java

@@ -125,6 +125,7 @@ public class CommonUtils {
      * @return
      */
     public static String dealTextFrontWithColor(String textFront, String entityName,String colorStr,String nameStr) {
+        log.info("正则匹配替换颜色或名称 sourceName:{},upName:{}",entityName,nameStr);
         String regex = "<span[^>]*data-before=\"" + entityName + "\"[^>]*>([^<]+)<\\/span>";
         log.info("regex:{}", regex);
         Pattern pattern = Pattern.compile(regex);
@@ -136,7 +137,9 @@ public class CommonUtils {
             log.info("matcher[0]:{}",matcher.group(0));
             String replacedStr = matcher.group(0).replaceAll("--color: #[0-9a-fA-F]{6}", "--color:" + colorStr);
             replacedStr = replacedStr.replaceAll("--color:#[0-9a-fA-F]{6}", "--color:" + colorStr);
-            replacedStr = replacedStr.replaceAll("data-before=\"" + entityName + "\"", "data-before=\"" + nameStr + "\"");
+            if (null != nameStr && StringUtils.isNotEmpty(nameStr)){
+                replacedStr = replacedStr.replaceAll("data-before=\"" + entityName + "\"", "data-before=\"" + nameStr + "\"");
+            }
             log.info("replacedStr:{}",replacedStr);
             matcher.appendReplacement(upTextFront, replacedStr);
         }

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

@@ -177,10 +177,10 @@ public class AnnotationController {
     @ApiOperation("去标注接口")
     @ApiImplicitParam(name = "fileId", value = "文档id")
     @GetMapping("/toAnnotation")
-    public AjaxResult toAnnotation(@RequestParam("kgId") String kgId, @RequestParam("fileId") String fileId) {
-        if (null != kgId && null != fileId && StringUtils.isNotEmpty(kgId) && StringUtils.isNotEmpty(fileId)) {
+    public AjaxResult toAnnotation(@RequestParam("id") String id, @RequestParam("kgId") String kgId, @RequestParam("fileId") String fileId) {
+        if (null != id && null != id && StringUtils.isNotEmpty(id) && null != kgId && null != fileId && StringUtils.isNotEmpty(kgId) && StringUtils.isNotEmpty(fileId)) {
             log.info("kgId:{},fileId:{}", kgId, fileId);
-            return AjaxResult.success("标注数据获取成功", entityLablesRelationService.toAnnotation(kgId, fileId));
+            return AjaxResult.success("标注数据获取成功", entityLablesRelationService.toAnnotation(id, kgId, fileId));
         }
         return AjaxResult.error(1001, "参数不能为空");
     }

+ 4 - 5
src/main/java/com/pavis/backend/slim/project/system/controller/SysKgController.java

@@ -3,12 +3,11 @@ 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;
 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.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.CreateEntityKg;
 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.service.SysEntityService;
@@ -91,8 +90,7 @@ public class SysKgController {
     @ApiOperation("接收算法返回数据接口")
     @PostMapping("/algorithm")
     public AjaxResult algorithm(@RequestBody AlgSpO algSpO) {
-        kgService.algorithm(algSpO);
-        return AjaxResult.success();
+        return AjaxResult.success(kgService.algorithm(algSpO));
     }
 
     @ApiOperation("删除图谱")
@@ -138,7 +136,8 @@ public class SysKgController {
 
     @ApiOperation("实体,实体关系创建(前段所传纹丝不动保存)")
     @PostMapping("/createEntityKg")
-    public AjaxResult createEntityKg(@RequestBody SysEntity sysEntityAll) {
+    // public AjaxResult createEntityKg(@RequestBody SysEntity sysEntityAll) {
+    public AjaxResult createEntityKg(@RequestBody CreateEntityKg sysEntityAll) {
         return AjaxResult.success(kgService.createEntityKg(sysEntityAll));
     }
 

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

@@ -0,0 +1,26 @@
+package com.pavis.backend.slim.project.system.domain.annotation;
+
+import com.pavis.backend.slim.project.system.domain.SysEntity;
+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:
+ * @date: 2023-12-12 11:20
+ */
+// @SuperBuilder
+@Builder
+@Getter
+@Setter
+@AllArgsConstructor
+@NoArgsConstructor
+public class CreateEntityKg extends SysEntity {
+    @ApiModelProperty("实体名称更新")
+    private String upName;
+}

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

@@ -21,6 +21,9 @@ import java.util.List;
 @AllArgsConstructor
 @NoArgsConstructor
 public class ExportAnnotationData {
+    // 图谱ID。
+    @ApiModelProperty("主键ID")
+    private String id;
     // 图谱ID。
     @ApiModelProperty("图谱ID")
     private String kgId;

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

@@ -38,7 +38,7 @@ public interface EntityLablesRelationService extends IService<EntityLabelsRelati
      * @param fileId
      * @return
      */
-    ToAnnotation toAnnotation(String kgId, String fileId);
+    ToAnnotation toAnnotation(String id, String kgId, String fileId);
 
     /**
      * 根据图谱id和文档id获取历史标注实体关系信息数据列表。

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

@@ -2,12 +2,12 @@ package com.pavis.backend.slim.project.system.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.github.pagehelper.PageInfo;
-import com.pavis.backend.slim.project.system.domain.SysEntity;
 import com.pavis.backend.slim.project.system.domain.SysEntityAll;
 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.CreateEntityKg;
 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;
@@ -49,7 +49,7 @@ public interface SysKgService extends IService<SysKg> {
      */
     List listKg();
 
-    void algorithm(AlgSpO algSpO);
+    Boolean algorithm(AlgSpO algSpO);
 
     /**
      * 删除图谱,可批量
@@ -80,7 +80,7 @@ public interface SysKgService extends IService<SysKg> {
      * @param sysEntityAll 前端传参数据
      * @return 前端所需要的返参数据
      */
-    SysEntityAll createEntityKg(SysEntity sysEntityAll);
+    SysEntityAll createEntityKg(CreateEntityKg sysEntityAll);
 
 
     /**

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

@@ -177,7 +177,7 @@ public class AnnotationListServiceImpl extends ServiceImpl<AnnotationListMapper,
                     // String upTextFront = CommonUtils.dealTextFrontWithColor(annotationList.getTextFront(), entityColor.getName(), entityColor.getColor(),"");
                     annotationList.setTextFront(upTextFront);
                     int upRes = baseMapper.updateById(annotationList);
-                    log.info("实体颜色变更后,更新textFront结果 upRes:{},colorAfter:{}", upRes, entityColor.getColor());
+                    log.info("实体名称OR颜色变更后,更新textFront结果 upRes:{},colorAfter:{}", upRes, entityColor.getColor());
                 }
             }
         }

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

@@ -116,12 +116,12 @@ public class EntityLabelsRelationServiceImpl extends ServiceImpl<EntityLabelsRel
     }
 
     @Override
-    public ToAnnotation toAnnotation(String kgId, String fileId) {
+    public ToAnnotation toAnnotation(String id, String kgId, String fileId) {
         // 1.根据fileId获取文本信息text、历史标注的实体信息列表、历史标注的实体间关系信息列表。
         // List<TreeFile> treeFiles = sysFileService.listTreeFiles(kgId);
         // log.info("获取知识库下的文档信息treeFiles:{}",JSON.toJSONString(treeFiles));
         // String fileTextContent = sysFileService.getFileTextContent(fileId);
-        List<AnnotationList> annotationLists = annotationListMapper.selectList(new QueryWrapper<AnnotationList>().lambda().eq(AnnotationList::getKgId, kgId).eq(AnnotationList::getFileId, fileId));
+        List<AnnotationList> annotationLists = annotationListMapper.selectList(new QueryWrapper<AnnotationList>().lambda().eq(AnnotationList::getId, id).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());
@@ -300,7 +300,7 @@ public class EntityLabelsRelationServiceImpl extends ServiceImpl<EntityLabelsRel
         log.info("待导出的标注数据 annotationDatas:{}", JSON.toJSONString(annotationDatas));
         List<ToAnnotation> annotations = new ArrayList<>();
         for (String fileId : exportAnnotationData.getFileIds()) {
-            annotations.add(toAnnotation(exportAnnotationData.getKgId(), fileId));
+            annotations.add(toAnnotation(exportAnnotationData.getId(), exportAnnotationData.getKgId(), fileId));
         }
         log.info("待导出的标注数据 annotations:{}", JSON.toJSONString(annotations));
 

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

@@ -26,6 +26,7 @@ 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.CreateEntityKg;
 import com.pavis.backend.slim.project.system.domain.annotation.EntityColor;
 import com.pavis.backend.slim.project.system.domain.annotation.ExportSchemaData;
 import com.pavis.backend.slim.project.system.domain.annotation.ExportSysEntity;
@@ -206,7 +207,7 @@ public class SysKgServiceImpl extends ServiceImpl<SysKgMapper, SysKg> implements
     }
 
     @Override
-    public void algorithm(AlgSpO algSpO) {
+    public Boolean algorithm(AlgSpO algSpO) {
         log.info("算法传参map:{}", JSON.toJSONString(algSpO));
         // todo 先这么做,以后还需改动
         sysEntityInstanceMapper.delete(new QueryWrapper<SysEntityInstance>().eq("kg_id", algSpO.getKgId()));
@@ -215,6 +216,7 @@ public class SysKgServiceImpl extends ServiceImpl<SysKgMapper, SysKg> implements
         String oCopy = "";
         String sCopy = "";
         if (integer == 0) {
+            List<Integer> upLists = new ArrayList<>();
             for (Map map : algSpO.getSpo()) {
                 if (map.get("s") != null) {
                     // check库里是否存在此值
@@ -231,7 +233,8 @@ public class SysKgServiceImpl extends ServiceImpl<SysKgMapper, SysKg> implements
                         sysEntityInstanceS.setInstanceId(MD5.create().digestHex16((String) map.get("s")));
                         sysEntityInstanceS.setName((String) map.get("s"));
                         sysEntityInstanceS.setEntityName((String) map.get("sType"));
-                        sysEntityInstanceMapper.insert(sysEntityInstanceS);
+                        int insertRes = sysEntityInstanceMapper.insert(sysEntityInstanceS);
+                        upLists.add(insertRes);
                         sCopy = MD5.create().digestHex16((String) map.get("s"));
                     } else {
                         sCopy = s;
@@ -250,7 +253,8 @@ public class SysKgServiceImpl extends ServiceImpl<SysKgMapper, SysKg> implements
                         sysEntityInstanceO.setInstanceId(MD5.create().digestHex16((String) map.get("o")));
                         sysEntityInstanceO.setName((String) map.get("o"));
                         sysEntityInstanceO.setEntityName((String) map.get("oType"));
-                        sysEntityInstanceMapper.insert(sysEntityInstanceO);
+                        int insertRes = sysEntityInstanceMapper.insert(sysEntityInstanceO);
+                        upLists.add(insertRes);
                         oCopy = MD5.create().digestHex16((String) map.get("o"));
                     } else {
                         oCopy = o;
@@ -276,11 +280,15 @@ public class SysKgServiceImpl extends ServiceImpl<SysKgMapper, SysKg> implements
                         sysEntityRelation.setEntityRelation(map.get("sType") + "-" + map.get("pType") + "-" + map.get("oType"));
                         // 设置基本信息,创建人、创建时间等。
                         sysEntityRelation.setCreateTime(DateUtil.date());
-                        sysEntityRelationMapper.insert(sysEntityRelation);
+                        int insertRes = sysEntityRelationMapper.insert(sysEntityRelation);
+                        upLists.add(insertRes);
                     }
                 }
             }
+            log.info("后端存储算法图数据 upLists:{}",JSON.toJSONString(upLists));
+            return upLists.contains(0) ? false : true;
         }
+        return false;
     }
 
     /**
@@ -415,7 +423,7 @@ public class SysKgServiceImpl extends ServiceImpl<SysKgMapper, SysKg> implements
     }
 
     @Override
-    public SysEntityAll createEntityKg(SysEntity sysEntityAll) {
+    public SysEntityAll createEntityKg(CreateEntityKg sysEntityAll) {
         log.info("*********接口(createEntityKg)------>入参(sysEntityAll):{}", JSON.toJSONString(sysEntityAll));
 
         // zez 根据前端传参先进行删除需要删除的关系和实体
@@ -437,7 +445,22 @@ public class SysKgServiceImpl extends ServiceImpl<SysKgMapper, SysKg> implements
                     SysEntity sysEntity = sysEntityMapper.selectById(entityColor.getEntityId());
                     if (null != sysEntity) {
                         // 颜色发生变化,则更新标注的数据中的颜色,。
-                        entityColor.setUpName(sysEntity.getName());
+                        // entityColor.setUpName(sysEntity.getName());
+                        annotationListService.upTextFrontByColor(sysEntityAll.getKgId(), entityColor);
+                    }
+                }
+            }
+        }
+        // 处理前端标注数据的实体名称随实体名称的更新而更新值。
+        if (null != sysEntityAll && null != sysEntityAll.getUpName() && StringUtils.isNotEmpty(sysEntityAll.getUpName()) && CommonUtils.isJsonArray(sysEntityAll.getUpName())) {
+            List<EntityColor> entityColors = JSONArray.parseArray(sysEntityAll.getUpName(), EntityColor.class);
+            log.info("实体名称发生变化,需要处理 entityColors:{}", JSON.toJSONString(entityColors));
+            if (!CollectionUtils.isEmpty(entityColors)) {
+                for (EntityColor entityColor : entityColors) {
+                    SysEntity sysEntity = sysEntityMapper.selectById(entityColor.getEntityId());
+                    if (null != sysEntity) {
+                        // 颜色发生变化,则更新标注的数据中的颜色,。
+                        // entityColor.setUpName(sysEntity.getName());
                         annotationListService.upTextFrontByColor(sysEntityAll.getKgId(), entityColor);
                     }
                 }
@@ -792,7 +815,7 @@ public class SysKgServiceImpl extends ServiceImpl<SysKgMapper, SysKg> implements
         }
 
         if (null != sysEntityAll) {
-            SysEntity sysEntity = new SysEntity();
+            CreateEntityKg sysEntity = new CreateEntityKg();
             BeanUtils.copyProperties(sysEntityAll, sysEntity);
             // // 处理前端存储的实体和关系数据。
             ExportSysEntity exportSysEntity = new ExportSysEntity();