admin/src/Oms.SqlSugarCore/Orders/OrderTaskRepository.cs
2026-04-15 15:25:38 +08:00

41 lines
1.5 KiB
C#

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<OrderTask>, IOrderTaskRepository, IScopedDependency
{
public Task<OrderTask?> GetByCustomerAndIdAsync(long customerId, long id, CancellationToken cancellationToken = default)
{
return FirstOrDefaultAsync(x => !x.IsDeleted && x.CustomerId == customerId && x.Id == id, cancellationToken);
}
public Task<bool> ExistsAsync(long id, CancellationToken cancellationToken = default)
{
return AnyAsync(x => !x.IsDeleted && x.Id == id, cancellationToken);
}
public async Task<List<OrderTaskFail>> GetFailListAsync(long taskId, CancellationToken cancellationToken = default)
{
var db = await GetDbContextAsync(cancellationToken);
return await db.Queryable<OrderTaskFail>()
.Where(x => !x.IsDeleted && x.TaskId == taskId)
.OrderBy(x => x.RowNumber)
.ToListAsync(cancellationToken);
}
public async Task InsertFailListAsync(IEnumerable<OrderTaskFail> failList, CancellationToken cancellationToken = default)
{
var items = failList.ToArray();
if (items.Length == 0)
{
return;
}
var db = await GetDbContextAsync(cancellationToken);
await db.Insertable(items).ExecuteCommandAsync(cancellationToken);
}
}