package com.ssj.dao.sys.usercenter.dao;

import com.ssj.bean.sys.usercenter.domain.StudentCenter;
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 java.util.List;

/**
 * @author Mount Liu
 * @date 2018/9/20
 */
@Repository
public interface StudentCenterDao extends JpaRepository<StudentCenter, String> {

    /**
     * 分页查询列表
     * @param specification
     * @param page
     * @return
     */
    Page<StudentCenter> findAll(Specification<StudentCenter> specification, Pageable page);

    /**
     * 根据校长的userId查询名下的学生
     * @param schoolmasterUserId 校长的userId
     */
    @Query(nativeQuery = true,
            value = "select distinct ssj_student_v.* from ssj_student_v, tb_lib_vip_bind where ssj_student_v.parent_id = tb_lib_vip_bind.user_id and tb_lib_vip_bind.master_id = ?1")
    List<StudentCenter> findBySchoolmasterUserId(String schoolmasterUserId);

    /**
     * 根据家长的userId查询孩子列表
     * @param parentUserId 家长的userId
     */
    List<StudentCenter> findByParentId(String parentUserId);
}
