fix(接口测试): 修复接口测试报告全选删除时删除所有的场景和接口报告的问题

--bug=1015725 --user=宋天阳
【接口测试】接口测试报告-全选接口报告-批量删除,会把场景报告也都删掉,全选场景报告也是
https://www.tapd.cn/55049933/s/1221535
This commit is contained in:
song-tianyang 2022-08-10 14:27:28 +08:00 committed by 建国
parent 2562648a05
commit 5779930f56
5 changed files with 41 additions and 14 deletions

View File

@ -23,5 +23,10 @@ public class QueryAPIReportRequest {
private Map<String, List<String>> filters;
private Map<String, Object> combine;
/**
* 查询哪种用例的报告 SCENARIO/API
*/
private String caseType;
private String limit;
}

View File

@ -182,7 +182,12 @@ public class ApiScenarioReportService {
public List<String> idList(QueryAPIReportRequest request) {
request = this.initRequest(request);
request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders()));
return extApiScenarioReportMapper.idList(request);
//检查必填参数caseType
if (StringUtils.equalsAny(request.getCaseType(), ReportTypeConstants.API.name(), ReportTypeConstants.SCENARIO.name())) {
return extApiScenarioReportMapper.idList(request);
} else {
return new ArrayList<>(0);
}
}
private void checkNameExist(APIScenarioReportResult request) {
@ -271,7 +276,7 @@ public class ApiScenarioReportService {
}
public ApiScenarioReport updatePlanCase(ResultDTO dto) {
String status = getStatus(dto);
String status = getStatus(dto);
ApiScenarioReport report = editReport(dto.getReportType(), dto.getReportId(), status, dto.getRunMode());
TestPlanApiScenario testPlanApiScenario = testPlanApiScenarioMapper.selectByPrimaryKey(dto.getTestId());
if (testPlanApiScenario != null) {
@ -648,13 +653,19 @@ public class ApiScenarioReportService {
}
public void deleteAPIReportBatch(APIReportBatchRequest reportRequest) {
List<String> ids = getIdsByDeleteBatchRequest(reportRequest);
ids = batchDeleteReportResource(reportRequest, ids, true);
if (reportRequest.getIsUi()) {
//ui报告对应的用例类型也是scenario
reportRequest.setCaseType(ReportTypeConstants.SCENARIO.name());
}
if (StringUtils.isNotBlank(reportRequest.getCaseType())) {
List<String> ids = getIdsByDeleteBatchRequest(reportRequest);
ids = batchDeleteReportResource(reportRequest, ids, true);
//处理最后剩余的数据
if (!ids.isEmpty()) {
deleteScenarioReportByIds(ids);
deleteApiDefinitionResultByIds(ids);
//处理报告关联数据
if (!ids.isEmpty()) {
deleteScenarioReportByIds(ids);
deleteApiDefinitionResultByIds(ids);
}
}
}
@ -873,7 +884,6 @@ public class ApiScenarioReportService {
long errorReportResultSize = dto.getRequestResults().stream().filter(requestResult ->
StringUtils.equalsIgnoreCase(requestResult.getStatus(), ExecuteResult.ERROR_REPORT_RESULT.toString())).count();
String status = dto.getRequestResults().isEmpty() ? ExecuteResult.UN_EXECUTE.toString() : ScenarioStatus.Success.name();
if (errorSize > 0) {
status = ScenarioStatus.Error.name();

View File

@ -241,6 +241,7 @@
<select id="idList" resultType="java.lang.String">
select r.id from (
<if test="request.caseType == 'SCENARIO'">
SELECT s_r.name AS test_name,
s_r.end_time,
s_r.user_id,
@ -253,9 +254,10 @@
s_r.trigger_mode,
s_r.execute_type,
s_r.report_type
FROM api_scenario_report s_r
union all
select a_r.name as test_name,
FROM api_scenario_report s_r
</if>
<if test="request.caseType == 'API'">
select a_r.name as test_name,
a_r.end_time,
a_r.user_id,
a_r.name,
@ -267,8 +269,9 @@
a_r.trigger_mode,
'Saved' as execute_type,
'API_INDEPENDENT' as report_type
from api_definition_exec_result a_r
where a_r.integrated_report_id is null or a_r.integrated_report_id = 'null'
from api_definition_exec_result a_r
where a_r.integrated_report_id is null or a_r.integrated_report_id = 'null'
</if>
) r
<where>
<if test="request.combine != null">

View File

@ -1,6 +1,14 @@
package io.metersphere.commons.constants;
public enum ReportTypeConstants {
/**
* 所有场景类型包括接口场景UI场景
*/
SCENARIO,
/**
* 所有接口类型包括接口接口用例
*/
API,
SCENARIO_INTEGRATED,
SCENARIO_INDEPENDENT,
API_INTEGRATED,

View File

@ -373,6 +373,7 @@ export default {
sendParam.selectAllDate = this.isSelectAllDate;
sendParam.unSelectIds = this.unSelection;
sendParam = Object.assign(sendParam, this.condition);
sendParam.caseType = this.trashActiveDom === 'right' ? 'API' : 'SCENARIO';
this.$post('/api/scenario/report/batch/delete', sendParam, () => {
this.selectRows.clear();
this.$success(this.$t('commons.delete_success'));