From 28a090f5dc33b099291c7afc4c32643511a75a2b Mon Sep 17 00:00:00 2001 From: WangXu10 Date: Tue, 15 Oct 2024 10:14:25 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E4=BB=BB=E5=8A=A1=E4=B8=AD=E5=BF=83):=20?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F&=E7=BB=84=E7=BB=87&=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E4=B8=AD=E5=BF=83=E5=88=A0=E9=99=A4=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E6=8E=A5=E5=8F=A3=E9=83=A8=E5=88=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ProjectTaskHubController.java | 10 +++ .../ProjectTaskHubControllerTests.java | 16 +++++ .../OrganizationTaskHubController.java | 9 +++ .../controller/SystemTaskHubController.java | 9 +++ .../system/mapper/ExtExecTaskMapper.java | 2 + .../system/mapper/ExtExecTaskMapper.xml | 14 ++++ .../system/service/BaseTaskHubLogService.java | 65 +++++++++++++++++++ .../system/service/BaseTaskHubService.java | 12 +++- .../BaseTaskHubControllerTests.java | 31 +++++++++ .../resources/dml/init_exec_task_test.sql | 3 +- 10 files changed, 169 insertions(+), 2 deletions(-) diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectTaskHubController.java b/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectTaskHubController.java index 13506c499a..79db30f523 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectTaskHubController.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectTaskHubController.java @@ -80,4 +80,14 @@ public class ProjectTaskHubController { public void stopTask(@PathVariable String id) { baseTaskHubService.stopTask(id, SessionUtils.getUserId(), null, SessionUtils.getCurrentProjectId()); } + + + @GetMapping("/exec-task/delete/{id}") + @Operation(summary = "项目-任务中心-用例执行任务-删除任务") + @Log(type = OperationLogType.DELETE, expression = "#msClass.projectDeleteLog(#id)", msClass = BaseTaskHubLogService.class) + @RequiresPermissions(PermissionConstants.PROJECT_CASE_TASK_CENTER_DELETE) + public void deleteTask(@PathVariable String id) { + + baseTaskHubService.deleteTask(id, null, SessionUtils.getCurrentProjectId()); + } } diff --git a/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectTaskHubControllerTests.java b/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectTaskHubControllerTests.java index d9db682145..2cd9dc7427 100644 --- a/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectTaskHubControllerTests.java +++ b/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectTaskHubControllerTests.java @@ -25,6 +25,7 @@ public class ProjectTaskHubControllerTests extends BaseTest { public static final String PROJECT_STATISTICS = "/project/task-center/exec-task/statistics"; public static final String PROJECT_RESOURCE_POOL_OPTIONS = "/project/task-center/resource-pool/options"; public static final String PROJECT_TASK_STOP = "/project/task-center/exec-task/stop/"; + public static final String PROJECT_TASK_DELETE = "/project/task-center/exec-task/delete/"; @Test @Order(1) @@ -121,4 +122,19 @@ public class ProjectTaskHubControllerTests extends BaseTest { // 返回请求正常 Assertions.assertNotNull(resultHolder); } + + + /** + * 项目执行任务删除 + */ + @Test + @Order(5) + public void projectTaskDelete() throws Exception { + MvcResult mvcResult = this.requestGetWithOkAndReturn(PROJECT_TASK_DELETE + "4"); + // 获取返回值 + String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); + ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class); + // 返回请求正常 + Assertions.assertNotNull(resultHolder); + } } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/OrganizationTaskHubController.java b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/OrganizationTaskHubController.java index 4611b4a58f..c6e3934c2e 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/OrganizationTaskHubController.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/OrganizationTaskHubController.java @@ -87,4 +87,13 @@ public class OrganizationTaskHubController { public void stopTask(@PathVariable String id) { baseTaskHubService.stopTask(id, SessionUtils.getUserId(), SessionUtils.getCurrentOrganizationId(), null); } + + + @GetMapping("/exec-task/delete/{id}") + @Operation(summary = "组织-任务中心-用例执行任务-删除任务") + @Log(type = OperationLogType.DELETE, expression = "#msClass.orgDeleteLog(#id)", msClass = BaseTaskHubLogService.class) + @RequiresPermissions(PermissionConstants.ORGANIZATION_CASE_TASK_CENTER_DELETE) + public void deleteTask(@PathVariable String id) { + baseTaskHubService.deleteTask(id, SessionUtils.getCurrentOrganizationId(), null); + } } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/SystemTaskHubController.java b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/SystemTaskHubController.java index 43abffd03e..7fc8a8a304 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/SystemTaskHubController.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/SystemTaskHubController.java @@ -89,6 +89,15 @@ public class SystemTaskHubController { baseTaskHubService.stopTask(id, SessionUtils.getUserId(), null, null); } + + @GetMapping("/exec-task/delete/{id}") + @Operation(summary = "系统-任务中心-用例执行任务-删除任务") + @Log(type = OperationLogType.DELETE, expression = "#msClass.systemDeleteLog(#id)", msClass = BaseTaskHubLogService.class) + @RequiresPermissions(PermissionConstants.SYSTEM_CASE_TASK_CENTER_DELETE) + public void deleteTask(@PathVariable String id) { + baseTaskHubService.deleteTask(id, null, null); + } + //TODO 系统&组织&项目 任务按钮操作:删除 停止 失败重跑 查看报告 批量删除 批量停止 批量失败重跑 diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskMapper.java b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskMapper.java index 2cc4f09b36..98dfb15e6a 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskMapper.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskMapper.java @@ -14,4 +14,6 @@ public interface ExtExecTaskMapper { List selectList(@Param("request") BasePageRequest request, @Param("orgId") String orgId, @Param("projectId") String projectId); void updateTaskStatus(@Param("execTask") ExecTask execTask); + + void deleteTaskById(@Param("id") String id, @Param("orgId") String orgId, @Param("projectId") String projectId); } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskMapper.xml b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskMapper.xml index 8c1384e6fa..9d3c67e44f 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskMapper.xml +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskMapper.xml @@ -32,5 +32,19 @@ and organization_id = #{execTask.organizationId} + and `status` = 'RUNNING' + + + DELETE + FROM exec_task + WHERE id = #{id} + + and project_id = #{projectId} + + + and organization_id = #{orgId} + + and `status` in ('PENDING', 'STOPPED', 'COMPLETED') + \ No newline at end of file diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseTaskHubLogService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseTaskHubLogService.java index cab2dacaea..d65469fe1d 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseTaskHubLogService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseTaskHubLogService.java @@ -89,4 +89,69 @@ public class BaseTaskHubLogService { return dto; } + + /** + * 系统删除任务日志 + * @param id + * @return + */ + public LogDTO systemDeleteLog(String id) { + ExecTask execTask = execTaskMapper.selectByPrimaryKey(id); + LogDTO dto = null; + if (execTask != null) { + dto = new LogDTO( + OperationLogConstants.SYSTEM, + OperationLogConstants.SYSTEM, + execTask.getId(), + null, + OperationLogType.DELETE.name(), + OperationLogModule.SETTING_SYSTEM_TASK_CENTER, + execTask.getTaskName()); + } + return dto; + } + + /** + * 组织删除任务日志 + * @param id + * @return + */ + public LogDTO orgDeleteLog(String id) { + ExecTask execTask = execTaskMapper.selectByPrimaryKey(id); + LogDTO dto = null; + if (execTask != null) { + dto = new LogDTO( + OperationLogConstants.ORGANIZATION, + null, + execTask.getId(), + null, + OperationLogType.DELETE.name(), + OperationLogModule.SETTING_ORGANIZATION_TASK_CENTER, + execTask.getTaskName()); + } + return dto; + } + + + /** + * 项目删除任务日志 + * @param id + * @return + */ + public LogDTO projectDeleteLog(String id) { + ExecTask execTask = execTaskMapper.selectByPrimaryKey(id); + LogDTO dto = null; + if (execTask != null) { + dto = new LogDTO( + null, + null, + execTask.getId(), + null, + OperationLogType.DELETE.name(), + OperationLogModule.PROJECT_MANAGEMENT_TASK_CENTER, + execTask.getTaskName()); + } + return dto; + } + } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseTaskHubService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseTaskHubService.java index 6b90468a20..1ef8b8c3a6 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseTaskHubService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseTaskHubService.java @@ -398,7 +398,7 @@ public class BaseTaskHubService { extExecTaskMapper.updateTaskStatus(execTask); //2.更新任务明细状态 ExecTaskItemExample itemExample = new ExecTaskItemExample(); - itemExample.createCriteria().andTaskIdEqualTo(id); + itemExample.createCriteria().andTaskIdEqualTo(id).andStatusEqualTo(ExecStatus.RUNNING.name()); ExecTaskItem execTaskItem = new ExecTaskItem(); execTaskItem.setStatus(ExecStatus.STOPPED.name()); execTaskItem.setExecutor(userId); @@ -407,4 +407,14 @@ public class BaseTaskHubService { } + + public void deleteTask(String id, String orgId, String projectId) { + //1.删除任务 + extExecTaskMapper.deleteTaskById(id, orgId, projectId); + //2.删除任务明细 + ExecTaskItemExample itemExample = new ExecTaskItemExample(); + itemExample.createCriteria().andTaskIdEqualTo(id); + execTaskItemMapper.deleteByExample(itemExample); + //TODO jmeter执行队列中移除 + } } diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/BaseTaskHubControllerTests.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/BaseTaskHubControllerTests.java index 53bc58aeef..b45c7bbe6e 100644 --- a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/BaseTaskHubControllerTests.java +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/BaseTaskHubControllerTests.java @@ -38,6 +38,7 @@ public class BaseTaskHubControllerTests extends BaseTest { public static final String SYSTEM_RESOURCE_POOL_OPTIONS = "/system/task-center/resource-pool/options"; public static final String SYSTEM_RESOURCE_POOL_STATUS = "/system/task-center/resource-pool/status"; public static final String SYSTEM_TASK_STOP = "/system/task-center/exec-task/stop/"; + public static final String SYSTEM_TASK_DELETE = "/system/task-center/exec-task/delete/"; @Test @Order(1) @@ -154,6 +155,21 @@ public class BaseTaskHubControllerTests extends BaseTest { } + /** + * 系统执行任务删除 + */ + @Test + @Order(4) + public void systemTaskDelete() throws Exception { + MvcResult mvcResult = this.requestGetWithOkAndReturn(SYSTEM_TASK_DELETE + "4"); + // 获取返回值 + String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); + ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class); + // 返回请求正常 + Assertions.assertNotNull(resultHolder); + } + + /** * 组织任务中心测试用例 */ @@ -163,6 +179,7 @@ public class BaseTaskHubControllerTests extends BaseTest { public static final String ORG_STATISTICS = "/organization/task-center/exec-task/statistics"; public static final String ORG_RESOURCE_POOL_OPTIONS = "/organization/task-center/resource-pool/options"; public static final String ORG_TASK_STOP = "/organization/task-center/exec-task/stop/"; + public static final String ORG_TASK_DELETE = "/organization/task-center/exec-task/delete/"; @Test @Order(20) @@ -259,6 +276,20 @@ public class BaseTaskHubControllerTests extends BaseTest { Assertions.assertNotNull(resultHolder); } + /** + * 组织执行任务删除 + */ + @Test + @Order(5) + public void orgTaskDelete() throws Exception { + MvcResult mvcResult = this.requestGetWithOkAndReturn(ORG_TASK_DELETE + "4"); + // 获取返回值 + String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); + ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class); + // 返回请求正常 + Assertions.assertNotNull(resultHolder); + } + @Test diff --git a/backend/services/system-setting/src/test/resources/dml/init_exec_task_test.sql b/backend/services/system-setting/src/test/resources/dml/init_exec_task_test.sql index 7a551fd87d..e281df6211 100644 --- a/backend/services/system-setting/src/test/resources/dml/init_exec_task_test.sql +++ b/backend/services/system-setting/src/test/resources/dml/init_exec_task_test.sql @@ -2,7 +2,8 @@ INSERT INTO `exec_task`(`id`, `num`, `task_name`, `status`, `case_count`, `resul VALUES ('1', 1, '测试任务1', 'SUCCESS', 10, 'SUCCESS', 'FUNCTIONAL', 'API', '100001100001', '100001', 1727676089639, 'wx', 1727676089639, 1727676089639), ('2', 2, '测试任务2', 'SUCCESS', 11, 'SUCCESS', 'FUNCTIONAL', 'API', '12345567', '11234', 1727676089639, 'wx', 1727676089639, 1727676089639), - ('3', 3, '测试任务3', 'SUCCESS', 11, 'SUCCESS', 'FUNCTIONAL', 'API', '100001100001', '11234', 1727676089639, 'wx', 1727676089639, 1727676089639); + ('3', 3, '测试任务3', 'SUCCESS', 11, 'SUCCESS', 'FUNCTIONAL', 'API', '100001100001', '11234', 1727676089639, 'wx', 1727676089639, 1727676089639), + ('4', 4, '删除任务4', 'SUCCESS', 11, 'SUCCESS', 'FUNCTIONAL', 'API', '100001100001', '11234', 1727676089639, 'wx', 1727676089639, 1727676089639);