refactor(系统设置): 优化项目创建资源池的传参

This commit is contained in:
wxg0103 2023-09-22 18:42:50 +08:00 committed by 刘瑞斌
parent 15711f3a31
commit 1f3245fbcb
3 changed files with 16 additions and 13 deletions

View File

@ -153,10 +153,10 @@ public class SystemProjectController {
return userService.getUserList(keyword);
}
@GetMapping("/pool-options/{organizationId}")
@GetMapping("/pool-options")
@Operation(summary = "系统设置-系统-组织与项目-项目-获取资源池下拉选项")
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ)
public List<OptionDTO> getProjectOptions(@PathVariable String organizationId) {
public List<OptionDTO> getProjectOptions(@RequestParam(value = "organizationId",required = false) String organizationId) {
return systemProjectService.getTestResourcePoolOptions(organizationId);
}

View File

@ -591,14 +591,16 @@ public class CommonProjectService {
public List<OptionDTO> getTestResourcePoolOptions(String organizationId) {
//获取制定组织的资源池 和全部组织的资源池
List<TestResourcePool> testResourcePools = new ArrayList<>();
TestResourcePoolOrganizationExample example = new TestResourcePoolOrganizationExample();
example.createCriteria().andOrgIdEqualTo(organizationId);
List<TestResourcePoolOrganization> orgPools = testResourcePoolOrganizationMapper.selectByExample(example);
if (CollectionUtils.isNotEmpty(orgPools)) {
List<String> poolIds = orgPools.stream().map(TestResourcePoolOrganization::getTestResourcePoolId).toList();
TestResourcePoolExample poolExample = new TestResourcePoolExample();
poolExample.createCriteria().andIdIn(poolIds).andEnableEqualTo(true).andDeletedEqualTo(false);
testResourcePools.addAll(testResourcePoolMapper.selectByExample(poolExample));
if (StringUtils.isNotBlank(organizationId)) {
TestResourcePoolOrganizationExample example = new TestResourcePoolOrganizationExample();
example.createCriteria().andOrgIdEqualTo(organizationId);
List<TestResourcePoolOrganization> orgPools = testResourcePoolOrganizationMapper.selectByExample(example);
if (CollectionUtils.isNotEmpty(orgPools)) {
List<String> poolIds = orgPools.stream().map(TestResourcePoolOrganization::getTestResourcePoolId).toList();
TestResourcePoolExample poolExample = new TestResourcePoolExample();
poolExample.createCriteria().andIdIn(poolIds).andEnableEqualTo(true).andDeletedEqualTo(false);
testResourcePools.addAll(testResourcePoolMapper.selectByExample(poolExample));
}
}
//获取应用全部组织的资源池
TestResourcePoolExample poolExample = new TestResourcePoolExample();

View File

@ -68,7 +68,7 @@ public class SystemProjectControllerTests extends BaseTest {
private final static String disableProject = prefix + "/disable/";
private final static String enableProject = prefix + "/enable/";
private final static String userList = prefix + "/user-list";
private final static String getPoolOptions = prefix + "/pool-options/";
private final static String getPoolOptions = prefix + "/pool-options";
private static final ResultMatcher BAD_REQUEST_MATCHER = status().isBadRequest();
private static final ResultMatcher ERROR_REQUEST_MATCHER = status().is5xxServerError();
@ -767,8 +767,9 @@ public class SystemProjectControllerTests extends BaseTest {
@Test
@Order(22)
public void testGetOptions() throws Exception {
this.requestGetWithOkAndReturn(getPoolOptions + "organizationId");
this.requestGetWithOkAndReturn(getPoolOptions);
this.requestGetWithOkAndReturn(getPoolOptions + "?organizationId=organizationId");
// @@校验权限
requestGetPermissionTest(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ, getPoolOptions + "organizationId");
requestGetPermissionTest(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ, getPoolOptions + "?organizationId=organizationId");
}
}