From 9b0c48a5bfbc12e71a78900e8a4e25516ec42244 Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Fri, 21 Jun 2024 10:54:20 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=8A=9F=E8=83=BD=E7=94=A8=E4=BE=8B):=20?= =?UTF-8?q?=E8=84=91=E5=9B=BE=E5=88=86=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FunctionalCaseMinderController.java | 10 +++- .../request/FunctionalCaseMindRequest.java | 5 ++ .../service/FunctionalCaseMinderService.java | 8 --- .../FunctionalCaseMinderControllerTest.java | 52 +++++++++++-------- 4 files changed, 44 insertions(+), 31 deletions(-) diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseMinderController.java b/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseMinderController.java index 7491218e4c..6c5511f96c 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseMinderController.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseMinderController.java @@ -1,6 +1,8 @@ package io.metersphere.functional.controller; import com.alibaba.excel.util.StringUtils; +import com.github.pagehelper.Page; +import com.github.pagehelper.PageHelper; import io.metersphere.functional.dto.FunctionalMinderTreeDTO; import io.metersphere.functional.request.FunctionalCaseMindRequest; import io.metersphere.functional.request.FunctionalCaseMinderEditRequest; @@ -10,6 +12,8 @@ import io.metersphere.functional.service.FunctionalCaseMinderService; import io.metersphere.sdk.constants.PermissionConstants; import io.metersphere.system.dto.sdk.BaseTreeNode; import io.metersphere.system.security.CheckOwner; +import io.metersphere.system.utils.PageUtils; +import io.metersphere.system.utils.Pager; import io.metersphere.system.utils.SessionUtils; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; @@ -46,8 +50,10 @@ public class FunctionalCaseMinderController { @Operation(summary = "用例管理-功能用例-脑图用例跟根据模块ID查询列表") @RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ) @CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project") - public List getFunctionalCaseMinderTree(@Validated @RequestBody FunctionalCaseMindRequest request) { - return functionalCaseMinderService.getMindFunctionalCase(request, false); + public Pager> getFunctionalCaseMinderTree(@Validated @RequestBody FunctionalCaseMindRequest request) { + Page page = PageHelper.startPage(request.getCurrent(), 100 ); + return PageUtils.setPageInfo(page, functionalCaseMinderService.getMindFunctionalCase(request, false)); + } @PostMapping("/edit") diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/request/FunctionalCaseMindRequest.java b/backend/services/case-management/src/main/java/io/metersphere/functional/request/FunctionalCaseMindRequest.java index e5b0a8f2d6..c19767180a 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/request/FunctionalCaseMindRequest.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/request/FunctionalCaseMindRequest.java @@ -1,6 +1,7 @@ package io.metersphere.functional.request; import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.Min; import jakarta.validation.constraints.NotBlank; import lombok.Data; @@ -12,4 +13,8 @@ public class FunctionalCaseMindRequest { @Schema(description = "模块ID", requiredMode = Schema.RequiredMode.REQUIRED) private String moduleId; + + @Min(value = 1, message = "当前页码必须大于0") + @Schema(description = "当前页码") + private int current; } diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseMinderService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseMinderService.java index 0579497f79..b8dc6d8d7f 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseMinderService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseMinderService.java @@ -32,7 +32,6 @@ import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.log.dto.LogDTO; import io.metersphere.system.log.service.OperationLogService; import io.metersphere.system.mapper.CustomFieldMapper; -import io.metersphere.system.mapper.ExtCheckOwnerMapper; import io.metersphere.system.mapper.UserMapper; import io.metersphere.system.notice.constants.NoticeConstants; import io.metersphere.system.service.CommonNoticeSendService; @@ -84,9 +83,6 @@ public class FunctionalCaseMinderService { @Resource private FunctionalCaseCustomFieldMapper functionalCaseCustomFieldMapper; - @Resource - private ExtCheckOwnerMapper extCheckOwnerMapper; - @Resource private FunctionalCaseService functionalCaseService; @@ -127,10 +123,6 @@ public class FunctionalCaseMinderService { private ProjectTemplateService projectTemplateService; - private static final String FUNCTIONAL_CASE = "functional_case"; - private static final String FUNCTIONAL_CASE_MODULE = "functional_case_module"; - private static final String CHECK_OWNER_CASE = "check_owner_case"; - /** * 功能用例-脑图用例列表查询 * diff --git a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseMinderControllerTest.java b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseMinderControllerTest.java index 3c9b43b864..6b4069199f 100644 --- a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseMinderControllerTest.java +++ b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseMinderControllerTest.java @@ -1,10 +1,7 @@ package io.metersphere.functional.controller; import io.metersphere.functional.domain.*; -import io.metersphere.functional.dto.CaseCustomFieldDTO; -import io.metersphere.functional.dto.FunctionalCaseStepDTO; -import io.metersphere.functional.dto.FunctionalMinderTreeDTO; -import io.metersphere.functional.dto.MinderOptionDTO; +import io.metersphere.functional.dto.*; import io.metersphere.functional.mapper.*; import io.metersphere.functional.request.*; import io.metersphere.sdk.util.JSON; @@ -12,6 +9,7 @@ import io.metersphere.sdk.util.Translator; import io.metersphere.system.base.BaseTest; import io.metersphere.system.controller.handler.ResultHolder; import io.metersphere.system.dto.sdk.BaseTreeNode; +import io.metersphere.system.utils.Pager; import jakarta.annotation.Resource; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; @@ -64,17 +62,21 @@ public class FunctionalCaseMinderControllerTest extends BaseTest { public void testGetPageList() throws Exception { FunctionalCaseMindRequest request = new FunctionalCaseMindRequest(); request.setProjectId("project-case-minder-test"); + request.setCurrent(1); MvcResult mvcResultPage = this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_LIST_URL, request); - String contentAsString = mvcResultPage.getResponse().getContentAsString(StandardCharsets.UTF_8); - ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); - Assertions.assertNotNull(resultHolder); + Pager> tableData = JSON.parseObject(JSON.toJSONString( + JSON.parseObject(mvcResultPage.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()), + Pager.class); + Assertions.assertNotNull(tableData); request = new FunctionalCaseMindRequest(); request.setProjectId("project-case-minder-test"); request.setModuleId("TEST_MINDER_MODULE_ID_GYQ"); + request.setCurrent(1); mvcResultPage = this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_LIST_URL, request); - contentAsString = mvcResultPage.getResponse().getContentAsString(StandardCharsets.UTF_8); - resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); - Assertions.assertNotNull(resultHolder); + tableData = JSON.parseObject(JSON.toJSONString( + JSON.parseObject(mvcResultPage.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()), + Pager.class); + Assertions.assertNotNull(tableData); FunctionalCaseBlob functionalCaseBlob = new FunctionalCaseBlob(); functionalCaseBlob.setId("TEST_FUNCTIONAL_MINDER_CASE_ID_2"); functionalCaseBlob.setSteps(JSON.toJSONString(new ArrayList<>()).getBytes(StandardCharsets.UTF_8)); @@ -92,9 +94,10 @@ public class FunctionalCaseMinderControllerTest extends BaseTest { functionalCaseBlob6.setDescription(StringUtils.EMPTY.getBytes(StandardCharsets.UTF_8)); functionalCaseBlobMapper.updateByPrimaryKeyWithBLOBs(functionalCaseBlob6); mvcResultPage = this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_LIST_URL, request); - contentAsString = mvcResultPage.getResponse().getContentAsString(StandardCharsets.UTF_8); - resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); - Assertions.assertNotNull(resultHolder); + tableData = JSON.parseObject(JSON.toJSONString( + JSON.parseObject(mvcResultPage.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()), + Pager.class); + Assertions.assertNotNull(tableData); List list = new ArrayList<>(); FunctionalCaseStepDTO functionalCaseStepDTO = new FunctionalCaseStepDTO(); functionalCaseStepDTO.setId("12455"); @@ -130,9 +133,11 @@ public class FunctionalCaseMinderControllerTest extends BaseTest { functionalCaseBlob6.setDescription(description.getBytes(StandardCharsets.UTF_8)); functionalCaseBlobMapper.updateByPrimaryKeyWithBLOBs(functionalCaseBlob6); mvcResultPage = this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_LIST_URL, request); - contentAsString = mvcResultPage.getResponse().getContentAsString(StandardCharsets.UTF_8); - resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); - Assertions.assertNotNull(resultHolder); + + tableData = JSON.parseObject(JSON.toJSONString( + JSON.parseObject(mvcResultPage.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()), + Pager.class); + Assertions.assertNotNull(tableData); expectedResult = "文本描述的结果"; functionalCaseBlob = new FunctionalCaseBlob(); functionalCaseBlob.setId("TEST_FUNCTIONAL_MINDER_CASE_ID_2"); @@ -145,11 +150,12 @@ public class FunctionalCaseMinderControllerTest extends BaseTest { mvcResultPage = this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_LIST_URL, request); - contentAsString = mvcResultPage.getResponse().getContentAsString(StandardCharsets.UTF_8); - resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); - List baseTreeNodes = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), FunctionalMinderTreeDTO.class); - Assertions.assertNotNull(baseTreeNodes); - Assertions.assertEquals(2, baseTreeNodes.size()); + tableData = JSON.parseObject(JSON.toJSONString( + JSON.parseObject(mvcResultPage.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()), + Pager.class); + Assertions.assertNotNull(tableData); + Assertions.assertNotNull(tableData.getList()); + Assertions.assertEquals(2, tableData.getList().size()); } @Test @@ -330,6 +336,7 @@ public class FunctionalCaseMinderControllerTest extends BaseTest { public void testGetCaseModuleNodeList() throws Exception { FunctionalCaseMindRequest request = new FunctionalCaseMindRequest(); request.setProjectId("project-case-minder-test"); + request.setCurrent(1); MvcResult mvcResultPage = this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_NODE_MODULE_URL, request); String contentAsString = mvcResultPage.getResponse().getContentAsString(StandardCharsets.UTF_8); ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); @@ -350,6 +357,7 @@ public class FunctionalCaseMinderControllerTest extends BaseTest { request.setProjectId("project-case-minder-test"); request.setModuleId("TEST_MINDER_MODULE_ID_GYQ4"); request.setReviewId("TEST_MINDER_REVIEW_ID_GYQ"); + request.setCurrent(1); MvcResult mvcResultPage = this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_REVIEW_LIST_URL, request); String contentAsString = mvcResultPage.getResponse().getContentAsString(StandardCharsets.UTF_8); ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); @@ -362,6 +370,7 @@ public class FunctionalCaseMinderControllerTest extends BaseTest { request.setReviewId("TEST_MINDER_REVIEW_ID_GYQ2"); request.setViewFlag(true); request.setViewStatusFlag(true); + request.setCurrent(1); mvcResultPage = this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_REVIEW_LIST_URL, request); contentAsString = mvcResultPage.getResponse().getContentAsString(StandardCharsets.UTF_8); resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); @@ -377,6 +386,7 @@ public class FunctionalCaseMinderControllerTest extends BaseTest { request.setProjectId("project-case-minder-test"); request.setModuleId("TEST_MINDER_MODULE_ID_GYQ4"); request.setPlanId("TEST_MINDER_PLAN_ID_1"); + request.setCurrent(1); MvcResult mvcResultPage = this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_PLAN_LIST_URL, request); String contentAsString = mvcResultPage.getResponse().getContentAsString(StandardCharsets.UTF_8); ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);