Browse Source

Merge pull request #265 from EasyAbp/fix-product-to-product-view-mapping

Fix the Product to ProductView mapping
pull/266/head
Super 3 years ago
committed by GitHub
parent
commit
476b539105
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/Products/ProductViewAppService.cs
  2. 2
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/ProductsApplicationAutoMapperProfile.cs
  3. 71
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/ProductView.cs

15
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/Products/ProductViewAppService.cs

@ -2,12 +2,14 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using EasyAbp.EShop.Products.Options;
using EasyAbp.EShop.Products.Permissions; using EasyAbp.EShop.Products.Permissions;
using EasyAbp.EShop.Products.Products.CacheItems; using EasyAbp.EShop.Products.Products.CacheItems;
using EasyAbp.EShop.Products.Products.Dtos; using EasyAbp.EShop.Products.Products.Dtos;
using EasyAbp.EShop.Products.Settings; using EasyAbp.EShop.Products.Settings;
using EasyAbp.EShop.Stores.Stores; using EasyAbp.EShop.Stores.Stores;
using Microsoft.Extensions.Caching.Distributed; using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Options;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Volo.Abp.Caching; using Volo.Abp.Caching;
using Volo.Abp.Uow; using Volo.Abp.Uow;
@ -22,6 +24,7 @@ namespace EasyAbp.EShop.Products.Products
protected override string GetListPolicyName { get; set; } = null; protected override string GetListPolicyName { get; set; } = null;
protected override string CrossStorePolicyName { get; set; } = ProductsPermissions.Products.CrossStore; protected override string CrossStorePolicyName { get; set; } = ProductsPermissions.Products.CrossStore;
private readonly EShopProductsOptions _options;
private readonly IProductViewCacheKeyProvider _productViewCacheKeyProvider; private readonly IProductViewCacheKeyProvider _productViewCacheKeyProvider;
private readonly IDistributedCache<ProductViewCacheItem> _cache; private readonly IDistributedCache<ProductViewCacheItem> _cache;
private readonly IProductManager _productManager; private readonly IProductManager _productManager;
@ -29,12 +32,14 @@ namespace EasyAbp.EShop.Products.Products
private readonly IProductViewRepository _repository; private readonly IProductViewRepository _repository;
public ProductViewAppService( public ProductViewAppService(
IOptions<EShopProductsOptions> options,
IProductViewCacheKeyProvider productViewCacheKeyProvider, IProductViewCacheKeyProvider productViewCacheKeyProvider,
IDistributedCache<ProductViewCacheItem> cache, IDistributedCache<ProductViewCacheItem> cache,
IProductManager productManager, IProductManager productManager,
IProductRepository productRepository, IProductRepository productRepository,
IProductViewRepository repository) : base(repository) IProductViewRepository repository) : base(repository)
{ {
_options = options.Value;
_productViewCacheKeyProvider = productViewCacheKeyProvider; _productViewCacheKeyProvider = productViewCacheKeyProvider;
_cache = cache; _cache = cache;
_productManager = productManager; _productManager = productManager;
@ -123,11 +128,13 @@ namespace EasyAbp.EShop.Products.Products
await _repository.DeleteAsync(x => x.StoreId == storeId, true); await _repository.DeleteAsync(x => x.StoreId == storeId, true);
var productGroupDisplayNameMapping = await GetProductGroupDisplayNamesAsync();
var productViews = new Dictionary<Product, ProductView>(); var productViews = new Dictionary<Product, ProductView>();
foreach (var product in products) foreach (var product in products)
{ {
var productView = ObjectMapper.Map<Product, ProductView>(product); productGroupDisplayNameMapping.TryGetValue(product.ProductGroupName, out var productGroupDisplayName);
var productView = new ProductView(product, productGroupDisplayName);
productViews[product] = productView; productViews[product] = productView;
} }
@ -151,6 +158,12 @@ namespace EasyAbp.EShop.Products.Products
} }
} }
protected virtual Task<Dictionary<string, string>> GetProductGroupDisplayNamesAsync()
{
return Task.FromResult(_options.Groups.GetConfigurationsDictionary()
.ToDictionary(x => x.Key, x => x.Value.DisplayName));
}
protected virtual async Task<TimeSpan?> GetCacheDurationOrNullAsync(List<ProductView> productViews, protected virtual async Task<TimeSpan?> GetCacheDurationOrNullAsync(List<ProductView> productViews,
DateTime now) DateTime now)
{ {

2
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/ProductsApplicationAutoMapperProfile.cs

@ -11,7 +11,6 @@ using EasyAbp.EShop.Products.ProductHistories;
using EasyAbp.EShop.Products.ProductHistories.Dtos; using EasyAbp.EShop.Products.ProductHistories.Dtos;
using EasyAbp.EShop.Products.Products; using EasyAbp.EShop.Products.Products;
using EasyAbp.EShop.Products.Products.Dtos; using EasyAbp.EShop.Products.Products.Dtos;
using System.Linq;
using Volo.Abp.AutoMapper; using Volo.Abp.AutoMapper;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
@ -46,7 +45,6 @@ namespace EasyAbp.EShop.Products
CreateMap<ProductHistory, ProductHistoryDto>(); CreateMap<ProductHistory, ProductHistoryDto>();
CreateMap<ProductDetailHistory, ProductDetailHistoryDto>(); CreateMap<ProductDetailHistory, ProductDetailHistoryDto>();
CreateMap<ProductView, ProductViewDto>(); CreateMap<ProductView, ProductViewDto>();
CreateMap<Product, ProductView>(MemberList.Destination);
} }
} }
} }

71
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/ProductView.cs

@ -43,9 +43,9 @@ namespace EasyAbp.EShop.Products.Products
public virtual string ProductGroupDisplayName { get; protected set; } public virtual string ProductGroupDisplayName { get; protected set; }
public virtual List<ProductDiscountInfoModel> ProductDiscounts { get; set; } public virtual List<ProductDiscountInfoModel> ProductDiscounts { get; protected set; }
public virtual List<OrderDiscountPreviewInfoModel> OrderDiscountPreviews { get; set; } public virtual List<OrderDiscountPreviewInfoModel> OrderDiscountPreviews { get; protected set; }
public virtual decimal? MinimumPrice { get; protected set; } public virtual decimal? MinimumPrice { get; protected set; }
@ -61,57 +61,28 @@ namespace EasyAbp.EShop.Products.Products
{ {
} }
public ProductView( public ProductView(Product product, string productGroupDisplayName) : base(product.Id)
Guid id,
Guid? tenantId,
Guid storeId,
string productGroupName,
Guid? productDetailId,
string uniqueName,
string displayName,
string overview,
InventoryStrategy inventoryStrategy,
string inventoryProviderName,
bool isPublished,
bool isStatic,
bool isHidden,
TimeSpan? paymentExpireIn,
string mediaResources,
int displayOrder,
string productGroupDisplayName,
List<ProductDiscountInfoModel> productDiscounts,
List<OrderDiscountPreviewInfoModel> orderDiscountPreviews,
decimal? minimumPrice,
decimal? maximumPrice,
decimal? minimumPriceWithoutDiscount,
decimal? maximumPriceWithoutDiscount,
long sold
) : base(id)
{ {
TenantId = tenantId; TenantId = product.TenantId;
StoreId = storeId; StoreId = product.StoreId;
ProductGroupName = productGroupName; ProductGroupName = product.ProductGroupName;
ProductDetailId = productDetailId; ProductDetailId = product.ProductDetailId;
UniqueName = uniqueName?.Trim(); UniqueName = product.UniqueName?.Trim();
DisplayName = displayName; DisplayName = product.DisplayName;
Overview = overview; Overview = product.Overview;
InventoryStrategy = inventoryStrategy; InventoryStrategy = product.InventoryStrategy;
InventoryProviderName = inventoryProviderName; InventoryProviderName = product.InventoryProviderName;
IsPublished = isPublished; IsPublished = product.IsPublished;
IsStatic = isStatic; IsStatic = product.IsStatic;
IsHidden = isHidden; IsHidden = product.IsHidden;
PaymentExpireIn = paymentExpireIn; PaymentExpireIn = product.PaymentExpireIn;
MediaResources = mediaResources; MediaResources = product.MediaResources;
DisplayOrder = displayOrder; DisplayOrder = product.DisplayOrder;
ProductGroupDisplayName = productGroupDisplayName; ProductGroupDisplayName = productGroupDisplayName;
ProductDiscounts = productDiscounts ?? new List<ProductDiscountInfoModel>();
OrderDiscountPreviews = orderDiscountPreviews ?? new List<OrderDiscountPreviewInfoModel>(); ProductDiscounts = new List<ProductDiscountInfoModel>();
MinimumPrice = minimumPrice; OrderDiscountPreviews = new List<OrderDiscountPreviewInfoModel>();
MaximumPrice = maximumPrice;
MinimumPriceWithoutDiscount = minimumPriceWithoutDiscount;
MaximumPriceWithoutDiscount = maximumPriceWithoutDiscount;
Sold = sold;
} }
public void SetSold(long sold) public void SetSold(long sold)

Loading…
Cancel
Save