代码提交

topo_dev
liu 9 months ago
parent a20e6f218d
commit b0cca791dd

@ -5,24 +5,29 @@ import lombok.Getter;
@Getter
public enum JudgeResultEnum {
TRUE("1","真实"),
TRUE("1","真实","1"),
FALSE("2","虚构"),
FALSE("2","虚构","0"),
EXIST("3","存在"),
EXIST("3","存在","1"),
NOT_EXIST("4","不存在"),
NOT_EXIST("4","不存在","0"),
UNKNOWN("5","未知");
UNKNOWN("5","未知","-1");
private String code;
private String desc;
// 原子指标结果 -1:未知, 0:不存在, 1存在
private String translateResult;
JudgeResultEnum(String code, String desc) {
JudgeResultEnum(String code, String desc,String translateResult) {
this.code = code;
this.desc = desc;
this.translateResult = translateResult;
}
/**
* code
* @param code
@ -34,9 +39,19 @@ public enum JudgeResultEnum {
return judgeResultEnum;
}
}
return null;
return JudgeResultEnum.UNKNOWN;
}
public static JudgeResultEnum getInstanceByTranslateResult(String translateResult) {
for (JudgeResultEnum judgeResultEnum : JudgeResultEnum.values()) {
if (judgeResultEnum.getTranslateResult().equals(translateResult)) {
return judgeResultEnum;
}
}
return JudgeResultEnum.UNKNOWN;
}
/**
*
* @return

@ -1,5 +1,6 @@
package com.supervision.police.dto;
import cn.hutool.core.util.StrUtil;
import com.supervision.constant.JudgeResultEnum;
import com.supervision.constant.ScoreEnum;
import lombok.Data;
@ -9,6 +10,8 @@ import java.util.Objects;
@Data
public class AtomicIndexDTO {
private String atomicIndexId;
/**
*
*/
@ -44,4 +47,27 @@ public class AtomicIndexDTO {
this.indexResult = instance.flagIsTrue() ? "true" : "false";
}
public void judgeWithIndexResult(String judgeLogic){
JudgeResultEnum instance = JudgeResultEnum.getInstanceByTranslateResult(this.atomicResult);
if (Objects.isNull(instance)){
this.indexResult = "false";
return;
}
if (StrUtil.isBlank(judgeLogic)){
this.indexResult = instance.flagIsTrue() ? "true" : "false";
}else {
String translateResult = instance.getTranslateResult();
// 1.指标判断符合,规则要求不符合,返回false
// 2.指标判断不符合,规则要求符合,返回false
// 3.指标判断符合,规则要求符合,返回true
// 4.指标判断不符合,规则要求不符合,返回true
if (judgeLogic.equals(translateResult)){
this.indexResult = "true";
}else {
this.indexResult = "false";
}
}
}
}

@ -37,4 +37,9 @@ public class IndexDetail {
*/
private List<AtomicIndexDTO> children;
/**
*
*/
private String judgeLogic;
}

@ -5,6 +5,7 @@ import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@ -18,10 +19,7 @@ import com.supervision.common.utils.IPages;
import com.supervision.common.utils.StringUtils;
import com.supervision.police.domain.CasePerson;
import com.supervision.police.domain.ComDictionary;
import com.supervision.police.dto.AtomicIndexDTO;
import com.supervision.police.dto.IndexDetail;
import com.supervision.police.dto.ModelCaseBase;
import com.supervision.police.dto.ModelCaseDTO;
import com.supervision.police.dto.*;
import com.supervision.police.mapper.CasePersonMapper;
import com.supervision.police.mapper.ModelCaseMapper;
import com.supervision.police.domain.ModelCase;
@ -59,6 +57,7 @@ public class ModelCaseServiceImpl extends ServiceImpl<ModelCaseMapper, ModelCase
/**
*
*
* @param modelCase
* @param page
* @param size
@ -68,7 +67,7 @@ public class ModelCaseServiceImpl extends ServiceImpl<ModelCaseMapper, ModelCase
public IPage<ModelCaseDTO> queryList(ModelCase modelCase, Integer page, Integer size) {
IPage<ModelCase> modelCaseIPage = modelCaseMapper.selectAll(Page.of(page, size), modelCase);
if (CollUtil.isEmpty(modelCaseIPage.getRecords())){
if (CollUtil.isEmpty(modelCaseIPage.getRecords())) {
return Page.of(page, size);
}
@ -88,7 +87,7 @@ public class ModelCaseServiceImpl extends ServiceImpl<ModelCaseMapper, ModelCase
for (String type : caseTypes) {
caseType.add(comDictionaryService.getName(dicts, "case_type", type));
}
if (StrUtil.isEmpty(modelCaseDTO.getCaseStatus())){
if (StrUtil.isEmpty(modelCaseDTO.getCaseStatus())) {
modelCaseDTO.setCaseStatus("1");
}
modelCaseDTO.setCaseTypeName(StringUtils.join(caseType, ","));
@ -96,12 +95,12 @@ public class ModelCaseServiceImpl extends ServiceImpl<ModelCaseMapper, ModelCase
modelCaseDTO.setCrimeModeName(comDictionaryService.getName(dicts, "crime_mode", modelCaseDTO.getCrimeMode()));
modelCaseDTO.setIdentifyResultName(comDictionaryService.getName(dicts, "identify_result", modelCaseDTO.getIdentifyResult()));
Map<String, List<CasePerson>> casePersonMap = persionMap.get(modelCaseDTO.getId());
if (CollUtil.isNotEmpty(casePersonMap)){
if (CollUtil.isNotEmpty(casePersonMap)) {
modelCaseDTO.setLawActor(CollUtil.getFirst(casePersonMap.get("1")));
modelCaseDTO.floatLawActorInfo();
modelCaseDTO.setLawPartyList(casePersonMap.getOrDefault("2",new ArrayList<>()));
modelCaseDTO.setLawPartyList(casePersonMap.getOrDefault("2", new ArrayList<>()));
}
if (Objects.isNull(modelCaseDTO.getLawPartyList())){
if (Objects.isNull(modelCaseDTO.getLawPartyList())) {
modelCaseDTO.setLawPartyList(new ArrayList<>());
}
return modelCaseDTO;
@ -110,13 +109,15 @@ public class ModelCaseServiceImpl extends ServiceImpl<ModelCaseMapper, ModelCase
/**
*
*
* @param lawActor
* @param lawParty
*/
record lawActorPartyPair(String lawActor, String lawParty){}
record lawActorPartyPair(String lawActor, String lawParty) {
}
@Override
public R<?> checkCaseNo(String caseNo,String caseId) {
public R<?> checkCaseNo(String caseNo, String caseId) {
Long count = modelCaseMapper.selectCount(new LambdaQueryWrapper<ModelCase>()
.eq(ModelCase::getCaseNo, caseNo)
.eq(ModelCase::getDataStatus, "1")
@ -162,7 +163,7 @@ public class ModelCaseServiceImpl extends ServiceImpl<ModelCaseMapper, ModelCase
public R<List<CasePerson>> getPerson(String caseId, String name) {
LambdaQueryWrapper<CasePerson> wrapper = Wrappers.lambdaQuery();
wrapper.eq(CasePerson::getCaseId, caseId)
.like(StrUtil.isNotEmpty(name),CasePerson::getName, name);
.like(StrUtil.isNotEmpty(name), CasePerson::getName, name);
List<CasePerson> casePeople = casePersonMapper.selectList(wrapper);
List<ComDictionary> dicts = comDictionaryService.list();
for (CasePerson cp : casePeople) {
@ -172,7 +173,7 @@ public class ModelCaseServiceImpl extends ServiceImpl<ModelCaseMapper, ModelCase
}
@Override
@Transactional(transactionManager = "dataSourceTransactionManager",rollbackFor = Exception.class)
@Transactional(transactionManager = "dataSourceTransactionManager", rollbackFor = Exception.class)
public R<?> addPersion(CasePerson person) {
Assert.notEmpty(person.getCaseId(), "案件id不能为空");
@ -259,18 +260,43 @@ public class ModelCaseServiceImpl extends ServiceImpl<ModelCaseMapper, ModelCase
iPage = modelCaseMapper.getIndexDetail(iPage, caseId, indexType);
List<IndexDetail> records = iPage.getRecords();
for (IndexDetail record : records) {
if (StringUtils.isEmpty(record.getAtomicIds())){
if (StringUtils.isEmpty(record.getAtomicIds())) {
continue;
}
String judgeLogic = record.getJudgeLogic();
Map<String, String> indexJundgeLogicMap = parseLogicMap(judgeLogic);
String[] array = record.getAtomicIds().split(",");
List<String> atomicIds = Arrays.asList(array);
List<AtomicIndexDTO> atomics = modelCaseMapper.getAtomicDetail(caseId, atomicIds);
atomics.forEach(AtomicIndexDTO::atomicResultToIndexResult);
for (AtomicIndexDTO atomic : atomics) {
// 需要和原子指标的规则判断是否一致(解决出罪和入罪冲突的问题)
String s = indexJundgeLogicMap.get(atomic.getAtomicIndexId());
atomic.judgeWithIndexResult(s);
}
record.setChildren(atomics);
}
iPage.setRecords(records);
return R.ok(IPages.buildDataMap(iPage));
}
private Map<String, String> parseLogicMap(String judgeLogic) {
List<JudgeLogic> judgeLogics = JSONUtil.toList(judgeLogic, JudgeLogic.class);
Map<String, String> resultMap = new HashMap<>();
for (JudgeLogic logic : judgeLogics) {
for (AtomicData atomicDatum : logic.getAtomicData()) {
// 原子指标结果 -1:未知, 0:不存在, 1存在
if (atomicDatum.getRelationalSymbol().equals("1") || atomicDatum.getRelationalSymbol().equals("3")) {
resultMap.put(atomicDatum.getAtomicIndex(), "1");
} else if (atomicDatum.getRelationalSymbol().equals("2") || atomicDatum.getRelationalSymbol().equals("4")) {
resultMap.put(atomicDatum.getAtomicIndex(), "0");
} else {
resultMap.put(atomicDatum.getAtomicIndex(), "-1");
}
}
}
return resultMap;
}
}

@ -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. 11=100=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;

@ -47,7 +47,7 @@
and mi.index_type = #{indexType}
</select>
<select id="getAtomicDetail" resultType="com.supervision.police.dto.AtomicIndexDTO">
select mai.name as indexName,
select mai.id as atomicIndexId,mai.name as indexName,
mar.atomic_result as atomicResult,
concat(nrs.question, nrs.answer) as record
from model_atomic_result mar
@ -59,7 +59,7 @@
</foreach>
</select>
<select id="getIndexDetail" resultType="com.supervision.police.dto.IndexDetail">
select mi.name as indexName, mi.index_score as score, mir.index_result, mir.atomic_ids
select mi.name as indexName, mi.index_score as score, mir.index_result, mir.atomic_ids,mi.judge_logic as judgeLogic
from model_index mi
left join model_index_result mir on ( mi.id = mir.index_id and mir.case_id = #{caseId} )
WHERE mi.data_status = '1'

Loading…
Cancel
Save