🏗️ 地理位置优化

master
smallbun 2024-12-16 01:05:20 +08:00
parent 53670079c3
commit f3eb0cde17
4 changed files with 13 additions and 13 deletions

View File

@ -18,8 +18,8 @@
package cn.topiam.employee.common.geo;
import cn.topiam.employee.support.geo.GeoLocation;
import cn.topiam.employee.support.geo.GeoLocationParser;
import cn.topiam.employee.support.geo.GeoLocationProvider;
import cn.topiam.employee.support.geo.GeoLocationService;
/**
* None
@ -27,13 +27,13 @@ import cn.topiam.employee.support.geo.GeoLocationService;
* @author TopIAM
* Created by support@topiam.cn on 2021/11/27 21:20
*/
public class NoneGeoLocationServiceImpl implements GeoLocationService {
public class NoneGeoLocationParserImpl implements GeoLocationParser {
/**
*
*
* @param remote {@link String}
* @return {@link GeoLocationService}
* @return {@link GeoLocation}
*/
@Override
public GeoLocation getGeoLocation(String remote) {

View File

@ -27,8 +27,8 @@ import org.springframework.util.Assert;
import cn.topiam.employee.common.enums.Country;
import cn.topiam.employee.support.geo.GeoLocation;
import cn.topiam.employee.support.geo.GeoLocationParser;
import cn.topiam.employee.support.geo.GeoLocationProvider;
import cn.topiam.employee.support.geo.GeoLocationService;
import lombok.extern.slf4j.Slf4j;
import static cn.topiam.employee.common.geo.District.CITY_DISTRICT;
@ -41,7 +41,7 @@ import static cn.topiam.employee.common.geo.District.PROVINCE_DISTRICT;
* Created by support@topiam.cn on 2023/10/30 19:11
*/
@Slf4j
public class Ip2regionGeoLocationServiceImpl implements GeoLocationService, DisposableBean {
public class Ip2regionGeoLocationParserImpl implements GeoLocationParser, DisposableBean {
public static GeoLocationProvider IP2REGION = new GeoLocationProvider("default",
"ip2region");
@ -50,7 +50,7 @@ public class Ip2regionGeoLocationServiceImpl implements GeoLocationService, Disp
private final Searcher searcher;
public Ip2regionGeoLocationServiceImpl() throws IOException {
public Ip2regionGeoLocationParserImpl() throws IOException {
// 加载整个xdb到内存。
try (InputStream in = this.getClass().getResourceAsStream(DEFAULT_XDB_PATH)) {
Assert.notNull(in, "XDB must not be null");

View File

@ -46,8 +46,8 @@ import com.maxmind.geoip2.record.*;
import cn.topiam.employee.support.constant.EiamConstants;
import cn.topiam.employee.support.geo.GeoLocation;
import cn.topiam.employee.support.geo.GeoLocationParser;
import cn.topiam.employee.support.geo.GeoLocationProvider;
import cn.topiam.employee.support.geo.GeoLocationService;
import cn.topiam.employee.support.util.IpUtils;
import lombok.Getter;
@ -66,7 +66,7 @@ import static cn.topiam.employee.common.geo.District.PROVINCE_DISTRICT;
*/
@Slf4j
@Getter
public class MaxmindGeoLocationServiceImpl implements GeoLocationService {
public class MaxmindGeoLocationParserImpl implements GeoLocationParser {
private final DatabaseReader reader;
private final MaxmindProviderConfig maxmindProviderConfig;
@ -86,8 +86,8 @@ public class MaxmindGeoLocationServiceImpl implements GeoLocationService {
*/
public static final String SHA256_URL = "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&license_key=%s&suffix=tar.gz.sha256";
public MaxmindGeoLocationServiceImpl(MaxmindProviderConfig maxmindProviderConfig,
RestTemplate restTemplate) throws IOException {
public MaxmindGeoLocationParserImpl(MaxmindProviderConfig maxmindProviderConfig,
RestTemplate restTemplate) throws IOException {
this.maxmindProviderConfig = maxmindProviderConfig;
this.restTemplate = restTemplate;
download();

View File

@ -22,7 +22,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import cn.topiam.employee.support.geo.GeoLocationService;
import cn.topiam.employee.support.geo.GeoLocationParser;
import lombok.RequiredArgsConstructor;
@ -43,7 +43,7 @@ public class UpdateMaxmindTaskConfiguration {
@Scheduled(cron = "0 0 1 * * ?")
public void update() {
try {
if (geoLocationService instanceof MaxmindGeoLocationServiceImpl maxmindGeoLocation) {
if (geoLocationParser instanceof MaxmindGeoLocationParserImpl maxmindGeoLocation) {
logger.info("执行IP库文件更新定时任务开始");
if (maxmindGeoLocation.checkDbFileIsUpdate()) {
maxmindGeoLocation.download();
@ -55,6 +55,6 @@ public class UpdateMaxmindTaskConfiguration {
}
}
private final GeoLocationService geoLocationService;
private final GeoLocationParser geoLocationParser;
}