From fcb50f9e6408bf42e3bc5d34d9f6eff93c2dd263 Mon Sep 17 00:00:00 2001 From: wankeda <Administrator@DESKTOP-HAU3ST3> Date: 星期六, 01 三月 2025 17:36:16 +0800 Subject: [PATCH] 1 --- 代码管理/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/MesPPOutboundOrderDetailService.cs | 179 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 178 insertions(+), 1 deletions(-) diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/MesPPOutboundOrderDetailService.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/MesPPOutboundOrderDetailService.cs" index d1b593f..2f8ea48 100644 --- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/MesPPOutboundOrderDetailService.cs" +++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/MesPPOutboundOrderDetailService.cs" @@ -3,6 +3,8 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using WIDESEA_Common.LocationEnum; +using WIDESEA_Core; using WIDESEA_Core.BaseServices; using WIDESEA_IBasicRepository; using WIDESEA_IBasicService; @@ -22,16 +24,191 @@ private readonly IOutStockLockInfoService _outStockLockInfoService; private readonly IBasicService _basicService; private readonly IRecordService _recordService; + private readonly IOutboundService _outboundService; public IMesPPOutboundOrderDetailRepository Repository => BaseDal; - public MesPPOutboundOrderDetailService(IMesPPOutboundOrderDetailRepository BaseDal, IBasicRepository basicRepository, IStockService stockService, IOutStockLockInfoService outStockLockInfoService, IBasicService basicService, IRecordService recordService) : base(BaseDal) + public MesPPOutboundOrderDetailService(IMesPPOutboundOrderDetailRepository BaseDal, IBasicRepository basicRepository, IOutboundService outboundService, IStockService stockService, IOutStockLockInfoService outStockLockInfoService, IBasicService basicService, IRecordService recordService) : base(BaseDal) { _basicRepository = basicRepository; _stockService = stockService; _outStockLockInfoService = outStockLockInfoService; _basicService = basicService; _recordService = recordService; + _outboundService = outboundService; + } + + /// <summary> + /// 鍑哄簱搴撳瓨鍒嗛厤鍚庯紝鏇存柊鏁版嵁搴撴暟鎹� + /// </summary> + /// <param name="stockInfos"></param> + /// <param name="outboundOrderDetails"></param> + /// <param name="outStockLockInfos"></param> + /// <param name="locationInfos"></param> + /// <param name="locationStatus"></param> + /// <param name="tasks"></param> + /// <returns></returns> + public WebResponseContent LockOutboundStockDataUpdate(List<Dt_StockInfo> stockInfos, List<Dt_MesPPOutboundOrderDetail> outboundOrderDetails, List<Dt_OutStockLockInfo> outStockLockInfos, List<Dt_LocationInfo> locationInfos, LocationStatusEnum locationStatus = LocationStatusEnum.Lock, List<Dt_Task>? tasks = null) + { + try + { + _stockService.StockInfoService.Repository.UpdateData(stockInfos); + List<Dt_StockInfoDetail> stockInfoDetails = new List<Dt_StockInfoDetail>(); + foreach (var item in stockInfos) + { + stockInfoDetails.AddRange(item.Details); + } + _stockService.StockInfoDetailService.Repository.UpdateData(stockInfoDetails); + BaseDal.UpdateData(outboundOrderDetails); + + List<Dt_OutStockLockInfo> addOutStockLockInfos = outStockLockInfos.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; + }); + } + + _outStockLockInfoService.Repository.AddData(addOutStockLockInfos); + } + List<Dt_OutStockLockInfo> updateOutStockLockInfos = outStockLockInfos.Where(x => x.Id > 0).ToList(); + if (updateOutStockLockInfos != null && updateOutStockLockInfos.Any()) + { + _outStockLockInfoService.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> + /// <param name="outboundOrderDetails"></param> + /// <returns></returns> + public (List<Dt_StockInfo>, List<Dt_MesPPOutboundOrderDetail>, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>) AssignStockOutbound(List<Dt_MesPPOutboundOrderDetail> outboundOrderDetails) + { + if (!outboundOrderDetails.Any()) + { + throw new Exception($"鏈壘鍒板嚭搴撳崟鏄庣粏淇℃伅"); + } + + if (outboundOrderDetails.GroupBy(x => x.OrderId).Count() > 1) + { + throw new Exception($"璇峰嬁鍚屾椂鎿嶄綔澶氫釜鍗曟嵁鏄庣粏"); + } + Dt_MesPPOutboundOrder mesPPOutboundOrder = BaseDal.Db.Queryable<Dt_MesPPOutboundOrder>().Where(x => x.Id == outboundOrderDetails.FirstOrDefault().OrderId).First(); + List<Dt_StockInfo> outStocks = new List<Dt_StockInfo>(); + + List<Dt_OutStockLockInfo> outStockLockInfos = new List<Dt_OutStockLockInfo>(); + List<Dt_LocationInfo> locationInfos = new List<Dt_LocationInfo>(); + + + List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.GetUseableStocks(mesPPOutboundOrder.MaterialCode, "", outboundOrderDetails.FirstOrDefault()?.CarrierCode ?? "", mesPPOutboundOrder.WarehouseId); + if (!stockInfos.Any()) + { + throw new Exception($"鏈壘鍒板彲鍒嗛厤搴撳瓨"); + } + float originalNeedQuantity = mesPPOutboundOrder.OrderQuantity; + + float needQuantity = originalNeedQuantity; + List<Dt_StockInfo> autoAssignStocks = _stockService.StockInfoService.GetOutboundStocks(stockInfos, mesPPOutboundOrder.MaterialCode, needQuantity, out float residueQuantity); + mesPPOutboundOrder.LockQuantity += needQuantity - residueQuantity; + outStocks.AddRange(autoAssignStocks); + float assignQuantity = needQuantity - residueQuantity; + + float orderQuantity = mesPPOutboundOrder.OrderQuantity; + for (int j = 0; j < autoAssignStocks.Count; j++) + { + float detailAssignQuantity = outStockLockInfos.Where(x => x.MaterielCode == mesPPOutboundOrder.MaterialCode).Sum(x => x.AssignQuantity);//鍑哄簱璁㈠崟鏄庣粏宸插垎閰嶆暟閲� + + float palletAssignQuantity = outStockLockInfos.Where(x => x.MaterielCode == mesPPOutboundOrder.MaterialCode && x.PalletCode == autoAssignStocks[j].PalletCode).Sum(x => x.AssignQuantity);//鍑哄簱璇︽儏宸插垎閰嶆暟閲� + + float palletOutboundQuantity = autoAssignStocks[j].Details.Sum(x => x.OutboundQuantity); + if (palletAssignQuantity < palletOutboundQuantity)//濡傛灉鍑哄簱璇︽儏宸插垎閰嶆暟閲忓皬浜庢墭鐩樺凡鍒嗛厤鏁伴噺锛屽垯鍙互缁х画娣诲姞璇ユ墭鐩樺嚭搴撲俊鎭� + { + float orderDetailNeedQuantity = mesPPOutboundOrder.OrderQuantity - detailAssignQuantity; + if (orderDetailNeedQuantity > autoAssignStocks[j].Details.Sum(x => x.OutboundQuantity) - palletAssignQuantity) + { + mesPPOutboundOrder.LockQuantity += autoAssignStocks[j].Details.Sum(x => x.OutboundQuantity) - palletAssignQuantity; + Dt_OutStockLockInfo outStockLockInfo = _outStockLockInfoService.GetOutStockLockInfo(mesPPOutboundOrder, autoAssignStocks[j], autoAssignStocks[j].Details.Sum(x => x.OutboundQuantity) - palletAssignQuantity); + outStockLockInfos.Add(outStockLockInfo); + } + else + { + Dt_OutStockLockInfo outStockLockInfo = _outStockLockInfoService.GetOutStockLockInfo(mesPPOutboundOrder, autoAssignStocks[j], mesPPOutboundOrder.OrderQuantity - mesPPOutboundOrder.LockQuantity); + outStockLockInfos.Add(outStockLockInfo); + mesPPOutboundOrder.LockQuantity = mesPPOutboundOrder.OrderQuantity; + break; + } + } + } + locationInfos.AddRange(_basicService.LocationInfoService.Repository.GetLocationInfos(outStocks.Select(x => x.LocationCode).ToList())); + + return (outStocks, outboundOrderDetails, outStockLockInfos, locationInfos); + } + + + public (List<Dt_StockInfo>, Dt_MesPPOutboundOrderDetail, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>) AssignStockOutbound(Dt_MesPPOutboundOrderDetail mesPPOutboundOrder) + { + List<Dt_StockInfo> outStocks = new List<Dt_StockInfo>(); + + List<Dt_OutStockLockInfo> outStockLockInfos = new List<Dt_OutStockLockInfo>(); + List<Dt_LocationInfo> locationInfos = new List<Dt_LocationInfo>(); + + //float originalNeedQuantity = mesPPOutboundOrder.OrderQuantity; + + //float needQuantity = originalNeedQuantity; + + //List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.GetUseableStocks(mesPPOutboundOrder.MaterialCode, "", mesPPOutboundOrder.Details.FirstOrDefault()?.CarrierCode ?? "", mesPPOutboundOrder.WarehouseId); + //if (!stockInfos.Any()) + //{ + // throw new Exception($"鏈壘鍒板彲鍒嗛厤搴撳瓨"); + //} + //List<Dt_StockInfo> autoAssignStocks = _stockService.StockInfoService.GetOutboundStocks(stockInfos, mesPPOutboundOrder.MaterialCode, needQuantity, out float residueQuantity); + //mesPPOutboundOrder.LockQuantity += needQuantity - residueQuantity; + //outStocks.AddRange(autoAssignStocks); + //float assignQuantity = needQuantity - residueQuantity; + + //float orderQuantity = mesPPOutboundOrder.OrderQuantity; + //for (int j = 0; j < autoAssignStocks.Count; j++) + //{ + // float detailAssignQuantity = outStockLockInfos.Where(x => x.MaterielCode == mesPPOutboundOrder.MaterialCode).Sum(x => x.AssignQuantity);//鍑哄簱璁㈠崟鏄庣粏宸插垎閰嶆暟閲� + + // float palletAssignQuantity = outStockLockInfos.Where(x => x.MaterielCode == mesPPOutboundOrder.MaterialCode && x.PalletCode == autoAssignStocks[j].PalletCode).Sum(x => x.AssignQuantity);//鍑哄簱璇︽儏宸插垎閰嶆暟閲� + + // float palletOutboundQuantity = autoAssignStocks[j].Details.Sum(x => x.OutboundQuantity); + // if (palletAssignQuantity < palletOutboundQuantity)//濡傛灉鍑哄簱璇︽儏宸插垎閰嶆暟閲忓皬浜庢墭鐩樺凡鍒嗛厤鏁伴噺锛屽垯鍙互缁х画娣诲姞璇ユ墭鐩樺嚭搴撲俊鎭� + // { + // float orderDetailNeedQuantity = mesPPOutboundOrder.OrderQuantity - detailAssignQuantity; + // if (orderDetailNeedQuantity > autoAssignStocks[j].Details.Sum(x => x.OutboundQuantity) - palletAssignQuantity) + // { + // mesPPOutboundOrder.LockQuantity += autoAssignStocks[j].Details.Sum(x => x.OutboundQuantity) - palletAssignQuantity; + // Dt_OutStockLockInfo outStockLockInfo = _outStockLockInfoService.GetOutStockLockInfo(mesPPOutboundOrder, autoAssignStocks[j], autoAssignStocks[j].Details.Sum(x => x.OutboundQuantity) - palletAssignQuantity); + // outStockLockInfos.Add(outStockLockInfo); + // } + // else + // { + // Dt_OutStockLockInfo outStockLockInfo = _outStockLockInfoService.GetOutStockLockInfo(mesPPOutboundOrder, autoAssignStocks[j], mesPPOutboundOrder.OrderQuantity - mesPPOutboundOrder.LockQuantity); + // outStockLockInfos.Add(outStockLockInfo); + // mesPPOutboundOrder.LockQuantity = mesPPOutboundOrder.OrderQuantity; + // break; + // } + // } + //} + //locationInfos.AddRange(_basicService.LocationInfoService.Repository.GetLocationInfos(outStocks.Select(x => x.LocationCode).ToList())); + + return (outStocks, mesPPOutboundOrder, outStockLockInfos, locationInfos); } } } -- Gitblit v1.9.3