package cn.com.qmth.stmms.ms.core.repository;

import cn.com.qmth.stmms.ms.core.domain.MarkTaskJob;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Description: 定时任务调度 repo
 * @Param:
 * @return:
 * @Author: wangliang
 * @Date: 2020/1/19
 */
@Repository
public interface MarkTaskJobRepo extends JpaRepository<MarkTaskJob, Long>, JpaSpecificationExecutor<MarkTaskJob> {

    /**
     * 根据条件查询数据
     *
     * @param workId
     * @return
     */
    List<MarkTaskJob> findAllByStatusIsFalseAndWorkId(Long workId);

    /**
     * 更新markTaskJob
     *
     * @param id
     * @param version
     * @return
     */
    @Modifying
    @Transactional
    @Query(value = "update mark_task_job set status = true,version = ?2 + 1 where id = ?1 and version = ?2", nativeQuery = true)
    int updateMarkTaskJobByVersion(Long id, Integer version);
}
