package com.gxwebsoft.common.system.entity;

import cn.hutool.core.util.DesensitizedUtil;
import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.security.core.userdetails.UserDetails;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 用户
 *
 * @author WebSoft
 * @since 2018-12-24 16:10:13
 */
@Data
@ApiModel(description = "用户")
@TableName("sys_user")
public class User implements UserDetails {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("用户id")
    @TableId(type = IdType.AUTO)
    private Integer userId;

    @ApiModelProperty("用户类型, 0普通用户 6开发者 10企业用户")
    private Integer type;

    @ApiModelProperty("用户编码")
    private String userCode;

    @ApiModelProperty("账号")
    private String username;

    @ApiModelProperty("密码")
    private String password;

    @ApiModelProperty("昵称")
    private String nickname;

    @ApiModelProperty("头像")
    private String avatar;

    @ApiModelProperty("性别, 字典标识")
    private String sex;

    @ApiModelProperty("手机号")
    private String phone;

    @ApiModelProperty("邮箱")
    private String email;

    @ApiModelProperty("职务")
    private String position;

    @ApiModelProperty("邮箱是否验证, 0否, 1是")
    private Integer emailVerified;

    @ApiModelProperty("别名")
    private String alias;

    @ApiModelProperty("真实姓名")
    private String realName;

    @ApiModelProperty("身份证号")
    private String idCard;

    @ApiModelProperty("出生日期")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date birthday;

    @ApiModelProperty("所在国家")
    private String country;

    @ApiModelProperty(value = "所在省份")
    private String province;

    @ApiModelProperty(value = "所在城市")
    private String city;

    @ApiModelProperty(value = "所在辖区")
    private String region;

    @ApiModelProperty("街道地址")
    private String address;

    @ApiModelProperty("用户可用余额")
    private BigDecimal balance;

    @ApiModelProperty("用户可用积分")
    private Integer points;

    @ApiModelProperty("用户总支付的金额")
    private String payMoney;

    @ApiModelProperty("实际消费的金额(不含退款)")
    private String expendMoney;

    @ApiModelProperty("会员等级ID")
    private Integer gradeId;

    @ApiModelProperty("个人简介")
    private String introduction;

    @ApiModelProperty("机构ID")
    private Integer organizationId;

    @ApiModelProperty("客户ID")
    private Integer customerId;

    @ApiModelProperty("企业ID")
    private Integer companyId;

    @ApiModelProperty("注册来源客户端")
    private String platform;

    @ApiModelProperty("备注")
    private String comments;

    @ApiModelProperty("状态, 0正常, 1冻结")
    private Integer status;

    @ApiModelProperty("是否删除, 0否, 1是")
    @TableLogic
    private Integer deleted;

    @ApiModelProperty(value = "租户id")
    private Integer tenantId;

    @ApiModelProperty(value = "租户名称")
    @TableField(exist = false)
    private String tenantName;

    @ApiModelProperty(value = "最后结算时间")
    private Date settlementTime;

    @ApiModelProperty("注册时间")
    private Date createTime;

    @ApiModelProperty("修改时间")
    private Date updateTime;

    @ApiModelProperty("公司名称")
    private String companyName;

    @ApiModelProperty("是否已实名认证")
    private Integer certification;

    @ApiModelProperty("用户等级(0无权限1班组组长2资料员3经营人员4生产主管)")
    private Integer userLevel;

    @ApiModelProperty("机构名称")
    @TableField(exist = false)
    private String organizationName;

    @ApiModelProperty("性别名称")
    @TableField(exist = false)
    private String sexName;

    @ApiModelProperty("默认注册的角色ID")
    @TableField(exist = false)
    private Integer roleId;

    @ApiModelProperty("角色列表")
    @TableField(exist = false)
    private List<Role> roles;

    @ApiModelProperty("权限列表")
    @TableField(exist = false)
    private List<Menu> authorities;

    @ApiModelProperty("微信凭证")
    @TableField(exist = false)
    private String code;

    @ApiModelProperty("所属商户的编号")
    @TableField(exist = false)
    private String merchantCode;

    @ApiModelProperty("所属商户名称")
    @TableField(exist = false)
    private String merchantName;

    @ApiModelProperty("ico文件")
    @TableField(exist = false)
    private String logo;

    @ApiModelProperty("创建的应用数量")
    @TableField(exist = false)
    private Double apps;

    @ApiModelProperty("租户设置信息")
    @TableField(exist = false)
    private String setting;

    @ApiModelProperty("手机号(脱敏)")
    @TableField(exist = false)
    private String mobile;

    @ApiModelProperty("企业信息")
    @TableField(exist = false)
    private Company companyInfo;

    @TableField(exist = false)
    private Integer auditStatus;


    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return this.status != null && this.status == 0;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
//
//    public String getRealName(){
//      return DesensitizedUtil.chineseName(this.realName);
//    }
//
//    public String getIdCard(){
//      return DesensitizedUtil.idCardNum(this.idCard,1,2);
//    }
    public String getMobile(){
      return DesensitizedUtil.mobilePhone(this.phone);
    }

}
