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

import com.ssj.bean.weixin.story.bean.StoryTask;
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;


/** 
 * @author  ZhangCaibao 
 * @version 2017年6月12日 下午2:28:43 
 * 类说明 
 */
@Repository
public interface StoryTaskDao extends JpaRepository<StoryTask, String>{

	
	 public Page<StoryTask> findAll(Specification<StoryTask> specification, Pageable page);
	 
	 public StoryTask findByStoryIdAndDaysNum(String storyId ,Integer daysNum);
	 
	 @Query(nativeQuery = true, value = " select *  from  tb_story_task  order by rand() limit 1 ") 
	public StoryTask randStoryTask();
		
	 @Query(nativeQuery = true, value = " select count(1)  from  tb_jxy_read_in  where isbn13 = ?1 and user_id = ?2")
	 public Integer getObjectCount(String isbn13,String userId);
	 
	 @Query(nativeQuery = true, value = " INSERT  into   tb_jxy_read_in ( id,isbn13,user_id,user_img,create_time)\n" +
			 " values(  ?4 ,?1,?2,?3,now() ) ")
	 @Modifying
	 public void insertReadIn(String isbn13,String userId,String userImg,String id );
	 
	 
	 @Query(nativeQuery = true, value = "SELECT  * from tb_story_task where  story_id ='af6d0b2b-3b3d-40ab-b396-2e3b0fab818f' " +
			 "GROUP BY num " +
			 "ORDER BY days_num ")
	 public List<StoryTask> findByStoryTaskId();
	 
}
