package com.tmerclub.cloud.supplier.listener;

import com.tmerclub.cloud.common.rocketmq.config.RocketMqConstant;
import com.tmerclub.cloud.common.util.Json;
import com.tmerclub.cloud.supplier.mongo.MongoSupplierWalletLogBO;
import com.tmerclub.cloud.supplier.service.SupplierWalletLogService;
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_SUPPLIER_WALLET_LOG_TOPIC, consumerGroup = RocketMqConstant.ADD_SUPPLIER_WALLET_LOG_TOPIC)
public class AddSupplierWalletLogConsumer implements RocketMQListener<List<MongoSupplierWalletLogBO>> {
    private static final Logger LOG = LoggerFactory.getLogger(AddSupplierWalletLogConsumer.class);

    @Autowired
    private SupplierWalletLogService supplierWalletLogService;

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