net.groupbuy.entity.OrderItem.java Source code

Java tutorial

Introduction

Here is the source code for net.groupbuy.entity.OrderItem.java

Source

/*
 * Copyright 2005-2013 shopxx.net. All rights reserved.
 * Support: http://www.shopxx.net
 * License: http://www.shopxx.net/license
 */
package net.groupbuy.entity;

import java.math.BigDecimal;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.Digits;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.NotEmpty;

import com.fasterxml.jackson.annotation.JsonProperty;

/**
 * Entity - ?
 * 
 * @author SHOP++ Team
 * @version 3.0
 */
@Entity
@Table(name = "xx_order_item")
@SequenceGenerator(name = "sequenceGenerator", sequenceName = "xx_order_item_sequence")
public class OrderItem extends BaseEntity {

    private static final long serialVersionUID = -4999926022604479334L;

    /** ?? */
    private String sn;

    /** ??? */
    private String name;

    /** ? */
    private String fullName;

    /** ? */
    private BigDecimal price;

    /** ??? */
    private Integer weight;

    /** ? */
    private String thumbnail;

    /** ?? */
    private Boolean isGift;

    /** ? */
    private Integer quantity;

    /** ?? */
    private Integer shippedQuantity;

    /** ? */
    private Integer returnQuantity;

    /** ? */
    private Product product;

    /** ? */
    private Order order;

    /**
     * ???
     * 
     * @return ??
     */
    @JsonProperty
    @NotEmpty
    @Column(nullable = false, updatable = false)
    public String getSn() {
        return sn;
    }

    /**
     * ??
     * 
     * @param sn
     *            ??
     */
    public void setSn(String sn) {
        this.sn = sn;
    }

    /**
     * ????
     * 
     * @return ???
     */
    @JsonProperty
    @Column(nullable = false, updatable = false)
    public String getName() {
        return name;
    }

    /**
     * ???
     * 
     * @param name
     *            ???
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * ??
     * 
     * @return ?
     */
    @JsonProperty
    @Column(nullable = false, updatable = false)
    public String getFullName() {
        return fullName;
    }

    /**
     * ?
     * 
     * @param fullName
     *            ?
     */
    public void setFullName(String fullName) {
        this.fullName = fullName;
    }

    /**
     * ??
     * 
     * @return ?
     */
    @JsonProperty
    @NotNull
    @Min(0)
    @Digits(integer = 12, fraction = 3)
    @Column(nullable = false, precision = 21, scale = 6)
    public BigDecimal getPrice() {
        return price;
    }

    /**
     * ?
     * 
     * @param price
     *            ?
     */
    public void setPrice(BigDecimal price) {
        this.price = price;
    }

    /**
     * ????
     * 
     * @return ???
     */
    @JsonProperty
    @Column(updatable = false)
    public Integer getWeight() {
        return weight;
    }

    /**
     * ???
     * 
     * @param weight
     *            ???
     */
    public void setWeight(Integer weight) {
        this.weight = weight;
    }

    /**
     * ??
     * 
     * @return ?
     */
    @JsonProperty
    @Column(updatable = false)
    public String getThumbnail() {
        return thumbnail;
    }

    /**
     * ?
     * 
     * @param thumbnail
     *            ?
     */
    public void setThumbnail(String thumbnail) {
        this.thumbnail = thumbnail;
    }

    /**
     * ???
     * 
     * @return ??
     */
    @JsonProperty
    @Column(nullable = false, updatable = false)
    public Boolean getIsGift() {
        return isGift;
    }

    /**
     * ??
     * 
     * @param isGift
     *            ??
     */
    public void setIsGift(Boolean isGift) {
        this.isGift = isGift;
    }

    /**
     * ??
     * 
     * @return ?
     */
    @JsonProperty
    @NotNull
    @Min(1)
    @Max(10000)
    @Column(nullable = false)
    public Integer getQuantity() {
        return quantity;
    }

    /**
     * ?
     * 
     * @param quantity
     *            ?
     */
    public void setQuantity(Integer quantity) {
        this.quantity = quantity;
    }

    /**
     * ???
     * 
     * @return ??
     */
    @Column(nullable = false)
    public Integer getShippedQuantity() {
        return shippedQuantity;
    }

    /**
     * ??
     * 
     * @param shippedQuantity
     *            ??
     */
    public void setShippedQuantity(Integer shippedQuantity) {
        this.shippedQuantity = shippedQuantity;
    }

    /**
     * ??
     * 
     * @return ?
     */
    @Column(nullable = false)
    public Integer getReturnQuantity() {
        return returnQuantity;
    }

    /**
     * ?
     * 
     * @param returnQuantity
     *            ?
     */
    public void setReturnQuantity(Integer returnQuantity) {
        this.returnQuantity = returnQuantity;
    }

    /**
     * ??
     * 
     * @return ?
     */
    @ManyToOne(fetch = FetchType.LAZY)
    public Product getProduct() {
        return product;
    }

    /**
     * ?
     * 
     * @param product
     *            ?
     */
    public void setProduct(Product product) {
        this.product = product;
    }

    /**
     * ??
     * 
     * @return ?
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "orders", nullable = false, updatable = false)
    public Order getOrder() {
        return order;
    }

    /**
     * ?
     * 
     * @param order
     *            ?
     */
    public void setOrder(Order order) {
        this.order = order;
    }

    /**
     * ????
     * 
     * @return ???
     */
    @JsonProperty
    @Transient
    public int getTotalWeight() {
        if (getWeight() != null && getQuantity() != null) {
            return getWeight() * getQuantity();
        } else {
            return 0;
        }
    }

    /**
     * ??
     * 
     * @return ?
     */
    @JsonProperty
    @Transient
    public BigDecimal getSubtotal() {
        if (getPrice() != null && getQuantity() != null) {
            return getPrice().multiply(new BigDecimal(getQuantity()));
        } else {
            return new BigDecimal(0);
        }
    }

}