
package com.tmerclub.cloud.payment.listener;

import com.tmerclub.cloud.common.order.bo.PayRefundBO;
import com.tmerclub.cloud.common.rocketmq.config.RocketMqConstant;
import com.tmerclub.cloud.payment.service.RefundInfoService;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 退款的通知的监听
 *
 * @author tmerclub
 */
@Component
@RocketMQMessageListener(topic = RocketMqConstant.ORDER_REFUND_PAYMENT_TOPIC, consumerGroup = RocketMqConstant.ORDER_REFUND_PAYMENT_TOPIC)
public class OrderRefundPaymentConsumer implements RocketMQListener<PayRefundBO> {

    private static final Logger logger = LoggerFactory.getLogger(OrderRefundPaymentConsumer.class);

    @Autowired
    private RefundInfoService refundInfoService;

    /**
     * 订单退款 支付服务，开始进行退款啦
     */
    @Override
    public void onMessage(PayRefundBO payRefundBO) {
        // 打印日志，防止消息丢失
        logger.info("订单退款 开始进行退款啦... OrderRefundPaymentConsumer: {}", payRefundBO);
        refundInfoService.doRefund(payRefundBO);
    }
}
