private void GetNextRccpTrans(DateTime effdate, RccpTrans parentRccpPlan, ConcurrentBag<RccpTrans> rccpTransQueue, BusinessException businessException) { var pboms = GetMrpBomList(parentRccpPlan.Item, parentRccpPlan.Item, effdate, businessException, true); if(pboms.Count > 0) { foreach(var pbom in pboms) { RccpTrans rccpTrans = new RccpTrans(); rccpTrans.Bom = pbom.Bom; rccpTrans.PlanVersion = parentRccpPlan.PlanVersion; rccpTrans.Item = pbom.Item; rccpTrans.Qty = pbom.RateQty * parentRccpPlan.Qty; rccpTrans.ScrapPercentage = pbom.ScrapPercentage; rccpTrans.SourcePlanVersion = parentRccpPlan.SourcePlanVersion; rccpTrans.DateIndex = parentRccpPlan.DateIndex; rccpTrans.DateType = parentRccpPlan.DateType; rccpTrans.Model = parentRccpPlan.Model; rccpTrans.ModelRate = parentRccpPlan.ModelRate; rccpTransQueue.Add(rccpTrans); this.GetNextRccpTrans(effdate, rccpTrans, rccpTransQueue, businessException); } } else { parentRccpPlan.IsLastLevel = true; } }
private List<RccpTrans> GetRccpTrans(DateTime planVersion, IList<RccpPlan> rccpPlans, BusinessException businessException) { var groupRccpPlans = from p in rccpPlans //where p.Qty > 0 group p by new { p.DateIndex, p.DateType } into g select new { DateIndex = g.Key.DateIndex, DateType = g.Key.DateType, List = g.ToList() }; var rccpTransBag = new ConcurrentBag<RccpTrans>(); DateTime effdate = DateTime.Now; var errorItems = new List<string>(); var itemDic = this.itemMgr.GetCacheAllItem(); var bomDetDic = bomMgr.GetCacheAllBomDetail(); foreach(var bomDet in bomDetDic) { if(!itemDic.ContainsKey(bomDet.Key)) { errorItems.Add(bomDet.Key); } } if(errorItems.Count > 0) { string errorMessage = string.Format("{0}", string.Join(",", errorItems)); businessException.AddMessage(new Message(CodeMaster.MessageType.Warning, "没有发现bom{0}的物料基础数据", errorMessage)); } foreach(var groupRccpPlan in groupRccpPlans) { log.Info(string.Format("正在分解{0}的计划", groupRccpPlan.DateIndex)); if(groupRccpPlan.DateType == CodeMaster.TimeUnit.Month) { effdate = DateTime.Parse(string.Format("{0}-01", groupRccpPlan.DateIndex)); } else { effdate = Utility.DateTimeHelper.GetWeekIndexDateFrom(groupRccpPlan.DateIndex); } Parallel.ForEach(groupRccpPlan.List, rccpPlan => //foreach (var rccpPlan in rccpPlans) { RccpTrans topRccpTrans = new RccpTrans(); topRccpTrans.PlanVersion = planVersion; topRccpTrans.Item = rccpPlan.Item; topRccpTrans.Qty = rccpPlan.Qty; topRccpTrans.ScrapPercentage = 0; topRccpTrans.SourcePlanVersion = rccpPlan.PlanVersion; topRccpTrans.DateIndex = rccpPlan.DateIndex; topRccpTrans.DateType = rccpPlan.DateType; rccpTransBag.Add(topRccpTrans); var item = this.itemMgr.GetCacheItem(rccpPlan.Item); BomDetail modelBomDetail = null; if(item.ItemCategory == "FERT") { modelBomDetail = bomDetDic .Where(p => (this.itemMgr.GetCacheItem(p.Key) ?? new Item()).ItemCategory == "MODEL") .SelectMany(p => p.Value) .Where(p => p.Item == item.Code) .FirstOrDefault(); } var mrpBoms = GetMrpBomList(rccpPlan.Item, rccpPlan.Item, effdate, businessException, true); if(mrpBoms.Count() > 0) { foreach(var mrpBom in mrpBoms) { RccpTrans rccpTrans = new RccpTrans(); rccpTrans.Bom = mrpBom.Bom; rccpTrans.PlanVersion = planVersion; rccpTrans.Item = mrpBom.Item; rccpTrans.Qty = mrpBom.RateQty * rccpPlan.Qty; rccpTrans.ScrapPercentage = mrpBom.ScrapPercentage; rccpTrans.SourcePlanVersion = rccpPlan.PlanVersion; rccpTrans.DateIndex = rccpPlan.DateIndex; rccpTrans.DateType = rccpPlan.DateType; if(item.ItemCategory == "MODEL") { rccpTrans.Model = item.Code; rccpTrans.ModelRate = mrpBom.RateQty; } else if(item.ItemCategory == "FERT") { if(modelBomDetail != null) { rccpTrans.Model = modelBomDetail.Bom; rccpTrans.ModelRate = (double)modelBomDetail.UnitBomQty; } } rccpTransBag.Add(rccpTrans); this.GetNextRccpTrans(effdate, rccpTrans, rccpTransBag, businessException); } } else { topRccpTrans.IsLastLevel = true; } } ); } return rccpTransBag.ToList(); }