diff --git a/backend/src/main/java/io/metersphere/performance/controller/PerformanceReportController.java b/backend/src/main/java/io/metersphere/performance/controller/PerformanceReportController.java index 5fd93d32f2..e54e40675f 100644 --- a/backend/src/main/java/io/metersphere/performance/controller/PerformanceReportController.java +++ b/backend/src/main/java/io/metersphere/performance/controller/PerformanceReportController.java @@ -11,6 +11,7 @@ import io.metersphere.commons.utils.SessionUtils; import io.metersphere.dto.LogDetailDTO; import io.metersphere.dto.ReportDTO; import io.metersphere.performance.base.*; +import io.metersphere.performance.controller.request.DeleteReportRequest; import io.metersphere.performance.controller.request.ReportRequest; import io.metersphere.performance.service.ReportService; import org.apache.shiro.authz.annotation.Logical; @@ -113,4 +114,9 @@ public class PerformanceReportController { public void downloadLog(@PathVariable String reportId, @PathVariable String resourceId, HttpServletResponse response) throws Exception { reportService.downloadLog(response, reportId, resourceId); } + + @PostMapping("/batch/delete") + public void deleteReportBatch(@RequestBody DeleteReportRequest reportRequest) { + reportService.deleteReportBatch(reportRequest); + } } diff --git a/backend/src/main/java/io/metersphere/performance/controller/request/DeleteReportRequest.java b/backend/src/main/java/io/metersphere/performance/controller/request/DeleteReportRequest.java new file mode 100644 index 0000000000..5e1b2b2132 --- /dev/null +++ b/backend/src/main/java/io/metersphere/performance/controller/request/DeleteReportRequest.java @@ -0,0 +1,13 @@ +package io.metersphere.performance.controller.request; + +import lombok.Getter; +import lombok.Setter; + +import java.util.List; + +@Getter +@Setter +public class DeleteReportRequest { + + private List ids; +} diff --git a/backend/src/main/java/io/metersphere/performance/service/ReportService.java b/backend/src/main/java/io/metersphere/performance/service/ReportService.java index b3624cdca7..6dd37cea0e 100644 --- a/backend/src/main/java/io/metersphere/performance/service/ReportService.java +++ b/backend/src/main/java/io/metersphere/performance/service/ReportService.java @@ -14,6 +14,7 @@ import io.metersphere.controller.request.OrderRequest; import io.metersphere.dto.LogDetailDTO; import io.metersphere.dto.ReportDTO; import io.metersphere.performance.base.*; +import io.metersphere.performance.controller.request.DeleteReportRequest; import io.metersphere.performance.controller.request.ReportRequest; import io.metersphere.performance.engine.Engine; import io.metersphere.performance.engine.EngineFactory; @@ -72,18 +73,22 @@ public class ReportService { LogUtil.info("Delete report started, report ID: %s" + reportId); - final Engine engine = EngineFactory.createEngine(loadTest); - if (engine == null) { - MSException.throwException(String.format("Delete report fail. create engine fail,report ID:%s", reportId)); - } + try { + final Engine engine = EngineFactory.createEngine(loadTest); + if (engine == null) { + MSException.throwException(String.format("Delete report fail. create engine fail,report ID:%s", reportId)); + } - String reportStatus = loadTestReport.getStatus(); - boolean isRunning = StringUtils.equals(reportStatus, PerformanceTestStatus.Running.name()); - boolean isStarting = StringUtils.equals(reportStatus, PerformanceTestStatus.Starting.name()); - boolean isError = StringUtils.equals(reportStatus, PerformanceTestStatus.Error.name()); - if (isRunning || isStarting || isError) { - LogUtil.info("Start stop engine, report status: %s" + reportStatus); - stopEngine(loadTest, engine); + String reportStatus = loadTestReport.getStatus(); + boolean isRunning = StringUtils.equals(reportStatus, PerformanceTestStatus.Running.name()); + boolean isStarting = StringUtils.equals(reportStatus, PerformanceTestStatus.Starting.name()); + boolean isError = StringUtils.equals(reportStatus, PerformanceTestStatus.Error.name()); + if (isRunning || isStarting || isError) { + LogUtil.info("Start stop engine, report status: %s" + reportStatus); + stopEngine(loadTest, engine); + } + } catch (Exception e) { + LogUtil.error(e.getMessage(), e); } // delete load_test_report_result @@ -246,4 +251,9 @@ public class ReportService { report.setStatus(status); loadTestReportMapper.updateByPrimaryKeySelective(report); } + + public void deleteReportBatch(DeleteReportRequest reportRequest) { + List ids = reportRequest.getIds(); + ids.forEach(this::deleteReport); + } } diff --git a/frontend/src/business/components/performance/report/PerformanceTestReport.vue b/frontend/src/business/components/performance/report/PerformanceTestReport.vue index 3111cd30c9..569eca7028 100644 --- a/frontend/src/business/components/performance/report/PerformanceTestReport.vue +++ b/frontend/src/business/components/performance/report/PerformanceTestReport.vue @@ -9,9 +9,18 @@ + + + + { + this.$set(row, "showMore", true); + }) + } + }, + handleSelectAll(selection) { + if (selection.length > 0) { + if (selection.length === 1) { + this.selectRows.add(selection[0]); + } else { + this.tableData.forEach(item => { + this.$set(item, "showMore", true); + this.selectRows.add(item); + }); + } + } else { + this.selectRows.clear(); + this.tableData.forEach(row => { + this.$set(row, "showMore", false); + }) + } + }, + handleBatchDelete() { + this.$alert(this.$t('report.delete_batch_confirm') + "?", '', { + confirmButtonText: this.$t('commons.confirm'), + callback: (action) => { + if (action === 'confirm') { + let ids = Array.from(this.selectRows).map(row => row.id); + this.result = this.$post('/performance/report/batch/delete', {ids: ids}, () => { + this.selectRows.clear(); + this.$success(this.$t('commons.delete_success')); + this.search(); + // 发送广播,刷新 head 上的最新列表 + PerformanceEvent.$emit(LIST_CHANGE); + }); + } + } + }); + } } } diff --git a/frontend/src/i18n/en-US.js b/frontend/src/i18n/en-US.js index 98e9550fcf..929932242f 100644 --- a/frontend/src/i18n/en-US.js +++ b/frontend/src/i18n/en-US.js @@ -298,6 +298,8 @@ export default { force_stop_btn: 'Terminating', stop_btn: 'Graceful shutdown', not_exist: "Test report does not exist", + batch_delete: "Delete reports in bulk", + delete_batch_confirm: 'Confirm batch delete report', }, load_test: { same_project_test: 'Only tests within the same project can be run', diff --git a/frontend/src/i18n/zh-CN.js b/frontend/src/i18n/zh-CN.js index 3c597f04c9..a4fe3512a3 100644 --- a/frontend/src/i18n/zh-CN.js +++ b/frontend/src/i18n/zh-CN.js @@ -298,6 +298,8 @@ export default { force_stop_btn: '强制停止', stop_btn: '停止', not_exist: "测试报告不存在", + batch_delete: "批量删除报告", + delete_batch_confirm: '确认批量删除报告', }, load_test: { same_project_test: '只能运行同一项目内的测试', diff --git a/frontend/src/i18n/zh-TW.js b/frontend/src/i18n/zh-TW.js index 66ac7798ec..985a4e65bf 100644 --- a/frontend/src/i18n/zh-TW.js +++ b/frontend/src/i18n/zh-TW.js @@ -297,6 +297,8 @@ export default { force_stop_btn: '強制停止', stop_btn: '停止', not_exist: "測試報告不存在", + batch_delete: "批量刪除報告", + delete_batch_confirm: '確認批量刪除報告', }, load_test: { same_project_test: '只能運行同一項目內的測試',