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

import java.sql.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.springframework.util.CollectionUtils;

import com.uas.platform.b2b.model.PurchaseForecastAll;
import com.uas.platform.b2b.model.PurchaseForecastAllItem;
import com.uas.platform.b2b.model.User;
import com.uas.platform.b2b.support.SystemSession;

public class PurchaseForecast {
	private Long pf_id;
	private String pf_code;
	private Date pf_date;	
	private String pf_kind;
	private String pf_recorder;
	private String pf_purpose;//用途
	private Long em_uu;
	private List<PurchaseForecastDetail> purchaseForecastDetails;
	
	
	public Long getPf_id() {
		return pf_id;
	}
	public void setPf_id(Long pf_id) {
		this.pf_id = pf_id;
	}
	public String getPf_code() {
		return pf_code;
	}
	public void setPf_code(String pf_code) {
		this.pf_code = pf_code;
	}
	public Date getPf_date() {
		return pf_date;
	}
	public void setPf_date(Date pf_date) {
		this.pf_date = pf_date;
	}
	public String getPf_kind() {
		return pf_kind;
	}
	public void setPf_kind(String pf_kind) {
		this.pf_kind = pf_kind;
	}
	public String getPf_recorder() {
		return pf_recorder;
	}
	public void setPf_recorder(String pf_recorder) {
		this.pf_recorder = pf_recorder;
	}
	public String getPf_purpose() {
		return pf_purpose;
	}
	public void setPf_purpose(String pf_purpose) {
		this.pf_purpose = pf_purpose;
	}
	public Long getEm_uu() {
		return em_uu;
	}
	public void setEm_uu(Long em_uu) {
		this.em_uu = em_uu;
	}
	public List<PurchaseForecastDetail> getPurchaseForecastDetails() {
		return purchaseForecastDetails;
	}
	public void setPurchaseForecastDetails(
			List<PurchaseForecastDetail> purchaseForecastDetails) {
		this.purchaseForecastDetails = purchaseForecastDetails;
	}

	/**
	 * 转为平台的采购订单
	 * 
	 * @return
	 */
	public PurchaseForecastAll convert() {
		PurchaseForecastAll forecast = new PurchaseForecastAll();
		forecast.setCode(this.pf_code);		
		forecast.setDate(this.pf_date);
		forecast.setEnUU(SystemSession.getUser().getEnterprise().getUu());
		forecast.setEnterprise(SystemSession.getUser().getEnterprise());
		User user = new User();
		user.setUserUU(this.em_uu);
		forecast.setUser(user);
		if (this.em_uu != null) {//ERP采购预测中采购员存在UU号
			forecast.setUserUU(this.em_uu);
		}
		forecast.setRecorder(this.pf_recorder);
		forecast.setPurpose(this.pf_purpose);
		forecast.setKind(this.pf_kind);
		if (!CollectionUtils.isEmpty(this.purchaseForecastDetails)) {
			Set<PurchaseForecastAllItem> items = new HashSet<PurchaseForecastAllItem>();
			for (PurchaseForecastDetail detail : this.purchaseForecastDetails) {
				items.add(detail.convert());
			}
			forecast.setForecastItems(items);
		}
		return forecast;
	}
}
