diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiReportController.java b/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiReportController.java index 32c55daf54..f9d7197997 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiReportController.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiReportController.java @@ -2,10 +2,7 @@ package io.metersphere.api.controller.definition; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; -import io.metersphere.api.dto.definition.ApiReportBatchRequest; -import io.metersphere.api.dto.definition.ApiReportDTO; -import io.metersphere.api.dto.definition.ApiReportDetailDTO; -import io.metersphere.api.dto.definition.ApiReportPageRequest; +import io.metersphere.api.dto.definition.*; import io.metersphere.api.dto.report.ApiReportListDTO; import io.metersphere.api.service.ApiReportShareService; import io.metersphere.api.service.definition.ApiReportLogService; @@ -139,7 +136,7 @@ public class ApiReportController { @Operation(summary = "系统-任务中心-接口用例执行任务详情-查看") @RequiresPermissions(value = {PermissionConstants.SYSTEM_CASE_TASK_CENTER_READ, PermissionConstants.ORGANIZATION_CASE_TASK_CENTER_READ, PermissionConstants.PROJECT_CASE_TASK_CENTER_READ}, logical = Logical.OR) - public List viewCaseItemReport(@PathVariable String id) { + public ApiTaskReportDTO viewCaseItemReport(@PathVariable String id) { return apiReportService.viewCaseTaskItemReport(id); } } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioReportController.java b/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioReportController.java index ca77372eda..9210388b54 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioReportController.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioReportController.java @@ -4,9 +4,11 @@ import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import io.metersphere.api.dto.definition.ApiReportBatchRequest; import io.metersphere.api.dto.definition.ApiReportPageRequest; +import io.metersphere.api.dto.definition.ApiTaskReportDTO; import io.metersphere.api.dto.report.ApiScenarioReportListDTO; import io.metersphere.api.dto.scenario.ApiScenarioReportDTO; import io.metersphere.api.dto.scenario.ApiScenarioReportDetailDTO; +import io.metersphere.api.dto.scenario.ExecTaskDetailDTO; import io.metersphere.api.service.ApiReportShareService; import io.metersphere.api.service.scenario.ApiScenarioReportLogService; import io.metersphere.api.service.scenario.ApiScenarioReportNoticeService; @@ -139,7 +141,7 @@ public class ApiScenarioReportController { @Operation(summary = "系统-任务中心-场景用例执行任务详情-查看(任务步骤)") @RequiresPermissions(value = {PermissionConstants.SYSTEM_CASE_TASK_CENTER_READ, PermissionConstants.ORGANIZATION_CASE_TASK_CENTER_READ, PermissionConstants.PROJECT_CASE_TASK_CENTER_READ}, logical = Logical.OR) - public ApiScenarioReportDTO viewScenarioItemReport(@PathVariable String id) { + public ExecTaskDetailDTO viewScenarioItemReport(@PathVariable String id) { return apiScenarioReportService.viewScenarioItemReport(id); } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiTaskReportDTO.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiTaskReportDTO.java new file mode 100644 index 0000000000..01d7c954e9 --- /dev/null +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiTaskReportDTO.java @@ -0,0 +1,47 @@ +package io.metersphere.api.dto.definition; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.util.List; + +@Data +public class ApiTaskReportDTO { + + + @Schema(description = "发起时间") + private Long createTime; + + @Schema(description = "开始时间") + private Long startTime; + + @Schema(description = "结束时间") + private Long endTime; + + @Schema(description = "任务来源") + private String taskOrigin; + @Schema(description = "任务来源名称") + private String taskOriginName; + + @Schema(description = "结果") + private String result; + + @Schema(description = "资源池ID") + private String resourcePoolId; + @Schema(description = "资源池名称") + private String resourcePoolName; + + @Schema(description = "节点") + private String resourcePoolNode; + + @Schema(description = "线程ID") + private String threadId; + + @Schema(description = "详细信息") + private List apiReportDetailDTOList; + + @Schema(description = "环境id") + private String environmentId; + @Schema(description = "环境名称") + private String environmentName; +} \ No newline at end of file diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/scenario/ExecTaskDetailDTO.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/scenario/ExecTaskDetailDTO.java new file mode 100644 index 0000000000..6bfb15c121 --- /dev/null +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/scenario/ExecTaskDetailDTO.java @@ -0,0 +1,32 @@ +package io.metersphere.api.dto.scenario; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Data +public class ExecTaskDetailDTO extends ApiScenarioReportDTO{ + @Schema(description = "发起时间") + private Long createTime; + + @Schema(description = "开始时间") + private Long startTime; + + @Schema(description = "结束时间") + private Long endTime; + + @Schema(description = "任务来源") + private String taskOrigin; + @Schema(description = "任务来源名称") + private String taskOriginName; + + + @Schema(description = "结果") + private String result; + + @Schema(description = "节点") + private String resourcePoolNode; + + @Schema(description = "线程ID") + private String threadId; + +} diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiReportService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiReportService.java index ea8c9d47e7..ab6f6ab758 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiReportService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiReportService.java @@ -5,6 +5,8 @@ import io.metersphere.api.dto.definition.*; import io.metersphere.api.dto.report.ApiReportListDTO; import io.metersphere.api.mapper.*; import io.metersphere.api.utils.ApiDataUtils; +import io.metersphere.plan.domain.TestPlan; +import io.metersphere.plan.mapper.TestPlanMapper; import io.metersphere.sdk.constants.ExecStatus; import io.metersphere.sdk.domain.Environment; import io.metersphere.sdk.domain.EnvironmentGroup; @@ -19,6 +21,7 @@ import io.metersphere.system.domain.ExecTask; import io.metersphere.system.domain.ExecTaskItem; import io.metersphere.system.domain.TestResourcePool; import io.metersphere.system.domain.User; +import io.metersphere.system.dto.taskhub.ExecTaskItemDetailDTO; import io.metersphere.system.mapper.ExecTaskItemMapper; import io.metersphere.system.mapper.ExtExecTaskMapper; import io.metersphere.system.mapper.TestResourcePoolMapper; @@ -77,6 +80,8 @@ public class ApiReportService { private ExtExecTaskMapper extExecTaskMapper; @Resource private ExecTaskItemMapper execTaskItemMapper; + @Resource + private TestPlanMapper testPlanMapper; @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW) public void insertApiReport(ApiReport report) { @@ -315,7 +320,7 @@ public class ApiReportService { public void batchExportLog(ApiReportBatchRequest request, String userId, String projectId) { List ids = doSelectIds(request); - if(CollectionUtils.isNotEmpty(ids)){ + if (CollectionUtils.isNotEmpty(ids)) { ApiReportExample example = new ApiReportExample(); example.createCriteria().andIdIn(ids); List reports = apiReportMapper.selectByExample(example); @@ -323,23 +328,37 @@ public class ApiReportService { } } - public List viewCaseTaskItemReport(String id) { - List taskList = extExecTaskMapper.selectTypeByItemId(id); + public ApiTaskReportDTO viewCaseTaskItemReport(String id) { + List taskList = extExecTaskMapper.selectTypeByItemId(id); + ApiTaskReportDTO apiTaskReportDTO = new ApiTaskReportDTO(); if (CollectionUtils.isNotEmpty(taskList)) { - ExecTask task = taskList.getFirst(); + ExecTaskItemDetailDTO task = taskList.getFirst(); + //设置 顶部数据 + BeanUtils.copyBean(apiTaskReportDTO, task); + //计划组处理来源 + if (StringUtils.isNotBlank(apiTaskReportDTO.getTaskOrigin())) { + TestPlan testPlan = testPlanMapper.selectByPrimaryKey(apiTaskReportDTO.getTaskOrigin()); + Optional.ofNullable(testPlan).ifPresent(item -> apiTaskReportDTO.setTaskOriginName(testPlan.getName())); + } + //资源池名称 + if (StringUtils.isNotBlank(apiTaskReportDTO.getResourcePoolId())) { + TestResourcePool testResourcePool = testResourcePoolMapper.selectByPrimaryKey(apiTaskReportDTO.getResourcePoolId()); + Optional.ofNullable(testResourcePool).ifPresent(item -> apiTaskReportDTO.setResourcePoolName(testResourcePool.getName())); + } + if (task.getIntegrated()) { //集合报告 - return getIntegratedItemDetail(id, task.getId()); + apiTaskReportDTO.setApiReportDetailDTOList(getIntegratedItemDetail(id, task.getId(), apiTaskReportDTO)); } else { //非集合报告 - return reportDetail(id); + apiTaskReportDTO.setApiReportDetailDTOList(reportDetail(id, apiTaskReportDTO)); } } - return new ArrayList<>(); + return apiTaskReportDTO; } - private List getIntegratedItemDetail(String taskItemId, String taskId) { + private List getIntegratedItemDetail(String taskItemId, String taskId, ApiTaskReportDTO apiTaskReportDTO) { ExecTaskItem taskItem = execTaskItemMapper.selectByPrimaryKey(taskItemId); ApiReportRelateTaskExample example = new ApiReportRelateTaskExample(); example.createCriteria().andTaskResourceIdEqualTo(taskId); @@ -348,10 +367,11 @@ public class ApiReportService { return new ArrayList<>(); } String reportId = apiReportRelateTasks.getFirst().getReportId(); + setEnvironment(reportId, apiTaskReportDTO); return getDetail(reportId, taskItem.getResourceId()); } - private List reportDetail(String id) { + private List reportDetail(String id, ApiTaskReportDTO apiTaskReportDTO) { List list = new ArrayList<>(); ApiReportRelateTaskExample example = new ApiReportRelateTaskExample(); example.createCriteria().andTaskResourceIdEqualTo(id); @@ -361,12 +381,20 @@ public class ApiReportService { String reportId = apiReportRelateTasks.getFirst().getReportId(); //获取步骤id String stepId = getStepId(reportId); + setEnvironment(reportId, apiTaskReportDTO); list = getDetail(reportId, stepId); } return list; } + private void setEnvironment(String reportId, ApiTaskReportDTO apiTaskReportDTO) { + ApiReport apiReport = apiReportMapper.selectByPrimaryKey(reportId); + Environment environment = environmentMapper.selectByPrimaryKey(apiReport.getEnvironmentId()); + apiTaskReportDTO.setEnvironmentId(apiReport.getEnvironmentId()); + apiTaskReportDTO.setEnvironmentName(environment.getName()); + } + private String getStepId(String reportId) { ApiReportStepExample example = new ApiReportStepExample(); example.createCriteria().andReportIdEqualTo(reportId); diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioReportService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioReportService.java index 545f768b9e..ac04bedd55 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioReportService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioReportService.java @@ -8,7 +8,10 @@ import io.metersphere.api.dto.report.ApiScenarioReportListDTO; import io.metersphere.api.dto.scenario.ApiScenarioReportDTO; import io.metersphere.api.dto.scenario.ApiScenarioReportDetailDTO; import io.metersphere.api.dto.scenario.ApiScenarioReportStepDTO; +import io.metersphere.api.dto.scenario.ExecTaskDetailDTO; import io.metersphere.api.mapper.*; +import io.metersphere.plan.domain.TestPlan; +import io.metersphere.plan.mapper.TestPlanMapper; import io.metersphere.sdk.constants.ExecStatus; import io.metersphere.sdk.constants.ResultStatus; import io.metersphere.sdk.domain.Environment; @@ -22,6 +25,7 @@ import io.metersphere.system.domain.ExecTask; import io.metersphere.system.domain.ExecTaskItem; import io.metersphere.system.domain.TestResourcePool; import io.metersphere.system.domain.User; +import io.metersphere.system.dto.taskhub.ExecTaskItemDetailDTO; import io.metersphere.system.mapper.ExecTaskItemMapper; import io.metersphere.system.mapper.ExtExecTaskMapper; import io.metersphere.system.mapper.TestResourcePoolMapper; @@ -81,6 +85,8 @@ public class ApiScenarioReportService { private ExtExecTaskMapper extExecTaskMapper; @Resource private ExecTaskItemMapper execTaskItemMapper; + @Resource + private TestPlanMapper testPlanMapper; @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW) public void insertApiScenarioReport(ApiScenarioReport report, ApiReportRelateTask taskRelation) { @@ -449,19 +455,30 @@ public class ApiScenarioReportService { } } - public ApiScenarioReportDTO viewScenarioItemReport(String id) { - List taskList = extExecTaskMapper.selectTypeByItemId(id); + public ExecTaskDetailDTO viewScenarioItemReport(String id) { + List taskList = extExecTaskMapper.selectTypeByItemId(id); + ExecTaskDetailDTO apiTaskReportDTO = new ExecTaskDetailDTO(); if (CollectionUtils.isNotEmpty(taskList)) { - if (taskList.getFirst().getIntegrated()) { + ExecTaskItemDetailDTO task = taskList.getFirst(); + //设置 顶部数据 + BeanUtils.copyBean(apiTaskReportDTO, task); + //计划组处理来源 + if (StringUtils.isNotBlank(apiTaskReportDTO.getTaskOrigin())) { + TestPlan testPlan = testPlanMapper.selectByPrimaryKey(apiTaskReportDTO.getTaskOrigin()); + Optional.ofNullable(testPlan).ifPresent(item -> apiTaskReportDTO.setTaskOriginName(testPlan.getName())); + } + if (task.getIntegrated()) { //场景集合报告 - return getScenarioReportDetail(taskList.getFirst().getId(), id); + ApiScenarioReportDTO scenarioReportDetail = getScenarioReportDetail(id, task.getId()); + BeanUtils.copyBean(apiTaskReportDTO, scenarioReportDetail); } else { //场景非集合报告 - return scenarioReportDetail(id); + ApiScenarioReportDTO scenarioReportDetail = scenarioReportDetail(id); + BeanUtils.copyBean(apiTaskReportDTO, scenarioReportDetail); } } - return new ApiScenarioReportDTO(); + return apiTaskReportDTO; } private ApiScenarioReportDTO getScenarioReportDetail(String taskId, String taskItemId) { diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/taskhub/ExecTaskItemDetailDTO.java b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/taskhub/ExecTaskItemDetailDTO.java new file mode 100644 index 0000000000..d32b8a9d54 --- /dev/null +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/taskhub/ExecTaskItemDetailDTO.java @@ -0,0 +1,47 @@ +package io.metersphere.system.dto.taskhub; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serial; +import java.io.Serializable; + +/** + * @author wx + */ +@Data +public class ExecTaskItemDetailDTO implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + @Schema(description = "id") + private String id; + + @Schema(description = "发起时间") + private Long createTime; + + @Schema(description = "开始时间") + private Long startTime; + + @Schema(description = "结束时间") + private Long endTime; + + @Schema(description = "任务来源") + private String taskOrigin; + + @Schema(description = "结果") + private String result; + + @Schema(description = "资源池ID", requiredMode = Schema.RequiredMode.REQUIRED) + private String resourcePoolId; + + @Schema(description = "节点") + private String resourcePoolNode; + + @Schema(description = "线程ID") + private String threadId; + + @Schema(description = "是否集合报告") + private Boolean integrated; +} 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 a0f8b90b4c..c364d9cae2 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 @@ -3,6 +3,7 @@ package io.metersphere.system.mapper; import io.metersphere.system.domain.ExecTask; import io.metersphere.system.dto.sdk.BasePageRequest; import io.metersphere.system.dto.table.TableBatchProcessDTO; +import io.metersphere.system.dto.taskhub.ExecTaskItemDetailDTO; import io.metersphere.system.dto.taskhub.TaskHubDTO; import org.apache.ibatis.annotations.Param; @@ -28,5 +29,5 @@ public interface ExtExecTaskMapper { */ List getTaskIdsByTime(@Param("timeMills") long timeMills, @Param("projectId") String projectId); - List selectTypeByItemId(@Param("itemId") String itemId); + List selectTypeByItemId(@Param("itemId") String itemId); } 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 d1316429f9..55a06c1a8c 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 @@ -120,7 +120,16 @@ - + select exec_task.id, + exec_task.integrated, + exec_task.create_time as createTime, + exec_task_item.result as result, + exec_task_item.resource_pool_id as resourcePoolId, + exec_task_item.resource_pool_node as resourcePoolNode, + exec_task_item.thread_id as threadId, + exec_task_item.start_time as startTime, + exec_task_item.end_time as endTime + from exec_task inner join exec_task_item on exec_task.id = exec_task_item.task_id where exec_task_item.id = #{itemId} \ No newline at end of file