From bc4fed955345e4ad71255b29da845f2388c56d5a Mon Sep 17 00:00:00 2001 From: WangXu10 Date: Thu, 16 May 2024 16:30:16 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92):=20?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92-?= =?UTF-8?q?=E7=94=A8=E4=BE=8B=E8=AF=A6=E6=83=85-=E8=A1=8C=E5=86=85?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E6=89=A7=E8=A1=8C=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TestPlanFunctionalCaseController.java | 8 +++++ .../dto/request/TestPlanCaseEditRequest.java | 31 +++++++++++++++++++ .../TestPlanFunctionalCaseService.java | 27 ++++++++++++++++ .../TestPlanCaseControllerTests.java | 12 +++++++ 4 files changed, 78 insertions(+) create mode 100644 backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanCaseEditRequest.java 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 c7bc4567d7..d52fe0cfe6 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 @@ -170,4 +170,12 @@ public class TestPlanFunctionalCaseController { return testPlanFunctionalCaseService.getCaseExecHistory(request); } + + @PostMapping("/edit") + @Operation(summary = "测试计划-计划详情-功能用例-编辑执行结果") + @RequiresPermissions(PermissionConstants.TEST_PLAN_READ_UPDATE) + @CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan") + public void editFunctionalCase(@Validated @RequestBody TestPlanCaseEditRequest request) { + testPlanFunctionalCaseService.editFunctionalCase(request, SessionUtils.getUserId()); + } } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanCaseEditRequest.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanCaseEditRequest.java new file mode 100644 index 0000000000..b967c0c96b --- /dev/null +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanCaseEditRequest.java @@ -0,0 +1,31 @@ +package io.metersphere.plan.dto.request; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotBlank; +import lombok.Data; + +import java.io.Serial; +import java.io.Serializable; + +/** + * @author wx + */ +@Data +public class TestPlanCaseEditRequest implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + @Schema(description = "测试计划id",requiredMode = Schema.RequiredMode.REQUIRED) + @NotBlank(message = "{test_plan.id.not_blank}") + private String testPlanId; + + @Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED) + @NotBlank(message = "{id.not_blank}") + private String id; + + @Schema(description = "最终执行结果") + @NotBlank(message = "{test_plan.last_exec_result.not_blank}") + private String lastExecResult; + +} 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 6e1093abcc..705bc5482e 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 @@ -567,4 +567,31 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService { }); return list; } + + + public void editFunctionalCase(TestPlanCaseEditRequest request, String userId) { + TestPlanFunctionalCase planFunctionalCase = testPlanFunctionalCaseMapper.selectByPrimaryKey(request.getId()); + TestPlanFunctionalCase functionalCase = new TestPlanFunctionalCase(); + functionalCase.setId(request.getId()); + functionalCase.setLastExecResult(request.getLastExecResult()); + functionalCase.setLastExecTime(System.currentTimeMillis()); + testPlanFunctionalCaseMapper.updateByPrimaryKeySelective(functionalCase); + + updateFunctionalCaseStatus(Arrays.asList(planFunctionalCase.getFunctionalCaseId()), request.getLastExecResult()); + + //执行历史 + TestPlanCaseExecuteHistory executeHistory = new TestPlanCaseExecuteHistory(); + executeHistory.setId(IDGenerator.nextStr()); + executeHistory.setTestPlanCaseId(planFunctionalCase.getId()); + executeHistory.setCaseId(planFunctionalCase.getFunctionalCaseId()); + executeHistory.setStatus(request.getLastExecResult()); + executeHistory.setDeleted(false); + executeHistory.setCreateUser(userId); + executeHistory.setCreateTime(System.currentTimeMillis()); + testPlanCaseExecuteHistoryMapper.insert(executeHistory); + + //通知 + handleFileAndNotice(planFunctionalCase.getFunctionalCaseId(), null, null, userId, null, null, request.getTestPlanId(), request.getLastExecResult()); + + } } 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 ff1deb68cc..0bec654943 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 @@ -44,6 +44,7 @@ public class TestPlanCaseControllerTests extends BaseTest { 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"; public static final String FUNCTIONAL_CASE_EXEC_HISTORY_URL = "/test-plan/functional/case/exec/history"; + public static final String FUNCTIONAL_CASE_EDIT_URL = "/test-plan/functional/case/edit"; @Resource private TestPlanFunctionalCaseMapper testPlanFunctionalCaseMapper; @Resource @@ -239,4 +240,15 @@ public class TestPlanCaseControllerTests extends BaseTest { request.setCaseId("fc_1"); this.requestPostWithOk(FUNCTIONAL_CASE_EXEC_HISTORY_URL, request); } + + + @Test + @Order(15) + public void testFunctionalCaseEdit() throws Exception { + TestPlanCaseEditRequest request = new TestPlanCaseEditRequest(); + request.setId("relate_case_1"); + request.setTestPlanId("plan_1"); + request.setLastExecResult("SUCCESS"); + this.requestPostWithOk(FUNCTIONAL_CASE_EDIT_URL, request); + } }