feat: 新增请求访问统计功能
This commit is contained in:
@@ -5,6 +5,7 @@ using Quartz;
|
||||
using Volo.Abp.BackgroundWorkers.Quartz;
|
||||
using Volo.Abp.Caching;
|
||||
using Volo.Abp.DependencyInjection;
|
||||
using Volo.Abp.Domain.Entities;
|
||||
using Yi.Framework.Bbs.Domain.Entities;
|
||||
using Yi.Framework.Bbs.Domain.Shared.Caches;
|
||||
using Yi.Framework.Bbs.Domain.Shared.Enums;
|
||||
@@ -15,7 +16,7 @@ namespace Yi.Framework.Bbs.Application.Jobs;
|
||||
public class AccessLogStoreJob : QuartzBackgroundWorkerBase
|
||||
{
|
||||
private readonly ISqlSugarRepository<AccessLogAggregateRoot> _repository;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 缓存前缀
|
||||
/// </summary>
|
||||
@@ -46,10 +47,13 @@ public class AccessLogStoreJob : QuartzBackgroundWorkerBase
|
||||
_repository = repository;
|
||||
JobDetail = JobBuilder.Create<AccessLogStoreJob>().WithIdentity(nameof(AccessLogStoreJob))
|
||||
.Build();
|
||||
|
||||
//每分钟执行一次
|
||||
Trigger = TriggerBuilder.Create().WithIdentity(nameof(AccessLogStoreJob))
|
||||
.WithCronSchedule("* * * * *")
|
||||
.WithCronSchedule("0 * * * * ?")
|
||||
.Build();
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override async Task Execute(IJobExecutionContext context)
|
||||
@@ -64,9 +68,20 @@ public class AccessLogStoreJob : QuartzBackgroundWorkerBase
|
||||
var entity = await _repository._DbQueryable.Where(x => x.AccessLogType == AccessLogTypeEnum.Request)
|
||||
.Where(x => x.CreationTime.Date == DateTime.Today)
|
||||
.FirstAsync();
|
||||
// _repository._Db.Storageable(list2).ExecuteCommandAsync();
|
||||
|
||||
|
||||
if (entity is not null)
|
||||
{
|
||||
entity.Number = number+1;
|
||||
await _repository.UpdateAsync(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
await _repository.InsertAsync((new AccessLogAggregateRoot() { Number = number,AccessLogType = AccessLogTypeEnum.Request}));
|
||||
}
|
||||
|
||||
//删除前一天的缓存
|
||||
await RedisClient.DelAsync($"{CacheKeyPrefix}:{AccessLogCacheConst.Key}:{DateTime.Now.Date.AddDays(-1)}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user