public SplitedOrder SplitWithOrganization1(string orderId, List <Product> productList, int totalQuantity, List <string> logistics) { try { var pel = ConvertToProductEntity(productList, false); List <RuleEntity> rules = new List <RuleEntity>(); foreach (var item in logistics) { Logistic l = this.GetLogisticcDic()[Logistic.GetLogisticName(item, "标准型")]; if (l != null && l.RuleSequenceDic != null) { rules.AddRange(l.RuleSequenceDic.Values); } } // 指定物流拆单 var result = SplitOrderWithOrganization(orderId, pel.Item1, totalQuantity, rules); if (result.Item2.Count > 0) { var secondLogistics = logisticsRelated.Where(o => o.Logistics.Any(oi => logistics.Contains(oi))).SelectMany(o => o.Logistics) .Where(o => !logistics.Contains(o)); List <RuleEntity> secondRules = new List <RuleEntity>(); foreach (var item in secondLogistics) { Logistic l = this.GetLogisticcDic()[Logistic.GetLogisticName(item, "标准型")]; if (l != null && l.RuleSequenceDic != null) { secondRules.AddRange(l.RuleSequenceDic.Values); } } var secondResult = SplitOrderWithOrganization(orderId, result.Item2, totalQuantity, secondRules); result.Item1.AddSubOrderRange(secondResult.Item1); if (secondResult.Item2.Count > 0) { // 指定物流情况下,重新调用一遍价格优先将剩余订单拆分 result.Item1.AddSubOrderRange(SplitOrder(orderId, secondResult.Item2, pel.Item2, totalQuantity, SplitPrinciple.PriceFirst)); } } result.Item1.GenerateSubOrderId(); LogHelper.Logger.Info(string.Format("Spliter.SplitWithOrganization return:\n {0}", result.Item1)); return(result.Item1); } catch (Exception ex) { LogHelper.Logger.Info(ex.Message, ex); throw; } }
/// <summary> /// 按照指定物流拆单 /// </summary> /// <param name="productNoList">待拆单货号列表</param> /// <param name="OrganizationId">物流ID</param> public SplitedOrder SplitWithOrganization(string orderId, List <Product> productList, int totalQuantity, string logisticsName, string gradeName) { try { string key = Logistic.GetLogisticName(logisticsName, gradeName); if (!this.logisticcDic.ContainsKey(key)) { LogHelper.Logger.Error(string.Format("指定物流(logisticsName[{0}], gradeName[{1}])不存在:", logisticsName, gradeName)); return(this.Split(orderId, productList, totalQuantity, (int)SplitPrinciple.PriceFirst)); } var logistics = this.logisticcDic[key]; if (logistics.RuleSequenceDic == null) { LogHelper.Logger.Error(string.Format("物流(logisticsName[{0}], gradeName[{1}])的规则配置为NULL。", logistics.LogisticName, gradeName)); return(this.Split(orderId, productList, totalQuantity, (int)SplitPrinciple.PriceFirst)); } // 读取该指定物流的规则清单 var relst = logistics.RuleSequenceDic.Values.ToList(); var pel = ConvertToProductEntity(productList); // 指定物流拆单 var result = SplitOrderWithOrganization(orderId, pel.Item1, totalQuantity, relst); if (result.Item2.Count > 0) { // 指定物流情况下,重新调用一遍价格优先将剩余订单拆分 result.Item1.AddSubOrderRange(SplitOrder(orderId, result.Item2, pel.Item2, totalQuantity, SplitPrinciple.PriceFirst)); } result.Item1.GenerateSubOrderId(); LogHelper.Logger.Info(string.Format("Spliter.SplitWithOrganization return:\n {0}", result.Item1)); return(result.Item1); } catch (Exception ex) { LogHelper.Logger.Info(ex.Message, ex); throw; } }
protected Tuple <bool, string> ValidRequire <T>(T request) where T : BaseRequest { //非空验证 if (request == null) { LogHelper.Logger.Info("Request model is null", new ArgumentException("SRequest model is null")); return(Tuple.Create(false, "Request model is null")); } // 待拆分商品清单有效性验证 if ((request.ProList == null) || (request.ProList.Count <= 0)) { LogHelper.Logger.Info("Product list is null", new ArgumentException("Product list is null")); return(Tuple.Create(false, "Product list is null")); } //商品价格 if (request.ProList.Any(o => o.ProPrice <= 0)) { return(Tuple.Create(false, "商品价格必须大于0")); } //商品重量 if (request.ProList.Any(o => o.Weight <= 0)) { return(Tuple.Create(false, "商品重量必须大于0")); } //商品数量 if (request.ProList.Any(o => o.Quantity <= 0)) { return(Tuple.Create(false, "商品数量必须大于0")); } //sku或ptid if (request is SplitWithExpRequest1) { if (request.ProList.Any(o => string.IsNullOrEmpty(o.PTId))) { return(Tuple.Create(false, "缺少PTId")); } var unDeployPTIds = request.ProList.Where(o => !this.spliter.GetProductConfig().Products.Any(oi => oi.PTId.Equals(o.PTId))).Select(o => o.PTId).ToList(); if (unDeployPTIds.Count > 0) { return(Tuple.Create(false, string.Format("不存在PTId:{0}", string.Join(",", unDeployPTIds.Distinct())))); } } else { if (request.ProList.Any(o => string.IsNullOrEmpty(o.SkuNo))) { return(Tuple.Create(false, "缺少SkuNo")); } var unDeploySkuNoes = request.ProList.Where(o => !this.spliter.GetProductConfig().Products.Any(oi => oi.SKUNo.Trim().Equals(o.SkuNo))).Select(o => o.SkuNo).ToList(); if (unDeploySkuNoes.Count > 0) { return(Tuple.Create(false, string.Format("不存在SkuNo:{0}", string.Join(",", unDeploySkuNoes.Distinct())))); } } //指定物流判断 if (request is SplitWithExpRequest) { SplitWithExpRequest swr = (request as SplitWithExpRequest); string key = Logistic.GetLogisticName(swr.LogisticsName, swr.GradeName); if (key.Equals(Logistic.GetLogisticName(string.Empty, string.Empty))) { return(Tuple.Create(false, "请提供指定物流商")); } if (!this.spliter.GetLogisticcDic().ContainsKey(key)) { return(Tuple.Create(false, string.Format("不存在{0}的规则", key))); } } else if (request is SplitWithExpRequest1) { List <string> requestLogistics = (request as SplitWithExpRequest1).logistics; if (requestLogistics == null || requestLogistics.Count == 0) { return(Tuple.Create(false, "请提供指定物流商")); } var logisticsIds = requestLogistics.Distinct(); var unDeploylogisticsIds = logisticsIds.Where(o => !this.spliter.GetLogisticsList().Any(oi => oi.Name.Trim().Equals(o))).ToList(); if (unDeploylogisticsIds.Count > 0) { return(Tuple.Create(false, string.Format("指定物流商:{0}不存在", string.Join(",", unDeploylogisticsIds)))); } } return(Tuple.Create(true, string.Empty)); }
/// <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; } }
public Logistic(Organization subOrganization, SplitPackageConfig organization) { this.LogisticName = Logistic.GetLogisticName(organization.OrganizationName, subOrganization.GradeName); }