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

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

/**
 * (OrderPayment)表Repository类
 *
 * @author johnson lin
 * @since 2019-05-13 17:49:08
 */
public interface OrderPaymentRepository extends JpaRepository<OrderPayment, Integer> {

    /**
     * 根据orderId获取订单支付信息
     *
     * @param orderId       订单id
     * @param paymentStatus 支付状态 {@link com.ywt.taihe.rpc.domain.enums.PaymentStatus}
     * @return {@link OrderPayment}
     */
    @Query(value = "select * from order_payment where order_id = ? and payment_status = ? and deleted = 0 order by create_time desc limit 1;", nativeQuery = true)
    OrderPayment getFirstByOrderIdAndPaymentStatusAndDeletedFalseOrderByCreateTimeDesc(int orderId, int paymentStatus);

    @Query(value = "select * from order_payment where order_no = ? and deleted = 0 and payment_status = 2  order by create_time desc limit 1", nativeQuery = true)
    OrderPayment getOrderPaymentByOrderNo(String orderNo);
}