Ver código fonte

修复导入导出schema的bug

guanz 1 ano atrás
pai
commit
e1e6642878

+ 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;
+    }
+
 }

+ 1 - 0
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;
             }

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

@@ -738,10 +738,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;
@@ -770,9 +772,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 {