package com.dxhy.common.rabbitmq;

import javax.annotation.Resource;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;

/**
 * @author jiaohongyang
 */
@Component
@Slf4j
public class RabbitLogsSender {
    @Resource
    private RabbitTemplate rabbitTemplate;
    @Value("${TO_MESSAGE_LOG:TO_MESSAGE_LOG}")
    private String tomessagelog;
    @Value("${TO_INVOICE_LOG:TO_INVOICE_LOG}")
    private String toinvoicelog;
    @Value("${TO_CUSTOMS_LOG:TO_CUSTOMS_LOG}")
    private String tocustomslog;
    @Value("${TO_MENU_TABULATE:TO_MENU_TABULATE}")
    private String toMenuTabulate;
    @Value("${TO_CUSTOMS_OCR:TO_CUSTOMS_OCR}")
    private String toCustomsOcr;

    /**
     * 日志存储推送 mq
     */
    public boolean sendSaveLogs(String logs) {
        log.debug(" 日志推送开始  --   " + logs + " 队列名：" + tomessagelog);
        try {
            this.rabbitTemplate.convertAndSend("exchange", tomessagelog, logs);
            log.debug(" 日志推送结束 ");
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    /**
     * 发票操作日志推送 mq
     */
    public boolean sendInvoiceLogs(String logs) {
        log.debug(" 发票操作日志推送开始  --   " + logs + " 队列名：" + toinvoicelog);
        try {
            this.rabbitTemplate.convertAndSend("exchange", toinvoicelog, logs);
            log.debug(" 发票操作日志推送结束 ");
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    /**
     * 缴款书操作日志推送 mq
     */
    public boolean sendCustomsLogs(String logs) {
        log.debug(" 缴款书操作日志推送开始  --   " + logs + " 队列名：" + tocustomslog);
        try {
            this.rabbitTemplate.convertAndSend("exchange", tocustomslog, logs);
            log.debug(" 缴款书操作日志推送结束 ");
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    /**
     * 保存菜单分配记录
     *
     * @param menuTabulate
     *            菜单显示累信息
     * @return 返回信息
     */
    public boolean saveMenuTabulate(String menuTabulate) {
        log.debug(" 保存显示列推送开始  --   " + menuTabulate + " 队列名：" + toMenuTabulate);
        try {
            this.rabbitTemplate.convertAndSend("exchange", toMenuTabulate, menuTabulate);
            log.debug(" 保存显示列推送结束 ");
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    /**
     * 缴款书ocr识别
     *
     * @param sendInfo
     *            图片信息
     * @return 返回结果
     */
    public boolean toCustomsOcr(String sendInfo) {
        log.debug(" 缴款书ocr识别推送开始  --   " + sendInfo + " 队列名：" + toCustomsOcr);
        try {
            this.rabbitTemplate.convertAndSend("exchange", toCustomsOcr, sendInfo);
            log.debug(" 缴款书ocr识别推送结束 ");
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
}
