@@ -11,6 +11,10 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@@ -40,6 +44,41 @@ public class GeoCountryService {
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, Integer> getUniqueGeoCount(List<String> ipList) {
|
||||
Set<String> uniqueCountries = new HashSet<>();
|
||||
Set<String> uniqueCountryCodes = new HashSet<>();
|
||||
Set<String> uniqueCities = new HashSet<>();
|
||||
|
||||
if (ipList != null) {
|
||||
for (String ip : ipList) {
|
||||
try {
|
||||
String country = getCountryByIp(ip);
|
||||
if (!"UNKNOWN".equals(country)) {
|
||||
uniqueCountries.add(country);
|
||||
}
|
||||
|
||||
String countryCode = getCountryCodeByIp(ip);
|
||||
if (!"UNKNOWN".equals(countryCode)) {
|
||||
uniqueCountryCodes.add(countryCode);
|
||||
}
|
||||
|
||||
String city = getCityByIp(ip);
|
||||
if (!"UNKNOWN".equals(city)) {
|
||||
uniqueCities.add(city);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("Error processing IP: {}", ip, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Map.of(
|
||||
"uniqueCountries", uniqueCountries.size(),
|
||||
"uniqueCountryCodes", uniqueCountryCodes.size(),
|
||||
"uniqueCities", uniqueCities.size()
|
||||
);
|
||||
}
|
||||
|
||||
public String getCountryCode(String input) {
|
||||
try {
|
||||
CountryResponse response = extractCountry(input);
|
||||
|
||||
Reference in New Issue
Block a user