From 1a1bc81ac1d9ad656e15b409122e23f7f3763293 Mon Sep 17 00:00:00 2001
From: pan <antony1029@163.com>
Date: 星期四, 27 十一月 2025 08:27:41 +0800
Subject: [PATCH] 提交

---
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_DTO/Stock/StockSelectViewDTO.cs                           |    7 
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/Allocate/AllocateOrderController.cs |    4 
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_StockService/StockInfoService.cs                          |  144 +++++++--
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/Inbound/InboundOrderController.cs   |   14 
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_AllocateService/AllocateService.cs                        |   97 ++++--
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundPickingService.cs                 |  161 +++++++---
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_IStockService/IStockInfoService.cs                        |    3 
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs                            |  195 ++++++++----
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_Model/Models/Allocate/Dt_AllocateOrderDetail.cs           |    2 
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundOrderDetailService.cs             |  248 +++++++++++++--
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_OutboundService/WIDESEA_OutboundService.csproj            |    1 
 11 files changed, 656 insertions(+), 220 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_AllocateService/AllocateService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_AllocateService/AllocateService.cs"
index b720756..ae0c484 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_AllocateService/AllocateService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_AllocateService/AllocateService.cs"
@@ -1,4 +1,5 @@
-锘縰sing MailKit.Search;
+锘縰sing Autofac.Core;
+using MailKit.Search;
 using Microsoft.Extensions.Logging;
 using SqlSugar;
 using SqlSugar.Extensions;
@@ -61,7 +62,7 @@
                 {
                     1 => await AddAllocateOrder(allocateOrder),
                     2 => await UpdateAllocateOrder(allocateOrder),
-                    3 => DeleteAllocateOrder(allocateOrder),
+                    3 => await DeleteAllocateOrder(allocateOrder),
 
                     _ => WebResponseContent.Instance.OK(),
                 };
@@ -82,33 +83,7 @@
                 }
                 allocateOrder.OrderNo = CreateCodeByRule(nameof(RuleCodeEnum.AllocateOrderCodeRule));
                 Db.InsertNav(allocateOrder).Include(x => x.Details).ExecuteCommand();
-                if (Enum.TryParse<BusinessTypeEnum>(allocateOrder.BusinessType, out var businessType))
-                {
-                    if (businessType == BusinessTypeEnum.鏅轰粨璋冨閮ㄤ粨搴�)
-                    {
-                        var inboundOrders = ConvertToInboundOrders(allocateOrder);
-                        await _inboundService.InbounOrderService.ReceiveInboundOrder(inboundOrders, 1);
-                    }
-                    else if (businessType == BusinessTypeEnum.澶栭儴浠撳簱璋冩櫤浠� || businessType == BusinessTypeEnum.鏅轰粨璋冩櫤浠�)
-                    {
-                        if (businessType == BusinessTypeEnum.澶栭儴浠撳簱璋冩櫤浠�)
-                        {
-                            allocateOrder.OrderType = InOrderTypeEnum.Allocat.ObjToInt();
-                        }
-                        else if (businessType == BusinessTypeEnum.鏅轰粨璋冩櫤浠�)
-                        {
-                            allocateOrder.OrderType = InOrderTypeEnum.InternalAllocat.ObjToInt();
-                        }
-
-                        var outboundOrders = ConvertToOutboundOrders(allocateOrder);
-                        await _outboundService.OutboundOrderService.ReceiveOutboundOrder(outboundOrders, 1);
-                    }
-                    else
-                    {
-                        // 澶勭悊鏈畾涔夌殑鏋氫妇鍊硷紙濡傛湭鏉ユ柊澧炰絾鏈疄鐜扮殑绫诲瀷锛�
-                        throw new NotSupportedException($"涓嶆敮鎸佺殑涓氬姟绫诲瀷鏋氫妇鍊�: {businessType}");
-                    }
-                }
+                await AddInOutData(allocateOrder);
                 return WebResponseContent.Instance.OK();
             }
             catch (Exception ex)
@@ -117,6 +92,39 @@
                 return WebResponseContent.Instance.Error(ex.Message);
             }
         }
+
+        private async Task AddInOutData(Dt_AllocateOrder allocateOrder)
+        {
+            if (Enum.TryParse<BusinessTypeEnum>(allocateOrder.BusinessType, out var businessType))
+            {
+                if (businessType == BusinessTypeEnum.鏅轰粨璋冨閮ㄤ粨搴�)
+                {
+                    allocateOrder.OrderType = InOrderTypeEnum.Allocat.ObjToInt();
+                    var inboundOrders = ConvertToInboundOrders(allocateOrder);
+                    await _inboundService.InbounOrderService.ReceiveInboundOrder(inboundOrders, 1);
+                }
+                else if (businessType == BusinessTypeEnum.澶栭儴浠撳簱璋冩櫤浠� || businessType == BusinessTypeEnum.鏅轰粨璋冩櫤浠�)
+                {
+                    if (businessType == BusinessTypeEnum.澶栭儴浠撳簱璋冩櫤浠�)
+                    {
+                        allocateOrder.OrderType = InOrderTypeEnum.Allocat.ObjToInt();
+                    }
+                    else if (businessType == BusinessTypeEnum.鏅轰粨璋冩櫤浠�)
+                    {
+                        allocateOrder.OrderType = InOrderTypeEnum.InternalAllocat.ObjToInt();
+                    }
+
+                    var outboundOrders = ConvertToOutboundOrders(allocateOrder);
+                    await _outboundService.OutboundOrderService.ReceiveOutboundOrder(outboundOrders, 1);
+                }
+                else
+                {
+                    // 澶勭悊鏈畾涔夌殑鏋氫妇鍊硷紙濡傛湭鏉ユ柊澧炰絾鏈疄鐜扮殑绫诲瀷锛�
+                    throw new NotSupportedException($"涓嶆敮鎸佺殑涓氬姟绫诲瀷鏋氫妇鍊�: {businessType}");
+                }
+            }
+        }
+
         public async Task<WebResponseContent> UpdateAllocateOrder(Dt_AllocateOrder model)
         {
             try
@@ -196,6 +204,10 @@
                 _allocateOrderDetailRepository.AddData(allocateOrderDetails);
 
                 BaseDal.UpdateData(allocateOrder);
+
+                DeleteInOutData(model.UpperOrderNo, allocateOrder);
+                await AddInOutData(allocateOrder);
+
                 _unitOfWorkManage.CommitTran();
 
 
@@ -209,7 +221,7 @@
             }
         }
 
-        public WebResponseContent DeleteAllocateOrder(Dt_AllocateOrder model)
+        public async Task<WebResponseContent> DeleteAllocateOrder(Dt_AllocateOrder model)
         {
             try
             {
@@ -231,6 +243,9 @@
                     _allocateOrderDetailRepository.DeleteData(item);
                 }
                 BaseDal.DeleteData(allocateOrder);
+
+                DeleteInOutData(model.UpperOrderNo, allocateOrder);
+
                 _unitOfWorkManage.CommitTran();
                 return WebResponseContent.Instance.OK();
             }
@@ -239,6 +254,26 @@
                 _unitOfWorkManage.RollbackTran();
                 _logger.LogInformation("AllocateService DeleteAllocateOrder  err:  " + ex.Message);
                 return WebResponseContent.Instance.Error(ex.Message);
+            }
+        }
+
+        private void DeleteInOutData(string upperOrderNo, Dt_AllocateOrder allocateOrder)
+        {
+            if (Enum.TryParse<BusinessTypeEnum>(allocateOrder.BusinessType, out var businessType))
+            {
+                if (businessType == BusinessTypeEnum.鏅轰粨璋冨閮ㄤ粨搴�)
+                {
+                    _inboundService.InbounOrderService.Db.Deleteable<Dt_InboundOrder>().Where(x => x.UpperOrderNo == upperOrderNo).ExecuteCommand();
+
+                    _inboundService.InboundOrderDetailService.Db.Deleteable<Dt_InboundOrderDetail>()
+                     .Where(p => SqlFunc.Subqueryable<Dt_InboundOrder>().Where(s => s.Id == p.OrderId && s.UpperOrderNo == upperOrderNo).Any()).ExecuteCommand();
+                }
+                else if (businessType == BusinessTypeEnum.澶栭儴浠撳簱璋冩櫤浠� || businessType == BusinessTypeEnum.鏅轰粨璋冩櫤浠�)
+                {
+                    _outboundService.OutboundOrderService.Db.Deleteable<Dt_OutboundOrder>().Where(x => x.UpperOrderNo == upperOrderNo).ExecuteCommand();
+                    _outboundService.OutboundOrderDetailService.Db.Deleteable<Dt_OutboundOrderDetail>()
+                     .Where(p => SqlFunc.Subqueryable<Dt_OutboundOrder>().Where(s => s.Id == p.OrderId && s.UpperOrderNo == upperOrderNo).Any()).ExecuteCommand();
+                }
             }
         }
 
@@ -288,7 +323,7 @@
                 WarehouseId = allocateOrder.WarehouseId,
                 OrderNo = allocateOrder.OrderNo,
                 UpperOrderNo = allocateOrder.UpperOrderNo,
-                OrderType = OutOrderTypeEnum.Allocate.ObjToInt(),
+                OrderType = allocateOrder.OrderType,
                 OrderStatus = allocateOrder.OrderStatus,
                 CreateType = allocateOrder.CreateType,
                 BusinessType = allocateOrder.BusinessType,
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_DTO/Stock/StockSelectViewDTO.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_DTO/Stock/StockSelectViewDTO.cs"
index e529e33..0497a6f 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_DTO/Stock/StockSelectViewDTO.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_DTO/Stock/StockSelectViewDTO.cs"
@@ -21,5 +21,12 @@
 
 
         public string Barcode { get; set; }
+
+
+        public string BatchNo { get; set; }
+        public string SupplyCode { get; set; }
+        public DateTime StockCreateDate { get; set; }
+        public int StockId { get; set; }
+        public int? OrderDetailId { get; set; }
     }
 }
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_IStockService/IStockInfoService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_IStockService/IStockInfoService.cs"
index 34899a9..f5620fc 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_IStockService/IStockInfoService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_IStockService/IStockInfoService.cs"
@@ -13,7 +13,8 @@
         List<Dt_StockInfo> GetStockInfos(string materielCode, string lotNo, string supplyCode, List<string> locationCodes);
 
         List<Dt_StockInfo> GetUseableStocks(string materielCode, string batchNo,string supplyCode);
-       
+
+        Dt_StockInfo GetStockInfoByPalletCode(string palletCode);
         void AddMaterielGroup(Dt_StockInfo stockInfo);
         (List<Dt_StockInfo>, Dictionary<int, decimal>) GetOutboundStocks(List<Dt_StockInfo> stockInfos, string materielCode, decimal needQuantity, out decimal residueQuantity);
 
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_Model/Models/Allocate/Dt_AllocateOrderDetail.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_Model/Models/Allocate/Dt_AllocateOrderDetail.cs"
index c5cf770..73a6f5c 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_Model/Models/Allocate/Dt_AllocateOrderDetail.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_Model/Models/Allocate/Dt_AllocateOrderDetail.cs"
@@ -120,5 +120,7 @@
         /// </summary>
         [SugarColumn(IsNullable = true, ColumnDescription = "鍥炰紶MES")]
         public int ReturnToMESStatus { get; set; } = 0;
+        [SugarColumn(IsNullable = true, ColumnDescription = "杩囨湡鏃ユ湡")]
+        public DateTime ValidDate { get; set; }
     }
 }
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundOrderDetailService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundOrderDetailService.cs"
index 4459d4c..121a74e 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundOrderDetailService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundOrderDetailService.cs"
@@ -336,71 +336,231 @@
         }
 
 
-        public (List<Dt_StockInfo>, Dt_OutboundOrderDetail, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>) AssignStockOutbound(Dt_OutboundOrderDetail outboundOrderDetail, List<StockSelectViewDTO> stockSelectViews)
+        public (List<Dt_StockInfo>, Dt_OutboundOrderDetail, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>)
+       AssignStockOutbound(Dt_OutboundOrderDetail outboundOrderDetail, List<StockSelectViewDTO> stockSelectViews)
         {
+            // 楠岃瘉鐢ㄦ埛閫夋嫨
             (bool, string) checkResult = CheckSelectStockDeital(outboundOrderDetail, stockSelectViews);
             if (!checkResult.Item1) throw new Exception(checkResult.Item2);
 
             Dt_OutboundOrder outboundOrder = _outboundOrderService.Repository.QueryFirst(x => x.Id == outboundOrderDetail.OrderId);
             var originalNeedQuantity = outboundOrderDetail.OrderQuantity - outboundOrderDetail.LockQuantity - outboundOrderDetail.MoveQty;
 
-            var needQuantity = originalNeedQuantity;
+            List<Dt_StockInfo> outStocks = new List<Dt_StockInfo>();
+            List<Dt_OutStockLockInfo> outStockLockInfos = new List<Dt_OutStockLockInfo>();
 
-            List<Dt_StockInfo> outStocks = _stockService.StockInfoService.GetStockInfosByPalletCodes(stockSelectViews.Select(x => x.PalletCode).ToList());
-            var assignQuantity = 0m;
-            outStocks.ForEach(x =>
-            {
-                x.Details.ForEach(v =>
-                {
-                    assignQuantity += v.StockQuantity - v.OutboundQuantity;
-                });
-            });
+            decimal remainingNeedQuantity = originalNeedQuantity;
+            decimal totalAssignedFromUserSelection = 0;
 
-            outboundOrderDetail.LockQuantity += assignQuantity;
-            outStocks.ForEach(x =>
+            // 鎸夊厛杩涘厛鍑烘帓搴忕敤鎴烽�夋嫨鐨勫簱瀛�
+            var userSelectedStocks = _stockService.StockInfoService.GetStockInfosByPalletCodes(
+                stockSelectViews.Select(x => x.PalletCode).ToList());
+
+            var sortedUserSelectedStocks = userSelectedStocks
+                .OrderBy(x => x.CreateDate)
+                .ToList();
+
+            // 鍒嗛厤鐢ㄦ埛閫夋嫨鐨勫簱瀛�
+            foreach (var stock in sortedUserSelectedStocks)
             {
-                x.Details.ForEach(v =>
+                if (remainingNeedQuantity <= 0) break;
+
+                // 鑾峰彇鐢ㄦ埛瀵硅鎵樼洏鐨勯�夋嫨鏁伴噺
+                var userSelection = stockSelectViews.FirstOrDefault(x => x.PalletCode == stock.PalletCode);
+                if (userSelection == null) continue;
+
+                // 璁$畻璇ユ墭鐩樺疄闄呭彲鐢ㄦ暟閲�
+                var availableQuantity = CalculateAvailableQuantity(stock, outboundOrderDetail.MaterielCode,
+                    outboundOrderDetail.BatchNo, outboundOrderDetail.SupplyCode);
+
+                // 纭畾鍒嗛厤鏁伴噺锛氬彇鐢ㄦ埛閫夋嫨鏁伴噺銆佸彲鐢ㄦ暟閲忓拰鍓╀綑闇�姹傜殑鏈�灏忓��
+                var assignQuantity = Math.Min(
+                    Math.Min(userSelection.UseableQuantity, availableQuantity),
+                    remainingNeedQuantity);
+
+                if (assignQuantity <= 0) continue;
+
+                // 鎵ц鍒嗛厤
+                var actualAssigned = AssignStockQuantity(stock, outboundOrderDetail, assignQuantity);
+                if (actualAssigned > 0)
                 {
-                    v.OutboundQuantity = v.StockQuantity;
-                });
-            });
-            needQuantity -= assignQuantity;
-            if (outboundOrderDetail.OrderQuantity > outboundOrderDetail.LockQuantity)
-            {
-                List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.GetUseableStocks(outboundOrderDetail.MaterielCode, outboundOrderDetail.BatchNo, "");
-                stockInfos = stockInfos.Where(x => !stockSelectViews.Select(v => v.PalletCode).Contains(x.PalletCode)).ToList();
-                var (autoAssignStocks, stockAllocations) = _stockService.StockInfoService.GetOutboundStocks(stockInfos, outboundOrderDetail.MaterielCode, needQuantity, out decimal residueQuantity);
-                outboundOrderDetail.LockQuantity += needQuantity - residueQuantity;
-                outStocks.AddRange(autoAssignStocks);
-                outboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.AssignOver.ObjToInt();
-                if (residueQuantity > 0)
-                {
-                    outboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.AssignOverPartial.ObjToInt();
+                    outStocks.Add(stock);
+                    totalAssignedFromUserSelection += actualAssigned;
+                    remainingNeedQuantity -= actualAssigned;
+
+                    // 鍒涘缓閿佸畾璁板綍
+                    var lockInfo = CreateOutStockLockInfo(outboundOrder, outboundOrderDetail, stock, actualAssigned);
+                    outStockLockInfos.Add(lockInfo);
                 }
             }
 
-            List<Dt_OutStockLockInfo> outStockLockInfos = _outStockLockInfoService.GetOutStockLockInfos(outboundOrder, outboundOrderDetail, outStocks);
+            // 妫�鏌ョ敤鎴烽�夋嫨鏄惁鑷冲皯鍒嗛厤浜嗕竴閮ㄥ垎
+            if (totalAssignedFromUserSelection <= 0)
+            {
+                throw new Exception("鐢ㄦ埛閫夋嫨鐨勫簱瀛樻棤娉曞垎閰嶄换浣曟暟閲�");
+            }
+
+            // 濡傛灉鐢ㄦ埛閫夋嫨鐨勫簱瀛樹笉澶燂紝鑷姩鍒嗛厤鍓╀綑閮ㄥ垎
+            decimal autoAssignedQuantity = 0;
+            if (remainingNeedQuantity > 0)
+            {
+                List<Dt_StockInfo> autoStocks = _stockService.StockInfoService.GetUseableStocks(
+                    outboundOrderDetail.MaterielCode, outboundOrderDetail.BatchNo, "");
+
+                // 鎺掗櫎鐢ㄦ埛宸查�夋嫨鐨勬墭鐩�
+                autoStocks = autoStocks
+                    .Where(x => !stockSelectViews.Select(v => v.PalletCode).Contains(x.PalletCode))
+                    .ToList();
+
+                var (autoAssignStocks, stockAllocations) = _stockService.StockInfoService.GetOutboundStocks(
+                    autoStocks, outboundOrderDetail.MaterielCode, remainingNeedQuantity, out decimal residueQuantity);
+
+                // 妫�鏌ヨ嚜鍔ㄥ垎閰嶇粨鏋�
+                autoAssignedQuantity = remainingNeedQuantity - residueQuantity;
+                if (autoAssignedQuantity <= 0 && remainingNeedQuantity > 0)
+                {
+                    // 閮ㄥ垎鍒嗛厤鏄彲浠ユ帴鍙楃殑锛岃褰曡鍛婁絾涓嶆姤閿�
+                    _logger.LogWarning($"鑷姩鍒嗛厤澶辫触锛屽墿浣欓渶姹倇remainingNeedQuantity}鏃犳硶婊¤冻");
+                }
+                else if (autoAssignedQuantity > 0)
+                {
+                    outStocks.AddRange(autoAssignStocks);
+
+                    // 涓鸿嚜鍔ㄥ垎閰嶇殑搴撳瓨鍒涘缓閿佸畾璁板綍
+                    var autoLockInfos = CreateLockInfosForAutoAssign(outboundOrder, outboundOrderDetail, autoAssignStocks, stockAllocations);
+                    outStockLockInfos.AddRange(autoLockInfos);
+                }
+            }
+
+            // 鏇存柊閿佸畾鏁伴噺
+            outboundOrderDetail.LockQuantity += totalAssignedFromUserSelection + autoAssignedQuantity;
+
+            // 鏇存柊鐘舵��
+            UpdateOrderDetailStatus(outboundOrderDetail, remainingNeedQuantity - autoAssignedQuantity);
 
             List<Dt_LocationInfo> locationInfos = _locationInfoService.GetLocationInfos(outStocks.Select(x => x.LocationCode).ToList());
 
             return (outStocks, outboundOrderDetail, outStockLockInfos, locationInfos);
         }
-        private (bool, string) CheckSelectStockDeital(Dt_OutboundOrderDetail outboundOrderDetail, List<StockSelectViewDTO> stockSelectViews)
+
+        // 杈呭姪鏂规硶
+        private decimal CalculateAvailableQuantity(Dt_StockInfo stock, string materielCode, string batchNo, string supplyCode)
         {
-            if (outboundOrderDetail == null)
-            {
-                return (false, "鏈壘鍒板嚭搴撳崟鏄庣粏淇℃伅");
-            }
-            if (outboundOrderDetail.OrderDetailStatus != OrderDetailStatusEnum.New.ObjToInt() && outboundOrderDetail.OrderDetailStatus != OrderDetailStatusEnum.AssignOverPartial.ObjToInt())
-            {
-                return (false, "璇ユ槑缁嗕笉鍙搷浣�");
-            }
-            //if (stockSelectViews.Sum(x => x.UseableQuantity) > outboundOrderDetail.OrderQuantity - outboundOrderDetail.LockQuantity - outboundOrderDetail.MoveQty)
-            //{
-            //    return (false, "閫夋嫨鏁伴噺瓒呭嚭鍗曟嵁鏁伴噺");
-            //}
-            return (true, "鎴愬姛");
+            var relevantDetails = stock.Details
+                .Where(d => d.MaterielCode == materielCode &&
+                           (string.IsNullOrEmpty(batchNo) || d.BatchNo == batchNo) &&
+                           (string.IsNullOrEmpty(supplyCode) || d.SupplyCode == supplyCode))
+                .ToList();
+
+            return relevantDetails.Sum(d => d.StockQuantity - d.OutboundQuantity);
         }
 
+        private decimal AssignStockQuantity(Dt_StockInfo stock, Dt_OutboundOrderDetail detail, decimal assignQuantity)
+        {
+            decimal remainingAssign = assignQuantity;
+
+            // 鎸夊厛杩涘厛鍑哄垎閰嶅簱瀛樻槑缁�
+            var sortedDetails = stock.Details
+                .Where(d => d.MaterielCode == detail.MaterielCode &&
+                           d.BatchNo == detail.BatchNo &&
+                           (d.StockQuantity - d.OutboundQuantity) > 0)
+                .OrderBy(d => d.CreateDate)
+                .ToList();
+
+            foreach (var stockDetail in sortedDetails)
+            {
+                if (remainingAssign <= 0) break;
+
+                var available = stockDetail.StockQuantity - stockDetail.OutboundQuantity;
+                var assign = Math.Min(available, remainingAssign);
+
+                stockDetail.OutboundQuantity += assign;
+                remainingAssign -= assign;
+            }
+
+            return assignQuantity - remainingAssign; // 杩斿洖瀹為檯鍒嗛厤鏁伴噺
+        }
+
+        private Dt_OutStockLockInfo CreateOutStockLockInfo(Dt_OutboundOrder outboundOrder, Dt_OutboundOrderDetail detail,
+            Dt_StockInfo stock, decimal quantity)
+        {
+            var barcode = stock.Details
+                .Where(d => !string.IsNullOrEmpty(d.Barcode))
+                .Select(d => d.Barcode)
+                .FirstOrDefault();
+
+            return _outStockLockInfoService.GetOutStockLockInfo(outboundOrder, detail, stock, quantity, barcode);
+        }
+
+        private List<Dt_OutStockLockInfo> CreateLockInfosForAutoAssign(Dt_OutboundOrder outboundOrder,
+            Dt_OutboundOrderDetail detail, List<Dt_StockInfo> stocks, Dictionary<int, decimal> allocations)
+        {
+            var lockInfos = new List<Dt_OutStockLockInfo>();
+
+            foreach (var stock in stocks.OrderBy(x => x.CreateDate))
+            {
+                if (allocations.TryGetValue(stock.Id, out decimal quantity) && quantity > 0)
+                {
+                    var lockInfo = CreateOutStockLockInfo(outboundOrder, detail, stock, quantity);
+                    lockInfos.Add(lockInfo);
+                }
+            }
+
+            return lockInfos;
+        }
+
+        private void UpdateOrderDetailStatus(Dt_OutboundOrderDetail detail, decimal remainingQuantity)
+        {
+            if (remainingQuantity <= 0)
+            {
+                detail.OrderDetailStatus = OrderDetailStatusEnum.AssignOver.ObjToInt();
+            }
+            else
+            {
+                detail.OrderDetailStatus = OrderDetailStatusEnum.AssignOverPartial.ObjToInt();
+            }
+        }
+
+        private (bool, string) CheckSelectStockDeital(Dt_OutboundOrderDetail outboundOrderDetail, List<StockSelectViewDTO> stockSelectViews)
+        {
+            var needQuantity = outboundOrderDetail.OrderQuantity - outboundOrderDetail.LockQuantity - outboundOrderDetail.MoveQty;
+
+            if (needQuantity <= 0)
+            {
+                return (false, "鍑哄簱鍗曟槑缁嗘棤闇�鍒嗛厤搴撳瓨");
+            }
+
+            // 妫�鏌ユ�婚�夋嫨鏁伴噺鏄惁澶т簬0
+            var totalSelected = stockSelectViews.Sum(x => x.UseableQuantity);
+            if (totalSelected <= 0)
+            {
+                return (false, "鐢ㄦ埛閫夋嫨鐨勫簱瀛樻暟閲忓繀椤诲ぇ浜�0");
+            }
+
+            // 妫�鏌ユ瘡涓墭鐩樼殑鍙敤鏁伴噺
+            foreach (var selection in stockSelectViews)
+            {
+                if (selection.UseableQuantity <= 0)
+                {
+                    return (false, $"鎵樼洏[{selection.PalletCode}]鐨勯�夋嫨鏁伴噺蹇呴』澶т簬0");
+                }
+
+                var stock = _stockService.StockInfoService.GetStockInfoByPalletCode(selection.PalletCode);
+                if (stock == null)
+                {
+                    return (false, $"鎵樼洏[{selection.PalletCode}]涓嶅瓨鍦�");
+                }
+
+                var available = CalculateAvailableQuantity(stock, outboundOrderDetail.MaterielCode,
+                    outboundOrderDetail.BatchNo, outboundOrderDetail.SupplyCode);
+
+                if (available <= 0)
+                {
+                    return (false, $"鎵樼洏[{selection.PalletCode}]娌℃湁鍙敤搴撳瓨");
+                }
+            }
+
+            return (true, "楠岃瘉閫氳繃");
+        }
     }
 }
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundPickingService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundPickingService.cs"
index 81def2c..d9a755c 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundPickingService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundPickingService.cs"
@@ -20,9 +20,11 @@
 using WIDESEA_Core.BaseServices;
 using WIDESEA_Core.Enums;
 using WIDESEA_Core.Helper;
+using WIDESEA_DTO.Allocate;
 using WIDESEA_DTO.Basic;
 using WIDESEA_DTO.Inbound;
 using WIDESEA_DTO.Outbound;
+using WIDESEA_IAllocateService;
 using WIDESEA_IBasicService;
 using WIDESEA_IOutboundService;
 using WIDESEA_IStockService;
@@ -50,6 +52,7 @@
         private readonly IESSApiService _eSSApiService;
         private readonly IInvokeMESService _invokeMESService;
         private readonly IDailySequenceService _dailySequenceService;
+        private readonly IAllocateService _allocateService;
 
         private readonly ILogger<OutboundPickingService> _logger;
 
@@ -70,7 +73,7 @@
         public OutboundPickingService(IRepository<Dt_PickingRecord> BaseDal, IUnitOfWorkManage unitOfWorkManage, IStockInfoService stockInfoService, IStockService stockService,
             IOutStockLockInfoService outStockLockInfoService, IStockInfoDetailService stockInfoDetailService, ILocationInfoService locationInfoService,
             IOutboundOrderDetailService outboundOrderDetailService, ISplitPackageService splitPackageService, IOutboundOrderService outboundOrderService,
-            IRepository<Dt_Task> taskRepository, IESSApiService eSSApiService, ILogger<OutboundPickingService> logger, IInvokeMESService invokeMESService, IDailySequenceService dailySequenceService) : base(BaseDal)
+            IRepository<Dt_Task> taskRepository, IESSApiService eSSApiService, ILogger<OutboundPickingService> logger, IInvokeMESService invokeMESService, IDailySequenceService dailySequenceService, IAllocateService allocateService) : base(BaseDal)
         {
             _unitOfWorkManage = unitOfWorkManage;
             _stockInfoService = stockInfoService;
@@ -86,6 +89,7 @@
             _logger = logger;
             _invokeMESService = invokeMESService;
             _dailySequenceService = dailySequenceService;
+            _allocateService = allocateService;
         }
 
 
@@ -1654,78 +1658,141 @@
         private async Task HandleOrderCompletion(Dt_OutboundOrder outboundOrder, string orderNo)
         {
             // 璋冩嫧鍑哄簱鍜岄噸妫�鍑哄簱涓嶉渶瑕佸弽棣圡ES
-            if (outboundOrder.OrderType == OutOrderTypeEnum.Allocate.ObjToInt() ||
-                outboundOrder.OrderType == OutOrderTypeEnum.ReCheck.ObjToInt())
+            if (outboundOrder.OrderType == OutOrderTypeEnum.Allocate.ObjToInt())
             {
-                return;
-            }
-
-            try
-            {
-                var feedmodel = new FeedbackOutboundRequestModel
+                var allocate = _allocateService.Repository.QueryData(x => x.UpperOrderNo == outboundOrder.UpperOrderNo).First();
+                var feedmodel = new AllocateDto
                 {
-                    reqCode = Guid.NewGuid().ToString(),
-                    reqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
-                    business_type = outboundOrder.BusinessType,
-                    factoryArea = outboundOrder.FactoryArea,
-                    operationType = 1,
+                    ReqCode = Guid.NewGuid().ToString(),
+                    ReqTime = DateTime.Now.ToString(),
+                    BusinessType = "3",
+                  
+                    FactoryArea = outboundOrder.FactoryArea,
+                    OperationType = 1,
                     Operator = App.User.UserName,
-                    orderNo = outboundOrder.UpperOrderNo,
-                    documentsNO = outboundOrder.OrderNo,
-                    status = outboundOrder.OrderStatus,
-                    details = new List<FeedbackOutboundDetailsModel>()
-                };
+                    OrderNo = outboundOrder.UpperOrderNo,
+                   // documentsNO = outboundOrder.OrderNo,
+                   // status = outboundOrder.OrderStatus,
+                    fromWarehouse = allocate?.FromWarehouse ?? "",
+                    toWarehouse = allocate?.ToWarehouse ?? "",
+                    Details = new List<AllocateDtoDetail>()
 
+                };
                 // 鍙幏鍙栧凡鎷i�夊畬鎴愮殑閿佸畾璁板綍
                 var lists = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
                     .Where(x => x.OrderNo == orderNo && x.Status == (int)OutLockStockStatusEnum.鎷i�夊畬鎴�)
                     .ToListAsync();
 
                 var groupedData = lists.GroupBy(item => new { item.MaterielCode, item.lineNo, item.Unit, item.WarehouseCode })
-                   .Select(group => new FeedbackOutboundDetailsModel
+                   .Select(group => new AllocateDtoDetail
                    {
-                       materialCode = group.Key.MaterielCode,
-                       lineNo = group.Key.lineNo,
-                       warehouseCode = group.Key.WarehouseCode,
-                       qty = group.Sum(x => x.PickedQty),
-                       currentDeliveryQty = group.Sum(x => x.PickedQty),
-                       unit = group.Key.Unit,
-                       barcodes = group.Select(row => new WIDESEA_DTO.Outbound.BarcodesModel
+                       MaterialCode = group.Key.MaterielCode,
+                       LineNo = group.Key.lineNo,
+                       WarehouseCode = group.Key.WarehouseCode,
+                       Qty = group.Sum(x => x.PickedQty),
+                      
+                       Unit = group.Key.Unit,
+                       Barcodes = group.Select(row => new BarcodeInfo
                        {
-                           barcode = row.CurrentBarcode,
-                           supplyCode = row.SupplyCode,
-                           batchNo = row.BatchNo,
-                           unit = row.Unit,
-                           qty = row.PickedQty
+                           Barcode = row.CurrentBarcode,
+                           SupplyCode = row.SupplyCode,
+                           BatchNo = row.BatchNo,
+                           Unit = row.Unit,
+                           Qty = row.PickedQty
                        }).ToList()
+
+                  
                    }).ToList();
+                feedmodel.Details = groupedData;
 
-                feedmodel.details = groupedData;
-
-                var result = await _invokeMESService.FeedbackOutbound(feedmodel);
+                var result = await _invokeMESService.FeedbackAllocate(feedmodel);
                 if (result != null && result.code == 200)
-                {
+                {                    
                     await _outboundOrderDetailService.Db.Updateable<Dt_OutboundOrderDetail>()
-                        .SetColumns(x => x.ReturnToMESStatus == 1)
-                        .Where(x => x.OrderId == outboundOrder.Id)
-                        .ExecuteCommandAsync();
+                           .SetColumns(x => x.ReturnToMESStatus == 1)
+                           .Where(x => x.OrderId == outboundOrder.Id).ExecuteCommandAsync();
 
                     await _outboundOrderService.Db.Updateable<Dt_OutboundOrder>()
                           .SetColumns(x => new Dt_OutboundOrder
                           {
                               ReturnToMESStatus = 1,
                               Operator = App.User.UserName,
-                          })
-
-                        .Where(x => x.OrderNo == orderNo)
-                        .ExecuteCommandAsync();
+                          }).Where(x => x.OrderNo == orderNo).ExecuteCommandAsync();
                 }
-
-                _logger.LogError($"FeedbackOutbound鎴愬姛 - OrderNo: {orderNo}, {JsonSerializer.Serialize(result)}");
             }
-            catch (Exception ex)
+            else if (outboundOrder.OrderType == OutOrderTypeEnum.ReCheck.ObjToInt())
             {
-                _logger.LogError($"FeedbackOutbound澶辫触 - OrderNo: {orderNo}, Error: {ex.Message}");
+
+            }
+            else
+            {
+                try
+                {
+                    var feedmodel = new FeedbackOutboundRequestModel
+                    {
+                        reqCode = Guid.NewGuid().ToString(),
+                        reqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
+                        business_type = outboundOrder.BusinessType,
+                        factoryArea = outboundOrder.FactoryArea,
+                        operationType = 1,
+                        Operator = App.User.UserName,
+                        orderNo = outboundOrder.UpperOrderNo,
+                        documentsNO = outboundOrder.OrderNo,
+                        status = outboundOrder.OrderStatus,
+                        details = new List<FeedbackOutboundDetailsModel>()
+                    };
+
+                    // 鍙幏鍙栧凡鎷i�夊畬鎴愮殑閿佸畾璁板綍
+                    var lists = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+                        .Where(x => x.OrderNo == orderNo && x.Status == (int)OutLockStockStatusEnum.鎷i�夊畬鎴�)
+                        .ToListAsync();
+
+                    var groupedData = lists.GroupBy(item => new { item.MaterielCode, item.lineNo, item.Unit, item.WarehouseCode })
+                       .Select(group => new FeedbackOutboundDetailsModel
+                       {
+                           materialCode = group.Key.MaterielCode,
+                           lineNo = group.Key.lineNo,
+                           warehouseCode = group.Key.WarehouseCode,
+                           qty = group.Sum(x => x.PickedQty),
+                           currentDeliveryQty = group.Sum(x => x.PickedQty),
+                           unit = group.Key.Unit,
+                           barcodes = group.Select(row => new WIDESEA_DTO.Outbound.BarcodesModel
+                           {
+                               barcode = row.CurrentBarcode,
+                               supplyCode = row.SupplyCode,
+                               batchNo = row.BatchNo,
+                               unit = row.Unit,
+                               qty = row.PickedQty
+                           }).ToList()
+                       }).ToList();
+
+                    feedmodel.details = groupedData;
+
+                    var result = await _invokeMESService.FeedbackOutbound(feedmodel);
+                    if (result != null && result.code == 200)
+                    {
+                        await _outboundOrderDetailService.Db.Updateable<Dt_OutboundOrderDetail>()
+                            .SetColumns(x => x.ReturnToMESStatus == 1)
+                            .Where(x => x.OrderId == outboundOrder.Id)
+                            .ExecuteCommandAsync();
+
+                        await _outboundOrderService.Db.Updateable<Dt_OutboundOrder>()
+                              .SetColumns(x => new Dt_OutboundOrder
+                              {
+                                  ReturnToMESStatus = 1,
+                                  Operator = App.User.UserName,
+                              })
+
+                            .Where(x => x.OrderNo == orderNo)
+                            .ExecuteCommandAsync();
+                    }
+
+                    _logger.LogError($"FeedbackOutbound鎴愬姛 - OrderNo: {orderNo}, {JsonSerializer.Serialize(result)}");
+                }
+                catch (Exception ex)
+                {
+                    _logger.LogError($"FeedbackOutbound澶辫触 - OrderNo: {orderNo}, Error: {ex.Message}");
+                }
             }
         }
 
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_OutboundService/WIDESEA_OutboundService.csproj" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_OutboundService/WIDESEA_OutboundService.csproj"
index b11d170..ebf59e5 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_OutboundService/WIDESEA_OutboundService.csproj"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_OutboundService/WIDESEA_OutboundService.csproj"
@@ -7,6 +7,7 @@
   </PropertyGroup>
 
   <ItemGroup>
+    <ProjectReference Include="..\WIDESEA_IAllocateService\WIDESEA_IAllocateService.csproj" />
     <ProjectReference Include="..\WIDESEA_IBasicService\WIDESEA_IBasicService.csproj" />
     <ProjectReference Include="..\WIDESEA_IOutboundService\WIDESEA_IOutboundService.csproj" />
     <ProjectReference Include="..\WIDESEA_IRecordService\WIDESEA_IRecordService.csproj" />
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_StockService/StockInfoService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_StockService/StockInfoService.cs"
index e550934..492701c 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_StockService/StockInfoService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_StockService/StockInfoService.cs"
@@ -22,14 +22,16 @@
         public IRepository<Dt_StockInfo> Repository => BaseDal;
         private readonly IRepository<Dt_StockInfoDetail> _stockInfoDetailRepository;
         private readonly IOutboundOrderService _outboundOrderService;
+        private readonly IOutboundOrderDetailService _outboundOrderDetailService;
         private readonly ILocationInfoService _locationInfoService;
-        public StockInfoService(IRepository<Dt_StockInfo> BaseDal, IMapper mapper, IRepository<Dt_StockInfoDetail> stockInfoDetailRepository, IRecordService recordService, ILocationInfoService locationInfoService, IOutboundOrderService outboundOrderService) : base(BaseDal)
+        public StockInfoService(IRepository<Dt_StockInfo> BaseDal, IMapper mapper, IRepository<Dt_StockInfoDetail> stockInfoDetailRepository, IRecordService recordService, ILocationInfoService locationInfoService, IOutboundOrderService outboundOrderService, IOutboundOrderDetailService outboundOrderDetailService) : base(BaseDal)
         {
             _mapper = mapper;
             _stockInfoDetailRepository = stockInfoDetailRepository;
             _recordService = recordService;
             _locationInfoService = locationInfoService;
             _outboundOrderService = outboundOrderService;
+            _outboundOrderDetailService = outboundOrderDetailService;
         }
 
         /// <summary>
@@ -226,49 +228,131 @@
         {
             return Db.Queryable<Dt_StockInfo>().Where(x => palletCodes.Contains(x.PalletCode)).Includes(x => x.Details).OrderBy(x => x.CreateDate).ToList();
         }
+        // 娣诲姞鑾峰彇鍗曚釜鎵樼洏搴撳瓨鐨勬柟娉曪紙濡傛灉涓嶅瓨鍦級
+        public Dt_StockInfo GetStockInfoByPalletCode(string palletCode)
+        {
+            return Db.Queryable<Dt_StockInfo>()
+                .Where(x => x.PalletCode == palletCode)
+                .Includes(x => x.Details)
+                .First();
+        }
 
- 
         /// <summary>
         /// 
         /// </summary>
         /// <param name="orderId"></param>
         /// <param name="materielCode"></param>
         /// <returns></returns>
+        //public List<StockSelectViewDTO> GetStockSelectViews(int orderId, string materielCode)
+        //{
+        //    try
+        //    {
+        //        Dt_OutboundOrder outboundOrder = _outboundOrderService.Repository.QueryFirst(x => x.Id == orderId);
+        //        if (outboundOrder == null)
+        //        {
+        //            throw new Exception($"鏈壘鍒板嚭搴撳崟淇℃伅");
+        //        }
+
+        //        List<string> locationCodes = _locationInfoService.GetCanOutLocationCodes();
+
+        //        return 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,
+        //            Barcode=b.Barcode,
+        //            PalletCode = a.PalletCode,
+        //            UseableQuantity = b.StockQuantity - b.OutboundQuantity
+        //        }, a => locationCodes.Contains(a.LocationCode), b => b.StockQuantity > b.OutboundQuantity && b.MaterielCode == materielCode, x => true).GroupBy(x => x.PalletCode).Select(x => new StockSelectViewDTO
+        //        {
+        //            LocationCode = x.FirstOrDefault()?.LocationCode ?? "",
+        //            MaterielCode = x.FirstOrDefault()?.MaterielCode ?? "",
+        //            MaterielName = x.FirstOrDefault()?.MaterielName ?? "",
+        //            Barcode=x.FirstOrDefault()?.Barcode??"",
+        //            PalletCode = x.Key,
+        //            UseableQuantity = x.Sum(x => x.UseableQuantity)
+        //        }).ToList();
+        //    }
+        //    catch (Exception ex)
+        //    {
+        //        return null;
+        //    }
+
+        //}
+
         public List<StockSelectViewDTO> GetStockSelectViews(int orderId, string materielCode)
         {
-            try
+            Dt_OutboundOrder outboundOrder = _outboundOrderService.Repository.QueryFirst(x => x.Id == orderId);
+            if (outboundOrder == null)
             {
-                Dt_OutboundOrder outboundOrder = _outboundOrderService.Repository.QueryFirst(x => x.Id == orderId);
-                if (outboundOrder == null)
+                throw new Exception($"鏈壘鍒癐D涓簕orderId}鐨勫嚭搴撳崟淇℃伅");
+            }
+
+            // 鑾峰彇鍑哄簱鍗曟槑缁嗭紝鐢ㄤ簬纭畾闇�瑕佺殑鎵规鍜屼緵搴斿晢
+            var orderDetails = _outboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>().Where(x => x.OrderId == orderId && x.MaterielCode == materielCode).ToList();
+
+            if (!orderDetails.Any())
+            {
+                throw new Exception($"鍑哄簱鍗晎orderId}涓湭鎵惧埌鐗╂枡{materielCode}鐨勬槑缁嗕俊鎭�");
+            }
+
+            List<string> locationCodes = _locationInfoService.GetCanOutLocationCodes();
+            var result = new List<StockSelectViewDTO>();
+
+            // 涓烘瘡涓嚭搴撳崟鏄庣粏鏌ヨ瀵瑰簲鐨勫簱瀛�
+            foreach (var orderDetail in orderDetails)
+            {
+                // 鏋勫缓鏌ヨ鏉′欢
+                var stockQuery = Db.Queryable<Dt_StockInfo>()
+                    .Where(x => locationCodes.Contains(x.LocationCode))
+                    .Where(x => x.StockStatus == (int)StockStatusEmun.鍏ュ簱瀹屾垚)
+                    .Includes(x => x.Details);
+
+                // 鎵ц鏌ヨ骞舵寜鍏堣繘鍏堝嚭鎺掑簭
+                var stocks = stockQuery.ToList()
+                    .Where(x => x.Details.Any(d =>
+                        d.MaterielCode == materielCode &&
+                        d.BatchNo == orderDetail.BatchNo &&
+                        d.SupplyCode == orderDetail.SupplyCode &&
+                        d.StockQuantity > d.OutboundQuantity
+                    ))
+                    .OrderBy(x => x.CreateDate)
+                    .ToList();
+
+                foreach (var stock in stocks)
                 {
-                    throw new Exception($"鏈壘鍒板嚭搴撳崟淇℃伅");
+                    var relevantDetails = stock.Details
+                        .Where(d => d.MaterielCode == materielCode &&
+                                   d.BatchNo == orderDetail.BatchNo &&
+                                   d.SupplyCode == orderDetail.SupplyCode &&
+                                   d.StockQuantity > d.OutboundQuantity)
+                        .ToList();
+
+                    if (relevantDetails.Any())
+                    {
+                        var firstDetail = relevantDetails.First();
+                        var useableQuantity = relevantDetails.Sum(d => d.StockQuantity - d.OutboundQuantity);
+
+                        result.Add(new StockSelectViewDTO
+                        {
+                            LocationCode = stock.LocationCode,
+                            MaterielCode = materielCode,
+                            MaterielName = firstDetail.MaterielName,
+                            BatchNo = orderDetail.BatchNo,
+                            SupplyCode = orderDetail.SupplyCode,
+                            Barcode = firstDetail.Barcode,
+                            PalletCode = stock.PalletCode,
+                            UseableQuantity = useableQuantity,
+                            StockCreateDate = stock.CreateDate,
+                            StockId = stock.Id,
+                            OrderDetailId = orderDetail.Id // 鍏宠仈鍒板叿浣撶殑鍑哄簱鍗曟槑缁�
+                        });
+                    }
                 }
-
-                List<string> locationCodes = _locationInfoService.GetCanOutLocationCodes();
-
-                return 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,
-                    Barcode=b.Barcode,
-                    PalletCode = a.PalletCode,
-                    UseableQuantity = b.StockQuantity - b.OutboundQuantity
-                }, a => locationCodes.Contains(a.LocationCode), b => b.StockQuantity > b.OutboundQuantity && b.MaterielCode == materielCode, x => true).GroupBy(x => x.PalletCode).Select(x => new StockSelectViewDTO
-                {
-                    LocationCode = x.FirstOrDefault()?.LocationCode ?? "",
-                    MaterielCode = x.FirstOrDefault()?.MaterielCode ?? "",
-                    MaterielName = x.FirstOrDefault()?.MaterielName ?? "",
-                    Barcode=x.FirstOrDefault()?.Barcode??"",
-                    PalletCode = x.Key,
-                    UseableQuantity = x.Sum(x => x.UseableQuantity)
-                }).ToList();
-            }
-            catch (Exception ex)
-            {
-                return null;
             }
 
+            return result;
         }
+
     }
 }
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs"
index 828f2b5..3021a88 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs"
@@ -127,7 +127,7 @@
 
                 if (int.TryParse(taskNum, out var newTaskNum))
                 {
-                    task =await BaseDal.QueryFirstAsync(x => x.TaskNum == newTaskNum);
+                    task = await BaseDal.QueryFirstAsync(x => x.TaskNum == newTaskNum);
                     if (task == null)
                     {
                         return WebResponseContent.Instance.Error("鏈壘鍒颁换鍔′俊鎭�");
@@ -154,12 +154,12 @@
                                 return responseContent;
                             }
                         }
-                        catch (AggregateException ex) 
+                        catch (AggregateException ex)
                         {
                             _logger.LogError($"TaskService TaskCompleted  taskResult:   {ex.Message} ");
                             return WebResponseContent.Instance.Error(ex.Message);
                         }
-                        catch(Exception ex)
+                        catch (Exception ex)
                         {
                             _logger.LogError(ex, $"Unexpected error in {task.TaskType}");
                             return WebResponseContent.Instance.Error(ex.Message);
@@ -394,7 +394,7 @@
             locationInfo.LocationStatus = LocationStatusEnum.Free.ObjToInt();
             _locationInfoService.Repository.UpdateData(locationInfo);
 
-            var outloks =await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>().Where(x => x.TaskNum == task.TaskNum).ToListAsync();
+            var outloks = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>().Where(x => x.TaskNum == task.TaskNum).ToListAsync();
 
             var stockids = outloks.Select(x => x.StockId).ToList();
 
@@ -489,7 +489,7 @@
             try
             {
                 //鏌ュ簱瀛�
-                Dt_StockInfo stockInfo =await _stockRepository.Db.Queryable<Dt_StockInfo>().Includes(x => x.Details).Where(x => x.PalletCode == task.PalletCode).FirstAsync();
+                Dt_StockInfo stockInfo = await _stockRepository.Db.Queryable<Dt_StockInfo>().Includes(x => x.Details).Where(x => x.PalletCode == task.PalletCode).FirstAsync();
                 if (stockInfo == null)
                 {
                     _logger.LogInformation($"TaskService  InPickTaskCompleted: 鏈壘鍒版墭鐩樺搴旂殑缁勭洏淇℃伅.{task.TaskNum}");
@@ -510,7 +510,7 @@
 
                 var beforelocationStatus = locationInfo.LocationStatus;
                 // 鑾峰彇鎵�鏈夊洖搴撲腑鐨勫嚭搴撻攣瀹氳褰�
-                var returnLocks =await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+                var returnLocks = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
                     .Where(it => it.OrderNo == task.OrderNo && it.PalletCode == task.PalletCode && it.Status == (int)OutLockStockStatusEnum.鍥炲簱涓�)
                     .ToListAsync();
                 // 鏇存柊鍑哄簱閿佸畾璁板綍鐘舵�佷负鍥炲簱瀹屾垚
@@ -518,7 +518,7 @@
                 {
                     lockInfo.Status = (int)OutLockStockStatusEnum.宸插洖搴�;
                 }
-                _outStockLockInfoService.Db.Updateable(returnLocks).ExecuteCommand();                             
+                _outStockLockInfoService.Db.Updateable(returnLocks).ExecuteCommand();
 
                 stockInfo.LocationCode = task.TargetAddress;
                 stockInfo.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
@@ -532,7 +532,7 @@
                 }
 
                 _stockService.StockInfoService.Repository.UpdateData(stockInfo);
-            
+
                 await ProcessStockDetailsForReturn(task, stockInfo.Id);
 
                 await DeleteZeroQuantityStockDetails(stockInfo.Id);
@@ -572,14 +572,13 @@
 
         private async Task HandleOutboundOrderToMESCompletion(Dt_OutboundOrder outboundOrder, string orderNo)
         {
-
             try
             {
                 var orderDetails = await _outboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>()
                     .LeftJoin<Dt_OutboundOrder>((o, item) => o.OrderId == item.Id)
                     .Where((o, item) => item.OrderNo == orderNo)
                     .Select((o, item) => o)
-                    .ToListAsync(); 
+                    .ToListAsync();
 
                 bool allCompleted = true;
                 foreach (var detail in orderDetails)
@@ -599,75 +598,147 @@
                         .SetColumns(x => x.OrderStatus == newStatus)
                         .Where(x => x.OrderNo == orderNo)
                         .ExecuteCommandAsync();
-                 
+
                 }
                 //鍙湁姝e父鍒嗘嫞瀹屾垚鏃舵墠鍚慚ES鍙嶉
                 if (allCompleted && newStatus == (int)OutOrderStatusEnum.鍑哄簱瀹屾垚)
                 {
-                    var feedmodel = new FeedbackOutboundRequestModel
+
+                    if (outboundOrder.OrderType == OutOrderTypeEnum.Allocate.ObjToInt())
                     {
-                        reqCode = Guid.NewGuid().ToString(),
-                        reqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
-                        business_type = outboundOrder.BusinessType,
-                        factoryArea = outboundOrder.FactoryArea,
-                        operationType = 1,
-                        Operator = outboundOrder.Operator,
-                        orderNo = outboundOrder.UpperOrderNo,
-                        documentsNO = outboundOrder.OrderNo,
-                        status = outboundOrder.OrderStatus,
-                        details = new List<FeedbackOutboundDetailsModel>()
-                    };
-
-
-                    foreach (var detail in orderDetails)
-                    {
-                        // 鑾峰彇璇ユ槑缁嗗搴旂殑鏉$爜淇℃伅锛堜粠閿佸畾璁板綍锛�
-                        var detailLocks = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
-                            .Where(x => x.OrderNo == orderNo &&
-                                       x.OrderDetailId == detail.Id &&
-                                       x.Status == (int)OutLockStockStatusEnum.鎷i�夊畬鎴�)
-                            .ToListAsync();
-
-                        var detailModel = new FeedbackOutboundDetailsModel
+                        var allocate = _allocateService.Repository.QueryData(x => x.UpperOrderNo == outboundOrder.UpperOrderNo).First();
+                        var feedmodel = new AllocateDto
                         {
-                            materialCode = detail.MaterielCode,
-                            lineNo = detail.lineNo, // 娉ㄦ剰锛氳繖閲屽彲鑳介渶瑕佽皟鏁村瓧娈靛悕
-                            warehouseCode = detail.WarehouseCode,
-                            qty = detail.OverOutQuantity, // 浣跨敤璁㈠崟鏄庣粏鐨勫凡鍑哄簱鏁伴噺
-                            currentDeliveryQty = detail.OverOutQuantity,
-                            unit = detail.Unit,
-                            barcodes = detailLocks.Select(lockInfo => new WIDESEA_DTO.Outbound.BarcodesModel
+                            ReqCode = Guid.NewGuid().ToString(),
+                            ReqTime = DateTime.Now.ToString(),
+                            BusinessType = "3",
+                            FactoryArea = outboundOrder.FactoryArea,
+                            OperationType = 1,
+                            Operator = outboundOrder.Operator,
+                            OrderNo = outboundOrder.UpperOrderNo,
+                            // documentsNO = outboundOrder.OrderNo,
+                            // status = outboundOrder.OrderStatus,
+                            fromWarehouse = allocate?.FromWarehouse ?? "",
+                            toWarehouse = allocate?.ToWarehouse ?? "",
+                            Details = new List<AllocateDtoDetail>()
+
+                        };
+                        foreach (var detail in orderDetails)
+                        {
+                            // 鑾峰彇璇ユ槑缁嗗搴旂殑鏉$爜淇℃伅锛堜粠閿佸畾璁板綍锛�
+                            var detailLocks = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+                                .Where(x => x.OrderNo == orderNo &&
+                                           x.OrderDetailId == detail.Id &&
+                                           x.Status == (int)OutLockStockStatusEnum.鎷i�夊畬鎴�)
+                                .ToListAsync();
+
+                            var detailModel = new AllocateDtoDetail
                             {
-                                barcode = lockInfo.CurrentBarcode,
-                                supplyCode = lockInfo.SupplyCode,
-                                batchNo = lockInfo.BatchNo,
-                                unit = lockInfo.Unit,
-                                qty = lockInfo.PickedQty // 鏉$爜绾у埆鐨勬暟閲忎粛鐢ㄩ攣瀹氳褰�
-                            }).ToList()
+                                MaterialCode = detail.MaterielCode,
+                                LineNo = detail.lineNo, // 娉ㄦ剰锛氳繖閲屽彲鑳介渶瑕佽皟鏁村瓧娈靛悕
+                                WarehouseCode = detail.WarehouseCode,
+                                Qty = detail.OverOutQuantity, // 浣跨敤璁㈠崟鏄庣粏鐨勫凡鍑哄簱鏁伴噺
+                                //currentDeliveryQty = detail.OverOutQuantity,
+                                Unit = detail.Unit,
+                                Barcodes = detailLocks.Select(lockInfo => new BarcodeInfo
+                                {
+                                    Barcode = lockInfo.CurrentBarcode,
+                                    SupplyCode = lockInfo.SupplyCode,
+                                    BatchNo = lockInfo.BatchNo,
+                                    Unit = lockInfo.Unit,
+                                    Qty = lockInfo.PickedQty // 鏉$爜绾у埆鐨勬暟閲忎粛鐢ㄩ攣瀹氳褰�
+                                }).ToList()
+                            };
+
+                            feedmodel.Details.Add(detailModel);
+                        }
+
+                        var result = await _invokeMESService.FeedbackAllocate(feedmodel);
+                        if (result != null && result.code == 200)
+                        {
+                            await _outboundOrderDetailService.Db.Updateable<Dt_OutboundOrderDetail>()
+                                   .SetColumns(x => x.ReturnToMESStatus == 1)
+                                   .Where(x => x.OrderId == outboundOrder.Id).ExecuteCommandAsync();
+
+                            await _outboundOrderService.Db.Updateable<Dt_OutboundOrder>()
+                                  .SetColumns(x => new Dt_OutboundOrder
+                                  {
+                                      ReturnToMESStatus = 1,
+                                      Operator = App.User.UserName,
+                                  }).Where(x => x.OrderNo == orderNo).ExecuteCommandAsync();
+                        }
+                    }
+                    else if (outboundOrder.OrderType == OutOrderTypeEnum.ReCheck.ObjToInt())
+                    {
+
+                    }
+                    else
+                    {
+                        var feedmodel = new FeedbackOutboundRequestModel
+                        {
+                            reqCode = Guid.NewGuid().ToString(),
+                            reqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
+                            business_type = outboundOrder.BusinessType,
+                            factoryArea = outboundOrder.FactoryArea,
+                            operationType = 1,
+                            Operator = outboundOrder.Operator,
+                            orderNo = outboundOrder.UpperOrderNo,
+                            documentsNO = outboundOrder.OrderNo,
+                            status = outboundOrder.OrderStatus,
+                            details = new List<FeedbackOutboundDetailsModel>()
                         };
 
-                        feedmodel.details.Add(detailModel);
-                    }
 
-                    var result = await _invokeMESService.FeedbackOutbound(feedmodel);
-                    if (result != null && result.code == 200)
-                    {
-                        await _outboundOrderDetailService.Db.Updateable<Dt_OutboundOrderDetail>()
-                            .SetColumns(x => x.ReturnToMESStatus == 1)
-                            .Where(x => x.OrderId == outboundOrder.Id)
-                            .ExecuteCommandAsync();
+                        foreach (var detail in orderDetails)
+                        {
+                            // 鑾峰彇璇ユ槑缁嗗搴旂殑鏉$爜淇℃伅锛堜粠閿佸畾璁板綍锛�
+                            var detailLocks = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+                                .Where(x => x.OrderNo == orderNo &&
+                                           x.OrderDetailId == detail.Id &&
+                                           x.Status == (int)OutLockStockStatusEnum.鎷i�夊畬鎴�)
+                                .ToListAsync();
 
-                        await _outboundOrderService.Db.Updateable<Dt_OutboundOrder>()
-                            .SetColumns(x => x.ReturnToMESStatus == 1)
-                            .Where(x => x.OrderNo == orderNo)
-                            .ExecuteCommandAsync();
+                            var detailModel = new FeedbackOutboundDetailsModel
+                            {
+                                materialCode = detail.MaterielCode,
+                                lineNo = detail.lineNo, // 娉ㄦ剰锛氳繖閲屽彲鑳介渶瑕佽皟鏁村瓧娈靛悕
+                                warehouseCode = detail.WarehouseCode,
+                                qty = detail.OverOutQuantity, // 浣跨敤璁㈠崟鏄庣粏鐨勫凡鍑哄簱鏁伴噺
+                                currentDeliveryQty = detail.OverOutQuantity,
+                                unit = detail.Unit,
+                                barcodes = detailLocks.Select(lockInfo => new WIDESEA_DTO.Outbound.BarcodesModel
+                                {
+                                    barcode = lockInfo.CurrentBarcode,
+                                    supplyCode = lockInfo.SupplyCode,
+                                    batchNo = lockInfo.BatchNo,
+                                    unit = lockInfo.Unit,
+                                    qty = lockInfo.PickedQty // 鏉$爜绾у埆鐨勬暟閲忎粛鐢ㄩ攣瀹氳褰�
+                                }).ToList()
+                            };
+
+                            feedmodel.details.Add(detailModel);
+                        }
+
+                        var result = await _invokeMESService.FeedbackOutbound(feedmodel);
+                        if (result != null && result.code == 200)
+                        {
+                            await _outboundOrderDetailService.Db.Updateable<Dt_OutboundOrderDetail>()
+                                .SetColumns(x => x.ReturnToMESStatus == 1)
+                                .Where(x => x.OrderId == outboundOrder.Id)
+                                .ExecuteCommandAsync();
+
+                            await _outboundOrderService.Db.Updateable<Dt_OutboundOrder>()
+                                .SetColumns(x => x.ReturnToMESStatus == 1)
+                                .Where(x => x.OrderNo == orderNo)
+                                .ExecuteCommandAsync();
+                        }
                     }
                 }
             }
             catch (Exception ex)
             {
                 _logger.LogError($"CheckAndUpdateOrderStatus澶辫触 - OrderNo: {orderNo}, Error: {ex.Message}");
-            }          
+            }
 
         }
 
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/Allocate/AllocateOrderController.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/Allocate/AllocateOrderController.cs"
index 31f6001..07ac628 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/Allocate/AllocateOrderController.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/Allocate/AllocateOrderController.cs"
@@ -69,7 +69,9 @@
                             Barcode = barcodeDto.Barcode,
                             BatchNo = barcodeDto.BatchNo,
                             BarcodeQty = barcodeDto.Qty,
-                            BarcodeUnit = barcodeDto.Unit
+                            BarcodeUnit = barcodeDto.Unit,
+                            ValidDate=barcodeDto.validDate,
+
                         };
                         allocateOrder.Details.Add(orderDetail);
                     }
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/Inbound/InboundOrderController.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/Inbound/InboundOrderController.cs"
index ce96600..4b98acf 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/Inbound/InboundOrderController.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/Inbound/InboundOrderController.cs"
@@ -30,13 +30,13 @@
         private readonly WIDESEA_IBasicService.IErpApiService erpApiService;
 
         private readonly WIDESEA_IBasicService.IInvokeMESService _invokeMESService;
- 
+        public readonly IInboundService _inboundService;
         private readonly IESSApiService _eSSApiService;
         private readonly ILocationInfoService _locationInfoService;
         private readonly IDailySequenceService _dailySequenceService;
         private readonly IMaterialUnitService _materialUnitService;
         private readonly ILogger<InboundOrderController> _logger;
-        public InboundOrderController(IInboundOrderService service, WIDESEA_IBasicService.IErpApiService erpApiService, WIDESEA_IBasicService.IInvokeMESService invokeMESService, IESSApiService eSSApiService, IDailySequenceService dailySequenceService, ILocationInfoService locationInfoService, ILogger<InboundOrderController> logger, IMaterialUnitService materialUnitService) : base(service)
+        public InboundOrderController(IInboundOrderService service, WIDESEA_IBasicService.IErpApiService erpApiService, WIDESEA_IBasicService.IInvokeMESService invokeMESService, IESSApiService eSSApiService, IDailySequenceService dailySequenceService, ILocationInfoService locationInfoService, ILogger<InboundOrderController> logger, IMaterialUnitService materialUnitService, IInboundService inboundService) : base(service)
         {
             this.erpApiService = erpApiService;
             _invokeMESService = invokeMESService;
@@ -45,14 +45,20 @@
             _locationInfoService = locationInfoService;
             _logger = logger;
             _materialUnitService = materialUnitService;
+            _inboundService = inboundService;
         }
 
         [HttpPost, Route("Test"), AllowAnonymous, MethodParamsValidate]
         public async Task<WebResponseContent> Test()
         {
-           // var purchaseToStockResult = await _materialUnitService.ConvertPurchaseToStockAsync("101001-00002", 10);
+          
+             Service.Db.Deleteable<Dt_InboundOrder>().Where(x=>x.UpperOrderNo== "12020251100040").ExecuteCommand();
+            _inboundService.InboundOrderDetailService.Db.Deleteable<Dt_InboundOrderDetail>()
+             .Where(p => SqlFunc.Subqueryable<Dt_InboundOrder>().Where(s => s.Id == p.OrderId && s.UpperOrderNo == "12020251100040").Any()).ExecuteCommand();
 
-           // var pdddurchaseToStockResult = await _materialUnitService.ConvertPurchaseToStockAsync("100513-00210", 10);
+            // var purchaseToStockResult = await _materialUnitService.ConvertPurchaseToStockAsync("101001-00002", 10);
+
+            // var pdddurchaseToStockResult = await _materialUnitService.ConvertPurchaseToStockAsync("100513-00210", 10);
 
             //var sddd = _locationInfoService.AssignLocation();
             //var code = sddd.LocationCode;

--
Gitblit v1.9.3