refactor(系统设置): 删除重复代码

This commit is contained in:
shiziyuan9527 2022-12-26 11:14:25 +08:00 committed by lyh
parent 254e0d4959
commit 3489e6e306
5 changed files with 24 additions and 577 deletions

View File

@ -5,8 +5,8 @@ import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.*;
import io.metersphere.base.mapper.ext.ExtGroupMapper;
import io.metersphere.base.mapper.ext.BaseUserGroupMapper;
import io.metersphere.base.mapper.ext.ExtGroupMapper;
import io.metersphere.commons.constants.MicroServiceName;
import io.metersphere.commons.constants.RedisKey;
import io.metersphere.commons.constants.UserGroupConstants;
@ -516,23 +516,6 @@ public class GroupService {
}
}
private void addSystemGroupUser(Group group, List<String> userIds) {
for (String userId : userIds) {
User user = userMapper.selectByPrimaryKey(userId);
if (user == null) {
continue;
}
UserGroupExample userGroupExample = new UserGroupExample();
userGroupExample.createCriteria().andUserIdEqualTo(userId).andGroupIdEqualTo(group.getId());
List<UserGroup> userGroups = userGroupMapper.selectByExample(userGroupExample);
if (userGroups.size() <= 0) {
UserGroup userGroup = new UserGroup(UUID.randomUUID().toString(), userId, group.getId(),
"system", System.currentTimeMillis(), System.currentTimeMillis());
userGroupMapper.insertSelective(userGroup);
}
}
}
private void addNotSystemGroupUser(Group group, List<String> userIds, List<String> sourceIds) {
QuotaService quotaService = CommonBeanFactory.getBean(QuotaService.class);
for (String userId : userIds) {

View File

@ -1,12 +1,20 @@
package io.metersphere.service;
import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.*;
import io.metersphere.base.mapper.ext.*;
import io.metersphere.commons.constants.*;
import io.metersphere.base.mapper.ProjectApplicationMapper;
import io.metersphere.base.mapper.ProjectMapper;
import io.metersphere.base.mapper.UserGroupMapper;
import io.metersphere.base.mapper.UserMapper;
import io.metersphere.base.mapper.ext.BaseUserGroupMapper;
import io.metersphere.base.mapper.ext.ExtProjectMapper;
import io.metersphere.commons.constants.MicroServiceName;
import io.metersphere.commons.constants.ProjectApplicationType;
import io.metersphere.commons.constants.ScheduleGroup;
import io.metersphere.commons.constants.ScheduleType;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.user.SessionUser;
import io.metersphere.commons.utils.*;
import io.metersphere.commons.utils.JSON;
import io.metersphere.commons.utils.LogUtil;
import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.dto.ProjectConfig;
import io.metersphere.dto.ProjectDTO;
import io.metersphere.dto.WorkspaceMemberDTO;
@ -17,17 +25,21 @@ import io.metersphere.log.vo.DetailColumn;
import io.metersphere.log.vo.OperatingLogDetails;
import io.metersphere.log.vo.system.SystemReference;
import io.metersphere.metadata.service.FileMetadataService;
import io.metersphere.request.*;
import io.metersphere.request.AddProjectRequest;
import io.metersphere.request.ProjectRequest;
import io.metersphere.request.ScheduleRequest;
import io.metersphere.request.member.AddMemberRequest;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.*;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
@Service
@ -44,76 +56,18 @@ public class ProjectService {
@Resource
private BaseUserGroupMapper baseUserGroupMapper;
@Resource
private BaseUserMapper baseUserMapper;
@Resource
private BaseProjectMapper baseProjectMapper;
@Resource
private UserMapper userMapper;
@Value("${tcp.mock.port}")
private String tcpMockPorts;
@Resource
private ExtProjectVersionMapper extProjectVersionMapper;
@Resource
private ProjectApplicationMapper projectApplicationMapper;
@Resource
private ProjectVersionMapper projectVersionMapper;
@Resource
private MicroService microService;
@Resource
private BaseScheduleService baseScheduleService;
@Resource
private ProjectApplicationService projectApplicationService;
public void addProjectVersion(Project project) {
ProjectVersion projectVersion = new ProjectVersion();
projectVersion.setId(UUID.randomUUID().toString());
projectVersion.setName("v1.0.0");
projectVersion.setProjectId(project.getId());
projectVersion.setCreateTime(System.currentTimeMillis());
projectVersion.setCreateTime(System.currentTimeMillis());
projectVersion.setStartTime(System.currentTimeMillis());
projectVersion.setPublishTime(System.currentTimeMillis());
projectVersion.setLatest(true);
projectVersion.setStatus("open");
String name = projectVersion.getName();
ProjectVersionExample example = new ProjectVersionExample();
example.createCriteria().andProjectIdEqualTo(projectVersion.getProjectId()).andNameEqualTo(name);
if (projectVersionMapper.countByExample(example) > 0) {
MSException.throwException("当前版本已经存在");
}
projectVersion.setId(UUID.randomUUID().toString());
projectVersion.setCreateUser(SessionUtils.getUserId());
projectVersion.setCreateTime(System.currentTimeMillis());
projectVersionMapper.insertSelective(projectVersion);
}
private String genSystemId() {
String maxSystemIdInDb = extProjectMapper.getMaxSystemId();
String systemId = "10001";
if (StringUtils.isNotEmpty(maxSystemIdInDb)) {
systemId = String.valueOf(Long.parseLong(maxSystemIdInDb) + 1);
}
return systemId;
}
public Project checkSystemId(Project project) {
if (project != null) {
ProjectExample example = new ProjectExample();
example.createCriteria().andSystemIdEqualTo(project.getSystemId());
long count = projectMapper.countByExample(example);
if (count > 1) {
String systemId = this.genSystemId();
Project updateModel = new Project();
updateModel.setId(project.getId());
updateModel.setSystemId(systemId);
projectMapper.updateByPrimaryKeySelective(updateModel);
project = this.getProjectById(project.getId());
}
}
return project;
}
public List<ProjectDTO> getProjectList(ProjectRequest request) {
if (StringUtils.isNotBlank(request.getName())) {
request.setName(StringUtils.wrapIfMissing(request.getName(), "%"));
@ -130,21 +84,6 @@ public class ProjectService {
return extProjectMapper.getUserProject(request);
}
public List<Project> getProjectByIds(List<String> ids) {
if (!CollectionUtils.isEmpty(ids)) {
ProjectExample example = new ProjectExample();
example.createCriteria().andIdIn(ids);
return projectMapper.selectByExample(example);
}
return new ArrayList<>();
}
private void deleteProjectUserGroup(String projectId) {
UserGroupExample userGroupExample = new UserGroupExample();
userGroupExample.createCriteria().andSourceIdEqualTo(projectId);
userGroupMapper.deleteByExample(userGroupExample);
}
public void updateIssueTemplate(String originId, String templateId, String projectId) {
Project project = new Project();
project.setIssueTemplateId(templateId);
@ -254,10 +193,6 @@ public class ProjectService {
}
}
public List<Project> listAll() {
return projectMapper.selectByExample(null);
}
public List<Project> getRecentProjectList(ProjectRequest request) {
ProjectExample example = new ProjectExample();
ProjectExample.Criteria criteria = example.createCriteria();
@ -361,57 +296,10 @@ public class ProjectService {
return baseUserGroupMapper.checkSourceRole(workspaceId, userId, roleId);
}
public String getSystemIdByProjectId(String projectId) {
return extProjectMapper.getSystemIdByProjectId(projectId);
}
public Project findBySystemId(String systemId) {
ProjectExample example = new ProjectExample();
example.createCriteria().andSystemIdEqualTo(systemId);
List<Project> returnList = projectMapper.selectByExample(example);
if (CollectionUtils.isEmpty(returnList)) {
return null;
} else {
return returnList.get(0);
}
}
public List<String> getProjectIds() {
return extProjectMapper.getProjectIds();
}
public List<Project> getProjectForCustomField(String workspaceId) {
return extProjectMapper.getProjectForCustomField(workspaceId);
}
public Map<String, Project> queryNameByIds(List<String> ids) {
return extProjectMapper.queryNameByIds(ids);
}
public Map<String, Workspace> getWorkspaceNameByProjectIds(List<String> projectIds) {
if (projectIds.isEmpty()) {
return new HashMap<>(0);
}
return extProjectMapper.queryWorkNameByProjectIds(projectIds);
}
public long getProjectSize() {
return projectMapper.countByExample(new ProjectExample());
}
public long getProjectMemberSize(String id) {
return extProjectMapper.getProjectMemberSize(id);
}
public int getProjectBugSize(String projectId) {
return extProjectMapper.getProjectPlanBugSize(projectId);
}
public boolean isVersionEnable(String projectId) {
return extProjectVersionMapper.isVersionEnable(projectId);
}
public List<ServiceIntegration> getAllServiceIntegration() {
return microService.getForDataArray(MicroServiceName.SYSTEM_SETTING, "/service/integration/all", ServiceIntegration.class);
}

View File

@ -33,11 +33,11 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.util.*;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
@Service
@ -170,23 +170,6 @@ public class SystemProjectService {
return systemId;
}
public Project checkSystemId(Project project) {
if (project != null) {
ProjectExample example = new ProjectExample();
example.createCriteria().andSystemIdEqualTo(project.getSystemId());
long count = projectMapper.countByExample(example);
if (count > 1) {
String systemId = this.genSystemId();
Project updateModel = new Project();
updateModel.setId(project.getId());
updateModel.setSystemId(systemId);
projectMapper.updateByPrimaryKeySelective(updateModel);
project = this.getProjectById(project.getId());
}
}
return project;
}
public List<ProjectDTO> getProjectList(ProjectRequest request) {
if (StringUtils.isNotBlank(request.getName())) {
request.setName(StringUtils.wrapIfMissing(request.getName(), "%"));
@ -195,15 +178,6 @@ public class SystemProjectService {
return baseProjectMapper.getProjectWithWorkspace(request);
}
public List<Project> getProjectByIds(List<String> ids) {
if (!CollectionUtils.isEmpty(ids)) {
ProjectExample example = new ProjectExample();
example.createCriteria().andIdIn(ids);
return projectMapper.selectByExample(example);
}
return new ArrayList<>();
}
public void deleteProject(String projectId) {
// 删除项目发送通知
@ -227,26 +201,6 @@ public class SystemProjectService {
userGroupMapper.deleteByExample(userGroupExample);
}
public void updateIssueTemplate(String originId, String templateId, String projectId) {
Project project = new Project();
project.setIssueTemplateId(templateId);
ProjectExample example = new ProjectExample();
example.createCriteria().andIssueTemplateIdEqualTo(originId).andIdEqualTo(projectId);
projectMapper.updateByExampleSelective(project, example);
}
/**
* 把原来为系统模板的项目模板设置成新的模板
* 只设置改工作空间下的
*
* @param originId
* @param templateId
* @param projectId
*/
public void updateCaseTemplate(String originId, String templateId, String projectId) {
baseProjectMapper.updateUseDefaultCaseTemplateProject(originId, templateId, projectId);
}
public void updateProject(AddProjectRequest project) {
project.setCreateTime(null);
project.setCreateUser(null);
@ -288,18 +242,6 @@ public class SystemProjectService {
}
}
public void checkProjectTcpPort(AddProjectRequest project) {
//判断端口是否重复
if (project.getMockTcpPort() != null && project.getMockTcpPort() != 0) {
String projectId = StringUtils.isEmpty(project.getId()) ? StringUtils.EMPTY : project.getId();
ProjectApplicationExample example = new ProjectApplicationExample();
example.createCriteria().andTypeEqualTo(ProjectApplicationType.MOCK_TCP_PORT.name()).andTypeValueEqualTo(String.valueOf(project.getMockTcpPort())).andProjectIdNotEqualTo(projectId);
if (projectApplicationMapper.countByExample(example) > 0) {
MSException.throwException(Translator.get("tcp_mock_not_unique"));
}
}
}
private void checkProjectExist(Project project) {
if (project.getName() != null) {
ProjectExample example = new ProjectExample();
@ -310,10 +252,6 @@ public class SystemProjectService {
}
}
public List<Project> listAll() {
return projectMapper.selectByExample(null);
}
public List<Project> getRecentProjectList(ProjectRequest request) {
ProjectExample example = new ProjectExample();
ProjectExample.Criteria criteria = example.createCriteria();
@ -325,40 +263,6 @@ public class SystemProjectService {
return projectMapper.selectByExample(example);
}
public Project getProjectById(String id) {
Project project = projectMapper.selectByPrimaryKey(id);
if (project != null) {
String createUser = project.getCreateUser();
if (StringUtils.isNotBlank(createUser)) {
User user = userMapper.selectByPrimaryKey(createUser);
if (user != null) {
project.setCreateUser(user.getName());
}
}
}
return project;
}
public List<Project> getByCaseTemplateId(String templateId) {
ProjectExample example = new ProjectExample();
example.createCriteria().andCaseTemplateIdEqualTo(templateId);
return projectMapper.selectByExample(example);
}
public List<Project> getByIssueTemplateId(String templateId) {
ProjectExample example = new ProjectExample();
example.createCriteria().andIssueTemplateIdEqualTo(templateId);
return projectMapper.selectByExample(example);
}
public List<FileMetadata> uploadFiles(String projectId, List<MultipartFile> files) {
return fileMetadataService.uploadFiles(projectId, files);
}
public FileMetadata updateFile(String fileId, MultipartFile file) {
return fileMetadataService.updateFile(fileId, file);
}
public String getLogDetails(String id) {
Project project = projectMapper.selectByPrimaryKey(id);
if (project != null) {
@ -424,57 +328,10 @@ public class SystemProjectService {
return baseUserGroupMapper.checkSourceRole(workspaceId, userId, roleId);
}
public String getSystemIdByProjectId(String projectId) {
return baseProjectMapper.getSystemIdByProjectId(projectId);
}
public Project findBySystemId(String systemId) {
ProjectExample example = new ProjectExample();
example.createCriteria().andSystemIdEqualTo(systemId);
List<Project> returnList = projectMapper.selectByExample(example);
if (CollectionUtils.isEmpty(returnList)) {
return null;
} else {
return returnList.get(0);
}
}
public List<String> getProjectIds() {
return baseProjectMapper.getProjectIds();
}
public List<Project> getProjectForCustomField(String workspaceId) {
return baseProjectMapper.getProjectForCustomField(workspaceId);
}
public Map<String, Project> queryNameByIds(List<String> ids) {
return baseProjectMapper.queryNameByIds(ids);
}
public Map<String, Workspace> getWorkspaceNameByProjectIds(List<String> projectIds) {
if (projectIds.isEmpty()) {
return new HashMap<>(0);
}
return baseProjectMapper.queryWorkNameByProjectIds(projectIds);
}
public long getProjectSize() {
return projectMapper.countByExample(new ProjectExample());
}
public long getProjectMemberSize(String id) {
return baseProjectMapper.getProjectMemberSize(id);
}
public int getProjectBugSize(String projectId) {
return baseProjectMapper.getProjectPlanBugSize(projectId);
}
public boolean isVersionEnable(String projectId) {
return baseProjectVersionMapper.isVersionEnable(projectId);
}
private void initProjectApplication(String projectId) {
//创建新项目也创建相关新项目的应用分测试跟踪接口性能
ProjectApplication projectApplication = new ProjectApplication();

View File

@ -27,12 +27,10 @@ import io.metersphere.log.utils.ReflexObjectUtil;
import io.metersphere.log.vo.DetailColumn;
import io.metersphere.log.vo.OperatingLogDetails;
import io.metersphere.log.vo.system.SystemReference;
import io.metersphere.notice.domain.UserDetail;
import io.metersphere.request.UserRequest;
import io.metersphere.request.WorkspaceRequest;
import io.metersphere.request.member.AddMemberRequest;
import io.metersphere.request.member.EditPassWordRequest;
import io.metersphere.request.member.EditSeleniumServerRequest;
import io.metersphere.request.member.QueryMemberRequest;
import io.metersphere.request.resourcepool.UserBatchProcessRequest;
import io.metersphere.xpack.quota.service.QuotaService;
@ -82,27 +80,8 @@ public class UserService {
@Resource
private ProjectMapper projectMapper;
@Resource
private BaseProjectMapper baseProjectMapper;
@Resource
private BaseWorkspaceMapper baseWorkspaceMapper;
@Resource
private BaseUserService baseUserService;
public List<UserDetail> queryTypeByIds(List<String> userIds) {
return baseUserMapper.queryTypeByIds(userIds);
}
public Map<String, User> queryNameByIds(List<String> userIds) {
if (userIds.isEmpty()) {
return new HashMap<>(0);
}
return baseUserMapper.queryNameByIds(userIds);
}
public Map<String, User> queryName() {
return baseUserMapper.queryName();
}
public UserDTO insert(io.metersphere.request.member.UserRequest userRequest) {
checkUserParam(userRequest);
String id = userRequest.getId();
@ -166,22 +145,6 @@ public class UserService {
quotaService.checkMemberCount(addMemberMap, type);
}
}
public User selectUser(String userId, String email) {
User user = userMapper.selectByPrimaryKey(userId);
if (user == null) {
if (StringUtils.isNotBlank(email)) {
UserExample example = new UserExample();
example.createCriteria().andEmailEqualTo(email);
List<User> users = userMapper.selectByExample(example);
if (!CollectionUtils.isEmpty(users)) {
return users.get(0);
}
}
}
return user;
}
private void checkUserParam(User user) {
if (StringUtils.isBlank(user.getId())) {
@ -271,33 +234,6 @@ public class UserService {
return permissionDTO;
}
public UserDTO getLoginUser(String userId, List<String> list) {
UserExample example = new UserExample();
example.createCriteria().andIdEqualTo(userId).andSourceIn(list);
if (userMapper.countByExample(example) == 0) {
return null;
}
return getUserDTO(userId);
}
public UserDTO getUserDTOByEmail(String email, String... source) {
UserExample example = new UserExample();
UserExample.Criteria criteria = example.createCriteria();
criteria.andEmailEqualTo(email);
if (!CollectionUtils.isEmpty(Arrays.asList(source))) {
criteria.andSourceIn(Arrays.asList(source));
}
List<User> users = userMapper.selectByExample(example);
if (users == null || users.size() <= 0) {
return null;
}
return getUserDTO(users.get(0).getId());
}
public List<User> getUserList() {
UserExample example = new UserExample();
example.setOrderByClause("update_time desc");
@ -408,11 +344,6 @@ public class UserService {
return projectList;
}
public UserDTO getUserInfo(String userId) {
return getUserDTO(userId);
}
public void addMember(AddMemberRequest request) {
if (CollectionUtils.isEmpty(request.getUserIds())
|| CollectionUtils.isEmpty(request.getGroupIds())) {
@ -487,18 +418,6 @@ public class UserService {
userGroupMapper.deleteByExample(userGroupExample);
}
public boolean checkUserPassword(String userId, String password) {
if (StringUtils.isBlank(userId)) {
MSException.throwException(Translator.get("user_name_is_null"));
}
if (StringUtils.isBlank(password)) {
MSException.throwException(Translator.get("password_is_null"));
}
UserExample example = new UserExample();
example.createCriteria().andIdEqualTo(userId).andPasswordEqualTo(CodingUtil.md5(password));
return userMapper.countByExample(example) > 0;
}
public void setLanguage(String lang) {
if (SessionUtils.getUser() != null) {
User user = new User();
@ -549,11 +468,6 @@ public class UserService {
return null;
}
public int updateCurrentUserPassword(EditPassWordRequest request) {
User user = updateCurrentUserPwd(request);
return baseUserMapper.updatePassword(user);
}
/*管理员修改用户密码*/
private User updateUserPwd(EditPassWordRequest request) {
User user = userMapper.selectByPrimaryKey(request.getId());
@ -568,76 +482,6 @@ public class UserService {
return baseUserMapper.updatePassword(user);
}
public String getDefaultLanguage() {
final String key = "default.language";
return baseUserMapper.getDefaultLanguage(key);
}
private boolean hasLastProjectPermission(UserDTO user) {
if (StringUtils.isNotBlank(user.getLastProjectId())) {
List<UserGroup> projectUserGroups = user.getUserGroups().stream()
.filter(ug -> StringUtils.equals(user.getLastProjectId(), ug.getSourceId()))
.collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(projectUserGroups)) {
Project project = projectMapper.selectByPrimaryKey(user.getLastProjectId());
if (StringUtils.equals(project.getWorkspaceId(), user.getLastWorkspaceId())) {
return true;
}
// last_project_id last_workspace_id 对应不上了
user.setLastWorkspaceId(project.getWorkspaceId());
updateUser(user);
return true;
}
}
return false;
}
private boolean hasLastWorkspacePermission(UserDTO user) {
if (StringUtils.isNotBlank(user.getLastWorkspaceId())) {
List<UserGroup> workspaceUserGroups = user.getUserGroups().stream()
.filter(ug -> StringUtils.equals(user.getLastWorkspaceId(), ug.getSourceId()))
.collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(workspaceUserGroups)) {
ProjectExample example = new ProjectExample();
example.createCriteria().andWorkspaceIdEqualTo(user.getLastWorkspaceId());
List<Project> projects = projectMapper.selectByExample(example);
// 工作空间下没有项目
if (CollectionUtils.isEmpty(projects)) {
return true;
}
// 工作空间下有项目选中有权限的项目
List<String> projectIds = projects.stream()
.map(Project::getId)
.collect(Collectors.toList());
List<UserGroup> userGroups = user.getUserGroups();
List<String> projectGroupIds = user.getGroups()
.stream().filter(ug -> StringUtils.equals(ug.getType(), UserGroupType.PROJECT))
.map(Group::getId)
.collect(Collectors.toList());
List<String> projectIdsWithPermission = userGroups.stream().filter(ug -> projectGroupIds.contains(ug.getGroupId()))
.filter(p -> StringUtils.isNotBlank(p.getSourceId()))
.map(UserGroup::getSourceId)
.filter(projectIds::contains)
.collect(Collectors.toList());
List<String> intersection = projectIds.stream().filter(projectIdsWithPermission::contains).collect(Collectors.toList());
// 当前工作空间下的所有项目都没有权限
if (CollectionUtils.isEmpty(intersection)) {
return true;
}
Project project = projects.stream().filter(p -> StringUtils.equals(intersection.get(0), p.getId())).findFirst().get();
String wsId = project.getWorkspaceId();
user.setId(user.getId());
user.setLastProjectId(project.getId());
user.setLastWorkspaceId(wsId);
updateUser(user);
return true;
}
}
return false;
}
public List<User> searchUser(String condition) {
return baseUserMapper.searchUser(condition);
}
@ -932,17 +776,6 @@ public class UserService {
}
public Set<String> getUserPermission(String userId) {
UserGroupExample userGroupExample = new UserGroupExample();
userGroupExample.createCriteria().andUserIdEqualTo(userId);
List<UserGroup> userGroups = userGroupMapper.selectByExample(userGroupExample);
List<String> groupId = userGroups.stream().map(UserGroup::getGroupId).collect(Collectors.toList());
UserGroupPermissionExample userGroupPermissionExample = new UserGroupPermissionExample();
userGroupPermissionExample.createCriteria().andGroupIdIn(groupId);
List<UserGroupPermission> userGroupPermissions = userGroupPermissionMapper.selectByExample(userGroupPermissionExample);
return userGroupPermissions.stream().map(UserGroupPermission::getPermissionId).collect(Collectors.toSet());
}
public UserGroupPermissionDTO getUserGroup(String userId) {
UserGroupPermissionDTO userGroupPermissionDTO = new UserGroupPermissionDTO();
//
@ -1114,31 +947,6 @@ public class UserService {
userGroupMapper.deleteByExample(userGroupExample);
}
public List<User> getWsAllMember(String workspaceId) {
List<String> sourceIds = new ArrayList<>();
ProjectExample projectExample = new ProjectExample();
projectExample.createCriteria().andWorkspaceIdEqualTo(workspaceId);
List<Project> projectList = projectMapper.selectByExample(projectExample);
if (CollectionUtils.isEmpty(projectList)) {
return new ArrayList<>();
}
List<String> proIds = projectList.stream().map(Project::getId).collect(Collectors.toList());
sourceIds.addAll(proIds);
UserGroupExample userGroupExample = new UserGroupExample();
userGroupExample.createCriteria().andSourceIdIn(sourceIds);
List<UserGroup> userGroups = userGroupMapper.selectByExample(userGroupExample);
List<String> userIds = userGroups.stream().map(UserGroup::getUserId).distinct().collect(Collectors.toList());
if (CollectionUtils.isEmpty(userIds)) {
return new ArrayList<>();
}
UserExample userExample = new UserExample();
userExample.createCriteria().andIdIn(userIds);
return userMapper.selectByExample(userExample);
}
public void updateImportUserGroup(io.metersphere.request.member.UserRequest user) {
UserGroupExample userGroupExample = new UserGroupExample();
userGroupExample.createCriteria().andUserIdEqualTo(user.getId());
@ -1220,42 +1028,9 @@ public class UserService {
}
}
}
public UserDTO updateCurrentUser(User user) {
String currentUserId = SessionUtils.getUserId();
if (!StringUtils.equals(currentUserId, user.getId())) {
MSException.throwException(Translator.get("not_authorized"));
}
updateUser(user);
UserDTO userDTO = getUserDTO(user.getId());
SessionUtils.putUser(SessionUser.fromUser(userDTO, SessionUtils.getSessionId()));
return SessionUtils.getUser();
}
public long getUserSize() {
return userMapper.countByExample(new UserExample());
}
/**
* 根据userId 获取 user 所属工作空间和所属工作项目
*
* @param userId
*/
public Map<Object, Object> getWSAndProjectByUserId(String userId) {
Map<Object, Object> map = new HashMap<>(2);
List<Project> projects = baseProjectMapper.getProjectByUserId(userId);
List<Workspace> workspaces = baseWorkspaceMapper.getWorkspaceByUserId(userId);
map.put("project", projects);
map.put("workspace", workspaces);
return map;
}
public List<User> getProjectMemberOption(String projectId) {
return baseUserGroupMapper.getProjectMemberOption(projectId);
}
public void addWorkspaceMember(AddMemberRequest request) {
this.addGroupMember("WORKSPACE", request.getWorkspaceId(), request.getUserIds(), request.getGroupIds());
}

View File

@ -7,7 +7,6 @@ import io.metersphere.base.mapper.ProjectMapper;
import io.metersphere.base.mapper.UserGroupMapper;
import io.metersphere.base.mapper.WorkspaceMapper;
import io.metersphere.base.mapper.ext.BaseUserGroupMapper;
import io.metersphere.base.mapper.ext.BaseUserMapper;
import io.metersphere.base.mapper.ext.BaseWorkspaceMapper;
import io.metersphere.commons.constants.UserGroupConstants;
import io.metersphere.commons.constants.UserGroupType;
@ -55,48 +54,12 @@ public class WorkspaceService {
@Resource
private BaseUserGroupMapper baseUserGroupMapper;
@Resource
private BaseUserMapper baseUserMapper;
@Resource
private EnvironmentGroupService environmentGroupService;
@Resource
private BaseScheduleService baseScheduleService;
private static final String GLOBAL = "global";
public Workspace saveWorkspace(Workspace workspace) {
if (StringUtils.isBlank(workspace.getName())) {
MSException.throwException(Translator.get("workspace_name_is_null"));
}
long currentTime = System.currentTimeMillis();
checkWorkspace(workspace);
if (StringUtils.isBlank(workspace.getId())) {
workspace.setId(UUID.randomUUID().toString());
workspace.setCreateTime(currentTime);
workspace.setUpdateTime(currentTime);
workspace.setCreateUser(SessionUtils.getUserId());
workspaceMapper.insertSelective(workspace);
// 创建工作空间为当前用户添加用户组
UserGroup userGroup = new UserGroup();
userGroup.setId(UUID.randomUUID().toString());
userGroup.setUserId(SessionUtils.getUserId());
userGroup.setCreateTime(System.currentTimeMillis());
userGroup.setUpdateTime(System.currentTimeMillis());
userGroup.setGroupId(UserGroupConstants.WS_ADMIN);
userGroup.setSourceId(workspace.getId());
userGroupMapper.insert(userGroup);
// 新项目创建新工作空间时设置
baseUserMapper.updateLastWorkspaceIdIfNull(workspace.getId(), SessionUtils.getUserId());
} else {
workspace.setUpdateTime(currentTime);
workspaceMapper.updateByPrimaryKeySelective(workspace);
}
return workspace;
}
public List<Workspace> getWorkspaceList(WorkspaceRequest request) {
WorkspaceExample example = new WorkspaceExample();
WorkspaceExample.Criteria criteria = example.createCriteria();
@ -136,15 +99,6 @@ public class WorkspaceService {
baseScheduleService.deleteByWorkspaceId(workspaceId);
}
public void checkWorkspaceIsExist(String workspaceId) {
WorkspaceExample example = new WorkspaceExample();
example.createCriteria().andIdEqualTo(workspaceId);
if (workspaceMapper.countByExample(example) == 0) {
MSException.throwException(Translator.get("workspace_not_exists"));
}
}
public void updateWorkspaceMember(WorkspaceMemberDTO memberDTO) {
String workspaceId = memberDTO.getWorkspaceId();
String userId = memberDTO.getId();
@ -235,12 +189,6 @@ public class WorkspaceService {
}
public List<Project> getProjects(String workspaceId) {
ProjectExample projectExample = new ProjectExample();
projectExample.createCriteria().andWorkspaceIdEqualTo(workspaceId);
return projectMapper.selectByExample(projectExample);
}
public String getLogDetails(String id) {
Workspace user = workspaceMapper.selectByPrimaryKey(id);
if (user != null) {
@ -327,8 +275,4 @@ public class WorkspaceService {
}
return workspaceMapper.selectByExample(workspaceExample);
}
public List<String> getWorkspaceIds() {
return baseWorkspaceMapper.getWorkspaceIds();
}
}