package com.iformall.domain.po;

import com.iformall.enums.EnumUserWechat;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Table(name = "mall_user_info")
@Data
public class MallUserInfo implements Serializable {
	private static final long serialVersionUID = 1L;
	
	@Id
    protected Long id;
    
    @Transient
    protected List<String> 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<String> getIds() {
		return ids;
	}
	public void setIds(List<String> ids) {
		this.ids = ids;
	}


	
	/**租户ID**/
	@io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId")
	private String tenantId;
	/**登录用户名**/
	@io.swagger.annotations.ApiModelProperty(value="登录用户名",name="username")
	private String username;
	/**用户名称**/
	@io.swagger.annotations.ApiModelProperty(value="用户名称",name="name")
	private String name;
	/**密码**/
	@io.swagger.annotations.ApiModelProperty(value="密码",name="password")
	private String password;
	/**创建时间**/
	@io.swagger.annotations.ApiModelProperty(value="创建时间",name="createTime")
	private Date createTime;
	/**最后登录时间**/
	@io.swagger.annotations.ApiModelProperty(value="最后登录时间",name="lastLoginTime")
	private Date lastLoginTime;
	/**1:有效，0:禁止登录**/
	@io.swagger.annotations.ApiModelProperty(value="1:有效，0:禁止登录",name="status")
	private Integer status;
	/**0 不是超管 1是超管**/
	@io.swagger.annotations.ApiModelProperty(value="0 不是超管 1是超管",name="isAdmin")
	private Integer isAdmin;
	@io.swagger.annotations.ApiModelProperty(value="昵称",name="nickName")
	private String nickName;

	@io.swagger.annotations.ApiModelProperty(value="手机,系统内手机号唯一",name="phone")
	private String phone;

	@io.swagger.annotations.ApiModelProperty(value="B端用户微信openid，领导看数据塔台用",name="bopenId")
	private String bopenId;

    @io.swagger.annotations.ApiModelProperty(value="admin用户微信登录用，可绑定多个账户",name="webOpenId")
    private String webOpenId;

    @io.swagger.annotations.ApiModelProperty(value="1 未绑定wechat，0 绑定微信",name="withWechat")
    @Transient
    private Integer withWechat;

	@Transient
	private Long roleId;
	
	@Transient
	private String roleName;
    //该用户所有的角色
    @Transient
    private List<MallRole> role;
    //该用户包含的所有权限
    @Transient
    private List<MallPermission> permission;
    //拥有的菜单权限
    @Transient
    private String menus;

	@Transient
	private String captcha;

	/**1合同审批 2账单审批**/
	@io.swagger.annotations.ApiModelProperty(value="1合同审批 2账单审批",name="flowPermission")
	private String flowPermission;

	public String getFlowPermission() {
		return flowPermission;
	}

	public void setFlowPermission(String flowPermission) {
		this.flowPermission = flowPermission;
	}

	public String getMenus() {
		return menus;
	}

	public void setMenus(String menus) {
		this.menus = menus;
	}

	public String getRoleName() {
		return roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	public String  getTenantId() {
		return tenantId;
	}
	public void setTenantId(String _tenantId) {
		tenantId = _tenantId;
	}
	public String  getUsername() {
		return username;
	}
	public void setUsername(String _username) {
		username = _username;
	}
	public String  getName() {
		return name;
	}
	public void setName(String _name) {
		name = _name;
	}
	public String  getPassword() {
		return password;
	}
	public void setPassword(String _password) {
		password = _password;
	}
	public Date  getCreateTime() {
		return createTime;
	}
	public void setCreateTime(Date _createTime) {
		createTime = _createTime;
	}
	public Date  getLastLoginTime() {
		return lastLoginTime;
	}
	public void setLastLoginTime(Date _lastLoginTime) {
		lastLoginTime = _lastLoginTime;
	}
	public Integer  getStatus() {
		return status;
	}
	public void setStatus(Integer _status) {
		status = _status;
	}
	public Integer  getIsAdmin() {
		return isAdmin;
	}
	public void setIsAdmin(Integer _isAdmin) {
		isAdmin = _isAdmin;
	}
    public List<MallRole> getRole() {
        return role;
    }

    public void setRole(List<MallRole> role) {
        this.role = role;
    }

    public List<MallPermission> getPermission() {
        return permission;
    }

    public void setPermission(List<MallPermission> permission) {
        this.permission = permission;
    }

	public String getNickName() {
		return nickName;
	}

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

	public Long getRoleId() {
		return roleId;
	}

	public void setRoleId(Long roleId) {
		this.roleId = roleId;
	}

	public String getCaptcha() {
		return captcha;
	}

	public void setCaptcha(String captcha) {
        this.captcha = captcha;
    }

    public Integer getWithWechat() {
        if(StringUtils.isNotBlank(this.webOpenId)) {
            this.withWechat = EnumUserWechat.HAD.getCode();
        } else {
            this.withWechat = EnumUserWechat.NO.getCode();
        }
        return this.withWechat;
    }

    public void setWithWechat(Integer withWechat) {
        this.withWechat = withWechat;
    }

    public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

    public String getBopenId() {
        return bopenId;
    }

    public void setBopenId(String bopenId) {
        this.bopenId = bopenId;
    }

    public String getWebOpenId() {
        return webOpenId;
    }

    public void setWebOpenId(String webOpenId) {
        this.webOpenId = webOpenId;
    }

    public static enum Field
	{
		Id_ASC("`id` ASC"),Id_DESC("`id` DESC")
			,TenantId_ASC("`tenant_id` ASC"),TenantId_DESC("`tenant_id` DESC")
			,Username_ASC("`username` ASC"),Username_DESC("`username` DESC")
			,Name_ASC("`name` ASC"),Name_DESC("`name` DESC")
			,Password_ASC("`password` ASC"),Password_DESC("`password` DESC")
			,CreateTime_ASC("`create_time` ASC"),CreateTime_DESC("`create_time` DESC")
			,LastLoginTime_ASC("`last_login_time` ASC"),LastLoginTime_DESC("`last_login_time` DESC")
			,Status_ASC("`status` ASC"),Status_DESC("`status` DESC")
			,IsAdmin_ASC("`is_admin` ASC"),IsAdmin_DESC("`is_admin` DESC")
			,NickName_ASC("`nick_name` ASC"),NickName_DESC("`nick_name` DESC")
			,Phone_ASC("`phone` ASC"),Phone_DESC("`phone` DESC")
			,BOpenId_ASC("`bopen_id` ASC"),BOpenId_DESC("`bopen_id` DESC")
            ,WebOpenId_ASC("`web_open_id` ASC"),WebOpenId_DESC("`web_open_id` 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(MallUserInfo.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(",");
			List<Field> fList = new 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));
		}
	}
}
