package cn.lihongjie.coal.loginUserHis.entity;

import cn.lihongjie.coal.base.entity.CommonEntity;
import cn.lihongjie.coal.user.entity.UserEntity;

import jakarta.persistence.Entity;
import jakarta.persistence.ManyToOne;

import lombok.Data;

import org.hibernate.annotations.Comment;
import org.hibernate.annotations.Formula;

import java.time.LocalDateTime;

@Data
@Entity
public class LoginUserHisEntity extends CommonEntity {



    @ManyToOne
    private UserEntity user;



    private String loginType;
    private String phone;
    private String userName;
    private String ip;
    private String location;
    private String ua;
    private String captcha;

    @Comment("登录状态")
    private String loginStatus;


    @Formula(
            "(select i.name\n"
            + "from t_dictionary d,\n"
            + "     t_dictionary_item i\n"
            + "where d.id = i.dictionary_id\n"
            + "  and d.code = 'loginUserHis.loginStatus'\n"
            + "  and i.code = login_status)")
    private String loginStatusName;

    @Comment("session id")
    private String sessionId;

    @Comment("登录时间")
    private LocalDateTime loginTime;

    @Comment("登出时间")
    private LocalDateTime logoutTime;

    @Comment("登出类型")
    private String logoutType;


    @Formula(
            "(select i.name\n"
            + "from t_dictionary d,\n"
            + "     t_dictionary_item i\n"
            + "where d.id = i.dictionary_id\n"
            + "  and d.code = 'loginUserHis.logoutType'\n"
            + "  and i.code = logout_type)")
    private String logoutTypeName;





}
