diff --git a/kernel-d-auth/auth-sdk/src/main/java/cn/stylefeng/roses/kernel/auth/auth/LoginService.java b/kernel-d-auth/auth-sdk/src/main/java/cn/stylefeng/roses/kernel/auth/auth/LoginService.java index 2124ccca0..6c7534438 100644 --- a/kernel-d-auth/auth-sdk/src/main/java/cn/stylefeng/roses/kernel/auth/auth/LoginService.java +++ b/kernel-d-auth/auth-sdk/src/main/java/cn/stylefeng/roses/kernel/auth/auth/LoginService.java @@ -150,7 +150,7 @@ public class LoginService { // 演示环境,跳过记录日志,非演示环境则记录登录日志 if (!DemoConfigExpander.getDemoEnvFlag()) { // 12. 更新用户登录时间和ip - sysUserServiceApi.updateUserLoginInfo(loginUser.getUserId(), ip); + sysUserServiceApi.updateUserLoginInfo(loginUser.getUserId(), ip, tenantId); // 13.登录成功日志 loginLogServiceApi.loginSuccess(loginUser.getUserId(), loginUser.getAccount()); diff --git a/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/sys/api/SysUserServiceApi.java b/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/sys/api/SysUserServiceApi.java index e6f3dda55..6b0e5443d 100644 --- a/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/sys/api/SysUserServiceApi.java +++ b/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/sys/api/SysUserServiceApi.java @@ -79,7 +79,7 @@ public interface SysUserServiceApi { * @author fengshuonan * @since 2023/6/17 22:46 */ - void updateUserLoginInfo(Long userId, String ip); + void updateUserLoginInfo(Long userId, String ip, Long tenantId); /** * 获取用户是否是超级管理员 diff --git a/kernel-s-system/system-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/user/service/impl/SysUserServiceImpl.java b/kernel-s-system/system-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/user/service/impl/SysUserServiceImpl.java index 98c130dbc..dc03e3e56 100644 --- a/kernel-s-system/system-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/user/service/impl/SysUserServiceImpl.java +++ b/kernel-s-system/system-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/user/service/impl/SysUserServiceImpl.java @@ -523,7 +523,7 @@ public class SysUserServiceImpl extends ServiceImpl impl } @Override - public void updateUserLoginInfo(Long userId, String ip) { + public void updateUserLoginInfo(Long userId, String ip, Long tenantId) { if (ObjectUtil.isEmpty(userId) || ObjectUtil.isEmpty(ip)) { return; @@ -534,19 +534,33 @@ public class SysUserServiceImpl extends ServiceImpl impl LambdaQueryWrapper sysUserOriginLoginCountWrapper = new LambdaQueryWrapper<>(); sysUserOriginLoginCountWrapper.eq(SysUser::getUserId, userId); sysUserOriginLoginCountWrapper.select(SysUser::getLoginCount); - SysUser originUser = this.getOne(sysUserOriginLoginCountWrapper, false); + SysUser originUser; + try { + TenantIdHolder.set(tenantId); + originUser = this.getOne(sysUserOriginLoginCountWrapper, false); + } finally { + TenantIdHolder.remove(); + } + + // 获取原有的登录次数,准备加1 if (originUser == null || originUser.getLoginCount() == null) { loginCount = 1; } else { loginCount = originUser.getLoginCount() + 1; } + // 更新登录次数,登录ip,登录时间 LambdaUpdateWrapper sysUserLambdaUpdateWrapper = new LambdaUpdateWrapper<>(); sysUserLambdaUpdateWrapper.eq(SysUser::getUserId, userId); sysUserLambdaUpdateWrapper.set(SysUser::getLastLoginTime, new Date()); sysUserLambdaUpdateWrapper.set(SysUser::getLastLoginIp, ip); sysUserLambdaUpdateWrapper.set(SysUser::getLoginCount, loginCount); - this.update(sysUserLambdaUpdateWrapper); + try { + TenantIdHolder.set(tenantId); + this.update(sysUserLambdaUpdateWrapper); + } finally { + TenantIdHolder.remove(); + } } @Override