package com.tmerclub.cloud.combo.listener;

import com.tmerclub.cloud.api.product.feign.ShopCartFeignClient;
import com.tmerclub.cloud.combo.bo.ComboSpuCountChangeNotifyBO;
import com.tmerclub.cloud.common.rocketmq.config.RocketMqConstant;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author xxw
 * @date 2022/11/30 16:39
 * 套餐修改商品起搭数时异步修改以后购物车商品数量
 */
@Component
@RocketMQMessageListener(topic = RocketMqConstant.COMBO_SPU_COUNT_CHANGE, consumerGroup = RocketMqConstant.COMBO_SPU_COUNT_CHANGE)
public class ComboSpuCountChangeListener implements RocketMQListener<List<ComboSpuCountChangeNotifyBO>> {

    @DubboReference
    private ShopCartFeignClient shopCartFeignClient;

    @Override
    public void onMessage(List<ComboSpuCountChangeNotifyBO> messageList) {
        for (ComboSpuCountChangeNotifyBO message : messageList) {
            shopCartFeignClient.updateCartComboCount(message.getComboId(), message.getSpuId(), message.getCount());
        }
    }
}
