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)); }
public Logistic(Organization subOrganization, SplitPackageConfig organization) { this.LogisticName = Logistic.GetLogisticName(organization.OrganizationName, subOrganization.GradeName); }