Commit d431c27c authored by lemin's avatar lemin

cccc

parent b2ab17e0
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;
}
...@@ -50,8 +50,7 @@ public class SalesAggregate { ...@@ -50,8 +50,7 @@ public class SalesAggregate {
@CommandHandler @CommandHandler
public void cancelSalesOrder(CancleSalesCommand command) { public void cancelSalesOrder(CancleSalesCommand command) {
log.info("[@CommandHandler cancelSalesOrder CancleSalesCommand]"); log.info("[@CommandHandler cancelSalesOrder CancleSalesCommand]");
// if(this.quantiy < command.getQuantity()) throw new IllegalArgumentException("tfy "); apply(new SalesCanceledEvent(command.getSalesOrderId()));
// apply(new SalesQuantityChangedEvent(command.getProductId(), this.quantiy - command.getQuantity()));
} }
@EventSourcingHandler @EventSourcingHandler
......
...@@ -31,7 +31,7 @@ public class SalesEntity { ...@@ -31,7 +31,7 @@ public class SalesEntity {
public void cancelOrder() { public void cancelOrder() {
this.orderStatus = SalesStatus.CANCELED; this.orderStatus = SalesStatus.CANCELED;
if(this.orderComment != null && !this.orderComment.isEmpty()) { 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.");
} }
} }
} }
package com.showcase.synapse.sales.event.handler; package com.showcase.synapse.sales.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.sales.entity.SalesEntity; import com.showcase.synapse.sales.entity.SalesEntity;
import com.showcase.synapse.sales.enums.SalesStatus; 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.repository.SalesRepository; import com.showcase.synapse.sales.repository.SalesRepository;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@Component @Component
@AllArgsConstructor @AllArgsConstructor
@Slf4j @Slf4j
...@@ -36,12 +37,12 @@ public class SalesEventHandler { ...@@ -36,12 +37,12 @@ public class SalesEventHandler {
} }
@EventHandler @EventHandler
protected void changeOrderQuantity(SalesQuantityChangedEvent salesQuantityChangedEvent) { protected void changeOrderQuantity(SalesCanceledEvent SalesCanceledEvent) {
log.info("SalesQuantityChangedEvent 이벤트 받음?"); log.info("SalesCanceledEvent 이벤트 받음?");
log.info("[SalesQuantityChangedEvent]"); log.info("[changeOrderQuantity] SalesCanceledEvent");
SalesEntity salesEntity = salesRepository.findById(salesQuantityChangedEvent.getSalesOrderId()).get(); SalesEntity salesEntity = salesRepository.findById(SalesCanceledEvent.getSalesOrderId()).get();
// log.info("[{}] quantity:{}", productEntity.getName(), productEntity.getQuentity()); salesEntity.cancelOrder();
// productEntity.setQuentity(productQuantityChangedEvent.getQuantity()); log.info("[OrderComment]:{}", salesEntity.getOrderComment());
salesRepository.save(salesEntity); salesRepository.save(salesEntity);
} }
......
package com.showcase.synapse.sales.saga; package com.showcase.synapse.sales.saga;
import java.util.UUID;
import org.axonframework.commandhandling.CommandCallback; import org.axonframework.commandhandling.CommandCallback;
import org.axonframework.commandhandling.CommandMessage; import org.axonframework.commandhandling.CommandMessage;
import org.axonframework.commandhandling.CommandResultMessage; import org.axonframework.commandhandling.CommandResultMessage;
...@@ -11,6 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -11,6 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import com.showcase.synapse.common.command.CancleSalesCommand; import com.showcase.synapse.common.command.CancleSalesCommand;
import com.showcase.synapse.common.command.ChangeInventoryQuantityCommand; import com.showcase.synapse.common.command.ChangeInventoryQuantityCommand;
import com.showcase.synapse.common.command.CreateDeliveryCommand;
import com.showcase.synapse.sales.event.SalesCreatedEvent; import com.showcase.synapse.sales.event.SalesCreatedEvent;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -40,8 +43,31 @@ public class SalesSaga { ...@@ -40,8 +43,31 @@ public class SalesSaga {
// 보상 transaction // 보상 transaction
log.info("[주문 qty over에 대한 보상Transaction -> 주문은 취소] cancel order"); log.info("[주문 qty over에 대한 보상Transaction -> 주문은 취소] cancel order");
commandGateway.send(new CancleSalesCommand(event.getSalesOrderId(), event.getOrderQuantity())); 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!!!");
}
}
});
}
}); });
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment