From 2c0c4c07fa1111b8558a6b17913d11c7170a963b Mon Sep 17 00:00:00 2001 From: WangXu10 Date: Mon, 13 May 2024 10:28:53 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92):=20?= =?UTF-8?q?=E5=85=B3=E8=81=94=E8=AE=A1=E5=88=92=E5=BC=B9=E7=AA=97=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E7=94=A8=E4=BE=8B=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/FunctionalCaseController.java | 2 +- .../FunctionalCaseRelationshipController.java | 2 +- .../FunctionalCaseTrashController.java | 2 +- .../mapper/ExtFunctionalCaseMapper.java | 6 +-- .../mapper/ExtFunctionalCaseMapper.xml | 5 ++ .../request/FunctionalCasePageRequest.java | 2 + .../service/FunctionalCaseService.java | 4 +- .../TestPlanAssociateController.java | 50 +++++++++++++++++++ .../plan/service/TestPlanConfigService.java | 6 +++ .../TestPlanAssociateControllerTests.java | 42 ++++++++++++++++ .../dml/init_test_plan_association.sql | 21 ++++++++ 11 files changed, 134 insertions(+), 8 deletions(-) create mode 100644 backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanAssociateController.java create mode 100644 backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanAssociateControllerTests.java create mode 100644 backend/services/test-plan/src/test/resources/dml/init_test_plan_association.sql diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseController.java b/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseController.java index e289b78f20..079e2cf89e 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseController.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseController.java @@ -144,7 +144,7 @@ public class FunctionalCaseController { public Pager> getFunctionalCasePage(@Validated @RequestBody FunctionalCasePageRequest request) { Page page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "pos desc"); - return PageUtils.setPageInfo(page, functionalCaseService.getFunctionalCasePage(request, false)); + return PageUtils.setPageInfo(page, functionalCaseService.getFunctionalCasePage(request, false, false)); } @PostMapping("/module/count") diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseRelationshipController.java b/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseRelationshipController.java index 2055999ac0..82690172b6 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseRelationshipController.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseRelationshipController.java @@ -57,7 +57,7 @@ public class FunctionalCaseRelationshipController { public Pager> getFunctionalCasePage(@Validated @RequestBody RelationshipPageRequest request) { Page page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "pos desc"); - return PageUtils.setPageInfo(page, functionalCaseService.getFunctionalCasePage(request, false)); + return PageUtils.setPageInfo(page, functionalCaseService.getFunctionalCasePage(request, false, false)); } @PostMapping("/add") diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseTrashController.java b/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseTrashController.java index 399dae3263..681bbbb0c2 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseTrashController.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseTrashController.java @@ -43,7 +43,7 @@ public class FunctionalCaseTrashController { public Pager> getFunctionalCasePage(@Validated @RequestBody FunctionalCasePageRequest request) { Page 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)); + return PageUtils.setPageInfo(page, functionalCaseService.getFunctionalCasePage(request, true, false)); } @PostMapping("/module/count") diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtFunctionalCaseMapper.java b/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtFunctionalCaseMapper.java index f2534e470f..a415ea91fa 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtFunctionalCaseMapper.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtFunctionalCaseMapper.java @@ -34,7 +34,7 @@ public interface ExtFunctionalCaseMapper { List checkCaseByModuleIds(@Param("moduleIds") List deleteIds); - List list(@Param("request") FunctionalCasePageRequest request, @Param("deleted") boolean deleted); + List list(@Param("request") FunctionalCasePageRequest request, @Param("deleted") boolean deleted, @Param("isRepeat") boolean isRepeat); void recoverCase(@Param("ids") List ids, @Param("userId") String userId, @Param("time") long time); @@ -84,12 +84,12 @@ public interface ExtFunctionalCaseMapper { List getSelectIdsByAssociateParam(@Param("request") AssociateOtherCaseRequest request, @Param("deleted") boolean deleted); /** - * 根据模块ID获取脑图展示数据 + * 根据模块ID获取脑图展示数据 */ List getMinderCaseList(@Param("request") FunctionalCaseMindRequest request, @Param("deleted") boolean deleted); /** - * 根据模块ID获取用例评审脑图展示数据 + * 根据模块ID获取用例评审脑图展示数据 */ List getMinderCaseReviewList(@Param("request") FunctionalCaseReviewMindRequest request, @Param("deleted") boolean delete, @Param("userId") String userId, @Param("viewStatusUserId") boolean viewStatusUserId); diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtFunctionalCaseMapper.xml b/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtFunctionalCaseMapper.xml index cbd05916f1..d4ac4ddc03 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtFunctionalCaseMapper.xml +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtFunctionalCaseMapper.xml @@ -127,6 +127,11 @@ select case_review_functional_case.case_id from case_review_functional_case where case_review_functional_case.review_id = #{request.reviewId} ) + + AND functional_case.id not in ( + select test_plan_functional_case.functional_case_id from test_plan_functional_case where test_plan_functional_case.test_plan_id = #{request.testPlanId} + ) + AND functional_case.id not in diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/request/FunctionalCasePageRequest.java b/backend/services/case-management/src/main/java/io/metersphere/functional/request/FunctionalCasePageRequest.java index 28560ce997..3e8185837c 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/request/FunctionalCasePageRequest.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/request/FunctionalCasePageRequest.java @@ -47,4 +47,6 @@ public class FunctionalCasePageRequest extends BasePageRequest implements Serial @Schema(description = "排除ids") private List excludeIds; + @Schema(description = "测试计划id") + private String testPlanId; } diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java index 631e698437..49b350c623 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java @@ -676,8 +676,8 @@ public class FunctionalCaseService { * @param request request * @return List */ - public List getFunctionalCasePage(FunctionalCasePageRequest request, Boolean deleted) { - List functionalCaseLists = extFunctionalCaseMapper.list(request, deleted); + public List getFunctionalCasePage(FunctionalCasePageRequest request, Boolean deleted, Boolean isRepeat) { + List functionalCaseLists = extFunctionalCaseMapper.list(request, deleted, isRepeat); if (CollectionUtils.isEmpty(functionalCaseLists)) { return new ArrayList<>(); } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanAssociateController.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanAssociateController.java new file mode 100644 index 0000000000..0e914a5f47 --- /dev/null +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanAssociateController.java @@ -0,0 +1,50 @@ +package io.metersphere.plan.controller; + +import com.github.pagehelper.Page; +import com.github.pagehelper.PageHelper; +import io.metersphere.functional.dto.FunctionalCasePageDTO; +import io.metersphere.functional.request.FunctionalCasePageRequest; +import io.metersphere.functional.service.FunctionalCaseService; +import io.metersphere.plan.service.TestPlanConfigService; +import io.metersphere.sdk.constants.PermissionConstants; +import io.metersphere.system.security.CheckOwner; +import io.metersphere.system.utils.PageUtils; +import io.metersphere.system.utils.Pager; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.annotation.Resource; +import org.apache.commons.lang3.StringUtils; +import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RestController +@Tag(name = "测试计划关联用例弹窗接口相关") +@RequestMapping("/test-plan/association") +public class TestPlanAssociateController { + + @Resource + private TestPlanConfigService testPlanConfigService; + @Resource + private FunctionalCaseService functionalCaseService; + + @PostMapping("/page") + @Operation(summary = "测试计划-关联用例弹窗-功能用例列表查询(项目)") + @RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ) + @CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan") + public Pager> getFunctionalCasePage(@Validated @RequestBody FunctionalCasePageRequest request) { + Boolean isRepeat = false; + if (StringUtils.isNotBlank(request.getTestPlanId())) { + isRepeat = testPlanConfigService.getConfigById(request.getTestPlanId()); + } + Page page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), + StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "pos desc"); + return PageUtils.setPageInfo(page, functionalCaseService.getFunctionalCasePage(request, false, isRepeat)); + } + +} diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanConfigService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanConfigService.java index a4158991a3..e77208a97a 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanConfigService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanConfigService.java @@ -1,5 +1,6 @@ package io.metersphere.plan.service; +import io.metersphere.plan.domain.TestPlanConfig; import io.metersphere.plan.domain.TestPlanConfigExample; import io.metersphere.plan.mapper.TestPlanConfigMapper; import jakarta.annotation.Resource; @@ -25,4 +26,9 @@ public class TestPlanConfigService { example.createCriteria().andTestPlanIdIn(testPlanIdList); testPlanConfigMapper.deleteByExample(example); } + + public boolean getConfigById(String testPlanId) { + TestPlanConfig testPlanConfig = testPlanConfigMapper.selectByPrimaryKey(testPlanId); + return testPlanConfig.getRepeatCase(); + } } diff --git a/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanAssociateControllerTests.java b/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanAssociateControllerTests.java new file mode 100644 index 0000000000..9231af8282 --- /dev/null +++ b/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanAssociateControllerTests.java @@ -0,0 +1,42 @@ +package io.metersphere.plan.controller; + +import io.metersphere.functional.request.FunctionalCasePageRequest; +import io.metersphere.sdk.util.JSON; +import io.metersphere.system.base.BaseTest; +import io.metersphere.system.controller.handler.ResultHolder; +import org.junit.jupiter.api.*; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.jdbc.Sql; +import org.springframework.test.context.jdbc.SqlConfig; +import org.springframework.test.web.servlet.MvcResult; + +import java.nio.charset.StandardCharsets; +import java.util.HashMap; + +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +@AutoConfigureMockMvc +public class TestPlanAssociateControllerTests extends BaseTest { + public static final String FUNCTIONAL_CASE_ASSOCIATION_URL = "/test-plan/association/page"; + + @Test + @Order(1) + @Sql(scripts = {"/dml/init_test_plan_association.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED)) + public void testGetPageList() throws Exception { + FunctionalCasePageRequest request = new FunctionalCasePageRequest(); + request.setProjectId("123"); + request.setCurrent(1); + request.setPageSize(10); + this.requestPost(FUNCTIONAL_CASE_ASSOCIATION_URL, request); + request.setSort(new HashMap<>() {{ + put("createTime", "desc"); + }}); + request.setTestPlanId("wxx_1"); + MvcResult mvcResult = this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_ASSOCIATION_URL, request); + String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); + ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class); + Assertions.assertNotNull(resultHolder); + + } +} diff --git a/backend/services/test-plan/src/test/resources/dml/init_test_plan_association.sql b/backend/services/test-plan/src/test/resources/dml/init_test_plan_association.sql new file mode 100644 index 0000000000..ec0842125e --- /dev/null +++ b/backend/services/test-plan/src/test/resources/dml/init_test_plan_association.sql @@ -0,0 +1,21 @@ +INSERT INTO `test_plan`(`id`, `num`, `project_id`, `group_id`, `module_id`, `name`, `status`, `type`, `tags`, `create_time`, `create_user`, `update_time`, `update_user`, `planned_start_time`, `planned_end_time`, `actual_start_time`, `actual_end_time`, `description`) +VALUES + ('wxx_1', 5000, '123', 'NONE', '1', 'qwe', 'PREPARED', 'TEST_PLAN', NULL, 1714980158000, 'WX', 1714980158000, 'WX', 1714980158000, 1714980158000, 1714980158000, 1714980158000, '11'), + ('wxx_2', 10000, '123', 'NONE', '1', 'eeew', 'PREPARED', 'TEST_PLAN', NULL, 1714980158000, 'WX', 1714980158000, 'WX', 1714980158000, 1714980158000, 1714980158000, 1714980158000, '11'); + + +INSERT INTO `test_plan_config`(`test_plan_id`, `automatic_status_update`, `repeat_case`, `pass_threshold`, `test_planning`) +VALUES + ('wxx_1', b'0', b'0', 100, b'0'), + ('wxx_2', b'0', b'0', 100, b'0'); + +INSERT INTO `test_plan_functional_case`(`id`, `test_plan_id`, `functional_case_id`, `create_time`, `create_user`, `execute_user`, `last_exec_time`, `last_exec_result`, `pos`) +VALUES ('wxx_tpfc_1', 'wxx_1', 'wxx_test_1', 1714980158000, 'admin', NULL, NULL, NULL, 1); + + +INSERT INTO functional_case(id, num, module_id, project_id, template_id, name, review_status, tags, case_edit_type, pos, version_id, ref_id, last_execute_result, deleted, public_case, latest, create_user, update_user, delete_user, create_time, update_time, delete_time) +VALUES + ('wxx_test_1', 1, '1', '123', '100001', '1111', 'UN_REVIEWED', NULL, 'TEXT', 55000, 'v3.0.0', 'TEST_FUNCTIONAL_MINDER_CASE_ID_7', 'UN_EXECUTED', b'0', b'0', b'1', 'admin', 'admin', '', 1698058347559, 1698058347559, NULL), + ('wxx_test_2', 2, '1', '123', '100001', '2222', 'UN_REVIEWED', NULL, 'TEXT', 55000, 'v3.0.0', 'TEST_FUNCTIONAL_MINDER_CASE_ID_7', 'UN_EXECUTED', b'0', b'0', b'1', 'admin', 'admin', '', 1698058347559, 1698058347559, NULL), + ('wxx_test_3', 3, 'root', '123', '100001', '3333', 'UN_REVIEWED', NULL, 'TEXT', 55000, 'v3.0.0', 'TEST_FUNCTIONAL_MINDER_CASE_ID_7', 'UN_EXECUTED', b'0', b'0', b'1', 'admin', 'admin', '', 1698058347559, 1698058347559, NULL); +