package com.iformall.domain.po;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.iformall.utils.BaseConstant;

import javax.persistence.*;
import java.util.*;
import java.math.*;
import javax.persistence.Transient;
import java.util.List;
import javax.persistence.Id;
import java.io.Serializable;

@Table(name = "wx_c_user")
@JsonIgnoreProperties(ignoreUnknown = true)
public class WxCUser 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;
	}
	
	
	
	/*租户ID**/
	@io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId")
	private String tenantId;
	/*微信openId**/
	@io.swagger.annotations.ApiModelProperty(value="微信openId",name="openId")
	private String openId;
	/*微信unionId**/
	@io.swagger.annotations.ApiModelProperty(value="微信unionId",name="unionId")
	private String unionId;
	/*用户昵称**/
	@io.swagger.annotations.ApiModelProperty(value="用户昵称",name="nickName")
	private String nickName;
	/*用户性别**/
	@io.swagger.annotations.ApiModelProperty(value="用户性别",name="gender")
	private Integer gender;
	/*用户头像地址**/
	@io.swagger.annotations.ApiModelProperty(value="用户头像地址",name="avatarUrl")
	private String avatarUrl;
	/*用户绑定的手机号**/
	@io.swagger.annotations.ApiModelProperty(value="用户绑定的手机号",name="phone")
	private String phone;
	/*用户没有区号的手机号**/
	@io.swagger.annotations.ApiModelProperty(value="用户没有区号的手机号",name="purePhone")
	private String purePhone;
	/*用户所在城市**/
	@io.swagger.annotations.ApiModelProperty(value="用户所在城市",name="city")
	private String city;
	/*用户所在省份**/
	@io.swagger.annotations.ApiModelProperty(value="用户所在省份",name="province")
	private String province;
	/*用户所在语言**/
	@io.swagger.annotations.ApiModelProperty(value="用户所在语言",name="language")
	private String language;
	/*用户手机区号**/
	@io.swagger.annotations.ApiModelProperty(value="用户手机区号",name="countryCode")
	private String countryCode;
	/*用户注册IP**/
	@io.swagger.annotations.ApiModelProperty(value="用户注册IP",name="registerIp")
	private String registerIp;
	/***/
	@io.swagger.annotations.ApiModelProperty(value="",name="verifyCodePhone")
	private String verifyCodePhone;
	/*注册时记录用户扫码渠道，如朋友圈广告**/
	@io.swagger.annotations.ApiModelProperty(value="注册时记录用户扫码渠道，如朋友圈广告",name="qrcodeSource")
	private String qrcodeSource;
	/*二维码来源，小程序**/
	@io.swagger.annotations.ApiModelProperty(value="二维码来源，小程序",name="scene")
	private String scene;
	/*渠道，小程序**/
	@io.swagger.annotations.ApiModelProperty(value="渠道，小程序",name="sceneAddress")
	private String sceneAddress;
	/*session key for 微信小程序**/
	@io.swagger.annotations.ApiModelProperty(value="session key for 微信小程序",name="sessionKey")
	private String sessionKey;
	/*成长值**/
	@io.swagger.annotations.ApiModelProperty(value="成长值",name="score")
	private Integer score;
	/*更新时间**/
	@io.swagger.annotations.ApiModelProperty(value="更新时间",name="updateDate")
	private Date updateDate;
	/*创建时间**/
	@io.swagger.annotations.ApiModelProperty(value="创建时间",name="createDate")
	private Date createDate;
	/*小程序的appId**/
	@io.swagger.annotations.ApiModelProperty(value="小程序的appId",name="appId")
	private String appId;
	/*用户登录用token**/
	@io.swagger.annotations.ApiModelProperty(value="用户登录用token",name="token")
	private String token;
	/*用户过期时间**/
	@io.swagger.annotations.ApiModelProperty(value="用户过期时间",name="expireTime")
	private Date expireTime;
	/*经度**/
	@io.swagger.annotations.ApiModelProperty(value="经度",name="longitude")
	private BigDecimal longitude;
	/*纬度**/
	@io.swagger.annotations.ApiModelProperty(value="纬度",name="latitude")
	private BigDecimal latitude;
	/*登录次数**/
	@io.swagger.annotations.ApiModelProperty(value="登录次数",name="loginCount")
	private Integer loginCount;
	/*附加信息**/
	@io.swagger.annotations.ApiModelProperty(value="附加信息",name="extraInfo")
	private String extraInfo;
	/**是否关注公众号**/
	@io.swagger.annotations.ApiModelProperty(value="是否关注公众号",name="isSubscribe")
	private Integer isSubscribe;


	//渠道名称
	@Transient
	private String channelName;
	//渠道描述
	@Transient
	protected String sceneDescription;

	@Transient
	List<String> sceneList;

	@Transient
	protected Date startDate;

	@Transient
	protected Date endDate;

	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public Date getEndDate() {
		return endDate;
	}

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

	public List<String> getSceneList() {
		return sceneList;
	}

	public void setSceneList(List<String> sceneList) {
		this.sceneList = sceneList;
	}

	public String getChannelName() {
		return channelName;
	}

	public void setChannelName(String channelName) {
		this.channelName = channelName;
	}

	public String  getTenantId() {
		return tenantId;
	}
	public void setTenantId(String _tenantId) {
		tenantId = _tenantId;
	}
	public String  getOpenId() {
		return openId;
	}
	public void setOpenId(String _openId) {
		openId = _openId;
	}
	public String  getUnionId() {
		return unionId;
	}
	public void setUnionId(String _unionId) {
		unionId = _unionId;
	}
	public String  getNickName() {
		return nickName;
	}
	public void setNickName(String _nickName) {
		nickName = _nickName;
	}
	public Integer  getGender() {
		return gender;
	}
	public void setGender(Integer _gender) {
		gender = _gender;
	}
	public String  getAvatarUrl() {
		return avatarUrl;
	}
	public void setAvatarUrl(String _avatarUrl) {
		avatarUrl = _avatarUrl;
	}
	public String  getPhone() {
		return phone;
	}
	public void setPhone(String _phone) {
		phone = _phone;
	}
	public String  getPurePhone() {
		return purePhone;
	}
	public void setPurePhone(String _purePhone) {
		purePhone = _purePhone;
	}
	public String  getCity() {
		return city;
	}
	public void setCity(String _city) {
		city = _city;
	}
	public String  getProvince() {
		return province;
	}
	public void setProvince(String _province) {
		province = _province;
	}
	public String  getLanguage() {
		return language;
	}
	public void setLanguage(String _language) {
		language = _language;
	}
	public String  getCountryCode() {
		return countryCode;
	}
	public void setCountryCode(String _countryCode) {
		countryCode = _countryCode;
	}
	public String  getRegisterIp() {
		return registerIp;
	}
	public void setRegisterIp(String _registerIp) {
		registerIp = _registerIp;
	}
	public String  getVerifyCodePhone() {
		return verifyCodePhone;
	}
	public void setVerifyCodePhone(String _verifyCodePhone) {
		verifyCodePhone = _verifyCodePhone;
	}
	public String  getQrcodeSource() {
		return qrcodeSource;
	}
	public void setQrcodeSource(String _qrcodeSource) {
		qrcodeSource = _qrcodeSource;
	}
	public String  getScene() {
		return scene;
	}
	public void setScene(String _scene) {
		scene = _scene;
	}
	public String  getSceneAddress() {
		return sceneAddress;
	}
	public void setSceneAddress(String _sceneAddress) {
		sceneAddress = _sceneAddress;
	}
	public String  getSessionKey() {
		return sessionKey;
	}
	public void setSessionKey(String _sessionKey) {
		sessionKey = _sessionKey;
	}
	public Integer  getScore() {
		return score;
	}
	public void setScore(Integer _score) {
		score = _score;
	}
	public Date  getUpdateDate() {
		return updateDate;
	}
	public void setUpdateDate(Date _updateDate) {
		updateDate = _updateDate;
	}
	public Date  getCreateDate() {
		return createDate;
	}
	public void setCreateDate(Date _createDate) {
		createDate = _createDate;
	}
	public String  getAppId() {
		return appId;
	}
	public void setAppId(String _appId) {
		appId = _appId;
	}
	public String  getToken() {
		return token;
	}
	public void setToken(String _token) {
		token = _token;
	}
	public Date  getExpireTime() {
		return expireTime;
	}
	public void setExpireTime(Date _expireTime) {
		expireTime = _expireTime;
	}

	public BigDecimal getLongitude() {
		return longitude;
	}

	public void setLongitude(BigDecimal longitude) {
		this.longitude = longitude;
	}

	public BigDecimal getLatitude() {
		return latitude;
	}

	public void setLatitude(BigDecimal latitude) {
		this.latitude = latitude;
	}

	public Integer getLoginCount() {
		return loginCount;
	}

	public void setLoginCount(Integer loginCount) {
		this.loginCount = loginCount;
	}

	public String getSceneDescription() {
		return sceneDescription;
	}

	public void setSceneDescription(String sceneDescription) {
		this.sceneDescription = sceneDescription;
	}

	public String getExtraInfo() {
		return extraInfo;
	}

	public void setExtraInfo(String extraInfo) {
		this.extraInfo = extraInfo;
	}

	public Integer getIsSubscribe() {
		return isSubscribe;
	}

	public void setIsSubscribe(Integer isSubscribe) {
		this.isSubscribe = isSubscribe;
	}

	public static enum Field
	{
		Id_ASC("`id` ASC"),Id_DESC("`id` DESC")
		,TenantId_ASC("`tenant_id` ASC"),TenantId_DESC("`tenant_id` DESC")
		,OpenId_ASC("`open_id` ASC"),OpenId_DESC("`open_id` DESC")
		,UnionId_ASC("`union_id` ASC"),UnionId_DESC("`union_id` DESC")
		,NickName_ASC("`nick_name` ASC"),NickName_DESC("`nick_name` DESC")
		,Gender_ASC("`gender` ASC"),Gender_DESC("`gender` DESC")
		,AvatarUrl_ASC("`avatar_url` ASC"),AvatarUrl_DESC("`avatar_url` DESC")
		,Phone_ASC("`phone` ASC"),Phone_DESC("`phone` DESC")
		,PurePhone_ASC("`pure_phone` ASC"),PurePhone_DESC("`pure_phone` DESC")
		,City_ASC("`city` ASC"),City_DESC("`city` DESC")
		,Province_ASC("`province` ASC"),Province_DESC("`province` DESC")
		,Language_ASC("`language` ASC"),Language_DESC("`language` DESC")
		,CountryCode_ASC("`country_code` ASC"),CountryCode_DESC("`country_code` DESC")
		,RegisterIp_ASC("`register_ip` ASC"),RegisterIp_DESC("`register_ip` DESC")
		,VerifyCodePhone_ASC("`verify_code_phone` ASC"),VerifyCodePhone_DESC("`verify_code_phone` DESC")
		,QrcodeSource_ASC("`qrcode_source` ASC"),QrcodeSource_DESC("`qrcode_source` DESC")
		,Scene_ASC("`scene` ASC"),Scene_DESC("`scene` DESC")
		,SceneAddress_ASC("`scene_address` ASC"),SceneAddress_DESC("`scene_address` DESC")
		,SessionKey_ASC("`session_key` ASC"),SessionKey_DESC("`session_key` DESC")
		,Score_ASC("`score` ASC"),Score_DESC("`score` DESC")
		,UpdateDate_ASC("`update_date` ASC"),UpdateDate_DESC("`update_date` DESC")
		,CreateDate_ASC("`create_date` ASC"),CreateDate_DESC("`create_date` DESC")
		,AppId_ASC("`app_id` ASC"),AppId_DESC("`app_id` DESC")
		,Token_ASC("`token` ASC"),Token_DESC("`token` DESC")
		,ExpireTime_ASC("`expire_time` ASC"),ExpireTime_DESC("`expire_time` DESC")
		,Longitude_ASC("`longitude` ASC"),Longitude_DESC("`longitude` DESC")
		,Latitude_ASC("`latitude` ASC"),Latitude_DESC("`latitude` DESC")
		,LoginCount_ASC("`login_count` ASC"),LoginCount_DESC("`login_count` DESC")
		,ExtraInfo_ASC("`extra_info` ASC"),ExtraInfo_DESC("`extra_info` DESC")
		,IsSubscribe_ASC("`is_subscribe` ASC"),IsSubscribe_DESC("`is_subscribe` 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(WxCUser.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));
		}
	}

	public String createToken(Date currentDate) {
		if (expireTime == null || expireTime.getTime() < currentDate.getTime())
		{
			//生成一个token
			this.token = UUID.randomUUID().toString();
			//过期时间
			this.expireTime = new Date(currentDate.getTime() + BaseConstant.EXPIRE * 1000);
		}
		return this.token;
	}
}
