feat(接口测试): 用例集合报告清理同步清理用例结果

This commit is contained in:
fit2-zhao 2022-02-16 16:37:55 +08:00 committed by fit2-zhao
parent 6ce7f5b870
commit 91a9901533
4 changed files with 109 additions and 26 deletions

View File

@ -478,6 +478,14 @@ public class ApiScenarioReportService {
structureExample.createCriteria().andReportIdEqualTo(request.getId()); structureExample.createCriteria().andReportIdEqualTo(request.getId());
apiScenarioReportStructureMapper.deleteByExample(structureExample); 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()); ApiScenarioReport report = apiScenarioReportMapper.selectByPrimaryKey(request.getId());
if (report != null && StringUtils.isNotEmpty(report.getScenarioId())) { if (report != null && StringUtils.isNotEmpty(report.getScenarioId())) {
@ -501,23 +509,42 @@ public class ApiScenarioReportService {
ApiScenarioReportStructureExample structureExample = new ApiScenarioReportStructureExample(); ApiScenarioReportStructureExample structureExample = new ApiScenarioReportStructureExample();
structureExample.createCriteria().andReportIdEqualTo(id); structureExample.createCriteria().andReportIdEqualTo(id);
apiScenarioReportStructureMapper.deleteByExample(structureExample); 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<String> ids) { public void deleteByIds(List<String> ids) {
ApiScenarioReportExample example = new ApiScenarioReportExample(); if (CollectionUtils.isNotEmpty(ids)) {
example.createCriteria().andIdIn(ids); ApiScenarioReportExample example = new ApiScenarioReportExample();
ApiScenarioReportDetailExample detailExample = new ApiScenarioReportDetailExample(); example.createCriteria().andIdIn(ids);
detailExample.createCriteria().andReportIdIn(ids); ApiScenarioReportDetailExample detailExample = new ApiScenarioReportDetailExample();
apiScenarioReportDetailMapper.deleteByExample(detailExample); detailExample.createCriteria().andReportIdIn(ids);
apiScenarioReportMapper.deleteByExample(example); apiScenarioReportDetailMapper.deleteByExample(detailExample);
apiScenarioReportMapper.deleteByExample(example);
ApiScenarioReportResultExample reportResultExample = new ApiScenarioReportResultExample(); ApiScenarioReportResultExample reportResultExample = new ApiScenarioReportResultExample();
reportResultExample.createCriteria().andReportIdIn(ids); reportResultExample.createCriteria().andReportIdIn(ids);
apiScenarioReportResultMapper.deleteByExample(reportResultExample); apiScenarioReportResultMapper.deleteByExample(reportResultExample);
ApiScenarioReportStructureExample structureExample = new ApiScenarioReportStructureExample(); ApiScenarioReportStructureExample structureExample = new ApiScenarioReportStructureExample();
structureExample.createCriteria().andReportIdIn(ids); structureExample.createCriteria().andReportIdIn(ids);
apiScenarioReportStructureMapper.deleteByExample(structureExample); 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) { public void deleteAPIReportBatch(APIReportBatchRequest reportRequest) {
@ -571,6 +598,14 @@ public class ApiScenarioReportService {
structureExample.createCriteria().andReportIdIn(handleIdList); structureExample.createCriteria().andReportIdIn(handleIdList);
apiScenarioReportStructureMapper.deleteByExample(structureExample); 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; ids = otherIdList;
} }
@ -592,6 +627,13 @@ public class ApiScenarioReportService {
structureExample.createCriteria().andReportIdIn(ids); structureExample.createCriteria().andReportIdIn(ids);
apiScenarioReportStructureMapper.deleteByExample(structureExample); 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);
} }
} }

View File

@ -183,11 +183,36 @@
</select> </select>
<select id="idList" resultType="java.lang.String"> <select id="idList" resultType="java.lang.String">
SELECT r.id select r.id from (
FROM api_scenario_report r SELECT s_r.name AS test_name,
LEFT JOIN api_scenario s on r.scenario_id = s.id s_r.end_time,
LEFT JOIN project ON project.id = r.project_id s_r.user_id,
LEFT JOIN user ON user.id = r.user_id s_r.name,
s_r.id,
s_r.project_id,
s_r.create_time,
s_r.update_time,
s_r.status,
s_r.trigger_mode,
s_r.execute_type,
s_r.report_type
FROM api_scenario_report s_r
union
select a_r.name as test_name,
a_r.end_time,
a_r.user_id,
a_r.name,
a_r.id,
a_r.project_id,
a_r.create_time,
a_r.create_time as update_time,
a_r.status,
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
) r
<where> <where>
<if test="request.combine != null"> <if test="request.combine != null">
<include refid="combine"> <include refid="combine">
@ -203,10 +228,7 @@
AND r.user_id = #{request.userId,jdbcType=VARCHAR} AND r.user_id = #{request.userId,jdbcType=VARCHAR}
</if> </if>
<if test="request.projectId != null"> <if test="request.projectId != null">
AND project.id = #{request.projectId} AND r.project_id = #{request.projectId}
</if>
<if test="request.workspaceId != null">
AND project.workspace_id = #{request.workspaceId,jdbcType=VARCHAR}
</if> </if>
<if test="request.filters != null and request.filters.size() > 0"> <if test="request.filters != null and request.filters.size() > 0">
<foreach collection="request.filters.entrySet()" index="key" item="values"> <foreach collection="request.filters.entrySet()" index="key" item="values">
@ -218,6 +240,12 @@
#{value} #{value}
</foreach> </foreach>
</when> </when>
<when test="key=='report_type'">
and r.report_type in
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</when>
<otherwise> <otherwise>
and r.trigger_mode in and r.trigger_mode in
<foreach collection="values" item="value" separator="," open="(" close=")"> <foreach collection="values" item="value" separator="," open="(" close=")">

View File

@ -315,7 +315,7 @@
<select id="listSimple" resultType="io.metersphere.api.dto.definition.ApiTestCaseDTO"> <select id="listSimple" resultType="io.metersphere.api.dto.definition.ApiTestCaseDTO">
select 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, 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 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 from
api_test_case t1 api_test_case t1

View File

@ -108,9 +108,15 @@
min-width="120px" min-width="120px"
:label="$t('test_track.plan_view.execute_result')"> :label="$t('test_track.plan_view.execute_result')">
<template v-slot:default="scope"> <template v-slot:default="scope">
<i class="el-icon-loading ms-running" v-if="scope.row.status === 'Running'"/> <div v-if="scope.row.status === 'Running'">
<el-link @click="getExecResult(scope.row)" <i class="el-icon-loading ms-running"/>
:class="getStatusClass(scope.row.status)">{{ getStatusTitle(scope.row.status) }}</el-link> <el-link :class="getStatusClass(scope.row.status)">
{{ getStatusTitle(scope.row.status) }}
</el-link>
</div>
<el-link v-else @click="getExecResult(scope.row)" :class="getStatusClass(scope.row.execResult)">
{{ getStatusTitle(scope.row.execResult) }}
</el-link>
</template> </template>
</ms-table-column> </ms-table-column>
@ -406,6 +412,7 @@ export default {
statusFilters: [ statusFilters: [
{text: this.$t('api_test.automation.success'), value: 'success'}, {text: this.$t('api_test.automation.success'), value: 'success'},
{text: this.$t('api_test.automation.fail'), value: 'error'}, {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('api_test.home_page.detail_card.unexecute'), value: ''},
{text: this.$t('commons.testing'), value: 'Running'} {text: this.$t('commons.testing'), value: 'Running'}
], ],
@ -549,7 +556,7 @@ export default {
this.$refs.taskCenter.openHistory(row.id); this.$refs.taskCenter.openHistory(row.id);
}, },
getExecResult(apiCase) { getExecResult(apiCase) {
if (apiCase.lastResultId) { if (apiCase.lastResultId && apiCase.execResult) {
let url = "/api/definition/report/get/" + apiCase.lastResultId; let url = "/api/definition/report/get/" + apiCase.lastResultId;
this.$get(url, response => { this.$get(url, response => {
if (response.data) { if (response.data) {
@ -560,6 +567,8 @@ export default {
} catch (error) { } catch (error) {
this.resVisible = true; this.resVisible = true;
} }
} else {
this.$warning(this.$t('commons.report_delete'));
} }
}); });
} }
@ -574,6 +583,8 @@ export default {
return "ms-running"; return "ms-running";
case "errorReportResult": case "errorReportResult":
return "ms-error-report-result"; return "ms-error-report-result";
case "STOP":
return "stop";
default: default:
return "ms-unexecute"; return "ms-unexecute";
} }
@ -588,6 +599,8 @@ export default {
return this.$t('commons.testing'); return this.$t('commons.testing');
case "errorReportResult": case "errorReportResult":
return this.$t('error_report_library.option.name'); return this.$t('error_report_library.option.name');
case "STOP":
return this.$t('report.stop_btn');
default: default:
return this.$t('api_test.home_page.detail_card.unexecute'); return this.$t('api_test.home_page.detail_card.unexecute');
} }