package cn.com.qmth.stmms.biz.mark.dao;

import java.util.List;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import cn.com.qmth.stmms.biz.mark.model.TagInfo;
import cn.com.qmth.stmms.common.enums.TagType;

public interface TagInfoDao extends PagingAndSortingRepository<TagInfo, Integer>, JpaSpecificationExecutor<TagInfo> {

    List<TagInfo> findByLibraryId(Integer libraryId);

    TagInfo findByStudentIdAndType(Integer studentId, TagType type);

    @Modifying
    @Query("delete from TagInfo t where t.libraryId=?1")
    void deleteByLibraryId(Integer libraryId);

    @Modifying
    @Query("delete from TagInfo s where s.libraryId in (select m.id from MarkLibrary m where m.markerId=?1 ) ")
    public void deleteByMarkerId(Integer markerId);

    @Modifying
    @Query("delete from TagInfo s where s.libraryId in (select m.id from MarkLibrary m where m.examId=?1 and m.subjectCode=?2 )")
    public void deleteByExamAndSubject(Integer examId, String subjectCode);

    @Modifying
    @Query("delete from TagInfo t where t.studentId=?1")
    public void deleteByStudentId(Integer studentId);

    @Modifying
    @Query("delete from TagInfo s where s.libraryId in (select m.id from MarkLibrary m where m.examId=?1 )")
    public void deleteByExam(int examId);
}
