Bladeren bron

营销系统-IP工具类修改

wangcl 1 week geleden
bovenliggende
commit
e1bc42a25f

+ 9 - 5
pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/util/ip/IPUtils.java

@@ -8,6 +8,7 @@ import org.lionsoul.ip2region.xdb.Searcher;
 
 import java.io.BufferedReader;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.net.HttpURLConnection;
 import java.net.InetAddress;
@@ -48,12 +49,15 @@ public class IPUtils {
 	 * 初始化IP地址索引
 	 */
 	private static void initIpSearcher() {
-		try {
-			// 基于内存查询-从资源文件加载xdb数据库
-			String dbPath = IPUtils.class.getClassLoader().getResource("ip/ip2region.xdb").getPath();
-			byte[] cBuff = Searcher.loadContentFromFile(dbPath);
+		try (InputStream is = IPUtils.class.getClassLoader().getResourceAsStream("ip/ip2region.xdb")) {
+			if (is == null) {
+				log.error("ip2region资源不存在: ip/ip2region.xdb");
+				searcher = null;
+				return;
+			}
+			byte[] cBuff = is.readAllBytes();
 			searcher = Searcher.newWithBuffer(cBuff);
-			log.info("ip2region初始化成功");
+			log.info("ip2region初始化成功 (classpath)");
 		} catch (Exception e) {
 			log.error("ip2region初始化失败", e);
 			searcher = null;

+ 1 - 0
pig-marketing/pig-marketing-biz/src/main/java/com/pig4cloud/pig/marketing/service/impl/TcpDataServiceImpl.java

@@ -544,6 +544,7 @@ import java.util.stream.Collectors;
 			
 			for (Device device : devices) {
 				if (StringUtils.isNotBlank(device.getClientIp())) {
+					log.debug("正在解析IP:{}", device.getClientIp());
 					String country = getCountryFromIp(device.getClientIp());
 					if (StringUtils.isNotBlank(country) && !"未知".equals(country) && !"内网".equals(country)) {
 						countryCountMap.merge(country, 1L, Long::sum);