package com.jeesms.entity.system;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.jeesms.common.Constants;
import com.jeesms.entity.base.IdEntity;

import javax.persistence.*;
import java.util.Date;

/**
 * 登录日志Entity
 *
 * @author ASHNL
 * @time 2014-08-22 15:42:51
 */
@Entity
@Table(name = "T_S_LOGIN_LOG")
@JsonIgnoreProperties(value = {"hibernateLazyInitializer", "handler", "fieldHandler"})
public class LoginLog extends IdEntity {
    /**
     * 登录用户
     */
    private User user;
    /**
     * 登录时间
     */
    private Date loginTime;
    /**
     * 登录IP
     */
    private String loginIp;
    /**
     * 描述
     */
    private String remark;

    public LoginLog() {

    }

    public LoginLog(String id) {
        this();
        this.id = id;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id")
    @JsonIgnore
    public User getUser() {
        return this.user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @Column(name = "LOGIN_TIME")
    @JsonFormat(pattern = Constants.yyyyMMddHHmmss, locale = Constants.LOCALE_ZH, timezone = Constants.TIMEZONE)
    public Date getLoginTime() {
        return this.loginTime;
    }

    public void setLoginTime(Date loginTime) {
        this.loginTime = loginTime;
    }

    @Column(name = "LOGIN_IP", length = 255)
    public String getLoginIp() {
        return this.loginIp;
    }

    public void setLoginIp(String loginIp) {
        this.loginIp = loginIp;
    }

    @Column(name = "REMARK", length = 255)
    public String getRemark() {
        return remark;
    }

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

    @Transient
    public String getLoginName() {
        return user == null ? null : user.getName();
    }
}