package com.lanyuanxiaoyao.leopard.core.repository;

import com.lanyuanxiaoyao.leopard.core.entity.Task;
import com.lanyuanxiaoyao.service.template.repository.SimpleRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

/**
 * @author lanyuanxiaoyao
 * @version 20250829
 */
@Repository
public interface TaskRepository extends SimpleRepository<Task> {
  @Modifying
  @Query("update Task task set task.status = com.lanyuanxiaoyao.leopard.core.entity.Task.Status.FAILURE where task.status = com.lanyuanxiaoyao.leopard.core.entity.Task.Status.RUNNING")
  void updateAllRunningTaskToFailure();

  @Modifying
  @Query("update Task task set task.step = ?1 where task.id = ?2")
  void updateStepById(Integer step, Long id);
}
