mirror of https://gitee.com/stylefeng/roses
【8.1.9】【sys】修复最后登录时间填充的问题
parent
ae9f8687e1
commit
15e81d2c1a
|
@ -150,7 +150,7 @@ public class LoginService {
|
||||||
// 演示环境,跳过记录日志,非演示环境则记录登录日志
|
// 演示环境,跳过记录日志,非演示环境则记录登录日志
|
||||||
if (!DemoConfigExpander.getDemoEnvFlag()) {
|
if (!DemoConfigExpander.getDemoEnvFlag()) {
|
||||||
// 12. 更新用户登录时间和ip
|
// 12. 更新用户登录时间和ip
|
||||||
sysUserServiceApi.updateUserLoginInfo(loginUser.getUserId(), ip);
|
sysUserServiceApi.updateUserLoginInfo(loginUser.getUserId(), ip, tenantId);
|
||||||
|
|
||||||
// 13.登录成功日志
|
// 13.登录成功日志
|
||||||
loginLogServiceApi.loginSuccess(loginUser.getUserId(), loginUser.getAccount());
|
loginLogServiceApi.loginSuccess(loginUser.getUserId(), loginUser.getAccount());
|
||||||
|
|
|
@ -79,7 +79,7 @@ public interface SysUserServiceApi {
|
||||||
* @author fengshuonan
|
* @author fengshuonan
|
||||||
* @since 2023/6/17 22:46
|
* @since 2023/6/17 22:46
|
||||||
*/
|
*/
|
||||||
void updateUserLoginInfo(Long userId, String ip);
|
void updateUserLoginInfo(Long userId, String ip, Long tenantId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户是否是超级管理员
|
* 获取用户是否是超级管理员
|
||||||
|
|
|
@ -523,7 +523,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateUserLoginInfo(Long userId, String ip) {
|
public void updateUserLoginInfo(Long userId, String ip, Long tenantId) {
|
||||||
|
|
||||||
if (ObjectUtil.isEmpty(userId) || ObjectUtil.isEmpty(ip)) {
|
if (ObjectUtil.isEmpty(userId) || ObjectUtil.isEmpty(ip)) {
|
||||||
return;
|
return;
|
||||||
|
@ -534,19 +534,33 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||||
LambdaQueryWrapper<SysUser> sysUserOriginLoginCountWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<SysUser> sysUserOriginLoginCountWrapper = new LambdaQueryWrapper<>();
|
||||||
sysUserOriginLoginCountWrapper.eq(SysUser::getUserId, userId);
|
sysUserOriginLoginCountWrapper.eq(SysUser::getUserId, userId);
|
||||||
sysUserOriginLoginCountWrapper.select(SysUser::getLoginCount);
|
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) {
|
if (originUser == null || originUser.getLoginCount() == null) {
|
||||||
loginCount = 1;
|
loginCount = 1;
|
||||||
} else {
|
} else {
|
||||||
loginCount = originUser.getLoginCount() + 1;
|
loginCount = originUser.getLoginCount() + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 更新登录次数,登录ip,登录时间
|
||||||
LambdaUpdateWrapper<SysUser> sysUserLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
LambdaUpdateWrapper<SysUser> sysUserLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
||||||
sysUserLambdaUpdateWrapper.eq(SysUser::getUserId, userId);
|
sysUserLambdaUpdateWrapper.eq(SysUser::getUserId, userId);
|
||||||
sysUserLambdaUpdateWrapper.set(SysUser::getLastLoginTime, new Date());
|
sysUserLambdaUpdateWrapper.set(SysUser::getLastLoginTime, new Date());
|
||||||
sysUserLambdaUpdateWrapper.set(SysUser::getLastLoginIp, ip);
|
sysUserLambdaUpdateWrapper.set(SysUser::getLastLoginIp, ip);
|
||||||
sysUserLambdaUpdateWrapper.set(SysUser::getLoginCount, loginCount);
|
sysUserLambdaUpdateWrapper.set(SysUser::getLoginCount, loginCount);
|
||||||
|
try {
|
||||||
|
TenantIdHolder.set(tenantId);
|
||||||
this.update(sysUserLambdaUpdateWrapper);
|
this.update(sysUserLambdaUpdateWrapper);
|
||||||
|
} finally {
|
||||||
|
TenantIdHolder.remove();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue