Browse Source

feat:补充特征

zhaohaipeng 8 hours ago
parent
commit
ee3a4a1e66

+ 20 - 0
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/score/strategy/RankStrategyBasic.java

@@ -1,6 +1,8 @@
 package com.tzld.piaoquan.ad.engine.service.score.strategy;
 
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson.TypeReference;
 import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
 import com.tzld.piaoquan.ad.engine.commons.dto.AdPlatformCreativeDTO;
 import com.tzld.piaoquan.ad.engine.commons.enums.RedisPrefixEnum;
@@ -346,4 +348,22 @@ public abstract class RankStrategyBasic implements RankStrategy {
         adRankItem.getMetaFeatureMap().put("reqFeature", reqFeature);
         adRankItem.getMetaFeatureMap().put("sceneFeature", sceneFeatureMap);
     }
+
+    protected Map<String, String> getUserLayer(String mid) {
+        if (StringUtils.isEmpty(mid)) {
+            return new HashMap<>();
+        }
+        String key = String.format("ad:engine:mid:layer:%s", mid);
+        String value = algRedisHelper.get(key);
+        if (StringUtils.isEmpty(value)) {
+            return new HashMap<>();
+        }
+        try {
+            return JSON.parseObject(value, new TypeReference<Map<String, String>>() {
+            });
+        } catch (Exception e) {
+            log.error("getUserLayer error. mid: {}, \n", mid, e);
+            return new HashMap<>();
+        }
+    }
 }

+ 12 - 24
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/score/strategy/RankStrategyBy687.java

@@ -71,32 +71,21 @@ public class RankStrategyBy687 extends RankStrategyBasic {
         }
 
         // 选择一个客户
-        List<String> customers = rankItems.stream()
-                .map(i -> i.getExt().getOrDefault(CUSTOMER_FIELD_NAME, ""))
-                .map(Objects::toString)
-                .filter(StringUtils::isNotEmpty)
-                .distinct()
-                .collect(Collectors.toList());
+        List<String> customers = rankItems.stream().map(i -> i.getExt().getOrDefault(CUSTOMER_FIELD_NAME, "")).map(Objects::toString).filter(StringUtils::isNotEmpty).distinct().collect(Collectors.toList());
         String keyFormat = "ad:engine:customer:layer:info:%s:" + userLayer;
         List<HotRankFeatureInfo> customerFeature = this.multiGetFeature(customers, keyFormat);
         String customer = this.choose(customerFeature);
 
         // 从当前客户的所有创意中,选择一个创意
-        List<String> customerCreativeIds = rankItems.stream()
-                .filter(c -> StringUtils.equals(c.getExt().getOrDefault(CUSTOMER_FIELD_NAME, "").toString(), customer))
-                .map(AdRankItem::getAdId)
-                .map(Objects::toString)
-                .collect(Collectors.toList());
+        List<String> customerCreativeIds = rankItems.stream().filter(c -> StringUtils.equals(c.getExt().getOrDefault(CUSTOMER_FIELD_NAME, "").toString(), customer)).map(AdRankItem::getAdId).map(Objects::toString).collect(Collectors.toList());
         String cidKeyFormat = "ad:engine:cid:layer:info:%s:" + userLayer;
         List<HotRankFeatureInfo> creativeFeature = this.multiGetFeature(customerCreativeIds, cidKeyFormat);
         String chooseCreativeIdStr = this.choose(creativeFeature);
         Long chooseCreativeId = Long.parseLong(chooseCreativeIdStr);
 
-        Map<String, HotRankFeatureInfo> allCustomerFeatureMap = customerFeature.stream()
-                .collect(Collectors.toMap(HotRankFeatureInfo::getLabel, Function.identity(), (o1, o2) -> o1));
+        Map<String, HotRankFeatureInfo> allCustomerFeatureMap = customerFeature.stream().collect(Collectors.toMap(HotRankFeatureInfo::getLabel, Function.identity(), (o1, o2) -> o1));
 
-        Map<Long, HotRankFeatureInfo> allCreativeFeatureInfoMap = creativeFeature.stream()
-                .collect(Collectors.toMap(i -> Long.parseLong(i.getLabel()), Function.identity(), (o1, o2) -> o1));
+        Map<Long, HotRankFeatureInfo> allCreativeFeatureInfoMap = creativeFeature.stream().collect(Collectors.toMap(i -> Long.parseLong(i.getLabel()), Function.identity(), (o1, o2) -> o1));
 
         Map<String, String> sceneFeature = this.handleSceneFeature(System.currentTimeMillis() / 1000);
         Map<String, String> reqFeature = this.getReqFeature(scoreParam, request);
@@ -119,18 +108,17 @@ public class RankStrategyBy687 extends RankStrategyBasic {
 
     private String getUserLayer(RankRecommendRequestParam request) {
 
-        String userLayer = "无曝光";
 
-        String key = String.format("ad:engine:mid:layer:%s", request.getMid());
-        String value = algRedisHelper.get(key);
-        if (StringUtils.isNotEmpty(value)) {
-            userLayer = value;
-        }
+        Map<String, String> userLayer = this.getUserLayer(request.getMid());
+
+        String layer = userLayer.getOrDefault("layer", "无曝光");
+        String clazz = userLayer.getOrDefault("class", "其他");
+
         if (request.getIsFilterUser()) {
-            userLayer += "-炸";
+            return String.join("-", layer, "炸", clazz);
+        } else {
+            return String.join("-", layer, clazz);
         }
-
-        return userLayer;
     }
 
     private List<HotRankFeatureInfo> multiGetFeature(List<String> customers, String keyFormat) {