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.OrderBy;
import javax.persistence.Table;

/**
 * 商城采购订单
 * 
 * @author sunyj
 * @since 2016年10月14日 上午10:24:00
 */
@Entity(name = "trade.Purchase")
@Table(name = "trade$purchase")
public class Purchase implements Serializable {

	private static final long serialVersionUID = 1L;

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

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

	/**
	 * 企业卖方uu
	 * 
	 * @Tip 这里因为平台作为中间商，所以采购单都由平台下达
	 */
	@Column(name = "pu_sellerenuu")
	private Long sellerenuu;

	/**
	 * 卖方企业名称
	 */
	@Column(name = "pu_sellername")
	private String sellerenname;

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

	/**
	 * 订单状态(1->2->3)
	 * 
	 * @Tip 必须严格按照顺序流转 1、TOBESHIPPED(406, "待出货"), 2、INBOUND(404, "待收货"),
	 *      3、RECEIVED(405, "已收货"), 4、TOBEPAID(503, "待付款"), 5、PAID(504, "已付款"),
	 */
	@Column(name = "pu_status")
	private Integer status;

	/**
	 * 采购单明细
	 */
	@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
	@JoinColumn(name = "purchase_id", updatable = false, insertable = false)
	@OrderBy("detno")
	private Set<PurchaseDetail> 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 getSellerenuu() {
		return sellerenuu;
	}

	public void setSellerenuu(Long sellerenuu) {
		this.sellerenuu = sellerenuu;
	}

	public String getSellerenname() {
		return sellerenname;
	}

	public void setSellerenname(String sellerenname) {
		this.sellerenname = sellerenname;
	}

	public Date getCreatetime() {
		return createtime;
	}

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

	public Integer getStatus() {
		return status;
	}

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

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

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

	@Override
	public String toString() {
		return "Purchase [id=" + id + ", code=" + code + ", sellerenuu=" + sellerenuu + ", sellerenname="
				+ sellerenname + ", createtime=" + createtime + ", status=" + status + ", details=" + details + "]";
	}

}
