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
b2ab17e0
Commit
b2ab17e0
authored
Sep 13, 2023
by
lemin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ccc
parent
dab6eada
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
229 additions
and
63 deletions
+229
-63
CancleSalesCommand.java
...m/showcase/synapse/common/command/CancleSalesCommand.java
+23
-0
ChangeInventoryQuantityCommand.java
...ynapse/common/command/ChangeInventoryQuantityCommand.java
+21
-0
CreateSalesCommand.java
...m/showcase/synapse/common/command/CreateSalesCommand.java
+25
-0
AxonConfig.java
src/main/java/com/showcase/synapse/sales/AxonConfig.java
+20
-0
MsaSalesApplication.java
.../java/com/showcase/synapse/sales/MsaSalesApplication.java
+2
-0
SalesAggregate.java
.../com/showcase/synapse/sales/aggregate/SalesAggregate.java
+24
-16
SalesController.java
...om/showcase/synapse/sales/controller/SalesController.java
+7
-8
SalesCreateDto.java
...n/java/com/showcase/synapse/sales/dto/SalesCreateDto.java
+4
-3
SalesEntity.java
...n/java/com/showcase/synapse/sales/entity/SalesEntity.java
+22
-8
SalesCanceledEvent.java
.../com/showcase/synapse/sales/event/SalesCanceledEvent.java
+10
-0
SalesCreatedEvent.java
...a/com/showcase/synapse/sales/event/SalesCreatedEvent.java
+5
-4
SalesQuantityChangedEvent.java
...owcase/synapse/sales/event/SalesQuantityChangedEvent.java
+3
-2
SalesEventHandler.java
...owcase/synapse/sales/event/handler/SalesEventHandler.java
+16
-13
SalesSaga.java
src/main/java/com/showcase/synapse/sales/saga/SalesSaga.java
+33
-1
SalesService.java
...java/com/showcase/synapse/sales/service/SalesService.java
+9
-8
application.yml
src/main/resources/application.yml
+5
-0
No files found.
src/main/java/com/showcase/synapse/
sales/command/Creat
eSalesCommand.java
→
src/main/java/com/showcase/synapse/
common/command/Cancl
eSalesCommand.java
View file @
b2ab17e0
package
com
.
showcase
.
synapse
.
sales
.
command
;
package
com
.
showcase
.
synapse
.
common
.
command
;
import
lombok.AllArgsConstructor
;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
import
lombok.Getter
;
import
org.axonframework.modelling.command.TargetAggregateIdentifier
;
import
org.axonframework.modelling.command.TargetAggregateIdentifier
;
import
java.io.Serializable
;
import
java.math.BigDecimal
;
import
java.math.BigDecimal
;
import
javax.persistence.EnumType
;
import
javax.persistence.Enumerated
;
@AllArgsConstructor
@AllArgsConstructor
@Getter
@Getter
public
class
CreateSalesCommand
{
public
class
CancleSalesCommand
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
@TargetAggregateIdentifier
@TargetAggregateIdentifier
private
final
String
id
;
private
final
String
salesOrderId
;
private
final
String
name
;
private
final
Integer
orderQuantity
;
private
final
String
comment
;
private
final
BigDecimal
price
;
// private final Integer quantity;
}
}
src/main/java/com/showcase/synapse/
sales/command/ChangeSales
QuantityCommand.java
→
src/main/java/com/showcase/synapse/
common/command/ChangeInventory
QuantityCommand.java
View file @
b2ab17e0
package
com
.
showcase
.
synapse
.
sales
.
command
;
package
com
.
showcase
.
synapse
.
common
.
command
;
import
java.io.Serializable
;
import
org.axonframework.modelling.command.TargetAggregateIdentifier
;
import
org.axonframework.modelling.command.TargetAggregateIdentifier
;
...
@@ -7,9 +9,13 @@ import lombok.Getter;
...
@@ -7,9 +9,13 @@ import lombok.Getter;
@AllArgsConstructor
@AllArgsConstructor
@Getter
@Getter
public
class
ChangeSalesQuantityCommand
{
public
class
ChangeInventoryQuantityCommand
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
@TargetAggregateIdentifier
@TargetAggregateIdentifier
private
String
productId
;
private
String
salesOrderId
;
private
int
quantity
;
private
String
whId
;
private
String
orderComment
;
private
Integer
orderQuantity
;
}
}
src/main/java/com/showcase/synapse/common/command/CreateSalesCommand.java
0 → 100644
View file @
b2ab17e0
package
com
.
showcase
.
synapse
.
common
.
command
;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
import
org.axonframework.modelling.command.TargetAggregateIdentifier
;
import
java.io.Serializable
;
import
java.math.BigDecimal
;
import
javax.persistence.EnumType
;
import
javax.persistence.Enumerated
;
@AllArgsConstructor
@Getter
public
class
CreateSalesCommand
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
@TargetAggregateIdentifier
private
final
String
salesOrderId
;
private
final
String
whId
;
private
final
String
orderName
;
private
final
String
orderComment
;
private
final
Integer
orderQuantity
;
}
src/main/java/com/showcase/synapse/sales/AxonConfig.java
0 → 100644
View file @
b2ab17e0
package
com
.
showcase
.
synapse
.
sales
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
com.thoughtworks.xstream.XStream
;
@Configuration
public
class
AxonConfig
{
@Bean
public
XStream
xStream
()
{
XStream
xStream
=
new
XStream
();
xStream
.
allowTypesByWildcard
(
new
String
[]
{
"com.showcase.synapse.**"
});
return
xStream
;
}
}
\ No newline at end of file
src/main/java/com/showcase/synapse/sales/MsaSalesApplication.java
View file @
b2ab17e0
...
@@ -2,8 +2,10 @@ package com.showcase.synapse.sales;
...
@@ -2,8 +2,10 @@ package com.showcase.synapse.sales;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.context.annotation.Import
;
@SpringBootApplication
@SpringBootApplication
@Import
({
AxonConfig
.
class
})
public
class
MsaSalesApplication
{
public
class
MsaSalesApplication
{
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
...
...
src/main/java/com/showcase/synapse/sales/aggregate/SalesAggregate.java
View file @
b2ab17e0
package
com
.
showcase
.
synapse
.
sales
.
aggregate
;
package
com
.
showcase
.
synapse
.
sales
.
aggregate
;
import
lombok.NoArgsConstructor
;
import
static
org
.
axonframework
.
modelling
.
command
.
AggregateLifecycle
.
apply
;
import
lombok.extern.slf4j.Slf4j
;
import
org.axonframework.commandhandling.CommandHandler
;
import
org.axonframework.commandhandling.CommandHandler
;
import
org.axonframework.eventsourcing.EventSourcingHandler
;
import
org.axonframework.eventsourcing.EventSourcingHandler
;
import
org.axonframework.modelling.command.AggregateIdentifier
;
import
org.axonframework.modelling.command.AggregateIdentifier
;
import
org.axonframework.spring.stereotype.Aggregate
;
import
org.axonframework.spring.stereotype.Aggregate
;
import
com.showcase.synapse.sales.command.ChangeSalesQuantityCommand
;
import
com.showcase.synapse.common.command.CancleSalesCommand
;
import
com.showcase.synapse.sales.command.CreateSalesCommand
;
import
com.showcase.synapse.common.command.CreateSalesCommand
;
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.SalesCreatedEvent
;
import
com.showcase.synapse.sales.event.SalesQuantityChangedEvent
;
import
com.showcase.synapse.sales.event.SalesQuantityChangedEvent
;
import
com.showcase.synapse.sales.saga.SalesSaga
;
import
java.math.BigDecimal
;
import
lombok.NoArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
static
org
.
axonframework
.
modelling
.
command
.
AggregateLifecycle
.
apply
;
@Aggregate
@Aggregate
@NoArgsConstructor
@NoArgsConstructor
...
@@ -25,30 +24,39 @@ public class SalesAggregate {
...
@@ -25,30 +24,39 @@ public class SalesAggregate {
@AggregateIdentifier
@AggregateIdentifier
private
String
id
;
private
String
id
;
// private int quantiy;
private
int
orderQuantity
;
private
SalesStatus
salesStatus
;
@CommandHandler
@CommandHandler
public
SalesAggregate
(
CreateSalesCommand
command
)
{
public
SalesAggregate
(
CreateSalesCommand
command
)
{
log
.
info
(
"[SalesAggregate(CreateSalesCommand) > apply new SalesCreatedEvent]"
);
log
.
info
(
"[SalesAggregate(CreateSalesCommand) > apply new SalesCreatedEvent]"
);
apply
(
new
SalesCreatedEvent
(
command
.
getId
(),
command
.
getName
(),
command
.
getComment
(),
command
.
getPrice
()));
apply
(
new
SalesCreatedEvent
(
command
.
getSalesOrderId
(),
command
.
getWhId
(),
command
.
getOrderName
(),
command
.
getOrderComment
(),
command
.
getOrderQuantity
()));
}
}
@EventSourcingHandler
@EventSourcingHandler
public
void
createProduct
(
SalesCreatedEvent
event
)
{
public
void
createSalesOrder
(
SalesCreatedEvent
event
)
{
this
.
id
=
event
.
getProductId
();
this
.
id
=
event
.
getSalesOrderId
();
// this.quantiy = event.getQuantity();
this
.
orderQuantity
=
event
.
getOrderQuantity
();
this
.
salesStatus
=
SalesStatus
.
CREATED
;
}
@EventSourcingHandler
public
void
cancelSalesOrder
(
SalesCanceledEvent
event
)
{
this
.
salesStatus
=
SalesStatus
.
CANCELED
;
}
}
@CommandHandler
@CommandHandler
public
void
c
hangeQuantity
(
ChangeSalesQuantity
Command
command
)
{
public
void
c
ancelSalesOrder
(
CancleSales
Command
command
)
{
log
.
info
(
"[@CommandHandler
ProductchangeQuantity
]"
);
log
.
info
(
"[@CommandHandler
cancelSalesOrder CancleSalesCommand
]"
);
// if(this.quantiy < command.getQuantity()) throw new IllegalArgumentException("tfy ");
// if(this.quantiy < command.getQuantity()) throw new IllegalArgumentException("tfy ");
// apply(new SalesQuantityChangedEvent(command.getProductId(), this.quantiy - command.getQuantity()));
// apply(new SalesQuantityChangedEvent(command.getProductId(), this.quantiy - command.getQuantity()));
}
}
@EventSourcingHandler
@EventSourcingHandler
public
void
changeQuantity
(
SalesQuantityChangedEvent
event
)
{
public
void
changeSalesQuantity
(
SalesQuantityChangedEvent
event
)
{
log
.
info
(
"[@CommandHandler changeSalesQuantity SalesQuantityChangedEvent]"
);
// this.quantiy = event.getQuantity();
// this.quantiy = event.getQuantity();
}
}
...
...
src/main/java/com/showcase/synapse/sales/controller/SalesController.java
View file @
b2ab17e0
package
com
.
showcase
.
synapse
.
sales
.
controller
;
package
com
.
showcase
.
synapse
.
sales
.
controller
;
import
java.math.BigDecimal
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -16,7 +15,6 @@ import org.springframework.web.bind.annotation.RestController;
...
@@ -16,7 +15,6 @@ import org.springframework.web.bind.annotation.RestController;
import
com.showcase.synapse.sales.dto.ProductSalesDto
;
import
com.showcase.synapse.sales.dto.ProductSalesDto
;
import
com.showcase.synapse.sales.dto.SalesCreateDto
;
import
com.showcase.synapse.sales.dto.SalesCreateDto
;
import
com.showcase.synapse.sales.entity.ProductEntity
;
import
com.showcase.synapse.sales.entity.SalesEntity
;
import
com.showcase.synapse.sales.entity.SalesEntity
;
import
com.showcase.synapse.sales.service.SalesService
;
import
com.showcase.synapse.sales.service.SalesService
;
...
@@ -44,13 +42,14 @@ public class SalesController {
...
@@ -44,13 +42,14 @@ public class SalesController {
}
}
@PostMapping
(
"/"
)
@PostMapping
(
"/"
)
public
ResponseEntity
<
Map
<
String
,
String
>>
productCreate
(
@RequestBody
SalesCreateDto
productCreateDto
)
{
public
ResponseEntity
<
Map
<
String
,
String
>>
salesCreate
(
@RequestBody
SalesCreateDto
salesCreateDto
)
{
String
productId
=
salesService
.
createProduct
(
productCreateDto
.
getName
(),
String
salesOrderId
=
salesService
.
createSales
(
salesCreateDto
.
getWhId
(),
productCreateDto
.
getComment
(),
salesCreateDto
.
getOrderName
(),
BigDecimal
.
valueOf
(
productCreateDto
.
getPrice
()));
salesCreateDto
.
getOrderComment
(),
salesCreateDto
.
getOrderQuantity
());
HashMap
<
String
,
String
>
m
=
new
HashMap
<>();
HashMap
<
String
,
String
>
m
=
new
HashMap
<>();
m
.
put
(
"
productId"
,
product
Id
);
m
.
put
(
"
salesOrderId"
,
salesOrder
Id
);
m
.
put
(
"
productName"
,
productCreateDto
.
getName
(
));
m
.
put
(
"
orderQuantity"
,
String
.
valueOf
(
salesCreateDto
.
getOrderQuantity
()
));
return
ResponseEntity
.
ok
(
m
);
return
ResponseEntity
.
ok
(
m
);
}
}
...
...
src/main/java/com/showcase/synapse/sales/dto/SalesCreateDto.java
View file @
b2ab17e0
...
@@ -6,8 +6,9 @@ import lombok.Setter;
...
@@ -6,8 +6,9 @@ import lombok.Setter;
@Getter
@Getter
@Setter
@Setter
public
class
SalesCreateDto
{
public
class
SalesCreateDto
{
private
String
name
;
private
String
whId
;
private
String
comment
;
private
String
orderName
;
private
int
price
;
private
String
orderComment
;
private
Integer
orderQuantity
;
}
}
src/main/java/com/showcase/synapse/sales/entity/SalesEntity.java
View file @
b2ab17e0
package
com
.
showcase
.
synapse
.
sales
.
entity
;
package
com
.
showcase
.
synapse
.
sales
.
entity
;
import
javax.persistence.Entity
;
import
javax.persistence.EnumType
;
import
javax.persistence.Enumerated
;
import
javax.persistence.Id
;
import
com.showcase.synapse.sales.enums.SalesStatus
;
import
lombok.AllArgsConstructor
;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
import
lombok.Getter
;
import
lombok.NoArgsConstructor
;
import
lombok.NoArgsConstructor
;
import
lombok.Setter
;
import
lombok.Setter
;
import
javax.persistence.Entity
;
import
javax.persistence.Id
;
import
java.math.BigDecimal
;
@Entity
@Entity
@Getter
@Getter
@Setter
@Setter
...
@@ -16,8 +19,19 @@ import java.math.BigDecimal;
...
@@ -16,8 +19,19 @@ import java.math.BigDecimal;
@NoArgsConstructor
@NoArgsConstructor
public
class
SalesEntity
{
public
class
SalesEntity
{
@Id
@Id
private
String
id
;
private
String
salesOrderId
;
private
String
name
;
private
String
whId
;
private
String
comment
;
private
String
orderName
;
private
BigDecimal
price
;
private
String
orderComment
;
private
Integer
orderQuantity
;
@Enumerated
(
EnumType
.
STRING
)
private
SalesStatus
orderStatus
;
public
void
cancelOrder
()
{
this
.
orderStatus
=
SalesStatus
.
CANCELED
;
if
(
this
.
orderComment
!=
null
&&
!
this
.
orderComment
.
isEmpty
())
{
this
.
orderComment
.
concat
(
" : order["
+
salesOrderId
+
"], ["
+
orderName
+
"] cancled by over qty."
);
}
}
}
}
src/main/java/com/showcase/synapse/sales/event/SalesCanceledEvent.java
0 → 100644
View file @
b2ab17e0
package
com
.
showcase
.
synapse
.
sales
.
event
;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
@AllArgsConstructor
@Getter
public
class
SalesCanceledEvent
{
private
String
salesOrderId
;
}
src/main/java/com/showcase/synapse/sales/event/SalesCreatedEvent.java
View file @
b2ab17e0
...
@@ -8,8 +8,9 @@ import java.math.BigDecimal;
...
@@ -8,8 +8,9 @@ import java.math.BigDecimal;
@AllArgsConstructor
@AllArgsConstructor
@Getter
@Getter
public
class
SalesCreatedEvent
{
public
class
SalesCreatedEvent
{
private
String
productId
;
private
final
String
salesOrderId
;
private
String
name
;
private
final
String
whId
;
private
String
comment
;
private
final
String
orderName
;
private
BigDecimal
price
;
private
final
String
orderComment
;
private
final
Integer
orderQuantity
;
}
}
src/main/java/com/showcase/synapse/sales/event/SalesQuantityChangedEvent.java
View file @
b2ab17e0
...
@@ -6,6 +6,7 @@ import lombok.Getter;
...
@@ -6,6 +6,7 @@ import lombok.Getter;
@AllArgsConstructor
@AllArgsConstructor
@Getter
@Getter
public
class
SalesQuantityChangedEvent
{
public
class
SalesQuantityChangedEvent
{
private
String
productId
;
private
String
salesOrderId
;
private
int
quantity
;
private
String
whId
;
private
int
orderQuantity
;
}
}
src/main/java/com/showcase/synapse/sales/event/handler/SalesEventHandler.java
View file @
b2ab17e0
...
@@ -6,6 +6,7 @@ import org.axonframework.eventhandling.EventHandler;
...
@@ -6,6 +6,7 @@ import org.axonframework.eventhandling.EventHandler;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
com.showcase.synapse.sales.entity.SalesEntity
;
import
com.showcase.synapse.sales.entity.SalesEntity
;
import
com.showcase.synapse.sales.enums.SalesStatus
;
import
com.showcase.synapse.sales.event.SalesCreatedEvent
;
import
com.showcase.synapse.sales.event.SalesCreatedEvent
;
import
com.showcase.synapse.sales.event.SalesQuantityChangedEvent
;
import
com.showcase.synapse.sales.event.SalesQuantityChangedEvent
;
import
com.showcase.synapse.sales.repository.SalesRepository
;
import
com.showcase.synapse.sales.repository.SalesRepository
;
...
@@ -15,31 +16,33 @@ import com.showcase.synapse.sales.repository.SalesRepository;
...
@@ -15,31 +16,33 @@ import com.showcase.synapse.sales.repository.SalesRepository;
@Slf4j
@Slf4j
public
class
SalesEventHandler
{
public
class
SalesEventHandler
{
private
final
SalesRepository
product
Repository
;
private
final
SalesRepository
sales
Repository
;
@EventHandler
@EventHandler
protected
void
save
Product
(
SalesCreatedEvent
productCreatedEvent
)
{
protected
void
save
SalesOrder
(
SalesCreatedEvent
productCreatedEvent
)
{
log
.
info
(
"SalesCreatedEvent 이벤트 받음?"
);
log
.
info
(
"SalesCreatedEvent 이벤트 받음?"
);
log
.
info
(
"SalesEventHandler > [SalesCreatedEvent] productCreatedEvent"
);
log
.
info
(
"SalesEventHandler > [SalesCreatedEvent] SalesCreatedEvent"
);
SalesEntity
productEntity
=
new
SalesEntity
();
SalesEntity
salesEntity
=
new
SalesEntity
();
productEntity
.
setId
(
productCreatedEvent
.
getProductId
());
salesEntity
.
setSalesOrderId
(
productCreatedEvent
.
getSalesOrderId
());
productEntity
.
setName
(
productCreatedEvent
.
getName
());
salesEntity
.
setWhId
(
productCreatedEvent
.
getWhId
());
productEntity
.
setComment
(
productCreatedEvent
.
getComment
());
salesEntity
.
setOrderName
(
productCreatedEvent
.
getOrderName
());
productEntity
.
setPrice
(
productCreatedEvent
.
getPrice
());
salesEntity
.
setOrderComment
(
productCreatedEvent
.
getOrderComment
());
salesEntity
.
setOrderQuantity
(
productCreatedEvent
.
getOrderQuantity
());
productRepository
.
save
(
productEntity
);
salesEntity
.
setOrderStatus
(
SalesStatus
.
CREATED
);
salesRepository
.
save
(
salesEntity
);
}
}
@EventHandler
@EventHandler
protected
void
change
Quantity
(
SalesQuantityChangedEvent
product
QuantityChangedEvent
)
{
protected
void
change
OrderQuantity
(
SalesQuantityChangedEvent
sales
QuantityChangedEvent
)
{
log
.
info
(
"SalesQuantityChangedEvent 이벤트 받음?"
);
log
.
info
(
"SalesQuantityChangedEvent 이벤트 받음?"
);
log
.
info
(
"[SalesQuantityChangedEvent]"
);
log
.
info
(
"[SalesQuantityChangedEvent]"
);
SalesEntity
productEntity
=
productRepository
.
findById
(
productQuantityChangedEvent
.
getProduct
Id
()).
get
();
SalesEntity
salesEntity
=
salesRepository
.
findById
(
salesQuantityChangedEvent
.
getSalesOrder
Id
()).
get
();
// log.info("[{}] quantity:{}", productEntity.getName(), productEntity.getQuentity());
// log.info("[{}] quantity:{}", productEntity.getName(), productEntity.getQuentity());
// productEntity.setQuentity(productQuantityChangedEvent.getQuantity());
// productEntity.setQuentity(productQuantityChangedEvent.getQuantity());
productRepository
.
save
(
product
Entity
);
salesRepository
.
save
(
sales
Entity
);
}
}
}
}
src/main/java/com/showcase/synapse/sales/saga/SalesSaga.java
View file @
b2ab17e0
package
com
.
showcase
.
synapse
.
sales
.
saga
;
package
com
.
showcase
.
synapse
.
sales
.
saga
;
import
org.axonframework.commandhandling.CommandCallback
;
import
org.axonframework.commandhandling.CommandMessage
;
import
org.axonframework.commandhandling.CommandResultMessage
;
import
org.axonframework.commandhandling.gateway.CommandGateway
;
import
org.axonframework.commandhandling.gateway.CommandGateway
;
import
org.axonframework.modelling.saga.SagaEventHandler
;
import
org.axonframework.modelling.saga.StartSaga
;
import
org.axonframework.spring.stereotype.Saga
;
import
org.axonframework.spring.stereotype.Saga
;
import
org.springframework.beans.factory.annotation.Autowired
;
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.sales.event.SalesCreatedEvent
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
//
@Saga
@Saga
@Slf4j
@Slf4j
public
class
SalesSaga
{
public
class
SalesSaga
{
@Autowired
@Autowired
private
transient
CommandGateway
commandGateway
;
private
transient
CommandGateway
commandGateway
;
@StartSaga
@SagaEventHandler
(
associationProperty
=
"salesOrderId"
)
public
void
createOrder
(
SalesCreatedEvent
event
)
{
log
.
info
(
"[SalesSaga] Sales saga"
);
log
.
info
(
"event.getSalesOrderId() === "
+
event
.
getSalesOrderId
());
log
.
info
(
"event.getOrderComment() === "
+
event
.
getOrderComment
());
log
.
info
(
"event.getOrderQuantity() === "
+
event
.
getOrderQuantity
());
ChangeInventoryQuantityCommand
ciqc
=
new
ChangeInventoryQuantityCommand
(
event
.
getSalesOrderId
(),
event
.
getWhId
(),
event
.
getOrderComment
(),
event
.
getOrderQuantity
());
commandGateway
.
send
(
ciqc
,
new
CommandCallback
<
ChangeInventoryQuantityCommand
,
Object
>()
{
@Override
public
void
onResult
(
CommandMessage
<?
extends
ChangeInventoryQuantityCommand
>
commandMessage
,
CommandResultMessage
<?>
commandResultMessage
)
{
log
.
info
(
"ChangeInventoryQuantityCommand onResult commandResultMessage.isExceptional() = "
+
commandResultMessage
.
isExceptional
());
if
(
commandResultMessage
.
isExceptional
()){
// 보상 transaction
log
.
info
(
"[주문 qty over에 대한 보상Transaction -> 주문은 취소] cancel order"
);
commandGateway
.
send
(
new
CancleSalesCommand
(
event
.
getSalesOrderId
(),
event
.
getOrderQuantity
()));
}
}
});
}
}
}
src/main/java/com/showcase/synapse/sales/service/SalesService.java
View file @
b2ab17e0
package
com
.
showcase
.
synapse
.
sales
.
service
;
package
com
.
showcase
.
synapse
.
sales
.
service
;
import
java.math.BigDecimal
;
import
java.math.BigDecimal
;
import
java.math.RoundingMode
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.UUID
;
import
java.util.UUID
;
...
@@ -11,7 +12,7 @@ import org.axonframework.messaging.responsetypes.ResponseTypes;
...
@@ -11,7 +12,7 @@ import org.axonframework.messaging.responsetypes.ResponseTypes;
import
org.axonframework.queryhandling.QueryGateway
;
import
org.axonframework.queryhandling.QueryGateway
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
com.showcase.synapse.
sales
.command.CreateSalesCommand
;
import
com.showcase.synapse.
common
.command.CreateSalesCommand
;
import
com.showcase.synapse.sales.dto.ProductSalesDto
;
import
com.showcase.synapse.sales.dto.ProductSalesDto
;
import
com.showcase.synapse.sales.entity.ProductEntity
;
import
com.showcase.synapse.sales.entity.ProductEntity
;
import
com.showcase.synapse.sales.entity.SalesEntity
;
import
com.showcase.synapse.sales.entity.SalesEntity
;
...
@@ -32,16 +33,16 @@ public class SalesService {
...
@@ -32,16 +33,16 @@ public class SalesService {
this
.
queryGateway
=
queryGateway
;
this
.
queryGateway
=
queryGateway
;
}
}
public
String
create
Product
(
String
name
,
String
comment
,
BigDecimal
price
)
{
public
String
create
Sales
(
String
whId
,
String
orderName
,
String
orderComment
,
Integer
orderQuantity
)
{
log
.
info
(
"[@Service create
Product
] new CreateSalesCommand"
);
log
.
info
(
"[@Service create
Sales
] new CreateSalesCommand"
);
// command생성
// command생성
CreateSalesCommand
create
Product
Command
=
new
CreateSalesCommand
(
CreateSalesCommand
create
Sales
Command
=
new
CreateSalesCommand
(
UUID
.
randomUUID
().
toString
(),
name
,
comment
,
price
UUID
.
randomUUID
().
toString
(),
whId
,
orderName
,
orderComment
,
orderQuantity
);
);
System
.
out
.
println
(
"test"
);
// 여기
// 여기
// 생성한 command전송(비동기)
// 생성한 command전송(비동기)
String
returnValue
=
commandGateway
.
sendAndWait
(
createProductCommand
);
log
.
info
(
"[@createSalesCommand] 전송"
);
String
returnValue
=
commandGateway
.
sendAndWait
(
createSalesCommand
);
System
.
out
.
printf
(
"returnValue: %s \n"
,
returnValue
);
System
.
out
.
printf
(
"returnValue: %s \n"
,
returnValue
);
return
returnValue
;
return
returnValue
;
}
}
...
@@ -68,7 +69,7 @@ public class SalesService {
...
@@ -68,7 +69,7 @@ public class SalesService {
dto
.
setProductComment
(
tempPE
.
getComment
());
dto
.
setProductComment
(
tempPE
.
getComment
());
dto
.
setOrgPrice
(
tempPE
.
getPrice
());
dto
.
setOrgPrice
(
tempPE
.
getPrice
());
dto
.
setDiscountRate
(
tempPE
.
getChannel
().
getDiscountRate
());
dto
.
setDiscountRate
(
tempPE
.
getChannel
().
getDiscountRate
());
dto
.
setRatePrice
(
tempPE
.
getPrice
().
multiply
(
tempPE
.
getChannel
().
getDiscountRate
().
add
(
new
BigDecimal
(
1
))
));
dto
.
setRatePrice
(
tempPE
.
getPrice
().
multiply
(
(
new
BigDecimal
(
1
)).
subtract
(
tempPE
.
getChannel
().
getDiscountRate
())).
setScale
(
2
,
RoundingMode
.
DOWN
));
dto
.
setSalesChannel
(
tempPE
.
getChannel
().
getName
());
dto
.
setSalesChannel
(
tempPE
.
getChannel
().
getName
());
dto
.
setWhId
(
tempPE
.
getInventory
().
getWhid
());
dto
.
setWhId
(
tempPE
.
getInventory
().
getWhid
());
dto
.
setWhName
(
tempPE
.
getInventory
().
getWhName
());
dto
.
setWhName
(
tempPE
.
getInventory
().
getWhName
());
...
...
src/main/resources/application.yml
View file @
b2ab17e0
#axon:
# serializer:
# general: jackson
# events: jackson
# messages: jackson
axon
:
axon
:
serializer
:
serializer
:
general
:
xstream
general
:
xstream
...
...
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