diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanReportController.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanReportController.java index 91b0503ac6..10c83cc1ca 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanReportController.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanReportController.java @@ -187,8 +187,10 @@ public class TestPlanReportController { @CheckOwner(resourceId = "#request.getReportId()", resourceType = "test_plan_report") public Pager> pageFunctionalCase(@Validated @RequestBody TestPlanReportDetailPageRequest request) { request.setDetailReportIds(testPlanReportService.getActualReportIds(request.getReportId())); + String sort = request.getSortString(); + sort = StringUtils.replace(sort, "request_time", "request_duration"); Page 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()) { // 不分页仅排序 {测试集升序, 用例位次倒序} page.setPageSize(0); @@ -196,7 +198,7 @@ public class TestPlanReportController { page.setOrderBy("tpc.pos, tpc.name, tprfc.pos desc"); 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}") @@ -212,8 +214,10 @@ public class TestPlanReportController { @CheckOwner(resourceId = "#request.getReportId()", resourceType = "test_plan_report") public Pager> pageApiCase(@Validated @RequestBody TestPlanReportDetailPageRequest request) { request.setDetailReportIds(testPlanReportService.getActualReportIds(request.getReportId())); + String sort = request.getSortString(); + sort = StringUtils.replace(sort, "request_time", "request_duration"); Page 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()) { // 不分页仅排序 {测试集升序, 用例位次倒序} page.setPageSize(0); @@ -221,7 +225,7 @@ public class TestPlanReportController { page.setOrderBy("tpc.pos, tpc.name, tprac.pos desc"); 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") @@ -230,8 +234,10 @@ public class TestPlanReportController { @CheckOwner(resourceId = "#request.getReportId()", resourceType = "test_plan_report") public Pager> pageScenarioCase(@Validated @RequestBody TestPlanReportDetailPageRequest request) { request.setDetailReportIds(testPlanReportService.getActualReportIds(request.getReportId())); + String sort = request.getSortString(); + sort = StringUtils.replace(sort, "request_time", "request_duration"); Page 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()) { // 不分页仅排序 {测试集升序, 用例位次倒序} page.setPageSize(0); @@ -239,7 +245,7 @@ public class TestPlanReportController { page.setOrderBy("tpc.pos, tpc.name, tpras.pos desc"); 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") diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanReportShareController.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanReportShareController.java index 60b1283220..8deaf22730 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanReportShareController.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanReportShareController.java @@ -108,9 +108,11 @@ public class TestPlanReportShareController { request.setDetailReportIds(testPlanReportService.getActualReportIds(request.getReportId())); ShareInfo shareInfo = testPlanReportShareService.checkResource(request.getShareId()); testPlanReportShareService.validateExpired(shareInfo); + String sort = request.getSortString(); + sort = StringUtils.replace(sort, "request_time", "request_duration"); Page page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), - StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "tprfc.pos desc"); - return PageUtils.setPageInfo(page, testPlanReportService.listReportDetailCases(request, AssociateCaseType.FUNCTIONAL)); + StringUtils.isNotBlank(sort) ? sort : "tprfc.pos desc"); + return PageUtils.setPageInfo(page, testPlanReportService.listReportDetailCases(request, null, AssociateCaseType.FUNCTIONAL)); } @PostMapping("/detail/api/case/page") @@ -119,9 +121,11 @@ public class TestPlanReportShareController { request.setDetailReportIds(testPlanReportService.getActualReportIds(request.getReportId())); ShareInfo shareInfo = testPlanReportShareService.checkResource(request.getShareId()); testPlanReportShareService.validateExpired(shareInfo); + String sort = request.getSortString(); + sort = StringUtils.replace(sort, "request_time", "request_duration"); Page page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), - StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "tprac.pos desc"); - return PageUtils.setPageInfo(page, testPlanReportService.listReportDetailCases(request, AssociateCaseType.API_CASE)); + StringUtils.isNotBlank(sort) ? sort : "tprac.pos desc"); + return PageUtils.setPageInfo(page, testPlanReportService.listReportDetailCases(request, null, AssociateCaseType.API_CASE)); } @PostMapping("/detail/scenario/case/page") @@ -130,9 +134,11 @@ public class TestPlanReportShareController { request.setDetailReportIds(testPlanReportService.getActualReportIds(request.getReportId())); ShareInfo shareInfo = testPlanReportShareService.checkResource(request.getShareId()); testPlanReportShareService.validateExpired(shareInfo); + String sort = request.getSortString(); + sort = StringUtils.replace(sort, "request_time", "request_duration"); Page page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), - StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "tpras.pos desc"); - return PageUtils.setPageInfo(page, testPlanReportService.listReportDetailCases(request, AssociateCaseType.API_SCENARIO)); + StringUtils.isNotBlank(sort) ? sort : "tpras.pos desc"); + return PageUtils.setPageInfo(page, testPlanReportService.listReportDetailCases(request, null, AssociateCaseType.API_SCENARIO)); } @PostMapping("/detail/plan/report/page") diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanReportService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanReportService.java index e929366bf3..d4f486e3d1 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanReportService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanReportService.java @@ -927,15 +927,13 @@ public class TestPlanReportService { * @param request 请求参数 * @return 用例分页数据 */ - public List listReportDetailCases(TestPlanReportDetailPageRequest request, String caseType) { + public List listReportDetailCases(TestPlanReportDetailPageRequest request, String sort, String caseType) { List detailCases; switch (caseType) { case AssociateCaseType.FUNCTIONAL -> - detailCases = extTestPlanReportFunctionalCaseMapper.list(request, request.getSortString()); - case AssociateCaseType.API_CASE -> - detailCases = extTestPlanReportApiCaseMapper.list(request, request.getSortString()); - case AssociateCaseType.API_SCENARIO -> - detailCases = extTestPlanReportApiScenarioMapper.list(request, request.getSortString()); + detailCases = extTestPlanReportFunctionalCaseMapper.list(request, sort); + case AssociateCaseType.API_CASE -> detailCases = extTestPlanReportApiCaseMapper.list(request, sort); + case AssociateCaseType.API_SCENARIO -> detailCases = extTestPlanReportApiScenarioMapper.list(request, sort); default -> detailCases = new ArrayList<>(); } List distinctUserIds = detailCases.stream().map(ReportDetailCasePageDTO::getExecuteUser).distinct().collect(Collectors.toList()); @@ -1344,17 +1342,18 @@ public class TestPlanReportService { if (CollectionUtils.isNotEmpty(collections)) { TestPlanReportDetailPageRequest reportDetail = new TestPlanReportDetailPageRequest(); BeanUtils.copyBean(reportDetail, request); + String sort = StringUtils.replace(request.getSortString(), "request_time", "request_duration"); collections.forEach(item -> { reportDetail.setCollectionId(item.getId()); reportDetail.setDetailReportIds(getActualReportIds(request.getReportId())); List caseList = new ArrayList<>(); switch (caseType) { case CollectionQueryType.FUNCTIONAL -> - caseList = listReportDetailCases(reportDetail, AssociateCaseType.FUNCTIONAL); + caseList = listReportDetailCases(reportDetail, sort, AssociateCaseType.FUNCTIONAL); case CollectionQueryType.API -> - caseList = listReportDetailCases(reportDetail, AssociateCaseType.API_CASE); + caseList = listReportDetailCases(reportDetail, sort, AssociateCaseType.API_CASE); case CollectionQueryType.SCENARIO -> - caseList = listReportDetailCases(reportDetail, AssociateCaseType.API_SCENARIO); + caseList = listReportDetailCases(reportDetail, sort, AssociateCaseType.API_SCENARIO); default -> caseList = new ArrayList<>(); } item.setReportDetailCaseList(caseList);