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

import com.uas.platform.b2b.model.SaleSend;
import com.uas.platform.b2b.model.SaleSendItem;
import com.uas.platform.b2b.support.SystemSession;
import com.uas.platform.core.model.Status;
import org.apache.commons.collections.CollectionUtils;

import java.util.*;

/**
 * 买家ERP的收料通知单
 *
 * @author hejq
 * @date 2018-06-28 17:18
 */
public class AcceptNotify {

	private Long b2b_ss_id;
	private long an_venduu;
	private String an_currency;
	private Float an_rate;
	private String an_payment;
	private Long an_buyeruu;
	private String an_remark;
	private String an_sendcode;
	private String an_recorder;
	private Date an_date;
	private List<AcceptNotifyDetail> details;

	public Long getB2b_ss_id() {
		return b2b_ss_id;
	}

	public void setB2b_ss_id(Long b2b_ss_id) {
		this.b2b_ss_id = b2b_ss_id;
	}

	public Long getAn_venduu() {
		return an_venduu;
	}

	public void setAn_venduu(Long an_venduu) {
		this.an_venduu = an_venduu;
	}

	public String getAn_currency() {
		return an_currency;
	}

	public void setAn_currency(String an_currency) {
		this.an_currency = an_currency;
	}

	public Float getAn_rate() {
		return an_rate;
	}

	public void setAn_rate(Float an_rate) {
		this.an_rate = an_rate;
	}

	public void setAn_venduu(long an_venduu) {
		this.an_venduu = an_venduu;
	}

	public Date getAn_date() {
		return an_date;
	}

	public void setAn_date(Date an_date) {
		this.an_date = an_date;
	}

	public String getAn_payment() {
		return an_payment;
	}

	public void setAn_payment(String an_payment) {
		this.an_payment = an_payment;
	}

	public Long getAn_buyeruu() {
		return an_buyeruu;
	}

	public void setAn_buyeruu(Long an_buyeruu) {
		this.an_buyeruu = an_buyeruu;
	}

	public String getAn_remark() {
		return an_remark;
	}

	public void setAn_remark(String an_remark) {
		this.an_remark = an_remark;
	}

	public List<AcceptNotifyDetail> getDetails() {
		return details;
	}

	public void setDetails(List<AcceptNotifyDetail> details) {
		this.details = details;
	}

	public String getAn_sendcode() {
		return an_sendcode;
	}

	public void setAn_sendcode(String an_sendcode) {
		this.an_sendcode = an_sendcode;
	}

	public String getAn_recorder() {
		return an_recorder;
	}

	public void setAn_recorder(String an_recorder) {
		this.an_recorder = an_recorder;
	}

	public AcceptNotify() {

	}

	/**
	 * 卖家做的发货单，转为买家的收料通知
	 * 
	 * @param send
	 */
	public AcceptNotify(SaleSend send) {
		this.b2b_ss_id = send.getId();
		this.an_buyeruu = send.getCustUserUU();
		this.an_currency = send.getCurrency();
		this.an_payment = send.getPayments();
		this.an_rate = send.getRate();
		this.an_remark = send.getRemark();
		this.an_venduu = send.getEnUU();
		this.an_sendcode = send.getCode();
		this.an_recorder = send.getRecorder();
		this.an_date = send.getDate();
		this.details = new ArrayList<AcceptNotifyDetail>();
		if (!CollectionUtils.isEmpty(send.getSendItems())) {
			for (SaleSendItem item : send.getSendItems()) {
				this.details.add(new AcceptNotifyDetail(item));
			}
		}
	}

	/**
	 * 买家主动做的收料通知，转到平台的发货单
	 * 
	 * @return
	 */
	public SaleSend convert() {
		SaleSend send = new SaleSend();
		send.setEnUU(this.getAn_venduu());
		send.setCustUU(SystemSession.getUser().getEnterprise().getUu());
		send.setCurrency(this.an_currency);
		send.setRate(this.an_rate);
		send.setPayments(this.an_payment);
		send.setCustUserUU(this.an_buyeruu);
		send.setRemark(this.an_remark);
		send.setSendStatus((short) Status.DOWNLOADED.value());
		send.setBackStatus((short) Status.NOT_UPLOAD.value());
		send.setRecorder(this.an_recorder);
		send.setCode(this.an_sendcode == null ? String.valueOf(System.currentTimeMillis()) : this.an_sendcode);
		Set<SaleSendItem> items = new HashSet<SaleSendItem>();
		if (!CollectionUtils.isEmpty(details)) {
			for (AcceptNotifyDetail detail : details) {
                items.add(detail.convert());
            }
		}
		send.setSendItems(items);
		return send;
	}

}
