helongyang
2026-03-31 8fcd7a67e4391a5f1fbdb590c2a3f913aeb2a0a0
´úÂë¹ÜÀí/WMS/WIDESEA_WMSServer/WIDESEA_StockService/StockInfoService.cs
@@ -11,6 +11,7 @@
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Common.StockEnum;
using WIDESEA_Common.WareHouseEnum;
using WIDESEA_Core;
using WIDESEA_Core.BaseServices;
using WIDESEA_Core.Enums;
@@ -290,6 +291,84 @@
            residueQuantity = needQuantity;
            return outStocks;
        }
    //PP大卷出库(新)
    public List<Dt_StockInfo> GetOutboundPPStocks(List<Dt_StockInfo> stockInfos, string materielCode, float needQuantity, out float residueQuantity,string targetAddressCode = "")
    {
        List<Dt_StockInfo> outStocks = new List<Dt_StockInfo>();
        stockInfos = stockInfos.OrderBy(x =>
            x.WarehouseId == WarehouseEnum.HA581.ObjToInt()? 0 :
            x.WarehouseId == WarehouseEnum.HA58.ObjToInt()? 1 :
            2
        ).ToList();
        // è®¡ç®—总可用库存(仅统计指定物料编码)
        float stockTotalQuantity = stockInfos
            .Select(x => x.Details
                .Where(d => d.MaterielCode == materielCode)
                .Sum(v => v.StockQuantity - v.OutboundQuantity)
            ).Sum(x => x);
        if (stockTotalQuantity >= needQuantity)//库存够
        {
            int index = 0;
            while (needQuantity > 0 && index < stockInfos.Count)
            {
                Dt_StockInfo stockInfo = stockInfos[index];
                decimal useableStockQuantity = stockInfo.Details
                    .Where(x => x.MaterielCode == materielCode)
                    .Sum(x => (decimal)x.StockQuantity - (decimal)x.OutboundQuantity);
                if (useableStockQuantity < (decimal)needQuantity && useableStockQuantity > 0)
                {
                    // å¯ç”¨é‡ä¸è¶³ï¼Œå…¨éƒ¨å‡ºåº“
                    stockInfo.Details.ForEach(x =>
                    {
                        if (x.MaterielCode == materielCode)
                            x.OutboundQuantity = x.StockQuantity;
                    });
                    needQuantity = (float)((decimal)needQuantity - useableStockQuantity);
                }
                else if (useableStockQuantity > 0)
                {
                    stockInfo.Details.ForEach(x =>
                    {
                        if (x.StockQuantity > x.OutboundQuantity && x.MaterielCode == materielCode)
                        {
                            decimal currentStock = (decimal)x.StockQuantity;
                            decimal currentOutbound = (decimal)x.OutboundQuantity;
                            decimal currentNeed = (decimal)needQuantity;
                            decimal available = currentStock - currentOutbound;
                            if (available >= currentNeed)
                            {
                                x.OutboundQuantity = (float)(currentOutbound + currentNeed);
                                needQuantity = 0;
                            }
                            else
                            {
                                needQuantity = (float)(currentNeed - available);
                                x.OutboundQuantity = x.StockQuantity;
                            }
                        }
                    });
                }
                // ä»…将有实际出库的库存加入结果集
                if (useableStockQuantity > 0)
                    {
                        stockInfo.Remark = targetAddressCode;
                        outStocks.Add(stockInfo);
                    }
                index++;
            }
        }
        else
        {
            throw new Exception("库存不足");
        }
        residueQuantity = needQuantity;
        return outStocks;
    }
        public List<Dt_StockInfo> GetUseableStocks(string materielCode, string batchNo, int warehoseId)
        {
@@ -301,6 +380,13 @@
            return BaseDal.GetStockInfos(materielCode, batchNo, locationCodes);
        }
        //PP大卷出库(新)
        public List<Dt_StockInfo> GetUseablePPStocks(string materielCode, string batchNo, int warehoseId)
        {
            List<string> locationCodes = _basicRepository.LocationInfoRepository.GetCanOutPPLocationCodes(warehoseId);
            return BaseDal.GetStockInfos(materielCode, batchNo, locationCodes);
        }
        public List<Dt_StockInfo> GetUseableStocks(string materielCode, string batchNo, string palletcode, int warehoseId)
        {