2023-12-11 09:55:12 +08:00
|
|
|
|
using SqlSugar;
|
|
|
|
|
|
using Volo.Abp;
|
|
|
|
|
|
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;
|
|
|
|
|
|
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")]
|
2023-12-11 09:55:12 +08:00
|
|
|
|
public class UserEntity : Entity<Guid>, ISoftDelete, IAuditedObject, IOrderNum, IState
|
2023-04-13 21:12:06 +08:00
|
|
|
|
{
|
|
|
|
|
|
public UserEntity()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
public UserEntity(string userName, string password, long phone, string nick = "萌新")
|
|
|
|
|
|
{
|
|
|
|
|
|
UserName = userName;
|
|
|
|
|
|
Password = password;
|
|
|
|
|
|
Phone = phone;
|
|
|
|
|
|
Nick = nick;
|
|
|
|
|
|
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>
|
|
|
|
|
|
/// 密码
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public string Password { get; set; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 加密盐值
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public string Salt { get; set; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
|
|
/// <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))]
|
|
|
|
|
|
public List<RoleEntity> Roles { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 岗位
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
|
|
|
|
[Navigate(typeof(UserPostEntity), nameof(UserPostEntity.UserId), nameof(UserPostEntity.PostId))]
|
|
|
|
|
|
public List<PostEntity> Posts { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 部门
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
|
|
|
|
[Navigate(NavigateType.OneToOne, nameof(DeptId))]
|
2023-12-11 09:55:12 +08:00
|
|
|
|
public DeptEntity? Dept { get; set; }
|
2023-04-13 21:12:06 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 构建密码,MD5盐值加密
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 判断密码和加密后的密码是否相同
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="password"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|