193 lines
6.9 KiB
C#
193 lines
6.9 KiB
C#
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.Domain.Mappers;
|
||
using WMS.Web.Repositories.Configuration;
|
||
|
||
namespace WMS.Web.Repositories
|
||
{
|
||
/// <summary>
|
||
/// 箱与任务单绑定(收货)关系表-仓储
|
||
/// </summary>
|
||
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;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 集合:根据boxIDS
|
||
/// </summary>
|
||
/// <param name="boxIds"></param>
|
||
/// <returns></returns>
|
||
public async Task<List<InStockTaskBox>> GetListBy(List<int> boxIds)
|
||
{
|
||
var entitys = await _context.InstockTaskBox
|
||
.Include(s => s.Details).Where(x => boxIds.Contains(x.BoxId) && (x.UnBind==null || x.UnBind==false)).ToListAsync();
|
||
return entitys;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 集合:根据箱号集合
|
||
/// </summary>
|
||
/// <param name="boxBillNos"></param>
|
||
/// <returns></returns>
|
||
public async Task<List<InStockTaskBox>> GetListBy(List<string> boxBillNos)
|
||
{
|
||
var entitys = await _context.InstockTaskBox
|
||
.Include(s => s.Details).Where(x => boxBillNos.Contains(x.BoxBillNo) && (x.UnBind == null || x.UnBind == false)).ToListAsync();
|
||
return entitys;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 实体:箱号ID
|
||
/// </summary>
|
||
/// <param name="taskId"></param>
|
||
/// <returns></returns>
|
||
public async Task<InStockTaskBox> GetBy(string boxBillNo)
|
||
{
|
||
var entity = await _context.InstockTaskBox
|
||
.Include(s => s.Details).Where(x => x.BoxBillNo == boxBillNo && (x.UnBind == null || x.UnBind == false)).FirstOrDefaultAsync();
|
||
return entity;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 实体:箱号和任务单ID
|
||
/// </summary>
|
||
/// <param name="taskId"></param>
|
||
/// <returns></returns>
|
||
public async Task<InStockTaskBox> GetBy(string boxBillNo, int? taskId)
|
||
{
|
||
var query = _context.InstockTaskBox
|
||
.Include(s => s.Details).Where(x => x.BoxBillNo == boxBillNo && (x.UnBind == null || x.UnBind == false));
|
||
|
||
if (taskId.HasValue)
|
||
query = query.Where(x => x.TaskId == taskId.Value);
|
||
|
||
return await query.FirstOrDefaultAsync();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 批量添加
|
||
/// </summary>
|
||
/// <param name="entitys"></param>
|
||
/// <param name="isTransaction"></param>
|
||
/// <returns></returns>
|
||
public async Task<bool> AddRange(List<InStockTaskBox> 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;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 批量删除
|
||
/// </summary>
|
||
/// <param name="id"></param>
|
||
/// <returns></returns>
|
||
public async Task<bool> DeleteRange(List<int> 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;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 批量修改
|
||
/// </summary>
|
||
/// <param name="entitys"></param>
|
||
/// <returns></returns>
|
||
public async Task<bool> UpdateRange(List<InStockTaskBox> entitys, bool isTransaction = true)
|
||
{
|
||
IDbContextTransaction _transaction = null;
|
||
if (isTransaction)
|
||
_transaction = _context.Database.BeginTransaction();
|
||
{
|
||
try
|
||
{
|
||
List<int> list = entitys.Select(s => s.Id).ToList();
|
||
var res = await _context.InstockTaskBox.Include(x => x.Details).Where(f => list.Contains(f.Id)).ToListAsync();
|
||
_mapper.Map(entitys, res);
|
||
var tt = await _context.SaveChangesAsync();
|
||
if (_transaction != null)
|
||
_transaction.Commit();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
if (_transaction != null)
|
||
_transaction.Rollback();
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
}
|
||
}
|
||
}
|