From 754f107737adc1bfa6f56afa59cd62890f22458a Mon Sep 17 00:00:00 2001 From: WangXu10 Date: Fri, 11 Oct 2024 17:45:05 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E4=BB=BB=E5=8A=A1=E4=B8=AD=E5=BF=83):=20?= =?UTF-8?q?=E7=BB=84=E7=BB=87&=E9=A1=B9=E7=9B=AE=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E4=BB=BB=E5=8A=A1=E5=88=97=E8=A1=A8=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=BB=9F=E8=AE=A1=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ProjectTaskHubController.java | 13 ++++++++++++- .../controller/ProjectTaskHubControllerTests.java | 15 +++++++++++++++ .../controller/OrganizationTaskHubController.java | 12 ++++++++++++ .../controller/SystemTaskHubController.java | 4 ++-- .../system/mapper/ExtExecTaskItemMapper.java | 2 +- .../system/mapper/ExtExecTaskItemMapper.xml | 13 +++++++++++-- .../system/service/BaseTaskHubService.java | 6 ++++-- .../controller/BaseTaskHubControllerTests.java | 14 ++++++++++++++ 8 files changed, 71 insertions(+), 8 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 968cce5795..193bbb1669 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 @@ -2,15 +2,17 @@ package io.metersphere.project.controller; import io.metersphere.sdk.constants.PermissionConstants; import io.metersphere.system.dto.sdk.BasePageRequest; -import io.metersphere.system.dto.sdk.OptionDTO; import io.metersphere.system.dto.taskhub.TaskHubDTO; import io.metersphere.system.dto.taskhub.TaskHubItemDTO; import io.metersphere.system.dto.taskhub.TaskHubScheduleDTO; import io.metersphere.system.dto.taskhub.request.TaskHubItemRequest; +import io.metersphere.system.dto.taskhub.response.TaskStatisticsResponse; import io.metersphere.system.service.BaseTaskHubService; 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.Parameter; +import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.Resource; import org.apache.shiro.authz.annotation.RequiresPermissions; @@ -51,4 +53,13 @@ public class ProjectTaskHubController { public Pager> itemPageList(@Validated @RequestBody TaskHubItemRequest request) { return baseTaskHubService.getCaseTaskItemList(request, null, SessionUtils.getCurrentProjectId()); } + + + @PostMapping("/exec-task/statistics") + @Operation(summary = "项目-任务中心-获取任务统计{通过率}接口") + @RequiresPermissions(PermissionConstants.PROJECT_CASE_TASK_CENTER_READ) + @Parameter(name = "ids", description = "任务ID集合", schema = @Schema(requiredMode = Schema.RequiredMode.REQUIRED)) + public List calculateRate(@RequestBody List ids) { + return baseTaskHubService.calculateRate(ids, 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 d87bab1940..07315dac33 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 @@ -13,6 +13,7 @@ import org.springframework.test.context.jdbc.SqlConfig; import org.springframework.test.web.servlet.MvcResult; import java.nio.charset.StandardCharsets; +import java.util.List; public class ProjectTaskHubControllerTests extends BaseTest { /** @@ -21,6 +22,7 @@ public class ProjectTaskHubControllerTests extends BaseTest { public static final String PROJECT_TASK_PAGE = "/project/task-center/exec-task/page"; public static final String PROJECT_SCHEDULE_TASK_PAGE = "/project/task-center/schedule/page"; public static final String PROJECT_TASK_ITEM_PAGE = "/project/task-center/exec-task/item/page"; + public static final String PROJECT_STATISTICS = "/project/task-center/exec-task/statistics"; @Test @Order(1) @@ -76,4 +78,17 @@ public class ProjectTaskHubControllerTests extends BaseTest { // 返回请求正常 Assertions.assertNotNull(resultHolder); } + + + @Test + @Order(4) + public void getProStatistics() throws Exception { + List ids = List.of("pro_1","pro_2"); + MvcResult mvcResult = this.requestPostWithOkAndReturn(PROJECT_STATISTICS, ids); + // 获取返回值 + 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 73d1340ea8..7aac27af9a 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 @@ -7,11 +7,14 @@ import io.metersphere.system.dto.taskhub.TaskHubDTO; import io.metersphere.system.dto.taskhub.TaskHubItemDTO; import io.metersphere.system.dto.taskhub.TaskHubScheduleDTO; import io.metersphere.system.dto.taskhub.request.TaskHubItemRequest; +import io.metersphere.system.dto.taskhub.response.TaskStatisticsResponse; import io.metersphere.system.mapper.BaseProjectMapper; import io.metersphere.system.service.BaseTaskHubService; 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.Parameter; +import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.Resource; import org.apache.shiro.authz.annotation.RequiresPermissions; @@ -57,4 +60,13 @@ public class OrganizationTaskHubController { public Pager> itemPageList(@Validated @RequestBody TaskHubItemRequest request) { return baseTaskHubService.getCaseTaskItemList(request, SessionUtils.getCurrentOrganizationId(), null); } + + + @PostMapping("/exec-task/statistics") + @Operation(summary = "组织-任务中心-获取任务统计{通过率}接口") + @RequiresPermissions(PermissionConstants.ORGANIZATION_CASE_TASK_CENTER_READ) + @Parameter(name = "ids", description = "任务ID集合", schema = @Schema(requiredMode = Schema.RequiredMode.REQUIRED)) + public List calculateRate(@RequestBody List ids) { + return baseTaskHubService.calculateRate(ids, 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 173a8a5246..f25a171def 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 @@ -58,7 +58,7 @@ public class SystemTaskHubController { @Operation(summary = "系统-任务中心-获取任务统计{通过率}接口") @RequiresPermissions(PermissionConstants.SYSTEM_CASE_TASK_CENTER_READ) @Parameter(name = "ids", description = "任务ID集合", schema = @Schema(requiredMode = Schema.RequiredMode.REQUIRED)) - public List selectTestPlanMetricById(@RequestBody List ids) { - return baseTaskHubService.calculateRate(ids); + public List calculateRate(@RequestBody List ids) { + return baseTaskHubService.calculateRate(ids, null, null); } } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskItemMapper.java b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskItemMapper.java index 281baa10fb..302fa07731 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskItemMapper.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskItemMapper.java @@ -15,5 +15,5 @@ import java.util.List; public interface ExtExecTaskItemMapper { List selectList(@Param("request") TaskHubItemRequest request, @Param("orgId") String orgId, @Param("projectId") String projectId); - List selectItemByTaskIds(@Param("taskIds") List taskIds); + List selectItemByTaskIds(@Param("taskIds") List taskIds, @Param("orgId") String orgId, @Param("projectId") String projectId); } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskItemMapper.xml b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskItemMapper.xml index f5313edaed..986ea339a1 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskItemMapper.xml +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskItemMapper.xml @@ -12,12 +12,15 @@ or exec_task_item.resource_name like concat('%', #{request.keyword},'%') ) - + and exec_task_item.organization_id = #{orgId} - + and exec_task_item.project_id = #{projectId} + + and exec_task_item.resource_pool_id = #{request.resourcePoolId} + @@ -28,6 +31,12 @@ #{taskId} + + and exec_task_item.organization_id = #{orgId} + + + and exec_task_item.project_id = #{projectId} + \ No newline at end of file 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 7466e6ad00..f9e8220708 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 @@ -185,11 +185,13 @@ public class BaseTaskHubService { * 计算任务通过率和执行进度 * * @param taskIds + * @param orgId + * @param projectId * @return */ - public List calculateRate(List taskIds) { + public List calculateRate(List taskIds, String orgId, String projectId) { List responseList = new ArrayList<>(); - List taskItemList = extExecTaskItemMapper.selectItemByTaskIds(taskIds); + List taskItemList = extExecTaskItemMapper.selectItemByTaskIds(taskIds, orgId, projectId); Map> taskItems = taskItemList.stream().collect(Collectors.groupingBy(ExecTaskItem::getTaskId)); taskItems.forEach((taskId, items) -> { //成功数量 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 bb43bfe1f5..83a43f3a9e 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 @@ -113,6 +113,7 @@ public class BaseTaskHubControllerTests extends BaseTest { public static final String ORG_TASK_PAGE = "/organization/task-center/exec-task/page"; public static final String ORG_SCHEDULE_TASK_PAGE = "/organization/task-center/schedule/page"; public static final String ORG_TASK_ITEM_PAGE = "/organization/task-center/exec-task/item/page"; + public static final String ORG_STATISTICS = "/organization/task-center/exec-task/statistics"; @Test @Order(20) @@ -169,6 +170,19 @@ public class BaseTaskHubControllerTests extends BaseTest { } + @Test + @Order(4) + public void getOrgStatistics() throws Exception { + List ids = List.of("1","2"); + MvcResult mvcResult = this.requestPostWithOkAndReturn(ORG_STATISTICS, ids); + // 获取返回值 + String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); + ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class); + // 返回请求正常 + Assertions.assertNotNull(resultHolder); + } + + @Test