microservices-event-sourcing-master/inventory-service/src/main/java/com/timeyang/inventory/Inventory.java
package com.timeyang.inventory;

import com.timeyang.product.Product;
import com.timeyang.warehouse.Warehouse;
import org.neo4j.ogm.annotation.GraphId;
import org.neo4j.ogm.annotation.NodeEntity;
import org.neo4j.ogm.annotation.Relationship;

/**
 * <h1>库存</h1>
 * 每个库存代表的数量为1的一个产品。如一个产品有800个库存，在neo4j就有800个inventory节点与该product节点关联<br/>
 * 一个商品的库存可以位于不同仓库<br/>
 * 这样设计易于实现幂等性，在完成订单事务失败时，能够更好地返库存。而如果一个库存记录代表多个库存数量，则在并发返库存时会遇到一些问题<br/>
 * @author chaokunyang
 */
@NodeEntity
public class Inventory {
    @GraphId
    private Long id;

    private String inventoryNumber;

    @Relationship(type = "PRODUCT_TYPE")
    private Product product;

    @Relationship(type = "STOCKED_IN")
    private Warehouse warehouse;

    private InventoryStatus status;

    public Inventory() {
    }

    public Inventory(String inventoryNumber, Product product, Warehouse warehouse, InventoryStatus status) {
        this.inventoryNumber = inventoryNumber;
        this.product = product;
        this.warehouse = warehouse;
        this.status = status;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getInventoryNumber() {
        return inventoryNumber;
    }

    public void setInventoryNumber(String inventoryNumber) {
        this.inventoryNumber = inventoryNumber;
    }

    public Product getProduct() {
        return product;
    }

    public void setProduct(Product product) {
        this.product = product;
    }

    public Warehouse getWarehouse() {
        return warehouse;
    }

    public void setWarehouse(Warehouse warehouse) {
        this.warehouse = warehouse;
    }

    public InventoryStatus getStatus() {
        return status;
    }

    public void setStatus(InventoryStatus status) {
        this.status = status;
    }

    @Override
    public String toString() {
        return "Inventory{" +
                "id=" + id +
                ", inventoryNumber='" + inventoryNumber + '\'' +
                ", product=" + product +
                ", warehouse=" + warehouse +
                ", status=" + status +
                '}';
    }
}
