diff --git a/continew-server/src/main/resources/db/changelog/mysql/plugin/plugin_tenant.sql b/continew-server/src/main/resources/db/changelog/mysql/plugin/plugin_tenant.sql index e2cbed06..62f160d7 100644 --- a/continew-server/src/main/resources/db/changelog/mysql/plugin/plugin_tenant.sql +++ b/continew-server/src/main/resources/db/changelog/mysql/plugin/plugin_tenant.sql @@ -134,4 +134,10 @@ VALUES (3022, '详情', 3020, 3, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'tenant:package:get', 2, 1, 1, NOW()), (3023, '新增', 3020, 3, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'tenant:package:create', 3, 1, 1, NOW()), (3024, '修改', 3020, 3, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'tenant:package:update', 4, 1, 1, NOW()), -(3025, '删除', 3020, 3, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'tenant:package:delete', 5, 1, 1, NOW()); \ No newline at end of file +(3025, '删除', 3020, 3, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'tenant:package:delete', 5, 1, 1, NOW()); + +-- changeset kai:20251022-01 +-- comment 重置租户场景索引 +ALTER TABLE `sys_user_social` +DROP INDEX `uk_source_open_id`, + ADD UNIQUE INDEX `uk_source_open_id` (`source`, `open_id`, `tenant_id`); \ No newline at end of file diff --git a/continew-server/src/main/resources/db/changelog/postgresql/plugin/plugin_tenant.sql b/continew-server/src/main/resources/db/changelog/postgresql/plugin/plugin_tenant.sql index 87d88aa6..48f784e9 100644 --- a/continew-server/src/main/resources/db/changelog/postgresql/plugin/plugin_tenant.sql +++ b/continew-server/src/main/resources/db/changelog/postgresql/plugin/plugin_tenant.sql @@ -172,4 +172,11 @@ VALUES (3022, '详情', 3020, 3, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'tenant:package:get', 2, 1, 1, NOW()), (3023, '新增', 3020, 3, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'tenant:package:create', 3, 1, 1, NOW()), (3024, '修改', 3020, 3, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'tenant:package:update', 4, 1, 1, NOW()), -(3025, '删除', 3020, 3, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'tenant:package:delete', 5, 1, 1, NOW()); \ No newline at end of file +(3025, '删除', 3020, 3, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'tenant:package:delete', 5, 1, 1, NOW()); + +-- changeset kai:20251022-01 +-- comment 重置租户场景索引 +DROP INDEX IF EXISTS "uk_user_source_open_id"; +CREATE UNIQUE INDEX "uk_user_source_open_id" + ON "sys_user_social" ("source", "open_id", "tenant_id"); + diff --git a/continew-system/src/main/java/top/continew/admin/auth/handler/SocialLoginHandler.java b/continew-system/src/main/java/top/continew/admin/auth/handler/SocialLoginHandler.java index 606f9664..dfb2f935 100644 --- a/continew-system/src/main/java/top/continew/admin/auth/handler/SocialLoginHandler.java +++ b/continew-system/src/main/java/top/continew/admin/auth/handler/SocialLoginHandler.java @@ -23,6 +23,7 @@ import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.RandomUtil; import cn.hutool.core.util.ReUtil; import cn.hutool.json.JSONUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.xkcoding.justauth.autoconfigure.JustAuthProperties; import jakarta.servlet.http.HttpServletRequest; import lombok.RequiredArgsConstructor; @@ -33,6 +34,7 @@ import me.zhyd.oauth.model.AuthResponse; import me.zhyd.oauth.model.AuthUser; import me.zhyd.oauth.request.AuthRequest; import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; import top.continew.admin.auth.AbstractLoginHandler; import top.continew.admin.auth.enums.AuthTypeEnum; import top.continew.admin.auth.model.req.SocialLoginReq; @@ -41,13 +43,14 @@ import top.continew.admin.common.constant.RegexConstants; import top.continew.admin.common.enums.DisEnableStatusEnum; import top.continew.admin.common.enums.GenderEnum; import top.continew.admin.common.enums.RoleCodeEnum; -import top.continew.admin.system.constant.SystemConstants; import top.continew.admin.system.enums.MessageTemplateEnum; import top.continew.admin.system.enums.MessageTypeEnum; +import top.continew.admin.system.model.entity.DeptDO; import top.continew.admin.system.model.entity.user.UserDO; import top.continew.admin.system.model.entity.user.UserSocialDO; import top.continew.admin.system.model.req.MessageReq; import top.continew.admin.system.model.resp.ClientResp; +import top.continew.admin.system.service.DeptService; import top.continew.admin.system.service.MessageService; import top.continew.admin.system.service.UserRoleService; import top.continew.admin.system.service.UserSocialService; @@ -74,8 +77,10 @@ public class SocialLoginHandler extends AbstractLoginHandler { private final UserRoleService userRoleService; private final MessageService messageService; private final ApplicationProperties applicationProperties; + private final DeptService deptService; @Override + @Transactional public LoginResp login(SocialLoginReq req, ClientResp client, HttpServletRequest request) { // 获取第三方登录信息 AuthRequest authRequest = this.getAuthRequest(req.getSource()); @@ -108,7 +113,11 @@ public class SocialLoginHandler extends AbstractLoginHandler { user.setGender(GenderEnum.valueOf(authUser.getGender().name())); } user.setAvatar(authUser.getAvatar()); - user.setDeptId(SystemConstants.SUPER_DEPT_ID); + // 默认设置为系统内置数据的根部门 如果需要设置其他部门自行替换查询条件 + DeptDO deptDO = deptService.getOne(new LambdaQueryWrapper().eq(DeptDO::getIsSystem, true) + .eq(DeptDO::getParentId, 0)); + ValidationUtils.throwIf(deptDO == null, "未查询到系统内置部门"); + user.setDeptId(deptDO.getId()); user.setStatus(DisEnableStatusEnum.ENABLE); userService.save(user); Long userId = user.getId(); diff --git a/continew-system/src/main/java/top/continew/admin/system/constant/SystemConstants.java b/continew-system/src/main/java/top/continew/admin/system/constant/SystemConstants.java index c45c77c2..fd1c1c18 100644 --- a/continew-system/src/main/java/top/continew/admin/system/constant/SystemConstants.java +++ b/continew-system/src/main/java/top/continew/admin/system/constant/SystemConstants.java @@ -29,11 +29,6 @@ public class SystemConstants { */ public static final Long SUPER_ADMIN_ROLE_ID = 1L; - /** - * 顶级部门 ID - */ - public static final Long SUPER_DEPT_ID = 1L; - /** * 全部权限标识 */ diff --git a/continew-system/src/main/java/top/continew/admin/system/service/impl/UserServiceImpl.java b/continew-system/src/main/java/top/continew/admin/system/service/impl/UserServiceImpl.java index c9139a0a..b8f98a25 100644 --- a/continew-system/src/main/java/top/continew/admin/system/service/impl/UserServiceImpl.java +++ b/continew-system/src/main/java/top/continew/admin/system/service/impl/UserServiceImpl.java @@ -60,7 +60,6 @@ import top.continew.admin.common.context.UserContextHolder; import top.continew.admin.common.enums.DisEnableStatusEnum; import top.continew.admin.common.enums.GenderEnum; import top.continew.admin.common.util.SecureUtils; -import top.continew.admin.system.constant.SystemConstants; import top.continew.admin.system.enums.OptionCategoryEnum; import top.continew.admin.system.mapper.user.UserMapper; import top.continew.admin.system.model.entity.DeptDO; @@ -505,7 +504,7 @@ public class UserServiceImpl extends BaseServiceImpl { + .and(deptId != null, q -> { List deptIdList = CollUtils.mapToList(deptService.listChildren(deptId), DeptDO::getId); deptIdList.add(deptId); q.in("t1.dept_id", deptIdList);