topo_dev
liu 10 months ago
parent c00a2c2da0
commit c99dcf02dd

@ -21,10 +21,14 @@ public class R<T> implements Serializable {
public static final String TOTAL_COUNT = "total"; public static final String TOTAL_COUNT = "total";
public static final String RESULT_LIST = "result"; public static final String RESULT_LIST = "result";
/** 成功 */ /**
*
*/
public static final int SUCCESS = Constants.SUCCESS; public static final int SUCCESS = Constants.SUCCESS;
/** 失败 */ /**
*
*/
public static final int FAIL = Constants.FAIL; public static final int FAIL = Constants.FAIL;
private int code; private int code;
@ -37,6 +41,14 @@ public class R<T> implements Serializable {
return restResult(null, SUCCESS, null); return restResult(null, SUCCESS, null);
} }
public static <T> R<T> judgeResult(Boolean bo, String successMessage, String failMessage) {
if (bo) {
return restResult(null, SUCCESS, successMessage);
} else {
return restResult(null, FAIL, failMessage);
}
}
public static <T> R<T> okMsg(String msg) { public static <T> R<T> okMsg(String msg) {
return restResult(null, SUCCESS, msg); return restResult(null, SUCCESS, msg);
} }
@ -73,7 +85,9 @@ public class R<T> implements Serializable {
return restResult(resultStatusEnum); return restResult(resultStatusEnum);
} }
public static <T> R<T> fail(ResultStatusEnum resultStatusEnum, T data) {return restResult(resultStatusEnum,data);} public static <T> R<T> fail(ResultStatusEnum resultStatusEnum, T data) {
return restResult(resultStatusEnum, data);
}
private static <T> R<T> restResult(ResultStatusEnum resultStatusEnum, T data) { private static <T> R<T> restResult(ResultStatusEnum resultStatusEnum, T data) {
R<T> apiResult = new R<>(); R<T> apiResult = new R<>();
@ -100,7 +114,6 @@ public class R<T> implements Serializable {
} }
public static Map<String, Object> buildDataMap(List list) { public static Map<String, Object> buildDataMap(List list) {
Map<String, Object> dataMap = new HashMap<>(); Map<String, Object> dataMap = new HashMap<>();
if (list == null) { if (list == null) {

@ -65,7 +65,8 @@ public class Neo4jController {
@PostMapping("/saveRelation") @PostMapping("/saveRelation")
public R<?> saveRelation(@RequestBody Rel rel) { public R<?> saveRelation(@RequestBody Rel rel) {
return neo4jService.saveRelation(rel); Boolean result = neo4jService.saveRelation(rel);
return R.judgeResult(result, null, "保存失败");
} }
/*************************************************************************************/ /*************************************************************************************/

@ -23,7 +23,7 @@ public interface Neo4jService {
Rel findRelation(Rel rel); Rel findRelation(Rel rel);
R<?> saveRelation(Rel rel); Boolean saveRelation(Rel rel);
R<?> getNode(String picType, String caseId); R<?> getNode(String picType, String caseId);

@ -198,7 +198,7 @@ public class Neo4jServiceImpl implements Neo4jService {
} }
@Override @Override
public R<?> saveRelation(Rel rel) { public Boolean saveRelation(Rel rel) {
Rel res = null; Rel res = null;
try { try {
Session session = driver.session(); Session session = driver.session();
@ -214,11 +214,7 @@ public class Neo4jServiceImpl implements Neo4jService {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
if (rel != null) { return rel != null;
return R.ok(rel);
} else {
return R.fail("保存失败");
}
} }
@Override @Override

@ -1,5 +1,6 @@
package com.supervision.police.service.impl; package com.supervision.police.service.impl;
import cn.hutool.core.util.StrUtil;
import com.alibaba.druid.util.StringUtils; import com.alibaba.druid.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@ -121,7 +122,7 @@ public class ModelRecordTypeServiceImpl extends ServiceImpl<ModelRecordTypeMappe
} }
} }
private List<TripleInfo> extractThreeInfo(String caseId, String name, String recordId) { private List<TripleInfo> extractTripleInfo(String caseId, String name, String recordId) {
List<NoteRecord> records = noteRecordMapper.selectRecord(caseId, name, recordId); List<NoteRecord> records = noteRecordMapper.selectRecord(caseId, name, recordId);
List<TripleInfo> tripleInfos = new ArrayList<>(); List<TripleInfo> tripleInfos = new ArrayList<>();
for (NoteRecord record : records) { for (NoteRecord record : records) {
@ -150,9 +151,8 @@ public class ModelRecordTypeServiceImpl extends ServiceImpl<ModelRecordTypeMappe
String endNodeType = object.getString("endNodeType"); String endNodeType = object.getString("endNodeType");
String property = object.getString("property"); String property = object.getString("property");
String value = object.getString("value"); String value = object.getString("value");
//去空 // 去空,如果存在任何的空值,则忽略
if (StringUtils.isEmpty(startNodeType) || StringUtils.isEmpty(entity) || StringUtils.isEmpty(endNodeType) if (StrUtil.hasEmpty(startNodeType, entity, endNodeType, property, value)) {
|| StringUtils.isEmpty(property) || StringUtils.isEmpty(value)) {
continue; continue;
} }
TripleInfo tripleInfo = new TripleInfo(entity, property, value, record.getId(), new Date(), startNodeType, endNodeType); TripleInfo tripleInfo = new TripleInfo(entity, property, value, record.getId(), new Date(), startNodeType, endNodeType);
@ -170,7 +170,7 @@ public class ModelRecordTypeServiceImpl extends ServiceImpl<ModelRecordTypeMappe
@Override @Override
public List<TripleInfo> getThreeInfo(String caseId, String name, String recordId) { public List<TripleInfo> getThreeInfo(String caseId, String name, String recordId) {
// TODO 这里应该改成异步的形式,通过异步的形式来进行提取三元组信息,不能每次点击就跑一遍 // TODO 这里应该改成异步的形式,通过异步的形式来进行提取三元组信息,不能每次点击就跑一遍
return extractThreeInfo(caseId, name, recordId); return extractTripleInfo(caseId, name, recordId);
} }
@Override @Override
@ -181,6 +181,7 @@ public class ModelRecordTypeServiceImpl extends ServiceImpl<ModelRecordTypeMappe
try { try {
//开始节点 //开始节点
String start = tripleInfo.getStartNode(); String start = tripleInfo.getStartNode();
// 首先看是否已经存在了,如果已经存在了,就不添加了
CaseNode startNode = neo4jService.findOneByName(tripleInfo.getCaseId(), tripleInfo.getNoteRecordsId(), tripleInfo.getStartNodeType(), start, "1"); CaseNode startNode = neo4jService.findOneByName(tripleInfo.getCaseId(), tripleInfo.getNoteRecordsId(), tripleInfo.getStartNodeType(), start, "1");
if (startNode == null) { if (startNode == null) {
startNode = new CaseNode(start, tripleInfo.getStartNodeType(), tripleInfo.getNoteRecordId(), tripleInfo.getNoteRecordsId(), tripleInfo.getCaseId(), "1"); startNode = new CaseNode(start, tripleInfo.getStartNodeType(), tripleInfo.getNoteRecordId(), tripleInfo.getNoteRecordsId(), tripleInfo.getCaseId(), "1");
@ -199,13 +200,14 @@ public class ModelRecordTypeServiceImpl extends ServiceImpl<ModelRecordTypeMappe
Rel rel = new Rel(startNode.getId(), tripleInfo.getRelation(), endNode.getId()); Rel rel = new Rel(startNode.getId(), tripleInfo.getRelation(), endNode.getId());
Rel relation = neo4jService.findRelation(rel); Rel relation = neo4jService.findRelation(rel);
if (relation == null) { if (relation == null) {
R<?> r = neo4jService.saveRelation(rel); neo4jService.saveRelation(rel);
} }
tripleInfo.setAddNeo4j("1"); tripleInfo.setAddNeo4j("1");
int j = tripleInfoMapper.updateById(tripleInfo); int j = tripleInfoMapper.updateById(tripleInfo);
if (j > 0) { if (j > 0) {
i++; i++;
} }
// TODO 重复添加的OK了,删除的呢?
} catch (Exception e) { } catch (Exception e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
} }

Loading…
Cancel
Save