refactor(测试计划): 优化部分返回值

This commit is contained in:
WangXu10 2024-05-31 17:12:12 +08:00 committed by Craftsman
parent c2db62cbd5
commit 52a1da156d
15 changed files with 61 additions and 10 deletions

View File

@ -28,4 +28,10 @@ public class CaseRelateBugDTO implements Serializable {
@Schema(description = "用例id")
private String caseId;
@Schema(description = "num")
private String num;
@Schema(description = "status")
private String status;
}

View File

@ -261,6 +261,8 @@
<select id="getBugCountByIds" resultType="io.metersphere.bug.dto.CaseRelateBugDTO">
SELECT
bug.id as bugId,
bug.num as num,
bug.status as status,
bug.title as title,
bug_relation_case.case_type as caseType,
bug_relation_case.case_id as caseId,

View File

@ -144,7 +144,7 @@ public class FunctionalCaseController {
public Pager<List<FunctionalCasePageDTO>> getFunctionalCasePage(@Validated @RequestBody FunctionalCasePageRequest request) {
Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize(),
StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "pos desc");
return PageUtils.setPageInfo(page, functionalCaseService.getFunctionalCasePage(request, false, false));
return PageUtils.setPageInfo(page, functionalCaseService.getFunctionalCasePage(request, false, true));
}
@PostMapping("/module/count")

View File

@ -57,7 +57,7 @@ public class FunctionalCaseRelationshipController {
public Pager<List<FunctionalCasePageDTO>> getFunctionalCasePage(@Validated @RequestBody RelationshipPageRequest request) {
Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize(),
StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "pos desc");
return PageUtils.setPageInfo(page, functionalCaseService.getFunctionalCasePage(request, false, false));
return PageUtils.setPageInfo(page, functionalCaseService.getFunctionalCasePage(request, false, true));
}
@PostMapping("/add")

View File

@ -43,7 +43,7 @@ public class FunctionalCaseTrashController {
public Pager<List<FunctionalCasePageDTO>> getFunctionalCasePage(@Validated @RequestBody FunctionalCasePageRequest request) {
Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize(),
StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "delete_time desc, id asc");
return PageUtils.setPageInfo(page, functionalCaseService.getFunctionalCasePage(request, true, false));
return PageUtils.setPageInfo(page, functionalCaseService.getFunctionalCasePage(request, true, true));
}
@PostMapping("/module/count")

View File

@ -29,4 +29,6 @@ public class TestPlanBugPageResponse {
private String createUser;
@Schema(description = "创建时间")
private Long createTime;
@Schema(description = "测试计划id")
private String testPlanId;
}

View File

@ -53,4 +53,6 @@ public class TestPlanStatisticsResponse {
private Integer apiCaseCount = 0;
@Schema(description = "接口场景数量")
private Integer apiScenarioCount = 0;
@Schema(description = "缺陷数量")
private Integer bugCount = 0;
}

View File

@ -23,4 +23,7 @@ public interface ExtTestPlanBugMapper {
* @return 用例集合
*/
List<TestPlanBugCaseDTO> getBugRelatedCase(@Param("ids") List<String> bugIds, @Param("planId") String planId);
List<TestPlanBugPageResponse> countBugByIds(@Param("planIds") List<String> planIds);
}

View File

@ -24,6 +24,23 @@
group by brc.bug_id
</select>
<select id="countBugByIds" resultType="io.metersphere.plan.dto.response.TestPlanBugPageResponse">
select b.id as id, b.num as num, b.title as title, bc.description content, b.handle_user handleUser, b.status as status, b.create_user createUser, b.create_time createTime,brc.test_plan_id testPlanId
from bug_relation_case brc join bug b on brc.bug_id = b.id
left join bug_content bc on b.id = bc.bug_id
<where>
<if test="planIds != null and planIds.size() > 0">
and brc.test_plan_id IN
<foreach collection="planIds" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</if>
</where>
group by brc.bug_id
</select>
<select id="getBugRelatedCase" resultType="io.metersphere.plan.dto.TestPlanBugCaseDTO">
select brc.test_plan_case_id as id, fc.num as num, brc.bug_id as bugId, fc.name as name
from bug_relation_case brc

View File

@ -119,7 +119,6 @@
LEFT JOIN project_version ON functional_case.version_id = project_version.id
where functional_case.deleted = #{deleted}
and test_plan_functional_case.test_plan_id = #{request.testPlanId}
and functional_case.project_id = #{request.projectId}
<include refid="queryWhereCondition"/>
order by
<if test="sort != null and sort != ''">

View File

@ -7,6 +7,7 @@ import io.metersphere.bug.dto.CaseRelateBugDTO;
import io.metersphere.bug.mapper.BugMapper;
import io.metersphere.bug.mapper.BugRelationCaseMapper;
import io.metersphere.bug.mapper.ExtBugRelateCaseMapper;
import io.metersphere.bug.service.BugStatusService;
import io.metersphere.dto.BugProviderDTO;
import io.metersphere.functional.constants.CaseFileSourceType;
import io.metersphere.functional.domain.FunctionalCase;
@ -24,6 +25,7 @@ import io.metersphere.plan.dto.TestPlanResourceAssociationParam;
import io.metersphere.plan.dto.request.*;
import io.metersphere.plan.dto.response.*;
import io.metersphere.plan.mapper.*;
import io.metersphere.plugin.platform.dto.SelectOption;
import io.metersphere.project.domain.Project;
import io.metersphere.project.dto.ModuleCountDTO;
import io.metersphere.provider.BaseAssociateBugProvider;
@ -103,6 +105,8 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService {
private FunctionalCaseAttachmentService functionalCaseAttachmentService;
@Resource
private TestPlanSendNoticeService testPlanSendNoticeService;
@Resource
private BugStatusService bugStatusService;
@Resource
private ExtUserMapper extUserMapper;
@ -195,6 +199,8 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService {
Set<String> userIds = extractUserIds(functionalCaseLists);
List<String> relateIds = functionalCaseLists.stream().map(TestPlanCasePageResponse::getId).collect(Collectors.toList());
Map<String, List<CaseRelateBugDTO>> bugListMap = getBugData(relateIds, functionalCaseLists.get(0).getTestPlanId());
List<SelectOption> statusOption = bugStatusService.getHeaderStatusOption(projectId);
Map<String, String> statusMap = statusOption.stream().collect(Collectors.toMap(SelectOption::getValue, SelectOption::getText));
Map<String, String> userMap = userLoginService.getUserNameMap(new ArrayList<>(userIds));
functionalCaseLists.forEach(testPlanCasePageResponse -> {
testPlanCasePageResponse.setCustomFields(collect.get(testPlanCasePageResponse.getCaseId()));
@ -202,7 +208,7 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService {
testPlanCasePageResponse.setExecuteUserName(userMap.get(testPlanCasePageResponse.getExecuteUser()));
if (bugListMap.containsKey(testPlanCasePageResponse.getCaseId())) {
List<CaseRelateBugDTO> bugDTOList = bugListMap.get(testPlanCasePageResponse.getCaseId());
testPlanCasePageResponse.setBugList(bugDTOList);
testPlanCasePageResponse.setBugList(handleStatus(bugDTOList, statusMap));
testPlanCasePageResponse.setBugCount(bugDTOList.size());
}
});
@ -210,6 +216,13 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService {
}
private List<CaseRelateBugDTO> handleStatus(List<CaseRelateBugDTO> bugDTOList, Map<String, String> statusMap) {
bugDTOList.forEach(bugDTO -> {
bugDTO.setStatus(statusMap.get(bugDTO.getStatus()));
});
return bugDTOList;
}
private Map<String, List<CaseRelateBugDTO>> getBugData(List<String> ids, String testPlanId) {
List<CaseRelateBugDTO> bugList = bugRelateCaseMapper.getBugCountByIds(ids, testPlanId);
return bugList.stream().collect(Collectors.groupingBy(CaseRelateBugDTO::getCaseId));

View File

@ -3,7 +3,9 @@ package io.metersphere.plan.service;
import io.metersphere.plan.domain.TestPlanConfig;
import io.metersphere.plan.domain.TestPlanConfigExample;
import io.metersphere.plan.domain.TestPlanFunctionalCase;
import io.metersphere.plan.dto.response.TestPlanBugPageResponse;
import io.metersphere.plan.dto.response.TestPlanStatisticsResponse;
import io.metersphere.plan.mapper.ExtTestPlanBugMapper;
import io.metersphere.plan.mapper.ExtTestPlanFunctionalCaseMapper;
import io.metersphere.plan.mapper.TestPlanConfigMapper;
import io.metersphere.plan.utils.RateCalculateUtils;
@ -25,6 +27,8 @@ public class TestPlanStatisticsService {
private TestPlanConfigMapper testPlanConfigMapper;
@Resource
private ExtTestPlanFunctionalCaseMapper extTestPlanFunctionalCaseMapper;
@Resource
private ExtTestPlanBugMapper extTestPlanBugMapper;
/**
* 计划的用例统计数据
@ -42,11 +46,15 @@ public class TestPlanStatisticsService {
// 计划-功能用例的关联数据
List<TestPlanFunctionalCase> planFunctionalCases = extTestPlanFunctionalCaseMapper.getPlanFunctionalCaseByIds(planIds);
Map<String, List<TestPlanFunctionalCase>> planFunctionalCaseMap = planFunctionalCases.stream().collect(Collectors.groupingBy(TestPlanFunctionalCase::getTestPlanId));
List<TestPlanBugPageResponse> planBugs = extTestPlanBugMapper.countBugByIds(planIds);
Map<String, List<TestPlanBugPageResponse>> planBugMap = planBugs.stream().collect(Collectors.groupingBy(TestPlanBugPageResponse::getTestPlanId));
// TODO: 计划-接口用例的关联数据
plans.forEach(plan -> {
// 功能用例统计开始
List<TestPlanFunctionalCase> functionalCases = planFunctionalCaseMap.get(plan.getId());
plan.setFunctionalCaseCount(CollectionUtils.isNotEmpty(functionalCases) ? functionalCases.size() : 0);
List<TestPlanBugPageResponse> bugs = planBugMap.get(plan.getId());
plan.setBugCount(CollectionUtils.isNotEmpty(bugs) ? bugs.size() : 0);
// TODO: 接口用例统计开始
// FIXME: CaseTotal后续会补充接口用例及场景的统计数据

View File

@ -75,7 +75,7 @@ public class TestPlanCaseControllerTests extends BaseTest {
@Sql(scripts = {"/dml/init_test_plan_case_relate_bug.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED))
public void testGetFunctionalCaseList() throws Exception {
TestPlanCaseRequest request = new TestPlanCaseRequest();
request.setProjectId(DEFAULT_PROJECT_ID);
request.setProjectId("123");
request.setCurrent(1);
request.setPageSize(10);
request.setTestPlanId("plan_1");

View File

@ -64,3 +64,6 @@ VALUES
('123445', 'relate_case_1', 'plan_1', 'fc_1', 'PASSED', '1234', '2132134', b'0', '', 'admin', 1715828421525);
INSERT INTO functional_case_blob(id, steps, text_description, expected_result, prerequisite, description) VALUES ('fc_1', 'STEP', '1111', '', '', 'TEST');
INSERT INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time, module_setting)
VALUES
('123', 2, 1, 'wx', 'wx', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000,'["bugManagement","caseManagement","apiTest","testPlan"]');

View File

@ -37,10 +37,6 @@ VALUES
('wx_test_plan_id_7', b'0', b'0', 100);
INSERT INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time, module_setting)
VALUES
('123', 2, 1, 'wx', 'wx', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000,'["bugManagement","caseManagement","apiTest","testPlan"]');
INSERT INTO `test_plan_allocation`(`id`, `test_plan_id`, `test_resource_pool_id`, `retry_on_fail`, `retry_type`, `retry_times`, `retry_interval`, `stop_on_fail`)
VALUES ('1', 'wx_test_plan_id_1', '111', b'0', 'scenario', '10', '1000', b'0');