package com.njcn.sso.pojo.user;


import com.njcn.pojo.user.Depts;
import com.njcn.pojo.user.Role;
import com.njcn.pojo.user.RoleGroup;
import com.njcn.utils.PubUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.persistence.Column;
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;

/**
 * PQS_User用户表。把之前的用户表分成用户基础表（PQS_User）和用户配置表（PQS_Set），并且在用户表中增加了用户名和部门ID。
 * ①	、考虑到用户登录时候要采用RSA加密，但是这个加密中假如使用汉字则会产生乱码，因此登录名只能是8-18未特殊字符【@#_】+字母+数字组成，因此增加了用户名字段。
 * ②	、密码加密方法为：【Md5-2】+【私有秘钥】，然后进行3des加密
 * ③	、此外用户跟部门绑定，部门跟区域绑定，实现用户区域权限。
 * ④	、删除Role_Index，新建PQS_UserRole表
 */
@Table(name = "PQS_USER")
public class User implements Serializable {
    private static final Logger logger= LoggerFactory.getLogger(User.class);

    private static final long serialVersionUID = 1L;

    @Id
    @Column(name = "USER_INDEX")
    private String userIndex;

    private String name;

    @Column(name = "LOGINNAME")
    private String loginName;

    private String password;

    private String phone;

    private String email;

    @Transient
    private String lastLoginTime;

    @Transient
    private String registTime;

    @Transient
    private String loginTimes;

    @Transient
    private String lastIp;

    @Transient
    private String ip;

    @Column(name = "REGISTERTIME")
    private Date registerTime;

    @Column(name = "PSDVALIDITY")
    private Date psdvalidity;

    @Column(name = "LOGINTIME")
    private Date loginTime;

    @Column(name = "LIMIT_IPSTART")
    private String limitIpStart;

    @Column(name = "LIMIT_IPEND")
    private String limitIpEnd;

    @Column(name = "LIMIT_TIME")
    private String limitTime;

    @Column(name = "LOGIN_ERROR_TIMES")
    private Integer loginErrorTimes;

    @Column(name = "casual_user")
    private Integer casualUser;

    @Column(name = "firsterror_time")
    private Date firstErrorTime;

    @Column(name = "lock_time")
    private Date lockTime;

    @Column(name="REFERRAL_CODE")
    private String referralCode;

    public Date getFirstErrorTime() {
        return firstErrorTime;
    }

    public void setFirstErrorTime(Date firstErrorTime) {
        this.firstErrorTime = firstErrorTime;
    }

    public Date getLockTime() {
        return lockTime;
    }

    public void setLockTime(Date lockTime) {
        this.lockTime = lockTime;
    }

    private Integer state;

    private Integer mark;

    public Integer getCasualUser() {
        return casualUser;
    }

    public void setCasualUser(Integer casualUser) {
        this.casualUser = casualUser;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public String getRegistTime() {
        return registTime;
    }

    public void setRegistTime(String registTime) {
        this.registTime = registTime;
    }

    //系统代号
    @Transient
    private String item;

    public void setItem(String item) {
        this.item = item;
    }

    public String getItem() {
        return item;
    }

    public User() {
        super();
    }

    public User(User user) {
        super();
        this.userIndex = user.getUserIndex();
        this.name = user.getName();
        this.loginName = user.getLoginName();
        this.password = user.getPassword();
        this.phone = user.getPhone();
        this.email = user.getEmail();
        this.registerTime = user.getRegisterTime();
        this.psdvalidity = user.getPsdvalidity();
        this.loginTime = user.getLoginTime();
        this.state = user.getState();
        this.mark = user.getMark();
    }


    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    public String getUserIndex() {
        return userIndex;
    }

    public void setUserIndex(String userIndex) {
        this.userIndex = userIndex;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getLoginName() {
        return loginName;
    }

    public void setLoginName(String loginName) {
        this.loginName = loginName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getPhone() {
        return phone;
    }

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

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Date getRegisterTime() {
        return registerTime;
    }

    public void setRegisterTime(Date registerTime) {
        this.registerTime = registerTime;
        try {
            this.registTime = PubUtils.date2String(registerTime, "yyyy-MM-dd HH:mm:ss");
        } catch (Exception e) {
            logger.error("时间转化异常，异常是"+e.getMessage());
        }
    }

    public Date getPsdvalidity() {
        return psdvalidity;
    }

    public void setPsdvalidity(Date psdvalidity) {
        this.psdvalidity = psdvalidity;
    }

    public Date getLoginTime() {
        return loginTime;
    }

    public void setLoginTime(Date loginTime) {
        this.loginTime = loginTime;
        try {
            this.lastLoginTime = PubUtils.date2String(loginTime, "yyyy-MM-dd HH:mm:ss");
        } catch (Exception e) {
            logger.error("时间转化异常，异常是"+e.getMessage());
        }
    }

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    public Integer getMark() {
        return mark;
    }

    public void setMark(Integer mark) {
        this.mark = mark;
    }

    public String getLastLoginTime() {
        return lastLoginTime;
    }

    public void setLastLoginTime(String lastLoginTime) {
        this.lastLoginTime = lastLoginTime;
    }

    public String getLastIp() {
        return lastIp;
    }

    public void setLastIp(String lastIp) {
        this.lastIp = lastIp;
    }

    public String getLoginTimes() {
        return loginTimes;
    }

    public void setLoginTimes(String loginTimes) {
        this.loginTimes = loginTimes;
    }

    public String getReferralCode() {
        return referralCode;
    }

    public void setReferralCode(String referralCode) {
        this.referralCode = referralCode;
    }

    //修改用户需要的数据
    //起始IP 截止IP 时间段 来源 部门
    @Transient
    private String ipStart;
    @Transient
    private String ipEnd;
    @Transient
    private String time;
    @Transient
    private String deptsName;
    @Transient
    private String roleGPIndex;
    @Transient
    private int isnotice;
    //获取当前sysType下所有的部门信息
    @Transient
    private List<Depts> deptsList = new ArrayList<>();
    //获取当前sysType下所有的角色组信息
    @Transient
    private List<Role> roleGroups = new ArrayList<>();

    public String getRoleGPIndex() {
        return roleGPIndex;
    }

    public void setRoleGPIndex(String roleGPIndex) {
        this.roleGPIndex = roleGPIndex;
    }

    public List<Role> getRoleGroups() {
        return roleGroups;
    }

    public void setRoleGroups(List<Role> roleGroups) {
        this.roleGroups = roleGroups;
    }

    public List<Depts> getDeptsList() {
        return deptsList;
    }

    public void setDeptsList(List<Depts> deptsList) {
        this.deptsList = deptsList;
    }

    public String getIpStart() {
        return ipStart;
    }

    public void setIpStart(String ipStart) {
        this.ipStart = ipStart;
    }

    public String getIpEnd() {
        return ipEnd;
    }

    public void setIpEnd(String ipEnd) {
        this.ipEnd = ipEnd;
    }

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    public String getDeptsName() {
        return deptsName;
    }

    public void setDeptsName(String deptsName) {
        this.deptsName = deptsName;
    }

    public String getLimitIpStart() {
        return limitIpStart;
    }

    public void setLimitIpStart(String limitIpStart) {
        this.limitIpStart = limitIpStart;
    }

    public String getLimitIpEnd() {
        return limitIpEnd;
    }

    public int getIsnotice() {
        return isnotice;
    }

    public void setIsnotice(int isnotice) {
        this.isnotice = isnotice;
    }

    public void setLimitIpEnd(String limitIpEnd) {
        this.limitIpEnd = limitIpEnd;
    }

    public String getLimitTime() {
        return limitTime;
    }

    public void setLimitTime(String limitTime) {
        this.limitTime = limitTime;
    }

    public Integer getLoginErrorTimes() {
        return loginErrorTimes;
    }

    public void setLoginErrorTimes(Integer errorTimes) {
        this.loginErrorTimes = errorTimes;
    }

    @Override
    public String toString() {
        return "User{" +
                "userIndex='" + userIndex + '\'' +
                ", name='" + name + '\'' +
                ", loginName='" + loginName + '\'' +
                ", password='" + password + '\'' +
                ", phone='" + phone + '\'' +
                ", email='" + email + '\'' +
                ", lastLoginTime='" + lastLoginTime + '\'' +
                ", registTime='" + registTime + '\'' +
                ", loginTimes='" + loginTimes + '\'' +
                ", lastIp='" + lastIp + '\'' +
                ", ip='" + ip + '\'' +
                ", registerTime=" + registerTime +
                ", psdvalidity=" + psdvalidity +
                ", loginTime=" + loginTime +
                ", limitIpStart='" + limitIpStart + '\'' +
                ", limitIpEnd='" + limitIpEnd + '\'' +
                ", limitTime='" + limitTime + '\'' +
                ", loginErrorTimes=" + loginErrorTimes +
                ", casualUser=" + casualUser +
                ", firstErrorTime=" + firstErrorTime +
                ", lockTime=" + lockTime +
                ", state=" + state +
                ", mark=" + mark +
                ", item='" + item + '\'' +
                ", ipStart='" + ipStart + '\'' +
                ", ipEnd='" + ipEnd + '\'' +
                ", time='" + time + '\'' +
                ", deptsName='" + deptsName + '\'' +
                ", roleGPIndex='" + roleGPIndex + '\'' +
                ", deptsList=" + deptsList +
                ", roleGroups=" + roleGroups +
                '}';
    }
}
