diff --git a/module/upms/NPin.Framework.Upms.Domain/Entities/AnnouncementEntity.cs b/module/upms/NPin.Framework.Upms.Domain/Entities/AnnouncementAggregateRoot.cs similarity index 88% rename from module/upms/NPin.Framework.Upms.Domain/Entities/AnnouncementEntity.cs rename to module/upms/NPin.Framework.Upms.Domain/Entities/AnnouncementAggregateRoot.cs index 2f44f4f..9f42290 100644 --- a/module/upms/NPin.Framework.Upms.Domain/Entities/AnnouncementEntity.cs +++ b/module/upms/NPin.Framework.Upms.Domain/Entities/AnnouncementAggregateRoot.cs @@ -6,7 +6,7 @@ using Volo.Abp.Domain.Entities; namespace NPin.Framework.Upms.Domain.Entities; [SugarTable("SysAnnouncement", "系统公告表")] -public class AnnouncementEntity : Entity, ISoftDelete, IAuditedObject, IOrderNum, IEnabled +public class AnnouncementAggregateRoot : AggregateRoot, ISoftDelete, IAuditedObject, IOrderNum, IEnabled { [SugarColumn(IsPrimaryKey = true)] public override Guid Id { get; protected set; } diff --git a/module/upms/NPin.Framework.Upms.Domain/Entities/ConfigEntity.cs b/module/upms/NPin.Framework.Upms.Domain/Entities/ConfigAggregateRoot.cs similarity index 89% rename from module/upms/NPin.Framework.Upms.Domain/Entities/ConfigEntity.cs rename to module/upms/NPin.Framework.Upms.Domain/Entities/ConfigAggregateRoot.cs index d64ad89..6d9a804 100644 --- a/module/upms/NPin.Framework.Upms.Domain/Entities/ConfigEntity.cs +++ b/module/upms/NPin.Framework.Upms.Domain/Entities/ConfigAggregateRoot.cs @@ -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, IEnabled, IOrderNum, ISoftDelete, IAuditedObject +public class ConfigAggregateRoot : AggregateRoot, IEnabled, IOrderNum, ISoftDelete, IAuditedObject { [SugarColumn(IsPrimaryKey = true)] public override Guid Id { get; protected set; } diff --git a/module/upms/NPin.Framework.Upms.Domain/Entities/LoginLogEntity.cs b/module/upms/NPin.Framework.Upms.Domain/Entities/LoginLogAggregateRoot.cs similarity index 89% rename from module/upms/NPin.Framework.Upms.Domain/Entities/LoginLogEntity.cs rename to module/upms/NPin.Framework.Upms.Domain/Entities/LoginLogAggregateRoot.cs index ea173bf..06d1686 100644 --- a/module/upms/NPin.Framework.Upms.Domain/Entities/LoginLogEntity.cs +++ b/module/upms/NPin.Framework.Upms.Domain/Entities/LoginLogAggregateRoot.cs @@ -12,7 +12,7 @@ namespace NPin.Framework.Upms.Domain.Entities; [SugarTable("SysLoginLog", "登录日志表")] [SugarIndex($"index_{nameof(LoginUser)}", nameof(LoginUser), OrderByType.Asc)] -public class LoginLogEntity : Entity, ICreationAuditedObject +public class LoginLogAggregateRoot : AggregateRoot, ICreationAuditedObject { [SugarColumn(IsPrimaryKey = true)] public override Guid Id { get; protected set; } @@ -43,7 +43,7 @@ public class LoginLogEntity : Entity, 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, ICreationAuditedObject var clientInfo = GetClientInfo(httpContext); - return new LoginLogEntity + return new LoginLogAggregateRoot { Browser = clientInfo.Device.Family, Os = clientInfo.OS.ToString(), diff --git a/module/upms/NPin.Framework.Upms.Domain/Entities/OrganizationEntity.cs b/module/upms/NPin.Framework.Upms.Domain/Entities/OrganizationAggregateRoot.cs similarity index 89% rename from module/upms/NPin.Framework.Upms.Domain/Entities/OrganizationEntity.cs rename to module/upms/NPin.Framework.Upms.Domain/Entities/OrganizationAggregateRoot.cs index a1e8d94..78296a4 100644 --- a/module/upms/NPin.Framework.Upms.Domain/Entities/OrganizationEntity.cs +++ b/module/upms/NPin.Framework.Upms.Domain/Entities/OrganizationAggregateRoot.cs @@ -6,7 +6,7 @@ using Volo.Abp.Domain.Entities; namespace NPin.Framework.Upms.Domain.Entities; [SugarTable("SysOrganization", "组织机构表")] -public class OrganizationEntity : Entity, ISoftDelete, IAuditedObject, IOrderNum, IEnabled +public class OrganizationAggregateRoot : AggregateRoot, ISoftDelete, IAuditedObject, IOrderNum, IEnabled { [SugarColumn(IsPrimaryKey = true, ColumnDescription = "主键")] public override Guid Id { get; protected set; } diff --git a/module/upms/NPin.Framework.Upms.Domain/Entities/PostEntity.cs b/module/upms/NPin.Framework.Upms.Domain/Entities/PostAggregateRoot.cs similarity index 80% rename from module/upms/NPin.Framework.Upms.Domain/Entities/PostEntity.cs rename to module/upms/NPin.Framework.Upms.Domain/Entities/PostAggregateRoot.cs index 1f21cc3..38e8e31 100644 --- a/module/upms/NPin.Framework.Upms.Domain/Entities/PostEntity.cs +++ b/module/upms/NPin.Framework.Upms.Domain/Entities/PostAggregateRoot.cs @@ -6,7 +6,7 @@ using Volo.Abp.Domain.Entities; namespace NPin.Framework.Upms.Domain.Entities; [SugarTable("SysPost", "岗位表")] -public class PostEntity : Entity, ISoftDelete, IAuditedObject, IOrderNum, IEnabled +public class PostAggregateRoot : AggregateRoot, ISoftDelete, IAuditedObject, IOrderNum, IEnabled { [SugarColumn(IsPrimaryKey = true, ColumnDescription = "主键")] public override Guid Id { get; protected set; } @@ -17,6 +17,9 @@ public class PostEntity : Entity, 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; } diff --git a/module/upms/NPin.Framework.Upms.Domain/Entities/RoleEntity.cs b/module/upms/NPin.Framework.Upms.Domain/Entities/RoleAggregateRoot.cs similarity index 85% rename from module/upms/NPin.Framework.Upms.Domain/Entities/RoleEntity.cs rename to module/upms/NPin.Framework.Upms.Domain/Entities/RoleAggregateRoot.cs index 5b4e21c..0da5ec7 100644 --- a/module/upms/NPin.Framework.Upms.Domain/Entities/RoleEntity.cs +++ b/module/upms/NPin.Framework.Upms.Domain/Entities/RoleAggregateRoot.cs @@ -7,7 +7,7 @@ using Volo.Abp.Domain.Entities; namespace NPin.Framework.Upms.Domain.Entities; [SugarTable("SysRole", "角色表")] -public class RoleEntity : Entity, ISoftDelete, IAuditedObject, IOrderNum, IEnabled +public class RoleAggregateRoot : AggregateRoot, ISoftDelete, IAuditedObject, IOrderNum, IEnabled { [SugarColumn(IsPrimaryKey = true, ColumnDescription = "主键")] public override Guid Id { get; protected set; } @@ -36,7 +36,7 @@ public class RoleEntity : Entity, ISoftDelete, IAuditedObject, IOrderNum, [Navigate(typeof(RoleOrganizationEntity), nameof(RoleOrganizationEntity.RoleId), nameof(RoleOrganizationEntity.OrgId))] - public List OrganizationList { get; set; } + public List OrganizationList { get; set; } #endregion } \ No newline at end of file diff --git a/module/upms/NPin.Framework.Upms.Domain/Entities/UserEntity.cs b/module/upms/NPin.Framework.Upms.Domain/Entities/UserAggregateRoot.cs similarity index 87% rename from module/upms/NPin.Framework.Upms.Domain/Entities/UserEntity.cs rename to module/upms/NPin.Framework.Upms.Domain/Entities/UserAggregateRoot.cs index ede549f..84f9ff2 100644 --- a/module/upms/NPin.Framework.Upms.Domain/Entities/UserEntity.cs +++ b/module/upms/NPin.Framework.Upms.Domain/Entities/UserAggregateRoot.cs @@ -11,7 +11,7 @@ namespace NPin.Framework.Upms.Domain.Entities; [SugarTable("SysUser", "用户表")] [SugarIndex($"index_{nameof(Username)}", nameof(Username), OrderByType.Asc)] -public class UserEntity : Entity, ISoftDelete, IAuditedObject, IEnabled, IOrderNum +public class UserAggregateRoot : AggregateRoot, ISoftDelete, IAuditedObject, IEnabled, IOrderNum { #region User @@ -80,28 +80,28 @@ public class UserEntity : Entity, ISoftDelete, IAuditedObject, IEnabled, I /// 角色列表,多对多 /// [Navigate(typeof(UserRoleEntity), nameof(UserRoleEntity.UserId), nameof(UserRoleEntity.RoleId))] - public List Roles { get; set; } + public List Roles { get; set; } /// /// 岗位列表,多对多 /// [Navigate(typeof(UserPostEntity), nameof(UserPostEntity.UserId), nameof(UserPostEntity.PostId))] - public List Posts { get; set; } + public List Posts { get; set; } /// /// 所在的组织机构列表,多对多 /// [Navigate(typeof(UserOrganizationEntity), nameof(UserOrganizationEntity.UserId), nameof(UserOrganizationEntity.OrganizationId))] - public List Organizations { get; set; } + public List 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, ISoftDelete, IAuditedObject, IEnabled, I /// 通过随机盐值给密码加密,使用BCrypt算法 /// /// - public UserEntity BuildPassword(string? password = null) + public UserAggregateRoot BuildPassword(string? password = null) { // 若传入密码无值,则使用原本Password // 若原本Password依然无值,则抛出参数异常 diff --git a/module/upms/NPin.Framework.Upms.Domain/EventHandlers/LoginEventHandler.cs b/module/upms/NPin.Framework.Upms.Domain/EventHandlers/LoginEventHandler.cs index 88fd809..676a8a7 100644 --- a/module/upms/NPin.Framework.Upms.Domain/EventHandlers/LoginEventHandler.cs +++ b/module/upms/NPin.Framework.Upms.Domain/EventHandlers/LoginEventHandler.cs @@ -12,9 +12,9 @@ namespace NPin.Framework.Upms.Domain.EventHandlers; public class LoginEventHandler : ILocalEventHandler, ITransientDependency { public ILogger Logger { get; set; } - private readonly IRepository _repository; + private readonly IRepository _repository; - public LoginEventHandler(IRepository repository) + public LoginEventHandler(IRepository repository) { Logger = NullLogger.Instance; _repository = repository; @@ -23,7 +23,7 @@ public class LoginEventHandler : ILocalEventHandler, ITransientD public async Task HandleEventAsync(LoginEventArgs eventData) { Logger.LogInformation($"用户[{eventData.UserId}:{eventData.Username}]登录"); - var loginLogEntity = eventData.Adapt(); + var loginLogEntity = eventData.Adapt(); loginLogEntity.LoginMsg = $"{eventData.Username}登录系统"; loginLogEntity.LoginUser = eventData.Username; loginLogEntity.LoginUserId = eventData.UserId; diff --git a/module/upms/NPin.Framework.Upms.Domain/Managers/AccountManager.cs b/module/upms/NPin.Framework.Upms.Domain/Managers/AccountManager.cs index febe58e..aab1cd1 100644 --- a/module/upms/NPin.Framework.Upms.Domain/Managers/AccountManager.cs +++ b/module/upms/NPin.Framework.Upms.Domain/Managers/AccountManager.cs @@ -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(); loginEto.Username = userInfo.User.Username; loginEto.UserId = userInfo.User.Id; diff --git a/module/upms/NPin.Framework.Upms.Domain/Managers/RoleManager.cs b/module/upms/NPin.Framework.Upms.Domain/Managers/RoleManager.cs index 446a558..2851db8 100644 --- a/module/upms/NPin.Framework.Upms.Domain/Managers/RoleManager.cs +++ b/module/upms/NPin.Framework.Upms.Domain/Managers/RoleManager.cs @@ -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 _repository; - - public RoleManager(ISqlSugarRepository 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 _repository; + + public RoleManager(ISqlSugarRepository repository) + { + _repository = repository; + } } \ No newline at end of file diff --git a/module/upms/NPin.Framework.Upms.Domain/Managers/UserManager.cs b/module/upms/NPin.Framework.Upms.Domain/Managers/UserManager.cs index e39236a..6d68be5 100644 --- a/module/upms/NPin.Framework.Upms.Domain/Managers/UserManager.cs +++ b/module/upms/NPin.Framework.Upms.Domain/Managers/UserManager.cs @@ -29,7 +29,7 @@ public partial class UserManager : DomainService private static partial Regex UsernameRegex(); private readonly IUserRepository _repository; - private readonly ISqlSugarRepository _repositoryRole; + private readonly ISqlSugarRepository _repositoryRole; private readonly ISqlSugarRepository _repositoryUserRole; private readonly ISqlSugarRepository _repositoryUserPost; @@ -44,7 +44,7 @@ public partial class UserManager : DomainService ISqlSugarRepository repositoryUserPost, ISqlSugarRepository repositoryUserOrg, IDistributedCache userCache, - ILocalEventBus localEventBus, ISqlSugarRepository repositoryRole) + ILocalEventBus localEventBus, ISqlSugarRepository repositoryRole) { _repository = repository; _repositoryUserRole = repositoryUserRole; @@ -58,33 +58,33 @@ public partial class UserManager : DomainService /// /// 创建用户 /// - /// - public async Task CreateAsync(UserEntity entity) + /// + 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) { diff --git a/module/upms/NPin.Framework.Upms.Domain/Repositories/IConfigRepository.cs b/module/upms/NPin.Framework.Upms.Domain/Repositories/IConfigRepository.cs index 905eb32..30ae250 100644 --- a/module/upms/NPin.Framework.Upms.Domain/Repositories/IConfigRepository.cs +++ b/module/upms/NPin.Framework.Upms.Domain/Repositories/IConfigRepository.cs @@ -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 -{ - Task GetSingleByKeyAsync(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 +{ + Task GetSingleByKeyAsync(string key) where TDestination : new(); } \ No newline at end of file diff --git a/module/upms/NPin.Framework.Upms.Domain/Repositories/IUserRepository.cs b/module/upms/NPin.Framework.Upms.Domain/Repositories/IUserRepository.cs index 2eafe2e..5bb9a1a 100644 --- a/module/upms/NPin.Framework.Upms.Domain/Repositories/IUserRepository.cs +++ b/module/upms/NPin.Framework.Upms.Domain/Repositories/IUserRepository.cs @@ -3,14 +3,14 @@ using NPin.Framework.Upms.Domain.Entities; namespace NPin.Framework.Upms.Domain.Repositories; -public interface IUserRepository : ISqlSugarRepository +public interface IUserRepository : ISqlSugarRepository { /// /// 获取用户所有信息,即所有的关联关系 /// /// /// - Task GetAllInfoAsync(Guid userId); + Task GetAllInfoAsync(Guid userId); /// /// 获取用户列表 @@ -18,5 +18,5 @@ public interface IUserRepository : ISqlSugarRepository /// /// /// - Task> GetListUserAllInfoAsync(List userIds); + Task> GetListUserAllInfoAsync(List userIds); } \ No newline at end of file diff --git a/module/upms/NPin.Framework.Upms.SqlSugarCore/DataSeeds/UserDataSeed.cs b/module/upms/NPin.Framework.Upms.SqlSugarCore/DataSeeds/UserDataSeed.cs index b4d8cf0..c1268fe 100644 --- a/module/upms/NPin.Framework.Upms.SqlSugarCore/DataSeeds/UserDataSeed.cs +++ b/module/upms/NPin.Framework.Upms.SqlSugarCore/DataSeeds/UserDataSeed.cs @@ -18,10 +18,10 @@ public class UserDataSeed : IDataSeedContributor, ITransientDependency public ILogger Logger { get; set; } private readonly ISettingManager _settingManager; private readonly UpmsOptions _options; - private readonly ISqlSugarRepository _userRepository; + private readonly ISqlSugarRepository _userRepository; public UserDataSeed(ISettingManager settingManager, IOptions options, - ISqlSugarRepository userRepository + ISqlSugarRepository userRepository ) { _settingManager = settingManager; @@ -41,7 +41,7 @@ public class UserDataSeed : IDataSeedContributor, ITransientDependency // 获取系统配置数据 var sysSetting = await _settingManager.GetSysSettingAsync(_options); - var users = new List + var users = new List { new() { diff --git a/module/upms/NPin.Framework.Upms.SqlSugarCore/Repositories/ConfigRepository.cs b/module/upms/NPin.Framework.Upms.SqlSugarCore/Repositories/ConfigRepository.cs index 9a7e3d9..d71c00f 100644 --- a/module/upms/NPin.Framework.Upms.SqlSugarCore/Repositories/ConfigRepository.cs +++ b/module/upms/NPin.Framework.Upms.SqlSugarCore/Repositories/ConfigRepository.cs @@ -7,7 +7,7 @@ using Volo.Abp.DependencyInjection; namespace NPin.Framework.Upms.SqlSugarCore.Repositories; -public class ConfigRepository : SqlSugarRepository, IConfigRepository, ITransientDependency +public class ConfigRepository : SqlSugarRepository, IConfigRepository, ITransientDependency { public ConfigRepository(ISugarDbContextProvider sugarDbContextProvider) : base( sugarDbContextProvider) diff --git a/module/upms/NPin.Framework.Upms.SqlSugarCore/Repositories/UserRepository.cs b/module/upms/NPin.Framework.Upms.SqlSugarCore/Repositories/UserRepository.cs index 58f485b..c8e55c7 100644 --- a/module/upms/NPin.Framework.Upms.SqlSugarCore/Repositories/UserRepository.cs +++ b/module/upms/NPin.Framework.Upms.SqlSugarCore/Repositories/UserRepository.cs @@ -6,14 +6,14 @@ using Volo.Abp.DependencyInjection; namespace NPin.Framework.Upms.SqlSugarCore.Repositories; -public class UserRepository : SqlSugarRepository, IUserRepository, ITransientDependency +public class UserRepository : SqlSugarRepository, IUserRepository, ITransientDependency { public UserRepository(ISugarDbContextProvider sugarDbContextProvider) : base( sugarDbContextProvider) { } - public async Task GetAllInfoAsync(Guid userId) + public async Task GetAllInfoAsync(Guid userId) { var ret = await DbQueryable .Includes(u => u.Metadata) @@ -24,7 +24,7 @@ public class UserRepository : SqlSugarRepository, IUserRepository, I return ret; } - public async Task> GetListUserAllInfoAsync(List userIds) + public async Task> GetListUserAllInfoAsync(List userIds) { var ret = await DbQueryable .Where(u => userIds.Contains(u.Id))