wlzboy
2025-12-02 d294abb765e4ed349907c92ce313689c6299ba7d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package com.ruoyi.system.config;
 
import com.ruoyi.common.config.MapServiceConfig;
import com.ruoyi.system.service.IMapService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
 
/**
 * 地图服务配置类
 * 根据配置动态选择使用百度地图还是天地图
 * 
 * @author ruoyi
 */
@Configuration
public class MapServiceConfiguration {
    
    private static final Logger logger = LoggerFactory.getLogger(MapServiceConfiguration.class);
    
    @Autowired
    private MapServiceConfig mapServiceConfig;
    
    @Autowired
    @Qualifier("baiduMapService")
    private IMapService baiduMapService;
    
    @Autowired
    @Qualifier("tiandituMapService")
    private IMapService tiandituMapService;
    
    /**
     * 根据配置提供主要的地图服务实现
     * 
     * @return 地图服务实例
     */
    @Bean
    @Primary
    public IMapService mapService() {
        String provider = mapServiceConfig.getProvider();
        logger.info("使用的地图服务进行地理编码:{}",provider);
        if ("tianditu".equalsIgnoreCase(provider)) {
            logger.info("使用天地图服务进行地理编码");
            return tiandituMapService;
        } else {
            // 默认使用百度地图
            logger.info("使用百度地图服务进行地理编码");
            return baiduMapService;
        }
    }
}