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

import com.alibaba.dubbo.common.utils.StringUtils;
import com.uas.platform.b2b.model.EnterpriseInfo;
import com.uas.platform.b2b.model.PurchaseInquiryMould;
import com.uas.platform.b2b.model.PurchaseInquiryMouldItem;
import com.uas.platform.b2b.support.SystemSession;
import com.uas.platform.core.model.Status;
import org.apache.commons.collections.CollectionUtils;

import java.util.*;

/**
 * 买家ERP系统的模具询价单
 * 
 *
 */
public class InquiryMould {
	
	
	/**
	 * id
	 */
	private Long in_id;

	/**
	 * 询价单号
	 */
	private String in_code;

	/**
	 * 日期
	 */
	private Date in_date;

	/**
	 * 供应商号
	 */
	private String in_vendcode;

	/**
	 * 供应商名
	 */
	private String in_vendname;

	/**
	 * 供应商UU
	 */
	private Long in_veuu;

	/**
	 * 币别
	 */
	private String in_currency;

	/**
	 * 税率
	 */
	private Float in_taxrate;

	/**
	 * 备注
	 */
	private String in_remark;

	/**
	 * 单据状态
	 */
	private String in_status;

	/**
	 * 所属公司
	 */
	private String in_cop;

	/**
	 * 来源id
	 */
	private Long in_sourceid;

	/**
	 * 来源单号
	 */
	private String in_sourcecode;

	/**
	 * 来源类型
	 */
	private String in_sourcetype;

	/**
	 * 状态编号
	 */
	private String in_statuscode;

	/**
	 * 审核人
	 */
	private String in_auditor;

	/**
	 * 审核日期
	 */
	private Date in_auditdate;

	/**
	 * 录入人
	 */
	private String in_recorder;

	/**
	 * 录入人id
	 */
	private Long in_recorderid;

	/**
	 * 录入日期
	 */
	private Date in_recorddate;

	/**
	 * 截止日期
	 */
	private Date in_enddate;

	/**
	 * 采纳状态
	 */
	private String in_adoptstatus;

	/**
	 * 上传状态
	 */
	private String in_sendstatus;

	/**
	 * 模具询价明细
	 */
	private List<InquiryMouldDet> items;

	/**
	 * 审核状态
	 * 
	 * @return
	 */
	private String in_checksendStatus;

	// private Long in_venduseruu;
	// private String in_source;
	// private Long in_recorderuu;

	private Long b2b_im_id;

	private List<Attach> attaches;

	public Long getIn_id() {
		return in_id;
	}

	public void setIn_id(Long in_id) {
		this.in_id = in_id;
	}

	public String getIn_code() {
		return in_code;
	}

	public void setIn_code(String in_code) {
		this.in_code = in_code;
	}

	public Date getIn_date() {
		return in_date;
	}

	public void setIn_date(Date in_date) {
		this.in_date = in_date;
	}

	public Long getIn_veuu() {
		return in_veuu;
	}

	public void setIn_veuu(Long in_veuu) {
		this.in_veuu = in_veuu;
	}

	public String getIn_adoptstatus() {
		return in_adoptstatus;
	}

	public void setIn_adoptstatus(String in_adoptstatus) {
		this.in_adoptstatus = in_adoptstatus;
	}

	public String getIn_vendname() {
		return in_vendname;
	}

	public void setIn_vendname(String in_vendname) {
		this.in_vendname = in_vendname;
	}


	public String getIn_currency() {
		return in_currency;
	}

	public void setIn_currency(String in_currency) {
		this.in_currency = in_currency;
	}

	public String getIn_remark() {
		return in_remark;
	}

	public void setIn_remark(String in_remark) {
		this.in_remark = in_remark;
	}

	public String getIn_cop() {
		return in_cop;
	}

	public void setIn_cop(String in_cop) {
		this.in_cop = in_cop;
	}

	public Long getIn_sourceid() {
		return in_sourceid;
	}

	public void setIn_sourceid(Long in_sourceid) {
		this.in_sourceid = in_sourceid;
	}


	public String getIn_sourcetype() {
		return in_sourcetype;
	}

	public void setIn_sourcetype(String in_sourcetype) {
		this.in_sourcetype = in_sourcetype;
	}

	public String getIn_statuscode() {
		return in_statuscode;
	}

	public void setIn_statuscode(String in_statuscode) {
		this.in_statuscode = in_statuscode;
	}

	public String getIn_auditor() {
		return in_auditor;
	}

	public void setIn_auditor(String in_auditor) {
		this.in_auditor = in_auditor;
	}

	public Date getIn_auditdate() {
		return in_auditdate;
	}

	public void setIn_auditdate(Date in_auditdate) {
		this.in_auditdate = in_auditdate;
	}

	public String getIn_recorder() {
		return in_recorder;
	}

	public void setIn_recorder(String in_recorder) {
		this.in_recorder = in_recorder;
	}

	public Date getIn_recorddate() {
		return in_recorddate;
	}

	public void setIn_recorddate(Date in_recorddate) {
		this.in_recorddate = in_recorddate;
	}


	public Date getIn_enddate() {
		return in_enddate;
	}

	public void setIn_enddate(Date in_enddate) {
		this.in_enddate = in_enddate;
	}

	public String getIn_sendstatus() {
		return in_sendstatus;
	}

	public void setIn_sendstatus(String in_sendstatus) {
		this.in_sendstatus = in_sendstatus;
	}

	public String getIn_vendcode() {
		return in_vendcode;
	}

	public void setIn_vendcode(String in_vendcode) {
		this.in_vendcode = in_vendcode;
	}

	public Float getIn_tax() {
		return in_taxrate;
	}

	public void setIn_tax(Float in_taxrate) {
		this.in_taxrate = in_taxrate;
	}

	public String getIn_sourcecode() {
		return in_sourcecode;
	}

	public void setIn_sourcecode(String in_sourcecode) {
		this.in_sourcecode = in_sourcecode;
	}

	public Long getIn_recorderid() {
		return in_recorderid;
	}

	public void setIn_recorderid(Long in_recorderid) {
		this.in_recorderid = in_recorderid;
	}

	public String getIn_checksendStatus() {
		return in_checksendStatus;
	}

	public void setIn_checksendStatus(String in_checksendStatus) {
		this.in_checksendStatus = in_checksendStatus;
	}

	public Long getB2b_im_id() {
		return b2b_im_id;
	}

	public void setB2b_im_id(Long b2b_im_id) {
		this.b2b_im_id = b2b_im_id;
	}

	public List<InquiryMouldDet> getItems() {
		return items;
	}

	public void setItems(List<InquiryMouldDet> items) {
		this.items = items;
	}

	public String getIn_status() {
		return in_status;
	}

	public void setIn_status(String in_status) {
		this.in_status = in_status;
	}

	public List<Attach> getAttaches() {
		return attaches;
	}

	public void setAttaches(List<Attach> attaches) {
		this.attaches = attaches;
	}

	/**
	 * 转为平台的模具询价
	 * 
	 * @return
	 */
	public PurchaseInquiryMould convert() {
		PurchaseInquiryMould inquiryMould = new PurchaseInquiryMould();
		inquiryMould.setErpSourceId(this.in_id);
		inquiryMould.setEnuu(SystemSession.getUser().getEnterprise().getUu());
		inquiryMould.setEnterprise(new EnterpriseInfo(SystemSession.getUser().getEnterprise()));
		inquiryMould.setAuditDate(this.in_auditdate);
		inquiryMould.setAuditor(this.in_auditor);
		inquiryMould.setCode(this.in_code);
		inquiryMould.setCurrency(this.in_currency);
		inquiryMould.setDate(this.in_date);
		inquiryMould.setEndDate(this.in_enddate);
		inquiryMould.setRecordDate(this.in_recorddate);
		inquiryMould.setRecorder(this.in_recorder);
		inquiryMould.setRemark(this.in_remark);
		inquiryMould.setSourceId(this.in_sourceid);
		inquiryMould.setSourceType(this.in_sourcetype);
		inquiryMould.setStatusCode(this.in_statuscode);
		inquiryMould.setTaxrate(this.in_taxrate);
		inquiryMould.setVendName(this.in_vendname);
		inquiryMould.setVenduu(this.in_veuu);
		// 记录传入时间为当前时间
		inquiryMould.setErpInDate(new Date());
		inquiryMould.setSendStatus((short) Status.NOT_UPLOAD.value());
		if (!StringUtils.isEmpty(this.in_adoptstatus)) {
			inquiryMould.setStatus((short) Status.REPLIED.value());
		} else {
			inquiryMould.setStatus((short) Status.NOT_REPLY.value());
		}
		if (this.in_status.equals("已作废")) {
			inquiryMould.setValid((short) 0);
		} else {
			inquiryMould.setValid((short) 1);
		}
		// if (this.in_sendstatus.equals("待上传")) {
		// inquiryMould.setSendStatus((short) Status.NOT_UPLOAD.value());
		// } else if (this.in_sendstatus.equals("已上传")) {
		// inquiryMould.setSendStatus((short) Status.DOWNLOADED.value());
		// }
		if (this.in_adoptstatus != null) {
			if (this.in_adoptstatus.equals("已采纳")) {
				inquiryMould.setAdoptStatus((short) 1);
			} else if (this.in_adoptstatus.equals("未采纳")) {
				inquiryMould.setAdoptStatus((short) 0);
			}
		}

		if (!CollectionUtils.isEmpty(this.items)) {
			Set<PurchaseInquiryMouldItem> inquiryMouldItems = new HashSet<PurchaseInquiryMouldItem>();
			for (InquiryMouldDet item : items) {
				inquiryMouldItems.add(item.convert());
			}
			inquiryMould.setInquiryMouldItems(inquiryMouldItems);
		}
		if (!CollectionUtils.isEmpty(this.attaches)) {
			Set<com.uas.platform.b2b.model.Attach> b2bAttaches = new HashSet<com.uas.platform.b2b.model.Attach>();
			for(Attach attach : this.attaches) {
				com.uas.platform.b2b.model.Attach b2bAttach = attach.convertToB2bAttach("客户模具询价单附件");
				b2bAttaches.add(b2bAttach);
			}
			inquiryMould.setAttachs(b2bAttaches);
		}
		return inquiryMould;
	}

	public InquiryMould() {

	}

	public InquiryMould(PurchaseInquiryMould mould) {
		this.b2b_im_id = mould.getId();
		// this.in_attach = mould.getAttachs();
		this.in_id = mould.getErpSourceId();
		this.in_auditdate = mould.getAuditDate();
		this.in_auditor = mould.getAuditor();
		this.in_code = mould.getCode();
		this.in_vendname = mould.getVendName();
		this.in_veuu = mould.getVenduu();
		this.in_currency = mould.getCurrency();
		this.in_date = mould.getDate();
		this.in_enddate = mould.getEndDate();
		this.in_recorddate = mould.getRecordDate();
		this.in_recorder = mould.getRecorder();
		this.in_recorderid = mould.getRecorderuu();
		this.in_remark = mould.getRemark();
		this.in_sourcecode = mould.getSourceCode();
		this.in_sourcetype = mould.getSourceType();
		// this.in_status = mould.getStatus();
		this.in_statuscode = mould.getStatusCode();
		this.in_taxrate = mould.getTaxrate();
		if (!CollectionUtils.isEmpty(mould.getInquiryMouldItems())) {
			items = new ArrayList<InquiryMouldDet>();
			for (PurchaseInquiryMouldItem item : mould.getInquiryMouldItems()) {
				items.add(new InquiryMouldDet(item));
			}

		}
	}
}
