package com.ssj.dao.conch.schoolmaster.dao;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import com.ssj.bean.weixin.libmy.domain.TbLibManager;


@Repository
public interface ISchoolDao  extends JpaRepository<TbLibManager, String> {

    @Query(nativeQuery = true, value = "select * from tb_lib_manager where type=?2 and user_id = ?1 and state = 1")
    public List<TbLibManager> findByUserIdAndType(String userId, int type);

    public int countUserIdByLibIdAndType(String libId, int type);

    public int countUserIdByTypeAndLibIdInAndState(int type, String[] libIds,int state);

    public int countDistinctByMasterIdAndTypeAndState(String masterId, int type,int state);

    public Page<TbLibManager> findAll (Specification<TbLibManager> specification, Pageable page);

    public List<TbLibManager> findByLibIdAndType(String libId, int type);

    @Query(nativeQuery = true, value = "select * from tb_lib_manager where type=?1 and master_id is not null and state = 1")
    public List<TbLibManager> find121TeacherList(int type);
    @Query(nativeQuery = true, value = "select DISTINCT * from tb_lib_manager where type=?1 and course_name=?2 and grade REGEXP ?3 and state = 1 " +
            " order by praise desc, course_count desc, school_age desc, student_count desc")
    public List<TbLibManager> find121TeacherListBySubject(int type, String subject, String grade);
    
    @Query(nativeQuery = true, value = "select DISTINCT * from tb_lib_manager where type=?1 and course_name REGEXP ?2 and grade REGEXP ?3  and state = 1 " +
            " and teacher_lever REGEXP ?4 order by praise desc, course_count desc, school_age desc, student_count desc")
    public List<TbLibManager> find121TeacherListBySubjectAndLever(int type, String subject, String grade,String teacherLever);

    @Query(nativeQuery = true, value = "select DISTINCT * from tb_lib_manager where type=?1 and grade REGEXP ?2  and state = 1 " +
            " and teacher_lever REGEXP ?3 order by praise desc, course_count desc, school_age desc, student_count desc")
    public List<TbLibManager> find121TeacherListByLever(int type, String grade,String teacherLever);
}
