/**
 * Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.workclientinfo.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.Lists;
import com.jeeplus.common.persistence.DataEntity;
import com.jeeplus.common.utils.excel.annotation.ExcelField;
import com.jeeplus.modules.sys.entity.Area;
import com.jeeplus.modules.sys.utils.DictUtils;
import org.apache.commons.lang3.StringUtils;

import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.List;

/**
 * 客户管理Entity
 * @author 丁旭
 * @version 2017-03-20
 */
public class WorkClientInfo extends DataEntity<WorkClientInfo> {

	private static final long serialVersionUID = 1L;
	private String name;		// 客户名称
	private String number;      //客户编号
	private String nameForShort;		// 客户名称缩写
	private String orUnicode;		// 组织机构代码
	private String companyType;		// 客户性质
	private String companyIndustry;		// 客户行业
	private String clientType;		// 客户类型
	private String creditRank;		// 信用等级
	private Area area;		// 地区Id
	private String zipCode;		// 邮政编码
	private String fax;		// 传真
	private String telephone; //公司电话
    private String lawerPresint;  //法人代表
	private String ourBank;		// 开户银行
	private String bankNumber;		// 开户账号
	private String taxId;		// 税务号
	private String email;		// 电子邮箱
	private String address;		// 详细地址
	private String registerAddress;		// 注册地址
	private String companyUrl;		// 公司网址
    private WorkClientLinkman workClientLinkman;        //联系人信息
	private String companyId;
	private String officeId;
	private String workLinkName; 	//联系人查询条件
	private String param; 	//联系人查询条件
	private List<WorkClientLinkman> workClientLinkmanList = Lists.newArrayList();		// 子表列表
    private List<WorkClientBank> workClientBankList = Lists.newArrayList();     //银行列表
//    private List<WorkClientAttachment> workClientAttachmentList = Lists.newArrayList();     //附件列表
    private List<WorkClientAttachment> workAttachments = Lists.newArrayList();     //附件列表
	private String linkManNames;
	private String linkname;		// 联系人姓名
	private String position;		// 职务
	private String qq;		// QQ
	private String linkPhone;		// 联系人电话
	private String linkMobile;		// 联系人手机
	private String linkemail;		// E-mail
	private String nowDate;
	private String userName;
	private String errInfo;
	private String unitIntroduction;

	public String getUnitIntroduction() {
		return unitIntroduction;
	}

	public void setUnitIntroduction(String unitIntroduction) {
		this.unitIntroduction = unitIntroduction;
	}

	private int hasUscc; //是否拥有统一社会信用代码
	private String uscCode; //统一社会信用代码
	private String clientTypeLables;

	private Date beginDate;
	private Date endDate;

	public WorkClientInfo() {
		super();
	}

	public WorkClientInfo(String id){
		super(id);
	}

	@NotNull(message="客户名称不能为空")
	@ExcelField(title="客户名称", align=2, sort=1)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getNameForShort() {
		return nameForShort;
	}

	public void setNameForShort(String nameForShort) {
		this.nameForShort = nameForShort;
	}

//	@NotNull(message="组织机构代码不能为空")
	public String getOrUnicode() {
		return orUnicode;
	}

	public void setOrUnicode(String orUnicode) {
		this.orUnicode = orUnicode;
	}

	@NotNull(message="客户性质不能为空")
	@ExcelField(title="客户性质", mainDictType="company_type", align=2, sort=3)
	public String getCompanyType() {
		return companyType;
	}

	public void setCompanyType(String companyType) {
		this.companyType = companyType;
	}

	@ExcelField(title="客户行业", mainDictType="company_industry", align=2, sort=4)
	public String getCompanyIndustry() {
		return companyIndustry;
	}

	public void setCompanyIndustry(String companyIndustry) {
		this.companyIndustry = companyIndustry;
	}

	@ExcelField(title="客户类型", align=2, sort=5)
	public String getClientTypeLables() {
		if (StringUtils.isBlank(clientType)){
			return clientType;
		}
		StringBuilder builder = new StringBuilder();
		String[] split = clientType.split(",");
		for (String s : split) {
			builder.append(DictUtils.getMainDictLabel(s,"client_type","")).append(",");
		}
		builder.deleteCharAt(builder.length()-1);
		return builder.toString();
	}

	public void setClientTypeLables(String clientTypeLables) {
		this.clientTypeLables = clientTypeLables;
	}

	public String getClientType() {
		return clientType;
	}

	public void setClientType(String clientType) {
		this.clientType = clientType;
	}

	public String getCreditRank() {
		return creditRank;
	}

	public void setCreditRank(String creditRank) {
		this.creditRank = creditRank;
	}

	@JsonIgnore
	@NotNull(message="地区名称不能为空")
	@ExcelField(title="地区名称",align=2,sort=7)
	public Area getArea() {
		return area;
	}

	public void setArea(Area area) {
		this.area = area;
	}

	@ExcelField(title="邮政编码", align=2, sort=8)
	public String getZipCode() {
		return zipCode;
	}

	public void setZipCode(String zipCode) {
		this.zipCode = zipCode;
	}

	@ExcelField(title="传真", align=2, sort=9)
	public String getFax() {
		return fax;
	}

	public void setFax(String fax) {
		this.fax = fax;
	}

	@ExcelField(title="开户银行", align=2, sort=15)
	public String getOurBank() {
	    if(StringUtils.isNotBlank(ourBank))
		return ourBank;
	    return (workClientBankList==null||workClientBankList.size()==0)?null:(workClientBankList.get(0)==null?null:workClientBankList.get(0).getOurBank());
	}

	public void setOurBank(String ourBank) {
		this.ourBank = ourBank;
	}

	@ExcelField(title="开户账号", align=2, sort=16)
	public String getBankNumber() {
        if(StringUtils.isNotBlank(bankNumber))
		return bankNumber;
        return (workClientBankList==null||workClientBankList.size()==0)?null:workClientBankList.get(0)==null?null:workClientBankList.get(0).getBankNumber();
	}

	public void setBankNumber(String bankNumber) {
		this.bankNumber = bankNumber;
	}

	public String getTaxId() {
		return taxId;
	}

	public void setTaxId(String taxId) {
		this.taxId = taxId;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	@ExcelField(title="详细地址", align=2, sort=12)
	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	@ExcelField(title="注册地址", align=2, sort=13)
	public String getRegisterAddress() {
		return registerAddress;
	}

	public void setRegisterAddress(String registerAddress) {
		this.registerAddress = registerAddress;
	}

	@ExcelField(title="公司网址", align=2, sort=14)
	public String getCompanyUrl() {
		return companyUrl;
	}

	public void setCompanyUrl(String companyUrl) {
		this.companyUrl = companyUrl;
	}


	public String getCompanyId() {
		return companyId;
	}

	public void setCompanyId(String companyId) {
		this.companyId = companyId;
	}

	public WorkClientLinkman getWorkClientLinkman() {
        return workClientLinkman;
    }

    public void setWorkClientLinkman(WorkClientLinkman workClientLinkman) {
        this.workClientLinkman = workClientLinkman;
    }

    public String getLawerPresint() {
        return lawerPresint;
    }

    public void setLawerPresint(String lawerPresint) {
        this.lawerPresint = lawerPresint;
    }

    public List<WorkClientLinkman> getWorkClientLinkmanList() {
		return workClientLinkmanList;
	}

	public void setWorkClientLinkmanList(List<WorkClientLinkman> workClientLinkmanList) {
		this.workClientLinkmanList = workClientLinkmanList;
	}

    public List<WorkClientBank> getWorkClientBankList() {
        return workClientBankList;
    }

    public void setWorkClientBankList(List<WorkClientBank> workClientBankList) {
        this.workClientBankList = workClientBankList;
    }

//    public List<WorkClientAttachment> getWorkClientAttachmentList() {
//        return workClientAttachmentList;
//    }
//
//    public void setWorkClientAttachmentList(List<WorkClientAttachment> workClientAttachmentList) {
//        this.workClientAttachmentList = workClientAttachmentList;
//    }


	public List<WorkClientAttachment> getWorkAttachments() {
		return workAttachments;
	}

	public void setWorkAttachments(List<WorkClientAttachment> workAttachments) {
		this.workAttachments = workAttachments;
	}

	public String getWorkLinkName() {
		return workLinkName;
	}

	public void setWorkLinkName(String workLinkName) {
		this.workLinkName = workLinkName;
	}

	public String getOfficeId() {
		return officeId;
	}

	public void setOfficeId(String officeId) {
		this.officeId = officeId;
	}

	public String getParam() {
		return param;
	}

	public void setParam(String param) {
		this.param = param;
	}

	public String getLinkManNames() {
		return linkManNames;
	}

	public void setLinkManNames(String linkManNames) {
		this.linkManNames = linkManNames;
	}

	@ExcelField(title="联系人E-mail", align=2, sort=22)
	public String getLinkemail() {
        if(StringUtils.isNotBlank(linkemail))
		return linkemail;
        return (workClientLinkmanList==null||workClientLinkmanList.size()==0)?null:workClientLinkmanList.get(0)==null?null:workClientLinkmanList.get(0).getEmail();
    }

	public void setLinkemail(String linkemail) {
		this.linkemail = linkemail;
	}

	@ExcelField(title="联系人职务", align=2, sort=18)
	public String getPosition() {
        if(StringUtils.isNotBlank(position))
            return position;
        return (workClientLinkmanList==null||workClientLinkmanList.size()==0)?null:workClientLinkmanList.get(0)==null?null:workClientLinkmanList.get(0).getPosition();
	}

	public void setPosition(String position) {
		this.position = position;
	}

	@ExcelField(title="联系人QQ", align=2, sort=19)
	public String getQq() {
        if(StringUtils.isNotBlank(qq))
            return qq;
        return (workClientLinkmanList==null||workClientLinkmanList.size()==0)?null:workClientLinkmanList.get(0)==null?null:workClientLinkmanList.get(0).getQq();
	}

	public void setQq(String qq) {
		this.qq = qq;
	}

	@ExcelField(title="联系人电话", align=2, sort=20)
	public String getLinkPhone() {
        if(StringUtils.isNotBlank(linkPhone))
            return linkPhone;
        return (workClientLinkmanList==null||workClientLinkmanList.size()==0)?null:workClientLinkmanList.get(0)==null?null:workClientLinkmanList.get(0).getLinkPhone();
	}

	public void setLinkPhone(String linkPhone) {
		this.linkPhone = linkPhone;
	}

	@ExcelField(title="联系人手机", align=2, sort=21)
	public String getLinkMobile() {
        if(StringUtils.isNotBlank(linkMobile))
            return linkMobile;
        return (workClientLinkmanList==null||workClientLinkmanList.size()==0)?null:workClientLinkmanList.get(0)==null?null:workClientLinkmanList.get(0).getLinkMobile();
	}

	public void setLinkMobile(String linkMobile) {
		this.linkMobile = linkMobile;
	}

	@ExcelField(title="联系人姓名", align=2, sort=17)
	public String getLinkname() {
        if(StringUtils.isNotBlank(linkname))
            return linkname;
        return (workClientLinkmanList==null||workClientLinkmanList.size()==0)?null:workClientLinkmanList.get(0)==null?null:workClientLinkmanList.get(0).getName();
	}

	public void setLinkname(String linkname) {
		this.linkname = linkname;
	}

	@ExcelField(title="导入时间", align=2, sort=23)
	public String getNowDate() {
		return nowDate;
	}

	public void setNowDate(String nowDate) {
		this.nowDate = nowDate;
	}

	@ExcelField(title="导入用户", align=2, sort=24)
	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	@ExcelField(title="失败原因", align=2, sort=25)
	public String getErrInfo() {
		return errInfo;
	}

	public void setErrInfo(String errInfo) {
		this.errInfo = errInfo;
	}

	public String getTelephone() {
		return telephone;
	}

	public void setTelephone(String telephone) {
		this.telephone = telephone;
	}

	public int getHasUscc() {
		return hasUscc;
	}

	public void setHasUscc(int hasUscc) {
		this.hasUscc = hasUscc;
	}

	@ExcelField(title="统一社会信用代码", align=2, sort=10)
	public String getUscCode() {
		return uscCode;
	}

	public void setUscCode(String uscCode) {
		this.uscCode = uscCode;
	}

	public void convertClientType() {
		if (StringUtils.isNotBlank(clientTypeLables)){
			String[] split = clientTypeLables.split(",");
			StringBuilder builder = new StringBuilder();
			for (String s : split) {
				builder.append(DictUtils.getMainDictValue(s,"client_type","")).append(",");
			}
			builder.deleteCharAt(builder.length()-1);
			this.clientType = builder.toString();
		}
	}

    public Date getBeginDate() {
        return beginDate;
    }

    public void setBeginDate(Date beginDate) {
        this.beginDate = beginDate;
    }

    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

	public String getNumber() {
		return number;
	}

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