修改-修复原子指标可能重复的问题

topo_dev
liu 9 months ago
parent 24d4e8217a
commit 7df5b3de43

@ -14,6 +14,7 @@ public interface ModelAtomicResultMapper extends BaseMapper<ModelAtomicResult> {
ModelAtomicResult selectByCaseIdAndAtomicId(@Param("caseId") String caseId, ModelAtomicResult selectByCaseIdAndAtomicId(@Param("caseId") String caseId,
@Param("casePersonId") String casePersonId, @Param("casePersonId") String casePersonId,
@Param("indexId") String indexId,
@Param("atomicId") String atomicId); @Param("atomicId") String atomicId);
} }

@ -26,10 +26,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.mapper.*; import com.supervision.police.mapper.*;
import com.supervision.police.mybatis.RowSqlMapper; import com.supervision.police.mybatis.RowSqlMapper;
import com.supervision.police.service.CaseStatusManageService; import com.supervision.police.service.*;
import com.supervision.police.service.ModelIndexService;
import com.supervision.police.service.ModelService;
import com.supervision.police.service.NoteRecordService;
import com.supervision.utils.SqlParserUtil; import com.supervision.utils.SqlParserUtil;
import jakarta.servlet.ServletOutputStream; import jakarta.servlet.ServletOutputStream;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
@ -41,6 +38,7 @@ import org.neo4j.driver.Session;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader; import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -75,9 +73,12 @@ public class ModelServiceImpl implements ModelService {
private final CaseStatusManageService caseStatusManageService; private final CaseStatusManageService caseStatusManageService;
private final ModelIndexAtomicRelationService modelIndexAtomicRelationService;
private final NoteRecordService noteRecordService; private final NoteRecordService noteRecordService;
@Override @Override
@Transactional(transactionManager = "dataSourceTransactionManager", rollbackFor = Exception.class)
public R<?> analyseCase(AnalyseCaseDTO analyseCaseDTO) { public R<?> analyseCase(AnalyseCaseDTO analyseCaseDTO) {
CaseStatus caseDateStatus = this.getCaseDateStatus(analyseCaseDTO.getCaseId()); CaseStatus caseDateStatus = this.getCaseDateStatus(analyseCaseDTO.getCaseId());
@ -98,7 +99,8 @@ public class ModelServiceImpl implements ModelService {
modelIndexResultMapper.updatePreResult(analyseCaseDTO.getCaseId()); modelIndexResultMapper.updatePreResult(analyseCaseDTO.getCaseId());
//原子指标 //原子指标
List<ModelAtomicIndex> atomicIndices = modelAtomicIndexMapper.selectByCaseType(modelCase.getCaseType()); List<ModelAtomicIndex> atomicIndices = modelAtomicIndexMapper.selectByCaseType(modelCase.getCaseType());
Map<String, String> atomicResultMap = new HashMap<>(); // 存放原子指标的结果,key:原子指标ID,value:(key大指标ID,value:结果)
Map<String, Map<String,String>> atomicResultMap = new HashMap<>();
for (ModelAtomicIndex atomicIndex : atomicIndices) { for (ModelAtomicIndex atomicIndex : atomicIndices) {
//原子指标结果 //原子指标结果
ModelAtomicResult result = new ModelAtomicResult(); ModelAtomicResult result = new ModelAtomicResult();
@ -110,10 +112,6 @@ public class ModelServiceImpl implements ModelService {
//原子指标结果表 //原子指标结果表
try { try {
// index_source==1
// List<ModelAtomicIndex> list = analyseCaseDTO.getAtomicIndexList();
//index_source==3
//查询图谱 index_source: 1人工定义 2数据库查询 3图谱生成 4大模型 //查询图谱 index_source: 1人工定义 2数据库查询 3图谱生成 4大模型
if ("1".equals(atomicIndex.getIndexSource())) { if ("1".equals(atomicIndex.getIndexSource())) {
// list // list
@ -130,21 +128,30 @@ public class ModelServiceImpl implements ModelService {
} catch (Exception e) { } catch (Exception e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
} }
// 非人工填写的,需要进行更新结果,人工填写的不更新(人工填写的编码,需要进行特殊处理) // 根据原子指标ID查model_index_atomic_relation表所有的指标ID
//保存原子指标结果表 List<ModelIndexAtomicRelation> relationList = modelIndexAtomicRelationService.lambdaQuery().eq(ModelIndexAtomicRelation::getAtomicIndexId, atomicIndex.getId()).list();
ModelAtomicResult exist = modelAtomicResultMapper.selectByCaseIdAndAtomicId(analyseCaseDTO.getCaseId(), casePerson.getId(), atomicIndex.getId()); for (ModelIndexAtomicRelation relation : relationList) {
// 保存或更新原子指标结果表
ModelAtomicResult exist = modelAtomicResultMapper.selectByCaseIdAndAtomicId(analyseCaseDTO.getCaseId(), casePerson.getId(),relation.getModelIndexId(), atomicIndex.getId());
result.setIndexId(relation.getModelIndexId());
if (exist == null) { if (exist == null) {
modelAtomicResultMapper.insert(result); modelAtomicResultMapper.insert(result);
} else { } else {
result.setId(exist.getId()); result.setId(exist.getId());
modelAtomicResultMapper.updateById(result); modelAtomicResultMapper.updateById(result);
} }
atomicResultMap.put(result.getAtomicId(), result.getAtomicResult()); Map<String, String> indexMap = atomicResultMap.computeIfAbsent(
result.getAtomicId(),
k -> new HashMap<>() // 如果不存在则创建一个新的 HashMap
);
indexMap.put(relation.getModelIndexId(), result.getAtomicResult());
}
} }
// 最终计算得分 // 最终计算得分
calculateFinalScore(analyseCaseDTO, modelCase, atomicResultMap); calculateFinalScore(analyseCaseDTO, modelCase, atomicResultMap);
caseStatusManageService.whenAnalyseCaseSuccess(analyseCaseDTO.getCaseId(), modelCase.getTotalScore()); caseStatusManageService.whenAnalyseCaseSuccess(analyseCaseDTO.getCaseId(), modelCase.getTotalScore());
// TODO 计算完成之后,把所有的笔录异步上传到模型 // 计算完成之后,把所有的笔录上传到模型
noteRecordService.uploadFileToLangChainChat(analyseCaseDTO.getCaseId()); noteRecordService.uploadFileToLangChainChat(analyseCaseDTO.getCaseId());
return R.ok(); return R.ok();
} }
@ -229,7 +236,7 @@ public class ModelServiceImpl implements ModelService {
/** /**
* *
*/ */
private void calculateFinalScore(AnalyseCaseDTO analyseCaseDTO, ModelCase modelCase, Map<String, String> atomicResultMap) { private void calculateFinalScore(AnalyseCaseDTO analyseCaseDTO, ModelCase modelCase, Map<String, Map<String,String>> atomicResultMap) {
// 计算指标结果 // 计算指标结果
int score = 0; int score = 0;
// 根据案件类型获取所有的指标 // 根据案件类型获取所有的指标
@ -257,8 +264,10 @@ public class ModelServiceImpl implements ModelService {
for (int j = 0; j < atomicData.size(); j++) { for (int j = 0; j < atomicData.size(); j++) {
AtomicData data = atomicData.get(j); AtomicData data = atomicData.get(j);
atomicIds.add(data.getAtomicIndex()); atomicIds.add(data.getAtomicIndex());
// 先找到原子指标对应的大指标的结果
Map<String, String> atomicIndexMap = atomicResultMap.get(data.getAtomicIndex());
// 这里可能不存在,如果未找到,就默认为false // 这里可能不存在,如果未找到,就默认为false
String atomicIndexResult = atomicResultMap.getOrDefault(data.getAtomicIndex(), JudgeResultEnum.UNKNOWN.getCode()); String atomicIndexResult = atomicIndexMap.getOrDefault(modelIndex.getId(), JudgeResultEnum.UNKNOWN.getCode());
String relationalSymbol = data.getRelationalSymbol(); String relationalSymbol = data.getRelationalSymbol();
JudgeResultEnum instance = JudgeResultEnum.getInstance(relationalSymbol); JudgeResultEnum instance = JudgeResultEnum.getInstance(relationalSymbol);
boolean ato = StrUtil.equals(atomicIndexResult, instance.getCode()); boolean ato = StrUtil.equals(atomicIndexResult, instance.getCode());

@ -10,6 +10,9 @@
<if test="atomicId != null and atomicId != ''"> <if test="atomicId != null and atomicId != ''">
and atomic_id = #{atomicId} and atomic_id = #{atomicId}
</if> </if>
<if test="indexId != null and indexId != ''">
and index_id = #{indexId}
</if>
<if test="casePersonId != null and casePersonId != ''"> <if test="casePersonId != null and casePersonId != ''">
and case_person_id = #{casePersonId} and case_person_id = #{casePersonId}
</if> </if>

Loading…
Cancel
Save