From 58140fb2b707afc5f7ed3dc7932af5e99746bef5 Mon Sep 17 00:00:00 2001 From: WangXu10 Date: Tue, 14 May 2024 18:06:28 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92):=20?= =?UTF-8?q?=E6=89=B9=E9=87=8F=E4=BF=AE=E6=94=B9=E6=89=A7=E8=A1=8C=E4=BA=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/resources/i18n/plan_en_US.properties | 3 +- .../main/resources/i18n/plan_zh_CN.properties | 3 +- .../main/resources/i18n/plan_zh_TW.properties | 3 +- .../TestPlanFunctionalCaseController.java | 12 ++++ .../request/TestPlanCaseUpdateRequest.java | 17 +++++ .../ExtTestPlanFunctionalCaseMapper.java | 4 +- .../ExtTestPlanFunctionalCaseMapper.xml | 62 +++------------- .../plan/service/TestPlanCaseLogService.java | 71 +++++++++++++++++++ .../TestPlanFunctionalCaseService.java | 31 ++++---- .../TestPlanCaseControllerTests.java | 17 +++++ 10 files changed, 150 insertions(+), 73 deletions(-) create mode 100644 backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanCaseUpdateRequest.java create mode 100644 backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanCaseLogService.java diff --git a/backend/framework/sdk/src/main/resources/i18n/plan_en_US.properties b/backend/framework/sdk/src/main/resources/i18n/plan_en_US.properties index 8e437cc1e3..ed0ce155e8 100644 --- a/backend/framework/sdk/src/main/resources/i18n/plan_en_US.properties +++ b/backend/framework/sdk/src/main/resources/i18n/plan_en_US.properties @@ -97,4 +97,5 @@ log.test_plan.api_scenario=Api scenario test_plan.type.not_blank=Test plan type cannot be empty test_plan.group.not_plan=There are no archived plans in the current testing plan group test_plan_group.batch.log={0} test plan group -test_plan.batch.log={0} plan \ No newline at end of file +test_plan.batch.log={0} plan +run_functional_case=Run functional case \ No newline at end of file diff --git a/backend/framework/sdk/src/main/resources/i18n/plan_zh_CN.properties b/backend/framework/sdk/src/main/resources/i18n/plan_zh_CN.properties index 5b9e9d150c..f51741e6c6 100644 --- a/backend/framework/sdk/src/main/resources/i18n/plan_zh_CN.properties +++ b/backend/framework/sdk/src/main/resources/i18n/plan_zh_CN.properties @@ -97,4 +97,5 @@ log.test_plan.api_scenario=接口场景 test_plan.type.not_blank=测试计划类型不能为空 test_plan.group.not_plan=当前测试计划组没有可归档计划 test_plan_group.batch.log={0}测试计划组 -test_plan.batch.log={0}测试计划 \ No newline at end of file +test_plan.batch.log={0}测试计划 +run_functional_case=执行功能用例 \ No newline at end of file diff --git a/backend/framework/sdk/src/main/resources/i18n/plan_zh_TW.properties b/backend/framework/sdk/src/main/resources/i18n/plan_zh_TW.properties index 731a8aba83..967577eabb 100644 --- a/backend/framework/sdk/src/main/resources/i18n/plan_zh_TW.properties +++ b/backend/framework/sdk/src/main/resources/i18n/plan_zh_TW.properties @@ -97,4 +97,5 @@ log.test_plan.api_scenario=接口場景 test_plan.type.not_blank=測試計劃類型不能為空 test_plan.group.not_plan=當前測試計劃組沒有可歸檔計劃 test_plan_group.batch.log={0}測試計劃組 -test_plan.batch.log={0}測試計劃 \ No newline at end of file +test_plan.batch.log={0}測試計劃 +run_functional_case=執行功能用例 \ No newline at end of file diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanFunctionalCaseController.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanFunctionalCaseController.java index 1f20c58158..289310bbf9 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanFunctionalCaseController.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanFunctionalCaseController.java @@ -8,6 +8,7 @@ import io.metersphere.plan.dto.request.*; import io.metersphere.plan.dto.response.TestPlanAssociationResponse; import io.metersphere.plan.dto.response.TestPlanCasePageResponse; import io.metersphere.plan.dto.response.TestPlanResourceSortResponse; +import io.metersphere.plan.service.TestPlanCaseLogService; import io.metersphere.plan.service.TestPlanFunctionalCaseService; import io.metersphere.plan.service.TestPlanManagementService; import io.metersphere.request.AssociateBugPageRequest; @@ -149,4 +150,15 @@ public class TestPlanFunctionalCaseController { return PageUtils.setPageInfo(page, testPlanFunctionalCaseService.hasAssociateBugPage(request)); } + + @PostMapping("/batch/update/executor") + @Operation(summary = "测试计划-计划详情-功能用例-批量更新执行人") + @RequiresPermissions(PermissionConstants.TEST_PLAN_READ_UPDATE) + @CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan") + @Log(type = OperationLogType.DISASSOCIATE, expression = "#msClass.batchUpdateExecutor(#request)", msClass = TestPlanCaseLogService.class) + public void batchUpdateExecutor(@Validated @RequestBody TestPlanCaseUpdateRequest request) { + testPlanFunctionalCaseService.batchUpdateExecutor(request); + } + + } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanCaseUpdateRequest.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanCaseUpdateRequest.java new file mode 100644 index 0000000000..73e4bdfc50 --- /dev/null +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanCaseUpdateRequest.java @@ -0,0 +1,17 @@ +package io.metersphere.plan.dto.request; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotBlank; +import lombok.Data; + + +/** + * @author wx + */ +@Data +public class TestPlanCaseUpdateRequest extends BasePlanCaseBatchRequest { + + @Schema(description = "执行人id", requiredMode = Schema.RequiredMode.REQUIRED) + @NotBlank(message = "{test_plan.user_id.not_blank}") + private String userId; +} diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanFunctionalCaseMapper.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanFunctionalCaseMapper.java index 16003adc98..40f92cd9c6 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanFunctionalCaseMapper.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanFunctionalCaseMapper.java @@ -48,7 +48,7 @@ public interface ExtTestPlanFunctionalCaseMapper { */ List getPlanFunctionalCaseByIds(@Param("planIds") List planIds); - List selectIdByConditions(@Param("request") BasePlanCaseBatchRequest request, @Param("projectId") String projectId); - void batchUpdate(@Param("ids") List ids, @Param("lastExecResult") String lastExecResult, @Param("lastExecTime") long lastExecTime, @Param("userId") String userId); + + void batchUpdateExecutor(@Param("ids") List ids, @Param("userId") String userId); } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanFunctionalCaseMapper.xml b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanFunctionalCaseMapper.xml index d7317bc251..cac6dbb0bb 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanFunctionalCaseMapper.xml +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanFunctionalCaseMapper.xml @@ -481,58 +481,6 @@ - - - - - - and functional_case.module_id in - - #{moduleId} - - - - and ( - functional_case.name like concat('%', #{request.condition.keyword},'%') - or functional_case.num like concat('%', #{request.condition.keyword},'%') - or functional_case.tags like concat('%', #{request.condition.keyword},'%') - ) - - - - - - - AND - - - and ( - - ) - - - - - - - - - - - - 1=1 - - - update test_plan_functional_case set last_exec_result = #{lastExecResult}, @@ -543,4 +491,14 @@ #{id} + + + update test_plan_functional_case + set execute_user = #{userId} + where id in + + #{id} + + + \ No newline at end of file diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanCaseLogService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanCaseLogService.java new file mode 100644 index 0000000000..d4e6801ec6 --- /dev/null +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanCaseLogService.java @@ -0,0 +1,71 @@ +package io.metersphere.plan.service; + +import io.metersphere.functional.domain.FunctionalCase; +import io.metersphere.functional.domain.FunctionalCaseExample; +import io.metersphere.functional.mapper.FunctionalCaseMapper; +import io.metersphere.plan.domain.TestPlanFunctionalCase; +import io.metersphere.plan.domain.TestPlanFunctionalCaseExample; +import io.metersphere.plan.dto.request.TestPlanCaseUpdateRequest; +import io.metersphere.plan.mapper.TestPlanFunctionalCaseMapper; +import io.metersphere.sdk.constants.HttpMethodConstants; +import io.metersphere.sdk.util.JSON; +import io.metersphere.system.log.constants.OperationLogModule; +import io.metersphere.system.log.constants.OperationLogType; +import io.metersphere.system.log.dto.LogDTO; +import jakarta.annotation.Resource; +import org.apache.commons.collections.CollectionUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +@Service +@Transactional(rollbackFor = Exception.class) +public class TestPlanCaseLogService { + + @Resource + private TestPlanFunctionalCaseService testPlanFunctionalCaseService; + @Resource + private TestPlanFunctionalCaseMapper testPlanFunctionalCaseMapper; + @Resource + private FunctionalCaseMapper functionalCaseMapper; + + public void batchUpdateExecutor(TestPlanCaseUpdateRequest request) { + List ids = testPlanFunctionalCaseService.doSelectIds(request); + if (CollectionUtils.isNotEmpty(ids)) { + TestPlanFunctionalCaseExample example = new TestPlanFunctionalCaseExample(); + example.createCriteria().andIdIn(ids); + List planCaseList = testPlanFunctionalCaseMapper.selectByExample(example); + Map userMap = planCaseList.stream().collect(Collectors.toMap(TestPlanFunctionalCase::getId, TestPlanFunctionalCase::getExecuteUser)); + Map idsMap = planCaseList.stream().collect(Collectors.toMap(TestPlanFunctionalCase::getId, TestPlanFunctionalCase::getFunctionalCaseId)); + List caseIds = planCaseList.stream().map(TestPlanFunctionalCase::getFunctionalCaseId).collect(Collectors.toList()); + FunctionalCaseExample caseExample = new FunctionalCaseExample(); + caseExample.createCriteria().andIdIn(caseIds); + List functionalCases = functionalCaseMapper.selectByExample(caseExample); + Map caseMap = functionalCases.stream().collect(Collectors.toMap(FunctionalCase::getId, FunctionalCase::getName)); + List dtoList = new ArrayList<>(); + idsMap.forEach((k, v) -> { + LogDTO dto = new LogDTO( + null, + null, + k, + null, + OperationLogType.UPDATE.name(), + OperationLogModule.TEST_PLAN, + caseMap.get(v)); + dto.setPath("/test-plan/functional/case/batch/update/executer"); + dto.setMethod(HttpMethodConstants.POST.name()); + dto.setOriginalValue(JSON.toJSONBytes(userMap.get(k))); + dto.setModifiedValue(JSON.toJSONBytes(request.getUserId())); + dtoList.add(dto); + }); + } + } + +} + + + diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanFunctionalCaseService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanFunctionalCaseService.java index 4c03b30ea7..b28357ab03 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanFunctionalCaseService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanFunctionalCaseService.java @@ -302,7 +302,7 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService { this::deleteTestPlanResource); } - private List doSelectIds(BasePlanCaseBatchRequest request) { + public List doSelectIds(BasePlanCaseBatchRequest request) { if (request.isSelectAll()) { List ids = extTestPlanFunctionalCaseMapper.getIds(request, false); if (CollectionUtils.isNotEmpty(request.getExcludeIds())) { @@ -411,7 +411,6 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService { } - /** * 批量执行功能用例 * @@ -419,7 +418,7 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService { * @param logInsertModule */ public void batchRun(TestPlanCaseBatchRunRequest request, String organizationId, LogInsertModule logInsertModule) { - List ids = doSelectIds(request, request.getProjectId()); + List ids = doSelectIds(request); if (CollectionUtils.isNotEmpty(ids)) { handleBatchRun(ids, organizationId, request, logInsertModule); } @@ -488,19 +487,6 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService { } - public List doSelectIds(BasePlanCaseBatchRequest request, String projectId) { - if (request.isSelectAll()) { - List ids = extTestPlanFunctionalCaseMapper.selectIdByConditions(request, projectId); - if (CollectionUtils.isNotEmpty(request.getExcludeIds())) { - ids.removeAll(request.getExcludeIds()); - } - return ids; - } else { - return request.getSelectIds(); - } - } - - public List runLog(Map idsMap, List caseIds, String projectId, String organizationId, ResourceLogInsertModule logInsertModule) { FunctionalCaseExample example = new FunctionalCaseExample(); example.createCriteria().andIdIn(caseIds); @@ -523,4 +509,17 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService { }); return list; } + + + /** + * 批量更新执行人 + * + * @param request + */ + public void batchUpdateExecutor(TestPlanCaseUpdateRequest request) { + List ids = doSelectIds(request); + if (CollectionUtils.isNotEmpty(ids)) { + extTestPlanFunctionalCaseMapper.batchUpdateExecutor(ids, request.getUserId()); + } + } } diff --git a/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanCaseControllerTests.java b/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanCaseControllerTests.java index e69b1b634f..fae33ee59f 100644 --- a/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanCaseControllerTests.java +++ b/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanCaseControllerTests.java @@ -42,6 +42,7 @@ public class TestPlanCaseControllerTests extends BaseTest { public static final String FUNCTIONAL_CASE_RUN_URL = "/test-plan/functional/case/run"; public static final String FUNCTIONAL_CASE_BATCH_RUN_URL = "/test-plan/functional/case/batch/run"; + public static final String FUNCTIONAL_CASE_BATCH_UPDATE_EXECUTOR_URL = "/test-plan/functional/case/batch/update/executor"; @Resource private TestPlanFunctionalCaseMapper testPlanFunctionalCaseMapper; @Resource @@ -211,4 +212,20 @@ public class TestPlanCaseControllerTests extends BaseTest { this.requestPostWithOk(FUNCTIONAL_CASE_BATCH_RUN_URL, request); } + + + @Test + @Order(13) + public void testBatchUpdateExecutor() throws Exception { + TestPlanCaseUpdateRequest request = new TestPlanCaseUpdateRequest(); + request.setUserId("test_user"); + request.setTestPlanId("plan_4"); + request.setSelectAll(true); + this.requestPostWithOk(FUNCTIONAL_CASE_BATCH_UPDATE_EXECUTOR_URL, request); + request.setTestPlanId("plan_2"); + request.setSelectAll(false); + request.setSelectIds(List.of("relate_case_3")); + this.requestPostWithOk(FUNCTIONAL_CASE_BATCH_UPDATE_EXECUTOR_URL, request); + + } }