From efaf0b8aeb26aca6536a4b384c912cc3cac4d070 Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期六, 15 三月 2025 16:07:45 +0800
Subject: [PATCH] 成品代码,其他仓优化,前端优化界面增加

---
 代码管理/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/ProOutOrderDetailService.cs |  151 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 149 insertions(+), 2 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/ProOutOrderDetailService.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/ProOutOrderDetailService.cs"
index dd8108e..1941997 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/ProOutOrderDetailService.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/ProOutOrderDetailService.cs"
@@ -3,10 +3,16 @@
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using WIDESEA_Common.LocationEnum;
+using WIDESEA_Core;
 using WIDESEA_Core.BaseRepository;
 using WIDESEA_Core.BaseServices;
+using WIDESEA_Core.Helper;
+using WIDESEA_IBasicService;
 using WIDESEA_IOutboundRepository;
 using WIDESEA_IOutboundService;
+using WIDESEA_IRecordService;
+using WIDESEA_IStockService;
 using WIDESEA_Model.Models;
 
 namespace WIDESEA_OutboundService
@@ -16,10 +22,151 @@
         private readonly IUnitOfWorkManage _unitOfWorkManage;
 
         public IProOutOrderDetailRepository Repository => BaseDal;
-
-        public ProOutOrderDetailService(IProOutOrderDetailRepository BaseDal, IUnitOfWorkManage unitOfWorkManage) : base(BaseDal)
+        private readonly IStockService _stockInfoService;
+        private readonly IBasicService _basicService;
+        private readonly IOutProStockInfoService _outProStockInfoService;
+        private readonly IRecordService _recordService;
+        public ProOutOrderDetailService(IProOutOrderDetailRepository BaseDal, IUnitOfWorkManage unitOfWorkManage, IStockService stockInfoService, IBasicService basicService,IOutProStockInfoService outProStockInfoService, IRecordService recordService) : base(BaseDal)
         {
             _unitOfWorkManage = unitOfWorkManage;
+            _stockInfoService = stockInfoService;
+            _basicService = basicService;
+            _outProStockInfoService = outProStockInfoService;
+            _recordService = recordService;
+        }
+        /// <summary>
+        /// 鍑哄簱搴撳瓨鍒嗛厤鍚庯紝鏇存柊鏁版嵁搴撴暟鎹�
+        /// </summary>
+        public WebResponseContent LockOutboundStockDataUpdate(List<Dt_ProStockInfo> proStockInfos, List<Dt_ProOutOrderDetail> proOutOrderDetails, List<Dt_OutProStockInfo> outProStockInfos, List<Dt_LocationInfo> locationInfos, LocationStatusEnum locationStatus = LocationStatusEnum.Lock, List<Dt_Task>? tasks = null)
+        {
+            try
+            {
+                _stockInfoService.ProStockInfoService.Repository.UpdateData(proStockInfos);
+                List<Dt_ProStockInfoDetail> proStockInfoDetails = new List<Dt_ProStockInfoDetail>();
+                foreach (var item in proStockInfos)
+                {
+                    proStockInfoDetails.AddRange(item.proStockInfoDetails);
+                }
+                _stockInfoService.ProStockInfoDetailService.Repository.UpdateData(proStockInfoDetails);
+                BaseDal.UpdateData(proOutOrderDetails);
+
+                List<Dt_OutProStockInfo> addOutStockLockInfos = outProStockInfos.Where(x => x.Id == 0).ToList();
+                if (addOutStockLockInfos != null && addOutStockLockInfos.Any())
+                {
+                    if (tasks != null)
+                    {
+                        addOutStockLockInfos.ForEach(x =>
+                        {
+                            x.TaskNum = tasks.FirstOrDefault(v => v.PalletCode == x.PalletCode)?.TaskNum;
+                        });
+                    }
+
+                    _outProStockInfoService.Repository.AddData(addOutStockLockInfos);
+                }
+                List<Dt_OutProStockInfo> updateOutStockLockInfos = outProStockInfos.Where(x => x.Id > 0).ToList();
+                if (updateOutStockLockInfos != null && updateOutStockLockInfos.Any())
+                {
+                    _outProStockInfoService.Repository.UpdateData(updateOutStockLockInfos);
+                }
+
+                _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfos, locationStatus, LocationChangeType.OutboundAssignLocation, "", tasks?.Select(x => x.TaskNum).ToList());
+                _basicService.LocationInfoService.Repository.UpdateLocationStatus(locationInfos, locationStatus);
+                return WebResponseContent.Instance.OK();
+            }
+            catch (Exception ex)
+            {
+                return WebResponseContent.Instance.Error(ex.Message);
+            }
+        }
+        /// <summary>
+        /// 鍒嗛厤搴撳瓨澶勭悊璐т綅鏁版嵁
+        /// </summary>
+        public (List<Dt_ProStockInfo>, List<Dt_ProOutOrderDetail>, List<Dt_OutProStockInfo>, List<Dt_LocationInfo>) AssignProStockOut(int warehouseId, Dt_ProOutOrder proOutOrder)
+        {
+            List<Dt_ProOutOrderDetail> OutOrderDetails = proOutOrder.Details;
+            if (!OutOrderDetails.Any())
+            {
+                throw new Exception($"鏈壘鍒板嚭搴撳崟鏄庣粏淇℃伅");
+            }
+            List<Dt_ProStockInfo> outStocks = new List<Dt_ProStockInfo>();
+            List<Dt_OutProStockInfo> outProStockInfos = new List<Dt_OutProStockInfo>();
+            List<Dt_LocationInfo> locationInfos = new List<Dt_LocationInfo>();
+            List<Dt_ProOutOrderDetail> groupDetails = OutOrderDetails.GroupBy(x => new { x.SaleOrder, x.PCode, x.PVer, x.PLot, x.DateCode }).Select(x => new Dt_ProOutOrderDetail()
+            {
+                QtyPcs = x.Sum(x => x.QtyPcs) - x.Sum(x => x.OverQtyPcs),
+                SaleOrder = x.Key.SaleOrder,
+                PCode = x.Key.PCode,
+                PVer = x.Key.PVer,
+                PLot = x.Key.PLot,
+                DateCode = x.Key.DateCode,
+            }).ToList();
+            foreach (var item in groupDetails)
+            {
+                float needQty = item.QtyPcs;
+                //鏌ユ壘鍙敤搴撳瓨
+                List<Dt_ProStockInfo> stockInfoss = _stockInfoService.ProStockInfoService.GetUseableStocks(warehouseId, item);
+                if (!stockInfoss.Any())
+                {
+                    throw new Exception("鏈壘鍒板彲鍒嗛厤搴撳瓨");
+                }
+                //鑾峰彇鍑哄簱搴撳瓨
+                List<Dt_ProStockInfo> assignOutStocks = _stockInfoService.ProStockInfoService.GetOutboundStocks(stockInfoss, item, needQty, out float residueQuantity);
+                item.LockQtyPcs += needQty - residueQuantity;
+                outStocks.AddRange(assignOutStocks);
+                float assignQuantity = needQty - residueQuantity;
+                bool isCanLot = !string.IsNullOrEmpty(item.PLot);
+                bool isCanDate = !string.IsNullOrEmpty(item.DateCode);
+                List<Dt_ProOutOrderDetail> details = OutOrderDetails
+                    .Where(x => x.SaleOrder == item.SaleOrder && x.PCode == item.PCode && x.PVer == item.PVer
+                    && (isCanLot ? x.PLot == item.PLot : true)
+                    && (isCanDate ? x.DateCode == item.DateCode : true))
+                    .ToList();
+
+                for (int i = 0; i < details.Count; i++)
+                {
+                    float orderQuantity = details[i].QtyPcs;
+                    for (int j = 0; j < assignOutStocks.Count; j++)
+                    {
+                        float detailAssignQuantity = outProStockInfos.Where(x => x.SaleOrder == item.SaleOrder && x.PCode == item.PCode && x.PVer == item.PVer
+                            && (item.PLot.IsNotEmptyOrNull() ? x.PLot == item.PLot : false)
+                            && (item.DateCode.IsNotEmptyOrNull() ? x.DateCode == item.PLot : false) 
+                            && x.OrderDetailId == details[i].Id).Sum(x => x.AssignQuantity);//鍑哄簱璁㈠崟鏄庣粏宸插垎閰嶆暟閲�
+
+                        float palletAssignQuantity = outProStockInfos.Where(x => x.SaleOrder == item.SaleOrder && x.PCode == item.PCode && x.PVer == item.PVer
+                            && (item.PLot.IsNotEmptyOrNull() ? x.PLot == item.PLot : false)
+                            && (item.DateCode.IsNotEmptyOrNull() ? x.DateCode == item.PLot : false 
+                            && x.PalletCode == assignOutStocks[j].PalletCode)).Sum(x => x.AssignQuantity);
+                        //鍑哄簱璇︽儏宸插垎閰嶆暟閲�
+                        palletAssignQuantity = outProStockInfos.Where(x => x.SaleOrder == item.SaleOrder && x.PCode == item.PCode && x.PVer == item.PVer
+                            && (item.PLot.IsNotEmptyOrNull() ? x.PLot == item.PLot : false)
+                            && (item.DateCode.IsNotEmptyOrNull() ? x.DateCode == item.PLot : false && x.PalletCode == assignOutStocks[j].PalletCode)).Sum(x => x.AssignQuantity);//鍑哄簱璇︽儏宸插垎閰嶆暟閲�
+                        float palletOutboundQuantity = assignOutStocks[j].proStockInfoDetails.Sum(x => x.OutboundQuantity);
+                        if (palletAssignQuantity < palletOutboundQuantity)//濡傛灉鍑哄簱璇︽儏宸插垎閰嶆暟閲忓皬浜庢墭鐩樺凡鍒嗛厤鏁伴噺锛屽垯鍙互缁х画娣诲姞璇ユ墭鐩樺嚭搴撲俊鎭�
+                        {
+                            float orderDetailNeedQuantity = details[i].QtyPcs - detailAssignQuantity;
+                            if (orderDetailNeedQuantity > assignOutStocks[j].proStockInfoDetails.Sum(x => x.OutboundQuantity) - palletAssignQuantity)
+                            {
+                                details[i].LockQtyPcs += assignOutStocks[j].proStockInfoDetails.Sum(x => x.OutboundQuantity) - palletAssignQuantity;
+                                Dt_OutProStockInfo outStockLockInfo = _outProStockInfoService.GetOutStockLockInfo(proOutOrder, details[i], assignOutStocks[j], assignOutStocks[j].proStockInfoDetails.Sum(x => x.OutboundQuantity) - palletAssignQuantity);
+                                outProStockInfos.Add(outStockLockInfo);
+                            }
+                            else
+                            {
+                                Dt_OutProStockInfo outStockLockInfo = _outProStockInfoService.GetOutStockLockInfo(proOutOrder, details[i], assignOutStocks[j], details[i].QtyPcs - details[i].LockQtyPcs);
+                                outProStockInfos.Add(outStockLockInfo);
+                                details[i].LockQtyPcs = details[i].QtyPcs;
+                                break;
+                            }
+
+                        }
+                    }
+                }
+                List<string> locationArr = outStocks.Select(x => x.LocationCode).ToList();
+
+                locationInfos.AddRange(_basicService.LocationInfoService.Repository.GetLocationInfos(locationArr));
+
+            }
+            return (outStocks, OutOrderDetails, outProStockInfos, locationInfos);
         }
     }
 }

--
Gitblit v1.9.3