package com.cirle.scientific.dao;

import com.cirle.scientific.po.QkjVedioPlayRecordLog;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.List;

public interface QkjVedioPlayRecordLogDao extends PagingAndSortingRepository<QkjVedioPlayRecordLog, Long>, JpaSpecificationExecutor<QkjVedioPlayRecordLog> {

    @Query(value = "select * from qkj_video_play_record_log where mem_card = ?1 limit ?2,?3",nativeQuery = true)
    List<QkjVedioPlayRecordLog> findUserStudyRecord(String memCard, int i, Integer size);


    @Query(value = "select l.* from qkj_video_play_record_log l where l.mem_card =?1 and l.obj_type=?2 and l.obj_id=?3 order by l.opr_time desc limit 0,1",nativeQuery = true)
    QkjVedioPlayRecordLog findMaxEndPlayTime(String memCard, Integer objType, Integer objId);

    @Query(value = "select * from qkj_video_play_record_log l where l.mem_card =?1 and l.obj_type=?2 and l.obj_id=?3 and look_up = ?4",nativeQuery = true)
    List<QkjVedioPlayRecordLog> findAllByMemCardAndObjIdAndObjTypeAndObjType(String memCard, Integer objType, Integer objId ,Integer lookUp);

    @Query(value = "select learn_time from qkj_video_play_record_log l where l.mem_card =?1 and l.obj_type=?2 and l.obj_id=?3 and look_up = ?4",nativeQuery = true)
    List<Integer> findCountPlayTime(String memCard, Integer objType, Integer objId ,Integer lookUp);

    @Query(value = "SELECT * FROM qkj_video_play_record_log WHERE mem_card =?1 and obj_type = ?2 and obj_id = ?3 order by opr_time asc " , nativeQuery = true)
    List<QkjVedioPlayRecordLog> listPlayRecordLog(String memCard, Integer objType, long objId);
}
