feat(任务中心): 组织&项目获取资源池下拉选项

This commit is contained in:
WangXu10 2024-10-12 17:37:47 +08:00 committed by Craftsman
parent d13ee84e2b
commit de928b3bcc
10 changed files with 145 additions and 15 deletions

View File

@ -2,6 +2,7 @@ package io.metersphere.project.controller;
import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.system.dto.sdk.BasePageRequest;
import io.metersphere.system.dto.taskhub.ResourcePoolOptionsDTO;
import io.metersphere.system.dto.taskhub.TaskHubDTO;
import io.metersphere.system.dto.taskhub.TaskHubItemDTO;
import io.metersphere.system.dto.taskhub.TaskHubScheduleDTO;
@ -17,10 +18,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@ -62,4 +60,12 @@ public class ProjectTaskHubController {
public List<TaskStatisticsResponse> calculateRate(@RequestBody List<String> ids) {
return baseTaskHubService.calculateRate(ids, null, SessionUtils.getCurrentProjectId());
}
@GetMapping("/resource-pool/options")
@Operation(summary = "项目-任务中心-获取资源池下拉选项")
@RequiresPermissions(PermissionConstants.PROJECT_CASE_TASK_CENTER_READ)
public List<ResourcePoolOptionsDTO> getUserProject() {
return baseTaskHubService.getProjectResourcePoolOptions(SessionUtils.getCurrentProjectId());
}
}

View File

@ -23,6 +23,7 @@ public class ProjectTaskHubControllerTests extends BaseTest {
public static final String PROJECT_SCHEDULE_TASK_PAGE = "/project/task-center/schedule/page";
public static final String PROJECT_TASK_ITEM_PAGE = "/project/task-center/exec-task/item/page";
public static final String PROJECT_STATISTICS = "/project/task-center/exec-task/statistics";
public static final String PROJECT_RESOURCE_POOL_OPTIONS = "/project/task-center/resource-pool/options";
@Test
@Order(1)
@ -91,4 +92,18 @@ public class ProjectTaskHubControllerTests extends BaseTest {
// 返回请求正常
Assertions.assertNotNull(resultHolder);
}
/**
* 组织获取资源池下拉选项
*/
@Test
@Order(5)
public void getOrgResourcePoolOptions() throws Exception {
MvcResult mvcResult = this.requestGetWithOkAndReturn(PROJECT_RESOURCE_POOL_OPTIONS);
// 获取返回值
String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
// 返回请求正常
Assertions.assertNotNull(resultHolder);
}
}

View File

@ -3,6 +3,7 @@ package io.metersphere.system.controller;
import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.system.dto.sdk.BasePageRequest;
import io.metersphere.system.dto.sdk.OptionDTO;
import io.metersphere.system.dto.taskhub.ResourcePoolOptionsDTO;
import io.metersphere.system.dto.taskhub.TaskHubDTO;
import io.metersphere.system.dto.taskhub.TaskHubItemDTO;
import io.metersphere.system.dto.taskhub.TaskHubScheduleDTO;
@ -19,10 +20,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@ -69,4 +67,12 @@ public class OrganizationTaskHubController {
public List<TaskStatisticsResponse> calculateRate(@RequestBody List<String> ids) {
return baseTaskHubService.calculateRate(ids, SessionUtils.getCurrentOrganizationId(), null);
}
@GetMapping("/resource-pool/options")
@Operation(summary = "组织-任务中心-获取资源池下拉选项")
@RequiresPermissions(PermissionConstants.ORGANIZATION_CASE_TASK_CENTER_READ)
public List<ResourcePoolOptionsDTO> getUserProject() {
return baseTaskHubService.getOrgResourcePoolOptions(SessionUtils.getCurrentOrganizationId());
}
}

View File

@ -63,14 +63,13 @@ public class SystemTaskHubController {
@GetMapping("/resource-pool/options")
@Operation(summary = "系统-任务中心-获取资源池下拉选项")
@RequiresPermissions(PermissionConstants.SYSTEM_CASE_TASK_CENTER_READ)
public List<ResourcePoolOptionsDTO> getUserProject() {
return baseTaskHubService.getResourcePoolOptions();
}
//TODO 检查节点状态
//TODO 组织&项目 获取资源池下拉选项
//TODO 系统&组织&项目 任务按钮操作删除 停止 失败重跑 查看报告 批量删除 批量停止 批量失败重跑

View File

@ -10,6 +10,9 @@ import lombok.Data;
@Data
public class TaskHubItemDTO extends ExecTaskItem {
@Schema(description = "业务id")
private Long num;
@Schema(description = "任务名称")
private String taskName;

View File

@ -3,12 +3,13 @@
<mapper namespace="io.metersphere.system.mapper.ExtExecTaskItemMapper">
<select id="selectList" resultType="io.metersphere.system.dto.taskhub.TaskHubItemDTO">
SELECT *
SELECT exec_task_item.*, exec_task.num
FROM exec_task_item
inner join exec_task on exec_task_item.task_id = exec_task.id
<where>
<if test="request.keyword != null and request.keyword != ''">
and (
exec_task_item.task_id like concat('%', #{request.keyword},'%')
exec_task.num like concat('%', #{request.keyword},'%')
or exec_task_item.resource_name like concat('%', #{request.keyword},'%')
)
</if>

View File

@ -1,6 +1,7 @@
package io.metersphere.system.mapper;
import io.metersphere.system.domain.TestResourcePool;
import io.metersphere.system.domain.TestResourcePoolOrganization;
import io.metersphere.system.dto.sdk.QueryResourcePoolRequest;
import org.apache.ibatis.annotations.Param;
@ -9,4 +10,8 @@ import java.util.List;
public interface ExtResourcePoolMapper {
List<TestResourcePool> getResourcePoolList(@Param("request") QueryResourcePoolRequest request);
List<TestResourcePool> selectAllResourcePool(@Param("poolIds")List<String> poolIds);
List<TestResourcePool> selectProjectAllResourcePool(@Param("poolIds")List<String> poolIds);
}

View File

@ -60,4 +60,31 @@
</sql>
<select id="selectAllResourcePool" resultType="io.metersphere.system.domain.TestResourcePool">
SELECT id, name
FROM test_resource_pool
where deleted = false
<if test="poolIds != null and poolIds.size() > 0 ">
and (all_org = true or id
<foreach collection="poolIds" item="poolId" open="(" separator="," close=")">
#{poolId}
</foreach>
)
</if>
<if test="poolIds == null or poolIds.size() == 0">
and all_org = true
</if>
</select>
<select id="selectProjectAllResourcePool" resultType="io.metersphere.system.domain.TestResourcePool">
SELECT id, name
FROM test_resource_pool
where deleted = false and id in
<foreach collection="poolIds" item="poolId" open="(" separator="," close=")">
#{poolId}
</foreach>
</select>
</mapper>

View File

@ -2,6 +2,9 @@ package io.metersphere.system.service;
import com.github.pagehelper.Page;
import com.github.pagehelper.page.PageMethod;
import io.metersphere.project.domain.ProjectTestResourcePool;
import io.metersphere.project.domain.ProjectTestResourcePoolExample;
import io.metersphere.project.mapper.ProjectTestResourcePoolMapper;
import io.metersphere.sdk.constants.ExecStatus;
import io.metersphere.sdk.constants.ResultStatus;
import io.metersphere.sdk.util.JSON;
@ -59,6 +62,12 @@ public class BaseTaskHubService {
private TestResourcePoolMapper testResourcePoolMapper;
@Resource
private TestResourcePoolBlobMapper testResourcePoolBlobMapper;
@Resource
private TestResourcePoolOrganizationMapper testResourcePoolOrganizationMapper;
@Resource
private ExtResourcePoolMapper extResourcePoolMapper;
@Resource
private ProjectTestResourcePoolMapper projectTestResourcePoolMapper;
/**
* 系统-获取执行任务列表
@ -230,15 +239,19 @@ public class BaseTaskHubService {
TestResourcePoolExample example = new TestResourcePoolExample();
example.createCriteria().andDeletedEqualTo(false);
List<TestResourcePool> allResourcePools = testResourcePoolMapper.selectByExample(example);
Map<String, List<TestResourcePoolBlob>> poolMap = getPoolMap(allResourcePools);
return handleOptions(allResourcePools, poolMap);
}
private Map<String, List<TestResourcePoolBlob>> getPoolMap(List<TestResourcePool> allResourcePools) {
List<String> ids = allResourcePools.stream().map(TestResourcePool::getId).toList();
//获取全部资源池节点
TestResourcePoolBlobExample blobExample = new TestResourcePoolBlobExample();
blobExample.createCriteria().andIdIn(ids);
List<TestResourcePoolBlob> testResourcePoolBlobs = testResourcePoolBlobMapper.selectByExampleWithBLOBs(blobExample);
Map<String, List<TestResourcePoolBlob>> poolMap = testResourcePoolBlobs.stream().collect(Collectors.groupingBy(TestResourcePoolBlob::getId));
return handleOptions(allResourcePools, poolMap);
return poolMap;
}
private List<ResourcePoolOptionsDTO> handleOptions(List<TestResourcePool> allResourcePools, Map<String, List<TestResourcePoolBlob>> poolMap) {
@ -264,4 +277,43 @@ public class BaseTaskHubService {
return options;
}
/**
* 获取组织下的资源池及节点下拉选项
*
* @param orgId
* @return
*/
public List<ResourcePoolOptionsDTO> getOrgResourcePoolOptions(String orgId) {
TestResourcePoolOrganizationExample example = new TestResourcePoolOrganizationExample();
example.createCriteria().andOrgIdEqualTo(orgId);
List<TestResourcePoolOrganization> orgPools = testResourcePoolOrganizationMapper.selectByExample(example);
List<String> poolIds = orgPools.stream().map(TestResourcePoolOrganization::getTestResourcePoolId).toList();
List<TestResourcePool> allResourcePools = extResourcePoolMapper.selectAllResourcePool(poolIds);
if (CollectionUtils.isEmpty(allResourcePools)) {
return null;
}
Map<String, List<TestResourcePoolBlob>> poolMap = getPoolMap(allResourcePools);
return handleOptions(allResourcePools, poolMap);
}
/**
* 获取项目下的资源池及节点下拉选项
*
* @param projectId
* @return
*/
public List<ResourcePoolOptionsDTO> getProjectResourcePoolOptions(String projectId) {
ProjectTestResourcePoolExample example = new ProjectTestResourcePoolExample();
example.createCriteria().andProjectIdEqualTo(projectId);
List<ProjectTestResourcePool> projectPools = projectTestResourcePoolMapper.selectByExample(example);
List<String> poolIds = projectPools.stream().map(ProjectTestResourcePool::getTestResourcePoolId).toList();
if (CollectionUtils.isNotEmpty(poolIds)) {
List<TestResourcePool> allResourcePools = extResourcePoolMapper.selectProjectAllResourcePool(poolIds);
Map<String, List<TestResourcePoolBlob>> poolMap = getPoolMap(allResourcePools);
return handleOptions(allResourcePools, poolMap);
}
return null;
}
}

View File

@ -129,6 +129,7 @@ public class BaseTaskHubControllerTests extends BaseTest {
public static final String ORG_SCHEDULE_TASK_PAGE = "/organization/task-center/schedule/page";
public static final String ORG_TASK_ITEM_PAGE = "/organization/task-center/exec-task/item/page";
public static final String ORG_STATISTICS = "/organization/task-center/exec-task/statistics";
public static final String ORG_RESOURCE_POOL_OPTIONS = "/organization/task-center/resource-pool/options";
@Test
@Order(20)
@ -198,6 +199,21 @@ public class BaseTaskHubControllerTests extends BaseTest {
}
/**
* 组织获取资源池下拉选项
*/
@Test
@Order(5)
public void getOrgResourcePoolOptions() throws Exception {
MvcResult mvcResult = this.requestGetWithOkAndReturn(ORG_RESOURCE_POOL_OPTIONS);
// 获取返回值
String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
// 返回请求正常
Assertions.assertNotNull(resultHolder);
}
@Test
@Order(21)
public void testInsert() throws Exception {