diff --git a/src/main/java/com/supervision/police/service/impl/ModelServiceImpl.java b/src/main/java/com/supervision/police/service/impl/ModelServiceImpl.java index 10e8ff7..50d9de2 100644 --- a/src/main/java/com/supervision/police/service/impl/ModelServiceImpl.java +++ b/src/main/java/com/supervision/police/service/impl/ModelServiceImpl.java @@ -27,6 +27,7 @@ import com.supervision.police.mapper.*; import com.supervision.police.mybatis.RowSqlMapper; import com.supervision.police.service.*; import com.supervision.utils.CalculationUtil; +import com.supervision.utils.IndexRuleUtil; import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -221,6 +222,9 @@ public class ModelServiceImpl implements ModelService { log.error("未找到指标原子关系信息"); return R.fail("未找到指标原子关系信息"); } + + List modelAtomicResultList = modelAtomicResultService.lambdaQuery().eq(ModelAtomicResult::getCaseId, caseId).list(); + log.info("开始计算指标结果"); // 遍历指标集合,处理每个指标的判断逻辑,得出结果 modelIndices.forEach(modelIndex -> { @@ -290,6 +294,10 @@ public class ModelServiceImpl implements ModelService { modelIndexResult.setId(exist.getId()); } modelIndexResult.setIndexResult(result ? "true" : "false"); + + // 先清除掉与指标失去关联的原子指标对应的结果 + removeAtomicResultWithNoReference(modelIndex.getId(), modelIndexAtomicRelations, modelAtomicResultList); + if (exist == null) { modelIndexResultMapper.insert(modelIndexResult); } else { @@ -313,6 +321,22 @@ public class ModelServiceImpl implements ModelService { return R.ok(); } + private void removeAtomicResultWithNoReference(String modelIndexId, List modelIndexAtomicRelations, + List modelAtomicResultList) { + List atomicIds = modelIndexAtomicRelations.stream() + .filter(relation -> StrUtil.equals(relation.getModelIndexId(), modelIndexId)) + .map(ModelIndexAtomicRelation::getAtomicIndexId).toList(); + + List modelAtomicResults = modelAtomicResultList.stream() + .filter(atomicResult -> StrUtil.equals(atomicResult.getIndexId(), modelIndexId) + && !atomicIds.contains(atomicResult.getAtomicId())).toList(); + + for (ModelAtomicResult modelAtomicResult : modelAtomicResults) { + log.info("删除无引用的原子指标结果,指标id:{},原子指标ID:{}", modelIndexId,modelAtomicResult.getAtomicId()); + modelAtomicResultMapper.deleteById(modelAtomicResult.getId()); + } + } + /** * 人工定义指标分析 * diff --git a/src/main/resources/mapper/ModelCaseMapper.xml b/src/main/resources/mapper/ModelCaseMapper.xml index 3513ded..ec17d34 100644 --- a/src/main/resources/mapper/ModelCaseMapper.xml +++ b/src/main/resources/mapper/ModelCaseMapper.xml @@ -128,6 +128,7 @@ and exists(select 1 from model_atomic_result mar + join model_index_atomic_relation iar on mar.index_id = iar.model_index_id and mar.atomic_id = iar.atomic_index_id left join note_record_split nrs on mar.record_split_id = nrs.id left join model_atomic_index mai on mar.atomic_id = mai.id where mar.case_id = #{query.caseId}