Merge branch 'refs/heads/abp' into digital-collectibles
This commit is contained in:
@@ -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;
|
||||
/// 需考虑一致性问题,又不能上锁影响性能
|
||||
/// </summary>
|
||||
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<AccessLogResetArgs>,
|
||||
ITransientDependency
|
||||
{
|
||||
/// <summary>
|
||||
/// 缓存前缀
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<AccessLogCacheJob>().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());
|
||||
}
|
||||
}
|
||||
@@ -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")}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Yi.Framework.Bbs.Domain.Shared.Etos;
|
||||
|
||||
public class AccessLogResetArgs
|
||||
{
|
||||
|
||||
}
|
||||
@@ -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<MenuEntity>? Children { get; set; }
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@ namespace Yi.Framework.Rbac.Application.Contracts.Dtos.Menu
|
||||
|
||||
public int OrderNum { get; set; }
|
||||
|
||||
public string? RouterName { get; set; }
|
||||
|
||||
//public List<MenuEntity>? Children { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,12 +20,12 @@ namespace Yi.Framework.Rbac.Application.Services.RecordLog
|
||||
public override async Task<PagedResultDto<LoginLogGetListOutputDto>> GetListAsync(LoginLogGetListInputVo input)
|
||||
{
|
||||
RefAsync<int> 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<LoginLogGetListOutputDto>(total, await MapToGetListOutputDtosAsync(entities));
|
||||
}
|
||||
|
||||
@@ -24,12 +24,12 @@ namespace Yi.Framework.Rbac.Application.Services.RecordLog
|
||||
public override async Task<PagedResultDto<OperationLogGetListOutputDto>> GetListAsync(OperationLogGetListInputVo input)
|
||||
{
|
||||
RefAsync<int> 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<OperationLogGetListOutputDto>(total, await MapToGetListOutputDtosAsync(entities));
|
||||
}
|
||||
|
||||
@@ -63,12 +63,12 @@ namespace Yi.Framework.Rbac.Domain.Entities
|
||||
/// <summary>
|
||||
/// 部门名称
|
||||
///</summary>
|
||||
public string DeptName { get; set; } = string.Empty;
|
||||
public string DeptName { get; set; }
|
||||
/// <summary>
|
||||
/// 部门编码
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName = "DeptCode")]
|
||||
public string DeptCode { get; set; } = string.Empty;
|
||||
public string DeptCode { get; set; }
|
||||
/// <summary>
|
||||
/// 负责人
|
||||
///</summary>
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user