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

import com.apobates.forum.member.dao.MemberDao;
import com.apobates.forum.member.entity.Member;
import com.apobates.forum.member.entity.MemberRoleEnum;
import com.apobates.forum.member.impl.event.MemberSignUpEvent;
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;

/**
 * 将1号员工提升为管理员
 *
 * @author xiaofanku
 * @since 20200521
 */
@Component("promoteRole")
public class MemberSignUpPromoteRoleListener implements MessageListener<MemberSignUpEvent> {
    @Autowired
    private MemberDao memberDao;
    private final static Logger logger = LoggerFactory.getLogger(MemberSignUpPromoteRoleListener.class);
    
    @Override
    public void onMessage(Message<MemberSignUpEvent> event) throws RetryableMessageException {
        logger.info("[Member][SignUpEvent][1]开始1号员工提升");
        Member m = event.getPayload().getMember();
        if (m.getId() == 1) {
            memberDao.editMemberRole(1L, MemberRoleEnum.ADMIN);
        }
        logger.info("[Member][SignUpEvent][1]1号员工提升结束");
    }
}