Sfoglia il codice sorgente

feat:特征服务优化适配

zhaohaipeng 1 mese fa
parent
commit
1a0fd6db28

+ 26 - 0
ad-engine-server/src/test/java/com/tzld/piaoquan/ad/engine/service/FeatureServiceTest.java

@@ -0,0 +1,26 @@
+package com.tzld.piaoquan.ad.engine.service;
+
+import com.tzld.piaoquan.ad.engine.server.Application;
+import com.tzld.piaoquan.ad.engine.service.feature.FeatureService;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+
+@SpringBootTest(classes = Application.class)
+public class FeatureServiceTest {
+
+
+    @Autowired
+    private FeatureService featureService;
+
+    @Test
+    public void featureV3OptimizeTest() {
+
+        // List<FeatureKeyProto> protos = new ArrayList<>();
+        // protos.add(featureService.genWithKeyMap("o:%s:%s", "alg_videoid_feature", "10035427", ImmutableMap.of("videoid", "68781839")));
+
+        // System.out.println(featureService.invokeFeatureService(protos));
+    }
+
+
+}

+ 13 - 5
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/feature/FeatureService.java

@@ -13,6 +13,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.tuple.Pair;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
 
 import java.util.*;
@@ -21,6 +22,9 @@ import java.util.*;
 @Component
 public class FeatureService {
 
+    @Value("${feature.service.optimize.switch}")
+    private Boolean featureServiceOptimizeSwtich;
+
     @Autowired
     private FeatureV2RemoteService remoteService;
 
@@ -246,7 +250,7 @@ public class FeatureService {
     }
 
 
-    public Feature invokeFeatureService(List<FeatureKeyProto> protos) {
+    private Feature invokeFeatureService(List<FeatureKeyProto> protos) {
 
         Map<String, String> featureMap = remoteService.getFeature(protos);
         if (featureMap == null) {
@@ -430,10 +434,14 @@ public class FeatureService {
         for (Map.Entry<String, String> entry : metaFeatureMap.entrySet()) {
             String key = entry.getKey();
             try {
-                Map<String, String> valueMap = JSONUtils.fromJson(entry.getValue(), new TypeToken<Map<String, String>>() {
-                }, Collections.emptyMap());
-                String value = valueMap.getOrDefault("feature", "{}");
-                newFeatureMap.put(key, value);
+                if (Boolean.TRUE.equals(featureServiceOptimizeSwtich)) {
+                    newFeatureMap.put(key, entry.getValue());
+                } else {
+                    Map<String, String> valueMap = JSONUtils.fromJson(entry.getValue(), new TypeToken<Map<String, String>>() {
+                    }, Collections.emptyMap());
+                    String value = valueMap.getOrDefault("feature", "{}");
+                    newFeatureMap.put(key, value);
+                }
             } catch (Exception e) {
                 log.error("featureStrCover error: ", e);
             }

+ 11 - 1
pom.xml

@@ -330,7 +330,17 @@
             <version>2.0.23</version>
         </dependency>
 
-
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <scope>test</scope>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.junit.vintage</groupId>
+                    <artifactId>junit-vintage-engine</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
 
         <!--easyexcel-->
     </dependencies>