You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
114 lines
3.8 KiB
114 lines
3.8 KiB
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
using CellularManagement.Domain.Entities;
|
|
|
|
namespace CellularManagement.Infrastructure.Configurations.Identity;
|
|
|
|
/// <summary>
|
|
/// AppUser 实体配置类
|
|
/// 用于配置用户实体在数据库中的映射关系
|
|
/// </summary>
|
|
public sealed class AppUserConfiguration : IEntityTypeConfiguration<AppUser>
|
|
{
|
|
/// <summary>
|
|
/// 配置 AppUser 实体
|
|
/// </summary>
|
|
/// <param name="builder">实体类型构建器</param>
|
|
public void Configure(EntityTypeBuilder<AppUser> builder)
|
|
{
|
|
// 配置表名
|
|
builder.ToTable("tb_users", t => t.HasComment("用户表"));
|
|
|
|
// 配置索引
|
|
builder.HasIndex(u => u.UserName).IsUnique().HasDatabaseName("IX_user_UserName");
|
|
builder.HasIndex(u => u.Email).IsUnique().HasDatabaseName("IX_user_Email");
|
|
builder.HasIndex(u => u.PhoneNumber).IsUnique().HasDatabaseName("IX_user_PhoneNumber");
|
|
builder.HasIndex(u => u.NormalizedEmail).HasDatabaseName("EmailIndex");
|
|
builder.HasIndex(u => u.NormalizedUserName).IsUnique().HasDatabaseName("UserNameIndex");
|
|
|
|
// 配置属性
|
|
builder.Property(u => u.Id)
|
|
.HasComment("用户ID,主键");
|
|
|
|
builder.Property(u => u.UserName)
|
|
.IsRequired()
|
|
.HasMaxLength(256)
|
|
.HasComment("账号");
|
|
|
|
builder.Property(u => u.NormalizedUserName)
|
|
.HasMaxLength(256)
|
|
.HasComment("标准化账号(大写)");
|
|
|
|
builder.Property(u => u.Email)
|
|
.IsRequired()
|
|
.HasMaxLength(256)
|
|
.HasComment("电子邮箱");
|
|
|
|
builder.Property(u => u.NormalizedEmail)
|
|
.HasMaxLength(256)
|
|
.HasComment("标准化电子邮箱(大写)");
|
|
|
|
builder.Property(u => u.EmailConfirmed)
|
|
.HasComment("邮箱是否已验证");
|
|
|
|
builder.Property(u => u.PasswordHash)
|
|
.HasComment("密码哈希值");
|
|
|
|
builder.Property(u => u.SecurityStamp)
|
|
.HasComment("安全戳,用于并发控制");
|
|
|
|
builder.Property(u => u.ConcurrencyStamp)
|
|
.IsConcurrencyToken()
|
|
.HasComment("并发控制戳");
|
|
|
|
builder.Property(u => u.PhoneNumber)
|
|
.IsRequired()
|
|
.HasComment("电话号码");
|
|
|
|
builder.Property(u => u.PhoneNumberConfirmed)
|
|
.HasComment("电话号码是否已验证");
|
|
|
|
builder.Property(u => u.TwoFactorEnabled)
|
|
.HasComment("是否启用双因素认证");
|
|
|
|
builder.Property(u => u.LockoutEnd)
|
|
.HasComment("账户锁定结束时间");
|
|
|
|
builder.Property(u => u.LockoutEnabled)
|
|
.HasComment("是否启用账户锁定");
|
|
|
|
builder.Property(u => u.AccessFailedCount)
|
|
.HasComment("登录失败次数");
|
|
|
|
builder.Property(u => u.RealName)
|
|
.HasMaxLength(50)
|
|
.HasComment("用户名");
|
|
|
|
// 配置审计字段
|
|
builder.Property(u => u.CreatedTime)
|
|
.IsRequired()
|
|
.HasColumnType("timestamp with time zone")
|
|
.HasComment("创建时间");
|
|
|
|
builder.Property(u => u.ModifiedTime)
|
|
.HasColumnType("timestamp with time zone")
|
|
.HasComment("修改时间");
|
|
|
|
builder.Property(u => u.IsActive)
|
|
.IsRequired()
|
|
.HasDefaultValue(true)
|
|
.HasComment("用户状态(true: 启用, false: 禁用)");
|
|
|
|
builder.Property(u => u.IsDeleted)
|
|
.IsRequired()
|
|
.HasDefaultValue(false)
|
|
.HasComment("是否已删除");
|
|
|
|
builder.Property(u => u.LastLoginTime)
|
|
.HasColumnType("timestamp with time zone")
|
|
.HasComment("最后登录时间");
|
|
|
|
// 添加软删除过滤器
|
|
builder.HasQueryFilter(u => !u.IsDeleted);
|
|
}
|
|
}
|