From b6a40a2d8fdcffb3accfc7e424c0726a87a59ddf Mon Sep 17 00:00:00 2001
From: heshaofeng <heshaofeng@hnkhzn.com>
Date: 星期五, 05 十二月 2025 21:20:59 +0800
Subject: [PATCH] 提交

---
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundBatchPickingService.cs |   56 ++++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 46 insertions(+), 10 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/OutboundBatchPickingService.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/OutboundBatchPickingService.cs"
index 6507bd0..c0e37a5 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/OutboundBatchPickingService.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/OutboundBatchPickingService.cs"
@@ -21,6 +21,7 @@
 using WIDESEA_IBasicService;
 using WIDESEA_IOutboundService;
 using WIDESEA_IStockService;
+using WIDESEA_ITaskInfoService;
 using WIDESEA_Model.Models;
 using WIDESEA_Model.Models.Basic;
 using WIDESEA_Model.Models.Outbound;
@@ -49,6 +50,7 @@
         private readonly IDailySequenceService _dailySequenceService;
         private readonly IAllocateService _allocateService;
         private readonly IRepository<Dt_OutboundBatch> _outboundBatchRepository;
+        private readonly ITask_HtyService _task_HtyService;
         private readonly ILogger<OutboundPickingService> _logger;
 
         private Dictionary<string, string> stations = new Dictionary<string, string>
@@ -68,7 +70,7 @@
         public OutboundBatchPickingService(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_OutboundBatch> outboundBatchRepository) : base(BaseDal)
+            IRepository<Dt_Task> taskRepository, IESSApiService eSSApiService, ILogger<OutboundPickingService> logger, IInvokeMESService invokeMESService, IDailySequenceService dailySequenceService, IAllocateService allocateService, IRepository<Dt_OutboundBatch> outboundBatchRepository, ITask_HtyService task_HtyService) : base(BaseDal)
         {
             _unitOfWorkManage = unitOfWorkManage;
             _stockInfoService = stockInfoService;
@@ -86,6 +88,7 @@
             _dailySequenceService = dailySequenceService;
             _allocateService = allocateService;
             _outboundBatchRepository = outboundBatchRepository;
+            _task_HtyService = task_HtyService;
         }
 
         // <summary>
@@ -1798,7 +1801,7 @@
 
                 // 鏇存柊閿佸畾璁板綍鐘舵�佷负宸插洖搴�
                 lockInfo.Status = (int)OutLockStockStatusEnum.宸插洖搴�;
-                lockInfo.Operator = App.User.UserName; 
+                lockInfo.Operator = App.User.UserName;
 
                 await _outStockLockInfoService.Db.Updateable(lockInfo).ExecuteCommandAsync();
 
@@ -1854,7 +1857,7 @@
 
                     // 鏇存柊閿佸畾璁板綍鐘舵�佷负宸插洖搴�
                     lockInfo.Status = (int)OutLockStockStatusEnum.宸插洖搴�;
-                    lockInfo.Operator = App.User.UserName; 
+                    lockInfo.Operator = App.User.UserName;
 
                     await _outStockLockInfoService.Db.Updateable(lockInfo).ExecuteCommandAsync();
 
@@ -1945,11 +1948,33 @@
                     PalletType = stockInfo.PalletType,
                     WarehouseId = currentTask.WarehouseId
                 };
+                var targetAddress = currentTask.TargetAddress;
 
-                await _taskRepository.Db.Insertable(returnTask).ExecuteCommandAsync();
+                try
+                {
+                    await _taskRepository.Db.Insertable(returnTask).ExecuteCommandAsync();
+                 
+                    _logger.LogInformation($"CreateReturnTaskAndHandleESS  鍒嗘壒鍒犻櫎鍘嗗彶浠诲姟: {orderNo} 锛� {currentTask.TaskNum}");
+                    // 鍒犻櫎鍘熷鍑哄簱浠诲姟
+                    //_taskRepository.DeleteAndMoveIntoHty(originalTask, OperateTypeEnum.鑷姩瀹屾垚);
+                    var result = _task_HtyService.DeleteAndMoveIntoHty(currentTask, OperateTypeEnum.浜哄伐鍒犻櫎);
+                    await _taskRepository.Db.Deleteable(currentTask).ExecuteCommandAsync();
 
+                    if (!result)
+                    {
+                        await _taskRepository.Db.Deleteable(currentTask).ExecuteCommandAsync();
+                    }
+                    _logger.LogInformation($"CreateReturnTaskAndHandleESS  鍒嗘壒鍒犻櫎鍘嗗彶浠诲姟: {orderNo} 锛� {currentTask.TaskNum},褰卞搷琛�  {result}");
+
+                }
+                catch (Exception ex)
+                {
+                    _logger.LogInformation($"鍒涘缓鍥炲簱浠诲姟澶辫触 - 璁㈠崟: {orderNo}, 鎵樼洏: {palletCode}");
+                    throw new Exception($"鍒涘缓鍥炲簱浠诲姟澶辫触 - 璁㈠崟: {orderNo}, 鎵樼洏: {palletCode}");
+                  
+                }
                 // 鍙戦�丒SS鍛戒护
-                await SendESSCommands(palletCode, currentTask.TargetAddress, returnTask);
+                await SendESSCommands(palletCode, targetAddress, returnTask);
 
                 _logger.LogInformation($"鍒涘缓鍥炲簱浠诲姟鎴愬姛 - 璁㈠崟: {orderNo}, 鎵樼洏: {palletCode}");
             }
@@ -2037,7 +2062,7 @@
 
             if (unfinishedLocks.Any())
             {
-                // 閲嶈锛氬尯鍒嗗凡鍒嗛厤鍜屾湭鍒嗛厤鐨勯攣瀹氳褰�
+                //  鍖哄垎宸插垎閰嶅拰鏈垎閰嶇殑閿佸畾璁板綍
                 var allocatedLocks = unfinishedLocks.Where(x => x.IsUnallocated != 1 && x.OrderDetailId > 0).ToList();
                 var unallocatedLocks = unfinishedLocks.Where(x => x.IsUnallocated == 1 || x.OrderDetailId == 0).ToList();
 
@@ -2223,7 +2248,7 @@
                     // 鍒嗛厤鏁伴噺鍦ㄨ鍗曟槑缁嗗眰闈㈢粺涓�澶勭悊
                     var originalStatus = lockInfo.Status;
                     lockInfo.Status = (int)OutLockStockStatusEnum.宸插洖搴�;
-                    lockInfo.Operator = App.User.UserName; 
+                    lockInfo.Operator = App.User.UserName;
 
                     await _outStockLockInfoService.Db.Updateable(lockInfo).ExecuteCommandAsync();
 
@@ -2550,7 +2575,7 @@
         /// <summary>
         /// 澶勭悊鏈垎鎷g殑閿佸畾璁板綍鍥炲簱
         /// </summary>
-  
+
 
         /// <summary>
         /// 澶勭悊鎵樼洏涓婄殑搴撳瓨璐х墿鍥炲簱
@@ -3478,13 +3503,24 @@
 
             };
             // 淇濆瓨鍥炲簱浠诲姟
-            await _taskRepository.Db.Insertable(returnTask).ExecuteCommandAsync();
+            var insertcount = await _taskRepository.Db.Insertable(returnTask).ExecuteCommandAsync();
+            if (insertcount <= 0)
+            {
+                throw new Exception("鍒涘缓浠诲姟澶辫触锛�");
+            }
             var targetAddress = originalTask.TargetAddress;
 
+            _logger.LogInformation($"CreateReturnTaskAndHandleESS  鍒嗘壒鍒犻櫎鍘嗗彶浠诲姟: {orderNo} 锛� {originalTask.TaskNum}");
             // 鍒犻櫎鍘熷鍑哄簱浠诲姟
-            _taskRepository.DeleteAndMoveIntoHty(originalTask, OperateTypeEnum.鑷姩瀹屾垚);
+            //_taskRepository.DeleteAndMoveIntoHty(originalTask, OperateTypeEnum.鑷姩瀹屾垚);
+           var result= _task_HtyService.DeleteAndMoveIntoHty(originalTask, OperateTypeEnum.浜哄伐鍒犻櫎);
             await _taskRepository.Db.Deleteable(originalTask).ExecuteCommandAsync();
 
+            if (!result)
+            {
+                await _taskRepository.Db.Deleteable(originalTask).ExecuteCommandAsync();
+            }
+            _logger.LogInformation($"CreateReturnTaskAndHandleESS  鍒嗘壒鍒犻櫎鍘嗗彶浠诲姟: {orderNo} 锛� {originalTask.TaskNum},褰卞搷琛�  {result}");
 
 
             // 缁� ESS 鍙戦�佹祦鍔ㄤ俊鍙峰拰鍒涘缓浠诲姟

--
Gitblit v1.9.3