feat(测试计划): 测试计划组报告总结一键生成内容新增子计划信息

--task=1016926 --user=王旭 【Bug转需求】[测试计划]github#33641生成报告统计的缺陷个数错误,应该用缺陷条数,而不是用关联用例加和-后端 https://www.tapd.cn/55049933/s/1603574
This commit is contained in:
WangXu10 2024-11-01 15:13:21 +08:00 committed by Craftsman
parent 6313afe427
commit fcee7fb217
6 changed files with 1382 additions and 1336 deletions

View File

@ -1,11 +1,14 @@
package io.metersphere.plan.dto.response;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.metersphere.plan.dto.CaseCount;
import io.metersphere.system.serializer.CustomRateSerializer;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.List;
@Data
public class TestPlanReportDetailResponse {
@ -91,4 +94,8 @@ public class TestPlanReportDetailResponse {
*/
@Schema(description = "报告是否默认布局")
private Boolean defaultLayout;
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@Schema(description = "计划组子计划数据信息")
private List<TestPlanReportDetailResponse> children;
}

View File

@ -33,14 +33,30 @@
</select>
<select id="countBug" resultType="io.metersphere.plan.dto.ReportBugSumDTO">
select 'FUNCTIONAL' as caseType, ifnull(sum(tprfc.function_case_bug_count), 0) as bugCount from test_plan_report_function_case tprfc
where tprfc.test_plan_report_id = #{id}
union
select 'API' as caseType, ifnull(sum(tprac.api_case_bug_count), 0) as bugCount from test_plan_report_api_case tprac
where tprac.test_plan_report_id = #{id}
union
select 'SCENARIO' as caseType, ifnull(sum(tpras.api_scenario_bug_count), 0) as bugCount from test_plan_report_api_scenario tpras
where tpras.test_plan_report_id = #{id}
SELECT
'FUNCTIONAL' AS caseType,
count( DISTINCT brc.bug_id ) AS bugCount
FROM
bug_relation_case brc
INNER JOIN test_plan_report_function_case tprfc ON brc.test_plan_case_id = tprfc.test_plan_function_case_id
WHERE
tprfc.test_plan_report_id = #{id} UNION
SELECT
'API' AS caseType,
count( DISTINCT brc.bug_id ) AS bugCount
FROM
bug_relation_case brc
INNER JOIN test_plan_report_api_case tprac ON brc.test_plan_case_id = tprac.test_plan_api_case_id
WHERE
tprac.test_plan_report_id = #{id} UNION
SELECT
'SCENARIO' AS caseType,
count( DISTINCT brc.bug_id ) AS bugCount
FROM
bug_relation_case brc
INNER JOIN test_plan_report_api_scenario tpras ON brc.test_plan_case_id = tpras.test_plan_api_scenario_id
WHERE
tpras.test_plan_report_id = #{id}
</select>
<select id="countPlanBug" resultType="io.metersphere.plan.dto.ReportBugCountDTO">

View File

@ -67,4 +67,6 @@ public interface ExtTestPlanReportMapper {
List<ReportDTO> getReportsByIds(@Param("ids") List<String> ids);
void deleteGroupReport(@Param("id") String id);
List<TestPlanReport> getChildrenReport(@Param("reportId") String reportId);
}

View File

@ -137,7 +137,7 @@
tpr.result_status,
tpr.pass_rate,
tpr.pass_threshold,
(tprs.functional_case_count + tprs.api_case_count + tprs.api_scenario_count + tprs.bug_count) as caseTotal,
(tprs.functional_case_count + tprs.api_case_count + tprs.api_scenario_count) as caseTotal,
tpr.create_time,
tpr.deleted
@ -471,4 +471,9 @@
</when>
</choose>
</sql>
<select id="getChildrenReport" resultType="io.metersphere.plan.domain.TestPlanReport">
select id from test_plan_report where parent_id = #{reportId} and id != #{reportId}
</select>
</mapper>

View File

@ -780,6 +780,17 @@ public class TestPlanReportService {
planReportDetail.setApiCaseCount(reportSummary.getApiExecuteResult() == null ? CaseCount.builder().build() : JSON.parseObject(new String(reportSummary.getApiExecuteResult()), CaseCount.class));
planReportDetail.setApiScenarioCount(reportSummary.getScenarioExecuteResult() == null ? CaseCount.builder().build() : JSON.parseObject(new String(reportSummary.getScenarioExecuteResult()), CaseCount.class));
planReportDetail.setExecuteCount(reportSummary.getExecuteResult() == null ? CaseCount.builder().build() : JSON.parseObject(new String(reportSummary.getExecuteResult()), CaseCount.class));
//如果是计划组需要获取每条子计划数据
List<TestPlanReport> testPlans = extTestPlanReportMapper.getChildrenReport(reportId);
if (CollectionUtils.isNotEmpty(testPlans)) {
List<TestPlanReportDetailResponse> children = new ArrayList<>();
testPlans.forEach(item -> {
TestPlanReportDetailResponse report = getReport(item.getId());
children.add(report);
});
planReportDetail.setChildren(children);
}
return planReportDetail;
}
@ -1253,6 +1264,7 @@ public class TestPlanReportService {
/**
* 获取测试点集合
*
* @param collectionIds 测试点ID集合
* @return 测试点集合
*/
@ -1278,6 +1290,7 @@ public class TestPlanReportService {
/**
* 计划报告测试集列表
*
* @param request 请求参数
* @param caseType 用例类型
* @return 测试集列表
@ -1285,9 +1298,11 @@ public class TestPlanReportService {
public List<TestPlanReportDetailCollectionResponse> listReportCollection(TestPlanReportDetailPageRequest request, String caseType) {
List<TestPlanReportDetailCollectionResponse> collections;
switch (caseType) {
case CollectionQueryType.FUNCTIONAL -> collections = extTestPlanReportFunctionalCaseMapper.listCollection(request);
case CollectionQueryType.FUNCTIONAL ->
collections = extTestPlanReportFunctionalCaseMapper.listCollection(request);
case CollectionQueryType.API -> collections = extTestPlanReportApiCaseMapper.listCollection(request);
case CollectionQueryType.SCENARIO -> collections = extTestPlanReportApiScenarioMapper.listCollection(request);
case CollectionQueryType.SCENARIO ->
collections = extTestPlanReportApiScenarioMapper.listCollection(request);
default -> collections = new ArrayList<>();
}
collections.sort(Comparator.comparing(TestPlanReportDetailCollectionResponse::getPos));

View File

@ -296,6 +296,7 @@ public class TestPlanReportControllerTests extends BaseTest {
@Order(14)
void testGetReportSuccess() throws Exception {
this.requestGet(GET_PLAN_REPORT + "/" + GEN_REPORT_ID);
this.requestGet(GET_PLAN_REPORT + "/" + "test-plan-report-id-5");
}
@Test