diff --git a/IRaCIS.Core.API/_ServiceExtensions/EFSetup.cs b/IRaCIS.Core.API/_ServiceExtensions/EFSetup.cs index 6c679d676..69370b646 100644 --- a/IRaCIS.Core.API/_ServiceExtensions/EFSetup.cs +++ b/IRaCIS.Core.API/_ServiceExtensions/EFSetup.cs @@ -50,7 +50,8 @@ namespace IRaCIS.Core.API //triggerOptions.AddTrigger(); triggerOptions.AddTrigger(); triggerOptions.AddTrigger(); - + triggerOptions.AddTrigger(); + }); diff --git a/IRaCIS.Core.Application/IRaCIS.Core.Application.csproj b/IRaCIS.Core.Application/IRaCIS.Core.Application.csproj index 38b149790..797baa8aa 100644 --- a/IRaCIS.Core.Application/IRaCIS.Core.Application.csproj +++ b/IRaCIS.Core.Application/IRaCIS.Core.Application.csproj @@ -77,6 +77,7 @@ + true diff --git a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml index bfad115dd..08193d132 100644 --- a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml +++ b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml @@ -978,7 +978,7 @@ - + 格式化日期和时间 @@ -986,7 +986,7 @@ - + 获取外键表数据 @@ -994,7 +994,7 @@ - + 获取枚举 diff --git a/IRaCIS.Core.Application/Service/Management/DTO/UserLogViewModel.cs b/IRaCIS.Core.Application/Service/Management/DTO/UserLogViewModel.cs index c7d2b37ab..3615f265c 100644 --- a/IRaCIS.Core.Application/Service/Management/DTO/UserLogViewModel.cs +++ b/IRaCIS.Core.Application/Service/Management/DTO/UserLogViewModel.cs @@ -47,10 +47,17 @@ namespace IRaCIS.Core.Application.ViewModel public string? LoginFaildName { get; set; } + public string? LoginUserName { get; set; } + public DateTime? BeginDate { get; set; } public DateTime? EndDate { get; set; } + public UserTypeEnum? LoginUserTypeEnum { get; set; } + + public Guid? UserTypeId { get; set; } + + public Guid? UserId { get; set; } } diff --git a/IRaCIS.Core.Application/Service/Management/UserService.cs b/IRaCIS.Core.Application/Service/Management/UserService.cs index ea5e82ae7..f53c1246f 100644 --- a/IRaCIS.Core.Application/Service/Management/UserService.cs +++ b/IRaCIS.Core.Application/Service/Management/UserService.cs @@ -661,7 +661,9 @@ namespace IRaCIS.Application.Services failCount++; _cache.Set(cacheKey, failCount, TimeSpan.FromMinutes(lockoutMinutes)); - await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, LoginUserId = Guid.Empty, OptUserId=Guid.Empty, LoginFaildName = userName, LoginPassword = password, OptType = UserOptType.AccountOrPasswordError }, true); + var errorPwdUserId = await _userRepository.Where(u => u.UserName == userName).Select(t => t.Id).FirstOrDefaultAsync(); + + await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, LoginUserId = errorPwdUserId, OptUserId=Guid.Empty, LoginFaildName = userName, LoginPassword = password, OptType = UserOptType.AccountOrPasswordError }, true); return ResponseOutput.NotOk(_localizer["User_CheckNameOrPw"], new LoginReturnDTO()); @@ -694,15 +696,22 @@ namespace IRaCIS.Application.Services [HttpPost] public async Task> GetUserLogList(UserLogQuery inQuery) { + DateTime? trialCreateTime = inQuery.TrialId != null ? _repository.Where(t => t.Id == inQuery.TrialId).Select(t => t.CreateTime).FirstOrDefault() : null; var userLogQueryable = _userLogRepository - .WhereIf(inQuery.TrialId != null, t => t.LoginUser.UserTrials.Any(c => c.TrialId == inQuery.TrialId && c.UserId == t.LoginUserId)) + .WhereIf(inQuery.TrialId != null, t => t.LoginUser.UserTrials.Any(c => c.TrialId == inQuery.TrialId && (c.UserId == t.LoginUserId || c.UserId == t.OptUserId))) + .WhereIf(trialCreateTime != null, t => t.CreateTime >= trialCreateTime) .WhereIf(inQuery.OptType != null, t => t.OptType == inQuery.OptType) + .WhereIf(inQuery.UserId != null, t => t.LoginUserId == inQuery.UserId) .WhereIf(inQuery.BeginDate != null, t => t.CreateTime >= inQuery.BeginDate) .WhereIf(inQuery.EndDate != null, t => t.CreateTime <= inQuery.EndDate) + .WhereIf(!string.IsNullOrEmpty(inQuery.LoginUserName), t => t.LoginUser.UserName.Contains(inQuery.LoginUserName!)) .WhereIf(!string.IsNullOrEmpty(inQuery.LoginFaildName), t => t.LoginFaildName.Contains(inQuery.LoginFaildName!)) .WhereIf(!string.IsNullOrEmpty(inQuery.IP), t => t.IP.Contains(inQuery.IP!)) + .WhereIf(inQuery.LoginUserTypeEnum != null, t => t.LoginUser.UserTypeEnum == inQuery.LoginUserTypeEnum) + .WhereIf(inQuery.UserTypeId != null, t => t.LoginUser.UserTypeId == inQuery.UserTypeId) + .ProjectTo(_mapper.ConfigurationProvider); var pageList = await userLogQueryable.ToPagedListAsync(inQuery.PageIndex, inQuery.PageSize, string.IsNullOrWhiteSpace(inQuery.SortField) ? "Id" : inQuery.SortField, inQuery.Asc); diff --git a/IRaCIS.Core.Application/Triggers/UserLogTrigger.cs b/IRaCIS.Core.Application/Triggers/UserLogTrigger.cs new file mode 100644 index 000000000..eb94e0e15 --- /dev/null +++ b/IRaCIS.Core.Application/Triggers/UserLogTrigger.cs @@ -0,0 +1,42 @@ +using EntityFrameworkCore.Triggered; +using IP2Region.Net.Abstractions; +using Microsoft.Extensions.Localization; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IRaCIS.Core.Application.Triggers +{ + public class UserLogTrigger : IBeforeSaveTrigger + { + public ISearcher _searcher; + + public ILogger _logger; + public UserLogTrigger(ISearcher searcher,ILogger logger) + { + _searcher = searcher; + _logger= logger; + } + + //国家|区域|省份|城市|ISP 缺省的地域信息默认是0 + //0|0|0|内网IP|内网IP + // 中国|0|湖北省|武汉市|电信 + public async Task BeforeSave(ITriggerContext context, CancellationToken cancellationToken) + { + var userLog = context.Entity; + + if (context.ChangeType == ChangeType.Added) + { + + var ipinfo = _searcher.Search(userLog.IP); + + userLog.IPRegion = string.Join('|', ipinfo.Split('|').TakeLast(3)); + + + } + } + } +} diff --git a/IRaCIS.Core.Domain/Management/UserLog.cs b/IRaCIS.Core.Domain/Management/UserLog.cs index 6aeb2c909..631eb51d2 100644 --- a/IRaCIS.Core.Domain/Management/UserLog.cs +++ b/IRaCIS.Core.Domain/Management/UserLog.cs @@ -47,6 +47,8 @@ namespace IRaCIS.Core.Domain.Models [JsonIgnore] public User OptUser { get; set; } + public string IPRegion { get; set; } + } ///