Pārlūkot izejas kodu

营销系统-IP修改

wangcl 1 nedēļu atpakaļ
vecāks
revīzija
f8796e860a

+ 8 - 0
pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/util/ip/IPUtils.java

@@ -56,6 +56,10 @@ public class IPUtils {
 				externalPath = System.getenv("IP2REGION_DB_PATH");
 			}
 			if (externalPath != null && !externalPath.trim().isEmpty()) {
+				java.nio.file.Path p = java.nio.file.Paths.get(externalPath.trim());
+				Long size = null;
+				try { size = java.nio.file.Files.exists(p) ? java.nio.file.Files.size(p) : null; } catch (Exception ignore) {}
+				log.info("ip2region准备使用外部文件: path={}, exists={}, size={}", externalPath, java.nio.file.Files.exists(p), size);
 				searcher = Searcher.newWithFileOnly(externalPath.trim());
 				log.info("ip2region初始化成功 (external path: {})", externalPath);
 				return;
@@ -69,9 +73,13 @@ public class IPUtils {
 					return;
 				}
 				byte[] cBuff = is.readAllBytes();
+				java.net.URL resUrl = IPUtils.class.getClassLoader().getResource("ip/ip2region.xdb");
+				log.info("ip2region从classpath读取: url={}, bytes={}", resUrl, cBuff != null ? cBuff.length : null);
 				java.nio.file.Path tmp = java.nio.file.Files.createTempFile("ip2region", ".xdb");
 				java.nio.file.Files.write(tmp, cBuff);
 				subtleSetDeleteOnExit(tmp);
+				Long tmpSize = null; try { tmpSize = java.nio.file.Files.size(tmp); } catch (Exception ignore) {}
+				log.info("ip2region写入临时文件: path={}, size={} (bytes)", tmp, tmpSize);
 				searcher = Searcher.newWithFileOnly(tmp.toString());
 				log.info("ip2region初始化成功 (temp file: {})", tmp);
 			}

+ 3 - 0
pig-marketing/pig-marketing-biz/src/main/java/com/pig4cloud/pig/marketing/util/IPLocationUtil.java

@@ -123,8 +123,10 @@ public class IPLocationUtil {
             }
             
             // 使用ip2region获取完整的三级地址信息
+            log.info("IPLocationUtil 开始解析IP: {}", ip);
             String fullAddress = getFullAddressFromIp2region(ip);
             if (fullAddress != null) {
+                log.info("IPLocationUtil 解析结果: {} -> {}", ip, fullAddress);
                 cacheResult(cacheKey, fullAddress);
                 return fullAddress;
             }
@@ -149,6 +151,7 @@ public class IPLocationUtil {
         try {
             // 统一委托给 IPUtils,避免本地 Searcher 与库/数据版本不一致
             String region = IPUtils.getIpRegion(ip);
+            log.info("IPLocationUtil 调用 IPUtils.getIpRegion 返回: ip={}, region={}", ip, region);
             if (region == null || region.trim().isEmpty() || "未知".equals(region) || "内网".equals(region)) {
                 return null;
             }