From f534cb16b9958b80bef6bf20ac9b5a07a201e76d Mon Sep 17 00:00:00 2001
From: pan <antony1029@163.com>
Date: 星期五, 12 十二月 2025 19:50:10 +0800
Subject: [PATCH] 提交

---
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs |  132 +++++++++++++++++++++++++++++++++++++------
 1 files changed, 113 insertions(+), 19 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 80aec45..eb77ed2 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"
@@ -297,9 +297,16 @@
             {
                 await Db.Deleteable(task).ExecuteCommandAsync();
             }
-            _locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Inbound.ObjToInt(), "", task.TaskNum);
+            try
+            {
+                _locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Inbound.ObjToInt(), "", task.TaskNum);
 
-            _recordService.StockQuantityChangeRecordService.AddStockChangeRecord(stockInfo, stockInfo.Details, beforeQuantity, stockInfo.Details.Sum(x => x.StockQuantity) + beforeQuantity, WIDESEA_Common.StockEnum.StockChangeType.MaterielGroup);
+                _recordService.StockQuantityChangeRecordService.AddStockChangeRecord(stockInfo, stockInfo.Details, beforeQuantity, stockInfo.Details.Sum(x => x.StockQuantity) + beforeQuantity, WIDESEA_Common.StockEnum.StockChangeType.MaterielGroup);
+            }
+            catch (Exception ex)
+            {
+                _logger.LogInformation($"InboundTaskCompleted AddLocationStatusChangeRecord : {ex.Message} ");
+            }
             try
             {
                 foreach (var inboundOrder in inboundOrders)
@@ -568,8 +575,14 @@
                 {
                     await Db.Deleteable(task).ExecuteCommandAsync();
                 }
-                _locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfo, beforelocationStatus, StockChangeType.Inbound.ObjToInt(), "", task.TaskNum);
-
+                try
+                {
+                    _locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfo, beforelocationStatus, StockChangeType.Inbound.ObjToInt(), "", task.TaskNum);
+                }
+                catch (Exception ex)
+                {
+                    _logger.LogInformation($"InEmptyTaskCompleted AddLocationStatusChangeRecord : {ex.Message} ");
+                }
 
                 if (outboundOrder != null)
                 {
@@ -683,18 +696,25 @@
                 {
                     await Db.Deleteable(task).ExecuteCommandAsync();
                 }
-                // 璁板綍璐т綅鐘舵�佸彉鏇�
-                _locationStatusChangeRecordService.AddLocationStatusChangeRecord(
-                    locationInfo,
-                    beforelocationStatus,
-                    StockChangeType.Inbound.ObjToInt(),
-                    "",
-                    task.TaskNum
-                );
+
                 await RecalculateOrderStatus(task.OrderNo);
+                try
+                {
+                    // 璁板綍璐т綅鐘舵�佸彉鏇�
+                    _locationStatusChangeRecordService.AddLocationStatusChangeRecord(
+                        locationInfo,
+                        beforelocationStatus,
+                        StockChangeType.Inbound.ObjToInt(),
+                        "",
+                        task.TaskNum
+                    );
+                }
+                catch (Exception ex)
+                {
+                    _logger.LogInformation($"InPickTaskCompleted AddLocationStatusChangeRecord : {ex.Message} ");
+                }
 
-
-                _logger.LogInformation($"鎵樼洏鍥炲簱瀹屾垚澶勭悊鎴愬姛 - 浠诲姟鍙�: {task.TaskNum}, 鎵樼洏: {task.PalletCode}, 璁㈠崟: {task.OrderNo}");
+                _logger.LogInformation($"鎵樼洏鍥炲簱瀹屾垚澶勭悊鎴愬姛 - 浠诲姟鍙�: {task.TaskNum}, 鎵樼洏: {task.PalletCode}, 璁㈠崟: {task.OrderNo} 璐т綅鐘舵�侊細{locationInfo.LocationStatus}");
                 _ = Task.Run(async () =>
                 {
                     try
@@ -737,8 +757,8 @@
         {
             try
             {
-              
-           
+
+
                 // 鑾峰彇鍙楀奖鍝嶇殑璁㈠崟鏄庣粏ID锛堝幓閲嶏級
                 //var affectedDetailIds = returnLocks
                 //    .Select(x => x.OrderDetailId)
@@ -979,7 +999,7 @@
 
                     _logger.LogInformation($"鏇存柊璁㈠崟鐘舵�� - OrderNo: {orderNo}, 鏃х姸鎬�: {outboundOrder.OrderStatus}, 鏂扮姸鎬�: {newStatus}");
                 }
-               
+
             }
             catch (Exception ex)
             {
@@ -1116,6 +1136,34 @@
 
                                 allocatefeedmodel.Details.Add(detailModel);
                             }
+                            var groupedResult = allocatefeedmodel.Details
+                                .GroupBy(item => new { item.WarehouseCode, item.MaterialCode, item.Unit, item.LineNo })
+                                .Select(group =>
+                                {
+
+                                    var deduplicatedBarcodes = group.SelectMany(x => x.Barcodes)
+                                                                   .GroupBy(b => b.Barcode)
+                                                                   .Select(b => new BarcodeInfo
+                                                                   {
+                                                                       Barcode = b.Key,
+                                                                       BatchNo = b.First().BatchNo,
+                                                                       SupplyCode = b.First().SupplyCode,
+                                                                       Qty = b.Max(x => x.Qty),
+                                                                       Unit = b.First().Unit
+                                                                   }).ToList();
+                                    return new AllocateDtoDetail
+                                    {
+                                        WarehouseCode = group.Key.WarehouseCode,
+                                        MaterialCode = group.Key.MaterialCode,
+                                        LineNo = group.Key.LineNo,
+                                        Qty = deduplicatedBarcodes.Sum(b => b.Qty),
+                                        Unit = group.Key.Unit,
+                                        Barcodes = deduplicatedBarcodes
+                                    };
+                                }).ToList();
+
+                            allocatefeedmodel.Details = groupedResult;
+
 
                             var result = await _invokeMESService.FeedbackAllocate(allocatefeedmodel);
                             if (result != null && result.code == 200)
@@ -1130,6 +1178,19 @@
                                           ReturnToMESStatus = 1,
                                       }).Where(x => x.OrderNo == orderNo).ExecuteCommandAsync();
                             }
+                            else
+                            {
+                                await _outboundOrderDetailService.Db.Updateable<Dt_OutboundOrderDetail>()
+                                 .SetColumns(x => x.ReturnToMESStatus == 2)
+                                 .Where(x => x.OrderId == outboundOrder.Id)
+                                 .ExecuteCommandAsync();
+
+                                await _outboundOrderService.Db.Updateable<Dt_OutboundOrder>()
+                                    .SetColumns(it => new Dt_OutboundOrder { ReturnToMESStatus = 2, Remark = result.message })
+                                     .Where(x => x.OrderNo == orderNo)
+                                    .ExecuteCommandAsync();
+                            }
+
                         }
                     }
                     else if (outboundOrder.OrderType == OutOrderTypeEnum.ReCheck.ObjToInt())
@@ -1202,6 +1263,33 @@
                                 }
                                 feedmodel.details.Add(detailModel);
                             }
+
+                            var groupedResult = feedmodel.details
+                               .GroupBy(item => new { item.warehouseCode, item.materialCode, item.unit, item.lineNo })
+                               .Select(group =>
+                               {
+                                   var deduplicatedBarcodes = group.SelectMany(x => x.barcodes)
+                                                                  .GroupBy(b => b.barcode)
+                                                                  .Select(b => new WIDESEA_DTO.Outbound.BarcodesModel
+                                                                  {
+                                                                      barcode = b.Key,
+                                                                      batchNo = b.First().batchNo,
+                                                                      supplyCode = b.First().supplyCode,
+                                                                      qty = b.Max(x => x.qty),
+                                                                      unit = b.First().unit
+                                                                  }).ToList();
+                                   return new FeedbackOutboundDetailsModel
+                                   {
+                                       warehouseCode = group.Key.warehouseCode,
+                                       materialCode = group.Key.materialCode,
+                                       lineNo = group.Key.lineNo,
+                                       qty = deduplicatedBarcodes.Sum(b => b.qty),
+                                       unit = group.Key.unit,
+                                       barcodes = deduplicatedBarcodes
+                                   };
+                               }).ToList();
+
+                            feedmodel.details = groupedResult;
 
                             var result = await _invokeMESService.FeedbackOutbound(feedmodel);
                             if (result != null && result.code == 200)
@@ -1284,8 +1372,14 @@
                     _stockRepository.Db.Deleteable(stockInfo).ExecuteCommand();
                 }
                 _stockService.StockInfoService.DeleteData(stockInfo);
-                _locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Outbound.ObjToInt(), stockInfo.Details.FirstOrDefault()?.OrderNo ?? "", task.TaskNum);
-
+                try
+                {
+                    _locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Outbound.ObjToInt(), stockInfo?.Details.FirstOrDefault()?.OrderNo ?? "", task.TaskNum);
+                }
+                catch (Exception ex)
+                {
+                    _logger.LogError($"TaskService OutEmptyTaskCompleted AddLocationStatusChangeRecord:  {ex.Message} ");
+                }
                 return await Task.FromResult(WebResponseContent.Instance.OK());
 
             }

--
Gitblit v1.9.3