using Fake.DependencyInjection; using Oms.Domain.OrdersAggregate.Entities; using Oms.Domain.OrdersAggregate.Repositories; using Oms.SqlSugarCore.Repositories; namespace Oms.SqlSugarCore.Orders; public class OrderFileRepository : OmsSqlSugarRepository, IOrderFileRepository, IScopedDependency { public Task> GetByOrderIdAsync(int orderId, CancellationToken cancellationToken = default) => GetListAsync( x => x.OrderId == orderId, cancellationToken: cancellationToken); public Task GetByOrderAndTypeAsync( int orderId, string fileType, CancellationToken cancellationToken = default) => FirstOrDefaultAsync( x => x.OrderId == orderId && x.FileType == fileType, cancellationToken); public Task> GetByOrderAndTypeListAsync( int orderId, string fileType, CancellationToken cancellationToken = default) => GetListAsync( x => x.OrderId == orderId && x.FileType == fileType, cancellationToken: cancellationToken); public Task> GetByOrderIdsAndTypeAsync( IReadOnlyCollection orderIds, string fileType, CancellationToken cancellationToken = default) { var ids = orderIds?.Where(x => x > 0).Distinct().ToList() ?? []; if (ids.Count == 0) { return Task.FromResult(new List()); } return GetListAsync( x => ids.Contains(x.OrderId) && x.FileType == fileType, cancellationToken: cancellationToken); } public async Task SoftDeleteByOrderAndTypeAsync( int orderId, string fileType, CancellationToken cancellationToken = default) { var list = await GetByOrderAndTypeListAsync(orderId, fileType, cancellationToken); foreach (var item in list) { item.IsDeleted = true; item.UpdateTime = DateTime.Now; await UpdateAsync(item, cancellationToken); } } }