From 77c5c0b820513fee5d83ea1957012d3bfdac926f Mon Sep 17 00:00:00 2001
From: pan <antony1029@163.com>
Date: 星期一, 08 十二月 2025 21:20:15 +0800
Subject: [PATCH] Merge branch 'master' of http://115.159.85.185:8098/r/ZhongRui/ALDbanyunxiangmu

---
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundPickingService.cs |  598 ++++++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 526 insertions(+), 72 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_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 0fb6e2d..ad5c134 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"
@@ -7,9 +7,11 @@
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Reflection.Metadata;
 using System.Text;
 using System.Text.Json;
 using System.Threading.Tasks;
+using WIDESEA_BasicService;
 using WIDESEA_Common.CommonEnum;
 using WIDESEA_Common.LocationEnum;
 using WIDESEA_Common.OrderEnum;
@@ -20,16 +22,22 @@
 using WIDESEA_Core.BaseServices;
 using WIDESEA_Core.Enums;
 using WIDESEA_Core.Helper;
+using WIDESEA_Core.Utilities;
 using WIDESEA_DTO.Allocate;
 using WIDESEA_DTO.Basic;
 using WIDESEA_DTO.Inbound;
 using WIDESEA_DTO.Outbound;
 using WIDESEA_IAllocateService;
 using WIDESEA_IBasicService;
+using WIDESEA_ICheckService;
 using WIDESEA_IInboundService;
 using WIDESEA_IOutboundService;
 using WIDESEA_IStockService;
+using WIDESEA_ITaskInfoService;
 using WIDESEA_Model.Models;
+using WIDESEA_Model.Models.Basic;
+using WIDESEA_Model.Models.Check;
+using WIDESEA_Model.Models.Outbound;
 
 namespace WIDESEA_OutboundService
 {
@@ -56,9 +64,11 @@
         private readonly IAllocateService _allocateService;
         private readonly IRepository<Dt_InboundOrder> _inboundOrderRepository;
         private readonly IInboundOrderDetailService _inboundOrderDetailService;
-
-
+        private readonly IRepository<Dt_WarehouseArea> _warehouseAreaRepository;
+        private readonly IReCheckOrderService _reCheckOrderService;
+        private readonly ITask_HtyService _task_HtyService;
         private readonly ILogger<OutboundPickingService> _logger;
+        private readonly IRepository<Dt_InterfaceLog> _interfaceLog;
 
         private Dictionary<string, string> stations = new Dictionary<string, string>
         {
@@ -77,7 +87,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, IAllocateService allocateService, IRepository<Dt_InboundOrder> inboundOrderRepository,IInboundOrderDetailService inboundOrderDetailService) : base(BaseDal)
+            IRepository<Dt_Task> taskRepository, IESSApiService eSSApiService, ILogger<OutboundPickingService> logger, IInvokeMESService invokeMESService, IDailySequenceService dailySequenceService, IAllocateService allocateService, IRepository<Dt_InboundOrder> inboundOrderRepository, IInboundOrderDetailService inboundOrderDetailService, IRepository<Dt_WarehouseArea> warehouseAreaRepository, IReCheckOrderService reCheckOrderService, ITask_HtyService task_HtyService, IRepository<Dt_InterfaceLog> interfaceLog) : base(BaseDal)
         {
             _unitOfWorkManage = unitOfWorkManage;
             _stockInfoService = stockInfoService;
@@ -96,6 +106,10 @@
             _allocateService = allocateService;
             _inboundOrderRepository = inboundOrderRepository;
             _inboundOrderDetailService = inboundOrderDetailService;
+            _warehouseAreaRepository = warehouseAreaRepository;
+            _reCheckOrderService = reCheckOrderService;
+            _task_HtyService = task_HtyService;
+            _interfaceLog = interfaceLog;
         }
 
 
@@ -290,7 +304,27 @@
 
                 var statusAnalysis = await AnalyzePalletStatus(orderNo, palletCode, stockInfo.Id);
                 if (!statusAnalysis.HasItemsToReturn)
-                    return await HandleNoReturnItems(orderNo, palletCode, task, stockInfo.Id);
+                {
+                    try
+                    {
+                        var result = await HandleNoReturnItems(orderNo, palletCode, task, stockInfo.Id);
+                        _unitOfWorkManage.CommitTran();
+                        if (result.Status)
+                        {
+                            task.PalletType = PalletTypeEnum.Empty.ObjToInt();
+                            await CreateReturnTaskAndHandleESS(orderNo, palletCode, task, TaskTypeEnum.InEmpty, PalletTypeEnum.Empty.ObjToInt());
+                        }
+                        return result;
+                    }
+                    catch (Exception ex)
+                    {
+                        _unitOfWorkManage.RollbackTran();
+                        _logger.LogError($"ReturnRemaining 鍥炲簱绌虹澶辫触 - OrderNo: {orderNo}, PalletCode: {palletCode}, Error: {ex.Message}");
+                        return WebResponseContent.Instance.Error($"鍥炲簱绌虹鎿嶄綔澶辫触: {ex.Message}");
+                    }
+
+
+                }
 
                 // 4. 妫�鏌ユ槸鍚︽湁杩涜涓殑浠诲姟
                 if (statusAnalysis.HasActiveTasks)
@@ -471,10 +505,21 @@
                     var completedLockInfo = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
                         .Where(it => it.CurrentBarcode == barcode &&
                                    (it.Status == (int)OutLockStockStatusEnum.鎷i�夊畬鎴� ||
+                                    it.Status == (int)OutLockStockStatusEnum.宸查噴鏀� ||
+                                    it.Status == (int)OutLockStockStatusEnum.宸插彇璧� ||
                                     it.PickedQty >= it.AssignQuantity)).FirstAsync();
 
                     if (completedLockInfo != null)
-                        throw new Exception($"鏉$爜{barcode}宸茬粡瀹屾垚鍒嗘嫞锛屼笉鑳介噸澶嶅垎鎷�");
+                    {
+                        string statusMsg = completedLockInfo.Status switch
+                        {
+                            (int)OutLockStockStatusEnum.鎷i�夊畬鎴� => "宸茬粡瀹屾垚鍒嗘嫞",
+                            (int)OutLockStockStatusEnum.宸查噴鏀� => "宸茬粡閲婃斁",
+                            (int)OutLockStockStatusEnum.宸插彇璧� => "宸茬粡鍙栬蛋",
+                            _ => "宸茬粡瀹屾垚鍒嗘嫞"
+                        };
+                        throw new Exception($"鏉$爜{barcode}{statusMsg}锛屼笉鑳介噸澶嶅垎鎷�");
+                    }
                     else
                         return null;
                 }
@@ -747,13 +792,13 @@
                 PickTime = DateTime.Now,
                 Operator = App.User.UserName,
                 OutStockLockId = result.FinalLockInfo.Id,
-                BarcodeUnit=result.FinalLockInfo.BarcodeUnit,
-                BarcodeQty=result.FinalLockInfo.BarcodeQty,
-                BatchNo= result.FinalLockInfo.BatchNo,  
-                lineNo= result.FinalLockInfo.lineNo ,
-                SupplyCode= result.FinalLockInfo.SupplyCode ,
-                WarehouseCode = result.FinalLockInfo.WarehouseCode  ,
-                
+                BarcodeUnit = result.FinalLockInfo.BarcodeUnit,
+                BarcodeQty = result.FinalLockInfo.BarcodeQty,
+                BatchNo = result.FinalLockInfo.BatchNo,
+                lineNo = result.FinalLockInfo.lineNo,
+                SupplyCode = result.FinalLockInfo.SupplyCode,
+                WarehouseCode = result.FinalLockInfo.WarehouseCode,
+
 
             };
 
@@ -810,13 +855,13 @@
 
         private async Task<bool> CanCancelPicking(Dt_OutStockLockInfo lockInfo, Dt_StockInfoDetail stockDetail)
         {
+            if (lockInfo.Status == (int)OutLockStockStatusEnum.宸查噴鏀� || lockInfo.Status == (int)OutLockStockStatusEnum.宸插彇璧�)
+                return false;
             // 閿佸畾淇℃伅鐘舵�佹鏌�
             if (lockInfo.Status != (int)OutLockStockStatusEnum.鎷i�夊畬鎴�)
                 return false;
 
-            ////// 搴撳瓨鐘舵�佹鏌�
-            ////if (stockDetail.Status == StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt())
-            ////    return false;
+
 
             // 濡傛灉鏄媶鍖呰褰曪紝杩橀渶瑕佹鏌ョ埗閿佸畾淇℃伅鐘舵��
             if (lockInfo.IsSplitted == 1 && lockInfo.ParentLockId.HasValue)
@@ -824,7 +869,9 @@
                 var parentLock = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
                     .FirstAsync(x => x.Id == lockInfo.ParentLockId.Value);
 
-                if (parentLock == null || parentLock.Status == (int)OutLockStockStatusEnum.鍥炲簱涓�)
+                if (parentLock == null || parentLock.Status == (int)OutLockStockStatusEnum.鍥炲簱涓� ||
+                        parentLock.Status == (int)OutLockStockStatusEnum.宸查噴鏀� ||
+                        parentLock.Status == (int)OutLockStockStatusEnum.宸插彇璧�)
                     return false;
             }
 
@@ -1104,7 +1151,7 @@
         {
             // 鑾峰彇鏈�鏂扮殑璁㈠崟鏄庣粏鏁版嵁锛堝甫閿侊級
             var currentOrderDetail = await _outboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>()
-                .With(SqlWith.RowLock)
+                //.With(SqlWith.RowLock)
                 .FirstAsync(x => x.Id == orderDetailId);
 
             decimal newOverOutQuantity = currentOrderDetail.OverOutQuantity - cancelQty;
@@ -1287,8 +1334,6 @@
                 //绌烘墭鐩樺浣曞鐞�  杩樻湁涓�涓嚭搴撲换鍔¤澶勭悊銆�
                 originalTask.PalletType = PalletTypeEnum.Empty.ObjToInt();
 
-                await CreateReturnTaskAndHandleESS(orderNo, palletCode, originalTask, TaskTypeEnum.InEmpty, PalletTypeEnum.Empty.ObjToInt());
-
             }
             catch (Exception ex)
             {
@@ -1382,8 +1427,8 @@
             await _outStockLockInfoService.Db.Updateable<Dt_OutStockLockInfo>()
                 .SetColumns(it => new Dt_OutStockLockInfo
                 {
-                    Status = (int)OutLockStockStatusEnum.宸查噴鏀�, // 闇�瑕佹柊澧炶繖涓姸鎬�
-                   // ReleaseTime = DateTime.Now,
+                    Status = (int)OutLockStockStatusEnum.宸查噴鏀�,
+
                     Operator = App.User.UserName
                 })
                 .Where(it => lockIds.Contains(it.Id))
@@ -1664,15 +1709,31 @@
                 WarehouseId = originalTask.WarehouseId
 
             };
-            // 淇濆瓨鍥炲簱浠诲姟
-            await _taskRepository.Db.Insertable(returnTask).ExecuteCommandAsync();
+            try
+            {
+                // 淇濆瓨鍥炲簱浠诲姟
+                var insertcount = await _taskRepository.Db.Insertable(returnTask).ExecuteCommandAsync();
+                if (insertcount <= 0)
+                {
+                    throw new Exception("鍒涘缓浠诲姟澶辫触锛�");
+                }
+            }
+            catch (Exception ex)
+            {
+                _logger.LogInformation($"CreateReturnTaskAndHandleESS 鍒涘缓浠诲姟澶辫触: {orderNo} 锛� {palletCode}");
+                throw new Exception("鍒涘缓浠诲姟澶辫触锛�");
+            }
             var targetAddress = originalTask.TargetAddress;
 
+            _logger.LogInformation($"CreateReturnTaskAndHandleESS 鍒犻櫎鍘嗗彶浠诲姟: {orderNo} 锛� {originalTask.TaskNum}");
             // 鍒犻櫎鍘熷鍑哄簱浠诲姟
-            _taskRepository.DeleteAndMoveIntoHty(originalTask, OperateTypeEnum.鑷姩瀹屾垚);
-            // await _taskRepository.Db.Deleteable(originalTask).ExecuteCommandAsync();
-
-
+            // _taskRepository.DeleteAndMoveIntoHty(originalTask, OperateTypeEnum.鑷姩瀹屾垚);
+            var result = _task_HtyService.DeleteAndMoveIntoHty(originalTask, OperateTypeEnum.浜哄伐鍒犻櫎);
+            if (!result)
+            {
+                await _taskRepository.Db.Deleteable(originalTask).ExecuteCommandAsync();
+            }
+            _logger.LogInformation($"CreateReturnTaskAndHandleESS 鍒犻櫎鍘嗗彶浠诲姟: {orderNo} 锛� {originalTask.TaskNum},褰卞搷琛�  {result}");
 
             // 缁� ESS 鍙戦�佹祦鍔ㄤ俊鍙峰拰鍒涘缓浠诲姟
             await SendESSCommands(palletCode, targetAddress, returnTask);
@@ -1777,7 +1838,7 @@
                 {
                     newStatus = (int)OutOrderStatusEnum.鍑哄簱瀹屾垚;
                 }
-                else if (hasPartial )
+                else if (hasPartial)
                 {
                     newStatus = (int)OutOrderStatusEnum.鍑哄簱涓�;
                 }
@@ -1799,11 +1860,7 @@
 
                     _logger.LogInformation($"璁㈠崟鐘舵�佹洿鏂� - OrderNo: {orderNo}, 鏃х姸鎬�: {outboundOrder.OrderStatus}, 鏂扮姸鎬�: {newStatus}");
 
-                    // 鍙湁姝e父鍒嗘嫞瀹屾垚鏃舵墠鍚慚ES鍙嶉
-                    if (allCompleted && newStatus == (int)OutOrderStatusEnum.鍑哄簱瀹屾垚)
-                    {
-                        await HandleOrderCompletion(outboundOrder, orderNo);
-                    }
+
                 }
             }
             catch (Exception ex)
@@ -1852,7 +1909,7 @@
                     .SetColumns(it => new Dt_OutboundOrderDetail
                     {
                         OrderDetailStatus = newStatus,
-                         
+
                     })
                     .Where(it => it.Id == orderDetailId)
                     .ExecuteCommandAsync();
@@ -1933,14 +1990,14 @@
                 {
                     ReqCode = Guid.NewGuid().ToString(),
                     ReqTime = DateTime.Now.ToString(),
-                    BusinessType = "3",
-                  
+                    BusinessType = "2",
+
                     FactoryArea = outboundOrder.FactoryArea,
                     OperationType = 1,
                     Operator = App.User.UserName,
                     OrderNo = outboundOrder.UpperOrderNo,
-                   // documentsNO = outboundOrder.OrderNo,
-                   // status = outboundOrder.OrderStatus,
+                    // documentsNO = outboundOrder.OrderNo,
+                    // status = outboundOrder.OrderStatus,
                     fromWarehouse = allocate?.FromWarehouse ?? "",
                     toWarehouse = allocate?.ToWarehouse ?? "",
                     Details = new List<AllocateDtoDetail>()
@@ -1951,31 +2008,31 @@
                     .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 })
+                var groupedData = lists.GroupBy(item => new { item.MaterielCode, item.lineNo, item.BarcodeUnit, item.WarehouseCode })
                    .Select(group => new AllocateDtoDetail
                    {
                        MaterialCode = group.Key.MaterielCode,
                        LineNo = group.Key.lineNo,
                        WarehouseCode = group.Key.WarehouseCode,
                        Qty = group.Sum(x => x.PickedQty),
-                      
-                       Unit = group.Key.Unit,
+
+                       Unit = group.Key.BarcodeUnit,
                        Barcodes = group.Select(row => new BarcodeInfo
                        {
                            Barcode = row.CurrentBarcode,
                            SupplyCode = row.SupplyCode,
                            BatchNo = row.BatchNo,
-                           Unit = row.Unit,
+                           Unit = row.BarcodeUnit,
                            Qty = row.PickedQty
                        }).ToList()
 
-                  
+
                    }).ToList();
                 allocatefeedmodel.Details = groupedData;
 
                 var result = await _invokeMESService.FeedbackAllocate(allocatefeedmodel);
                 if (result != null && result.code == 200)
-                {                    
+                {
                     await _outboundOrderDetailService.Db.Updateable<Dt_OutboundOrderDetail>()
                            .SetColumns(x => x.ReturnToMESStatus == 1)
                            .Where(x => x.OrderId == outboundOrder.Id).ExecuteCommandAsync();
@@ -2012,10 +2069,10 @@
 
                     // 鍙幏鍙栧凡鎷i�夊畬鎴愮殑閿佸畾璁板綍
                     var lists = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
-                        .Where(x => x.OrderNo == orderNo && x.Status == (int)OutLockStockStatusEnum.鎷i�夊畬鎴�)
+                        .Where(x => x.OrderNo == orderNo && (x.Status == (int)OutLockStockStatusEnum.鎷i�夊畬鎴� || x.Status == (int)OutLockStockStatusEnum.宸插洖搴�))
                         .ToListAsync();
 
-                    var groupedData = lists.GroupBy(item => new { item.MaterielCode, item.lineNo, item.Unit, item.WarehouseCode })
+                    var groupedData = lists.GroupBy(item => new { item.MaterielCode, item.lineNo, item.BarcodeUnit, item.WarehouseCode })
                        .Select(group => new FeedbackOutboundDetailsModel
                        {
                            materialCode = group.Key.MaterielCode,
@@ -2023,13 +2080,13 @@
                            warehouseCode = group.Key.WarehouseCode,
                            qty = group.Sum(x => x.PickedQty),
                            currentDeliveryQty = group.Sum(x => x.PickedQty),
-                           unit = group.Key.Unit,
+                           unit = group.Key.BarcodeUnit,
                            barcodes = group.Select(row => new WIDESEA_DTO.Outbound.BarcodesModel
                            {
                                barcode = row.CurrentBarcode,
                                supplyCode = row.SupplyCode,
                                batchNo = row.BatchNo,
-                               unit = row.Unit,
+                               unit = row.BarcodeUnit,
                                qty = row.PickedQty
                            }).ToList()
                        }).ToList();
@@ -2077,12 +2134,10 @@
             {
                 // 1. 鍒犻櫎搴撳瓨鏁伴噺涓�0鐨勬槑缁嗚褰�
                 var deleteDetailCount = await _stockInfoDetailService.Db.Deleteable<Dt_StockInfoDetail>()
-                    .Where(x => x.StockId == stockId && x.StockQuantity == 0 && (x.Status == StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt() || x.Status ==
-                                          StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt()))
+                    .Where(x => x.StockId == stockId && x.StockQuantity == 0)
                     .ExecuteCommandAsync();
 
-                await _stockInfoService.Db.Deleteable<Dt_StockInfo>()
-                   .Where(x => x.Id == stockId).ExecuteCommandAsync();
+                _stockInfoService.DeleteData(stockId);
 
                 _logger.LogInformation($"娓呯悊闆跺簱瀛樻槑缁嗚褰� - StockId: {stockId}, 鍒犻櫎璁板綍鏁�: {deleteDetailCount}");
 
@@ -2199,7 +2254,7 @@
                 _logger.LogInformation($"璁㈠崟 {orderNo} 宸叉爣璁颁负鍑哄簱瀹屾垚");
 
                 // 鍚慚ES鍙嶉璁㈠崟瀹屾垚锛堝鏋滈渶瑕侊級
-                await HandleOrderCompletion(outboundOrder, orderNo);
+                //await HandleOrderCompletion(outboundOrder, orderNo);
             }
         }
 
@@ -2436,8 +2491,8 @@
                 FactoryArea = originalLock.FactoryArea,
                 lineNo = originalLock.lineNo,
                 WarehouseCode = originalLock.WarehouseCode,
-                BarcodeQty=originalLock.BarcodeQty,
-                BarcodeUnit=originalLock.BarcodeUnit,
+                BarcodeQty = originalLock.BarcodeQty,
+                BarcodeUnit = originalLock.BarcodeUnit,
 
             };
 
@@ -2550,7 +2605,7 @@
         {
             List<Dt_InboundOrder> InOders = _inboundOrderRepository.QueryData().Where(x => x.OrderStatus != InOrderStatusEnum.鍏ュ簱瀹屾垚.ObjToInt()).ToList();
             List<string> InOderCodes = InOders.Select(x => x.UpperOrderNo).ToList();
-            return WebResponseContent.Instance.OK("鎴愬姛",data: InOderCodes);
+            return WebResponseContent.Instance.OK("鎴愬姛", data: InOderCodes);
         }
 
         public WebResponseContent GetAvailablePickingOrders()
@@ -2566,7 +2621,7 @@
             try
             {
                 Dt_InboundOrder inboundOrder = Db.Queryable<Dt_InboundOrder>().Where(x => x.UpperOrderNo == noStockOut.inOder && x.OrderStatus != InOrderStatusEnum.鍏ュ簱瀹屾垚.ObjToInt()).Includes(x => x.Details).First();
-                if(inboundOrder == null)
+                if (inboundOrder == null)
                 {
                     return WebResponseContent.Instance.Error($"鏈壘鍒伴噰璐崟锛歿noStockOut.inOder}");
                 }
@@ -2593,7 +2648,7 @@
 
                 //鍓╀綑鍏ュ簱鏁伴噺鍗宠櫄鎷熷嚭鍏ュ簱鍓╀綑鍙嚭鏁伴噺
                 decimal outQuantity = matchedDetail.OrderQuantity - matchedDetail.ReceiptQuantity;
-                if(outQuantity == 0)
+                if (outQuantity == 0)
                 {
                     return WebResponseContent.Instance.Error($"璇ラ噰璐崟涓殑鏉$爜瀵瑰簲鐨勫彲鍑烘暟閲忎负0");
                 }
@@ -2607,7 +2662,7 @@
 
                 if ((matchedCode.LockQuantity + matchedCode.NoStockOutQty) > matchedCode.OrderQuantity)
                 {
-                   return WebResponseContent.Instance.Error($"鍑哄簱鍗曟槑缁嗘暟閲忔孩鍑簕matchedCode.LockQuantity - matchedCode.OrderQuantity}");
+                    return WebResponseContent.Instance.Error($"鍑哄簱鍗曟槑缁嗘暟閲忔孩鍑簕matchedCode.LockQuantity - matchedCode.OrderQuantity}");
                 }
                 matchedDetail.OrderDetailStatus = OrderDetailStatusEnum.Inbounding.ObjToInt();
                 matchedCode.OrderDetailStatus = OrderDetailStatusEnum.AssignOver.ObjToInt();
@@ -2618,7 +2673,7 @@
                 _unitOfWorkManage.CommitTran();
                 return WebResponseContent.Instance.OK();
             }
-            catch(Exception ex)
+            catch (Exception ex)
             {
                 _unitOfWorkManage.RollbackTran();
                 return WebResponseContent.Instance.Error(ex.Message);
@@ -2643,7 +2698,7 @@
                 }
                 matchedDetail.NoStockOutQty = 0;
 
-                if(matchedDetail.ReceiptQuantity==0 && matchedDetail.OverInQuantity==0)
+                if (matchedDetail.ReceiptQuantity == 0 && matchedDetail.OverInQuantity == 0)
                 {
                     matchedDetail.OrderDetailStatus = OrderDetailStatusEnum.New.ObjToInt();
                 }
@@ -2671,23 +2726,23 @@
                 return WebResponseContent.Instance.OK();
 
             }
-            catch(Exception ex)
+            catch (Exception ex)
             {
                 _unitOfWorkManage.RollbackTran();
                 return WebResponseContent.Instance.Error(ex.Message);
             }
         }
 
-        public WebResponseContent NoStockOutSubmit(NoStockOutSubmit noStockOutSubmit)
+        public async Task<WebResponseContent> NoStockOutSubmit(NoStockOutSubmit noStockOutSubmit)
         {
             try
             {
-                Dt_InboundOrder inboundOrder = Db.Queryable<Dt_InboundOrder>().Where(x => x.UpperOrderNo == noStockOutSubmit.InOderSubmit && x.OrderStatus != InOrderStatusEnum.鍏ュ簱瀹屾垚.ObjToInt()).Includes(x => x.Details).First();
+                Dt_InboundOrder inboundOrder = _inboundOrderRepository.Db.Queryable<Dt_InboundOrder>().Where(x => x.UpperOrderNo == noStockOutSubmit.InOderSubmit && x.OrderStatus != InOrderStatusEnum.鍏ュ簱瀹屾垚.ObjToInt()).Includes(x => x.Details).First();
                 if (inboundOrder == null)
                 {
                     return WebResponseContent.Instance.Error($"鏈壘鍒伴噰璐崟锛歿noStockOutSubmit.InOderSubmit}");
                 }
-                Dt_OutboundOrder outboundOrder = Db.Queryable<Dt_OutboundOrder>().Where(x => x.UpperOrderNo == noStockOutSubmit.OutOderSubmit && x.OrderStatus != OutOrderStatusEnum.鍑哄簱瀹屾垚.ObjToInt()).Includes(x => x.Details).First();
+                Dt_OutboundOrder outboundOrder = _inboundOrderRepository.Db.Queryable<Dt_OutboundOrder>().Where(x => x.UpperOrderNo == noStockOutSubmit.OutOderSubmit && x.OrderStatus != OutOrderStatusEnum.鍑哄簱瀹屾垚.ObjToInt()).Includes(x => x.Details).First();
                 if (outboundOrder == null)
                 {
                     return WebResponseContent.Instance.Error($"鏈壘鍒板嚭搴撳崟锛歿noStockOutSubmit.OutOderSubmit}");
@@ -2696,9 +2751,9 @@
                 List<Dt_OutboundOrderDetail> outboundOrderDetails = new List<Dt_OutboundOrderDetail>();
                 foreach (var BarCode in noStockOutSubmit.BarCodeSubmit)
                 {
-                   var inboundOrderDetail = inboundOrder.Details.FirstOrDefault(detail => detail.Barcode == BarCode && detail.OrderDetailStatus != OrderDetailStatusEnum.Over.ObjToInt());
+                    var inboundOrderDetail = inboundOrder.Details.FirstOrDefault(detail => detail.Barcode == BarCode && detail.OrderDetailStatus != OrderDetailStatusEnum.Over.ObjToInt());
 
-                    if(inboundOrderDetail == null)
+                    if (inboundOrderDetail == null)
                     {
                         return WebResponseContent.Instance.Error($"鍦ㄩ噰璐崟 {noStockOutSubmit.InOderSubmit} 涓湭鎵惧埌鏉$爜涓� {BarCode} 鐨勬槑缁嗐��");
                     }
@@ -2715,24 +2770,62 @@
 
                     outboundOrderDetail.LockQuantity += outboundOrderDetail.NoStockOutQty;
                     outboundOrderDetail.OverOutQuantity = outboundOrderDetail.LockQuantity;
-                    if(outboundOrderDetail.OrderQuantity == outboundOrderDetail.OverOutQuantity)
+                    if (outboundOrderDetail.OrderQuantity == outboundOrderDetail.OverOutQuantity)
                     {
                         outboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.Over.ObjToInt();
                     }
                     outboundOrderDetails.Add(outboundOrderDetail);
 
+                    var newLockInfo = new Dt_OutStockLockInfo
+                    {
+                        OrderNo = outboundOrder.UpperOrderNo,
+                        OrderDetailId = outboundOrderDetail.Id,
+                        OutboundBatchNo = outboundOrderDetail.BatchNo,
+                        MaterielCode = outboundOrderDetail.MaterielCode,
+                        MaterielName = outboundOrderDetail.MaterielName,
+                        StockId = 0,
+                        OrderQuantity = outboundOrderDetail.OrderQuantity,
+                        AssignQuantity = outboundOrderDetail.OverOutQuantity,
+                        PickedQty = outboundOrderDetail.NoStockOutQty,
+                        LocationCode = "绌�",
+                        PalletCode = "绌�",
+                        TaskNum = 0,
+                        Status = (int)OutLockStockStatusEnum.鎷i�夊畬鎴�,
+                        Unit = outboundOrderDetail.Unit,
+                        SupplyCode = outboundOrderDetail.SupplyCode ?? "鏃�",
+                        OrderType = outboundOrder.OrderType,
+                        CurrentBarcode = inboundOrderDetail.Barcode,
+                        IsSplitted = 1,
+                        Operator = App.User.UserName,
+                        lineNo = outboundOrderDetail.lineNo,
+                        WarehouseCode = outboundOrderDetail.WarehouseCode ?? "鏃�",
+                        BarcodeQty = outboundOrderDetail.NoStockOutQty,
+                        BarcodeUnit = outboundOrderDetail.BarcodeUnit,
+                        BatchNo = outboundOrderDetail.BatchNo
+                    };
+                    _outStockLockInfoService.AddData(newLockInfo);
                 }
                 //鍒ゆ柇鍏ュ簱鍗曟嵁鏄庣粏鏄惁鍏ㄩ儴鏄畬鎴愮姸鎬�
-                bool inoderOver = inboundOrder.Details.Count() == inboundOrder.Details.Select(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()).Count();
+                int e = inboundOrder.Details.Count();
+                int w = inboundOrder.Details.Where(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()).Count();
+                bool inoderOver = inboundOrder.Details.Count() == inboundOrder.Details.Where(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()).Count();
                 if (inoderOver)
                 {
                     inboundOrder.OrderStatus = InOrderStatusEnum.鍏ュ簱瀹屾垚.ObjToInt();
                 }
+                else
+                {
+                    inboundOrder.OrderStatus = InOrderStatusEnum.鍏ュ簱涓�.ObjToInt();
+                }
                 //鍒ゆ柇鍑哄簱鍗曟嵁鏄庣粏鏄惁鍏ㄩ儴鏄畬鎴愮姸鎬�
-                bool outOderOver = outboundOrder.Details.Count() == outboundOrder.Details.Select(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()).Count();
+                bool outOderOver = outboundOrder.Details.Count() == outboundOrder.Details.Where(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()).Count();
                 if (outOderOver)
                 {
                     outboundOrder.OrderStatus = OutOrderStatusEnum.鍑哄簱瀹屾垚.ObjToInt();
+                }
+                else
+                {
+                    outboundOrder.OrderStatus = OutOrderStatusEnum.鍑哄簱涓�.ObjToInt();
                 }
                 //鏁版嵁澶勭悊
                 _unitOfWorkManage.BeginTran();
@@ -2742,9 +2835,131 @@
                 _outboundOrderService.UpdateData(outboundOrder);
                 _unitOfWorkManage.CommitTran();
 
+                //鍏ュ簱鍥炰紶MES
+                var infeedmodel = new FeedbackInboundRequestModel
+                {
+                    reqCode = Guid.NewGuid().ToString(),
+                    reqTime = DateTime.Now.ToString(),
+                    business_type = inboundOrder.BusinessType,
+                    factoryArea = inboundOrder.FactoryArea,
+                    operationType = 1,
+                    Operator = App.User.UserName,
+                    orderNo = inboundOrder.UpperOrderNo,
+                    status = inboundOrder.OrderStatus,
+                    details = new List<FeedbackInboundDetailsModel>()
+
+                };
+
+                var groupedData = inboundOrderDetails.GroupBy(item => new { item.MaterielCode, item.SupplyCode, item.BatchNo, item.lineNo, item.BarcodeUnit, item.WarehouseCode })
+                    .Select(group => new FeedbackInboundDetailsModel
+                    {
+                        materialCode = group.Key.MaterielCode,
+                        supplyCode = group.Key.SupplyCode,
+                        batchNo = group.Key.BatchNo,
+                        lineNo = group.Key.lineNo,
+                        warehouseCode = group.Key.WarehouseCode,
+                        qty = group.Sum(x => x.BarcodeQty),
+                        // warehouseCode= "1072",
+                        unit = group.Key.BarcodeUnit,
+                        barcodes = group.Select(row => new FeedbackBarcodesModel
+                        {
+                            barcode = row.Barcode,
+                            qty = row.BarcodeQty
+                        }).ToList()
+                    }).ToList();
+                infeedmodel.details = groupedData;
+
+                var result1 = await _invokeMESService.FeedbackInbound(infeedmodel);
+                if (result1 != null && result1.code == 200)
+                {
+                    var orderIds = inboundOrderDetails.Select(x => x.Id).Distinct().ToList();
+                    _inboundOrderRepository.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 1 })
+                    .Where(it => it.Id == inboundOrder.Id).ExecuteCommand();
+                    _inboundOrderDetailService.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = 1 })
+                    .Where(it => orderIds.Contains(it.Id)).ExecuteCommand();
+                }
+                //鍑哄簱鍥炰紶MES
+
+                var documentNo = UniqueValueGenerator.Generate();
+
+                var outfeedmodel = 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 = documentNo,
+                    status = outboundOrder.OrderStatus,
+                    details = new List<FeedbackOutboundDetailsModel>()
+                };
+                foreach (var detail in outboundOrderDetails)
+                {
+                    // 鑾峰彇璇ユ槑缁嗗搴旂殑鏉$爜淇℃伅锛堜粠閿佸畾璁板綍锛�
+                    var detailLocks = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+                        .Where(x => x.OrderNo == outboundOrder.UpperOrderNo &&
+                                    x.OrderDetailId == detail.Id &&
+                                        (x.Status == (int)OutLockStockStatusEnum.鎷i�夊畬鎴� || x.Status == (int)OutLockStockStatusEnum.宸插洖搴�))
+                        .ToListAsync();
+
+                    var groupdata = detailLocks.GroupBy(item => new { item.MaterielCode, item.lineNo, item.BarcodeUnit, 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.BarcodeUnit,
+                              barcodes = group.Select(lockInfo => new WIDESEA_DTO.Outbound.BarcodesModel
+                              {
+                                  barcode = lockInfo.CurrentBarcode,
+                                  supplyCode = lockInfo.SupplyCode,
+                                  batchNo = lockInfo.BatchNo,
+                                  unit = lockInfo.BarcodeUnit,
+                                  qty = lockInfo.PickedQty
+                              }).ToList()
+                          }).ToList();
+                    outfeedmodel.details.AddRange(groupdata);
+                }
+                //瀛樺偍鍥炰紶鍙傛暟锛屼繚璇佸紓甯告墜鍔ㄥ洖浼�
+                Dt_InterfaceLog interfaceLog = new Dt_InterfaceLog
+                {
+                    OrderNo = outboundOrder.UpperOrderNo,
+                    DocumentNo = documentNo,
+                    OrderType = "铏氭嫙鍑哄叆搴�",
+                    Content = outfeedmodel.ToJson(),
+                    ReturnToMESStatus = 0,
+                    IsDeleted = false
+                };
+                _interfaceLog.AddData(interfaceLog);
+
+                var result = await _invokeMESService.FeedbackOutbound(outfeedmodel);
+                if (result != null && result.code == 200)
+                {
+                    var orderIds = outboundOrderDetails.Select(x => x.Id).Distinct().ToList();
+                    await _outboundOrderDetailService.Db.Updateable<Dt_OutboundOrderDetail>()
+                        .SetColumns(x => x.ReturnToMESStatus == 1)
+                        .Where(x => orderIds.Contains(x.Id))
+                        .ExecuteCommandAsync();
+
+
+                    await _outboundOrderService.Db.Updateable<Dt_OutboundOrder>()
+                        .SetColumns(x => x.ReturnToMESStatus == 1)
+                        .Where(x => x.Id == outboundOrder.Id)
+                        .ExecuteCommandAsync();
+
+                    await _interfaceLog.Db.Updateable<Dt_InterfaceLog>()
+                        .SetColumns(x => x.ReturnToMESStatus == 1)
+                        .Where(x => x.DocumentNo == documentNo)
+                        .ExecuteCommandAsync();
+                }
                 return WebResponseContent.Instance.OK();
             }
-            catch(Exception ex)
+            catch (Exception ex)
             {
                 _unitOfWorkManage.RollbackTran();
                 return WebResponseContent.Instance.Error(ex.Message);
@@ -2752,11 +2967,240 @@
         }
         #endregion
 
+        public WebResponseContent UnPalletQuantity(string orderNo)
+        {
+            // 鍒濆鍖栬繑鍥濪TO锛堥粯璁ゅ�奸兘涓�0锛岄伩鍏峮ull锛�
+            var resultDTO = new PalletSumQuantityDTO
+            {
+                StockSumQuantity = 0,
+                StockCount = 0,
+                UniqueUnit = ""
+            };
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                if (string.IsNullOrWhiteSpace(orderNo))
+                {
+                    return content.Error("浼犲叆鐨勮鍗曞彿orderNo涓虹┖鎴栫┖鐧�");
+                }
+                var orderDetail = Db.Queryable<Dt_PickingRecord>().Where(s => s.OrderNo == orderNo).ToList();
+                if (orderDetail == null)
+                {
+                    return content.Error("鏈壘鍒板崟鎹�");
+                }
+                var unitGroups = orderDetail.GroupBy(d => d.BarcodeUnit).ToList();
+                if (unitGroups.Count == 1)
+                {
+                    resultDTO.UniqueUnit = unitGroups.First().Key;
+                }
+                else
+                {
+                    resultDTO.UniqueUnit = "";
+                }
+                var validDetails = _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>().Where(s => s.OrderNo == orderNo).ToList();
+                resultDTO.StockSumQuantity = orderDetail.Sum(d => d.PickQuantity);
+                resultDTO.StockCount = orderDetail.Count;
+                if (validDetails.Any())
+                {
+                    resultDTO.StockSumQuantity -= validDetails.Sum(d => d.StockQuantity);
+                    // 鏄庣粏璁板綍鏁帮細绗﹀悎鏉′欢鐨勬湁鏁堣褰曟潯鏁�
+                    resultDTO.StockCount -= validDetails.Count;
+                }
+                return content.OK("", resultDTO);
+            }
+            catch (Exception ex)
+            {
+                return content.Error("SumQuantity 缁熻搴撳瓨鏁伴噺澶辫触锛岃鍗曞彿锛歿OrderNo}");
+            }
+        }
+
+        public WebResponseContent BarcodeMaterielGroup(BarcodeMaterielGroupDTO materielGroupDTO)
+        {
+
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                (bool, string, object?) result2 = ModelValidate.ValidateModelData(materielGroupDTO);
+                if (!result2.Item1) return content = WebResponseContent.Instance.Error(result2.Item2);
+
+                //  materielGroupDTO.WarehouseCode
+                var code = _warehouseAreaRepository.Db.Queryable<Dt_WarehouseArea>().Where(x => x.Code == materielGroupDTO.WarehouseType).Select(x => x.Code).First();
+                if (string.IsNullOrEmpty(code))
+                {
+                    return content = WebResponseContent.Instance.Error($"浠撳簱涓病鏈夎{materielGroupDTO.WarehouseType}缂栧彿銆�");
+                }
+
+                if (materielGroupDTO.orderTypes == InOrderTypeEnum.ReCheck.ObjToInt())
+                {
+                    var dborder = _reCheckOrderService.Db.Queryable<Dt_ReCheckOrder>().First(x => x.OrderNo == materielGroupDTO.OrderNo);
+                    if (dborder != null && (dborder.SignSeq == 0 || dborder.SignSeq == 1))
+                    {
+                        return content.Error("鍙湁鎷垮埌閲嶆缁撴灉鎵嶈兘鍏ュ簱锛�");
+                    }
+
+
+                }
+                //  Dt_InboundOrder inboundOrder = GetInboundOrder(materielGroupDTO.OrderNo);
+
+                var dbinboundOrderDetails = Db.Queryable<Dt_PickingRecord>().Where(x => x.OrderNo == materielGroupDTO.OrderNo && !x.IsCancelled && x.Barcode == materielGroupDTO.Barcodes).ToList();
+
+                if (dbinboundOrderDetails != null && !dbinboundOrderDetails.Any())
+                {
+                    return content = WebResponseContent.Instance.Error($"鍗曟嵁涓病鏈夎{materielGroupDTO.Barcodes}鏉$爜鏁版嵁銆�");
+                }
+
+                List<string?> materielCodes = dbinboundOrderDetails.GroupBy(x => x.Barcode).Select(x => x.Key).ToList();
+
+                Dt_StockInfo? stockInfo = _stockService.StockInfoService.GetStockByPalletCode(materielGroupDTO.PalletCode);
+
+
+
+                (bool, string, object?) result = CheckMaterielGroupParam(materielGroupDTO, materielCodes, stockInfo);
+                if (!result.Item1) return content = WebResponseContent.Instance.Error(result.Item2);
+
+                if (stockInfo == null)
+                {
+                    stockInfo = new Dt_StockInfo() { PalletType = (int)PalletTypeEnum.None, LocationType = materielGroupDTO.locationType.ObjToInt() };
+                    stockInfo.Details = new List<Dt_StockInfoDetail>();
+                }
+                var inboindId = 0; Dt_InboundOrder dt_InboundOrder = null;
+                var orderno = dbinboundOrderDetails.First().OrderNo;
+                var dbinbound = _inboundOrderRepository.QueryData(x => x.InboundOrderNo == orderno).FirstOrDefault();
+                if (dbinbound == null)
+                {
+                    dt_InboundOrder = new Dt_InboundOrder
+                    {
+                        WarehouseId = 0,
+                        InboundOrderNo = dbinboundOrderDetails.First()?.OrderNo,
+                        UpperOrderNo = dbinboundOrderDetails.First()?.OrderNo,
+                        SupplierId = dbinboundOrderDetails.First()?.SupplyCode,
+                        OrderType = materielGroupDTO.orderTypes,
+
+                        BusinessType = materielGroupDTO.orderTypes.ToString(),
+
+                        FactoryArea = dbinboundOrderDetails.First()?.FactoryArea,
+                        Remark = "",
+                        Details = new List<Dt_InboundOrderDetail>()
+                    };
+                    inboindId = _inboundOrderRepository.AddData(dt_InboundOrder);
+                }
+                else
+                {
+                    dt_InboundOrder = new Dt_InboundOrder { Details = new List<Dt_InboundOrderDetail>() };
+                    inboindId = dbinbound.Id;
+                }
+
+                foreach (var item in dbinboundOrderDetails)
+                {
+                    stockInfo.Details.Add(new Dt_StockInfoDetail
+                    {
+                        StockId = stockInfo == null ? 0 : stockInfo.Id,
+                        Barcode = item.Barcode,
+                        MaterielCode = item.MaterielCode,
+                        BatchNo = item.BatchNo,
+                        Unit = item.BarcodeUnit,
+                        InboundOrderRowNo = item.lineNo,
+                        SupplyCode = item.SupplyCode,
+                        WarehouseCode = materielGroupDTO.WarehouseType,
+                        StockQuantity = item.PickQuantity,
+                        BarcodeQty = item.BarcodeQty,
+                        BarcodeUnit = item.BarcodeUnit,
+                        FactoryArea = item.FactoryArea,
+                        Status = 0,
+                        OrderNo = item.OrderNo,
+                        BusinessType = materielGroupDTO.orderTypes.ToString()
+
+                    });
+                    item.WarehouseCode = item.WarehouseCode;
+
+                    dt_InboundOrder.Details.Add(new Dt_InboundOrderDetail
+                    {
+                        OrderId = inboindId,
+                        MaterielCode = item.MaterielCode,
+                        MaterielName = "",
+                        BatchNo = item.BatchNo,
+                        OrderQuantity = item.PickQuantity,
+                        ReceiptQuantity = 0,
+                        OverInQuantity = 0,
+                        Unit = item.BarcodeUnit,
+                        RowNo = 0,
+                        lineNo = item.lineNo,
+                        SupplyCode = item.SupplyCode,
+                        WarehouseCode = item.WarehouseCode,
+                        Barcode = item.Barcode,
+                        OutBoxbarcodes = "",
+                        BarcodeQty = (decimal)item.BarcodeQty,
+                        BarcodeUnit = item.BarcodeUnit
+                    });
+                }
+
+                _inboundOrderDetailService.Db.Insertable<Dt_InboundOrderDetail>(dt_InboundOrder.Details);
+                if (stockInfo.Id == 0)
+                {
+                    stockInfo.PalletCode = materielGroupDTO.PalletCode;
+                    stockInfo.StockStatus = StockStatusEmun.缁勭洏鏆傚瓨.ObjToInt();
+                }
+                stockInfo.PalletType = (int)PalletTypeEnum.None;
+
+                List<int> updateDetailIds = dbinboundOrderDetails.Select(x => x.Id).ToList();
+
+                try
+                {
+                    _unitOfWorkManage.BeginTran();
+
+                    _stockService.StockInfoService.AddMaterielGroup(stockInfo);
+                    _unitOfWorkManage.CommitTran();
+                    return WebResponseContent.Instance.OK();
+                }
+                catch (Exception ex)
+                {
+                    _unitOfWorkManage.RollbackTran();
+                    return WebResponseContent.Instance.Error(ex.Message);
+                }
+            }
+            catch (Exception ex)
+            {
+                content = WebResponseContent.Instance.Error(ex.Message);
+            }
+            finally
+            {
+
+            }
+            return content;
+
+        }
+
+
+        public (bool, string, object?) CheckMaterielGroupParam(BarcodeMaterielGroupDTO materielGroupDTO, List<string> barcodeCodes, Dt_StockInfo stockInfo)
+        {
+            (bool, string, object?) result = ModelValidate.ValidateModelData(materielGroupDTO);
+            if (!result.Item1) return result;
+
+            if (_taskRepository.QueryFirst(x => x.PalletCode == materielGroupDTO.PalletCode) != null)
+            {
+                return (false, "璇ユ墭鐩樺彿宸叉湁浠诲姟", materielGroupDTO);
+            }
+
+            if (stockInfo != null && !string.IsNullOrEmpty(stockInfo.LocationCode) && stockInfo.StockStatus != StockStatusEmun.缁勭洏鏆傚瓨.ObjToInt())
+            {
+                return (false, "宸蹭笂鏋剁殑鎵樼洏涓嶈兘鍐嶆缁勭洏", materielGroupDTO);
+            }
+
+            if (_stockService.StockInfoDetailService.ExistBarcodes(barcodeCodes))
+            {
+                return (false, $"{barcodeCodes[0]} 鏉$爜鍦ㄥ簱瀛樹腑宸插瓨鍦�", materielGroupDTO);
+            }
+
+
+
+            return (true, "鎴愬姛", materielGroupDTO);
+        }
+
 
         #endregion
     }
 
-   
+
 
     #region 鏀寔绫诲畾涔�
 
@@ -2821,12 +3265,22 @@
         public bool HasSplitRecords { get; set; }
         public decimal RemainingLocksReturnQty { get; set; }
         public decimal PalletStockReturnQty { get; set; }
+
         public decimal SplitReturnQty { get; set; }
         public decimal TotalReturnQty { get; set; }
+
+        // 鏈垎閰嶇殑閿佸畾璁板綍锛堝鑷姩鎷嗗寘浜х敓鐨勶級
+        public bool HasUnallocatedLocks { get; set; }
+        public List<Dt_OutStockLockInfo> UnallocatedLocks { get; set; } = new List<Dt_OutStockLockInfo>();
+        public decimal UnallocatedLocksReturnQty { get; set; }
+
         public List<Dt_OutStockLockInfo> RemainingLocks { get; set; } = new List<Dt_OutStockLockInfo>();
         public List<Dt_StockInfoDetail> PalletStockGoods { get; set; } = new List<Dt_StockInfoDetail>();
         public List<Dt_SplitPackageRecord> SplitRecords { get; set; } = new List<Dt_SplitPackageRecord>();
 
+        // 銆愭柊澧炪�戝凡澶勭悊鐨勬潯鐮侀泦鍚堬紙鐢ㄤ簬閬垮厤閲嶅锛�
+        public HashSet<string> ProcessedBarcodes { get; set; } = new HashSet<string>();
+        public List<string> AllBarcodes { get; set; } = new List<string>();
         // 绌烘墭鐩樼浉鍏冲睘鎬�
         public bool IsEmptyPallet { get; set; }
         public bool HasActiveTasks { get; set; }

--
Gitblit v1.9.3