From 9af98089f29b061d22233f080db0fcd1aaf51108 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A9=99=E5=AD=90?= <454313500@qq.com> Date: Wed, 14 Aug 2024 22:23:54 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E8=AE=BF=E9=97=AE=E7=BB=9F=E8=AE=A1=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Jobs/AccessLogStoreJob.cs | 21 ++- .../Services/Analyses/AccessLogService.cs | 12 +- Yi.Abp.Net8/src/Yi.Abp.Web/YiAbpWebModule.cs | 4 +- Yi.Bbs.Vue3/src/apis/accessApi.js | 6 +- Yi.Bbs.Vue3/src/components/InfoCard.vue | 14 +- Yi.Bbs.Vue3/src/views/home/Index.vue | 170 ++++++++++-------- 6 files changed, 135 insertions(+), 92 deletions(-) diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Jobs/AccessLogStoreJob.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Jobs/AccessLogStoreJob.cs index 53659519..8420e66b 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Jobs/AccessLogStoreJob.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Jobs/AccessLogStoreJob.cs @@ -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 _repository; - + /// /// 缓存前缀 /// @@ -46,10 +47,13 @@ public class AccessLogStoreJob : QuartzBackgroundWorkerBase _repository = repository; JobDetail = JobBuilder.Create().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)}"); } } } \ No newline at end of file diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/Analyses/AccessLogService.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/Analyses/AccessLogService.cs index 53dd4a07..1c90ae40 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/Analyses/AccessLogService.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/Analyses/AccessLogService.cs @@ -55,9 +55,9 @@ namespace Yi.Framework.Bbs.Application.Services /// /// /// - public async Task> GetListAsync([FromQuery] AccessLogTypeEnum AccessLogType) + public async Task> GetListAsync([FromQuery] AccessLogTypeEnum accessLogType) { - var entities = await _repository._DbQueryable.Where(x => x.AccessLogType == AccessLogType) + var entities = await _repository._DbQueryable.Where(x => x.AccessLogType == accessLogType) .Where(x => x.CreationTime >= DateTime.Now.AddMonths(-3)) .OrderBy(x => x.CreationTime).ToListAsync(); var output = entities.Adapt>(); @@ -73,11 +73,11 @@ namespace Yi.Framework.Bbs.Application.Services public async Task AccessAsync() { //可判断http重复,防止同一ip多次访问 - var last = await _repository._DbQueryable.OrderByDescending(x => x.CreationTime).FirstAsync(); + var last = await _repository._DbQueryable.Where(x=>x.AccessLogType==AccessLogTypeEnum.HomeClick).OrderByDescending(x => x.CreationTime).FirstAsync(); if (last is null || last.CreationTime.Date != DateTime.Today) { - await _repository.InsertAsync(new AccessLogAggregateRoot()); + await _repository.InsertAsync(new AccessLogAggregateRoot(){AccessLogType=AccessLogTypeEnum.HomeClick}); } else { @@ -90,10 +90,10 @@ namespace Yi.Framework.Bbs.Application.Services /// 获取当前周首页点击数据 /// /// - public async Task GetWeekAsync() + public async Task GetWeekAsync([FromQuery] AccessLogTypeEnum accessLogType) { var lastSeven = await _repository._DbQueryable - .Where(x => x.AccessLogType == AccessLogTypeEnum.HomeClick) + .Where(x => x.AccessLogType == accessLogType) .OrderByDescending(x => x.CreationTime).ToPageListAsync(1, 7); return WeekTimeHandler(lastSeven.ToArray()); diff --git a/Yi.Abp.Net8/src/Yi.Abp.Web/YiAbpWebModule.cs b/Yi.Abp.Net8/src/Yi.Abp.Web/YiAbpWebModule.cs index 71b21ed9..49fda747 100644 --- a/Yi.Abp.Net8/src/Yi.Abp.Web/YiAbpWebModule.cs +++ b/Yi.Abp.Net8/src/Yi.Abp.Web/YiAbpWebModule.cs @@ -288,8 +288,8 @@ namespace Yi.Abp.Web //swagger app.UseYiSwagger(); - //流量访问统计,不启用 - //app.UseAccessLog(); + //流量访问统计,需redis支持,否则不生效 + app.UseAccessLog(); //请求处理 app.UseYiApiHandlinge(); diff --git a/Yi.Bbs.Vue3/src/apis/accessApi.js b/Yi.Bbs.Vue3/src/apis/accessApi.js index cbbcf2cc..784048c8 100644 --- a/Yi.Bbs.Vue3/src/apis/accessApi.js +++ b/Yi.Bbs.Vue3/src/apis/accessApi.js @@ -9,16 +9,18 @@ export function access() { } // 获取本周数据 -export function getWeek() { +export function getWeek(data) { return request({ url: "/access-log/week", method: "get", + params :data }); } // 获取全部数据 -export function getAccessList() { +export function getAccessList(data) { return request({ url: "/access-log", method: "get", + params :data }); } diff --git a/Yi.Bbs.Vue3/src/components/InfoCard.vue b/Yi.Bbs.Vue3/src/components/InfoCard.vue index 2820ecb0..bd4be6ce 100644 --- a/Yi.Bbs.Vue3/src/components/InfoCard.vue +++ b/Yi.Bbs.Vue3/src/components/InfoCard.vue @@ -37,7 +37,14 @@ const onClickText=()=>{ .el-divider { margin: 0.2rem 0; } - +.VisitsLineChart /deep/ .el-card__body{ + padding: 0 20px; +} + .box-card-info { + width: 100%; + height: v-bind(height); + padding-bottom: 10px; +} .card-header { display: flex; justify-content: space-between; @@ -52,9 +59,4 @@ const onClickText=()=>{ margin: 1rem 0; } -.box-card { - width: 100%; - height: v-bind(height); - padding-bottom: 10px; -} diff --git a/Yi.Bbs.Vue3/src/views/home/Index.vue b/Yi.Bbs.Vue3/src/views/home/Index.vue index a88d9233..1c276fe2 100644 --- a/Yi.Bbs.Vue3/src/views/home/Index.vue +++ b/Yi.Bbs.Vue3/src/views/home/Index.vue @@ -3,10 +3,11 @@
-

点击前往-最新上线《聊天室》 ,现已支持Ai助手,希望能帮助大家

+

点击前往-最新上线《聊天室》 ,现已支持Ai助手,希望能帮助大家 +

- +
@@ -14,23 +15,23 @@ 'padding-left': i % 3 == 1 ? 0 : 0.2 + 'rem', 'padding-right': i % 3 == 0 ? 0 : 0.2 + 'rem', }"> - +
@@ -42,7 +43,7 @@ - + @@ -97,23 +98,26 @@ - - + + - - + + - @@ -129,16 +133,17 @@ @@ -148,14 +153,14 @@ @@ -164,21 +169,21 @@ - + @@ -187,8 +192,8 @@