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

import javax.persistence.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 委外变更单明细
 * 
 * @author suntg
 * @since 2015年8月6日下午2:57:52
 */
@Table(name = MakeOrderChangeItemSimpleInfo.TABLE_NAME)
@Entity
public class MakeOrderChangeItemSimpleInfo {

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

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

	public static final String CODE_FIELD = "mcd_macode";

	public static final String VEND_FIELD = "mcd_venduu";

	public static final String PRODUCT_FIELD = "mcd_prid";

	public static final String MAKE_FIELD = "mcd_pcid";

	public static final String DATE_FIELD = "mcd_date";

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

	/**
	 * 供应商企业
	 */
	@OneToOne
	@JoinColumn(name = VEND_FIELD, insertable = false, updatable = false)
	private EnterpriseSimpleInfo vend;

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

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

	/**
	 * 采购变更单
	 */
	@OneToOne(cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
	@JoinColumn(name = MAKE_FIELD, insertable = false, updatable = false)
	private MakeChangesSimpleInfo makeChanges;

	@Column(name = DATE_FIELD)
	private Date date;

	public Long getId() {
		return id;
	}

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

	public EnterpriseSimpleInfo getVend() {
		return vend;
	}

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

	public String getOrderCode() {
		return orderCode;
	}

	public void setOrderCode(String orderCode) {
		this.orderCode = orderCode;
	}

	public ProductSimpleInfo getProduct() {
		return product;
	}

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

	public MakeChangesSimpleInfo getMakeChanges() {
		return makeChanges;
	}

	public void setMakeChanges(MakeChangesSimpleInfo makeChanges) {
		this.makeChanges = makeChanges;
	}

	public Date getDate() {
		return this.getMakeChanges().getDate();
	}

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

	@Override
	public String toString() {
		return "MakeOrderChangeItemSimpleInfo{" +
				"id=" + id +
				", vend=" + vend +
				", orderCode='" + orderCode + '\'' +
				", product=" + product +
				", makeChanges=" + makeChanges +
				", date=" + date +
				'}';
	}

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

}