using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Serialization;
using SqlSugar;
using Yi.Framework.Common.Helper;
using Yi.Framework.Model.Base;
namespace Yi.Framework.Model.RABC.Entitys
{
///
/// 用户表
///
[SugarTable("User")]
public partial class UserEntity : IBaseModelEntity
{
public UserEntity()
{
CreateTime = DateTime.Now;
}
[JsonConverter(typeof(ValueToStringConverter))]
[SugarColumn(ColumnName = "Id", IsPrimaryKey = true)]
public long Id { get; set; }
///
///
///
[SugarColumn(ColumnName = "Name")]
public string? Name { get; set; }
///
///
///
[SugarColumn(ColumnName = "Age")]
public int? Age { get; set; }
///
///
///
[SugarColumn(ColumnName = "CreateUser")]
public long? CreateUser { get; set; }
///
///
///
[SugarColumn(ColumnName = "CreateTime")]
public DateTime? CreateTime { get; set; }
///
///
///
[SugarColumn(ColumnName = "ModifyUser")]
public long? ModifyUser { get; set; }
///
///
///
[SugarColumn(ColumnName = "ModifyTime")]
public DateTime? ModifyTime { get; set; }
///
///
///
[SugarColumn(ColumnName = "IsDeleted")]
public bool? IsDeleted { get; set; }
///
///
///
[SugarColumn(ColumnName = "TenantId")]
public long? TenantId { get; set; }
///
///
///
[SugarColumn(ColumnName = "UserName")]
public string? UserName { get; set; }
///
///
///
[SugarColumn(ColumnName = "Password")]
public string? Password { get; set; }
///
///
///
[SugarColumn(ColumnName = "Salt")]
public string? Salt { get; set; }
///
///
///
[SugarColumn(ColumnName = "Icon")]
public string? Icon { get; set; }
///
///
///
[SugarColumn(ColumnName = "Nick")]
public string? Nick { get; set; }
///
///
///
[SugarColumn(ColumnName = "Email")]
public string? Email { get; set; }
///
///
///
[SugarColumn(ColumnName = "Ip")]
public string? Ip { get; set; }
///
///
///
[SugarColumn(ColumnName = "Address")]
public string? Address { get; set; }
///
///
///
[SugarColumn(ColumnName = "Phone")]
public string? Phone { get; set; }
///
///
///
[SugarColumn(ColumnName = "Introduction")]
public string? Introduction { get; set; }
///
/// 排序字段
///
[SugarColumn(ColumnName = "OrderNum")]
public int? OrderNum { get; set; }
///
/// 描述
///
[SugarColumn(ColumnName = "Remark")]
public string? Remark { get; set; }
///
/// 部门id
///
[SugarColumn(ColumnName = "DeptId")]
public long? DeptId { get; set; }
///
/// 性别
///
[SugarColumn(ColumnName = "Sex")]
public int? Sex { get; set; }
///
/// 看好啦!ORM精髓,导航属性
///
[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("Password不能为空");
}
password = Password;
}
Salt = MD5Helper.GenerateSalt();
Password = MD5Helper.SHA2Encode(password, Salt);
return this;
}
///
/// 判断密码和加密后的密码是否相同
///
///
///
public bool JudgePassword(string password)
{
var p = MD5Helper.SHA2Encode(password, Salt);
if (Password == MD5Helper.SHA2Encode(password, Salt))
{
return true;
}
return false;
}
}
}