package com.qmth.qrzk.dao.repositories;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import com.qmth.qrzk.paper.model.Paper;

/**
 * 试卷
 * @author zhengmin
 *
 */
public interface PaperRepo extends JpaRepository<Paper, Long> {

	/**
	 * 查询状态不为启用，且没有供卷过的试卷
	 * @param courseCode 课程代码
	 * @return
	 */
	@Query("select p from Paper p where p.courseCode = ?2 and p.status != 'ENABLED' and not exists (select sc.paperId from SupplyCourse sc where sc.paperId = p.id and sc.batchId != ?1) and exists (select psw.paperId from PaperStateView psw where psw.paperId=p.id and psw.isStorageScanned = true)")
	//@Query("select p from Paper p where p.courseCode = ?1 and p.status != 'ENABLED'")
	List<Paper> findSupplyCoursePaper(Integer batchId, String courseCode);
	
	@Query("select p from Paper p where p.courseCode=?1")
	List<Paper> findByCourseCode(String courseCode);
	
	@Query("select p from Paper p where p.id in (select s.paperId from SupplyCourse s where s.batchId=?1)")
	List<Paper> findBySupplyBatchId(Integer batchId);
}
