/// <summary> /// 初始化商品拆单规则,构建以商品ID为Key,拆单规则对象为Value的字典 /// 其中专线的Value为单个对象, /// 混装的Value为集合,对应一类商品可以和多类不同商品混装的情况 /// </summary> private void InitSplitRule() { if (this.Rule == null) { return; } //Dictionary<int, ProductSingleRuleEntity> singleRuleDic = new Dictionary<int, ProductSingleRuleEntity>(); //Dictionary<int, List<ProductMixedRuleEntity>> mixRuleDic = new Dictionary<int, List<ProductMixedRuleEntity>>(); //this.pRuleDic = new Dictionary<string, List<IProductRuleEntity>>(); if (this.Rule.SinglePackRule != null) { foreach (var singleRule in this.Rule.SinglePackRule) { if (SingleRuleDic.ContainsKey(singleRule.PTId)) { throw new ArgumentException(string.Format("配置文件异常。 PTId:[{1}] in Rule[{0}].SinglePackRules ", this.Key, singleRule.PTId)); } var psre = new ProductSingleRuleEntity(singleRule, this); SingleRuleDic.Add(singleRule.PTId, psre); // 将商品规则添加到商品规则字典中 if (pRuleDic.ContainsKey(singleRule.PTId.ToString())) { pRuleDic[singleRule.PTId.ToString()].Add(psre); } else { var ipsrelist = new List <IProductRuleEntity>(); ipsrelist.Add(psre); pRuleDic.Add(singleRule.PTId.ToString(), ipsrelist); } } } if (this.Rule.MixRule != null) { foreach (var mixRule in this.Rule.MixRule) { var pmre = new ProductMixedRuleEntity(mixRule, this); foreach (var ruleItem in mixRule.RuleItems) { //循环混装规则中的商品ID(PTId) if (MixRuleDic.ContainsKey(ruleItem.PTId)) { MixRuleDic[ruleItem.PTId].Add(pmre); } else { var pmreList = new List <ProductMixedRuleEntity>(); pmreList.Add(pmre); MixRuleDic.Add(ruleItem.PTId, pmreList); } // 将商品规则添加到商品规则字典中 if (pRuleDic.ContainsKey(ruleItem.PTId.ToString())) { pRuleDic[ruleItem.PTId.ToString()].Add(pmre); } else { var ipmrelist = new List <IProductRuleEntity>(); ipmrelist.Add(pmre); pRuleDic.Add(ruleItem.PTId.ToString(), ipmrelist); } } } } }
private static bool IsValid(ProductMixedRuleEntity pmre, List <string> ptids) { return((ptids != null && ptids.Count > 0) ? pmre.CanSupportPTId(ptids) : true); }