|
@@ -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) {
|