package com.nokia.tsl_data.dao;

import com.nokia.tsl_data.entity.TaskRecord;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.time.Instant;
import java.util.List;

@Repository
public interface TaskRecordRepository extends JpaRepository<TaskRecord, Long> {

    TaskRecord findFirstByTaskNameAndEndStatusOrderByStartTimeDesc(String taskName, Integer endStatus);

    default Instant findLastSuccessUpdateWorkFlowBasicDataTaskEndInstant() {
        TaskRecord taskRecord = findFirstByTaskNameAndEndStatusOrderByStartTimeDesc("更新工作流数据", 0);
        return taskRecord.getTaskInfo().getInstant("end");
    }

    List<TaskRecord> findTop2ByOrderByStartTimeDesc();
}
