【8.1.9】【sys】修复最后登录时间填充的问题

dev-8.1.9
stylefeng 2024-07-11 14:03:20 +08:00
parent ae9f8687e1
commit 15e81d2c1a
3 changed files with 19 additions and 5 deletions

View File

@ -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());

View File

@ -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);
/**
*

View File

@ -523,7 +523,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> 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<SysUserMapper, SysUser> impl
LambdaQueryWrapper<SysUser> 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<SysUser> 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