allen 2 年之前
父节点
当前提交
ee9ef6ffa4
共有 1 个文件被更改,包括 9 次插入3 次删除
  1. 9 3
      kgraph-graph/src/main/java/com/kgraph/graph/neo4j/seavice/impl/KgServiceImpl.java

+ 9 - 3
kgraph-graph/src/main/java/com/kgraph/graph/neo4j/seavice/impl/KgServiceImpl.java

@@ -47,15 +47,21 @@ public class KgServiceImpl implements IKgService {
             if (newEntity != null) {
                 // 如果已经在db中则替换
                 entityMap.put(entity.getName(), newEntity);
+            } else {
+                Neo4jEntity save = entityRepository.save(entity);
+                entityMap.put(entity.getName(), save);
             }
         }
 
         // build relation
         List<Neo4jRelation> relationList = buildRelation(kgDTOList, entityMap);
-        // 剔除已有的关系
-        relationList.removeIf(this::relationExist);
         // save entity and relation
-        relationRepository.saveAll(relationList);
+        for (Neo4jRelation neo4jRelation : relationList) {
+            // 如果不存在则跳过
+            if(!relationExist(neo4jRelation)){
+                relationRepository.save(neo4jRelation);
+            }
+        }
     }
 
     private boolean relationExist(Neo4jRelation relation) {