package com.zksy.common.core.domain.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.zksy.common.annotation.Excel;
import com.zksy.common.core.domain.BaseEntity;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.util.Date;
import java.util.List;

/**
 * 用户信息对象 sys_user
 *
 * @author zksy
 * @date 2022-04-13
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("sys_user")
@ApiModel(value = "用户实体")
public class SysUser extends BaseEntity {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "用户ID")
    @TableId(value = "user_id", type = IdType.AUTO)
    /** 用户ID */
    private Long userId;

    @ApiModelProperty(value = "部门ID")
    /** 部门ID */
    @Excel(name = "部门ID")
    private Long deptId;

    @ApiModelProperty(value = "用户账号")
    /** 用户账号 */
    @Excel(name = "用户账号")
    private String userName;

    @ApiModelProperty(value = "用户昵称")
    /** 用户昵称 */
    @Excel(name = "用户昵称")
    private String nickName;

    @ApiModelProperty(value = "用户类型（0系统用户 1 干部 2 会员）")
    /** 用户类型（0系统用户 1 干部 2 会员） */
    @Excel(name = "用户类型", readConverterExp = "0=系统用户,1=,干=部,2=,会=员")
    private String userType;

    @ApiModelProperty(value = "用户邮箱")
    /** 用户邮箱 */
    @Excel(name = "用户邮箱")
    private String email;

    @ApiModelProperty(value = "手机号码")
    /** 手机号码 */
    @Excel(name = "手机号码")
    private String phonenumber;

    @ApiModelProperty(value = "用户性别（0男 1女 2未知）")
    /** 用户性别（0男 1女 2未知） */
    @Excel(name = "用户性别", readConverterExp = "0=男,1=女,2=未知")
    private String sex;

    @ApiModelProperty(value = "头像地址")
    /** 头像地址 */
    @Excel(name = "头像地址")
    private String avatar;

    @ApiModelProperty(value = "密码")
    /** 密码 */
    @Excel(name = "密码")
    private String password;

    @ApiModelProperty(value = "帐号状态（0正常 1停用）")
    /** 帐号状态（0正常 1停用） */
    @Excel(name = "帐号状态", readConverterExp = "0=正常,1=停用")
    private String status;

    @ApiModelProperty(value = "删除标志（0代表存在 2代表删除）")
    /** 删除标志（0代表存在 2代表删除） */
    private String delFlag;

    @ApiModelProperty(value = "最后登录IP")
    /** 最后登录IP */
    @Excel(name = "最后登录IP")
    private String loginIp;

    @ApiModelProperty(value = "最后登录时间")
    /** 最后登录时间 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "最后登录时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date loginDate;

    @ApiModelProperty(value = "机构")
    @TableField(exist = false)
    private SysDept dept;

    /**
     * 角色对象
     */
    @ApiModelProperty(value = "角色对象")
    @TableField(exist = false)
    private List<SysRole> roles;

    /**
     * 角色组
     */
    @ApiModelProperty(value = "角色组")
    @TableField(exist = false)
    private Long[] roleIds;

    /**
     * 岗位组
     */
    @ApiModelProperty(value = "岗位组")
    @TableField(exist = false)
    private Long[] postIds;

    /**
     * 角色ID
     */
    @TableField(exist = false)
    @ApiModelProperty(value = "角色ID")
    private Long roleId;

    /**
     * 单位名称
     */
    @TableField(exist = false)
    @ApiModelProperty(value = "单位名称")
    private String orgName;

    /**
     * 部门名称
     */
    @ApiModelProperty(value = "部门名称")
    @TableField(exist = false)
    private String deptName;



    public boolean isAdmin() {
        return isAdmin(this.userId);
    }

    public static boolean isAdmin(Long userId) {
        return userId != null && 1L == userId;
    }

    public SysUser() {
    }

    public SysUser(Long userId) {
        this.userId = userId;
    }
}
