package com.uas.platform.b2b.model;

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

import javax.persistence.*;
import java.util.*;

/**
 * 买家的采购验退单明细
 * 
 * @author suntg
 * 
 */
@Table(name = "purc$returnitem")
@Entity
public class PurchaseReturnItem {

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

	/**
	 * 序号
	 */
	@Column(name = "pri_number")
	private Short number;

	/**
	 * 数量
	 */
	@Column(name = "pri_qty")
	private Double qty;

	/**
	 * 采购单价
	 */
	@Column(name = "pri_orderprice")
	private Double orderPrice;

	/**
	 * 单价
	 */
	@Column(name = "pri_taxrate")
	private Double taxrate;

	/**
	 * 验收单主记录
	 */
	@ManyToOne(cascade = CascadeType.ALL, optional = true)
	@JoinColumn(name = "pri_prid", nullable = false)
	private PurchaseReturn purchaseReturn;

	/**
	 * 采购单明细id
	 */
	@Column(name = "pri_pdid")
	private Long orderItemId;

	/**
	 * 入库批号
	 */
	@Column(name = "pri_batchcode")
	private String batchCode;

	/**
	 * 入库料号
	 */
	@Column(name = "pri_prodcode")
	private String prodCode;

	/**
	 * 仓库名称
	 */
	@Column(name = "pri_whname")
	private String whname;

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

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

	/**
	 * 物料Id
	 */
	@Column(name = "pri_prodid")
	private Long prodId;

	/**
	 * 采购单号，存在ERP上传的采购验退单没有采购单对应的情况，需要这里处理
	 */
	@Column(name = "pri_ordercode")
	private String orderCode = "";

	/**
	 * 采购单明细序号
	 */
	@Column(name = "pri_orderdetno")
	private Short orderDetno = 0;

	/**
	 * 本次对账数
	 */
	@Column(name = "pri_ycheckqty")
	private Integer checkQty;

	public Long getId() {
		return id;
	}

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

	public Short getNumber() {
		return number;
	}

	public void setNumber(Short number) {
		this.number = number;
	}

	public Double getQty() {
		return qty;
	}

	public void setQty(Double qty) {
		this.qty = qty;
	}

	public Double getOrderPrice() {
		return orderPrice;
	}

	public void setOrderPrice(Double orderPrice) {
		this.orderPrice = orderPrice;
	}

	public String getRemark() {
		return remark;
	}

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

	@JsonIgnore
	@JSONField(serialize = false)
	public PurchaseReturn getPurchaseReturn() {
		return purchaseReturn;
	}

	public void setPurchaseReturn(PurchaseReturn purchaseReturn) {
		this.purchaseReturn = purchaseReturn;
	}

	public Long getOrderItemId() {
		return orderItemId;
	}

	public void setOrderItemId(Long orderItemId) {
		this.orderItemId = orderItemId;
	}

	public String getBatchCode() {
		return batchCode;
	}

	public void setBatchCode(String batchCode) {
		this.batchCode = batchCode;
	}

	public Double getTaxrate() {
		return taxrate;
	}

	public void setTaxrate(Double taxrate) {
		this.taxrate = taxrate;
	}

	public String getWhname() {
		return whname;
	}

	public void setWhname(String whname) {
		this.whname = whname;
	}

    public String getProdCode() {
        return prodCode;
    }

    public void setProdCode(String prodCode) {
        this.prodCode = prodCode;
    }

	public Date getErpDate() {
		return erpDate;
	}

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

	public static List<PurchaseReturn> distinct(List<PurchaseReturnItem> items) {
		List<PurchaseReturn> list = new ArrayList<PurchaseReturn>();
		Set<Long> keys = new HashSet<Long>();
		for (PurchaseReturnItem item : items) {
			if (!keys.contains(item.getPurchaseReturn())) {
				list.add(item.getPurchaseReturn());
				keys.add(item.getPurchaseReturn().getId());
			}
		}
		return list;
	}

	public Long getProdId() {
		return prodId;
	}

	public void setProdId(Long prodId) {
		this.prodId = prodId;
	}

	public String getOrderCode() {
		return orderCode;
	}

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

	public Short getOrderDetno() {
		return orderDetno;
	}

	public void setOrderDetno(Short orderDetno) {
		this.orderDetno = orderDetno;
	}

	public Integer getCheckQty() {
		return checkQty;
	}

	public void setCheckQty(Integer checkQty) {
		this.checkQty = checkQty;
	}
}
