package com.izouma.nineth.repo;

import com.izouma.nineth.domain.WithdrawApply;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.math.BigDecimal;
import java.util.Optional;

public interface WithdrawApplyRepo  extends JpaRepository<WithdrawApply, Long>, JpaSpecificationExecutor<WithdrawApply> {

    /**
     * 计数
     * @param orderNo
     * @return
     */
    Integer countByOrderNo(String orderNo);

    Optional<WithdrawApply> findByOrderNo(String orderNo);

    @Query(nativeQuery = true ,value = "select sum(order_amount) from withdraw_apply wa where date(wa.created_at) = date_sub(curdate(),interval 1 day) and wa.status  = 'SUCCESS'")
    BigDecimal lastDayWithdrawNum();
}
