From e83c793bebdb1b9ecdcd79fab8d83fd167baa817 Mon Sep 17 00:00:00 2001
From: wankeda <Administrator@DESKTOP-HAU3ST3>
Date: 星期一, 19 一月 2026 15:51:56 +0800
Subject: [PATCH] 盘点流程

---
 WMS/WIDESEA_WMSServer/WIDESEA_InboundService/Base/InboundOrderService.cs |  113 +++++++++++++++++++++++++++-----------------------------
 1 files changed, 54 insertions(+), 59 deletions(-)

diff --git a/WMS/WIDESEA_WMSServer/WIDESEA_InboundService/Base/InboundOrderService.cs b/WMS/WIDESEA_WMSServer/WIDESEA_InboundService/Base/InboundOrderService.cs
index 783f84f..cf22938 100644
--- a/WMS/WIDESEA_WMSServer/WIDESEA_InboundService/Base/InboundOrderService.cs
+++ b/WMS/WIDESEA_WMSServer/WIDESEA_InboundService/Base/InboundOrderService.cs
@@ -213,6 +213,7 @@
                         Wlstatus = (int)InventoryMaterialStatus.鍚堟牸,
                         Mgeneratetime = DateTime.Now,
                         WarehouseId = warehouse.WarehouseId,
+                        System = inboundOrder.System,
                         Details = new List<Dt_StockInfoDetail>()
                     };
                 }
@@ -348,7 +349,7 @@
         }
 
         //鑽按锛屼綆娓╀粨缁勭洏
-        public WebResponseContent NEWMaterielGroup(SaveModel saveModel)
+        public WebResponseContent NewMaterielGroup(SaveModel saveModel)
         {
             WebResponseContent content = new WebResponseContent();
             try
@@ -442,7 +443,7 @@
                 {
                     stockInfo = new Dt_StockInfo()
                     {
-                        BatchNo = inboundOrderDet.BatchNo,
+                        BatchNo ="",
                         PalletCode = palletCode,
                         PalletType = GetPalletType(warehouse, palletCode),//GetPalletType(warehouse, palletCode)
                         IsFull = true,
@@ -454,48 +455,14 @@
                         Wlstatus = (int)InventoryMaterialStatus.鍚堟牸,
                         Mgeneratetime = DateTime.Now,
                         WarehouseId = warehouse.WarehouseId,
+                        System = inboundOrder.System,
                         Details = new List<Dt_StockInfoDetail>()
                     };
                 }
                 else
                 {
-                    //if (stockInfo.StockStatus != StockStatusEmun.缁勭洏鏆傚瓨.ObjToInt())
-                    //{
                     return WebResponseContent.Instance.Error($"鎵樼洏鍙烽噸澶�,璇ユ墭鐩樺凡缁勮繃鐗╂枡");
-                    //}
-                    //beforeQuantity = stockInfo.Details.Sum(x => x.StockQuantity);
                 }
-
-                if (warehouse.WarehouseCode == WarehouseEnum.SC01_BC.ToString())
-                {
-                    stockInfo.Remark = Initiallife.ToString();
-                    string batchNo = models.FirstOrDefault()?.LotNo ?? "";
-                    //Dt_StockInfoDetail existDetail = _stockRepository.StockInfoDetailRepository.QueryFirst(x => x.BatchNo == batchNo);
-                    //if (existDetail != null)
-                    //{
-                    //    return WebResponseContent.Instance.Error($"{batchNo}娴嬭瘯鏋跺凡瀛樺湪");
-                    //}
-                    if (models.Count >= 2)
-                    {
-                        return WebResponseContent.Instance.Error($"缁勭洏鏄庣粏涓嶅敮涓�");
-                    }
-                    //if (palletCode.Substring(0, 1) == "6")
-                    //{
-                    //    stockInfo.PalletType = PalletTypeEnum.MediumPallet.ObjToInt();
-                    //}
-                    //else
-                    //{
-                    //    stockInfo.PalletType = PalletTypeEnum.LargestPallet.ObjToInt();
-                    //}
-                }
-                else if (warehouse.WarehouseCode == WarehouseEnum.SC01_BC.ToString())
-                {
-                    if (models.Count >= 2)
-                    {
-                        return WebResponseContent.Instance.Error($"缁勭洏鏄庣粏涓嶅敮涓�");
-                    }
-                }
-
                 List<Dt_StockInfoDetail> stockInfoDetails = new List<Dt_StockInfoDetail>();
                 foreach (var model in models)
                 {
@@ -515,7 +482,7 @@
                         OrderNo = inboundOrder.OrderNo,
                         BatchNo = notGroupDetail.BatchNo,
                         LinId = notGroupDetail.LinId,
-                        StockQuantity = (quantitys.FirstOrDefault()),
+                        StockQuantity = model.Quantity,
                         Status = (int)StockStatusEmun.缁勭洏鏆傚瓨,
                         Creater = "WMS",
                         CreateDate = DateTime.Now,
@@ -535,9 +502,9 @@
                     stockInfoDetails.Add(stockInfoDetail);
 
                     decimal decimalReceiptQuantity = Convert.ToDecimal(notGroupDetail.ReceiptQuantity);
-                    decimal decimalModelQuantity = Convert.ToDecimal((quantitys.FirstOrDefault()));
+                    decimal decimalModelQuantity = Convert.ToDecimal(notGroupDetail.OrderQuantity);
                     decimal decimalOrderQuantity = Convert.ToDecimal(notGroupDetail.OrderQuantity);
-                    decimalReceiptQuantity += decimalModelQuantity;
+                    decimalReceiptQuantity += model.Quantity;
                     // 妫�鏌ユ槸鍚﹁秴鍑鸿鍗曟暟閲�
                     if (decimalReceiptQuantity > decimalOrderQuantity)
                     {
@@ -757,6 +724,7 @@
                         Wlstatus = (int)InventoryMaterialStatus.鍚堟牸,
                         Mgeneratetime = DateTime.Now,
                         WarehouseId = warehouse.WarehouseId,
+                        System = inboundOrder.System,
                         Details = new List<Dt_StockInfoDetail>()
                     };
                 }
@@ -904,10 +872,46 @@
                 {
                     throw new Exception("搴撳瓨鏈壘鍒版墭鐩樺彿");
                 }
+
+                var sameItems = from sourceItem in stockInfo.Details
+                                join targetItem in targetstockInfo.Details
+                                on new
+                                {
+                                    sourceItem.BatchNo,
+                                    sourceItem.MaterielName,
+                                    sourceItem.MaterielCode
+                                }
+                                equals new
+                                {
+                                    targetItem.BatchNo,
+                                    targetItem.MaterielName,
+                                    targetItem.MaterielCode
+                                }
+                                select new
+                                {
+                                    SourceItem = sourceItem,
+                                    TargetItem = targetItem,
+                                    BatchNo = sourceItem.BatchNo,
+                                    MaterialCode = sourceItem.MaterielCode,
+                                    MaterialType = sourceItem.MaterielName
+                                };
+
+                var matchedSourceItemIds = sameItems.Select(x => x.SourceItem.Id).ToList();
+
                 foreach (var item in stockInfo.Details)
                 {
-                    item.StockId = targetstockInfo.Id;
+                    if (!matchedSourceItemIds.Contains(item.Id))
+                    {
+                        item.StockId = targetstockInfo.Id;
+                    }
                 }
+                var differentItems = stockInfo.Details
+      .Where(x => !matchedSourceItemIds.Contains(x.Id))
+      .ToList();
+                targetstockInfo.Details = targetstockInfo.Details
+      .Where(x => !matchedSourceItemIds.Contains(x.Id))
+      .Concat(differentItems)
+      .ToList();
                 if (warehouse.WarehouseCode == "SC02_CP")
                 {
                     warehouse.WarehouseCode = "SC01_CP";
@@ -940,21 +944,6 @@
                         }).ToList()
                             }
                     }
-                    //    Parameters = stockInfo.Details.Select(g => new HouseSyncretism.data
-                    //    {
-                    //        Lpn = stockInfo.PalletCode,
-                    //        MoveType = 0,
-                    //        WareHouseCode = warehouse.WarehouseCode,
-                    //        ItemCode = g.MaterielCode,
-                    //        MoveNumber = g.StockQuantity,
-                    //        //LotNo = g.,
-                    //        WipBatch = g.BatchNo,
-                    //        LocationName = stockInfo.PalletCode,
-                    //        TargetLocName = targetstockInfo.PalletCode,
-                    //        TargetLpn = targetstockInfo.PalletCode,
-
-                    //    }).ToList()
-                    //};
                 };
                 var authResult = AuthenticateWithWMS();
                 if (authResult.IsSuccess)
@@ -967,7 +956,6 @@
                                             };
 
                     var response = HttpHelper.Post<MomRequestContent>(ReceiveWMSTaskin, houseSyncretism, "绔嬪簱鍏ュ簱鏁伴噺鍥炰紶WMS");
-                    // 鍒ゆ柇Success鐨勫��
                     if (!response.Success)
                     {
                         throw new Exception($"鎿嶄綔澶辫触: {response.Message ?? "鏈彁渚涢敊璇俊鎭�"}");
@@ -975,10 +963,16 @@
 
                 }
                 _unitOfWorkManage.BeginTran();
-                targetstockInfo.Details.AddRange(stockInfo.Details);
+                foreach (var sameItem in sameItems)
+                {
+                    sameItem.TargetItem.StockQuantity += sameItem.SourceItem.StockQuantity;
+                    _stockRepository.StockInfoDetailRepository.UpdateData(sameItem.TargetItem);
+                    _stockRepository.StockInfoDetailRepository.DeleteData(sameItem.SourceItem);
+                }
                 _stockRepository.StockInfoRepository.UpdateData(targetstockInfo);
-                _stockRepository.StockInfoDetailRepository.UpdateData(stockInfo.Details);
+                _stockRepository.StockInfoDetailRepository.UpdateData(targetstockInfo.Details);
                 _stockRepository.StockInfoRepository.DeleteData(stockInfo);
+
                 _unitOfWorkManage.CommitTran();
                 webResponseContent = WebResponseContent.Instance.OK("鍚堟墭鎴愬姛");
             }
@@ -1282,6 +1276,7 @@
                             if (inboundOrderDetailOld != null)
                             {
                                 inboundOrderDetailOld.OrderQuantity += item.OrderQuantity;
+                                inboundOrderDetailOld.OrderDetailStatus = OrderDetailStatusEnum.Inbounding.ObjToInt();
                                 _inboundRepository.InboundOrderDetailRepository.UpdateData(inboundOrderDetailOld);
                             }
                             else

--
Gitblit v1.9.3