package com.ywt.mg.domain.entities;

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

public interface OrderPaymentRepository extends JpaRepository<OrderPayment, Integer> {

    /**
     * 根据订单流水号得到最新的商户流水号对象
     *
     * @param orderNo
     * @return
     */
    @Query(value = "select * from order_payment where order_no = ? order by id desc limit 1;", nativeQuery = true)
    OrderPayment getOrderPaymentByOrderNo(String orderNo);

    // 本来想去搜索 alipay_trade_no 字段，后面发现 alipay_trade_no 字段里面的值（如果有的话）和 payment_no 的值一样，故进行替换
    // @Query(value = "select * from order_payment where (transaction_id = ? or alipay_trade_no = ?) order by id desc limit 1;", nativeQuery = true)
    @Query(value = "select * from order_payment where (transaction_id = ? or payment_no = ?) order by id desc limit 1;", nativeQuery = true)
    OrderPayment getOrderPaymentByTransactionId(String transactionId, String paymentNo);
}
