package com.sdtool.common.entity.system;

import com.sdtool.common.datas.TokenUserFrom;
import com.sdtool.common.entity.base.BaseEntity;
import com.sdtool.common.entity.site.TokenUserData;
import com.sweetfish.util.Comment;
import org.rex.db.RColumn;

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

/**
 * Created by jlutt on 2018-07-12.
 *
 * @author jlutt
 */
public class LoginUser extends BaseEntity implements TokenUserData {

    @Comment("")
    @RColumn("id")
    private long id;

    @Comment("公司ID")
    @RColumn("companyid")
    private long companyId;

    @Comment("人员编码")
    @RColumn("usercode")
    private String userCode;

    @Comment("部门ID")
    @RColumn("deptid")
    private long deptId;

    @Comment("登录名")
    @RColumn("loginname")
    private String loginName;

    @Comment("用户名")
    @RColumn("username")
    private String userName;

    @Comment("用户类型")
    @RColumn("usertype")
    private int userType;

    @Comment("邮件")
    @RColumn("email")
    private String email;

    @Comment("电话")
    @RColumn("phonenumber")
    private String phoneNumber;

    @Comment("性别")
    @RColumn("sex")
    private int sex;

    @Comment("头像")
    @RColumn("avatar")
    private String avatar;

    @Comment("密码")
    @RColumn("password")
    private String password;

    @Comment("盐")
    @RColumn("salt")
    private String salt;

    @Comment("状态")
    @RColumn("status")
    private int status;

    @Comment("删除标记")
    @RColumn("delflag")
    private int delFlag;

    @Comment("备注")
    @RColumn("remark")
    private String remark;

    @Comment("sessionid")
    @RColumn("sessionid")
    private String sessionId;

    @Comment("部门名称")
    @RColumn("deptname")
    private String deptName;

    @Comment("对应角色")
    private List<UserRole> roleList = new ArrayList<>();

    /**
     * 客户端增加、编辑页面传递的角色信息，逗号分隔
     */
    @Comment("对应角色ID")
    @RColumn("roleids")
    private String roleIds;

    @Comment("分享码")
    @RColumn("sharecode")
    private String shareCode;

    /**
     * 岗位信息，逗号分隔
     */
    @Comment("岗位")
    @RColumn("postids")
    private String postIds;

    @Comment("订阅消息")
    @RColumn("msggroups")
    private String msgGroups;

    @Comment("上班打卡时间，冗余字段，不存数据库")
    private Date checkInTime;

    @Comment("工作状态 1可接单 2忙碌不接单，冗余字段，不存数据库")
    private int workInState;

    @Comment("工作数量 冗余字段，不存数据库")
    private int workInCount;

    @Comment("登录ip地址，冗余字段")
    private String loginIpAddr;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public long getCompanyId() {
        return companyId;
    }

    public void setCompanyId(long companyId) {
        this.companyId = companyId;
    }

    public String getUserCode() {
        return userCode;
    }

    public void setUserCode(String userCode) {
        this.userCode = userCode;
    }

    public long getDeptId() {
        return deptId;
    }

    public void setDeptId(long deptId) {
        this.deptId = deptId;
    }

    public String getLoginName() {
        return loginName;
    }

    public String getAccount() {
        return loginName;
    }

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

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public int getUserType() {
        return userType;
    }

    public void setUserType(int userType) {
        this.userType = userType;
    }

    public String getEmail() {
        return email;
    }

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

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public int getSex() {
        return sex;
    }

    public void setSex(int sex) {
        this.sex = sex;
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    public String getPassword() {
        return password;
    }

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

    public String getSalt() {
        return salt;
    }

    public void setSalt(String salt) {
        this.salt = salt;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public int getDelFlag() {
        return delFlag;
    }

    public void setDelFlag(int delFlag) {
        this.delFlag = delFlag;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getSessionId() {
        return sessionId;
    }

    public void setSessionId(String sessionId) {
        this.sessionId = sessionId;
    }

    public List<UserRole> getRoleList() {
        return roleList;
    }

    public void setRoleList(List<UserRole> roleList) {
        this.roleList = roleList;
    }

    public String getDeptName() {
        return deptName;
    }

    @Override
    public int getUserFrom() {
        return TokenUserFrom.PC_ERP_ADMIN.getValue();
    }

    @Override
    public long getIdBindOrg() {
        return 0L;
    }

    @Override
    public String getBindUserName() {
        return "";
    }

    @Override
    public String getUserOpenId() {
        return "";
    }

    @Override
    public String getBindUserLinkPhone() {
        return "";
    }

    public void setDeptName(String deptName) {
        this.deptName = deptName;
    }

    public String getRoleIds() {
        return roleIds;
    }

    public void setRoleIds(String roleIds) {
        this.roleIds = roleIds;
    }

    public String getPostIds() {
        return postIds;
    }

    public void setPostIds(String postIds) {
        this.postIds = postIds;
    }

    public long[] parseRoleArray() {
        return getRoleList().stream().mapToLong(UserRole::getRoleId).toArray();
    }

    public String getMsgGroups() {
        return msgGroups;
    }

    public void setMsgGroups(String msgGroups) {
        this.msgGroups = msgGroups;
    }

    public Date getCheckInTime() {
        return checkInTime;
    }

    public void setCheckInTime(Date checkInTime) {
        this.checkInTime = checkInTime;
    }

    public int getWorkInState() {
        return workInState;
    }

    public void setWorkInState(int workInState) {
        this.workInState = workInState;
    }

    public String getLoginIpAddr() {
        return loginIpAddr;
    }

    public void setLoginIpAddr(String loginIpAddr) {
        this.loginIpAddr = loginIpAddr;
    }

    public int getWorkInCount() {
        return workInCount;
    }

    public void setWorkInCount(int workInCount) {
        this.workInCount = workInCount;
    }

    public String getShareCode() {
        return shareCode;
    }

    public void setShareCode(String shareCode) {
        this.shareCode = shareCode;
    }
}
