From bcbb2b5139397d8b616a7adc86a2e39a53413e6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=87=A4=E5=87=B0?= <1+1> Date: Tue, 15 Oct 2024 00:25:43 +0800 Subject: [PATCH 1/4] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E5=90=8D=E9=A9=BC=E5=B3=B0=E8=BD=AC=E4=B8=8B=E5=88=92=E7=BA=BF?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E6=9F=A5=E8=AF=A2=E6=97=A5=E5=BF=97=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E5=A4=B1=E8=B4=A5=E7=9A=84=E5=85=BC=E5=AE=B9=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/RecordLog/LoginLogService.cs | 6 +++--- .../Services/RecordLog/OperationLogService.cs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/RecordLog/LoginLogService.cs b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/RecordLog/LoginLogService.cs index 8a30b299..f83766e2 100644 --- a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/RecordLog/LoginLogService.cs +++ b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/RecordLog/LoginLogService.cs @@ -20,12 +20,12 @@ namespace Yi.Framework.Rbac.Application.Services.RecordLog public override async Task> GetListAsync(LoginLogGetListInputVo input) { RefAsync total = 0; - if (input.Sorting.IsNullOrWhiteSpace()) - input.Sorting = $"{nameof(LoginLogAggregateRoot.CreationTime)} Desc"; + //if (input.Sorting.IsNullOrWhiteSpace()) + // input.Sorting = $"{nameof(LoginLogAggregateRoot.CreationTime)} Desc"; var entities = await _repository._DbQueryable.WhereIF(!string.IsNullOrEmpty(input.LoginIp), x => x.LoginIp.Contains(input.LoginIp!)) .WhereIF(!string.IsNullOrEmpty(input.LoginUser), x => x.LoginUser!.Contains(input.LoginUser!)) .WhereIF(input.StartTime is not null && input.EndTime is not null, x => x.CreationTime >= input.StartTime && x.CreationTime <= input.EndTime) - .OrderBy(input.Sorting) + .OrderByDescending(it => it.CreationTime) //降序 .ToPageListAsync(input.SkipCount, input.MaxResultCount, total); return new PagedResultDto(total, await MapToGetListOutputDtosAsync(entities)); } diff --git a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/RecordLog/OperationLogService.cs b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/RecordLog/OperationLogService.cs index 4e70b58a..5f0ec9e9 100644 --- a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/RecordLog/OperationLogService.cs +++ b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/RecordLog/OperationLogService.cs @@ -24,12 +24,12 @@ namespace Yi.Framework.Rbac.Application.Services.RecordLog public override async Task> GetListAsync(OperationLogGetListInputVo input) { RefAsync total = 0; - if (input.Sorting.IsNullOrWhiteSpace()) - input.Sorting = $"{nameof(OperationLogEntity.CreationTime)} Desc"; + //if (input.Sorting.IsNullOrWhiteSpace()) + // input.Sorting = $"{nameof(OperationLogEntity.CreationTime)} Desc"; var entities = await _repository._DbQueryable.WhereIF(!string.IsNullOrEmpty(input.OperUser), x => x.OperUser.Contains(input.OperUser!)) .WhereIF(input.OperType is not null, x => x.OperType == input.OperType) .WhereIF(input.StartTime is not null && input.EndTime is not null, x => x.CreationTime >= input.StartTime && x.CreationTime <= input.EndTime) - .OrderBy(input.Sorting) + .OrderByDescending(it => it.CreationTime) //降序 .ToPageListAsync(input.SkipCount, input.MaxResultCount, total); return new PagedResultDto(total, await MapToGetListOutputDtosAsync(entities)); } From 7b20b68b6a00925ee7d79f738a0aa0e6da5d3354 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BF=97=E7=A6=8F?= Date: Tue, 15 Oct 2024 18:31:14 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=8F=9C=E5=8D=95?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E9=87=8C=E9=9D=A2=EF=BC=8C=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E5=90=8E=E6=88=96=E8=80=85=E6=96=B0=E5=A2=9E=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0routerName=EF=BC=8C=E4=BC=9A=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E4=B8=BB=E8=8F=9C=E5=8D=95=E5=AF=BC=E8=88=AA=E6=97=B6?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Dtos/Menu/MenuGetListOutputDto.cs | 2 +- .../Dtos/Menu/MenuGetOutputDto.cs | 2 ++ Yi.Pure.Vue3/src/views/system/menu/form.vue | 19 +++++++++++++++++-- .../src/views/system/menu/utils/hook.tsx | 2 +- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application.Contracts/Dtos/Menu/MenuGetListOutputDto.cs b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application.Contracts/Dtos/Menu/MenuGetListOutputDto.cs index a97c34af..261d7e00 100644 --- a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application.Contracts/Dtos/Menu/MenuGetListOutputDto.cs +++ b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application.Contracts/Dtos/Menu/MenuGetListOutputDto.cs @@ -20,7 +20,7 @@ namespace Yi.Framework.Rbac.Application.Contracts.Dtos.Menu public string? Remark { get; set; } public string? Component { get; set; } public string? Query { get; set; } - + public string? RouterName { get; set; } public int OrderNum { get; set; } //public List? Children { get; set; } } diff --git a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application.Contracts/Dtos/Menu/MenuGetOutputDto.cs b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application.Contracts/Dtos/Menu/MenuGetOutputDto.cs index 764bdeda..9fba4947 100644 --- a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application.Contracts/Dtos/Menu/MenuGetOutputDto.cs +++ b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application.Contracts/Dtos/Menu/MenuGetOutputDto.cs @@ -24,6 +24,8 @@ namespace Yi.Framework.Rbac.Application.Contracts.Dtos.Menu public int OrderNum { get; set; } + public string? RouterName { get; set; } + //public List? Children { get; set; } } } diff --git a/Yi.Pure.Vue3/src/views/system/menu/form.vue b/Yi.Pure.Vue3/src/views/system/menu/form.vue index c00a71e1..cad2f4f3 100644 --- a/Yi.Pure.Vue3/src/views/system/menu/form.vue +++ b/Yi.Pure.Vue3/src/views/system/menu/form.vue @@ -91,13 +91,28 @@ defineExpose({ getRef }); + + + + + (isShow ? "否" : "是"), + formatter: ({ isShow }) => (isShow ? "是" : "否"), width: 100 }, { From ae2cc7ad9b0f8024cd12ae7ffa628fdd9e7d3a1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A9=99=E5=AD=90?= <454313500@qq.com> Date: Tue, 15 Oct 2024 23:07:12 +0800 Subject: [PATCH 3/4] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E8=AE=BF?= =?UTF-8?q?=E9=97=AE=E6=95=B0=E9=87=8F=E7=BB=9F=E8=AE=A1=EF=BC=8C=E9=87=87?= =?UTF-8?q?=E7=94=A8=E6=9C=AC=E5=9C=B0=E7=BC=93=E5=AD=98+=E5=88=86?= =?UTF-8?q?=E5=B8=83=E5=BC=8F=E7=BC=93=E5=AD=98+=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extensions/AccessLogMiddleware.cs | 48 +++++++++++++++++-- .../Jobs/AccessLogCacheJob.cs | 38 +++++++++++++++ .../Jobs/AccessLogStoreJob.cs | 2 +- .../Etos/AccessLogResetArgs.cs | 6 +++ 4 files changed, 89 insertions(+), 5 deletions(-) create mode 100644 Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Jobs/AccessLogCacheJob.cs create mode 100644 Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain.Shared/Etos/AccessLogResetArgs.cs diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Extensions/AccessLogMiddleware.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Extensions/AccessLogMiddleware.cs index 7aba4c48..255377ad 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Extensions/AccessLogMiddleware.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Extensions/AccessLogMiddleware.cs @@ -4,7 +4,9 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Options; using Volo.Abp.Caching; using Volo.Abp.DependencyInjection; +using Volo.Abp.EventBus; using Yi.Framework.Bbs.Domain.Shared.Caches; +using Yi.Framework.Bbs.Domain.Shared.Etos; namespace Yi.Framework.Bbs.Application.Extensions; @@ -14,6 +16,29 @@ namespace Yi.Framework.Bbs.Application.Extensions; /// 需考虑一致性问题,又不能上锁影响性能 /// public class AccessLogMiddleware : IMiddleware, ITransientDependency +{ + private static int _accessLogNumber = 0; + + internal static void ResetAccessLogNumber() + { + _accessLogNumber = 0; + } + internal static int GetAccessLogNumber() + { + return _accessLogNumber; + } + + + public async Task InvokeAsync(HttpContext context, RequestDelegate next) + { + await next(context); + + Interlocked.Increment(ref _accessLogNumber); + } +} + +public class AccessLogResetEventHandler : ILocalEventHandler, + ITransientDependency { /// /// 缓存前缀 @@ -39,13 +64,28 @@ public class AccessLogMiddleware : IMiddleware, ITransientDependency return redisEnabled.IsNullOrEmpty() || bool.Parse(redisEnabled); } } - - public async Task InvokeAsync(HttpContext context, RequestDelegate next) + + //该事件由job定时10秒触发 + public async Task HandleEventAsync(AccessLogResetArgs eventData) { - await next(context); if (EnableRedisCache) { - await RedisClient.IncrByAsync($"{CacheKeyPrefix}:{AccessLogCacheConst.Key}:{DateTime.Now.Date}", 1); + //分布式锁 + if (await RedisClient.SetNxAsync("AccessLogLock",true,TimeSpan.FromSeconds(5))) + { + //自增长数 + var incrNumber= AccessLogMiddleware.GetAccessLogNumber(); + //立即重置,开始计算,方式丢失 + AccessLogMiddleware.ResetAccessLogNumber(); + if (incrNumber>0) + { + await RedisClient.IncrByAsync( + $"{CacheKeyPrefix}:{AccessLogCacheConst.Key}:{DateTime.Now.Date.ToString("yyyyMMdd")}", incrNumber); + } + + + } + } } } \ No newline at end of file diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Jobs/AccessLogCacheJob.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Jobs/AccessLogCacheJob.cs new file mode 100644 index 00000000..8f936574 --- /dev/null +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Jobs/AccessLogCacheJob.cs @@ -0,0 +1,38 @@ +using FreeRedis; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Options; +using Quartz; +using Volo.Abp.BackgroundWorkers.Quartz; +using Volo.Abp.Caching; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Domain.Entities; +using Volo.Abp.EventBus.Local; +using Yi.Framework.Bbs.Domain.Entities; +using Yi.Framework.Bbs.Domain.Shared.Caches; +using Yi.Framework.Bbs.Domain.Shared.Enums; +using Yi.Framework.Bbs.Domain.Shared.Etos; +using Yi.Framework.SqlSugarCore.Abstractions; + +namespace Yi.Framework.Bbs.Application.Jobs; + +public class AccessLogCacheJob : QuartzBackgroundWorkerBase +{ + private readonly ILocalEventBus _localEventBus; + + public AccessLogCacheJob(ILocalEventBus localEventBus) + { + _localEventBus = localEventBus; + JobDetail = JobBuilder.Create().WithIdentity(nameof(AccessLogCacheJob)) + .Build(); + + //每10秒执行一次,将本地缓存转入redis,防止丢数据 + Trigger = TriggerBuilder.Create().WithIdentity(nameof(AccessLogCacheJob)) + .WithSimpleSchedule((schedule) => { schedule.WithInterval(TimeSpan.FromSeconds(10)).RepeatForever();; }) + .Build(); + } + + public override async Task Execute(IJobExecutionContext context) + { + await _localEventBus.PublishAsync(new AccessLogResetArgs()); + } +} \ No newline at end of file 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 8420e66b..5b408bb7 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 @@ -81,7 +81,7 @@ public class AccessLogStoreJob : QuartzBackgroundWorkerBase } //删除前一天的缓存 - await RedisClient.DelAsync($"{CacheKeyPrefix}:{AccessLogCacheConst.Key}:{DateTime.Now.Date.AddDays(-1)}"); + await RedisClient.DelAsync($"{CacheKeyPrefix}:{AccessLogCacheConst.Key}:{DateTime.Now.Date.AddDays(-1).ToString("yyyyMMdd")}"); } } } \ No newline at end of file diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain.Shared/Etos/AccessLogResetArgs.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain.Shared/Etos/AccessLogResetArgs.cs new file mode 100644 index 00000000..8e46aa1b --- /dev/null +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain.Shared/Etos/AccessLogResetArgs.cs @@ -0,0 +1,6 @@ +namespace Yi.Framework.Bbs.Domain.Shared.Etos; + +public class AccessLogResetArgs +{ + +} \ No newline at end of file From 22ba44c2711049d24447204be77fb619d3b018f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A9=99=E5=AD=90?= <454313500@qq.com> Date: Tue, 15 Oct 2024 23:26:18 +0800 Subject: [PATCH 4/4] =?UTF-8?q?feat:=20=E5=AE=8C=E5=96=84=E9=83=A8?= =?UTF-8?q?=E9=97=A8=E7=BC=96=E5=8F=B7=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entities/DeptAggregateRoot.cs | 4 ++-- .../DataSeeds/DeptDataSeed.cs | 18 +++++++++--------- Yi.RuoYi.Vue3/src/views/system/dept/index.vue | 16 ++++++++++++++++ 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/Entities/DeptAggregateRoot.cs b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/Entities/DeptAggregateRoot.cs index ad855069..17fc6ac6 100644 --- a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/Entities/DeptAggregateRoot.cs +++ b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/Entities/DeptAggregateRoot.cs @@ -63,12 +63,12 @@ namespace Yi.Framework.Rbac.Domain.Entities /// /// 部门名称 /// - public string DeptName { get; set; } = string.Empty; + public string DeptName { get; set; } /// /// 部门编码 /// [SugarColumn(ColumnName = "DeptCode")] - public string DeptCode { get; set; } = string.Empty; + public string DeptCode { get; set; } /// /// 负责人 /// diff --git a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.SqlSugarCore/DataSeeds/DeptDataSeed.cs b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.SqlSugarCore/DataSeeds/DeptDataSeed.cs index d3e3ae49..377a409a 100644 --- a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.SqlSugarCore/DataSeeds/DeptDataSeed.cs +++ b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.SqlSugarCore/DataSeeds/DeptDataSeed.cs @@ -41,7 +41,7 @@ namespace Yi.Framework.Rbac.SqlSugarCore.DataSeeds DeptAggregateRoot shenzhenDept = new DeptAggregateRoot(_guidGenerator.Create()) { - + DeptCode = "SZ", DeptName = "深圳总公司", OrderNum = 100, IsDeleted = false, @@ -52,7 +52,7 @@ namespace Yi.Framework.Rbac.SqlSugarCore.DataSeeds DeptAggregateRoot jiangxiDept = new DeptAggregateRoot(_guidGenerator.Create()) { - + DeptCode = "JX", DeptName = "江西总公司", OrderNum = 100, IsDeleted = false, @@ -64,7 +64,7 @@ namespace Yi.Framework.Rbac.SqlSugarCore.DataSeeds DeptAggregateRoot szDept1 = new DeptAggregateRoot(_guidGenerator.Create()) { - + DeptCode = "YF", DeptName = "研发部门", OrderNum = 100, IsDeleted = false, @@ -74,7 +74,7 @@ namespace Yi.Framework.Rbac.SqlSugarCore.DataSeeds DeptAggregateRoot szDept2 = new DeptAggregateRoot(_guidGenerator.Create()) { - + DeptCode = "SC", DeptName = "市场部门", OrderNum = 100, IsDeleted = false, @@ -84,7 +84,7 @@ namespace Yi.Framework.Rbac.SqlSugarCore.DataSeeds DeptAggregateRoot szDept3 = new DeptAggregateRoot(_guidGenerator.Create()) { - + DeptCode = "CS", DeptName = "测试部门", OrderNum = 100, IsDeleted = false, @@ -94,7 +94,7 @@ namespace Yi.Framework.Rbac.SqlSugarCore.DataSeeds DeptAggregateRoot szDept4 = new DeptAggregateRoot(_guidGenerator.Create()) { - + DeptCode = "CW", DeptName = "财务部门", OrderNum = 100, IsDeleted = false, @@ -104,7 +104,7 @@ namespace Yi.Framework.Rbac.SqlSugarCore.DataSeeds DeptAggregateRoot szDept5 = new DeptAggregateRoot(_guidGenerator.Create()) { - + DeptCode = "YW", DeptName = "运维部门", OrderNum = 100, IsDeleted = false, @@ -115,7 +115,7 @@ namespace Yi.Framework.Rbac.SqlSugarCore.DataSeeds DeptAggregateRoot jxDept1 = new DeptAggregateRoot(_guidGenerator.Create()) { - + DeptCode = "SC", DeptName = "市场部门", OrderNum = 100, IsDeleted = false, @@ -126,7 +126,7 @@ namespace Yi.Framework.Rbac.SqlSugarCore.DataSeeds DeptAggregateRoot jxDept2 = new DeptAggregateRoot(_guidGenerator.Create()) { - + DeptCode = "CW2", DeptName = "财务部门", OrderNum = 100, IsDeleted = false, diff --git a/Yi.RuoYi.Vue3/src/views/system/dept/index.vue b/Yi.RuoYi.Vue3/src/views/system/dept/index.vue index 32b73c1e..3ab7c4df 100644 --- a/Yi.RuoYi.Vue3/src/views/system/dept/index.vue +++ b/Yi.RuoYi.Vue3/src/views/system/dept/index.vue @@ -9,6 +9,14 @@ @keyup.enter="handleQuery" /> + + + +