private decimal CalculatePrice(ProductEntity productEntity) { return(productEntity.OrderInfo.Sum(p => p.ProPrice * p.Quantity)); }
/// <summary> /// 初始化(加载配置文件) /// </summary> /// <param name="folderPath">配置文件所在路径</param> public void Initialize(string folderPath) { try { ruleSequenceDic = new Dictionary <string, RuleEntity>(); ruleEntityList = new List <RuleEntity>(); logisticcDic = new Dictionary <string, Logistic>(); logisticsList = new List <LogisticsModel>(); // 加载产品配置文件,并初始化 productConfig = this.LoadProductConfig(Path.Combine(folderPath, "Product.xml")); if ((productConfig == null) || (productConfig.Products == null) || (productConfig.Products.Count <= 0)) { throw new ArgumentException("配置文件Product.xml有误。"); } SubLevelDic = productConfig.ProductClass.SubLevels.ToDictionary(sl => sl.PTId); foreach (var p in productConfig.Products) { ProductEntity pe = new ProductEntity(p); if (this.prodDic.ContainsKey(p.SKUNo.Trim().ToLower())) { throw new ArgumentException(string.Format("SKUNO[{0}]重复配置", pe.SKUNo)); } this.prodDic.Add(p.SKUNo.Trim().ToLower(), pe); } // 加载规则配置文件,并初始化 ruleConfigs = this.LoadRules(Path.Combine(folderPath, "Rules")); foreach (SplitPackageConfig config in ruleConfigs) { var organizations = config.SubOrganizations; if ((organizations == null) || (organizations.Count < 0)) { continue; } LogisticsModel logisiticsModel = new LogisticsModel() { ID = config.OrganizationId, Name = config.OrganizationName, Rule = config.RuleDiscription, URL = config.URL, LogoURL = config.LogoURL }; if (logisticsList.Any(o => o.ID == logisiticsModel.ID)) { throw new ArgumentException(string.Format("Logistics ID:{0}重复配置", logisiticsModel.ID)); } else { // 海关的配置不需要,代码不处理,不在配置文件目录中放海关的规则 if (!Regex.IsMatch(config.OrganizationId, @"^(\-\d+|0)$")) { logisticsList.Add(logisiticsModel); } } foreach (var organization in organizations) { logisiticsModel.GradeList.Add(organization.GradeName); var rules = organization.Rules; if ((rules == null) || (rules.Count < 0)) { continue; } Logistic logistics = new Logistic(organization, config); if (logisticcDic.ContainsKey(logistics.LogisticName)) { throw new ArgumentException(String.Format("Logistics Name is already Added. LogisticName:[{0}]", logistics.LogisticName)); } logisticcDic.Add(logistics.LogisticName, logistics); foreach (PackageRule rule in rules) { if (rule == null) { continue; } RuleEntity ruleSeq = new RuleEntity(rule, config, organization); ruleSequenceDic.Add(ruleSeq.Key, ruleSeq); ruleEntityList.Add(ruleSeq); logistics.AddRuleSequenceDic(ruleSeq); } } } logisticsRelated = this.LoadLogisticsRelated(Path.Combine(folderPath, "LogisticsRelated.xml")); CheckLevelConfig(); splitConfig.Initialize(ruleEntityList); bcRuleEntity.Initialize(productConfig.ProductClass.BcConfig, SubLevelDic); var msgs = Enumerable.Repeat("Spliter Initialized.", 1) .Concat(ruleEntityList.Select(re => string.Format(" ({0}, {1}, {2})", re.LogisticsName, re.SubOrganizationName, re.RuleName))); LogHelper.Logger.Info(string.Join(Environment.NewLine, msgs)); } catch (Exception ex) { LogHelper.Logger.Info(ex.Message, ex); throw; } }