package com.uas.platform.b2b.erp.model;

import com.uas.platform.b2b.model.Enterprise;
import com.uas.platform.b2b.model.Product;
import com.uas.platform.b2b.support.SystemSession;
import com.uas.platform.core.model.Constant;
import com.uas.platform.core.model.Status;

import java.util.Date;

/**
 * ERP系统的产品
 * 
 * @author yingp
 * 
 */
public class Prod {

	private Long pr_id;// 买方ERP物料ID
	private String pr_code;
	private String pr_detail;
	private String pr_spec;
	private String pr_unit;
	private Double pr_zxbzs;
	private Double pr_zxdhl;
	private Double pr_leadtime;
	private Double pr_ltinstock;// 备料提前期，天数
	private String pr_brand;
	private String pr_orispeccode;// 原厂型号
	private String pr_uuid; // 标准料号
	private String pr_status; // 状态： ‘已审核’->有效；‘已禁用’->失效
	private Short pr_issale; // 可销售
	private Short pr_ispurchase; // 可采购
	private Short pr_isshow; // 开放采购物料
	private Short pr_ispubsale; // 开发销售物料
	private Long b2b_id; // 平台id
	/**
	 * 类目（平台）
	 */
	private String kind;

	/**
	 * 品牌（平台）
	 */
	private String pbrand;

	/**
	 * 型号（平台）
	 */
	private String pcmpcode;

	/**
	 * 类目英文
	 */
	private String kinden;

	/**
	 * 品牌英文
	 */
	private String pbranden;

	/**
	 * 是否是标准
	 */
	private Short standard;

	public String getPr_code() {
		return pr_code;
	}

	public void setPr_code(String pr_code) {
		this.pr_code = pr_code;
	}

	public String getPr_detail() {
		return pr_detail;
	}

	public void setPr_detail(String pr_detail) {
		this.pr_detail = pr_detail;
	}

	public String getPr_spec() {
		return pr_spec;
	}

	public void setPr_spec(String pr_spec) {
		this.pr_spec = pr_spec;
	}

	public String getPr_unit() {
		return pr_unit;
	}

	public void setPr_unit(String pr_unit) {
		this.pr_unit = pr_unit;
	}

	public Double getPr_zxbzs() {
		return pr_zxbzs;
	}

	public void setPr_zxbzs(Double pr_zxbzs) {
		this.pr_zxbzs = pr_zxbzs;
	}

	public Double getPr_zxdhl() {
		return pr_zxdhl;
	}

	public void setPr_zxdhl(Double pr_zxdhl) {
		this.pr_zxdhl = pr_zxdhl;
	}

	public Double getPr_leadtime() {
		return pr_leadtime;
	}

	public void setPr_leadtime(Double pr_leadtime) {
		this.pr_leadtime = pr_leadtime;
	}

	public Double getPr_ltinstock() {
		return pr_ltinstock;
	}

	public void setPr_ltinstock(Double pr_ltinstock) {
		this.pr_ltinstock = pr_ltinstock;
	}

	public Long getPr_id() {
		return pr_id;
	}

	public void setPr_id(Long pr_id) {
		this.pr_id = pr_id;
	}

	public String getPr_orispeccode() {
		return pr_orispeccode;
	}

	public void setPr_orispeccode(String pr_orispeccode) {
		this.pr_orispeccode = pr_orispeccode;
	}

	public String getPr_uuid() {
		return pr_uuid;
	}

	public void setPr_uuid(String pr_uuid) {
		this.pr_uuid = pr_uuid;
	}

	public String getPr_status() {
		return pr_status;
	}

	public void setPr_status(String pr_status) {
		this.pr_status = pr_status;
	}

	public Short getPr_issale() {
		return pr_issale;
	}

	public void setPr_issale(Short pr_issale) {
		this.pr_issale = pr_issale;
	}

	public Short getPr_ispurchase() {
		return pr_ispurchase;
	}

	public void setPr_ispurchase(Short pr_ispurchase) {
		this.pr_ispurchase = pr_ispurchase;
	}

	public Short getPr_isshow() {
		return pr_isshow;
	}

	public void setPr_isshow(Short pr_isshow) {
		this.pr_isshow = pr_isshow;
	}

	public Short getPr_ispubsale() {
		return pr_ispubsale;
	}

	public void setPr_ispubsale(Short pr_ispubsale) {
		this.pr_ispubsale = pr_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 String getPr_brand() {
		return pr_brand;
	}

	public void setPr_brand(String pr_brand) {
		this.pr_brand = pr_brand;
	}

	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 Short getStandard() {
		return standard;
	}

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

	public Long getB2b_id() {
		return b2b_id;
	}

	public void setB2b_id(Long b2b_id) {
		this.b2b_id = b2b_id;
	}

	/**
	 * 转为平台的产品
	 * 
	 * @return
	 */
	public Product convert() {
		Product product = new Product();
		product.setCode(this.pr_code);
		product.setEnUU(SystemSession.getUser().getEnterprise().getUu());
		product.setUserUU(SystemSession.getUser().getUserUU());
		product.setTitle(this.pr_detail);
		product.setSpec(this.pr_spec);
		product.setUnit(this.pr_unit);
		product.setMinPack(this.pr_zxbzs);
		product.setMinOrder(this.pr_zxdhl);
		product.setLeadtime(this.pr_leadtime);
		product.setLtinstock(this.pr_ltinstock);
		product.setSourceId(this.pr_id);
		product.setBrand(this.pr_brand);
		if (this.pr_orispeccode != null) {
			product.setCmpCode(this.pr_orispeccode);
		} else {
			product.setCmpCode(this.pr_spec);
		}
		// if (this.pr_uuid != null) {
		// // 如果传过来的数据是有UUID，则把原来的信息赋值给标准信息上
		// product.setStandard(Constant.YES);
		// product.setPcmpcode(product.getCmpCode());
		// product.setPbrand(product.getBrand());
		// product.setKind(product.getTitle());
		// } else {
		// product.setStandard(Constant.NO);
		// }
		product.setStandard(Constant.NO);// 默认设置为非标准，到平台做匹配更新
		Enterprise enter = SystemSession.getUser().getEnterprise();
		// 默认开启关闭状态都是开启
		product.setIsPurchase(Constant.YES);
		product.setIsSale(Constant.YES);
		if (null != enter.getProdpurc() && enter.getProdpurc().equals(Constant.NO)) {
			product.setIsPurchase(Constant.NO);
		}
		if (null != enter.getProdsale() && enter.getProdsale().equals(Constant.NO)) {
			product.setIsSale(Constant.NO);
		}
		// erp上传的数据默认赋值给标准信息
		product.setPbrand(product.getBrand());
		product.setPcmpcode(product.getCmpCode());
		product.setKind(product.getTitle());
		product.setIsPubsale(this.pr_ispubsale);
		product.setIsPurchase(this.pr_ispurchase);
		product.setIsSale(this.pr_issale);
		product.setIsShow(this.pr_isshow);
		product.setStandard(this.standard);
		product.setSourceApp("ERP");
		product.setErpDate(new Date());
		return product;
	}

}
