|  |  | 
 |  |  |                 float needQuantity = originalNeedQuantity; | 
 |  |  |  | 
 |  |  |                 List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.GetUseableStocks(item.MaterielCode, item.BatchNo, outboundOrder.WarehouseId); | 
 |  |  |                 if (!stockInfos.Any()) | 
 |  |  |                 { | 
 |  |  |                     throw new Exception($"æªæ¾å°å¯åé
åºå"); | 
 |  |  |                 } | 
 |  |  |                 List<Dt_StockInfo> autoAssignStocks = _stockService.StockInfoService.GetOutboundStocks(stockInfos, item.MaterielCode, needQuantity, out float residueQuantity); | 
 |  |  |                 item.LockQuantity += needQuantity - residueQuantity; | 
 |  |  |                 outStocks.AddRange(autoAssignStocks); | 
 |  |  |                 float assignQuantity = needQuantity - residueQuantity; | 
 |  |  |                 //for (int i = 0; i < outboundOrderDetails.Count; i++) | 
 |  |  |                 //{ | 
 |  |  |                 //    for (int j = 0; j < outStocks.Count; j++) | 
 |  |  |                 //    { | 
 |  |  |                 //        if(assignQuantity > 0) | 
 |  |  |                 //        { | 
 |  |  |                 //            if (outboundOrderDetails[i].OrderQuantity - outboundOrderDetails[i].LockQuantity >= outStocks[j].) | 
 |  |  |                 //            { | 
 |  |  |  | 
 |  |  |                 //            } | 
 |  |  |                 //        } | 
 |  |  |                 //    } | 
 |  |  |                 List<Dt_OutboundOrderDetail> details = outboundOrderDetails.Where(x => !string.IsNullOrEmpty(x.BatchNo) ? x.BatchNo == item.BatchNo : true && x.MaterielCode == item.MaterielCode).ToList(); | 
 |  |  |  | 
 |  |  |                 //    if (assignQuantity > 0 && outboundOrderDetails[i].LockQuantity < outboundOrderDetails[i].OrderQuantity) | 
 |  |  |                 //    { | 
 |  |  |                 //        outStockLockInfos.AddRange(_outStockLockInfoService.GetOutStockLockInfos(outboundOrder, outboundOrderDetails[i], outStocks)); | 
 |  |  |                 //        if (outboundOrderDetails[i].OrderQuantity - outboundOrderDetails[i].LockQuantity >= assignQuantity) | 
 |  |  |                 //        { | 
 |  |  |                 //            outboundOrderDetails[i].LockQuantity += assignQuantity; | 
 |  |  |                 //            break; | 
 |  |  |                 //        } | 
 |  |  |                 //        else | 
 |  |  |                 //        { | 
 |  |  |                 //            assignQuantity -= (outboundOrderDetails[i].OrderQuantity - outboundOrderDetails[i].LockQuantity); | 
 |  |  |                 //            outboundOrderDetails[i].LockQuantity = outboundOrderDetails[i].OrderQuantity; | 
 |  |  |                 //        } | 
 |  |  |                 //    } | 
 |  |  |                 //} | 
 |  |  |                 for (int i = 0; i < details.Count; i++) | 
 |  |  |                 { | 
 |  |  |                     float orderQuantity = details[i].OrderQuantity; | 
 |  |  |                     for (int j = 0; j < autoAssignStocks.Count; j++) | 
 |  |  |                     { | 
 |  |  |                         float detailAssignQuantity = outStockLockInfos.Where(x => !string.IsNullOrEmpty(x.BatchNo) ? x.BatchNo == item.BatchNo : true && x.MaterielCode == item.MaterielCode && x.OrderDetailId == details[i].Id).Sum(x => x.AssignQuantity);//åºåºè®¢åæç»å·²åé
æ°é | 
 |  |  |  | 
 |  |  |                         float palletAssignQuantity = outStockLockInfos.Where(x => x.BatchNo == item.BatchNo && x.MaterielCode == item.MaterielCode && x.PalletCode == autoAssignStocks[j].PalletCode).Sum(x => x.AssignQuantity);//åºåºè¯¦æ
å·²åé
æ°é | 
 |  |  |                         if (string.IsNullOrEmpty(item.BatchNo)) | 
 |  |  |                         { | 
 |  |  |                             palletAssignQuantity = outStockLockInfos.Where(x => x.MaterielCode == item.MaterielCode && x.PalletCode == autoAssignStocks[j].PalletCode).Sum(x => x.AssignQuantity);//åºåºè¯¦æ
å·²åé
æ°é | 
 |  |  |                         } | 
 |  |  |                         float palletOutboundQuantity = autoAssignStocks[j].Details.Sum(x => x.OutboundQuantity); | 
 |  |  |                         if (palletAssignQuantity < palletOutboundQuantity)//妿åºåºè¯¦æ
å·²åé
æ°éå°äºæçå·²åé
æ°éï¼åå¯ä»¥ç»§ç»æ·»å è¯¥æçåºåºä¿¡æ¯ | 
 |  |  |                         { | 
 |  |  |                             float orderDetailNeedQuantity = details[i].OrderQuantity - detailAssignQuantity; | 
 |  |  |                             if (orderDetailNeedQuantity > autoAssignStocks[j].Details.Sum(x => x.OutboundQuantity) - palletAssignQuantity) | 
 |  |  |                             { | 
 |  |  |                                 details[i].LockQuantity += autoAssignStocks[j].Details.Sum(x => x.OutboundQuantity) - palletAssignQuantity; | 
 |  |  |                                 Dt_OutStockLockInfo outStockLockInfo = _outStockLockInfoService.GetOutStockLockInfo(outboundOrder, details[i], autoAssignStocks[j], autoAssignStocks[j].Details.Sum(x => x.OutboundQuantity) - palletAssignQuantity); | 
 |  |  |                                 outStockLockInfos.Add(outStockLockInfo); | 
 |  |  |                             } | 
 |  |  |                             else | 
 |  |  |                             { | 
 |  |  |                                 Dt_OutStockLockInfo outStockLockInfo = _outStockLockInfoService.GetOutStockLockInfo(outboundOrder, details[i], autoAssignStocks[j], details[i].OrderQuantity - details[i].LockQuantity); | 
 |  |  |                                 outStockLockInfos.Add(outStockLockInfo); | 
 |  |  |                                 details[i].LockQuantity = details[i].OrderQuantity; | 
 |  |  |                                 break; | 
 |  |  |                             } | 
 |  |  |  | 
 |  |  |                         } | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |                 locationInfos.AddRange(_basicService.LocationInfoService.Repository.GetLocationInfos(outStocks.Select(x => x.LocationCode).ToList())); | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |  | 
 |  |  |             return (outStocks, outboundOrderDetails, outStockLockInfos, locationInfos); | 
 |  |  |         } | 
 |  |  | 
 |  |  |                 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(); |