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

import cn.newfeifan.mall.module.distri.mq.message.order.CalcMessage;
import cn.newfeifan.mall.module.distri.mq.message.order.DistriOrderMessage;
import cn.newfeifan.mall.module.distri.service.ordercalc.OrderCalcService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;


@Component
@Slf4j
public class OrderConsumer {

    @Resource
    private OrderCalcService orderCalcService;

    @EventListener
    @Async // Spring Event 默认在 Producer 发送的线程，通过 @Async 实现异步
    public void onMessage(CalcMessage calcMessage) {
        log.info("[onMessage][消息内容({})]", calcMessage);
        // todo 计算数据
        orderCalcService.calc(calcMessage.getDistriOrderMessages());

    }

}
