| | |
| | | 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; |
| | |
| | | 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); |
| | | } |
| | | } |
| | | } |