箱库存-列表接口

This commit is contained in:
tongfei
2023-10-31 15:05:24 +08:00
parent 68f70fa820
commit 1eafbc8503
9 changed files with 413 additions and 2 deletions

View File

@@ -0,0 +1,151 @@
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.Inventory;
using WMS.Web.Core.Internal.Results;
using WMS.Web.Domain.Entitys;
using WMS.Web.Domain.Infrastructure;
using WMS.Web.Domain.IService.Public;
using WMS.Web.Domain.Values.Single;
using WMS.Web.Repositories.Configuration;
namespace WMS.Web.Repositories
{
/// <summary>
/// 箱库存-仓储
/// </summary>
public class BoxInventoryRepositories: IBoxInventoryRepositories
{
private readonly IMapper _mapper;
private readonly IServiceProvider _serviceProvider;
private readonly ILoginRepositories _loginRepositories;
private readonly RepositoryDbContext _context;
private readonly ISingleDataService _singleDataService;
public BoxInventoryRepositories(RepositoryDbContext context,
IMapper mapper,
ILoginRepositories loginRepositories,
IServiceProvider serviceProvider,
ISingleDataService singleDataService)
{
_context = context;
_mapper = mapper;
_serviceProvider = serviceProvider;
_loginRepositories = loginRepositories;
_singleDataService = singleDataService;
}
/// <summary>
/// 列表-分页
/// </summary>
/// <param name="dto"></param>
/// <returns></returns>
public async Task<ResultPagedList<BoxInventoryQueryResponse>> GetPagedList(BoxInventoryQueryRequest dto)
{
var query = _context.BoxInventoryDetails
.GroupJoin(_context.BoxInventory, detail => detail.Fid, order => order.Id, (detail, orders) => new { detail, orders })
.SelectMany(x => x.orders.DefaultIfEmpty(), (p, order) => new { p.detail, order })
.GroupJoin(_context.Box, p => p.order.BoxId, t => t.Id, (p, ts) => new { p.detail,p.order, ts })
.SelectMany(x => x.ts.DefaultIfEmpty(), (p, box) => new { p.detail, p.order, box })
.Where(adv => 1 == 1);
if (!string.IsNullOrEmpty(dto.BoxBillNo))
query = query.Where(w => EF.Functions.Like(w.box.BoxBillNo, "%" + dto.BoxBillNo + "%"));
//if (!string.IsNullOrEmpty(dto.MaterialNumber))
// query = query.Where(w => EF.Functions.Like(w.detail.BillNo, "%" + dto.BillNo + "%"));
if (dto.StockId.HasValue)
query = query.Where(w => w.order.StockId == dto.StockId.Value);
if (dto.SubStockId.HasValue)
query = query.Where(w => w.order.SubStockId == dto.SubStockId.Value);
var response = new ResultPagedList<BoxInventoryQueryResponse>();
int total = await query.CountAsync();
response.TotalCount = total;
var list = await query.Select(s => new BoxInventoryQueryResponse()
{
Id = s.order.Id,
DetailsId = s.detail.Id,
BoxBillNo = s.box.BoxBillNo,
MaterialName = "",
MaterialNumber = "",
Specifications = "",
Stock = _singleDataService.GetSingleData(SingleAction.Stocks, _loginRepositories.CompanyId, s.order.StockId),
SubStock="",
Qty = s.detail.Qty,
}).OrderByDescending(x => x.Id).Skip((dto.PageNo - 1) * dto.PageSize).Take(dto.PageSize).ToListAsync();
response.Data = list;
return response;
}
/// <summary>
/// 批量添加
/// </summary>
/// <param name="entitys"></param>
/// <param name="isTransaction"></param>
/// <returns></returns>
public async Task<bool> AddRange(List<BoxInventory> entitys, bool isTransaction = true)
{
IDbContextTransaction _transaction = null;
if (isTransaction)
_transaction = _context.Database.BeginTransaction();
try
{
if (entitys != null && entitys.Count != 0)
{
await _context.BoxInventory.AddRangeAsync(entitys);
await _context.SaveChangesAsync();
}
if (_transaction != null)
_transaction.Commit();
return true;
}
catch
{
if (_transaction != null)
_transaction.Rollback();
return false;
}
}
/// <summary>
/// 批量修改
/// </summary>
/// <param name="entitys"></param>
/// <returns></returns>
public async Task<bool> UpdateRange(List<BoxInventory> 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.BoxInventory.Include(x => x.Details).Where(f => list.Contains(f.Id)).ToListAsync();
_mapper.Map(entitys, res);
await _context.SaveChangesAsync();
if (_transaction != null)
_transaction.Commit();
}
catch (Exception ex)
{
if (_transaction != null)
_transaction.Rollback();
return false;
}
return true;
}
}
}
}