feat: 实现动态租户解析与移除菜单回退逻辑
1. 新增 ITenantCodeResolver 接口和 DatabaseTenantCodeResolver 实现 2. 修改 TenantResolutionMiddleware 支持从数据库动态解析租户编码 3. ITenantRepository 新增 FindIdByCodeAsync 方法 4. 移除 EfMenuRepository 中危险的系统菜单回退逻辑 5. 调整服务注册顺序确保依赖正确注入 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -162,6 +162,20 @@ public sealed class EfTenantRepository(TakeoutAppDbContext context, TakeoutLogsD
|
||||
return context.Tenants.AnyAsync(x => x.Code == normalized, cancellationToken);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<long?> FindIdByCodeAsync(string code, CancellationToken cancellationToken = default)
|
||||
{
|
||||
// 1. 标准化编码
|
||||
var normalized = code.Trim();
|
||||
|
||||
// 2. 查询租户 ID(仅查询未删除且状态正常的租户)
|
||||
return context.Tenants
|
||||
.AsNoTracking()
|
||||
.Where(x => x.Code == normalized && x.DeletedAt == null)
|
||||
.Select(x => (long?)x.Id)
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<bool> ExistsByNameAsync(string name, long? excludeTenantId = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user