feat: 配送单查询支持tenantId可选过滤

This commit is contained in:
2026-01-29 13:30:49 +00:00
parent a035334c94
commit bb3bb842bc
9 changed files with 120 additions and 48 deletions

View File

@@ -23,6 +23,16 @@ public sealed class EfDeliveryRepository(TakeoutAdminDbContext context) : IDeliv
.FirstOrDefaultAsync(cancellationToken);
}
/// <inheritdoc />
public Task<DeliveryOrder?> FindByIdAsync(long deliveryOrderId, CancellationToken cancellationToken = default)
{
// 1. 按主键查询(跨租户)
return context.DeliveryOrders
.AsNoTracking()
.Where(x => x.Id == deliveryOrderId)
.FirstOrDefaultAsync(cancellationToken);
}
/// <inheritdoc />
public Task<DeliveryOrder?> FindByOrderIdAsync(long orderId, long tenantId, CancellationToken cancellationToken = default)
{
@@ -84,6 +94,34 @@ public sealed class EfDeliveryRepository(TakeoutAdminDbContext context) : IDeliv
.ToListAsync(cancellationToken);
}
/// <inheritdoc />
public async Task<IReadOnlyList<DeliveryOrder>> SearchAsync(long? tenantId, DeliveryStatus? status, long? orderId, CancellationToken cancellationToken = default)
{
// 1. 构建查询(可选租户过滤)
var query = context.DeliveryOrders.AsNoTracking();
if (tenantId.HasValue)
{
query = query.Where(x => x.TenantId == tenantId.Value);
}
// 2. (空行后) 可选过滤:配送状态
if (status.HasValue)
{
query = query.Where(x => x.Status == status.Value);
}
// 3. (空行后) 可选过滤:订单标识
if (orderId.HasValue)
{
query = query.Where(x => x.OrderId == orderId.Value);
}
// 4. (空行后) 排序并返回
return await query
.OrderByDescending(x => x.CreatedAt)
.ToListAsync(cancellationToken);
}
/// <inheritdoc />
public Task UpdateDeliveryOrderAsync(DeliveryOrder deliveryOrder, CancellationToken cancellationToken = default)
{