From 64840e4e6d97d177b8a765ba8c53888abcf86d16 Mon Sep 17 00:00:00 2001
From: heshaofeng <heshaofeng@hnkhzn.com>
Date: 星期二, 13 一月 2026 18:48:20 +0800
Subject: [PATCH] Merge branch 'htq20251215' of http://115.159.85.185:8098/r/ZhongRui/ALDbanyunxiangmu into htq20251215

---
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs |  154 ++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 140 insertions(+), 14 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 5e89b8c..2a47bdd 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"
@@ -282,6 +282,23 @@
                     _inboundOrderService.UpdateData(inboundOrder);
                 }
             }
+            Dt_OutboundOrder outboundOrder = _outboundOrderService.Db.Queryable<Dt_OutboundOrder>().Where(x => x.OrderNo == stockInfo.Details.FirstOrDefault().OrderNo).Includes(x => x.Details).First();
+
+            if (outboundOrder != null)
+            {
+                foreach (var item in stockInfo.Details.Where(x => x.OrderNo == outboundOrder.OrderNo).ToList())
+                {
+                    var inbounddetail = _allocateMaterialInfo.QueryFirst(x => x.OrderNo == item.OrderNo && x.Barcode == item.Barcode);
+                    if (inbounddetail != null)
+                    {
+                        var alldelete = _allocateMaterialInfo.DeleteAndMoveIntoHty(inbounddetail, OperateTypeEnum.鑷姩鍒犻櫎);
+                        if (!alldelete)
+                        {
+                            await Db.Deleteable(task).ExecuteCommandAsync();
+                        }
+                    }
+                }
+            }
             stockInfo.LocationCode = task.TargetAddress;
             stockInfo.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
             stockInfo.Details.ForEach(x =>
@@ -345,8 +362,9 @@
                                 Details = new List<AllocateDtoDetail>()
 
                             };
-
-                            var groupedData = inboundOrder.Details.GroupBy(item => new { item.MaterielCode, item.lineNo, item.BarcodeUnit, item.WarehouseCode })
+                            var query = inboundOrder.Details.AsQueryable();
+                            query = query.Where(item => item.ReturnToMESStatus == 0);
+                            var groupedData = query.GroupBy(item => new { item.MaterielCode, item.lineNo, item.BarcodeUnit, item.WarehouseCode })
                                .Select(group => new AllocateDtoDetail
                                {
                                    MaterialCode = group.Key.MaterielCode,
@@ -403,8 +421,9 @@
                                 Details = new List<AllocateDtoDetail>()
 
                             };
-
-                            var groupedData = inboundOrder.Details.GroupBy(item => new { item.MaterielCode, item.lineNo, item.BarcodeUnit, item.WarehouseCode })
+                            var query = inboundOrder.Details.AsQueryable();
+                            query = query.Where(item => item.ReturnToMESStatus == 0);
+                            var groupedData = query.GroupBy(item => new { item.MaterielCode, item.lineNo, item.BarcodeUnit, item.WarehouseCode })
                                .Select(group => new AllocateDtoDetail
                                {
                                    MaterialCode = group.Key.MaterielCode,
@@ -452,8 +471,9 @@
                                 details = new List<FeedbackInboundDetailsModel>()
 
                             };
-
-                            var groupedData = inboundOrder.Details.GroupBy(item => new { item.MaterielCode, item.SupplyCode, item.BatchNo, item.lineNo, item.BarcodeUnit, item.WarehouseCode })
+                            var query = inboundOrder.Details.AsQueryable();
+                            query = query.Where(item => item.ReturnToMESStatus == 0);
+                            var groupedData = query.GroupBy(item => new { item.MaterielCode, item.SupplyCode, item.BatchNo, item.lineNo, item.BarcodeUnit, item.WarehouseCode })
                                .Select(group => new FeedbackInboundDetailsModel
                                {
                                    materialCode = group.Key.MaterielCode,
@@ -588,7 +608,11 @@
 
             stock.Details.ForEach(x =>
             {
-                x.Status = StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt();
+                if (x.Status != StockStatusEmun.鎵嬪姩鍐荤粨.ObjToInt()) 
+                {
+                    x.Status = StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt();
+                }
+                
             });
 
             _stockService.StockInfoService.Db.UpdateNav(stock).IncludesAllFirstLayer().ExecuteCommand();
@@ -737,15 +761,19 @@
                     await Db.Deleteable(task).ExecuteCommandAsync();
                 }
                 Dt_OutboundOrder outboundOrder = _outboundOrderService.Db.Queryable<Dt_OutboundOrder>().Where(x => x.OrderNo == stockInfo.Details.FirstOrDefault().OrderNo).Includes(x=>x.Details).First();
-                foreach (var item in stockInfo.Details.Where(x => x.OrderNo == outboundOrder.OrderNo).ToList())
+
+                if(outboundOrder != null)
                 {
-                    var inbounddetail = _allocateMaterialInfo.QueryFirst(x => x.OrderNo == item.OrderNo && x.Barcode == item.Barcode);
-                    if (inbounddetail != null)
+                    foreach (var item in stockInfo.Details.Where(x => x.OrderNo == outboundOrder.OrderNo).ToList())
                     {
-                        var alldelete = _allocateMaterialInfo.DeleteAndMoveIntoHty(inbounddetail, OperateTypeEnum.鑷姩鍒犻櫎);
-                        if (!alldelete)
+                        var inbounddetail = _allocateMaterialInfo.QueryFirst(x => x.OrderNo == item.OrderNo && x.Barcode == item.Barcode);
+                        if (inbounddetail != null)
                         {
-                            await Db.Deleteable(task).ExecuteCommandAsync();
+                            var alldelete = _allocateMaterialInfo.DeleteAndMoveIntoHty(inbounddetail, OperateTypeEnum.鑷姩鍒犻櫎);
+                            if (!alldelete)
+                            {
+                                await Db.Deleteable(task).ExecuteCommandAsync();
+                            }
                         }
                     }
                 }
@@ -976,7 +1004,10 @@
                 {
                     foreach (var detail in stockInfo.Details)
                     {
-                        detail.Status = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
+                        if(detail.Status != StockStatusEmun.鎵嬪姩鍐荤粨.ObjToInt())
+                        {
+                            detail.Status = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
+                        }
                         detail.OutboundQuantity = 0;
                     }
                     _stockService.StockInfoDetailService.Repository.UpdateData(stockInfo.Details);
@@ -1980,6 +2011,101 @@
                 return await Task.FromResult(WebResponseContent.Instance.Error(ex.Message));
             }
         }
+
+        /// <summary>
+        /// 閲嶆鍏ュ簱瀹屾垚
+        /// </summary>
+        /// <param name="task"></param>
+        /// <returns></returns>
+        public async Task<WebResponseContent> InQualityTaskCompleted(Dt_Task task)
+        {
+
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+
+                Dt_StockInfo stockInfo = await _stockRepository.Db.Queryable<Dt_StockInfo>()
+                    .Includes(x => x.Details)
+                    .Where(x => x.PalletCode == task.PalletCode)
+                    .FirstAsync();
+
+                if (stockInfo == null)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒版墭鐩樺搴旂殑缁勭洏淇℃伅");
+                }
+
+                if (stockInfo.Details.Count == 0 && stockInfo.PalletType != PalletTypeEnum.Empty.ObjToInt())
+                {
+                    _logger.LogInformation($"TaskService InPickTaskCompleted: 鏈壘鍒拌鎵樼洏搴撳瓨鏄庣粏淇℃伅.{task.TaskNum}");
+                    return WebResponseContent.Instance.Error($"鏈壘鍒拌鎵樼洏搴撳瓨鏄庣粏淇℃伅");
+                }
+                Dt_LocationInfo locationInfo = _locationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress);
+                if (locationInfo == null)
+                {
+                    return content.Error($"鏈壘鍒板搴旂殑缁堢偣璐т綅淇℃伅");
+                }
+
+                if (!string.IsNullOrEmpty(stockInfo.LocationCode))
+                {
+                    return WebResponseContent.Instance.Error($"璇ユ墭鐩樺凡缁戝畾璐т綅");
+                }
+                if (locationInfo.LocationStatus == LocationStatusEnum.InStock.ObjToInt())
+                {
+                    return WebResponseContent.Instance.Error($"璐т綅鐘舵�佷笉姝g‘");
+                }
+
+                _unitOfWorkManage.BeginTran();
+
+                var beforelocationStatus = locationInfo.LocationStatus;
+                locationInfo.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
+                _locationInfoService.Repository.UpdateData(locationInfo);
+
+                stockInfo.LocationCode = locationInfo.LocationCode;
+                stockInfo.PalletCode = task.PalletCode;
+                stockInfo.LocationCode = task.TargetAddress;
+                stockInfo.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
+                _stockRepository.UpdateData(stockInfo);
+
+                task.TaskStatus = TaskStatusEnum.Finish.ObjToInt();
+                var result = _task_HtyService.DeleteAndMoveIntoHty(task, OperateTypeEnum.鑷姩瀹屾垚);
+                _unitOfWorkManage.CommitTran();
+                if (!result)
+                {
+                    await Db.Deleteable(task).ExecuteCommandAsync();
+                }
+                Dt_OutboundOrder outboundOrder = _outboundOrderService.Db.Queryable<Dt_OutboundOrder>().Where(x => x.OrderNo == stockInfo.Details.FirstOrDefault().OrderNo).Includes(x => x.Details).First();
+
+                if (outboundOrder != null)
+                {
+                    foreach (var item in stockInfo.Details.Where(x => x.OrderNo == outboundOrder.OrderNo).ToList())
+                    {
+                        var inbounddetail = _allocateMaterialInfo.QueryFirst(x => x.OrderNo == item.OrderNo && x.Barcode == item.Barcode);
+                        if (inbounddetail != null)
+                        {
+                            var alldelete = _allocateMaterialInfo.DeleteAndMoveIntoHty(inbounddetail, OperateTypeEnum.鑷姩鍒犻櫎);
+                            if (!alldelete)
+                            {
+                                await Db.Deleteable(task).ExecuteCommandAsync();
+                            }
+                        }
+                    }
+                }
+                try
+                {
+                    _locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfo, beforelocationStatus, StockChangeType.Inbound.ObjToInt(), "", task.TaskNum);
+                }
+                catch (Exception ex)
+                {
+                    _logger.LogInformation($"InEmptyTaskCompleted AddLocationStatusChangeRecord : {ex.Message} ");
+                }
+                return content;
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                return await Task.FromResult(WebResponseContent.Instance.Error(ex.Message));
+            }
+        }
     }
 }
 

--
Gitblit v1.9.3