package com.ssj.dao.weixin.library.dao;

import com.ssj.bean.weixin.libmy.domain.LibVipBook;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface LibVipBookDao extends JpaRepository<LibVipBook, String>{

    /**
     * 统计学生添加的教辅数量
     * @param vipId 学生id
     */
    Integer countByVipId(String vipId);

    /**
     * 删除学生的所有教辅
     * @param vipId 学生id
     */
    @Modifying
    @Query(nativeQuery = true, value = "delete from tb_lib_vip_book where vip_id = ?1")
    void deleteByVipId(String vipId);

    /**
     * 查询数据库中已有的学生添加的教辅
     * @param vipId
     * @param subject
     * @return
     */
    @Query(nativeQuery = true, value = "select * from tb_lib_vip_book where vip_id=?1 and subject=?2 and book_id is not null")
    List<LibVipBook> findVipBookByVipIdAndSubject(String vipId, String subject);

}
