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

import com.apobates.forum.member.dao.MemberDao;
import com.apobates.forum.member.impl.event.MemberPenalizeEvent;
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("changeStatus")
public class MemberPenalizeChangeStatusListener implements MessageListener<MemberPenalizeEvent> {
    @Autowired
    private MemberDao memberDao;
    private final static Logger logger = LoggerFactory.getLogger(MemberPenalizeChangeStatusListener.class);
    
    @Override
    public void onMessage(Message<MemberPenalizeEvent> event) throws RetryableMessageException {
        logger.info("[Member][PenalizeEvent][1]惩罚状态更新开始");
        //惩罚开始了吗?,暂不支持预定日期的惩罚,只支持即可生效
        memberDao.editMemberStatus(event.getPayload().getMember(), event.getPayload().getArrive());
        logger.info("[Member][PenalizeEvent][1]惩罚状态更新结束");
    }
}