refactor(任务中心): 优化任务详情查看结果

This commit is contained in:
WangXu10 2024-10-22 16:16:43 +08:00 committed by Craftsman
parent a98f8bc20f
commit d440688cbf
9 changed files with 204 additions and 24 deletions

View File

@ -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<ApiReportDetailDTO> viewCaseItemReport(@PathVariable String id) {
public ApiTaskReportDTO viewCaseItemReport(@PathVariable String id) {
return apiReportService.viewCaseTaskItemReport(id);
}
}

View File

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

View File

@ -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<ApiReportDetailDTO> apiReportDetailDTOList;
@Schema(description = "环境id")
private String environmentId;
@Schema(description = "环境名称")
private String environmentName;
}

View File

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

View File

@ -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) {
@ -323,23 +328,37 @@ public class ApiReportService {
}
}
public List<ApiReportDetailDTO> viewCaseTaskItemReport(String id) {
List<ExecTask> taskList = extExecTaskMapper.selectTypeByItemId(id);
public ApiTaskReportDTO viewCaseTaskItemReport(String id) {
List<ExecTaskItemDetailDTO> taskList = extExecTaskMapper.selectTypeByItemId(id);
ApiTaskReportDTO apiTaskReportDTO = new ApiTaskReportDTO();
if (CollectionUtils.isNotEmpty(taskList)) {
ExecTask task = taskList.getFirst();
if (task.getIntegrated()) {
//集合报告
return getIntegratedItemDetail(id, task.getId());
} else {
//非集合报告
return reportDetail(id);
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()));
}
}
return new ArrayList<>();
//资源池名称
if (StringUtils.isNotBlank(apiTaskReportDTO.getResourcePoolId())) {
TestResourcePool testResourcePool = testResourcePoolMapper.selectByPrimaryKey(apiTaskReportDTO.getResourcePoolId());
Optional.ofNullable(testResourcePool).ifPresent(item -> apiTaskReportDTO.setResourcePoolName(testResourcePool.getName()));
}
private List<ApiReportDetailDTO> getIntegratedItemDetail(String taskItemId, String taskId) {
if (task.getIntegrated()) {
//集合报告
apiTaskReportDTO.setApiReportDetailDTOList(getIntegratedItemDetail(id, task.getId(), apiTaskReportDTO));
} else {
//非集合报告
apiTaskReportDTO.setApiReportDetailDTOList(reportDetail(id, apiTaskReportDTO));
}
}
return apiTaskReportDTO;
}
private List<ApiReportDetailDTO> 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<ApiReportDetailDTO> reportDetail(String id) {
private List<ApiReportDetailDTO> reportDetail(String id, ApiTaskReportDTO apiTaskReportDTO) {
List<ApiReportDetailDTO> 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);

View File

@ -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<ExecTask> taskList = extExecTaskMapper.selectTypeByItemId(id);
public ExecTaskDetailDTO viewScenarioItemReport(String id) {
List<ExecTaskItemDetailDTO> 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) {

View File

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

View File

@ -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<String> getTaskIdsByTime(@Param("timeMills") long timeMills, @Param("projectId") String projectId);
List<ExecTask> selectTypeByItemId(@Param("itemId") String itemId);
List<ExecTaskItemDetailDTO> selectTypeByItemId(@Param("itemId") String itemId);
}

View File

@ -120,7 +120,16 @@
</select>
<select id="selectTypeByItemId" resultType="io.metersphere.system.domain.ExecTask">
select exec_task.* from exec_task inner join exec_task_item on exec_task.id = exec_task_item.task_id where exec_task_item.id = #{itemId}
<select id="selectTypeByItemId" resultType="io.metersphere.system.dto.taskhub.ExecTaskItemDetailDTO">
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}
</select>
</mapper>