Compare commits
No commits in common. "main" and "v1.0.14" have entirely different histories.
@ -1,13 +1,17 @@
|
|||||||
namespace Fengling.Platform.Domain.AggregatesModel.GatewayAggregate;
|
namespace Fengling.Platform.Domain.AggregatesModel.GatewayAggregate;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 网关路由实体 - 表示全局路由规则配置
|
/// 网关租户路由实体 - 表示路由规则配置
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class GwRoute
|
public class GwTenantRoute
|
||||||
{
|
{
|
||||||
public string Id { get; set; } = Guid.CreateVersion7().ToString("N");
|
public string Id { get; set; } = Guid.CreateVersion7().ToString("N");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 租户代码
|
||||||
|
/// </summary>
|
||||||
|
public string TenantCode { get; set; } = string.Empty;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 服务名称
|
/// 服务名称
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -63,7 +67,11 @@ public class GwRoute
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public int Status { get; set; } = 1;
|
public int Status { get; set; } = 1;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否全局路由
|
||||||
|
/// </summary>
|
||||||
|
public bool IsGlobal { get; set; } = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 创建人ID
|
/// 创建人ID
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -9,9 +9,10 @@ namespace Fengling.Platform.Infrastructure;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IRouteManager
|
public interface IRouteManager
|
||||||
{
|
{
|
||||||
Task<GwRoute?> FindByIdAsync(string? id, CancellationToken cancellationToken = default);
|
Task<GwTenantRoute?> FindByIdAsync(string? id, CancellationToken cancellationToken = default);
|
||||||
Task<IList<GwRoute>> GetAllAsync(CancellationToken cancellationToken = default);
|
Task<GwTenantRoute?> FindByTenantCodeAsync(string tenantCode, CancellationToken cancellationToken = default);
|
||||||
Task<IdentityResult> CreateRouteAsync(GwRoute route, CancellationToken cancellationToken = default);
|
Task<IList<GwTenantRoute>> GetAllAsync(CancellationToken cancellationToken = default);
|
||||||
Task<IdentityResult> UpdateRouteAsync(GwRoute route, CancellationToken cancellationToken = default);
|
Task<IdentityResult> CreateRouteAsync(GwTenantRoute route, CancellationToken cancellationToken = default);
|
||||||
Task<IdentityResult> DeleteRouteAsync(GwRoute route, CancellationToken cancellationToken = default);
|
Task<IdentityResult> UpdateRouteAsync(GwTenantRoute route, CancellationToken cancellationToken = default);
|
||||||
|
Task<IdentityResult> DeleteRouteAsync(GwTenantRoute route, CancellationToken cancellationToken = default);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,14 +9,15 @@ namespace Fengling.Platform.Infrastructure;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IRouteStore
|
public interface IRouteStore
|
||||||
{
|
{
|
||||||
Task<GwRoute?> FindByIdAsync(string? id, CancellationToken cancellationToken = default);
|
Task<GwTenantRoute?> FindByIdAsync(string? id, CancellationToken cancellationToken = default);
|
||||||
Task<GwRoute?> FindByClusterIdAsync(string clusterId, CancellationToken cancellationToken = default);
|
Task<GwTenantRoute?> FindByTenantCodeAsync(string tenantCode, CancellationToken cancellationToken = default);
|
||||||
Task<IList<GwRoute>> GetAllAsync(CancellationToken cancellationToken = default);
|
Task<GwTenantRoute?> FindByClusterIdAsync(string clusterId, CancellationToken cancellationToken = default);
|
||||||
Task<IList<GwRoute>> GetPagedAsync(int page, int pageSize,
|
Task<IList<GwTenantRoute>> GetAllAsync(CancellationToken cancellationToken = default);
|
||||||
|
Task<IList<GwTenantRoute>> GetPagedAsync(int page, int pageSize, string? tenantCode = null,
|
||||||
string? serviceName = null, RouteStatus? status = null, CancellationToken cancellationToken = default);
|
string? serviceName = null, RouteStatus? status = null, CancellationToken cancellationToken = default);
|
||||||
Task<int> GetCountAsync(string? serviceName = null,
|
Task<int> GetCountAsync(string? tenantCode = null, string? serviceName = null,
|
||||||
RouteStatus? status = null, CancellationToken cancellationToken = default);
|
RouteStatus? status = null, CancellationToken cancellationToken = default);
|
||||||
Task<IdentityResult> CreateAsync(GwRoute route, CancellationToken cancellationToken = default);
|
Task<IdentityResult> CreateAsync(GwTenantRoute route, CancellationToken cancellationToken = default);
|
||||||
Task<IdentityResult> UpdateAsync(GwRoute route, CancellationToken cancellationToken = default);
|
Task<IdentityResult> UpdateAsync(GwTenantRoute route, CancellationToken cancellationToken = default);
|
||||||
Task<IdentityResult> DeleteAsync(GwRoute route, CancellationToken cancellationToken = default);
|
Task<IdentityResult> DeleteAsync(GwTenantRoute route, CancellationToken cancellationToken = default);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,7 @@ public class PlatformDbContext(DbContextOptions options)
|
|||||||
public DbSet<AuditLog> AuditLogs => Set<AuditLog>();
|
public DbSet<AuditLog> AuditLogs => Set<AuditLog>();
|
||||||
|
|
||||||
// Gateway 实体
|
// Gateway 实体
|
||||||
public DbSet<GwRoute> GwRoutes => Set<GwRoute>();
|
public DbSet<GwTenantRoute> GwTenantRoutes => Set<GwTenantRoute>();
|
||||||
public DbSet<GwCluster> GwClusters => Set<GwCluster>();
|
public DbSet<GwCluster> GwClusters => Set<GwCluster>();
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
@ -91,10 +91,10 @@ public class PlatformDbContext(DbContextOptions options)
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Gateway 实体配置
|
// Gateway 实体配置
|
||||||
modelBuilder.Entity<GwRoute>(entity =>
|
modelBuilder.Entity<GwTenantRoute>(entity =>
|
||||||
{
|
{
|
||||||
entity.ToTable("GwRoutes");
|
|
||||||
entity.HasKey(e => e.Id);
|
entity.HasKey(e => e.Id);
|
||||||
|
entity.Property(e => e.TenantCode).HasMaxLength(50);
|
||||||
entity.Property(e => e.ServiceName).HasMaxLength(100).IsRequired();
|
entity.Property(e => e.ServiceName).HasMaxLength(100).IsRequired();
|
||||||
entity.Property(e => e.ClusterId).HasMaxLength(100).IsRequired();
|
entity.Property(e => e.ClusterId).HasMaxLength(100).IsRequired();
|
||||||
entity.Property(e => e.AuthorizationPolicy).HasMaxLength(100);
|
entity.Property(e => e.AuthorizationPolicy).HasMaxLength(100);
|
||||||
@ -132,15 +132,15 @@ public class PlatformDbContext(DbContextOptions options)
|
|||||||
c => JsonSerializer.Deserialize<List<GwTransform>>(JsonSerializer.Serialize(c, jsonOptions), jsonOptions)!))
|
c => JsonSerializer.Deserialize<List<GwTransform>>(JsonSerializer.Serialize(c, jsonOptions), jsonOptions)!))
|
||||||
.HasColumnType("jsonb");
|
.HasColumnType("jsonb");
|
||||||
|
|
||||||
|
entity.HasIndex(e => e.TenantCode);
|
||||||
entity.HasIndex(e => e.ServiceName);
|
entity.HasIndex(e => e.ServiceName);
|
||||||
entity.HasIndex(e => e.ClusterId);
|
entity.HasIndex(e => e.ClusterId);
|
||||||
entity.HasIndex(e => new { e.ServiceName, e.Status });
|
entity.HasIndex(e => new { e.ServiceName, e.IsGlobal, e.Status });
|
||||||
});
|
});
|
||||||
|
|
||||||
// GwCluster 聚合根配置
|
// GwCluster 聚合根配置
|
||||||
modelBuilder.Entity<GwCluster>(entity =>
|
modelBuilder.Entity<GwCluster>(entity =>
|
||||||
{
|
{
|
||||||
entity.ToTable("ServiceInstances");
|
|
||||||
entity.HasKey(e => e.Id);
|
entity.HasKey(e => e.Id);
|
||||||
entity.Property(e => e.ClusterId).HasMaxLength(100).IsRequired();
|
entity.Property(e => e.ClusterId).HasMaxLength(100).IsRequired();
|
||||||
entity.Property(e => e.Name).HasMaxLength(100).IsRequired();
|
entity.Property(e => e.Name).HasMaxLength(100).IsRequired();
|
||||||
|
|||||||
@ -15,21 +15,24 @@ public class RouteManager : IRouteManager
|
|||||||
_store = store;
|
_store = store;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual Task<GwRoute?> FindByIdAsync(string? id, CancellationToken cancellationToken = default)
|
public virtual Task<GwTenantRoute?> FindByIdAsync(string? id, CancellationToken cancellationToken = default)
|
||||||
=> _store.FindByIdAsync(id, cancellationToken);
|
=> _store.FindByIdAsync(id, cancellationToken);
|
||||||
|
|
||||||
public virtual Task<IList<GwRoute>> GetAllAsync(CancellationToken cancellationToken = default)
|
public virtual Task<GwTenantRoute?> FindByTenantCodeAsync(string tenantCode, CancellationToken cancellationToken = default)
|
||||||
|
=> _store.FindByTenantCodeAsync(tenantCode, cancellationToken);
|
||||||
|
|
||||||
|
public virtual Task<IList<GwTenantRoute>> GetAllAsync(CancellationToken cancellationToken = default)
|
||||||
=> _store.GetAllAsync(cancellationToken);
|
=> _store.GetAllAsync(cancellationToken);
|
||||||
|
|
||||||
public virtual Task<IdentityResult> CreateRouteAsync(GwRoute route, CancellationToken cancellationToken = default)
|
public virtual Task<IdentityResult> CreateRouteAsync(GwTenantRoute route, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
route.CreatedTime = DateTime.UtcNow;
|
route.CreatedTime = DateTime.UtcNow;
|
||||||
return _store.CreateAsync(route, cancellationToken);
|
return _store.CreateAsync(route, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual Task<IdentityResult> UpdateRouteAsync(GwRoute route, CancellationToken cancellationToken = default)
|
public virtual Task<IdentityResult> UpdateRouteAsync(GwTenantRoute route, CancellationToken cancellationToken = default)
|
||||||
=> _store.UpdateAsync(route, cancellationToken);
|
=> _store.UpdateAsync(route, cancellationToken);
|
||||||
|
|
||||||
public virtual Task<IdentityResult> DeleteRouteAsync(GwRoute route, CancellationToken cancellationToken = default)
|
public virtual Task<IdentityResult> DeleteRouteAsync(GwTenantRoute route, CancellationToken cancellationToken = default)
|
||||||
=> _store.DeleteAsync(route, cancellationToken);
|
=> _store.DeleteAsync(route, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,37 +11,45 @@ public class RouteStore<TContext> : IRouteStore
|
|||||||
where TContext : PlatformDbContext
|
where TContext : PlatformDbContext
|
||||||
{
|
{
|
||||||
private readonly TContext _context;
|
private readonly TContext _context;
|
||||||
private readonly DbSet<GwRoute> _routes;
|
private readonly DbSet<GwTenantRoute> _routes;
|
||||||
|
|
||||||
public RouteStore(TContext context)
|
public RouteStore(TContext context)
|
||||||
{
|
{
|
||||||
_context = context;
|
_context = context;
|
||||||
_routes = context.GwRoutes;
|
_routes = context.GwTenantRoutes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose() { }
|
public void Dispose() { }
|
||||||
|
|
||||||
public virtual Task<GwRoute?> FindByIdAsync(string? id, CancellationToken cancellationToken = default)
|
public virtual Task<GwTenantRoute?> FindByIdAsync(string? id, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
if (id == null) return Task.FromResult<GwRoute?>(null);
|
if (id == null) return Task.FromResult<GwTenantRoute?>(null);
|
||||||
return _routes.FirstOrDefaultAsync(r => r.Id == id, cancellationToken);
|
return _routes.FirstOrDefaultAsync(r => r.Id == id, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual Task<GwRoute?> FindByClusterIdAsync(string clusterId, CancellationToken cancellationToken = default)
|
public virtual Task<GwTenantRoute?> FindByTenantCodeAsync(string tenantCode, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
return _routes.FirstOrDefaultAsync(r => r.TenantCode == tenantCode && !r.IsDeleted, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual Task<GwTenantRoute?> FindByClusterIdAsync(string clusterId, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
return _routes.FirstOrDefaultAsync(r => r.ClusterId == clusterId && !r.IsDeleted, cancellationToken);
|
return _routes.FirstOrDefaultAsync(r => r.ClusterId == clusterId && !r.IsDeleted, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual async Task<IList<GwRoute>> GetAllAsync(CancellationToken cancellationToken = default)
|
public virtual async Task<IList<GwTenantRoute>> GetAllAsync(CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
return await _routes.Where(r => !r.IsDeleted).ToListAsync(cancellationToken);
|
return await _routes.Where(r => !r.IsDeleted).ToListAsync(cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual async Task<IList<GwRoute>> GetPagedAsync(int page, int pageSize,
|
public virtual async Task<IList<GwTenantRoute>> GetPagedAsync(int page, int pageSize, string? tenantCode = null,
|
||||||
string? serviceName = null, RouteStatus? status = null, CancellationToken cancellationToken = default)
|
string? serviceName = null, RouteStatus? status = null, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var query = _routes.AsQueryable();
|
var query = _routes.AsQueryable();
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(tenantCode))
|
||||||
|
query = query.Where(r => r.TenantCode.Contains(tenantCode));
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(serviceName))
|
if (!string.IsNullOrEmpty(serviceName))
|
||||||
query = query.Where(r => r.ServiceName.Contains(serviceName));
|
query = query.Where(r => r.ServiceName.Contains(serviceName));
|
||||||
|
|
||||||
@ -56,11 +64,14 @@ public class RouteStore<TContext> : IRouteStore
|
|||||||
.ToListAsync(cancellationToken);
|
.ToListAsync(cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual async Task<int> GetCountAsync(string? serviceName = null,
|
public virtual async Task<int> GetCountAsync(string? tenantCode = null, string? serviceName = null,
|
||||||
RouteStatus? status = null, CancellationToken cancellationToken = default)
|
RouteStatus? status = null, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var query = _routes.AsQueryable();
|
var query = _routes.AsQueryable();
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(tenantCode))
|
||||||
|
query = query.Where(r => r.TenantCode.Contains(tenantCode));
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(serviceName))
|
if (!string.IsNullOrEmpty(serviceName))
|
||||||
query = query.Where(r => r.ServiceName.Contains(serviceName));
|
query = query.Where(r => r.ServiceName.Contains(serviceName));
|
||||||
|
|
||||||
@ -70,14 +81,14 @@ public class RouteStore<TContext> : IRouteStore
|
|||||||
return await query.Where(r => !r.IsDeleted).CountAsync(cancellationToken);
|
return await query.Where(r => !r.IsDeleted).CountAsync(cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual async Task<IdentityResult> CreateAsync(GwRoute route, CancellationToken cancellationToken = default)
|
public virtual async Task<IdentityResult> CreateAsync(GwTenantRoute route, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
_routes.Add(route);
|
_routes.Add(route);
|
||||||
await _context.SaveChangesAsync(cancellationToken);
|
await _context.SaveChangesAsync(cancellationToken);
|
||||||
return IdentityResult.Success;
|
return IdentityResult.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual async Task<IdentityResult> UpdateAsync(GwRoute route, CancellationToken cancellationToken = default)
|
public virtual async Task<IdentityResult> UpdateAsync(GwTenantRoute route, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
route.UpdatedTime = DateTime.UtcNow;
|
route.UpdatedTime = DateTime.UtcNow;
|
||||||
_routes.Update(route);
|
_routes.Update(route);
|
||||||
@ -85,7 +96,7 @@ public class RouteStore<TContext> : IRouteStore
|
|||||||
return IdentityResult.Success;
|
return IdentityResult.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual async Task<IdentityResult> DeleteAsync(GwRoute route, CancellationToken cancellationToken = default)
|
public virtual async Task<IdentityResult> DeleteAsync(GwTenantRoute route, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
// 软删除
|
// 软删除
|
||||||
route.IsDeleted = true;
|
route.IsDeleted = true;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user