package cn.newfeifan.mall.module.distri.mq.consumer.shareLinkRegister;

import cn.newfeifan.mall.module.distri.controller.app.sharelinkregister.vo.AppShareLinkRegisterSaveReqVO;
import cn.newfeifan.mall.module.distri.service.sharelinkregister.ShareLinkRegisterService;
import cn.newfeifan.mall.module.member.message.share.ShareLinkRegisterCreateMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 用户注册时，发送通过分享链接注册的用户的消费者，基 {@link ShareLinkRegisterCreateMessage} 消息
 */
@Component
@Slf4j
public class AddShareLinkRegisterConsumer {

    @Resource
    private ShareLinkRegisterService shareLinkRegisterService;

    @EventListener
//    @Async // Spring Event 默认在 Producer 发送的线程，通过 @Async 实现异步
    public void onMessage(ShareLinkRegisterCreateMessage message) {
        log.info("[onMessage][消息内容({})]", message);
        AppShareLinkRegisterSaveReqVO reqVO = AppShareLinkRegisterSaveReqVO
                .builder()
                .distriShareLinkId(message.getShareLinkId())
                .registerUserId(message.getRegisterUserId())
                .build();
        shareLinkRegisterService.createShareLinkRegister(reqVO);
    }

}
