|
|
|
@ -5,6 +5,7 @@ using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using EasyAbp.EShop.Products.Options; |
|
|
|
using EasyAbp.EShop.Products.ProductInventories; |
|
|
|
using EasyAbp.EShop.Products.Products.CacheItems; |
|
|
|
using EasyAbp.EShop.Stores.Stores; |
|
|
|
using Microsoft.Extensions.Options; |
|
|
|
@ -14,7 +15,9 @@ using Volo.Abp.Domain.Entities; |
|
|
|
|
|
|
|
namespace EasyAbp.EShop.Products.Products |
|
|
|
{ |
|
|
|
public class ProductAppService : MultiStoreCrudAppService<Product, ProductDto, Guid, GetProductListInput, CreateUpdateProductDto, CreateUpdateProductDto>, IProductAppService |
|
|
|
public class ProductAppService : |
|
|
|
MultiStoreCrudAppService<Product, ProductDto, Guid, GetProductListInput, CreateUpdateProductDto, |
|
|
|
CreateUpdateProductDto>, IProductAppService |
|
|
|
{ |
|
|
|
protected override string CreatePolicyName { get; set; } = ProductsPermissions.Products.Create; |
|
|
|
protected override string DeletePolicyName { get; set; } = ProductsPermissions.Products.Delete; |
|
|
|
@ -81,14 +84,11 @@ namespace EasyAbp.EShop.Products.Products |
|
|
|
await _productManager.CreateAsync(product, input.CategoryIds); |
|
|
|
|
|
|
|
var dto = await MapToGetOutputDtoAsync(product); |
|
|
|
|
|
|
|
|
|
|
|
await LoadDtoExtraDataAsync(product, dto); |
|
|
|
await LoadDtosProductGroupDisplayNameAsync(new[] {dto}); |
|
|
|
|
|
|
|
UnitOfWorkManager.Current.OnCompleted(async () => |
|
|
|
{ |
|
|
|
await ClearProductViewCacheAsync(product.StoreId); |
|
|
|
}); |
|
|
|
await LoadDtosProductGroupDisplayNameAsync(new[] { dto }); |
|
|
|
|
|
|
|
UnitOfWorkManager.Current.OnCompleted(async () => { await ClearProductViewCacheAsync(product.StoreId); }); |
|
|
|
|
|
|
|
return dto; |
|
|
|
} |
|
|
|
@ -101,14 +101,14 @@ namespace EasyAbp.EShop.Products.Products |
|
|
|
public override async Task<ProductDto> UpdateAsync(Guid id, CreateUpdateProductDto input) |
|
|
|
{ |
|
|
|
var product = await GetEntityByIdAsync(id); |
|
|
|
|
|
|
|
|
|
|
|
await CheckMultiStorePolicyAsync(product.StoreId, UpdatePolicyName); |
|
|
|
|
|
|
|
if (input.StoreId != product.StoreId) |
|
|
|
{ |
|
|
|
await CheckMultiStorePolicyAsync(input.StoreId, UpdatePolicyName); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
CheckProductIsNotStatic(product); |
|
|
|
|
|
|
|
MapToEntity(input, product); |
|
|
|
@ -118,15 +118,12 @@ namespace EasyAbp.EShop.Products.Products |
|
|
|
await _productManager.UpdateAsync(product, input.CategoryIds); |
|
|
|
|
|
|
|
var dto = await MapToGetOutputDtoAsync(product); |
|
|
|
|
|
|
|
|
|
|
|
await LoadDtoExtraDataAsync(product, dto); |
|
|
|
await LoadDtosProductGroupDisplayNameAsync(new[] {dto}); |
|
|
|
await LoadDtosProductGroupDisplayNameAsync(new[] { dto }); |
|
|
|
|
|
|
|
UnitOfWorkManager.Current.OnCompleted(async () => { await ClearProductViewCacheAsync(product.StoreId); }); |
|
|
|
|
|
|
|
UnitOfWorkManager.Current.OnCompleted(async () => |
|
|
|
{ |
|
|
|
await ClearProductViewCacheAsync(product.StoreId); |
|
|
|
}); |
|
|
|
|
|
|
|
return dto; |
|
|
|
} |
|
|
|
|
|
|
|
@ -137,10 +134,10 @@ namespace EasyAbp.EShop.Products.Products |
|
|
|
var usedAttributeOptionIds = new HashSet<Guid>(); |
|
|
|
|
|
|
|
foreach (var serializedAttributeOptionIds in product.ProductSkus.Select(sku => |
|
|
|
sku.SerializedAttributeOptionIds)) |
|
|
|
sku.SerializedAttributeOptionIds)) |
|
|
|
{ |
|
|
|
foreach (var attributeOptionId in await _attributeOptionIdsSerializer.DeserializeAsync( |
|
|
|
serializedAttributeOptionIds)) |
|
|
|
serializedAttributeOptionIds)) |
|
|
|
{ |
|
|
|
usedAttributeOptionIds.Add(attributeOptionId); |
|
|
|
} |
|
|
|
@ -182,9 +179,9 @@ namespace EasyAbp.EShop.Products.Products |
|
|
|
.Except(attributeDto.ProductAttributeOptions.Select(o => o.DisplayName)).ToList(); |
|
|
|
|
|
|
|
if (!isProductSkusEmpty && removedOptionNames.Any() && usedAttributeOptionIds |
|
|
|
.Intersect(attribute.ProductAttributeOptions |
|
|
|
.Where(option => removedOptionNames.Contains(option.DisplayName)) |
|
|
|
.Select(option => option.Id)).Any()) |
|
|
|
.Intersect(attribute.ProductAttributeOptions |
|
|
|
.Where(option => removedOptionNames.Contains(option.DisplayName)) |
|
|
|
.Select(option => option.Id)).Any()) |
|
|
|
{ |
|
|
|
throw new ProductAttributeOptionsDeletionFailedException(); |
|
|
|
} |
|
|
|
@ -217,7 +214,7 @@ namespace EasyAbp.EShop.Products.Products |
|
|
|
var dto = await MapToGetOutputDtoAsync(product); |
|
|
|
|
|
|
|
await LoadDtoExtraDataAsync(product, dto); |
|
|
|
await LoadDtosProductGroupDisplayNameAsync(new[] {dto}); |
|
|
|
await LoadDtosProductGroupDisplayNameAsync(new[] { dto }); |
|
|
|
|
|
|
|
return dto; |
|
|
|
} |
|
|
|
@ -248,7 +245,7 @@ namespace EasyAbp.EShop.Products.Products |
|
|
|
var dto = await MapToGetOutputDtoAsync(product); |
|
|
|
|
|
|
|
await LoadDtoExtraDataAsync(product, dto); |
|
|
|
await LoadDtosProductGroupDisplayNameAsync(new[] {dto}); |
|
|
|
await LoadDtosProductGroupDisplayNameAsync(new[] { dto }); |
|
|
|
|
|
|
|
return dto; |
|
|
|
} |
|
|
|
@ -290,7 +287,10 @@ namespace EasyAbp.EShop.Products.Products |
|
|
|
|
|
|
|
protected virtual async Task<ProductDto> LoadDtoInventoryDataAsync(Product product, ProductDto productDto) |
|
|
|
{ |
|
|
|
var inventoryDataDict = await _productInventoryProvider.GetInventoryDataDictionaryAsync(product); |
|
|
|
var models = product.ProductSkus.Select(x => |
|
|
|
new InventoryQueryModel(product.TenantId, product.StoreId, product.Id, x.Id)).ToList(); |
|
|
|
|
|
|
|
var inventoryDataDict = await _productInventoryProvider.GetSkuIdInventoryDataMappingAsync(models); |
|
|
|
|
|
|
|
productDto.Sold = 0; |
|
|
|
|
|
|
|
@ -313,7 +313,7 @@ namespace EasyAbp.EShop.Products.Products |
|
|
|
|
|
|
|
return productDto; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected virtual async Task<ProductDto> LoadDtoPriceDataAsync(Product product, ProductDto productDto) |
|
|
|
{ |
|
|
|
foreach (var productSku in product.ProductSkus) |
|
|
|
@ -321,7 +321,7 @@ namespace EasyAbp.EShop.Products.Products |
|
|
|
var productSkuDto = productDto.ProductSkus.First(x => x.Id == productSku.Id); |
|
|
|
|
|
|
|
var priceDataModel = await _productManager.GetRealPriceAsync(product, productSku); |
|
|
|
|
|
|
|
|
|
|
|
productSkuDto.Price = priceDataModel.Price; |
|
|
|
productSkuDto.DiscountedPrice = priceDataModel.DiscountedPrice; |
|
|
|
} |
|
|
|
@ -338,17 +338,14 @@ namespace EasyAbp.EShop.Products.Products |
|
|
|
public override async Task DeleteAsync(Guid id) |
|
|
|
{ |
|
|
|
var product = await GetEntityByIdAsync(id); |
|
|
|
|
|
|
|
|
|
|
|
await CheckMultiStorePolicyAsync(product.StoreId, DeletePolicyName); |
|
|
|
|
|
|
|
|
|
|
|
CheckProductIsNotStatic(product); |
|
|
|
|
|
|
|
await _productManager.DeleteAsync(product); |
|
|
|
|
|
|
|
UnitOfWorkManager.Current.OnCompleted(async () => |
|
|
|
{ |
|
|
|
await ClearProductViewCacheAsync(product.StoreId); |
|
|
|
}); |
|
|
|
|
|
|
|
UnitOfWorkManager.Current.OnCompleted(async () => { await ClearProductViewCacheAsync(product.StoreId); }); |
|
|
|
} |
|
|
|
|
|
|
|
private static void CheckProductIsNotStatic(Product product) |
|
|
|
@ -362,9 +359,9 @@ namespace EasyAbp.EShop.Products.Products |
|
|
|
public async Task<ProductDto> CreateSkuAsync(Guid productId, CreateProductSkuDto input) |
|
|
|
{ |
|
|
|
var product = await GetEntityByIdAsync(productId); |
|
|
|
|
|
|
|
|
|
|
|
await CheckMultiStorePolicyAsync(product.StoreId, UpdatePolicyName); |
|
|
|
|
|
|
|
|
|
|
|
CheckProductIsNotStatic(product); |
|
|
|
|
|
|
|
var sku = ObjectMapper.Map<CreateProductSkuDto, ProductSku>(input); |
|
|
|
@ -374,15 +371,12 @@ namespace EasyAbp.EShop.Products.Products |
|
|
|
await _productManager.CreateSkuAsync(product, sku); |
|
|
|
|
|
|
|
var dto = await MapToGetOutputDtoAsync(product); |
|
|
|
|
|
|
|
|
|
|
|
await LoadDtoExtraDataAsync(product, dto); |
|
|
|
await LoadDtosProductGroupDisplayNameAsync(new[] {dto}); |
|
|
|
await LoadDtosProductGroupDisplayNameAsync(new[] { dto }); |
|
|
|
|
|
|
|
UnitOfWorkManager.Current.OnCompleted(async () => { await ClearProductViewCacheAsync(product.StoreId); }); |
|
|
|
|
|
|
|
UnitOfWorkManager.Current.OnCompleted(async () => |
|
|
|
{ |
|
|
|
await ClearProductViewCacheAsync(product.StoreId); |
|
|
|
}); |
|
|
|
|
|
|
|
return dto; |
|
|
|
} |
|
|
|
|
|
|
|
@ -401,15 +395,12 @@ namespace EasyAbp.EShop.Products.Products |
|
|
|
await _productManager.UpdateSkuAsync(product, sku); |
|
|
|
|
|
|
|
var dto = await MapToGetOutputDtoAsync(product); |
|
|
|
|
|
|
|
|
|
|
|
await LoadDtoExtraDataAsync(product, dto); |
|
|
|
await LoadDtosProductGroupDisplayNameAsync(new[] {dto}); |
|
|
|
await LoadDtosProductGroupDisplayNameAsync(new[] { dto }); |
|
|
|
|
|
|
|
UnitOfWorkManager.Current.OnCompleted(async () => { await ClearProductViewCacheAsync(product.StoreId); }); |
|
|
|
|
|
|
|
UnitOfWorkManager.Current.OnCompleted(async () => |
|
|
|
{ |
|
|
|
await ClearProductViewCacheAsync(product.StoreId); |
|
|
|
}); |
|
|
|
|
|
|
|
return dto; |
|
|
|
} |
|
|
|
|
|
|
|
@ -426,15 +417,12 @@ namespace EasyAbp.EShop.Products.Products |
|
|
|
await _productManager.DeleteSkuAsync(product, sku); |
|
|
|
|
|
|
|
var dto = await MapToGetOutputDtoAsync(product); |
|
|
|
|
|
|
|
|
|
|
|
await LoadDtoExtraDataAsync(product, dto); |
|
|
|
await LoadDtosProductGroupDisplayNameAsync(new[] {dto}); |
|
|
|
await LoadDtosProductGroupDisplayNameAsync(new[] { dto }); |
|
|
|
|
|
|
|
UnitOfWorkManager.Current.OnCompleted(async () => { await ClearProductViewCacheAsync(product.StoreId); }); |
|
|
|
|
|
|
|
UnitOfWorkManager.Current.OnCompleted(async () => |
|
|
|
{ |
|
|
|
await ClearProductViewCacheAsync(product.StoreId); |
|
|
|
}); |
|
|
|
|
|
|
|
return dto; |
|
|
|
} |
|
|
|
|
|
|
|
|