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.Domain.Entitys; using WMS.Web.Domain.Infrastructure; using WMS.Web.Domain.IService.Public; using WMS.Web.Repositories.Configuration; namespace WMS.Web.Repositories { /// /// 箱与任务单绑定(收货)关系表-仓储 /// public class InStockTaskBoxRepositories : IInStockTaskBoxRepositories { private readonly IMapper _mapper; private readonly IServiceProvider _serviceProvider; private readonly RepositoryDbContext _context; private readonly ISingleDataService _singleDataService; private readonly IBasicsRepositories _basicsRepositories; private readonly ILoginRepositories _loginRepositories; private readonly IErpService _erpService; private readonly IErpBasicDataExtendService _erpBasicDataExtendService; public InStockTaskBoxRepositories(RepositoryDbContext context, IMapper mapper, IErpService erpService, IBasicsRepositories basicsRepositories, IServiceProvider serviceProvider, ISingleDataService singleDataService, ILoginRepositories loginRepositories, IErpBasicDataExtendService erpBasicDataExtendService) { _context = context; _mapper = mapper; _erpService = erpService; _basicsRepositories = basicsRepositories; _serviceProvider = serviceProvider; _singleDataService = singleDataService; _loginRepositories = loginRepositories; _erpBasicDataExtendService = erpBasicDataExtendService; } /// /// 集合:根据任务ID /// /// /// public async Task> GetListBy(int taskId) { var entitys = await _context.InstockTaskBox .Include(s => s.Details).Where(x => x.TaskId == taskId).ToListAsync(); return entitys; } /// /// 集合:根据boxIDS /// /// /// public async Task> GetListBy(List boxIds) { var entitys = await _context.InstockTaskBox .Include(s => s.Details).Where(x => boxIds.Contains(x.BoxId)).ToListAsync(); return entitys; } /// /// 集合:根据箱号集合 /// /// /// public async Task> GetListBy(List boxBillNos) { var entitys = await _context.InstockTaskBox .Include(s => s.Details).Where(x => boxBillNos.Contains(x.BoxBillNo)).ToListAsync(); return entitys; } /// /// 实体:箱号ID /// /// /// public async Task GetBy(string boxBillNo) { var entity = await _context.InstockTaskBox .Include(s => s.Details).Where(x => x.BoxBillNo == boxBillNo).FirstOrDefaultAsync(); return entity; } /// /// 实体:箱号和任务单ID /// /// /// public async Task GetBy(string boxBillNo, int? taskId) { var query = _context.InstockTaskBox .Include(s => s.Details).Where(x => x.BoxBillNo == boxBillNo); if (taskId.HasValue) query = query.Where(x => x.TaskId == taskId.Value); return await query.FirstOrDefaultAsync(); } /// /// 批量添加 /// /// /// /// public async Task AddRange(List entitys, bool isTransaction = true) { IDbContextTransaction _transaction = null; if (isTransaction) _transaction = _context.Database.BeginTransaction(); try { if (entitys != null && entitys.Count != 0) { await _context.InstockTaskBox.AddRangeAsync(entitys); await _context.SaveChangesAsync(); } if (_transaction != null) _transaction.Commit(); return true; } catch { if (_transaction != null) _transaction.Rollback(); return false; } } /// /// 批量删除 /// /// /// public async Task DeleteRange(List ids, bool isTransaction = true) { IDbContextTransaction _transaction = null; if (isTransaction) _transaction = _context.Database.BeginTransaction(); try { var list = await _context.InstockTaskBox.Include(x => x.Details) .Where(f => ids.Contains(f.Id)).ToListAsync(); _context.InstockTaskBox.RemoveRange(list); await _context.SaveChangesAsync(); if (_transaction != null) _transaction.Commit(); } catch (Exception ex) { if (_transaction != null) _transaction.Rollback(); return false; } return true; } } }