package com.ruoyi.cai.mq.consumer;

import com.ruoyi.cai.service.ConsumeLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class CalculateSalesQueueConsumer {

    public final static String CALCULATE_SALES_QUEUE = "calculateSalesQueue";
    public final static String CALCULATE_SALES_EXCHANGE = "calculateSalesExchange";
    public final static String CALCULATE_SALES_KEY = "calculateSalesKey";


    @Autowired
    private ConsumeLogService consumeLogService;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = CALCULATE_SALES_QUEUE, durable = "false", autoDelete = "false"),
            exchange = @Exchange(value = CALCULATE_SALES_EXCHANGE),
            key = CALCULATE_SALES_KEY)
            ,containerFactory = "customContainerFactory")
    public void calculateSalesQueue(String message) {
        log.info("接受到到分销处理请求: message=" + message);
        try {
            consumeLogService.dealFenxiao(Long.valueOf(message),true);
        }catch (Exception e){
            log.error("处理分销失败: message=" + message,e);
        }
        log.info("分销处理完成: message=" + message);
    }


}
