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
Show 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
;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
import
java.io.Serializable
;
import
org.axonframework.modelling.command.TargetAggregateIdentifier
;
import
java.math.BigDecimal
;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
@AllArgsConstructor
@Getter
public
class
CreateDeliveryCommand
{
public
class
CreateDeliveryCommand
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
@TargetAggregateIdentifier
private
final
String
id
;
private
final
String
name
;
private
final
String
comment
;
private
final
BigDecimal
price
;
// private final Integer quantity;
private
String
deliveryOrderId
;
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
;
import
lombok.NoArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
static
org
.
axonframework
.
modelling
.
command
.
AggregateLifecycle
.
apply
;
import
org.axonframework.commandhandling.CommandHandler
;
import
org.axonframework.eventsourcing.EventSourcingHandler
;
import
org.axonframework.modelling.command.AggregateIdentifier
;
import
org.axonframework.spring.stereotype.Aggregate
;
import
com.showcase.synapse.common.command.ChangeDeliveryStatusCommand
;
import
com.showcase.synapse.common.command.CreateDeliveryCommand
;
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
@NoArgsConstructor
...
...
@@ -24,32 +19,21 @@ import static org.axonframework.modelling.command.AggregateLifecycle.apply;
public
class
DeliveryAggregate
{
@AggregateIdentifier
private
String
i
d
;
// private int quanti
y;
private
String
deliveryOrderI
d
;
private
int
orderQuantit
y
;
@CommandHandler
public
DeliveryAggregate
(
CreateDeliveryCommand
command
)
{
log
.
info
(
"[DeliveryAggregate(CreateDeliveryCommand) > apply new DeliveryCreatedEvent]"
);
apply
(
new
DeliveryCreatedEvent
(
command
.
getId
(),
command
.
getName
(),
command
.
getComment
(),
command
.
getPrice
()));
}
@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()));
apply
(
new
DeliveryCreatedEvent
(
command
.
getDeliveryOrderId
(),
command
.
getSalesOrderId
(),
command
.
getWhId
(),
command
.
getOrderName
(),
command
.
getOrderComment
(),
command
.
getOrderQuantity
()));
}
@EventSourcingHandler
public
void
changeQuantity
(
DeliveryQuantityChangedEvent
event
)
{
// this.quantiy = event.getQuantity();
public
void
createDelivery
(
DeliveryCreatedEvent
event
)
{
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;
import
java.util.concurrent.ExecutionException
;
@RestController
@RequestMapping
(
"/api/msa/
product
"
)
@RequestMapping
(
"/api/msa/
delivery
"
)
@CrossOrigin
(
origins
=
"*"
)
public
class
DeliveryController
{
final
DeliveryService
product
Service
;
final
DeliveryService
delivery
Service
;
public
DeliveryController
(
DeliveryService
product
Service
)
{
this
.
productService
=
product
Service
;
public
DeliveryController
(
DeliveryService
delivery
Service
)
{
this
.
deliveryService
=
delivery
Service
;
}
@GetMapping
(
"/"
)
public
ResponseEntity
<
List
<
DeliveryEntity
>>
get
Products
()
throws
ExecutionException
,
InterruptedException
{
List
<
DeliveryEntity
>
productEntities
=
productService
.
getProducts
();
return
ResponseEntity
.
ok
(
productEntities
);
public
ResponseEntity
<
List
<
DeliveryEntity
>>
get
DeliveryList
()
throws
ExecutionException
,
InterruptedException
{
List
<
DeliveryEntity
>
deliveryEntity
=
deliveryService
.
getDeliveryList
();
return
ResponseEntity
.
ok
(
deliveryEntity
);
}
@PostMapping
(
"/"
)
public
ResponseEntity
<
Map
<
String
,
String
>>
productCreate
(
@RequestBody
DeliveryCreateDto
productCreateDto
)
{
String
productId
=
productService
.
createProduct
(
productCreateDto
.
getName
(),
productCreateDto
.
getComment
(),
BigDecimal
.
valueOf
(
productCreateDto
.
getPrice
()));
public
ResponseEntity
<
Map
<
String
,
String
>>
deliveryOrderCreate
(
@RequestBody
DeliveryCreateDto
deliveryCreateDto
)
{
String
deliveryId
=
deliveryService
.
createDeliveryOrder
(
deliveryCreateDto
.
getSalesOrderId
(),
deliveryCreateDto
.
getWhId
());
HashMap
<
String
,
String
>
m
=
new
HashMap
<>();
m
.
put
(
"productId"
,
productId
);
m
.
put
(
"productName"
,
productCreateDto
.
getName
());
m
.
put
(
"deliveryId"
,
deliveryId
);
m
.
put
(
"salesOrderId"
,
deliveryCreateDto
.
getSalesOrderId
());
m
.
put
(
"getWhId"
,
deliveryCreateDto
.
getWhId
());
return
ResponseEntity
.
ok
(
m
);
}
...
...
src/main/java/com/showcase/synapse/delivery/dto/DeliveryCreateDto.java
View file @
fa5082e6
...
...
@@ -6,8 +6,7 @@ import lombok.Setter;
@Getter
@Setter
public
class
DeliveryCreateDto
{
private
String
name
;
private
String
comment
;
private
int
price
;
private
String
salesOrderId
;
private
String
whId
;
}
src/main/java/com/showcase/synapse/delivery/entity/DeliveryEntity.java
View file @
fa5082e6
...
...
@@ -16,8 +16,10 @@ import java.math.BigDecimal;
@NoArgsConstructor
public
class
DeliveryEntity
{
@Id
private
String
id
;
private
String
name
;
private
String
comment
;
private
BigDecimal
price
;
private
String
deliveryOrderId
;
private
String
salesOrderId
;
private
String
whId
;
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;
@AllArgsConstructor
@Getter
public
class
DeliveryCreatedEvent
{
private
String
productId
;
private
String
name
;
private
String
comment
;
private
BigDecimal
price
;
private
String
deliveryOrderId
;
private
String
salesOrderId
;
private
String
whId
;
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
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.axonframework.eventhandling.EventHandler
;
import
org.springframework.stereotype.Component
;
import
com.showcase.synapse.delivery.entity.DeliveryEntity
;
import
com.showcase.synapse.delivery.event.DeliveryCreatedEvent
;
import
com.showcase.synapse.delivery.event.DeliveryQuantityChangedEvent
;
import
com.showcase.synapse.delivery.repository.DeliveryRepository
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
@Component
@AllArgsConstructor
@Slf4j
public
class
DeliveryEventHandler
{
private
final
DeliveryRepository
product
Repository
;
private
final
DeliveryRepository
delivery
Repository
;
@EventHandler
protected
void
save
Product
(
DeliveryCreatedEvent
product
CreatedEvent
)
{
protected
void
save
DeliveryOrder
(
DeliveryCreatedEvent
Delivery
CreatedEvent
)
{
log
.
info
(
"DeliveryCreatedEvent 이벤트 받음?"
);
log
.
info
(
"DeliveryEventHandler > [DeliveryCreatedEvent] productCreatedEvent"
);
DeliveryEntity
productEntity
=
new
DeliveryEntity
();
productEntity
.
setId
(
productCreatedEvent
.
getProductId
());
productEntity
.
setName
(
productCreatedEvent
.
getName
());
productEntity
.
setComment
(
productCreatedEvent
.
getComment
());
productEntity
.
setPrice
(
productCreatedEvent
.
getPrice
());
log
.
info
(
"DeliveryEventHandler > [DeliveryCreatedEvent]"
);
DeliveryEntity
deliveryEntity
=
new
DeliveryEntity
();
deliveryEntity
.
setDeliveryOrderId
(
DeliveryCreatedEvent
.
getDeliveryOrderId
());
deliveryEntity
.
setSalesOrderId
(
DeliveryCreatedEvent
.
getSalesOrderId
());
deliveryEntity
.
setOrderComment
(
DeliveryCreatedEvent
.
getOrderComment
());
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
...
...
@@ -28,21 +28,21 @@ public class DeliveryService {
this
.
queryGateway
=
queryGateway
;
}
public
String
create
Product
(
String
name
,
String
comment
,
BigDecimal
price
)
{
log
.
info
(
"[@Service create
Product
] new CreateDeliveryCommand"
);
public
String
create
DeliveryOrder
(
String
salesOrderId
,
String
whId
)
{
log
.
info
(
"[@Service create
DeliveryOrder
] new CreateDeliveryCommand"
);
// command생성
CreateDeliveryCommand
create
Product
Command
=
new
CreateDeliveryCommand
(
UUID
.
randomUUID
().
toString
(),
name
,
comment
,
price
CreateDeliveryCommand
create
Delivery
Command
=
new
CreateDeliveryCommand
(
UUID
.
randomUUID
().
toString
(),
salesOrderId
,
whId
,
"Direct api call orderComment"
,
0
,
"Direct api call orderName"
);
System
.
out
.
println
(
"test"
);
// 여기
// 생성한 command전송(비동기)
String
returnValue
=
commandGateway
.
sendAndWait
(
createProductCommand
);
log
.
info
(
"[CreateDeliveryCommand] command전송(비동기)"
);
String
returnValue
=
commandGateway
.
sendAndWait
(
createDeliveryCommand
);
System
.
out
.
printf
(
"returnValue: %s \n"
,
returnValue
);
return
returnValue
;
}
public
List
<
DeliveryEntity
>
get
Products
()
throws
ExecutionException
,
InterruptedException
{
public
List
<
DeliveryEntity
>
get
DeliveryList
()
throws
ExecutionException
,
InterruptedException
{
return
queryGateway
.
query
(
new
GetDeliveryQuery
(),
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