From fc598de402cffa8744ee656948f715c31e7d58a2 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Thu, 23 Dec 2021 19:08:21 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=8B=E8=BD=BDJMX=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=8F=8AZIP=E5=8C=85=E5=90=8D=E7=A7=B0=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/controller/ApiJmeterFileController.java | 3 ++- .../metersphere/api/service/ApiJmeterFileService.java | 11 ++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/controller/ApiJmeterFileController.java b/backend/src/main/java/io/metersphere/api/controller/ApiJmeterFileController.java index 9fd3402508..270c7330b8 100644 --- a/backend/src/main/java/io/metersphere/api/controller/ApiJmeterFileController.java +++ b/backend/src/main/java/io/metersphere/api/controller/ApiJmeterFileController.java @@ -49,9 +49,10 @@ public class ApiJmeterFileController { @GetMapping("download") public ResponseEntity downloadJmeterFiles(@RequestParam("testId") String testId, @RequestParam("reportId") String reportId, @RequestParam("runMode") String runMode, @RequestParam("testPlanScenarioId") String testPlanScenarioId) { byte[] bytes = apiJmeterFileService.downloadJmeterFiles(runMode, testId, reportId, testPlanScenarioId); + String zipName = reportId + "_" + testId; return ResponseEntity.ok() .contentType(MediaType.parseMediaType("application/octet-stream")) - .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + testId + ".zip\"") + .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + zipName + ".zip\"") .body(bytes); } diff --git a/backend/src/main/java/io/metersphere/api/service/ApiJmeterFileService.java b/backend/src/main/java/io/metersphere/api/service/ApiJmeterFileService.java index 15b4fadea1..4562446351 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiJmeterFileService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiJmeterFileService.java @@ -68,7 +68,7 @@ public class ApiJmeterFileService { } } HashTree hashTree; - if (StringUtils.equalsAnyIgnoreCase(runMode, ApiRunMode.DEFINITION.name(), ApiRunMode.JENKINS_API_PLAN.name(),ApiRunMode.API_PLAN.name(), ApiRunMode.SCHEDULE_API_PLAN.name(), ApiRunMode.MANUAL_PLAN.name())) { + if (StringUtils.equalsAnyIgnoreCase(runMode, ApiRunMode.DEFINITION.name(), ApiRunMode.JENKINS_API_PLAN.name(), ApiRunMode.API_PLAN.name(), ApiRunMode.SCHEDULE_API_PLAN.name(), ApiRunMode.MANUAL_PLAN.name())) { String testId = remoteTestId; if (remoteTestId.contains(":")) { //执行测试计划案例时会有拼接ID,ID为 planTestCaseId:测试计划报告ID @@ -82,9 +82,11 @@ public class ApiJmeterFileService { } hashTree = apiAutomationService.generateHashTree(item, reportId, planEnvMap); } - return zipFilesToByteArray(reportId, hashTree); + String jmxName = reportId + "_" + remoteTestId + ".jmx"; + return zipFilesToByteArray(jmxName, hashTree); } + public byte[] downloadJmx(String runMode, String testId, String reportId, String testPlanScenarioId) { Map planEnvMap = new HashMap<>(); if (StringUtils.isNotEmpty(testPlanScenarioId)) { @@ -222,12 +224,11 @@ public class ApiJmeterFileService { return multipartFiles; } - private byte[] zipFilesToByteArray(String testId, HashTree hashTree) { - String fileName = testId + ".jmx"; + private byte[] zipFilesToByteArray(String jmxName, HashTree hashTree) { String jmx = new MsTestPlan().getJmx(hashTree); Map files = new HashMap<>(); // 每个测试生成一个文件夹 - files.put(fileName, jmx.getBytes(StandardCharsets.UTF_8)); + files.put(jmxName, jmx.getBytes(StandardCharsets.UTF_8)); // 获取JMX使用到的附件 Map multipartFiles = this.getMultipartFiles(hashTree); if (!com.alibaba.excel.util.CollectionUtils.isEmpty(multipartFiles)) {