From 7f8faea704130d9f272684dd3f0c35133c048389 Mon Sep 17 00:00:00 2001 From: song-cc-rock Date: Mon, 21 Oct 2024 16:20:11 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E4=BB=BB=E5=8A=A1=E4=B8=AD=E5=BF=83):=20?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E5=88=97=E8=A1=A8=E8=A1=A5=E5=85=85=E6=8A=A5?= =?UTF-8?q?=E5=91=8AID?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/dto/taskhub/TaskHubDTO.java | 3 +++ .../system/service/BaseTaskHubService.java | 25 ++++++++++++------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/taskhub/TaskHubDTO.java b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/taskhub/TaskHubDTO.java index 07d9ed13be..ab8436e2ac 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/taskhub/TaskHubDTO.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/taskhub/TaskHubDTO.java @@ -21,4 +21,7 @@ public class TaskHubDTO extends ExecTask { @Schema(description = "操作人名称") private String createUserName; + @Schema(description = "报告ID") + private String reportId; + } 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 c2bf606d7f..d96ba646a4 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 @@ -2,6 +2,7 @@ package io.metersphere.system.service; import com.github.pagehelper.Page; import com.github.pagehelper.page.PageMethod; +import io.metersphere.api.domain.ApiReportRelateTask; import io.metersphere.api.domain.ApiReportRelateTaskExample; import io.metersphere.api.mapper.ApiReportRelateTaskMapper; import io.metersphere.engine.EngineFactory; @@ -16,14 +17,6 @@ import io.metersphere.sdk.constants.*; import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.util.*; import io.metersphere.system.controller.handler.ResultHolder; -import io.metersphere.sdk.constants.ExecStatus; -import io.metersphere.sdk.constants.ExecTaskType; -import io.metersphere.sdk.constants.ResourcePoolTypeEnum; -import io.metersphere.sdk.constants.ResultStatus; -import io.metersphere.sdk.util.BeanUtils; -import io.metersphere.sdk.util.JSON; -import io.metersphere.sdk.util.LogUtils; -import io.metersphere.sdk.util.SubListUtils; import io.metersphere.system.domain.*; import io.metersphere.system.dto.BatchExecTaskReportDTO; import io.metersphere.system.dto.ProjectDTO; @@ -41,7 +34,6 @@ import io.metersphere.system.dto.taskhub.request.ScheduleRequest; import io.metersphere.system.dto.taskhub.request.TaskHubItemBatchRequest; import io.metersphere.system.dto.taskhub.request.TaskHubItemRequest; import io.metersphere.system.dto.taskhub.response.TaskStatisticsResponse; -import io.metersphere.system.log.constants.OperationLogModule; import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.log.dto.LogDTO; import io.metersphere.system.log.service.OperationLogService; @@ -156,13 +148,16 @@ public class BaseTaskHubService { List projectIds = list.stream().map(TaskHubDTO::getProjectId).distinct().toList(); List organizationIds = list.stream().map(TaskHubDTO::getOrganizationId).distinct().toList(); List userIds = list.stream().map(TaskHubDTO::getCreateUser).distinct().toList(); + List taskIds = list.stream().map(TaskHubDTO::getId).distinct().toList(); Map projectMaps = getProjectMaps(projectIds); Map organizationMaps = getOrganizationMaps(organizationIds); Map userMaps = getUserMaps(userIds); + Map taskReportMap = getTaskReportMap(taskIds); list.forEach(item -> { item.setProjectName(projectMaps.getOrDefault(item.getProjectId(), StringUtils.EMPTY)); item.setOrganizationName(organizationMaps.getOrDefault(item.getOrganizationId(), StringUtils.EMPTY)); item.setCreateUserName(userMaps.getOrDefault(item.getCreateUser(), StringUtils.EMPTY)); + item.setReportId(taskReportMap.getOrDefault(item.getId(), StringUtils.EMPTY)); }); } @@ -191,6 +186,18 @@ public class BaseTaskHubService { return projectMaps; } + /** + * 获取任务的报告集合 + * @param taskIds 任务ID集合 + * @return 报告集合 + */ + private Map getTaskReportMap(List taskIds) { + ApiReportRelateTaskExample example = new ApiReportRelateTaskExample(); + example.createCriteria().andTaskResourceIdIn(taskIds); + List reportRelateTasks = apiReportRelateTaskMapper.selectByExample(example); + return reportRelateTasks.stream().collect(Collectors.toMap(ApiReportRelateTask::getTaskResourceId, ApiReportRelateTask::getReportId)); + } + /** * 系统-获取后台执行任务列表