dev add method link
Test Workflow / test (push) Has been cancelled

This commit is contained in:
2026-05-05 15:31:49 +07:00
parent d2b94802de
commit ba89406417
4 changed files with 53 additions and 26 deletions
@@ -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);