From 57148c2264abe80bd3b472f2980104d90dad5c61 Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期六, 13 九月 2025 08:35:32 +0800
Subject: [PATCH] 合并,接口优化等

---
 代码管理/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/ProOutOrderService.cs |   73 ++++++++++++++++++++++++++----------
 1 files changed, 53 insertions(+), 20 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/ProOutOrderService.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/ProOutOrderService.cs"
index 662402c..696e8d3 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/ProOutOrderService.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/ProOutOrderService.cs"
@@ -1,5 +1,6 @@
 锘縰sing AutoMapper;
 using Castle.Core.Resource;
+using Org.BouncyCastle.Asn1.Cmp;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -94,7 +95,7 @@
                 }
                 else if (outOrderDTO.OType==2)
                 {
-                    warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA101.ToString());
+                    warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA71.ToString());
                 }
                 List<Dt_ProOutOrderDetail> proOutOrderDetails = new List<Dt_ProOutOrderDetail>();
                 Dictionary<string,string> keyValuePairs =new Dictionary<string, string>();
@@ -106,18 +107,31 @@
                     {
                         return content.Error($"瀹㈡埛{item.Customer}涓嶅瓨鍦�!");
                     }
+                    //瀵勫敭鍗曟嵁
+                    if (outOrderDTO.OType == 2)
+                    {
+                        Dt_ProOutOrderDetail? ExistProDetail = proOutOrderDetails.FirstOrDefault(x => x.PCode == item.PCode && x.SaleOrder == item.SaleOrder && x.PVer == item.PVer && x.DateCode == item.DateCode);
+                        if (ExistProDetail!=null)
+                        {
+                            Dt_ProOutOrderDetail OutOrderDetail = _mapper.Map<Dt_ProOutOrderDetail>(item);
+                            ExistProDetail.QtyPcs += (OutOrderDetail.QtyPcs + OutOrderDetail.SpareQty);
+                            ExistProDetail.SpareQty += OutOrderDetail.SpareQty;
+                            continue;
+                        }
+                    }
+                    
                     Dt_ProOutOrderDetail proOutOrderDetail = _mapper.Map<Dt_ProOutOrderDetail>(item);
                     if (!string.IsNullOrEmpty(item.SaleOrder))
                     {
-                        if (keyValuePairs!=null && keyValuePairs.ContainsKey(item.SaleOrder))
+                        if (keyValuePairs != null && keyValuePairs.ContainsKey(item.SaleOrder))
                         {
                             proOutOrderDetail.EndCustomer = keyValuePairs[item.SaleOrder];
                         }
                         else
                         {
                             string request = _invokeERPService.InvokeProSaleCustomer(item.SaleOrder);
-                            ErpSaleCustomResponseContent responseContent=request.DeserializeObject<ErpSaleCustomResponseContent>();
-                            if (responseContent.Code!=200)
+                            ErpSaleCustomResponseContent responseContent = request.DeserializeObject<ErpSaleCustomResponseContent>();
+                            if (responseContent.Code != 200)
                             {
                                 return content.Error($"璁㈠崟{item.SaleOrder}缁堢瀹㈡埛鑾峰彇澶辫触!");
                             }
@@ -764,19 +778,14 @@
                 .Select((master, detail) => detail)
                 .ToList();
                 proStockInfoDetails = proStockInfoDetails.OrderBy(x => x.DateCode).ThenBy(x => x.CreateDate).ToList();
-
+                List<int> stockIds = proStockInfoDetails.Select(x => x.ProStockId).Distinct().ToList();
+                //鑾峰彇鎵�鏈夊钩搴撲富琛�
+                List<Dt_ProStockInfo> proStockInfos = _stockRepository.ProStockInfoRepository.Db.Queryable<Dt_ProStockInfo>().Where(x => stockIds.Contains(x.Id)).Includes(x => x.proStockInfoDetails).ToList();
                 List<Dt_ProStockInfo> delProStockInfos = new List<Dt_ProStockInfo>();
                 List<Dt_ProStockInfoDetail> delStockInfoDetails = new List<Dt_ProStockInfoDetail>();
                 foreach (var item in outProStocks)
                 {
-                    
-                    //鑾峰彇搴撳瓨
-                    List<Dt_ProStockInfoDetail> outStocks = proStockInfoDetails.Where(x=>x.ProductCode==item.Partnum).ToList();
-                    if (outStocks.Count==0 || outStocks==null)
-                    {
-                        return content.Error($"{item.Partnum}浜у搧鍨嬪彿搴撳瓨涓嶅瓨鍦�");
-                    }
-                    foreach (var itemOut in outStocks)
+                    foreach (var itemOut in proStockInfoDetails.Where(x => x.ProductCode == item.Partnum).ToList())
                     {
                         if (item.Quantity==0)
                         {
@@ -808,10 +817,20 @@
                             
                             //鏇存柊鍑哄簱鏄庣粏鍗曟暟閲�
                             proOutOrderDetail.OverQtyPcs += item.Quantity;
-                            item.Quantity -= item.Quantity;
-                            float Range = itemOut.StockPcsQty / itemOut.SETQty;
-                            itemOut.SETQty = item.Quantity / Range;
+                            int Range = (int)itemOut.StockPcsQty / (int)itemOut.SETQty;
+                            if (Range == 0)
+                            {
+                                return content.Error($"{itemOut.BagNo}鍗曞厓鏁伴噺杞崲澶辫触,璇锋鏌�,Range:{Range}");
+                            }
+                            int outSet =item.Quantity / Range;
+                            if (outSet == 0)
+                            {
+                                return content.Error($"{itemOut.BagNo}鍗曞厓鏁伴噺杞崲澶辫触,璇锋鏌�,outSet:{outSet}");
+                            }
+                            itemOut.SETQty -= outSet;
+                            
                             itemOut.StockPcsQty -= item.Quantity;
+                            item.Quantity = 0;
                             if (proOutOrderDetail.OverQtyPcs > proOutOrderDetail.QtyPcs)
                             {
                                 return content.Error($"鍑哄簱鍗晎proOutOrder.ProOutOrderNo}閿�鍞鍗晎item.SoNumber}鏁伴噺婧㈠嚭{proOutOrderDetail.OverQtyPcs - proOutOrderDetail.QtyPcs}");
@@ -826,6 +845,10 @@
                             }
                         }
                     }
+                    if (item.Quantity>0)
+                    {
+                        return content.Error($"鏈壘鍒皗item.SoNumber}鍙墸鍑忓簱瀛�");
+                    }
                 }
                 if (proOutOrder.Details.Count == proOutOrder.Details.Where(x => x.ProOrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()).Count())
                 {
@@ -836,12 +859,22 @@
                     Dt_ProOutOrderDetail? proOutOrderDetail = proOutOrder.Details.FirstOrDefault(x => x.ProOrderDetailStatus <= OrderDetailStatusEnum.Over.ObjToInt());
                     return content.Error($"{proOutOrderDetail?.SaleOrder}閿�鍞鍗曟暟閲忛渶鍑簕proOutOrderDetail?.QtyPcs},鍙嚭{proOutOrderDetail?.OverQtyPcs}");
                 }
+                //鑾峰彇鍒犻櫎鐨勫簱瀛樹富琛�
+                List<int> delStockIds = delStockInfoDetails.Select(x => x.ProStockId).Distinct().ToList();
+                List<int> delStockDetailIds = delStockInfoDetails.Select(x => x.Id).ToList();
+                foreach (var item in delStockIds)
+                {
+                    Dt_ProStockInfo proStockInfo = proStockInfos.FirstOrDefault(x => x.Id == item);
+                    Dt_ProStockInfoDetail? proStockInfoDetail = proStockInfo.proStockInfoDetails.FirstOrDefault(x => !delStockDetailIds.Contains(x.Id));
+                    if (proStockInfoDetail == null)
+                    {
+                        delProStockInfos.Add(proStockInfo);
+                    }
+                }
                 //鏇存柊鏁版嵁
                 _unitOfWorkManage.BeginTran();
-                if (delStockInfoDetails.Count > 0)
-                {
-                    _stockRepository.ProStockInfoDetailRepository.DeleteAndMoveIntoHty(delStockInfoDetails, OperateTypeEnum.鑷姩鍒犻櫎);
-                }
+                _stockRepository.ProStockInfoDetailRepository.DeleteAndMoveIntoHty(delStockInfoDetails, OperateTypeEnum.鑷姩鍒犻櫎);
+                _stockRepository.ProStockInfoRepository.DeleteAndMoveIntoHty(delProStockInfos, OperateTypeEnum.鑷姩瀹屾垚);
                 _stockRepository.ProStockInfoDetailRepository.UpdateData(proStockInfoDetails);
                 BaseDal.UpdateData(proOutOrder);
                 _outboundRepository.ProOutOrderDetailRepository.UpdateData(proOutOrder.Details);

--
Gitblit v1.9.3