package com.ssj.dao.weixin.sales.dao;

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 com.ssj.bean.weixin.sales.domain.LibBorrowedService;


/** 
 * @author  ZhangCaibao 
 * @version 2017年6月22日 下午2:56:34 
 * 类说明 
 */
@Repository
public interface LibBorrowedServiceDao extends JpaRepository<LibBorrowedService, String>{

	 public Page<LibBorrowedService> findAll(Specification<LibBorrowedService> specification, Pageable page);
	 
	 @Query(nativeQuery = true, value = "INSERT  into   tb_lib_borrowed_service ( id,species,type,create_time,lib_id ,deposit,borrow_num,borrow_day,out_money ) \n" +
			 "			 SELECT  ?3,species,type,now(),?1 ,deposit,borrow_num,borrow_day,out_money  from  tb_lib_borrowed_service where lib_id =?2")
	 @Modifying
	 public void insertBorrowedService(String libId, String addType,String id);
	 
	 @Query(nativeQuery = true, value = " select count(1) from   tb_lib_borrowed_service  where lib_id = ?1  ")
	 public Integer getLibCount(String libId);
	 
	 @Query(nativeQuery = true, value = " select * from   tb_lib_borrowed_service  where lib_id = ?1  and   species =?2  and type =?3  LIMIT 1 ")
	 public LibBorrowedService findByLibIdAndSpeciesAndType(String libId,String species,String type);
}
