diff --git a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java index 2d2b78e48f..efa306fe41 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java @@ -478,6 +478,14 @@ public class ApiScenarioReportService { structureExample.createCriteria().andReportIdEqualTo(request.getId()); apiScenarioReportStructureMapper.deleteByExample(structureExample); + ApiDefinitionExecResultExample definitionExecResultExample = new ApiDefinitionExecResultExample(); + definitionExecResultExample.createCriteria().andIdEqualTo(request.getId()); + definitionExecResultMapper.deleteByExample(definitionExecResultExample); + + ApiDefinitionExecResultExample execResultExample = new ApiDefinitionExecResultExample(); + execResultExample.createCriteria().andIntegratedReportIdEqualTo(request.getId()); + definitionExecResultMapper.deleteByExample(execResultExample); + // 补充逻辑,如果是集成报告则把零时报告全部删除 ApiScenarioReport report = apiScenarioReportMapper.selectByPrimaryKey(request.getId()); if (report != null && StringUtils.isNotEmpty(report.getScenarioId())) { @@ -501,23 +509,42 @@ public class ApiScenarioReportService { ApiScenarioReportStructureExample structureExample = new ApiScenarioReportStructureExample(); structureExample.createCriteria().andReportIdEqualTo(id); apiScenarioReportStructureMapper.deleteByExample(structureExample); + + ApiDefinitionExecResultExample definitionExecResultExample = new ApiDefinitionExecResultExample(); + definitionExecResultExample.createCriteria().andIdEqualTo(id); + definitionExecResultMapper.deleteByExample(definitionExecResultExample); + + ApiDefinitionExecResultExample execResultExample = new ApiDefinitionExecResultExample(); + execResultExample.createCriteria().andIntegratedReportIdEqualTo(id); + definitionExecResultMapper.deleteByExample(execResultExample); + } public void deleteByIds(List ids) { - ApiScenarioReportExample example = new ApiScenarioReportExample(); - example.createCriteria().andIdIn(ids); - ApiScenarioReportDetailExample detailExample = new ApiScenarioReportDetailExample(); - detailExample.createCriteria().andReportIdIn(ids); - apiScenarioReportDetailMapper.deleteByExample(detailExample); - apiScenarioReportMapper.deleteByExample(example); + if (CollectionUtils.isNotEmpty(ids)) { + ApiScenarioReportExample example = new ApiScenarioReportExample(); + example.createCriteria().andIdIn(ids); + ApiScenarioReportDetailExample detailExample = new ApiScenarioReportDetailExample(); + detailExample.createCriteria().andReportIdIn(ids); + apiScenarioReportDetailMapper.deleteByExample(detailExample); + apiScenarioReportMapper.deleteByExample(example); - ApiScenarioReportResultExample reportResultExample = new ApiScenarioReportResultExample(); - reportResultExample.createCriteria().andReportIdIn(ids); - apiScenarioReportResultMapper.deleteByExample(reportResultExample); + ApiScenarioReportResultExample reportResultExample = new ApiScenarioReportResultExample(); + reportResultExample.createCriteria().andReportIdIn(ids); + apiScenarioReportResultMapper.deleteByExample(reportResultExample); - ApiScenarioReportStructureExample structureExample = new ApiScenarioReportStructureExample(); - structureExample.createCriteria().andReportIdIn(ids); - apiScenarioReportStructureMapper.deleteByExample(structureExample); + ApiScenarioReportStructureExample structureExample = new ApiScenarioReportStructureExample(); + structureExample.createCriteria().andReportIdIn(ids); + apiScenarioReportStructureMapper.deleteByExample(structureExample); + + ApiDefinitionExecResultExample definitionExecResultExample = new ApiDefinitionExecResultExample(); + definitionExecResultExample.createCriteria().andIdIn(ids); + definitionExecResultMapper.deleteByExample(definitionExecResultExample); + + ApiDefinitionExecResultExample execResultExample = new ApiDefinitionExecResultExample(); + execResultExample.createCriteria().andIntegratedReportIdIn(ids); + definitionExecResultMapper.deleteByExample(execResultExample); + } } public void deleteAPIReportBatch(APIReportBatchRequest reportRequest) { @@ -571,6 +598,14 @@ public class ApiScenarioReportService { structureExample.createCriteria().andReportIdIn(handleIdList); apiScenarioReportStructureMapper.deleteByExample(structureExample); + ApiDefinitionExecResultExample definitionExecResultExample = new ApiDefinitionExecResultExample(); + definitionExecResultExample.createCriteria().andIdIn(handleIdList); + definitionExecResultMapper.deleteByExample(definitionExecResultExample); + + ApiDefinitionExecResultExample execResultExample = new ApiDefinitionExecResultExample(); + execResultExample.createCriteria().andIntegratedReportIdIn(handleIdList); + definitionExecResultMapper.deleteByExample(execResultExample); + //转存剩余的数据 ids = otherIdList; } @@ -592,6 +627,13 @@ public class ApiScenarioReportService { structureExample.createCriteria().andReportIdIn(ids); apiScenarioReportStructureMapper.deleteByExample(structureExample); + ApiDefinitionExecResultExample definitionExecResultExample = new ApiDefinitionExecResultExample(); + definitionExecResultExample.createCriteria().andIdIn(ids); + definitionExecResultMapper.deleteByExample(definitionExecResultExample); + + ApiDefinitionExecResultExample execResultExample = new ApiDefinitionExecResultExample(); + execResultExample.createCriteria().andIntegratedReportIdIn(handleIdList); + definitionExecResultMapper.deleteByExample(execResultExample); } } diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReportMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReportMapper.xml index c888aa69ec..cb166de194 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReportMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReportMapper.xml @@ -183,11 +183,36 @@ select t1.id, t1.project_id, t1.name,t1.case_status, t1.api_definition_id, t1.priority, t1.description, t1.create_user_id, t1.update_user_id, t1.create_time, t1.update_time, t1.num, - a.module_id, a.path, a.protocol, t1.tags,t1.status,t2.STATUS AS execResult, t1.last_result_id as lastResultId, project.name as project_name, + a.module_id, a.path, a.protocol, t1.tags,t1.status,t2.STATUS AS execResult, t2.id as lastResultId, project.name as project_name, t1.delete_time, deleteUser.name AS deleteUser,CONCAT(FORMAT(SUM(IF (t2.`status`='success',1,0))/COUNT(t2.id)*100,2),'%') passRate, project_version.name as version_name from api_test_case t1 diff --git a/frontend/src/business/components/api/definition/components/list/ApiCaseSimpleList.vue b/frontend/src/business/components/api/definition/components/list/ApiCaseSimpleList.vue index 63a2874ef4..6c31ec8abe 100644 --- a/frontend/src/business/components/api/definition/components/list/ApiCaseSimpleList.vue +++ b/frontend/src/business/components/api/definition/components/list/ApiCaseSimpleList.vue @@ -108,9 +108,15 @@ min-width="120px" :label="$t('test_track.plan_view.execute_result')"> @@ -406,6 +412,7 @@ export default { statusFilters: [ {text: this.$t('api_test.automation.success'), value: 'success'}, {text: this.$t('api_test.automation.fail'), value: 'error'}, + {text: this.$t('report.stop_btn'), value: 'STOP'}, {text: this.$t('api_test.home_page.detail_card.unexecute'), value: ''}, {text: this.$t('commons.testing'), value: 'Running'} ], @@ -549,7 +556,7 @@ export default { this.$refs.taskCenter.openHistory(row.id); }, getExecResult(apiCase) { - if (apiCase.lastResultId) { + if (apiCase.lastResultId && apiCase.execResult) { let url = "/api/definition/report/get/" + apiCase.lastResultId; this.$get(url, response => { if (response.data) { @@ -560,6 +567,8 @@ export default { } catch (error) { this.resVisible = true; } + } else { + this.$warning(this.$t('commons.report_delete')); } }); } @@ -574,6 +583,8 @@ export default { return "ms-running"; case "errorReportResult": return "ms-error-report-result"; + case "STOP": + return "stop"; default: return "ms-unexecute"; } @@ -588,6 +599,8 @@ export default { return this.$t('commons.testing'); case "errorReportResult": return this.$t('error_report_library.option.name'); + case "STOP": + return this.$t('report.stop_btn'); default: return this.$t('api_test.home_page.detail_card.unexecute'); }