package com.mortals.xhx.base.system.message;

import com.alibaba.fastjson.JSON;
import com.mortals.framework.model.AccessLogPdu;
import com.mortals.framework.model.BizLogPdu;
import com.mortals.framework.model.ErrorLogPdu;
import com.mortals.framework.model.OperateLogPdu;
import com.mortals.framework.service.IMessageProduceService;
import com.mortals.xhx.common.key.QueueKey;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;

@Component
@Primary
@Slf4j
public class MessageProducer implements IMessageProduceService {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void syncAccessSend(AccessLogPdu accessLogPdu) {
        //log.info("accessinfo==>{}",JSON.toJSONString(accessLogPdu));
        rabbitTemplate.convertAndSend(QueueKey.EXCHANGE, QueueKey.ACCESS_LOG_QUEUE, accessLogPdu);
    }

    @Override
    public void syncBizSend(BizLogPdu bizLogPdu) {
        rabbitTemplate.convertAndSend(QueueKey.EXCHANGE, QueueKey.BIZ_LOG_QUEUE, JSON.toJSONString(bizLogPdu));
    }

    @Override
    public void syncErrorSend(ErrorLogPdu errorLogPdu) {
        rabbitTemplate.convertAndSend(QueueKey.EXCHANGE, QueueKey.ERROR_LOG_QUEUE, JSON.toJSONString(errorLogPdu));

    }

    @Override
    public void syncOperSend(OperateLogPdu operLogPdu) {
        log.info("operLogInfo==>{}",JSON.toJSONString(operLogPdu));
        rabbitTemplate.convertAndSend(QueueKey.EXCHANGE, QueueKey.OPERATION_LOG_QUEUE, JSON.toJSONString(operLogPdu));

    }

}
