예제 #1
0
 public Logistic(LogisticCacheDto logistic)
 {
     this.LogisticName    = logistic.LogisticCode;
     this.RuleSequenceDic = new Dictionary <string, RuleEntity>();
     foreach (var item in logistic.LogisticChannels)
     {
         this.RuleSequenceDic.Add(item.ChannelName, new RuleEntity(item, logistic));
     }
 }
예제 #2
0
 public RuleEntity(ChannelCacheDto channel, LogisticCacheDto logistic)
 {
     this.LogisticsName = logistic.CorporationName;
     this.LogisticsId   = logistic.LogisticCode;
     this.RuleName      = channel.ChannelName;
     this.Rule          = new PackageRule()
     {
         Id = (int)channel.Id,
         SubBusinessName = channel.ChannelName,
         StartingPrice   = channel.WeightFreights.First().StartingPrice,
         StartingWeight  = channel.WeightFreights.First().StartingWeight,
         Price           = channel.WeightFreights.First().Price,
         StepWeight      = (int)channel.WeightFreights.First().StepWeight,
         MixRule         = channel.SplitRules.Select(o => new MixRule()
         {
             MRId            = (int)o.Id,
             LimitedQuantity = o.MaxPackage,
             LimitedWeight   = o.MaxWeight,
             TaxThreshold    = o.MaxTax,
             LimitedMaxPrice = o.MaxPrice,
             RuleItems       = o.ProductClasses.Select(oi => new RuleItem()
             {
                 PTId        = oi.StintMark,
                 MinQuantity = oi.MinNum,
                 MaxQuantity = oi.MaxNum
             }).ToList()
         }).OrderBy(o => o.MRId).ToList()
     };
     this.Organization = new SplitPackageConfig()
     {
         OrganizationId   = logistic.LogisticCode,
         OrganizationName = logistic.CorporationName,
         URL     = logistic.CorporationUrl,
         LogoURL = logistic.LogoURL
     };
     this.InitSplitRule();
 }
예제 #3
0
 public void InitCache()
 {
     using (var unitOfWork = _unitOfWorkManager.Begin())
     {
         List <ProductClassCacheDto> pcSet = this._productClassRepository.GetAll().Include(p => p.ProductSortBy).ToList().Select(o => new ProductClassCacheDto()
         {
             ProductClassId = o.Id,
             ProductSortId  = o.ProductSortId,
             SortName       = o.ProductSortBy.SortName,
             ClassName      = o.ClassName,
             PTId           = o.PTId,
             PostTaxRate    = o.PostTaxRate,
             BCTaxRate      = o.BCTaxRate,
             IsActive       = o.IsActive
         }).ToList();
         productClassCache.Set("host", pcSet);
         var logisticQuery = this._logisticRepository.GetAll().Include(p => p.LogisticChannels)
                             .ThenInclude((LogisticChannel p) => p.NumFreights)
                             .Include(p => p.LogisticChannels).ThenInclude((LogisticChannel p) => p.WeightFreights)
                             .Include(p => p.LogisticChannels).ThenInclude((LogisticChannel p) => p.SplitRules).ThenInclude((SplitRule p) => p.ProductClasses);
         var logisticRelatedQuery = this._logisticRelatedRepository.GetAll().Include(p => p.Items).ThenInclude((LogisticRelatedItem p) => p.LogisticBy);
         var hostLogistics        = logisticQuery.IgnoreQueryFilters().Where(o => o.TenantId == null && o.IsActive).Select(this._objectMapper.Map <LogisticCacheDto>).ToList();
         splitPackageSettingCache.Set("host", new SplitPackageSettingCache()
         {
             OwnLogistics = hostLogistics,
             Relateds     = logisticRelatedQuery.IgnoreQueryFilters().Where(o => o.TenantId == null).Select(this._objectMapper.Map <LogisticRelatedCacheDto>).ToList()
         });
         foreach (var item in _tenantRepository.GetAll().Where(o => o.IsActive).ToList())
         {
             var ownLogistics = logisticQuery.IgnoreQueryFilters().Where(o => o.TenantId == item.Id && o.IsActive).Select(this._objectMapper.Map <LogisticCacheDto>).ToList();
             var import       = this._importLogisticRepository.GetAll().Include(o => o.LogisticChannelBy)
                                .ThenInclude((LogisticChannel p) => p.LogisticBy)
                                .IgnoreQueryFilters().Where(o => o.TenantId == item.Id).ToList();
             var set = hostLogistics.Where(o => import.Any(oi => oi.LogisticChannelBy.LogisticId == o.Id)).SelectMany(o => o.LogisticChannels)
                       .Where(o => import.Any(oi => oi.LogisticChannelId == o.Id)).ToList();
             var importChannls = new ChannelCacheDto[set.Count];
             set.CopyTo(importChannls);
             var importSet = import.GroupBy(o => o.LogisticChannelBy.LogisticBy).Select(o => {
                 var result = new LogisticCacheDto()
                 {
                     Id = o.Key.Id,
                     CorporationName = o.Key.CorporationName,
                     CorporationUrl  = o.Key.CorporationUrl,
                     LogoURL         = o.Key.LogoURL,
                     LogisticCode    = o.Key.LogisticCode,
                 };
                 result.LogisticChannels = o.Select(oi => {
                     var c = importChannls.Where(oii => oi.LogisticChannelId == oii.Id).FirstOrDefault();
                     if (c == null)
                     {
                         return(null);
                     }
                     if (!string.IsNullOrEmpty(oi.AliasName))
                     {
                         c.AliasName = oi.AliasName;
                     }
                     if (oi.Way.HasValue)
                     {
                         c.Way = oi.Way.Value;
                     }
                     var information = oi.GetInformation();
                     if (information != null)
                     {
                         c.WeightFreights = information.WeightChargeRules.Select(this._objectMapper.Map <WeightFreightCacheDto>).ToList();
                         c.NumFreights    = information.NumChargeRules.Select(this._objectMapper.Map <NumFreightCacheDto>).ToList();
                     }
                     return(c);
                 }).Where(oi => oi != null).ToList();
                 return(result);
             });
             ownLogistics.AddRange(importSet);
             var relateds = logisticRelatedQuery.IgnoreQueryFilters().Where(o => o.TenantId == item.Id).Select(this._objectMapper.Map <LogisticRelatedCacheDto>).ToList();
             if (ownLogistics.Count > 0)
             {
                 splitPackageSettingCache.Set(item.Id.ToString(), new SplitPackageSettingCache()
                 {
                     OwnLogistics = ownLogistics,
                     Relateds     = relateds
                 });
             }
         }
         unitOfWork.Complete();
     }
 }