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

import com.ssj.bean.weixin.story.bean.Story;
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 StoryDao  extends JpaRepository<Story, String>{
	
	 public Page<Story> findAll(Specification<Story> specification, Pageable page);
	 
	 @Query(nativeQuery = true, value =" SELECT   *  from  tb_story  where  TO_DAYS(create_time) < TO_DAYS(NOW())  \n" +
			 "AND DATEDIFF(create_time, NOW()) < 1 \n" +
			 "ORDER BY   create_time desc  LIMIT  1 ")
	 public  Story  getRecentStroy();
	 
	 @Query(nativeQuery = true, value =" SELECT   *  from  tb_story  where   type = 2 order by  start_time  desc  LIMIT  1 ")
	 public Story  getEqStroy();
	 @Query(nativeQuery = true, value =" SELECT   *  from  tb_story  where   type = ?1   ")
	 public List<Story> findByType(Integer type);
	 
	 
	  @Query(nativeQuery = true, value = "update tb_story set type = ?2   where id =?1 ")
	  @Modifying
	  public Integer updateType(String id,Integer type);
	  
	  
	  @Query(nativeQuery = true, value ="  SELECT   *  from  tb_story  where  TO_DAYS(start_time) <=TO_DAYS(now()) and   TO_DAYS(end_time) >=TO_DAYS(now()) ")
	  public List<Story> punchTimeStory();

}
