package com.ssj.dao.sys.fx.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.Query;
import org.springframework.stereotype.Repository;

import com.ssj.bean.sys.fx.domain.MerchantMeal;

@Repository
public interface MerchantMealDao extends JpaRepository<MerchantMeal, String> {
	
	public Page<MerchantMeal> findAll(Specification<MerchantMeal> specification, Pageable page);
	
	@Query(nativeQuery = true, value = " SELECT * from fx_merchant_meal t WHERE t.merchant_id=?1 and t.status=1  ORDER BY t.end_sign_time DESC LIMIT 1 ")
	public MerchantMeal getMerchantMealByMaxEndSignTime(String merchantId);
	
	@Query(nativeQuery = true, value = " SELECT * from fx_merchant_meal t WHERE t.merchant_id=?1 and t.status=1 and TO_DAYS(t.sign_time)>=TO_DAYS(NOW()) ORDER BY t.sign_time ASC LIMIT 1 ")
	public MerchantMeal getMerchantMealByCurSignTime(String merchantId);
	
	@Query(nativeQuery = true, value = " SELECT * from fx_merchant_meal t WHERE t.merchant_id=?1 and t.status=1  ORDER BY t.end_sign_time DESC")
	public List<MerchantMeal> findMerchantMealByStatusList(String merchantId);
	
	@Query(nativeQuery = true, value = " SELECT * from fx_merchant_meal t WHERE t.merchant_id=?1 ORDER BY t.create_time DESC,t.end_sign_time DESC")
	public List<MerchantMeal> findMerchantMealAll(String merchantId);
	
	@Query(nativeQuery = true, value = " SELECT * from fx_merchant_meal t WHERE t.merchant_id=?1 AND t.`status`=1 AND TO_DAYS(t.sign_time)<=TO_DAYS(NOW()) AND TO_DAYS(t.end_sign_time)>TO_DAYS(NOW()) ORDER BY t.end_sign_time DESC LIMIT 1")
	public MerchantMeal getMerchantMealByCurTime(String merchantId);
	
	
	
	
}
