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

import com.ssj.bean.weixin.libmy.domain.TbLibBookInfo;
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.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
public interface ILibBookDao extends JpaRepository<TbLibBookInfo, String> {

	@Query(nativeQuery = true, value = "select *  from tb_lib_book_info  where isbn13 = ?1 and lib_id=?2  limit 1")
	TbLibBookInfo findByIsbn13AndLibId(String isbn13, String libId);

	 public Page<TbLibBookInfo> findAll(Specification<TbLibBookInfo> specification, Pageable page);
	 
	 @Query(nativeQuery = true, value = "select *  from tb_lib_book_info  where lib_id = ?1 ")
	 public List<TbLibBookInfo> findByInfoLibId(String libId);

	 @Query(nativeQuery = true, value = "select *  from tb_lib_book_info  where (isbn13 = ?1 or csisbn=?1) and title is not null and title<>'' and local_image is not null and local_image <>''  limit 1")
	 TbLibBookInfo findBookInfoByIsbn(String isbn13);
	 
	 @Query(nativeQuery = true, value = "select *  from tb_lib_book_info  where isbn13 = ?1 limit 1")
	 TbLibBookInfo findByIsbn(String isbn13);

	 @Query(nativeQuery = true, value = "SELECT count(DISTINCT lib_id)  from tb_lib_book_info where isbn13=?1 ")
	 Integer findPlCount(String isbn13);
	 
	 @Query(nativeQuery = true, value = " delete a from tb_lib_book_info a left join tb_lib_book_detail b on a.id = b.info_id where a.lib_id=? and b.id is null ")
	 @Modifying
	 void delNodetailInfoData(String libId);
}
