package com.ssj.dao.kmt.kmt.dao;

import com.ssj.bean.kmt.kmt.domain.KmtExerciseBookTeacherRecord;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author: chchen
 * @Description
 * @Date Create in 10:52 2020/5/21
 * @Modified By
 */
@Repository
public interface KmtExerciseTeacherRecordDao extends JpaRepository<KmtExerciseBookTeacherRecord, String> {

    /**
     * 查询最新的分配记录
     * @param exerciseBookId
     * @param type
     * @return
     */
    @Query(nativeQuery = true, value = "select * from kmt_exercise_book_teacher_record where exercise_book_id =?1 and authority_type =?2 " +
            " order by create_time desc limit 1")
    KmtExerciseBookTeacherRecord findByExerciseBookIdAndAuthorityType (String exerciseBookId, int type);

    /**
     * 查询最新的分配记录
     *
     * @param exerciseBookId 练习册id
     *
     * @param lastFlag 是否最新
     * @return 分配记录list
     */
    List<KmtExerciseBookTeacherRecord> findByExerciseBookIdAndLastFlag(String exerciseBookId, int lastFlag);
}
