public OrderHead PreviewGenOrder(string flowCode) { IList <LeanEngineView> leanEngineViews = this.GetLeanEngineView(null, flowCode, null, null, null, null, null); List <string> locList = leanEngineViews.Where(l => l.LocTo != null).Select(l => l.LocTo).Distinct().ToList(); List <string> itemList = leanEngineViews.Select(l => l.Item).Distinct().ToList(); IList <LocationDetail> locationDetails = this.GetLocationDetail(locList, itemList); IList <OrderLocTransView> orderLocTrans = this.GetOrderLocTransView(locList, itemList); IEngine engine = new Engine(); LeanEngine.Entity.EngineContainer container = new LeanEngine.Entity.EngineContainer(); container.ItemFlows = this.TransformToItemFlow(leanEngineViews); container.InvBalances = this.TransformToInvBalances(locationDetails); container.Plans = this.TransformToPlans(orderLocTrans); engine.TellMeDemands(container); List <LeanEngine.Entity.Orders> orders = engine.DemandToOrders(container.ItemFlows); List <LeanEngine.Entity.ItemFlow> itemFlows = (from o in orders from i in o.ItemFlows where i.OrderQty > 0 select i).ToList(); OrderHead orderHead = null; if (itemFlows != null && itemFlows.Count > 0) { orderHead = this.OrderMgr.TransferFlow2Order(flowCode); if (orderHead.OrderDetails != null && orderHead.OrderDetails.Count > 0) { foreach (var orderDetail in orderHead.OrderDetails) { var itemFlow = itemFlows.SingleOrDefault(i => i.ID == orderDetail.FlowDetail.Id); if (itemFlow != null) { orderDetail.RequiredQty = itemFlow.ReqQty; orderDetail.OrderedQty = itemFlow.OrderQty; } } orderHead.OrderDetails = orderHead.OrderDetails.Where(o => o.OrderedQty > 0).ToList(); } } return(orderHead); }
//3G LeanEngine public void OrderGenerate() { log.Info("----------------------------------Invincible's dividing line---------------------------------------"); log.Debug("Lean Engine start working."); this.Initial_DBCache(); #region Load data IEngine engine = new Engine(); LeanEngine.Entity.EngineContainer container = new LeanEngine.Entity.EngineContainer(); log.Debug("Begin to load data:"); container.ItemFlows = this.TransformToItemFlow(); container.InvBalances = this.TransformToInvBalances(); container.Plans = this.TransformToPlans(); log.Debug("FlowDetail count:" + container.ItemFlows.Count); log.Debug("LocationDetail count:" + container.InvBalances.Count); log.Debug("OrderLocTrans count:" + container.Plans.Count); log.Debug("Load data finished."); #endregion #region Lean Engine Core Logic log.Debug("Begin to calculate:"); engine.TellMeDemands(container); log.Debug("Calculating finished."); log.Debug("Begin to create orders:"); List <LeanEngine.Entity.Orders> orders = engine.DemandToOrders(container.ItemFlows); if (orders == null || orders.Count == 0) { log.Debug("No orders to create."); return; } #endregion List <string> flowList = orders.Select(o => o.Flow.Code).Distinct().ToList(); _flows = this.GetFlow(flowList, true); log.Debug("Flow count:" + _flows.Count); foreach (var order in orders) { this.ProcessNewOrder(order); } this.Initial_DBCache(); log.Debug("Lean Engine finished the job."); }