fix(性能测试): 修复性能测试导出测试报告时没有环境内容的问题

--bug=1015089 --user=宋天阳 【性能测试】导出报告,没有展示运行环境
https://www.tapd.cn/55049933/s/1267182
This commit is contained in:
song-tianyang 2022-10-19 15:19:01 +08:00 committed by 刘瑞斌
parent f43b2f473a
commit e450297353
4 changed files with 62 additions and 16 deletions

View File

@ -24,6 +24,7 @@ import io.metersphere.service.BaseProjectService;
import io.metersphere.service.NodeTreeService;
import io.metersphere.service.SystemParameterService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.ExecutorType;
@ -807,4 +808,24 @@ public class BaseEnvironmentService extends NodeTreeService<ApiModuleDTO> {
}
}
public LinkedHashMap<String, List<String>> selectProjectNameAndEnvName(Map<String, List<String>> projectEnvIdMap) {
LinkedHashMap<String, List<String>> returnMap = new LinkedHashMap<>();
if (MapUtils.isNotEmpty(projectEnvIdMap)) {
for (Map.Entry<String, List<String>> entry : projectEnvIdMap.entrySet()) {
String projectId = entry.getKey();
List<String> envIdList = entry.getValue();
Project project = baseProjectService.getProjectById(projectId);
if (project != null) {
String projectName = project.getName();
List<String> envNameList = this.selectNameByIds(envIdList);
if (CollectionUtils.isNotEmpty(envNameList) && StringUtils.isNotEmpty(projectName)) {
returnMap.put(projectName, new ArrayList<>() {{
this.addAll(envNameList);
}});
}
}
}
}
return returnMap;
}
}

View File

@ -15,6 +15,7 @@ import io.metersphere.commons.utils.LogUtil;
import io.metersphere.dto.*;
import io.metersphere.engine.Engine;
import io.metersphere.engine.EngineFactory;
import io.metersphere.environment.service.BaseEnvironmentService;
import io.metersphere.i18n.Translator;
import io.metersphere.log.utils.ReflexObjectUtil;
import io.metersphere.log.vo.DetailColumn;
@ -27,6 +28,7 @@ import io.metersphere.request.RenameReportRequest;
import io.metersphere.request.ReportRequest;
import io.metersphere.xpack.quota.service.QuotaService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
@ -81,6 +83,8 @@ public class PerformanceReportService {
private LoadTestReportFileMapper loadTestReportFileMapper;
@Resource
private ExtTestPlanLoadCaseMapper extTestPlanLoadCaseMapper;
@Resource
private BaseEnvironmentService baseEnvironmentService;
public List<ReportDTO> getRecentReportList(ReportRequest request) {
List<OrderRequest> orders = new ArrayList<>();
@ -349,19 +353,19 @@ public class PerformanceReportService {
}
private void parseRunEnvironment(LoadTestReportInfoDTO loadTestReportInfoDTO) {
// todo
// if (loadTestReportInfoDTO != null && StringUtils.isNotEmpty(loadTestReportInfoDTO.getEnvInfo())) {
// Map<String, List<String>> projectEnvIdMap = new HashMap<>();
// try {
// projectEnvIdMap = JSONObject.parseObject(loadTestReportInfoDTO.getEnvInfo(), Map.class);
// LinkedHashMap<String, List<String>> projectEnvNameMap = apiScenarioEnvService.selectProjectNameAndEnvName(projectEnvIdMap);
// if (MapUtils.isNotEmpty(projectEnvNameMap)) {
// loadTestReportInfoDTO.setProjectEnvMap(projectEnvNameMap);
// }
// } catch (Exception e) {
// LogUtil.error("性能测试报告解析运行环境信息失败!解析参数:" + loadTestReportInfoDTO.getEnvInfo(), e);
// }
// }
if (loadTestReportInfoDTO != null && StringUtils.isNotEmpty(loadTestReportInfoDTO.getEnvInfo())) {
Map<String, List<String>> projectEnvIdMap = new HashMap<>();
try {
projectEnvIdMap = JSON.parseObject(loadTestReportInfoDTO.getEnvInfo(), Map.class);
LinkedHashMap<String, List<String>> projectEnvNameMap = baseEnvironmentService.selectProjectNameAndEnvName(projectEnvIdMap);
if (MapUtils.isNotEmpty(projectEnvNameMap)) {
loadTestReportInfoDTO.setProjectEnvMap(projectEnvNameMap);
}
} catch (Exception e) {
LogUtil.error("性能测试报告解析运行环境信息失败!解析参数:" + loadTestReportInfoDTO.getEnvInfo(), e);
}
}
}
public List<LogDetailDTO> getReportLogResource(String reportId) {

View File

@ -3,6 +3,14 @@
<el-card id="testOverview">
<template v-slot:header>
<span class="title">{{ $t('report.test_overview') }}</span>
<span v-if="projectEnvMap && Object.keys(projectEnvMap).length > 0">
<span> {{ $t('commons.environment') + ':' }} </span>
<span v-for="(values,key) in projectEnvMap" :key="key" style="margin-right: 10px">
{{ key + ":" }}
<ms-tag v-for="(item,index) in values" :key="index" type="success" :content="item"
style="margin-left: 2px"/>
</span>
</span>
</template>
<ms-report-test-overview :report="report" :export="true" ref="testOverview"/>
</el-card>
@ -43,6 +51,7 @@ import MsReportTitle from "metersphere-frontend/src/components/report/MsReportTi
import MsReportExportTemplate from "metersphere-frontend/src/components/report/MsReportExportTemplate";
import MsReportTestDetails from "./components/TestDetails";
import MonitorCard from "./components/MonitorCard";
import MsTag from "metersphere-frontend/src/components/MsTag";
export default {
@ -55,8 +64,9 @@ export default {
MsReportTestDetails,
MsReportRequestStatistics,
MsReportTestOverview,
MsTag,
},
props: ['report', 'title']
props: ['report', 'title', 'projectEnvMap']
}
</script>

View File

@ -54,7 +54,8 @@
@click="compareReports()">
{{ $t('report.compare') }}
</el-button>
<el-button type="warning" plain size="mini" :disabled="isReadOnly || report.status !== 'Completed' || testDeleted"
<el-button type="warning" plain size="mini"
:disabled="isReadOnly || report.status !== 'Completed' || testDeleted"
@click="downloadJtl()">
{{ $t('report.downloadJtl') }}
</el-button>
@ -142,6 +143,7 @@
</div>
<ms-performance-report-export :title="reportName" id="performanceReportExport" v-show="reportExportVisible"
:project-env-map="allProjectEnvMap"
:report="report"/>
</el-card>
@ -181,7 +183,16 @@ import MonitorCard from "./components/MonitorCard";
import MsTestConfiguration from "./components/TestConfiguration";
import {generateShareInfoWithExpired, getShareRedirectUrl} from "@/api/share";
import ProjectEnvironmentDialog from "./components/ProjectEnvironmentDialog";
import {downloadJtl, downloadZip, getProjectApplication, getReport, getReportTime, getTestProInfo, initReportSocket, stopTest} from "@/api/report";
import {
downloadJtl,
downloadZip,
getProjectApplication,
getReport,
getReportTime,
getTestProInfo,
initReportSocket,
stopTest
} from "@/api/report";
import {getTest, runTest} from "@/api/performance";