package com.jeequan.jeepay.pay.mq;

import com.jeequan.jeepay.components.mq.model.PayOrderCashoutMQ;
import com.jeequan.jeepay.pay.service.MchChannelCashoutService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 接收MQ消息
 * 业务： 订单支付成功自动提现通知
 * @author zx
 * @date 2021/7/27 9:23
 */
@Slf4j
@Component
public class PayOrderCashoutMQReceiver implements PayOrderCashoutMQ.IMQReceiver {

    @Autowired private MchChannelCashoutService mchChannelCashoutService;

    @Override
    public void receive(PayOrderCashoutMQ.MsgPayload payload) {

        try {
            log.info("接收商户通知MQ, msg={}", payload.toString());

            String payOrderId = payload.getPayOrderId();

            // 发起提现
            mchChannelCashoutService.cashout(payOrderId);

        }catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
}
