refactor: 移除租户审核领取模型

This commit is contained in:
root
2026-01-29 12:15:19 +00:00
parent 3297ff26ab
commit c7307c1942
4 changed files with 2 additions and 140 deletions

View File

@@ -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");

View File

@@ -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)
{