118 lines
4.2 KiB
C#
118 lines
4.2 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.Core.Dto;
|
|
using WMS.Web.Core.Help;
|
|
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>
|
|
/// 老ops箱信息
|
|
/// </summary>
|
|
public class BoxRepositories : IBoxRepositories
|
|
{
|
|
private readonly IMapper _mapper;
|
|
private readonly IServiceProvider _serviceProvider;
|
|
private readonly RepositoryDbContext _context;
|
|
private readonly ISingleDataService _singleDataService;
|
|
private readonly ILoginRepositories _loginRepositories;
|
|
private readonly IBasicsRepositories _basicsRepositories;
|
|
|
|
public BoxRepositories(RepositoryDbContext context, IMapper mapper, IServiceProvider serviceProvider,
|
|
ISingleDataService singleDataService, ILoginRepositories loginRepositories, IBasicsRepositories basicsRepositories)
|
|
{
|
|
_context = context;
|
|
_mapper = mapper;
|
|
_serviceProvider = serviceProvider;
|
|
_singleDataService = singleDataService;
|
|
_loginRepositories = loginRepositories;
|
|
_basicsRepositories = basicsRepositories;
|
|
}
|
|
public async Task<Box> Get(int id)
|
|
{
|
|
var entity= await _context.Box.Include(x => x.Details)
|
|
.FirstOrDefaultAsync(f => f.Id.Equals(id));
|
|
|
|
return entity.Clone();
|
|
}
|
|
/// <summary>
|
|
/// 根据箱号查询物料信息
|
|
/// </summary>
|
|
/// <param name="BoxBillNo"></param>
|
|
/// <returns></returns>
|
|
public async Task<BoxResponse> GetBox(string BoxBillNo)
|
|
{
|
|
var entity = await _context.Box.FirstOrDefaultAsync(f => f.BoxBillNo.Equals(BoxBillNo));
|
|
if (entity == null) return null;
|
|
BoxResponse result = new BoxResponse()
|
|
{
|
|
Id = entity.Id,
|
|
SupplierId=entity.SupplierId,
|
|
BoxBillNo = entity.BoxBillNo
|
|
};
|
|
result.Details = await _context.BoxDetails
|
|
.GroupJoin(_context.Box, detail => detail.Fid, order => order.Id, (detail, orders) => new { detail, orders })
|
|
.SelectMany(x => x.orders.DefaultIfEmpty(), (p, order) => new { p.detail, order })
|
|
.Where(w => w.order.BoxBillNo.Equals(BoxBillNo))
|
|
.Select(s => new BoxDetailResponse()
|
|
{
|
|
MaterialId = s.detail.MaterialId,
|
|
MaterialName = "",
|
|
MaterialNumber = "",
|
|
Specifications = "",
|
|
SerialNumbers = s.detail.SerialNumbers,
|
|
SupplierId = s.detail.SupplierId,
|
|
Qty = s.detail.Qty
|
|
})
|
|
.ToListAsync();
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 批量修改
|
|
/// </summary>
|
|
/// <param name="entitys"></param>
|
|
/// <param name="isTransaction"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> EditEntityList(List<Box> 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.Box
|
|
.Include(s => s.Details)
|
|
.Where(f => list.Contains(f.Id)).ToListAsync();
|
|
|
|
_mapper.ToMapList(entitys, res);
|
|
_mapper.ToMapList(entitys.SelectMany(s => s.Details).ToList(), res.SelectMany(s => s.Details).ToList());
|
|
|
|
await _context.SaveChangesAsync();
|
|
if (_transaction != null)
|
|
_transaction.Commit();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (_transaction != null)
|
|
_transaction.Rollback();
|
|
return false;
|
|
}
|
|
return true;
|
|
|
|
}
|
|
}
|
|
}
|