package com.nokia.tsl_data.entity;

import com.alibaba.fastjson2.JSONObject;
import com.nokia.tsl_data.entity.converter.JSONObjectConverter;

import lombok.Data;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.time.Instant;

@Data
@Entity
@EntityListeners(AuditingEntityListener.class)
@Table(name = "task_record", schema = "tsl_data")
public class TaskRecord {

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

    // 任务名称
    @Column
    private String taskName;

    // 任务执行开始时间
    @Column
    private Instant startTime;

    // 任务执行结束时间
    @Column
    private Instant endTime;

    // 任务结束状态 非0即为失败
    @Column
    private Integer endStatus;

    // 任务耗时
    @Column
    private Long timeCost;

    // 任务详情，采用json字符串记录
    @Column(name = "task_info", columnDefinition = "text")
    @Convert(converter = JSONObjectConverter.class)
    private JSONObject taskInfo;

    @CreatedDate
    private Instant createDate;

    @LastModifiedDate
    private Instant lastUpdateDate;
}
