package com.uas.search.console.b2b.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

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

/**
 * 平台里面，以供应商的角度来查看委外加工单
 * 
 * @author suntg
 *
 */
@Entity
@Table(name = MakeOrderSimpleInfo.TABLE_NAME)
public class MakeOrderSimpleInfo {

	/**
	 * 表名
	 */
	public static final String TABLE_NAME = "MAKE$ORDERS";

	/**
	 * 各字段列名（也是存储索引时的field名）
	 */
	public static final String ID_FIELD = "ma_id";

	public static final String CODE_FIELD = "ma_code";

	public static final String STATUS_FIELD = "ma_status";

	public static final String END_FIELD = "ma_end";

	public static final String VEND_FIELD = "ma_venduu";

	public static final String ENTERPRISE_FIELD = "ma_enuu";

	public static final String DATE_FIELD = "ma_date";

	public static final String PRODUCT_FIELD = "ma_prid";

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

	/**
	 * 委外加工单号
	 */
	@Column(name = CODE_FIELD)
	private String code;

	/**
	 * 处理状态（已回复、未回复），全部回复后改为已回复
	 */
	@Column(name = STATUS_FIELD)
	private Short status;

	/**
	 * 已结案为1
	 */
	@Column(name = END_FIELD)
	private Short end;

	/**
	 * 日期
	 */
	@Column(name = DATE_FIELD)
	private Date date;

	/**
	 * 采购单所属企业UU(客户)
	 */
	@OneToOne
	@JoinColumn(name = ENTERPRISE_FIELD, insertable = false, updatable = false)
	private EnterpriseSimpleInfo enterprise;

	/**
	 * 供应商（登录的本企业）
	 */
	@OneToOne
	@JoinColumn(name = VEND_FIELD, insertable = false, updatable = false)
	private EnterpriseSimpleInfo vend;

	/**
	 * 产品
	 */
	@OneToOne(cascade = { CascadeType.REFRESH })
	@JoinColumn(name = PRODUCT_FIELD, insertable = false, updatable = false)
	private ProductSimpleInfo product;

	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 Date getDate() {
		return date;
	}

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

	public Short getEnd() {
		return end;
	}

	public void setEnd(Short end) {
		this.end = end;
	}

	public EnterpriseSimpleInfo getEnterprise() {
		return enterprise;
	}

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

	public EnterpriseSimpleInfo getVend() {
		return vend;
	}

	public void setVend(EnterpriseSimpleInfo vend) {
		this.vend = vend;
	}

	public ProductSimpleInfo getProduct() {
		return product;
	}

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

	public Short getStatus() {
		return status;
	}

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

	/**
	 * 获取所有可以搜索的字段列名（索引的field名）
	 * 
	 * @return 可以搜索的字段列名
	 */
	public static List<String> getKeywordFields() {
		List<String> fields = new ArrayList<>();
		fields.add(CODE_FIELD);
		fields.add(ENTERPRISE_FIELD);
		fields.add(VEND_FIELD);
		fields.add(PRODUCT_FIELD);
		return fields;
	}

	@Override
	public String toString() {
		return "MakeOrderSimpleInfo [id=" + id + ", code=" + code + ", status=" + status + ", end=" + end + ", date="
				+ date + ", enterprise=" + enterprise + ", vend=" + vend + ", product=" + product + "]";
	}

}
