|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
package com.supervision.police.service.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
|
|
import com.supervision.common.domain.R;
|
|
|
|
|
import com.supervision.common.utils.StringUtils;
|
|
|
|
@ -11,6 +12,7 @@ import com.supervision.police.dto.AtomicData;
|
|
|
|
|
import com.supervision.police.dto.JudgeLogic;
|
|
|
|
|
import com.supervision.police.mapper.*;
|
|
|
|
|
import com.supervision.police.service.ModelService;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.neo4j.driver.Driver;
|
|
|
|
|
import org.neo4j.driver.Result;
|
|
|
|
|
import org.neo4j.driver.Session;
|
|
|
|
@ -19,6 +21,7 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Service
|
|
|
|
|
public class ModelServiceImpl implements ModelService {
|
|
|
|
|
|
|
|
|
@ -29,6 +32,7 @@ public class ModelServiceImpl implements ModelService {
|
|
|
|
|
private ModelAtomicIndexMapper modelAtomicIndexMapper;
|
|
|
|
|
|
|
|
|
|
private final Driver driver;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ModelServiceImpl(Driver driver) {
|
|
|
|
|
this.driver = driver;
|
|
|
|
@ -56,9 +60,7 @@ public class ModelServiceImpl implements ModelService {
|
|
|
|
|
result.setAtomicId(atomicIndex.getId());
|
|
|
|
|
//查询语句
|
|
|
|
|
String ql = atomicIndex.getQueryLang();
|
|
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
|
|
params.put("lawActor", analyseCaseDTO.getLawActor());
|
|
|
|
|
params.put("caseId", analyseCaseDTO.getCaseId());
|
|
|
|
|
|
|
|
|
|
//原子指标结果表
|
|
|
|
|
try {
|
|
|
|
|
// index_source==1
|
|
|
|
@ -71,34 +73,8 @@ public class ModelServiceImpl implements ModelService {
|
|
|
|
|
} else if ("2".endsWith(atomicIndex.getIndexSource()) && StringUtils.isNotEmpty(ql)) {
|
|
|
|
|
//
|
|
|
|
|
} else if ("3".endsWith(atomicIndex.getIndexSource()) && StringUtils.isNotEmpty(ql)) {
|
|
|
|
|
//图谱
|
|
|
|
|
int i = 1;
|
|
|
|
|
String lawPartys = analyseCaseDTO.getLawParty();
|
|
|
|
|
String[] split = StringUtils.isEmpty(lawPartys) ? new String[0] : lawPartys.split(",");
|
|
|
|
|
if (ql.contains("$lawParty") && split.length > 1) {
|
|
|
|
|
i = split.length;
|
|
|
|
|
}
|
|
|
|
|
for (int j = 0; j < i; j++) {
|
|
|
|
|
if (split.length > 0) {
|
|
|
|
|
params.put("lawParty", split[j]);
|
|
|
|
|
}
|
|
|
|
|
Result run = session.run(ql, params);
|
|
|
|
|
List<ResultDTO> res = Neo4jUtils.getResultDTOList(run);
|
|
|
|
|
if (res.isEmpty()) {
|
|
|
|
|
result.setAtomicResult("-1");
|
|
|
|
|
} else {
|
|
|
|
|
ResultDTO resultDTO = res.get(0);
|
|
|
|
|
if (StringUtils.isNotEmpty(resultDTO.getRelId())) {
|
|
|
|
|
//存在关系
|
|
|
|
|
result.setAtomicResult("1");
|
|
|
|
|
result.setRecordId(resultDTO.getRecordId());
|
|
|
|
|
result.setRecordsId(resultDTO.getRecordsId());
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
|
|
|
|
result.setAtomicResult("0");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 使用知识图谱进行计算
|
|
|
|
|
analyseGraphCase(analyseCaseDTO, result, ql, session);
|
|
|
|
|
} else if ("4".endsWith(atomicIndex.getIndexSource())) {
|
|
|
|
|
//
|
|
|
|
|
}
|
|
|
|
@ -119,51 +95,55 @@ public class ModelServiceImpl implements ModelService {
|
|
|
|
|
|
|
|
|
|
// 计算指标结果
|
|
|
|
|
int score = 0;
|
|
|
|
|
// 根据案件类型获取所有的指标
|
|
|
|
|
List<ModelIndex> modelIndices = modelIndexMapper.selectByCaseType(modelCase.getCaseType());
|
|
|
|
|
for (ModelIndex modelIndex : modelIndices) {
|
|
|
|
|
ModelIndexResult result = new ModelIndexResult();
|
|
|
|
|
result.setCaseId(analyseCaseDTO.getCaseId());
|
|
|
|
|
result.setIndexId(modelIndex.getId());
|
|
|
|
|
Set<String> atomicIds = new HashSet<>();
|
|
|
|
|
// 判断逻辑是否为空,如果不为空,就根据判断逻辑进行判断
|
|
|
|
|
if (StringUtils.isNotEmpty(modelIndex.getJudgeLogic())) {
|
|
|
|
|
List<JudgeLogic> judgeLogics = JSONUtil.toList(modelIndex.getJudgeLogic(), JudgeLogic.class);
|
|
|
|
|
boolean res = false;
|
|
|
|
|
for (int i = 0; i < judgeLogics.size(); i++) {
|
|
|
|
|
boolean group = false;
|
|
|
|
|
JudgeLogic logic = judgeLogics.get(i);
|
|
|
|
|
String rowLogic = logic.getRowLogic();
|
|
|
|
|
List<AtomicData> atomicData = logic.getAtomicData();
|
|
|
|
|
for (int j = 0; j < atomicData.size(); j++) {
|
|
|
|
|
AtomicData data = atomicData.get(j);
|
|
|
|
|
atomicIds.add(data.getAtomicIndex());
|
|
|
|
|
Boolean ato = atomic.get(data.getAtomicIndex());
|
|
|
|
|
String relationalSymbol = data.getRelationalSymbol();
|
|
|
|
|
if ("2".equals(relationalSymbol) || "4".equals(relationalSymbol) || "5".equals(relationalSymbol)) {
|
|
|
|
|
ato = !ato;
|
|
|
|
|
if (CollUtil.isNotEmpty(judgeLogics)) {
|
|
|
|
|
boolean res = false;
|
|
|
|
|
for (int i = 0; i < judgeLogics.size(); i++) {
|
|
|
|
|
boolean group = false;
|
|
|
|
|
JudgeLogic logic = judgeLogics.get(i);
|
|
|
|
|
String rowLogic = logic.getRowLogic();
|
|
|
|
|
List<AtomicData> atomicData = logic.getAtomicData();
|
|
|
|
|
for (int j = 0; j < atomicData.size(); j++) {
|
|
|
|
|
AtomicData data = atomicData.get(j);
|
|
|
|
|
atomicIds.add(data.getAtomicIndex());
|
|
|
|
|
Boolean ato = atomic.get(data.getAtomicIndex());
|
|
|
|
|
String relationalSymbol = data.getRelationalSymbol();
|
|
|
|
|
if ("2".equals(relationalSymbol) || "4".equals(relationalSymbol) || "5".equals(relationalSymbol)) {
|
|
|
|
|
ato = !ato;
|
|
|
|
|
}
|
|
|
|
|
if (j == 0) {
|
|
|
|
|
group = ato;
|
|
|
|
|
} else {
|
|
|
|
|
if ("1".equals(rowLogic)) {
|
|
|
|
|
group = group && ato;
|
|
|
|
|
} else if ("2".equals(rowLogic)) {
|
|
|
|
|
group = group || ato;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (j == 0) {
|
|
|
|
|
group = ato;
|
|
|
|
|
String groupLogic = logic.getGroupLogic();
|
|
|
|
|
if (i == 0) {
|
|
|
|
|
res = group;
|
|
|
|
|
} else {
|
|
|
|
|
if ("1".equals(rowLogic)) {
|
|
|
|
|
group = group && ato;
|
|
|
|
|
} else if ("2".equals(rowLogic)) {
|
|
|
|
|
group = group || ato;
|
|
|
|
|
if ("1".equals(groupLogic)) {
|
|
|
|
|
res = res && group;
|
|
|
|
|
} else if ("2".equals(groupLogic)) {
|
|
|
|
|
res = res || group;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
String groupLogic = logic.getGroupLogic();
|
|
|
|
|
if (i == 0) {
|
|
|
|
|
res = group;
|
|
|
|
|
} else {
|
|
|
|
|
if ("1".equals(groupLogic)) {
|
|
|
|
|
res = res && group;
|
|
|
|
|
} else if ("2".equals(groupLogic)) {
|
|
|
|
|
res = res || group;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
result.setIndexResult(res ? "true" : "false");
|
|
|
|
|
result.setAtomicIds(StringUtils.join(atomicIds, ","));
|
|
|
|
|
}
|
|
|
|
|
result.setIndexResult(res? "true" : "false");
|
|
|
|
|
result.setAtomicIds(StringUtils.join(atomicIds, ","));
|
|
|
|
|
}
|
|
|
|
|
ModelIndexResult exist = modelIndexResultMapper.selectByCaseIdAndIndexId(analyseCaseDTO.getCaseId(), modelIndex.getId());
|
|
|
|
|
if (exist == null) {
|
|
|
|
@ -182,4 +162,49 @@ public class ModelServiceImpl implements ModelService {
|
|
|
|
|
return R.ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void analyseGraphCase(AnalyseCaseDTO analyseCaseDTO, ModelAtomicResult result, String ql, Session session) {
|
|
|
|
|
//图谱
|
|
|
|
|
int i = 1;
|
|
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
|
|
// 行为人
|
|
|
|
|
params.put("lawActor", analyseCaseDTO.getLawActor());
|
|
|
|
|
// 案号
|
|
|
|
|
params.put("caseId", analyseCaseDTO.getCaseId());
|
|
|
|
|
// 参数中是否传了受害人
|
|
|
|
|
String lawPartys = analyseCaseDTO.getLawParty();
|
|
|
|
|
// 如果有受害人的话就进行分割
|
|
|
|
|
String[] split = StringUtils.isEmpty(lawPartys) ? new String[0] : lawPartys.split(",");
|
|
|
|
|
if (ql.contains("$lawParty") && split.length > 1) {
|
|
|
|
|
i = split.length;
|
|
|
|
|
}
|
|
|
|
|
for (int j = 0; j < i; j++) {
|
|
|
|
|
if (split.length > 0) {
|
|
|
|
|
params.put("lawParty", split[j]);
|
|
|
|
|
}
|
|
|
|
|
Result run = null;
|
|
|
|
|
try {
|
|
|
|
|
run = session.run(ql, params);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.info("图数据库查询出现错误,查询语句{},参数{}", ql, JSONUtil.toJsonStr(params));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<ResultDTO> res = Neo4jUtils.getResultDTOList(run);
|
|
|
|
|
if (res.isEmpty()) {
|
|
|
|
|
result.setAtomicResult("-1");
|
|
|
|
|
} else {
|
|
|
|
|
ResultDTO resultDTO = res.get(0);
|
|
|
|
|
if (StringUtils.isNotEmpty(resultDTO.getRelId())) {
|
|
|
|
|
//存在关系
|
|
|
|
|
result.setAtomicResult("1");
|
|
|
|
|
result.setRecordId(resultDTO.getRecordId());
|
|
|
|
|
result.setRecordsId(resultDTO.getRecordsId());
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
|
|
|
|
result.setAtomicResult("0");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|