package com.izouma.nineth.repo;

import com.izouma.nineth.domain.RechargeOrder;
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 RechargeOrderRepo extends JpaRepository<RechargeOrder, Long>, JpaSpecificationExecutor<RechargeOrder> {

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

    Optional<RechargeOrder> findByOrderNo(String orderNo);

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