From e9009168dd433fb1ee5a167e1eb1b8b1822612c2 Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Tue, 28 May 2024 11:51:26 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE):?= =?UTF-8?q?=20=E4=BC=98=E5=8C=96=E7=B3=BB=E7=BB=9F=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=91=98=E7=99=BB=E9=99=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/mapper/BaseUserMapper.java | 8 ++++++ .../system/mapper/BaseUserMapper.xml | 7 +++++ .../system/service/UserLoginService.java | 28 +++++++------------ 3 files changed, 25 insertions(+), 18 deletions(-) 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;