Commit 21d7cea0 authored by lemin's avatar lemin

commit

parent 57fe27fb
package com.showcase.synapse.product.entity;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Entity
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class InventoryEntity implements Serializable{
private static final long serialVersionUID = -6540276275154344203L;
@Id
@Column(name = "wh_id")
private String whid;
@Column(name = "ref_product_id")
private String productid;
private String whName;
private Integer quantity;
}
...@@ -4,6 +4,7 @@ import java.math.BigDecimal; ...@@ -4,6 +4,7 @@ import java.math.BigDecimal;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.OneToOne; import javax.persistence.OneToOne;
...@@ -30,7 +31,11 @@ public class ProductEntity { ...@@ -30,7 +31,11 @@ public class ProductEntity {
// @Column(name = "channel", nullable = false) // @Column(name = "channel", nullable = false)
// private Integer channel; // private Integer channel;
@OneToOne(cascade = CascadeType.PERSIST) @OneToOne(fetch= FetchType.EAGER,cascade = CascadeType.PERSIST)
@JoinColumn(name = "channel_id") @JoinColumn(name = "channel_id")
private ChannelEntity channel; private ChannelEntity channel;
@OneToOne(fetch= FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumn(name = "ref_product_id", referencedColumnName = "ref_product_id")
private InventoryEntity inventory;
} }
package com.showcase.synapse.product.event.handler; package com.showcase.synapse.product.event.handler;
import java.util.UUID;
import org.axonframework.eventhandling.EventHandler; import org.axonframework.eventhandling.EventHandler;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import com.showcase.synapse.product.entity.ChannelEntity; import com.showcase.synapse.product.entity.ChannelEntity;
import com.showcase.synapse.product.entity.InventoryEntity;
import com.showcase.synapse.product.entity.ProductEntity; import com.showcase.synapse.product.entity.ProductEntity;
import com.showcase.synapse.product.event.ChannelCreatedEvent; import com.showcase.synapse.product.event.ChannelCreatedEvent;
import com.showcase.synapse.product.event.ProductCreatedEvent; import com.showcase.synapse.product.event.ProductCreatedEvent;
...@@ -35,6 +38,12 @@ public class ProductEventHandler { ...@@ -35,6 +38,12 @@ public class ProductEventHandler {
ChannelEntity ce = new ChannelEntity(); ChannelEntity ce = new ChannelEntity();
ce.setId(productCreatedEvent.getChannel()); ce.setId(productCreatedEvent.getChannel());
productEntity.setChannel(ce); productEntity.setChannel(ce);
InventoryEntity ie = new InventoryEntity();
ie.setWhid(UUID.randomUUID().toString());
ie.setProductid(productCreatedEvent.getProductId());
ie.setWhName("init wh data");
ie.setQuantity(0);
productEntity.setInventory(ie);
productRepository.save(productEntity); productRepository.save(productEntity);
......
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