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

import com.uas.platform.b2b.model.EnterpriseInfo;
import com.uas.platform.b2b.model.MakeOrderChange;
import com.uas.platform.b2b.model.MakeOrderChangeItem;
import com.uas.platform.b2b.support.SystemSession;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.springframework.util.CollectionUtils;

public class MakeChange {

	private Long mc_id;// id
	private String mc_code;// 变更单号
	private Date mc_indate;// 录入日期
	private Date mc_date;// 日期
	private String mc_recorder;// 录入人
	private String mc_auditman;// 审核人
	private Date mc_auditdate;// 审核日期
	private String mc_remark;// 备注
	private List<MakeChangeDetail> changeDetails;// 明细

	@JsonIgnore
	public Long getMc_id() {
		return mc_id;
	}

	public void setMc_id(Long mc_id) {
		this.mc_id = mc_id;
	}

	public String getMc_code() {
		return mc_code;
	}

	public void setMc_code(String mc_code) {
		this.mc_code = mc_code;
	}

	public Date getMc_indate() {
		return mc_indate;
	}

	public void setMc_indate(Date mc_indate) {
		this.mc_indate = mc_indate;
	}

	public Date getMc_date() {
		return mc_date;
	}

	public void setMc_date(Date mc_date) {
		this.mc_date = mc_date;
	}

	public String getMc_recorder() {
		return mc_recorder;
	}

	public void setMc_recorder(String mc_recorder) {
		this.mc_recorder = mc_recorder;
	}

	public String getMc_auditman() {
		return mc_auditman;
	}

	public void setMc_auditman(String mc_auditman) {
		this.mc_auditman = mc_auditman;
	}

	public Date getMc_auditdate() {
		return mc_auditdate;
	}

	public void setMc_auditdate(Date mc_auditdate) {
		this.mc_auditdate = mc_auditdate;
	}

	public String getMc_remark() {
		return mc_remark;
	}

	public void setMc_remark(String mc_remark) {
		this.mc_remark = mc_remark;
	}

	public List<MakeChangeDetail> getChangeDetails() {
		return changeDetails;
	}

	public void setChangeDetails(List<MakeChangeDetail> changeDetails) {
		this.changeDetails = changeDetails;
	}

	public MakeOrderChange convert() {
		MakeOrderChange change = new MakeOrderChange();
		change.setCode(mc_code);
		change.setDate(mc_indate);
		change.setEnUU(SystemSession.getUser().getEnterprise().getUu());
		change.setEnterprise(new EnterpriseInfo(SystemSession.getUser().getEnterprise()));
		change.setRecorder(mc_recorder);
		change.setRemark(mc_remark);
		change.setUserUU(SystemSession.getUser().getUserUU());
		change.setAuditDate(mc_auditdate);
		change.setAuditMan(mc_auditman);
		change.setErpId(mc_id);
		if (!CollectionUtils.isEmpty(changeDetails)) {
			Set<MakeOrderChangeItem> changeItems = new HashSet<MakeOrderChangeItem>();
			for (MakeChangeDetail changeDetail : changeDetails) {
				changeItems.add(changeDetail.convert());
			}
			change.setOrderChangeItems(changeItems);
		}
		return change;
	}

}
