fix: 语音评估查询
This commit is contained in:
parent
bf159ce7be
commit
25fcc34b68
@ -48,8 +48,8 @@ public class AeViEvaluationVO {
|
|||||||
@ApiModelProperty(value = "评估项响应时间(ms)")
|
@ApiModelProperty(value = "评估项响应时间(ms)")
|
||||||
private Long itemResponseTime;
|
private Long itemResponseTime;
|
||||||
|
|
||||||
@ApiModelProperty(value = "是否成功(true:成功,false:失败)")
|
@ApiModelProperty("评估状态,0:待评估,1:评估中,3:评估成功,4:评估失败")
|
||||||
private Boolean success;
|
private Integer status;
|
||||||
|
|
||||||
@ApiModelProperty(value = "评估相关视频地址")
|
@ApiModelProperty(value = "评估相关视频地址")
|
||||||
private String videoPath;
|
private String videoPath;
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package com.cmvr.vi.service.impl;
|
package com.cmvr.vi.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.util.ObjUtil;
|
import cn.hutool.core.util.ObjUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.alibaba.fastjson2.JSON;
|
import com.alibaba.fastjson2.JSON;
|
||||||
@ -9,8 +10,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|||||||
import com.cmvr.common.exception.GlobalException;
|
import com.cmvr.common.exception.GlobalException;
|
||||||
import com.cmvr.evaluation.model.domain.AeEvaluation;
|
import com.cmvr.evaluation.model.domain.AeEvaluation;
|
||||||
import com.cmvr.evaluation.model.domain.AeIndicatorEntity;
|
import com.cmvr.evaluation.model.domain.AeIndicatorEntity;
|
||||||
import com.cmvr.evaluation.model.vo.AeViEvaluationVO;
|
|
||||||
import com.cmvr.evaluation.model.dto.AeIResultDTO;
|
import com.cmvr.evaluation.model.dto.AeIResultDTO;
|
||||||
|
import com.cmvr.evaluation.model.vo.AeViEvaluationVO;
|
||||||
import com.cmvr.evaluation.service.AeIndicatorService;
|
import com.cmvr.evaluation.service.AeIndicatorService;
|
||||||
import com.cmvr.evaluation.service.IAeEvaluationService;
|
import com.cmvr.evaluation.service.IAeEvaluationService;
|
||||||
import com.cmvr.test.enums.FlowSceneTypeEnum;
|
import com.cmvr.test.enums.FlowSceneTypeEnum;
|
||||||
@ -165,8 +166,8 @@ public class ViProjectServiceImpl extends ServiceImpl<ViProjectMapper, ViProject
|
|||||||
return latestTaskInst;
|
return latestTaskInst;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<AeViEvaluationVO> queryEvaluation(String projectId) {
|
/*public List<AeViEvaluationVO> queryEvaluation(String projectId) {
|
||||||
// 1. 查询项目
|
// 1. 查询项目
|
||||||
ViProject project = getById(projectId);
|
ViProject project = getById(projectId);
|
||||||
|
|
||||||
@ -187,6 +188,8 @@ public class ViProjectServiceImpl extends ServiceImpl<ViProjectMapper, ViProject
|
|||||||
// 4. 查询评估数据
|
// 4. 查询评估数据
|
||||||
List<AeEvaluation> evaluations = aeEvaluationService.queryEvaluation(instId);
|
List<AeEvaluation> evaluations = aeEvaluationService.queryEvaluation(instId);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 5. 获取指标定义
|
// 5. 获取指标定义
|
||||||
List<AeIndicatorEntity> indicators = aeIndicatorService.getChildrenByParentIdWithLevelLimit(project.getIndicatorId(), 4, 0);
|
List<AeIndicatorEntity> indicators = aeIndicatorService.getChildrenByParentIdWithLevelLimit(project.getIndicatorId(), 4, 0);
|
||||||
|
|
||||||
@ -214,6 +217,7 @@ public class ViProjectServiceImpl extends ServiceImpl<ViProjectMapper, ViProject
|
|||||||
|
|
||||||
// 8. 计算每个评估项的响应时间得分和成功率得分
|
// 8. 计算每个评估项的响应时间得分和成功率得分
|
||||||
for (AeEvaluation evaluation : evalList) {
|
for (AeEvaluation evaluation : evalList) {
|
||||||
|
|
||||||
AeIResultDTO dto = JSON.parseObject(evaluation.getResult(), AeIResultDTO.class);
|
AeIResultDTO dto = JSON.parseObject(evaluation.getResult(), AeIResultDTO.class);
|
||||||
|
|
||||||
// 创建评估项对象
|
// 创建评估项对象
|
||||||
@ -270,6 +274,161 @@ public class ViProjectServiceImpl extends ServiceImpl<ViProjectMapper, ViProject
|
|||||||
resultList.add(vo);
|
resultList.add(vo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return resultList;
|
||||||
|
}*/
|
||||||
|
@Override
|
||||||
|
public List<AeViEvaluationVO> queryEvaluation(String projectId) {
|
||||||
|
|
||||||
|
// 1. 查询项目
|
||||||
|
ViProject project = getById(projectId);
|
||||||
|
|
||||||
|
// 2. 查询实例ID
|
||||||
|
String instId = queryExecuteInstId(projectId);
|
||||||
|
|
||||||
|
// 3. 查询检测项(itemId -> schemeId)
|
||||||
|
List<TeQueryProjectOrchestraItemVO> items = queryExecuteRunParams(projectId);
|
||||||
|
|
||||||
|
Map<String, String> itemSchemeMap = items.stream()
|
||||||
|
.filter(i -> StrUtil.isNotBlank(i.getItemId()) && StrUtil.isNotBlank(i.getSchemeId()))
|
||||||
|
.collect(Collectors.toMap(
|
||||||
|
TeQueryProjectOrchestraItemVO::getItemId,
|
||||||
|
TeQueryProjectOrchestraItemVO::getSchemeId,
|
||||||
|
(a, b) -> a
|
||||||
|
));
|
||||||
|
|
||||||
|
Map<String, String> schemeNameMap = items.stream()
|
||||||
|
.filter(i -> StrUtil.isNotBlank(i.getSchemeId()))
|
||||||
|
.collect(Collectors.toMap(
|
||||||
|
TeQueryProjectOrchestraItemVO::getSchemeId,
|
||||||
|
TeQueryProjectOrchestraItemVO::getSchemeName,
|
||||||
|
(a, b) -> a
|
||||||
|
));
|
||||||
|
|
||||||
|
// 4. 查询评估数据(允许不完整)
|
||||||
|
List<AeEvaluation> evaluations = aeEvaluationService.queryEvaluation(instId);
|
||||||
|
|
||||||
|
if (CollUtil.isEmpty(evaluations)) {
|
||||||
|
throw new GlobalException(StrUtil.format("暂无项目id为{}的数据", projectId));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5. 获取指标定义
|
||||||
|
List<AeIndicatorEntity> indicators =
|
||||||
|
aeIndicatorService.getChildrenByParentIdWithLevelLimit(
|
||||||
|
project.getIndicatorId(), 4, 0
|
||||||
|
);
|
||||||
|
|
||||||
|
// 6. 按 schemeId 分组评估数据
|
||||||
|
Map<String, List<AeEvaluation>> schemaEvaluationMap = evaluations.stream()
|
||||||
|
.map(e -> new AbstractMap.SimpleEntry<>(itemSchemeMap.get(e.getItemId()), e))
|
||||||
|
.filter(entry -> StrUtil.isNotBlank(entry.getKey()))
|
||||||
|
.collect(Collectors.groupingBy(
|
||||||
|
Map.Entry::getKey,
|
||||||
|
Collectors.mapping(Map.Entry::getValue, Collectors.toList())
|
||||||
|
));
|
||||||
|
|
||||||
|
List<AeViEvaluationVO> resultList = new ArrayList<>();
|
||||||
|
|
||||||
|
// 7. 按 scheme 处理
|
||||||
|
for (Map.Entry<String, List<AeEvaluation>> entry : schemaEvaluationMap.entrySet()) {
|
||||||
|
|
||||||
|
String schemeId = entry.getKey();
|
||||||
|
List<AeEvaluation> evalList = entry.getValue();
|
||||||
|
|
||||||
|
List<AeViEvaluationVO.AeItemDetail> itemDetails = new ArrayList<>();
|
||||||
|
|
||||||
|
long responseTimeSum = 0L;
|
||||||
|
long responseTimeCount = 0L;
|
||||||
|
long successCount = 0L;
|
||||||
|
|
||||||
|
// ===== 关键:scheme 是否全部完成 =====
|
||||||
|
boolean allFinished = true;
|
||||||
|
|
||||||
|
for (AeEvaluation evaluation : evalList) {
|
||||||
|
|
||||||
|
AeViEvaluationVO.AeItemDetail itemDto = new AeViEvaluationVO.AeItemDetail();
|
||||||
|
itemDto.setAeId(evaluation.getAeId());
|
||||||
|
itemDto.setContent(evaluation.getAvContent());
|
||||||
|
|
||||||
|
boolean finished =
|
||||||
|
StrUtil.isNotBlank(evaluation.getResult())
|
||||||
|
&& evaluation.getStatus() != null
|
||||||
|
&& evaluation.getStatus() != 0 // 待评估
|
||||||
|
&& evaluation.getStatus() != 1; // 评估中
|
||||||
|
itemDto.setStatus(evaluation.getStatus());
|
||||||
|
if (!finished) {
|
||||||
|
allFinished = false;
|
||||||
|
|
||||||
|
// 未完成,只返回基础信息
|
||||||
|
|
||||||
|
// itemDto.setExecutionDetail("评估尚未完成");
|
||||||
|
itemDetails.add(itemDto);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===== 已完成 =====
|
||||||
|
AeIResultDTO dto = JSON.parseObject(evaluation.getResult(), AeIResultDTO.class);
|
||||||
|
|
||||||
|
itemDto.setItemResponseTime(dto.getResponseTime());
|
||||||
|
|
||||||
|
boolean success = "成功".equals(dto.getOverallResult());
|
||||||
|
|
||||||
|
if (!success) {
|
||||||
|
itemDto.setFailureReason(dto.getFailureReason());
|
||||||
|
}
|
||||||
|
|
||||||
|
itemDto.setVideoPath(dto.getVideoPath());
|
||||||
|
itemDto.setExecutionDetail(dto.getExecutionDetail());
|
||||||
|
|
||||||
|
itemDetails.add(itemDto);
|
||||||
|
|
||||||
|
// 汇总(即便先算,最终是否使用由 allFinished 决定)
|
||||||
|
if (dto.getResponseTime() != null) {
|
||||||
|
responseTimeSum += dto.getResponseTime();
|
||||||
|
responseTimeCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (success) {
|
||||||
|
successCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===== 组装 VO =====
|
||||||
|
AeViEvaluationVO vo = new AeViEvaluationVO();
|
||||||
|
vo.setSchemeId(schemeId);
|
||||||
|
vo.setSchemeName(schemeNameMap.getOrDefault(schemeId, ""));
|
||||||
|
vo.setItemDetails(itemDetails);
|
||||||
|
|
||||||
|
// ===== 核心规则:只要有一条未完成,就不算指标 =====
|
||||||
|
if (!allFinished) {
|
||||||
|
vo.setResponseTime(null);
|
||||||
|
vo.setResponseTimeScore(null);
|
||||||
|
vo.setSuccessRate(null);
|
||||||
|
vo.setSuccessRateScore(null);
|
||||||
|
resultList.add(vo);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===== 全部完成,才计算指标 =====
|
||||||
|
Long avgResponseTime =
|
||||||
|
responseTimeCount == 0 ? 0L : responseTimeSum / responseTimeCount;
|
||||||
|
|
||||||
|
Long responseTimeScore =
|
||||||
|
calculateResponseTimeScore(avgResponseTime, indicators);
|
||||||
|
|
||||||
|
Long successRate =
|
||||||
|
evalList.isEmpty() ? 0L : (successCount * 100) / evalList.size();
|
||||||
|
|
||||||
|
Long successRateScore =
|
||||||
|
calculateSuccessRateScore(successRate, indicators);
|
||||||
|
|
||||||
|
vo.setResponseTime(avgResponseTime);
|
||||||
|
vo.setResponseTimeScore(responseTimeScore);
|
||||||
|
vo.setSuccessRate(successRate);
|
||||||
|
vo.setSuccessRateScore(successRateScore);
|
||||||
|
|
||||||
|
resultList.add(vo);
|
||||||
|
}
|
||||||
|
|
||||||
return resultList;
|
return resultList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user