
package com.tmerclub.cloud.order.listener;

import com.tmerclub.cloud.common.order.bo.RefundNotifyBO;
import com.tmerclub.cloud.common.rocketmq.config.RocketMqConstant;
import com.tmerclub.cloud.order.service.OrderRefundService;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * @author tmerclub
 * @date 2021/1/7
 */
@Component
@RocketMQMessageListener(topic = RocketMqConstant.ORDER_REFUND_SUCCESS_TOPIC, consumerGroup = RocketMqConstant.ORDER_REFUND_SUCCESS_TOPIC)
public class OrderRefundSuccessConsumer implements RocketMQListener<RefundNotifyBO> {

    @Autowired
    private OrderRefundService orderRefundService;

    @Override
    public void onMessage(RefundNotifyBO refundNotifyBO) {
        // 因为未成团进行团购订单的退款
        if (Objects.equals(refundNotifyBO.getUnSuccessGroupOrder(), 1)) {
            // 创建退款订单然后再退款
            orderRefundService.createGroupUnSuccessRefundInfo(refundNotifyBO);
        } else {
            // 退款
            orderRefundService.refundSuccess(refundNotifyBO);
        }
    }
}
