Commit db341fb3 by 叶立庆

Merge remote-tracking branch 'origin/v5.7.4' into v5.7.5

# Conflicts:
#	rpc-dj-mindworkplate-api/pom.xml
#	rpc-dj-mindworkplate/pom.xml
2 parents 4ca7a449 c9e163b4
Showing 33 changed files with 656 additions and 119 deletions
......@@ -33,7 +33,7 @@
<dependency>
<groupId>cn.com.glsx</groupId>
<artifactId>rpc-dj-mindworkplate-api</artifactId>
<version>5.7.5-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
</dependencies>
</plugin>
......
......@@ -73,4 +73,10 @@ public class ReceptionViolationInfoDTO implements Serializable {
private RecordingBatchModelCallWghs recordingBatchModelCallWghs;
private String resultJson;
@ApiModelProperty(notes = "二级品牌ID")
private Integer carBrandId;
@ApiModelProperty(notes = "二级品牌名称")
private String carBrandName;
}
\ No newline at end of file
......@@ -38,4 +38,7 @@ public class ReceptionViolationReqDTO implements Serializable {
@ApiModelProperty(notes = "1.延保 2.轻改")
private Integer bussinessType;
@ApiModelProperty(notes = "二级品牌ID")
private Integer carBrandId;
}
\ No newline at end of file
package cn.com.glsx.dj.mindworkplate.model;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import lombok.Data;
@Table(name = "recording_tag_config_model_type")
@Data
public class RecordingTagConfigModelType {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
/**
* 配置编码
*/
@Column(name = "config_code")
private String configCode;
/**
* 模型类型
*/
@Column(name = "model_type")
private String modelType;
/**
* 创建人
*/
@Column(name = "created_by")
private String createdBy;
/**
* 创建时间
*/
@Column(name = "created_date")
private Date createdDate;
/**
* 修改人
*/
@Column(name = "updated_by")
private String updatedBy;
/**
* 修改时间
*/
@Column(name = "updated_date")
private Date updatedDate;
/**
* 删除标识(D:已删除;N:未删除)
*/
@Column(name = "deleted_flag")
private String deletedFlag;
}
......@@ -62,4 +62,10 @@ public class RecordingTagGroup {
*/
private String description;
/**
* 配置编码
*/
@Column(name = "config_code")
private String configCode;
}
\ No newline at end of file
......@@ -123,4 +123,10 @@ public class RecordingTagRuleMapping {
*/
@Transient
private BigDecimal sumScore;
/**
* 配置编码
*/
@Transient
private String configCode;
}
\ No newline at end of file
package cn.com.glsx.dj.mindworkplate.config;
import java.util.List;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
/**
* 模型类型配置
*/
@Data
@Configuration
@ConfigurationProperties("model.type")
public class ModelTypeConfig {
/**
* 走新逻辑的模型类型集合
*/
private List<String> newLogicModelTypes;
}
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.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.ConversationBatch;
import cn.com.glsx.dj.mindworkplate.model.EmployeeBadge;
......@@ -30,6 +32,12 @@ public class CheckResultJob implements SimpleJob {
@Autowired
private ConversationDateService conversationDateService;
@Autowired
private BadgeRecordingsMapper badgeRecordingsMapper;
@Autowired
private ModelTypeConfig modelTypeConfig;
@Override
public void execute(ShardingContext shardingContext) {
log.info("----------------获取质检结果任务开始-----------------");
......@@ -37,7 +45,13 @@ public class CheckResultJob implements SimpleJob {
if(CollectionUtils.isNotEmpty(conversationBatchList)){
for (ConversationBatch conversationBatch : conversationBatchList) {
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);
}else{
conversationDateService.getCheckResult(conversationBatch);
......
package cn.com.glsx.dj.mindworkplate.mapper;
import cn.com.glsx.dj.mindworkplate.model.RecordingTagConfigModelType;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.oreframework.datasource.mybatis.mapper.OreMapper;
@Mapper
public interface RecordingTagConfigModelTypeMapper extends OreMapper<RecordingTagConfigModelType> {
/**
* 根据模型类型查询配置编码
*/
List<String> findConfigCodesByModelType(@Param("modelType") String modelType);
/**
* 根据配置编码查询模型类型
*/
List<String> findModelTypesByConfigCode(@Param("configCode") String configCode);
/**
* 检查配置编码和模型类型是否存在
*/
int countByConfigCodeAndModelType(@Param("configCode") String configCode, @Param("modelType") String modelType);
}
......@@ -10,4 +10,6 @@ import org.oreframework.datasource.mybatis.mapper.OreMapper;
public interface RecordingTagGroupMapper extends OreMapper<RecordingTagGroup> {
List<RecordingTagGroup> findAll(@Param("checkType") Integer checkType);
List<RecordingTagGroup> findAllByConfigCode(@Param("configCode") String configCode);
}
\ No newline at end of file
......@@ -10,4 +10,6 @@ import org.oreframework.datasource.mybatis.mapper.OreMapper;
public interface RecordingTagRuleMappingMapper extends OreMapper<RecordingTagRuleMapping> {
List<RecordingTagRuleMapping> findAll(@Param("checkType") Integer checkType);
List<RecordingTagRuleMapping> findAllByConfigCode(@Param("configCode") String configCode);
}
\ No newline at end of file
......@@ -20,6 +20,9 @@ public class ViolationExportModel implements Serializable {
@ExcelProperty({"序号"})
private Integer index;
@ExcelProperty({"品牌"})
private String carBrandName;
@ExcelProperty({"员工"})
private String employeeName;
......
......@@ -615,7 +615,7 @@ public class ConversationDateService {
ModelResponse modelResponse = JSONObject.parseObject(jsonResult.toJSONString(),
ModelResponse.class);
List<RecordingTagRuleMapping> process = tagService.process(modelResponse,
conversationBatch.getId(), conversationBatch.getCheckType());
conversationBatch.getId(), conversationBatch.getCheckType(), latest.getModelType());
conversationBatch.setEstimatedResult("未知");
recordingCheckResultService.buildInsertCheckList(process, modelResponse, conversationBatch);
conversationBatch.setUpdatedBy("system");
......
......@@ -194,12 +194,8 @@ public class EmployeeBadgeRecordingService {
conversationBatchMapper.insertUseGeneratedKeys(conversationBatch);
if (badgeRecordings.getCheResultFlag() == 0 && badgeRecordings.getCheckType() == 1) {
// 需要质检
String carModel = badgeRecordings.getCarModel();
if(carModel!=null&& carModel.contains("问界")) {
recordingBatchModelCallService.insertWaitGet(conversationBatch.getId());
}else {
recordingBatchModelCallService.insertWaitGetWJ(conversationBatch.getId());
}
String carBrandId = Objects.isNull(badgeRecordings.getCarBrandId()) ? null : badgeRecordings.getCarBrandId().toString();
recordingBatchModelCallService.insertWaitGet(conversationBatch.getId(), carBrandId);
}
}
}
......
......@@ -205,6 +205,8 @@ public class ReceptionCustomerService {
boolean checkFlag = true;
MerchantDTO merchantBrand = findMerchantBrand(merchantDTO);
badgeRecordings.setCarModel(receptionCustomerInfoDTO.getCarModel());
badgeRecordings.setCarBrandId(receptionCustomerInfoDTO.getCarBrandId());
badgeRecordings.setOneCarBrandId(receptionCustomerInfoDTO.getOneCarBrandId());
Integer recordId = employeeBadgeRecordingService.addRecordingForMatePad(
badgeRecordings,
recordUrlList, receptionCustomerInfoDTO.getChannelType(), checkFlag,Arrays.asList(receptionCustomerInfo.getOneCarBrandId()));
......@@ -1388,6 +1390,7 @@ public class ReceptionCustomerService {
violationExportModel.setIndex(
violationReceptionByConditionPage.getResult().indexOf(
receptionViolationInfoDTO) + 1);
violationExportModel.setCarBrandName(receptionViolationInfoDTO.getCarBrandName());
violationExportModel.setEmployeeName(receptionViolationInfoDTO.getEmployeeName()
+ receptionViolationInfoDTO.getEmployeePhone());
violationExportModel.setCustomerName(receptionViolationInfoDTO.getCustomerName()
......@@ -1414,9 +1417,12 @@ public class ReceptionCustomerService {
: receptionViolationInfoDTO.getViolationStatus().intValue() == 2
? "确认违规" : "未违规");
}
String resultJson = receptionViolationInfoDTO.getResultJson();
if (StringUtils.isNotEmpty(resultJson)) {
violationExportModel.setJsonObject(processRules(resultJson));
// 20260422 未违规不展示
if (receptionViolationInfoDTO.getViolationStatus().intValue() != 0) {
String resultJson = receptionViolationInfoDTO.getResultJson();
if (StringUtils.isNotEmpty(resultJson)) {
violationExportModel.setJsonObject(processRules(resultJson));
}
}
violationExportModels.add(violationExportModel);
}
......
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.ConversationDetailRequestDTO;
import cn.com.glsx.dj.mindworkplate.mapper.BadgeRecordingsMapper;
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.RecordingCheckResult;
import cn.com.glsx.dj.mindworkplate.model.RecordingTagRuleMapping;
......@@ -49,6 +52,12 @@ public class RecordingCheckResultService {
@Autowired
private SopTaskDetailInfoService sopTaskDetailInfoService;
@Autowired
private BadgeRecordingsMapper badgeRecordingsMapper;
@Autowired
private ModelTypeConfig modelTypeConfig;
/**
* 写入质检结果
*
......@@ -58,28 +67,22 @@ public class RecordingCheckResultService {
*/
public void buildInsertCheckList(List<RecordingTagRuleMapping> process, ModelResponse modelResponse, ConversationBatch conversationBatch) {
if(CollectionUtils.isNotEmpty(process)){
List<Label> labels = modelResponse.getLabels();
BigDecimal reduce = process.stream()
.map(RecordingTagRuleMapping::getScore)
.filter(score -> score != null) // 过滤 null 值
.reduce(BigDecimal.ZERO, BigDecimal::add);
conversationBatch.setScore(reduce);
List<RecordingCheckResult> recordingCheckResults = process.stream().map(index -> {
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());
String jsonString2 = JSONObject.toJSONString(label.getRetouching());
build.setHitText(jsonString);
}
return build;
}).collect(Collectors.toList());
List<RecordingCheckResult> recordingCheckResults = new ArrayList<>();
// 获取录音记录,以获取modelType
BadgeRecordings badgeRecordings = badgeRecordingsMapper.selectByPrimaryKey(conversationBatch.getRecordId());
String modelType = badgeRecordings != null ? badgeRecordings.getModelType() : null;
// 对于配置的模型类型,使用大模型直接返回的分数
if (modelTypeConfig.getNewLogicModelTypes() != null && modelTypeConfig.getNewLogicModelTypes().contains(modelType)) {
// 处理大模型返回的分数
processModelScores(modelResponse.getAllLabels(), process, recordingCheckResults, conversationBatch);
} else {
// 其他品牌,使用业务侧判断的规则拿到的分数
processBusinessScores(process, modelResponse.getLabels(), recordingCheckResults, conversationBatch);
}
// 后续处理逻辑
LabelRequest labelRequest = new LabelRequest();
labelRequest.setTagList(process.stream().map(RecordingTagRuleMapping::getTagGroupName).collect(Collectors.toList()));
labelRequest.setTagResponseCount(1);
......@@ -100,9 +103,69 @@ public class RecordingCheckResultService {
recordingCheckResult.setScriptRec("[]");
}
}
recordingCheckResultMapper.insertList(recordingCheckResults);
if (CollectionUtils.isNotEmpty(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);
}
/**
* 通过批次号查询质检结果
......
package cn.com.glsx.dj.mindworkplate.service.recordingtag;
import cn.com.glsx.dj.mindworkplate.mapper.RecordingTagConfigModelTypeMapper;
import cn.com.glsx.dj.mindworkplate.model.RecordingTagConfigModelType;
import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* 录音标签配置模型类型关联服务
*/
@Service
public class RecordingTagConfigModelTypeService {
@Autowired
private RecordingTagConfigModelTypeMapper recordingTagConfigModelTypeMapper;
/**
* 根据模型类型查询配置编码
*/
public List<String> findConfigCodesByModelType(String modelType) {
return recordingTagConfigModelTypeMapper.findConfigCodesByModelType(modelType);
}
/**
* 检查配置编码和模型类型是否存在
*/
public boolean existsByConfigCodeAndModelType(String configCode, String modelType) {
return recordingTagConfigModelTypeMapper.countByConfigCodeAndModelType(configCode, modelType) > 0;
}
/**
* 保存配置编码和模型类型的关联关系
*/
public void save(String configCode, String modelType) {
if (!existsByConfigCodeAndModelType(configCode, modelType)) {
RecordingTagConfigModelType recordingTagConfigModelType = new RecordingTagConfigModelType();
recordingTagConfigModelType.setConfigCode(configCode);
recordingTagConfigModelType.setModelType(modelType);
recordingTagConfigModelType.setCreatedBy("system");
recordingTagConfigModelType.setCreatedDate(new Date());
recordingTagConfigModelType.setUpdatedBy("system");
recordingTagConfigModelType.setUpdatedDate(new Date());
recordingTagConfigModelType.setDeletedFlag("N");
recordingTagConfigModelTypeMapper.insert(recordingTagConfigModelType);
}
}
/**
* 批量保存配置编码和模型类型的关联关系
*/
public void saveBatch(String configCode, List<String> modelTypes) {
for (String modelType : modelTypes) {
save(configCode, modelType);
}
}
/**
* 删除配置编码和模型类型的关联关系
*/
public void delete(String configCode, String modelType) {
RecordingTagConfigModelType recordingTagConfigModelType = new RecordingTagConfigModelType();
recordingTagConfigModelType.setConfigCode(configCode);
recordingTagConfigModelType.setModelType(modelType);
recordingTagConfigModelType.setDeletedFlag("Y");
recordingTagConfigModelType.setUpdatedBy("system");
recordingTagConfigModelType.setUpdatedDate(new Date());
recordingTagConfigModelTypeMapper.updateByExampleSelective(recordingTagConfigModelType, null);
}
}
......@@ -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.model.RecordingTagGroup;
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.stereotype.Service;
......@@ -19,7 +21,19 @@ public class RecordingTagGroupService {
@Autowired
private RecordingTagGroupMapper recordingTagGroupMapper;
@Autowired
private RecordingTagConfigModelTypeService recordingTagConfigModelTypeService;
public List<RecordingTagGroup> findAll(Integer 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;
import cn.com.glsx.dj.mindworkplate.mapper.RecordingTagRuleMappingMapper;
import cn.com.glsx.dj.mindworkplate.model.RecordingTagRuleMapping;
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.stereotype.Service;
......@@ -20,7 +22,20 @@ public class RecordingTagRuleMappingService {
@Autowired
private RecordingTagRuleMappingMapper recordingTagRuleMappingMapper;
@Autowired
private RecordingTagConfigModelTypeService recordingTagConfigModelTypeService;
public List<RecordingTagRuleMapping> findAll(Integer 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;
import cn.com.glsx.dj.mindworkplate.config.ModelTypeConfig;
import cn.com.glsx.dj.mindworkplate.model.ConversationBatch;
import cn.com.glsx.dj.mindworkplate.model.RecordingTagGroup;
import cn.com.glsx.dj.mindworkplate.model.RecordingTagRelation;
import cn.com.glsx.dj.mindworkplate.model.RecordingTagRuleMapping;
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.strategy.TagProcessingPipeline;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.function.Function;
......@@ -35,12 +39,15 @@ public class TagService {
@Autowired
private ConversationBatchService conversationBatchService;
@Autowired
private ModelTypeConfig modelTypeConfig;
/**
* 计算录音标签,并且入库
*
*/
public List<RecordingTagRuleMapping> process(ModelResponse response,Integer batchId,
Integer checkType) {
* 计算录音标签,并且入库
*
*/
public List<RecordingTagRuleMapping> process(ModelResponse response, Integer batchId,
Integer checkType, String modelType) {
ConversationBatch recordindIdByBatchId = conversationBatchService.findRecordindIdByBatchId(
batchId);
if (recordindIdByBatchId == null) {
......@@ -48,33 +55,109 @@ public class TagService {
return null;
}
Integer recordingId = recordindIdByBatchId.getRecordId();
List<RecordingTagRuleMapping> recordingTagRuleMappings = recordingTagRuleMappingService.findAll(checkType);
List<RecordingTagGroup> groupList = recordingTagGroupService.findAll(checkType);
List<Integer> tagIds = tagProcessingPipeline.process(recordindIdByBatchId, response,
recordingTagRuleMappings, groupList);
List<RecordingTagRuleMapping> recordingTagRuleMappings = recordingTagRuleMappingService.findAllByModelType(checkType, modelType);
List<RecordingTagGroup> groupList = recordingTagGroupService.findAllByModelType(checkType, modelType);
List<Integer> tagIds;
// 对于配置的模型类型,直接使用大模型返回的标签
if (modelTypeConfig.getNewLogicModelTypes() != null && modelTypeConfig.getNewLogicModelTypes().contains(modelType)) {
tagIds = getTagIdsFromModel(response, recordingTagRuleMappings);
} else {
// 其他品牌,使用业务侧判断的规则拿到的标签
tagIds = tagProcessingPipeline.process(recordindIdByBatchId, response,
recordingTagRuleMappings, groupList);
}
if (CollectionUtils.isNotEmpty(tagIds)) {
List<RecordingTagRelation> collect = tagIds.stream().map(index -> {
RecordingTagRelation recordingTagRelation = new RecordingTagRelation();
recordingTagRelation.setRecordingId(recordingId);
recordingTagRelation.setTagId(index);
recordingTagRelation.setCreatedDate(new Date());
recordingTagRelation.setCreatedBy("system");
recordingTagRelation.setDeletedFlag("N");
return recordingTagRelation;
}).collect(Collectors.toList());
recordingTagRelationService.saveList(collect);
return recordingTagRuleMappings.stream()
.filter(index -> tagIds.contains(index.getTagId()))
.collect(Collectors.toMap(
RecordingTagRuleMapping::getTagId, // 去重依据字段
Function.identity(), // 当前对象
(existing, replacement) -> existing // 如果重复,保留第一个出现的对象
))
.values()
.stream()
.collect(Collectors.toList());
// 保存标签关系
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 -> {
RecordingTagRelation recordingTagRelation = new RecordingTagRelation();
recordingTagRelation.setRecordingId(recordingId);
recordingTagRelation.setTagId(index);
recordingTagRelation.setCreatedDate(new Date());
recordingTagRelation.setCreatedBy("system");
recordingTagRelation.setDeletedFlag("N");
return recordingTagRelation;
}).collect(Collectors.toList());
recordingTagRelationService.saveList(collect);
}
/**
* 处理命中的标签规则
*/
private List<RecordingTagRuleMapping> processHitRules(List<RecordingTagRuleMapping> recordingTagRuleMappings, List<Integer> tagIds) {
return recordingTagRuleMappings.stream()
.filter(index -> tagIds.contains(index.getTagId()))
.collect(Collectors.toMap(
RecordingTagRuleMapping::getTagId, // 去重依据字段
Function.identity(), // 当前对象
(existing, replacement) -> existing // 如果重复,保留第一个出现的对象
))
.values()
.stream()
.collect(Collectors.toList());
}
/**
* 应用大模型返回的分数
*/
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
......@@ -5,13 +5,26 @@ import lombok.Data;
@Data
public class Label {
private String ruler;
private String label;
private List<String> shots;
private Assessment assessment;
private List<String> sentence;
private List<String> retouching;
private String reason;
private List<String> shots;
@Data
public static class Assessment {
private String level;
private String scores;
private String sumScores;
}
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
......@@ -4,6 +4,7 @@ import java.util.List;
public class ModelResponse {
private List<Label> labels;
private Result result;
public List<Label> getLabels() {
return labels;
......@@ -12,4 +13,31 @@ public class ModelResponse {
public void setLabels(List<Label> 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
......@@ -10,11 +10,11 @@ import cn.com.glsx.dj.mindworkplate.service.bigmodelapi.BigModelExecutorFactory;
import cn.com.glsx.dj.mindworkplate.service.recordmodelcall.enums.ModelCallTaskEnum;
import cn.com.glsx.dj.mindworkplate.service.recordmodelcall.enums.ModelCallTypeEnum;
import cn.com.glsx.dj.mindworkplate.service.recordmodelcall.strtype.RecordModelCallExecutionStrategy;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -43,7 +43,9 @@ public class RecordingBatchModelCallService {
* 新增录音任务
*
* @param recordingBatchId 录音批次id
* @deprecated use #insertWaitGet(Integer recordingBatchId, String carModel)
*/
@Deprecated
public void insertWaitGet(Integer recordingBatchId){
try {
List<RecordingBatchModelCall> recordingBatchModelCallList = new ArrayList<>();
......@@ -68,25 +70,55 @@ public class RecordingBatchModelCallService {
/**
* 新增录音任务
* 指定品牌取不同的模型类型参数
*
* @param recordingBatchId 录音批次id
*/
public void insertWaitGetWJ(Integer recordingBatchId){
public void insertWaitGet(Integer recordingBatchId, String carBrandId){
List<RecordingBatchModelCall> recordingBatchModelCallList = new ArrayList<>();
// 通用配置
String property = environment.getProperty("recording.model.call.type.nwj");
// 车型关联配置
String carBrandPropertyStr = environment.getProperty("recording.model.call.type.map");
if (StringUtils.isBlank(carBrandPropertyStr)) {
log.error("录音大模型任务创建异常,未配置车型对应关系");
return;
}
try {
List<RecordingBatchModelCall> recordingBatchModelCallList = new ArrayList<>();
String property = environment.getProperty("recording.model.call.type.nwj");
if (StringUtils.isNotEmpty(property)) {
String[] split = property.split(",");
for (String s : split) {
int i = Integer.parseInt(s);
RecordingBatchModelCall build = RecordingBatchModelCall.builder()
.recordingBatchId(recordingBatchId).createTime(new Date()).businessType(i).requestType(
(byte) 2).resultStatus(
ModelCallTaskEnum.READY.getValue()).build();
recordingBatchModelCallList.add(build);
}
recordingBatchModelCallMapper.insertList(recordingBatchModelCallList);
JSONObject carBrandPropertyObj = JSON.parseObject(carBrandPropertyStr);
if (Objects.isNull(carBrandPropertyObj)) {
log.error("录音大模型任务创建异常,配置解析异常");
return;
}
if (StringUtils.isNotBlank(carBrandId)) {
property = carBrandPropertyObj.keySet().stream()
.filter(p -> StringUtils.equals(p, carBrandId))
.findFirst()
.map(carBrandPropertyObj::getString)
.orElse(property); // 匹配不到匹配的则使用通用配置
}
log.info("录音大模型任务配置准备,carBrandId:{}, property:{}", carBrandId, property);
if (StringUtils.isEmpty(property)) {
log.error("录音大模型任务创建异常,配置为空, carBrandId:{}, property:{}", carBrandId, property);
return;
}
for (String s : property.split(",")) {
int i = Integer.parseInt(s);
RecordingBatchModelCall build = RecordingBatchModelCall.builder()
.recordingBatchId(recordingBatchId)
.createTime(new Date())
.businessType(i)
.requestType((byte) 2)
.resultStatus(ModelCallTaskEnum.READY.getValue())
.build();
recordingBatchModelCallList.add(build);
}
int insertCnt = recordingBatchModelCallMapper.insertList(recordingBatchModelCallList);
log.info("录音大模型任务创建成功,数量:{}, 成功:{}", recordingBatchModelCallList.size(), insertCnt);
}catch (Exception e){
e.printStackTrace();
log.info("录音大模型任务创建异常{}",e.getMessage());
......@@ -206,6 +238,7 @@ public class RecordingBatchModelCallService {
/**
* 业务不存在使用默认实例处理
*/
log.warn("业务不存在使用默认实例处理, {}", businessType);
instance= BigModelExecutorFactory.getInstance(
ModelCallTypeEnum.fromBusType(0).getHanderImp(),
RecordModelCallExecutionStrategy.class);
......
......@@ -28,6 +28,11 @@ ModelCallTypeEnum {
ModelCall_WGHS(11, "violationScriptsAbstractStrategy", RecordModelCallExecutionStrategy.class),
/**
* 违规话术-岚图
*/
ModelCall_WGHS_LT(1107, "violationScriptsAbstractStrategy", RecordModelCallExecutionStrategy.class),
/**
* 默认业务处理
*/
ModelCall_default(0, "defaultAbstractStrategy", RecordModelCallExecutionStrategy.class);
......
......@@ -10,10 +10,9 @@ import cn.com.glsx.dj.mindworkplate.service.recordmodelcall.RecordingBatchModelC
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import com.alibaba.fastjson.JSONObject;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
......@@ -82,46 +81,49 @@ public class ViolationScriptsAbstractStrategy implements RecordModelCallExecutio
}
List<Map> maps = JSONObject.parseArray(o1+"", Map.class);
List<RecordingBatchModelCallWghsDetail> recordingBatchModelCallWghsDetails = new ArrayList<>();
byte isMntioned = 0;
byte isMntioned1 = 0;
byte isMntioned2 = 0;
byte isMntioned3 = 0;
int isMntioned = 0;
for (Map map : maps) {
Object o = map.get("rule");
Object match = map.get("match");
Object g1_match = map.get("g1_match");
Object g2_match = map.get("g2_match");
if (o != null) {
boolean isMatch = false;
switch (o.toString()) {
case "R101":
if ("YES".equals(match) && "NO".equals(g1_match) && "NO".equals(g2_match)) {
isMntioned1 = 1;
recordingBatchModelCallWghsDetails.addAll(extractTimeAndText(map.get("sentence") + "",o.toString()));
if (!Objects.equals("NO", g2_match)) {
log.info("规则:{},g2_match:{}", o, match);
break;
}
break;
case "R102":
if ("YES".equals(match) && ("NO".equals(g1_match))) {
isMntioned2 = 1;
recordingBatchModelCallWghsDetails.addAll(extractTimeAndText(map.get("sentence") + "",o.toString()));
if (!Objects.equals("NO", g1_match)) {
log.info("规则:{},g1_match:{}", o, match);
break;
}
break;
case "R103":
case "H001":
case "H002":
case "H003":
case "H004":
if ("YES".equals(match)) {
isMntioned3 = 1;
recordingBatchModelCallWghsDetails.addAll(extractTimeAndText(map.get("sentence") + "",o.toString()));
isMatch = true;
isMntioned |= 1;
}
break;
default:
break;
log.warn("未定义的规则{}", o);
}
if (isMatch) {
recordingBatchModelCallWghsDetails.addAll(extractTimeAndText(map.get("sentence") + "", Objects.toString(o, null)));
}
}
}
if (isMntioned1 == 1 || isMntioned2 == 1 || isMntioned3 == 1) {
isMntioned = 1;
}
RecordingBatchModelCallWghs build = RecordingBatchModelCallWghs.builder().
batchId(recordingBatchModelCall.getRecordingBatchId()).
isMentioned(isMntioned).wghsStatus((int) isMntioned).createdTime(new Date()).build();
RecordingBatchModelCallWghs build = RecordingBatchModelCallWghs.builder()
.batchId(recordingBatchModelCall.getRecordingBatchId())
.isMentioned((byte) isMntioned)
.wghsStatus(isMntioned)
.createdTime(new Date())
.build();
recordingBatchModelCallWGHSService.insert(build, recordingBatchModelCallWghsDetails);
}
......
......@@ -624,13 +624,14 @@
resultType="cn.com.glsx.dj.mindworkplate.model.ReceptionViolationInfoDTO">
select t3.id as batchId,t5.employee_name as employeeName,t5.phone_number as employeePhone,t1.merchant_id as merchantNo,t1.phone_number as phoneNumber,t1.customer_name as customerName,
t1.car_model as carModel,t1.reception_start_time as startTime,t2.recording_url as fileUrl, t1.reception_end_time as endTime,t1.reception_status as receptionStatus,
t1.car_brand as carBrandName, t1.car_brandid as carBrandId,
t2.recording_duration as totalDuration,t4.wghs_Status as violationStatus,t4.Violation_Reason_confim_time as violationReasonConfimTime,t1.bussiness_type as bussinessTypeName,t6.result_json as resultJson
from reception_customer_info t1
left join inspection_badge_recordings t2 on t1.id=t2.reception_id
left join inspection_employee_badge t5 on t2.badge_id =t5.badge_id
left join inspection_conversation_batch t3 on t2.id =t3.record_id
left join recording_batch_model_call_wghs t4 on t3.id =t4.batch_id
left join recording_batch_model_call t6 on (t6.recording_batch_id =t4.batch_id and t6.business_type=11)
left join recording_batch_model_call t6 on (t6.recording_batch_id =t4.batch_id and t6.business_type in (11,1107))
where t4.id is not null
<if test="merchantNo!=null">
and t1.merchant_id = #{merchantNo}
......@@ -659,6 +660,9 @@
<if test="violationStatus!=null">
and t4.wghs_Status = #{violationStatus}
</if>
<if test="carBrandId != null">
and t1.car_brandid = #{carBrandId}
</if>
<choose>
<!-- 当 violationStatus 不为 null 时 -->
<when test="violationStatus == null || violationStatus == 1">
......@@ -675,6 +679,7 @@
select t3.id as batchId,t5.employee_name as employeeName,t5.phone_number as employeePhone,t1.merchant_id as merchantNo,t1.phone_number as phoneNumber,t1.customer_name as customerName,
t1.car_model as carModel,t1.reception_start_time as startTime,t2.recording_url as fileUrl, t1.reception_end_time as endTime,t1.reception_status as receptionStatus,
t1.car_brand as carBrandName, t1.car_brandid as carBrandId,
t2.recording_duration as totalDuration,t4.wghs_Status as violationStatus,t4.Violation_Reason_confim_time as violationReasonConfimTime,t1.bussiness_type as bussinessTypeName
from reception_customer_info t1
left join inspection_badge_recordings t2 on t1.id=t2.reception_id
......
......@@ -52,7 +52,7 @@
select
t2.*,t1.result_json
from recording_batch_model_call_wghs t2
left join recording_batch_model_call t1 on (t1.recording_batch_id = t2.batch_id and t1.business_type=11)
left join recording_batch_model_call t1 on (t1.recording_batch_id = t2.batch_id and t1.business_type in (11,1107))
where t2.batch_id = #{batchId}
</select>
......
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="cn.com.glsx.dj.mindworkplate.mapper.RecordingTagConfigModelTypeMapper" >
<resultMap id="BaseResultMap" type="cn.com.glsx.dj.mindworkplate.model.RecordingTagConfigModelType" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="config_code" property="configCode" jdbcType="VARCHAR" />
<result column="model_type" property="modelType" jdbcType="VARCHAR" />
<result column="created_by" property="createdBy" jdbcType="VARCHAR" />
<result column="created_date" property="createdDate" jdbcType="TIMESTAMP" />
<result column="updated_by" property="updatedBy" jdbcType="VARCHAR" />
<result column="updated_date" property="updatedDate" jdbcType="TIMESTAMP" />
<result column="deleted_flag" property="deletedFlag" jdbcType="CHAR" />
</resultMap>
<sql id="Base_Column_List" >
id, config_code, model_type, created_by, created_date, updated_by, updated_date, deleted_flag
</sql>
<select id="findConfigCodesByModelType" resultType="java.lang.String">
select config_code from recording_tag_config_model_type
where model_type = #{modelType} and deleted_flag = 'N'
</select>
<select id="findModelTypesByConfigCode" resultType="java.lang.String">
select model_type from recording_tag_config_model_type
where config_code = #{configCode} and deleted_flag = 'N'
</select>
<select id="countByConfigCodeAndModelType" resultType="java.lang.Integer">
select count(*) from recording_tag_config_model_type
where config_code = #{configCode} and model_type = #{modelType} and deleted_flag = 'N'
</select>
</mapper>
......@@ -14,6 +14,7 @@
<result column="updated_date" property="updatedDate" jdbcType="TIMESTAMP" />
<result column="deleted_flag" property="deletedFlag" jdbcType="CHAR" />
<result column="description" property="description" jdbcType="VARCHAR" />
<result column="configCode" property="configCode" jdbcType="VARCHAR" />
</resultMap>
<sql id="Base_Column_List" >
......@@ -25,10 +26,20 @@
</sql>
<select id="findAll" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
<include refid="Base_Column_List" />,
config_code as configCode
from recording_tag_group
where deleted_flag = 'N'
AND config_code in (select code from recording_tag_config where scene_type=#{checkType})
</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>
\ No newline at end of file
......@@ -17,11 +17,12 @@
<result column="deleted_flag" property="deletedFlag" jdbcType="CHAR" />
<result column="rule_sql" property="ruleSql" 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="tagName" property="tagName" jdbcType="VARCHAR" />
<result column="tagId" property="tagId" jdbcType="INTEGER" />
<result column="score" property="score" jdbcType="DOUBLE" />
<result column="sumScore" property="sumScore" jdbcType="DOUBLE" />
<result column="configCode" property="configCode" jdbcType="VARCHAR" />
</resultMap>
<sql id="Base_Column_List" >
......@@ -35,10 +36,20 @@
<select id="findAll"
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 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_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 in (select code from recording_tag_config where scene_type=#{checkType})
</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>
\ No newline at end of file
......@@ -45,15 +45,15 @@ public class ConversationDateServiceTest extends BaseServiceTest{
ConversationBatch conversationBatch = conversationBatchMapper.selectByPrimaryKey(122);
conversationBatch.setCheckType(1);
conversationBatch.setCarBrandId(1);
conversationBatch.setOneCarBrandId(1);
conversationBatch.setOneCarBrandId(2336);
conversationDateService.singleBatchInspection(conversationBatch);
}
@Test
public void getCheckResult() throws Exception{
ConversationBatch conversationBatch = conversationBatchMapper.selectByPrimaryKey(124);
conversationBatch.setCheTaskId("Task-1932639431466942464");
conversationBatch.setCheckType(3);
ConversationBatch conversationBatch = conversationBatchMapper.selectByPrimaryKey(122);
conversationBatch.setCheTaskId("Task-2043591565565231104");
conversationBatch.setCheckType(1);
conversationDateService.getCheckResult(conversationBatch);
}
......
......@@ -38,7 +38,8 @@ public class RecordingModelCallTest extends BaseServiceTest{
@Test
public void insertWaitGet() {
recordingBatchModelCallService.insertWaitGet(121);
recordingBatchModelCallService.insertWaitGet(121, "问界");
recordingBatchModelCallService.insertWaitGet(121, "岚图");
}
@Test
public void execute1() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!