|  |  |  | 
|---|
|  |  |  | private readonly IOutStockLockInfoService _outStockLockInfoService; | 
|---|
|  |  |  | private readonly IBasicService _basicService; | 
|---|
|  |  |  | private readonly IRecordService _recordService; | 
|---|
|  |  |  | private readonly IOutboundService _outboundService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private readonly IMesPPOutboundOrderService _mesPPOutboundOrderService; | 
|---|
|  |  |  | public IMesPPOutboundOrderDetailRepository Repository => BaseDal; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public MesPPOutboundOrderDetailService(IMesPPOutboundOrderDetailRepository BaseDal, IBasicRepository basicRepository, IOutboundService outboundService, IStockService stockService, IOutStockLockInfoService outStockLockInfoService, IBasicService basicService, IRecordService recordService) : base(BaseDal) | 
|---|
|  |  |  | public MesPPOutboundOrderDetailService(IMesPPOutboundOrderDetailRepository BaseDal,IMesPPOutboundOrderService mesPPOutboundOrderService ,IBasicRepository basicRepository, IStockService stockService, IOutStockLockInfoService outStockLockInfoService, IBasicService basicService, IRecordService recordService) : base(BaseDal) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | _basicRepository = basicRepository; | 
|---|
|  |  |  | _stockService = stockService; | 
|---|
|  |  |  | _outStockLockInfoService = outStockLockInfoService; | 
|---|
|  |  |  | _basicService = basicService; | 
|---|
|  |  |  | _recordService = recordService; | 
|---|
|  |  |  | _outboundService = outboundService; | 
|---|
|  |  |  | _mesPPOutboundOrderService=mesPPOutboundOrderService; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public (List<Dt_StockInfo>, List<Dt_MesPPOutboundOrderDetail>, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>, Dt_MesPPOutboundOrder  mesPPOutboundOrder) AssignStockOutbound(List<Dt_MesPPOutboundOrderDetail> mesPPOutboundOrderDetails) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | List<Dt_StockInfo> outStocks = new List<Dt_StockInfo>(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Dt_OutStockLockInfo> outStockLockInfos = new List<Dt_OutStockLockInfo>(); | 
|---|
|  |  |  | List<Dt_LocationInfo> locationInfos = new List<Dt_LocationInfo>(); | 
|---|
|  |  |  | Dt_MesPPOutboundOrder OutboundOrder = BaseDal.Db.Queryable<Dt_MesPPOutboundOrder>().Where(x => x.Id == mesPPOutboundOrderDetails.FirstOrDefault().OrderId).First(); | 
|---|
|  |  |  | float originalNeedQuantity = OutboundOrder.OrderQuantity; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | float needQuantity = originalNeedQuantity; | 
|---|
|  |  |  | //Dt_MesPPOutboundOrder outboundOrder = _outboundRepository.QueryFirst(x => x.Id == outboundOrderDetails.FirstOrDefault().OrderId); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.GetUseableStocks(OutboundOrder.MaterialCode, "", mesPPOutboundOrderDetails.FirstOrDefault()?.CarrierCode ?? "", OutboundOrder.WarehouseId); | 
|---|
|  |  |  | if (!stockInfos.Any()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | throw new Exception($"æªæ¾å°å¯åé
åºå"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<Dt_StockInfo> autoAssignStocks = _stockService.StockInfoService.GetOutboundStocks(stockInfos, OutboundOrder.MaterialCode, needQuantity, out float residueQuantity); | 
|---|
|  |  |  | OutboundOrder.LockQuantity += needQuantity - residueQuantity; | 
|---|
|  |  |  | autoAssignStocks.OrderBy(x => x.Details.FirstOrDefault()?.StockQuantity).ToList(); | 
|---|
|  |  |  | outStocks.AddRange(autoAssignStocks); | 
|---|
|  |  |  | float assignQuantity = needQuantity - residueQuantity; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | float orderQuantity = OutboundOrder.OrderQuantity; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (int j = 0; j < autoAssignStocks.Count; j++) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | float detailAssignQuantity = outStockLockInfos.Where(x => x.MaterielCode == OutboundOrder.MaterialCode).Sum(x => x.AssignQuantity);//åºåºè®¢åæç»å·²åé
æ°é | 
|---|
|  |  |  |  | 
|---|
|  |  |  | float palletAssignQuantity = outStockLockInfos.Where(x => x.MaterielCode == OutboundOrder.MaterialCode && x.PalletCode == autoAssignStocks[j].PalletCode).Sum(x => x.AssignQuantity);//åºåºè¯¦æ
å·²åé
æ°é | 
|---|
|  |  |  |  | 
|---|
|  |  |  | float palletOutboundQuantity = autoAssignStocks[j].Details.Sum(x => x.OutboundQuantity); | 
|---|
|  |  |  | if (palletAssignQuantity < palletOutboundQuantity)//妿åºåºè¯¦æ
å·²åé
æ°éå°äºæçå·²åé
æ°éï¼åå¯ä»¥ç»§ç»æ·»å è¯¥æçåºåºä¿¡æ¯ | 
|---|
|  |  |  | { | 
|---|
|  |  |  | float orderDetailNeedQuantity = OutboundOrder.OrderQuantity - detailAssignQuantity; | 
|---|
|  |  |  | if (orderDetailNeedQuantity > autoAssignStocks[j].Details.Sum(x => x.OutboundQuantity) - palletAssignQuantity) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | OutboundOrder.LockQuantity += autoAssignStocks[j].Details.Sum(x => x.OutboundQuantity) - palletAssignQuantity; | 
|---|
|  |  |  | //Dt_OutStockLockInfo outStockLockInfo = _outStockLockInfoService.GetOutStockLockInfo(OutboundOrder, autoAssignStocks[j], autoAssignStocks[j].Details.Sum(x => x.OutboundQuantity) - palletAssignQuantity); | 
|---|
|  |  |  | Dt_OutStockLockInfo outStockLockInfo = _outStockLockInfoService.GetOutStockLockInfo(OutboundOrder, autoAssignStocks[j], assignQuantity); | 
|---|
|  |  |  | outStockLockInfos.Add(outStockLockInfo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | //Dt_OutStockLockInfo outStockLockInfo = _outStockLockInfoService.GetOutStockLockInfo(OutboundOrder, autoAssignStocks[j], OutboundOrder.OrderQuantity - OutboundOrder.LockQuantity); | 
|---|
|  |  |  | Dt_OutStockLockInfo outStockLockInfo = _outStockLockInfoService.GetOutStockLockInfo(OutboundOrder, autoAssignStocks[j], assignQuantity); | 
|---|
|  |  |  | outStockLockInfos.Add(outStockLockInfo); | 
|---|
|  |  |  | OutboundOrder.LockQuantity = OutboundOrder.OrderQuantity; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | locationInfos.AddRange(_basicService.LocationInfoService.Repository.GetLocationInfos(outStocks.Select(x => x.LocationCode).ToList())); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return (outStocks, mesPPOutboundOrderDetails, outStockLockInfos, locationInfos, OutboundOrder); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | 
|---|
|  |  |  | /// <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) | 
|---|
|  |  |  | public WebResponseContent LockOutboundStockDataUpdate(Dt_MesPPOutboundOrder mesPPOutboundOrder, 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 | 
|---|
|  |  |  | { | 
|---|
|  |  |  | 
|---|
|  |  |  | { | 
|---|
|  |  |  | _outStockLockInfoService.Repository.UpdateData(updateOutStockLockInfos); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (mesPPOutboundOrder != null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | _mesPPOutboundOrderService.UpdateData(mesPPOutboundOrder); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfos, locationStatus, LocationChangeType.OutboundAssignLocation, "", tasks?.Select(x => x.TaskNum).ToList()); | 
|---|
|  |  |  | _basicService.LocationInfoService.Repository.UpdateLocationStatus(locationInfos, locationStatus); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /// <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); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|