using SqlSugar; using Volo.Abp; using Volo.Abp.Auditing; using Volo.Abp.Domain.Entities; using Yi.Framework.Core.Data; using Yi.Framework.Core.Helper; using Yi.Framework.Rbac.Domain.Shared.Enums; namespace Yi.Framework.Rbac.Domain.Entities { /// /// 用户表 /// [SugarTable("User")] public class UserEntity : Entity, ISoftDelete, IAuditedObject, IOrderNum, IState { public UserEntity() { } public UserEntity(string userName, string password, long phone, string nick = "萌新") { UserName = userName; Password = password; Phone = phone; Nick = nick; BuildPassword(); } /// /// 主键 /// [SugarColumn(IsPrimaryKey = true)] public override Guid Id { get; protected set; } /// /// 逻辑删除 /// public bool IsDeleted { get; set; } /// /// 姓名 /// public string? Name { get; set; } /// /// 年龄 /// public int? Age { get; set; } /// /// 用户名 /// public string UserName { get; set; } = string.Empty; /// /// 密码 /// public string Password { get; set; } = string.Empty; /// /// 加密盐值 /// public string Salt { get; set; } = string.Empty; /// /// 头像 /// public string? Icon { get; set; } /// /// 昵称 /// public string? Nick { get; set; } /// /// 邮箱 /// public string? Email { get; set; } /// /// Ip /// public string? Ip { get; set; } /// /// 地址 /// public string? Address { get; set; } /// /// 电话 /// public long? Phone { get; set; } /// /// 简介 /// public string? Introduction { get; set; } /// /// 备注 /// public string? Remark { get; set; } /// /// 性别 /// public SexEnum Sex { get; set; } = SexEnum.Unknown; /// /// 部门id /// public Guid? DeptId { get; set; } /// /// 创建时间 /// public DateTime CreationTime { get; set; } = DateTime.Now; /// /// 创建者 /// public Guid? CreatorId { get; set; } /// /// 最后修改者 /// public Guid? LastModifierId { get; set; } /// /// 最后修改时间 /// public DateTime? LastModificationTime { get; set; } /// /// 排序 /// public int OrderNum { get; set; } = 0; /// /// 状态 /// public bool State { get; set; } = true; /// /// 角色 /// [Navigate(typeof(UserRoleEntity), nameof(UserRoleEntity.UserId), nameof(UserRoleEntity.RoleId))] public List Roles { get; set; } /// /// 岗位 /// [Navigate(typeof(UserPostEntity), nameof(UserPostEntity.UserId), nameof(UserPostEntity.PostId))] public List Posts { get; set; } /// /// 部门 /// [Navigate(NavigateType.OneToOne, nameof(DeptId))] public DeptEntity? Dept { get; set; } /// /// 构建密码,MD5盐值加密 /// public UserEntity BuildPassword(string password = null) { //如果不传值,那就把自己的password当作传进来的password if (password == null) { if (Password == null) { throw new ArgumentNullException(nameof(Password)); } password = Password; } Salt = MD5Helper.GenerateSalt(); Password = MD5Helper.SHA2Encode(password, Salt); return this; } /// /// 判断密码和加密后的密码是否相同 /// /// /// public bool JudgePassword(string password) { if (Salt is null) { throw new ArgumentNullException(Salt); } var p = MD5Helper.SHA2Encode(password, Salt); if (Password == MD5Helper.SHA2Encode(password, Salt)) { return true; } return false; } } }