/**
 * @ProjectName: 智慧评标-主观分助手
 * @Package: com.zhpb.gdyd_zhpb_zgf.entity.mysql
 * @ClassName: SysLog
 * @Description: 系统日志实体类，映射t_sys_log表，记录所有控制台输出和系统日志
 * @Author: 张志锋
 * @Date: 2025-10-31
 * @Version: 1.0
 * @Copyright: © 2025 智慧评标-主观分助手
 */
package com.zhpb.gdyd_zhpb_zgf.entity.mysql;

import jakarta.persistence.*;
import lombok.Data;

import java.time.LocalDateTime;

/**
 * 系统日志实体类
 */
@Entity
@Table(name = "t_sys_log", indexes = {
        @Index(name = "idx_log_level", columnList = "log_level"),
        @Index(name = "idx_create_time", columnList = "create_time"),
        @Index(name = "idx_thread_name", columnList = "thread_name")
})
@Data
public class SysLog {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 日志级别（INFO, DEBUG, WARN, ERROR, OUT等）
     */
    @Column(name = "log_level", length = 20, nullable = false)
    private String logLevel;

    /**
     * 日志来源（logger名称或SYSTEM_OUT）
     */
    @Column(name = "logger_name", length = 255)
    private String loggerName;

    /**
     * 线程名称
     */
    @Column(name = "thread_name", length = 255)
    private String threadName;

    /**
     * 日志内容
     */
    @Column(name = "log_content", columnDefinition = "TEXT", nullable = false)
    private String logContent;

    /**
     * 完整的日志消息（包含格式化信息）
     */
    @Column(name = "full_message", columnDefinition = "TEXT")
    private String fullMessage;

    /**
     * 异常堆栈信息（如果有）
     */
    @Column(name = "exception_stack", columnDefinition = "TEXT")
    private String exceptionStack;

    /**
     * 类名
     */
    @Column(name = "class_name", length = 500)
    private String className;

    /**
     * 方法名
     */
    @Column(name = "method_name", length = 255)
    private String methodName;

    /**
     * 行号
     */
    @Column(name = "line_number")
    private Integer lineNumber;

    /**
     * 创建时间
     */
    @Column(name = "create_time", nullable = false)
    private LocalDateTime createTime;

    /**
     * 应用名称
     */
    @Column(name = "application_name", length = 100)
    private String applicationName;

    /**
     * 用户ID（如果有）
     */
    @Column(name = "user_id", length = 64)
    private String userId;

    /**
     * 请求ID或跟踪ID（如果有）
     */
    @Column(name = "trace_id", length = 64)
    private String traceId;

    @PrePersist
    public void prePersist() {
        if (this.createTime == null) {
            this.createTime = LocalDateTime.now();
        }
    }
}

