refactor(系统设置): 优化项目查询资源池
This commit is contained in:
parent
015065282f
commit
83e8f78e6c
|
@ -4,23 +4,20 @@ package io.metersphere.system.controller;
|
|||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import io.metersphere.sdk.constants.PermissionConstants;
|
||||
import io.metersphere.system.dto.sdk.OptionDTO;
|
||||
import io.metersphere.system.dto.user.UserExtendDTO;
|
||||
import io.metersphere.system.security.CheckOwner;
|
||||
import io.metersphere.system.utils.PageUtils;
|
||||
import io.metersphere.system.utils.Pager;
|
||||
import io.metersphere.system.dto.AddProjectRequest;
|
||||
import io.metersphere.system.dto.ProjectDTO;
|
||||
import io.metersphere.system.dto.UpdateProjectNameRequest;
|
||||
import io.metersphere.system.dto.UpdateProjectRequest;
|
||||
import io.metersphere.system.dto.request.*;
|
||||
import io.metersphere.system.dto.sdk.OptionDTO;
|
||||
import io.metersphere.system.dto.user.UserExtendDTO;
|
||||
import io.metersphere.system.log.annotation.Log;
|
||||
import io.metersphere.system.log.constants.OperationLogType;
|
||||
import io.metersphere.system.dto.request.OrganizationProjectRequest;
|
||||
import io.metersphere.system.dto.request.ProjectAddMemberBatchRequest;
|
||||
import io.metersphere.system.dto.request.ProjectAddMemberRequest;
|
||||
import io.metersphere.system.dto.request.ProjectMemberRequest;
|
||||
import io.metersphere.system.security.CheckOwner;
|
||||
import io.metersphere.system.service.OrganizationProjectLogService;
|
||||
import io.metersphere.system.service.OrganizationProjectService;
|
||||
import io.metersphere.system.utils.PageUtils;
|
||||
import io.metersphere.system.utils.Pager;
|
||||
import io.metersphere.system.utils.SessionUtils;
|
||||
import io.metersphere.validation.groups.Created;
|
||||
import io.metersphere.validation.groups.Updated;
|
||||
|
@ -168,11 +165,11 @@ public class OrganizationProjectController {
|
|||
return organizationProjectService.getUserMemberList(organizationId, projectId, keyword);
|
||||
}
|
||||
|
||||
@GetMapping("/pool-options/{organizationId}")
|
||||
@PostMapping("/pool-options")
|
||||
@Operation(summary = "系统设置-组织-项目-获取资源池下拉选项")
|
||||
@RequiresPermissions(PermissionConstants.ORGANIZATION_PROJECT_READ)
|
||||
public List<OptionDTO> getProjectOptions(@PathVariable String organizationId) {
|
||||
return organizationProjectService.getTestResourcePoolOptions(organizationId);
|
||||
public List<OptionDTO> getProjectOptions(@Validated @RequestBody ProjectPoolRequest request) {
|
||||
return organizationProjectService.getTestResourcePoolOptions(request);
|
||||
}
|
||||
|
||||
@PostMapping("/rename")
|
||||
|
|
|
@ -4,25 +4,22 @@ package io.metersphere.system.controller;
|
|||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import io.metersphere.sdk.constants.PermissionConstants;
|
||||
import io.metersphere.system.dto.sdk.OptionDTO;
|
||||
import io.metersphere.system.dto.user.UserExtendDTO;
|
||||
import io.metersphere.system.security.CheckOwner;
|
||||
import io.metersphere.system.utils.PageUtils;
|
||||
import io.metersphere.system.utils.Pager;
|
||||
import io.metersphere.system.domain.User;
|
||||
import io.metersphere.system.dto.AddProjectRequest;
|
||||
import io.metersphere.system.dto.ProjectDTO;
|
||||
import io.metersphere.system.dto.UpdateProjectNameRequest;
|
||||
import io.metersphere.system.dto.UpdateProjectRequest;
|
||||
import io.metersphere.system.dto.request.*;
|
||||
import io.metersphere.system.dto.sdk.OptionDTO;
|
||||
import io.metersphere.system.dto.user.UserExtendDTO;
|
||||
import io.metersphere.system.log.annotation.Log;
|
||||
import io.metersphere.system.log.constants.OperationLogType;
|
||||
import io.metersphere.system.dto.request.ProjectAddMemberBatchRequest;
|
||||
import io.metersphere.system.dto.request.ProjectAddMemberRequest;
|
||||
import io.metersphere.system.dto.request.ProjectMemberRequest;
|
||||
import io.metersphere.system.dto.request.ProjectRequest;
|
||||
import io.metersphere.system.security.CheckOwner;
|
||||
import io.metersphere.system.service.SystemProjectLogService;
|
||||
import io.metersphere.system.service.SystemProjectService;
|
||||
import io.metersphere.system.service.UserService;
|
||||
import io.metersphere.system.utils.PageUtils;
|
||||
import io.metersphere.system.utils.Pager;
|
||||
import io.metersphere.system.utils.SessionUtils;
|
||||
import io.metersphere.validation.groups.Created;
|
||||
import io.metersphere.validation.groups.Updated;
|
||||
|
@ -164,11 +161,11 @@ public class SystemProjectController {
|
|||
return userService.getUserList(keyword);
|
||||
}
|
||||
|
||||
@GetMapping("/pool-options")
|
||||
@PostMapping("/pool-options")
|
||||
@Operation(summary = "系统设置-系统-组织与项目-项目-获取资源池下拉选项")
|
||||
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ)
|
||||
public List<OptionDTO> getProjectOptions(@RequestParam(value = "organizationId",required = false) String organizationId) {
|
||||
return systemProjectService.getTestResourcePoolOptions(organizationId);
|
||||
public List<OptionDTO> getProjectOptions(@Validated @RequestBody ProjectPoolRequest request) {
|
||||
return systemProjectService.getTestResourcePoolOptions(request);
|
||||
}
|
||||
|
||||
@PostMapping("/rename")
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
package io.metersphere.system.dto.request;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class ProjectPoolRequest implements Serializable {
|
||||
@Schema(description = "组织id")
|
||||
@Size(min = 0, max = 50, message = "project.organization_id.length_range")
|
||||
private String organizationId;
|
||||
|
||||
@Schema(description = "项目开启的模块id集合")
|
||||
@NotEmpty
|
||||
private List<String> modulesIds;
|
||||
}
|
|
@ -18,6 +18,7 @@ import io.metersphere.sdk.util.Translator;
|
|||
import io.metersphere.system.domain.*;
|
||||
import io.metersphere.system.dto.*;
|
||||
import io.metersphere.system.dto.request.ProjectAddMemberBatchRequest;
|
||||
import io.metersphere.system.dto.request.ProjectPoolRequest;
|
||||
import io.metersphere.system.dto.sdk.OptionDTO;
|
||||
import io.metersphere.system.dto.user.UserExtendDTO;
|
||||
import io.metersphere.system.invoker.ProjectServiceInvoker;
|
||||
|
@ -74,6 +75,9 @@ public class CommonProjectService {
|
|||
@Resource
|
||||
private TestResourcePoolService testResourcePoolService;
|
||||
public static final Integer DEFAULT_REMAIN_DAY_COUNT = 30;
|
||||
public static final String API_TEST = "apiTest";
|
||||
public static final String UI_TEST = "uiTest";
|
||||
public static final String LOAD_TEST = "loadTest";
|
||||
|
||||
@Autowired
|
||||
public CommonProjectService(ProjectServiceInvoker serviceInvoker) {
|
||||
|
@ -612,12 +616,13 @@ public class CommonProjectService {
|
|||
projectMapper.updateByPrimaryKeySelective(project);
|
||||
}
|
||||
|
||||
public List<OptionDTO> getTestResourcePoolOptions(String organizationId) {
|
||||
public List<OptionDTO> getTestResourcePoolOptions(ProjectPoolRequest request) {
|
||||
List<OptionDTO> optionDTOS = new ArrayList<>();
|
||||
//获取制定组织的资源池 和全部组织的资源池
|
||||
List<TestResourcePool> testResourcePools = new ArrayList<>();
|
||||
if (StringUtils.isNotBlank(organizationId)) {
|
||||
if (StringUtils.isNotBlank(request.getOrganizationId())) {
|
||||
TestResourcePoolOrganizationExample example = new TestResourcePoolOrganizationExample();
|
||||
example.createCriteria().andOrgIdEqualTo(organizationId);
|
||||
example.createCriteria().andOrgIdEqualTo(request.getOrganizationId());
|
||||
List<TestResourcePoolOrganization> orgPools = testResourcePoolOrganizationMapper.selectByExample(example);
|
||||
if (CollectionUtils.isNotEmpty(orgPools)) {
|
||||
List<String> poolIds = orgPools.stream().map(TestResourcePoolOrganization::getTestResourcePoolId).toList();
|
||||
|
@ -632,9 +637,19 @@ public class CommonProjectService {
|
|||
testResourcePools.addAll(testResourcePoolMapper.selectByExample(poolExample));
|
||||
|
||||
testResourcePools = testResourcePools.stream().filter(Objects::nonNull).distinct().collect(Collectors.toList());
|
||||
return testResourcePools.stream().map(testResourcePool ->
|
||||
new OptionDTO(testResourcePool.getId(), testResourcePool.getName())
|
||||
).toList();
|
||||
//这里需要获取项目开启的模块 判断资源池开启的使用范围的模块是否在项目开启的模块中
|
||||
List<String> moduleIds = request.getModulesIds();
|
||||
testResourcePools.forEach(pool -> {
|
||||
if ((moduleIds.contains(API_TEST) && pool.getApiTest()) ||
|
||||
(moduleIds.contains(LOAD_TEST) && pool.getLoadTest()) ||
|
||||
(moduleIds.contains(UI_TEST) && pool.getUiTest())) {
|
||||
OptionDTO optionDTO = new OptionDTO();
|
||||
optionDTO.setId(pool.getId());
|
||||
optionDTO.setName(pool.getName());
|
||||
optionDTOS.add(optionDTO);
|
||||
}
|
||||
});
|
||||
return optionDTOS;
|
||||
}
|
||||
|
||||
public void rename(UpdateProjectNameRequest request, String userId) {
|
||||
|
@ -653,6 +668,7 @@ public class CommonProjectService {
|
|||
|
||||
/**
|
||||
* 校验该项目是否有权限使用该资源池
|
||||
*
|
||||
* @param resourcePool
|
||||
* @return
|
||||
*/
|
||||
|
@ -683,6 +699,7 @@ public class CommonProjectService {
|
|||
|
||||
/**
|
||||
* 剩余天数
|
||||
*
|
||||
* @param deleteTime 删除时间
|
||||
* @return 剩余天数
|
||||
*/
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package io.metersphere.system.service;
|
||||
|
||||
import io.metersphere.system.dto.sdk.OptionDTO;
|
||||
import io.metersphere.system.dto.user.UserExtendDTO;
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.util.BeanUtils;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
|
@ -11,15 +9,14 @@ import io.metersphere.system.dto.AddProjectRequest;
|
|||
import io.metersphere.system.dto.ProjectDTO;
|
||||
import io.metersphere.system.dto.UpdateProjectNameRequest;
|
||||
import io.metersphere.system.dto.UpdateProjectRequest;
|
||||
import io.metersphere.system.dto.request.*;
|
||||
import io.metersphere.system.dto.sdk.OptionDTO;
|
||||
import io.metersphere.system.dto.user.UserExtendDTO;
|
||||
import io.metersphere.system.log.constants.OperationLogModule;
|
||||
import io.metersphere.system.log.constants.OperationLogType;
|
||||
import io.metersphere.system.mapper.ExtSystemProjectMapper;
|
||||
import io.metersphere.system.mapper.OrganizationMapper;
|
||||
import io.metersphere.system.mapper.UserRoleRelationMapper;
|
||||
import io.metersphere.system.dto.request.OrganizationProjectRequest;
|
||||
import io.metersphere.system.dto.request.ProjectAddMemberBatchRequest;
|
||||
import io.metersphere.system.dto.request.ProjectMemberRequest;
|
||||
import io.metersphere.system.dto.request.ProjectRequest;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
@ -131,8 +128,8 @@ public class OrganizationProjectService {
|
|||
}
|
||||
}
|
||||
|
||||
public List<OptionDTO> getTestResourcePoolOptions(String organizationId) {
|
||||
return commonProjectService.getTestResourcePoolOptions(organizationId);
|
||||
public List<OptionDTO> getTestResourcePoolOptions(ProjectPoolRequest request) {
|
||||
return commonProjectService.getTestResourcePoolOptions(request);
|
||||
}
|
||||
|
||||
public void rename(UpdateProjectNameRequest project, String userId) {
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
package io.metersphere.system.service;
|
||||
|
||||
import io.metersphere.project.domain.Project;
|
||||
import io.metersphere.system.dto.sdk.OptionDTO;
|
||||
import io.metersphere.system.dto.user.UserExtendDTO;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
import io.metersphere.system.dto.*;
|
||||
import io.metersphere.system.dto.request.ProjectAddMemberBatchRequest;
|
||||
import io.metersphere.system.dto.request.ProjectMemberRequest;
|
||||
import io.metersphere.system.dto.request.ProjectPoolRequest;
|
||||
import io.metersphere.system.dto.request.ProjectRequest;
|
||||
import io.metersphere.system.dto.sdk.OptionDTO;
|
||||
import io.metersphere.system.dto.user.UserExtendDTO;
|
||||
import io.metersphere.system.log.constants.OperationLogModule;
|
||||
import io.metersphere.system.log.constants.OperationLogType;
|
||||
import io.metersphere.system.mapper.ExtSystemProjectMapper;
|
||||
import io.metersphere.system.dto.request.ProjectAddMemberBatchRequest;
|
||||
import io.metersphere.system.dto.request.ProjectMemberRequest;
|
||||
import io.metersphere.system.dto.request.ProjectRequest;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -96,8 +97,8 @@ public class SystemProjectService {
|
|||
commonProjectService.disable(id, updateUser);
|
||||
}
|
||||
|
||||
public List<OptionDTO> getTestResourcePoolOptions(String organizationId) {
|
||||
return commonProjectService.getTestResourcePoolOptions(organizationId);
|
||||
public List<OptionDTO> getTestResourcePoolOptions(ProjectPoolRequest request) {
|
||||
return commonProjectService.getTestResourcePoolOptions(request);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ import io.metersphere.system.dto.*;
|
|||
import io.metersphere.system.dto.request.OrganizationProjectRequest;
|
||||
import io.metersphere.system.dto.request.ProjectAddMemberRequest;
|
||||
import io.metersphere.system.dto.request.ProjectMemberRequest;
|
||||
import io.metersphere.system.dto.request.ProjectPoolRequest;
|
||||
import io.metersphere.system.dto.user.UserDTO;
|
||||
import io.metersphere.system.dto.user.UserExtendDTO;
|
||||
import io.metersphere.system.invoker.ProjectServiceInvoker;
|
||||
|
@ -128,6 +129,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
|||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn();
|
||||
}
|
||||
|
||||
private void responseGet(String url, ResultMatcher resultMatcher) throws Exception {
|
||||
mockMvc.perform(MockMvcRequestBuilders.get(url)
|
||||
.header(SessionConstants.HEADER_TOKEN, sessionId)
|
||||
|
@ -148,6 +150,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void compareProjectDTO(Project currentProject, Project result) {
|
||||
Assertions.assertNotNull(currentProject);
|
||||
Assertions.assertNotNull(result);
|
||||
|
@ -173,6 +176,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
|||
addProjectDTO.setUserIds(userIds);
|
||||
return addProjectDTO;
|
||||
}
|
||||
|
||||
public UpdateProjectRequest generatorUpdate(String organizationId,
|
||||
String projectId,
|
||||
String name,
|
||||
|
@ -285,6 +289,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
|||
serviceInvoker.invokeCreateServices(initProject.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
@Sql(scripts = {"/dml/init_org_project.sql"},
|
||||
|
@ -391,7 +396,6 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
|||
Assertions.assertTrue(projectTestResourcePools.stream().map(ProjectTestResourcePool::getTestResourcePoolId).toList().contains("resourcePoolId"));
|
||||
|
||||
|
||||
|
||||
project.setName("organization-testAddProjectSuccess1");
|
||||
project.setOrganizationId(getDefault().getId());
|
||||
// @@校验权限
|
||||
|
@ -424,6 +428,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
|||
this.requestPost(addProject, project, ERROR_REQUEST_MATCHER);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
public void testGetProject() throws Exception {
|
||||
|
@ -448,6 +453,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
|||
// @@校验权限
|
||||
requestGetPermissionTest(PermissionConstants.ORGANIZATION_PROJECT_READ, getProject + projectId);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
public void testGetProjectError() throws Exception {
|
||||
|
@ -959,9 +965,12 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
|||
@Test
|
||||
@Order(23)
|
||||
public void testGetOptions() throws Exception {
|
||||
this.requestGetWithOkAndReturn(getPoolOptions + "organizationId");
|
||||
ProjectPoolRequest projectPoolRequest = new ProjectPoolRequest();
|
||||
projectPoolRequest.setModulesIds(List.of("apiTest", "uiTest", "loadTest"));
|
||||
projectPoolRequest.setOrganizationId(DEFAULT_ORGANIZATION_ID);
|
||||
this.responsePost(getPoolOptions, projectPoolRequest);
|
||||
// @@校验权限
|
||||
requestGetPermissionTest(PermissionConstants.ORGANIZATION_PROJECT_READ, getPoolOptions + DEFAULT_ORGANIZATION_ID);
|
||||
requestPostPermissionTest(PermissionConstants.ORGANIZATION_PROJECT_READ, getPoolOptions, projectPoolRequest);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -149,6 +149,7 @@ public class SystemProjectControllerTests extends BaseTest {
|
|||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn();
|
||||
}
|
||||
|
||||
private void responseGet(String url, ResultMatcher resultMatcher) throws Exception {
|
||||
mockMvc.perform(MockMvcRequestBuilders.get(url)
|
||||
.header(SessionConstants.HEADER_TOKEN, sessionId)
|
||||
|
@ -169,6 +170,7 @@ public class SystemProjectControllerTests extends BaseTest {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void compareProjectDTO(Project currentProject, Project result) {
|
||||
Assertions.assertNotNull(currentProject);
|
||||
Assertions.assertNotNull(result);
|
||||
|
@ -194,6 +196,7 @@ public class SystemProjectControllerTests extends BaseTest {
|
|||
addProjectDTO.setUserIds(userIds);
|
||||
return addProjectDTO;
|
||||
}
|
||||
|
||||
public UpdateProjectRequest generatorUpdate(String organizationId,
|
||||
String projectId,
|
||||
String name,
|
||||
|
@ -308,6 +311,7 @@ public class SystemProjectControllerTests extends BaseTest {
|
|||
serviceInvoker.invokeCreateServices(initProject.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
/**
|
||||
|
@ -624,6 +628,7 @@ public class SystemProjectControllerTests extends BaseTest {
|
|||
this.requestPost(addProject, project, ERROR_REQUEST_MATCHER);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
public void testGetProject() throws Exception {
|
||||
|
@ -643,6 +648,7 @@ public class SystemProjectControllerTests extends BaseTest {
|
|||
// @@校验权限
|
||||
requestGetPermissionTest(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ, getProject + projectId);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
public void testGetProjectError() throws Exception {
|
||||
|
@ -894,7 +900,6 @@ public class SystemProjectControllerTests extends BaseTest {
|
|||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
@Order(13)
|
||||
public void testAddProjectMember() throws Exception {
|
||||
|
@ -1091,10 +1096,13 @@ public class SystemProjectControllerTests extends BaseTest {
|
|||
@Test
|
||||
@Order(22)
|
||||
public void testGetOptions() throws Exception {
|
||||
this.requestGetWithOkAndReturn(getPoolOptions);
|
||||
this.requestGetWithOkAndReturn(getPoolOptions + "?organizationId=" + DEFAULT_ORGANIZATION_ID);
|
||||
ProjectPoolRequest projectPoolRequest = new ProjectPoolRequest();
|
||||
projectPoolRequest.setModulesIds(List.of("apiTest", "uiTest", "loadTest"));
|
||||
this.responsePost(getPoolOptions, projectPoolRequest);
|
||||
projectPoolRequest.setOrganizationId(DEFAULT_ORGANIZATION_ID);
|
||||
this.responsePost(getPoolOptions, projectPoolRequest);
|
||||
// @@校验权限
|
||||
requestGetPermissionTest(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ, getPoolOptions + "?organizationId=" + DEFAULT_ORGANIZATION_ID);
|
||||
requestPostPermissionTest(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ, getPoolOptions, projectPoolRequest);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue