refactor(任务中心): 优化列表查询返回值
This commit is contained in:
parent
d9d8acb50f
commit
ec7112f400
|
@ -8,7 +8,7 @@ CREATE TABLE IF NOT EXISTS exec_task(
|
|||
`task_name` VARCHAR(255) NOT NULL COMMENT '任务名称' ,
|
||||
`status` VARCHAR(20) NOT NULL COMMENT '状态' ,
|
||||
`case_count` BIGINT NOT NULL COMMENT '用例数量' ,
|
||||
`result` VARCHAR(64) COMMENT '执行结果' ,
|
||||
`result` VARCHAR(64) NOT NULL DEFAULT 'PENDING' COMMENT '执行结果' ,
|
||||
`task_type` VARCHAR(50) NOT NULL COMMENT '任务类型' ,
|
||||
`resource_id` VARCHAR(50) COMMENT '测试计划id/测试计划组id' ,
|
||||
`trigger_mode` VARCHAR(20) NOT NULL COMMENT '执行模式' ,
|
||||
|
@ -43,7 +43,7 @@ CREATE TABLE IF NOT EXISTS exec_task_item(
|
|||
`resource_name` VARCHAR(255) NOT NULL COMMENT '资源名称' ,
|
||||
`task_origin` VARCHAR(50) COMMENT '任务来源(任务组下的任务id)' ,
|
||||
`status` VARCHAR(20) NOT NULL COMMENT '执行状态' ,
|
||||
`result` VARCHAR(255) COMMENT '执行结果' ,
|
||||
`result` VARCHAR(255) NOT NULL DEFAULT 'PENDING' COMMENT '执行结果' ,
|
||||
`resource_pool_id` VARCHAR(50) NOT NULL COMMENT '资源池ID' ,
|
||||
`resource_pool_node` VARCHAR(50) COMMENT '节点' ,
|
||||
`resource_type` VARCHAR(50) NOT NULL COMMENT '资源类型' ,
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<mapper namespace="io.metersphere.system.mapper.ExtExecTaskItemMapper">
|
||||
|
||||
<select id="selectList" resultType="io.metersphere.system.dto.taskhub.TaskHubItemDTO">
|
||||
SELECT exec_task_item.*, exec_task.num
|
||||
SELECT exec_task_item.*, exec_task.num, exec_task.task_name, exec_task.trigger_mode
|
||||
FROM exec_task_item
|
||||
inner join exec_task on exec_task_item.task_id = exec_task.id
|
||||
<where>
|
||||
|
|
|
@ -80,6 +80,8 @@ public class BaseTaskHubService {
|
|||
private ProjectMapper projectMapper;
|
||||
@Resource
|
||||
private OrganizationMapper organizationMapper;
|
||||
@Resource
|
||||
private UserMapper userMapper;
|
||||
|
||||
/**
|
||||
* 系统-获取执行任务列表
|
||||
|
@ -107,21 +109,40 @@ public class BaseTaskHubService {
|
|||
}
|
||||
List<String> projectIds = list.stream().map(TaskHubDTO::getProjectId).distinct().toList();
|
||||
List<String> organizationIds = list.stream().map(TaskHubDTO::getProjectId).distinct().toList();
|
||||
ProjectExample projectExample = new ProjectExample();
|
||||
projectExample.createCriteria().andIdIn(projectIds);
|
||||
List<Project> projectList = projectMapper.selectByExample(projectExample);
|
||||
Map<String, String> projectMaps = projectList.stream().collect(Collectors.toMap(Project::getId, Project::getName));
|
||||
List<String> userIds = list.stream().map(TaskHubDTO::getCreateUser).distinct().toList();
|
||||
Map<String, String> projectMaps = getProjectMaps(projectIds);
|
||||
Map<String, String> organizationMaps = getOrganizationMaps(organizationIds);
|
||||
Map<String, String> userMaps = getUserMaps(userIds);
|
||||
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));
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private Map<String, String> getUserMaps(List<String> userIds) {
|
||||
UserExample userExample = new UserExample();
|
||||
userExample.createCriteria().andIdIn(userIds);
|
||||
List<User> userList = userMapper.selectByExample(userExample);
|
||||
Map<String, String> userMaps = userList.stream().collect(Collectors.toMap(User::getId, User::getName));
|
||||
return userMaps;
|
||||
}
|
||||
|
||||
private Map<String, String> getOrganizationMaps(List<String> organizationIds) {
|
||||
OrganizationExample organizationExample = new OrganizationExample();
|
||||
organizationExample.createCriteria().andIdIn(organizationIds);
|
||||
List<Organization> organizationList = organizationMapper.selectByExample(organizationExample);
|
||||
Map<String, String> organizationMaps = organizationList.stream().collect(Collectors.toMap(Organization::getId, Organization::getName));
|
||||
return organizationMaps;
|
||||
}
|
||||
|
||||
list.forEach(item -> {
|
||||
item.setProjectName(projectMaps.getOrDefault(item.getProjectId(), StringUtils.EMPTY));
|
||||
item.setOrganizationName(organizationMaps.getOrDefault(item.getOrganizationId(), StringUtils.EMPTY));
|
||||
});
|
||||
|
||||
private Map<String, String> getProjectMaps(List<String> projectIds) {
|
||||
ProjectExample projectExample = new ProjectExample();
|
||||
projectExample.createCriteria().andIdIn(projectIds);
|
||||
List<Project> projectList = projectMapper.selectByExample(projectExample);
|
||||
Map<String, String> projectMaps = projectList.stream().collect(Collectors.toMap(Project::getId, Project::getName));
|
||||
return projectMaps;
|
||||
}
|
||||
|
||||
|
||||
|
@ -251,7 +272,20 @@ public class BaseTaskHubService {
|
|||
}
|
||||
|
||||
private List<TaskHubItemDTO> getCaseTaskItemPage(TaskHubItemRequest request, String orgId, String projectId) {
|
||||
return extExecTaskItemMapper.selectList(request, orgId, projectId);
|
||||
List<TaskHubItemDTO> itemDTOS = extExecTaskItemMapper.selectList(request, orgId, projectId);
|
||||
handleTaskItem(itemDTOS);
|
||||
return itemDTOS;
|
||||
}
|
||||
|
||||
private void handleTaskItem(List<TaskHubItemDTO> list) {
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
return;
|
||||
}
|
||||
List<String> userIds = list.stream().map(TaskHubItemDTO::getExecutor).distinct().toList();
|
||||
Map<String, String> userMaps = getUserMaps(userIds);
|
||||
list.forEach(item -> {
|
||||
item.setUserName(userMaps.getOrDefault(item.getExecutor(), StringUtils.EMPTY));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue