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

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


@Repository
public interface LibUserHistoryDao extends JpaRepository<LibUserHistory, String>{

	
	@Query(nativeQuery = true, value = "SELECT  count(y.id) from  tb_lib_user_history y join  tb_lib_book_detail l\n" +
			"on y.book_detail_id =l.id \n" +
			"join  tb_lib_book_info o on o.id =l.info_id\n" +
			"where  o.isbn13 =?1")
	Integer findUserHistoryIsbn(String isbn13);
	
	@Query(nativeQuery = true, value = "SELECT  count(y.id) from  tb_lib_user_history y join  tb_lib_book_detail l\n" +
			"on y.book_detail_id =l.id \n" +
			"join  tb_lib_book_info o on o.id =l.info_id\n" +
			"where  o.child_theme =?1")
	Integer findUserHistoryChildTheme(String childTheme);

	@Query(nativeQuery = true, value = "SELECT  ifnull(sum(heat),0) as heat from  tb_lib_book_isbn_heat where isbn13=?1 limit 1")
    int findUserIsbnHeat(String isbn13);

	@Query(nativeQuery = true, value = "SELECT count(1) as vipcount from tb_lib_read_vip t left join tb_lib_vip_service t11 on t.id = t11.vip_id  where t11.lib_id=?1 and t11.species='S001' and to_days(t11.start_time)=to_days(now())")
    int findTotayAdd(String libId);
}
