refactor: 移除租户审核领取模型
This commit is contained in:
@@ -1,34 +0,0 @@
|
||||
using TakeoutSaaS.Shared.Abstractions.Entities;
|
||||
|
||||
namespace TakeoutSaaS.Domain.Tenants.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// 租户入驻审核领取记录(防止多管理员并发审核)。
|
||||
/// </summary>
|
||||
public sealed class TenantReviewClaim : AuditableEntityBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 被领取的租户 ID。
|
||||
/// </summary>
|
||||
public long TenantId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 领取人用户 ID。
|
||||
/// </summary>
|
||||
public long ClaimedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 领取人名称(展示用快照)。
|
||||
/// </summary>
|
||||
public string ClaimedByName { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 领取时间(UTC)。
|
||||
/// </summary>
|
||||
public DateTime ClaimedAt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 释放时间(UTC),未释放时为 null。
|
||||
/// </summary>
|
||||
public DateTime? ReleasedAt { get; set; }
|
||||
}
|
||||
@@ -135,38 +135,6 @@ public interface ITenantRepository
|
||||
/// <returns>异步任务。</returns>
|
||||
Task UpsertVerificationProfileAsync(TenantVerificationProfile profile, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前审核领取信息(仅返回未释放的记录)。
|
||||
/// </summary>
|
||||
/// <param name="tenantId">租户 ID(雪花算法)。</param>
|
||||
/// <param name="cancellationToken">取消标记。</param>
|
||||
/// <returns>领取记录,未领取返回 null。</returns>
|
||||
Task<TenantReviewClaim?> GetActiveReviewClaimAsync(long tenantId, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// 查询当前审核领取信息(用于更新,返回可跟踪实体)。
|
||||
/// </summary>
|
||||
/// <param name="tenantId">租户 ID(雪花算法)。</param>
|
||||
/// <param name="cancellationToken">取消标记。</param>
|
||||
/// <returns>领取记录,未领取返回 null。</returns>
|
||||
Task<TenantReviewClaim?> FindActiveReviewClaimAsync(long tenantId, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// 新增审核领取记录。
|
||||
/// </summary>
|
||||
/// <param name="claim">领取记录。</param>
|
||||
/// <param name="auditLog">领取动作审计日志。</param>
|
||||
/// <param name="cancellationToken">取消标记。</param>
|
||||
/// <returns>新增成功返回 true;若已被其他人领取导致冲突则返回 false。</returns>
|
||||
Task<bool> TryAddReviewClaimAsync(TenantReviewClaim claim, TenantAuditLog auditLog, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// 更新审核领取记录。
|
||||
/// </summary>
|
||||
/// <param name="claim">领取记录。</param>
|
||||
/// <param name="cancellationToken">取消标记。</param>
|
||||
Task UpdateReviewClaimAsync(TenantReviewClaim claim, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前订阅。
|
||||
/// </summary>
|
||||
|
||||
@@ -88,10 +88,6 @@ public sealed class TakeoutAppDbContext(
|
||||
/// </summary>
|
||||
public DbSet<TenantVerificationProfile> TenantVerificationProfiles => Set<TenantVerificationProfile>();
|
||||
/// <summary>
|
||||
/// 租户审核领取记录。
|
||||
/// </summary>
|
||||
public DbSet<TenantReviewClaim> TenantReviewClaims => Set<TenantReviewClaim>();
|
||||
/// <summary>
|
||||
/// 配额包定义。
|
||||
/// </summary>
|
||||
public DbSet<QuotaPackage> QuotaPackages => Set<QuotaPackage>();
|
||||
@@ -398,7 +394,6 @@ public sealed class TakeoutAppDbContext(
|
||||
ConfigureTenantAnnouncement(modelBuilder.Entity<TenantAnnouncement>());
|
||||
ConfigureTenantAnnouncementRead(modelBuilder.Entity<TenantAnnouncementRead>());
|
||||
ConfigureTenantVerificationProfile(modelBuilder.Entity<TenantVerificationProfile>());
|
||||
ConfigureTenantReviewClaim(modelBuilder.Entity<TenantReviewClaim>());
|
||||
ConfigureQuotaPackage(modelBuilder.Entity<QuotaPackage>());
|
||||
ConfigureTenantQuotaPackagePurchase(modelBuilder.Entity<TenantQuotaPackagePurchase>());
|
||||
ConfigureMerchantDocument(modelBuilder.Entity<MerchantDocument>());
|
||||
@@ -469,6 +464,7 @@ public sealed class TakeoutAppDbContext(
|
||||
ConfigureMetricSnapshot(modelBuilder.Entity<MetricSnapshot>());
|
||||
ConfigureMetricAlertRule(modelBuilder.Entity<MetricAlertRule>());
|
||||
|
||||
// 3. 应用多租户全局查询过滤器
|
||||
ApplyTenantQueryFilters(modelBuilder);
|
||||
}
|
||||
|
||||
@@ -509,21 +505,7 @@ public sealed class TakeoutAppDbContext(
|
||||
builder.HasIndex(x => x.TenantId).IsUnique();
|
||||
}
|
||||
|
||||
private static void ConfigureTenantReviewClaim(EntityTypeBuilder<TenantReviewClaim> builder)
|
||||
{
|
||||
builder.ToTable("tenant_review_claims");
|
||||
builder.HasKey(x => x.Id);
|
||||
builder.Property(x => x.TenantId).IsRequired();
|
||||
builder.Property(x => x.ClaimedBy).IsRequired();
|
||||
builder.Property(x => x.ClaimedByName).HasMaxLength(64).IsRequired();
|
||||
builder.Property(x => x.ClaimedAt).IsRequired();
|
||||
builder.Property(x => x.ReleasedAt);
|
||||
builder.HasIndex(x => x.TenantId);
|
||||
builder.HasIndex(x => x.ClaimedBy);
|
||||
builder.HasIndex(x => x.TenantId).IsUnique().HasFilter("\"ReleasedAt\" IS NULL AND \"DeletedAt\" IS NULL");
|
||||
}
|
||||
|
||||
|
||||
// 租户订阅历史映射
|
||||
private static void ConfigureTenantSubscriptionHistory(EntityTypeBuilder<TenantSubscriptionHistory> builder)
|
||||
{
|
||||
builder.ToTable("tenant_subscription_histories");
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Npgsql;
|
||||
using TakeoutSaaS.Domain.Tenants.Entities;
|
||||
using TakeoutSaaS.Domain.Tenants.Enums;
|
||||
using TakeoutSaaS.Domain.Tenants.Repositories;
|
||||
@@ -251,59 +250,6 @@ public sealed class EfTenantRepository(TakeoutAppDbContext context, TakeoutLogsD
|
||||
context.Entry(existing).CurrentValues.SetValues(profile);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<TenantReviewClaim?> GetActiveReviewClaimAsync(long tenantId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return context.TenantReviewClaims
|
||||
.AsNoTracking()
|
||||
.Where(x => x.TenantId == tenantId && x.ReleasedAt == null)
|
||||
.OrderByDescending(x => x.ClaimedAt)
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<TenantReviewClaim?> FindActiveReviewClaimAsync(long tenantId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return context.TenantReviewClaims
|
||||
.Where(x => x.TenantId == tenantId && x.ReleasedAt == null)
|
||||
.OrderByDescending(x => x.ClaimedAt)
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> TryAddReviewClaimAsync(
|
||||
TenantReviewClaim claim,
|
||||
TenantAuditLog auditLog,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 1. 写入领取记录
|
||||
await context.TenantReviewClaims.AddAsync(claim, cancellationToken);
|
||||
await context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
// 2. 写入审计日志
|
||||
await logsContext.TenantAuditLogs.AddAsync(auditLog, cancellationToken);
|
||||
await logsContext.SaveChangesAsync(cancellationToken);
|
||||
return true;
|
||||
}
|
||||
catch (DbUpdateException ex) when (ex.InnerException is PostgresException pg && pg.SqlState == PostgresErrorCodes.UniqueViolation)
|
||||
{
|
||||
// 1. 释放实体跟踪避免重复写入
|
||||
context.Entry(claim).State = EntityState.Detached;
|
||||
|
||||
// 2. 返回抢占失败
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task UpdateReviewClaimAsync(TenantReviewClaim claim, CancellationToken cancellationToken = default)
|
||||
{
|
||||
context.TenantReviewClaims.Update(claim);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<TenantSubscription?> GetActiveSubscriptionAsync(long tenantId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user