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.MerchantMealOrder;

@Repository
public interface MerchantMealOrderDao extends JpaRepository<MerchantMealOrder, String> {
	
	public Page<MerchantMealOrder> findAll(Specification<MerchantMealOrder> specification, Pageable page);
	
	@Query(nativeQuery = true, value = " SELECT * from fx_merchant_meal_order t WHERE t.merchant_id=?1 ORDER BY t.create_time DESC")
	public List<MerchantMealOrder> findMerchantMealOrderAll(String merchantId);
	
	@Query(nativeQuery = true, value = " SELECT * from fx_merchant_meal_order t WHERE t.merchant_id=?1 AND TO_DAYS(t.sign_time)<=TO_DAYS(NOW()) AND TO_DAYS(t.end_sign_time)>TO_DAYS(NOW()) ORDER BY t.create_time DESC LIMIT 1")
	public MerchantMealOrder getMerchantMealOrderByCurTime(String merchantId);
	
	@Query(nativeQuery = true, value = " SELECT * from fx_merchant_meal_order t WHERE t.merchant_id=?1 ORDER BY t.create_time DESC LIMIT 1")
	public MerchantMealOrder getMerchantMealOrderByMaxCreateTime(String merchantId);
	
	
}
