Commit c1948877 by 林永健

feat(violation): 添加违规检测中的车辆品牌信息支持

- 在ReceptionViolationRequest中新增carBrandId字段
- 在ViolationExportModel中新增carBrandName导出字段
- 重构ViolationScriptsAbstractStrategy中的违规检测逻辑,优化规则匹配算法
- 修改RecordingBatchModelCallService以支持按车型指定不同模型类型
- 标记旧的insertWaitGet方法为废弃并新增带车型参数的方法
- 在数据库查询中添加车辆品牌相关的筛选条件
- 更新ReceptionViolationInfoDTO和ReceptionViolationReqDTO数据传输对象
- 调整测试用例以验证新的车型参数功能
1 parent 9e3d4f8a
......@@ -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
......@@ -20,6 +20,9 @@ public class ViolationExportModel implements Serializable {
@ExcelProperty({"序号"})
private Integer index;
@ExcelProperty({"品牌"})
private String carBrandName;
@ExcelProperty({"员工"})
private String employeeName;
......
......@@ -195,11 +195,7 @@ public class EmployeeBadgeRecordingService {
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());
}
recordingBatchModelCallService.insertWaitGet(conversationBatch.getId(), carModel);
}
}
}
......
......@@ -1388,6 +1388,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()
......
......@@ -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 carModel){
List<RecordingBatchModelCall> recordingBatchModelCallList = new ArrayList<>();
// 通用配置
String property = environment.getProperty("recording.model.call.type.nwj");
// 车型关联配置
String carModelPropertyStr = environment.getProperty("recording.model.call.type.map");
if (StringUtils.isBlank(carModelPropertyStr)) {
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 carModelPropertyObj = JSON.parseObject(carModelPropertyStr);
if (Objects.isNull(carModelPropertyObj)) {
log.error("录音大模型任务创建异常,配置解析异常");
return;
}
if (StringUtils.isNotBlank(carModel)) {
property = carModelPropertyObj.keySet().stream()
.filter(carModel::contains)
.findFirst()
.map(carModelPropertyObj::getString)
.orElse(property); // 匹配不到匹配的则使用通用配置
}
log.info("录音大模型任务配置准备,carModel:{}, property:{}", carModel, property);
if (StringUtils.isEmpty(property)) {
log.error("录音大模型任务创建异常,配置为空, carModel:{}, property:{}", carModel, 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());
......
......@@ -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 "H101":
case "H102":
case "H103":
case "H104":
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,6 +624,7 @@
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
......@@ -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
......
......@@ -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() {
......
  • @wangxw1
    commented
    Master

    一、关键问题与优化建议

    • 问题 1:ViolationScriptsAbstractStrategy 中的 Switch 逻辑存在严重的 Fall-through(穿透)缺陷
      • 问题描述:在 ViolationScriptsAbstractStrategy.java 的 switch (o.toString()) 块中,case "R101" 和 case "R102" 两个分支在执行完逻辑后没有 break 语句。由于 isMatch 变量在循环开始时被重置为 false,这会导致即使 R101 匹配成功,逻辑也会继续穿透到 R102、R103 等后续分支。
      • 影响分析:逻辑错误。如果 R101 匹配成功,由于没有 break,代码会继续判断后续 case。虽然 isMatch 可能在 R101 时为 true,但如果后续 case 逻辑(如 R103)不符合条件,isMatch 状态可能被覆盖或产生非预期行为。更严重的是,R101 匹配时会执行 R102 的逻辑,导致数据重复处理或逻辑误判。
      • 优化建议:在每个 case 逻辑块结束处显式添加 break。
    • 问题 2:RecordingBatchModelCallService 中配置解析缺乏防御性校验
      • 问题描述:在 insertWaitGet 方法中,从 environment 获取的 property(通用配置)和 carModelPropertyStr(车型映射配置)在后续使用时存在风险。虽然代码检查了 carModelPropertyStr 是否为空,但对于 property 的处理不够健壮。如果 property 为空且未匹配到车型映射,后续 property.split(",") 将触发 NullPointerException。
      • 影响分析:系统稳定性风险。配置文件的缺失或格式错误会导致整个录音任务创建流程崩溃,并在日志中抛出空指针异常。
      • 优化建议:在执行 split 之前,确保 property 变量不为 null。
    • 问题 3:资源管理风险:异常处理不规范(e.printStackTrace())
      • 问题描述:在 RecordingBatchModelCallService.java 的 insertWaitGet 方法中,catch 块使用了 e.printStackTrace()。
      • 影响分析:性能与运维风险。printStackTrace() 将堆栈信息输出到标准错误流(System.err),可能导致日志系统无法统一收集、阻塞 JVM 线程,且在高并发下产生明显的性能损耗。
      • 优化建议:移除 e.printStackTrace(),统一使用 log.error("...", e) 记录异常信息,确保堆栈信息能通过日志框架(如 Logback/Log4j2)正确持久化。

    二、评分明细

    评分维度 分数 理由
    功能实现正确性与健壮性 30分 引入了严重的 switch 穿透逻辑错误;异常处理逻辑中存在 NPE 隐患。
    安全性与潜在风险 30分 未发现 SQL 注入或越权等直接安全漏洞,SQL 参数使用了 #{} 占位符。
    最佳实践与可维护性 15分 使用了 @Deprecated 维护兼容性,但 e.printStackTrace() 不符合工程实践。
    性能与资源利用 4分 逻辑中存在不必要的日志打印(循环内打印),且 printStackTrace 有潜在性能影响。
    提交信息质量 5分 Commit 信息详尽,准确描述了变更内容及作者。

    总分:84分

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