diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanTestCaseMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanTestCaseMapper.xml index 3aa47c66b7..ab991531ed 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanTestCaseMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanTestCaseMapper.xml @@ -258,11 +258,8 @@ order by - - customNum ${order.type} - - - test_case.name ${order.type} + + test_case.${order.name} ${order.type} test_plan_test_case.${order.name} ${order.type} diff --git a/backend/src/main/java/io/metersphere/commons/utils/ServiceUtils.java b/backend/src/main/java/io/metersphere/commons/utils/ServiceUtils.java index 88fcee4ef2..8bc61b3dad 100644 --- a/backend/src/main/java/io/metersphere/commons/utils/ServiceUtils.java +++ b/backend/src/main/java/io/metersphere/commons/utils/ServiceUtils.java @@ -54,6 +54,24 @@ public class ServiceUtils { return getDefaultOrderByField(prefix, orders, field); } + /** + * 根据当前项目设置是否启用自定义ID + * 设置按照哪个字段排序 + * @param isCustomNum + * @param orders + * @return + */ + public static List replaceCustomNumOrder(Boolean isCustomNum, List orders) { + orders.forEach(item -> { + if (isCustomNum && StringUtils.equals(item.getName(), "num")) { + item.setName("custom_num"); + } else if (StringUtils.equals(item.getName(), "custom_num")) { + item.setName("num"); + } + }); + return orders; + } + private static List getDefaultOrderByField(String prefix, List orders, String field) { if (orders == null || orders.size() < 1) { OrderRequest orderRequest = new OrderRequest(); diff --git a/backend/src/main/java/io/metersphere/track/controller/TestPlanTestCaseController.java b/backend/src/main/java/io/metersphere/track/controller/TestPlanTestCaseController.java index adf11e9c2b..8b4f533e59 100644 --- a/backend/src/main/java/io/metersphere/track/controller/TestPlanTestCaseController.java +++ b/backend/src/main/java/io/metersphere/track/controller/TestPlanTestCaseController.java @@ -29,6 +29,7 @@ public class TestPlanTestCaseController { @PostMapping("/list/{goPage}/{pageSize}") public Pager> getTestPlanCases(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryTestPlanCaseRequest request) { + testPlanTestCaseService.wrapQueryTestPlanCaseRequest(request); Page page = PageHelper.startPage(goPage, pageSize, true); return PageUtils.setPageInfo(page, testPlanTestCaseService.list(request)); } @@ -94,6 +95,7 @@ public class TestPlanTestCaseController { @PostMapping("/list/all") public List getTestPlanCases(@RequestBody QueryTestPlanCaseRequest request) { + testPlanTestCaseService.wrapQueryTestPlanCaseRequest(request); return testPlanTestCaseService.list(request); } diff --git a/backend/src/main/java/io/metersphere/track/request/testplancase/QueryTestPlanCaseRequest.java b/backend/src/main/java/io/metersphere/track/request/testplancase/QueryTestPlanCaseRequest.java index 2546e41205..821108af09 100644 --- a/backend/src/main/java/io/metersphere/track/request/testplancase/QueryTestPlanCaseRequest.java +++ b/backend/src/main/java/io/metersphere/track/request/testplancase/QueryTestPlanCaseRequest.java @@ -35,5 +35,9 @@ public class QueryTestPlanCaseRequest extends BaseQueryRequest { private String id; + private Boolean isCustomNum = false; + + private String projectName; + private Map combine; } diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java index eb7260bb75..d7ad7e7a3a 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java @@ -696,6 +696,8 @@ public class TestPlanService { public List listTestCaseByPlanId(String planId) { QueryTestPlanCaseRequest request = new QueryTestPlanCaseRequest(); request.setPlanId(planId); + request.setProjectId(testPlanMapper.selectByPrimaryKey(planId).getProjectId()); + testPlanTestCaseService.wrapQueryTestPlanCaseRequest(request); return testPlanTestCaseService.list(request); } diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanTestCaseService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanTestCaseService.java index 73a26d2b15..70059dc375 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanTestCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanTestCaseService.java @@ -86,35 +86,43 @@ public class TestPlanTestCaseService { } public List list(QueryTestPlanCaseRequest request) { - request.setOrders(ServiceUtils.getDefaultSortOrder(request.getOrders())); - List list = extTestPlanTestCaseMapper.list(request); - if (CollectionUtils.isEmpty(list)) { - return list; - } - Project project = projectService.getProjectById(list.get(0).getProjectId()); + List orders = ServiceUtils.getDefaultSortOrder(request.getOrders()); + orders = ServiceUtils.replaceCustomNumOrder(request.getIsCustomNum(), orders); + request.setOrders(orders); - ProjectApplication projectApplication = projectApplicationService.getProjectApplication(project.getId(), "CASE_CUSTOM_NUM"); - list.forEach(item -> { - // 设置项目名称 - item.setProjectName(project.getName()); - if (StringUtils.equals(projectApplication.getTypeValue(), "false")) { - // 如果配置是不启用自定义字段,则设置为 num - item.setCustomNum(item.getNum().toString()); - } - }); - // 设置版本信息 - ServiceUtils.buildVersionInfo(list); - QueryMemberRequest queryMemberRequest = new QueryMemberRequest(); - queryMemberRequest.setProjectId(request.getProjectId()); - Map userMap = userService.getProjectMemberList(queryMemberRequest) - .stream().collect(Collectors.toMap(User::getId, User::getName)); - list.forEach(item -> { - item.setExecutorName(userMap.get(item.getExecutor())); - item.setMaintainerName(userMap.get(item.getMaintainer())); - }); + List list = extTestPlanTestCaseMapper.list(request); + if (CollectionUtils.isNotEmpty(list)) { + list.forEach(item -> { + // 设置项目名称 + item.setProjectName(request.getProjectName()); + if (!request.getIsCustomNum()) { + // 如果配置是不启用自定义字段,则设置为 num + item.setCustomNum(item.getNum().toString()); + } + }); + + // 设置版本信息 + ServiceUtils.buildVersionInfo(list); + QueryMemberRequest queryMemberRequest = new QueryMemberRequest(); + queryMemberRequest.setProjectId(request.getProjectId()); + Map userMap = userService.getProjectMemberList(queryMemberRequest) + .stream().collect(Collectors.toMap(User::getId, User::getName)); + list.forEach(item -> { + item.setExecutorName(userMap.get(item.getExecutor())); + item.setMaintainerName(userMap.get(item.getMaintainer())); + }); + } return list; } + public QueryTestPlanCaseRequest wrapQueryTestPlanCaseRequest(QueryTestPlanCaseRequest request) { + Project project = projectService.getProjectById(request.getProjectId()); + ProjectApplication projectApplication = projectApplicationService.getProjectApplication(project.getId(), ProjectApplicationType.CASE_CUSTOM_NUM.name()); + request.setIsCustomNum(StringUtils.equals(projectApplication.getTypeValue(), "false") ? false : true); + request.setProjectName(project.getName()); + return request; + } + public List listByPlanId(QueryTestPlanCaseRequest request) { List list = extTestPlanTestCaseMapper.listByPlanId(request); return list;