2023-12-11 09:55:12 +08:00
|
|
|
|
using SqlSugar;
|
|
|
|
|
|
using Volo.Abp.Auditing;
|
|
|
|
|
|
using Volo.Abp.Domain.Entities;
|
2023-12-11 18:43:36 +08:00
|
|
|
|
using Yi.Framework.Core.Data;
|
2023-12-11 09:55:12 +08:00
|
|
|
|
using Yi.Framework.Core.Helper;
|
2024-04-22 18:06:09 +08:00
|
|
|
|
using Yi.Framework.Rbac.Domain.Entities.ValueObjects;
|
2023-12-11 09:55:12 +08:00
|
|
|
|
using Yi.Framework.Rbac.Domain.Shared.Enums;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Yi.Framework.Rbac.Domain.Entities
|
2023-04-13 21:12:06 +08:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 用户表
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[SugarTable("User")]
|
2024-01-11 22:06:15 +08:00
|
|
|
|
[SugarIndex($"index_{nameof(UserName)}", nameof(UserName), OrderByType.Asc)]
|
2024-05-22 14:35:08 +08:00
|
|
|
|
public class UserAggregateRoot : AggregateRoot<Guid>, ISoftDelete, IAuditedObject, IOrderNum, IState
|
2023-04-13 21:12:06 +08:00
|
|
|
|
{
|
2024-05-22 14:35:08 +08:00
|
|
|
|
public UserAggregateRoot()
|
2023-04-13 21:12:06 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2024-10-02 23:25:29 +08:00
|
|
|
|
public UserAggregateRoot(string userName, string password, long phone, string? nick = null)
|
2023-04-13 21:12:06 +08:00
|
|
|
|
{
|
|
|
|
|
|
UserName = userName;
|
2024-04-22 18:06:09 +08:00
|
|
|
|
EncryPassword.Password = password;
|
2023-04-13 21:12:06 +08:00
|
|
|
|
Phone = phone;
|
2024-10-02 23:25:29 +08:00
|
|
|
|
Nick =string.IsNullOrWhiteSpace(nick)?"萌新-"+userName:nick.Trim();
|
2023-04-13 21:12:06 +08:00
|
|
|
|
BuildPassword();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 主键
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[SugarColumn(IsPrimaryKey = true)]
|
2023-12-11 09:55:12 +08:00
|
|
|
|
public override Guid Id { get; protected set; }
|
2023-04-13 21:12:06 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 逻辑删除
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public bool IsDeleted { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 姓名
|
|
|
|
|
|
/// </summary>
|
2023-04-20 23:08:21 +08:00
|
|
|
|
public string? Name { get; set; }
|
2023-04-13 21:12:06 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 年龄
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public int? Age { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 用户名
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public string UserName { get; set; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-04-22 18:06:09 +08:00
|
|
|
|
/// 加密密码
|
2023-04-13 21:12:06 +08:00
|
|
|
|
/// </summary>
|
2024-04-22 18:06:09 +08:00
|
|
|
|
[SugarColumn(IsOwnsOne = true)]
|
2024-04-26 19:08:18 +08:00
|
|
|
|
public EncryPasswordValueObject EncryPassword { get; set; } = new EncryPasswordValueObject();
|
2023-04-13 21:12:06 +08:00
|
|
|
|
|
2024-04-22 18:06:09 +08:00
|
|
|
|
///// <summary>
|
|
|
|
|
|
///// 密码
|
|
|
|
|
|
///// </summary>
|
|
|
|
|
|
//public string Password { get; set; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
|
|
///// <summary>
|
|
|
|
|
|
///// 加密盐值
|
|
|
|
|
|
///// </summary>
|
|
|
|
|
|
//public string Salt { get; set; } = string.Empty;
|
2023-04-13 21:12:06 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 头像
|
|
|
|
|
|
/// </summary>
|
2023-04-20 22:36:32 +08:00
|
|
|
|
public string? Icon { get; set; }
|
2023-04-13 21:12:06 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 昵称
|
|
|
|
|
|
/// </summary>
|
2023-04-20 22:36:32 +08:00
|
|
|
|
public string? Nick { get; set; }
|
2023-04-13 21:12:06 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 邮箱
|
|
|
|
|
|
/// </summary>
|
2023-04-20 22:36:32 +08:00
|
|
|
|
public string? Email { get; set; }
|
2023-04-13 21:12:06 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Ip
|
|
|
|
|
|
/// </summary>
|
2023-04-20 22:36:32 +08:00
|
|
|
|
public string? Ip { get; set; }
|
2023-04-13 21:12:06 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 地址
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
2023-04-20 22:36:32 +08:00
|
|
|
|
public string? Address { get; set; }
|
2023-04-13 21:12:06 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 电话
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public long? Phone { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 简介
|
|
|
|
|
|
/// </summary>
|
2023-04-20 22:36:32 +08:00
|
|
|
|
public string? Introduction { get; set; }
|
2023-04-13 21:12:06 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 备注
|
|
|
|
|
|
/// </summary>
|
2023-04-20 22:36:32 +08:00
|
|
|
|
public string? Remark { get; set; }
|
2023-04-13 21:12:06 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 性别
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public SexEnum Sex { get; set; } = SexEnum.Unknown;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 部门id
|
|
|
|
|
|
/// </summary>
|
2023-12-11 09:55:12 +08:00
|
|
|
|
public Guid? DeptId { get; set; }
|
2023-04-13 21:12:06 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 创建时间
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public DateTime CreationTime { get; set; } = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 创建者
|
|
|
|
|
|
/// </summary>
|
2023-12-11 09:55:12 +08:00
|
|
|
|
public Guid? CreatorId { get; set; }
|
2023-04-13 21:12:06 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 最后修改者
|
|
|
|
|
|
/// </summary>
|
2023-12-11 09:55:12 +08:00
|
|
|
|
public Guid? LastModifierId { get; set; }
|
2023-04-13 21:12:06 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 最后修改时间
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public DateTime? LastModificationTime { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 排序
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public int OrderNum { get; set; } = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 状态
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public bool State { get; set; } = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 角色
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[Navigate(typeof(UserRoleEntity), nameof(UserRoleEntity.UserId), nameof(UserRoleEntity.RoleId))]
|
2024-05-22 14:35:08 +08:00
|
|
|
|
public List<RoleAggregateRoot> Roles { get; set; }
|
2023-04-13 21:12:06 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 岗位
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
|
|
|
|
[Navigate(typeof(UserPostEntity), nameof(UserPostEntity.UserId), nameof(UserPostEntity.PostId))]
|
2024-05-22 14:35:08 +08:00
|
|
|
|
public List<PostAggregateRoot> Posts { get; set; }
|
2023-04-13 21:12:06 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 部门
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
|
|
|
|
[Navigate(NavigateType.OneToOne, nameof(DeptId))]
|
2024-05-22 14:35:08 +08:00
|
|
|
|
public DeptAggregateRoot? Dept { get; set; }
|
2023-04-13 21:12:06 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 构建密码,MD5盐值加密
|
|
|
|
|
|
/// </summary>
|
2024-05-22 14:35:08 +08:00
|
|
|
|
public UserAggregateRoot BuildPassword(string password = null)
|
2023-04-13 21:12:06 +08:00
|
|
|
|
{
|
|
|
|
|
|
//如果不传值,那就把自己的password当作传进来的password
|
|
|
|
|
|
if (password == null)
|
|
|
|
|
|
{
|
2024-04-26 19:08:18 +08:00
|
|
|
|
if (EncryPassword?.Password == null)
|
2023-04-13 21:12:06 +08:00
|
|
|
|
{
|
2024-04-22 18:06:09 +08:00
|
|
|
|
throw new ArgumentNullException(nameof(EncryPassword.Password));
|
2023-04-13 21:12:06 +08:00
|
|
|
|
}
|
2024-04-22 18:06:09 +08:00
|
|
|
|
password = EncryPassword.Password;
|
2023-04-13 21:12:06 +08:00
|
|
|
|
}
|
2024-04-22 18:06:09 +08:00
|
|
|
|
EncryPassword.Salt = MD5Helper.GenerateSalt();
|
|
|
|
|
|
EncryPassword.Password = MD5Helper.SHA2Encode(password, EncryPassword.Salt);
|
2023-04-13 21:12:06 +08:00
|
|
|
|
return this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 判断密码和加密后的密码是否相同
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="password"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public bool JudgePassword(string password)
|
|
|
|
|
|
{
|
2024-04-22 18:06:09 +08:00
|
|
|
|
if (EncryPassword.Salt is null)
|
2023-04-13 21:12:06 +08:00
|
|
|
|
{
|
2024-04-22 18:06:09 +08:00
|
|
|
|
throw new ArgumentNullException(EncryPassword.Salt);
|
2023-04-13 21:12:06 +08:00
|
|
|
|
}
|
2024-04-22 18:06:09 +08:00
|
|
|
|
var p = MD5Helper.SHA2Encode(password, EncryPassword.Salt);
|
|
|
|
|
|
if (EncryPassword.Password == MD5Helper.SHA2Encode(password, EncryPassword.Salt))
|
2023-04-13 21:12:06 +08:00
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|