using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Reflection;
|
using System.Text;
|
using System.Threading.Tasks;
|
using WIDESEA_Core;
|
using WIDESEA_Core.BaseRepository;
|
using WIDESEA_Core.BaseServices;
|
using WIDESEA_Core.Enums;
|
using WIDESEA_Core.Helper;
|
using WIDESEA_DTO.Stock;
|
using WIDESEA_IBasicRepository;
|
using WIDESEA_IBasicService;
|
using WIDESEA_IOutboundRepository;
|
using WIDESEA_IOutboundService;
|
using WIDESEA_IRecordService;
|
using WIDESEA_IStockRepository;
|
using WIDESEA_IStockService;
|
using WIDESEA_Model.Models;
|
using WIDESEA_StockRepository;
|
|
namespace WIDESEA_OutboundService
|
{
|
public partial class OutboundOrderDetailService : ServiceBase<Dt_OutboundOrderDetail, IOutboundOrderDetailRepository>, IOutboundOrderDetailService
|
{
|
private readonly IUnitOfWorkManage _unitOfWorkManage;
|
|
private readonly IStockService _stockService;
|
private readonly IBasicService _basicService;
|
private readonly IRecordService _recordService;
|
private readonly IOutboundRepository _outboundRepository;
|
private readonly IOutStockLockInfoService _outStockLockInfoService;
|
|
public IOutboundOrderDetailRepository Repository => BaseDal;
|
|
public OutboundOrderDetailService(IOutboundOrderDetailRepository BaseDal, IUnitOfWorkManage unitOfWorkManage, IStockService stockService, IBasicService basicService, IRecordService recordService, IOutboundRepository outboundRepository, IOutStockLockInfoService outStockLockInfoService) : base(BaseDal)
|
{
|
_unitOfWorkManage = unitOfWorkManage;
|
_stockService = stockService;
|
_basicService = basicService;
|
_recordService = recordService;
|
_outboundRepository = outboundRepository;
|
_outStockLockInfoService = outStockLockInfoService;
|
}
|
|
public (List<Dt_StockInfo>, Dt_OutboundOrderDetail, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>, Dt_OutboundOrder) AssignStockOutbound(Dt_OutboundOrderDetail outboundOrderDetail)
|
{
|
Dt_OutboundOrder outboundOrder = _outboundRepository.OutboundOrderRepository.QueryFirst(x => x.Id == outboundOrderDetail.OrderId);
|
List<Dt_StockInfo> outStocks = new List<Dt_StockInfo>();
|
List<string> LocationCodes = new List<string>();
|
List<Dt_OutStockLockInfo> outStockLockInfos = new List<Dt_OutStockLockInfo>();
|
List<Dt_LocationInfo> locationInfos = new List<Dt_LocationInfo>();
|
return (outStocks, outboundOrderDetail, outStockLockInfos, locationInfos, outboundOrder);
|
}
|
|
public (List<Dt_StockInfo>, List<Dt_OutboundOrderDetail>, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>, Dt_OutboundOrder) AssignStockOutbound(List<Dt_OutboundOrderDetail> outboundOrderDetails)
|
{
|
if (outboundOrderDetails.GroupBy(x => x.OrderId).Count() > 1)
|
{
|
throw new Exception($"请勿同时操作多个单据明细");
|
}
|
Dt_OutboundOrder outboundOrder = _outboundRepository.OutboundOrderRepository.QueryFirst(x => x.Id == outboundOrderDetails.FirstOrDefault().OrderId);
|
List<Dt_StockInfo> outStocks = new List<Dt_StockInfo>();
|
List<string> LocationCodes = new List<string>();
|
List<Dt_OutStockLockInfo> outStockLockInfos = new List<Dt_OutStockLockInfo>();
|
List<Dt_LocationInfo> locationInfos = new List<Dt_LocationInfo>();
|
foreach (var item in outboundOrderDetails)
|
{
|
var StockSelectViews = BaseDal.QueryTabs<Dt_StockInfo, Dt_StockInfoDetail, StockSelectViewDTO>((a, b) => a.Id == b.StockId, (a, b) => new StockSelectViewDTO
|
{
|
LocationCode = a.LocationCode,
|
MaterielCode = b.MaterielCode,
|
MaterielName = b.MaterielName,
|
PalletCode = a.PalletCode,
|
UseableQuantity = b.StockQuantity,
|
BatchNo = b.BatchNo,
|
InDate = a.InDate
|
}, a => a.StockStatus == StockStatusEmun.已入库.ObjToInt(), b => b.Status == StockStatusEmun.已入库.ObjToInt() && b.MaterielCode == item.MaterielCode, x => true).GroupBy(x => x.LocationCode).Select(x => new StockSelectViewDTO
|
{
|
LocationCode = x.FirstOrDefault()?.LocationCode ?? "",
|
MaterielCode = x.FirstOrDefault()?.MaterielCode ?? "",
|
MaterielName = x.FirstOrDefault()?.MaterielName ?? "",
|
//PalletCode = string.Join(",", x.Select(x => x.PalletCode).ToList()),
|
PalletCode = x.Select(x => x.PalletCode).ToList().Aggregate((i, j) => i + "," + j),
|
UseableQuantity = x.Sum(x => x.UseableQuantity),
|
BatchNo = x.FirstOrDefault()?.BatchNo ?? "",
|
InDate = x.FirstOrDefault()?.InDate
|
}).ToList();
|
if (StockSelectViews.Count < 1) throw new Exception($"未找到可分配库存");
|
StockSelectViewDTO? stockSelectView = StockSelectViews.Where(x => x.UseableQuantity == item.OrderQuantity)?.OrderBy(x => x.InDate).First();
|
if (stockSelectView == null)
|
{
|
throw new Exception($"未找到可分配库存");
|
}
|
item.LockQuantity = stockSelectView.UseableQuantity;
|
item.OrderDetailStatus = OrderDetailStatusEnum.Outbound.ObjToInt();
|
List<Dt_StockInfo> dt_StockInfos = _stockService.StockInfoService.Repository.QueryData(x => x.LocationCode == stockSelectView.LocationCode);
|
dt_StockInfos.ForEach(x =>
|
{
|
x.StockStatus = StockStatusEmun.出库中.ObjToInt();
|
});
|
outboundOrder.OrderStatus = OutboundStatusEnum.出库中.ObjToInt();
|
outStockLockInfos.AddRange(_outStockLockInfoService.GetOutStockLockInfo(outboundOrder, item, dt_StockInfos, BatchNo: stockSelectView.BatchNo));
|
outStocks.AddRange(dt_StockInfos);
|
LocationCodes.Add(stockSelectView.LocationCode);
|
}
|
locationInfos.AddRange(_basicService.LocationInfoService.Repository.GetLocationInfos(LocationCodes));
|
locationInfos.ForEach(x =>
|
{
|
x.LocationStatus = LocationStatusEnum.Outbounding.ObjToInt();
|
});
|
return (outStocks, outboundOrderDetails, outStockLockInfos, locationInfos, outboundOrder);
|
}
|
}
|
}
|