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; } } }