package com.uas.platform.b2b.model;

import com.uas.platform.core.persistence.EnterpriseUU;
import com.uas.platform.core.persistence.Logger;
import com.uas.platform.core.persistence.UserUU;

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.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.Set;

/**
 * 商品信息
 * 
 * @author yingp
 *
 */
@Entity
@Table(name = "v$products", indexes = {@Index(name = "enuu_code_unique", columnList = "pr_enuu,pr_code", unique = true),
		@Index(name = "pr_issale_idx", columnList = "pr_issale"),
		@Index(name = "pr_ispurchase_idx", columnList = "pr_ispurchase"),
		@Index(name = "pr_standard_idx", columnList = "pr_standard")})
@Logger
public class Product {

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

	/**
	 * 商品信息标题
	 */
	@Column(name = "pr_title")
	private String title;

	/**
	 * 产品编号
	 */
	@NotNull
	@Column(name = "pr_code")
	private String code;

	/**
	 * 产品规格
	 */
	@Column(name = "pr_spec", length = 500)
	private String spec;

	/**
	 * 单位
	 */
	@Column(name = "pr_unit")
	private String unit;

	/**
	 * 所属企业UU
	 */
	@NotNull
	@Column(name = "pr_enuu")
	@EnterpriseUU
	private Long enUU;

	/**
	 * 个人UU
	 */
	@Column(name = "pr_useruu")
	@UserUU
	private Long userUU;

	/**
	 * 最小包装量
	 */
	@Column(name = "pr_minpack")
	private Double minPack;

	/**
	 * 最小采购量
	 */
	@Column(name = "pr_minorder")
	private Double minOrder;

	/**
	 * 采购提前期
	 */
	@Column(name = "pr_leadtime")
	private Double leadtime;

	/**
	 * 备货提前期（天数）
	 */
	@Column(name = "pr_ltinstock")
	private Double ltinstock;

	/**
	 * 价格
	 */
	@Column(name = "pr_price")
	private Double price;

	/**
	 * 品牌（ERP)
	 */
	@Column(name = "pr_brand")
	private String brand;

	/**
	 * 买方ERP物料ID
	 */
	@Column(name = "pr_sourceid")
	private Long sourceId;

	/**
	 * 保存erp传入数据的时间
	 * 
	 * @return
	 */
	@Column(name = "pr_erpdate")
	private Date erpDate;

	/**
	 * 原厂型号(erp)
	 * 
	 * @return
	 */
	@Column(name = "pr_cmpcode", length = 500)
	private String cmpCode;

	/**
	 * UUID 标准料号
	 * 
	 * @return
	 */
	@Column(name = "pr_cmpuuid")
	private String cmpUuId;

	/**
	 * 应用来源<br>
	 * 平台上传的为可以销售的
	 * 
	 * @return
	 */
	@Column(name = "pr_sourceapp")
	private String sourceApp;

	/**
	 * 是否可卖<br>
	 * 1. 可以卖 <br>
	 * 0. 不可
	 */
	@Column(name = "pr_issale")
	private Short isSale;

	/**
	 * 是否可买<br>
	 * 1. 可以买<br>
	 * 0. 不可
	 */
	@Column(name = "pr_ispurchase")
	private Short isPurchase;

	/**
	 * 公开展示<br>
	 * 
	 * 1. 是<br>
	 * 0. 否
	 */
	@Column(name = "pr_isshow")
	private Short isShow;

	/**
	 * 公开销售 <br>
	 * 1. 是<br>
	 * 0. 否
	 */
	@Column(name = "pr_ispubsale")
	private Short isPubsale;

	/**
	 * 附件
	 */
	@Column(name = "pr_attachment")
	private String attachment;

	/**
	 * 类目（平台）（中文）
	 */
	@Column(name = "pr_kind")
	private String kind;

	/**
	 * 品牌（平台）（中文）
	 */
	@Column(name = "pr_pbrand")
	private String pbrand;

	/**
	 * 型号（平台）
	 */
	@Column(name = "pr_pcmpcode")
	private String pcmpcode;

	/**
	 * 是否是标准物料<br>
	 * 1.YES<br>
	 * 0.NO
	 */
	@Column(name = "pr_standard")
	private Short standard;

	/**
	 * 类目（平台）（英文）
	 */
	@Column(name = "pr_kinden")
	private String kinden;

	/**
	 * 品牌（平台）（英文）
	 */
	@Column(name = "pr_pbranden")
	private String pbranden;

	/**
	 * 匹配状态（记录匹配状态，方便下次查看）
	 */
	@Column(name = "pr_matchstatus")
	private Integer matchstatus;

	/**
	 * 匹配数量（用作排序）
	 */
	@Column(name = "pr_matchsize")
	private Integer matchsize;

	/**
	 * 下载状态，平台更新ERP的数据后，将数据回传回ERP更新
	 */
	@Column(name = "pr_downloadstatus")
	private Integer downloadstatus;

	/**
	 * 图片
	 */
	@Column(name = "pr_cmpimg")
	private String img;

	/**
	 * 封装
	 */
	@Column(name = "pr_encapsulation")
	private String encapsulation;

	/**
	 * 匹配成标准的日期
	 */
	@Column(name = "pr_tostandard")
	private Date tostandard;

	/**
	 * 编码版本号
	 */
	@Column(name = "pr_goodsnover")
	private String goodsnover;

	/**
	 * 税收分类编码
	 */
	@Column(name = "pr_goodstaxno")
	private String goodstaxno;

	/**
	 * 是否享受优惠政策
	 */
	@Column(name = "pr_taxpre")
	private String taxpre;

	/**
	 * 享受优惠政策内容
	 */
	@Column(name = "pr_taxprecon")
	private String taxprecon;

	/**
	 * ERP库存
	 */
	@Column(name = "pr_reserve")
	private Double reserve;

	/**
	 * 标准类目id
	 */
	@Column(name = "pr_kindid")
	private Long kindId;

	/**
	 * 标准品牌id
	 */
	@Column(name = "pr_pbrandid")
	private Long pbrandId;

	/**
	 * 标准品牌uuid
	 */
	@Column(name = "pr_pbranduuid")
	private String pbrandUuid;

	/**
	 * 包装方式
	 */
	@Column(name = "pr_packaging")
	private String packaging;

	/**
	 * 产品建立时间
	 */
	@Column(name = "pr_create_time")
	private Date createTime;

	/**
	 * 产品生产日期
	 */
	@Column(name = "pr_manufacturedate")
	private String manufactureDate;

	/**
	 * 最大交期
	 */
	@Column(name = "pr_maxdelivery")
	private Short maxDelivery;

	/**
	 * 最小交期
	 */
	@Column(name = "pr_mindelivery")
	private Short minDelivery;

	/**
	 * 是否可拆卖
	 */
	@Column(name = "pr_isbreakup")
	private Boolean isBreakUp;

	/**
	 * b2b物料禁用状态
	 */
	@Column(name = "pr_b2bdisabled", insertable = false, updatable = false)
	private Short b2bDisabled;

	/**
	 * 匹配的料号（买方）（用于供应商推荐接口匹配状态）
	 */
	@Transient
	private String ifMatched;

	public Product() {
	}

	public Product(PurchaseTenderProd tenderProd, Long currentEnUU) {
    	this.code = tenderProd.getProdCode();
    	this.title = tenderProd.getProdTitle();
    	this.unit = tenderProd.getUnit();
    	this.brand = tenderProd.getBrand();
    	this.enUU = currentEnUU;
    }

	public Long getId() {
		return id;
	}

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

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getCode() {
		return code;
	}

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

	public String getSpec() {
		return spec;
	}

	public void setSpec(String spec) {
		this.spec = spec;
	}

	public String getUnit() {
		return unit;
	}

	public void setUnit(String unit) {
		this.unit = unit;
	}

	public Long getEnUU() {
		return enUU;
	}

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

	public Long getUserUU() {
		return userUU;
	}

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

	public Double getMinPack() {
		return minPack;
	}

	public void setMinPack(Double minPack) {
		this.minPack = minPack;
	}

	public Double getMinOrder() {
		return minOrder;
	}

	public void setMinOrder(Double minOrder) {
		this.minOrder = minOrder;
	}

	public Double getLeadtime() {
		return leadtime;
	}

	public void setLeadtime(Double leadtime) {
		this.leadtime = leadtime;
	}

	public Double getPrice() {
		return price;
	}

	public void setPrice(Double price) {
		this.price = price;
	}

	public String getBrand() {
		return brand;
	}

	public void setBrand(String brand) {
		this.brand = brand;
	}

	public Double getLtinstock() {
		return ltinstock;
	}

	public void setLtinstock(Double ltinstock) {
		this.ltinstock = ltinstock;
	}

	public Long getSourceId() {
		return sourceId;
	}

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

	public Date getErpDate() {
		return erpDate;
	}

	public void setErpDate(Date erpDate) {
		this.erpDate = erpDate;
	}

	public String getCmpCode() {
		return cmpCode;
	}

	public void setCmpCode(String cmpCode) {
		this.cmpCode = cmpCode;
	}

	public String getCmpUuId() {
		return cmpUuId;
	}

	public void setCmpUuId(String cmpUuId) {
		this.cmpUuId = cmpUuId;
	}

	@Override
	public String toString() {
		return "编号：" + getCode() + "，标题：" + getTitle() + "，规格型号：" + getSpec();
	}

	public String getSourceApp() {
		return sourceApp;
	}

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

	public Short getIsSale() {
		return isSale;
	}

	public void setIsSale(Short isSale) {
		this.isSale = isSale;
	}

	public Short getIsPurchase() {
		return isPurchase;
	}

	public void setIsPurchase(Short isPurchase) {
		this.isPurchase = isPurchase;
	}

	public Short getIsShow() {
		return isShow;
	}

	public void setIsShow(Short isShow) {
		this.isShow = isShow;
	}

	public Short getIsPubsale() {
		return isPubsale;
	}

	public void setIsPubsale(Short isPubsale) {
		this.isPubsale = isPubsale;
	}

	public String getKind() {
		return kind;
	}

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

	public String getPbrand() {
		return pbrand;
	}

	public void setPbrand(String pbrand) {
		this.pbrand = pbrand;
	}

	public String getPcmpcode() {
		return pcmpcode;
	}

	public void setPcmpcode(String pcmpcode) {
		this.pcmpcode = pcmpcode;
	}

	public Short getStandard() {
		return standard;
	}

	public void setStandard(Short standard) {
		this.standard = standard;
	}

	public String getKinden() {
		return kinden;
	}

	public void setKinden(String kinden) {
		this.kinden = kinden;
	}

	public String getPbranden() {
		return pbranden;
	}

	public void setPbranden(String pbranden) {
		this.pbranden = pbranden;
	}

	public Integer getMatchstatus() {
		return matchstatus;
	}

	public void setMatchstatus(Integer matchstatus) {
		this.matchstatus = matchstatus;
	}

	public Integer getMatchsize() {
		return matchsize;
	}

	public void setMatchsize(Integer matchsize) {
		this.matchsize = matchsize;
	}

	public Integer getDownloadstatus() {
		return downloadstatus;
	}

	public void setDownloadstatus(Integer downloadstatus) {
		this.downloadstatus = downloadstatus;
	}

	public String getImg() {
		return img;
	}

	public void setImg(String img) {
		this.img = img;
	}

	public String getEncapsulation() {
		return encapsulation;
	}

	public void setEncapsulation(String encapsulation) {
		this.encapsulation = encapsulation;
	}

	public Date getTostandard() {
		return tostandard;
	}

	public void setTostandard(Date tostandard) {
		this.tostandard = tostandard;
	}

	public String getGoodsnover() {
		return goodsnover;
	}

	public void setGoodsnover(String goodsnover) {
		this.goodsnover = goodsnover;
	}

	public String getGoodstaxno() {
		return goodstaxno;
	}

	public void setGoodstaxno(String goodstaxno) {
		this.goodstaxno = goodstaxno;
	}

	public String getTaxpre() {
		return taxpre;
	}

	public void setTaxpre(String taxpre) {
		this.taxpre = taxpre;
	}

	public String getTaxprecon() {
		return taxprecon;
	}

	public void setTaxprecon(String taxprecon) {
		this.taxprecon = taxprecon;
	}

	public String getAttachment() {
		return attachment;
	}

	public void setAttachment(String attachment) {
		this.attachment = attachment;
	}

	public Double getReserve() {
		return reserve;
	}

	public void setReserve(Double reserve) {
		this.reserve = reserve;
	}

	public Long getKindId() {
		return kindId;
	}

	public void setKindId(Long kindId) {
		this.kindId = kindId;
	}

	public Long getPbrandId() {
		return pbrandId;
	}

	public void setPbrandId(Long pbrandId) {
		this.pbrandId = pbrandId;
	}

	public String getPbrandUuid() {
		return pbrandUuid;
	}

	public void setPbrandUuid(String pbrandUuid) {
		this.pbrandUuid = pbrandUuid;
	}

	public String getPackaging() {
		return packaging;
	}

	public void setPackaging(String packaging) {
		this.packaging = packaging;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public String getManufactureDate() {
		return manufactureDate;
	}

	public void setManufactureDate(String manufactureDate) {
		this.manufactureDate = manufactureDate;
	}

	public Short getMaxDelivery() {
		return maxDelivery;
	}

	public void setMaxDelivery(Short maxDelivery) {
		this.maxDelivery = maxDelivery;
	}

	public Short getMinDelivery() {
		return minDelivery;
	}

	public void setMinDelivery(Short minDelivery) {
		this.minDelivery = minDelivery;
	}

	public Boolean getBreakUp() {
		return isBreakUp;
	}

	public void setBreakUp(Boolean breakUp) {
		isBreakUp = breakUp;
	}

	public Short getB2bDisabled() {
		return b2bDisabled;
	}

	public void setB2bDisabled(Short b2bDisabled) {
		this.b2bDisabled = b2bDisabled;
	}

	public String getIfMatched() {
		return ifMatched;
	}

	public void setIfMatched(String ifMatched) {
		this.ifMatched = ifMatched;
	}
}