diff --git a/ruoyi-admin/src/main/java/org/dromara/web/service/SysLoginService.java b/ruoyi-admin/src/main/java/org/dromara/web/service/SysLoginService.java index d944a5ad..52bf56c6 100644 --- a/ruoyi-admin/src/main/java/org/dromara/web/service/SysLoginService.java +++ b/ruoyi-admin/src/main/java/org/dromara/web/service/SysLoginService.java @@ -175,13 +175,15 @@ public class SysLoginService { return R.fail("对不起,授权信息验证不通过,请退出重试!"); } AuthUser authUserData = authUser.getData(); - SysSocialVo user = sysSocialService.selectByAuthId(authUserData.getSource() + authUserData.getUuid()); - if (ObjectUtil.isNotNull(user)) { + SysSocialVo social = sysSocialService.selectByAuthId(authUserData.getSource() + authUserData.getUuid()); + if (ObjectUtil.isNotNull(social)) { + SysUser user = userMapper.selectOne(new LambdaQueryWrapper() + .eq(SysUser::getUserId, social.getUserId())); // 执行登录和记录登录信息操作 return loginAndRecord(user.getTenantId(), user.getUserName(), authUserData); } else { // 判断是否已登录 - if (LoginHelper.getUserId() == null) { + if (!StpUtil.isLogin()) { return R.fail("授权失败,请先登录才能绑定"); } SysSocialBo bo = new SysSocialBo(); @@ -211,10 +213,10 @@ public class SysLoginService { */ private R loginAndRecord(String tenantId, String userName, AuthUser authUser) { checkTenant(tenantId); - SysUserVo dbUser = loadUserByUsername(tenantId, userName); - LoginHelper.loginByDevice(buildLoginUser(dbUser), DeviceType.SOCIAL); - recordLogininfor(dbUser.getTenantId(), userName, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")); - recordLoginInfo(dbUser.getUserId()); + SysUserVo user = loadUserByUsername(tenantId, userName); + LoginHelper.loginByDevice(buildLoginUser(user), DeviceType.SOCIAL); + recordLogininfor(user.getTenantId(), userName, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")); + recordLoginInfo(user.getUserId()); return R.ok(StpUtil.getTokenValue()); } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/SysSocial.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/SysSocial.java index fa9cb9f6..10f2936c 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/SysSocial.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/SysSocial.java @@ -27,6 +27,11 @@ public class SysSocial extends TenantEntity { @TableId(value = "id") private Long id; + /** + * 用户ID + */ + private Long userId; + /** * 的唯一ID */ @@ -57,11 +62,6 @@ public class SysSocial extends TenantEntity { */ private String openId; - /** - * 用户的 ID - */ - private Long userId; - /** * 授权的第三方账号 */ diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/vo/SysSocialVo.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/vo/SysSocialVo.java index a8463b8b..2a72efe0 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/vo/SysSocialVo.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/vo/SysSocialVo.java @@ -29,6 +29,12 @@ public class SysSocialVo implements Serializable { @ExcelProperty(value = "主键") private Long id; + /** + * 用户ID + */ + @ExcelProperty(value = "用户ID") + private Long userId; + /** * 租户ID */ @@ -70,12 +76,6 @@ public class SysSocialVo implements Serializable { @ExcelProperty(value = "用户的 open id") private String openId; - /** - * 用户的 ID - */ - @ExcelProperty(value = "用户的 ID") - private Long userId; - /** * 授权的第三方账号 */ diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/mapper/SysSocialMapper.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/mapper/SysSocialMapper.java index a4fc3cd2..b9420613 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/mapper/SysSocialMapper.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/mapper/SysSocialMapper.java @@ -11,12 +11,4 @@ import org.dromara.system.domain.vo.SysSocialVo; */ public interface SysSocialMapper extends BaseMapperPlus { - /** - * 根据 authId 查询 SysSocial 表和 SysUser 表,返回 SysSocialAuthResult 映射的对象 - * - * @param authId 认证ID - * @return SysSocial - */ - SysSocialVo selectByAuthId(String authId); - } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysSocialServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysSocialServiceImpl.java index 3fda7039..065dea0d 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysSocialServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysSocialServiceImpl.java @@ -86,12 +86,12 @@ public class SysSocialServiceImpl implements ISysSocialService { /** * 根据 authId 查询用户信息 * - * @param authId 用户id - * @return 用户信息 + * @param authId 认证id + * @return 授权信息 */ @Override public SysSocialVo selectByAuthId(String authId) { - return baseMapper.selectByAuthId(authId); + return baseMapper.selectVoOne(new LambdaQueryWrapper().eq(SysSocial::getAuthId, authId)); } } diff --git a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysSocialMapper.xml b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysSocialMapper.xml index 90f5b1a2..baa4b594 100644 --- a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysSocialMapper.xml +++ b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysSocialMapper.xml @@ -4,20 +4,4 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - - - - - -