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

import com.apobates.forum.member.dao.MemberDao;
import com.apobates.forum.member.entity.MemberGroupEnum;
import com.apobates.forum.member.impl.event.MemberVipExchangeEvent;
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;
/**
 * VIP会员交易会员组变更侦听器
 *
 * @author xiaofanku
 * @since 20200921
 */
@Component("changeGroup")
public class MemberVipExchangeGroupListener implements MessageListener<MemberVipExchangeEvent> {
    @Autowired
    private MemberDao memberDao;
    private final static Logger logger = LoggerFactory.getLogger(MemberVipExchangeGroupListener.class);

    @Override
    public void onMessage(Message<MemberVipExchangeEvent> event) throws RetryableMessageException {
        logger.info("[Member][VipExchangeEvent][1]VIP会员的组变更开始");
        MemberVipExchangeEvent vee = event.getPayload();
        if (vee.getRecord().getId() > 0) {
            memberDao.editMemberGroup(vee.getRecord().getMemberId(), MemberGroupEnum.VIP);
        }
        logger.info("[Member][VipExchangeEvent][1]VIP会员的组结束变更");
    }
}
