package com.reyun.repository;

import com.reyun.model.Notice;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * Created by sunhao on 17/3/1.
 */
@Transactional
public interface NoticeRepository  extends JpaRepository<Notice, Long> {

    @Query(value = "select * from (select * from notice n where n.isdeploy is true and n.deploy_date <= ?1 and end_date > ?1 order by deploy_date desc ) as notice_top " +
            " union select * from (select * from notice n where n.isdeploy is true and n.deploy_date <= ?1 and end_date is null order by deploy_date desc limit 3) as notice_normal "
            , nativeQuery = true)
    List<Notice> listRecentDeployNotice(Date currentDate);


}
