package com.dxhy.erp.rabbitmq;

import com.dxhy.common.constant.RabbitMqConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author user
 */
@Component
@Slf4j

public class ErpSender implements RabbitTemplate.ConfirmCallback {
    @Autowired
    private AmqpTemplate rabbitTemplate;

    private String toExcelApply = RabbitMqConstant.TO_SALE_COUNT_ITEM;

    public boolean sendToStatus(String msg) {
        log.debug("推送销项汇总发送消息  --    " + msg);
        try {
            rabbitTemplate.convertAndSend("exchange", toExcelApply, msg);
            log.debug("推送销项汇总发送消息成功" + msg);
            return true;
        } catch (Exception e) {
           log.info("业务处理异常：{}", e);
            return false;
        }
    }

    @Override
    public void confirm(CorrelationData correlationData, boolean b, String s) {
        if (b) {
            log.debug(correlationData + "发送成功！");
        } else {
            log.info(correlationData + "消息发送确认失败:" + s);
        }
    }
}
