feat(任务中心): 组织&项目用例执行任务列表数据统计接口

This commit is contained in:
WangXu10 2024-10-11 17:45:05 +08:00 committed by Craftsman
parent 97ae904911
commit 754f107737
8 changed files with 71 additions and 8 deletions

View File

@ -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<List<TaskHubItemDTO>> 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<TaskStatisticsResponse> calculateRate(@RequestBody List<String> ids) {
return baseTaskHubService.calculateRate(ids, null, SessionUtils.getCurrentProjectId());
}
}

View File

@ -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<String> 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);
}
}

View File

@ -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<List<TaskHubItemDTO>> 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<TaskStatisticsResponse> calculateRate(@RequestBody List<String> ids) {
return baseTaskHubService.calculateRate(ids, SessionUtils.getCurrentOrganizationId(), null);
}
}

View File

@ -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<TaskStatisticsResponse> selectTestPlanMetricById(@RequestBody List<String> ids) {
return baseTaskHubService.calculateRate(ids);
public List<TaskStatisticsResponse> calculateRate(@RequestBody List<String> ids) {
return baseTaskHubService.calculateRate(ids, null, null);
}
}

View File

@ -15,5 +15,5 @@ import java.util.List;
public interface ExtExecTaskItemMapper {
List<TaskHubItemDTO> selectList(@Param("request") TaskHubItemRequest request, @Param("orgId") String orgId, @Param("projectId") String projectId);
List<ExecTaskItem> selectItemByTaskIds(@Param("taskIds") List<String> taskIds);
List<ExecTaskItem> selectItemByTaskIds(@Param("taskIds") List<String> taskIds, @Param("orgId") String orgId, @Param("projectId") String projectId);
}

View File

@ -12,12 +12,15 @@
or exec_task_item.resource_name like concat('%', #{request.keyword},'%')
)
</if>
<if test="orgId != null">
<if test="orgId != null and orgId != ''">
and exec_task_item.organization_id = #{orgId}
</if>
<if test="projectId != null">
<if test="projectId != null and projectId != ''">
and exec_task_item.project_id = #{projectId}
</if>
<if test="request.resourcePoolId != null and request.resourcePoolId != ''">
and exec_task_item.resource_pool_id = #{request.resourcePoolId}
</if>
</where>
</select>
@ -28,6 +31,12 @@
<foreach collection="taskIds" item="taskId" open="(" separator="," close=")">
#{taskId}
</foreach>
<if test="orgId != null and orgId != ''">
and exec_task_item.organization_id = #{orgId}
</if>
<if test="projectId != null and projectId != ''">
and exec_task_item.project_id = #{projectId}
</if>
</select>
</mapper>

View File

@ -185,11 +185,13 @@ public class BaseTaskHubService {
* 计算任务通过率和执行进度
*
* @param taskIds
* @param orgId
* @param projectId
* @return
*/
public List<TaskStatisticsResponse> calculateRate(List<String> taskIds) {
public List<TaskStatisticsResponse> calculateRate(List<String> taskIds, String orgId, String projectId) {
List<TaskStatisticsResponse> responseList = new ArrayList<>();
List<ExecTaskItem> taskItemList = extExecTaskItemMapper.selectItemByTaskIds(taskIds);
List<ExecTaskItem> taskItemList = extExecTaskItemMapper.selectItemByTaskIds(taskIds, orgId, projectId);
Map<String, List<ExecTaskItem>> taskItems = taskItemList.stream().collect(Collectors.groupingBy(ExecTaskItem::getTaskId));
taskItems.forEach((taskId, items) -> {
//成功数量

View File

@ -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<String> 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