package com.iformall.domain.po;

import cn.afterturn.easypoi.excel.annotation.Excel;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;

import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

@Table(name = "wx_c_user_basic_info")
public class WxCUserBasicInfo implements Serializable {
	private static final long serialVersionUID = 1L;
	
	@Id
    protected Long id;
    
    @Transient
    protected List<Long> ids;
    @Transient
    protected String sortColumns;
  
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
	
	public String getSortColumns() {
		return sortColumns;
	}
	 
	public List<Long> getIds() {
		return ids;
	}

	public void setIds(List<Long> ids) {
		this.ids = ids;
	}
	

	/**微信用户绑定的手机号**/
	@Excel(name="手机号",width = 20,orderNum = "3")
	@io.swagger.annotations.ApiModelProperty(value="微信用户绑定的手机号",name="phone")
	@NotNull
	private String phone;
	/**出生日期**/
	@Excel(name="生日",width = 20,format="yyyy-MM-dd",orderNum = "6")
	@NotNull
	@io.swagger.annotations.ApiModelProperty(value="出生日期",name="birthdate")
	private Date birthdate;
	/**学历**/
	@Excel(name="学历",width = 20,orderNum = "5")
	@NotNull
	@io.swagger.annotations.ApiModelProperty(value="学历",name="education")
	private String education;
	/**性别：0：保密 1.男 2女**/
	@Excel(name="性别",width = 20,replace = { "保密_0", "男_1","女_2"},orderNum = "2")
	@NotNull
	@io.swagger.annotations.ApiModelProperty(value="性别：0：保密 1.男 2女",name="sex")
	private Integer sex;
	/**邮箱**/
	@io.swagger.annotations.ApiModelProperty(value="邮箱",name="email")
	private String email;
	/**地址**/
	@Excel(name="地址",width = 20,orderNum = "7")
	@io.swagger.annotations.ApiModelProperty(value="地址",name="address")
	private String address;
	/**积分**/
	@io.swagger.annotations.ApiModelProperty(value="积分",name="poins")
	private Integer poins;
	/**用户标签**/
	@io.swagger.annotations.ApiModelProperty(value="用户标签",name="tagId")
	private Long tagId;
	/**创建时间**/
	@Excel(name="注册时间",width = 20,format="yyyy-MM-dd", orderNum = "9")
	@io.swagger.annotations.ApiModelProperty(value="创建时间",name="createDate")
	private Date createDate;
	/**更新时间**/
	@Excel(name="上次活跃时间",width = 20,format="yyyy-MM-dd", orderNum = "8")
	@io.swagger.annotations.ApiModelProperty(value="更新时间",name="updateDate")
	private Date updateDate;
	/**租户id**/
	@io.swagger.annotations.ApiModelProperty(value="租户id",name="tenantId")
	private String tenantId;

	/**用户姓名**/
	@Excel(name="姓名",width = 20,orderNum = "1")
	@NotNull
	@io.swagger.annotations.ApiModelProperty(value="用户姓名",name="name")
	private String name;

	/**会员等级**/
	@io.swagger.annotations.ApiModelProperty(value="会员等级",name="level")
	private String level;
	/**用户昵称**/
	@Excel(name="微信昵称",width = 20,orderNum = "4")
	@io.swagger.annotations.ApiModelProperty(value="用户昵称",name="nickName")
	private String nickName;

	@Transient
	private String tagIds;
	@Transient
	@Excel(name="标签",width = 20,orderNum = "10")
	private String tagNames;

	@Transient
	private List<WxTags> tagsList;

	@Transient
	private List<String> carList;

	@Transient
	private Integer carCount;

	@Transient
	private Date startTime;
	@Transient
	private Date endTime;

	@Transient
	private String addressStr;

	public String getLevel() {
		return level;
	}

	public void setLevel(String level) {
		this.level = level;
	}

	public String getNickName() {
		return nickName;
	}

	public void setNickName(String nickName) {
		this.nickName = nickName;
	}

	public String getTagNames() {
		return tagNames;
	}

	public void setTagNames(String tagNames) {
		this.tagNames = tagNames;
	}

	public String getTagIds() {
		return tagIds;
	}

	public void setTagIds(String tagIds) {
		this.tagIds = tagIds;
	}

	public String  getPhone() {
		return phone;
	}
	public void setPhone(String _phone) {
		phone = _phone;
	}
	public Date  getBirthdate() {
		return birthdate;
	}
	public void setBirthdate(Date _birthdate) {
		birthdate = _birthdate;
	}
	public String  getEducation() {
		return education;
	}
	public void setEducation(String _education) {
		education = _education;
	}
	public Integer  getSex() {
		return sex;
	}
	public void setSex(Integer _sex) {
		sex = _sex;
	}
	public String  getEmail() {
		return email;
	}
	public void setEmail(String _email) {
		email = _email;
	}
	public String  getAddress() {
		return address;
	}
	public void setAddress(String _address) {
		address = _address;
	}
	public Integer  getPoins() {
		return poins;
	}
	public void setPoins(Integer _poins) {
		poins = _poins;
	}
	public Long  getTagId() {
		return tagId;
	}
	public void setTagId(Long _tagId) {
		tagId = _tagId;
	}
	public Date  getCreateDate() {
		return createDate;
	}
	public void setCreateDate(Date _createDate) {
		createDate = _createDate;
	}
	public Date  getUpdateDate() {
		return updateDate;
	}
	public void setUpdateDate(Date _updateDate) {
		updateDate = _updateDate;
	}
	public String  getTenantId() {
		return tenantId;
	}
	public void setTenantId(String _tenantId) {
		tenantId = _tenantId;
	}
	
	public String  getName() {
		return name;
	}
	public void setName(String _name) {
		name = _name;
	}

	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	public Date getEndTime() {
		return endTime;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}

	public String  getAddressStr() {
		if (address == null)
			return null;
		JSONObject addressJSON;
		try {
			addressJSON = JSONObject.parseObject(address);
			addressStr = addressJSON.getString("address")+addressJSON.getString("name");
		} catch (Exception e){
			return address;
		}

		return addressStr;
	}

	public void setAddressStr(String _addressStr) {
		addressStr = _addressStr;
	}

	public List<WxTags> getTagsList() {
		return tagsList;
	}

	public void setTagsList(List<WxTags> tagsList) {
		this.tagsList = tagsList;
	}

	public List<String> getCarList() {
		return carList;
	}

	public void setCarList(List<String> carList) {
		this.carList = carList;
	}

	public Integer getCarCount() {
		return carCount;
	}

	public void setCarCount(Integer carCount) {
		this.carCount = carCount;
	}

	public static enum Field
	{
		Id_ASC("`id` ASC"),Id_DESC("`id` DESC")
			,Phone_ASC("`phone` ASC"),Phone_DESC("`phone` DESC")
			,Birthdate_ASC("`birthdate` ASC"),Birthdate_DESC("`birthdate` DESC")
			,Education_ASC("`education` ASC"),Education_DESC("`education` DESC")
			,Sex_ASC("`sex` ASC"),Sex_DESC("`sex` DESC")
			,Email_ASC("`email` ASC"),Email_DESC("`email` DESC")
			,Address_ASC("`address` ASC"),Address_DESC("`address` DESC")
			,Poins_ASC("`poins` ASC"),Poins_DESC("`poins` DESC")
			,TagId_ASC("`tag_id` ASC"),TagId_DESC("`tag_id` DESC")
			,CreateDate_ASC("`create_date` ASC"),CreateDate_DESC("`create_date` DESC")
			,UpdateDate_ASC("`update_date` ASC"),UpdateDate_DESC("`update_date` DESC")
			,TenantId_ASC("`tenant_id` ASC"),TenantId_DESC("`tenant_id` DESC")
			,Name_ASC("`name` ASC"),Name_DESC("`name` DESC")
	;
		private String value;
		Field(String value){
			this.value = value;
		}
		public String getValue() {
			return value;
		}
		public void setCol(String value) {
			this.value = value;
		}
		@Override
		public String toString() {
			return this.getValue();
		}
	}
	
	public void setSortColumns(WxCUserBasicInfo.Field... fields)
	{
		if (fields == null || fields.length == 0) {
			return;
		}
		for (int k = 0; k < fields.length; k++) {
			if (fields[k] == null) {
				return;
			}
		}
		StringBuilder sb = new StringBuilder(fields[0].toString());
		for (int k = 1; k < fields.length; k++) {
			sb.append(",");
			sb.append(fields[k].toString());
		}

		this.sortColumns = sb.toString();
		 
	}
	
	public void setSortColumns(String sortColumns)
	{
		if (sortColumns == null || "".equals(sortColumns.trim())) {
			return;
		}
		if (sortColumns.contains(",")) {
			String[] cols = sortColumns.split(",");
			java.util.List<Field> fList = new java.util.ArrayList();
			for (int k = 0; k < cols.length; k++) {
				fList.add(Field.valueOf(cols[k]));
			}
			this.setSortColumns(fList.toArray(new Field[fList.size()]));
		} else {
			this.setSortColumns(Field.valueOf(sortColumns));
		}
	}
}
