feat: 性能测试报告批量删除

This commit is contained in:
shiziyuan9527 2020-09-01 16:22:58 +08:00
parent 4fa973eff1
commit 1a9fcf0d7b
7 changed files with 122 additions and 12 deletions

View File

@ -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);
}
}

View File

@ -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<String> ids;
}

View File

@ -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 failreport ID%s", reportId));
}
try {
final Engine engine = EngineFactory.createEngine(loadTest);
if (engine == null) {
MSException.throwException(String.format("Delete report fail. create engine failreport 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<String> ids = reportRequest.getIds();
ids.forEach(this::deleteReport);
}
}

View File

@ -9,9 +9,18 @@
</template>
<el-table border :data="tableData" class="adjust-table test-content"
@select-all="handleSelectAll"
@select="handleSelect"
@sort-change="sort"
@filter-change="filter"
>
<el-table-column
type="selection"/>
<el-table-column width="40" :resizable="false" align="center">
<template v-slot:default="scope">
<show-more-btn :is-show="scope.row.showMore" :buttons="buttons" :size="selectRows.size"/>
</template>
</el-table-column>
<el-table-column
prop="name"
:label="$t('commons.name')"
@ -89,13 +98,19 @@ import ReportTriggerModeItem from "../../common/tableItem/ReportTriggerModeItem"
import {REPORT_CONFIGS} from "../../common/components/search/search-components";
import MsTableHeader from "../../common/components/MsTableHeader";
import {LIST_CHANGE, PerformanceEvent} from "@/business/components/common/head/ListEvent";
import ShowMoreBtn from "../../track/case/components/ShowMoreBtn";
export default {
name: "PerformanceTestReport",
components: {
MsTableHeader,
ReportTriggerModeItem,
MsTableOperatorButton, MsPerformanceReportStatus, MsTablePagination, MsContainer, MsMainContainer
MsTableOperatorButton,
MsPerformanceReportStatus,
MsTablePagination,
MsContainer,
MsMainContainer,
ShowMoreBtn,
},
created: function () {
this.initTableData();
@ -128,6 +143,12 @@ export default {
{text: '定时任务', value: 'SCHEDULE'},
{text: 'API', value: 'API'}
],
buttons: [
{
name: this.$t('report.batch_delete'), handleClick: this.handleBatchDelete
}
],
selectRows: new Set(),
}
},
watch: {
@ -194,6 +215,60 @@ export default {
_filter(filters, this.condition);
this.initTableData();
},
handleSelect(selection, row) {
if (this.selectRows.has(row)) {
this.$set(row, "showMore", false);
this.selectRows.delete(row);
} else {
this.$set(row, "showMore", true);
this.selectRows.add(row);
}
let arr = Array.from(this.selectRows);
// 1
if (this.selectRows.size === 1) {
this.$set(arr[0], "showMore", false);
} else if (this.selectRows.size === 2) {
arr.forEach(row => {
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);
});
}
}
});
}
}
}
</script>

View File

@ -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',

View File

@ -298,6 +298,8 @@ export default {
force_stop_btn: '强制停止',
stop_btn: '停止',
not_exist: "测试报告不存在",
batch_delete: "批量删除报告",
delete_batch_confirm: '确认批量删除报告',
},
load_test: {
same_project_test: '只能运行同一项目内的测试',

View File

@ -297,6 +297,8 @@ export default {
force_stop_btn: '強制停止',
stop_btn: '停止',
not_exist: "測試報告不存在",
batch_delete: "批量刪除報告",
delete_batch_confirm: '確認批量刪除報告',
},
load_test: {
same_project_test: '只能運行同一項目內的測試',