indexRule数据结构调整

topo_dev
DESKTOP-DDTUS3E\yaxin 7 months ago
parent f7da9c67c0
commit 08d1535533

@ -2,14 +2,11 @@ package com.supervision.police.dto.indexRule;
import lombok.Data; import lombok.Data;
import java.util.HashSet;
import java.util.Set;
/** /**
* *
*/ */
@Data @Data
public class Operand{ public class Operand {
/** /**
* id * id
@ -33,7 +30,6 @@ public class Operand{
private String valueType; private String valueType;
/** /**
*
* *
*/ */
private String operandType; private String operandType;
@ -43,11 +39,4 @@ public class Operand{
* 0 1 2 * 0 1 2
*/ */
private String aggregateType; private String aggregateType;
/**
*
* 3
* 4
*/
private String relationalSymbol;
} }

@ -16,4 +16,32 @@ public class RuleCondition {
* *
*/ */
private List<OperandUnit> operandUnitList = new ArrayList<>(); private List<OperandUnit> operandUnitList = new ArrayList<>();
/**
* 1 2 3 4 5:
*/
private String indexSource;
/**
* id
*/
private String atomicIndexId;
/**
*
*/
private String value;
/**
* > >= < <= = !=
*/
private String operator;
/**
*
* 3
* 4
*/
private String relationalSymbol;
} }

@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.supervision.police.domain.ModelIndex; import com.supervision.police.domain.ModelIndex;
import com.supervision.police.domain.ModelIndexAtomicRelation; import com.supervision.police.domain.ModelIndexAtomicRelation;
import com.supervision.police.dto.ModelIndexAtomicRelationDTO; import com.supervision.police.dto.ModelIndexAtomicRelationDTO;
import com.supervision.police.dto.indexRule.IndexRule;
import com.supervision.police.service.ModelIndexAtomicRelationService; import com.supervision.police.service.ModelIndexAtomicRelationService;
import com.supervision.police.mapper.ModelIndexAtomicRelationMapper; import com.supervision.police.mapper.ModelIndexAtomicRelationMapper;
import com.supervision.utils.JudgeLogicUtil; import com.supervision.utils.JudgeLogicUtil;
@ -14,8 +15,10 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Set;
/** /**
* @author Administrator * @author Administrator
@ -45,10 +48,8 @@ public class ModelIndexAtomicRelationServiceImpl extends ServiceImpl<ModelIndexA
return; return;
} }
String judgeLogic = modelIndex.getJudgeLogic(); String judgeLogic = modelIndex.getJudgeLogic();
if (StrUtil.isEmpty(judgeLogic)){ IndexRule indexRule = modelIndex.getIndexRule();
log.info("saveByModelIndex: modelIndex judgeLogic 为空,不保存关联关系....modelIndex:{}", JSONUtil.toJsonStr(modelIndex)); if (StrUtil.isNotEmpty(judgeLogic)){
return;
}
List<String> atomicIndexIds = JudgeLogicUtil.pickAtomicIndexIds(judgeLogic); List<String> atomicIndexIds = JudgeLogicUtil.pickAtomicIndexIds(judgeLogic);
atomicIndexIds.forEach(atomicIndexId -> { atomicIndexIds.forEach(atomicIndexId -> {
ModelIndexAtomicRelation modelIndexAtomicRelation = new ModelIndexAtomicRelation(); ModelIndexAtomicRelation modelIndexAtomicRelation = new ModelIndexAtomicRelation();
@ -56,6 +57,20 @@ public class ModelIndexAtomicRelationServiceImpl extends ServiceImpl<ModelIndexA
modelIndexAtomicRelation.setAtomicIndexId(atomicIndexId); modelIndexAtomicRelation.setAtomicIndexId(atomicIndexId);
super.save(modelIndexAtomicRelation); super.save(modelIndexAtomicRelation);
}); });
}else if(Objects.nonNull(indexRule)){
Set<String> ids = new HashSet<>();
indexRule.getRuleConditionGroupList().forEach(ruleConditionGroup -> {
ruleConditionGroup.getRuleConditionList().forEach(ruleCondition -> {
ids.add(ruleCondition.getAtomicIndexId());
});
});
ids.forEach(atomicIndexId -> {
ModelIndexAtomicRelation modelIndexAtomicRelation = new ModelIndexAtomicRelation();
modelIndexAtomicRelation.setModelIndexId(modelIndex.getId());
modelIndexAtomicRelation.setAtomicIndexId(atomicIndexId);
super.save(modelIndexAtomicRelation);
});
}
} }
@Override @Override

@ -21,6 +21,9 @@ import com.supervision.common.utils.StringUtils;
import com.supervision.constant.DataStatus; import com.supervision.constant.DataStatus;
import com.supervision.police.domain.*; import com.supervision.police.domain.*;
import com.supervision.police.dto.*; import com.supervision.police.dto.*;
import com.supervision.police.dto.indexRule.IndexRule;
import com.supervision.police.dto.indexRule.RuleCondition;
import com.supervision.police.dto.indexRule.RuleConditionGroup;
import com.supervision.police.mapper.CasePersonMapper; import com.supervision.police.mapper.CasePersonMapper;
import com.supervision.police.mapper.ModelAtomicResultMapper; import com.supervision.police.mapper.ModelAtomicResultMapper;
import com.supervision.police.mapper.ModelIndexMapper; import com.supervision.police.mapper.ModelIndexMapper;
@ -86,14 +89,14 @@ public class ModelIndexServiceImpl extends ServiceImpl<ModelIndexMapper, ModelIn
.eq(ModelIndex::getDataStatus, "1"); .eq(ModelIndex::getDataStatus, "1");
if (StrUtil.isNotEmpty(modelIndex.getAtomicIndexName())){ if (StrUtil.isNotEmpty(modelIndex.getAtomicIndexName())) {
// 如果查询条件中有原子指标名称则根据原子指标名称过滤关联的指标id // 如果查询条件中有原子指标名称则根据原子指标名称过滤关联的指标id
List<ModelIndexAtomicRelationDTO> modelIndexAtomicDTOS = modelIndexAtomicRelationService.listByAtomicIndexName(modelIndex.getAtomicIndexName()); List<ModelIndexAtomicRelationDTO> modelIndexAtomicDTOS = modelIndexAtomicRelationService.listByAtomicIndexName(modelIndex.getAtomicIndexName());
List<String> indexIdList = modelIndexAtomicDTOS.stream().map(ModelIndexAtomicRelationDTO::getModelIndexId).distinct().toList(); List<String> indexIdList = modelIndexAtomicDTOS.stream().map(ModelIndexAtomicRelationDTO::getModelIndexId).distinct().toList();
if (CollUtil.isEmpty(indexIdList)){ if (CollUtil.isEmpty(indexIdList)) {
return R.ok(IPages.buildDataMap(iPage)); return R.ok(IPages.buildDataMap(iPage));
} }
wrapper.in(CollUtil.isNotEmpty(indexIdList),ModelIndex::getId, indexIdList); wrapper.in(CollUtil.isNotEmpty(indexIdList), ModelIndex::getId, indexIdList);
} }
wrapper.orderBy(true, false, ModelIndex::getUpdateTime); wrapper.orderBy(true, false, ModelIndex::getUpdateTime);
@ -110,7 +113,19 @@ public class ModelIndexServiceImpl extends ServiceImpl<ModelIndexMapper, ModelIn
//原子指标 //原子指标
String judgeLogic = index.getJudgeLogic(); String judgeLogic = index.getJudgeLogic();
List<String> ids = new ArrayList<>(); List<String> ids = new ArrayList<>();
if (StringUtils.isNotEmpty(judgeLogic)) { IndexRule indexRule = index.getIndexRule();
if (indexRule != null) {
Set<String> idSet = new HashSet<>();
List<RuleConditionGroup> ruleConditionGroupList = indexRule.getRuleConditionGroupList();
for (RuleConditionGroup ruleConditionGroup : ruleConditionGroupList) {
List<RuleCondition> ruleConditionList = ruleConditionGroup.getRuleConditionList();
for (RuleCondition ruleCondition : ruleConditionList) {
idSet.add(ruleCondition.getAtomicIndexId());
}
}
List<ModelAtomicIndex> atomicIndexList = modelAtomicIndexService.selectBatchIds(idSet.stream().toList());
index.setAtomicIndexList(atomicIndexList);
} else if (StringUtils.isNotEmpty(judgeLogic)) {
List<JudgeLogic> logic = JSONUtil.toList(judgeLogic, JudgeLogic.class); List<JudgeLogic> logic = JSONUtil.toList(judgeLogic, JudgeLogic.class);
for (JudgeLogic judge : logic) { for (JudgeLogic judge : logic) {
List<AtomicData> atomicData = judge.getAtomicData(); List<AtomicData> atomicData = judge.getAtomicData();
@ -190,7 +205,7 @@ public class ModelIndexServiceImpl extends ServiceImpl<ModelIndexMapper, ModelIn
ModelAtomicIndex existIndex = modelAtomicIndexService.lambdaQuery().eq(ModelAtomicIndex::getName, modelAtomicIndex.getName()) ModelAtomicIndex existIndex = modelAtomicIndexService.lambdaQuery().eq(ModelAtomicIndex::getName, modelAtomicIndex.getName())
.eq(ModelAtomicIndex::getDataStatus, DataStatus.AVAILABLE.getCode()).last("limit 1").one(); .eq(ModelAtomicIndex::getDataStatus, DataStatus.AVAILABLE.getCode()).last("limit 1").one();
if (ObjectUtil.isNotEmpty(existIndex) && !StringUtils.equals(modelAtomicIndex.getId(), existIndex.getId())){ if (ObjectUtil.isNotEmpty(existIndex) && !StringUtils.equals(modelAtomicIndex.getId(), existIndex.getId())) {
throw new RuntimeException("已存在相同名称的原子指标"); throw new RuntimeException("已存在相同名称的原子指标");
} }
@ -200,6 +215,7 @@ public class ModelIndexServiceImpl extends ServiceImpl<ModelIndexMapper, ModelIn
/** /**
* *
*
* @param modelAtomicIndex * @param modelAtomicIndex
*/ */
private void saveAtomicIndexPreDo(ModelAtomicIndex modelAtomicIndex) { private void saveAtomicIndexPreDo(ModelAtomicIndex modelAtomicIndex) {
@ -208,7 +224,7 @@ public class ModelIndexServiceImpl extends ServiceImpl<ModelIndexMapper, ModelIn
// 如果查询类型为数据查询,则校验查询语句 // 如果查询类型为数据查询,则校验查询语句
Assert.notEmpty(modelAtomicIndex.getQueryLang(), "查询语言不能为空"); Assert.notEmpty(modelAtomicIndex.getQueryLang(), "查询语言不能为空");
Assert.isTrue(checkSql(modelAtomicIndex.getQueryLang()), "查询语句不合法"); Assert.isTrue(checkSql(modelAtomicIndex.getQueryLang()), "查询语句不合法");
}else if (StringUtils.equals(IndexRuleConstants.OPERAND_TYPE_LLM, modelAtomicIndex.getIndexSource())){ } else if (StringUtils.equals(IndexRuleConstants.OPERAND_TYPE_LLM, modelAtomicIndex.getIndexSource())) {
Assert.notEmpty(modelAtomicIndex.getPromptId(), "promptId不能为空"); Assert.notEmpty(modelAtomicIndex.getPromptId(), "promptId不能为空");
NotePrompt notePrompt = notePromptService.getBaseMapper().selectById(modelAtomicIndex.getPromptId()); NotePrompt notePrompt = notePromptService.getBaseMapper().selectById(modelAtomicIndex.getPromptId());
Assert.notNull(notePrompt, "提示词信息不存在"); Assert.notNull(notePrompt, "提示词信息不存在");
@ -281,9 +297,9 @@ public class ModelIndexServiceImpl extends ServiceImpl<ModelIndexMapper, ModelIn
// 以原子指标为基准,组装数据 // 以原子指标为基准,组装数据
return modelAtomicIndexList.stream().flatMap(atomicIndex -> return modelAtomicIndexList.stream().flatMap(atomicIndex ->
modelIndexMapAtomic.get(atomicIndex.getId()).stream().map(modelIndex ->{ modelIndexMapAtomic.get(atomicIndex.getId()).stream().map(modelIndex -> {
Map<String, List<ModelAtomicResult>> map = modelAtomicResultGroup.getOrDefault(modelIndex.getId(),new HashMap<>(1)); Map<String, List<ModelAtomicResult>> map = modelAtomicResultGroup.getOrDefault(modelIndex.getId(), new HashMap<>(1));
return new CaseAtomicIndexDTO(atomicIndex, modelIndex,CollUtil.getFirst(map.get(atomicIndex.getId()))); return new CaseAtomicIndexDTO(atomicIndex, modelIndex, CollUtil.getFirst(map.get(atomicIndex.getId())));
}) })
).toList(); ).toList();
} }
@ -351,18 +367,18 @@ public class ModelIndexServiceImpl extends ServiceImpl<ModelIndexMapper, ModelIn
} }
@Override @Override
public Map<String,List<ValueCalculateScopeDTO>> listAtomicIndexAttributeScope(List<String> atomicIndexIds) { public Map<String, List<ValueCalculateScopeDTO>> listAtomicIndexAttributeScope(List<String> atomicIndexIds) {
if (CollUtil.isEmpty(atomicIndexIds)){ if (CollUtil.isEmpty(atomicIndexIds)) {
return Map.of(); return Map.of();
} }
Map<String, List<ValueCalculateScopeDTO>> result = atomicIndexIds.stream().collect(Collectors.toMap(i -> i, i->List.of())); Map<String, List<ValueCalculateScopeDTO>> result = atomicIndexIds.stream().collect(Collectors.toMap(i -> i, i -> List.of()));
List<ModelAtomicIndex> atomicIndexList = modelAtomicIndexService.listByIds(atomicIndexIds); List<ModelAtomicIndex> atomicIndexList = modelAtomicIndexService.listByIds(atomicIndexIds);
if (CollUtil.isEmpty(atomicIndexList)){ if (CollUtil.isEmpty(atomicIndexList)) {
return result; return result;
} }
List<String> promptIds = atomicIndexList.stream().map(ModelAtomicIndex::getPromptId).filter(StrUtil::isNotEmpty).toList(); List<String> promptIds = atomicIndexList.stream().map(ModelAtomicIndex::getPromptId).filter(StrUtil::isNotEmpty).toList();
if (CollUtil.isEmpty(promptIds)){ if (CollUtil.isEmpty(promptIds)) {
return result; return result;
} }
@ -371,7 +387,7 @@ public class ModelIndexServiceImpl extends ServiceImpl<ModelIndexMapper, ModelIn
for (Map.Entry<String, List<ValueCalculateScopeDTO>> entry : result.entrySet()) { for (Map.Entry<String, List<ValueCalculateScopeDTO>> entry : result.entrySet()) {
List<ValueCalculateScopeDTO> scopeDTOList = makeScopes(entry.getKey(), atomicIndexList, notePrompts, dicMap); List<ValueCalculateScopeDTO> scopeDTOList = makeScopes(entry.getKey(), atomicIndexList, notePrompts, dicMap);
if (scopeDTOList != null){ if (scopeDTOList != null) {
entry.setValue(scopeDTOList); entry.setValue(scopeDTOList);
} }
} }
@ -380,15 +396,15 @@ public class ModelIndexServiceImpl extends ServiceImpl<ModelIndexMapper, ModelIn
private List<ValueCalculateScopeDTO> makeScopes(String atomicIndexId, List<ModelAtomicIndex> atomicIndexList, List<NotePrompt> notePrompts, Map<String, String> dicMap) { private List<ValueCalculateScopeDTO> makeScopes(String atomicIndexId, List<ModelAtomicIndex> atomicIndexList, List<NotePrompt> notePrompts, Map<String, String> dicMap) {
ModelAtomicIndex modelAtomicIndex = atomicIndexList.stream().filter(i -> StrUtil.equals(atomicIndexId, i.getId())).findFirst().orElse(null); ModelAtomicIndex modelAtomicIndex = atomicIndexList.stream().filter(i -> StrUtil.equals(atomicIndexId, i.getId())).findFirst().orElse(null);
if (null == modelAtomicIndex || StrUtil.isEmpty(modelAtomicIndex.getPromptId())){ if (null == modelAtomicIndex || StrUtil.isEmpty(modelAtomicIndex.getPromptId())) {
return null; return null;
} }
String properties = modelAtomicIndex.getProperties(); String properties = modelAtomicIndex.getProperties();
if (StrUtil.isEmpty(properties)){ if (StrUtil.isEmpty(properties)) {
return null; return null;
} }
NotePrompt notePromptDTO = notePrompts.stream().filter(i -> StrUtil.equals(modelAtomicIndex.getPromptId(), i.getId())).findFirst().orElse(null); NotePrompt notePromptDTO = notePrompts.stream().filter(i -> StrUtil.equals(modelAtomicIndex.getPromptId(), i.getId())).findFirst().orElse(null);
if (null == notePromptDTO){ if (null == notePromptDTO) {
return null; return null;
} }
List<NotePromptExtractAttributesDto> extractAttributes = notePromptDTO.getExtractAttributes(); List<NotePromptExtractAttributesDto> extractAttributes = notePromptDTO.getExtractAttributes();

@ -21,6 +21,7 @@ import com.supervision.police.dto.caseScore.CaseScoreDetailBuilder;
import com.supervision.police.dto.caseScore.CaseScoreDetailDTO; import com.supervision.police.dto.caseScore.CaseScoreDetailDTO;
import com.supervision.police.dto.indexRule.IndexRule; import com.supervision.police.dto.indexRule.IndexRule;
import com.supervision.police.dto.indexRule.Operand; import com.supervision.police.dto.indexRule.Operand;
import com.supervision.police.dto.indexRule.OperandUnit;
import com.supervision.police.mapper.*; import com.supervision.police.mapper.*;
import com.supervision.police.mybatis.RowSqlMapper; import com.supervision.police.mybatis.RowSqlMapper;
import com.supervision.police.service.*; import com.supervision.police.service.*;
@ -196,8 +197,10 @@ public class ModelServiceImpl implements ModelService {
List<EvidenceDirectory> evidenceDirectories = evidenceDirectoryService.list(new LambdaQueryWrapper<EvidenceDirectory>().eq(EvidenceDirectory::getCaseId, caseId)); List<EvidenceDirectory> evidenceDirectories = evidenceDirectoryService.list(new LambdaQueryWrapper<EvidenceDirectory>().eq(EvidenceDirectory::getCaseId, caseId));
// 查出证据信息 // 查出证据信息
List<CaseEvidence> caseEvidences = caseEvidenceService.list(new LambdaQueryWrapper<CaseEvidence>().eq(CaseEvidence::getCaseId, caseId)); List<CaseEvidence> caseEvidences = caseEvidenceService.list(new LambdaQueryWrapper<CaseEvidence>().eq(CaseEvidence::getCaseId, caseId));
log.info("开始计算指标结果");
// 遍历指标集合,处理每个指标的判断逻辑,得出结果 // 遍历指标集合,处理每个指标的判断逻辑,得出结果
modelIndices.forEach(modelIndex -> { modelIndices.forEach(modelIndex -> {
log.info("开始计算指标ID:{},指标名称:{}", modelIndex.getId(), modelIndex.getName());
IndexRule indexRule = modelIndex.getIndexRule(); IndexRule indexRule = modelIndex.getIndexRule();
Set<Boolean> ruleConditionGroupResultList = new HashSet<>(); Set<Boolean> ruleConditionGroupResultList = new HashSet<>();
if (indexRule != null) { if (indexRule != null) {
@ -205,15 +208,16 @@ public class ModelServiceImpl implements ModelService {
Set<Boolean> ruleConditionResultSet = new HashSet<>(); Set<Boolean> ruleConditionResultSet = new HashSet<>();
ruleConditionGroup.getRuleConditionList().forEach(ruleCondition -> { ruleConditionGroup.getRuleConditionList().forEach(ruleCondition -> {
Set<Boolean> operandUnitResultSet = new HashSet<>(); Set<Boolean> operandUnitResultSet = new HashSet<>();
ruleCondition.getOperandUnitList().forEach(operandUnit -> { // 得到当前指标要求的存在关系(存在或不存在)
Operand left = operandUnit.getLeftOperand(); boolean relationSymbol = IndexRuleConstants.EVALUATE_RESULT_EXIST.equals(ruleCondition.getRelationalSymbol());
boolean relationSymbol = IndexRuleConstants.EVALUATE_RESULT_EXIST.equals(left.getRelationalSymbol()); ModelAtomicIndex modelAtomicIndex = atomicIndices.stream().filter(atomicIndex -> atomicIndex.getId().equals(ruleCondition.getAtomicIndexId())).findAny().orElse(null);
Operand right = operandUnit.getRightOperand();
ModelAtomicIndex modelAtomicIndex = atomicIndices.stream().filter(atomicIndex -> atomicIndex.getId().equals(left.getAtomicIndexId())).findAny().orElse(null);
if (modelAtomicIndex == null) { if (modelAtomicIndex == null) {
log.error("原子指标不存在,跳出当前循环。原子指标ID:{}", left.getAtomicIndexId()); log.error("原子指标不存在,跳出当前循环。原子指标ID:{}", ruleCondition.getAtomicIndexId());
return; return;
} }
ruleCondition.getOperandUnitList().forEach(operandUnit -> {
Operand left = operandUnit.getLeftOperand();
Operand right = operandUnit.getRightOperand();
// 定义原子指标结果共有属性 // 定义原子指标结果共有属性
ModelAtomicResult result = new ModelAtomicResult(); ModelAtomicResult result = new ModelAtomicResult();
result.setIndexId(modelIndex.getId()); result.setIndexId(modelIndex.getId());
@ -225,9 +229,9 @@ public class ModelServiceImpl implements ModelService {
if (exist != null) { if (exist != null) {
result.setId(exist.getId()); result.setId(exist.getId());
} }
switch (left.getOperandType()) { switch (ruleCondition.getIndexSource()) {
case OPERAND_TYPE_MANUAL: case OPERAND_TYPE_MANUAL:
operandUnitResultSet.add(relationSymbol == manualIndexAnalysis(left.getAtomicIndexId(), caseId)); operandUnitResultSet.add(relationSymbol == manualIndexAnalysis(ruleCondition.getAtomicIndexId(), caseId));
break; break;
case OPERAND_TYPE_DB: case OPERAND_TYPE_DB:
operandUnitResultSet.add(relationSymbol == dbIndexAnalysis(caseId, modelAtomicIndex.getQueryLang(), result)); operandUnitResultSet.add(relationSymbol == dbIndexAnalysis(caseId, modelAtomicIndex.getQueryLang(), result));
@ -236,7 +240,7 @@ public class ModelServiceImpl implements ModelService {
operandUnitResultSet.add(relationSymbol == graphIndexAnalysis(casePerson.getName(), modelAtomicIndex, analyseCaseDTO, result)); operandUnitResultSet.add(relationSymbol == graphIndexAnalysis(casePerson.getName(), modelAtomicIndex, analyseCaseDTO, result));
break; break;
case OPERAND_TYPE_STRUCTURE: case OPERAND_TYPE_STRUCTURE:
operandUnitResultSet.add(structureIndexAnalysis(left, right, operandUnit.getOperator(), modelAtomicIndex, atomicIndices, notePrompts, evidenceDirectories, caseEvidences, result)); operandUnitResultSet.add(structureIndexAnalysis(operandUnit, modelAtomicIndex, atomicIndices, notePrompts, evidenceDirectories, caseEvidences, result));
break; break;
default: default:
break; break;
@ -341,11 +345,12 @@ public class ModelServiceImpl implements ModelService {
params.put("lawActor", casePersonName); params.put("lawActor", casePersonName);
// 案号 // 案号
params.put("caseId", analyseCaseDTO.getCaseId()); params.put("caseId", analyseCaseDTO.getCaseId());
Result run = null; Result run;
try { try {
run = session.run(modelAtomicIndex.getQueryLang(), params); run = session.run(modelAtomicIndex.getQueryLang(), params);
} catch (Exception e) { } catch (Exception e) {
log.error("图数据库查询出现错误,查询语句{},参数{}", modelAtomicIndex.getQueryLang(), JSONUtil.toJsonStr(params), e); log.error("图数据库查询出现错误,查询语句{},参数{}", modelAtomicIndex.getQueryLang(), JSONUtil.toJsonStr(params), e);
return flag;
} }
List<ResultDTO> res = Neo4jUtils.getResultDTOList(run); List<ResultDTO> res = Neo4jUtils.getResultDTOList(run);
if (!res.isEmpty()) { if (!res.isEmpty()) {
@ -372,8 +377,7 @@ public class ModelServiceImpl implements ModelService {
/** /**
* *
* *
* @param left * @param operandUnit
* @param right
* @param modelAtomicIndex * @param modelAtomicIndex
* @param atomicIndices * @param atomicIndices
* @param notePrompts * @param notePrompts
@ -382,7 +386,10 @@ public class ModelServiceImpl implements ModelService {
* @param atomicResult * @param atomicResult
* @return * @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) { private boolean structureIndexAnalysis(OperandUnit operandUnit, ModelAtomicIndex modelAtomicIndex, List<ModelAtomicIndex> atomicIndices, List<NotePrompt> notePrompts, List<EvidenceDirectory> evidenceDirectories, List<CaseEvidence> caseEvidences, ModelAtomicResult atomicResult) {
Operand left = operandUnit.getLeftOperand();
String operator = operandUnit.getOperator();
Operand right = operandUnit.getRightOperand();
boolean flag = false; boolean flag = false;
List<CaseEvidence> evidences = getEvidencesByPromptId(modelAtomicIndex.getPromptId(), caseEvidences, evidenceDirectories, notePrompts); List<CaseEvidence> evidences = getEvidencesByPromptId(modelAtomicIndex.getPromptId(), caseEvidences, evidenceDirectories, notePrompts);
ModelAtomicIndex rightModelAtomicIndex = null; ModelAtomicIndex rightModelAtomicIndex = null;
@ -400,14 +407,14 @@ public class ModelServiceImpl implements ModelService {
case AGGREGATE_TYPE_SUM: case AGGREGATE_TYPE_SUM:
if (OPERAND_TYPE_STRUCTURE.equals(right.getOperandType())) { if (OPERAND_TYPE_STRUCTURE.equals(right.getOperandType())) {
List<CaseEvidence> rightEvidences = getEvidencesByPromptId(rightModelAtomicIndex.getPromptId(), caseEvidences, evidenceDirectories, notePrompts); List<CaseEvidence> rightEvidences = getEvidencesByPromptId(rightModelAtomicIndex.getPromptId(), caseEvidences, evidenceDirectories, notePrompts);
if (CalculationUtil.evaluateExpression(String.valueOf(getSumFromEvidences(left, evidences)), operator, String.valueOf(getSumFromEvidences(right, rightEvidences)))) { if (CalculationUtil.evaluateExpression(String.valueOf(getSumFromEvidences(left.getPropertyKey(), evidences)), operator, String.valueOf(getSumFromEvidences(right.getPropertyKey(), rightEvidences)))) {
atomicResult.setEvidenceId(evidences.stream().map(CaseEvidence::getId).collect(Collectors.joining(","))); atomicResult.setEvidenceId(evidences.stream().map(CaseEvidence::getId).collect(Collectors.joining(",")));
atomicResult.setAtomicResult(JudgeResultEnum.EXIST.getCode()); atomicResult.setAtomicResult(JudgeResultEnum.EXIST.getCode());
modelAtomicResultService.saveOrUpdate(atomicResult); modelAtomicResultService.saveOrUpdate(atomicResult);
return true; return true;
} }
} else if (OPERAND_TYPE_VALUE.equals(right.getOperandType())) { } else if (OPERAND_TYPE_VALUE.equals(right.getOperandType())) {
if (CalculationUtil.evaluateExpression(String.valueOf(getSumFromEvidences(left, evidences)), operator, right.getValue())) { if (CalculationUtil.evaluateExpression(String.valueOf(getSumFromEvidences(left.getPropertyKey(), evidences)), operator, right.getValue())) {
atomicResult.setEvidenceId(evidences.stream().map(CaseEvidence::getId).collect(Collectors.joining(","))); atomicResult.setEvidenceId(evidences.stream().map(CaseEvidence::getId).collect(Collectors.joining(",")));
atomicResult.setAtomicResult(JudgeResultEnum.EXIST.getCode()); atomicResult.setAtomicResult(JudgeResultEnum.EXIST.getCode());
modelAtomicResultService.saveOrUpdate(atomicResult); modelAtomicResultService.saveOrUpdate(atomicResult);
@ -464,14 +471,14 @@ public class ModelServiceImpl implements ModelService {
return flag; return flag;
} }
private Double getSumFromEvidences(Operand operand, List<CaseEvidence> evidences) { private Double getSumFromEvidences(String propertyKey, List<CaseEvidence> evidences) {
AtomicReference<Double> sum = new AtomicReference<>(0.0); AtomicReference<Double> sum = new AtomicReference<>(0.0);
if (evidences != null && !evidences.isEmpty()) { if (evidences != null && !evidences.isEmpty()) {
evidences.forEach(e -> { evidences.forEach(e -> {
List<NotePromptExtractAttributesDto> properties = e.getProperty(); List<NotePromptExtractAttributesDto> properties = e.getProperty();
if (properties != null && !properties.isEmpty()) { if (properties != null && !properties.isEmpty()) {
properties.forEach(p -> { properties.forEach(p -> {
if (p.getAttrName().equals(operand.getPropertyKey())) { if (p.getAttrName().equals(propertyKey)) {
if (StringUtils.isNotEmpty(p.getAttrValue())) { if (StringUtils.isNotEmpty(p.getAttrValue())) {
sum.updateAndGet(v -> v + NumberUtil.parseDouble(p.getAttrValue())); sum.updateAndGet(v -> v + NumberUtil.parseDouble(p.getAttrValue()));
} }

@ -1,11 +1,14 @@
package com.supervision.demo; package com.supervision.demo;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.supervision.common.constant.IndexRuleConstants;
import com.supervision.police.domain.ModelAtomicIndex; import com.supervision.police.domain.ModelAtomicIndex;
import com.supervision.police.domain.ModelIndex; import com.supervision.police.domain.ModelIndex;
import com.supervision.police.dto.AnalyseCaseDTO; import com.supervision.police.dto.AnalyseCaseDTO;
import com.supervision.police.dto.JudgeLogic; import com.supervision.police.dto.JudgeLogic;
import com.supervision.police.dto.indexRule.*; import com.supervision.police.dto.indexRule.IndexRule;
import com.supervision.police.dto.indexRule.RuleCondition;
import com.supervision.police.dto.indexRule.RuleConditionGroup;
import com.supervision.police.service.ModelAtomicIndexService; import com.supervision.police.service.ModelAtomicIndexService;
import com.supervision.police.service.ModelIndexService; import com.supervision.police.service.ModelIndexService;
import com.supervision.police.service.ModelService; import com.supervision.police.service.ModelService;
@ -58,15 +61,15 @@ public class CaseTest {
} }
judgeLogic.getAtomicData().forEach(atomicData -> { judgeLogic.getAtomicData().forEach(atomicData -> {
RuleCondition ruleCondition = new RuleCondition(); RuleCondition ruleCondition = new RuleCondition();
OperandUnit operandUnit = new OperandUnit(); ruleCondition.setAtomicIndexId(atomicData.getAtomicIndex());
Operand left = new Operand(); ruleCondition.setRelationalSymbol(atomicData.getRelationalSymbol());
left.setAtomicIndexId(atomicData.getAtomicIndex());
left.setRelationalSymbol(atomicData.getRelationalSymbol());
modelAtomicIndices.stream().filter(modelAtomicIndex -> modelAtomicIndex.getId().equals(atomicData.getAtomicIndex())).findFirst().ifPresent(modelAtomicIndex -> { modelAtomicIndices.stream().filter(modelAtomicIndex -> modelAtomicIndex.getId().equals(atomicData.getAtomicIndex())).findFirst().ifPresent(modelAtomicIndex -> {
left.setOperandType(modelAtomicIndex.getIndexSource()); if (modelAtomicIndex.getIndexSource().equals(IndexRuleConstants.OPERAND_TYPE_GRAPH)) {
ruleCondition.setOperator(">");
ruleCondition.setValue("0");
}
ruleCondition.setIndexSource(modelAtomicIndex.getIndexSource());
}); });
operandUnit.setLeftOperand(left);
ruleCondition.setOperandUnitList(List.of(operandUnit));
ruleConditions.add(ruleCondition); ruleConditions.add(ruleCondition);
}); });
ruleConditionGroup.setRuleConditionList(ruleConditions); ruleConditionGroup.setRuleConditionList(ruleConditions);

Loading…
Cancel
Save