From e9feb28be7d4417b24bd53a77332846e2cbab734 Mon Sep 17 00:00:00 2001
From: pan <antony1029@163.com>
Date: 星期二, 18 十一月 2025 11:32:30 +0800
Subject: [PATCH] 提交

---
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_OutboundService/SplitPackageService.cs    |  181 +++++++++++++++++++---
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_Outbound.cs   |    2 
 项目代码/WIDESEA_WMSClient/src/views/outbound/PickingConfirm.vue                     |    6 
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundPickingService.cs |  190 ++++-------------------
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_Common/AllocateEnum/BusinessTypeEnum.cs   |    2 
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs            |   68 +++++++-
 6 files changed, 258 insertions(+), 191 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/views/outbound/PickingConfirm.vue" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/views/outbound/PickingConfirm.vue"
index 3b78f02..6170a18 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/views/outbound/PickingConfirm.vue"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/views/outbound/PickingConfirm.vue"
@@ -1068,12 +1068,15 @@
         if (res.status) {
           this.$message.success('鎷嗗寘鎴愬姛');
           this.showSplitDialog = false;
+              this.splitLoading = false;
           this.resetSplitForm();
           this.loadData();
         } else {
+               this.splitLoading = false;
           this.$message.error(res.message || '鎷嗗寘澶辫触');
         }
       } catch (error) {
+             this.splitLoading = false;
         this.$message.error('鎷嗗寘澶辫触');
       }
     },
@@ -1121,12 +1124,15 @@
         if (res.status) {
           this.$message.success('鎾ら攢鎷嗗寘鎴愬姛');
           this.showRevertSplitDialog = false;
+           this.revertSplitLoading = false;
           this.revertSplitForm.originalBarcode = '';
           this.loadData();
         } else {
+         this.revertSplitLoading = false;
           this.$message.error(res.message || '鎾ら攢鎷嗗寘澶辫触');
         }
       } catch (error) {
+         this.revertSplitLoading = false;
         this.$message.error('鎾ら攢鎷嗗寘澶辫触');
       }
     },
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_Common/AllocateEnum/BusinessTypeEnum.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_Common/AllocateEnum/BusinessTypeEnum.cs"
index cad2935..d7f61a5 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_Common/AllocateEnum/BusinessTypeEnum.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_Common/AllocateEnum/BusinessTypeEnum.cs"
@@ -12,4 +12,6 @@
         鏅轰粨璋冨閮ㄤ粨搴�=2,
         澶栭儴浠撳簱璋冩櫤浠�=3
     }
+
+ 
 }
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 8c52841..93f7d84 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"
@@ -177,6 +177,12 @@
                 if (lockInfo.PalletCode != palletCode)
                     throw new Exception($"鏉$爜{barcode}涓嶅睘浜庢墭鐩榹palletCode}");
 
+                var outorderdetail = _outboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>().First(x => x.Id == lockInfo.OrderDetailId);
+                if (outorderdetail != null && lockInfo.AssignQuantity > outorderdetail.OrderQuantity)
+                {
+                    throw new Exception($"鏉$爜{barcode}鐨勫嚭搴撴暟閲忓ぇ浜庤鍗曠殑鏁伴噺");
+                }
+
                 var stockDetail = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
                         .Where(x => x.Barcode == barcode && x.StockId == lockInfo.StockId)
                         .FirstAsync();
@@ -248,10 +254,15 @@
         private async Task CheckAndUpdateOrderStatus(string orderNo)
         {
 
+            var orderDetails = _stockInfoDetailService.Db.Queryable<Dt_OutboundOrderDetail>()
+                      .LeftJoin<Dt_OutboundOrder>((o, item) => o.OrderId == item.Id) // 鍏宠仈鏉′欢锛氱埗琛� Id = 瀛愯〃 OrderId
+                      .Where((o, item) => item.OrderNo == orderNo) // 杩囨护鐖惰〃 OrderNo
+                      .Select((o, item) => o) // 鍙繑鍥炲瓙琛ㄦ暟鎹�
+                      .ToList();
 
-            var orderDetails = await _stockInfoDetailService.Db.Queryable<Dt_OutboundOrderDetail>()
-                .Where(x => x.OrderId == orderNo.ObjToInt())
-                .ToListAsync();
+            //var orderDetails = await _stockInfoDetailService.Db.Queryable<Dt_OutboundOrderDetail>()
+            //    .Where(x => x.OrderId == orderNo.ObjToInt())
+            //    .ToListAsync();
 
             bool allCompleted = true;
             foreach (var detail in orderDetails)
@@ -269,6 +280,8 @@
                     .SetColumns(x => x.OrderStatus == 2) // 宸插畬鎴�
                     .Where(x => x.OrderNo == orderNo)
                     .ExecuteCommandAsync();
+
+                //鍥炰紶MES
             }
         }
 
@@ -276,165 +289,18 @@
         /// <summary>
         /// 鍥炲簱鎿嶄綔  
         /// </summary>
-        //public async Task<WebResponseContent> ReturnRemaining(string orderNo, string palletCode, string reason)
-        //{
-        //    try
-        //    {
-        //        // 1. 鑾峰彇鎵�鏈夋湭鍒嗘嫞鐨勫嚭搴撻攣瀹氳褰曪紝鍖呮嫭鎷嗗寘浜х敓鐨勮褰�
-        //        var remainingLocks = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
-        //            .Where(it => it.OrderNo == orderNo && it.Status == 1)
-        //            .ToListAsync();
-
-        //        if (!remainingLocks.Any())
-        //        {
-        //            return WebResponseContent.Instance.Error("娌℃湁闇�瑕佸洖搴撶殑鍓╀綑璐х墿");
-        //        }
-        //        var tasks = new List<Dt_Task>();
-        //        // 鎸夋墭鐩樺垎缁�
-        //        var palletGroups = remainingLocks.GroupBy(x => x.PalletCode);
-        //        //鏌ヨ浠诲姟琛� 
-        //        var task = _taskRepository.QueryData(x => x.TaskNum == remainingLocks.First().TaskNum).FirstOrDefault();
-        //        foreach (var group in palletGroups)
-        //        {
-        //            if (group.Key == palletCode)
-        //            {
-        //                var totalReturnQty = group.Sum(x => x.AssignQuantity - x.PickedQty);
-
-        //                if (totalReturnQty <= 0) continue;
-
-        //                // 鍒嗛厤鏂拌揣浣�
-        //                var newLocation = _locationInfoService.AssignLocation();
-
-        //                // 鏇存柊鍑哄簱閿佸畾璁板綍鐘舵��
-        //                var lockIds = group.Where(x => x.PalletCode == palletCode).Select(x => x.Id).ToList();
-        //                await _outStockLockInfoService.Db.Updateable<Dt_OutStockLockInfo>()
-        //                    .SetColumns(it => new Dt_OutStockLockInfo { Status = OutLockStockStatusEnum.鍥炲簱涓�.ObjToInt() })
-        //                    .Where(it => lockIds.Contains(it.Id))
-        //                    .ExecuteCommandAsync();
-
-        //                // 鏇存柊鎷嗗寘鏉$爜璁板綍鐘舵��
-        //                var splitBarcodes = await _splitPackageService.Db.Queryable<Dt_SplitPackageRecord>()
-        //                    .Where(it => lockIds.Contains(it.OutStockLockInfoId))
-        //                    .ToListAsync();
-
-        //                foreach (var splitBarcode in splitBarcodes)
-        //                {
-        //                    splitBarcode.Status = 3;
-        //                    await _splitPackageService.Db.Updateable(splitBarcode).ExecuteCommandAsync();
-        //                }
-
-        //                foreach (var lockInfo in group)
-        //                {
-        //                    if (lockInfo.PalletCode == palletCode)
-        //                    {
-        //                        decimal returnQty = lockInfo.AssignQuantity - lockInfo.PickedQty;
-
-        //                        // 妫�鏌ュ簱瀛樿褰曟槸鍚﹀瓨鍦�
-        //                        var existingStock = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
-        //                            .Where(it => it.Barcode == lockInfo.CurrentBarcode && it.StockId == lockInfo.StockId)
-        //                            .FirstAsync();
-
-        //                        if (existingStock != null)
-        //                        {
-        //                            // 搴撳瓨璁板綍瀛樺湪锛屾仮澶嶉攣瀹氭暟閲�
-        //                            await _stockInfoDetailService.Db.Updateable<Dt_StockInfoDetail>()
-        //                                .SetColumns(it => new Dt_StockInfoDetail
-        //                                {
-        //                                    OutboundQuantity = it.OutboundQuantity - returnQty
-        //                                })
-        //                                .Where(it => it.Barcode == lockInfo.CurrentBarcode && it.StockId == lockInfo.StockId)
-        //                                .ExecuteCommandAsync();
-        //                        }
-        //                        else
-        //                        {
-        //                            // 搴撳瓨璁板綍涓嶅瓨鍦紙鍙兘鏄媶鍖呬骇鐢熺殑鏂版潯鐮侊級锛屽垱寤烘柊鐨勫簱瀛樿褰�
-        //                            var newStockDetail = new Dt_StockInfoDetail
-        //                            {
-        //                                StockId = lockInfo.StockId,
-        //                                MaterielCode = lockInfo.MaterielCode,
-        //                                OrderNo = lockInfo.OrderNo,
-        //                                BatchNo = lockInfo.BatchNo,
-        //                                StockQuantity = returnQty, // 瀹為檯搴撳瓨鏁伴噺
-        //                                OutboundQuantity = 0, // 鍥炲簱鍚庝笉鍐嶉攣瀹�
-        //                                Barcode = lockInfo.CurrentBarcode,
-        //                                InboundOrderRowNo = "0",
-        //                                Status = StockStatusEmun.鍏ュ簱纭.ObjToInt(),
-
-        //                            };
-        //                            await _stockInfoDetailService.Db.Insertable(newStockDetail).ExecuteCommandAsync();
-        //                        }
-        //                    }
-        //                }
-
-
-        //                Dt_Task newtask = new()
-        //                {
-        //                    CurrentAddress = stations[task.TargetAddress],
-        //                    Grade = 0,
-        //                    PalletCode = palletCode,
-        //                    NextAddress = "",
-        //                    OrderNo= task.OrderNo,
-        //                    Roadway = newLocation.RoadwayNo,
-        //                    SourceAddress = stations[task.TargetAddress],
-        //                    TargetAddress = newLocation.LocationCode,
-        //                    TaskStatus = TaskStatusEnum.New.ObjToInt(),
-        //                    TaskType = TaskTypeEnum.InPick.ObjToInt(),
-        //                    // TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
-        //                    PalletType = task.PalletType,
-        //                    WarehouseId = task.WarehouseId,
-        //                };
-        //                tasks.Add(newtask);
-
-        //            }
-        //        }
-        //        try
-        //        {
-        //            await _taskRepository.Db.Insertable(tasks).ExecuteCommandAsync();
-        //            //鍒犻櫎 鍑哄簱鐨�  task
-
-
-        //            //缁� ess  娴佸姩淇″彿  鍜屽垱寤轰换鍔�
-
-
-        //        }
-        //        catch (Exception ex)
-        //        {
-
-        //        }
-
-
-
-
-        //        return WebResponseContent.Instance.OK();
-        //    }
-        //    catch (Exception ex)
-        //    {
-        //        return WebResponseContent.Instance.Error($"鍥炲簱鎿嶄綔澶辫触: {ex.Message}");
-        //    }
-        //}
-
+       
         public async Task<WebResponseContent> ReturnRemaining(string orderNo, string palletCode, string reason)
         {
             try
             {
-                // 1. 鑾峰彇鎵�鏈夋湭鍒嗘嫞鐨勫嚭搴撻攣瀹氳褰曪紝鍖呮嫭鎷嗗寘浜х敓鐨勮褰�
+                //  鑾峰彇鎵�鏈夋湭鍒嗘嫞鐨勫嚭搴撻攣瀹氳褰曪紝鍖呮嫭鎷嗗寘浜х敓鐨勮褰�
                 var remainingLocks = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
                     .Where(it => it.OrderNo == orderNo && it.Status == 1)
                     .ToListAsync();
 
                 var stockinfo = _stockInfoService.Db.Queryable<Dt_StockInfo>().First(x => x.PalletCode == palletCode);
 
-                // 2. 妫�鏌ユ墭鐩樹笂鏄惁鏈夊叾浠栭潪鍑哄簱璐х墿锛堝簱瀛樿揣鐗╋級
-                var palletStockGoods = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
-                    .Where(it => it.StockId == stockinfo.Id && it.Status == StockStatusEmun.鍏ュ簱纭.ObjToInt())
-                    .Where(it => it.OutboundQuantity == 0 || it.OutboundQuantity < it.StockQuantity) // 鏈畬鍏ㄥ嚭搴撶殑
-                    .ToListAsync();
-
-                // 3. 濡傛灉娌℃湁闇�瑕佸洖搴撶殑璐х墿锛堟棦鏃犳湭鍒嗘嫞鍑哄簱璐х墿锛屼篃鏃犲叾浠栧簱瀛樿揣鐗╋級
-                if (!remainingLocks.Any() && !palletStockGoods.Any())
-                {
-                    return WebResponseContent.Instance.Error("娌℃湁闇�瑕佸洖搴撶殑鍓╀綑璐х墿");
-                }
 
                 var tasks = new List<Dt_Task>();
 
@@ -447,6 +313,21 @@
                 {
                     return WebResponseContent.Instance.Error("鏈壘鍒板搴旂殑浠诲姟淇℃伅");
                 }
+
+                //  妫�鏌ユ墭鐩樹笂鏄惁鏈夊叾浠栭潪鍑哄簱璐х墿锛堝簱瀛樿揣鐗╋級
+                var palletStockGoods = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+                    .Where(it => it.StockId == stockinfo.Id &&( it.Status == StockStatusEmun.鍏ュ簱纭.ObjToInt()  || it.Status == StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt()))
+                    .Where(it => it.OutboundQuantity == 0 || it.OutboundQuantity < it.StockQuantity) // 鏈畬鍏ㄥ嚭搴撶殑
+                    .ToListAsync();
+
+                //  濡傛灉娌℃湁闇�瑕佸洖搴撶殑璐х墿锛堟棦鏃犳湭鍒嗘嫞鍑哄簱璐х墿锛屼篃鏃犲叾浠栧簱瀛樿揣鐗╋級
+                if (!remainingLocks.Any() && !palletStockGoods.Any())
+                {
+                    //鏄惁鑷姩鍥炲簱锛屾妸涔嬪墠鍑哄簱鐨勪换鍔″垹闄わ紝鐒跺悗缁勪釜绌虹洏鍏ュ簱銆�
+                    return WebResponseContent.Instance.Error("娌℃湁闇�瑕佸洖搴撶殑鍓╀綑璐х墿");
+                }
+
+           
                 var firstlocation = _locationInfoService.Db.Queryable<Dt_LocationInfo>().First(x => x.LocationCode == task.SourceAddress);
                 decimal totalReturnQty = 0;
                 var hasRemainingLocks = remainingLocks.Any(x => x.PalletCode == palletCode);
@@ -687,11 +568,11 @@
                 var stockDetail = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
                        .Where(x => x.Barcode == barcode && x.StockId == outStockInfo.StockId)
                        .FirstAsync();
-           
+
                 stockDetail.StockQuantity += outStockInfo.AssignQuantity;
                 stockDetail.OutboundQuantity += outStockInfo.AssignQuantity;
                 await _stockInfoDetailService.Db.Updateable(stockDetail).ExecuteCommandAsync();
-         
+
 
                 // 杩樺師鍑哄簱鍗曟槑缁�
                 var orderDetail = await _outboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>()
@@ -699,6 +580,7 @@
                     .FirstAsync();
 
                 orderDetail.OverOutQuantity -= outStockInfo.AssignQuantity;
+                orderDetail.PickedQty = 0;
                 await _outboundOrderDetailService.Db.Updateable(orderDetail).ExecuteCommandAsync();
 
                 // 鍒犻櫎鎷i�夊巻鍙�
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/SplitPackageService.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/SplitPackageService.cs"
index 54ae514..18b32f1 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/SplitPackageService.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/SplitPackageService.cs"
@@ -84,7 +84,7 @@
                     SupplyCode = stockDetail.SupplyCode,
                     WarehouseCode = stockDetail.WarehouseCode,
                     BarcodeQty = stockDetail.BarcodeQty,
-                    BarcodeUnit = stockDetail.Barcode,
+                    BarcodeUnit = stockDetail.BarcodeUnit,
                     BusinessType = stockDetail.BusinessType,
                     Unit = stockDetail.Unit,
                     StockId = lockInfo.StockId,
@@ -170,48 +170,180 @@
             }
         }
 
-        // 鎾ら攢鎷嗗寘
+ 
+        //public async Task<WebResponseContent> RevertSplitPackage(string originalBarcode)
+        //{
+        //    try
+        //    {
+        //        _unitOfWorkManage.BeginTran();
+
+        //        // 1. 鏌ユ壘鏈�杩戠殑鏈挙閿�鎷嗗寘璁板綍
+        //        var splitRecord = await Db.Queryable<Dt_SplitPackageRecord>()
+        //                .Where(x => x.OriginalBarcode == originalBarcode && !x.IsReverted)
+        //                .OrderByDescending(x => x.SplitTime)
+        //                .FirstAsync();
+
+        //        if (splitRecord == null)
+        //            return WebResponseContent.Instance.Error("鏈壘鍒板彲鎾ら攢鐨勬媶鍖呰褰�");
+
+        //        // 2. 妫�鏌ユ柊鏉$爜鏄惁宸叉嫞閫�
+        //        var newLockInfo = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+        //            .Where(x => x.CurrentBarcode == splitRecord.NewBarcode)
+        //            .FirstAsync();
+
+        //        if (newLockInfo?.Status ==6) // 鍋囪鐘舵��2琛ㄧず宸叉嫞閫�
+        //            return WebResponseContent.Instance.Error("鏂版潯鐮佸凡鎷i�夛紝鏃犳硶鎾ら攢鎷嗗寘");
+
+        //        // 3. 鑾峰彇鍘熸潯鐮佺殑閿佸畾淇℃伅
+        //        var originalLockInfo = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+        //            .Where(x => x.CurrentBarcode == originalBarcode)
+        //            .FirstAsync();
+
+        //        if (originalLockInfo == null)
+        //            return WebResponseContent.Instance.Error("鏈壘鍒板師鏉$爜閿佸畾淇℃伅");
+
+          
+        //        originalLockInfo.AssignQuantity  += splitRecord.RemainQuantity;  
+        //       // originalLockInfo.Status = (int)OutLockStockStatusEnum.鍑哄簱涓�;
+        //        originalLockInfo.IsSplitted = 0; // 鏍囪涓烘湭鎷嗗寘
+        //        await _outStockLockInfoService.Db.Updateable(originalLockInfo).ExecuteCommandAsync();
+
+        //        // 5. 杩樺師鍘熸潯鐮佸簱瀛樿褰�
+        //        var originalStockDetail = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+        //            .Where(x => x.Barcode == originalBarcode && x.StockId == splitRecord.StockId)
+        //            .FirstAsync();
+
+        //        if (originalStockDetail != null)
+        //        {
+        //            // 灏嗘媶鍑虹殑鏁伴噺鍔犲洖鍒板師鏉$爜搴撳瓨
+        //            originalStockDetail.StockQuantity += splitRecord.RemainQuantity;
+        //            originalStockDetail.OutboundQuantity += splitRecord.RemainQuantity;
+        //            await _stockInfoDetailService.Db.Updateable(originalStockDetail).ExecuteCommandAsync();
+        //        }
+
+        //        // 6. 鍒犻櫎鏂版潯鐮佺殑閿佸畾淇℃伅
+        //        if (newLockInfo != null)
+        //        {
+        //            await _outStockLockInfoService.Db.Deleteable<Dt_OutStockLockInfo>()
+        //                .Where(x => x.CurrentBarcode == splitRecord.NewBarcode)
+        //                .ExecuteCommandAsync();
+        //        }
+
+        //        // 7. 鍒犻櫎鏂版潯鐮佺殑搴撳瓨璁板綍
+        //        var newStockDetail = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+        //            .Where(x => x.Barcode == splitRecord.NewBarcode)
+        //            .FirstAsync();
+
+        //        if (newStockDetail != null)
+        //        {
+        //            await _stockInfoDetailService.Db.Deleteable<Dt_StockInfoDetail>()
+        //                .Where(x => x.Barcode == splitRecord.NewBarcode)
+        //                .ExecuteCommandAsync();
+        //        }
+
+        //        // 8. 鏇存柊鎷嗗寘璁板綍涓哄凡鎾ら攢
+        //        splitRecord.IsReverted = true;              
+        
+        //        await Db.Updateable(splitRecord).ExecuteCommandAsync();
+
+        //        _unitOfWorkManage.CommitTran();
+
+        //        return WebResponseContent.Instance.OK($"鎾ら攢鎷嗗寘鎴愬姛锛岃繕鍘熸暟閲忥細{splitRecord.SplitQty}");
+
+        //    }
+        //    catch (Exception ex)
+        //    {
+        //        _unitOfWorkManage.RollbackTran();
+        //        return WebResponseContent.Instance.Error($"鎾ら攢鎷嗗寘澶辫触锛歿ex.Message}");
+        //    }
+        //}
+ 
         public async Task<WebResponseContent> RevertSplitPackage(string originalBarcode)
         {
             try
             {
                 _unitOfWorkManage.BeginTran();
-                // 鏌ユ壘鏈�杩戠殑鏈挙閿�鎷嗗寘璁板綍
-                var splitPackage = await Db.Queryable<Dt_SplitPackageRecord>()
+
+                // 1. 鏌ユ壘鎵�鏈夋湭鎾ら攢鐨勬媶鍖呰褰�
+                var splitRecords = await Db.Queryable<Dt_SplitPackageRecord>()
                         .Where(x => x.OriginalBarcode == originalBarcode && !x.IsReverted)
-                        .OrderByDescending(x => x.CreateDate)
-                        .FirstAsync();
+                        .OrderBy(x => x.SplitTime) // 鎸夋椂闂存搴忥紝浠庢渶鏃╁紑濮嬫挙閿�
+                        .ToListAsync();
 
-                if (splitPackage == null)
-                    return WebResponseContent.Instance.Error("鏈壘鍒版媶鍖呰褰�");
+                if (splitRecords == null || !splitRecords.Any())
+                    return WebResponseContent.Instance.Error("鏈壘鍒板彲鎾ら攢鐨勬媶鍖呰褰�");
 
-                // 妫�鏌ユ柊鏉$爜鏄惁宸叉嫞閫�
-                var newOutStockInfo = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
-                    .Where(x => x.CurrentBarcode == splitPackage.NewBarcode)
-                    .FirstAsync();
+                // 2. 妫�鏌ユ墍鏈夋柊鏉$爜鏄惁宸叉嫞閫�
+                var newBarcodes = splitRecords.Select(x => x.NewBarcode).ToList();
+                var newLockInfos = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+                    .Where(x => newBarcodes.Contains(x.CurrentBarcode))
+                    .ToListAsync();
 
-                if (newOutStockInfo.Status == 2)
-                    return WebResponseContent.Instance.Error("鏂版潯鐮佸凡鎷i�夛紝鏃犳硶鎾ら攢鎷嗗寘");
+                var pickedBarcodes = newLockInfos.Where(x => x.Status == 2).Select(x => x.CurrentBarcode).ToList();
+                if (pickedBarcodes.Any())
+                    return WebResponseContent.Instance.Error($"浠ヤ笅鏉$爜宸叉嫞閫夛紝鏃犳硶鎾ら攢锛歿string.Join(",", pickedBarcodes)}");
 
-                // 杩樺師鍘熷嚭搴撹鎯呮暟閲�
-                var originalOutStockInfo = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+                // 3. 鑾峰彇鍘熸潯鐮佷俊鎭�
+                var originalLockInfo = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
                     .Where(x => x.CurrentBarcode == originalBarcode)
                     .FirstAsync();
 
-                originalOutStockInfo.AssignQuantity += splitPackage.SplitQty;
-                await _outStockLockInfoService.Db.Updateable(originalOutStockInfo).ExecuteCommandAsync();
+                if (originalLockInfo == null)
+                    return WebResponseContent.Instance.Error("鏈壘鍒板師鏉$爜閿佸畾淇℃伅");
 
-                // 鍒犻櫎鏂板嚭搴撹鎯呰褰�
+                var originalStockDetail = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+                    .Where(x => x.Barcode == originalBarcode && x.StockId == originalLockInfo.StockId)
+                    .FirstAsync();
+
+                // 4. 鑾峰彇鎵�鏈夋柊鏉$爜鐨勫簱瀛樿褰�
+                var newStockDetails = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+                    .Where(x => newBarcodes.Contains(x.Barcode))
+                    .ToListAsync();
+
+                // 5. 璁$畻鎬昏繕鍘熸暟閲�
+                decimal totalRevertQty = newStockDetails.Sum(x => x.StockQuantity);
+
+                // 6. 杩樺師鍘熸潯鐮佸簱瀛樿褰�
+                if (originalStockDetail != null)
+                {
+                    // 鍘熸潯鐮佸綋鍓嶆暟閲忓姞涓婃墍鏈夋柊鏉$爜鐨勬暟閲�
+                    originalStockDetail.StockQuantity += totalRevertQty;
+                    originalStockDetail.OutboundQuantity += totalRevertQty;
+                    await _stockInfoDetailService.Db.Updateable(originalStockDetail).ExecuteCommandAsync();
+                }
+
+                // 7. 杩樺師鍘熸潯鐮侀攣瀹氫俊鎭�
+                decimal totalAssignQty = newLockInfos.Sum(x => x.AssignQuantity);
+                originalLockInfo.AssignQuantity += totalAssignQty;
+                if (originalLockInfo.OrderQuantity < originalLockInfo.AssignQuantity)
+                {
+                    originalLockInfo.AssignQuantity=originalLockInfo.OrderQuantity;
+                }
+                originalLockInfo.Status = (int)OutLockStockStatusEnum.鍑哄簱涓�;
+                originalLockInfo.IsSplitted = 0;
+                await _outStockLockInfoService.Db.Updateable(originalLockInfo).ExecuteCommandAsync();
+
+                // 8. 鍒犻櫎鎵�鏈夋柊鏉$爜鐨勯攣瀹氫俊鎭�
                 await _outStockLockInfoService.Db.Deleteable<Dt_OutStockLockInfo>()
-                    .Where(x => x.CurrentBarcode == splitPackage.NewBarcode)
+                    .Where(x => newBarcodes.Contains(x.CurrentBarcode))
                     .ExecuteCommandAsync();
 
-                // 鏍囪鎷嗗寘璁板綍涓哄凡鎾ら攢
-                splitPackage.IsReverted = true;
-                await Db.Updateable(splitPackage).ExecuteCommandAsync();
+                // 9. 鍒犻櫎鎵�鏈夋柊鏉$爜鐨勫簱瀛樿褰�
+                await _stockInfoDetailService.Db.Deleteable<Dt_StockInfoDetail>()
+                    .Where(x => newBarcodes.Contains(x.Barcode))
+                    .ExecuteCommandAsync();
+
+                // 10. 鏍囪鎵�鏈夋媶鍖呰褰曚负宸叉挙閿�
+                foreach (var record in splitRecords)
+                {
+                    record.IsReverted = true;
+              
+                }
+                await Db.Updateable(splitRecords).ExecuteCommandAsync();
 
                 _unitOfWorkManage.CommitTran();
-                return WebResponseContent.Instance.OK("鎾ら攢鎷嗗寘鎴愬姛");
+
+                return WebResponseContent.Instance.OK($"鎾ら攢鎷嗗寘鎴愬姛锛屽叡杩樺師{splitRecords.Count}娆℃媶鍖咃紝鎬绘暟閲忥細{totalRevertQty}");
 
             }
             catch (Exception ex)
@@ -220,7 +352,6 @@
                 return WebResponseContent.Instance.Error($"鎾ら攢鎷嗗寘澶辫触锛歿ex.Message}");
             }
         }
-
         // 鑾峰彇鎷嗗寘淇℃伅
         public async Task<WebResponseContent> GetSplitPackageInfo(string orderNo, string palletCode, string barcode)
         {
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 27d5101..4bfba35 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"
@@ -16,6 +16,7 @@
 #endregion << 鐗� 鏈� 娉� 閲� >>
 
 using AutoMapper;
+using Dm.filter;
 using MailKit.Search;
 using Microsoft.Extensions.Logging;
 using Newtonsoft.Json;
@@ -307,18 +308,25 @@
             _locationInfoService.Repository.UpdateData(locationInfo);
 
             var outloks = _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>().Where(x => x.TaskNum == task.TaskNum).ToList();
-            outloks.ForEach(o =>
-            {
-                o.Status = OutLockStockStatusEnum.宸插嚭搴�.ObjToInt();
-            });
-            _outStockLockInfoService.Db.Updateable(outloks).ExecuteCommand();
 
-            var locationCodes = outloks.Select(it => it.LocationCode).Distinct().ToList();
+            var stockids = outloks.Select(x => x.StockId).ToList();
+            
+            _stockService.StockInfoService.Db.Updateable<Dt_StockInfo>()
+                                  .SetColumns(it => new Dt_StockInfo
+                                  {
+                                      StockStatus = StockStatusEmun.鍑哄簱閿佸畾.ObjToInt()
+                                  })
+                                  .Where(it => stockids.Contains(it.Id))
+                                  .ExecuteCommand();
 
-            //_stockRepository.Db.Updateable<Dt_StockInfo>()
-            //  .SetColumns(it => new Dt_StockInfo { StockStatus = StockStatusEmun.})
-            //  .Where(it => locationCodes.Contains(it.LocationCode))
-            //  .ExecuteCommand();
+            _stockService.StockInfoDetailService.Db.Updateable<Dt_StockInfoDetail>()
+                                  .SetColumns(it => new Dt_StockInfoDetail
+                                  {
+                                      Status = StockStatusEmun.鍑哄簱閿佸畾.ObjToInt()
+                                  })
+                                  .Where(it => stockids.Contains( it.StockId))
+                                  .ExecuteCommand();
+ 
 
 
             return WebResponseContent.Instance.OK();
@@ -378,10 +386,48 @@
             }
         }
 
-        public  WebResponseContent InPickTaskCompleted(Dt_Task task)
+        public 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($"鏈壘鍒拌鎵樼洏搴撳瓨鏄庣粏淇℃伅");
+            }
 
+            //鏌ヨ揣浣�
+            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);
+
+            if (stockInfo.PalletType == PalletTypeEnum.Empty.ObjToInt())
+            {
+                locationInfo.LocationStatus = LocationStatusEnum.Pallet.ObjToInt();
+            }
+            else
+            {
+                locationInfo.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
+            }
+            _locationInfoService.Repository.UpdateData(locationInfo);
+
+            task.TaskStatus = TaskStatusEnum.Finish.ObjToInt();
+
+            BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateTypeEnum.鑷姩瀹屾垚 : OperateTypeEnum.浜哄伐瀹屾垚);
 
             return WebResponseContent.Instance.OK();
         }
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_Outbound.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_Outbound.cs"
index 61daea9..2bd7d87 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_Outbound.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_Outbound.cs"
@@ -159,7 +159,7 @@
                         (int)OutOrderTypeEnum.Issue => TaskTypeEnum.Outbound,
                         (int)OutOrderTypeEnum.Allocate => TaskTypeEnum.OutAllocate,
                         (int)OutOrderTypeEnum.Quality => TaskTypeEnum.OutQuality,
-                        _ => new TaskTypeEnum()
+                        _ =>   TaskTypeEnum.Outbound 
                     };
                     tasks = GetTasks(result.Item1, typeEnum, outStation);
                     tasks.ForEach(x =>

--
Gitblit v1.9.3