package com.uas.platform.b2b.model;

import com.alibaba.fastjson.annotation.JSONField;
import org.codehaus.jackson.annotate.JsonIgnore;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.Set;

/**
 * 平台里面，以供应商的角度来查看采购询价单
 * 
 * <pre>
 * 数据库虚拟列里面用到的函数，是不允许操作动态数据的；原over_sysdate函数用法存在问题；
 * 改用视图{@code v$purc$inquiry}处理
 * </pre>
 * 
 * @author yingp
 * 
 */
@Table(name = "v$purc$inquiry", indexes = {@Index(name = "unique_enuu_code", columnList = "in_enuu,in_code", unique = true)})
@Entity
public class Inquiry implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

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

	/**
	 * 询价单所属企业UU
	 */
	@Column(name = "in_enuu")
	private Long enUU;

	/**
	 * 询价单所属用户UU
	 */
	@Column(name = "in_recorderuu")
	private Long recorderUU;

	/**
	 * 询价单采购员
	 */
	@OneToOne(cascade = { CascadeType.REFRESH })
	@JoinColumn(name = "in_recorderuu", insertable = false, updatable = false)
	private UserBaseInfo recorderUser;

	/**
	 * 询价企业
	 */
	@OneToOne(cascade = { CascadeType.MERGE, CascadeType.REFRESH })
	@JoinColumn(name = "in_enuu", insertable = false, updatable = false)
	private EnterpriseInfo enterprise;

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

	/**
	 * 单据归属日期
	 */
	@Column(name = "in_date")
	private Date date;

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

	/**
	 * 审核人
	 */
	@Column(name = "in_auditor")
	private String auditor;

	/**
	 * 报价截止日期
	 */
	@Column(name = "in_enddate")
	private Date endDate;

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

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

	/**
	 * 价格类型
	 */
	@Column(name = "in_pricetype")
	private String priceType;

	/**
	 * 询价明细
	 */
	@OneToMany(mappedBy = "inquiry", cascade = { CascadeType.REFRESH, CascadeType.PERSIST, CascadeType.REMOVE,
			CascadeType.MERGE }, fetch = FetchType.EAGER)
	@OrderBy("number")
	private Set<PurchaseInquiryDetail> inquiryItems;

	/**
	 * 来源系统单据ID
	 */
	@Column(name = "in_sourceid")
	private Long sourceId;

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

	/**
	 * 客户已提交
	 */
	@Column(name = "in_checked")
	private Short check;

	/**
	 * 是否过期
	 */
	@Column(name = "in_overdue", insertable = false, updatable = false)
	private Short overdue;

	/**
	 * 是否公开<br>
	 * 1、 公共<br>
	 * 0、 不用开
	 */
	@Column(name = "in_isopen")
	private Short isOpen;

	/**
	 * 应用来源，主要是为了平台公共询价做处理
	 */
	@Column(name = "in_sourceapp")
	private String sourceApp;

	/**
	 * 收货地址
	 */
	@Column(name = "in_ship")
	private String ship;

	/**
	 * 是否开票<br>
	 * 1. 是<br>
	 * 0. 否
	 */
	@Column(name = "in_invoice")
	private Short invoice;

	/**
	 * 询价类型
	 */
	@Column(name = "in_inquirytype")
	private String inquirytype;

	/**
	 * 询价种类（公共或其他）
	 */
	@Column(name = "in_kind")
	private String kind;

	public Long getId() {
		return id;
	}

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

	public String getCode() {
		return code;
	}

	public String getPriceType() {
		return priceType;
	}

	public void setPriceType(String priceType) {
		this.priceType = priceType;
	}

	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 String getAuditor() {
		return auditor;
	}

	public void setAuditor(String auditor) {
		this.auditor = auditor;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	public String getRemark() {
		return remark;
	}

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

	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 getRecorderUU() {
		return recorderUU;
	}

	public void setRecorderUU(Long recorderUU) {
		this.recorderUU = recorderUU;
	}

	public Long getSourceId() {
		return sourceId;
	}

	public void setSourceId(Long sourceId) {
		this.sourceId = sourceId;
	}

	@JsonIgnore
	@JSONField(serialize = false)
	public Set<PurchaseInquiryDetail> getInquiryItems() {
		return inquiryItems;
	}

	public void setInquiryItems(Set<PurchaseInquiryDetail> inquiryItems) {
		this.inquiryItems = inquiryItems;
	}

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

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

	public String getEnvironment() {
		return environment;
	}

	public void setEnvironment(String environment) {
		this.environment = environment;
	}

	public Short getCheck() {
		return check;
	}

	public void setCheck(Short check) {
		this.check = check;
	}

	public Short getOverdue() {
		return overdue;
	}

	public void setOverdue(Short overdue) {
		this.overdue = overdue;
	}

	public Short getIsOpen() {
		return isOpen;
	}

	public void setIsOpen(Short isOpen) {
		this.isOpen = isOpen;
	}

	public String getSourceApp() {
		return sourceApp;
	}

	public void setSourceApp(String sourceApp) {
		this.sourceApp = sourceApp;
	}

	public String getShip() {
		return ship;
	}

	public void setShip(String ship) {
		this.ship = ship;
	}

	public Short getInvoice() {
		return invoice;
	}

	public void setInvoice(Short invoice) {
		this.invoice = invoice;
	}

	public String getInquirytype() {
		return inquirytype;
	}

	public void setInquirytype(String inquirytype) {
		this.inquirytype = inquirytype;
	}

	public String getKind() {
		return kind;
	}

	public void setKind(String kind) {
		this.kind = kind;
	}

	public UserBaseInfo getRecorderUser() {
		return recorderUser;
	}

	public void setRecorderUser(UserBaseInfo recorderUser) {
		this.recorderUser = recorderUser;
	}
}