style: 修改聚合跟类命名

This commit is contained in:
橙子
2024-05-22 14:35:08 +08:00
parent f2e3c76539
commit 3429de9eb6
89 changed files with 446 additions and 412 deletions

View File

@@ -10,7 +10,7 @@ namespace Yi.Framework.Rbac.Domain.Entities
/// 配置表
/// </summary>
[SugarTable("Config")]
public class ConfigEntity : Entity<Guid>, IAuditedObject, IOrderNum, ISoftDelete
public class ConfigAggregateRoot : AggregateRoot<Guid>, IAuditedObject, IOrderNum, ISoftDelete
{
[SugarColumn(ColumnName = "Id", IsPrimaryKey = true)]
public override Guid Id { get; protected set; }

View File

@@ -10,15 +10,15 @@ namespace Yi.Framework.Rbac.Domain.Entities
/// 部门表
///</summary>
[SugarTable("Dept")]
public class DeptEntity : Entity<Guid>, ISoftDelete, IAuditedObject, IOrderNum, IState
public class DeptAggregateRoot : AggregateRoot<Guid>, ISoftDelete, IAuditedObject, IOrderNum, IState
{
public DeptEntity()
public DeptAggregateRoot()
{
}
public DeptEntity(Guid Id) { this.Id = Id; ParentId = Guid.Empty; }
public DeptAggregateRoot(Guid Id) { this.Id = Id; ParentId = Guid.Empty; }
public DeptEntity(Guid Id, Guid parentId) { this.Id = Id; ParentId = parentId; }
public DeptAggregateRoot(Guid Id, Guid parentId) { this.Id = Id; ParentId = parentId; }
/// <summary>
/// 主键
/// </summary>

View File

@@ -10,7 +10,7 @@ namespace Yi.Framework.Rbac.Domain.Entities
{
[SugarTable("LoginLog")]
[SugarIndex($"index_{nameof(LoginUser)}", nameof(LoginUser), OrderByType.Asc)]
public class LoginLogEntity : Entity<Guid>, ICreationAuditedObject
public class LoginLogAggregateRoot : AggregateRoot<Guid>, ICreationAuditedObject
{
[SugarColumn(ColumnName = "Id", IsPrimaryKey = true)]
public override Guid Id { get; protected set; }
@@ -50,7 +50,7 @@ namespace Yi.Framework.Rbac.Domain.Entities
public Guid? CreatorId { get; set; }
public LoginLogEntity GetInfoByHttpContext(HttpContext context)
public LoginLogAggregateRoot GetInfoByHttpContext(HttpContext context)
{
ClientInfo GetClientInfo(HttpContext context)
{
@@ -78,7 +78,7 @@ namespace Yi.Framework.Rbac.Domain.Entities
location = IpTool.Search(ipAddr);
}
ClientInfo clientInfo = GetClientInfo(context);
LoginLogEntity entity = new()
LoginLogAggregateRoot entity = new()
{
Browser = clientInfo.Device.Family,
Os = clientInfo.OS.ToString(),

View File

@@ -13,12 +13,12 @@ namespace Yi.Framework.Rbac.Domain.Entities
/// 菜单表
///</summary>
[SugarTable("Menu")]
public partial class MenuEntity : Entity<Guid>, ISoftDelete, IAuditedObject, IOrderNum, IState
public partial class MenuAggregateRoot : AggregateRoot<Guid>, ISoftDelete, IAuditedObject, IOrderNum, IState
{
public MenuEntity() { }
public MenuAggregateRoot() { }
public MenuEntity(Guid id) { Id = id; ParentId = Guid.Empty; }
public MenuEntity(Guid id, Guid parentId) { Id = id; ParentId = parentId; }
public MenuAggregateRoot(Guid id) { Id = id; ParentId = Guid.Empty; }
public MenuAggregateRoot(Guid id, Guid parentId) { Id = id; ParentId = parentId; }
/// <summary>
/// 主键
/// </summary>
@@ -123,7 +123,7 @@ namespace Yi.Framework.Rbac.Domain.Entities
public string? Query { get; set; }
[SugarColumn(IsIgnore = true)]
public List<MenuEntity>? Children { get; set; }
public List<MenuAggregateRoot>? Children { get; set; }
}
@@ -137,7 +137,7 @@ namespace Yi.Framework.Rbac.Domain.Entities
/// </summary>
/// <param name="menus"></param>
/// <returns></returns>
public static List<Vue3RouterDto> Vue3RouterBuild(this List<MenuEntity> menus)
public static List<Vue3RouterDto> Vue3RouterBuild(this List<MenuAggregateRoot> menus)
{
menus = menus.Where(m => m.MenuType != MenuTypeEnum.Component).ToList();
List<Vue3RouterDto> routers = new();

View File

@@ -12,7 +12,7 @@ using Yi.Framework.Rbac.Domain.Shared.Enums;
namespace Yi.Framework.Rbac.Domain.Entities
{
[SugarTable("Notice")]
public class NoticeEntity : Entity<Guid>, ISoftDelete, IAuditedObject, IOrderNum, IState
public class NoticeAggregateRoot : AggregateRoot<Guid>, ISoftDelete, IAuditedObject, IOrderNum, IState
{
[SugarColumn(IsPrimaryKey = true)]

View File

@@ -10,7 +10,7 @@ namespace Yi.Framework.Rbac.Domain.Entities
/// 岗位表
///</summary>
[SugarTable("Post")]
public class PostEntity : Entity<Guid>, ISoftDelete, IAuditedObject, IOrderNum, IState
public class PostAggregateRoot : AggregateRoot<Guid>, ISoftDelete, IAuditedObject, IOrderNum, IState
{
/// <summary>

View File

@@ -1,5 +1,4 @@
using SqlSugar;
using Volo.Abp;
using Volo.Abp.Auditing;
using Volo.Abp.Domain.Entities;
using Yi.Framework.Core.Data;
@@ -11,7 +10,7 @@ namespace Yi.Framework.Rbac.Domain.Entities
/// 角色表
/// </summary>
[SugarTable("Role")]
public class RoleEntity : Entity<Guid>, ISoftDelete, IAuditedObject, IOrderNum, IState
public class RoleAggregateRoot : AggregateRoot<Guid>, ISoftDelete, IAuditedObject, IOrderNum, IState
{
/// <summary>
/// 主键
@@ -79,9 +78,9 @@ namespace Yi.Framework.Rbac.Domain.Entities
[Navigate(typeof(RoleMenuEntity), nameof(RoleMenuEntity.RoleId), nameof(RoleMenuEntity.MenuId))]
public List<MenuEntity>? Menus { get; set; }
public List<MenuAggregateRoot>? Menus { get; set; }
[Navigate(typeof(RoleDeptEntity), nameof(RoleDeptEntity.RoleId), nameof(RoleDeptEntity.DeptId))]
public List<DeptEntity>? Depts { get; set; }
public List<DeptAggregateRoot>? Depts { get; set; }
}
}

View File

@@ -1,5 +1,4 @@
using SqlSugar;
using Volo.Abp;
using Volo.Abp.Auditing;
using Volo.Abp.Domain.Entities;
using Yi.Framework.Core.Data;
@@ -14,13 +13,13 @@ namespace Yi.Framework.Rbac.Domain.Entities
/// </summary>
[SugarTable("User")]
[SugarIndex($"index_{nameof(UserName)}", nameof(UserName), OrderByType.Asc)]
public class UserEntity : Entity<Guid>, ISoftDelete, IAuditedObject, IOrderNum, IState
public class UserAggregateRoot : AggregateRoot<Guid>, ISoftDelete, IAuditedObject, IOrderNum, IState
{
public UserEntity()
public UserAggregateRoot()
{
}
public UserEntity(string userName, string password, long phone, string nick = "萌新")
public UserAggregateRoot(string userName, string password, long phone, string nick = "萌新")
{
UserName = userName;
EncryPassword.Password = password;
@@ -158,26 +157,26 @@ namespace Yi.Framework.Rbac.Domain.Entities
/// 角色
/// </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(NavigateType.OneToOne, nameof(DeptId))]
public DeptEntity? Dept { get; set; }
public DeptAggregateRoot? Dept { get; set; }
/// <summary>
/// 构建密码MD5盐值加密
/// </summary>
public UserEntity BuildPassword(string password = null)
public UserAggregateRoot BuildPassword(string password = null)
{
//如果不传值那就把自己的password当作传进来的password
if (password == null)

View File

@@ -17,12 +17,12 @@ namespace Yi.Framework.Rbac.Domain.EventHandlers
ITransientDependency
{
private readonly ILogger<LoginEventHandler> _logger;
private readonly IRepository<LoginLogEntity> _loginLogRepository;
public LoginEventHandler(ILogger<LoginEventHandler> logger, IRepository<LoginLogEntity> loginLogRepository) { _logger = logger; _loginLogRepository = loginLogRepository; }
private readonly IRepository<LoginLogAggregateRoot> _loginLogRepository;
public LoginEventHandler(ILogger<LoginEventHandler> logger, IRepository<LoginLogAggregateRoot> loginLogRepository) { _logger = logger; _loginLogRepository = loginLogRepository; }
public async Task HandleEventAsync(LoginEventArgs eventData)
{
_logger.LogInformation($"用户【{eventData.UserId}:{eventData.UserName}】登入系统");
var loginLogEntity = eventData.Adapt<LoginLogEntity>();
var loginLogEntity = eventData.Adapt<LoginLogAggregateRoot>();
loginLogEntity.LogMsg = eventData.UserName + "登录系统";
loginLogEntity.LoginUser = eventData.UserName;
loginLogEntity.CreatorId = eventData.UserId;

View File

@@ -36,7 +36,7 @@ namespace Yi.Framework.Rbac.Domain.Managers
private readonly RbacOptions _options;
private IHttpContextAccessor _httpContextAccessor;
private UserManager _userManager;
private ISqlSugarRepository<RoleEntity> _roleRepository;
private ISqlSugarRepository<RoleAggregateRoot> _roleRepository;
private RefreshJwtOptions _refreshJwtOptions;
public AccountManager(IUserRepository repository
@@ -45,7 +45,7 @@ namespace Yi.Framework.Rbac.Domain.Managers
, ILocalEventBus localEventBus
, UserManager userManager
, IOptions<RefreshJwtOptions> refreshJwtOptions
, ISqlSugarRepository<RoleEntity> roleRepository
, ISqlSugarRepository<RoleAggregateRoot> roleRepository
, IOptions<RbacOptions> options)
{
_repository = repository;
@@ -86,7 +86,7 @@ namespace Yi.Framework.Rbac.Domain.Managers
//这里抛出一个登录的事件
if (_httpContextAccessor.HttpContext is not null)
{
var loginEntity = new LoginLogEntity().GetInfoByHttpContext(_httpContextAccessor.HttpContext);
var loginEntity = new LoginLogAggregateRoot().GetInfoByHttpContext(_httpContextAccessor.HttpContext);
var loginEto = loginEntity.Adapt<LoginEventArgs>();
loginEto.UserName = userInfo.User.UserName;
loginEto.UserId = userInfo.User.Id;
@@ -149,9 +149,9 @@ namespace Yi.Framework.Rbac.Domain.Managers
/// <param name="password"></param>
/// <param name="userAction"></param>
/// <returns></returns>
public async Task LoginValidationAsync(string userName, string password, Action<UserEntity> userAction = null)
public async Task LoginValidationAsync(string userName, string password, Action<UserAggregateRoot> userAction = null)
{
var user = new UserEntity();
var user = new UserAggregateRoot();
if (await ExistAsync(userName, o => user = o))
{
if (userAction is not null)
@@ -173,7 +173,7 @@ namespace Yi.Framework.Rbac.Domain.Managers
/// <param name="userName"></param>
/// <param name="userAction"></param>
/// <returns></returns>
public async Task<bool> ExistAsync(string userName, Action<UserEntity> userAction = null)
public async Task<bool> ExistAsync(string userName, Action<UserAggregateRoot> userAction = null)
{
var user = await _repository.GetFirstAsync(u => u.UserName == userName && u.State == true);
if (userAction is not null)
@@ -280,7 +280,7 @@ namespace Yi.Framework.Rbac.Domain.Managers
/// <returns></returns>
public async Task RegisterAsync(string userName, string password, long phone)
{
var user = new UserEntity(userName, password, phone);
var user = new UserAggregateRoot(userName, password, phone);
await _userManager.CreateAsync(user);
await _userManager.SetDefautRoleAsync(user.Id);

View File

@@ -12,7 +12,7 @@ namespace Yi.Framework.Rbac.Domain.Managers
{
string CreateRefreshToken(Guid userId);
Task<string> GetTokenByUserIdAsync(Guid userId);
Task LoginValidationAsync(string userName, string password, Action<UserEntity> userAction = null);
Task LoginValidationAsync(string userName, string password, Action<UserAggregateRoot> userAction = null);
Task RegisterAsync(string userName, string password, long phone);
Task<bool> RestPasswordAsync(Guid userId, string password);
Task UpdatePasswordAsync(Guid userId, string newPassword, string oldPassword);

View File

@@ -6,9 +6,9 @@ namespace Yi.Framework.Rbac.Domain.Managers
{
public class RoleManager : DomainService
{
private ISqlSugarRepository<RoleEntity> _repository;
private ISqlSugarRepository<RoleAggregateRoot> _repository;
private ISqlSugarRepository<RoleMenuEntity> _roleMenuRepository;
public RoleManager(ISqlSugarRepository<RoleEntity> repository, ISqlSugarRepository<RoleMenuEntity> roleMenuRepository)
public RoleManager(ISqlSugarRepository<RoleAggregateRoot> repository, ISqlSugarRepository<RoleMenuEntity> roleMenuRepository)
{
_repository = repository;
_roleMenuRepository = roleMenuRepository;

View File

@@ -21,15 +21,15 @@ namespace Yi.Framework.Rbac.Domain.Managers
{
public class UserManager : DomainService
{
public readonly ISqlSugarRepository<UserEntity> _repository;
public readonly ISqlSugarRepository<UserAggregateRoot> _repository;
public readonly ISqlSugarRepository<UserRoleEntity> _repositoryUserRole;
public readonly ISqlSugarRepository<UserPostEntity> _repositoryUserPost;
private readonly ISqlSugarRepository<RoleEntity> _roleRepository;
private readonly ISqlSugarRepository<RoleAggregateRoot> _roleRepository;
private IDistributedCache<UserInfoCacheItem, UserInfoCacheKey> _userCache;
private readonly IGuidGenerator _guidGenerator;
private IUserRepository _userRepository;
private ILocalEventBus _localEventBus;
public UserManager(ISqlSugarRepository<UserEntity> repository, ISqlSugarRepository<UserRoleEntity> repositoryUserRole, ISqlSugarRepository<UserPostEntity> repositoryUserPost, IGuidGenerator guidGenerator, IDistributedCache<UserInfoCacheItem, UserInfoCacheKey> userCache, IUserRepository userRepository, ILocalEventBus localEventBus, ISqlSugarRepository<RoleEntity> roleRepository) =>
public UserManager(ISqlSugarRepository<UserAggregateRoot> repository, ISqlSugarRepository<UserRoleEntity> repositoryUserRole, ISqlSugarRepository<UserPostEntity> repositoryUserPost, IGuidGenerator guidGenerator, IDistributedCache<UserInfoCacheItem, UserInfoCacheKey> userCache, IUserRepository userRepository, ILocalEventBus localEventBus, ISqlSugarRepository<RoleAggregateRoot> roleRepository) =>
(_repository, _repositoryUserRole, _repositoryUserPost, _guidGenerator, _userCache, _userRepository, _localEventBus, _roleRepository) =
(repository, repositoryUserRole, repositoryUserPost, guidGenerator, userCache, userRepository, localEventBus, roleRepository);
@@ -96,7 +96,7 @@ namespace Yi.Framework.Rbac.Domain.Managers
/// 创建用户
/// </summary>
/// <returns></returns>
public async Task CreateAsync(UserEntity userEntity)
public async Task CreateAsync(UserAggregateRoot userEntity)
{
//校验用户名
ValidateUserName(userEntity);
@@ -139,7 +139,7 @@ namespace Yi.Framework.Rbac.Domain.Managers
}
}
private void ValidateUserName(UserEntity input)
private void ValidateUserName(UserAggregateRoot input)
{
if (input.UserName == UserConst.Admin || input.UserName == UserConst.TenantAdmin)
{
@@ -217,7 +217,7 @@ namespace Yi.Framework.Rbac.Domain.Managers
private UserRoleMenuDto EntityMapToDto(UserEntity user)
private UserRoleMenuDto EntityMapToDto(UserAggregateRoot user)
{
var userRoleMenu = new UserRoleMenuDto();
@@ -259,11 +259,11 @@ namespace Yi.Framework.Rbac.Domain.Managers
}
//刚好可以去除一下多余的导航属性
role.Menus = new List<MenuEntity>();
role.Menus = new List<MenuAggregateRoot>();
userRoleMenu.Roles.Add(role.Adapt<RoleDto>());
}
user.Roles = new List<RoleEntity>();
user.Roles = new List<RoleAggregateRoot>();
userRoleMenu.User = user.Adapt<UserDto>();
userRoleMenu.Menus = userRoleMenu.Menus.OrderByDescending(x => x.OrderNum).ToHashSet();
return userRoleMenu;

View File

@@ -3,9 +3,9 @@ using Yi.Framework.SqlSugarCore.Abstractions;
namespace Yi.Framework.Rbac.Domain.Repositories
{
public interface IDeptRepository : ISqlSugarRepository<DeptEntity, Guid>
public interface IDeptRepository : ISqlSugarRepository<DeptAggregateRoot, Guid>
{
Task<List<Guid>> GetChildListAsync(Guid deptId);
Task<List<DeptEntity>> GetListRoleIdAsync(Guid roleId);
Task<List<DeptAggregateRoot>> GetListRoleIdAsync(Guid roleId);
}
}

View File

@@ -5,20 +5,20 @@ using Yi.Framework.SqlSugarCore.Abstractions;
namespace Yi.Framework.Rbac.Domain.Repositories
{
public interface IUserRepository : ISqlSugarRepository<UserEntity>
public interface IUserRepository : ISqlSugarRepository<UserAggregateRoot>
{
/// <summary>
/// 获取用户的所有信息
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
Task<UserEntity> GetUserAllInfoAsync(Guid userId);
Task<UserAggregateRoot> GetUserAllInfoAsync(Guid userId);
/// <summary>
/// 批量获取用户的所有信息
/// </summary>
/// <param name="userIds"></param>
/// <returns></returns>
Task<List<UserEntity>> GetListUserAllInfoAsync(List<Guid> userIds);
Task<List<UserAggregateRoot>> GetListUserAllInfoAsync(List<Guid> userIds);
}
}