Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
E
EShop
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
EShop
Commits
01d73b8a
Commit
01d73b8a
authored
May 07, 2020
by
gdlcf88
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added TenantId to Etos
parent
c6a81c9a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
60 additions
and
42 deletions
+60
-42
OrderEto.cs
...ers.Domain.Shared/EasyAbp/EShop/Orders/Orders/OrderEto.cs
+2
-0
OrderProductInventoryReductionEventHandler.cs
...ders/Orders/OrderProductInventoryReductionEventHandler.cs
+19
-12
ProductInventoryReductionAfterOrderPlacedResultEto.cs
...cts/ProductInventoryReductionAfterOrderPlacedResultEto.cs
+2
-0
OrderCreatedEventHandler.cs
...syAbp/EShop/Products/Products/OrderCreatedEventHandler.cs
+37
-30
No files found.
modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain.Shared/EasyAbp/EShop/Orders/Orders/OrderEto.cs
View file @
01d73b8a
...
...
@@ -8,6 +8,8 @@ namespace EasyAbp.EShop.Orders.Orders
{
public
Guid
Id
{
get
;
set
;
}
public
Guid
?
TenantId
{
get
;
set
;
}
public
Guid
StoreId
{
get
;
set
;
}
public
Guid
CustomerUserId
{
get
;
set
;
}
...
...
modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp/EShop/Orders/Orders/OrderProductInventoryReductionEventHandler.cs
View file @
01d73b8a
using
System.Threading.Tasks
;
using
EasyAbp.EShop.Products.Products
;
using
Volo.Abp.DependencyInjection
;
using
Volo.Abp.MultiTenancy
;
using
Volo.Abp.Timing
;
using
Volo.Abp.Uow
;
...
...
@@ -9,35 +10,41 @@ namespace EasyAbp.EShop.Orders.Orders
public
class
OrderProductInventoryReductionEventHandler
:
IOrderProductInventoryReductionEventHandler
,
ITransientDependency
{
private
readonly
IClock
_clock
;
private
readonly
ICurrentTenant
_currentTenant
;
private
readonly
IOrderRepository
_orderRepository
;
public
OrderProductInventoryReductionEventHandler
(
IClock
clock
,
ICurrentTenant
currentTenant
,
IOrderRepository
orderRepository
)
{
_clock
=
clock
;
_currentTenant
=
currentTenant
;
_orderRepository
=
orderRepository
;
}
[
UnitOfWork
(
true
)]
public
virtual
async
Task
HandleEventAsync
(
ProductInventoryReductionAfterOrderPlacedResultEto
eventData
)
{
var
order
=
await
_orderRepository
.
GetAsync
(
eventData
.
OrderId
);
if
(
order
.
OrderStatus
!=
OrderStatus
.
Pending
||
order
.
ReducedInventoryAfterPlacingTime
.
HasValue
)
using
(
_currentTenant
.
Change
(
eventData
.
TenantId
))
{
return
;
}
var
order
=
await
_orderRepository
.
GetAsync
(
eventData
.
OrderId
);
if
(!
eventData
.
IsSuccess
)
{
// Todo: Cancel order.
return
;
}
if
(
order
.
OrderStatus
!=
OrderStatus
.
Pending
||
order
.
ReducedInventoryAfterPlacingTime
.
HasValue
)
{
return
;
}
if
(!
eventData
.
IsSuccess
)
{
// Todo: Cancel order.
return
;
}
order
.
SetReducedInventoryAfterPaymentTime
(
_clock
.
Now
);
order
.
SetReducedInventoryAfterPaymentTime
(
_clock
.
Now
);
await
_orderRepository
.
UpdateAsync
(
order
,
true
);
await
_orderRepository
.
UpdateAsync
(
order
,
true
);
}
}
}
}
\ No newline at end of file
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain.Shared/EasyAbp/EShop/Products/Products/ProductInventoryReductionAfterOrderPlacedResultEto.cs
View file @
01d73b8a
...
...
@@ -5,6 +5,8 @@ namespace EasyAbp.EShop.Products.Products
[
Serializable
]
public
class
ProductInventoryReductionAfterOrderPlacedResultEto
{
public
Guid
?
TenantId
{
get
;
set
;
}
public
Guid
OrderId
{
get
;
set
;
}
public
bool
IsSuccess
{
get
;
set
;
}
...
...
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/OrderCreatedEventHandler.cs
View file @
01d73b8a
...
...
@@ -4,23 +4,27 @@ using EasyAbp.EShop.Orders.Orders;
using
Volo.Abp.DependencyInjection
;
using
Volo.Abp.Domain.Entities.Events.Distributed
;
using
Volo.Abp.EventBus.Distributed
;
using
Volo.Abp.MultiTenancy
;
using
Volo.Abp.Uow
;
namespace
EasyAbp.EShop.Products.Products
{
public
class
OrderCreatedEventHandler
:
IOrderCreatedEventHandler
,
ITransientDependency
{
private
readonly
ICurrentTenant
_currentTenant
;
private
readonly
IUnitOfWorkManager
_unitOfWorkManager
;
private
readonly
IDistributedEventBus
_distributedEventBus
;
private
readonly
IProductRepository
_productRepository
;
private
readonly
IProductManager
_productManager
;
public
OrderCreatedEventHandler
(
ICurrentTenant
currentTenant
,
IUnitOfWorkManager
unitOfWorkManager
,
IDistributedEventBus
distributedEventBus
,
IProductRepository
productRepository
,
IProductManager
productManager
)
{
_currentTenant
=
currentTenant
;
_unitOfWorkManager
=
unitOfWorkManager
;
_distributedEventBus
=
distributedEventBus
;
_productRepository
=
productRepository
;
...
...
@@ -29,43 +33,46 @@ namespace EasyAbp.EShop.Products.Products
public
virtual
async
Task
HandleEventAsync
(
EntityCreatedEto
<
OrderEto
>
eventData
)
{
using
var
uow
=
_unitOfWorkManager
.
Begin
(
true
,
true
);
foreach
(
var
orderLine
in
eventData
.
Entity
.
OrderLines
)
using
(
_currentTenant
.
Change
(
eventData
.
Entity
.
TenantId
))
{
var
product
=
await
_productRepository
.
FindAsync
(
orderLine
.
ProductId
);
using
var
uow
=
_unitOfWorkManager
.
Begin
(
true
,
true
);
foreach
(
var
orderLine
in
eventData
.
Entity
.
OrderLines
)
{
var
product
=
await
_productRepository
.
FindAsync
(
orderLine
.
ProductId
);
var
productSku
=
product
?.
ProductSkus
.
FirstOrDefault
(
sku
=>
sku
.
Id
==
orderLine
.
ProductSkuId
);
var
productSku
=
product
?.
ProductSkus
.
FirstOrDefault
(
sku
=>
sku
.
Id
==
orderLine
.
ProductSkuId
);
if
(
productSku
==
null
)
{
await
uow
.
RollbackAsync
();
await
_distributedEventBus
.
PublishAsync
(
new
ProductInventoryReductionAfterOrderPlacedResultEto
{
OrderId
=
eventData
.
Entity
.
Id
,
IsSuccess
=
false
});
return
;
}
if
(
productSku
==
null
)
{
await
uow
.
RollbackAsync
();
await
_distributedEventBus
.
PublishAsync
(
new
ProductInventoryReductionAfterOrderPlacedResultEto
{
OrderId
=
eventData
.
Entity
.
Id
,
IsSuccess
=
false
});
return
;
}
if
(
product
.
InventoryStrategy
!=
InventoryStrategy
.
ReduceAfterPlacing
)
{
await
uow
.
RollbackAsync
();
await
_distributedEventBus
.
PublishAsync
(
new
ProductInventoryReductionAfterOrderPlacedResultEto
{
OrderId
=
eventData
.
Entity
.
Id
,
IsSuccess
=
false
});
return
;
}
if
(
product
.
InventoryStrategy
!=
InventoryStrategy
.
ReduceAfterPlacing
)
{
await
uow
.
RollbackAsync
();
await
_distributedEventBus
.
PublishAsync
(
new
ProductInventoryReductionAfterOrderPlacedResultEto
{
OrderId
=
eventData
.
Entity
.
Id
,
IsSuccess
=
false
});
return
;
}
if
(!
await
_productManager
.
TryReduceInventoryAsync
(
product
,
productSku
,
eventData
.
Entity
.
StoreId
,
orderLine
.
Quantity
))
{
await
uow
.
RollbackAsync
();
await
_distributedEventBus
.
PublishAsync
(
new
ProductInventoryReductionAfterOrderPlacedResultEto
{
OrderId
=
eventData
.
Entity
.
Id
,
IsSuccess
=
false
});
return
;
if
(!
await
_productManager
.
TryReduceInventoryAsync
(
product
,
productSku
,
eventData
.
Entity
.
StoreId
,
orderLine
.
Quantity
))
{
await
uow
.
RollbackAsync
();
await
_distributedEventBus
.
PublishAsync
(
new
ProductInventoryReductionAfterOrderPlacedResultEto
{
OrderId
=
eventData
.
Entity
.
Id
,
IsSuccess
=
false
});
return
;
}
}
}
await
uow
.
CompleteAsync
();
await
_distributedEventBus
.
PublishAsync
(
new
ProductInventoryReductionAfterOrderPlacedResultEto
{
OrderId
=
eventData
.
Entity
.
Id
,
IsSuccess
=
true
});
await
uow
.
CompleteAsync
();
await
_distributedEventBus
.
PublishAsync
(
new
ProductInventoryReductionAfterOrderPlacedResultEto
{
OrderId
=
eventData
.
Entity
.
Id
,
IsSuccess
=
true
});
}
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment