refactor(测试计划): 测试计划报告用例列表耗时字段增加排序

This commit is contained in:
WangXu10 2024-12-10 16:52:39 +08:00 committed by Craftsman
parent 31f8172473
commit 0e2894eea6
3 changed files with 32 additions and 21 deletions

View File

@ -187,8 +187,10 @@ public class TestPlanReportController {
@CheckOwner(resourceId = "#request.getReportId()", resourceType = "test_plan_report") @CheckOwner(resourceId = "#request.getReportId()", resourceType = "test_plan_report")
public Pager<List<ReportDetailCasePageDTO>> pageFunctionalCase(@Validated @RequestBody TestPlanReportDetailPageRequest request) { public Pager<List<ReportDetailCasePageDTO>> pageFunctionalCase(@Validated @RequestBody TestPlanReportDetailPageRequest request) {
request.setDetailReportIds(testPlanReportService.getActualReportIds(request.getReportId())); request.setDetailReportIds(testPlanReportService.getActualReportIds(request.getReportId()));
String sort = request.getSortString();
sort = StringUtils.replace(sort, "request_time", "request_duration");
Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize(),
StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "tprfc.pos desc"); StringUtils.isNotBlank(sort) ? sort : "tprfc.pos desc");
if (!request.getStartPager()) { if (!request.getStartPager()) {
// 不分页仅排序 {测试集升序, 用例位次倒序} // 不分页仅排序 {测试集升序, 用例位次倒序}
page.setPageSize(0); page.setPageSize(0);
@ -196,7 +198,7 @@ public class TestPlanReportController {
page.setOrderBy("tpc.pos, tpc.name, tprfc.pos desc"); page.setOrderBy("tpc.pos, tpc.name, tprfc.pos desc");
page.setOrderByOnly(true); page.setOrderByOnly(true);
} }
return PageUtils.setPageInfo(page, testPlanReportService.listReportDetailCases(request, AssociateCaseType.FUNCTIONAL)); return PageUtils.setPageInfo(page, testPlanReportService.listReportDetailCases(request, null, AssociateCaseType.FUNCTIONAL));
} }
@GetMapping("/detail/functional/case/step/{reportId}") @GetMapping("/detail/functional/case/step/{reportId}")
@ -212,8 +214,10 @@ public class TestPlanReportController {
@CheckOwner(resourceId = "#request.getReportId()", resourceType = "test_plan_report") @CheckOwner(resourceId = "#request.getReportId()", resourceType = "test_plan_report")
public Pager<List<ReportDetailCasePageDTO>> pageApiCase(@Validated @RequestBody TestPlanReportDetailPageRequest request) { public Pager<List<ReportDetailCasePageDTO>> pageApiCase(@Validated @RequestBody TestPlanReportDetailPageRequest request) {
request.setDetailReportIds(testPlanReportService.getActualReportIds(request.getReportId())); request.setDetailReportIds(testPlanReportService.getActualReportIds(request.getReportId()));
String sort = request.getSortString();
sort = StringUtils.replace(sort, "request_time", "request_duration");
Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize(),
StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "tprac.pos desc"); StringUtils.isNotBlank(sort) ? sort : "tprac.pos desc");
if (!request.getStartPager()) { if (!request.getStartPager()) {
// 不分页仅排序 {测试集升序, 用例位次倒序} // 不分页仅排序 {测试集升序, 用例位次倒序}
page.setPageSize(0); page.setPageSize(0);
@ -221,7 +225,7 @@ public class TestPlanReportController {
page.setOrderBy("tpc.pos, tpc.name, tprac.pos desc"); page.setOrderBy("tpc.pos, tpc.name, tprac.pos desc");
page.setOrderByOnly(true); page.setOrderByOnly(true);
} }
return PageUtils.setPageInfo(page, testPlanReportService.listReportDetailCases(request, AssociateCaseType.API_CASE)); return PageUtils.setPageInfo(page, testPlanReportService.listReportDetailCases(request, null, AssociateCaseType.API_CASE));
} }
@PostMapping("/detail/scenario/case/page") @PostMapping("/detail/scenario/case/page")
@ -230,8 +234,10 @@ public class TestPlanReportController {
@CheckOwner(resourceId = "#request.getReportId()", resourceType = "test_plan_report") @CheckOwner(resourceId = "#request.getReportId()", resourceType = "test_plan_report")
public Pager<List<ReportDetailCasePageDTO>> pageScenarioCase(@Validated @RequestBody TestPlanReportDetailPageRequest request) { public Pager<List<ReportDetailCasePageDTO>> pageScenarioCase(@Validated @RequestBody TestPlanReportDetailPageRequest request) {
request.setDetailReportIds(testPlanReportService.getActualReportIds(request.getReportId())); request.setDetailReportIds(testPlanReportService.getActualReportIds(request.getReportId()));
String sort = request.getSortString();
sort = StringUtils.replace(sort, "request_time", "request_duration");
Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize(),
StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "tpras.pos desc"); StringUtils.isNotBlank(sort) ? sort : "tpras.pos desc");
if (!request.getStartPager()) { if (!request.getStartPager()) {
// 不分页仅排序 {测试集升序, 用例位次倒序} // 不分页仅排序 {测试集升序, 用例位次倒序}
page.setPageSize(0); page.setPageSize(0);
@ -239,7 +245,7 @@ public class TestPlanReportController {
page.setOrderBy("tpc.pos, tpc.name, tpras.pos desc"); page.setOrderBy("tpc.pos, tpc.name, tpras.pos desc");
page.setOrderByOnly(true); page.setOrderByOnly(true);
} }
return PageUtils.setPageInfo(page, testPlanReportService.listReportDetailCases(request, AssociateCaseType.API_SCENARIO)); return PageUtils.setPageInfo(page, testPlanReportService.listReportDetailCases(request, null, AssociateCaseType.API_SCENARIO));
} }
@PostMapping("/detail/plan/report/page") @PostMapping("/detail/plan/report/page")

View File

@ -108,9 +108,11 @@ public class TestPlanReportShareController {
request.setDetailReportIds(testPlanReportService.getActualReportIds(request.getReportId())); request.setDetailReportIds(testPlanReportService.getActualReportIds(request.getReportId()));
ShareInfo shareInfo = testPlanReportShareService.checkResource(request.getShareId()); ShareInfo shareInfo = testPlanReportShareService.checkResource(request.getShareId());
testPlanReportShareService.validateExpired(shareInfo); testPlanReportShareService.validateExpired(shareInfo);
String sort = request.getSortString();
sort = StringUtils.replace(sort, "request_time", "request_duration");
Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize(),
StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "tprfc.pos desc"); StringUtils.isNotBlank(sort) ? sort : "tprfc.pos desc");
return PageUtils.setPageInfo(page, testPlanReportService.listReportDetailCases(request, AssociateCaseType.FUNCTIONAL)); return PageUtils.setPageInfo(page, testPlanReportService.listReportDetailCases(request, null, AssociateCaseType.FUNCTIONAL));
} }
@PostMapping("/detail/api/case/page") @PostMapping("/detail/api/case/page")
@ -119,9 +121,11 @@ public class TestPlanReportShareController {
request.setDetailReportIds(testPlanReportService.getActualReportIds(request.getReportId())); request.setDetailReportIds(testPlanReportService.getActualReportIds(request.getReportId()));
ShareInfo shareInfo = testPlanReportShareService.checkResource(request.getShareId()); ShareInfo shareInfo = testPlanReportShareService.checkResource(request.getShareId());
testPlanReportShareService.validateExpired(shareInfo); testPlanReportShareService.validateExpired(shareInfo);
String sort = request.getSortString();
sort = StringUtils.replace(sort, "request_time", "request_duration");
Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize(),
StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "tprac.pos desc"); StringUtils.isNotBlank(sort) ? sort : "tprac.pos desc");
return PageUtils.setPageInfo(page, testPlanReportService.listReportDetailCases(request, AssociateCaseType.API_CASE)); return PageUtils.setPageInfo(page, testPlanReportService.listReportDetailCases(request, null, AssociateCaseType.API_CASE));
} }
@PostMapping("/detail/scenario/case/page") @PostMapping("/detail/scenario/case/page")
@ -130,9 +134,11 @@ public class TestPlanReportShareController {
request.setDetailReportIds(testPlanReportService.getActualReportIds(request.getReportId())); request.setDetailReportIds(testPlanReportService.getActualReportIds(request.getReportId()));
ShareInfo shareInfo = testPlanReportShareService.checkResource(request.getShareId()); ShareInfo shareInfo = testPlanReportShareService.checkResource(request.getShareId());
testPlanReportShareService.validateExpired(shareInfo); testPlanReportShareService.validateExpired(shareInfo);
String sort = request.getSortString();
sort = StringUtils.replace(sort, "request_time", "request_duration");
Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize(),
StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "tpras.pos desc"); StringUtils.isNotBlank(sort) ? sort : "tpras.pos desc");
return PageUtils.setPageInfo(page, testPlanReportService.listReportDetailCases(request, AssociateCaseType.API_SCENARIO)); return PageUtils.setPageInfo(page, testPlanReportService.listReportDetailCases(request, null, AssociateCaseType.API_SCENARIO));
} }
@PostMapping("/detail/plan/report/page") @PostMapping("/detail/plan/report/page")

View File

@ -927,15 +927,13 @@ public class TestPlanReportService {
* @param request 请求参数 * @param request 请求参数
* @return 用例分页数据 * @return 用例分页数据
*/ */
public List<ReportDetailCasePageDTO> listReportDetailCases(TestPlanReportDetailPageRequest request, String caseType) { public List<ReportDetailCasePageDTO> listReportDetailCases(TestPlanReportDetailPageRequest request, String sort, String caseType) {
List<ReportDetailCasePageDTO> detailCases; List<ReportDetailCasePageDTO> detailCases;
switch (caseType) { switch (caseType) {
case AssociateCaseType.FUNCTIONAL -> case AssociateCaseType.FUNCTIONAL ->
detailCases = extTestPlanReportFunctionalCaseMapper.list(request, request.getSortString()); detailCases = extTestPlanReportFunctionalCaseMapper.list(request, sort);
case AssociateCaseType.API_CASE -> case AssociateCaseType.API_CASE -> detailCases = extTestPlanReportApiCaseMapper.list(request, sort);
detailCases = extTestPlanReportApiCaseMapper.list(request, request.getSortString()); case AssociateCaseType.API_SCENARIO -> detailCases = extTestPlanReportApiScenarioMapper.list(request, sort);
case AssociateCaseType.API_SCENARIO ->
detailCases = extTestPlanReportApiScenarioMapper.list(request, request.getSortString());
default -> detailCases = new ArrayList<>(); default -> detailCases = new ArrayList<>();
} }
List<String> distinctUserIds = detailCases.stream().map(ReportDetailCasePageDTO::getExecuteUser).distinct().collect(Collectors.toList()); List<String> distinctUserIds = detailCases.stream().map(ReportDetailCasePageDTO::getExecuteUser).distinct().collect(Collectors.toList());
@ -1344,17 +1342,18 @@ public class TestPlanReportService {
if (CollectionUtils.isNotEmpty(collections)) { if (CollectionUtils.isNotEmpty(collections)) {
TestPlanReportDetailPageRequest reportDetail = new TestPlanReportDetailPageRequest(); TestPlanReportDetailPageRequest reportDetail = new TestPlanReportDetailPageRequest();
BeanUtils.copyBean(reportDetail, request); BeanUtils.copyBean(reportDetail, request);
String sort = StringUtils.replace(request.getSortString(), "request_time", "request_duration");
collections.forEach(item -> { collections.forEach(item -> {
reportDetail.setCollectionId(item.getId()); reportDetail.setCollectionId(item.getId());
reportDetail.setDetailReportIds(getActualReportIds(request.getReportId())); reportDetail.setDetailReportIds(getActualReportIds(request.getReportId()));
List<ReportDetailCasePageDTO> caseList = new ArrayList<>(); List<ReportDetailCasePageDTO> caseList = new ArrayList<>();
switch (caseType) { switch (caseType) {
case CollectionQueryType.FUNCTIONAL -> case CollectionQueryType.FUNCTIONAL ->
caseList = listReportDetailCases(reportDetail, AssociateCaseType.FUNCTIONAL); caseList = listReportDetailCases(reportDetail, sort, AssociateCaseType.FUNCTIONAL);
case CollectionQueryType.API -> case CollectionQueryType.API ->
caseList = listReportDetailCases(reportDetail, AssociateCaseType.API_CASE); caseList = listReportDetailCases(reportDetail, sort, AssociateCaseType.API_CASE);
case CollectionQueryType.SCENARIO -> case CollectionQueryType.SCENARIO ->
caseList = listReportDetailCases(reportDetail, AssociateCaseType.API_SCENARIO); caseList = listReportDetailCases(reportDetail, sort, AssociateCaseType.API_SCENARIO);
default -> caseList = new ArrayList<>(); default -> caseList = new ArrayList<>();
} }
item.setReportDetailCaseList(caseList); item.setReportDetailCaseList(caseList);