
package com.tmerclub.cloud.user.listener;

import cn.hutool.core.collection.CollUtil;
import com.tmerclub.cloud.common.rocketmq.config.RocketMqConstant;
import com.tmerclub.cloud.user.bo.mongo.MongoUserScoreLogBO;
import com.tmerclub.cloud.user.service.UserScoreLogService;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author TRACK
 */
@Component
@RocketMQMessageListener(topic = RocketMqConstant.ADD_USER_SCORE_LOG_TOPIC, consumerGroup = RocketMqConstant.ADD_USER_SCORE_LOG_TOPIC)
public class AddUserScoreLogConsumer implements RocketMQListener<List<MongoUserScoreLogBO>> {

    @Autowired
    private UserScoreLogService userScoreLogService;

    @Override
    public void onMessage(List<MongoUserScoreLogBO> list) {
        if (CollUtil.isEmpty(list)) {
            return;
        }
        userScoreLogService.saveBatchToMongodb(list);
    }

}
