From 3da3b9de45a6f81d69ba0523e16fb1116c714b0a Mon Sep 17 00:00:00 2001
From: he <109787524@qq.com>
Date: Thu, 16 May 2024 13:59:11 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Service/Management/DTO/UserModel.cs | 7 ++++++-
.../Service/Management/UserService.cs | 18 +++++++++++-------
IRaCIS.Core.Domain/Management/User.cs | 5 +++++
3 files changed, 22 insertions(+), 8 deletions(-)
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; }