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:09:53
 */
@Entity(name = "trade.Order")
@Table(name = "trade$order")
public class Order implements Serializable {

	private static final long serialVersionUID = 1L;

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

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

	/**
	 * 买方uu
	 * 
	 * @Tip 这里因为平台作为中间商，下达订单都看做给平台下达订单
	 */
	@Column(name = "or_buyeruu")
	private Long buyeruu;

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

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

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

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

	/**
	 * 订单状态(1->2->3->4->5->6->7->8->9)
	 * 
	 * @Tip 必须严格按照顺序流转 1、TOBECONFIRMED(501, "待确认"), 2、TOBEPAID(503, "待付款"),
	 *      3、PAID(505, "已付款"), 4、TOBESHIPPED(406, "待出货"), 5、SHIPPINGIN(403,
	 *      "出货中"), 6、SHIPPED(407, "已出货"), 7、SENDING(408, "发货中"), 8、INBOUND(404,
	 *      "待收货") 9、RECEIVED(405, "已收货"), 10、UNAVAILABLE(602, "无效的");
	 */
	@Column(name = "or_status")
	private Integer status;

	/**
	 * 订单明细
	 */
	@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
	@JoinColumn(name = "order_id", updatable = false, insertable = false)
	@OrderBy("detno")
	private Set<OrderDetail> 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 Enterprise getBuyerEnterprise() {
		return buyerEnterprise;
	}

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

	public Enterprise getSellerEnterprise() {
		return sellerEnterprise;
	}

	public void setSellerEnterprise(Enterprise sellerEnterprise) {
		this.sellerEnterprise = sellerEnterprise;
	}

	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<OrderDetail> getDetails() {
		return details;
	}

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

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

}
