Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
C
com.showcase.synapse.delivery
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.delivery
Commits
fa5082e6
Commit
fa5082e6
authored
Sep 13, 2023
by
lemin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ccc
parent
90826b75
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
83 additions
and
112 deletions
+83
-112
CreateDeliveryCommand.java
...howcase/synapse/common/command/CreateDeliveryCommand.java
+24
-20
DeliveryAggregate.java
...howcase/synapse/delivery/aggregate/DeliveryAggregate.java
+10
-26
DeliveryController.java
...wcase/synapse/delivery/controller/DeliveryController.java
+13
-13
DeliveryCreateDto.java
.../com/showcase/synapse/delivery/dto/DeliveryCreateDto.java
+2
-3
DeliveryEntity.java
.../com/showcase/synapse/delivery/entity/DeliveryEntity.java
+6
-4
DeliveryCreatedEvent.java
...showcase/synapse/delivery/event/DeliveryCreatedEvent.java
+6
-4
DeliveryQuantityChangedEvent.java
.../synapse/delivery/event/DeliveryQuantityChangedEvent.java
+0
-11
DeliveryEventHandler.java
.../synapse/delivery/event/handler/DeliveryEventHandler.java
+14
-23
DeliveryService.java
...om/showcase/synapse/delivery/service/DeliveryService.java
+8
-8
No files found.
src/main/java/com/showcase/synapse/common/command/CreateDeliveryCommand.java
View file @
fa5082e6
package
com
.
showcase
.
synapse
.
common
.
command
;
package
com
.
showcase
.
synapse
.
common
.
command
;
import
lombok.AllArgsConstructor
;
import
java.io.Serializable
;
import
lombok.Getter
;
import
org.axonframework.modelling.command.TargetAggregateIdentifier
;
import
org.axonframework.modelling.command.TargetAggregateIdentifier
;
import
java.math.BigDecimal
;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
@AllArgsConstructor
@Getter
@AllArgsConstructor
public
class
CreateDeliveryCommand
{
@Getter
public
class
CreateDeliveryCommand
implements
Serializable
{
@TargetAggregateIdentifier
private
final
String
id
;
private
static
final
long
serialVersionUID
=
1L
;
private
final
String
name
;
private
final
String
comment
;
@TargetAggregateIdentifier
private
final
BigDecimal
price
;
private
String
deliveryOrderId
;
// private final Integer quantity;
private
String
salesOrderId
;
private
String
whId
;
}
private
String
orderComment
;
private
Integer
orderQuantity
;
private
String
orderName
;
}
src/main/java/com/showcase/synapse/delivery/aggregate/DeliveryAggregate.java
View file @
fa5082e6
package
com
.
showcase
.
synapse
.
delivery
.
aggregate
;
package
com
.
showcase
.
synapse
.
delivery
.
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.common.command.ChangeDeliveryStatusCommand
;
import
com.showcase.synapse.common.command.CreateDeliveryCommand
;
import
com.showcase.synapse.common.command.CreateDeliveryCommand
;
import
com.showcase.synapse.delivery.event.DeliveryCreatedEvent
;
import
com.showcase.synapse.delivery.event.DeliveryCreatedEvent
;
import
com.showcase.synapse.delivery.event.DeliveryQuantityChangedEvent
;
import
com.showcase.synapse.delivery.saga.DeliverySaga
;
import
java.math.BigDecimal
;
import
static
org
.
axonframework
.
modelling
.
command
.
AggregateLifecycle
.
apply
;
import
lombok.NoArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
@Aggregate
@Aggregate
@NoArgsConstructor
@NoArgsConstructor
...
@@ -24,32 +19,21 @@ import static org.axonframework.modelling.command.AggregateLifecycle.apply;
...
@@ -24,32 +19,21 @@ import static org.axonframework.modelling.command.AggregateLifecycle.apply;
public
class
DeliveryAggregate
{
public
class
DeliveryAggregate
{
@AggregateIdentifier
@AggregateIdentifier
private
String
i
d
;
private
String
deliveryOrderI
d
;
// private int quanti
y;
private
int
orderQuantit
y
;
@CommandHandler
@CommandHandler
public
DeliveryAggregate
(
CreateDeliveryCommand
command
)
{
public
DeliveryAggregate
(
CreateDeliveryCommand
command
)
{
log
.
info
(
"[DeliveryAggregate(CreateDeliveryCommand) > apply new DeliveryCreatedEvent]"
);
log
.
info
(
"[DeliveryAggregate(CreateDeliveryCommand) > apply new DeliveryCreatedEvent]"
);
apply
(
new
DeliveryCreatedEvent
(
command
.
getId
(),
command
.
getName
(),
command
.
getComment
(),
command
.
getPrice
()));
apply
(
new
DeliveryCreatedEvent
(
command
.
getDeliveryOrderId
(),
command
.
getSalesOrderId
(),
command
.
getWhId
(),
}
command
.
getOrderName
(),
command
.
getOrderComment
(),
command
.
getOrderQuantity
()));
@EventSourcingHandler
public
void
createProduct
(
DeliveryCreatedEvent
event
)
{
this
.
id
=
event
.
getProductId
();
// this.quantiy = event.getQuantity();
}
@CommandHandler
public
void
changeQuantity
(
ChangeDeliveryStatusCommand
command
)
{
log
.
info
(
"[@CommandHandler ProductchangeQuantity]"
);
// if(this.quantiy < command.getQuantity()) throw new IllegalArgumentException("tfy ");
// apply(new DeliveryQuantityChangedEvent(command.getProductId(), this.quantiy - command.getQuantity()));
}
}
@EventSourcingHandler
@EventSourcingHandler
public
void
changeQuantity
(
DeliveryQuantityChangedEvent
event
)
{
public
void
createDelivery
(
DeliveryCreatedEvent
event
)
{
// this.quantiy = event.getQuantity();
this
.
deliveryOrderId
=
event
.
getDeliveryOrderId
();
this
.
orderQuantity
=
event
.
getOrderQuantity
();
}
}
}
}
src/main/java/com/showcase/synapse/delivery/controller/DeliveryController.java
View file @
fa5082e6
...
@@ -14,31 +14,31 @@ import java.util.Map;
...
@@ -14,31 +14,31 @@ import java.util.Map;
import
java.util.concurrent.ExecutionException
;
import
java.util.concurrent.ExecutionException
;
@RestController
@RestController
@RequestMapping
(
"/api/msa/
product
"
)
@RequestMapping
(
"/api/msa/
delivery
"
)
@CrossOrigin
(
origins
=
"*"
)
@CrossOrigin
(
origins
=
"*"
)
public
class
DeliveryController
{
public
class
DeliveryController
{
final
DeliveryService
product
Service
;
final
DeliveryService
delivery
Service
;
public
DeliveryController
(
DeliveryService
product
Service
)
{
public
DeliveryController
(
DeliveryService
delivery
Service
)
{
this
.
productService
=
product
Service
;
this
.
deliveryService
=
delivery
Service
;
}
}
@GetMapping
(
"/"
)
@GetMapping
(
"/"
)
public
ResponseEntity
<
List
<
DeliveryEntity
>>
get
Products
()
throws
ExecutionException
,
InterruptedException
{
public
ResponseEntity
<
List
<
DeliveryEntity
>>
get
DeliveryList
()
throws
ExecutionException
,
InterruptedException
{
List
<
DeliveryEntity
>
productEntities
=
productService
.
getProducts
();
List
<
DeliveryEntity
>
deliveryEntity
=
deliveryService
.
getDeliveryList
();
return
ResponseEntity
.
ok
(
productEntities
);
return
ResponseEntity
.
ok
(
deliveryEntity
);
}
}
@PostMapping
(
"/"
)
@PostMapping
(
"/"
)
public
ResponseEntity
<
Map
<
String
,
String
>>
productCreate
(
@RequestBody
DeliveryCreateDto
productCreateDto
)
{
public
ResponseEntity
<
Map
<
String
,
String
>>
deliveryOrderCreate
(
@RequestBody
DeliveryCreateDto
deliveryCreateDto
)
{
String
productId
=
productService
.
createProduct
(
productCreateDto
.
getName
(),
String
deliveryId
=
deliveryService
.
createDeliveryOrder
(
deliveryCreateDto
.
getSalesOrderId
(),
productCreateDto
.
getComment
(),
deliveryCreateDto
.
getWhId
());
BigDecimal
.
valueOf
(
productCreateDto
.
getPrice
()));
HashMap
<
String
,
String
>
m
=
new
HashMap
<>();
HashMap
<
String
,
String
>
m
=
new
HashMap
<>();
m
.
put
(
"productId"
,
productId
);
m
.
put
(
"deliveryId"
,
deliveryId
);
m
.
put
(
"productName"
,
productCreateDto
.
getName
());
m
.
put
(
"salesOrderId"
,
deliveryCreateDto
.
getSalesOrderId
());
m
.
put
(
"getWhId"
,
deliveryCreateDto
.
getWhId
());
return
ResponseEntity
.
ok
(
m
);
return
ResponseEntity
.
ok
(
m
);
}
}
...
...
src/main/java/com/showcase/synapse/delivery/dto/DeliveryCreateDto.java
View file @
fa5082e6
...
@@ -6,8 +6,7 @@ import lombok.Setter;
...
@@ -6,8 +6,7 @@ import lombok.Setter;
@Getter
@Getter
@Setter
@Setter
public
class
DeliveryCreateDto
{
public
class
DeliveryCreateDto
{
private
String
name
;
private
String
salesOrderId
;
private
String
comment
;
private
String
whId
;
private
int
price
;
}
}
src/main/java/com/showcase/synapse/delivery/entity/DeliveryEntity.java
View file @
fa5082e6
...
@@ -16,8 +16,10 @@ import java.math.BigDecimal;
...
@@ -16,8 +16,10 @@ import java.math.BigDecimal;
@NoArgsConstructor
@NoArgsConstructor
public
class
DeliveryEntity
{
public
class
DeliveryEntity
{
@Id
@Id
private
String
id
;
private
String
deliveryOrderId
;
private
String
name
;
private
String
salesOrderId
;
private
String
comment
;
private
String
whId
;
private
BigDecimal
price
;
private
String
orderName
;
private
String
orderComment
;
private
Integer
orderQuantity
;
}
}
src/main/java/com/showcase/synapse/delivery/event/DeliveryCreatedEvent.java
View file @
fa5082e6
...
@@ -8,8 +8,10 @@ import java.math.BigDecimal;
...
@@ -8,8 +8,10 @@ import java.math.BigDecimal;
@AllArgsConstructor
@AllArgsConstructor
@Getter
@Getter
public
class
DeliveryCreatedEvent
{
public
class
DeliveryCreatedEvent
{
private
String
productId
;
private
String
deliveryOrderId
;
private
String
name
;
private
String
salesOrderId
;
private
String
comment
;
private
String
whId
;
private
BigDecimal
price
;
private
String
orderName
;
private
String
orderComment
;
private
Integer
orderQuantity
;
}
}
src/main/java/com/showcase/synapse/delivery/event/DeliveryQuantityChangedEvent.java
deleted
100644 → 0
View file @
90826b75
package
com
.
showcase
.
synapse
.
delivery
.
event
;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
@AllArgsConstructor
@Getter
public
class
DeliveryQuantityChangedEvent
{
private
String
productId
;
private
int
quantity
;
}
src/main/java/com/showcase/synapse/delivery/event/handler/DeliveryEventHandler.java
View file @
fa5082e6
package
com
.
showcase
.
synapse
.
delivery
.
event
.
handler
;
package
com
.
showcase
.
synapse
.
delivery
.
event
.
handler
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.axonframework.eventhandling.EventHandler
;
import
org.axonframework.eventhandling.EventHandler
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
com.showcase.synapse.delivery.entity.DeliveryEntity
;
import
com.showcase.synapse.delivery.entity.DeliveryEntity
;
import
com.showcase.synapse.delivery.event.DeliveryCreatedEvent
;
import
com.showcase.synapse.delivery.event.DeliveryCreatedEvent
;
import
com.showcase.synapse.delivery.event.DeliveryQuantityChangedEvent
;
import
com.showcase.synapse.delivery.repository.DeliveryRepository
;
import
com.showcase.synapse.delivery.repository.DeliveryRepository
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
@Component
@Component
@AllArgsConstructor
@AllArgsConstructor
@Slf4j
@Slf4j
public
class
DeliveryEventHandler
{
public
class
DeliveryEventHandler
{
private
final
DeliveryRepository
product
Repository
;
private
final
DeliveryRepository
delivery
Repository
;
@EventHandler
@EventHandler
protected
void
save
Product
(
DeliveryCreatedEvent
product
CreatedEvent
)
{
protected
void
save
DeliveryOrder
(
DeliveryCreatedEvent
Delivery
CreatedEvent
)
{
log
.
info
(
"DeliveryCreatedEvent 이벤트 받음?"
);
log
.
info
(
"DeliveryCreatedEvent 이벤트 받음?"
);
log
.
info
(
"DeliveryEventHandler > [DeliveryCreatedEvent] productCreatedEvent"
);
log
.
info
(
"DeliveryEventHandler > [DeliveryCreatedEvent]"
);
DeliveryEntity
productEntity
=
new
DeliveryEntity
();
DeliveryEntity
deliveryEntity
=
new
DeliveryEntity
();
productEntity
.
setId
(
productCreatedEvent
.
getProductId
());
deliveryEntity
.
setDeliveryOrderId
(
DeliveryCreatedEvent
.
getDeliveryOrderId
());
productEntity
.
setName
(
productCreatedEvent
.
getName
());
deliveryEntity
.
setSalesOrderId
(
DeliveryCreatedEvent
.
getSalesOrderId
());
productEntity
.
setComment
(
productCreatedEvent
.
getComment
());
deliveryEntity
.
setOrderComment
(
DeliveryCreatedEvent
.
getOrderComment
());
productEntity
.
setPrice
(
productCreatedEvent
.
getPrice
());
deliveryEntity
.
setWhId
(
DeliveryCreatedEvent
.
getWhId
());
deliveryEntity
.
setOrderName
(
DeliveryCreatedEvent
.
getOrderName
());
deliveryEntity
.
setOrderQuantity
(
DeliveryCreatedEvent
.
getOrderQuantity
());
productRepository
.
save
(
product
Entity
);
deliveryRepository
.
save
(
delivery
Entity
);
}
}
@EventHandler
protected
void
changeQuantity
(
DeliveryQuantityChangedEvent
productQuantityChangedEvent
)
{
log
.
info
(
"DeliveryQuantityChangedEvent 이벤트 받음?"
);
log
.
info
(
"[DeliveryQuantityChangedEvent]"
);
DeliveryEntity
productEntity
=
productRepository
.
findById
(
productQuantityChangedEvent
.
getProductId
()).
get
();
// log.info("[{}] quantity:{}", productEntity.getName(), productEntity.getQuentity());
// productEntity.setQuentity(productQuantityChangedEvent.getQuantity());
productRepository
.
save
(
productEntity
);
}
}
}
src/main/java/com/showcase/synapse/delivery/service/DeliveryService.java
View file @
fa5082e6
...
@@ -27,22 +27,22 @@ public class DeliveryService {
...
@@ -27,22 +27,22 @@ public class DeliveryService {
this
.
commandGateway
=
commandGateway
;
this
.
commandGateway
=
commandGateway
;
this
.
queryGateway
=
queryGateway
;
this
.
queryGateway
=
queryGateway
;
}
}
public
String
create
Product
(
String
name
,
String
comment
,
BigDecimal
price
)
{
public
String
create
DeliveryOrder
(
String
salesOrderId
,
String
whId
)
{
log
.
info
(
"[@Service create
Product
] new CreateDeliveryCommand"
);
log
.
info
(
"[@Service create
DeliveryOrder
] new CreateDeliveryCommand"
);
// command생성
// command생성
CreateDeliveryCommand
create
Product
Command
=
new
CreateDeliveryCommand
(
CreateDeliveryCommand
create
Delivery
Command
=
new
CreateDeliveryCommand
(
UUID
.
randomUUID
().
toString
(),
name
,
comment
,
price
UUID
.
randomUUID
().
toString
(),
salesOrderId
,
whId
,
"Direct api call orderComment"
,
0
,
"Direct api call orderName"
);
);
System
.
out
.
println
(
"test"
);
// 여기
// 여기
// 생성한 command전송(비동기)
// 생성한 command전송(비동기)
String
returnValue
=
commandGateway
.
sendAndWait
(
createProductCommand
);
log
.
info
(
"[CreateDeliveryCommand] command전송(비동기)"
);
String
returnValue
=
commandGateway
.
sendAndWait
(
createDeliveryCommand
);
System
.
out
.
printf
(
"returnValue: %s \n"
,
returnValue
);
System
.
out
.
printf
(
"returnValue: %s \n"
,
returnValue
);
return
returnValue
;
return
returnValue
;
}
}
public
List
<
DeliveryEntity
>
get
Products
()
throws
ExecutionException
,
InterruptedException
{
public
List
<
DeliveryEntity
>
get
DeliveryList
()
throws
ExecutionException
,
InterruptedException
{
return
queryGateway
.
query
(
new
GetDeliveryQuery
(),
return
queryGateway
.
query
(
new
GetDeliveryQuery
(),
ResponseTypes
.
multipleInstancesOf
(
DeliveryEntity
.
class
)).
get
();
ResponseTypes
.
multipleInstancesOf
(
DeliveryEntity
.
class
)).
get
();
}
}
...
...
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