package com.bonus.common.houqin.mq;

import com.bonus.common.houqin.mq.rabbit.RabbitPropertiesExt;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.boot.autoconfigure.amqp.RabbitProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class PropertyBeanPostProcessor implements ApplicationContextAware, BeanPostProcessor {
   private static final Logger log = LoggerFactory.getLogger(PropertyBeanPostProcessor.class);
   private ApplicationContext applicationContext;

   @Override
   public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
      if (bean instanceof RabbitProperties) {
         MQProperties mqProperties = (MQProperties)this.applicationContext.getBean(MQProperties.class);
         RabbitPropertiesExt rabbitmq = mqProperties.getRabbitmq();
         String var10001 = mqProperties.getNamespace();
         rabbitmq.setRetryQueue(var10001 + rabbitmq.getRetryQueue());
         return rabbitmq;
      } else {
         return bean;
      }
   }

   @Override
   public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
      return bean;
   }

   @Override
   public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
      this.applicationContext = applicationContext;
   }
}
