新增默认IP地理库

pull/82/head^2
awenes 8 months ago
parent c2bad81246
commit 9d2cd04d4e

@ -19,6 +19,7 @@ package cn.topiam.employee.console.converter.setting;
import java.util.Objects; import java.util.Objects;
import org.apache.commons.lang3.StringUtils;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -115,27 +116,27 @@ public interface GeoLocationSettingConverter {
*/ */
default GeoIpProviderResult entityToGeoLocationProviderConfig(SettingEntity entity) { default GeoIpProviderResult entityToGeoLocationProviderConfig(SettingEntity entity) {
//没有数据,默认未启用 //没有数据,默认未启用
if (Objects.isNull(entity)) { if (Objects.isNull(entity) || StringUtils.isBlank(entity.getValue())) {
return null; return null;
} }
try { try {
String value = entity.getValue(); String value = entity.getValue();
ObjectMapper objectMapper = EncryptionModule.deserializerDecrypt(); ObjectMapper objectMapper = EncryptionModule.deserializerDecrypt();
// 指定序列化输入的类型 // 指定序列化输入的类型
objectMapper.activateDefaultTyping(objectMapper.getPolymorphicTypeValidator(), objectMapper.activateDefaultTyping(objectMapper.getPolymorphicTypeValidator(),
ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY); ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
// 根据提供商序列化 // 根据提供商序列化
GeoLocationProviderConfig setting = objectMapper.readValue(value, GeoLocationProviderConfig.class); GeoLocationProviderConfig setting = objectMapper.readValue(value, GeoLocationProviderConfig.class);
if (MAXMIND.equals(setting.getProvider())) { if (MAXMIND.equals(setting.getProvider())) {
MaxmindProviderConfig config = (MaxmindProviderConfig) setting.getConfig(); MaxmindProviderConfig config = (MaxmindProviderConfig) setting.getConfig();
//@formatter:off //@formatter:off
return GeoIpProviderResult.builder() return GeoIpProviderResult.builder()
.provider(setting.getProvider().getProvider()) .provider(setting.getProvider().getProvider())
.config(config) .config(config)
.enabled(true) .enabled(true)
.build(); .build();
} }
//@formatter:on //@formatter:on
return null; return null;
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
throw new RuntimeException(e); throw new RuntimeException(e);

Loading…
Cancel
Save