using AutoMapper; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Storage; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using WMS.Web.Core.Dto.OutStock; using WMS.Web.Domain.Entitys; using WMS.Web.Domain.Infrastructure; using WMS.Web.Repositories.Configuration; namespace WMS.Web.Repositories { public class OutStockRepositories: IOutStockRepositories { private readonly IMapper _mapper; private readonly IServiceProvider _serviceProvider; private readonly RepositoryDbContext _context; public OutStockRepositories(RepositoryDbContext context, IMapper mapper, IServiceProvider serviceProvider) { _context = context; _mapper = mapper; _serviceProvider = serviceProvider; } /// /// 新增 /// /// /// /// public async Task Add(OutStock entity, bool isTransaction = true) { IDbContextTransaction _transaction = null; if (isTransaction) _transaction = _context.Database.BeginTransaction(); try { await _context.OutStock.AddAsync(entity); await _context.SaveChangesAsync(); //if (string.IsNullOrEmpty(entity.OutSourcFeedNo)) //{ // entity.GenerateNo(); // await _context.SaveChangesAsync(); //} if (_transaction != null) _transaction.Commit(); return entity; } catch (Exception ex) { if (_transaction != null) _transaction.Rollback(); return null; } } /// /// 列表 /// /// /// public async Task<(List list, int total)> GetListAsync(OutStockQueryRequest dto) { var query = _context.OutStock .OrderByDescending(o => o.Id) .Where(adv => 1 == 1); if (dto.CreateBeginDate != null) query = query.Where(w => w.CreateTime >= dto.CreateBeginDate); if (dto.CreateEndDate != null) query = query.Where(w => w.CreateTime <= dto.CreateEndDate); //组装 int total = await query.CountAsync(); var list = await query.Select(s => new OutStockQueryInfoResponse() { #region dto组装 Id = 0, Status = "", Type = "", Creator = "", CreateTime=s.CreateTime, SuccessSync = s.SuccessSync, Stock = "", SourceBillNo="", SaleBillNo = "", DeliveryOrg = "", ReceiptCustomer = "", MaterialName = "", MaterialNumber = "", Specifications = "", Qty=0 #endregion }).Skip((dto.PageNo - 1) * dto.PageSize).Take(dto.PageSize).ToListAsync(); return (list, total); } } }