Browse Source

Use `MultiStoreCrudAppService` replace `CrudAppService`

pull/184/head
Jadyn 4 years ago
parent
commit
889fff0cd5
  1. 3
      plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Application.Contracts/EasyAbp/EShop/Plugins/FlashSales/FlashSalesPlans/Dtos/FlashSalesPlanCreateOrUpdateDtoBase.cs
  2. 1
      plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Application.Contracts/EasyAbp/EShop/Plugins/FlashSales/Permissions/FlashSalesPermissionDefinitionProvider.cs
  3. 1
      plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Application.Contracts/EasyAbp/EShop/Plugins/FlashSales/Permissions/FlashSalesPermissions.cs
  4. 108
      plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Application/EasyAbp/EShop/Plugins/FlashSales/FlashSalesPlans/FlashSalesPlanAppService.cs
  5. 3
      plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Domain/EasyAbp/EShop/Plugins/FlashSales/FlashSalesPlans/FlashSalesPlan.cs

3
plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Application.Contracts/EasyAbp/EShop/Plugins/FlashSales/FlashSalesPlans/Dtos/FlashSalesPlanCreateOrUpdateDtoBase.cs

@ -1,10 +1,11 @@
using System;
using EasyAbp.EShop.Stores.Stores;
using Volo.Abp.Application.Dtos;
namespace EasyAbp.EShop.Plugins.FlashSales.FlashSalesPlans.Dtos;
[Serializable]
public abstract class FlashSalesPlanCreateOrUpdateDtoBase : ExtensibleEntityDto
public abstract class FlashSalesPlanCreateOrUpdateDtoBase : ExtensibleEntityDto, IMultiStore
{
public Guid StoreId { get; set; }

1
plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Application.Contracts/EasyAbp/EShop/Plugins/FlashSales/Permissions/FlashSalesPermissionDefinitionProvider.cs

@ -12,6 +12,7 @@ public class FlashSalesPermissionDefinitionProvider : PermissionDefinitionProvid
var flashSalesPlanPermission = myGroup.AddPermission(FlashSalesPermissions.FlashSalesPlan.Default, L("Permission:FlashSalesPlan"));
flashSalesPlanPermission.AddChild(FlashSalesPermissions.FlashSalesPlan.Manage, L("Permission:Manage"));
flashSalesPlanPermission.AddChild(FlashSalesPermissions.FlashSalesPlan.CrossStore, L("Permission:CrossStore"));
flashSalesPlanPermission.AddChild(FlashSalesPermissions.FlashSalesPlan.Create, L("Permission:Create"));
flashSalesPlanPermission.AddChild(FlashSalesPermissions.FlashSalesPlan.Update, L("Permission:Update"));
flashSalesPlanPermission.AddChild(FlashSalesPermissions.FlashSalesPlan.Delete, L("Permission:Delete"));

1
plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Application.Contracts/EasyAbp/EShop/Plugins/FlashSales/Permissions/FlashSalesPermissions.cs

@ -15,6 +15,7 @@ public class FlashSalesPermissions
{
public const string Default = GroupName + ".FlashSalesPlan";
public const string Manage = Default + ".Manage";
public const string CrossStore = Default + ".CrossStore";
public const string Update = Default + ".Update";
public const string Create = Default + ".Create";
public const string Delete = Default + ".Delete";

108
plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Application/EasyAbp/EShop/Plugins/FlashSales/FlashSalesPlans/FlashSalesPlanAppService.cs

@ -6,11 +6,10 @@ using EasyAbp.EShop.Plugins.FlashSales.FlashSalesResults;
using EasyAbp.EShop.Plugins.FlashSales.Permissions;
using EasyAbp.EShop.Products.Products;
using EasyAbp.EShop.Products.Products.Dtos;
using EasyAbp.EShop.Stores.Authorization;
using EasyAbp.EShop.Stores.Stores;
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Caching.Distributed;
using Volo.Abp;
using Volo.Abp.Application.Services;
using Volo.Abp.Caching;
using Volo.Abp.Data;
using Volo.Abp.DistributedLocking;
@ -23,9 +22,10 @@ namespace EasyAbp.EShop.Plugins.FlashSales.FlashSalesPlans;
[Authorize]
public class FlashSalesPlanAppService :
CrudAppService<FlashSalesPlan, FlashSalesPlanDto, Guid, FlashSalesPlanGetListInput, FlashSalesPlanCreateDto, FlashSalesPlanUpdateDto>,
MultiStoreCrudAppService<FlashSalesPlan, FlashSalesPlanDto, Guid, FlashSalesPlanGetListInput, FlashSalesPlanCreateDto, FlashSalesPlanUpdateDto>,
IFlashSalesPlanAppService
{
protected override string CrossStorePolicyName { get; set; } = FlashSalesPermissions.FlashSalesPlan.CrossStore;
protected override string GetPolicyName { get; set; }
protected override string GetListPolicyName { get; set; }
protected override string CreatePolicyName { get; set; } = FlashSalesPermissions.FlashSalesPlan.Create;
@ -71,13 +71,13 @@ public class FlashSalesPlanAppService :
public override async Task<FlashSalesPlanDto> GetAsync(Guid id)
{
await CheckGetPolicyAsync();
var flashSalesPlan = await GetEntityByIdAsync(id);
await CheckMultiStorePolicyAsync(flashSalesPlan.StoreId, GetPolicyName);
if (!flashSalesPlan.IsPublished)
{
await CheckPolicyAsync(FlashSalesPermissions.FlashSalesPlan.Manage);
await CheckMultiStorePolicyAsync(flashSalesPlan.StoreId, FlashSalesPermissions.FlashSalesPlan.Manage);
}
return await MapToGetOutputDtoAsync(flashSalesPlan);
@ -85,7 +85,7 @@ public class FlashSalesPlanAppService :
public override async Task<FlashSalesPlanDto> CreateAsync(FlashSalesPlanCreateDto input)
{
await AuthorizationService.CheckMultiStorePolicyAsync(input.StoreId, CreatePolicyName);
await CheckMultiStorePolicyAsync(input.StoreId, CreatePolicyName);
var product = await ProductAppService.GetAsync(input.ProductId);
var productSku = product.FindSkuById(input.ProductSkuId);
@ -118,7 +118,7 @@ public class FlashSalesPlanAppService :
public override async Task<FlashSalesPlanDto> UpdateAsync(Guid id, FlashSalesPlanUpdateDto input)
{
await AuthorizationService.CheckMultiStorePolicyAsync(input.StoreId, UpdatePolicyName);
await CheckMultiStorePolicyAsync(input.StoreId, UpdatePolicyName);
var product = await ProductAppService.GetAsync(input.ProductId);
var productSku = product.FindSkuById(input.ProductSkuId);
@ -150,7 +150,7 @@ public class FlashSalesPlanAppService :
{
var flashSalesPlan = await GetEntityByIdAsync(id);
await AuthorizationService.CheckMultiStorePolicyAsync(flashSalesPlan.StoreId, DeletePolicyName);
await CheckMultiStorePolicyAsync(flashSalesPlan.StoreId, DeletePolicyName);
await FlashSalesPlanRepository.DeleteAsync(flashSalesPlan);
}
@ -159,14 +159,14 @@ public class FlashSalesPlanAppService :
{
if (input.IncludeUnpublished)
{
await CheckPolicyAsync(FlashSalesPermissions.FlashSalesPlan.Manage);
await CheckMultiStorePolicyAsync(input.StoreId, FlashSalesPermissions.FlashSalesPlan.Manage);
}
return (await base.CreateFilteredQueryAsync(input))
.WhereIf(input.StoreId.HasValue, x => x.StoreId == input.StoreId.Value)
.WhereIf(input.ProductId.HasValue, x => x.ProductId == input.ProductId.Value)
.WhereIf(input.ProductSkuId.HasValue, x => x.ProductSkuId == input.ProductSkuId.Value)
.WhereIf(!input.IncludeUnpublished , x => x.IsPublished)
.WhereIf(!input.IncludeUnpublished, x => x.IsPublished)
.WhereIf(input.Start.HasValue, x => x.BeginTime >= input.Start.Value)
.WhereIf(input.End.HasValue, x => x.BeginTime <= input.End.Value);
}
@ -177,30 +177,7 @@ public class FlashSalesPlanAppService :
var product = await ProductAppService.GetAsync(plan.ProductId);
var productSku = product.GetSkuById(plan.ProductSkuId);
if (!product.IsPublished)
{
throw new BusinessException(FlashSalesErrorCodes.ProductIsNotPublished);
}
if (product.InventoryStrategy != InventoryStrategy.FlashSales)
{
throw new UnexpectedInventoryStrategyException(InventoryStrategy.FlashSales);
}
if (!plan.IsPublished)
{
throw new EntityNotFoundException(typeof(FlashSalesPlan), id);
}
if (Clock.Now >= plan.EndTime)
{
throw new BusinessException(FlashSalesErrorCodes.FlashSaleIsOver);
}
if (productSku.Inventory < 1)
{
throw new BusinessException(FlashSalesErrorCodes.ProductSkuInventoryExceeded);
}
await CheckPreOrderAsync(plan, product, productSku);
await SetCacheHashTokenAsync(plan, product, productSku);
}
@ -208,10 +185,6 @@ public class FlashSalesPlanAppService :
public virtual async Task CheckPreOrderAsync(Guid id)
{
var plan = await GetFlashSalesPlanCacheAsync(id);
if (Clock.Now > plan.EndTime)
{
throw new BusinessException(FlashSalesErrorCodes.FlashSaleIsOver);
}
var cacheHashToken = await GetCacheHashTokenAsync(plan);
if (cacheHashToken.IsNullOrWhiteSpace())
@ -227,30 +200,7 @@ public class FlashSalesPlanAppService :
throw new BusinessException(FlashSalesErrorCodes.PreOrderExpired);
}
if (!product.IsPublished)
{
throw new BusinessException(FlashSalesErrorCodes.ProductIsNotPublished);
}
if (product.InventoryStrategy != InventoryStrategy.FlashSales)
{
throw new UnexpectedInventoryStrategyException(InventoryStrategy.FlashSales);
}
if (!plan.IsPublished)
{
throw new EntityNotFoundException(typeof(FlashSalesPlan), id);
}
if (Clock.Now >= plan.EndTime)
{
throw new BusinessException(FlashSalesErrorCodes.FlashSaleIsOver);
}
if (productSku.Inventory < 1)
{
throw new BusinessException(FlashSalesErrorCodes.ProductSkuInventoryExceeded);
}
await CheckPreOrderAsync(plan, product, productSku);
}
public virtual async Task CreateOrderAsync(Guid id, CreateOrderInput input)
@ -262,7 +212,7 @@ public class FlashSalesPlanAppService :
throw new BusinessException(FlashSalesErrorCodes.ProductIsNotPublished);
}
if (now > plan.EndTime)
if (now >= plan.EndTime)
{
throw new BusinessException(FlashSalesErrorCodes.FlashSaleIsOver);
}
@ -398,4 +348,34 @@ public class FlashSalesPlanAppService :
);
return await FlashSalesResultRepository.InsertAsync(result, autoSave: true);
}
protected virtual Task CheckPreOrderAsync(FlashSalesPlanCacheItem plan, ProductDto product, ProductSkuDto productSku)
{
if (!product.IsPublished)
{
throw new BusinessException(FlashSalesErrorCodes.ProductIsNotPublished);
}
if (product.InventoryStrategy != InventoryStrategy.FlashSales)
{
throw new UnexpectedInventoryStrategyException(InventoryStrategy.FlashSales);
}
if (!plan.IsPublished)
{
throw new EntityNotFoundException(typeof(FlashSalesPlan), plan.Id);
}
if (Clock.Now >= plan.EndTime)
{
throw new BusinessException(FlashSalesErrorCodes.FlashSaleIsOver);
}
if (productSku.Inventory < 1)
{
throw new BusinessException(FlashSalesErrorCodes.ProductSkuInventoryExceeded);
}
return Task.CompletedTask;
}
}

3
plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Domain/EasyAbp/EShop/Plugins/FlashSales/FlashSalesPlans/FlashSalesPlan.cs

@ -1,10 +1,11 @@
using System;
using EasyAbp.EShop.Stores.Stores;
using Volo.Abp.Domain.Entities.Auditing;
using Volo.Abp.MultiTenancy;
namespace EasyAbp.EShop.Plugins.FlashSales.FlashSalesPlans;
public class FlashSalesPlan : FullAuditedAggregateRoot<Guid>, IMultiTenant
public class FlashSalesPlan : FullAuditedAggregateRoot<Guid>, IMultiTenant, IMultiStore
{
public virtual Guid? TenantId { get; protected set; }

Loading…
Cancel
Save