|
|
|
@ -13,6 +13,8 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
import com.deepoove.poi.XWPFTemplate;
|
|
|
|
|
import com.supervision.common.domain.R;
|
|
|
|
|
import com.supervision.common.utils.StringUtils;
|
|
|
|
|
import com.supervision.constant.JudgeResultEnum;
|
|
|
|
|
import com.supervision.constant.ScoreEnum;
|
|
|
|
|
import com.supervision.neo4j.dto.ResultDTO;
|
|
|
|
|
import com.supervision.neo4j.utils.Neo4jUtils;
|
|
|
|
|
import com.supervision.police.domain.*;
|
|
|
|
@ -88,7 +90,7 @@ public class ModelServiceImpl implements ModelService {
|
|
|
|
|
}
|
|
|
|
|
//原子指标
|
|
|
|
|
List<ModelAtomicIndex> atomicIndices = modelAtomicIndexMapper.selectByCaseType(modelCase.getCaseType());
|
|
|
|
|
Map<String, Boolean> atomicResultMap = new HashMap<>();
|
|
|
|
|
Map<String, String> atomicResultMap = new HashMap<>();
|
|
|
|
|
for (ModelAtomicIndex atomicIndex : atomicIndices) {
|
|
|
|
|
//原子指标结果
|
|
|
|
|
ModelAtomicResult result = new ModelAtomicResult();
|
|
|
|
@ -128,8 +130,12 @@ public class ModelServiceImpl implements ModelService {
|
|
|
|
|
result.setId(exist.getId());
|
|
|
|
|
modelAtomicResultMapper.updateById(result);
|
|
|
|
|
}
|
|
|
|
|
// 所有原子指标id,判断结果是否为1 或者3,如果为1或者3,则符合,为true
|
|
|
|
|
atomicResultMap.put(result.getAtomicId(), "1".equals(result.getAtomicResult()) || "3".equals(result.getAtomicResult()));
|
|
|
|
|
// 所有原子指标id,判断结果
|
|
|
|
|
Set<String> checkAtomicResult = Set.of("-1", "0", "1");
|
|
|
|
|
if (!checkAtomicResult.contains(result.getAtomicResult())) {
|
|
|
|
|
throw new RuntimeException("TEST:不被支持的校核结果,需排查BUG,atomicId:" + result.getAtomicId() + " result:" + result.getAtomicResult());
|
|
|
|
|
}
|
|
|
|
|
atomicResultMap.put(result.getAtomicId(), result.getAtomicResult());
|
|
|
|
|
}
|
|
|
|
|
// 最终计算得分
|
|
|
|
|
calculateFinalScore(analyseCaseDTO, modelCase, atomicResultMap);
|
|
|
|
@ -139,6 +145,7 @@ public class ModelServiceImpl implements ModelService {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 手动定义原子指标处理
|
|
|
|
|
*
|
|
|
|
|
* @param analyseCaseDTO
|
|
|
|
|
* @param result
|
|
|
|
|
* @param atomicIndex
|
|
|
|
@ -148,15 +155,18 @@ public class ModelServiceImpl implements ModelService {
|
|
|
|
|
new LambdaQueryWrapper<ModelAtomicResult>().eq(ModelAtomicResult::getCaseId, analyseCaseDTO.getCaseId())
|
|
|
|
|
.eq(ModelAtomicResult::getAtomicId, atomicIndex.getId()));
|
|
|
|
|
|
|
|
|
|
if (CollUtil.isEmpty(modelAtomicResults)){
|
|
|
|
|
if (CollUtil.isEmpty(modelAtomicResults)) {
|
|
|
|
|
log.info("manuallyDefinedCase:根据caseId:{},auomicId:{}未找到原子指标结果", analyseCaseDTO.getCaseId(), atomicIndex.getId());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (CollUtil.size(modelAtomicResults) > 0){
|
|
|
|
|
if (CollUtil.size(modelAtomicResults) > 0) {
|
|
|
|
|
log.warn("manuallyDefinedCase:根据caseId:{},auomicId:{}找到多个原子指标结果", analyseCaseDTO.getCaseId(), atomicIndex.getId());
|
|
|
|
|
}
|
|
|
|
|
ModelAtomicResult modelAtomicResult = CollUtil.getFirst(modelAtomicResults);
|
|
|
|
|
result.setAtomicResult(modelAtomicResult.getAtomicResult());
|
|
|
|
|
// 对结果进行映射操作,前端填的是1-5,我们这里应该是-1,0,1
|
|
|
|
|
JudgeResultEnum instance = JudgeResultEnum.getInstance(modelAtomicResult.getAtomicResult());
|
|
|
|
|
|
|
|
|
|
result.setAtomicResult(instance.getTranslateResult());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -194,14 +204,14 @@ public class ModelServiceImpl implements ModelService {
|
|
|
|
|
InputStream inputStream = null;
|
|
|
|
|
try {
|
|
|
|
|
response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
|
|
|
|
|
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(caseScoreDetailDTO.getCaseName()+".docx", StandardCharsets.UTF_8));
|
|
|
|
|
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(caseScoreDetailDTO.getCaseName() + ".docx", StandardCharsets.UTF_8));
|
|
|
|
|
inputStream = resource.getInputStream();
|
|
|
|
|
XWPFTemplate template = XWPFTemplate.compile(inputStream).render(caseScoreDetailDTO);
|
|
|
|
|
template.writeAndClose(response.getOutputStream());
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}finally {
|
|
|
|
|
if (inputStream != null){
|
|
|
|
|
} finally {
|
|
|
|
|
if (inputStream != null) {
|
|
|
|
|
try {
|
|
|
|
|
inputStream.close();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
@ -214,7 +224,7 @@ public class ModelServiceImpl implements ModelService {
|
|
|
|
|
/**
|
|
|
|
|
* 最终计算得分
|
|
|
|
|
*/
|
|
|
|
|
private void calculateFinalScore(AnalyseCaseDTO analyseCaseDTO, ModelCase modelCase, Map<String, Boolean> atomicResultMap) {
|
|
|
|
|
private void calculateFinalScore(AnalyseCaseDTO analyseCaseDTO, ModelCase modelCase, Map<String, String> atomicResultMap) {
|
|
|
|
|
// 计算指标结果
|
|
|
|
|
int score = 0;
|
|
|
|
|
// 根据案件类型获取所有的指标
|
|
|
|
@ -241,13 +251,11 @@ public class ModelServiceImpl implements ModelService {
|
|
|
|
|
for (int j = 0; j < atomicData.size(); j++) {
|
|
|
|
|
AtomicData data = atomicData.get(j);
|
|
|
|
|
atomicIds.add(data.getAtomicIndex());
|
|
|
|
|
// 这里可能不存在,如果不存在,就默认为false
|
|
|
|
|
Boolean ato = atomicResultMap.getOrDefault(data.getAtomicIndex(), false);
|
|
|
|
|
// 这里可能不存在,如果未找到,就默认为false
|
|
|
|
|
String atomicIndexResult = atomicResultMap.getOrDefault(data.getAtomicIndex(), "-1");
|
|
|
|
|
String relationalSymbol = data.getRelationalSymbol();
|
|
|
|
|
// 判断,如果是2 虚构,4不存在 ,5 未知,则取反,即判断结果为false
|
|
|
|
|
if ("2".equals(relationalSymbol) || "4".equals(relationalSymbol) || "5".equals(relationalSymbol)) {
|
|
|
|
|
ato = !ato;
|
|
|
|
|
}
|
|
|
|
|
JudgeResultEnum instance = JudgeResultEnum.getInstance(relationalSymbol);
|
|
|
|
|
boolean ato = atomicIndexResult.equals(instance.getTranslateResult());
|
|
|
|
|
if (j == 0) {
|
|
|
|
|
innerGroupJudge = ato;
|
|
|
|
|
} else {
|
|
|
|
@ -258,6 +266,7 @@ public class ModelServiceImpl implements ModelService {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 组间进行判断
|
|
|
|
|
String groupLogic = logic.getGroupLogic();
|
|
|
|
|
if (i == 0) {
|
|
|
|
|
finalJudgeResult = innerGroupJudge;
|
|
|
|
@ -318,7 +327,8 @@ public class ModelServiceImpl implements ModelService {
|
|
|
|
|
try {
|
|
|
|
|
run = session.run(ql, params);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.info("图数据库查询出现错误,查询语句{},参数{}", ql, JSONUtil.toJsonStr(params));
|
|
|
|
|
result.setAtomicResult("-1");
|
|
|
|
|
log.error("图数据库查询出现错误,查询语句{},参数{}", ql, JSONUtil.toJsonStr(params),e);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -326,7 +336,7 @@ public class ModelServiceImpl implements ModelService {
|
|
|
|
|
if (res.isEmpty()) {
|
|
|
|
|
result.setAtomicResult("-1");
|
|
|
|
|
} else {
|
|
|
|
|
// 设置为0,不符合
|
|
|
|
|
// 设置为0,不存在
|
|
|
|
|
result.setAtomicResult("0");
|
|
|
|
|
// 进行遍历,如果有存在的,就设置为有
|
|
|
|
|
for (ResultDTO resultDTO : res) {
|
|
|
|
@ -346,6 +356,7 @@ public class ModelServiceImpl implements ModelService {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 分析数据库类型的原子信息
|
|
|
|
|
*
|
|
|
|
|
* @param analyseCaseDTO
|
|
|
|
|
* @param result
|
|
|
|
|
* @param sql
|
|
|
|
@ -359,7 +370,7 @@ public class ModelServiceImpl implements ModelService {
|
|
|
|
|
params.put("party_a", analyseCaseDTO.getLawActorName());
|
|
|
|
|
params.put("party_b", analyseCaseDTO.getLawParty());
|
|
|
|
|
boolean success = false;
|
|
|
|
|
if (modelIndexService.checkSql(sql)){
|
|
|
|
|
if (modelIndexService.checkSql(sql)) {
|
|
|
|
|
success = parseResult(rowSqlMapper.selectList(sql, params, Map.class));
|
|
|
|
|
}
|
|
|
|
|
result.setAtomicResult(success ? "1" : "0");
|
|
|
|
@ -367,11 +378,11 @@ public class ModelServiceImpl implements ModelService {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean checkSql(String sql,List<String> allowedTables) {
|
|
|
|
|
private boolean checkSql(String sql, List<String> allowedTables) {
|
|
|
|
|
if (StringUtils.isEmpty(sql)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (CollUtil.isEmpty(allowedTables)){
|
|
|
|
|
if (CollUtil.isEmpty(allowedTables)) {
|
|
|
|
|
log.info("checkSql:未配置允许的表");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
@ -387,14 +398,14 @@ public class ModelServiceImpl implements ModelService {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
List<String> tableList = SqlParserUtil.extractTableNames(sqlStatement);
|
|
|
|
|
if (CollUtil.isEmpty(tableList)){
|
|
|
|
|
if (CollUtil.isEmpty(tableList)) {
|
|
|
|
|
log.warn("checkSql:未检测到表");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
long count = tableList.stream().filter(table -> !allowedTables.contains(table)).count();
|
|
|
|
|
if (count > 0){
|
|
|
|
|
log.warn("checkSql:表{}不在允许的表列表中",tableList);
|
|
|
|
|
if (count > 0) {
|
|
|
|
|
log.warn("checkSql:表{}不在允许的表列表中", tableList);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
@ -404,7 +415,8 @@ public class ModelServiceImpl implements ModelService {
|
|
|
|
|
/**
|
|
|
|
|
* 执行结果分析:
|
|
|
|
|
* 1. 如果查询出的结果只有一行,判断列数是否大于1,如果大于1,返回真,如果=1,继续判断值是否大于0,如果大于0,返回真,如果=0,返回假
|
|
|
|
|
*2. 如果查询出的结果大于一行,则返回真
|
|
|
|
|
* 2. 如果查询出的结果大于一行,则返回真
|
|
|
|
|
*
|
|
|
|
|
* @param mapList 查询结果
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
@ -414,12 +426,12 @@ public class ModelServiceImpl implements ModelService {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (CollUtil.size(mapList) > 1){
|
|
|
|
|
if (CollUtil.size(mapList) > 1) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Map firstRow = CollUtil.getFirst(mapList);
|
|
|
|
|
if (firstRow.size() == 1 && CollUtil.size(firstRow.values())==1) {
|
|
|
|
|
if (firstRow.size() == 1 && CollUtil.size(firstRow.values()) == 1) {
|
|
|
|
|
Object first = CollUtil.getFirst(firstRow.values());
|
|
|
|
|
if (NumberUtil.isNumber(first.toString())) {
|
|
|
|
|
return NumberUtil.parseInt(first.toString()) > 0;
|
|
|
|
|