Exemple #1
0
        /// <summary>
        /// 特殊规则,混装规则里正好能装下的优先
        /// </summary>
        /// <param name="re"></param>
        /// <param name="ptid"></param>
        /// <param name="totalCount"></param>
        /// <returns></returns>
        private static int CompareMixRuleMinMaxQuantity(RuleEntity re, string ptid, int totalCount)
        {
            if (!re.MixRuleDic.ContainsKey(ptid))
            {
                return(-10);
            }
            var ret = 0;

            foreach (var pmre in re.MixRuleDic[ptid])
            {
                var ruleItems = pmre.GetRuleItemList(ptid);
                foreach (var ruleItem in ruleItems)
                {
                    if (ruleItem.MaxQuantity == totalCount && ruleItem.MinQuantity == totalCount)
                    {
                        return(10);
                    }
                    if (ret < 9 && ruleItem.MaxQuantity == totalCount)
                    {
                        ret = 9;
                    }
                    if (ret < 8 && ruleItem.MaxQuantity > totalCount)
                    {
                        ret = 8;
                    }
                }
            }
            return(ret);
        }
Exemple #2
0
        public void AddRuleSequenceDic(RuleEntity rule)
        {
            if (this.RuleSequenceDic == null)
            {
                this.RuleSequenceDic = new Dictionary <string, RuleEntity>();
            }

            this.RuleSequenceDic.Add(rule.Key, rule);
        }
Exemple #3
0
 public ProductMixedRuleEntity(MixRule mixRule, RuleEntity rule)
 {
     this.Rule            = rule;
     this.MRId            = mixRule.MRId;
     this.LimitedQuantity = mixRule.LimitedQuantity;
     this.LimitedWeight   = (int)mixRule.LimitedWeight;
     this.TaxThreshold    = (decimal)mixRule.TaxThreshold;
     //this.TaxRate = (int)mixRule.TaxRate;
     this.LimitedMaxPrice  = (decimal)mixRule.LimitedMaxPrice;
     this.RuleItems        = mixRule.RuleItems;
     this.ruleItemLevelDic = this.RuleItems.ToDictionary(r => Tuple.Create(r.PTId, r.LevelName ?? string.Empty));
     this.ruleItemDic      = this.RuleItems.GroupBy(r => r.PTId).ToDictionary(g => g.Key, g => g.ToList());
 }
Exemple #4
0
        /// <summary>
        /// 父节点,拆单规则
        /// </summary>
        /// <param name="rule"></param>
        public ProductSingleRuleEntity(SingleRule singleRule, RuleEntity rule)
        {
            this.Rule = rule;
            this.Key  = string.Format("{0}${1}", rule.Key, this.PTId);

            this.PTId        = singleRule.PTId;
            this.BlackBrands = singleRule.BlackBrands;
            //this.ClassId = Int32.Parse(singleRule.ClassId);
            //this.ClassName = singleRule.ClassName;
            this.Levels       = singleRule.Levels;
            this.MaxPrice     = (decimal)singleRule.MaxPrice;
            this.MaxQuantity  = singleRule.MaxQuantity;
            this.MaxWeight    = (int)singleRule.MaxWeight;
            this.MinUnitPrice = singleRule.MinUnitPrice;
            //this.SingleOnly = singleRule.SingleOnly;
            //this.Specs = productType.Specs;
            //this.TaxRate = (int)singleRule.TaxRate;
            this.TaxThreshold = (decimal)singleRule.TaxThreshold;
            this.TypeName     = singleRule.TypeName;
            this.WhiteBrands  = singleRule.WhiteBrands;
        }
Exemple #5
0
        /// <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;
            }
        }