package com.cirle.scientific.dao;

import com.cirle.scientific.po.QkjCourseWare;
import com.cirle.scientific.po.QkjTqcourse;
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 QkjCourseWareDao extends PagingAndSortingRepository<QkjCourseWare, Long>, JpaSpecificationExecutor<QkjCourseWare> {

    @Query(value = "SELECT a.* FROM qkj_courseware a WHERE a.status=1 and a.is_visiable = 1 order by top_status desc, a.create_time desc limit ?1, ?2",nativeQuery = true)
    List<QkjCourseWare> findList(Integer start, Integer size);

    @Query(value = "select qt.* from qkj_courseware qt " +
                        "inner join qkj_catalogs_detail qcd on qcd.obj_id = qt.id " +
                    "where qcd.catalogs_id in (?1) and qcd.obj_type = 5 and qt.status = 1 and qt.is_visiable = 1 order by qt.top_status desc, qt.create_time desc limit ?2,?3",nativeQuery = true)
    List<QkjCourseWare> findList(String cataIds, Integer start, Integer size);


    @Query(value = "SELECT  count(*)  FROM qkj_courseware  WHERE status=1  and is_visiable = 1 ",nativeQuery = true)
    Integer findListCount();

    @Query(value = "select count(*)  from qkj_courseware qt " +
            "inner join qkj_catalogs_detail qcd on qcd.obj_id = qt.id " +
            "where qcd.catalogs_id in (?1) and qcd.obj_type = 5 and qt.status = 1 and qt.is_visiable = 1 ",nativeQuery = true)
    Integer findListCount(String cataIds);

    @Query(value = "select DISTINCT qt.* from qkj_courseware qt inner join qkj_catalogs_detail qcd on qcd.obj_id = qt.id where qcd.catalogs_id = ?1 and qcd.obj_type = 5 and qt.status = 1 and qt.is_visiable = 1 ", nativeQuery = true)
    List<QkjCourseWare> getByCataIds(Integer intValue);

    @Query(value = "SELECT a.* FROM qkj_courseware a WHERE a.uploader= ?1 and  a.status=1 and a.is_visiable in(0 ,1 , 2) order by top_status desc, a.create_time desc limit ?2, ?3",nativeQuery = true)
    List<QkjCourseWare> findListByMember(String memCard,Integer start, Integer size);

    @Query(value = "SELECT * FROM qkj_courseware  WHERE id = ?1",nativeQuery = true)
    QkjCourseWare getQkjCourseWare(Long id);

    @Query(value = "SELECT  count(*)  FROM qkj_courseware  WHERE status=1  and is_visiable = 2 and uploader = ?1 ",nativeQuery = true)
    Integer findListCountPpt(String memCard);


    @Query(value = "SELECT * FROM qkj_courseware  WHERE id in (?1) ",nativeQuery = true)
    List<QkjCourseWare> listQkjCourseWare(List<Integer> ids);
}
