package com.uas.platform.b2b.model;

import com.uas.platform.b2b.support.SystemSession;
import com.uas.platform.core.model.Constant;
import com.uas.platform.core.model.Status;

import javax.persistence.*;
import java.io.Serializable;

/**
 * 日志详情，记录一些不需要一直展示的数据
 *
 * Created by hejq on 2018-06-22.
 */
@Entity
@Table(name = "log$error$detail")
public class ErrorLogDetail implements Serializable {

    /**
     * default serialVersionUID
     */
    private static final long serialVersionUID = 1L;

    /**
     * id
     */
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "log_id")
    private Long id;

    /**
     * 用户UU
     */
    @Column(name = "log_useruu")
    private Long userUU = 0L;

    /**
     * 用户姓名
     */
    @Column(name = "log_username")
    private String userName = "";

    /**
     * ip地址
     */
    @Column(name = "log_ip")
    private String ip = "";

    /**
     * 是否需要阅读
     * <pre>
     *     1: 是
     *     0: 否
     * </pre>
     */
    @Column(name = "log_needread")
    private Short needRead = Constant.NO;

    /**
     * 请求参数
     */
    @Lob
    @Column(name = "log_parameters")
    private String parameters;

    /**
     * 加密信息
     */
    @Column(name = "log_access")
    private String access;

    /**
     * 处理状态
     * <pre>
     *     210: 未阅读
     *     211: 已阅读
     * </pre>
     */
    @Column(name = "log_status")
    private Integer status = Status.NOT_READ.value();

    /**
     * ErrorLog ID
     */
    @Column(name = "log_logid")
    private Long logId;

    public Long getId() {
        return id;
    }

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

    public Long getUserUU() {
        return userUU;
    }

    public void setUserUU(Long userUU) {
        this.userUU = userUU;
    }

    public String getUserName() {
        return userName;
    }

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

    public String getIp() {
        return ip;
    }

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

    public Short getNeedRead() {
        return needRead;
    }

    public void setNeedRead(Short needRead) {
        this.needRead = needRead;
    }

    public String getParameters() {
        return parameters;
    }

    public void setParameters(String parameters) {
        this.parameters = parameters;
    }

    public String getAccess() {
        return access;
    }

    public void setAccess(String access) {
        this.access = access;
    }

    public Integer getStatus() {
        return status;
    }

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

    public Long getLogId() {
        return logId;
    }

    public void setLogId(Long logId) {
        this.logId = logId;
    }

    public ErrorLogDetail() {}

    /**
     * 封装错误日志详情
     *
     * @param logId
     * @param ip
     * @param needRead
     */
    public ErrorLogDetail(Long logId, String ip, Short needRead, String parameter, String access) {
        this.logId = logId;
        this.ip = ip;
        this.needRead = needRead;
        this.parameters = parameter;
        this.access = access;
        User user = SystemSession.getUser();
        if (null != user) {
            this.userUU = user.getUserUU();
            this.userName = user.getUserName();
        }
    }
}
