
package com.tmerclub.cloud.config;

import com.tmerclub.cloud.common.rocketmq.config.RocketMqAdapter;
import com.tmerclub.cloud.common.rocketmq.config.RocketMqConstant;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;

/**
 * @author tmerclub
 * @date 2021/3/30
 */
@RefreshScope
@Configuration
public class RocketMqConfig {

    @Autowired
    private RocketMqAdapter rocketMqAdapter;

    @Lazy
    @Bean(destroyMethod = "destroy")
    public RocketMQTemplate shopWalletNotifyServiceTemplate() {
        return rocketMqAdapter.getTemplateByTopicName(RocketMqConstant.SHOP_WALLET_NOTIFY_SERVICE_TOPIC);
    }

    @Lazy
    @Bean(destroyMethod = "destroy")
    public RocketMQTemplate refundShopNotifyServiceTemplate() {
        return rocketMqAdapter.getTemplateByTopicName(RocketMqConstant.REFUND_SHOP_NOTIFY_SERVICE_TOPIC);
    }

    @Lazy
    @Bean(destroyMethod = "destroy")
    public RocketMQTemplate refundSuccessNotifySupplierTemplate() {
        return rocketMqAdapter.getTemplateByTopicName(RocketMqConstant.ORDER_REFUND_SUCCESS_SETTLEMENT_SUPPLIER_TOPIC);
    }

    @Lazy
    @Bean(destroyMethod = "destroy")
    public RocketMQTemplate addShopWalletLogTemplate() {
        return rocketMqAdapter.getTransactionTemplateByTopicName(RocketMqConstant.ADD_SHOP_WALLET_LOG_TOPIC);
    }

    @Lazy
    @Bean(destroyMethod = "destroy")
    public RocketMQTemplate updateShopRechargeSuccessTemplate() {
        return rocketMqAdapter.getTransactionTemplateByTopicName(RocketMqConstant.UPDATE_SHOP_RECHARGE_SUCCESS_TOPIC);
    }

    @Lazy
    @Bean(destroyMethod = "destroy")
    public RocketMQTemplate addSupplierWalletLogTemplate() {
        return rocketMqAdapter.getTransactionTemplateByTopicName(RocketMqConstant.ADD_SUPPLIER_WALLET_LOG_TOPIC);
    }
    @Lazy
    @Bean(destroyMethod = "destroy")
    public RocketMQTemplate openAllinPayRocketMQTemplate() {
        return rocketMqAdapter.getTransactionTemplateByTopicName(RocketMqConstant.OPEN_ALLINPAY_TOPIC);
    }


}
