From 25fcc34b6890cfd43dc0f1989acf0f2a6b334a28 Mon Sep 17 00:00:00 2001 From: stream Date: Fri, 6 Feb 2026 14:44:05 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=AF=AD=E9=9F=B3=E8=AF=84=E4=BC=B0?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../evaluation/model/vo/AeViEvaluationVO.java | 4 +- .../vi/service/impl/ViProjectServiceImpl.java | 165 +++++++++++++++++- 2 files changed, 164 insertions(+), 5 deletions(-) diff --git a/cmvr-iot-evaluation/src/main/java/com/cmvr/evaluation/model/vo/AeViEvaluationVO.java b/cmvr-iot-evaluation/src/main/java/com/cmvr/evaluation/model/vo/AeViEvaluationVO.java index 6383ffd..c5f4e39 100644 --- a/cmvr-iot-evaluation/src/main/java/com/cmvr/evaluation/model/vo/AeViEvaluationVO.java +++ b/cmvr-iot-evaluation/src/main/java/com/cmvr/evaluation/model/vo/AeViEvaluationVO.java @@ -48,8 +48,8 @@ public class AeViEvaluationVO { @ApiModelProperty(value = "评估项响应时间(ms)") private Long itemResponseTime; - @ApiModelProperty(value = "是否成功(true:成功,false:失败)") - private Boolean success; + @ApiModelProperty("评估状态,0:待评估,1:评估中,3:评估成功,4:评估失败") + private Integer status; @ApiModelProperty(value = "评估相关视频地址") private String videoPath; diff --git a/cmvr-iot-vi/src/main/java/com/cmvr/vi/service/impl/ViProjectServiceImpl.java b/cmvr-iot-vi/src/main/java/com/cmvr/vi/service/impl/ViProjectServiceImpl.java index 5dde44a..db31022 100644 --- a/cmvr-iot-vi/src/main/java/com/cmvr/vi/service/impl/ViProjectServiceImpl.java +++ b/cmvr-iot-vi/src/main/java/com/cmvr/vi/service/impl/ViProjectServiceImpl.java @@ -1,5 +1,6 @@ package com.cmvr.vi.service.impl; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjUtil; import cn.hutool.core.util.StrUtil; 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.evaluation.model.domain.AeEvaluation; 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.vo.AeViEvaluationVO; import com.cmvr.evaluation.service.AeIndicatorService; import com.cmvr.evaluation.service.IAeEvaluationService; import com.cmvr.test.enums.FlowSceneTypeEnum; @@ -165,8 +166,8 @@ public class ViProjectServiceImpl extends ServiceImpl queryEvaluation(String projectId) { + + /*public List queryEvaluation(String projectId) { // 1. 查询项目 ViProject project = getById(projectId); @@ -187,6 +188,8 @@ public class ViProjectServiceImpl extends ServiceImpl evaluations = aeEvaluationService.queryEvaluation(instId); + + // 5. 获取指标定义 List indicators = aeIndicatorService.getChildrenByParentIdWithLevelLimit(project.getIndicatorId(), 4, 0); @@ -214,6 +217,7 @@ public class ViProjectServiceImpl extends ServiceImpl queryEvaluation(String projectId) { + + // 1. 查询项目 + ViProject project = getById(projectId); + + // 2. 查询实例ID + String instId = queryExecuteInstId(projectId); + + // 3. 查询检测项(itemId -> schemeId) + List items = queryExecuteRunParams(projectId); + + Map itemSchemeMap = items.stream() + .filter(i -> StrUtil.isNotBlank(i.getItemId()) && StrUtil.isNotBlank(i.getSchemeId())) + .collect(Collectors.toMap( + TeQueryProjectOrchestraItemVO::getItemId, + TeQueryProjectOrchestraItemVO::getSchemeId, + (a, b) -> a + )); + + Map schemeNameMap = items.stream() + .filter(i -> StrUtil.isNotBlank(i.getSchemeId())) + .collect(Collectors.toMap( + TeQueryProjectOrchestraItemVO::getSchemeId, + TeQueryProjectOrchestraItemVO::getSchemeName, + (a, b) -> a + )); + + // 4. 查询评估数据(允许不完整) + List evaluations = aeEvaluationService.queryEvaluation(instId); + + if (CollUtil.isEmpty(evaluations)) { + throw new GlobalException(StrUtil.format("暂无项目id为{}的数据", projectId)); + } + + // 5. 获取指标定义 + List indicators = + aeIndicatorService.getChildrenByParentIdWithLevelLimit( + project.getIndicatorId(), 4, 0 + ); + + // 6. 按 schemeId 分组评估数据 + Map> 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 resultList = new ArrayList<>(); + + // 7. 按 scheme 处理 + for (Map.Entry> entry : schemaEvaluationMap.entrySet()) { + + String schemeId = entry.getKey(); + List evalList = entry.getValue(); + + List 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; }