From 8fcd7a67e4391a5f1fbdb590c2a3f913aeb2a0a0 Mon Sep 17 00:00:00 2001
From: helongyang <647556386@qq.com>
Date: 星期二, 31 三月 2026 14:11:23 +0800
Subject: [PATCH] PP平库功能上线,PDA优化,部分问题点优化

---
 代码管理/WMS/WIDESEA_WMSServer/WIDESEA_StockService/StockInfoService.cs |   88 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 87 insertions(+), 1 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_StockService/StockInfoService.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_StockService/StockInfoService.cs"
index 2fe284f..e169788 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_StockService/StockInfoService.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/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,8 +291,86 @@
             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();
 
-        public List<Dt_StockInfo> GetUseableStocks(string materielCode, string batchNo, int warehoseId)
+        // 璁$畻鎬诲彲鐢ㄥ簱瀛橈紙浠呯粺璁℃寚瀹氱墿鏂欑紪鐮侊級
+        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)
         {
             if ((materielCode.Equals("405000585")|| materielCode.Equals("405000831") || materielCode.Equals("405005565") || materielCode.Equals("405405097") || materielCode.Equals("405005461")) && warehoseId == 5)
             {
@@ -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)
         {

--
Gitblit v1.9.3