package cn.reghao.bnt.web.admin.model.po;

import cn.reghao.bnt.web.util.BaseEntity;
import cn.reghao.jutil.web.ServletUtil;
import cn.reghao.jutil.jdk.web.log.GatewayLog;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;

/**
 * @author reghao
 * @date 2023-04-19 15:22:44
 */
@NoArgsConstructor
@Setter
@Getter
@Entity
@Table(name = "sys1_access_log")
public class AccessLog extends BaseEntity {
    private String requestId;
    private String requestMethod;
    private String requestUrl;
    private Long requestTime;
    private String host;
    private String referer;
    @Column(columnDefinition="text")
    private String userAgent;
    private Integer statusCode;
    private Long executeTime;
    private String remoteAddr;
    private Integer remotePort;
    private String sessionId;

    public AccessLog(GatewayLog gatewayLog) {
        this.requestId = gatewayLog.getRequestId();
        this.requestMethod = gatewayLog.getRequestMethod();
        this.requestUrl = gatewayLog.getRequestUrl();
        this.requestTime = gatewayLog.getRequestTime();
        this.host = gatewayLog.getRequestHeaders().get("host");
        this.referer = gatewayLog.getRequestHeaders().get("referer");
        this.userAgent = gatewayLog.getRequestHeaders().get("user-agent");
        this.statusCode = gatewayLog.getStatusCode();
        this.executeTime = gatewayLog.getExecuteTime();
        this.remoteAddr = gatewayLog.getRemoteAddr();
        this.remotePort = gatewayLog.getRemotePort();
        //this.sessionId = ServletUtil.getSessionId();
        this.sessionId = "";
    }
}
