package com.uas.platform.b2b.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.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.OrderBy;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.codehaus.jackson.annotate.JsonIgnore;

import com.alibaba.fastjson.annotation.JSONField;

/**
 * 平台里面，以供应商的角度来查看客户打样申请
 * 
 * @author suntg
 *
 */
@Table(name = "purc$proofing", indexes = {@Index(name = "unique_enuu_code", columnList = "pp_enuu,pp_code",unique = true)})
@Entity
public class PurchaseProofing implements Serializable {

	/**
	 * 序列号
	 */
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "pp_id")
	private Long id;

	/**
	 * 所属企业UU(买方)
	 */
	@Column(name = "pp_enuu")
	private Long enUU;

	/**
	 * 企业（买方）
	 */
	@OneToOne(cascade = { CascadeType.MERGE, CascadeType.REFRESH })
	@JoinColumn(name = "pp_enuu", insertable = false, updatable = false)
	private EnterpriseInfo enterprise;

	/**
	 * 买方申请人uu
	 */
	@Column(name = "pp_useruu")
	private Long userUU;

	/**
	 * 买方申请人
	 */
	@OneToOne(cascade = { CascadeType.REFRESH })
	@JoinColumn(name = "pp_useruu", insertable = false, updatable = false)
	private UserBaseInfo user;

	/**
	 * 流水号
	 */
	@Column(name = "pp_code")
	private String code;

	/**
	 * 单据录入日期
	 */
	@Column(name = "pp_indate")
	private Date date;

	/**
	 * 录入人
	 */
	@Column(name = "pp_recorder")
	private String recorder;

	/**
	 * 物料(买方物料)
	 */
	@OneToOne(cascade = { CascadeType.REFRESH })
	@JoinColumn(name = "pp_prid", insertable = false, updatable = false)
	private Product product;

	@Column(name = "pp_prid")
	private Long productId;

	/**
	 * 是否收费
	 */
	@Column(name = "pp_ischarge")
	private String isCharge;

	/**
	 * 需求交货日期
	 */
	@Column(name = "pp_delivery")
	private Date delivery;

	/**
	 * 环保要求
	 */
	@Column(name = "pp_envrequiry")
	private String envrequiry;

	/**
	 * 备注
	 */
	@Column(name = "pp_remark")
	private String remark;

	/**
	 * 使用范围
	 */
	@Column(name = "pp_scope")
	private String scope;

	/**
	 * 打样申请明细
	 */
	@OneToMany(mappedBy = "proofing", cascade = { CascadeType.REFRESH, CascadeType.PERSIST, CascadeType.REMOVE,
			CascadeType.MERGE }, fetch = FetchType.EAGER)
	@OrderBy("number")
	private Set<PurchaseProofingItem> proofingItems;

	/**
	 * 附件
	 */
	@OneToMany(cascade = {CascadeType.ALL}, fetch = FetchType.EAGER)
	@JoinTable(name="purc$proofingattach", joinColumns = @JoinColumn(name = "pp_id", referencedColumnName = "pp_id"), inverseJoinColumns = @JoinColumn(name="at_id", referencedColumnName = "at_id"))
	private Set<Attach> attachs;

	/**
	 * 对应erpid
	 * 
	 * @return
	 */
	@Column(name = "pp_erpid")
	private Long erpId;

	public Long getId() {
		return id;
	}

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

	public Long getEnUU() {
		return enUU;
	}

	public void setEnUU(Long enUU) {
		this.enUU = enUU;
	}

	public EnterpriseInfo getEnterprise() {
		return enterprise;
	}

	public void setEnterprise(EnterpriseInfo enterprise) {
		this.enterprise = enterprise;
	}

	public Long getUserUU() {
		return userUU;
	}

	public void setUserUU(Long userUU) {
		this.userUU = userUU;
	}

	public UserBaseInfo getUser() {
		return user;
	}

	public void setUser(UserBaseInfo user) {
		this.user = user;
	}

	public String getCode() {
		return code;
	}

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

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public String getRecorder() {
		return recorder;
	}

	public void setRecorder(String recorder) {
		this.recorder = recorder;
	}

	public Product getProduct() {
		return product;
	}

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

	public Long getProductId() {
		return productId;
	}

	public void setProductId(Long productId) {
		this.productId = productId;
	}

	public String getIsCharge() {
		return isCharge;
	}

	public void setIsCharge(String isCharge) {
		this.isCharge = isCharge;
	}

	public Date getDelivery() {
		return delivery;
	}

	public void setDelivery(Date delivery) {
		this.delivery = delivery;
	}

	public String getEnvrequiry() {
		return envrequiry;
	}

	public void setEnvrequiry(String envrequiry) {
		this.envrequiry = envrequiry;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public String getScope() {
		return scope;
	}

	public void setScope(String scope) {
		this.scope = scope;
	}

	@JsonIgnore
	@JSONField(serialize = false)
	public Set<PurchaseProofingItem> getProofingItems() {
		return proofingItems;
	}

	public void setProofingItems(Set<PurchaseProofingItem> proofingItems) {
		this.proofingItems = proofingItems;
	}

	public Set<Attach> getAttachs() {
		return attachs;
	}

	public void setAttachs(Set<Attach> attachs) {
		this.attachs = attachs;
	}

	public Long getErpId() {
		return erpId;
	}

	public void setErpId(Long erpId) {
		this.erpId = erpId;
	}

}