using Fake.DependencyInjection; using Oms.Domain.OrdersAggregate.Entities; using Oms.Domain.OrdersAggregate.Repositories; using Oms.SqlSugarCore.Repositories; namespace Oms.SqlSugarCore.Orders; public class OrderTaskRepository : OmsSqlSugarRepository, IOrderTaskRepository, IScopedDependency { public Task GetByCustomerAndIdAsync(long customerId, long id, CancellationToken cancellationToken = default) { return FirstOrDefaultAsync(x => !x.IsDeleted && x.CustomerId == customerId && x.Id == id, cancellationToken); } public Task ExistsAsync(long id, CancellationToken cancellationToken = default) { return AnyAsync(x => !x.IsDeleted && x.Id == id, cancellationToken); } public async Task> GetFailListAsync(long taskId, CancellationToken cancellationToken = default) { var db = await GetDbContextAsync(cancellationToken); return await db.Queryable() .Where(x => !x.IsDeleted && x.TaskId == taskId) .OrderBy(x => x.RowNumber) .ToListAsync(cancellationToken); } public async Task InsertFailListAsync(IEnumerable failList, CancellationToken cancellationToken = default) { var items = failList.ToArray(); if (items.Length == 0) { return; } var db = await GetDbContextAsync(cancellationToken); await db.Insertable(items).ExecuteCommandAsync(cancellationToken); } }