package com.apobates.forum.core.impl.event.listener;

import com.apobates.forum.core.dao.BoardStatsDao;
import com.apobates.forum.core.entity.Board;
import com.apobates.forum.core.impl.event.BoardCreateEvent;
import com.github.davidmarquis.redisq.Message;
import com.github.davidmarquis.redisq.consumer.MessageListener;
import com.github.davidmarquis.redisq.consumer.retry.RetryableMessageException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 版块统计侦听器,创建版块的统计数据
 * @author xiaofanku
 * @since 20200521
 */
@Component("boardStatsEntry")
public class BoardStatsListener implements MessageListener<BoardCreateEvent> {
    @Autowired
    private BoardStatsDao boardStatsDao;
    private final static Logger logger = LoggerFactory.getLogger(BoardStatsListener.class);
    
    @Override
    public void onMessage(Message<BoardCreateEvent> event) throws RetryableMessageException {
        logger.info("[Board][CreateEvent][1]版块统计文件开始执行");
        Board board = event.getPayload().getBoard();
        //版块统计
        boardStatsDao.createStats(board.getId(), board.getVolumesId());
        logger.info("[Board][CreateEvent][1]版块统计文件执行结束");
    }
}