From 3acbf6efeec9022d3ad653fe4665e8842cc811dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Tue, 14 Nov 2023 13:20:43 +0800 Subject: [PATCH 01/59] =?UTF-8?q?update=20=E4=BC=98=E5=8C=96=20=E7=A7=9F?= =?UTF-8?q?=E6=88=B7=E6=8F=92=E4=BB=B6=20ignoreTable=20=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=8A=A8=E6=80=81=E7=A7=9F=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/tenant/handle/PlusTenantLineHandler.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/ruoyi-common/ruoyi-common-tenant/src/main/java/org/dromara/common/tenant/handle/PlusTenantLineHandler.java b/ruoyi-common/ruoyi-common-tenant/src/main/java/org/dromara/common/tenant/handle/PlusTenantLineHandler.java index aa77e3e63..6c93ee581 100644 --- a/ruoyi-common/ruoyi-common-tenant/src/main/java/org/dromara/common/tenant/handle/PlusTenantLineHandler.java +++ b/ruoyi-common/ruoyi-common-tenant/src/main/java/org/dromara/common/tenant/handle/PlusTenantLineHandler.java @@ -2,15 +2,14 @@ import cn.hutool.core.collection.ListUtil; import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler; -import lombok.extern.slf4j.Slf4j; -import org.dromara.common.core.utils.StringUtils; -import org.dromara.common.satoken.utils.LoginHelper; -import org.dromara.common.tenant.helper.TenantHelper; -import org.dromara.common.tenant.properties.TenantProperties; import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; import net.sf.jsqlparser.expression.Expression; import net.sf.jsqlparser.expression.NullValue; import net.sf.jsqlparser.expression.StringValue; +import org.dromara.common.core.utils.StringUtils; +import org.dromara.common.tenant.helper.TenantHelper; +import org.dromara.common.tenant.properties.TenantProperties; import java.util.List; @@ -38,7 +37,7 @@ public Expression getTenantId() { @Override public boolean ignoreTable(String tableName) { - String tenantId = LoginHelper.getTenantId(); + String tenantId = TenantHelper.getTenantId(); // 判断是否有租户 if (StringUtils.isNotBlank(tenantId)) { // 不需要过滤租户的表 From 9b0938e0d6f60a18be1f573e74c10eda14d1742b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Tue, 14 Nov 2023 17:02:51 +0800 Subject: [PATCH 02/59] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=20=E5=BB=B6?= =?UTF-8?q?=E8=BF=9F=E9=98=9F=E5=88=97=E5=9C=A8=E6=8A=95=E9=80=92=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E6=9C=AA=E5=88=B0=E8=BE=BE=E6=97=B6=E9=97=B4=E7=9A=84?= =?UTF-8?q?=E6=97=B6=E5=80=99=20=E6=9C=8D=E5=8A=A1=E6=AD=BB=E6=9C=BA?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E9=87=8D=E5=90=AF=E6=94=B6=E4=B8=8D=E5=88=B0?= =?UTF-8?q?=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/dromara/common/redis/utils/QueueUtils.java | 6 +++++- .../demo/controller/queue/DelayedQueueController.java | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/utils/QueueUtils.java b/ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/utils/QueueUtils.java index 67ce55254..4587e643d 100644 --- a/ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/utils/QueueUtils.java +++ b/ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/utils/QueueUtils.java @@ -224,8 +224,12 @@ public static boolean destroyBoundedQueue(String queueName) { /** * 订阅阻塞队列(可订阅所有实现类 例如: 延迟 优先 有界 等) */ - public static void subscribeBlockingQueue(String queueName, Consumer consumer) { + public static void subscribeBlockingQueue(String queueName, Consumer consumer, boolean isDelayed) { RBlockingQueue queue = CLIENT.getBlockingQueue(queueName); + if (isDelayed) { + // 订阅延迟队列 + CLIENT.getDelayedQueue(queue); + } queue.subscribeOnElements(consumer); } diff --git a/ruoyi-modules/ruoyi-demo/src/main/java/org/dromara/demo/controller/queue/DelayedQueueController.java b/ruoyi-modules/ruoyi-demo/src/main/java/org/dromara/demo/controller/queue/DelayedQueueController.java index f9b81c120..fb2aade7d 100644 --- a/ruoyi-modules/ruoyi-demo/src/main/java/org/dromara/demo/controller/queue/DelayedQueueController.java +++ b/ruoyi-modules/ruoyi-demo/src/main/java/org/dromara/demo/controller/queue/DelayedQueueController.java @@ -1,5 +1,6 @@ package org.dromara.demo.controller.queue; +import cn.dev33.satoken.annotation.SaIgnore; import org.dromara.common.core.domain.R; import org.dromara.common.redis.utils.QueueUtils; import lombok.RequiredArgsConstructor; @@ -22,6 +23,7 @@ * @author Lion Li * @version 3.6.0 */ +@SaIgnore @Slf4j @RequiredArgsConstructor @RestController @@ -40,7 +42,7 @@ public R subscribe(String queueName) { QueueUtils.subscribeBlockingQueue(queueName, (String orderNum) -> { // 观察接收时间 log.info("通道: {}, 收到数据: {}", queueName, orderNum); - }); + }, true); return R.ok("操作成功"); } From e2692aa9e9f4a7d796ea8c00d62778c0bb492569 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Fri, 17 Nov 2023 14:45:48 +0800 Subject: [PATCH 03/59] =?UTF-8?q?update=20=E4=BC=98=E5=8C=96=20=E5=B0=86?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E8=AE=B0=E5=BD=95=E6=8A=BD=E5=8F=96=E5=88=B0?= =?UTF-8?q?=E7=9B=91=E5=90=AC=E5=99=A8=E7=BB=9F=E4=B8=80=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web}/listener/UserActionListener.java | 70 +++++++++++-------- .../dromara/web/service/SysLoginService.java | 4 +- .../web/service/impl/EmailAuthStrategy.java | 3 - .../service/impl/PasswordAuthStrategy.java | 3 - .../web/service/impl/SmsAuthStrategy.java | 3 - .../web/service/impl/SocialAuthStrategy.java | 5 -- .../web/service/impl/XcxAuthStrategy.java | 5 -- 7 files changed, 42 insertions(+), 51 deletions(-) rename {ruoyi-common/ruoyi-common-satoken/src/main/java/org/dromara/common/satoken => ruoyi-admin/src/main/java/org/dromara/web}/listener/UserActionListener.java (61%) diff --git a/ruoyi-common/ruoyi-common-satoken/src/main/java/org/dromara/common/satoken/listener/UserActionListener.java b/ruoyi-admin/src/main/java/org/dromara/web/listener/UserActionListener.java similarity index 61% rename from ruoyi-common/ruoyi-common-satoken/src/main/java/org/dromara/common/satoken/listener/UserActionListener.java rename to ruoyi-admin/src/main/java/org/dromara/web/listener/UserActionListener.java index 80034f117..6d67fb112 100644 --- a/ruoyi-common/ruoyi-common-satoken/src/main/java/org/dromara/common/satoken/listener/UserActionListener.java +++ b/ruoyi-admin/src/main/java/org/dromara/web/listener/UserActionListener.java @@ -1,20 +1,24 @@ -package org.dromara.common.satoken.listener; +package org.dromara.web.listener; import cn.dev33.satoken.config.SaTokenConfig; import cn.dev33.satoken.listener.SaTokenListener; import cn.dev33.satoken.stp.SaLoginModel; import cn.hutool.http.useragent.UserAgent; import cn.hutool.http.useragent.UserAgentUtil; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.dromara.common.core.constant.CacheConstants; +import org.dromara.common.core.constant.Constants; import org.dromara.common.core.domain.dto.UserOnlineDTO; import org.dromara.common.core.domain.model.LoginUser; -import org.dromara.common.core.enums.UserType; +import org.dromara.common.core.utils.MessageUtils; +import org.dromara.common.core.utils.ServletUtils; +import org.dromara.common.core.utils.SpringUtils; +import org.dromara.common.core.utils.ip.AddressUtils; +import org.dromara.common.log.event.LogininforEvent; import org.dromara.common.redis.utils.RedisUtils; import org.dromara.common.satoken.utils.LoginHelper; -import org.dromara.common.core.utils.ip.AddressUtils; -import org.dromara.common.core.utils.ServletUtils; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; +import org.dromara.web.service.SysLoginService; import org.springframework.stereotype.Component; import java.time.Duration; @@ -30,37 +34,43 @@ public class UserActionListener implements SaTokenListener { private final SaTokenConfig tokenConfig; + private final SysLoginService loginService; /** * 每次登录时触发 */ @Override public void doLogin(String loginType, Object loginId, String tokenValue, SaLoginModel loginModel) { - UserType userType = UserType.getUserType(loginId.toString()); - if (userType == UserType.SYS_USER) { - UserAgent userAgent = UserAgentUtil.parse(ServletUtils.getRequest().getHeader("User-Agent")); - String ip = ServletUtils.getClientIP(); - LoginUser user = LoginHelper.getLoginUser(); - UserOnlineDTO dto = new UserOnlineDTO(); - dto.setIpaddr(ip); - dto.setLoginLocation(AddressUtils.getRealAddressByIP(ip)); - dto.setBrowser(userAgent.getBrowser().getName()); - dto.setOs(userAgent.getOs().getName()); - dto.setLoginTime(System.currentTimeMillis()); - dto.setTokenId(tokenValue); - dto.setUserName(user.getUsername()); - dto.setClientKey(user.getClientKey()); - dto.setDeviceType(user.getDeviceType()); - dto.setDeptName(user.getDeptName()); - if(tokenConfig.getTimeout() == -1) { - RedisUtils.setCacheObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue, dto); - } else { - RedisUtils.setCacheObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue, dto, Duration.ofSeconds(tokenConfig.getTimeout())); - } - log.info("user doLogin, userId:{}, token:{}", loginId, tokenValue); - } else if (userType == UserType.APP_USER) { - // app端 自行根据业务编写 + UserAgent userAgent = UserAgentUtil.parse(ServletUtils.getRequest().getHeader("User-Agent")); + String ip = ServletUtils.getClientIP(); + LoginUser user = LoginHelper.getLoginUser(); + UserOnlineDTO dto = new UserOnlineDTO(); + dto.setIpaddr(ip); + dto.setLoginLocation(AddressUtils.getRealAddressByIP(ip)); + dto.setBrowser(userAgent.getBrowser().getName()); + dto.setOs(userAgent.getOs().getName()); + dto.setLoginTime(System.currentTimeMillis()); + dto.setTokenId(tokenValue); + dto.setUserName(user.getUsername()); + dto.setClientKey(user.getClientKey()); + dto.setDeviceType(user.getDeviceType()); + dto.setDeptName(user.getDeptName()); + if(tokenConfig.getTimeout() == -1) { + RedisUtils.setCacheObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue, dto); + } else { + RedisUtils.setCacheObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue, dto, Duration.ofSeconds(tokenConfig.getTimeout())); } + // 记录登录日志 + LogininforEvent logininforEvent = new LogininforEvent(); + logininforEvent.setTenantId(user.getTenantId()); + logininforEvent.setUsername(user.getUsername()); + logininforEvent.setStatus(Constants.LOGIN_SUCCESS); + logininforEvent.setMessage(MessageUtils.message("user.login.success")); + logininforEvent.setRequest(ServletUtils.getRequest()); + SpringUtils.context().publishEvent(logininforEvent); + // 更新登录信息 + loginService.recordLoginInfo(user.getUserId(), ip); + log.info("user doLogin, userId:{}, token:{}", loginId, tokenValue); } /** 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 7e07e20fc..8449c8f7c 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 @@ -152,10 +152,10 @@ public LoginUser buildLoginUser(SysUserVo user) { * * @param userId 用户ID */ - public void recordLoginInfo(Long userId) { + public void recordLoginInfo(Long userId, String ip) { SysUser sysUser = new SysUser(); sysUser.setUserId(userId); - sysUser.setLoginIp(ServletUtils.getClientIP()); + sysUser.setLoginIp(ip); sysUser.setLoginDate(DateUtils.getNowDate()); sysUser.setUpdateBy(userId); userMapper.updateById(sysUser); diff --git a/ruoyi-admin/src/main/java/org/dromara/web/service/impl/EmailAuthStrategy.java b/ruoyi-admin/src/main/java/org/dromara/web/service/impl/EmailAuthStrategy.java index 99686eb9e..83ec9ba31 100644 --- a/ruoyi-admin/src/main/java/org/dromara/web/service/impl/EmailAuthStrategy.java +++ b/ruoyi-admin/src/main/java/org/dromara/web/service/impl/EmailAuthStrategy.java @@ -69,9 +69,6 @@ public LoginVo login(String body, SysClient client) { // 生成token LoginHelper.login(loginUser, model); - loginService.recordLogininfor(loginUser.getTenantId(), user.getUserName(), Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")); - loginService.recordLoginInfo(user.getUserId()); - LoginVo loginVo = new LoginVo(); loginVo.setAccessToken(StpUtil.getTokenValue()); loginVo.setExpireIn(StpUtil.getTokenTimeout()); diff --git a/ruoyi-admin/src/main/java/org/dromara/web/service/impl/PasswordAuthStrategy.java b/ruoyi-admin/src/main/java/org/dromara/web/service/impl/PasswordAuthStrategy.java index 95c7aed8e..fa8c9abf7 100644 --- a/ruoyi-admin/src/main/java/org/dromara/web/service/impl/PasswordAuthStrategy.java +++ b/ruoyi-admin/src/main/java/org/dromara/web/service/impl/PasswordAuthStrategy.java @@ -79,9 +79,6 @@ public LoginVo login(String body, SysClient client) { // 生成token LoginHelper.login(loginUser, model); - loginService.recordLogininfor(loginUser.getTenantId(), username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")); - loginService.recordLoginInfo(user.getUserId()); - LoginVo loginVo = new LoginVo(); loginVo.setAccessToken(StpUtil.getTokenValue()); loginVo.setExpireIn(StpUtil.getTokenTimeout()); diff --git a/ruoyi-admin/src/main/java/org/dromara/web/service/impl/SmsAuthStrategy.java b/ruoyi-admin/src/main/java/org/dromara/web/service/impl/SmsAuthStrategy.java index 8f64ce1fe..dda4504c2 100644 --- a/ruoyi-admin/src/main/java/org/dromara/web/service/impl/SmsAuthStrategy.java +++ b/ruoyi-admin/src/main/java/org/dromara/web/service/impl/SmsAuthStrategy.java @@ -69,9 +69,6 @@ public LoginVo login(String body, SysClient client) { // 生成token LoginHelper.login(loginUser, model); - loginService.recordLogininfor(loginUser.getTenantId(), user.getUserName(), Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")); - loginService.recordLoginInfo(user.getUserId()); - LoginVo loginVo = new LoginVo(); loginVo.setAccessToken(StpUtil.getTokenValue()); loginVo.setExpireIn(StpUtil.getTokenTimeout()); diff --git a/ruoyi-admin/src/main/java/org/dromara/web/service/impl/SocialAuthStrategy.java b/ruoyi-admin/src/main/java/org/dromara/web/service/impl/SocialAuthStrategy.java index 64a9e97a3..a4707029e 100644 --- a/ruoyi-admin/src/main/java/org/dromara/web/service/impl/SocialAuthStrategy.java +++ b/ruoyi-admin/src/main/java/org/dromara/web/service/impl/SocialAuthStrategy.java @@ -12,13 +12,11 @@ import lombok.extern.slf4j.Slf4j; import me.zhyd.oauth.model.AuthResponse; import me.zhyd.oauth.model.AuthUser; -import org.dromara.common.core.constant.Constants; import org.dromara.common.core.domain.model.LoginUser; import org.dromara.common.core.domain.model.SocialLoginBody; import org.dromara.common.core.enums.UserStatus; import org.dromara.common.core.exception.ServiceException; import org.dromara.common.core.exception.user.UserException; -import org.dromara.common.core.utils.MessageUtils; import org.dromara.common.core.utils.ValidatorUtils; import org.dromara.common.json.utils.JsonUtils; import org.dromara.common.satoken.utils.LoginHelper; @@ -106,9 +104,6 @@ public LoginVo login(String body, SysClient client) { // 生成token LoginHelper.login(loginUser, model); - loginService.recordLogininfor(loginUser.getTenantId(), user.getUserName(), Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")); - loginService.recordLoginInfo(user.getUserId()); - LoginVo loginVo = new LoginVo(); loginVo.setAccessToken(StpUtil.getTokenValue()); loginVo.setExpireIn(StpUtil.getTokenTimeout()); diff --git a/ruoyi-admin/src/main/java/org/dromara/web/service/impl/XcxAuthStrategy.java b/ruoyi-admin/src/main/java/org/dromara/web/service/impl/XcxAuthStrategy.java index f227dc174..e5aef1fad 100644 --- a/ruoyi-admin/src/main/java/org/dromara/web/service/impl/XcxAuthStrategy.java +++ b/ruoyi-admin/src/main/java/org/dromara/web/service/impl/XcxAuthStrategy.java @@ -5,11 +5,9 @@ import cn.hutool.core.util.ObjectUtil; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.dromara.common.core.constant.Constants; import org.dromara.common.core.domain.model.XcxLoginBody; import org.dromara.common.core.domain.model.XcxLoginUser; import org.dromara.common.core.enums.UserStatus; -import org.dromara.common.core.utils.MessageUtils; import org.dromara.common.core.utils.ValidatorUtils; import org.dromara.common.json.utils.JsonUtils; import org.dromara.common.satoken.utils.LoginHelper; @@ -68,9 +66,6 @@ public LoginVo login(String body, SysClient client) { // 生成token LoginHelper.login(loginUser, model); - loginService.recordLogininfor(loginUser.getTenantId(), user.getUserName(), Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")); - loginService.recordLoginInfo(user.getUserId()); - LoginVo loginVo = new LoginVo(); loginVo.setAccessToken(StpUtil.getTokenValue()); loginVo.setExpireIn(StpUtil.getTokenTimeout()); From 16685a8e0c7d6c968dca1c859727fab050e12a56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Fri, 17 Nov 2023 16:43:21 +0800 Subject: [PATCH 04/59] =?UTF-8?q?update=20=E4=BC=98=E5=8C=96=20=E8=A1=A5?= =?UTF-8?q?=E5=85=A8=E4=B8=89=E6=96=B9=E7=BB=91=E5=AE=9A=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=20=E5=88=A0=E9=99=A4=E6=97=A0=E7=94=A8excel?= =?UTF-8?q?=E6=B3=A8=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dromara/system/domain/vo/SysSocialVo.java | 31 +++---------------- 1 file changed, 5 insertions(+), 26 deletions(-) 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 8a00cc387..948dbcc7b 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 @@ -1,13 +1,12 @@ package org.dromara.system.domain.vo; -import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; -import com.alibaba.excel.annotation.ExcelProperty; import io.github.linpeilie.annotations.AutoMapper; import lombok.Data; import org.dromara.system.domain.SysSocial; import java.io.Serial; import java.io.Serializable; +import java.util.Date; /** @@ -16,7 +15,6 @@ * @author thiszhc */ @Data -@ExcelIgnoreUnannotated @AutoMapper(target = SysSocial.class) public class SysSocialVo implements Serializable { @@ -26,13 +24,11 @@ public class SysSocialVo implements Serializable { /** * 主键 */ - @ExcelProperty(value = "主键") private Long id; /** * 用户ID */ - @ExcelProperty(value = "用户ID") private Long userId; /** @@ -43,123 +39,106 @@ public class SysSocialVo implements Serializable { /** * 的唯一ID */ - @ExcelProperty(value = "授权UUID") private String authId; /** * 用户来源 */ - @ExcelProperty(value = "用户来源") private String source; /** * 用户的授权令牌 */ - @ExcelProperty(value = "用户的授权令牌") private String accessToken; /** * 用户的授权令牌的有效期,部分平台可能没有 */ - @ExcelProperty(value = "用户的授权令牌的有效期,部分平台可能没有") private int expireIn; /** * 刷新令牌,部分平台可能没有 */ - @ExcelProperty(value = "刷新令牌,部分平台可能没有") private String refreshToken; /** * 用户的 open id */ - @ExcelProperty(value = "平台的唯一id") private String openId; /** * 授权的第三方账号 */ - @ExcelProperty(value = "授权的第三方账号") private String userName; /** * 授权的第三方昵称 */ - @ExcelProperty(value = "授权的第三方昵称") private String nickName; /** * 授权的第三方邮箱 */ - @ExcelProperty(value = "授权的第三方邮箱") private String email; /** * 授权的第三方头像地址 */ - @ExcelProperty(value = "授权的第三方头像地址") private String avatar; /** * 平台的授权信息,部分平台可能没有 */ - @ExcelProperty(value = "平台的授权信息,部分平台可能没有") private String accessCode; /** * 用户的 unionid */ - @ExcelProperty(value = "用户的 unionid") private String unionId; /** * 授予的权限,部分平台可能没有 */ - @ExcelProperty(value = "授予的权限,部分平台可能没有") private String scope; /** * 个别平台的授权信息,部分平台可能没有 */ - @ExcelProperty(value = "个别平台的授权信息,部分平台可能没有") private String tokenType; /** * id token,部分平台可能没有 */ - @ExcelProperty(value = "id token,部分平台可能没有") private String idToken; /** * 小米平台用户的附带属性,部分平台可能没有 */ - @ExcelProperty(value = "小米平台用户的附带属性,部分平台可能没有") private String macAlgorithm; /** * 小米平台用户的附带属性,部分平台可能没有 */ - @ExcelProperty(value = "小米平台用户的附带属性,部分平台可能没有") private String macKey; /** * 用户的授权code,部分平台可能没有 */ - @ExcelProperty(value = "用户的授权code,部分平台可能没有") private String code; /** * Twitter平台用户的附带属性,部分平台可能没有 */ - @ExcelProperty(value = "Twitter平台用户的附带属性,部分平台可能没有") private String oauthToken; /** * Twitter平台用户的附带属性,部分平台可能没有 */ - @ExcelProperty(value = "Twitter平台用户的附带属性,部分平台可能没有") private String oauthTokenSecret; - + /** + * 创建时间 + */ + private Date createTime; } From 754c22f8a693da484e1aef18f5b3afa73d15b683 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Fri, 17 Nov 2023 18:00:20 +0800 Subject: [PATCH 05/59] =?UTF-8?q?update=20=E4=BC=98=E5=8C=96=20=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E7=94=A8=E6=88=B7=E7=99=BB=E5=BD=95=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E5=BF=BD=E7=95=A5=E6=95=B0=E6=8D=AE=E6=9D=83?= =?UTF-8?q?=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/org/dromara/web/service/SysLoginService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 8449c8f7c..84e0b4d76 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 @@ -17,6 +17,7 @@ import org.dromara.common.core.exception.user.UserException; import org.dromara.common.core.utils.*; import org.dromara.common.log.event.LogininforEvent; +import org.dromara.common.mybatis.helper.DataPermissionHelper; import org.dromara.common.redis.utils.RedisUtils; import org.dromara.common.satoken.utils.LoginHelper; import org.dromara.common.tenant.exception.TenantException; @@ -158,7 +159,7 @@ public void recordLoginInfo(Long userId, String ip) { sysUser.setLoginIp(ip); sysUser.setLoginDate(DateUtils.getNowDate()); sysUser.setUpdateBy(userId); - userMapper.updateById(sysUser); + DataPermissionHelper.ignore(() -> userMapper.updateById(sysUser)); } /** From f2956c322edfeb241acdd1e415080fb40a021ced Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Sun, 19 Nov 2023 21:37:03 +0800 Subject: [PATCH 06/59] =?UTF-8?q?update=20=E4=BC=98=E5=8C=96=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=A4=9A=E7=A7=9F=E6=88=B7=E7=BB=91=E5=AE=9A=E7=9B=B8?= =?UTF-8?q?=E5=90=8C=E7=9A=84=E4=B8=89=E6=96=B9=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dromara/web/service/SysLoginService.java | 7 ++++--- .../web/service/impl/SocialAuthStrategy.java | 19 ++++++++++--------- .../system/service/ISysSocialService.java | 2 +- .../service/impl/SysSocialServiceImpl.java | 4 ++-- 4 files changed, 17 insertions(+), 15 deletions(-) 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 84e0b4d76..ef5335fc7 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 @@ -3,6 +3,7 @@ import cn.dev33.satoken.exception.NotLoginException; import cn.dev33.satoken.stp.StpUtil; import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjectUtil; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -78,13 +79,13 @@ public void socialRegister(AuthUser authUserData) { bo.setUserName(authUserData.getUsername()); bo.setNickName(authUserData.getNickname()); // 查询是否已经绑定用户 - SysSocialVo vo = sysSocialService.selectByAuthId(authId); - if (ObjectUtil.isEmpty(vo)) { + List list = sysSocialService.selectByAuthId(authId); + if (CollUtil.isEmpty(list)) { // 没有绑定用户, 新增用户信息 sysSocialService.insertByBo(bo); } else { // 更新用户信息 - bo.setId(vo.getId()); + bo.setId(list.get(0).getId()); sysSocialService.updateByBo(bo); } } diff --git a/ruoyi-admin/src/main/java/org/dromara/web/service/impl/SocialAuthStrategy.java b/ruoyi-admin/src/main/java/org/dromara/web/service/impl/SocialAuthStrategy.java index a4707029e..8f6486d78 100644 --- a/ruoyi-admin/src/main/java/org/dromara/web/service/impl/SocialAuthStrategy.java +++ b/ruoyi-admin/src/main/java/org/dromara/web/service/impl/SocialAuthStrategy.java @@ -2,9 +2,9 @@ import cn.dev33.satoken.stp.SaLoginModel; import cn.dev33.satoken.stp.StpUtil; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.StrUtil; import cn.hutool.http.HttpUtil; import cn.hutool.http.Method; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; @@ -34,6 +34,9 @@ import org.dromara.web.service.SysLoginService; import org.springframework.stereotype.Service; +import java.util.List; +import java.util.Optional; + /** * 第三方授权策略 * @@ -76,19 +79,17 @@ public LoginVo login(String body, SysClient client) { .executeAsync(); } - SysSocialVo social = sysSocialService.selectByAuthId(authUserData.getSource() + authUserData.getUuid()); - if (!ObjectUtil.isNotNull(social)) { + List list = sysSocialService.selectByAuthId(authUserData.getSource() + authUserData.getUuid()); + if (CollUtil.isEmpty(list)) { throw new ServiceException("你还没有绑定第三方账号,绑定后才可以登录!"); } - // 验证授权表里面的租户id是否包含当前租户id - String tenantId = social.getTenantId(); - if (ObjectUtil.isNotNull(social) && StrUtil.isNotBlank(tenantId) - && !tenantId.contains(loginBody.getTenantId())) { + Optional opt = list.stream().filter(x -> x.getTenantId().equals(loginBody.getTenantId())).findAny(); + if (opt.isEmpty()) { throw new ServiceException("对不起,你没有权限登录当前租户!"); } - + SysSocialVo social = opt.get(); // 查找用户 - SysUserVo user = loadUser(tenantId, social.getUserId()); + SysUserVo user = loadUser(social.getTenantId(), social.getUserId()); // 此处可根据登录用户的数据不同 自行创建 loginUser 属性不够用继承扩展就行了 LoginUser loginUser = loginService.buildLoginUser(user); diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/ISysSocialService.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/ISysSocialService.java index 5f2014d9e..d5702c94a 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/ISysSocialService.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/ISysSocialService.java @@ -49,7 +49,7 @@ public interface ISysSocialService { * @param authId 认证ID * @return SysSocial */ - SysSocialVo selectByAuthId(String authId); + List 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 bd7248f3c..aa86ae113 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 @@ -99,8 +99,8 @@ public Boolean deleteWithValidById(Long id) { * @return 授权信息 */ @Override - public SysSocialVo selectByAuthId(String authId) { - return baseMapper.selectVoOne(new LambdaQueryWrapper().eq(SysSocial::getAuthId, authId)); + public List selectByAuthId(String authId) { + return baseMapper.selectVoList(new LambdaQueryWrapper().eq(SysSocial::getAuthId, authId)); } } From 3046362ff4b30ad265d8ea6ac23c2a5579a1ea3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Sun, 19 Nov 2023 21:38:15 +0800 Subject: [PATCH 07/59] =?UTF-8?q?update=20redisson=203.24.1=20=3D>=203.24.?= =?UTF-8?q?3=20=E4=BF=AE=E5=A4=8D=E8=AE=A2=E9=98=85=E9=87=8D=E5=90=AF?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E8=B6=85=E6=97=B6=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4e079f354..3f354d858 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,7 @@ 5.8.22 4.10.0 3.1.7 - 3.24.1 + 3.24.3 2.2.5 4.2.0 2.14.2 From 1e1616ceb0f4c7d11e043201ecbfc9d77092ae65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Tue, 21 Nov 2023 14:55:46 +0800 Subject: [PATCH 08/59] =?UTF-8?q?update=20=E4=BC=98=E5=8C=96=20TenantHelpe?= =?UTF-8?q?r=20=E5=8A=A8=E6=80=81=E7=A7=9F=E6=88=B7=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E5=BC=8F=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/tenant/helper/TenantHelper.java | 58 +++++++++++++++++-- 1 file changed, 52 insertions(+), 6 deletions(-) diff --git a/ruoyi-common/ruoyi-common-tenant/src/main/java/org/dromara/common/tenant/helper/TenantHelper.java b/ruoyi-common/ruoyi-common-tenant/src/main/java/org/dromara/common/tenant/helper/TenantHelper.java index 8d435a367..2ef1a220e 100644 --- a/ruoyi-common/ruoyi-common-tenant/src/main/java/org/dromara/common/tenant/helper/TenantHelper.java +++ b/ruoyi-common/ruoyi-common-tenant/src/main/java/org/dromara/common/tenant/helper/TenantHelper.java @@ -1,7 +1,7 @@ package org.dromara.common.tenant.helper; import cn.dev33.satoken.context.SaHolder; -import cn.dev33.satoken.spring.SpringMVCUtil; +import cn.dev33.satoken.stp.StpUtil; import cn.hutool.core.convert.Convert; import com.alibaba.ttl.TransmittableThreadLocal; import com.baomidou.mybatisplus.core.plugins.IgnoreStrategy; @@ -82,10 +82,13 @@ public static T ignore(Supplier handle) { /** * 设置动态租户(一直有效 需要手动清理) *

- * 如果为非web环境 那么只在当前线程内生效 + * 如果为未登录状态下 那么只在当前线程内生效 */ public static void setDynamic(String tenantId) { - if (!SpringMVCUtil.isWeb()) { + if (!isEnable()) { + return; + } + if (!isLogin()) { TEMP_DYNAMIC_TENANT.set(tenantId); return; } @@ -97,10 +100,13 @@ public static void setDynamic(String tenantId) { /** * 获取动态租户(一直有效 需要手动清理) *

- * 如果为非web环境 那么只在当前线程内生效 + * 如果为未登录状态下 那么只在当前线程内生效 */ public static String getDynamic() { - if (!SpringMVCUtil.isWeb()) { + if (!isEnable()) { + return null; + } + if (!isLogin()) { return TEMP_DYNAMIC_TENANT.get(); } String cacheKey = DYNAMIC_TENANT_KEY + ":" + LoginHelper.getUserId(); @@ -117,7 +123,10 @@ public static String getDynamic() { * 清除动态租户 */ public static void clearDynamic() { - if (!SpringMVCUtil.isWeb()) { + if (!isEnable()) { + return; + } + if (!isLogin()) { TEMP_DYNAMIC_TENANT.remove(); return; } @@ -126,6 +135,34 @@ public static void clearDynamic() { SaHolder.getStorage().delete(cacheKey); } + /** + * 在动态租户中执行 + * + * @param handle 处理执行方法 + */ + public static void dynamic(String tenantId, Runnable handle) { + setDynamic(tenantId); + try { + handle.run(); + } finally { + clearDynamic(); + } + } + + /** + * 在动态租户中执行 + * + * @param handle 处理执行方法 + */ + public static T dynamic(String tenantId, Supplier handle) { + setDynamic(tenantId); + try { + return handle.get(); + } finally { + clearDynamic(); + } + } + /** * 获取当前租户id(动态租户优先) */ @@ -137,4 +174,13 @@ public static String getTenantId() { return tenantId; } + private static boolean isLogin() { + try { + StpUtil.checkLogin(); + return true; + } catch (Exception e) { + return false; + } + } + } From ac6fe634dc6db33818c17a76b7271f166b2edeb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Tue, 21 Nov 2023 14:57:00 +0800 Subject: [PATCH 09/59] =?UTF-8?q?update=20=E4=BC=98=E5=8C=96=20=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E5=8A=A8=E6=80=81=E7=A7=9F=E6=88=B7=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E4=B8=9A=E5=8A=A1=E5=AF=B9=E7=A7=9F=E6=88=B7=E7=9A=84=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/service/SysRegisterService.java | 11 +++--- .../web/service/impl/EmailAuthStrategy.java | 28 +++++++-------- .../service/impl/PasswordAuthStrategy.java | 28 +++++++-------- .../web/service/impl/SmsAuthStrategy.java | 28 +++++++-------- .../web/service/impl/SocialAuthStrategy.java | 24 ++++++------- .../dromara/system/mapper/SysUserMapper.java | 34 +------------------ .../service/impl/SysConfigServiceImpl.java | 7 ++-- .../service/impl/SysOssConfigServiceImpl.java | 9 ++--- .../resources/mapper/system/SysUserMapper.xml | 15 -------- 9 files changed, 64 insertions(+), 120 deletions(-) diff --git a/ruoyi-admin/src/main/java/org/dromara/web/service/SysRegisterService.java b/ruoyi-admin/src/main/java/org/dromara/web/service/SysRegisterService.java index 4d4b07283..f38d074e3 100644 --- a/ruoyi-admin/src/main/java/org/dromara/web/service/SysRegisterService.java +++ b/ruoyi-admin/src/main/java/org/dromara/web/service/SysRegisterService.java @@ -3,6 +3,7 @@ import cn.dev33.satoken.secure.BCrypt; import cn.hutool.core.util.ObjectUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import lombok.RequiredArgsConstructor; import org.dromara.common.core.constant.Constants; import org.dromara.common.core.constant.GlobalConstants; import org.dromara.common.core.domain.model.RegisterBody; @@ -22,7 +23,6 @@ import org.dromara.system.domain.bo.SysUserBo; import org.dromara.system.mapper.SysUserMapper; import org.dromara.system.service.ISysUserService; -import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; /** @@ -59,10 +59,11 @@ public void register(RegisterBody registerBody) { sysUser.setPassword(BCrypt.hashpw(password)); sysUser.setUserType(userType); - boolean exist = userMapper.exists(new LambdaQueryWrapper() - .eq(TenantHelper.isEnable(), SysUser::getTenantId, tenantId) - .eq(SysUser::getUserName, sysUser.getUserName()) - .ne(ObjectUtil.isNotNull(sysUser.getUserId()), SysUser::getUserId, sysUser.getUserId())); + boolean exist = TenantHelper.dynamic(tenantId, () -> { + return userMapper.exists(new LambdaQueryWrapper() + .eq(SysUser::getUserName, sysUser.getUserName()) + .ne(ObjectUtil.isNotNull(sysUser.getUserId()), SysUser::getUserId, sysUser.getUserId())); + }); if (exist) { throw new UserException("user.register.save.error", username); } diff --git a/ruoyi-admin/src/main/java/org/dromara/web/service/impl/EmailAuthStrategy.java b/ruoyi-admin/src/main/java/org/dromara/web/service/impl/EmailAuthStrategy.java index 83ec9ba31..a2636bc22 100644 --- a/ruoyi-admin/src/main/java/org/dromara/web/service/impl/EmailAuthStrategy.java +++ b/ruoyi-admin/src/main/java/org/dromara/web/service/impl/EmailAuthStrategy.java @@ -89,21 +89,19 @@ private boolean validateEmailCode(String tenantId, String email, String emailCod } private SysUserVo loadUserByEmail(String tenantId, String email) { - SysUser user = userMapper.selectOne(new LambdaQueryWrapper() - .select(SysUser::getEmail, SysUser::getStatus) - .eq(TenantHelper.isEnable(), SysUser::getTenantId, tenantId) - .eq(SysUser::getEmail, email)); - if (ObjectUtil.isNull(user)) { - log.info("登录用户:{} 不存在.", email); - throw new UserException("user.not.exists", email); - } else if (UserStatus.DISABLE.getCode().equals(user.getStatus())) { - log.info("登录用户:{} 已被停用.", email); - throw new UserException("user.blocked", email); - } - if (TenantHelper.isEnable()) { - return userMapper.selectTenantUserByEmail(email, tenantId); - } - return userMapper.selectUserByEmail(email); + return TenantHelper.dynamic(tenantId, () -> { + SysUser user = userMapper.selectOne(new LambdaQueryWrapper() + .select(SysUser::getEmail, SysUser::getStatus) + .eq(SysUser::getEmail, email)); + if (ObjectUtil.isNull(user)) { + log.info("登录用户:{} 不存在.", email); + throw new UserException("user.not.exists", email); + } else if (UserStatus.DISABLE.getCode().equals(user.getStatus())) { + log.info("登录用户:{} 已被停用.", email); + throw new UserException("user.blocked", email); + } + return userMapper.selectUserByEmail(email); + }); } } diff --git a/ruoyi-admin/src/main/java/org/dromara/web/service/impl/PasswordAuthStrategy.java b/ruoyi-admin/src/main/java/org/dromara/web/service/impl/PasswordAuthStrategy.java index fa8c9abf7..bcb5916d3 100644 --- a/ruoyi-admin/src/main/java/org/dromara/web/service/impl/PasswordAuthStrategy.java +++ b/ruoyi-admin/src/main/java/org/dromara/web/service/impl/PasswordAuthStrategy.java @@ -108,21 +108,19 @@ private void validateCaptcha(String tenantId, String username, String code, Stri } private SysUserVo loadUserByUsername(String tenantId, String username) { - SysUser user = userMapper.selectOne(new LambdaQueryWrapper() - .select(SysUser::getUserName, SysUser::getStatus) - .eq(TenantHelper.isEnable(), SysUser::getTenantId, tenantId) - .eq(SysUser::getUserName, username)); - if (ObjectUtil.isNull(user)) { - log.info("登录用户:{} 不存在.", username); - throw new UserException("user.not.exists", username); - } else if (UserStatus.DISABLE.getCode().equals(user.getStatus())) { - log.info("登录用户:{} 已被停用.", username); - throw new UserException("user.blocked", username); - } - if (TenantHelper.isEnable()) { - return userMapper.selectTenantUserByUserName(username, tenantId); - } - return userMapper.selectUserByUserName(username); + return TenantHelper.dynamic(tenantId, () -> { + SysUser user = userMapper.selectOne(new LambdaQueryWrapper() + .select(SysUser::getUserName, SysUser::getStatus) + .eq(SysUser::getUserName, username)); + if (ObjectUtil.isNull(user)) { + log.info("登录用户:{} 不存在.", username); + throw new UserException("user.not.exists", username); + } else if (UserStatus.DISABLE.getCode().equals(user.getStatus())) { + log.info("登录用户:{} 已被停用.", username); + throw new UserException("user.blocked", username); + } + return userMapper.selectUserByUserName(username); + }); } } diff --git a/ruoyi-admin/src/main/java/org/dromara/web/service/impl/SmsAuthStrategy.java b/ruoyi-admin/src/main/java/org/dromara/web/service/impl/SmsAuthStrategy.java index dda4504c2..a4fa11c8e 100644 --- a/ruoyi-admin/src/main/java/org/dromara/web/service/impl/SmsAuthStrategy.java +++ b/ruoyi-admin/src/main/java/org/dromara/web/service/impl/SmsAuthStrategy.java @@ -89,21 +89,19 @@ private boolean validateSmsCode(String tenantId, String phonenumber, String smsC } private SysUserVo loadUserByPhonenumber(String tenantId, String phonenumber) { - SysUser user = userMapper.selectOne(new LambdaQueryWrapper() - .select(SysUser::getPhonenumber, SysUser::getStatus) - .eq(TenantHelper.isEnable(), SysUser::getTenantId, tenantId) - .eq(SysUser::getPhonenumber, phonenumber)); - if (ObjectUtil.isNull(user)) { - log.info("登录用户:{} 不存在.", phonenumber); - throw new UserException("user.not.exists", phonenumber); - } else if (UserStatus.DISABLE.getCode().equals(user.getStatus())) { - log.info("登录用户:{} 已被停用.", phonenumber); - throw new UserException("user.blocked", phonenumber); - } - if (TenantHelper.isEnable()) { - return userMapper.selectTenantUserByPhonenumber(phonenumber, tenantId); - } - return userMapper.selectUserByPhonenumber(phonenumber); + return TenantHelper.dynamic(tenantId, () -> { + SysUser user = userMapper.selectOne(new LambdaQueryWrapper() + .select(SysUser::getPhonenumber, SysUser::getStatus) + .eq(SysUser::getPhonenumber, phonenumber)); + if (ObjectUtil.isNull(user)) { + log.info("登录用户:{} 不存在.", phonenumber); + throw new UserException("user.not.exists", phonenumber); + } else if (UserStatus.DISABLE.getCode().equals(user.getStatus())) { + log.info("登录用户:{} 已被停用.", phonenumber); + throw new UserException("user.blocked", phonenumber); + } + return userMapper.selectUserByPhonenumber(phonenumber); + }); } } diff --git a/ruoyi-admin/src/main/java/org/dromara/web/service/impl/SocialAuthStrategy.java b/ruoyi-admin/src/main/java/org/dromara/web/service/impl/SocialAuthStrategy.java index 8f6486d78..a12386e94 100644 --- a/ruoyi-admin/src/main/java/org/dromara/web/service/impl/SocialAuthStrategy.java +++ b/ruoyi-admin/src/main/java/org/dromara/web/service/impl/SocialAuthStrategy.java @@ -113,21 +113,19 @@ public LoginVo login(String body, SysClient client) { } private SysUserVo loadUser(String tenantId, Long userId) { - SysUser user = userMapper.selectOne(new LambdaQueryWrapper() + return TenantHelper.dynamic(tenantId, () -> { + SysUser user = userMapper.selectOne(new LambdaQueryWrapper() .select(SysUser::getUserName, SysUser::getStatus) - .eq(TenantHelper.isEnable(), SysUser::getTenantId, tenantId) .eq(SysUser::getUserId, userId)); - if (ObjectUtil.isNull(user)) { - log.info("登录用户:{} 不存在.", ""); - throw new UserException("user.not.exists", ""); - } else if (UserStatus.DISABLE.getCode().equals(user.getStatus())) { - log.info("登录用户:{} 已被停用.", ""); - throw new UserException("user.blocked", ""); - } - if (TenantHelper.isEnable()) { - return userMapper.selectTenantUserByUserName(user.getUserName(), tenantId); - } - return userMapper.selectUserByUserName(user.getUserName()); + if (ObjectUtil.isNull(user)) { + log.info("登录用户:{} 不存在.", ""); + throw new UserException("user.not.exists", ""); + } else if (UserStatus.DISABLE.getCode().equals(user.getStatus())) { + log.info("登录用户:{} 已被停用.", ""); + throw new UserException("user.blocked", ""); + } + return userMapper.selectUserByUserName(user.getUserName()); + }); } } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/mapper/SysUserMapper.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/mapper/SysUserMapper.java index c3a886980..43222253c 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/mapper/SysUserMapper.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/mapper/SysUserMapper.java @@ -1,15 +1,14 @@ package org.dromara.system.mapper; -import com.baomidou.mybatisplus.annotation.InterceptorIgnore; import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.toolkit.Constants; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import org.apache.ibatis.annotations.Param; import org.dromara.common.mybatis.annotation.DataColumn; import org.dromara.common.mybatis.annotation.DataPermission; import org.dromara.common.mybatis.core.mapper.BaseMapperPlus; import org.dromara.system.domain.SysUser; import org.dromara.system.domain.vo.SysUserVo; -import org.apache.ibatis.annotations.Param; import java.util.List; @@ -86,37 +85,6 @@ public interface SysUserMapper extends BaseMapperPlus { */ SysUserVo selectUserByEmail(String email); - /** - * 通过用户名查询用户(不走租户插件) - * - * @param userName 用户名 - * @param tenantId 租户id - * @return 用户对象信息 - */ - @InterceptorIgnore(tenantLine = "true") - SysUserVo selectTenantUserByUserName(@Param("userName") String userName, @Param("tenantId") String tenantId); - - /** - * 通过手机号查询用户(不走租户插件) - * - * @param phonenumber 手机号 - * @param tenantId 租户id - * @return 用户对象信息 - */ - @InterceptorIgnore(tenantLine = "true") - SysUserVo selectTenantUserByPhonenumber(@Param("phonenumber") String phonenumber, @Param("tenantId") String tenantId); - - /** - * 通过邮箱查询用户(不走租户插件) - * - * @param email 邮箱 - * @param tenantId 租户id - * @return 用户对象信息 - */ - @InterceptorIgnore(tenantLine = "true") - SysUserVo selectTenantUserByEmail(@Param("email") String email, @Param("tenantId") String tenantId); - - /** * 通过用户ID查询用户 * diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysConfigServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysConfigServiceImpl.java index d1f824800..7738d8067 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysConfigServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysConfigServiceImpl.java @@ -85,9 +85,10 @@ public String selectConfigByKey(String configKey) { */ @Override public boolean selectRegisterEnabled(String tenantId) { - SysConfig retConfig = baseMapper.selectOne(new LambdaQueryWrapper() - .eq(SysConfig::getConfigKey, "sys.account.registerUser") - .eq(TenantHelper.isEnable(),SysConfig::getTenantId, tenantId)); + SysConfig retConfig = TenantHelper.dynamic(tenantId, () -> { + return baseMapper.selectOne(new LambdaQueryWrapper() + .eq(SysConfig::getConfigKey, "sys.account.registerUser")); + }); if (ObjectUtil.isNull(retConfig)) { return false; } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysOssConfigServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysOssConfigServiceImpl.java index be4ed039c..df5e23c6c 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysOssConfigServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysOssConfigServiceImpl.java @@ -57,9 +57,8 @@ public void init() { new LambdaQueryWrapper().orderByAsc(TenantEntity::getTenantId)) ); Map> map = StreamUtils.groupByKey(list, SysOssConfig::getTenantId); - try { - for (String tenantId : map.keySet()) { - TenantHelper.setDynamic(tenantId); + for (String tenantId : map.keySet()) { + TenantHelper.dynamic(tenantId, () -> { // 加载OSS初始化配置 for (SysOssConfig config : map.get(tenantId)) { String configKey = config.getConfigKey(); @@ -68,9 +67,7 @@ public void init() { } CacheUtils.put(CacheNames.SYS_OSS_CONFIG, config.getConfigKey(), JsonUtils.toJsonString(config)); } - } - } finally { - TenantHelper.clearDynamic(); + }); } } diff --git a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml index 52c1aa44a..7af7dd0cc 100644 --- a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml +++ b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml @@ -118,21 +118,6 @@ where u.del_flag = '0' and u.email = #{email} - - - - - -