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

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

public interface OrderPaymentRepository extends JpaRepository<OrderPayment, Integer> {
    OrderPayment findByPaymentNo(String paymentNo);

    /**
     * 根据订单流水号得到订单支付记录
     *
     * @param orderNo
     * @return
     */
    @Query(value = "select * from order_payment where order_no = ? and ( is_deleted = 0 or is_deleted is null ) and payment_status = 2  order by create_time desc limit 1", nativeQuery = true)
    OrderPayment getOrderPaymentByOrderNo(String orderNo);

    /**
     * 根据orderId获取订单支付信息
     *
     * @param orderId 订单id
     * @return {@link OrderPayment}
     */
    @Query(value = "select * from order_payment where order_id = ? and deleted = 0 and payment_status = 2  order by create_time desc limit 1", nativeQuery = true)
    OrderPayment getOrderPaymentByOrderId(int orderId);

    /**
     * 根据paymentNo获取订单支付信息
     *
     * @param paymentNo 支付流水号
     * @return
     */
    OrderPayment getFirstByPaymentNo(String paymentNo);

}
