成品即时库存
This commit is contained in:
177
src/WMS.Web.Repositories/ProductInventoryRepositories.cs
Normal file
177
src/WMS.Web.Repositories/ProductInventoryRepositories.cs
Normal file
@@ -0,0 +1,177 @@
|
||||
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.Erp.Customer;
|
||||
using WMS.Web.Core.Dto.Erp.Org;
|
||||
using WMS.Web.Core.Dto.Erp;
|
||||
using WMS.Web.Core.Dto.ProductInventory;
|
||||
using WMS.Web.Domain.Entitys;
|
||||
using WMS.Web.Domain.Infrastructure;
|
||||
using WMS.Web.Domain.IService.Public;
|
||||
using WMS.Web.Domain.Values;
|
||||
using WMS.Web.Repositories.Configuration;
|
||||
using WMS.Web.Core.Dto.OutStockTask;
|
||||
using WMS.Web.Domain.Values.Single;
|
||||
using WMS.Web.Core;
|
||||
using NPOI.SS.Formula.Functions;
|
||||
|
||||
namespace WMS.Web.Repositories
|
||||
{
|
||||
/// <summary>
|
||||
/// 成品仓即时库存
|
||||
/// </summary>
|
||||
public class ProductInventoryRepositories : IAllFielRepositories<ProductInventoryQueryRequest>, IProductInventoryRepositories
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private readonly ILoginRepositories _loginRepositories;
|
||||
private readonly IBasicsRepositories _basicsRepositories;
|
||||
private readonly RepositoryDbContext _context;
|
||||
private readonly IErpService _erpService;
|
||||
private readonly ISingleDataService _singleDataService;
|
||||
private readonly IErpBasicDataExtendService _erpBasicDataExtendService;
|
||||
|
||||
public ProductInventoryRepositories(RepositoryDbContext context,
|
||||
IMapper mapper,
|
||||
IErpService erpService,
|
||||
IBasicsRepositories basicsRepositories,
|
||||
ILoginRepositories loginRepositories,
|
||||
IServiceProvider serviceProvider,
|
||||
ISingleDataService singleDataService,
|
||||
IErpBasicDataExtendService erpBasicDataExtendService)
|
||||
{
|
||||
_erpService = erpService;
|
||||
_context = context;
|
||||
_mapper = mapper;
|
||||
_basicsRepositories = basicsRepositories;
|
||||
_serviceProvider = serviceProvider;
|
||||
_loginRepositories = loginRepositories;
|
||||
_singleDataService = singleDataService;
|
||||
_erpBasicDataExtendService = erpBasicDataExtendService;
|
||||
}
|
||||
|
||||
public async Task<bool> AddRange(List<ProductInventory> entitys, bool isTransaction = true)
|
||||
{
|
||||
IDbContextTransaction _transaction = null;
|
||||
if (isTransaction)
|
||||
_transaction = _context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
if (entitys != null && entitys.Count != 0)
|
||||
{
|
||||
await _context.ProductInventory.AddRangeAsync(entitys);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
if (_transaction != null)
|
||||
_transaction.Commit();
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (_transaction != null)
|
||||
_transaction.Rollback();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> Delete(ProductInventoryType type, bool isTransaction = true)
|
||||
{
|
||||
IDbContextTransaction _transaction = null;
|
||||
if (isTransaction)
|
||||
_transaction = _context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var list = await _context.ProductInventory.Where(w => w.Type == type).ToListAsync();
|
||||
_context.RemoveRange(list);
|
||||
|
||||
if (_transaction != null)
|
||||
_transaction.Commit();
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (_transaction != null)
|
||||
_transaction.Rollback();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<(List<ProductInventoryQueryResponse> list, int total, List<decimal> details)> GetListAsync(ProductInventoryQueryRequest dto, int companyId = 0)
|
||||
{
|
||||
if (companyId == 0)
|
||||
companyId = _loginRepositories.CompanyId;
|
||||
#region erp基础资料
|
||||
List<string> mNumber = new List<string>();
|
||||
var materials_result = await _erpService.BillQueryForMaterial();
|
||||
List<ErpMaterialDto> materials = new List<ErpMaterialDto>();
|
||||
if (materials_result.IsSuccess)
|
||||
materials = materials_result.Data.ToList();
|
||||
//物料集合;模糊查询后的物料集合
|
||||
if (!string.IsNullOrEmpty(dto.MaterialNumber))
|
||||
{
|
||||
if (materials != null)
|
||||
mNumber = materials.Where(w => w.MaterialNumber.Contains(dto.MaterialNumber)
|
||||
|| w.MaterialName.Contains(dto.MaterialNumber)
|
||||
|| w.Specifications.Contains(dto.MaterialNumber)
|
||||
).Select(s => s.MaterialNumber).ToList();
|
||||
}
|
||||
|
||||
//取组织
|
||||
var org_result = await _erpService.BillQueryForOrg();
|
||||
List<ErpOrgDto> orgs = new List<ErpOrgDto>();
|
||||
if (org_result.IsSuccess)
|
||||
orgs = org_result.Data.ToList();
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
var query = _context.ProductInventory
|
||||
.OrderByDescending(o => o.Id)
|
||||
.Where(adv => 1 == 1);
|
||||
|
||||
if (!string.IsNullOrEmpty(dto.MaterialNumber))
|
||||
query = query.Where(w => mNumber.Contains(w.MaterialNumber));
|
||||
if (!string.IsNullOrEmpty(dto.Customer))
|
||||
query = query.Where(w => dto.Customer.Contains(w.MaterialNumber));
|
||||
if (!string.IsNullOrEmpty(dto.StockCode))
|
||||
query = query.Where(w => dto.StockCode.Contains(w.StockCode));
|
||||
|
||||
//组装
|
||||
int total = await query.CountAsync();
|
||||
decimal qty = await query.SumAsync(s => s.Qty);
|
||||
decimal beforeQty = await query.SumAsync(s => s.BeforeQty);
|
||||
List<decimal> details = new List<decimal>();
|
||||
details.Add(qty);
|
||||
details.Add(beforeQty);
|
||||
var list = await query.Select(s => new ProductInventoryQueryResponse()
|
||||
{
|
||||
#region dto组装
|
||||
Id = s.Id,
|
||||
Type = s.Type.GetRemark(),
|
||||
Stock = _singleDataService.GetSingleData(SingleAction.StocksJoinOrgCode, companyId, s.StockCode + s.OrgCode),
|
||||
Org = _erpBasicDataExtendService.GetOrgName(orgs, s.OrgCode),
|
||||
MaterialName = _erpBasicDataExtendService.GetMaterialName(materials, s.MaterialNumber),
|
||||
MaterialNumber = s.MaterialNumber,
|
||||
Specifications = _erpBasicDataExtendService.GetMaterialSpecifications(materials, s.MaterialNumber),
|
||||
Batch = s.Batch,
|
||||
Customer = s.Customer,
|
||||
Qty = s.Qty,
|
||||
BeforeQty = s.BeforeQty
|
||||
#endregion
|
||||
|
||||
}).Skip((dto.PageNo - 1) * dto.PageSize).Take(dto.PageSize).ToListAsync();
|
||||
return (list, total, details);
|
||||
}
|
||||
|
||||
public async Task<(object obj, int total)> GetListField(ProductInventoryQueryRequest dto, int companyId)
|
||||
{
|
||||
var (list, count, qty) = await GetListAsync(dto, companyId);
|
||||
return (list, count);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user