package co.yixiang.yshop.module.order.mq.consumer;

import co.yixiang.yshop.framework.mq.core.stream.AbstractStreamMessageListener;
import co.yixiang.yshop.module.order.service.storeorder.AppStoreOrderService;
import co.yixiang.yshop.module.pay.mq.message.PayRefundMessage;
import co.yixiang.yshop.module.product.enums.product.StockBackTypeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 消息队列处理支付退款
 */
@Component
@Slf4j
public class PayRefundConsumer extends AbstractStreamMessageListener<PayRefundMessage> {

    @Resource
    private AppStoreOrderService appStoreOrderService;

    @Override
    public void onMessage(PayRefundMessage message) {
        log.info("[onMessage][支付退款处理消息内容({})]", message);
        try {
            appStoreOrderService.batchRefund(message.getIds(), StockBackTypeEnum.NORMAL.getValue());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        log.info("支付退款消息处理完毕【{}】", message.getIds());
    }
}
