feat(任务中心): 补充任务中心执行结果
This commit is contained in:
parent
79eaf80801
commit
99a123d6b9
|
@ -137,7 +137,8 @@ public class ApiReportController {
|
||||||
|
|
||||||
@GetMapping("/task-report/{id}")
|
@GetMapping("/task-report/{id}")
|
||||||
@Operation(summary = "系统-任务中心-接口用例执行任务详情-查看")
|
@Operation(summary = "系统-任务中心-接口用例执行任务详情-查看")
|
||||||
@RequiresPermissions(PermissionConstants.SYSTEM_CASE_TASK_CENTER_READ)
|
@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 List<ApiReportDetailDTO> viewCaseItemReport(@PathVariable String id) {
|
||||||
return apiReportService.viewCaseTaskItemReport(id);
|
return apiReportService.viewCaseTaskItemReport(id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@ package io.metersphere.api.controller.scenario;
|
||||||
import com.github.pagehelper.Page;
|
import com.github.pagehelper.Page;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import io.metersphere.api.dto.definition.ApiReportBatchRequest;
|
import io.metersphere.api.dto.definition.ApiReportBatchRequest;
|
||||||
import io.metersphere.api.dto.definition.ApiReportDetailDTO;
|
|
||||||
import io.metersphere.api.dto.definition.ApiReportPageRequest;
|
import io.metersphere.api.dto.definition.ApiReportPageRequest;
|
||||||
import io.metersphere.api.dto.report.ApiScenarioReportListDTO;
|
import io.metersphere.api.dto.report.ApiScenarioReportListDTO;
|
||||||
import io.metersphere.api.dto.scenario.ApiScenarioReportDTO;
|
import io.metersphere.api.dto.scenario.ApiScenarioReportDTO;
|
||||||
|
@ -138,14 +137,16 @@ public class ApiScenarioReportController {
|
||||||
|
|
||||||
@GetMapping("/task-step/{id}")
|
@GetMapping("/task-step/{id}")
|
||||||
@Operation(summary = "系统-任务中心-场景用例执行任务详情-查看(任务步骤)")
|
@Operation(summary = "系统-任务中心-场景用例执行任务详情-查看(任务步骤)")
|
||||||
@RequiresPermissions(PermissionConstants.SYSTEM_CASE_TASK_CENTER_READ)
|
@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 ApiScenarioReportDTO viewScenarioItemReport(@PathVariable String id) {
|
||||||
return apiScenarioReportService.viewScenarioItemReport(id);
|
return apiScenarioReportService.viewScenarioItemReport(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/task-report/{reportId}/{stepId}")
|
@GetMapping("/task-report/{reportId}/{stepId}")
|
||||||
@Operation(summary = "系统-任务中心-场景用例执行任务详情-查看(步骤结果)")
|
@Operation(summary = "系统-任务中心-场景用例执行任务详情-查看(步骤结果)")
|
||||||
@RequiresPermissions(PermissionConstants.SYSTEM_CASE_TASK_CENTER_READ)
|
@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<ApiScenarioReportDetailDTO> getScenarioReportDetail(@PathVariable String reportId,
|
public List<ApiScenarioReportDetailDTO> getScenarioReportDetail(@PathVariable String reportId,
|
||||||
@PathVariable String stepId) {
|
@PathVariable String stepId) {
|
||||||
return apiScenarioReportService.getDetail(reportId, stepId);
|
return apiScenarioReportService.getDetail(reportId, stepId);
|
||||||
|
|
|
@ -16,8 +16,10 @@ import io.metersphere.sdk.util.BeanUtils;
|
||||||
import io.metersphere.sdk.util.SubListUtils;
|
import io.metersphere.sdk.util.SubListUtils;
|
||||||
import io.metersphere.sdk.util.Translator;
|
import io.metersphere.sdk.util.Translator;
|
||||||
import io.metersphere.system.domain.ExecTask;
|
import io.metersphere.system.domain.ExecTask;
|
||||||
|
import io.metersphere.system.domain.ExecTaskItem;
|
||||||
import io.metersphere.system.domain.TestResourcePool;
|
import io.metersphere.system.domain.TestResourcePool;
|
||||||
import io.metersphere.system.domain.User;
|
import io.metersphere.system.domain.User;
|
||||||
|
import io.metersphere.system.mapper.ExecTaskItemMapper;
|
||||||
import io.metersphere.system.mapper.ExtExecTaskMapper;
|
import io.metersphere.system.mapper.ExtExecTaskMapper;
|
||||||
import io.metersphere.system.mapper.TestResourcePoolMapper;
|
import io.metersphere.system.mapper.TestResourcePoolMapper;
|
||||||
import io.metersphere.system.mapper.UserMapper;
|
import io.metersphere.system.mapper.UserMapper;
|
||||||
|
@ -73,6 +75,8 @@ public class ApiReportService {
|
||||||
private ApiReportStepMapper apiReportStepMapper;
|
private ApiReportStepMapper apiReportStepMapper;
|
||||||
@Resource
|
@Resource
|
||||||
private ExtExecTaskMapper extExecTaskMapper;
|
private ExtExecTaskMapper extExecTaskMapper;
|
||||||
|
@Resource
|
||||||
|
private ExecTaskItemMapper execTaskItemMapper;
|
||||||
|
|
||||||
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
|
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
|
||||||
public void insertApiReport(ApiReport report) {
|
public void insertApiReport(ApiReport report) {
|
||||||
|
@ -323,9 +327,10 @@ public class ApiReportService {
|
||||||
List<ExecTask> taskList = extExecTaskMapper.selectTypeByItemId(id);
|
List<ExecTask> taskList = extExecTaskMapper.selectTypeByItemId(id);
|
||||||
|
|
||||||
if (CollectionUtils.isNotEmpty(taskList)) {
|
if (CollectionUtils.isNotEmpty(taskList)) {
|
||||||
if (taskList.getFirst().getIntegrated()) {
|
ExecTask task = taskList.getFirst();
|
||||||
//集合报告 TODO
|
if (task.getIntegrated()) {
|
||||||
return new ArrayList<>();
|
//集合报告
|
||||||
|
return getIntegratedItemDetail(id, task.getId());
|
||||||
} else {
|
} else {
|
||||||
//非集合报告
|
//非集合报告
|
||||||
return reportDetail(id);
|
return reportDetail(id);
|
||||||
|
@ -334,6 +339,15 @@ public class ApiReportService {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<ApiReportDetailDTO> getIntegratedItemDetail(String taskItemId, String taskId) {
|
||||||
|
ExecTaskItem taskItem = execTaskItemMapper.selectByPrimaryKey(taskItemId);
|
||||||
|
ApiReportRelateTaskExample example = new ApiReportRelateTaskExample();
|
||||||
|
example.createCriteria().andTaskResourceIdEqualTo(taskId);
|
||||||
|
List<ApiReportRelateTask> apiReportRelateTasks = apiReportRelateTaskMapper.selectByExample(example);
|
||||||
|
String reportId = apiReportRelateTasks.getFirst().getReportId();
|
||||||
|
return getDetail(reportId, taskItem.getResourceId());
|
||||||
|
}
|
||||||
|
|
||||||
private List<ApiReportDetailDTO> reportDetail(String id) {
|
private List<ApiReportDetailDTO> reportDetail(String id) {
|
||||||
List<ApiReportDetailDTO> list = new ArrayList<>();
|
List<ApiReportDetailDTO> list = new ArrayList<>();
|
||||||
ApiReportRelateTaskExample example = new ApiReportRelateTaskExample();
|
ApiReportRelateTaskExample example = new ApiReportRelateTaskExample();
|
||||||
|
|
|
@ -3,7 +3,6 @@ package io.metersphere.api.service.scenario;
|
||||||
import io.metersphere.api.constants.ApiScenarioStepType;
|
import io.metersphere.api.constants.ApiScenarioStepType;
|
||||||
import io.metersphere.api.domain.*;
|
import io.metersphere.api.domain.*;
|
||||||
import io.metersphere.api.dto.definition.ApiReportBatchRequest;
|
import io.metersphere.api.dto.definition.ApiReportBatchRequest;
|
||||||
import io.metersphere.api.dto.definition.ApiReportDetailDTO;
|
|
||||||
import io.metersphere.api.dto.definition.ApiReportPageRequest;
|
import io.metersphere.api.dto.definition.ApiReportPageRequest;
|
||||||
import io.metersphere.api.dto.report.ApiScenarioReportListDTO;
|
import io.metersphere.api.dto.report.ApiScenarioReportListDTO;
|
||||||
import io.metersphere.api.dto.scenario.ApiScenarioReportDTO;
|
import io.metersphere.api.dto.scenario.ApiScenarioReportDTO;
|
||||||
|
@ -20,8 +19,10 @@ import io.metersphere.sdk.util.BeanUtils;
|
||||||
import io.metersphere.sdk.util.SubListUtils;
|
import io.metersphere.sdk.util.SubListUtils;
|
||||||
import io.metersphere.sdk.util.Translator;
|
import io.metersphere.sdk.util.Translator;
|
||||||
import io.metersphere.system.domain.ExecTask;
|
import io.metersphere.system.domain.ExecTask;
|
||||||
|
import io.metersphere.system.domain.ExecTaskItem;
|
||||||
import io.metersphere.system.domain.TestResourcePool;
|
import io.metersphere.system.domain.TestResourcePool;
|
||||||
import io.metersphere.system.domain.User;
|
import io.metersphere.system.domain.User;
|
||||||
|
import io.metersphere.system.mapper.ExecTaskItemMapper;
|
||||||
import io.metersphere.system.mapper.ExtExecTaskMapper;
|
import io.metersphere.system.mapper.ExtExecTaskMapper;
|
||||||
import io.metersphere.system.mapper.TestResourcePoolMapper;
|
import io.metersphere.system.mapper.TestResourcePoolMapper;
|
||||||
import io.metersphere.system.mapper.UserMapper;
|
import io.metersphere.system.mapper.UserMapper;
|
||||||
|
@ -78,6 +79,8 @@ public class ApiScenarioReportService {
|
||||||
private static final int BATCH_SIZE = 1000;
|
private static final int BATCH_SIZE = 1000;
|
||||||
@Resource
|
@Resource
|
||||||
private ExtExecTaskMapper extExecTaskMapper;
|
private ExtExecTaskMapper extExecTaskMapper;
|
||||||
|
@Resource
|
||||||
|
private ExecTaskItemMapper execTaskItemMapper;
|
||||||
|
|
||||||
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
|
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
|
||||||
public void insertApiScenarioReport(ApiScenarioReport report, ApiReportRelateTask taskRelation) {
|
public void insertApiScenarioReport(ApiScenarioReport report, ApiReportRelateTask taskRelation) {
|
||||||
|
@ -451,8 +454,8 @@ public class ApiScenarioReportService {
|
||||||
|
|
||||||
if (CollectionUtils.isNotEmpty(taskList)) {
|
if (CollectionUtils.isNotEmpty(taskList)) {
|
||||||
if (taskList.getFirst().getIntegrated()) {
|
if (taskList.getFirst().getIntegrated()) {
|
||||||
//场景集合报告 TODO
|
//场景集合报告
|
||||||
return new ApiScenarioReportDTO();
|
return getScenarioReportDetail(id, taskList.getFirst().getId());
|
||||||
} else {
|
} else {
|
||||||
//场景非集合报告
|
//场景非集合报告
|
||||||
return scenarioReportDetail(id);
|
return scenarioReportDetail(id);
|
||||||
|
@ -461,6 +464,15 @@ public class ApiScenarioReportService {
|
||||||
return new ApiScenarioReportDTO();
|
return new ApiScenarioReportDTO();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ApiScenarioReportDTO getScenarioReportDetail(String taskId, String taskItemId) {
|
||||||
|
ExecTaskItem taskItem = execTaskItemMapper.selectByPrimaryKey(taskItemId);
|
||||||
|
ApiScenarioReportDTO apiScenarioReportDTO = scenarioReportDetail(taskId);
|
||||||
|
List<ApiScenarioReportStepDTO> list = apiScenarioReportDTO.getChildren().stream()
|
||||||
|
.filter(step -> StringUtils.equals(step.getStepId(), taskItem.getResourceId())).toList();
|
||||||
|
apiScenarioReportDTO.setChildren(list);
|
||||||
|
return apiScenarioReportDTO;
|
||||||
|
}
|
||||||
|
|
||||||
private ApiScenarioReportDTO scenarioReportDetail(String id) {
|
private ApiScenarioReportDTO scenarioReportDetail(String id) {
|
||||||
ApiReportRelateTaskExample example = new ApiReportRelateTaskExample();
|
ApiReportRelateTaskExample example = new ApiReportRelateTaskExample();
|
||||||
example.createCriteria().andTaskResourceIdEqualTo(id);
|
example.createCriteria().andTaskResourceIdEqualTo(id);
|
||||||
|
|
|
@ -121,6 +121,6 @@
|
||||||
|
|
||||||
|
|
||||||
<select id="selectTypeByItemId" resultType="io.metersphere.system.domain.ExecTask">
|
<select id="selectTypeByItemId" resultType="io.metersphere.system.domain.ExecTask">
|
||||||
select integrated from exec_task inner join exec_task_item on exec_task.id = exec_task_item.task_id where exec_task_item.id = #{itemId}
|
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>
|
</select>
|
||||||
</mapper>
|
</mapper>
|
|
@ -46,6 +46,7 @@ import io.metersphere.system.utils.Pager;
|
||||||
import io.metersphere.system.utils.TaskRunnerClient;
|
import io.metersphere.system.utils.TaskRunnerClient;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
import org.apache.commons.collections4.ListUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.ibatis.session.ExecutorType;
|
import org.apache.ibatis.session.ExecutorType;
|
||||||
import org.apache.ibatis.session.SqlSession;
|
import org.apache.ibatis.session.SqlSession;
|
||||||
|
@ -153,18 +154,15 @@ public class BaseTaskHubService {
|
||||||
List<String> projectIds = list.stream().map(TaskHubDTO::getProjectId).distinct().toList();
|
List<String> projectIds = list.stream().map(TaskHubDTO::getProjectId).distinct().toList();
|
||||||
List<String> organizationIds = list.stream().map(TaskHubDTO::getOrganizationId).distinct().toList();
|
List<String> organizationIds = list.stream().map(TaskHubDTO::getOrganizationId).distinct().toList();
|
||||||
List<String> userIds = list.stream().map(TaskHubDTO::getCreateUser).distinct().toList();
|
List<String> userIds = list.stream().map(TaskHubDTO::getCreateUser).distinct().toList();
|
||||||
List<String> taskIds = list.stream().map(TaskHubDTO::getId).distinct().toList();
|
|
||||||
Map<String, String> projectMaps = getProjectMaps(projectIds);
|
Map<String, String> projectMaps = getProjectMaps(projectIds);
|
||||||
Map<String, String> organizationMaps = getOrganizationMaps(organizationIds);
|
Map<String, String> organizationMaps = getOrganizationMaps(organizationIds);
|
||||||
Map<String, String> userMaps = getUserMaps(userIds);
|
Map<String, String> userMaps = getUserMaps(userIds);
|
||||||
Map<String, String> taskReportMap = getTaskReportMap(taskIds);
|
|
||||||
list.forEach(item -> {
|
list.forEach(item -> {
|
||||||
item.setProjectName(projectMaps.getOrDefault(item.getProjectId(), StringUtils.EMPTY));
|
item.setProjectName(projectMaps.getOrDefault(item.getProjectId(), StringUtils.EMPTY));
|
||||||
item.setOrganizationName(organizationMaps.getOrDefault(item.getOrganizationId(), StringUtils.EMPTY));
|
item.setOrganizationName(organizationMaps.getOrDefault(item.getOrganizationId(), StringUtils.EMPTY));
|
||||||
item.setCreateUserName(userMaps.getOrDefault(item.getCreateUser(), StringUtils.EMPTY));
|
item.setCreateUserName(userMaps.getOrDefault(item.getCreateUser(), StringUtils.EMPTY));
|
||||||
item.setReportId(taskReportMap.getOrDefault(item.getId(), StringUtils.EMPTY));
|
|
||||||
});
|
});
|
||||||
|
setTaskReportId(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, String> getUserMaps(List<String> userIds) {
|
private Map<String, String> getUserMaps(List<String> userIds) {
|
||||||
|
@ -189,16 +187,40 @@ public class BaseTaskHubService {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取任务的报告集合
|
* 设置任务的报告ID
|
||||||
*
|
* @param tasks 任务集合
|
||||||
* @param taskIds 任务ID集合
|
|
||||||
* @return 报告集合
|
|
||||||
*/
|
*/
|
||||||
private Map<String, String> getTaskReportMap(List<String> taskIds) {
|
private void setTaskReportId(List<TaskHubDTO> tasks) {
|
||||||
|
List<TaskHubDTO> reportTasks = tasks.stream().filter(task -> !StringUtils.equals(task.getTaskType(), ExecTaskType.API_SCENARIO_BATCH.name()) &&
|
||||||
|
!StringUtils.equals(task.getTaskType(), ExecTaskType.API_CASE_BATCH.name())).toList();
|
||||||
|
List<String> integratedTaskIds = reportTasks.stream().filter(task ->
|
||||||
|
StringUtils.equalsAny(task.getTaskType(), ExecTaskType.TEST_PLAN.name(), ExecTaskType.TEST_PLAN_GROUP.name()) || task.getIntegrated()).map(ExecTask::getId).toList();
|
||||||
|
List<String> noIntegratedTasks = reportTasks.stream().map(ExecTask::getId).filter(id -> !integratedTaskIds.contains(id)).toList();
|
||||||
|
List<ExecTaskItem> taskItems = new ArrayList<>();
|
||||||
|
if (CollectionUtils.isNotEmpty(noIntegratedTasks)) {
|
||||||
|
ExecTaskItemExample itemExample = new ExecTaskItemExample();
|
||||||
|
itemExample.createCriteria().andTaskIdIn(noIntegratedTasks);
|
||||||
|
taskItems = execTaskItemMapper.selectByExample(itemExample);
|
||||||
|
}
|
||||||
|
Map<String, String> taskItemMap = taskItems.stream().collect(Collectors.toMap(ExecTaskItem::getTaskId, ExecTaskItem::getId));
|
||||||
|
List<String> noIntegratedTaskItemIds = taskItems.stream().map(ExecTaskItem::getId).toList();
|
||||||
|
List<String> resourceIds = ListUtils.union(integratedTaskIds, noIntegratedTaskItemIds);
|
||||||
|
if (CollectionUtils.isEmpty(resourceIds)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
ApiReportRelateTaskExample example = new ApiReportRelateTaskExample();
|
ApiReportRelateTaskExample example = new ApiReportRelateTaskExample();
|
||||||
example.createCriteria().andTaskResourceIdIn(taskIds);
|
example.createCriteria().andTaskResourceIdIn(resourceIds);
|
||||||
List<ApiReportRelateTask> reportRelateTasks = apiReportRelateTaskMapper.selectByExample(example);
|
List<ApiReportRelateTask> reportRelateTasks = apiReportRelateTaskMapper.selectByExample(example);
|
||||||
return reportRelateTasks.stream().collect(Collectors.toMap(ApiReportRelateTask::getTaskResourceId, ApiReportRelateTask::getReportId));
|
Map<String, String> reportMap = reportRelateTasks.stream().collect(Collectors.toMap(ApiReportRelateTask::getTaskResourceId, ApiReportRelateTask::getReportId));
|
||||||
|
reportTasks.forEach(task -> {
|
||||||
|
if (integratedTaskIds.contains(task.getId())) {
|
||||||
|
task.setReportId(reportMap.get(task.getId()));
|
||||||
|
} else {
|
||||||
|
if (taskItemMap.containsKey(task.getId())) {
|
||||||
|
task.setReportId(reportMap.get(taskItemMap.get(task.getId())));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue