nsnail a330495624
style: 💄 code format (#109)
[skip ci]
2024-04-26 16:35:11 +08:00

127 lines
3.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using NetAdmin.Domain.DbMaps.Dependency;
using NetAdmin.Domain.DbMaps.Dependency.Fields;
using NetAdmin.Domain.Dto.Sys.User;
namespace NetAdmin.Domain.DbMaps.Sys;
/// <summary>
/// 用户基本信息表
/// </summary>
[Index(Chars.FLG_DB_INDEX_PREFIX + nameof(Email), nameof(Email), true)]
[Index(Chars.FLG_DB_INDEX_PREFIX + nameof(Mobile), nameof(Mobile), true)]
[Index(Chars.FLG_DB_INDEX_PREFIX + nameof(UserName), nameof(UserName), true)]
[Table(Name = Chars.FLG_DB_TABLE_NAME_PREFIX + nameof(Sys_User))]
public record Sys_User : VersionEntity, IFieldSummary, IFieldEnabled, IRegister
{
/// <summary>
/// 头像链接
/// </summary>
[Column(DbType = Chars.FLG_DB_FIELD_TYPE_VARCHAR_127)]
[JsonIgnore]
public virtual string Avatar { get; init; }
/// <summary>
/// 所属部门
/// </summary>
[JsonIgnore]
[Navigate(nameof(DeptId))]
public Sys_Dept Dept { get; init; }
/// <summary>
/// 部门编号
/// </summary>
[Column]
[JsonIgnore]
public virtual long DeptId { get; init; }
/// <summary>
/// 邮箱
/// </summary>
[Column(DbType = Chars.FLG_DB_FIELD_TYPE_VARCHAR_63)]
[JsonIgnore]
public virtual string Email { get; init; }
/// <summary>
/// 是否启用
/// </summary>
[Column]
[JsonIgnore]
public virtual bool Enabled { get; init; }
/// <summary>
/// 手机号
/// </summary>
[Column(DbType = Chars.FLG_DB_FIELD_TYPE_VARCHAR_15)]
[JsonIgnore]
public virtual string Mobile { get; init; }
/// <summary>
/// 密码
/// </summary>
[Column]
[JsonIgnore]
public Guid Password { get; init; }
/// <summary>
/// 用户档案
/// </summary>
[JsonIgnore]
public Sys_UserProfile Profile { get; init; }
/// <summary>
/// 所属角色
/// </summary>
[JsonIgnore]
[Navigate(ManyToMany = typeof(Sys_UserRole))]
public ICollection<Sys_Role> Roles { get; init; }
/// <summary>
/// 发送给此用户的站内信集合
/// </summary>
[JsonIgnore]
[Navigate(ManyToMany = typeof(Sys_SiteMsgUser))]
public ICollection<Sys_SiteMsg> SiteMsgs { get; init; }
/// <summary>
/// 描述
/// </summary>
[Column(DbType = Chars.FLG_DB_FIELD_TYPE_VARCHAR_255)]
[JsonIgnore]
public virtual string Summary { get; init; }
/// <summary>
/// 授权验证Token全局唯一可以随时重置强制下线
/// </summary>
[Column]
[JsonIgnore]
public Guid Token { get; init; }
/// <summary>
/// 用户名
/// </summary>
[Column(DbType = Chars.FLG_DB_FIELD_TYPE_VARCHAR_31)]
[JsonIgnore]
public virtual string UserName { get; init; }
/// <inheritdoc />
public void Register(TypeAdapterConfig config)
{
_ = config.ForType<CreateUserReq, Sys_User>()
.Map(d => d.Password, s => s.PasswordText.Pwd().Guid())
.Map(d => d.Token, _ => Guid.NewGuid())
.Map( //
d => d.Roles
, s => s.RoleIds.NullOrEmpty()
? Array.Empty<Sys_Role>()
: s.RoleIds.Select(x => new Sys_Role { Id = x }));
_ = config.ForType<UpdateUserReq, Sys_User>()
.Map( //
d => d.Password, s => s.PasswordText.NullOrEmpty() ? Guid.Empty : s.PasswordText.Pwd().Guid())
.Map( //
d => d.Roles
, s => s.RoleIds.NullOrEmpty()
? Array.Empty<Sys_Role>()
: s.RoleIds.Select(x => new Sys_Role { Id = x }));
}
}