package com.qqchen.deploy.backend.schedule.entity;

import com.qqchen.deploy.backend.framework.annotation.LogicDelete;
import com.qqchen.deploy.backend.framework.domain.Entity;
import com.qqchen.deploy.backend.schedule.enums.JobStatusEnum;
import jakarta.persistence.Column;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalDateTime;

/**
 * 定时任务执行日志
 * 
 * @author qichen
 */
@Data
@EqualsAndHashCode(callSuper = true)
@jakarta.persistence.Entity
@Table(name = "schedule_job_log")
@LogicDelete
public class ScheduleJobLog extends Entity<Long> {

    /**
     * 任务ID
     */
    @Column(name = "job_id", nullable = false)
    private Long jobId;

    /**
     * 任务名称
     */
    @Column(name = "job_name", nullable = false, length = 100)
    private String jobName;

    // ==================== 执行信息 ====================

    /**
     * 执行器Bean名称
     */
    @Column(name = "bean_name", nullable = false, length = 100)
    private String beanName;

    /**
     * 执行方法名称
     */
    @Column(name = "method_name", nullable = false, length = 100)
    private String methodName;

    /**
     * 方法参数
     */
    @Column(name = "method_params", columnDefinition = "TEXT")
    private String methodParams;

    // ==================== 时间统计 ====================

    /**
     * 开始执行时间
     */
    @Column(name = "execute_time", nullable = false)
    private LocalDateTime executeTime;

    /**
     * 完成时间
     */
    @Column(name = "finish_time")
    private LocalDateTime finishTime;

    /**
     * 执行耗时（毫秒）
     */
    @Column(name = "duration")
    private Long duration;

    // ==================== 状态信息 ====================

    /**
     * 执行状态
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "status", nullable = false, length = 20)
    private JobStatusEnum status;

    /**
     * 执行结果消息
     */
    @Column(name = "result_message", columnDefinition = "TEXT")
    private String resultMessage;

    /**
     * 异常堆栈信息
     */
    @Column(name = "exception_info", columnDefinition = "TEXT")
    private String exceptionInfo;

    // ==================== 服务器信息 ====================

    /**
     * 执行服务器IP
     */
    @Column(name = "server_ip", length = 50)
    private String serverIp;

    /**
     * 执行服务器主机名
     */
    @Column(name = "server_host", length = 100)
    private String serverHost;
}

