refactor(系统设置): 优化项目返回的参数
This commit is contained in:
parent
7c5792d539
commit
809af2ddd4
|
@ -12,9 +12,11 @@ import java.util.List;
|
|||
@EqualsAndHashCode(callSuper = false)
|
||||
public class ProjectDTO extends Project {
|
||||
@Schema(description = "项目成员数量", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
|
||||
private String number;
|
||||
private long memberCount;
|
||||
@Schema(description = "所属组织", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
|
||||
private String organizationName;
|
||||
@Schema(description = "管理员", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
|
||||
private List<User> adminList;
|
||||
@Schema(description = "创建人是否是管理员", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
|
||||
private boolean projectCreateUserIsAdmin;
|
||||
}
|
||||
|
|
|
@ -94,6 +94,24 @@ public class OrganizationProjectController {
|
|||
return organizationProjectService.revoke(id);
|
||||
}
|
||||
|
||||
@GetMapping("/enable/{id}")
|
||||
@Operation(summary = "启用项目")
|
||||
@Parameter(name = "id", description = "项目ID", schema = @Schema(requiredMode = Schema.RequiredMode.REQUIRED))
|
||||
@Log(type = OperationLogType.UPDATE, expression = "#msClass.updateLog(#id)", msClass = OrganizationProjectLogService.class)
|
||||
@RequiresPermissions(PermissionConstants.ORGANIZATION_PROJECT_READ_UPDATE)
|
||||
public void enable(@PathVariable String id) {
|
||||
organizationProjectService.enable(id);
|
||||
}
|
||||
|
||||
@GetMapping("/disable/{id}")
|
||||
@Operation(summary = "禁用项目")
|
||||
@Parameter(name = "id", description = "项目ID", schema = @Schema(requiredMode = Schema.RequiredMode.REQUIRED))
|
||||
@RequiresPermissions(PermissionConstants.ORGANIZATION_PROJECT_READ_UPDATE)
|
||||
@Log(type = OperationLogType.UPDATE, expression = "#msClass.updateLog(#id)", msClass = OrganizationProjectLogService.class)
|
||||
public void disable(@PathVariable String id) {
|
||||
organizationProjectService.disable(id);
|
||||
}
|
||||
|
||||
@PostMapping("/member-list")
|
||||
@RequiresPermissions(PermissionConstants.ORGANIZATION_PROJECT_READ)
|
||||
@Operation(summary = "获取项目下成员列表")
|
||||
|
|
|
@ -29,6 +29,7 @@ import org.springframework.validation.annotation.Validated;
|
|||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author song-cc-rock
|
||||
|
@ -103,4 +104,11 @@ public class SystemOrganizationController {
|
|||
BeanUtils.copyBean(projectRequest, request);
|
||||
return PageUtils.setPageInfo(page, systemProjectService.getProjectList(projectRequest));
|
||||
}
|
||||
|
||||
@GetMapping("/total")
|
||||
@Operation(summary = "获取组织和项目总数")
|
||||
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ)
|
||||
public Map<String, Long> getTotal(@RequestParam(value = "organizationId",required = false) String organizationId) {
|
||||
return organizationService.getTotal(organizationId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,6 +86,7 @@ public class SystemProjectController {
|
|||
}
|
||||
|
||||
@GetMapping("/revoke/{id}")
|
||||
@Operation(summary = "撤销项目")
|
||||
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ_RECOVER)
|
||||
@Log(type = OperationLogType.UPDATE, expression = "#msClass.recoverLog(#id)", msClass = SystemProjectLogService.class)
|
||||
@Parameter(name = "id", description = "项目", schema = @Schema(requiredMode = Schema.RequiredMode.REQUIRED))
|
||||
|
@ -93,6 +94,24 @@ public class SystemProjectController {
|
|||
return systemProjectService.revoke(id);
|
||||
}
|
||||
|
||||
@GetMapping("/enable/{id}")
|
||||
@Operation(summary = "启用项目")
|
||||
@Parameter(name = "id", description = "项目ID", schema = @Schema(requiredMode = Schema.RequiredMode.REQUIRED))
|
||||
@Log(type = OperationLogType.UPDATE, expression = "#msClass.updateLog(#id)", msClass = SystemProjectLogService.class)
|
||||
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ_UPDATE)
|
||||
public void enable(@PathVariable String id) {
|
||||
systemProjectService.enable(id);
|
||||
}
|
||||
|
||||
@GetMapping("/disable/{id}")
|
||||
@Operation(summary = "禁用项目")
|
||||
@Parameter(name = "id", description = "项目ID", schema = @Schema(requiredMode = Schema.RequiredMode.REQUIRED))
|
||||
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ_UPDATE)
|
||||
@Log(type = OperationLogType.UPDATE, expression = "#msClass.updateLog(#id)", msClass = SystemProjectLogService.class)
|
||||
public void disable(@PathVariable String id) {
|
||||
systemProjectService.disable(id);
|
||||
}
|
||||
|
||||
@PostMapping("/member-list")
|
||||
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ)
|
||||
@Operation(summary = "获取项目下成员列表")
|
||||
|
|
|
@ -43,4 +43,10 @@ public class OrganizationDTO extends Organization {
|
|||
@Schema(description = "组织管理员ID集合")
|
||||
@NotEmpty(groups = {Created.class, Updated.class}, message = "{member.id.not_empty}")
|
||||
private List<String> memberIds;
|
||||
|
||||
/**
|
||||
* 创建人是否是管理员
|
||||
*/
|
||||
@Schema(description = "创建人是否是管理员")
|
||||
private boolean orgCreateUserIsAdmin;
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
p.deleted,
|
||||
p.delete_user,
|
||||
p.enable,
|
||||
count(distinct u.id) as number,
|
||||
count(distinct u.id) as memberCount,
|
||||
o.name as organizationName
|
||||
FROM project p
|
||||
LEFT JOIN user_role_relation u on p.id = u.source_id
|
||||
|
|
|
@ -185,6 +185,11 @@ public class CommonProjectService {
|
|||
projectList.forEach(projectDTO -> {
|
||||
List<User> users = extSystemProjectMapper.getProjectAdminList(projectDTO.getId());
|
||||
projectDTO.setAdminList(users);
|
||||
List<String> userIds = users.stream().map(User::getId).collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(userIds) && userIds.contains(projectDTO.getCreateUser())) {
|
||||
projectDTO.setProjectCreateUserIsAdmin(true);
|
||||
}
|
||||
|
||||
});
|
||||
return projectList;
|
||||
}
|
||||
|
@ -463,4 +468,22 @@ public class CommonProjectService {
|
|||
dto.setOriginalValue(JSON.toJSONBytes(StringUtils.EMPTY));
|
||||
logDTOList.add(dto);
|
||||
}
|
||||
|
||||
public void enable(String id) {
|
||||
checkProjectNotExist(id);
|
||||
Project project = new Project();
|
||||
project.setId(id);
|
||||
project.setEnable(true);
|
||||
project.setUpdateTime(System.currentTimeMillis());
|
||||
projectMapper.updateByPrimaryKeySelective(project);
|
||||
}
|
||||
|
||||
public void disable(String id) {
|
||||
checkProjectNotExist(id);
|
||||
Project project = new Project();
|
||||
project.setId(id);
|
||||
project.setEnable(false);
|
||||
project.setUpdateTime(System.currentTimeMillis());
|
||||
projectMapper.updateByPrimaryKeySelective(project);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package io.metersphere.system.service;
|
|||
|
||||
import io.metersphere.project.domain.Project;
|
||||
import io.metersphere.project.mapper.ProjectMapper;
|
||||
import io.metersphere.sdk.constants.HttpMethodConstants;
|
||||
import io.metersphere.sdk.dto.AddProjectRequest;
|
||||
import io.metersphere.sdk.dto.LogDTO;
|
||||
import io.metersphere.sdk.dto.UpdateProjectRequest;
|
||||
|
@ -60,6 +61,24 @@ public class OrganizationProjectLogService {
|
|||
return null;
|
||||
}
|
||||
|
||||
public LogDTO updateLog(String id) {
|
||||
Project project = projectMapper.selectByPrimaryKey(id);
|
||||
if (project != null) {
|
||||
LogDTO dto = new LogDTO(
|
||||
project.getId(),
|
||||
project.getOrganizationId(),
|
||||
project.getId(),
|
||||
project.getCreateUser(),
|
||||
OperationLogType.UPDATE.name(),
|
||||
OperationLogModule.SYSTEM_PROJECT,
|
||||
project.getName());
|
||||
dto.setMethod(HttpMethodConstants.GET.name());
|
||||
|
||||
dto.setOriginalValue(JSON.toJSONBytes(project));
|
||||
return dto;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除接口日志
|
||||
|
|
|
@ -93,4 +93,11 @@ public class OrganizationProjectService {
|
|||
return commonProjectService.revoke(id);
|
||||
}
|
||||
|
||||
public void enable(String id) {
|
||||
commonProjectService.enable(id);
|
||||
}
|
||||
|
||||
public void disable(String id) {
|
||||
commonProjectService.disable(id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -772,6 +772,10 @@ public class OrganizationService {
|
|||
organizationDTOS.forEach(organizationDTO -> {
|
||||
List<User> orgAdminList = extOrganizationMapper.getOrgAdminList(organizationDTO.getId());
|
||||
organizationDTO.setOrgAdmins(orgAdminList);
|
||||
List<String> userIds = orgAdminList.stream().map(User::getId).collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(userIds) && userIds.contains(organizationDTO.getCreateUser())) {
|
||||
organizationDTO.setOrgCreateUserIsAdmin(true);
|
||||
}
|
||||
});
|
||||
return organizationDTOS;
|
||||
}
|
||||
|
@ -810,4 +814,22 @@ public class OrganizationService {
|
|||
}
|
||||
return extOrganizationMapper.getOptionsByIds(orgIds);
|
||||
}
|
||||
|
||||
|
||||
public Map<String, Long> getTotal(String organizationId) {
|
||||
Map<String, Long> total = new HashMap<>();
|
||||
ProjectExample projectExample = new ProjectExample();
|
||||
OrganizationExample organizationExample = new OrganizationExample();
|
||||
if (StringUtils.isBlank(organizationId)) {
|
||||
// 统计所有项目
|
||||
total.put("projectTotal", projectMapper.countByExample(projectExample));
|
||||
total.put("organizationTotal", organizationMapper.countByExample(organizationExample));
|
||||
} else {
|
||||
// 统计组织下的项目
|
||||
projectExample.createCriteria().andOrganizationIdEqualTo(organizationId);
|
||||
total.put("projectTotal", projectMapper.countByExample(projectExample));
|
||||
total.put("organizationTotal", 1L);
|
||||
}
|
||||
return total;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package io.metersphere.system.service;
|
|||
|
||||
import io.metersphere.project.domain.Project;
|
||||
import io.metersphere.project.mapper.ProjectMapper;
|
||||
import io.metersphere.sdk.constants.HttpMethodConstants;
|
||||
import io.metersphere.sdk.dto.AddProjectRequest;
|
||||
import io.metersphere.sdk.dto.LogDTO;
|
||||
import io.metersphere.sdk.dto.UpdateProjectRequest;
|
||||
|
@ -60,6 +61,25 @@ public class SystemProjectLogService {
|
|||
return null;
|
||||
}
|
||||
|
||||
public LogDTO updateLog(String id) {
|
||||
Project project = projectMapper.selectByPrimaryKey(id);
|
||||
if (project != null) {
|
||||
LogDTO dto = new LogDTO(
|
||||
project.getId(),
|
||||
project.getOrganizationId(),
|
||||
project.getId(),
|
||||
project.getCreateUser(),
|
||||
OperationLogType.UPDATE.name(),
|
||||
OperationLogModule.SYSTEM_PROJECT,
|
||||
project.getName());
|
||||
dto.setMethod(HttpMethodConstants.GET.name());
|
||||
|
||||
dto.setOriginalValue(JSON.toJSONBytes(project));
|
||||
return dto;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除接口日志
|
||||
|
|
|
@ -98,4 +98,12 @@ public class SystemProjectService {
|
|||
public List<OrganizationProjectOptionsDTO> getProjectOptions() {
|
||||
return extSystemProjectMapper.selectProjectOptions();
|
||||
}
|
||||
|
||||
public void enable(String id) {
|
||||
commonProjectService.enable(id);
|
||||
}
|
||||
|
||||
public void disable(String id) {
|
||||
commonProjectService.disable(id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,6 +68,8 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
|||
private final static String getProjectMemberList = prefix + "/member-list";
|
||||
private final static String addProjectMember = prefix + "/add-members";
|
||||
private final static String removeProjectMember = prefix + "/remove-member/";
|
||||
private final static String disableProject = prefix + "/disable/";
|
||||
private final static String enableProject = prefix + "/enable/";
|
||||
private static final ResultMatcher BAD_REQUEST_MATCHER = status().isBadRequest();
|
||||
private static final ResultMatcher ERROR_REQUEST_MATCHER = status().is5xxServerError();
|
||||
|
||||
|
@ -665,4 +667,42 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
|||
this.responseGet(removeProjectMember + projectId + "/" + userId, ERROR_REQUEST_MATCHER);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(19)
|
||||
public void disableSuccess() throws Exception {
|
||||
String id = "projectId";
|
||||
this.responseGet(disableProject + id,status().isOk());
|
||||
Project currentProject = projectMapper.selectByPrimaryKey(id);
|
||||
Assertions.assertEquals(currentProject.getEnable(), false);
|
||||
checkLog(id, OperationLogType.UPDATE);
|
||||
// @@校验权限
|
||||
requestGetPermissionTest(PermissionConstants.ORGANIZATION_PROJECT_READ_UPDATE, disableProject + id);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(20)
|
||||
public void disableError() throws Exception {
|
||||
String id = "1111";
|
||||
this.responseGet(disableProject + id, ERROR_REQUEST_MATCHER);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(19)
|
||||
public void enableSuccess() throws Exception {
|
||||
String id = "projectId";
|
||||
this.responseGet(enableProject + id,status().isOk());
|
||||
Project currentProject = projectMapper.selectByPrimaryKey(id);
|
||||
Assertions.assertEquals(currentProject.getEnable(), true);
|
||||
checkLog(id, OperationLogType.UPDATE);
|
||||
// @@校验权限
|
||||
requestGetPermissionTest(PermissionConstants.ORGANIZATION_PROJECT_READ_UPDATE, enableProject + id);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(20)
|
||||
public void enableError() throws Exception {
|
||||
String id = "1111";
|
||||
this.responseGet(enableProject + id, ERROR_REQUEST_MATCHER);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,7 +29,6 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
|||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
|
@ -49,6 +48,7 @@ public class SystemOrganizationControllerTests extends BaseTest{
|
|||
public static final String ORGANIZATION_REMOVE_MEMBER = "/system/organization/remove-member";
|
||||
public static final String ORGANIZATION_LIST_PROJECT = "/system/organization/list-project";
|
||||
public static final String ORGANIZATION_MEMBER_OPTION = "/system/user/get-option";
|
||||
public static final String ORGANIZATION_TOTAL = "/system/organization/total";
|
||||
|
||||
@Test
|
||||
@Order(0)
|
||||
|
@ -415,6 +415,23 @@ public class SystemOrganizationControllerTests extends BaseTest{
|
|||
requestGetPermissionTest(PermissionConstants.SYSTEM_USER_READ, SystemOrganizationControllerTests.ORGANIZATION_MEMBER_OPTION + "/default-organization-2");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(17)
|
||||
public void testGetTotal() throws Exception {
|
||||
// 组织不存在
|
||||
MvcResult mvcResult = this.responseGet(SystemOrganizationControllerTests.ORGANIZATION_TOTAL + "?organizationId=default-organization-2");
|
||||
// 获取返回值
|
||||
String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
||||
Map<String, Integer> resultHolder = JSON.parseObject(returnData, Map.class);
|
||||
|
||||
mvcResult = this.responseGet(SystemOrganizationControllerTests.ORGANIZATION_TOTAL);
|
||||
// 获取返回值
|
||||
returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
||||
resultHolder = JSON.parseObject(returnData, Map.class);
|
||||
// 返回请求正常
|
||||
Assertions.assertNotNull(resultHolder);
|
||||
}
|
||||
|
||||
private void requestPost(String url, Object param, ResultMatcher resultMatcher) throws Exception {
|
||||
mockMvc.perform(MockMvcRequestBuilders.post(url)
|
||||
.header(SessionConstants.HEADER_TOKEN, sessionId)
|
||||
|
|
|
@ -66,6 +66,8 @@ public class SystemProjectControllerTests extends BaseTest {
|
|||
private final static String getProjectMemberList = prefix + "/member-list";
|
||||
private final static String addProjectMember = prefix + "/add-member";
|
||||
private final static String removeProjectMember = prefix + "/remove-member/";
|
||||
private final static String disableProject = prefix + "/disable/";
|
||||
private final static String enableProject = prefix + "/enable/";
|
||||
private static final ResultMatcher BAD_REQUEST_MATCHER = status().isBadRequest();
|
||||
private static final ResultMatcher ERROR_REQUEST_MATCHER = status().is5xxServerError();
|
||||
|
||||
|
@ -484,6 +486,8 @@ public class SystemProjectControllerTests extends BaseTest {
|
|||
this.responseGet(revokeProject + id, ERROR_REQUEST_MATCHER);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
@Order(13)
|
||||
public void testAddProjectMember() throws Exception{
|
||||
|
@ -627,4 +631,42 @@ public class SystemProjectControllerTests extends BaseTest {
|
|||
this.responseGet(removeProjectMember + projectId + "/" + userId, ERROR_REQUEST_MATCHER);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(19)
|
||||
public void disableSuccess() throws Exception {
|
||||
String id = "projectId";
|
||||
this.responseGet(disableProject + id,status().isOk());
|
||||
Project currentProject = projectMapper.selectByPrimaryKey(id);
|
||||
Assertions.assertEquals(currentProject.getEnable(), false);
|
||||
checkLog(id, OperationLogType.UPDATE);
|
||||
// @@校验权限
|
||||
requestGetPermissionTest(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ_UPDATE, disableProject + id);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(20)
|
||||
public void disableError() throws Exception {
|
||||
String id = "1111";
|
||||
this.responseGet(disableProject + id, ERROR_REQUEST_MATCHER);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(19)
|
||||
public void enableSuccess() throws Exception {
|
||||
String id = "projectId";
|
||||
this.responseGet(enableProject + id,status().isOk());
|
||||
Project currentProject = projectMapper.selectByPrimaryKey(id);
|
||||
Assertions.assertEquals(currentProject.getEnable(), true);
|
||||
checkLog(id, OperationLogType.UPDATE);
|
||||
// @@校验权限
|
||||
requestGetPermissionTest(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ_UPDATE, enableProject + id);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(20)
|
||||
public void enableError() throws Exception {
|
||||
String id = "1111";
|
||||
this.responseGet(enableProject + id, ERROR_REQUEST_MATCHER);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue