diff --git a/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteUserService.java b/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteUserService.java index 6720720b..c8382c59 100644 --- a/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteUserService.java +++ b/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteUserService.java @@ -21,6 +21,15 @@ public interface RemoteUserService { */ LoginUser getUserInfo(String username, String tenantId) throws UserException; + /** + * 通过用户id查询用户信息 + * + * @param userId 用户id + * @param tenantId 租户id + * @return 结果 + */ + LoginUser getUserInfo(Long userId, String tenantId) throws UserException; + /** * 通过手机号查询用户信息 * diff --git a/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/SocialAuthStrategy.java b/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/SocialAuthStrategy.java index cd1db9f5..06c608c2 100644 --- a/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/SocialAuthStrategy.java +++ b/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/SocialAuthStrategy.java @@ -90,7 +90,7 @@ public class SocialAuthStrategy implements IAuthStrategy { throw new ServiceException("对不起,你没有权限登录当前租户!"); } - LoginUser loginUser = remoteUserService.getUserInfo(socialVo.getUserName(), tenantId); + LoginUser loginUser = remoteUserService.getUserInfo(socialVo.getUserId(), tenantId); SaLoginModel model = new SaLoginModel(); model.setDevice(client.getDeviceType()); // 自定义分配 不同用户体系 不同 token 授权时间 不设置默认走全局 yml 配置 diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteUserServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteUserServiceImpl.java index a7e90904..26ae16fe 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteUserServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteUserServiceImpl.java @@ -62,6 +62,26 @@ public class RemoteUserServiceImpl implements RemoteUserService { return buildLoginUser(userMapper.selectUserByUserName(username)); } + @Override + public LoginUser getUserInfo(Long userId, String tenantId) throws UserException { + SysUser sysUser = userMapper.selectOne(new LambdaQueryWrapper() + .select(SysUser::getUserName, SysUser::getStatus) + .eq(TenantHelper.isEnable(), SysUser::getTenantId, tenantId) + .eq(SysUser::getUserId, userId)); + if (ObjectUtil.isNull(sysUser)) { + throw new UserException("user.not.exists", ""); + } + if (UserStatus.DISABLE.getCode().equals(sysUser.getStatus())) { + throw new UserException("user.blocked", sysUser.getUserName()); + } + // 框架登录不限制从什么表查询 只要最终构建出 LoginUser 即可 + // 此处可根据登录用户的数据不同 自行创建 loginUser 属性不够用继承扩展就行了 + if (TenantHelper.isEnable()) { + return buildLoginUser(userMapper.selectTenantUserByUserName(sysUser.getUserName(), tenantId)); + } + return buildLoginUser(userMapper.selectUserByUserName(sysUser.getUserName())); + } + @Override public LoginUser getUserInfoByPhonenumber(String phonenumber, String tenantId) throws UserException { SysUser sysUser = userMapper.selectOne(new LambdaQueryWrapper()