|
|
|
@ -8,28 +8,30 @@ import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
import com.deepoove.poi.XWPFTemplate;
|
|
|
|
|
import com.google.gson.Gson;
|
|
|
|
|
import com.supervision.common.domain.R;
|
|
|
|
|
import com.supervision.common.utils.StringUtils;
|
|
|
|
|
import com.supervision.constant.JudgeResultEnum;
|
|
|
|
|
import com.supervision.neo4j.dto.ResultDTO;
|
|
|
|
|
import com.supervision.neo4j.utils.Neo4jUtils;
|
|
|
|
|
import com.supervision.police.domain.*;
|
|
|
|
|
import com.supervision.police.dto.AnalyseCaseDTO;
|
|
|
|
|
import com.supervision.police.dto.AtomicData;
|
|
|
|
|
import com.supervision.police.dto.CaseStatus;
|
|
|
|
|
import com.supervision.police.dto.JudgeLogic;
|
|
|
|
|
import com.supervision.police.dto.*;
|
|
|
|
|
import com.supervision.police.dto.caseScore.CaseScore;
|
|
|
|
|
import com.supervision.police.dto.caseScore.CaseScoreDetailBuilder;
|
|
|
|
|
import com.supervision.police.dto.caseScore.CaseScoreDetailDTO;
|
|
|
|
|
import com.supervision.police.dto.indexRule.IndexRule;
|
|
|
|
|
import com.supervision.police.dto.indexRule.Operand;
|
|
|
|
|
import com.supervision.police.mapper.*;
|
|
|
|
|
import com.supervision.police.mybatis.RowSqlMapper;
|
|
|
|
|
import com.supervision.police.service.*;
|
|
|
|
|
import com.supervision.utils.CalculationUtil;
|
|
|
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.neo4j.driver.Driver;
|
|
|
|
|
import org.neo4j.driver.Result;
|
|
|
|
|
import org.neo4j.driver.Session;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.core.io.Resource;
|
|
|
|
|
import org.springframework.core.io.ResourceLoader;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
@ -40,8 +42,12 @@ import java.io.InputStream;
|
|
|
|
|
import java.net.URLEncoder;
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
import static com.supervision.common.constant.IndexRuleConstants.*;
|
|
|
|
|
import static com.supervision.common.constant.NotePromptConstants.TYPE_STRUCTURAL_REASONING;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Service
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
@ -73,6 +79,18 @@ public class ModelServiceImpl implements ModelService {
|
|
|
|
|
|
|
|
|
|
private final NoteRecordService noteRecordService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private NotePromptService notePromptService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private EvidenceDirectoryService evidenceDirectoryService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private CaseEvidenceService caseEvidenceService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ModelAtomicResultService modelAtomicResultService;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(transactionManager = "dataSourceTransactionManager", rollbackFor = Exception.class)
|
|
|
|
|
public R<?> analyseCase(AnalyseCaseDTO analyseCaseDTO) {
|
|
|
|
@ -116,7 +134,7 @@ public class ModelServiceImpl implements ModelService {
|
|
|
|
|
analyseGraphCase(analyseCaseDTO, result, ql, casePerson.getName());
|
|
|
|
|
} else if ("4".equals(atomicIndex.getIndexSource())) {
|
|
|
|
|
//
|
|
|
|
|
}else if ("5".equals(atomicIndex.getIndexSource())) {
|
|
|
|
|
} else if ("5".equals(atomicIndex.getIndexSource())) {
|
|
|
|
|
// todo: 结构化推理
|
|
|
|
|
//analyseStructuredInference(analyseCaseDTO, result);
|
|
|
|
|
}
|
|
|
|
@ -152,12 +170,346 @@ public class ModelServiceImpl implements ModelService {
|
|
|
|
|
return R.ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public R<?> analyseCaseNew(AnalyseCaseDTO analyseCaseDTO) {
|
|
|
|
|
log.info("数据准备阶段");
|
|
|
|
|
String caseId = analyseCaseDTO.getCaseId();
|
|
|
|
|
Map<String, Integer> typeScoreMap = new HashMap<>();
|
|
|
|
|
// 查出案件信息
|
|
|
|
|
ModelCase modelCase = modelCaseMapper.selectById(caseId);
|
|
|
|
|
// 获取案件行为人ID
|
|
|
|
|
CasePerson casePerson = casePersonMapper.selectOne(new LambdaQueryWrapper<CasePerson>()
|
|
|
|
|
.eq(CasePerson::getCaseId, analyseCaseDTO.getCaseId())
|
|
|
|
|
.eq(CasePerson::getCaseActorFlag, 1)
|
|
|
|
|
.eq(CasePerson::getRoleCode, "1")
|
|
|
|
|
.eq(StrUtil.isNotEmpty(analyseCaseDTO.getLawActorName()), CasePerson::getName, analyseCaseDTO.getLawActorName()));
|
|
|
|
|
if (ObjectUtil.isEmpty(casePerson)) {
|
|
|
|
|
throw new RuntimeException("未找到的行为人" + analyseCaseDTO.getLawActorName());
|
|
|
|
|
}
|
|
|
|
|
// 查出指标信息
|
|
|
|
|
List<ModelIndex> modelIndices = modelIndexMapper.selectByCaseType(modelCase.getCaseType());
|
|
|
|
|
// 查出原子指标信息
|
|
|
|
|
List<ModelAtomicIndex> atomicIndices = modelAtomicIndexMapper.selectByCaseType(modelCase.getCaseType());
|
|
|
|
|
// 查出提示词信息
|
|
|
|
|
List<NotePrompt> notePrompts = notePromptService.list(new LambdaQueryWrapper<NotePrompt>().eq(NotePrompt::getType, TYPE_STRUCTURAL_REASONING));
|
|
|
|
|
// 查出证据目录信息
|
|
|
|
|
List<EvidenceDirectory> evidenceDirectories = evidenceDirectoryService.list(new LambdaQueryWrapper<EvidenceDirectory>().eq(EvidenceDirectory::getCaseId, caseId));
|
|
|
|
|
// 查出证据信息
|
|
|
|
|
List<CaseEvidence> caseEvidences = caseEvidenceService.list(new LambdaQueryWrapper<CaseEvidence>().eq(CaseEvidence::getCaseId, caseId));
|
|
|
|
|
// 遍历指标集合,处理每个指标的判断逻辑,得出结果
|
|
|
|
|
modelIndices.forEach(modelIndex -> {
|
|
|
|
|
String indexRuleStr = modelIndex.getIndexRule();
|
|
|
|
|
Gson gson = new Gson();
|
|
|
|
|
IndexRule indexRule = gson.fromJson(indexRuleStr, IndexRule.class);
|
|
|
|
|
Set<Boolean> ruleConditionGroupResultList = new HashSet<>();
|
|
|
|
|
indexRule.getRuleConditionGroupList().forEach(ruleConditionGroup -> {
|
|
|
|
|
Set<Boolean> ruleConditionResultSet = new HashSet<>();
|
|
|
|
|
ruleConditionGroup.getRuleConditionList().forEach(ruleCondition -> {
|
|
|
|
|
Set<Boolean> operandUnitResultSet = new HashSet<>();
|
|
|
|
|
ruleCondition.getOperandUnitList().forEach(operandUnit -> {
|
|
|
|
|
Operand left = operandUnit.getLeftOperand();
|
|
|
|
|
Operand right = operandUnit.getRightOperand();
|
|
|
|
|
ModelAtomicIndex modelAtomicIndex = atomicIndices.stream().filter(atomicIndex -> atomicIndex.getId().equals(left.getAtomicIndexId())).findAny().orElse(null);
|
|
|
|
|
if (modelAtomicIndex == null) {
|
|
|
|
|
log.error("原子指标不存在,跳出当前循环。原子指标ID:{}", left.getAtomicIndexId());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// 定义原子指标结果共有属性
|
|
|
|
|
ModelAtomicResult result = new ModelAtomicResult();
|
|
|
|
|
result.setIndexId(modelIndex.getId());
|
|
|
|
|
result.setCasePersonId(casePerson.getId());
|
|
|
|
|
result.setCaseId(analyseCaseDTO.getCaseId());
|
|
|
|
|
result.setAtomicId(modelAtomicIndex.getId());
|
|
|
|
|
result.setAtomicResult(JudgeResultEnum.NOT_EXIST.getCode());
|
|
|
|
|
ModelAtomicResult exist = modelAtomicResultMapper.selectByCaseIdAndAtomicId(caseId, casePerson.getId(), modelIndex.getId(), modelAtomicIndex.getId());
|
|
|
|
|
if (exist != null) {
|
|
|
|
|
result.setId(exist.getId());
|
|
|
|
|
}
|
|
|
|
|
switch (left.getOperandType()) {
|
|
|
|
|
case OPERAND_TYPE_MANUAL:
|
|
|
|
|
operandUnitResultSet.add(manualIndexAnalysis(left, caseId));
|
|
|
|
|
break;
|
|
|
|
|
case OPERAND_TYPE_DB:
|
|
|
|
|
operandUnitResultSet.add(dbIndexAnalysis(caseId, modelAtomicIndex.getQueryLang(), result));
|
|
|
|
|
break;
|
|
|
|
|
case OPERAND_TYPE_GRAPH:
|
|
|
|
|
operandUnitResultSet.add(graphIndexAnalysis(modelIndex, casePerson, modelAtomicIndex, analyseCaseDTO, result));
|
|
|
|
|
break;
|
|
|
|
|
case OPERAND_TYPE_STRUCTURE:
|
|
|
|
|
operandUnitResultSet.add(structureIndexAnalysis(left, right, operandUnit.getOperator(), modelAtomicIndex, atomicIndices, notePrompts, evidenceDirectories, caseEvidences, result));
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
ruleConditionResultSet.add(CalculationUtil.calculateBooleanSet(operandUnitResultSet, ruleCondition.getLogic()));
|
|
|
|
|
});
|
|
|
|
|
ruleConditionGroupResultList.add(CalculationUtil.calculateBooleanSet(ruleConditionResultSet, ruleConditionGroup.getLogic()));
|
|
|
|
|
});
|
|
|
|
|
boolean result = CalculationUtil.calculateBooleanSet(ruleConditionGroupResultList, indexRule.getLogic());
|
|
|
|
|
if (result) {
|
|
|
|
|
Integer score = typeScoreMap.getOrDefault(modelIndex.getIndexType(), 0);
|
|
|
|
|
typeScoreMap.put(modelIndex.getIndexType(), score + modelIndex.getIndexScore());
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
log.info("计算分数(共性+入罪/共性+出罪 取最大值)");
|
|
|
|
|
Integer gx = typeScoreMap.getOrDefault("1", 0);
|
|
|
|
|
Integer rz = typeScoreMap.getOrDefault("2", 0);
|
|
|
|
|
Integer cz = typeScoreMap.getOrDefault("3", 0);
|
|
|
|
|
int max = Integer.max(gx + rz, gx + cz);
|
|
|
|
|
modelCase.setTotalScore(max);
|
|
|
|
|
log.info("更新案件得分情况");
|
|
|
|
|
caseStatusManageService.whenAnalyseCaseSuccess(analyseCaseDTO.getCaseId(), modelCase.getTotalScore());
|
|
|
|
|
noteRecordService.uploadFileToLangChainChat(analyseCaseDTO.getCaseId());
|
|
|
|
|
return R.ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 人工定义指标分析
|
|
|
|
|
*
|
|
|
|
|
* @param left 左操作数
|
|
|
|
|
* @param caseId 案件ID
|
|
|
|
|
*/
|
|
|
|
|
private boolean manualIndexAnalysis(Operand left, String caseId) {
|
|
|
|
|
boolean flag = false;
|
|
|
|
|
List<ModelAtomicResult> modelAtomicResults = modelAtomicResultMapper.selectList(
|
|
|
|
|
new LambdaQueryWrapper<ModelAtomicResult>().eq(ModelAtomicResult::getCaseId, caseId)
|
|
|
|
|
.eq(ModelAtomicResult::getAtomicId, left.getAtomicIndexId()));
|
|
|
|
|
if (modelAtomicResults != null && !modelAtomicResults.isEmpty()) {
|
|
|
|
|
ModelAtomicResult modelAtomicResult = CollUtil.getFirst(modelAtomicResults);
|
|
|
|
|
flag = EVALUATE_RESULT_EXIST.equals(modelAtomicResult.getAtomicResult());
|
|
|
|
|
}
|
|
|
|
|
return flag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 数据库查询指标分析
|
|
|
|
|
*
|
|
|
|
|
* @param caseId 案件ID
|
|
|
|
|
* @param sql 查询语句
|
|
|
|
|
* @param atomicResult 原子指标结果
|
|
|
|
|
* @return 是否存在
|
|
|
|
|
*/
|
|
|
|
|
private boolean dbIndexAnalysis(String caseId, String sql, ModelAtomicResult atomicResult) {
|
|
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
|
|
params.put("caseId", caseId);
|
|
|
|
|
List<Map> mapList = rowSqlMapper.selectList(sql, params, Map.class);
|
|
|
|
|
boolean flag = false;
|
|
|
|
|
if (mapList != null && !mapList.isEmpty()) {
|
|
|
|
|
flag = true;
|
|
|
|
|
String evidenceIds = mapList.stream().map(map -> map.get("id").toString()).collect(Collectors.joining(","));
|
|
|
|
|
atomicResult.setEvidenceId(evidenceIds);
|
|
|
|
|
atomicResult.setAtomicResult(JudgeResultEnum.EXIST.getCode());
|
|
|
|
|
}
|
|
|
|
|
modelAtomicResultService.saveOrUpdate(atomicResult);
|
|
|
|
|
return flag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 图谱查询指标分析
|
|
|
|
|
*
|
|
|
|
|
* @param modelIndex 大指标
|
|
|
|
|
* @param casePerson 行为人
|
|
|
|
|
* @param modelAtomicIndex 原子指标
|
|
|
|
|
* @param analyseCaseDTO 案件信息
|
|
|
|
|
* @return 是否存在
|
|
|
|
|
*/
|
|
|
|
|
private boolean graphIndexAnalysis(ModelIndex modelIndex, CasePerson casePerson, ModelAtomicIndex modelAtomicIndex, AnalyseCaseDTO analyseCaseDTO, ModelAtomicResult atomicResult) {
|
|
|
|
|
boolean flag = false;
|
|
|
|
|
Session session = driver.session();
|
|
|
|
|
//图谱
|
|
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
|
|
// 行为人
|
|
|
|
|
params.put("lawActor", casePerson.getName());
|
|
|
|
|
// 案号
|
|
|
|
|
params.put("caseId", analyseCaseDTO.getCaseId());
|
|
|
|
|
Result run = null;
|
|
|
|
|
try {
|
|
|
|
|
run = session.run(modelAtomicIndex.getQueryLang(), params);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("图数据库查询出现错误,查询语句{},参数{}", modelAtomicIndex.getQueryLang(), JSONUtil.toJsonStr(params), e);
|
|
|
|
|
}
|
|
|
|
|
List<ResultDTO> res = Neo4jUtils.getResultDTOList(run);
|
|
|
|
|
if (!res.isEmpty()) {
|
|
|
|
|
// 进行遍历,如果有存在的,就设置为有
|
|
|
|
|
for (ResultDTO resultDTO : res) {
|
|
|
|
|
if (StringUtils.isNotEmpty(resultDTO.getRelId())) {
|
|
|
|
|
//存在关系
|
|
|
|
|
flag = true;
|
|
|
|
|
atomicResult.setAtomicResult(JudgeResultEnum.EXIST.getCode());
|
|
|
|
|
atomicResult.setRecordId(resultDTO.getRecordId());
|
|
|
|
|
// 在退出循环之前先合并相关文本分片id
|
|
|
|
|
String recordSplitIdJoin = res.stream().filter(r ->
|
|
|
|
|
StringUtils.isNotEmpty(r.getRelId())
|
|
|
|
|
&& StringUtils.isNotEmpty(r.getRecordSplitId()))
|
|
|
|
|
.map(ResultDTO::getRecordSplitId).collect(Collectors.joining(","));
|
|
|
|
|
atomicResult.setRecordSplitId(recordSplitIdJoin);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
modelAtomicResultService.saveOrUpdate(atomicResult);
|
|
|
|
|
return flag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 结构化查询指标分析
|
|
|
|
|
*
|
|
|
|
|
* @param left 左操作数
|
|
|
|
|
* @param right 右操作数
|
|
|
|
|
* @param modelAtomicIndex 原子指标
|
|
|
|
|
* @param atomicIndices 原子指标集合
|
|
|
|
|
* @param notePrompts 提示词集合
|
|
|
|
|
* @param evidenceDirectories 证据目录集合
|
|
|
|
|
* @param caseEvidences 证据集合
|
|
|
|
|
* @param atomicResult 原子指标结果
|
|
|
|
|
* @return 是否存在
|
|
|
|
|
*/
|
|
|
|
|
private boolean structureIndexAnalysis(Operand left, Operand right, String operator, ModelAtomicIndex modelAtomicIndex, List<ModelAtomicIndex> atomicIndices, List<NotePrompt> notePrompts, List<EvidenceDirectory> evidenceDirectories, List<CaseEvidence> caseEvidences, ModelAtomicResult atomicResult) {
|
|
|
|
|
boolean flag = false;
|
|
|
|
|
List<CaseEvidence> evidences = getEvidencesByPromptId(modelAtomicIndex.getPromptId(), caseEvidences, evidenceDirectories, notePrompts);
|
|
|
|
|
ModelAtomicIndex rightModelAtomicIndex = null;
|
|
|
|
|
if (OPERAND_TYPE_STRUCTURE.equals(right.getOperandType())) {
|
|
|
|
|
log.info("右操作数为结构化查询,提前查好对应的原子指标");
|
|
|
|
|
rightModelAtomicIndex = atomicIndices.stream().filter(atomicIndex -> atomicIndex.getId().equals(left.getAtomicIndexId())).findAny().orElse(null);
|
|
|
|
|
if (rightModelAtomicIndex == null || StringUtils.isEmpty(rightModelAtomicIndex.getPromptId())) {
|
|
|
|
|
log.error("原子指标不存在。原子指标ID:{}", left.getAtomicIndexId());
|
|
|
|
|
return flag;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!evidences.isEmpty()) {
|
|
|
|
|
log.info("聚合类型为【{}】,右操作数操作类型为:【{}】", AGGREGATE_TYPE_SUM.equals(left.getAggregateType()) ? "求和" : AGGREGATE_TYPE_COUNT.equals(left.getAggregateType()) ? "计数" : "任一", OPERAND_TYPE_STRUCTURE.equals(right.getOperandType()) ? "结构化查询" : "值");
|
|
|
|
|
switch (left.getAggregateType()) {
|
|
|
|
|
case AGGREGATE_TYPE_SUM:
|
|
|
|
|
if (OPERAND_TYPE_STRUCTURE.equals(right.getOperandType())) {
|
|
|
|
|
List<CaseEvidence> rightEvidences = getEvidencesByPromptId(rightModelAtomicIndex.getPromptId(), caseEvidences, evidenceDirectories, notePrompts);
|
|
|
|
|
if (CalculationUtil.evaluateExpression(String.valueOf(getSumFromEvidences(left, evidences)), operator, String.valueOf(getSumFromEvidences(right, rightEvidences)))) {
|
|
|
|
|
atomicResult.setEvidenceId(evidences.stream().map(CaseEvidence::getId).collect(Collectors.joining(",")));
|
|
|
|
|
atomicResult.setAtomicResult(JudgeResultEnum.EXIST.getCode());
|
|
|
|
|
modelAtomicResultService.saveOrUpdate(atomicResult);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
} else if (OPERAND_TYPE_VALUE.equals(right.getOperandType())) {
|
|
|
|
|
if (CalculationUtil.evaluateExpression(String.valueOf(getSumFromEvidences(left, evidences)), operator, right.getValue())) {
|
|
|
|
|
atomicResult.setEvidenceId(evidences.stream().map(CaseEvidence::getId).collect(Collectors.joining(",")));
|
|
|
|
|
atomicResult.setAtomicResult(JudgeResultEnum.EXIST.getCode());
|
|
|
|
|
modelAtomicResultService.saveOrUpdate(atomicResult);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case AGGREGATE_TYPE_COUNT:
|
|
|
|
|
if (OPERAND_TYPE_STRUCTURE.equals(right.getOperandType())) {
|
|
|
|
|
List<CaseEvidence> rightEvidences = getEvidencesByPromptId(rightModelAtomicIndex.getPromptId(), caseEvidences, evidenceDirectories, notePrompts);
|
|
|
|
|
if (CalculationUtil.evaluateExpression(String.valueOf(evidences.size()), operator, String.valueOf(rightEvidences.size()))) {
|
|
|
|
|
atomicResult.setEvidenceId(evidences.stream().map(CaseEvidence::getId).collect(Collectors.joining(",")));
|
|
|
|
|
atomicResult.setAtomicResult(JudgeResultEnum.EXIST.getCode());
|
|
|
|
|
modelAtomicResultService.saveOrUpdate(atomicResult);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
} else if (OPERAND_TYPE_VALUE.equals(right.getOperandType())) {
|
|
|
|
|
if (CalculationUtil.evaluateExpression(String.valueOf(evidences.size()), operator, right.getValue())) {
|
|
|
|
|
atomicResult.setEvidenceId(evidences.stream().map(CaseEvidence::getId).collect(Collectors.joining(",")));
|
|
|
|
|
atomicResult.setAtomicResult(JudgeResultEnum.EXIST.getCode());
|
|
|
|
|
modelAtomicResultService.saveOrUpdate(atomicResult);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case AGGREGATE_TYPE_ANY:
|
|
|
|
|
if (OPERAND_TYPE_STRUCTURE.equals(right.getOperandType())) {
|
|
|
|
|
List<CaseEvidence> rightEvidences = getEvidencesByPromptId(rightModelAtomicIndex.getPromptId(), caseEvidences, evidenceDirectories, notePrompts);
|
|
|
|
|
Set<String> leftValueSet = getValueSetFromEvidences(left, evidences);
|
|
|
|
|
Set<String> rightValueSet = getValueSetFromEvidences(right, rightEvidences);
|
|
|
|
|
// 使用CalculationUtil.evaluateExpression方法遍历比较leftValueSet和rightValueSet的任一值,一旦有一个满足(返回true),则return true
|
|
|
|
|
if (leftValueSet.stream().anyMatch(leftValue -> rightValueSet.stream().anyMatch(rightValue -> CalculationUtil.evaluateExpression(leftValue, operator, rightValue)))) {
|
|
|
|
|
atomicResult.setEvidenceId(evidences.stream().map(CaseEvidence::getId).collect(Collectors.joining(",")));
|
|
|
|
|
atomicResult.setAtomicResult(JudgeResultEnum.EXIST.getCode());
|
|
|
|
|
modelAtomicResultService.saveOrUpdate(atomicResult);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
} else if (OPERAND_TYPE_VALUE.equals(right.getOperandType())) {
|
|
|
|
|
Set<String> leftValueSet = getValueSetFromEvidences(left, evidences);
|
|
|
|
|
if (leftValueSet.stream().anyMatch(leftValue -> CalculationUtil.evaluateExpression(leftValue, operator, right.getValue()))) {
|
|
|
|
|
atomicResult.setEvidenceId(evidences.stream().map(CaseEvidence::getId).collect(Collectors.joining(",")));
|
|
|
|
|
atomicResult.setAtomicResult(JudgeResultEnum.EXIST.getCode());
|
|
|
|
|
modelAtomicResultService.saveOrUpdate(atomicResult);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
log.error("证据不存在。提示词ID:{}", modelAtomicIndex.getPromptId());
|
|
|
|
|
}
|
|
|
|
|
return flag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Double getSumFromEvidences(Operand operand, List<CaseEvidence> evidences) {
|
|
|
|
|
AtomicReference<Double> sum = new AtomicReference<>(0.0);
|
|
|
|
|
if (evidences != null && !evidences.isEmpty()) {
|
|
|
|
|
evidences.forEach(e -> {
|
|
|
|
|
List<NotePromptExtractAttributesDto> properties = e.getProperty();
|
|
|
|
|
if (properties != null && !properties.isEmpty()) {
|
|
|
|
|
properties.forEach(p -> {
|
|
|
|
|
if (p.getAttrName().equals(operand.getPropertyKey())) {
|
|
|
|
|
if (StringUtils.isNotEmpty(p.getAttrValue())) {
|
|
|
|
|
sum.updateAndGet(v -> v + NumberUtil.parseDouble(p.getAttrValue()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return sum.get();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Set<String> getValueSetFromEvidences(Operand operand, List<CaseEvidence> evidences) {
|
|
|
|
|
Set<String> valueSet = new HashSet<>();
|
|
|
|
|
evidences.forEach(e -> {
|
|
|
|
|
List<NotePromptExtractAttributesDto> properties = e.getProperty();
|
|
|
|
|
if (properties != null && !properties.isEmpty()) {
|
|
|
|
|
properties.forEach(p -> {
|
|
|
|
|
if (p.getAttrName().equals(operand.getPropertyKey())) {
|
|
|
|
|
if (StringUtils.isNotEmpty(p.getAttrValue())) {
|
|
|
|
|
valueSet.add(p.getAttrValue());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return valueSet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据原子指标ID获取证据集合
|
|
|
|
|
*
|
|
|
|
|
* @param promptId 提示词ID
|
|
|
|
|
* @param caseEvidences 全量案件证据集合
|
|
|
|
|
* @param evidenceDirectories 证据目录集合
|
|
|
|
|
* @param notePrompts 提示词集合
|
|
|
|
|
* @return 证据集合
|
|
|
|
|
*/
|
|
|
|
|
private static List<CaseEvidence> getEvidencesByPromptId(String promptId, List<CaseEvidence> caseEvidences, List<EvidenceDirectory> evidenceDirectories, List<NotePrompt> notePrompts) {
|
|
|
|
|
List<CaseEvidence> evidences = new ArrayList<>();
|
|
|
|
|
NotePrompt notePrompt = notePrompts.stream().filter(n -> n.getId().equals(promptId)).findAny().orElse(null);
|
|
|
|
|
if (notePrompt == null) {
|
|
|
|
|
log.error("提示词不存在。提示词ID:{}", promptId);
|
|
|
|
|
return evidences;
|
|
|
|
|
}
|
|
|
|
|
List<EvidenceDirectory> directories = evidenceDirectories.stream().filter(e -> e.getCategoryId().equals(notePrompt.getEvidenceCategoryId())).toList();
|
|
|
|
|
List<String> directoryIds = directories.stream().map(EvidenceDirectory::getId).toList();
|
|
|
|
|
evidences = caseEvidences.stream().filter(e -> directoryIds.contains(e.getDirectoryId())).toList();
|
|
|
|
|
return evidences;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 手动定义原子指标处理
|
|
|
|
|
*
|
|
|
|
|
* @param analyseCaseDTO
|
|
|
|
|
* @param result
|
|
|
|
|
* @param atomicIndex
|
|
|
|
|
* @param analyseCaseDTO 案件信息
|
|
|
|
|
* @param result 原子指标结果
|
|
|
|
|
* @param atomicIndex 原子指标
|
|
|
|
|
*/
|
|
|
|
|
private void manuallyDefinedCase(AnalyseCaseDTO analyseCaseDTO, ModelAtomicResult result, ModelAtomicIndex atomicIndex) {
|
|
|
|
|
List<ModelAtomicResult> modelAtomicResults = modelAtomicResultMapper.selectList(
|
|
|
|
|