From 61d8f975a9f02a4e1d3bd0eb234851e6da39fff4 Mon Sep 17 00:00:00 2001
From: pan <antony1029@163.com>
Date: 星期二, 02 十二月 2025 14:16:28 +0800
Subject: [PATCH] 提交

---
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs |  789 +++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 723 insertions(+), 66 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_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 f3e6e0a..b00aac2 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"
@@ -27,6 +27,8 @@
 using System.Reflection.Emit;
 using System.Threading.Tasks;
 using System.Xml.Linq;
+using WIDESEA_BasicService;
+using WIDESEA_Common.AllocateEnum;
 using WIDESEA_Common.CommonEnum;
 using WIDESEA_Common.LocationEnum;
 using WIDESEA_Common.OrderEnum;
@@ -41,6 +43,7 @@
 using WIDESEA_DTO.Allocate;
 using WIDESEA_DTO.Basic;
 using WIDESEA_DTO.Inbound;
+using WIDESEA_DTO.Outbound;
 using WIDESEA_DTO.Task;
 using WIDESEA_IAllocateService;
 using WIDESEA_IBasicService;
@@ -50,6 +53,8 @@
 using WIDESEA_IStockService;
 using WIDESEA_ITaskInfoService;
 using WIDESEA_Model.Models;
+using WIDESEA_Model.Models.Check;
+using WIDESEA_Model.Models.Outbound;
 
 namespace WIDESEA_TaskInfoService
 {
@@ -62,12 +67,17 @@
         private readonly IRepository<Dt_StockInfo> _stockRepository;
         private readonly ILocationInfoService _locationInfoService;
         private readonly IInboundOrderService _inboundOrderService;
-        private readonly IInboundOrderDetailService _inboundOrderDetailService;
+        private readonly IInboundOrderDetailService _inboundOrderDetailService; 
 
+        private readonly IRepository<Dt_AllocateOrderDetail> _allocateOrderDetailRepository;
+        private readonly IRepository<Dt_AllocateOrder> _allocateOrderRepository; 
+        private readonly IRepository<Dt_ReCheckOrder> _reCheckOrderRepository;
+        private readonly IRepository<Dt_OutboundBatch> _OutboundBatchRepository;
         private readonly IOutboundOrderService _outboundOrderService;
         private readonly IOutboundOrderDetailService _outboundOrderDetailService;
         private readonly IOutStockLockInfoService _outStockLockInfoService;
         private readonly ILocationStatusChangeRecordService _locationStatusChangeRecordService;
+        private readonly IMaterialUnitService _materialUnitService;
         private readonly IESSApiService _eSSApiService;
         private readonly IStockService _stockService;
         private readonly IRecordService _recordService;
@@ -92,7 +102,7 @@
 
         public List<int> TaskOutboundTypes => typeof(TaskTypeEnum).GetEnumIndexList();
 
-        public TaskService(IRepository<Dt_Task> BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IRepository<Dt_StockInfo> stockRepository, ILocationInfoService locationInfoService, IInboundOrderService inboundOrderService, ILocationStatusChangeRecordService locationStatusChangeRecordService, IESSApiService eSSApiService, ILogger<TaskService> logger, IStockService stockService, IRecordService recordService, IInboundOrderDetailService inboundOrderDetailService, IOutboundOrderService outboundOrderService, IOutboundOrderDetailService outboundOrderDetailService, IInvokeMESService invokeMESService, IOutStockLockInfoService outStockLockInfoService, IAllocateService allocateService) : base(BaseDal)
+        public TaskService(IRepository<Dt_Task> BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IRepository<Dt_StockInfo> stockRepository, ILocationInfoService locationInfoService, IInboundOrderService inboundOrderService, ILocationStatusChangeRecordService locationStatusChangeRecordService, IESSApiService eSSApiService, ILogger<TaskService> logger, IStockService stockService, IRecordService recordService, IInboundOrderDetailService inboundOrderDetailService, IOutboundOrderService outboundOrderService, IOutboundOrderDetailService outboundOrderDetailService, IInvokeMESService invokeMESService, IOutStockLockInfoService outStockLockInfoService, IAllocateService allocateService, IRepository<Dt_OutboundBatch> outboundBatchRepository, IRepository<Dt_ReCheckOrder> reCheckOrderRepository, IRepository<Dt_AllocateOrderDetail> allocateOrderDetailRepository, IRepository<Dt_AllocateOrder> allocateOrderRepository, IMaterialUnitService materialUnitService) : base(BaseDal)
         {
             _mapper = mapper;
             _unitOfWorkManage = unitOfWorkManage;
@@ -110,6 +120,11 @@
             _invokeMESService = invokeMESService;
             _outStockLockInfoService = outStockLockInfoService;
             _allocateService = allocateService;
+            _OutboundBatchRepository = outboundBatchRepository;
+            _reCheckOrderRepository = reCheckOrderRepository;
+            _allocateOrderDetailRepository = allocateOrderDetailRepository;
+            _allocateOrderRepository = allocateOrderRepository;
+            _materialUnitService = materialUnitService;
         }
 
 
@@ -126,7 +141,7 @@
 
                 if (int.TryParse(taskNum, out var newTaskNum))
                 {
-                    task = BaseDal.QueryFirst(x => x.TaskNum == newTaskNum);
+                    task = await BaseDal.QueryFirstAsync(x => x.TaskNum == newTaskNum);
                     if (task == null)
                     {
                         return WebResponseContent.Instance.Error("鏈壘鍒颁换鍔′俊鎭�");
@@ -141,10 +156,28 @@
                 MethodInfo? methodInfo = GetType().GetMethod(((TaskTypeEnum)task.TaskType) + "TaskCompleted");
                 if (methodInfo != null)
                 {
-                    WebResponseContent? responseContent = (WebResponseContent?)methodInfo.Invoke(this, new object[] { task });
-                    if (responseContent != null)
+                    object? taskResult = methodInfo.Invoke(this, new object[] { task });
+                    if (taskResult is Task<WebResponseContent> asyncTask)
                     {
-                        return responseContent;
+                        try
+                        {
+                            // 3. 寮傛绛夊緟 Task 瀹屾垚锛岃嚜鍔ㄨВ鏋愬嚭 WebResponseContent
+                            WebResponseContent responseContent = await asyncTask;
+                            if (responseContent != null)
+                            {
+                                return responseContent;
+                            }
+                        }
+                        catch (AggregateException ex)
+                        {
+                            _logger.LogError($"TaskService TaskCompleted  taskResult:   {ex.Message} ");
+                            return WebResponseContent.Instance.Error(ex.Message);
+                        }
+                        catch (Exception ex)
+                        {
+                            _logger.LogError(ex, $"Unexpected error in {task.TaskType}");
+                            return WebResponseContent.Instance.Error(ex.Message);
+                        }
                     }
                 }
                 return WebResponseContent.Instance.Error("鏈壘鍒颁换鍔$被鍨嬪搴斾笟鍔″鐞嗛�昏緫");
@@ -251,27 +284,27 @@
             {
                 foreach (var inboundOrder in inboundOrders)
                 {
-                    if (inboundOrder.OrderType == InOrderTypeEnum.Allocat.ObjToInt())//璋冩嫧鍏ュ簱
+                    if (inboundOrder.OrderType == InOrderTypeEnum.AllocatInbound.ObjToInt())//璋冩嫧鍏ュ簱
                     {
                         if (inboundOrder != null && inboundOrder.OrderStatus == InOrderStatusEnum.鍏ュ簱瀹屾垚.ObjToInt())
                         {
                             var allocate = _allocateService.Repository.QueryData(x => x.OrderNo == inboundOrder.InboundOrderNo).First();
-                            var feedmodel = new AllocateDto
+                            var allocatefeedmodel = new AllocateDto
                             {
                                 ReqCode = Guid.NewGuid().ToString(),
                                 ReqTime = DateTime.Now.ToString(),
-                                BusinessType = "2",
+                                BusinessType = BusinessTypeEnum.澶栭儴浠撳簱璋冩櫤浠�.ObjToInt().ToString(),
                                 FactoryArea = inboundOrder.FactoryArea,
                                 OperationType = 1,
                                 Operator = inboundOrder.Operator,
                                 OrderNo = inboundOrder.UpperOrderNo,
-                                fromWarehouse = allocate?.FromWarehouse??"",
-                                toWarehouse = allocate?.ToWarehouse??"",
+                                fromWarehouse = allocate?.FromWarehouse ?? "",
+                                toWarehouse = allocate?.ToWarehouse ?? "",
                                 Details = new List<AllocateDtoDetail>()
 
                             };
 
-                            var groupedData = inboundOrder.Details.GroupBy(item => new { item.MaterielCode, item.SupplyCode, item.BatchNo, item.lineNo, item.BarcodeUnit, item.WarehouseCode })
+                            var groupedData = inboundOrder.Details.GroupBy(item => new { item.MaterielCode, item.lineNo, item.BarcodeUnit, item.WarehouseCode })
                                .Select(group => new AllocateDtoDetail
                                {
                                    MaterialCode = group.Key.MaterielCode,
@@ -286,12 +319,12 @@
                                        Qty = row.BarcodeQty,
                                        BatchNo = row.BatchNo,
                                        SupplyCode = row.SupplyCode,
-                                       Unit = row.Unit
+                                       Unit = row.BarcodeUnit
                                    }).ToList()
                                }).ToList();
-                            feedmodel.Details = groupedData;
+                            allocatefeedmodel.Details = groupedData;
 
-                            var result = await _invokeMESService.FeedbackAllocate(feedmodel);
+                            var result = await _invokeMESService.FeedbackAllocate(allocatefeedmodel);
                             if (result != null && result.code == 200)
                             {
                                 _inboundOrderService.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 1 })
@@ -303,6 +336,59 @@
                     }
                     else if (inboundOrder.OrderType == InOrderTypeEnum.ReCheck.ObjToInt()) //閲嶆鍏ュ簱
                     {
+                        //涓嶉渶瑕佸洖浼犮�傚崰涓�涓綅缃��
+                    }
+                    else if (inboundOrder.OrderType == InOrderTypeEnum.InternalAllocat.ObjToInt()) //鏅轰粨璋冩櫤浠�
+                    {
+                        _logger.LogInformation($"InboundTaskCompleted 鍥炲啓MES  : {inboundOrder.InboundOrderNo }  ,ordertype: {InOrderTypeEnum.InternalAllocat.ObjToInt()} "  );
+                        // BusinessTypeEnum.鏅轰粨璋冩櫤浠�
+                        if (inboundOrder != null && inboundOrder.OrderStatus == InOrderStatusEnum.鍏ュ簱瀹屾垚.ObjToInt())
+                        {
+                            var allocate = _allocateService.Repository.QueryData(x => x.OrderNo == inboundOrder.InboundOrderNo).First();
+                            var allocatefeedmodel = new AllocateDto
+                            {
+                                ReqCode = Guid.NewGuid().ToString(),
+                                ReqTime = DateTime.Now.ToString(),
+                                BusinessType = BusinessTypeEnum.鏅轰粨璋冩櫤浠�.ObjToInt().ToString(),
+                                FactoryArea = inboundOrder.FactoryArea,
+                                OperationType = 1,
+                                Operator = inboundOrder.Operator,
+                                OrderNo = inboundOrder.UpperOrderNo,
+                                fromWarehouse = allocate?.FromWarehouse ?? "",
+                                toWarehouse = allocate?.ToWarehouse ?? "",
+                                Details = new List<AllocateDtoDetail>()
+
+                            };
+
+                            var groupedData = inboundOrder.Details.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.BarcodeQty),
+                                   // warehouseCode= "1072",
+                                   Unit = group.Key.BarcodeUnit,
+                                   Barcodes = group.Select(row => new BarcodeInfo
+                                   {
+                                       Barcode = row.Barcode,
+                                       Qty = row.BarcodeQty,
+                                       BatchNo = row.BatchNo,
+                                       SupplyCode = row.SupplyCode,
+                                       Unit = row.BarcodeUnit
+                                   }).ToList()
+                               }).ToList();
+                            allocatefeedmodel.Details = groupedData;
+
+                            var result = await _invokeMESService.FeedbackAllocate(allocatefeedmodel);
+                            if (result != null && result.code == 200)
+                            {
+                                _inboundOrderService.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 => it.OrderId == inboundOrder.Id).ExecuteCommand();
+                            }
+                        }
 
                     }
                     else
@@ -363,7 +449,14 @@
             return WebResponseContent.Instance.OK();
         }
 
-        public WebResponseContent OutboundTaskCompleted(Dt_Task task)
+
+        public async Task<WebResponseContent> OutAllocateTaskCompleted(Dt_Task task)
+        {
+            _logger.LogInformation($"TaskService  OutAllocateTaskCompleted: {task.TaskNum}");
+
+           return  await OutboundTaskCompleted(task);          
+        }
+        public async Task<WebResponseContent> OutboundTaskCompleted(Dt_Task task)
         {
             _logger.LogInformation($"TaskService  OutboundTaskCompleted: {task.TaskNum}");
             //鏌ヨ揣浣�
@@ -375,7 +468,7 @@
             locationInfo.LocationStatus = LocationStatusEnum.Free.ObjToInt();
             _locationInfoService.Repository.UpdateData(locationInfo);
 
-            var outloks = _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>().Where(x => x.TaskNum == task.TaskNum).ToList();
+            var outloks = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>().Where(x => x.TaskNum == task.TaskNum).ToListAsync();
 
             var stockids = outloks.Select(x => x.StockId).ToList();
 
@@ -439,12 +532,22 @@
                 stockInfo.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
                 _stockRepository.UpdateData(stockInfo);
 
+                var outboundOrder = _outboundOrderService.Db.Queryable<Dt_OutboundOrder>().First(x => x.OrderNo == task.OrderNo);
+
                 task.TaskStatus = TaskStatusEnum.Finish.ObjToInt();
                 BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? WIDESEA_Core.Enums.OperateTypeEnum.鑷姩瀹屾垚 : OperateTypeEnum.浜哄伐瀹屾垚);
 
                 _locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfo, beforelocationStatus, StockChangeType.Inbound.ObjToInt(), "", task.TaskNum);
 
 
+                if (outboundOrder != null)
+                {
+                    await HandleOutboundOrderToMESCompletion(outboundOrder, outboundOrder.OrderNo);
+                }
+                else
+                {
+                    _logger.LogInformation($"TaskService  InEmptyTaskCompleted: {task.TaskNum} ,鏈壘鍒板嚭搴撳崟銆�  ");
+                }
 
                 return content;
             }
@@ -454,63 +557,617 @@
             }
         }
 
-        public WebResponseContent InPickTaskCompleted(Dt_Task task)
+ 
+        public async Task<WebResponseContent> InPickTaskCompleted(Dt_Task task)
         {
-            _logger.LogInformation($"TaskService  InPickTaskCompleted: {task.TaskNum}");
-            //鏌ュ簱瀛�
-            Dt_StockInfo stockInfo = _stockRepository.Db.Queryable<Dt_StockInfo>().Includes(x => x.Details).Where(x => x.PalletCode == task.PalletCode).First();
-            if (stockInfo == null)
-            {
-                return WebResponseContent.Instance.Error($"鏈壘鍒版墭鐩樺搴旂殑缁勭洏淇℃伅");
-            }
-            if (stockInfo.Details.Count == 0 && stockInfo.PalletType != PalletTypeEnum.Empty.ObjToInt())
-            {
-                return WebResponseContent.Instance.Error($"鏈壘鍒拌鎵樼洏搴撳瓨鏄庣粏淇℃伅");
-            }
+            _logger.LogInformation($"TaskService InPickTaskCompleted: {task.TaskNum}");
 
-            // 鑾峰彇鎵�鏈夊洖搴撲腑鐨勫嚭搴撻攣瀹氳褰�
-            var returnLocks = _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
-                .Where(it => it.OrderNo == task.OrderNo && it.PalletCode == task.PalletCode && it.Status == (int)OutLockStockStatusEnum.鍥炲簱涓�)
-                .ToList();
-            // 鏇存柊鍑哄簱閿佸畾璁板綍鐘舵�佷负鍥炲簱瀹屾垚
-            foreach (var lockInfo in returnLocks)
+            try
             {
-                lockInfo.Status = (int)OutLockStockStatusEnum.宸插洖搴�;
-            }
-            _outStockLockInfoService.Db.Updateable(returnLocks).ExecuteCommand();
+                _unitOfWorkManage.BeginTran(); // 娣诲姞浜嬪姟绠$悊
 
-            //鏌ヨ揣浣�
-            Dt_LocationInfo locationInfo = _locationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress);
-            if (locationInfo == null)
-            {
-                return WebResponseContent.Instance.Error($"鏈壘鍒板搴旂殑缁堢偣璐т綅淇℃伅");
-            }
-            stockInfo.LocationCode = task.TargetAddress;
-            stockInfo.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
-            stockInfo.Details.ForEach(x =>
-            {
-                x.Status = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
-            });
-            _stockService.StockInfoService.Repository.UpdateData(stockInfo);
-            _stockService.StockInfoDetailService.Repository.UpdateData(stockInfo.Details);
+                // 鏌ュ簱瀛�
+                Dt_StockInfo stockInfo = await _stockRepository.Db.Queryable<Dt_StockInfo>()
+                    .Includes(x => x.Details)
+                    .Where(x => x.PalletCode == task.PalletCode)
+                    .FirstAsync();
 
-            if (stockInfo.PalletType == PalletTypeEnum.Empty.ObjToInt())
-            {
-                locationInfo.LocationStatus = LocationStatusEnum.Pallet.ObjToInt();
-            }
-            else
-            {
-                locationInfo.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
-            }
-            _locationInfoService.Repository.UpdateData(locationInfo);
+                if (stockInfo == null)
+                {
+                    _logger.LogInformation($"TaskService InPickTaskCompleted: 鏈壘鍒版墭鐩樺搴旂殑缁勭洏淇℃伅.{task.TaskNum}");
+                    return WebResponseContent.Instance.Error($"鏈壘鍒版墭鐩樺搴旂殑缁勭洏淇℃伅");
+                }
 
-            task.TaskStatus = TaskStatusEnum.Finish.ObjToInt();
+                if (stockInfo.Details.Count == 0 && stockInfo.PalletType != PalletTypeEnum.Empty.ObjToInt())
+                {
+                    _logger.LogInformation($"TaskService InPickTaskCompleted: 鏈壘鍒拌鎵樼洏搴撳瓨鏄庣粏淇℃伅.{task.TaskNum}");
+                    return WebResponseContent.Instance.Error($"鏈壘鍒拌鎵樼洏搴撳瓨鏄庣粏淇℃伅");
+                }
 
-            BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateTypeEnum.鑷姩瀹屾垚 : OperateTypeEnum.浜哄伐瀹屾垚);
+                // 鏌ヨ揣浣�
+                Dt_LocationInfo locationInfo = _locationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress);
+                if (locationInfo == null)
+                {
+                    _logger.LogInformation($"TaskService InPickTaskCompleted: 鏈壘鍒板搴旂殑缁堢偣璐т綅淇℃伅 {task.TaskNum}.");
+                    return WebResponseContent.Instance.Error($"鏈壘鍒板搴旂殑缁堢偣璐т綅淇℃伅");
+                }
+
+                var beforelocationStatus = locationInfo.LocationStatus;
+
+                // 鑾峰彇鎵�鏈夊洖搴撲腑鐨勫嚭搴撻攣瀹氳褰�
+                var returnLocks = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+                    .Where(it => it.OrderNo == task.OrderNo &&
+                               it.PalletCode == task.PalletCode &&
+                               it.Status == (int)OutLockStockStatusEnum.鍥炲簱涓�)
+                    .ToListAsync();
+
+                // 鏇存柊鍑哄簱閿佸畾璁板綍鐘舵�佷负鍥炲簱瀹屾垚
+                foreach (var lockInfo in returnLocks)
+                {
+                    lockInfo.Status = (int)OutLockStockStatusEnum.宸插洖搴�;
+                    lockInfo.Operator = App.User.UserName;
+                }
+
+                if (returnLocks.Any())
+                {
+                    await _outStockLockInfoService.Db.Updateable(returnLocks).ExecuteCommandAsync();
+                    _logger.LogInformation($"鏇存柊{returnLocks.Count}鏉¢攣瀹氳褰曚负宸插洖搴撶姸鎬�");
+                }
+
+                // 鏇存柊搴撳瓨淇℃伅
+                stockInfo.LocationCode = task.TargetAddress;
+                stockInfo.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt(); 
+
+                // 鏇存柊搴撳瓨鏄庣粏鐘舵��
+                if (stockInfo.Details != null && stockInfo.Details.Any())
+                {
+                    foreach (var detail in stockInfo.Details)
+                    {
+                        detail.Status = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt(); 
+
+                        // 纭繚搴撳瓨鏁伴噺涓庡嚭搴撴暟閲忎竴鑷�
+                        if (detail.Status == StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt())
+                        {
+                            detail.OutboundQuantity = 0; // 鍏ュ簱瀹屾垚鏃跺嚭搴撴暟閲忔竻闆�
+                        }
+                    }
+                      _stockService.StockInfoDetailService.Repository.UpdateData(stockInfo.Details);
+                }
+
+                  _stockService.StockInfoService.Repository.UpdateData(stockInfo);
+
+                // 澶勭悊鍥炲簱鐩稿叧鐨勫簱瀛樻槑缁�
+                await ProcessStockDetailsForReturn(task, stockInfo.Id);
+
+                // 鍒犻櫎闆跺簱瀛樻暟鎹�
+                await DeleteZeroQuantityStockDetails(stockInfo.Id);
+
+                // 鏇存柊璐т綅鐘舵��
+                if (stockInfo.PalletType == PalletTypeEnum.Empty.ObjToInt())
+                {
+                    locationInfo.LocationStatus = LocationStatusEnum.Pallet.ObjToInt();
+                }
+                else
+                {
+                    locationInfo.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
+                }
+             
+                 _locationInfoService.Repository.UpdateData(locationInfo);
+
+                // 鏇存柊璁㈠崟鐩稿叧鏁版嵁
+                await UpdateOrderDataAfterReturn(task.OrderNo, returnLocks);
+
+                // 鑾峰彇骞舵洿鏂板嚭搴撹鍗�
+                var outboundOrder = await _outboundOrderService.Db.Queryable<Dt_OutboundOrder>()
+                    .FirstAsync(x => x.OrderNo == task.OrderNo);
+
+                task.TaskStatus = TaskStatusEnum.Finish.ObjToInt(); 
+
+                // 鍒犻櫎浠诲姟璁板綍
+                BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateTypeEnum.鑷姩瀹屾垚 : OperateTypeEnum.浜哄伐瀹屾垚);
+                BaseDal.DeleteData(task);
+
+                // 璁板綍璐т綅鐘舵�佸彉鏇�
+                _locationStatusChangeRecordService.AddLocationStatusChangeRecord(
+                    locationInfo,
+                    beforelocationStatus,
+                    StockChangeType.Inbound.ObjToInt(),
+                    "",
+                    task.TaskNum
+                );
+
+                if (outboundOrder != null)
+                {
+                    // 妫�鏌ヨ鍗曠姸鎬佹槸鍚﹂渶瑕佹洿鏂�
+                    await CheckAndUpdateOrderStatusAfterReturn(task.OrderNo);
+
+                    // 澶勭悊MES鍙嶉
+                    await HandleOutboundOrderToMESCompletion(outboundOrder, outboundOrder.OrderNo);
+                }
+                else
+                {
+                    _logger.LogInformation($"TaskService InPickTaskCompleted: {task.TaskNum} ,鏈壘鍒板嚭搴撳崟銆�");
+                }
+
+                _unitOfWorkManage.CommitTran(); // 鎻愪氦浜嬪姟
+
+                _logger.LogInformation($"鍥炲簱浠诲姟瀹屾垚澶勭悊鎴愬姛 - 浠诲姟鍙�: {task.TaskNum}, 鎵樼洏: {task.PalletCode}");
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran(); // 鍥炴粴浜嬪姟
+                _logger.LogError($"TaskService InPickTaskCompleted澶辫触 - TaskNum: {task.TaskNum}, Error: {ex.Message}");
+                return WebResponseContent.Instance.Error($"鍥炲簱浠诲姟瀹屾垚澶勭悊澶辫触: {ex.Message}");
+            }
 
             return WebResponseContent.Instance.OK();
         }
 
+        /// <summary>
+        /// 鍥炲簱鍚庢洿鏂拌鍗曟暟鎹�
+        /// </summary>
+        private async Task UpdateOrderDataAfterReturn(string orderNo, List<Dt_OutStockLockInfo> returnLocks)
+        {
+            try
+            {
+                // 鑾峰彇鎵�鏈夊彈褰卞搷鐨勮鍗曟槑缁咺D
+                var affectedDetailIds = returnLocks
+                    .Select(x => x.OrderDetailId)
+                    .Distinct()
+                    .ToList();
+
+                foreach (var detailId in affectedDetailIds)
+                {
+                    // 璁$畻璇ヨ鍗曟槑缁嗙殑鍥炲簱鎬绘暟閲�
+                    var detailReturnLocks = returnLocks
+                        .Where(x => x.OrderDetailId == detailId)
+                        .ToList();
+
+                    decimal totalReturnQty = detailReturnLocks.Sum(x => x.AssignQuantity - x.PickedQty);
+
+                    if (totalReturnQty > 0)
+                    {
+                        // 鑾峰彇璁㈠崟鏄庣粏
+                        var orderDetail = await _outboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>()
+                            .FirstAsync(x => x.Id == detailId);
+
+                        if (orderDetail != null)
+                        {
+                            // 鏇存柊閿佸畾鏁伴噺锛堝洖搴撳悗閿佸畾鏁伴噺搴斿噺灏戯級
+                            var remainingLocks = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+                                .Where(x => x.OrderDetailId == detailId &&
+                                           x.Status == (int)OutLockStockStatusEnum.鍑哄簱涓�)
+                                .ToListAsync();
+
+                            decimal remainingLockQty = remainingLocks.Sum(x => x.AssignQuantity - x.PickedQty);
+
+                            // 鏇存柊璁㈠崟鏄庣粏
+                            await _outboundOrderDetailService.Db.Updateable<Dt_OutboundOrderDetail>()
+                                .SetColumns(it => new Dt_OutboundOrderDetail
+                                {
+                                    LockQuantity = remainingLockQty, 
+                                })
+                                .Where(it => it.Id == detailId)
+                                .ExecuteCommandAsync();
+
+                            // 鏇存柊璁㈠崟鏄庣粏鐘舵��
+                            await UpdateOrderDetailStatus(detailId);
+
+                            _logger.LogInformation($"鍥炲簱鏇存柊璁㈠崟鏄庣粏 - OrderDetailId: {detailId}, " +
+                                                  $"鎵e噺閿佸畾鏁伴噺: {totalReturnQty}, 鏂伴攣瀹氭暟閲�: {remainingLockQty}");
+                        }
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+                _logger.LogError($"UpdateOrderDataAfterReturn澶辫触 - OrderNo: {orderNo}, Error: {ex.Message}");
+                throw;
+            }
+        }
+        /// <summary>
+        /// 鏇存柊璁㈠崟鏄庣粏鐘舵��
+        /// </summary>
+        private async Task UpdateOrderDetailStatus(int orderDetailId)
+        {
+            try
+            {
+                var orderDetail = await _outboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>()
+                    .FirstAsync(x => x.Id == orderDetailId);
+
+                if (orderDetail == null)
+                {
+                    _logger.LogWarning($"UpdateOrderDetailStatus澶辫触锛氭湭鎵惧埌璁㈠崟鏄庣粏锛孖D: {orderDetailId}");
+                    return;
+                }
+
+                int newStatus = orderDetail.OrderDetailStatus;
+
+                // 1. 妫�鏌ユ槸鍚﹀凡瀹屾垚
+                if (orderDetail.OverOutQuantity >= orderDetail.NeedOutQuantity)
+                {
+                    newStatus = (int)OrderDetailStatusEnum.Over;
+                }
+                // 2. 妫�鏌ユ槸鍚︽鍦ㄨ繘琛屼腑锛堟湁閿佸畾鏁伴噺鎴栭儴鍒嗘嫞閫夛級
+                else if (orderDetail.LockQuantity > 0 ||
+                         (orderDetail.OverOutQuantity > 0 && orderDetail.OverOutQuantity < orderDetail.NeedOutQuantity))
+                {
+                    newStatus = (int)OrderDetailStatusEnum.Outbound;
+                }
+                // 3. 妫�鏌ユ槸鍚︽湁閿佸畾浣嗘湭鎷i��
+                else if (orderDetail.LockQuantity > 0 && orderDetail.OverOutQuantity == 0)
+                {
+                    newStatus = (int)OrderDetailStatusEnum.AssignOverPartial;
+                }
+                // 4. 鍚﹀垯涓烘柊璁㈠崟
+                else
+                {
+                    newStatus = (int)OrderDetailStatusEnum.New;
+                }
+
+                // 鍙湁鐘舵�佸彉鍖栨椂鎵嶆洿鏂�
+                if (orderDetail.OrderDetailStatus != newStatus)
+                {
+                    await _outboundOrderDetailService.Db.Updateable<Dt_OutboundOrderDetail>()
+                        .SetColumns(it => new Dt_OutboundOrderDetail
+                        {
+                            OrderDetailStatus = newStatus, 
+                        })
+                        .Where(it => it.Id == orderDetailId)
+                        .ExecuteCommandAsync();
+
+                    _logger.LogInformation($"鏇存柊璁㈠崟鏄庣粏鐘舵�� - OrderDetailId: {orderDetailId}, " +
+                                          $"鏃х姸鎬�: {orderDetail.OrderDetailStatus}, 鏂扮姸鎬�: {newStatus}, " +
+                                          $"宸插嚭搴�: {orderDetail.OverOutQuantity}/{orderDetail.NeedOutQuantity}, " +
+                                          $"閿佸畾鏁伴噺: {orderDetail.LockQuantity}");
+                }
+            }
+            catch (Exception ex)
+            {
+                _logger.LogError($"UpdateOrderDetailStatus澶辫触 - OrderDetailId: {orderDetailId}, Error: {ex.Message}");
+                throw;
+            }
+        }
+        /// <summary>
+        /// 鍥炲簱鍚庢鏌ュ苟鏇存柊璁㈠崟鐘舵��
+        /// </summary>
+        private async Task CheckAndUpdateOrderStatusAfterReturn(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();
+
+                bool allCompleted = true;
+                bool hasInProgress = false;
+
+                foreach (var detail in orderDetails)
+                {
+                    // 妫�鏌ユ槸鍚﹀畬鎴�
+                    if (detail.OverOutQuantity < detail.NeedOutQuantity)
+                    {
+                        allCompleted = false;
+                    }
+
+                    // 妫�鏌ユ槸鍚︽湁杩涜涓殑浠诲姟锛堥攣瀹氭垨閮ㄥ垎鎷i�夛級
+                    if (detail.LockQuantity > 0 ||
+                        detail.OrderDetailStatus == OrderDetailStatusEnum.Outbound.ObjToInt())
+                    {
+                        hasInProgress = true;
+                    }
+                }
+
+                var outboundOrder = await _outboundOrderService.Db.Queryable<Dt_OutboundOrder>()
+                    .FirstAsync(x => x.OrderNo == orderNo);
+
+                if (outboundOrder == null) return;
+
+                int newStatus;
+                if (allCompleted)
+                {
+                    newStatus = (int)OutOrderStatusEnum.鍑哄簱瀹屾垚;
+                }
+                else if (hasInProgress)
+                {
+                    newStatus = (int)OutOrderStatusEnum.鍑哄簱涓�;
+                }
+                else
+                {
+                    newStatus = (int)OutOrderStatusEnum.鏈紑濮�;
+                }
+
+                if (outboundOrder.OrderStatus != newStatus)
+                {
+                    await _outboundOrderService.Db.Updateable<Dt_OutboundOrder>()
+                        .SetColumns(x => new Dt_OutboundOrder
+                        {
+                            OrderStatus = newStatus,
+                            Operator = App.User.UserName,
+                        })
+                        .Where(x => x.OrderNo == orderNo)
+                        .ExecuteCommandAsync();
+
+                    _logger.LogInformation($"鍥炲簱鍚庢洿鏂拌鍗曠姸鎬� - OrderNo: {orderNo}, 鏂扮姸鎬�: {newStatus}");
+                }
+            }
+            catch (Exception ex)
+            {
+                _logger.LogError($"CheckAndUpdateOrderStatusAfterReturn澶辫触 - OrderNo: {orderNo}, Error: {ex.Message}");
+                throw;
+            }
+        }
+
+        /// <summary>
+        /// 澶勭悊鍥炲簱鐨勫簱瀛樻槑缁嗭紙澧炲己鐗堬級
+        /// </summary>
+        private async Task ProcessStockDetailsForReturn(Dt_Task task, int stockId)
+        {
+            try
+            {
+                // 鑾峰彇鎵�鏈夐渶瑕佸鐞嗙殑搴撳瓨鏄庣粏
+                var stockDetails = await _stockService.StockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+                    .Where(x => x.StockId == stockId)
+                    .ToListAsync();
+
+                foreach (var detail in stockDetails)
+                {
+                    // 纭繚搴撳瓨鐘舵�佹纭�
+                    if (detail.Status == StockStatusEmun.鍏ュ簱纭.ObjToInt())
+                    {
+                        // 濡傛灉宸茬粡鏄叆搴撶‘璁ょ姸鎬侊紝鏇存柊涓哄叆搴撳畬鎴�
+                        detail.Status = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
+                        detail.OutboundQuantity = 0;
+
+                        await _stockService.StockInfoDetailService.Db.Updateable(detail).ExecuteCommandAsync();
+
+                        _logger.LogInformation($"鏇存柊搴撳瓨鏄庣粏鐘舵�� - 鏉$爜: {detail.Barcode}, " +
+                                              $"鏂扮姸鎬�: {detail.Status}, 鍑哄簱鏁伴噺: {detail.OutboundQuantity}");
+                    }
+                    else if (detail.Status == StockStatusEmun.鍑哄簱閿佸畾.ObjToInt() ||
+                             detail.Status == StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt())
+                    {
+                        // 杩欎簺鐘舵�佷笉搴旇瀛樺湪锛岃褰曡鍛�
+                        _logger.LogWarning($"寮傚父搴撳瓨鐘舵�� - 鏉$爜: {detail.Barcode}, 鐘舵��: {detail.Status}, " +
+                                         $"浠诲姟鍙�: {task.TaskNum}");
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+                _logger.LogError($"ProcessStockDetailsForReturn澶辫触 - StockId: {stockId}, Error: {ex.Message}");
+                throw;
+            }
+        }
+
+        /// <summary>
+        /// 鍒犻櫎闆跺簱瀛樻暟鎹紙澧炲己鐗堬級
+        /// </summary>
+        private async Task DeleteZeroQuantityStockDetails(int stockId)
+        {
+            try
+            {
+                // 鏌ユ壘搴撳瓨鏁伴噺涓�0鐨勮褰�
+                var zeroStockDetails = await _stockService.StockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+                    .Where(x => x.StockId == stockId && x.StockQuantity <= 0)
+                    .ToListAsync();
+
+                if (zeroStockDetails.Any())
+                {
+                    await _stockService.StockInfoDetailService.Db.Deleteable(zeroStockDetails).ExecuteCommandAsync();
+                    _logger.LogInformation($"鍒犻櫎{zeroStockDetails.Count}鏉¢浂搴撳瓨璁板綍 - StockId: {stockId}");
+                }
+            }
+            catch (Exception ex)
+            {
+                _logger.LogError($"DeleteZeroQuantityStockDetails澶辫触 - StockId: {stockId}, Error: {ex.Message}");
+                throw;
+            }
+        }
+
+        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();
+
+                bool allCompleted = true;
+                foreach (var detail in orderDetails)
+                {
+                    _logger.LogInformation($"TaskService  HandleOutboundOrderToMESCompletion: {outboundOrder.OrderNo} , {detail.NeedOutQuantity}");
+                    if (detail.OverOutQuantity < detail.NeedOutQuantity)
+                    {
+                        allCompleted = false;
+                        break;
+                    }
+                }
+                _logger.LogInformation($"TaskService  HandleOutboundOrderToMESCompletion: {outboundOrder.OrderNo} , {allCompleted}");
+                int newStatus = allCompleted ? (int)OutOrderStatusEnum.鍑哄簱瀹屾垚 : (int)OutOrderStatusEnum.鍑哄簱涓�;
+
+                if (outboundOrder.OrderStatus != newStatus)
+                {
+                    await _outboundOrderService.Db.Updateable<Dt_OutboundOrder>()
+                        .SetColumns(x => x.OrderStatus == newStatus)
+                        .Where(x => x.OrderNo == orderNo)
+                        .ExecuteCommandAsync();
+
+                }
+                //鍙湁姝e父鍒嗘嫞瀹屾垚鏃舵墠鍚慚ES鍙嶉
+                if (allCompleted && newStatus == (int)OutOrderStatusEnum.鍑哄簱瀹屾垚)
+                {
+
+                    if (outboundOrder.OrderType == OutOrderTypeEnum.Allocate.ObjToInt())
+                    {
+                        var allocate = _allocateService.Repository.QueryData(x => x.UpperOrderNo == outboundOrder.UpperOrderNo).First();
+                        var allocatefeedmodel = new AllocateDto
+                        {
+                            ReqCode = Guid.NewGuid().ToString(),
+                            ReqTime = DateTime.Now.ToString(),
+                            BusinessType = "2",
+                            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�夊畬鎴� || x.Status == (int)OutLockStockStatusEnum.宸插洖搴�))
+                                .ToListAsync();
+
+                            var detailModel = new AllocateDtoDetail
+                            {
+                                MaterialCode = detail.MaterielCode,
+                                LineNo = detail.lineNo,  
+                                WarehouseCode = detail.WarehouseCode,
+                                Qty = detailLocks.Sum(x=>x.PickedQty),                           
+                                Unit = detail.BarcodeUnit,
+                                Barcodes = new List<BarcodeInfo> ()
+                            };
+                            foreach (var item in detailLocks)
+                            {
+                                var barModel = new  BarcodeInfo
+                                {
+                                    Barcode = item.CurrentBarcode,
+                                    SupplyCode = item.SupplyCode,
+                                    BatchNo = item.BatchNo,
+                                    Unit = item.BarcodeUnit,
+                                    Qty = item.PickedQty
+                                };
+                                // 鍗曚綅涓嶄竴鑷存椂杞崲
+                                if (item.BarcodeUnit != item.Unit)
+                                {
+                                    var convertResult = await _materialUnitService.ConvertAsync(item.MaterielCode, item.PickedQty, item.Unit, item.BarcodeUnit);
+                                    barModel.Unit = convertResult.Unit;
+                                    barModel.Qty = convertResult.Quantity;
+                                }
+
+                                detailModel.Qty += barModel.Qty;                           
+                                detailModel.Barcodes.Add(barModel);
+                            }
+
+
+                            allocatefeedmodel.Details.Add(detailModel);
+                        }
+                        
+                        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();
+
+                            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>()
+                        };
+
+
+                        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�夊畬鎴� || x.Status == (int)OutLockStockStatusEnum.宸插洖搴�))
+                                .ToListAsync();
+
+                            var detailModel = new FeedbackOutboundDetailsModel
+                            {
+                                materialCode = detail.MaterielCode,
+                                lineNo = detail.lineNo, // 娉ㄦ剰锛氳繖閲屽彲鑳介渶瑕佽皟鏁村瓧娈靛悕
+                                warehouseCode = detail.WarehouseCode,
+                                qty = detail.PickedQty,  
+                                currentDeliveryQty = detail.PickedQty,
+                                unit = detail.Unit,
+                                barcodes = new List<WIDESEA_DTO.Outbound.BarcodesModel>()
+                            };
+                            foreach (var item in detailLocks)
+                            {
+                                var barModel = new WIDESEA_DTO.Outbound.BarcodesModel
+                                {
+                                    barcode = item.CurrentBarcode,
+                                    supplyCode = item.SupplyCode,
+                                    batchNo = item.BatchNo,
+                                    unit = item.BarcodeUnit,
+                                    qty = item.PickedQty
+                                };
+                                // 鍗曚綅涓嶄竴鑷存椂杞崲
+                                if (item.BarcodeUnit != item.Unit)
+                                {
+                                    var convertResult = await _materialUnitService.ConvertAsync(item.MaterielCode, item.PickedQty, item.Unit, item.BarcodeUnit);
+                                    barModel.unit = convertResult.Unit;
+                                    barModel.qty = convertResult.Quantity;
+                                }
+
+                                detailModel.qty += barModel.qty;
+                                detailModel.currentDeliveryQty += barModel.qty;
+                                detailModel.barcodes.Add(barModel);
+                            }
+                            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}");
+            }
+
+        }
+
+ 
         public async Task<WebResponseContent> OutEmptyTaskCompleted(Dt_Task task)
         {
             WebResponseContent content = new WebResponseContent();
@@ -539,11 +1196,11 @@
                 task.TaskStatus = TaskStatusEnum.Finish.ObjToInt();
                 BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateTypeEnum.鑷姩瀹屾垚 : OperateTypeEnum.浜哄伐瀹屾垚);
                 _stockService.StockInfoService.Repository.DeleteAndMoveIntoHty(stockInfo, App.User.UserId == 0 ? OperateTypeEnum.鑷姩瀹屾垚 : OperateTypeEnum.浜哄伐瀹屾垚);
-                _stockRepository.Db.Deleteable(stockInfo).ExecuteCommand();
-
+                //_stockRepository.Db.Deleteable(stockInfo).ExecuteCommand();
+                _stockService.StockInfoService.DeleteData(stockInfo);
                 _locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Outbound.ObjToInt(), stockInfo.Details.FirstOrDefault()?.OrderNo ?? "", task.TaskNum);
 
-                return WebResponseContent.Instance.OK();
+                return await Task.FromResult(WebResponseContent.Instance.OK());
 
             }
             catch (Exception ex)

--
Gitblit v1.9.3