mirror of https://gitee.com/topiam/eiam
🏗️ 地理位置优化
parent
53670079c3
commit
f3eb0cde17
|
@ -18,8 +18,8 @@
|
||||||
package cn.topiam.employee.common.geo;
|
package cn.topiam.employee.common.geo;
|
||||||
|
|
||||||
import cn.topiam.employee.support.geo.GeoLocation;
|
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.GeoLocationProvider;
|
||||||
import cn.topiam.employee.support.geo.GeoLocationService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* None
|
* None
|
||||||
|
@ -27,13 +27,13 @@ import cn.topiam.employee.support.geo.GeoLocationService;
|
||||||
* @author TopIAM
|
* @author TopIAM
|
||||||
* Created by support@topiam.cn on 2021/11/27 21:20
|
* 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}
|
* @param remote {@link String}
|
||||||
* @return {@link GeoLocationService}
|
* @return {@link GeoLocation}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public GeoLocation getGeoLocation(String remote) {
|
public GeoLocation getGeoLocation(String remote) {
|
|
@ -27,8 +27,8 @@ import org.springframework.util.Assert;
|
||||||
|
|
||||||
import cn.topiam.employee.common.enums.Country;
|
import cn.topiam.employee.common.enums.Country;
|
||||||
import cn.topiam.employee.support.geo.GeoLocation;
|
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.GeoLocationProvider;
|
||||||
import cn.topiam.employee.support.geo.GeoLocationService;
|
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import static cn.topiam.employee.common.geo.District.CITY_DISTRICT;
|
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
|
* Created by support@topiam.cn on 2023/10/30 19:11
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class Ip2regionGeoLocationServiceImpl implements GeoLocationService, DisposableBean {
|
public class Ip2regionGeoLocationParserImpl implements GeoLocationParser, DisposableBean {
|
||||||
|
|
||||||
public static GeoLocationProvider IP2REGION = new GeoLocationProvider("default",
|
public static GeoLocationProvider IP2REGION = new GeoLocationProvider("default",
|
||||||
"ip2region");
|
"ip2region");
|
||||||
|
@ -50,7 +50,7 @@ public class Ip2regionGeoLocationServiceImpl implements GeoLocationService, Disp
|
||||||
|
|
||||||
private final Searcher searcher;
|
private final Searcher searcher;
|
||||||
|
|
||||||
public Ip2regionGeoLocationServiceImpl() throws IOException {
|
public Ip2regionGeoLocationParserImpl() throws IOException {
|
||||||
// 加载整个xdb到内存。
|
// 加载整个xdb到内存。
|
||||||
try (InputStream in = this.getClass().getResourceAsStream(DEFAULT_XDB_PATH)) {
|
try (InputStream in = this.getClass().getResourceAsStream(DEFAULT_XDB_PATH)) {
|
||||||
Assert.notNull(in, "XDB must not be null");
|
Assert.notNull(in, "XDB must not be null");
|
|
@ -46,8 +46,8 @@ import com.maxmind.geoip2.record.*;
|
||||||
|
|
||||||
import cn.topiam.employee.support.constant.EiamConstants;
|
import cn.topiam.employee.support.constant.EiamConstants;
|
||||||
import cn.topiam.employee.support.geo.GeoLocation;
|
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.GeoLocationProvider;
|
||||||
import cn.topiam.employee.support.geo.GeoLocationService;
|
|
||||||
import cn.topiam.employee.support.util.IpUtils;
|
import cn.topiam.employee.support.util.IpUtils;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
@ -66,7 +66,7 @@ import static cn.topiam.employee.common.geo.District.PROVINCE_DISTRICT;
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Getter
|
@Getter
|
||||||
public class MaxmindGeoLocationServiceImpl implements GeoLocationService {
|
public class MaxmindGeoLocationParserImpl implements GeoLocationParser {
|
||||||
|
|
||||||
private final DatabaseReader reader;
|
private final DatabaseReader reader;
|
||||||
private final MaxmindProviderConfig maxmindProviderConfig;
|
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 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,
|
public MaxmindGeoLocationParserImpl(MaxmindProviderConfig maxmindProviderConfig,
|
||||||
RestTemplate restTemplate) throws IOException {
|
RestTemplate restTemplate) throws IOException {
|
||||||
this.maxmindProviderConfig = maxmindProviderConfig;
|
this.maxmindProviderConfig = maxmindProviderConfig;
|
||||||
this.restTemplate = restTemplate;
|
this.restTemplate = restTemplate;
|
||||||
download();
|
download();
|
|
@ -22,7 +22,7 @@ import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import cn.topiam.employee.support.geo.GeoLocationService;
|
import cn.topiam.employee.support.geo.GeoLocationParser;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ public class UpdateMaxmindTaskConfiguration {
|
||||||
@Scheduled(cron = "0 0 1 * * ?")
|
@Scheduled(cron = "0 0 1 * * ?")
|
||||||
public void update() {
|
public void update() {
|
||||||
try {
|
try {
|
||||||
if (geoLocationService instanceof MaxmindGeoLocationServiceImpl maxmindGeoLocation) {
|
if (geoLocationParser instanceof MaxmindGeoLocationParserImpl maxmindGeoLocation) {
|
||||||
logger.info("执行IP库文件更新定时任务开始");
|
logger.info("执行IP库文件更新定时任务开始");
|
||||||
if (maxmindGeoLocation.checkDbFileIsUpdate()) {
|
if (maxmindGeoLocation.checkDbFileIsUpdate()) {
|
||||||
maxmindGeoLocation.download();
|
maxmindGeoLocation.download();
|
||||||
|
@ -55,6 +55,6 @@ public class UpdateMaxmindTaskConfiguration {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final GeoLocationService geoLocationService;
|
private final GeoLocationParser geoLocationParser;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue