package com.sysu.admin.support.sms;

import com.xiesx.fastboot.core.jpa.JpaPlusRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.List;

public interface SmsRepository extends JpaPlusRepository<Sms, Long> {

    List<Sms> findByMobile(String mobile);

    @Query(value = "select * from sys_sms where mobile = ?1 and is_use=0  order by create_date desc limit 1", nativeQuery = true)
    Sms lastSend(String mobile);

    @Transactional
    @Modifying
    @Query(value = "update sys_sms set is_use=2 where id = ?1", nativeQuery = true)
    int expire(Long id);
}
