package com.ssj.dao.weixin.story.dao;

import java.util.List;

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.story.bean.StoryImg;


/** 
 * @author  ZhangCaibao 
 * @version 2017年6月12日 下午2:52:03 
 * 类说明 
 */
@Repository
public interface StoryImgDao extends JpaRepository<StoryImg, String>{

	 public Page<StoryImg> findAll(Specification<StoryImg> specification, Pageable page);
	
	 @Query(nativeQuery = true, value = "select img  from tb_story_img  where object_id =?1  ")
	 public List<String> getImgList(String objectId);
	 
	 @Query(nativeQuery = true, value = "select count(1)  from tb_story_img  where object_id =?1  ")
	 public Integer countObjectId(String objectId);
	 
	 
	 @Query(nativeQuery = true, value = "update tb_story_img set num = ?2  where id = ?1 ")
	 @Modifying
	 public void updateNum(String id ,Integer num);
	 
	 @Query(nativeQuery = true, value = "select * from  tb_story_img where file_code = ?1 limit1 ")
	 public StoryImg findImgByAnything(String fileCode);

	 @Query(nativeQuery = true, value = "select * from  tb_story_img where object_id = ?1 and num=?2 and stat=1 order by create_time desc limit 1 ")
	 public StoryImg findImgByIsbn13(String isbn13, Integer picIndex);

	 @Query(nativeQuery = true, value = "update tb_lib_book_base set book_gr =?2 where isbn13 = ?1 ")
	 @Modifying
	 public void updateBase(String isbn13, String fileGr);
	
	 @Query(nativeQuery = true, value = "update tb_lib_book_info set book_gr =?2 where isbn13 = ?1 ")
	 @Modifying
	 public void updateInfo(String isbn13, String fileGr);

	 @Query(nativeQuery = true, value = "update tb_story_img set stat =2 where object_id = ?1 ")
	 @Modifying
	 public void updateImgStat(String isbn13);
}
