fix bugs
This commit is contained in:
@@ -12,6 +12,9 @@ public class Order {
|
||||
private Long id;
|
||||
private String item;
|
||||
private Integer 수량;
|
||||
private String 상태;
|
||||
private String 가게;
|
||||
private Long 가격;
|
||||
|
||||
@PostPersist
|
||||
public void onPostPersist(){
|
||||
@@ -20,7 +23,12 @@ public class Order {
|
||||
// it is NOT A GOOD PRACTICE. instead, Event-Policy mapping is recommended.
|
||||
|
||||
fooddelivery.external.결제이력 결제이력 = new fooddelivery.external.결제이력();
|
||||
// mappings goes here
|
||||
|
||||
// this is Context Mapping (Anti-corruption Layer)
|
||||
결제이력.setOrderId(String.valueOf(getId()));
|
||||
if(get가격()!=null)
|
||||
결제이력.set금액(Double.valueOf(get가격()));
|
||||
|
||||
Application.applicationContext.getBean(fooddelivery.external.결제이력Service.class)
|
||||
.결제(결제이력);
|
||||
|
||||
@@ -51,7 +59,27 @@ public class Order {
|
||||
this.수량 = 수량;
|
||||
}
|
||||
|
||||
public String get상태() {
|
||||
return 상태;
|
||||
}
|
||||
|
||||
public void set상태(String 상태) {
|
||||
this.상태 = 상태;
|
||||
}
|
||||
|
||||
public String get가게() {
|
||||
return 가게;
|
||||
}
|
||||
|
||||
public void set가게(String 가게) {
|
||||
this.가게 = 가게;
|
||||
}
|
||||
|
||||
public Long get가격() {
|
||||
return 가격;
|
||||
}
|
||||
|
||||
public void set가격(Long 가격) {
|
||||
this.가격 = 가격;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,11 +11,29 @@ import org.springframework.stereotype.Service;
|
||||
@Service
|
||||
public class PolicyHandler{
|
||||
|
||||
@Autowired
|
||||
주문Repository 주문Repository;
|
||||
|
||||
@StreamListener(KafkaProcessor.INPUT)
|
||||
public void whenever배달시작됨_주문상태변경(@Payload 배달시작됨 배달시작됨){
|
||||
|
||||
if(배달시작됨.isMe()){
|
||||
System.out.println("##### listener 주문상태변경 : " + 배달시작됨.toJson());
|
||||
if(배달시작됨.isMe() && 배달시작됨.getOrderId()!=null){
|
||||
|
||||
try {
|
||||
// 원래 데이터가 트랜잭션 커밋되기도 전에 이벤트가 너무 빨리 도달하는 경우를 막기 위함
|
||||
Thread.currentThread().sleep(3000); // no good.
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
System.out.println("배달시작됨 orderId = " + 배달시작됨.getOrderId());
|
||||
|
||||
// Correlation id 는 'orderId' 임
|
||||
주문Repository.findById(Long.valueOf(배달시작됨.getOrderId())).ifPresent((주문)->{
|
||||
주문.set상태("배달시작됨");
|
||||
주문Repository.save(주문);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,11 +11,20 @@ import org.springframework.stereotype.Service;
|
||||
@Service
|
||||
public class PolicyHandler{
|
||||
|
||||
|
||||
@Autowired 결제이력Repository 결제이력Repository;
|
||||
|
||||
@StreamListener(KafkaProcessor.INPUT)
|
||||
public void whenever주문취소됨_결재취소함(@Payload 주문취소됨 주문취소됨){
|
||||
|
||||
if(주문취소됨.isMe()){
|
||||
System.out.println("##### listener 결재취소함 : " + 주문취소됨.toJson());
|
||||
|
||||
결제이력 결제이력 = new 결제이력();
|
||||
|
||||
결제이력.set행위("취소");
|
||||
|
||||
결제이력Repository.save(결제이력);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,18 +13,28 @@ public class 결제이력 {
|
||||
private Long id;
|
||||
private String orderId;
|
||||
private Double 금액;
|
||||
private String 행위;
|
||||
|
||||
@PrePersist
|
||||
public void onPrePersist(){
|
||||
결제승인됨 결제승인됨 = new 결제승인됨();
|
||||
BeanUtils.copyProperties(this, 결제승인됨);
|
||||
결제승인됨.publish();
|
||||
|
||||
if("취소".equals(행위)){
|
||||
결제취소됨 결제취소됨 = new 결제취소됨();
|
||||
BeanUtils.copyProperties(this, 결제취소됨);
|
||||
결제취소됨.publish();
|
||||
|
||||
}else{
|
||||
결제승인됨 결제승인됨 = new 결제승인됨();
|
||||
BeanUtils.copyProperties(this, 결제승인됨);
|
||||
결제승인됨.publish();
|
||||
|
||||
|
||||
try {
|
||||
Thread.currentThread().sleep((long) (400 + Math.random() * 220));
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
try {
|
||||
Thread.currentThread().sleep((long) (400 + Math.random() * 220));
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,6 +62,11 @@ public class 결제이력 {
|
||||
}
|
||||
|
||||
|
||||
public String get행위() {
|
||||
return 행위;
|
||||
}
|
||||
|
||||
|
||||
public void set행위(String 행위) {
|
||||
this.행위 = 행위;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package fooddelivery;
|
||||
public class 결제취소됨 extends AbstractEvent {
|
||||
|
||||
private Long id;
|
||||
private String orderId;
|
||||
|
||||
|
||||
public 결제취소됨(){
|
||||
super();
|
||||
@@ -15,4 +17,12 @@ public class 결제취소됨 extends AbstractEvent {
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getOrderId() {
|
||||
return orderId;
|
||||
}
|
||||
|
||||
public void setOrderId(String orderId) {
|
||||
this.orderId = orderId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,15 +20,22 @@ public class PolicyHandler{
|
||||
System.out.println("##### listener 주문정보받음 : " + 결제승인됨.toJson());
|
||||
|
||||
주문관리 주문 = new 주문관리();
|
||||
주문.setId(결제승인됨.getOrderId())
|
||||
주문.setOrderId(Long.valueOf(결제승인됨.getOrderId()));
|
||||
주문관리Repository.save(주문);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@StreamListener(KafkaProcessor.INPUT)
|
||||
public void whenever결제취소됨_주문취소처리(@Payload 결제취소됨 결제취소됨){
|
||||
|
||||
if(결제취소됨.isMe()){
|
||||
System.out.println("##### listener 주문취소처리 : " + 결제취소됨.toJson());
|
||||
|
||||
주문관리Repository.findById(결제취소됨.getOrderId()).ifPresent(주문관리->{
|
||||
주문관리Repository.delete(주문관리);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ package fooddelivery;
|
||||
public class 결제취소됨 extends AbstractEvent {
|
||||
|
||||
private Long id;
|
||||
private Long orderId;
|
||||
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
@@ -12,4 +14,12 @@ public class 결제취소됨 extends AbstractEvent {
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getOrderId() {
|
||||
return orderId;
|
||||
}
|
||||
|
||||
public void setOrderId(Long orderId) {
|
||||
this.orderId = orderId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,10 +11,14 @@ public class 주문관리 {
|
||||
@Id
|
||||
@GeneratedValue(strategy=GenerationType.AUTO)
|
||||
private Long id;
|
||||
Long orderId;
|
||||
String 배달지주소;
|
||||
String 요리종류;
|
||||
|
||||
@PostPersist
|
||||
public void onPostPersist(){
|
||||
배달시작됨 배달시작됨 = new 배달시작됨();
|
||||
배달시작됨.setOrderId(String.valueOf(getOrderId()));
|
||||
BeanUtils.copyProperties(this, 배달시작됨);
|
||||
배달시작됨.publish();
|
||||
|
||||
@@ -39,7 +43,27 @@ public class 주문관리 {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getOrderId() {
|
||||
return orderId;
|
||||
}
|
||||
|
||||
public void setOrderId(Long orderId) {
|
||||
this.orderId = orderId;
|
||||
}
|
||||
|
||||
public String get배달지주소() {
|
||||
return 배달지주소;
|
||||
}
|
||||
|
||||
public void set배달지주소(String 배달지주소) {
|
||||
this.배달지주소 = 배달지주소;
|
||||
}
|
||||
|
||||
public String get요리종류() {
|
||||
return 요리종류;
|
||||
}
|
||||
|
||||
public void set요리종류(String 요리종류) {
|
||||
this.요리종류 = 요리종류;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user