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

import cn.com.qmth.stmms.biz.mark.model.MarkSpecialTag;
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 java.util.List;

public interface MarkSpecialTagDao extends PagingAndSortingRepository<MarkSpecialTag, Integer>,
        JpaSpecificationExecutor<MarkSpecialTag> {

    @Modifying(clearAutomatically = true)
    @Query("delete from MarkSpecialTag s where s.libraryId = ?1")
    public void deleteByLibraryId(Integer libraryId);

    @Modifying(clearAutomatically = true)
    @Query("delete from MarkSpecialTag s where exists "
            + "(select l.id from MarkLibrary l where l.studentId=?1 and s.libraryId=l.id)")
    public void deleteByStudentId(Integer studentId);

    public List<MarkSpecialTag> findByLibraryIdOrderByIdAsc(Integer libraryId);

    // @Modifying(clearAutomatically = true)
    // @Query("delete from MarkSpecialTag s where s.libraryId in (select m.id from MarkLibrary m where m.markerId=?1  and m.status!=?2 and m.status not in (?3) ) ")
    // public void deleteByMarkerId(Integer markerId, LibraryStatus arbitrated,
    // LibraryStatus... waitArbitrate);

    @Modifying(clearAutomatically = true)
    @Query("delete from MarkSpecialTag s where s.libraryId in (select m.id from MarkLibrary m where m.examId=?1 and m.subjectCode=?2 and m.groupNumber=?3)")
    public void deleteByExamAndSubjectAndGroup(Integer examId, String subjectCode, Integer groupNumber);

}
