MallConfiguration.java 2.16 KB
package com.diligrp.cashier.mall;

import com.diligrp.cashier.mall.client.RtMallHttpClient;
import com.diligrp.cashier.mall.property.RtMallDynamicProperty;
import com.diligrp.cashier.shared.mybatis.MybatisMapperSupport;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
@ComponentScan("com.diligrp.cashier.mall")
@MapperScan(basePackages = {"com.diligrp.cashier.mall.dao"}, markerInterface = MybatisMapperSupport.class)
public class MallConfiguration {

    /**
     * 创建大润发HTTP客户端
     * 用于调用大润发订单详情接口
     */
    @Bean
    public RtMallHttpClient rtMallHttpClient(@Value("${rtmall.api.url:https://em-shop.feiniugo.com/api/externalapi/scanbuy/process}") String apiUrl,
                                             RtMallDynamicProperty rtMallDynamicProperty) {
        RtMallDynamicProperty.AppSecretDynamicProperty config = rtMallDynamicProperty.getAppSecrets().getFirst();
        return new RtMallHttpClient(apiUrl, config.getAppKey(), config.getAppSecret());
    }

    @Bean
    public Queue queue() {
        return new Queue(MallConstants.CASHIER_MALL_CALLBACK_RETRY_QUEUE, true, false, false);
    }

    @Bean
    public CustomExchange customExchange() {
        Map<String, Object> args = new HashMap<>();
        args.put("x-delayed-type", "direct");
        return new CustomExchange(MallConstants.CASHIER_MALL_CALLBACK_RETRY_EXCHANGE, MallConstants.EXCHANGE_TYPE, true, false, args);
    }

    @Bean
    public Binding binding(Queue queue, CustomExchange customExchange) {
        return BindingBuilder.bind(queue)
                .to(customExchange)
                .with(MallConstants.CASHIER_MALL_CALLBACK_RETRY_QUEUE)
                .noargs();
    }
}