package com.uas.search.model;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.OrderBy;
import javax.persistence.Table;

/**
 * 商城销售订单的发货单
 * 
 * @author sunyj
 * @since 2016年10月14日 上午10:05:02
 */
@Entity
@Table(name = "trade$invoice_fmor")
public class OrderInvoice implements Serializable {

	private static final long serialVersionUID = 1L;

	@Id
	@Column(name = "id")
	private Long id;

	/**
	 * 发货单号，因易与id命名混淆，其他类、lucenne建索引时该字段难以区分，特以此命名
	 */
	@Column(name = "in_id", unique = true)
	private String code;

	/**
	 * 买方uu
	 * 
	 * @Tip 这里因为平台作为中间商，所以发货单都由平台下达
	 */
	@Column(name = "in_buyeruu")
	private Long buyeruu;

	/**
	 * 买方姓名
	 */
	@Column(name = "in_buyername")
	private String buyername;

	/**
	 * 买方企业
	 * 
	 * @Tip 这里因为平台作为中间商，下达订单都看做给平台下达订单
	 */
	@OneToOne
	@JoinColumn(name = "in_buyerenuu", updatable = false, insertable = false)
	private Enterprise buyerEnterprise;

	/**
	 * 单生成时间
	 */
	@Column(name = "in_creattime")
	private Date createtime;

	/**
	 * 订单状态(1->2)
	 * 
	 * @Tip 必须严格按照顺序流转 1、INBOUND(404, "待收货") 2、RECEIVED(405, "已收货"),
	 */
	@Column(name = "in_status")
	private Integer status;

	/**
	 * 发货单明细
	 */
	@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
	@JoinColumn(name = "invoice_id", updatable = false, insertable = false)
	@OrderBy("detno")
	private Set<OrderInvoiceDetail> details;

	public Long getId() {
		return id;
	}

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

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public Long getBuyeruu() {
		return buyeruu;
	}

	public void setBuyeruu(Long buyeruu) {
		this.buyeruu = buyeruu;
	}

	public String getBuyername() {
		return buyername;
	}

	public void setBuyername(String buyername) {
		this.buyername = buyername;
	}

	public Date getCreatetime() {
		return createtime;
	}

	public void setCreatetime(Date createtime) {
		this.createtime = createtime;
	}

	public Enterprise getBuyerEnterprise() {
		return buyerEnterprise;
	}

	public void setBuyerEnterprise(Enterprise buyerEnterprise) {
		this.buyerEnterprise = buyerEnterprise;
	}

	public Integer getStatus() {
		return status;
	}

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

	public Set<OrderInvoiceDetail> getDetails() {
		return details;
	}

	public void setDetails(Set<OrderInvoiceDetail> details) {
		this.details = details;
	}

	@Override
	public String toString() {
		return "OrderInvoice [id=" + id + ", code=" + code + ", buyeruu=" + buyeruu + ", buyername="
				+ buyername + ", buyerEnterprise=" + buyerEnterprise + ", createtime=" + createtime + ", status="
				+ status + ", details=" + details + "]";
	}

}
