|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
package com.supervision.police.service.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import com.alibaba.druid.util.StringUtils;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
|
|
@ -431,20 +432,61 @@ public class ModelRecordTypeServiceImpl extends ServiceImpl<ModelRecordTypeMappe
|
|
|
|
|
Rel rel = new Rel(startNode.getId(), tripleInfo.getRelation(), endNode.getId());
|
|
|
|
|
Rel relation = neo4jService.findRelation(rel);
|
|
|
|
|
if (relation == null) {
|
|
|
|
|
neo4jService.saveRelation(rel);
|
|
|
|
|
relation = neo4jService.saveRelation(rel);
|
|
|
|
|
}
|
|
|
|
|
tripleInfo.setAddNeo4j("1");
|
|
|
|
|
tripleInfo.setStartNodeGraphId(startNode.getId());
|
|
|
|
|
tripleInfo.setRelGraphId(relation.getId());
|
|
|
|
|
tripleInfo.setEndNodeGraphId(endNode.getId());
|
|
|
|
|
boolean updateResult = tripleInfoService.updateById(tripleInfo);
|
|
|
|
|
if (updateResult) {
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
// TODO 重复添加的OK了,删除的呢?
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error(e.getMessage(), e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 删除的要进行移除
|
|
|
|
|
Optional<TripleInfo> any = tripleInfos.stream().findAny();
|
|
|
|
|
if (any.isPresent()) {
|
|
|
|
|
TripleInfo anyTripleInfo = any.get();
|
|
|
|
|
String recordId = anyTripleInfo.getRecordId();
|
|
|
|
|
List<TripleInfo> existNeoList = tripleInfoService.lambdaQuery().eq(TripleInfo::getRecordId, recordId).eq(TripleInfo::getAddNeo4j, "1").list();
|
|
|
|
|
Map<String, TripleInfo> existNeoMap = existNeoList.stream().collect(Collectors.toMap(TripleInfo::getId, Function.identity()));
|
|
|
|
|
// 去掉已经添加的
|
|
|
|
|
Set<String> existNeoIdSet = existNeoMap.keySet();
|
|
|
|
|
ids.forEach(existNeoIdSet::remove);
|
|
|
|
|
// 剩下的就是需要删除的
|
|
|
|
|
for (String needDeleteId : existNeoIdSet) {
|
|
|
|
|
TripleInfo tripleInfo = existNeoMap.get(needDeleteId);
|
|
|
|
|
if (ObjectUtil.isNotEmpty(tripleInfo.getRelGraphId())) {
|
|
|
|
|
// 先移除关系
|
|
|
|
|
neo4jService.deleteRel(tripleInfo.getRelGraphId());
|
|
|
|
|
} else {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (ObjectUtil.isNotEmpty(tripleInfo.getStartNodeGraphId())) {
|
|
|
|
|
// 再移除尾节点
|
|
|
|
|
neo4jService.delNode(tripleInfo.getEndNodeGraphId());
|
|
|
|
|
} else {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (ObjectUtil.isNotEmpty(tripleInfo.getEndNodeGraphId())) {
|
|
|
|
|
// 尝试删除头节点(只有头节点不存在任何关系的时候才进行删除)
|
|
|
|
|
neo4jService.deleteNoRelationNode(tripleInfo.getStartNodeGraphId());
|
|
|
|
|
} else {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
// 更新状态
|
|
|
|
|
tripleInfoService.lambdaUpdate().set(TripleInfo::getAddNeo4j, "0")
|
|
|
|
|
.set(TripleInfo::getEndNodeGraphId, null)
|
|
|
|
|
.set(TripleInfo::getRelGraphId, null)
|
|
|
|
|
.set(TripleInfo::getStartNodeGraphId, null)
|
|
|
|
|
.eq(TripleInfo::getId, needDeleteId).update();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ("成功插入" + i + "条信息");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|