fix: 🐛 请求日志批量插入,漏写了登录日志 (#210)

Co-authored-by: tk <fiyne1a@dingtalk.com>
This commit is contained in:
nsnail 2024-11-22 11:16:18 +08:00 committed by GitHub
parent 4e9f605ea2
commit 6c71c74a27
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 4 deletions

View File

@ -122,7 +122,6 @@ public sealed class VerifyCodeService(BasicRepository<Sys_VerifyCode, long> rpo,
QueryVerifyCodeRsp ret;
#if !DEBUG
// 有发送记录且小于1分钟不允许
if (lastSent != null && (DateTime.Now - lastSent.CreatedTime).TotalMinutes < 1) {
throw new NetAdminInvalidOperationException(Ln._1分钟内只能发送1次);

View File

@ -16,9 +16,9 @@ public sealed class RequestLogCache(IDistributedCache cache, IRequestLogService
/// <inheritdoc />
#if !DEBUG
public async Task<long> CountAsync(QueryReq<QueryRequestLogReq> req)
#else
#else
public Task<long> CountAsync(QueryReq<QueryRequestLogReq> req)
#endif
#endif
{
#if !DEBUG
var ret = await GetOrCreateAsync( //

View File

@ -1,6 +1,7 @@
#if !DEBUG && DBTYPE_SQLSERVER
using System.Collections.Concurrent;
using NetAdmin.Domain.DbMaps.Sys;
using NetAdmin.Domain.Dto.Sys.LoginLog;
using NetAdmin.Domain.Dto.Sys.RequestLog;
using NetAdmin.Domain.Events.Sys;
@ -42,6 +43,11 @@ public sealed class OperationLogger : IEventSubscriber
}
inserts.Add(log);
// 插入登录日志
if (log.ApiPathCrc32 == Chars.FLG_PATH_API_SYS_USER_LOGIN_BY_PWD.Crc32()) {
_ = await App.GetService<ILoginLogCache>().CreateAsync(log.Adapt<CreateLoginLogReq>()).ConfigureAwait(false);
}
}
// 如果首尾日期不一致,要分别插入不同的日期分表
@ -81,7 +87,7 @@ public sealed class OperationLogger : IEventSubscriber
return;
}
_ = await App.GetService<IRequestLogService>().CreateAsync(operationEvent.Data).ConfigureAwait(false);
_ = await App.GetService<IRequestLogCache>().CreateAsync(operationEvent.Data).ConfigureAwait(false);
}
}
#endif