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

import cn.com.qmth.stmms.ms.core.domain.ExamQuestion;
import cn.com.qmth.stmms.ms.core.vo.Subject;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * Created by zhengmin on 2016/10/9.
 */
public interface ExamQuestionRepo extends JpaRepository<ExamQuestion, Long> {

    List<ExamQuestion> findByWorkIdAndSubject(Long workId, Subject subject);

    @Query("select count(distinct s.areaCode) from ExamQuestion s where s.workId = ?1 and s.test = ?2")
    long countByWorkIdAndTest(Long workId, int test);

    long countByWorkIdAndAreaCode(Long workId, String areaCode);

    List<ExamQuestion> findByWorkIdAndAreaCode(Long workId, String areaCode);

    ExamQuestion findByWorkIdAndSubjectAndAreaCode(Long workId,
                                                   Subject subject, String areaCode);

    ExamQuestion findByWorkIdAndSubjectAndAreaCodeAndTest(Long workId,
                                                          Subject subject, String areaCode, int test);

    void deleteByWorkId(Long workId);

    void deleteByWorkIdAndSubjectAndTest(Long workId, Subject subject, int test);

    List<ExamQuestion> findAllByAreaCodeAndSubjectAndWorkId(String areaCode, Subject subject, Long workId);

    List<ExamQuestion> findByWorkIdAndSubjectAndTest(Long workId, Subject subject, int test);

    @Query("select distinct s.areaCode, s.areaName from ExamQuestion s where s.workId = ?1")
    List<Object[]> findByWorkId(Long workId);

    List<ExamQuestion> findByWorkIdAndSubjectAndTestNot(Long workId, Subject subject, int id);
}
