
package com.tmerclub.cloud.combo.listener;

import com.tmerclub.cloud.api.product.feign.ShopCartFeignClient;
import com.tmerclub.cloud.combo.bo.ComboSkuStatusChangeNotifyBO;
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/8/30 13:36
 * 套餐商品sku项状态变为删除或者失效时移除用户购物车商品
 */
@Component
@RocketMQMessageListener(topic = RocketMqConstant.COMBO_SKU_STATUS_TOPIC, consumerGroup = RocketMqConstant.COMBO_SKU_STATUS_TOPIC)
public class ComboSpuSkuListener implements RocketMQListener<ComboSkuStatusChangeNotifyBO> {
    @DubboReference
    private ShopCartFeignClient shopCartFeignClient;

    @Override
    public void onMessage(ComboSkuStatusChangeNotifyBO comboSkuStatusChangeNotifyBO) {
        Long comboId = comboSkuStatusChangeNotifyBO.getComboId();
        List<Long> skuList = comboSkuStatusChangeNotifyBO.getSkuList();
        if (skuList.size() != 0) {
            shopCartFeignClient.deleteCartByComboIdAndSkuIdS(comboId, skuList);
        }
    }
}
