package com.bizzan.bitrade.dao;

import org.springframework.data.jpa.repository.Query;

import com.bizzan.bitrade.dao.base.BaseDao;
import com.bizzan.bitrade.entity.Announcement;

/**
 * @author
 * @description
 * @date 2019/3/5 15:32
 */
public interface AnnouncementDao extends BaseDao<Announcement> {

    @Query("select max(s.sort) from Announcement s")
    int findMaxSort();

    @Query(value = "select * from announcement where announcement_classification=7 and is_show=1 and (publish_time <= now() or publish_time is null) ORDER by id desc limit 0,1", nativeQuery = true)
    Announcement findByContract();

    @Query(value = "select * from announcement where announcement_classification=:classification and is_show=1 and (publish_time <= now() or publish_time is null) ORDER by id desc limit 0,1", nativeQuery = true)
    Announcement findByClassification(int classification);

    @Query(value = "select * from announcement where id<:annId AND is_show=1 AND (publish_time <= now() or publish_time is null) ORDER by id desc limit 0,1", nativeQuery = true)
    Announcement getBack(long annId);

    @Query(value = "select * from announcement where id>:annId AND is_show=1 AND (publish_time <= now() or publish_time is null) limit 0,1", nativeQuery = true)
    Announcement getNext(long annId);
}
