package com.ywt.outpatient.domain.entity.center;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;

public interface WithdrawOrderRepository extends JpaRepository<WithdrawOrder, Integer> {

    @Query(value = "SELECT * FROM withdraw_order WHERE order_no = ? LIMIT 1", nativeQuery = true)
    WithdrawOrder findByOrderNo(String orderNo);

    @Query(value = "SELECT count(1) FROM withdraw_order WHERE user_id = ? and create_time >= ? and status = 1;", nativeQuery = true)
    int checkCount(int userId, Date date);

    @Query(value = "SELECT ifnull(sum(amount), 0) FROM withdraw_order WHERE user_id = ? and create_time >= ? and status = 1;", nativeQuery = true)
    int hasWithdrawAmount(int userId, Date date);
}
