public virtual void RemoveItem(UnitloadItem item) { if (this.Items.Contains(item) == false) { throw new InvalidOperationException("项不在这个货载里。"); } item.Unitload = null; _items.Remove(item); }
public virtual void AddItem(UnitloadItem item) { if (item == null) { throw new ArgumentNullException(nameof(item)); } if (item.Unitload != null) { throw new InvalidOperationException("向货载添加货载项失败,货载项已属于其他货载。"); } _items.Add(item); item.Unitload = this; }
public async Task <Unitload> PalletizeAsync <TStockKey>(string palletCode, IEnumerable <PalletizationItemInfo <TStockKey> > items, string opType, string bizType, string orderCode = Cst.None, string bizOrder = Cst.None, bool updateStock = true) where TStockKey : StockKeyBase { if (palletCode == null) { throw new ArgumentNullException(nameof(palletCode)); } if (bizType == null) { throw new ArgumentNullException(nameof(bizType)); } if (opType == null) { throw new ArgumentNullException(nameof(opType)); } _logger.Information($"正在组盘,托盘号:{palletCode}", palletCode); // 验证托盘编码是否已占用 bool used = await _session.Query <Unitload>() .IsPalletCodeInUseAsync(palletCode) .ConfigureAwait(false); if (used) { throw new InvalidOperationException($"托盘号已被占用:【{palletCode}】"); } // 验证托盘编码是否符合合法 if (_palletCodeValidator.IsWellFormed(palletCode, out string err) == false) { throw new InvalidOperationException($"托盘号无效:{err}"); } // 生成货载和流水 Unitload unitload = _unitloadFactory.CreateUnitload(); unitload.PalletCode = palletCode; foreach (var item in items) { UnitloadItem unitloadItem = _unitloadFactory.CreateUnitloadItem(); unitloadItem.SetStockKey(item.StockKey); unitloadItem.Quantity = item.Quantity; unitloadItem.OutOrdering = _outOrderingProvider.GetOutOrdering(item.StockKey); unitload.AddItem(unitloadItem); await _flowHelper .CreateAndSaveAsync(item.StockKey, item.Quantity, FlowDirection.Inbound, bizType, opType, palletCode, orderCode, bizOrder, Cst.None, updateStock) .ConfigureAwait(false); } var loc = await _session.Query <Location>().GetNAsync().ConfigureAwait(false); unitload.Enter(loc); unitload.StorageInfo = new UnitloadStorageInfo { StorageGroup = _storageInfoProvider.GetStorageGroup(unitload), OutFlag = _storageInfoProvider.GetOutFlag(unitload), ContainerSpecification = _storageInfoProvider.GetContainerSpecification(unitload) }; // 将货载保存到数据库 await _session.SaveAsync(unitload).ConfigureAwait(false); _logger.Information($"组盘成功"); return(unitload); }
/// <summary> /// 计算货载项在此出库单中的分配数量。 /// </summary> /// <param name="unitloadItem"></param> /// <returns></returns> public virtual decimal ComputeAllocated(UnitloadItem unitloadItem) { return(Lines.SelectMany(x => x.Allocations) .Where(x => x.UnitloadItem == unitloadItem) .Sum(x => x.Quantity)); }