Commit fd1d8f56 by zhouhaibao

[+]岚图质检逻辑调整,新的规则模版新增

1 parent bc337879
Showing 15 changed files with 307 additions and 39 deletions
...@@ -62,4 +62,10 @@ public class RecordingTagGroup { ...@@ -62,4 +62,10 @@ public class RecordingTagGroup {
*/ */
private String description; private String description;
/**
* 配置编码
*/
@Column(name = "config_code")
private String configCode;
} }
\ No newline at end of file \ No newline at end of file
...@@ -123,4 +123,10 @@ public class RecordingTagRuleMapping { ...@@ -123,4 +123,10 @@ public class RecordingTagRuleMapping {
*/ */
@Transient @Transient
private BigDecimal sumScore; private BigDecimal sumScore;
/**
* 配置编码
*/
@Transient
private String configCode;
} }
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.dj.mindworkplate.job; package cn.com.glsx.dj.mindworkplate.job;
import cn.com.glsx.dj.mindworkplate.config.ModelTypeConfig;
import cn.com.glsx.dj.mindworkplate.constant.RedisKeyConstants; import cn.com.glsx.dj.mindworkplate.constant.RedisKeyConstants;
import cn.com.glsx.dj.mindworkplate.enums.BadgeManufacturerEnum; import cn.com.glsx.dj.mindworkplate.enums.BadgeManufacturerEnum;
import cn.com.glsx.dj.mindworkplate.mapper.BadgeRecordingsMapper;
import cn.com.glsx.dj.mindworkplate.model.BadgeRecordings; import cn.com.glsx.dj.mindworkplate.model.BadgeRecordings;
import cn.com.glsx.dj.mindworkplate.model.ConversationBatch; import cn.com.glsx.dj.mindworkplate.model.ConversationBatch;
import cn.com.glsx.dj.mindworkplate.model.EmployeeBadge; import cn.com.glsx.dj.mindworkplate.model.EmployeeBadge;
...@@ -30,6 +32,12 @@ public class CheckResultJob implements SimpleJob { ...@@ -30,6 +32,12 @@ public class CheckResultJob implements SimpleJob {
@Autowired @Autowired
private ConversationDateService conversationDateService; private ConversationDateService conversationDateService;
@Autowired
private BadgeRecordingsMapper badgeRecordingsMapper;
@Autowired
private ModelTypeConfig modelTypeConfig;
@Override @Override
public void execute(ShardingContext shardingContext) { public void execute(ShardingContext shardingContext) {
log.info("----------------获取质检结果任务开始-----------------"); log.info("----------------获取质检结果任务开始-----------------");
...@@ -37,7 +45,13 @@ public class CheckResultJob implements SimpleJob { ...@@ -37,7 +45,13 @@ public class CheckResultJob implements SimpleJob {
if(CollectionUtils.isNotEmpty(conversationBatchList)){ if(CollectionUtils.isNotEmpty(conversationBatchList)){
for (ConversationBatch conversationBatch : conversationBatchList) { for (ConversationBatch conversationBatch : conversationBatchList) {
try { try {
if(conversationBatch.getCheckHistoryFlag()==null) { // 获取对应的录音记录,以获取modelType
BadgeRecordings badgeRecordings = badgeRecordingsMapper.selectByPrimaryKey(conversationBatch.getRecordId());
// 配置的模型类型走新规则
if (badgeRecordings != null && modelTypeConfig.getNewLogicModelTypes() != null && modelTypeConfig.getNewLogicModelTypes().contains(badgeRecordings.getModelType())) {
conversationDateService.getCheckResult(conversationBatch);
} else if(conversationBatch.getCheckHistoryFlag()==null) {
// 其他品牌的质检走旧的模版匹配规则
conversationDateService.getCheckResultOld(conversationBatch); conversationDateService.getCheckResultOld(conversationBatch);
}else{ }else{
conversationDateService.getCheckResult(conversationBatch); conversationDateService.getCheckResult(conversationBatch);
......
...@@ -10,4 +10,6 @@ import org.oreframework.datasource.mybatis.mapper.OreMapper; ...@@ -10,4 +10,6 @@ import org.oreframework.datasource.mybatis.mapper.OreMapper;
public interface RecordingTagGroupMapper extends OreMapper<RecordingTagGroup> { public interface RecordingTagGroupMapper extends OreMapper<RecordingTagGroup> {
List<RecordingTagGroup> findAll(@Param("checkType") Integer checkType); List<RecordingTagGroup> findAll(@Param("checkType") Integer checkType);
List<RecordingTagGroup> findAllByConfigCode(@Param("configCode") String configCode);
} }
\ No newline at end of file \ No newline at end of file
...@@ -10,4 +10,6 @@ import org.oreframework.datasource.mybatis.mapper.OreMapper; ...@@ -10,4 +10,6 @@ import org.oreframework.datasource.mybatis.mapper.OreMapper;
public interface RecordingTagRuleMappingMapper extends OreMapper<RecordingTagRuleMapping> { public interface RecordingTagRuleMappingMapper extends OreMapper<RecordingTagRuleMapping> {
List<RecordingTagRuleMapping> findAll(@Param("checkType") Integer checkType); List<RecordingTagRuleMapping> findAll(@Param("checkType") Integer checkType);
List<RecordingTagRuleMapping> findAllByConfigCode(@Param("configCode") String configCode);
} }
\ No newline at end of file \ No newline at end of file
...@@ -487,7 +487,7 @@ public class ConversationDateService { ...@@ -487,7 +487,7 @@ public class ConversationDateService {
return modeltype; return modeltype;
} }
case 2: case 2:
return 3001; return 3002;
case 3: case 3:
return 2001; return 2001;
default: default:
...@@ -615,7 +615,7 @@ public class ConversationDateService { ...@@ -615,7 +615,7 @@ public class ConversationDateService {
ModelResponse modelResponse = JSONObject.parseObject(jsonResult.toJSONString(), ModelResponse modelResponse = JSONObject.parseObject(jsonResult.toJSONString(),
ModelResponse.class); ModelResponse.class);
List<RecordingTagRuleMapping> process = tagService.process(modelResponse, List<RecordingTagRuleMapping> process = tagService.process(modelResponse,
conversationBatch.getId(), conversationBatch.getCheckType()); conversationBatch.getId(), conversationBatch.getCheckType(), latest.getModelType());
conversationBatch.setEstimatedResult("未知"); conversationBatch.setEstimatedResult("未知");
recordingCheckResultService.buildInsertCheckList(process, modelResponse, conversationBatch); recordingCheckResultService.buildInsertCheckList(process, modelResponse, conversationBatch);
conversationBatch.setUpdatedBy("system"); conversationBatch.setUpdatedBy("system");
......
package cn.com.glsx.dj.mindworkplate.service; package cn.com.glsx.dj.mindworkplate.service;
import cn.com.glsx.dj.mindworkplate.config.ModelTypeConfig;
import cn.com.glsx.dj.mindworkplate.dto.ConversationDetailDTO; import cn.com.glsx.dj.mindworkplate.dto.ConversationDetailDTO;
import cn.com.glsx.dj.mindworkplate.dto.ConversationDetailRequestDTO; import cn.com.glsx.dj.mindworkplate.dto.ConversationDetailRequestDTO;
import cn.com.glsx.dj.mindworkplate.mapper.BadgeRecordingsMapper;
import cn.com.glsx.dj.mindworkplate.mapper.RecordingCheckResultMapper; import cn.com.glsx.dj.mindworkplate.mapper.RecordingCheckResultMapper;
import cn.com.glsx.dj.mindworkplate.model.BadgeRecordings;
import cn.com.glsx.dj.mindworkplate.model.ConversationBatch; import cn.com.glsx.dj.mindworkplate.model.ConversationBatch;
import cn.com.glsx.dj.mindworkplate.model.RecordingCheckResult; import cn.com.glsx.dj.mindworkplate.model.RecordingCheckResult;
import cn.com.glsx.dj.mindworkplate.model.RecordingTagRuleMapping; import cn.com.glsx.dj.mindworkplate.model.RecordingTagRuleMapping;
...@@ -49,6 +52,12 @@ public class RecordingCheckResultService { ...@@ -49,6 +52,12 @@ public class RecordingCheckResultService {
@Autowired @Autowired
private SopTaskDetailInfoService sopTaskDetailInfoService; private SopTaskDetailInfoService sopTaskDetailInfoService;
@Autowired
private BadgeRecordingsMapper badgeRecordingsMapper;
@Autowired
private ModelTypeConfig modelTypeConfig;
/** /**
* 写入质检结果 * 写入质检结果
* *
...@@ -58,28 +67,22 @@ public class RecordingCheckResultService { ...@@ -58,28 +67,22 @@ public class RecordingCheckResultService {
*/ */
public void buildInsertCheckList(List<RecordingTagRuleMapping> process, ModelResponse modelResponse, ConversationBatch conversationBatch) { public void buildInsertCheckList(List<RecordingTagRuleMapping> process, ModelResponse modelResponse, ConversationBatch conversationBatch) {
if(CollectionUtils.isNotEmpty(process)){ if(CollectionUtils.isNotEmpty(process)){
List<Label> labels = modelResponse.getLabels(); List<RecordingCheckResult> recordingCheckResults = new ArrayList<>();
BigDecimal reduce = process.stream()
.map(RecordingTagRuleMapping::getScore) // 获取录音记录,以获取modelType
.filter(score -> score != null) // 过滤 null 值 BadgeRecordings badgeRecordings = badgeRecordingsMapper.selectByPrimaryKey(conversationBatch.getRecordId());
.reduce(BigDecimal.ZERO, BigDecimal::add); String modelType = badgeRecordings != null ? badgeRecordings.getModelType() : null;
conversationBatch.setScore(reduce);
List<RecordingCheckResult> recordingCheckResults = process.stream().map(index -> { // 对于配置的模型类型,使用大模型直接返回的分数
List<Label> collect = labels.stream() if (modelTypeConfig.getNewLogicModelTypes() != null && modelTypeConfig.getNewLogicModelTypes().contains(modelType)) {
.filter(label -> label.getLabel().equals(index.getTagGroupName())).collect( // 处理大模型返回的分数
Collectors.toList()); processModelScores(modelResponse.getAllLabels(), process, recordingCheckResults, conversationBatch);
RecordingCheckResult build = RecordingCheckResult.builder() } else {
.tagId(index.getTagId()).score(index.getScore()) // 其他品牌,使用业务侧判断的规则拿到的分数
.sumScore(index.getSumScore()).createdDate(new Date()).tagGroupName(index.getTagGroupName()) processBusinessScores(process, modelResponse.getLabels(), recordingCheckResults, conversationBatch);
.batchId(conversationBatch.getId()).deletedFlag("N").build();
if (CollectionUtils.isNotEmpty(collect)) {
Label label = collect.get(0);
String jsonString = JSONObject.toJSONString(label.getSentence());
String jsonString2 = JSONObject.toJSONString(label.getRetouching());
build.setHitText(jsonString);
} }
return build;
}).collect(Collectors.toList()); // 后续处理逻辑
LabelRequest labelRequest = new LabelRequest(); LabelRequest labelRequest = new LabelRequest();
labelRequest.setTagList(process.stream().map(RecordingTagRuleMapping::getTagGroupName).collect(Collectors.toList())); labelRequest.setTagList(process.stream().map(RecordingTagRuleMapping::getTagGroupName).collect(Collectors.toList()));
labelRequest.setTagResponseCount(1); labelRequest.setTagResponseCount(1);
...@@ -100,9 +103,69 @@ public class RecordingCheckResultService { ...@@ -100,9 +103,69 @@ public class RecordingCheckResultService {
recordingCheckResult.setScriptRec("[]"); recordingCheckResult.setScriptRec("[]");
} }
} }
if (CollectionUtils.isNotEmpty(recordingCheckResults)) {
recordingCheckResultMapper.insertList(recordingCheckResults); recordingCheckResultMapper.insertList(recordingCheckResults);
} }
} }
}
/**
* 处理大模型返回的分数
*/
private void processModelScores(List<Label> labels, List<RecordingTagRuleMapping> process, List<RecordingCheckResult> recordingCheckResults, ConversationBatch conversationBatch) {
BigDecimal totalScore = BigDecimal.ZERO;
for (Label label : labels) {
// 查找对应的规则
List<RecordingTagRuleMapping> matchedRules = process.stream()
.filter(rule -> rule.getTagGroupName() != null && rule.getTagGroupName().equals(label.getLabel()))
.collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(matchedRules)) {
for (RecordingTagRuleMapping rule : matchedRules) {
// 使用大模型返回的分数
BigDecimal score = new BigDecimal(label.getAssessment().getScores());
BigDecimal sumScore = new BigDecimal(label.getAssessment().getSumScores());
totalScore = totalScore.add(score);
RecordingCheckResult build = RecordingCheckResult.builder()
.tagId(rule.getTagId()).score(score)
.sumScore(sumScore).createdDate(new Date()).tagGroupName(label.getLabel())
.batchId(conversationBatch.getId()).deletedFlag("N").build();
build.setHitText(JSONObject.toJSONString(label.getSentence()));
recordingCheckResults.add(build);
}
}
}
conversationBatch.setScore(totalScore);
}
/**
* 处理业务侧判断的规则拿到的分数
*/
private void processBusinessScores(List<RecordingTagRuleMapping> process, List<Label> labels, List<RecordingCheckResult> recordingCheckResults, ConversationBatch conversationBatch) {
BigDecimal totalScore = process.stream()
.map(RecordingTagRuleMapping::getScore)
.filter(score -> score != null) // 过滤 null 值
.reduce(BigDecimal.ZERO, BigDecimal::add);
for (RecordingTagRuleMapping index : process) {
List<Label> collect = labels.stream()
.filter(label -> label.getLabel().equals(index.getTagGroupName())).collect(
Collectors.toList());
RecordingCheckResult build = RecordingCheckResult.builder()
.tagId(index.getTagId()).score(index.getScore())
.sumScore(index.getSumScore()).createdDate(new Date()).tagGroupName(index.getTagGroupName())
.batchId(conversationBatch.getId()).deletedFlag("N").build();
if (CollectionUtils.isNotEmpty(collect)) {
Label label = collect.get(0);
String jsonString = JSONObject.toJSONString(label.getSentence());
build.setHitText(jsonString);
}
recordingCheckResults.add(build);
}
conversationBatch.setScore(totalScore);
}
/** /**
* 通过批次号查询质检结果 * 通过批次号查询质检结果
......
...@@ -3,6 +3,8 @@ package cn.com.glsx.dj.mindworkplate.service.recordingtag; ...@@ -3,6 +3,8 @@ package cn.com.glsx.dj.mindworkplate.service.recordingtag;
import cn.com.glsx.dj.mindworkplate.mapper.RecordingTagGroupMapper; import cn.com.glsx.dj.mindworkplate.mapper.RecordingTagGroupMapper;
import cn.com.glsx.dj.mindworkplate.model.RecordingTagGroup; import cn.com.glsx.dj.mindworkplate.model.RecordingTagGroup;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -19,7 +21,19 @@ public class RecordingTagGroupService { ...@@ -19,7 +21,19 @@ public class RecordingTagGroupService {
@Autowired @Autowired
private RecordingTagGroupMapper recordingTagGroupMapper; private RecordingTagGroupMapper recordingTagGroupMapper;
@Autowired
private RecordingTagConfigModelTypeService recordingTagConfigModelTypeService;
public List<RecordingTagGroup> findAll(Integer checkType) { public List<RecordingTagGroup> findAll(Integer checkType) {
return recordingTagGroupMapper.findAll(checkType); return recordingTagGroupMapper.findAll(checkType);
} }
public List<RecordingTagGroup> findAllByModelType(Integer checkType, String modelType) {
List<String> configCodes = recordingTagConfigModelTypeService.findConfigCodesByModelType(modelType);
if (CollectionUtils.isNotEmpty(configCodes)) {
String configCode = configCodes.get(0);
return recordingTagGroupMapper.findAllByConfigCode(configCode);
}
return recordingTagGroupMapper.findAll(checkType);
}
} }
...@@ -3,6 +3,8 @@ package cn.com.glsx.dj.mindworkplate.service.recordingtag; ...@@ -3,6 +3,8 @@ package cn.com.glsx.dj.mindworkplate.service.recordingtag;
import cn.com.glsx.dj.mindworkplate.mapper.RecordingTagRuleMappingMapper; import cn.com.glsx.dj.mindworkplate.mapper.RecordingTagRuleMappingMapper;
import cn.com.glsx.dj.mindworkplate.model.RecordingTagRuleMapping; import cn.com.glsx.dj.mindworkplate.model.RecordingTagRuleMapping;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -20,7 +22,20 @@ public class RecordingTagRuleMappingService { ...@@ -20,7 +22,20 @@ public class RecordingTagRuleMappingService {
@Autowired @Autowired
private RecordingTagRuleMappingMapper recordingTagRuleMappingMapper; private RecordingTagRuleMappingMapper recordingTagRuleMappingMapper;
@Autowired
private RecordingTagConfigModelTypeService recordingTagConfigModelTypeService;
public List<RecordingTagRuleMapping> findAll(Integer checkType) { public List<RecordingTagRuleMapping> findAll(Integer checkType) {
return recordingTagRuleMappingMapper.findAll(checkType); return recordingTagRuleMappingMapper.findAll(checkType);
} }
public List<RecordingTagRuleMapping> findAllByModelType(Integer checkType, String modelType) {
List<String> configCodes = recordingTagConfigModelTypeService.findConfigCodesByModelType(modelType);
if (CollectionUtils.isNotEmpty(configCodes)) {
String configCode = configCodes.get(0);
List<RecordingTagRuleMapping> allByCheckType = recordingTagRuleMappingMapper.findAllByConfigCode(configCode);
return allByCheckType;
}
return recordingTagRuleMappingMapper.findAll(checkType);
}
} }
package cn.com.glsx.dj.mindworkplate.service.recordingtag; package cn.com.glsx.dj.mindworkplate.service.recordingtag;
import cn.com.glsx.dj.mindworkplate.config.ModelTypeConfig;
import cn.com.glsx.dj.mindworkplate.model.ConversationBatch; import cn.com.glsx.dj.mindworkplate.model.ConversationBatch;
import cn.com.glsx.dj.mindworkplate.model.RecordingTagGroup; import cn.com.glsx.dj.mindworkplate.model.RecordingTagGroup;
import cn.com.glsx.dj.mindworkplate.model.RecordingTagRelation; import cn.com.glsx.dj.mindworkplate.model.RecordingTagRelation;
import cn.com.glsx.dj.mindworkplate.model.RecordingTagRuleMapping; import cn.com.glsx.dj.mindworkplate.model.RecordingTagRuleMapping;
import cn.com.glsx.dj.mindworkplate.service.ConversationBatchService; import cn.com.glsx.dj.mindworkplate.service.ConversationBatchService;
import cn.com.glsx.dj.mindworkplate.service.recordingtag.model.Label;
import cn.com.glsx.dj.mindworkplate.service.recordingtag.model.Label.Assessment;
import cn.com.glsx.dj.mindworkplate.service.recordingtag.model.ModelResponse; import cn.com.glsx.dj.mindworkplate.service.recordingtag.model.ModelResponse;
import cn.com.glsx.dj.mindworkplate.service.recordingtag.strategy.TagProcessingPipeline; import cn.com.glsx.dj.mindworkplate.service.recordingtag.strategy.TagProcessingPipeline;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.function.Function; import java.util.function.Function;
...@@ -35,12 +39,15 @@ public class TagService { ...@@ -35,12 +39,15 @@ public class TagService {
@Autowired @Autowired
private ConversationBatchService conversationBatchService; private ConversationBatchService conversationBatchService;
@Autowired
private ModelTypeConfig modelTypeConfig;
/** /**
* 计算录音标签,并且入库 * 计算录音标签,并且入库
* *
*/ */
public List<RecordingTagRuleMapping> process(ModelResponse response,Integer batchId, public List<RecordingTagRuleMapping> process(ModelResponse response, Integer batchId,
Integer checkType) { Integer checkType, String modelType) {
ConversationBatch recordindIdByBatchId = conversationBatchService.findRecordindIdByBatchId( ConversationBatch recordindIdByBatchId = conversationBatchService.findRecordindIdByBatchId(
batchId); batchId);
if (recordindIdByBatchId == null) { if (recordindIdByBatchId == null) {
...@@ -48,11 +55,65 @@ public class TagService { ...@@ -48,11 +55,65 @@ public class TagService {
return null; return null;
} }
Integer recordingId = recordindIdByBatchId.getRecordId(); Integer recordingId = recordindIdByBatchId.getRecordId();
List<RecordingTagRuleMapping> recordingTagRuleMappings = recordingTagRuleMappingService.findAll(checkType); List<RecordingTagRuleMapping> recordingTagRuleMappings = recordingTagRuleMappingService.findAllByModelType(checkType, modelType);
List<RecordingTagGroup> groupList = recordingTagGroupService.findAll(checkType); List<RecordingTagGroup> groupList = recordingTagGroupService.findAllByModelType(checkType, modelType);
List<Integer> tagIds = tagProcessingPipeline.process(recordindIdByBatchId, response, List<Integer> tagIds;
// 对于配置的模型类型,直接使用大模型返回的标签
if (modelTypeConfig.getNewLogicModelTypes() != null && modelTypeConfig.getNewLogicModelTypes().contains(modelType)) {
tagIds = getTagIdsFromModel(response, recordingTagRuleMappings);
} else {
// 其他品牌,使用业务侧判断的规则拿到的标签
tagIds = tagProcessingPipeline.process(recordindIdByBatchId, response,
recordingTagRuleMappings, groupList); recordingTagRuleMappings, groupList);
}
if (CollectionUtils.isNotEmpty(tagIds)) { if (CollectionUtils.isNotEmpty(tagIds)) {
// 保存标签关系
saveTagRelations(recordingId, tagIds);
// 处理命中的标签规则
List<RecordingTagRuleMapping> result = processHitRules(recordingTagRuleMappings, tagIds);
// 对于配置的模型类型,使用大模型直接返回的分数
if (modelTypeConfig.getNewLogicModelTypes() != null && modelTypeConfig.getNewLogicModelTypes().contains(modelType)) {
applyModelScores(response, result);
}
return result;
}
return null;
}
/**
* 从大模型返回的结果中获取标签ID
*/
private List<Integer> getTagIdsFromModel(ModelResponse response, List<RecordingTagRuleMapping> recordingTagRuleMappings) {
List<Integer> tagIds = new ArrayList<>();
List<Label> labels = response.getAllLabels();
for (Label label : labels) {
Assessment assessment = label.getAssessment();
if (assessment == null) {
continue;
}
if (assessment.getLevel() == null) {
continue;
}
// 查找对应的规则
List<RecordingTagRuleMapping> matchedRules = recordingTagRuleMappings.stream()
.filter(rule -> rule.getTagGroupName() != null && rule.getTagGroupName().equals(label.getLabel()) && rule.getTagName().equals(assessment.getLevel()))
.collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(matchedRules)) {
for (RecordingTagRuleMapping rule : matchedRules) {
tagIds.add(rule.getTagId());
}
}
}
return tagIds;
}
/**
* 保存标签关系
*/
private void saveTagRelations(Integer recordingId, List<Integer> tagIds) {
List<RecordingTagRelation> collect = tagIds.stream().map(index -> { List<RecordingTagRelation> collect = tagIds.stream().map(index -> {
RecordingTagRelation recordingTagRelation = new RecordingTagRelation(); RecordingTagRelation recordingTagRelation = new RecordingTagRelation();
recordingTagRelation.setRecordingId(recordingId); recordingTagRelation.setRecordingId(recordingId);
...@@ -63,6 +124,12 @@ public class TagService { ...@@ -63,6 +124,12 @@ public class TagService {
return recordingTagRelation; return recordingTagRelation;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
recordingTagRelationService.saveList(collect); recordingTagRelationService.saveList(collect);
}
/**
* 处理命中的标签规则
*/
private List<RecordingTagRuleMapping> processHitRules(List<RecordingTagRuleMapping> recordingTagRuleMappings, List<Integer> tagIds) {
return recordingTagRuleMappings.stream() return recordingTagRuleMappings.stream()
.filter(index -> tagIds.contains(index.getTagId())) .filter(index -> tagIds.contains(index.getTagId()))
.collect(Collectors.toMap( .collect(Collectors.toMap(
...@@ -74,7 +141,23 @@ public class TagService { ...@@ -74,7 +141,23 @@ public class TagService {
.stream() .stream()
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
return null;
/**
* 应用大模型返回的分数
*/
private void applyModelScores(ModelResponse response, List<RecordingTagRuleMapping> result) {
List<Label> labels = response.getAllLabels();
for (Label label : labels) {
for (RecordingTagRuleMapping rule : result) {
if (rule.getTagGroupName() != null && rule.getTagGroupName().equals(label.getLabel())) {
// 使用大模型返回的分数
if (label.getAssessment() != null) {
rule.setScore(new java.math.BigDecimal(label.getAssessment().getScores()));
rule.setSumScore(new java.math.BigDecimal(label.getAssessment().getSumScores()));
}
}
}
}
} }
} }
\ No newline at end of file \ No newline at end of file
...@@ -5,13 +5,26 @@ import lombok.Data; ...@@ -5,13 +5,26 @@ import lombok.Data;
@Data @Data
public class Label { public class Label {
private String ruler;
private String label; private String label;
private List<String> shots; private Assessment assessment;
private List<String> sentence; private List<String> sentence;
private List<String> retouching; private List<String> retouching;
private String reason; private String reason;
private List<String> shots;
@Data
public static class Assessment {
private String level;
private String scores;
private String sumScores;
}
public int getShotCount() { public int getShotCount() {
return shots != null ? shots.size() : 0; // 优先使用shots字段(旧格式),如果没有则使用sentence字段(新格式)
if (shots != null) {
return shots.size();
}
return sentence != null ? sentence.size() : 0;
} }
} }
\ No newline at end of file \ No newline at end of file
...@@ -4,6 +4,7 @@ import java.util.List; ...@@ -4,6 +4,7 @@ import java.util.List;
public class ModelResponse { public class ModelResponse {
private List<Label> labels; private List<Label> labels;
private Result result;
public List<Label> getLabels() { public List<Label> getLabels() {
return labels; return labels;
...@@ -12,4 +13,31 @@ public class ModelResponse { ...@@ -12,4 +13,31 @@ public class ModelResponse {
public void setLabels(List<Label> labels) { public void setLabels(List<Label> labels) {
this.labels = labels; this.labels = labels;
} }
public Result getResult() {
return result;
}
public void setResult(Result result) {
this.result = result;
}
public List<Label> getAllLabels() {
if (result != null && result.getLabels() != null) {
return result.getLabels();
}
return labels;
}
public static class Result {
private List<Label> labels;
public List<Label> getLabels() {
return labels;
}
public void setLabels(List<Label> labels) {
this.labels = labels;
}
}
} }
\ No newline at end of file \ No newline at end of file
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
<result column="updated_date" property="updatedDate" jdbcType="TIMESTAMP" /> <result column="updated_date" property="updatedDate" jdbcType="TIMESTAMP" />
<result column="deleted_flag" property="deletedFlag" jdbcType="CHAR" /> <result column="deleted_flag" property="deletedFlag" jdbcType="CHAR" />
<result column="description" property="description" jdbcType="VARCHAR" /> <result column="description" property="description" jdbcType="VARCHAR" />
<result column="configCode" property="configCode" jdbcType="VARCHAR" />
</resultMap> </resultMap>
<sql id="Base_Column_List" > <sql id="Base_Column_List" >
...@@ -25,10 +26,20 @@ ...@@ -25,10 +26,20 @@
</sql> </sql>
<select id="findAll" resultMap="BaseResultMap"> <select id="findAll" resultMap="BaseResultMap">
select select
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />,
config_code as configCode
from recording_tag_group from recording_tag_group
where deleted_flag = 'N' where deleted_flag = 'N'
AND config_code in (select code from recording_tag_config where scene_type=#{checkType}) AND config_code in (select code from recording_tag_config where scene_type=#{checkType})
</select> </select>
<select id="findAllByConfigCode" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />,
config_code as configCode
from recording_tag_group
where deleted_flag = 'N'
AND config_code=#{configCode}
</select>
</mapper> </mapper>
\ No newline at end of file \ No newline at end of file
...@@ -17,11 +17,12 @@ ...@@ -17,11 +17,12 @@
<result column="deleted_flag" property="deletedFlag" jdbcType="CHAR" /> <result column="deleted_flag" property="deletedFlag" jdbcType="CHAR" />
<result column="rule_sql" property="ruleSql" jdbcType="VARCHAR" /> <result column="rule_sql" property="ruleSql" jdbcType="VARCHAR" />
<result column="description" property="description" jdbcType="VARCHAR" /> <result column="description" property="description" jdbcType="VARCHAR" />
<result column="tagName" property="tagName" jdbcType="VARCHAR" />
<result column="matchConditionType" property="matchConditionType" jdbcType="VARCHAR" /> <result column="matchConditionType" property="matchConditionType" jdbcType="VARCHAR" />
<result column="tagName" property="tagName" jdbcType="VARCHAR" />
<result column="tagId" property="tagId" jdbcType="INTEGER" /> <result column="tagId" property="tagId" jdbcType="INTEGER" />
<result column="score" property="score" jdbcType="DOUBLE" /> <result column="score" property="score" jdbcType="DOUBLE" />
<result column="sumScore" property="sumScore" jdbcType="DOUBLE" /> <result column="sumScore" property="sumScore" jdbcType="DOUBLE" />
<result column="configCode" property="configCode" jdbcType="VARCHAR" />
</resultMap> </resultMap>
<sql id="Base_Column_List" > <sql id="Base_Column_List" >
...@@ -35,10 +36,20 @@ ...@@ -35,10 +36,20 @@
<select id="findAll" <select id="findAll"
resultMap="BaseResultMap"> resultMap="BaseResultMap">
select t1.id as tagId,t1.value_name as tagName,t1.tag_groupid AS tagGroupid,t1.match_condition_type as matchConditionType, select t1.id as tagId,t1.value_name as tagName,t1.tag_groupid AS tagGroupid,t1.match_condition_type as matchConditionType,
t2.*,t1.tag_value_score as score,t3.tag_score as sumScore,t3.group_name as tagGroupName from recording_tag_value t1 t2.*,t1.tag_value_score as score,t3.tag_score as sumScore,t3.group_name as tagGroupName,t3.config_code as configCode from recording_tag_value t1
left join recording_tag_group t3 on t1.tag_groupid=t3.id left join recording_tag_group t3 on t1.tag_groupid=t3.id
left join recording_tag_rule_mapping t2 on (t1.id =t2.tag_value_id and t2.deleted_flag='N') left join recording_tag_rule_mapping t2 on (t1.id =t2.tag_value_id and t2.deleted_flag='N')
where t1.deleted_flag='N' and t3.deleted_flag='N' where t1.deleted_flag='N' and t3.deleted_flag='N'
AND t3.config_code in (select code from recording_tag_config where scene_type=#{checkType}) AND t3.config_code in (select code from recording_tag_config where scene_type=#{checkType})
</select> </select>
<select id="findAllByConfigCode"
resultMap="BaseResultMap">
select t1.id as tagId,t1.value_name as tagName,t1.tag_groupid AS tagGroupid,t1.match_condition_type as matchConditionType,
t2.*,t1.tag_value_score as score,t3.tag_score as sumScore,t3.group_name as tagGroupName,t3.config_code as configCode from recording_tag_value t1
left join recording_tag_group t3 on t1.tag_groupid=t3.id
left join recording_tag_rule_mapping t2 on (t1.id =t2.tag_value_id and t2.deleted_flag='N')
where t1.deleted_flag='N' and t3.deleted_flag='N'
AND t3.config_code=#{configCode}
</select>
</mapper> </mapper>
\ No newline at end of file \ No newline at end of file
...@@ -45,15 +45,15 @@ public class ConversationDateServiceTest extends BaseServiceTest{ ...@@ -45,15 +45,15 @@ public class ConversationDateServiceTest extends BaseServiceTest{
ConversationBatch conversationBatch = conversationBatchMapper.selectByPrimaryKey(122); ConversationBatch conversationBatch = conversationBatchMapper.selectByPrimaryKey(122);
conversationBatch.setCheckType(1); conversationBatch.setCheckType(1);
conversationBatch.setCarBrandId(1); conversationBatch.setCarBrandId(1);
conversationBatch.setOneCarBrandId(1); conversationBatch.setOneCarBrandId(2336);
conversationDateService.singleBatchInspection(conversationBatch); conversationDateService.singleBatchInspection(conversationBatch);
} }
@Test @Test
public void getCheckResult() throws Exception{ public void getCheckResult() throws Exception{
ConversationBatch conversationBatch = conversationBatchMapper.selectByPrimaryKey(124); ConversationBatch conversationBatch = conversationBatchMapper.selectByPrimaryKey(122);
conversationBatch.setCheTaskId("Task-1932639431466942464"); conversationBatch.setCheTaskId("Task-2043591565565231104");
conversationBatch.setCheckType(3); conversationBatch.setCheckType(1);
conversationDateService.getCheckResult(conversationBatch); conversationDateService.getCheckResult(conversationBatch);
} }
......
  • @wangxw1
    commented
    Master

    一、关键问题与优化建议

    • 问题 1:潜在的空指针风险(NPE)与配置依赖隐患

      • 问题描述:在 TagService.java 的 applyModelScores 方法中,虽然对 label.getAssessment() 进行了判空,但其内部属性 scores 和 sumScores 直接传入了 BigDecimal 构造函数。若大模型返回的 JSON 结构中缺失这些字段,将触发 NPE。此外,RecordingTagGroupService 中 configCodes.get(0) 未判断集合大小,可能导致越界异常。
      • 影响分析:导致质检任务在处理特定响应时崩溃,影响系统稳定性,可能导致部分录音质检中断。
      • 优化建议:

        // TagService.java 建议:增加字段检查与默认值
        if (label.getAssessment() != null && label.getAssessment().getScores() != null) {
            rule.setScore(new BigDecimal(label.getAssessment().getScores()));
        }
        
        // RecordingTagGroupService.java 建议:
        if (CollectionUtils.isNotEmpty(configCodes)) {
            return recordingTagGroupMapper.findAllByConfigCode(configCodes.get(0));
        }
        
    • 问题 2:SQL 查询违规使用子查询

      • 问题描述:在 RecordingTagGroupMapper.xml 和 RecordingTagRuleMappingMapper.xml 的 findAll 方法中,WHERE 条件使用了 IN (select code from ...) 子查询。这违反了本次审查中“mybatis SQL中不允许使用子查询”的明确要求。
      • 影响分析:违反工程规范,且在大数据量下,IN 子查询可能导致数据库执行计划失效,引发性能抖动。
      • 优化建议:建议将子查询逻辑拆分。先在 Service 层通过 recordingTagConfigMapper 查询出对应的 codes 列表,再作为参数传入 Mapper,使用 MyBatis 的 <foreach> 标签进行 IN 匹配。
    • 问题 3:数据库字段映射与模型定义不一致

      • 问题描述:在 RecordingTagGroup.java 中,新增字段 configCode 使用了 @Column(name = "config_code") 注解,但在对应的 RecordingTagGroupMapper.xml 的 ResultMap 中,property 却写成了 configCode(驼峰),且 SQL 查询中使用了 config_code as configCode。
      • 影响分析:虽然通过别名暂时解决了映射问题,但 JPA 注解与 XML 配置不统一会增加维护成本,且在某些自动化 ORM 框架下可能导致字段加载失败。
      • 优化建议:统一命名规范。确保 ResultMap 中的 column 对应数据库字段名 config_code,property 对应实体类属性名。

    二、评分明细

    评分维度 分数 理由
    功能实现正确性与健壮性 32 逻辑实现了新旧规则切换,但存在多处未严格判空的情况(如配置项获取、BigDecimal 转换)。
    安全性与潜在风险 28 无 SQL 注入风险,但子查询的使用在复杂场景下存在数据库性能风险。
    最佳实践与可维护性 15 违反了“禁止子查询”的特定约束;代码中存在硬编码(如 3002, 2001);实体类注解与 XML 映射不统一。
    性能与资源利用 4 引入了多次数据库查询(如在循环中查询 badgeRecordingsMapper),建议考虑批量查询或缓存。
    提交信息质量 4 描述了变更内容,但较为简单,未提及技术实现细节。

    总分:83分

Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!