From dccc001554c6c5376482df77f929c0d49b258844 Mon Sep 17 00:00:00 2001
From: yangpeixing <yangpeixing@hnkhzn.com>
Date: 星期三, 04 二月 2026 08:58:00 +0800
Subject: [PATCH] 1

---
 WMS/WIDESEA_WMSServer/WIDESEA_InboundService/Base/InboundOrderService.cs |  665 ++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 462 insertions(+), 203 deletions(-)

diff --git a/WMS/WIDESEA_WMSServer/WIDESEA_InboundService/Base/InboundOrderService.cs b/WMS/WIDESEA_WMSServer/WIDESEA_InboundService/Base/InboundOrderService.cs
index 783f84f..d841b3d 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,
@@ -453,49 +454,15 @@
                         Materialweight = 0,
                         Wlstatus = (int)InventoryMaterialStatus.鍚堟牸,
                         Mgeneratetime = DateTime.Now,
-                        WarehouseId = warehouse.WarehouseId,
+                        WarehouseId = 0,
+                        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)
                 {
@@ -503,6 +470,14 @@
                     Dt_InboundOrderDetail notGroupDetail = new Dt_InboundOrderDetail();
 
                     notGroupDetail = inboundOrder.Details.Where(x => x.OrderDetailStatus <= OrderDetailStatusEnum.Inbounding.ObjToInt() && x.MaterielCode == model.MaterielCode && x.BatchNo == model.LotNo).FirstOrDefault();
+                    if (notGroupDetail.MaterielType == 1)
+                    {
+                        stockInfo.WarehouseId = 6;
+                    }
+                    else if (notGroupDetail.MaterielType == 2)
+                    {
+                        stockInfo.WarehouseId = 5;
+                    }
 
                     if (notGroupDetail == null)
                     {
@@ -515,7 +490,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 +510,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)
                     {
@@ -585,7 +560,284 @@
         /// </summary>
         /// <param name="materielGroupDTO"></param>
         /// <returns></returns>
+        #region
         public WebResponseContent CPMaterielGroup(SaveModel saveModel)
+        {
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                var orderNo = saveModel.MainData["orderNo"].ToString();
+                var palletCode = saveModel.MainData["palletCode"].ToString();
+                var warehouseId = saveModel.MainData["warehouseId"].ObjToInt();
+                var serialNumbers = new List<string>();
+                var quantities = new List<decimal>();
+                var lotNos = new List<string>();
+                var materielCodes = new List<string>();
+                // 鑾峰彇浠撳簱淇℃伅
+                Dt_Warehouse warehouse = _warehouseService.Repository.QueryFirst(x => x.WarehouseId == warehouseId);
+                if (warehouse == null)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒拌浠撳簱淇℃伅");
+                }
+
+                // 鑾峰彇鍏ュ簱鍗曚俊鎭�
+                Dt_InboundOrder inboundOrder = BaseDal.Db.Queryable<Dt_InboundOrder>()
+                    .Where(x => x.OrderNo == orderNo && x.WarehouseId == warehouse.WarehouseId)
+                    .Includes(x => x.Details)
+                    .First();
+
+                if (inboundOrder == null || inboundOrder.Details == null || inboundOrder.Details.Count <= 0)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒板叆搴撳崟淇℃伅");
+                }
+
+                // 鎵归噺鏌ヨ鎵�鏈夌浉鍏崇鍙风殑CP鍏ュ簱鍗曟槑缁�
+                List<Dt_CPInboundOrderDetail> CPinboundOrderDetails = BaseDal.Db.Queryable<Dt_CPInboundOrderDetail>()
+                    .LeftJoin<Dt_InboundOrderDetail>((cp, d) => cp.OrderDetailId == d.Id)
+                    .LeftJoin<Dt_InboundOrder>((cp, d, o) => d.OrderId == o.Id)
+                    .Where((cp, d, o) =>
+                        o.OrderNo == orderNo &&
+                        o.WarehouseId == warehouse.WarehouseId
+                    )
+                    .Select((cp, d, o) => cp)
+                    .ToList();
+
+                //float totalQty = CPinboundOrderDetails.Sum(x => x.QtyOfpcs);
+
+
+                // 鎸夌収绠卞彿鍒嗙粍锛岀敤浜庡悗缁鐞�
+                var boxCodesToCheck = CPinboundOrderDetails
+                    .Select(x => x.BoxCode)
+                    .Where(bc => !string.IsNullOrEmpty(bc))
+                    .Distinct()
+                    .ToList();
+
+
+                // 3. 鏌ヨ杩欎簺绠卞彿鏄惁宸插瓨鍦ㄤ簬搴撳瓨涓�
+                var existingStockBoxCodes = _stockRepository.StockInfoRepository.Db
+                    .Queryable<Dt_StockInfo>()
+                    .LeftJoin<Dt_StockInfoDetail>((s, d) => s.Id == d.StockId)
+                    .LeftJoin<Dt_StockInfoDetailCP>((s, d, cp) => d.Id == cp.StockDetailId)
+                    .Where((s, d, cp) => boxCodesToCheck.Contains(cp.BoxCode) && !string.IsNullOrEmpty(cp.BoxCode))
+                    .Select((s, d, cp) => cp.BoxCode)
+                    .Distinct()
+                    .ToList();
+
+                // 4. 妫�鏌ユ槸鍚︽湁閲嶅
+                if (existingStockBoxCodes.Any())
+                {
+                    return WebResponseContent.Instance.Error($"浠ヤ笅绠卞彿宸插湪搴撳瓨涓細{string.Join(",", existingStockBoxCodes)}");
+                }
+
+                // 鑾峰彇鎵�鏈夌浉鍏崇殑鍏ュ簱鍗曟槑缁咺D
+                var orderDetailIds = CPinboundOrderDetails.Select(x => x.OrderDetailId).Distinct().ToList();
+
+                // 鏌ヨ瀵瑰簲鐨勫叆搴撳崟鏄庣粏
+                List<Dt_InboundOrderDetail> inboundOrderDetails = BaseDal.Db.Queryable<Dt_InboundOrderDetail>()
+                    .Where(x => orderDetailIds.Contains(x.Id))
+                    .ToList();
+
+                if (inboundOrderDetails.Sum(x => x.OrderQuantity) <= inboundOrderDetails.Sum(x => x.ReceiptQuantity))
+                {
+                    return WebResponseContent.Instance.Error($"姝ゅ崟鎹凡鍏ㄩ儴缁勭洏瀹屾垚");
+                }
+
+                // 鎸夎鍗曟槑缁咺D鍒嗙粍锛屾鏌ユ瘡涓槑缁嗙殑鎵�鏈夌鍙锋槸鍚﹂兘鎵弿浜�
+                var detailsByOrderDetailId = CPinboundOrderDetails
+                    .GroupBy(x => x.OrderDetailId)
+                    .ToDictionary(g => g.Key, g => g.ToList());
+
+                // 鑾峰彇鐩稿叧鐨勮鍗曟槑缁�
+                List<Dt_InboundOrderDetail> orderDetails = new List<Dt_InboundOrderDetail>();
+                List<Dt_InboundOrderDetail> detailsToUpdate = new List<Dt_InboundOrderDetail>();
+
+                // 妫�鏌ユ瘡涓鍗曟槑缁嗘槸鍚﹀畬鎴愪簡鎵�鏈夌鍙风殑鎵弿
+                foreach (var kvp in detailsByOrderDetailId)
+                {
+                    int orderDetailId = kvp.Key;
+                    var cpDetails = kvp.Value;
+
+                    // 鑾峰彇璁㈠崟鏄庣粏
+                    var orderDetail = inboundOrder.Details.FirstOrDefault(x => x.Id == orderDetailId);
+                    if (orderDetail == null)
+                    {
+                        orderDetail = BaseDal.Db.Queryable<Dt_InboundOrderDetail>()
+                            .First(x => x.Id == orderDetailId);
+                    }
+
+                    if (orderDetail == null)
+                    {
+                        return WebResponseContent.Instance.Error($"鏈壘鍒拌鍗曟槑缁咺D锛歿orderDetailId}");
+                    }
+
+                    orderDetails.Add(orderDetail);
+
+                    // 鏍囪璇ユ槑缁嗕负宸插畬鎴愮粍鐩�
+                    orderDetail.OrderDetailStatus = OrderDetailStatusEnum.GroupAndInbound.ObjToInt();
+                    var recqty = orderDetail.ReceiptQuantity;
+                    float totalQty = cpDetails.Sum(item => item.QtyOfpcs);
+                    orderDetail.ReceiptQuantity = (decimal)totalQty + recqty; // 鏀惰揣鏁伴噺绛変簬璁㈠崟鏁伴噺
+
+                    detailsToUpdate.Add(orderDetail);
+                }
+
+
+
+                // 妫�鏌ユ墭鐩樻槸鍚﹀凡瀛樺湪
+                Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db
+                    .Queryable<Dt_StockInfo>()
+                    .Where(x => x.PalletCode == palletCode)
+                    .First();
+
+                if (stockInfo == null)
+                {
+                    // 鍒涘缓鏂版墭鐩�
+                    stockInfo = new Dt_StockInfo()
+                    {
+                        BatchNo = "", // 浣跨敤鍏ュ簱鍗曟壒娆″彿
+                        PalletCode = palletCode,
+                        PalletType = GetPalletType(warehouse, palletCode),
+                        IsFull = true,
+                        StockStatus = (int)StockStatusEmun.缁勭洏鏆傚瓨,
+                        Creater = "WMS",
+                        CreateDate = DateTime.Now,
+                        MaterialType = (int)InventoryMaterialType.鍘熸潗鏂�,
+                        Materialweight = 0,
+                        Wlstatus = (int)InventoryMaterialStatus.鍚堟牸,
+                        Mgeneratetime = DateTime.Now,
+                        WarehouseId = warehouse.WarehouseId,
+                        System = inboundOrder.System,
+                        Details = new List<Dt_StockInfoDetail>()
+                    };
+                }
+                else
+                {
+                    // 濡傛灉鎵樼洏宸插瓨鍦紝妫�鏌ユ槸鍚﹀凡缁忔槸缁勭洏鏆傚瓨鐘舵��
+                    if (stockInfo.StockStatus != (int)StockStatusEmun.缁勭洏鏆傚瓨)
+                    {
+                        return WebResponseContent.Instance.Error($"鎵樼洏鍙烽噸澶�,璇ユ墭鐩樺凡缁勮繃鐗╂枡");
+                    }
+                }
+
+                List<Dt_CPInboundOrderDetail> cPInboundOrderDetail = new List<Dt_CPInboundOrderDetail>();
+                // 鍒涘缓搴撳瓨鏄庣粏 - 鎸夎鍗曟槑缁嗗垱寤�
+                foreach (var orderDetail in orderDetails)
+                {
+                    // 鑾峰彇璇ユ槑缁嗗搴旂殑鎵�鏈夌鍙�
+                    var detailBoxCodes = detailsByOrderDetailId[orderDetail.Id]
+                        .Select(x => x.BoxCode)
+                        .ToList();
+
+                    cPInboundOrderDetail = BaseDal.Db.Queryable<Dt_CPInboundOrderDetail>().Where(x => detailBoxCodes.Contains(x.BoxCode)).ToList();
+
+                    List<Dt_StockInfoDetailCP> stockInfoDetailCP = new List<Dt_StockInfoDetailCP>();
+                    foreach (var item in cPInboundOrderDetail)
+                    {
+                        Dt_StockInfoDetailCP stockInfoDetailCP1 = new Dt_StockInfoDetailCP()
+                        {
+                            BoxId = item.BoxId,
+                            BoxCode = item.BoxCode,
+                            DateCode = item.DateCode,
+                            JobId = item.JobId,
+                            PartNum = item.PartNum,
+                            QtyOfpcs = item.QtyOfpcs,
+                            QtyOfxout = item.QtyOfxout,
+                            CPStockDetailStatus = (int)StockStatusEmun.缁勭洏鏆傚瓨,
+                            LPNNO = item.LPNNO,
+                            OrinalLocation = item.OrinalLocation,
+                            Creater = "涓婃父WMS",
+                        };
+                        stockInfoDetailCP.Add(stockInfoDetailCP1);
+
+                        item.CPOrderDetailStatus = InOrderStatusEnum.鍏ュ簱涓�.ObjToInt();
+                    }
+
+                    // 鍒涘缓搴撳瓨鏄庣粏
+                    Dt_StockInfoDetail stockInfoDetail = new Dt_StockInfoDetail()
+                    {
+                        MaterielCode = orderDetail.MaterielCode,
+                        MaterielName = orderDetail.MaterielName,
+                        OrderNo = inboundOrder.OrderNo,
+                        BatchNo = orderDetail.BatchNo,
+                        SupplierBatch = orderDetail.SupplierBatch,
+                        LinId = orderDetail.LinId,
+                        StockQuantity = (decimal)cPInboundOrderDetail.Sum(item => item.QtyOfpcs),
+                        Status = (int)StockStatusEmun.缁勭洏鏆傚瓨,
+                        Creater = "WMS",
+                        CreateDate = DateTime.Now,
+                        Id = orderDetail.LinId.ObjToInt(),
+                        //DeliveryNote = orderDetail.DeliveryNote,
+                        MaterieSpec = orderDetail.MaterieSpec,
+                        StockDetails = stockInfoDetailCP,
+                        OrinalLocation = orderDetail.OrinalLocation
+                    };
+
+                    if (stockInfo.Id > 0)
+                    {
+                        stockInfoDetail.StockId = stockInfo.Id;
+                    }
+                    stockInfo.Details.Add(stockInfoDetail);
+                }
+
+                // 妫�鏌ュ叆搴撳崟鏄惁鎵�鏈夋槑缁嗛兘宸插畬鎴愮粍鐩�
+                bool allDetailsCompleted = inboundOrder.Details.All(x =>
+                    detailsToUpdate.Any(d => d.Id == x.Id) ||
+                    x.OrderDetailStatus == OrderDetailStatusEnum.GroupAndInbound.ObjToInt());
+
+
+
+                // 浜嬪姟澶勭悊
+                _unitOfWorkManage.BeginTran();
+                try
+                {
+                    if (stockInfo.Id == 0)
+                    {
+                        _stockRepository.StockInfoRepository.Db.InsertNav(stockInfo)
+                            .Include(x => x.Details).ThenInclude(x => x.StockDetails)
+                            .ExecuteCommand();
+                    }
+                    else
+                    {
+                        _stockRepository.StockInfoRepository.Db.UpdateNav(stockInfo)
+                            .Include(x => x.Details, new UpdateNavOptions()
+                            {
+                                OneToManyInsertOrUpdate = true
+                            }).ThenInclude(x => x.StockDetails)
+                            .ExecuteCommand();
+                    }
+
+                    // 鏇存柊璁㈠崟鏄庣粏
+                    if (detailsToUpdate.Count > 0)
+                    {
+                        _inboundRepository.InboundOrderDetailRepository.UpdateData(detailsToUpdate);
+                    }
+
+                    // 鏇存柊璁㈠崟
+                    _inboundRepository.InboundOrderRepository.UpdateData(inboundOrder);
+
+                    _cPInboundOrderDetailRepository.UpdateData(cPInboundOrderDetail);
+
+                    _unitOfWorkManage.CommitTran();
+
+                    content = WebResponseContent.Instance.OK("缁勭洏鎴愬姛");
+                }
+                catch (Exception ex)
+                {
+                    _unitOfWorkManage.RollbackTran();
+                    throw new Exception($"缁勭洏浜嬪姟澶勭悊澶辫触锛歿ex.Message}", ex);
+                }
+            }
+            catch (Exception ex)
+            {
+                content = WebResponseContent.Instance.Error($"缁勭洏澶辫触锛歿ex.Message}");
+            }
+
+            return content;
+        }
+        #endregion
+
+        #region 寮冪敤
+        public WebResponseContent CP1MaterielGroup(SaveModel saveModel)
         {
             WebResponseContent content = new WebResponseContent();
             try
@@ -757,6 +1009,7 @@
                         Wlstatus = (int)InventoryMaterialStatus.鍚堟牸,
                         Mgeneratetime = DateTime.Now,
                         WarehouseId = warehouse.WarehouseId,
+                        System = inboundOrder.System,
                         Details = new List<Dt_StockInfoDetail>()
                     };
                 }
@@ -882,7 +1135,10 @@
 
             return content;
         }
+        #endregion
+
         public string ReceiveWMSTaskin = WIDESEA_Core.Helper.AppSettings.Configuration["ReceiveWMSTaskin"];
+
         /// <summary>
         /// 缁勭洏鍚堟墭
         /// </summary>
@@ -904,10 +1160,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 +1232,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 +1244,6 @@
                                             };
 
                     var response = HttpHelper.Post<MomRequestContent>(ReceiveWMSTaskin, houseSyncretism, "绔嬪簱鍏ュ簱鏁伴噺鍥炰紶WMS");
-                    // 鍒ゆ柇Success鐨勫��
                     if (!response.Success)
                     {
                         throw new Exception($"鎿嶄綔澶辫触: {response.Message ?? "鏈彁渚涢敊璇俊鎭�"}");
@@ -975,10 +1251,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("鍚堟墭鎴愬姛");
             }
@@ -1016,7 +1298,6 @@
 
         public int GetPalletType(Dt_Warehouse warehouse, string palletCode)
         {
-
             if (warehouse.WarehouseCode == WarehouseEnum.SC01_BC.ObjToString())
             {
                 Dt_PalletTypeInfo palletTypeInfo = _palletTypeInfoRepository.QueryFirst(x => x.CodeStartStr == palletCode.Substring(0, 3));
@@ -1026,6 +1307,16 @@
                 }
                 return palletTypeInfo.PalletType;
             }
+            else
+            {
+                Dt_PalletTypeInfo palletTypeInfo = _palletTypeInfoRepository.QueryFirst(x => x.CodeStartStr == palletCode.Substring(0, 2));
+                if (palletTypeInfo == null)
+                {
+                    throw new Exception($"鎵樼洏鍙烽敊璇�");
+                }
+                return palletTypeInfo.PalletType;
+            }
+
             //else if (warehouse.WarehouseCode == WarehouseEnum.HA152.ObjToString())
             //{
             //    Dt_PalletTypeInfo palletTypeInfo = _palletTypeInfoRepository.QueryFirst(x => x.CodeStartStr == palletCode.Substring(0, 2));
@@ -1127,10 +1418,6 @@
                     }
                     if (warehouse.WarehouseCode.Contains("CP"))
                     {
-                        if (item.SupplierBatch == null)
-                        {
-                            return content.Error("渚涘簲鍟嗘壒娆′笉鍙负绌�");
-                        }
                         Dt_InboundOrder inboundOrderOld = BaseDal.Db.Queryable<Dt_InboundOrder>().Where(x => x.UpperOrderNo == model.AsnNo).Includes(x => x.Details).First();
 
                         if (inboundOrderOld != null)
@@ -1162,6 +1449,8 @@
                                         QtyOfpcs = (float)list.QtyOfpcs,
                                         QtyOfxout = (float)list.QtyOfxout,
                                         CPOrderDetailStatus = OrderDetailStatusEnum.New.ObjToInt(),
+                                        LPNNO = list.LPNNO,
+                                        OrinalLocation = list.OrinalLocation,
                                         Creater = "涓婃父WMS",
                                     };
                                     cPInboundOrderDetail.Add(cPInboundOrderDetail1);
@@ -1204,6 +1493,8 @@
                                     QtyOfpcs = (float)list.QtyOfpcs,
                                     QtyOfxout = (float)list.QtyOfxout,
                                     CPOrderDetailStatus = OrderDetailStatusEnum.New.ObjToInt(),
+                                    LPNNO = list.LPNNO,
+                                    OrinalLocation = list.OrinalLocation,
                                     Creater = "涓婃父WMS",
                                 };
                                 cPInboundOrderDetail.Add(cPInboundOrderDetail1);
@@ -1226,7 +1517,6 @@
                                 OrinalLocation = item.OrinalLocation,
                                 CPDetails = cPInboundOrderDetail
                             };
-
                             Dt_InboundOrder inboundOrder = new Dt_InboundOrder()
                             {
                                 OrderNo = model.AsnNo,
@@ -1264,10 +1554,10 @@
                     }
                     else
                     {
-                        if (item.SupplierBatch == null)
-                        {
-                            return content.Error("渚涘簲鍟嗘壒娆′笉鍙负绌�");
-                        }
+                        //if (item.SupplierBatch == null)
+                        //{
+                        //    return content.Error("渚涘簲鍟嗘壒娆′笉鍙负绌�");
+                        //}
                         Dt_InboundOrder inboundOrderOld = BaseDal.Db.Queryable<Dt_InboundOrder>().Where(x => x.UpperOrderNo == model.AsnNo).Includes(x => x.Details).First();
 
                         if (inboundOrderOld != null)
@@ -1282,6 +1572,7 @@
                             if (inboundOrderDetailOld != null)
                             {
                                 inboundOrderDetailOld.OrderQuantity += item.OrderQuantity;
+                                inboundOrderDetailOld.OrderDetailStatus = OrderDetailStatusEnum.Inbounding.ObjToInt();
                                 _inboundRepository.InboundOrderDetailRepository.UpdateData(inboundOrderDetailOld);
                             }
                             else
@@ -1290,6 +1581,7 @@
                                 {
                                     OrderId = orderDetail1.OrderId,
                                     MaterielCode = item.MaterielCode,
+                                    MaterielType=item.MaterielType,
                                     BatchNo = item.BatchNo,
                                     OrderQuantity = item.OrderQuantity,
                                     ReceiptQuantity = 0,
@@ -1309,6 +1601,7 @@
                         {
                             Dt_InboundOrderDetail orderDetail = new Dt_InboundOrderDetail()
                             {
+                                MaterielType = item.MaterielType,
                                 MaterielCode = item.MaterielCode,
                                 BatchNo = item.BatchNo,
                                 OrderQuantity = item.OrderQuantity,
@@ -1339,46 +1632,12 @@
                                 System = model.System,
                                 Details = new List<Dt_InboundOrderDetail> { orderDetail }
                             };
-                            //switch (model.OrderType)//鍗曟嵁绫诲瀷
-                            //{
-                            //    case 1:
-                            //        inboundOrder.OrderType = InOrderTypeEnum.Allocat.ObjToInt();
-                            //        break;
-                            //    case 3:
-                            //        inboundOrder.OrderType = InOrderTypeEnum.CustomerRecovery.ObjToInt();
-                            //        break;
-                            //    case 6:
-                            //        inboundOrder.OrderType = InOrderTypeEnum.SaleReturn.ObjToInt();
-                            //        break;
-                            //    default:
-                            //        break;
-                            //};
                             Db.InsertNav(inboundOrder).Include(x => x.Details).ExecuteCommand();
-
                         }
                     }
                 }
                 _unitOfWorkManage.CommitTran();
                 content = WebResponseContent.Instance.OK();
-                //InboundOrderAddDTO orderAddDTO1 = new InboundOrderAddDTO();
-                //orderAddDTO1.OrderNo = orderAddDTO.AsnNo;
-                //orderAddDTO1.UpperOrderNo = orderAddDTO.AsnNo;
-                //orderAddDTO1.OutWareHouse = orderAddDTO.InWarehouse;
-                //orderAddDTO1.TransactionCode = orderAddDTO.TransactionCode;
-                //orderAddDTO1.InoutType = orderAddDTO.OrderType;
-                //orderAddDTO1.OrderType = orderAddDTO.InoutType.ObjToInt();
-                //orderAddDTO1.Details = orderAddDTO.DetailList.DicToIEnumerable<InboundOrderDetailAddDTO>();
-                //#region 楠岃瘉鏁版嵁
-                //(bool, string, object?) result = CheckInboundOrderAddData(orderAddDTO1);
-                //if (!result.Item1) return content = WebResponseContent.Instance.Error(result.Item2);
-                //#endregion
-
-                //Dt_InboundOrder inboundOrder = _mapper.Map<Dt_InboundOrder>(orderAddDTO1);
-                //inboundOrder.OrderStatus = InboundStatusEnum.鏈紑濮�.ObjToInt();
-                //inboundOrder.Creater = "WMS";
-                //inboundOrder.CreateDate = DateTime.Now;
-                //bool a = BaseDal.Db.InsertNav(inboundOrder).Include(x => x.Details).ExecuteCommand();
-
             }
             catch (Exception ex)
             {
@@ -1685,7 +1944,7 @@
         }
         //鍙嶆嫞鍥炲簱鍗�
         public WebResponseContent ReceiveReturnOrder(List<HouseReturnOrder> houseReturnOrder)
-        {
+       {
             try
             {
                 Random random = new Random();
@@ -1693,119 +1952,119 @@
                 _unitOfWorkManage.BeginTran();
                 foreach (var item in houseReturnOrder)
                 {
-                    int randomNum = random.Next(1, 1000);
-                    string datePart = DateTime.Now.ToString("yyyyMMdd");
-                    Dt_ReturnOrder returnOrder = _returnOrderRepository.QueryFirst(x => x.LPNNo == item.LPNNo && x.OrderStatus == InOrderStatusEnum.鏈紑濮�.ObjToInt());
-                    if (returnOrder == null)
-                    {
-                        Dt_ReturnOrder newReturnOrder = new Dt_ReturnOrder
+                        int randomNum = random.Next(1, 1000);
+                        string datePart = DateTime.Now.ToString("yyyyMMdd");
+                        Dt_ReturnOrder returnOrder = _returnOrderRepository.QueryFirst(x => x.LPNNo == item.LPNNo && x.OrderStatus == InOrderStatusEnum.鏈紑濮�.ObjToInt());
+                        if (returnOrder == null)
                         {
-                            OrderType = OrderTypeEnum.鍙嶆嫞鍥炲簱鍗�.ObjToInt(),
-                            MaterielCode = item.MaterielCode,
-                            MaterielName = item.MaterielName,
+                            Dt_ReturnOrder newReturnOrder = new Dt_ReturnOrder
+                            {
+                                OrderType = OrderTypeEnum.鍙嶆嫞鍥炲簱鍗�.ObjToInt(),
+                                MaterielCode = item.MaterielCode,
+                                MaterielName = item.MaterielName,
                             MaterieSpec = item.MaterieSpec,
-                            BatchNo = item.BatchNo,
-                            OrderQuantity = item.OrderQuantity,
+                                BatchNo = item.BatchNo,
+                                OrderQuantity = item.OrderQuantity,
                             Remark = item.Remark,
-                            LinId = item.LinId,
-                            LPNNo = item.LPNNo,
+                                LinId = item.LinId,
+                                LPNNo = item.LPNNo,
                             LocationCode = item.LocationCode,
                             WarehouseCode = item.WarehouseCode,
                             System = item.System,
-                            OrderStatus = InOrderStatusEnum.鏈紑濮�.ObjToInt(),
-                            Creater = "SMOM",
-                            CreateDate = DateTime.Now
-                        };
-                        _returnOrderRepository.AddData(newReturnOrder);
-                        Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo, Dt_StockInfoDetail>((stock, detail) => stock.Id == detail.StockId).Where((stock, detail) => stock.PalletCode == item.LPNNo && stock.LocationCode == item.LocationCode).First();
-                        Dt_OutboundOrderDetail outboundOrderDetail = new Dt_OutboundOrderDetail();
-                        Dt_OutboundOrder outboundOrder = new Dt_OutboundOrder();
-                        if (stockInfo == null)
-                        {
-                            Dt_Warehouse warehouse = _warehouseService.Repository.QueryData(x => x.WarehouseCode == item.WarehouseCode).FirstOrDefault();
-                            if (warehouse == null)
-                            {
-                                return WebResponseContent.Instance.Error($"璇ヤ粨搴撶紪鍙穥item.WarehouseCode}鏈厤缃�");
-                            }
-                            Dt_StockInfoDetail stockInfoDetail = new Dt_StockInfoDetail
-                            {
-                                MaterielCode = item.MaterielCode,
-                                MaterielName = item.MaterielName,
-                                MaterieSpec = item.MaterieSpec,
-                                BatchNo = item.BatchNo,
-                                LinId = item.LinId,
-                                Status = StockStatusEmun.缁勭洏鏆傚瓨.ObjToInt(),
+                                OrderStatus = InOrderStatusEnum.鏈紑濮�.ObjToInt(),
                                 Creater = "SMOM",
-                                CreateDate = DateTime.Now,
-                                OrderNo = newReturnOrder.OrderNo,
-                                StockQuantity = item.OrderQuantity,
+                                CreateDate = DateTime.Now
                             };
-                            Dt_StockInfo stockInfo1 = new Dt_StockInfo
-                            {
-                                PalletCode = item.LPNNo,
-                                WarehouseId = warehouse.WarehouseId,
-                                BatchNo = item.BatchNo,
-                                PalletType = GetPalletType(warehouse, item.LPNNo),
-                                IsFull = true,
-                                StockStatus = (int)StockStatusEmun.鍙嶆嫞鍏ュ簱,
-                                Creater = "WMS",
-                                CreateDate = DateTime.Now,
-                                MaterialType = (int)InventoryMaterialType.鍘熸潗鏂�,
-                                Materialweight = 0,
-                                Wlstatus = (int)InventoryMaterialStatus.鍚堟牸,
-                                Mgeneratetime = DateTime.Now,
-                                Details = new List<Dt_StockInfoDetail> { stockInfoDetail }
-                            };
-                            Db.InsertNav(stockInfo1).Include(x => x.Details).ExecuteCommand();
+                            _returnOrderRepository.AddData(newReturnOrder);
+                        Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo, Dt_StockInfoDetail>((stock, detail) => stock.Id == detail.StockId).Where((stock, detail) => stock.PalletCode == item.LPNNo && stock.LocationCode == item.LocationCode).First();
+                                Dt_OutboundOrderDetail outboundOrderDetail = new Dt_OutboundOrderDetail();
+                                Dt_OutboundOrder outboundOrder = new Dt_OutboundOrder();
+                                if (stockInfo == null)
+                                {
+                            Dt_Warehouse warehouse = _warehouseService.Repository.QueryData(x => x.WarehouseCode == item.WarehouseCode).FirstOrDefault();
+                                    if (warehouse == null)
+                                    {
+                                return WebResponseContent.Instance.Error($"璇ヤ粨搴撶紪鍙穥item.WarehouseCode}鏈厤缃�");
+                                    }
+                                    Dt_StockInfoDetail stockInfoDetail = new Dt_StockInfoDetail
+                                    {
+                                        MaterielCode = item.MaterielCode,
+                                        MaterielName = item.MaterielName,
+                                MaterieSpec = item.MaterieSpec,
+                                        BatchNo = item.BatchNo,
+                                        LinId = item.LinId,
+                                        Status = StockStatusEmun.缁勭洏鏆傚瓨.ObjToInt(),
+                                        Creater = "SMOM",
+                                        CreateDate = DateTime.Now,
+                                        OrderNo = newReturnOrder.OrderNo,
+                                        StockQuantity = item.OrderQuantity,
+                                    };
+                                    Dt_StockInfo stockInfo1 = new Dt_StockInfo
+                                    {
+                                        PalletCode = item.LPNNo,
+                                        WarehouseId = warehouse.WarehouseId,
+                                        BatchNo = item.BatchNo,
+                                        PalletType = GetPalletType(warehouse, item.LPNNo),
+                                        IsFull = true,
+                                        StockStatus = (int)StockStatusEmun.鍙嶆嫞鍏ュ簱,
+                                        Creater = "WMS",
+                                        CreateDate = DateTime.Now,
+                                        MaterialType = (int)InventoryMaterialType.鍘熸潗鏂�,
+                                        Materialweight = 0,
+                                        Wlstatus = (int)InventoryMaterialStatus.鍚堟牸,
+                                        Mgeneratetime = DateTime.Now,
+                                        Details = new List<Dt_StockInfoDetail> { stockInfoDetail }
+                                    };
+                                    Db.InsertNav(stockInfo1).Include(x => x.Details).ExecuteCommand();
+                                }
+                                else
+                                {
+                                    outboundOrderDetail = new Dt_OutboundOrderDetail
+                                    {
+                                        MaterielCode = item.MaterielCode,
+                                        MaterielName = item.MaterielName,
+                                MaterieSpec = item.MaterieSpec,
+                                        BatchNo = item.BatchNo,
+                                        OrderQuantity = stockInfo.Details.Sum(x => x.StockQuantity),
+                                Remark = item.Remark,
+                                        LinId = item.LinId,
+                                        LPNNo = item.LPNNo,
+                                        Creater = "SMOM",
+                                        CreateDate = DateTime.Now,
+                                LocationName = item.LocationCode
+                                    };
+                                    outboundOrder = new Dt_OutboundOrder
+                                    {
+                                        OrderNo = "FJCK" + $"{datePart}{randomNum}",
+                                        UpperOrderNo = "WMSFJCK" + $"{datePart}{randomNum}",
+                                        OrderStatus = OutOrderStatusEnum.鏈紑濮�.ObjToInt(),
+                                        OrderType = OrderTypeEnum.鍙嶆嫞鍑哄簱鍗�.ObjToInt(),
+                                        InoutType = InoutTypeEnum.OtherOut.ToString(),
+                                System = item.System,
+                                        Creater = "SMOM",
+                                        CreateDate = DateTime.Now,
+                                        CreateType = OrderCreateTypeEnum.UpperSystemPush.ObjToInt(),
+                                        Details = new List<Dt_OutboundOrderDetail> { outboundOrderDetail }
+                                    };
+                                    Db.InsertNav(outboundOrder).Include(x => x.Details).ExecuteCommand();
+                                }
+
                         }
                         else
                         {
-                            outboundOrderDetail = new Dt_OutboundOrderDetail
-                            {
-                                MaterielCode = item.MaterielCode,
-                                MaterielName = item.MaterielName,
-                                MaterieSpec = item.MaterieSpec,
-                                BatchNo = item.BatchNo,
-                                OrderQuantity = stockInfo.Details.Sum(x => x.StockQuantity),
-                                Remark = item.Remark,
-                                LinId = item.LinId,
-                                LPNNo = item.LPNNo,
-                                Creater = "SMOM",
-                                CreateDate = DateTime.Now,
-                                LocationName = item.LocationCode
-                            };
-                            outboundOrder = new Dt_OutboundOrder
-                            {
-                                OrderNo = "FJCK" + $"{datePart}{randomNum}",
-                                UpperOrderNo = "WMSFJCK" + $"{datePart}{randomNum}",
-                                OrderStatus = OutOrderStatusEnum.鏈紑濮�.ObjToInt(),
-                                OrderType = OrderTypeEnum.鍙嶆嫞鍑哄簱鍗�.ObjToInt(),
-                                InoutType = InoutTypeEnum.OtherOut.ToString(),
-                                System = item.System,
-                                Creater = "SMOM",
-                                CreateDate = DateTime.Now,
-                                CreateType = OrderCreateTypeEnum.UpperSystemPush.ObjToInt(),
-                                Details = new List<Dt_OutboundOrderDetail> { outboundOrderDetail }
-                            };
-                            Db.InsertNav(outboundOrder).Include(x => x.Details).ExecuteCommand();
-                        }
-
-                    }
-                    else
-                    {
-                        Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo, Dt_StockInfoDetail>((stock, detail) => stock.Id == detail.StockId).Where((stock, detail) => stock.PalletCode == item.LPNNo && stock.StockStatus == StockStatusEmun.浣欐枡閫�搴�.ObjToInt()).First();
-                        stockInfo.StockStatus = StockStatusEmun.鍙嶆嫞鍏ュ簱.ObjToInt();
-                        returnOrder.LinId = item.LinId;
+                            Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo, Dt_StockInfoDetail>((stock, detail) => stock.Id == detail.StockId).Where((stock, detail) => stock.PalletCode == item.LPNNo && stock.StockStatus == StockStatusEmun.浣欐枡閫�搴�.ObjToInt()).First();
+                            stockInfo.StockStatus = StockStatusEmun.鍙嶆嫞鍏ュ簱.ObjToInt();
+                            returnOrder.LinId = item.LinId;
                         returnOrder.System = item.System;
                         returnOrder.WarehouseCode = item.WarehouseCode;
                         returnOrder.LocationCode = item.LocationCode;
-                        returnOrder.OrderType = OrderTypeEnum.鍙嶆嫞鍥炲簱鍗�.ObjToInt();
-                        returnOrder.OrderQuantity += item.OrderQuantity;
-                        returnOrder.ReceiptQuantity += item.OrderQuantity;
-                        _returnOrderRepository.UpdateData(returnOrder);
-                        _stockRepository.StockInfoRepository.UpdateData(stockInfo);
+                            returnOrder.OrderType = OrderTypeEnum.鍙嶆嫞鍥炲簱鍗�.ObjToInt();
+                            returnOrder.OrderQuantity += item.OrderQuantity;
+                            returnOrder.ReceiptQuantity += item.OrderQuantity;
+                            _returnOrderRepository.UpdateData(returnOrder);
+                            _stockRepository.StockInfoRepository.UpdateData(stockInfo);
 
-                    }
+                        }
                 }
                 _unitOfWorkManage.CommitTran();
                 return WebResponseContent.Instance.OK();

--
Gitblit v1.9.3