pan
2025-11-16 cf83e0828b286b61b69a15005e6247d8b03f4cd8
ÏîÄ¿´úÂë/WMSÎÞ²Ö´¢°æ/WIDESEA_WMSServer/WIDESEA_StockService/StockInfoService.cs
@@ -87,15 +87,25 @@
        /// <param name="needQuantity"></param>
        /// <param name="residueQuantity"></param>
        /// <returns></returns>
        public List<Dt_StockInfo> GetOutboundStocks(List<Dt_StockInfo> stockInfos, string materielCode, decimal needQuantity, out decimal residueQuantity)
        public (List<Dt_StockInfo>, Dictionary<int, decimal>) GetOutboundStocks(List<Dt_StockInfo> stockInfos, string materielCode, decimal needQuantity, out decimal residueQuantity)
        {
            List<Dt_StockInfo> outStocks = new List<Dt_StockInfo>();
            // æŒ‰å…ˆè¿›å…ˆå‡ºæŽ’序(按条码的生产日期)
            Dictionary<int, decimal> stockAllocations = new Dictionary<int, decimal>(); // è®°å½•每个库存明细的分配数量
            // æŒ‰å…ˆè¿›å…ˆå‡ºæŽ’序所有相关的库存明细
            var sortedStockDetails = stockInfos
                .SelectMany(x => x.Details)
                .Where(x => x.MaterielCode == materielCode && x.StockQuantity > x.OutboundQuantity)
                .OrderBy(x => x.ProductionDate).ThenBy(x => x.StockId)
                .Where(x => x.MaterielCode == materielCode &&
                           x.StockQuantity > x.OutboundQuantity) // æœ‰å¯ç”¨åº“å­˜
                .OrderBy(x => x.ProductionDate) // æŒ‰ç”Ÿäº§æ—¥æœŸæŽ’序,先进先出
                .ThenBy(x => x.StockId)         // ç›¸åŒç”Ÿäº§æ—¥æœŸæŒ‰åº“å­˜ID排序
                .ToList();
            if (!sortedStockDetails.Any())
            {
                residueQuantity = needQuantity;
                return (outStocks, stockAllocations);
            }
            // è®¡ç®—总可用库存
            var stockTotalQuantity = sortedStockDetails.Sum(x => x.StockQuantity - x.OutboundQuantity);
@@ -103,6 +113,7 @@
            if (stockTotalQuantity < needQuantity)
            {
                residueQuantity = needQuantity - stockTotalQuantity;
            }
            else
            {
@@ -111,17 +122,22 @@
            decimal remainingNeed = needQuantity;
            // æŒ‰æ¡ç åˆ†é…åº“å­˜
            // æŒ‰å…ˆè¿›å…ˆå‡ºé¡ºåºåˆ†é…åº“å­˜
            foreach (var detail in sortedStockDetails)
            {
                if (remainingNeed <= 0) break;
                decimal availableQuantity = detail.StockQuantity - detail.OutboundQuantity;
                if (availableQuantity <= 0) continue;
                decimal allocateQuantity = Math.Min(availableQuantity, remainingNeed);
                // æ›´æ–°å‡ºåº“数量
                detail.OutboundQuantity += allocateQuantity;
                remainingNeed -= allocateQuantity;
                // è®°å½•分配数量
                stockAllocations[detail.Id] = allocateQuantity;
                // å¦‚果这个库存还没添加到出库列表中,就添加
                var stockInfo = stockInfos.First(x => x.Id == detail.StockId);
@@ -132,8 +148,9 @@
            }
            residueQuantity = remainingNeed;
            return outStocks;
            return (outStocks, stockAllocations);
        }
        /// <summary>
        /// æ ¹æ®æ¡ç èŽ·å–åº“å­˜ä¿¡æ¯
        /// </summary>