diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/BaseUserMapper.java b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/BaseUserMapper.java index be75e2bc54..0b0aa2a0c5 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/BaseUserMapper.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/BaseUserMapper.java @@ -1,5 +1,6 @@ package io.metersphere.system.mapper; +import io.metersphere.project.domain.Project; import io.metersphere.system.domain.User; import io.metersphere.system.dto.CommentUserInfo; import io.metersphere.system.dto.sdk.OptionDTO; @@ -41,8 +42,15 @@ public interface BaseUserMapper { /** * 获取评论用户信息 + * * @param ids 用户ID集合 * @return 评论用户信息集合 */ List getCommentUserInfoByIds(List ids); + + /** + * 获取开启的项目和组织 + */ + Project getEnableProjectAndOrganization(); + } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/BaseUserMapper.xml b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/BaseUserMapper.xml index 2ffc01c649..4569c9455a 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/BaseUserMapper.xml +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/BaseUserMapper.xml @@ -132,4 +132,11 @@ #{id} + \ No newline at end of file diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserLoginService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserLoginService.java index 6ed6925ebe..d89d0f728c 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserLoginService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserLoginService.java @@ -237,35 +237,27 @@ public class UserLoginService { organizationExample.createCriteria().andIdEqualTo(user.getLastOrganizationId()).andEnableEqualTo(true); List organizations = organizationMapper.selectByExample(organizationExample); if (CollectionUtils.isNotEmpty(organizations)) { - Organization organization = organizations.get(0); + Organization organization = organizations.getFirst(); ProjectExample projectExample = new ProjectExample(); projectExample.createCriteria().andOrganizationIdEqualTo(organization.getId()).andEnableEqualTo(true); List projectList = projectMapper.selectByExample(projectExample); if (CollectionUtils.isNotEmpty(projectList)) { - Project project = projectList.get(0); + Project project = projectList.getFirst(); user.setLastProjectId(project.getId()); updateUser(user); + return true; } - return true; } } //项目和组织都没有权限 - OrganizationExample organizationExample = new OrganizationExample(); - organizationExample.createCriteria().andEnableEqualTo(true); - List organizations = organizationMapper.selectByExample(organizationExample); - if (CollectionUtils.isNotEmpty(organizations)) { - Organization organization = organizations.get(0); - ProjectExample projectExample = new ProjectExample(); - projectExample.createCriteria().andOrganizationIdEqualTo(organization.getId()).andEnableEqualTo(true); - List projectList = projectMapper.selectByExample(projectExample); - if (CollectionUtils.isNotEmpty(projectList)) { - Project project = projectList.get(0); - user.setLastProjectId(project.getId()); - user.setLastOrganizationId(organization.getId()); - updateUser(user); - return true; - } + Project project = baseUserMapper.getEnableProjectAndOrganization(); + if (project != null) { + user.setLastProjectId(project.getId()); + user.setLastOrganizationId(project.getOrganizationId()); + updateUser(user); + return true; } + return true; } return false;