
package com.tmerclub.cloud.combo.listener;

import com.tmerclub.cloud.api.product.feign.ShopCartFeignClient;
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/9/8 15:48
 */
@Component
@RocketMQMessageListener(topic = RocketMqConstant.COMBO_DELETE_OR_DISABLED, consumerGroup = RocketMqConstant.COMBO_DELETE_OR_DISABLED)
public class ComboListener implements RocketMQListener<List<Long>> {

    @DubboReference
    private ShopCartFeignClient shopCartFeignClient;

    /**
     * 失效或者删除套餐时移除购物车商品
     * @param comboIdList
     */
    @Override
    public void onMessage(List<Long> comboIdList) {
        if (comboIdList.size() != 0) {
            shopCartFeignClient.deleteCartByComboUpdate(comboIdList, -1L, -1L);
        }
    }
}
