From 010ef2a907e66efd4702443c06cdd18f8a7ffa5b Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期三, 30 十月 2024 14:08:53 +0800 Subject: [PATCH] IP归属地查询接口集成 --- src/main/java/com/yeshi/buwan/controller/parser/ConfigParser.java | 80 ++++++++++++++++++++-------------------- 1 files changed, 40 insertions(+), 40 deletions(-) diff --git a/src/main/java/com/yeshi/buwan/controller/parser/ConfigParser.java b/src/main/java/com/yeshi/buwan/controller/parser/ConfigParser.java index 6e79f62..8662171 100644 --- a/src/main/java/com/yeshi/buwan/controller/parser/ConfigParser.java +++ b/src/main/java/com/yeshi/buwan/controller/parser/ConfigParser.java @@ -3,14 +3,14 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.annotations.Expose; -import com.google.gson.reflect.TypeToken; +import com.yeshi.buwan.domain.ad.AdAreaConfig; +import com.yeshi.buwan.domain.ad.ThirdAdType; import com.yeshi.buwan.domain.recommend.FloatAD; import com.yeshi.buwan.domain.system.DetailSystem; -import com.yeshi.buwan.dto.config.ADShieldIPConfig; import com.yeshi.buwan.dto.log.BaseLog; -import com.yeshi.buwan.log.LogHelper; import com.yeshi.buwan.service.imp.DetailSystemConfigService; import com.yeshi.buwan.service.imp.SystemService; +import com.yeshi.buwan.service.inter.ad.AdAreaConfigService; import com.yeshi.buwan.service.inter.ad.FloatADService; import com.yeshi.buwan.service.inter.system.SystemConfigService; import com.yeshi.buwan.service.inter.user.UserDPContentWatchStatisticService; @@ -19,11 +19,11 @@ import com.yeshi.buwan.util.IPUtil; import com.yeshi.buwan.util.JsonUtil; import com.yeshi.buwan.util.StringUtil; +import com.yeshi.buwan.util.ad.AdAreaUtil; import com.yeshi.buwan.util.log.LoggerUtil; import com.yeshi.buwan.util.log.UserActiveLogFactory; import com.yeshi.buwan.vo.AcceptData; import com.yeshi.buwan.vo.ad.AdConfigTypeVO; -import net.sf.json.JSONArray; import net.sf.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -32,9 +32,7 @@ import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.io.PrintWriter; -import java.lang.reflect.Type; import java.math.BigDecimal; -import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -44,6 +42,9 @@ Logger logger = LoggerFactory.getLogger(ConfigParser.class); + + Logger debugLogger = LoggerFactory.getLogger("debug"); + @Resource private DetailSystemConfigService configService; @Resource @@ -63,6 +64,9 @@ @Resource private APPManager appManager; + + @Resource + private AdAreaConfigService adAreaConfigService; public ADConfig getAdShowType(String key, String channel, int version, Map<String, String> map) { @@ -111,47 +115,43 @@ // 鑾峰彇骞垮憡閰嶇疆淇℃伅 - private void loadAdConfig(AcceptData acceptData, Map<String, String> map, String ip, boolean isDPUser,JSONObject data) { + private void loadAdConfig(AcceptData acceptData, Map<String, String> map, String ip, boolean isDPUser, JSONObject data) { Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create(); - Map<String, Boolean> shieldMap = new HashMap<>(); // 鑾峰彇鍖哄煙灞忚斀淇℃伅 - String shieldInfo = map.get("ad_shield_province_rules"); - if (!StringUtil.isNullOrEmpty(shieldInfo)) { - JSONObject json = JSONObject.fromObject(shieldInfo); - //鑾峰彇娓犻亾闇�瑕佸睆钄界殑鍩庡競 - JSONObject shieldProvinceRules = json.optJSONObject(acceptData.getChannel().toLowerCase()); - if (shieldProvinceRules != null) { - IPUtil.IPInfo ipInfo = null; - try { - ipInfo = ipManager.getIPInfo(ip); - } catch (Exception e) { - e.printStackTrace(); - logger.error("IP鍦板潃浣嶇疆淇℃伅鑾峰彇澶辫触锛�" + ip); - } + List<AdAreaConfig> areaConfigList = null; + try { + areaConfigList = adAreaConfigService.listCache(acceptData.getChannel(), Long.parseLong(acceptData.getDetailSystem().getId())); + } catch (Exception e) { + + } + IPUtil.IPInfo ipInfo = null; + if (areaConfigList != null && areaConfigList.size() > 0) { + try { + ipInfo = ipManager.getIPInfo(ip); if (ipInfo != null) { - //鑾峰彇鏄惁闇�瑕佸睆钄藉紑灞� - for (AdConfigTypeVO adType : AdConfigTypeVO.values()) { - JSONArray splashProvinces = shieldProvinceRules.optJSONArray(adType.getSettingKey()); - if (splashProvinces != null) { - for (int i = 0; i < splashProvinces.size(); i++) { - String p = splashProvinces.optString(i); - if (p.equalsIgnoreCase(ipInfo.getProvince())) { - shieldMap.put(adType.getSettingKey(), true); - break; - } - } - } - } + debugLogger.info("IP褰掑睘鍦帮細IP-{},鐗堟湰-{}, 娓犻亾-{}锛岀渷-{}锛� 甯�-{}", ip, acceptData.getVersion(), acceptData.getChannel(), ipInfo.getProvince(), ipInfo.getCity()); } + } catch (Exception e) { + e.printStackTrace(); + logger.error("IP鍦板潃浣嶇疆淇℃伅鑾峰彇澶辫触锛�" + ip); } } JSONObject adNew = new JSONObject(); JSONObject ad = new JSONObject(); - for (AdConfigTypeVO adType: AdConfigTypeVO.values()){ - ADConfig adConfig = getAdShowType(adType.getDbKey(), acceptData.getChannel(), acceptData.getVersion(), map); - if (shieldMap.get(adType.getSettingKey())!=null&&shieldMap.get(adType.getSettingKey())) { - //灞忚斀骞垮憡 - adConfig = null; + for (AdConfigTypeVO adType : AdConfigTypeVO.values()) { + ADConfig adConfig = getAdShowType(adType.getDbKey(), acceptData.getChannel(), acceptData.getVersion(), map); + // 鍒ゆ柇骞垮憡鏄惁鏍规嵁鍦板煙灞忚斀 + if (ipInfo != null) { + ThirdAdType thirdAdType = AdAreaUtil.getAdType(ipInfo.getProvince(), ipInfo.getCity(), adType, areaConfigList); + if (thirdAdType != null) { + if (thirdAdType == ThirdAdType.none) { + // 涓嶅睍绀哄箍鍛� + adConfig = null; + } else if (adConfig != null) { + // 鎸囧畾骞垮憡绫诲瀷 + adConfig.setType(thirdAdType.name()); + } + } } ad.put(adType.getVoKey(), adConfig == null ? "" : adConfig.getType()); adNew.put(adType.getVoKey(), gson.toJson(adConfig)); @@ -191,7 +191,7 @@ } // 鍔犺浇骞垮憡閰嶇疆 - loadAdConfig(acceptData,map,ip,isDPUser,data); + loadAdConfig(acceptData, map, ip, isDPUser, data); //PPTV鍏嶅箍鍛婃潈鐩婃椂闀�,鏆傛椂璁剧疆涓�3灏忔椂 data.put("pptvNoAdRewardHour", 3); -- Gitblit v1.8.0