diff --git a/IRaCIS.Core.Application/Service/Management/DTO/UserModel.cs b/IRaCIS.Core.Application/Service/Management/DTO/UserModel.cs index 5f65c4d00..4ff5d1f95 100644 --- a/IRaCIS.Core.Application/Service/Management/DTO/UserModel.cs +++ b/IRaCIS.Core.Application/Service/Management/DTO/UserModel.cs @@ -37,7 +37,12 @@ namespace IRaCIS.Application.Contracts public string RealName { get; set; } = string.Empty; public int Sex { get; set; } // 1-男 2-女 - public UserTypeEnum UserTypeEnum { get; set; } + /// + /// LastLoginIP + /// + public string LastLoginIP { get; set; } = string.Empty; + + public UserTypeEnum UserTypeEnum { get; set; } /// /// 上一次修改密码的时间 diff --git a/IRaCIS.Core.Application/Service/Management/UserService.cs b/IRaCIS.Core.Application/Service/Management/UserService.cs index b48b721e3..87385eec5 100644 --- a/IRaCIS.Core.Application/Service/Management/UserService.cs +++ b/IRaCIS.Core.Application/Service/Management/UserService.cs @@ -714,11 +714,11 @@ namespace IRaCIS.Application.Services //登录成功 清除缓存 _cache.Set(cacheKey, 0, TimeSpan.FromMinutes(lockoutMinutes)); - var lastLoginLog = await _userLogRepository.Where(x => x.LoginUserId == loginUser.Id).OrderByDescending(x => x.CreateTime).FirstOrDefaultAsync(); - if (lastLoginLog!=null) + + if (loginUser.LastLoginIP != string.Empty) { // 与上一次IP不一致 - if (lastLoginLog.IP != _userInfo.IP) + if (loginUser.LastLoginIP != _userInfo.IP) { loginUser.LoginState = 2; } @@ -740,13 +740,17 @@ namespace IRaCIS.Application.Services } + await _userRepository.BatchUpdateNoTrackingAsync(x => x.Id == loginUser.Id, x => new User() + { + LastLoginIP = _userInfo.IP + + }); + // 登录 清除缓存 + //_cache.Remove(userLoginReturnModel.BasicInfo.Id.ToString()); - // 登录 清除缓存 - //_cache.Remove(userLoginReturnModel.BasicInfo.Id.ToString()); - - var userId = loginUser.Id; + var userId = loginUser.Id; await _cache.SetAsync($"{userId.ToString()}_Online", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), TimeSpan.FromMinutes(_verifyConfig.CurrentValue.AutoLoginOutMinutes)); diff --git a/IRaCIS.Core.Domain/Management/User.cs b/IRaCIS.Core.Domain/Management/User.cs index e47cbd423..775c56fd5 100644 --- a/IRaCIS.Core.Domain/Management/User.cs +++ b/IRaCIS.Core.Domain/Management/User.cs @@ -83,6 +83,11 @@ namespace IRaCIS.Core.Domain.Models /// public DateTime? LastChangePassWordTime { get; set; } + /// + /// LastLoginIP + /// + public string LastLoginIP { get; set; } = string.Empty; + //ҽ˺ź󣬻ֵ public Guid? DoctorId { get; set; }