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

import cn.com.qmth.stmms.ms.core.domain.InspectTask;
import cn.com.qmth.stmms.ms.core.domain.Paper;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import java.math.BigInteger;
import java.util.List;

/**
 * Created by yuanpan on 2017/11/20.
 */
@Repository
public interface InspectTaskRepo extends CrudRepository<InspectTask, Long>, JpaSpecificationExecutor<InspectTask> {

    int countByWorkIdAndInspectRangeId(Long workId, Long inspectRangeId);

    int countByMarkerId(Long markerId);

    List<InspectTask> findByMarkerIdAndInspectRangeId(Long markerId, Long inspectRangeId);

    List<InspectTask> findByInspectRangeId(Long inspectRangeId);

    List<InspectTask> findByPaperId(Long paperId);

    List<InspectTask> findByPaperIdAndInspectRangeId(Long paperId, Long inspectRangeId);

    @Query(value = "select t.paper_id from inspect_task t where t.inspect_range_id = ?1 group by t.paper_id", nativeQuery = true)
    List<BigInteger> findPaperIdsByInspectRangeId(Long inspectRangeId);
}
