User.java 4.79 KB
package com.huaheng.pc.system.user.domain;

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.fasterxml.jackson.annotation.JsonFormat;
import com.huaheng.framework.aspectj.lang.annotation.Excel;
import com.huaheng.pc.system.dept.domain.Dept;
import lombok.Data;
import org.apache.shiro.crypto.SecureRandomNumberGenerator;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 用户对象 sys_user
 * 
 * @author huaheng
 */
@Data
@TableName(value = "sys_user")
public class User implements Serializable
{

    private static final long serialVersionUID = 3875676767702L;

    /** 用户ID */
    @Excel(name = "用户序号")
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    /** 部门ID */
    @TableField(value = "deptId")
    private Integer deptId;

    /** 部门父ID */
    @TableField(value = "parentId")
    private Integer parentId;

    /** 登录名称 */
    @Excel(name = "登录名称")
    @TableField(value = "loginName")
    private String loginName;

    /** 用户名称 */
    @Excel(name = "用户名称")
    @TableField(value = "userName")
    private String userName;

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

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

    /** 用户性别 */
    @Excel(name = "用户性别")
    @TableField(value = "sex")
    private String sex;

    /** 用户头像 */
    @TableField(value = "avatar")
    private String avatar;

    /** 密码 */
    @TableField(value = "password")
    private String password;

    /** 盐加密 */
    @TableField(value = "salt")
    private String salt;

    /** 启用状态 */
    @Excel(name = "启用状态")
    @TableField(value = "enable")
    private Boolean enable;

    /** 删除状态 */
    @Excel(name = "删除状态")
    @TableField(value = "deleted")
    private Boolean deleted;

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

    /** 最后登陆时间 */
    @Excel(name = "最后登陆时间")
    @TableField(value = "loginDate")
    private Date loginDate;

    /** 部门对象 */
    private Dept dept;

    /** 仓库ID */
    private Integer warehouseId;

    /** 仓库编码 */
    private String warehouseCode;

    /** 角色列表 */
    private List<Integer> roleIds;

    /** 货主id列表 */
    private List<Integer> companyIdList;

    /** 货主编码列表 */
    private List<String> companyCodeList;

    /** 仓库编码列表 */
    private List<String> warehouseCodeList;

    /** 搜索值 */
    private String searchValue;

    /** 创建者 */
    @TableField(value = "createBy")
    private String createBy;

    /** 创建时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(value = "createTime")
    private Date createTime;

    /** 更新者 */
    @TableField(value = "updateBy")
    private String updateBy;

    /** 更新时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(value = "updateTime")
    private Date updateTime;

    /** 备注 */
    @TableField(value = "remark")
    private String remark;

    @TableField(exist = false)
    private Boolean admin;

    /** 请求参数 */
    private Map<String, Object> params;

    private List<Integer> supplierIds;

    /**
     * 生成随机盐
     */
    public void randomSalt()
    {
        // 一个Byte占两个字节,此处生成的3字节,字符串长度为6
        SecureRandomNumberGenerator secureRandom = new SecureRandomNumberGenerator();
        String hex = secureRandom.nextBytes(3).toHex();
        setSalt(hex);
    }

    public boolean unAdmin()
    {
        return unAdmin(this.id);
    }

    public static boolean unAdmin(Integer id)
    {
        return id != null && 1L == id;
    }

    public static boolean unAdmin(String loginName)
    {
        return "superAdmin".equals(loginName);
    }

    @Override
    public String toString()
    {
        return "User [id=" + id + ", deptId=" + deptId + ", parentId=" + parentId + ", loginName=" + loginName
                + ", userName=" + userName + ", email=" + email + ", phoneNumber=" + phoneNumber + ", sex=" + sex
                + ", avatar=" + avatar + ", password=" + password + ", salt=" + salt + ", enable=" + enable
                + ", deleted=" + deleted + ", loginIp=" + loginIp + ", loginDate=" + loginDate + ", dept=" + dept + "]";
//                + ", roleIds=" + String.join(",", roleIds) + ", companyIds=" + Arrays.toString(companyIds.toArray()) + "]";
    }

}