From ff083f6545e28dfe2ce7a5deeab924f3ebd6ff07 Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Fri, 24 Sep 2021 13:17:35 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=80=A7=E8=83=BD=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20=E4=B8=8B=E8=BD=BDzip=E6=8A=A5=E9=94=99=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../performance/controller/JmeterFileController.java | 2 +- .../performance/service/JmeterFileService.java | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/backend/src/main/java/io/metersphere/performance/controller/JmeterFileController.java b/backend/src/main/java/io/metersphere/performance/controller/JmeterFileController.java index aeeafce010..f37877c13e 100644 --- a/backend/src/main/java/io/metersphere/performance/controller/JmeterFileController.java +++ b/backend/src/main/java/io/metersphere/performance/controller/JmeterFileController.java @@ -48,7 +48,7 @@ public class JmeterFileController { @RequestParam("ratio") String ratio, @RequestParam("reportId") String reportId, @RequestParam("resourceIndex") int resourceIndex) { double[] ratios = Arrays.stream(ratio.split(",")).mapToDouble(Double::parseDouble).toArray(); - byte[] bytes = jmeterFileService.downloadZip(testId, ratios, reportId, resourceIndex); + byte[] bytes = jmeterFileService.downloadZip(reportId, ratios, resourceIndex); return ResponseEntity.ok() .contentType(MediaType.parseMediaType("application/octet-stream")) .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + testId + ".zip\"") diff --git a/backend/src/main/java/io/metersphere/performance/service/JmeterFileService.java b/backend/src/main/java/io/metersphere/performance/service/JmeterFileService.java index a4936c3afe..beb33b7600 100644 --- a/backend/src/main/java/io/metersphere/performance/service/JmeterFileService.java +++ b/backend/src/main/java/io/metersphere/performance/service/JmeterFileService.java @@ -1,9 +1,7 @@ package io.metersphere.performance.service; - import com.alibaba.excel.util.CollectionUtils; import io.metersphere.base.domain.LoadTestReportWithBLOBs; -import io.metersphere.base.mapper.LoadTestMapper; import io.metersphere.base.mapper.LoadTestReportMapper; import io.metersphere.base.mapper.ext.ExtLoadTestReportMapper; import io.metersphere.commons.exception.MSException; @@ -25,18 +23,17 @@ import java.util.zip.ZipOutputStream; @Service @Transactional(rollbackFor = Exception.class) public class JmeterFileService { - - @Resource - private LoadTestMapper loadTestMapper; @Resource private ExtLoadTestReportMapper extLoadTestReportMapper; @Resource private LoadTestReportMapper loadTestReportMapper; - public byte[] downloadZip(String testId, double[] ratios, String reportId, int resourceIndex) { + public byte[] downloadZip(String reportId, double[] ratios, int resourceIndex) { try { LoadTestReportWithBLOBs loadTestReport = loadTestReportMapper.selectByPrimaryKey(reportId); - + if (loadTestReport == null) { + MSException.throwException("测试报告不存在或还没产生"); + } EngineContext context = EngineFactory.createContext(loadTestReport, ratios, reportId, resourceIndex); return zipFilesToByteArray(context); } catch (MSException e) {