package com.tmerclub.cloud.multishop.listener;

import com.tmerclub.cloud.common.rocketmq.config.RocketMqConstant;
import com.tmerclub.cloud.common.util.Json;
import com.tmerclub.cloud.multishop.mongo.MongoShopWalletLogBO;
import com.tmerclub.cloud.multishop.service.ShopWalletLogService;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 添加店铺钱包日志至MongoDB
 * @author 菠萝凤梨
 */
@Component
@RocketMQMessageListener(topic = RocketMqConstant.ADD_SHOP_WALLET_LOG_TOPIC, consumerGroup = RocketMqConstant.ADD_SHOP_WALLET_LOG_TOPIC)
public class AddShopWalletLogConsumer implements RocketMQListener<List<MongoShopWalletLogBO>> {
    private static final Logger LOG = LoggerFactory.getLogger(AddShopWalletLogConsumer.class);

    @Autowired
    private ShopWalletLogService shopWalletLogService;

    @Override
    public void onMessage(List<MongoShopWalletLogBO> message) {
        LOG.info("通知添加店铺钱包日志至MongoDB开始... message: {}", Json.toJsonString(message));
        shopWalletLogService.saveMongoBatch(message);
        LOG.info("添加店铺钱包日志结束");
    }
}
