feat: 完善实体追踪审计日志
This commit is contained in:
@@ -160,7 +160,19 @@ namespace Yi.Framework.SqlSugarCore
|
|||||||
case DataFilterType.UpdateByObject:
|
case DataFilterType.UpdateByObject:
|
||||||
if (entityInfo.PropertyName == nameof(IEntity<object>.Id))
|
if (entityInfo.PropertyName == nameof(IEntity<object>.Id))
|
||||||
{
|
{
|
||||||
EntityChangeEventHelper.PublishEntityUpdatedEvent(entityInfo.EntityValue);
|
//软删除,发布的是删除事件
|
||||||
|
if (entityInfo.EntityValue is ISoftDelete softDelete)
|
||||||
|
{
|
||||||
|
if (softDelete.IsDeleted == true)
|
||||||
|
{
|
||||||
|
EntityChangeEventHelper.PublishEntityDeletedEvent(entityInfo.EntityValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
EntityChangeEventHelper.PublishEntityUpdatedEvent(entityInfo.EntityValue);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DataFilterType.DeleteByObject:
|
case DataFilterType.DeleteByObject:
|
||||||
|
|||||||
@@ -49,6 +49,22 @@ namespace Yi.Framework.Bbs.Domain.Entities
|
|||||||
/// 经验
|
/// 经验
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public long Experience { get; set; } = 0;
|
public long Experience { get; set; } = 0;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 发表主题数
|
||||||
|
/// </summary>
|
||||||
|
public int DiscussNumber { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 发表主题数
|
||||||
|
/// </summary>
|
||||||
|
public int CommentNumber { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 被点赞数
|
||||||
|
/// </summary>
|
||||||
|
public int AgreeNumber { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
using Volo.Abp.DependencyInjection;
|
||||||
|
using Volo.Abp.Domain.Entities.Events;
|
||||||
|
using Volo.Abp.EventBus;
|
||||||
|
using Yi.Framework.Bbs.Domain.Entities;
|
||||||
|
using Yi.Framework.Bbs.Domain.Entities.Forum;
|
||||||
|
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||||
|
|
||||||
|
namespace Yi.Framework.Bbs.Domain.EventHandlers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 被点赞
|
||||||
|
/// </summary>
|
||||||
|
public class AgreeCreatedEventHandler : ILocalEventHandler<EntityCreatedEventData<AgreeEntity>>,
|
||||||
|
ITransientDependency
|
||||||
|
{
|
||||||
|
private ISqlSugarRepository<BbsUserExtraInfoEntity> _userRepository;
|
||||||
|
private ISqlSugarRepository<AgreeEntity> _agreeRepository;
|
||||||
|
public AgreeCreatedEventHandler(ISqlSugarRepository<BbsUserExtraInfoEntity> userRepository, ISqlSugarRepository<AgreeEntity> agreeRepository)
|
||||||
|
{
|
||||||
|
_userRepository = userRepository;
|
||||||
|
_agreeRepository = agreeRepository;
|
||||||
|
}
|
||||||
|
public async Task HandleEventAsync(EntityCreatedEventData<AgreeEntity> eventData)
|
||||||
|
{
|
||||||
|
var agreeEntity = eventData.Entity;
|
||||||
|
var userId = await _agreeRepository._DbQueryable.LeftJoin<DiscussEntity>((agree, discuss) => agree.DiscussId == discuss.Id)
|
||||||
|
.Select((agree, discuss) => discuss.CreatorId).FirstAsync();
|
||||||
|
|
||||||
|
//给创建者发布数量+1
|
||||||
|
await _userRepository._Db.Updateable<BbsUserExtraInfoEntity>()
|
||||||
|
.SetColumns(it => it.DiscussNumber == it.DiscussNumber + 1)
|
||||||
|
.Where(it => it.Id == userId)
|
||||||
|
.ExecuteCommandAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 取消点赞
|
||||||
|
/// </summary>
|
||||||
|
public class AgreeDeletedEventHandler : ILocalEventHandler<EntityCreatedEventData<AgreeEntity>>,
|
||||||
|
ITransientDependency
|
||||||
|
{
|
||||||
|
private ISqlSugarRepository<BbsUserExtraInfoEntity> _userRepository;
|
||||||
|
private ISqlSugarRepository<AgreeEntity> _agreeRepository;
|
||||||
|
public AgreeDeletedEventHandler(ISqlSugarRepository<BbsUserExtraInfoEntity> userRepository, ISqlSugarRepository<AgreeEntity> agreeRepository)
|
||||||
|
{
|
||||||
|
_userRepository = userRepository;
|
||||||
|
_agreeRepository = agreeRepository;
|
||||||
|
}
|
||||||
|
public async Task HandleEventAsync(EntityCreatedEventData<AgreeEntity> eventData)
|
||||||
|
{
|
||||||
|
var agreeEntity = eventData.Entity;
|
||||||
|
var userId = await _agreeRepository._DbQueryable.LeftJoin<DiscussEntity>((agree, discuss) => agree.DiscussId == discuss.Id)
|
||||||
|
.Select((agree, discuss) => discuss.CreatorId).FirstAsync();
|
||||||
|
|
||||||
|
//给创建者发布数量-1
|
||||||
|
await _userRepository._Db.Updateable<BbsUserExtraInfoEntity>()
|
||||||
|
.SetColumns(it => it.DiscussNumber == it.DiscussNumber - 1)
|
||||||
|
.Where(it => it.Id == userId)
|
||||||
|
.ExecuteCommandAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
using Volo.Abp.DependencyInjection;
|
||||||
|
using Volo.Abp.Domain.Entities.Events;
|
||||||
|
using Volo.Abp.EventBus;
|
||||||
|
using Yi.Framework.Bbs.Domain.Entities;
|
||||||
|
using Yi.Framework.Bbs.Domain.Entities.Forum;
|
||||||
|
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||||
|
|
||||||
|
namespace Yi.Framework.Bbs.Domain.EventHandlers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 评论创建的领域事件
|
||||||
|
/// </summary>
|
||||||
|
public class CommentCreatedEventHandler : ILocalEventHandler<EntityCreatedEventData<CommentEntity>>,
|
||||||
|
ITransientDependency
|
||||||
|
{
|
||||||
|
private ISqlSugarRepository<BbsUserExtraInfoEntity> _userRepository;
|
||||||
|
public CommentCreatedEventHandler(ISqlSugarRepository<BbsUserExtraInfoEntity> userRepository)
|
||||||
|
{
|
||||||
|
_userRepository = userRepository;
|
||||||
|
}
|
||||||
|
public async Task HandleEventAsync(EntityCreatedEventData<CommentEntity> eventData)
|
||||||
|
{
|
||||||
|
var commentEntity = eventData.Entity;
|
||||||
|
|
||||||
|
//给创建者发布数量+1
|
||||||
|
await _userRepository._Db.Updateable<BbsUserExtraInfoEntity>()
|
||||||
|
.SetColumns(it => it.CommentNumber == it.CommentNumber + 1)
|
||||||
|
.Where(it => it.Id == commentEntity.CreatorId)
|
||||||
|
.ExecuteCommandAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
using Volo.Abp.DependencyInjection;
|
||||||
|
using Volo.Abp.Domain.Entities.Events;
|
||||||
|
using Volo.Abp.EventBus;
|
||||||
|
using Yi.Framework.Bbs.Domain.Entities;
|
||||||
|
using Yi.Framework.Bbs.Domain.Entities.Forum;
|
||||||
|
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||||
|
|
||||||
|
namespace Yi.Framework.Bbs.Domain.EventHandlers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 主题创建的领域事件
|
||||||
|
/// </summary>
|
||||||
|
public class DiscussCreatedEventHandler : ILocalEventHandler<EntityCreatedEventData<DiscussEntity>>,
|
||||||
|
ITransientDependency
|
||||||
|
{
|
||||||
|
private ISqlSugarRepository<BbsUserExtraInfoEntity> _userRepository;
|
||||||
|
public DiscussCreatedEventHandler(ISqlSugarRepository<BbsUserExtraInfoEntity> userRepository)
|
||||||
|
{
|
||||||
|
_userRepository = userRepository;
|
||||||
|
}
|
||||||
|
public async Task HandleEventAsync(EntityCreatedEventData<DiscussEntity> eventData)
|
||||||
|
{
|
||||||
|
var disucussEntity = eventData.Entity;
|
||||||
|
|
||||||
|
//给创建者发布数量+1
|
||||||
|
await _userRepository._Db.Updateable<BbsUserExtraInfoEntity>()
|
||||||
|
.SetColumns(it => it.DiscussNumber == it.DiscussNumber + 1)
|
||||||
|
.Where(it => it.Id == disucussEntity.CreatorId)
|
||||||
|
.ExecuteCommandAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,7 +4,7 @@ using Yi.Framework.Bbs.Domain.Entities;
|
|||||||
using Yi.Framework.Bbs.Domain.Shared.Etos;
|
using Yi.Framework.Bbs.Domain.Shared.Etos;
|
||||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||||
|
|
||||||
namespace Yi.Framework.Bbs.Application.EventHandlers
|
namespace Yi.Framework.Bbs.Domain.EventHandlers
|
||||||
{
|
{
|
||||||
public class MoneyChangeEventHandler : ILocalEventHandler<MoneyChangeEventArgs>, ITransientDependency
|
public class MoneyChangeEventHandler : ILocalEventHandler<MoneyChangeEventArgs>, ITransientDependency
|
||||||
{
|
{
|
||||||
@@ -9,7 +9,7 @@ using Volo.Abp.EventBus;
|
|||||||
using Yi.Framework.Bbs.Domain.Entities.Forum;
|
using Yi.Framework.Bbs.Domain.Entities.Forum;
|
||||||
using Yi.Framework.Bbs.Domain.Shared.Etos;
|
using Yi.Framework.Bbs.Domain.Shared.Etos;
|
||||||
|
|
||||||
namespace Yi.Framework.Bbs.Application.EventHandlers
|
namespace Yi.Framework.Bbs.Domain.EventHandlers
|
||||||
{
|
{
|
||||||
public class SeeDiscussEventHandler : ILocalEventHandler<SeeDiscussEventArgs>, ITransientDependency
|
public class SeeDiscussEventHandler : ILocalEventHandler<SeeDiscussEventArgs>, ITransientDependency
|
||||||
{
|
{
|
||||||
@@ -5,7 +5,7 @@ using Yi.Framework.Bbs.Domain.Entities;
|
|||||||
using Yi.Framework.Bbs.Domain.Shared.Enums;
|
using Yi.Framework.Bbs.Domain.Shared.Enums;
|
||||||
using Yi.Framework.Rbac.Domain.Shared.Etos;
|
using Yi.Framework.Rbac.Domain.Shared.Etos;
|
||||||
|
|
||||||
namespace Yi.Framework.Bbs.Application.EventHandlers
|
namespace Yi.Framework.Bbs.Domain.EventHandlers
|
||||||
{
|
{
|
||||||
public class UserCreateEventHandler : ILocalEventHandler<UserCreateEventArgs>, ITransientDependency
|
public class UserCreateEventHandler : ILocalEventHandler<UserCreateEventArgs>, ITransientDependency
|
||||||
{
|
{
|
||||||
@@ -31,7 +31,10 @@ namespace Yi.Framework.Bbs.Domain.Managers
|
|||||||
Level=info.Level,
|
Level=info.Level,
|
||||||
UserLimit=info.UserLimit,
|
UserLimit=info.UserLimit,
|
||||||
Money = info.Money,
|
Money = info.Money,
|
||||||
Experience = info.Experience
|
Experience = info.Experience,
|
||||||
|
AgreeNumber=info.AgreeNumber,
|
||||||
|
CommentNumber=info.CommentNumber,
|
||||||
|
DiscussNumber=info.DiscussNumber
|
||||||
}, true)
|
}, true)
|
||||||
.FirstAsync(user => user.Id==userId);
|
.FirstAsync(user => user.Id==userId);
|
||||||
}
|
}
|
||||||
@@ -43,7 +46,10 @@ namespace Yi.Framework.Bbs.Domain.Managers
|
|||||||
.LeftJoin<BbsUserExtraInfoEntity>((user, info) => user.Id == info.UserId)
|
.LeftJoin<BbsUserExtraInfoEntity>((user, info) => user.Id == info.UserId)
|
||||||
.Select((user, info) => new BbsUserInfoDto { Id = user.Id , Icon = user.Icon , Level = info.Level, UserLimit = info.UserLimit,
|
.Select((user, info) => new BbsUserInfoDto { Id = user.Id , Icon = user.Icon , Level = info.Level, UserLimit = info.UserLimit,
|
||||||
Money = info.Money,
|
Money = info.Money,
|
||||||
Experience = info.Experience
|
Experience = info.Experience,
|
||||||
|
AgreeNumber = info.AgreeNumber,
|
||||||
|
CommentNumber = info.CommentNumber,
|
||||||
|
DiscussNumber = info.DiscussNumber
|
||||||
},true)
|
},true)
|
||||||
|
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
@@ -90,5 +96,18 @@ namespace Yi.Framework.Bbs.Domain.Managers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public long Experience { get; set; }
|
public long Experience { get; set; }
|
||||||
|
|
||||||
|
public int DiscussNumber { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 发表主题数
|
||||||
|
/// </summary>
|
||||||
|
public int CommentNumber { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 被点赞数
|
||||||
|
/// </summary>
|
||||||
|
public int AgreeNumber { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ using Volo.Abp.EventBus;
|
|||||||
using Yi.Framework.Rbac.Domain.Entities;
|
using Yi.Framework.Rbac.Domain.Entities;
|
||||||
using Yi.Framework.Rbac.Domain.Shared.Etos;
|
using Yi.Framework.Rbac.Domain.Shared.Etos;
|
||||||
|
|
||||||
namespace Yi.Framework.Rbac.Application.EventHandlers
|
namespace Yi.Framework.Rbac.Domain.EventHandlers
|
||||||
{
|
{
|
||||||
public class LoginEventHandler : ILocalEventHandler<LoginEventArgs>,
|
public class LoginEventHandler : ILocalEventHandler<LoginEventArgs>,
|
||||||
ITransientDependency
|
ITransientDependency
|
||||||
@@ -3,7 +3,7 @@ using Volo.Abp.Domain.Entities.Events;
|
|||||||
using Volo.Abp.EventBus;
|
using Volo.Abp.EventBus;
|
||||||
using Yi.Framework.Rbac.Domain.Entities;
|
using Yi.Framework.Rbac.Domain.Entities;
|
||||||
|
|
||||||
namespace Yi.Framework.Rbac.Application.EventHandlers
|
namespace Yi.Framework.Rbac.Domain.EventHandlers
|
||||||
{
|
{
|
||||||
public class StudentEventHandler : ILocalEventHandler<EntityCreatedEventData<StudentEntity>>, ITransientDependency
|
public class StudentEventHandler : ILocalEventHandler<EntityCreatedEventData<StudentEntity>>, ITransientDependency
|
||||||
{
|
{
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Jobs\" />
|
<Folder Include="Jobs\" />
|
||||||
<Folder Include="EventHandlers\" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Managers\" />
|
<Folder Include="Managers\" />
|
||||||
<Folder Include="Repositories\" />
|
<Folder Include="Repositories\" />
|
||||||
|
<Folder Include="EventHandlers\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -13,8 +13,5 @@
|
|||||||
<ProjectReference Include="..\Yi.Abp.Domain\Yi.Abp.Domain.csproj" />
|
<ProjectReference Include="..\Yi.Abp.Domain\Yi.Abp.Domain.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="EventHandlers\" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Folder Include="EventHandlers\" />
|
||||||
<Folder Include="Entities\" />
|
<Folder Include="Entities\" />
|
||||||
<Folder Include="Managers\" />
|
<Folder Include="Managers\" />
|
||||||
<Folder Include="Repositories\" />
|
<Folder Include="Repositories\" />
|
||||||
|
|||||||
Reference in New Issue
Block a user