style: 修改聚合根类名

main
NoahLan 6 months ago
parent caa9d30940
commit 0dcff5bb82

@ -6,7 +6,7 @@ using Volo.Abp.Domain.Entities;
namespace NPin.Framework.Upms.Domain.Entities;
[SugarTable("SysAnnouncement", "系统公告表")]
public class AnnouncementEntity : Entity<Guid>, ISoftDelete, IAuditedObject, IOrderNum, IEnabled
public class AnnouncementAggregateRoot : AggregateRoot<Guid>, ISoftDelete, IAuditedObject, IOrderNum, IEnabled
{
[SugarColumn(IsPrimaryKey = true)] public override Guid Id { get; protected set; }

@ -8,7 +8,7 @@ namespace NPin.Framework.Upms.Domain.Entities;
[SugarTable("SysConfig", "系统配置表")]
[SugarIndex($"index_{nameof(Key)}", nameof(Key), OrderByType.Asc, true)]
public class ConfigEntity : Entity<Guid>, IEnabled, IOrderNum, ISoftDelete, IAuditedObject
public class ConfigAggregateRoot : AggregateRoot<Guid>, IEnabled, IOrderNum, ISoftDelete, IAuditedObject
{
[SugarColumn(IsPrimaryKey = true)] public override Guid Id { get; protected set; }

@ -12,7 +12,7 @@ namespace NPin.Framework.Upms.Domain.Entities;
[SugarTable("SysLoginLog", "登录日志表")]
[SugarIndex($"index_{nameof(LoginUser)}", nameof(LoginUser), OrderByType.Asc)]
public class LoginLogEntity : Entity<Guid>, ICreationAuditedObject
public class LoginLogAggregateRoot : AggregateRoot<Guid>, ICreationAuditedObject
{
[SugarColumn(IsPrimaryKey = true)] public override Guid Id { get; protected set; }
@ -43,7 +43,7 @@ public class LoginLogEntity : Entity<Guid>, ICreationAuditedObject
[SugarColumn(ColumnDescription = "登录信息")]
public string? LoginMsg { get; set; }
public static LoginLogEntity GetInfoByHttpContext(HttpContext httpContext)
public static LoginLogAggregateRoot GetInfoByHttpContext(HttpContext httpContext)
{
// var ipInfo = httpContext.GetRemoteIpInfo();
string ipv4AddrStr = null;
@ -68,7 +68,7 @@ public class LoginLogEntity : Entity<Guid>, ICreationAuditedObject
var clientInfo = GetClientInfo(httpContext);
return new LoginLogEntity
return new LoginLogAggregateRoot
{
Browser = clientInfo.Device.Family,
Os = clientInfo.OS.ToString(),

@ -6,7 +6,7 @@ using Volo.Abp.Domain.Entities;
namespace NPin.Framework.Upms.Domain.Entities;
[SugarTable("SysOrganization", "组织机构表")]
public class OrganizationEntity : Entity<Guid>, ISoftDelete, IAuditedObject, IOrderNum, IEnabled
public class OrganizationAggregateRoot : AggregateRoot<Guid>, ISoftDelete, IAuditedObject, IOrderNum, IEnabled
{
[SugarColumn(IsPrimaryKey = true, ColumnDescription = "主键")]
public override Guid Id { get; protected set; }

@ -6,7 +6,7 @@ using Volo.Abp.Domain.Entities;
namespace NPin.Framework.Upms.Domain.Entities;
[SugarTable("SysPost", "岗位表")]
public class PostEntity : Entity<Guid>, ISoftDelete, IAuditedObject, IOrderNum, IEnabled
public class PostAggregateRoot : AggregateRoot<Guid>, ISoftDelete, IAuditedObject, IOrderNum, IEnabled
{
[SugarColumn(IsPrimaryKey = true, ColumnDescription = "主键")]
public override Guid Id { get; protected set; }
@ -17,6 +17,9 @@ public class PostEntity : Entity<Guid>, ISoftDelete, IAuditedObject, IOrderNum,
[SugarColumn(ColumnDescription = "岗位名称")]
public string Name { get; set; } = string.Empty;
[SugarColumn(ColumnDescription = "岗位级别")]
public int Level { get; set; } = 0;
[SugarColumn(ColumnDescription = "岗位描述")]
public string? Remark { get; set; }

@ -7,7 +7,7 @@ using Volo.Abp.Domain.Entities;
namespace NPin.Framework.Upms.Domain.Entities;
[SugarTable("SysRole", "角色表")]
public class RoleEntity : Entity<Guid>, ISoftDelete, IAuditedObject, IOrderNum, IEnabled
public class RoleAggregateRoot : AggregateRoot<Guid>, ISoftDelete, IAuditedObject, IOrderNum, IEnabled
{
[SugarColumn(IsPrimaryKey = true, ColumnDescription = "主键")]
public override Guid Id { get; protected set; }
@ -36,7 +36,7 @@ public class RoleEntity : Entity<Guid>, ISoftDelete, IAuditedObject, IOrderNum,
[Navigate(typeof(RoleOrganizationEntity), nameof(RoleOrganizationEntity.RoleId),
nameof(RoleOrganizationEntity.OrgId))]
public List<OrganizationEntity> OrganizationList { get; set; }
public List<OrganizationAggregateRoot> OrganizationList { get; set; }
#endregion
}

@ -11,7 +11,7 @@ namespace NPin.Framework.Upms.Domain.Entities;
[SugarTable("SysUser", "用户表")]
[SugarIndex($"index_{nameof(Username)}", nameof(Username), OrderByType.Asc)]
public class UserEntity : Entity<Guid>, ISoftDelete, IAuditedObject, IEnabled, IOrderNum
public class UserAggregateRoot : AggregateRoot<Guid>, ISoftDelete, IAuditedObject, IEnabled, IOrderNum
{
#region User
@ -80,28 +80,28 @@ public class UserEntity : Entity<Guid>, ISoftDelete, IAuditedObject, IEnabled, I
/// 角色列表,多对多
/// </summary>
[Navigate(typeof(UserRoleEntity), nameof(UserRoleEntity.UserId), nameof(UserRoleEntity.RoleId))]
public List<RoleEntity> Roles { get; set; }
public List<RoleAggregateRoot> Roles { get; set; }
/// <summary>
/// 岗位列表,多对多
/// </summary>
[Navigate(typeof(UserPostEntity), nameof(UserPostEntity.UserId), nameof(UserPostEntity.PostId))]
public List<PostEntity> Posts { get; set; }
public List<PostAggregateRoot> Posts { get; set; }
/// <summary>
/// 所在的组织机构列表,多对多
/// </summary>
[Navigate(typeof(UserOrganizationEntity), nameof(UserOrganizationEntity.UserId),
nameof(UserOrganizationEntity.OrganizationId))]
public List<OrganizationEntity> Organizations { get; set; }
public List<OrganizationAggregateRoot> Organizations { get; set; }
#endregion
public UserEntity()
public UserAggregateRoot()
{
}
public UserEntity(string username, string phoneNumber, string password, string? nickname)
public UserAggregateRoot(string username, string phoneNumber, string password, string? nickname)
{
Username = username;
PhoneNumber = phoneNumber;
@ -120,7 +120,7 @@ public class UserEntity : Entity<Guid>, ISoftDelete, IAuditedObject, IEnabled, I
/// 通过随机盐值给密码加密使用BCrypt算法
/// </summary>
/// <exception cref="ArgumentNullException"></exception>
public UserEntity BuildPassword(string? password = null)
public UserAggregateRoot BuildPassword(string? password = null)
{
// 若传入密码无值则使用原本Password
// 若原本Password依然无值则抛出参数异常

@ -12,9 +12,9 @@ namespace NPin.Framework.Upms.Domain.EventHandlers;
public class LoginEventHandler : ILocalEventHandler<LoginEventArgs>, ITransientDependency
{
public ILogger<LoginEventHandler> Logger { get; set; }
private readonly IRepository<LoginLogEntity> _repository;
private readonly IRepository<LoginLogAggregateRoot> _repository;
public LoginEventHandler(IRepository<LoginLogEntity> repository)
public LoginEventHandler(IRepository<LoginLogAggregateRoot> repository)
{
Logger = NullLogger<LoginEventHandler>.Instance;
_repository = repository;
@ -23,7 +23,7 @@ public class LoginEventHandler : ILocalEventHandler<LoginEventArgs>, ITransientD
public async Task HandleEventAsync(LoginEventArgs eventData)
{
Logger.LogInformation($"用户[{eventData.UserId}:{eventData.Username}]登录");
var loginLogEntity = eventData.Adapt<LoginLogEntity>();
var loginLogEntity = eventData.Adapt<LoginLogAggregateRoot>();
loginLogEntity.LoginMsg = $"{eventData.Username}登录系统";
loginLogEntity.LoginUser = eventData.Username;
loginLogEntity.LoginUserId = eventData.UserId;

@ -93,7 +93,7 @@ public class AccountManager : DomainService, IAccountManager
if (_httpContextAccessor.HttpContext is not null)
{
// TODO eto 与 entity 保证
var loginLogEntity = LoginLogEntity.GetInfoByHttpContext(_httpContextAccessor.HttpContext);
var loginLogEntity = LoginLogAggregateRoot.GetInfoByHttpContext(_httpContextAccessor.HttpContext);
var loginEto = loginLogEntity.Adapt<LoginEventArgs>();
loginEto.Username = userInfo.User.Username;
loginEto.UserId = userInfo.User.Id;

@ -1,15 +1,15 @@
using NPin.Framework.SqlSugarCore.Abstractions;
using NPin.Framework.Upms.Domain.Entities;
using Volo.Abp.Domain.Services;
namespace NPin.Framework.Upms.Domain.Managers;
public class RoleManager: DomainService
{
private ISqlSugarRepository<RoleEntity> _repository;
public RoleManager(ISqlSugarRepository<RoleEntity> repository)
{
_repository = repository;
}
using NPin.Framework.SqlSugarCore.Abstractions;
using NPin.Framework.Upms.Domain.Entities;
using Volo.Abp.Domain.Services;
namespace NPin.Framework.Upms.Domain.Managers;
public class RoleManager: DomainService
{
private ISqlSugarRepository<RoleAggregateRoot> _repository;
public RoleManager(ISqlSugarRepository<RoleAggregateRoot> repository)
{
_repository = repository;
}
}

@ -29,7 +29,7 @@ public partial class UserManager : DomainService
private static partial Regex UsernameRegex();
private readonly IUserRepository _repository;
private readonly ISqlSugarRepository<RoleEntity> _repositoryRole;
private readonly ISqlSugarRepository<RoleAggregateRoot> _repositoryRole;
private readonly ISqlSugarRepository<UserRoleEntity> _repositoryUserRole;
private readonly ISqlSugarRepository<UserPostEntity> _repositoryUserPost;
@ -44,7 +44,7 @@ public partial class UserManager : DomainService
ISqlSugarRepository<UserPostEntity> repositoryUserPost,
ISqlSugarRepository<UserOrganizationEntity> repositoryUserOrg,
IDistributedCache<UserInfoCacheItem, UserInfoCacheKey> userCache,
ILocalEventBus localEventBus, ISqlSugarRepository<RoleEntity> repositoryRole)
ILocalEventBus localEventBus, ISqlSugarRepository<RoleAggregateRoot> repositoryRole)
{
_repository = repository;
_repositoryUserRole = repositoryUserRole;
@ -58,33 +58,33 @@ public partial class UserManager : DomainService
/// <summary>
/// 创建用户
/// </summary>
/// <param name="entity"></param>
public async Task CreateAsync(UserEntity entity)
/// <param name="aggregateRoot"></param>
public async Task CreateAsync(UserAggregateRoot aggregateRoot)
{
await ValidateUser(entity);
await ValidateUser(aggregateRoot);
var returnEntity = await _repository.InsertReturnEntityAsync(entity);
entity = returnEntity;
var returnEntity = await _repository.InsertReturnEntityAsync(aggregateRoot);
aggregateRoot = returnEntity;
// 触发事件
await _localEventBus.PublishAsync(new UserCreatedEventArgs(entity.Id));
await _localEventBus.PublishAsync(new UserCreatedEventArgs(aggregateRoot.Id));
}
private async Task ValidateUser(UserEntity entity)
private async Task ValidateUser(UserAggregateRoot aggregateRoot)
{
// TODO 不一定非要用户名,这里需要更自由的逻辑
if (entity.Username is UserConst.Admin or UserConst.TenantAdmin)
if (aggregateRoot.Username is UserConst.Admin or UserConst.TenantAdmin)
{
throw new UserFriendlyException("无效的用户名");
}
if (entity.Username.Length < 2)
if (aggregateRoot.Username.Length < 2)
{
throw new UserFriendlyException("用户名长度错误需大于2个字符");
}
// 正则表达式,匹配只包含数字和字母的字符串
var isMatch = UsernameRegex().IsMatch(entity.Username);
var isMatch = UsernameRegex().IsMatch(aggregateRoot.Username);
if (!isMatch)
{
throw new UserFriendlyException("用户名不能包含除【字母】与【数字】的其他字符");
@ -92,14 +92,14 @@ public partial class UserManager : DomainService
// 密码长度判断
// TODO需要读取配置
if (entity.EncryptPassword.Password.Length < 6)
if (aggregateRoot.EncryptPassword.Password.Length < 6)
{
throw new UserFriendlyException($"密码格式错误,长度需大于等于{6}位");
}
if (!string.IsNullOrEmpty(entity.PhoneNumber))
if (!string.IsNullOrEmpty(aggregateRoot.PhoneNumber))
{
if (await _repository.IsAnyAsync(x => x.PhoneNumber == entity.PhoneNumber))
if (await _repository.IsAnyAsync(x => x.PhoneNumber == aggregateRoot.PhoneNumber))
{
throw new UserFriendlyException("手机号重复");
}
@ -211,7 +211,7 @@ public partial class UserManager : DomainService
return ret!;
}
private UserFullDto? EntityMapToDto(UserEntity? entity)
private UserFullDto? EntityMapToDto(UserAggregateRoot? entity)
{
if (entity is null)
{

@ -1,9 +1,9 @@
using NPin.Framework.SqlSugarCore.Abstractions;
using NPin.Framework.Upms.Domain.Entities;
namespace NPin.Framework.Upms.Domain.Repositories;
public interface IConfigRepository : ISqlSugarRepository<ConfigEntity>
{
Task<TDestination> GetSingleByKeyAsync<TDestination>(string key) where TDestination : new();
using NPin.Framework.SqlSugarCore.Abstractions;
using NPin.Framework.Upms.Domain.Entities;
namespace NPin.Framework.Upms.Domain.Repositories;
public interface IConfigRepository : ISqlSugarRepository<ConfigAggregateRoot>
{
Task<TDestination> GetSingleByKeyAsync<TDestination>(string key) where TDestination : new();
}

@ -3,14 +3,14 @@ using NPin.Framework.Upms.Domain.Entities;
namespace NPin.Framework.Upms.Domain.Repositories;
public interface IUserRepository : ISqlSugarRepository<UserEntity>
public interface IUserRepository : ISqlSugarRepository<UserAggregateRoot>
{
/// <summary>
/// 获取用户所有信息,即所有的关联关系
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
Task<UserEntity> GetAllInfoAsync(Guid userId);
Task<UserAggregateRoot> GetAllInfoAsync(Guid userId);
/// <summary>
/// 获取用户列表
@ -18,5 +18,5 @@ public interface IUserRepository : ISqlSugarRepository<UserEntity>
/// </summary>
/// <param name="userIds"></param>
/// <returns></returns>
Task<List<UserEntity>> GetListUserAllInfoAsync(List<Guid> userIds);
Task<List<UserAggregateRoot>> GetListUserAllInfoAsync(List<Guid> userIds);
}

@ -18,10 +18,10 @@ public class UserDataSeed : IDataSeedContributor, ITransientDependency
public ILogger<UserDataSeed> Logger { get; set; }
private readonly ISettingManager _settingManager;
private readonly UpmsOptions _options;
private readonly ISqlSugarRepository<UserEntity> _userRepository;
private readonly ISqlSugarRepository<UserAggregateRoot> _userRepository;
public UserDataSeed(ISettingManager settingManager, IOptions<UpmsOptions> options,
ISqlSugarRepository<UserEntity> userRepository
ISqlSugarRepository<UserAggregateRoot> userRepository
)
{
_settingManager = settingManager;
@ -41,7 +41,7 @@ public class UserDataSeed : IDataSeedContributor, ITransientDependency
// 获取系统配置数据
var sysSetting = await _settingManager.GetSysSettingAsync(_options);
var users = new List<UserEntity>
var users = new List<UserAggregateRoot>
{
new()
{

@ -7,7 +7,7 @@ using Volo.Abp.DependencyInjection;
namespace NPin.Framework.Upms.SqlSugarCore.Repositories;
public class ConfigRepository : SqlSugarRepository<ConfigEntity, Guid>, IConfigRepository, ITransientDependency
public class ConfigRepository : SqlSugarRepository<ConfigAggregateRoot, Guid>, IConfigRepository, ITransientDependency
{
public ConfigRepository(ISugarDbContextProvider<ISqlSugarDbContext> sugarDbContextProvider) : base(
sugarDbContextProvider)

@ -6,14 +6,14 @@ using Volo.Abp.DependencyInjection;
namespace NPin.Framework.Upms.SqlSugarCore.Repositories;
public class UserRepository : SqlSugarRepository<UserEntity>, IUserRepository, ITransientDependency
public class UserRepository : SqlSugarRepository<UserAggregateRoot>, IUserRepository, ITransientDependency
{
public UserRepository(ISugarDbContextProvider<ISqlSugarDbContext> sugarDbContextProvider) : base(
sugarDbContextProvider)
{
}
public async Task<UserEntity> GetAllInfoAsync(Guid userId)
public async Task<UserAggregateRoot> GetAllInfoAsync(Guid userId)
{
var ret = await DbQueryable
.Includes(u => u.Metadata)
@ -24,7 +24,7 @@ public class UserRepository : SqlSugarRepository<UserEntity>, IUserRepository, I
return ret;
}
public async Task<List<UserEntity>> GetListUserAllInfoAsync(List<Guid> userIds)
public async Task<List<UserAggregateRoot>> GetListUserAllInfoAsync(List<Guid> userIds)
{
var ret = await DbQueryable
.Where(u => userIds.Contains(u.Id))

Loading…
Cancel
Save