From 6a17bde61e85c7dbe0dc441ad3faf057ff44d66f Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期二, 14 一月 2025 14:58:42 +0800
Subject: [PATCH] 1

---
 代码管理/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundOrderDetailService.cs |  110 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 107 insertions(+), 3 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundOrderDetailService.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundOrderDetailService.cs"
index 26e345a..c53d8e3 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundOrderDetailService.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundOrderDetailService.cs"
@@ -1,4 +1,5 @@
-锘縰sing OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
+锘縰sing MailKit.Search;
+using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -47,7 +48,21 @@
             _basicService = basicService;
             _recordService = recordService;
         }
-
+        public WebResponseContent GetOutboundOrderDetails(SaveModel saveModel)
+        {
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                string orderNo = saveModel.MainData["orderNo"].ToString();
+                Dt_OutboundOrder inboundOrder = Db.Queryable<Dt_OutboundOrder>().Where(x => x.OrderNo == orderNo).Includes(x => x.Details).First();
+                content.OK(data: inboundOrder.Details);
+            }
+            catch (Exception ex)
+            {
+                content.Error(ex.Message);
+            }
+            return content;
+        }
         /// <summary>
         /// 閿佸畾搴撳瓨锛岀敱绯荤粺鍒嗛厤(浠呴�昏緫杩愮畻锛屼笉鐢熸垚浠诲姟锛屼笉淇敼鏁版嵁搴撴暟鎹�)
         /// </summary>
@@ -149,7 +164,7 @@
         }
 
         /// <summary>
-        /// 
+        /// 鍗曚釜鍑哄簱鍗曟槑缁嗗簱瀛樺垎閰�
         /// </summary>
         /// <param name="outboundOrderDetail"></param>
         /// <param name="stockSelectViews"></param>
@@ -203,6 +218,87 @@
             List<Dt_LocationInfo> locationInfos = _basicService.LocationInfoService.Repository.GetLocationInfos(outStocks.Select(x => x.LocationCode).ToList());
 
             return (outStocks, outboundOrderDetail, outStockLockInfos, locationInfos);
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="outboundOrderDetails"></param>
+        /// <returns></returns>
+        public (List<Dt_StockInfo>, List<Dt_OutboundOrderDetail>, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>) AssignStockOutbound(List<Dt_OutboundOrderDetail> outboundOrderDetails)
+        {
+            if (!outboundOrderDetails.Any())
+            {
+                throw new Exception($"鏈壘鍒板嚭搴撳崟鏄庣粏淇℃伅");
+            }
+
+            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<Dt_OutboundOrderDetail> groupDetails = outboundOrderDetails.GroupBy(x => new { x.MaterielCode, x.BatchNo }).Select(x => new Dt_OutboundOrderDetail { OrderQuantity = x.Sum(v => v.OrderQuantity) - x.Sum(v => v.LockQuantity), MaterielCode = x.Key.MaterielCode, BatchNo = x.Key.BatchNo, }).ToList();
+
+            List<Dt_OutStockLockInfo> outStockLockInfos = new List<Dt_OutStockLockInfo>();
+            List<Dt_LocationInfo> locationInfos = new List<Dt_LocationInfo>();
+            foreach (var item in groupDetails)
+            {
+                float originalNeedQuantity = item.OrderQuantity;
+
+                float needQuantity = originalNeedQuantity;
+
+                List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.GetUseableStocks(item.MaterielCode, item.BatchNo, outboundOrder.WarehouseId);
+                if (!stockInfos.Any())
+                {
+                    throw new Exception($"鏈壘鍒板彲鍒嗛厤搴撳瓨");
+                }
+                List<Dt_StockInfo> autoAssignStocks = _stockService.StockInfoService.GetOutboundStocks(stockInfos, item.MaterielCode, needQuantity, out float residueQuantity);
+                item.LockQuantity += needQuantity - residueQuantity;
+                outStocks.AddRange(autoAssignStocks);
+                float assignQuantity = needQuantity - residueQuantity;
+
+                List<Dt_OutboundOrderDetail> details = outboundOrderDetails.Where(x => !string.IsNullOrEmpty(x.BatchNo) ? x.BatchNo == item.BatchNo : true && x.MaterielCode == item.MaterielCode).ToList();
+
+                for (int i = 0; i < details.Count; i++)
+                {
+                    float orderQuantity = details[i].OrderQuantity;
+                    for (int j = 0; j < autoAssignStocks.Count; j++)
+                    {
+                        float detailAssignQuantity = outStockLockInfos.Where(x => !string.IsNullOrEmpty(x.BatchNo) ? x.BatchNo == item.BatchNo : true && x.MaterielCode == item.MaterielCode && x.OrderDetailId == details[i].Id).Sum(x => x.AssignQuantity);//鍑哄簱璁㈠崟鏄庣粏宸插垎閰嶆暟閲�
+
+                        float palletAssignQuantity = outStockLockInfos.Where(x => x.BatchNo == item.BatchNo && x.MaterielCode == item.MaterielCode && x.PalletCode == autoAssignStocks[j].PalletCode).Sum(x => x.AssignQuantity);//鍑哄簱璇︽儏宸插垎閰嶆暟閲�
+                        if (string.IsNullOrEmpty(item.BatchNo))
+                        {
+                            palletAssignQuantity = outStockLockInfos.Where(x => x.MaterielCode == item.MaterielCode && x.PalletCode == autoAssignStocks[j].PalletCode).Sum(x => x.AssignQuantity);//鍑哄簱璇︽儏宸插垎閰嶆暟閲�
+                        }
+                        float palletOutboundQuantity = autoAssignStocks[j].Details.Sum(x => x.OutboundQuantity);
+                        if (palletAssignQuantity < palletOutboundQuantity)//濡傛灉鍑哄簱璇︽儏宸插垎閰嶆暟閲忓皬浜庢墭鐩樺凡鍒嗛厤鏁伴噺锛屽垯鍙互缁х画娣诲姞璇ユ墭鐩樺嚭搴撲俊鎭�
+                        {
+                            float orderDetailNeedQuantity = details[i].OrderQuantity - detailAssignQuantity;
+                            if (orderDetailNeedQuantity > autoAssignStocks[j].Details.Sum(x => x.OutboundQuantity) - palletAssignQuantity)
+                            {
+                                details[i].LockQuantity += autoAssignStocks[j].Details.Sum(x => x.OutboundQuantity) - palletAssignQuantity;
+                                Dt_OutStockLockInfo outStockLockInfo = _outStockLockInfoService.GetOutStockLockInfo(outboundOrder, details[i], autoAssignStocks[j], autoAssignStocks[j].Details.Sum(x => x.OutboundQuantity) - palletAssignQuantity);
+                                outStockLockInfos.Add(outStockLockInfo);
+                            }
+                            else
+                            {
+                                Dt_OutStockLockInfo outStockLockInfo = _outStockLockInfoService.GetOutStockLockInfo(outboundOrder, details[i], autoAssignStocks[j], details[i].OrderQuantity - details[i].LockQuantity);
+                                outStockLockInfos.Add(outStockLockInfo);
+                                details[i].LockQuantity = details[i].OrderQuantity;
+                                break;
+                            }
+
+                        }
+                    }
+                }
+
+
+                locationInfos.AddRange(_basicService.LocationInfoService.Repository.GetLocationInfos(outStocks.Select(x => x.LocationCode).ToList()));
+            }
+
+            return (outStocks, outboundOrderDetails, outStockLockInfos, locationInfos);
         }
 
         /// <summary>
@@ -316,6 +412,14 @@
                 List<Dt_OutStockLockInfo> addOutStockLockInfos = outStockLockInfos.Where(x => x.Id == 0).ToList();
                 if (addOutStockLockInfos != null && addOutStockLockInfos.Any())
                 {
+                    if (tasks != null)
+                    {
+                        addOutStockLockInfos.ForEach(x =>
+                        {
+                            x.TaskNum = tasks.FirstOrDefault(v => v.PalletCode == x.PalletCode)?.TaskNum;
+                        });
+                    }
+
                     _outStockLockInfoService.Repository.AddData(addOutStockLockInfos);
                 }
                 List<Dt_OutStockLockInfo> updateOutStockLockInfos = outStockLockInfos.Where(x => x.Id > 0).ToList();

--
Gitblit v1.9.3