package com.tmerclub.cloud.seckill.listener;

import com.tmerclub.cloud.api.seckill.dto.SecKillRefundDTO;
import com.tmerclub.cloud.common.order.bo.RefundReductionStockBO;
import com.tmerclub.cloud.common.rocketmq.config.RocketMqConstant;
import com.tmerclub.cloud.seckill.service.SeckillSkuService;
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;
/**
 * @author lanhai
 */
@Component
@RocketMQMessageListener(topic = RocketMqConstant.SECKILL_ORDER_REFUND_TOPIC, consumerGroup = RocketMqConstant.SECKILL_ORDER_REFUND_TOPIC)
public class SecKillOrderRefundConsumer implements RocketMQListener<SecKillRefundDTO> {

    @Autowired
    private SeckillSkuService seckillSkuService;

    @Override
    public void onMessage(SecKillRefundDTO secKillRefundDTO) {
        // 还原秒杀库存
        for (RefundReductionStockBO stockBO : secKillRefundDTO.getRefundReductionStocks()) {
            seckillSkuService.rollbackSecKillStock(secKillRefundDTO.getActivityId(), stockBO.getSkuId(), stockBO.getCount(), 0L,secKillRefundDTO.getUserId(), stockBO.getStockPointId());
        }
    }
}
