package com.qmth.teachcloud.common.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.qmth.teachcloud.common.enums.AppSourceEnum;
import com.qmth.teachcloud.common.util.ServletUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;

/**
 * <p>
 * 会话表
 * </p>
 *
 * @author wangliang
 * @since 2021-03-19
 */
@ApiModel(value = "TBSession对象", description = "会话表")
public class TBSession implements Serializable {

    private static final long serialVersionUID = 1L;

    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(value = "主键")
    @TableId(value = "id")
    private String id;

    @ApiModelProperty(value = "学校id")
    @JsonSerialize(using = ToStringSerializer.class)
    @TableField("school_id")
    private Long schoolId;

    @ApiModelProperty(value = "机构id")
    @JsonSerialize(using = ToStringSerializer.class)
    @TableField("org_id")
    private Long orgId;

    @ApiModelProperty(value = "用户标识")
    @TableField(value = "identity")
    private String identity;

    @ApiModelProperty(value = "用户类型")
    @TableField(value = "type")
    private String type;

    @ApiModelProperty(value = "访问来源")
    @TableField(value = "source")
    private String source;

    @ApiModelProperty(value = "设备分类")
    @TableField(value = "platform")
    private String platform;

    @ApiModelProperty(value = "设备标识")
    @TableField(value = "device_id")
    private String deviceId;

    @ApiModelProperty(value = "登录IP地址")
    @TableField(value = "address")
    private String address;

    @ApiModelProperty(value = "访问令牌")
    @TableField(value = "access_token")
    private String accessToken;

    @ApiModelProperty(value = "最近访问时间")
    @TableField(value = "last_access_time")
    private Long lastAccessTime;

    @ApiModelProperty(value = "最近访问IP地址")
    @TableField(value = "last_access_ip")
    private String lastAccessIp;

    @ApiModelProperty(value = "令牌更新时间")
    @TableField(value = "update_time")
    private Long updateTime;

    @ApiModelProperty(value = "令牌强制失效时间")
    @TableField(value = "expire_time")
    private Long expireTime;

    @ApiModelProperty(value = "应用来源")
    @TableField(value = "app_source")
    private AppSourceEnum appSource;

    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    public TBSession() {

    }

    public TBSession(Long schoolId, String id, String identity, String type, String source, String platform, String deviceId, String address, String accessToken, Long expireTime, AppSourceEnum appSource) {
        this.schoolId = schoolId;
        this.id = id;
        this.identity = identity;
        this.type = type;
        this.source = source;
        this.platform = platform;
        this.deviceId = deviceId;
        this.address = address;
        this.accessToken = accessToken;
        this.expireTime = expireTime;
        this.lastAccessTime = System.currentTimeMillis();
        this.lastAccessIp = address;
        this.appSource = appSource;
    }

    public void setLastInfo() {
        this.lastAccessTime = System.currentTimeMillis();
        this.lastAccessIp = ServletUtil.getRequest().getLocalAddr();
    }

    public Long getSchoolId() {
        return schoolId;
    }

    public void setSchoolId(Long schoolId) {
        this.schoolId = schoolId;
    }

    public Long getOrgId() {
        return orgId;
    }

    public void setOrgId(Long orgId) {
        this.orgId = orgId;
    }

    public AppSourceEnum getAppSource() {
        return appSource;
    }

    public void setAppSource(AppSourceEnum appSource) {
        this.appSource = appSource;
    }

    public String getId() {
        return id;
    }

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

    public String getIdentity() {
        return identity;
    }

    public void setIdentity(String identity) {
        this.identity = identity;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getSource() {
        return source;
    }

    public void setSource(String source) {
        this.source = source;
    }

    public String getPlatform() {
        return platform;
    }

    public void setPlatform(String platform) {
        this.platform = platform;
    }

    public String getDeviceId() {
        return deviceId;
    }

    public void setDeviceId(String deviceId) {
        this.deviceId = deviceId;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getAccessToken() {
        return accessToken;
    }

    public void setAccessToken(String accessToken) {
        this.accessToken = accessToken;
    }

    public Long getLastAccessTime() {
        return lastAccessTime;
    }

    public void setLastAccessTime(Long lastAccessTime) {
        this.lastAccessTime = lastAccessTime;
    }

    public String getLastAccessIp() {
        return lastAccessIp;
    }

    public void setLastAccessIp(String lastAccessIp) {
        this.lastAccessIp = lastAccessIp;
    }

    public Long getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Long updateTime) {
        this.updateTime = updateTime;
    }

    public Long getExpireTime() {
        return expireTime;
    }

    public void setExpireTime(Long expireTime) {
        this.expireTime = expireTime;
    }
}
