Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
C
com.showcase.synapse.sales
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
com.showcase.synapse
com.showcase.synapse.sales
Commits
d431c27c
Commit
d431c27c
authored
Sep 13, 2023
by
lemin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cccc
parent
b2ab17e0
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
62 additions
and
12 deletions
+62
-12
CreateDeliveryCommand.java
...howcase/synapse/common/command/CreateDeliveryCommand.java
+24
-0
SalesAggregate.java
.../com/showcase/synapse/sales/aggregate/SalesAggregate.java
+1
-2
SalesEntity.java
...n/java/com/showcase/synapse/sales/entity/SalesEntity.java
+1
-1
SalesEventHandler.java
...owcase/synapse/sales/event/handler/SalesEventHandler.java
+10
-9
SalesSaga.java
src/main/java/com/showcase/synapse/sales/saga/SalesSaga.java
+26
-0
No files found.
src/main/java/com/showcase/synapse/common/command/CreateDeliveryCommand.java
0 → 100644
View file @
d431c27c
package
com
.
showcase
.
synapse
.
common
.
command
;
import
java.io.Serializable
;
import
org.axonframework.modelling.command.TargetAggregateIdentifier
;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
@AllArgsConstructor
@Getter
public
class
CreateDeliveryCommand
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
@TargetAggregateIdentifier
private
String
deliveryOrderId
;
private
String
salesOrderId
;
private
String
whId
;
private
String
orderComment
;
private
Integer
orderQuantity
;
private
String
orderName
;
}
src/main/java/com/showcase/synapse/sales/aggregate/SalesAggregate.java
View file @
d431c27c
...
...
@@ -50,8 +50,7 @@ public class SalesAggregate {
@CommandHandler
public
void
cancelSalesOrder
(
CancleSalesCommand
command
)
{
log
.
info
(
"[@CommandHandler cancelSalesOrder CancleSalesCommand]"
);
// if(this.quantiy < command.getQuantity()) throw new IllegalArgumentException("tfy ");
// apply(new SalesQuantityChangedEvent(command.getProductId(), this.quantiy - command.getQuantity()));
apply
(
new
SalesCanceledEvent
(
command
.
getSalesOrderId
()));
}
@EventSourcingHandler
...
...
src/main/java/com/showcase/synapse/sales/entity/SalesEntity.java
View file @
d431c27c
...
...
@@ -31,7 +31,7 @@ public class SalesEntity {
public
void
cancelOrder
()
{
this
.
orderStatus
=
SalesStatus
.
CANCELED
;
if
(
this
.
orderComment
!=
null
&&
!
this
.
orderComment
.
isEmpty
())
{
this
.
orderComment
.
concat
(
" : order["
+
salesOrderId
+
"], ["
+
orderName
+
"] cancled by over qty."
);
this
.
orderComment
=
this
.
orderComment
.
concat
(
" : order["
+
salesOrderId
+
"], ["
+
orderName
+
"] cancled by over qty."
);
}
}
}
src/main/java/com/showcase/synapse/sales/event/handler/SalesEventHandler.java
View file @
d431c27c
package
com
.
showcase
.
synapse
.
sales
.
event
.
handler
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.axonframework.eventhandling.EventHandler
;
import
org.springframework.stereotype.Component
;
import
com.showcase.synapse.sales.entity.SalesEntity
;
import
com.showcase.synapse.sales.enums.SalesStatus
;
import
com.showcase.synapse.sales.event.SalesCanceledEvent
;
import
com.showcase.synapse.sales.event.SalesCreatedEvent
;
import
com.showcase.synapse.sales.event.SalesQuantityChangedEvent
;
import
com.showcase.synapse.sales.repository.SalesRepository
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
@Component
@AllArgsConstructor
@Slf4j
...
...
@@ -36,12 +37,12 @@ public class SalesEventHandler {
}
@EventHandler
protected
void
changeOrderQuantity
(
Sales
QuantityChangedEvent
salesQuantityChang
edEvent
)
{
log
.
info
(
"Sales
QuantityChang
edEvent 이벤트 받음?"
);
log
.
info
(
"[
SalesQuantityChangedEvent]
"
);
SalesEntity
salesEntity
=
salesRepository
.
findById
(
salesQuantityChang
edEvent
.
getSalesOrderId
()).
get
();
// log.info("[{}] quantity:{}", productEntity.getName(), productEntity.getQuentity()
);
// productEntity.setQuentity(productQuantityChangedEvent.getQuantity
());
protected
void
changeOrderQuantity
(
Sales
CanceledEvent
SalesCancel
edEvent
)
{
log
.
info
(
"Sales
Cancel
edEvent 이벤트 받음?"
);
log
.
info
(
"[
changeOrderQuantity] SalesCanceledEvent
"
);
SalesEntity
salesEntity
=
salesRepository
.
findById
(
SalesCancel
edEvent
.
getSalesOrderId
()).
get
();
salesEntity
.
cancelOrder
(
);
log
.
info
(
"[OrderComment]:{}"
,
salesEntity
.
getOrderComment
());
salesRepository
.
save
(
salesEntity
);
}
...
...
src/main/java/com/showcase/synapse/sales/saga/SalesSaga.java
View file @
d431c27c
package
com
.
showcase
.
synapse
.
sales
.
saga
;
import
java.util.UUID
;
import
org.axonframework.commandhandling.CommandCallback
;
import
org.axonframework.commandhandling.CommandMessage
;
import
org.axonframework.commandhandling.CommandResultMessage
;
...
...
@@ -11,6 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
com.showcase.synapse.common.command.CancleSalesCommand
;
import
com.showcase.synapse.common.command.ChangeInventoryQuantityCommand
;
import
com.showcase.synapse.common.command.CreateDeliveryCommand
;
import
com.showcase.synapse.sales.event.SalesCreatedEvent
;
import
lombok.extern.slf4j.Slf4j
;
...
...
@@ -40,8 +43,31 @@ public class SalesSaga {
// 보상 transaction
log
.
info
(
"[주문 qty over에 대한 보상Transaction -> 주문은 취소] cancel order"
);
commandGateway
.
send
(
new
CancleSalesCommand
(
event
.
getSalesOrderId
(),
event
.
getOrderQuantity
()));
}
else
{
log
.
info
(
"[주문 qty 정상] -> create delivery order"
);
createDeliveryOrder
(
event
);
}
}
private
void
createDeliveryOrder
(
SalesCreatedEvent
event
)
{
log
.
info
(
"[SalesSaga] createDeliveryOrder"
);
log
.
info
(
"event.getSalesOrderId() === "
+
event
.
getSalesOrderId
());
log
.
info
(
"event.getOrderComment() === "
+
event
.
getOrderComment
());
log
.
info
(
"event.getOrderQuantity() === "
+
event
.
getOrderQuantity
());
log
.
info
(
"event.getWhId() === "
+
event
.
getWhId
());
log
.
info
(
"event.getOrderName() === "
+
event
.
getOrderName
());
CreateDeliveryCommand
cdc
=
new
CreateDeliveryCommand
(
UUID
.
randomUUID
().
toString
(),
event
.
getSalesOrderId
(),
event
.
getWhId
(),
event
.
getOrderComment
(),
event
.
getOrderQuantity
(),
event
.
getOrderName
());
commandGateway
.
send
(
cdc
,
new
CommandCallback
<
CreateDeliveryCommand
,
Object
>()
{
@Override
public
void
onResult
(
CommandMessage
<?
extends
CreateDeliveryCommand
>
commandMessage
,
CommandResultMessage
<?>
commandResultMessage
)
{
log
.
info
(
"CreateDeliveryCommand onResult commandResultMessage.isExceptional() = "
+
commandResultMessage
.
isExceptional
());
if
(
commandResultMessage
.
isExceptional
()){
log
.
info
(
"[CreateDeliveryCommand] Exception!!!"
);
}
}
});
}
});
}
}
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