package com.yihu.jw.sms.dao;

import com.yihu.jw.entity.base.sms.SmsDO;
import com.yihu.jw.entity.base.sms.SmsTemplateDO;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.Date;

/**
 * Dao - 短信记录
 * Created by progr1mmer on 2018/8/23.
 */
public interface BaseSmsDao extends PagingAndSortingRepository<SmsDO, String>, JpaSpecificationExecutor<SmsDO> {

    boolean existsByCaptchaAndDeadlineAfter(String captcha, Date now);

    @Query("select a from SmsDO a where a.mobile = ?1  and a.type = ?2")
    Page<SmsDO> findByCaptcha(String mobile, SmsTemplateDO.Type type, Pageable pageRequest);
}
