Browse Source

add feature read

丁云鹏 1 year ago
parent
commit
4a82a5a42e

+ 5 - 0
recommend-server-service/pom.xml

@@ -124,6 +124,11 @@
             <artifactId>recommend-server-client</artifactId>
             <version>1.0.0</version>
         </dependency>
+        <dependency>
+            <groupId>com.tzld.piaoquan</groupId>
+            <artifactId>recommend-feature-client</artifactId>
+            <version>1.0.0</version>
+        </dependency>
         <dependency>
             <groupId>com.google.protobuf</groupId>
             <artifactId>protobuf-java</artifactId>

+ 10 - 0
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/Application.java

@@ -1,8 +1,10 @@
 package com.tzld.piaoquan.recommend.server;
 
+import com.tzld.piaoquan.recommend.feature.client.FeatureClient;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
+import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.ComponentScan;
 import org.springframework.context.annotation.EnableAspectJAutoProxy;
 
@@ -13,6 +15,7 @@ import org.springframework.context.annotation.EnableAspectJAutoProxy;
 @ComponentScan({
         "com.tzld.piaoquan.recommend.server.service",
         "com.tzld.piaoquan.recommend.server.grpcservice",
+        "com.tzld.piaoquan.recommend.server.remote",
         "com.tzld.piaoquan.recommend.server.config",
         "com.tzld.piaoquan.recommend.server.web"
 })
@@ -22,4 +25,11 @@ public class Application {
     public static void main(String[] args) {
         SpringApplication.run(Application.class, args);
     }
+
+
+    @Bean
+    public FeatureClient featureClient() {
+        return new FeatureClient();
+    }
 }
+

+ 5 - 1
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/common/base/ItemFeature.java

@@ -10,13 +10,17 @@ public class ItemFeature {
 
     private String tags;
 
+    /**
+     * 有多个标题,暂时不会用到所以先不处理
+     * @since 2023-12-05
+     */
     private String title;
 
     private String titleLength;
 
     private String playLength;
 
-    private String totolTime;
+    private String totalTime;
 
     private String daysSinceUpload;
 

+ 110 - 0
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/remote/FeatureRemoteService.java

@@ -0,0 +1,110 @@
+package com.tzld.piaoquan.recommend.server.remote;
+
+import com.tzld.piaoquan.recommend.feature.client.FeatureClient;
+import com.tzld.piaoquan.recommend.feature.model.feature.UserActionFeatureProto;
+import com.tzld.piaoquan.recommend.feature.model.feature.UserFeatureProto;
+import com.tzld.piaoquan.recommend.feature.model.feature.VideoFeatureProto;
+import com.tzld.piaoquan.recommend.server.common.base.ItemFeature;
+import com.tzld.piaoquan.recommend.server.common.base.UserActionFeature;
+import com.tzld.piaoquan.recommend.server.common.base.UserFeature;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author dyp
+ */
+@Component
+@Slf4j
+public class FeatureRemoteService {
+
+    @Autowired
+    private FeatureClient client;
+
+    public UserFeature getUserFeature(String uid) {
+        if (StringUtils.isBlank(uid)) {
+            return null;
+        }
+        UserFeatureProto proto = client.getUserFeature(uid);
+        return convert(proto);
+    }
+
+    private UserFeature convert(UserFeatureProto proto) {
+        if (proto == null) {
+            return null;
+        }
+        UserFeature feature = new UserFeature();
+        feature.setMid(proto.getMid());
+        feature.setUid(proto.getUid());
+        if (proto.hasDay1CntFeature()) {
+            feature.setDay1_cnt_features(convert(proto.getDay1CntFeature()));
+        }
+        if (proto.hasDay3CntFeature()) {
+            feature.setDay3_cnt_features(convert(proto.getDay3CntFeature()));
+        }
+        if (proto.hasDay7CntFeature()) {
+            feature.setDay7_cnt_features(convert(proto.getDay7CntFeature()));
+        }
+        if (proto.hasMonth3CntFeature()) {
+            feature.setMonth3_cnt_features(convert(proto.getMonth3CntFeature()));
+        }
+        feature.setUser_cycle_bucket_7days(proto.getUserCycleBucket7Day());
+        feature.setUser_cycle_bucket_30days(proto.getUserCycleBucket30Day());
+        feature.setUser_share_bucket_30days(proto.getUserShareBucket30Day());
+
+        return feature;
+    }
+
+    private UserActionFeature convert(UserActionFeatureProto proto) {
+        UserActionFeature feature = new UserActionFeature();
+        feature.setClick_cnt(proto.getClickCnt());
+        feature.setCtr(proto.getCtr());
+        feature.setExp_cnt(proto.getExpCnt());
+        feature.setReturn_cnt(proto.getReturnCnt());
+        feature.setRov(proto.getRov());
+        feature.setShare_cnt(proto.getShareCnt());
+        feature.setStr(proto.getStr());
+        return feature;
+    }
+
+    public ItemFeature getVideoFeature(Long videoId) {
+        if (videoId == null) {
+            return null;
+        }
+        VideoFeatureProto proto = client.getVideoFeature(videoId);
+        return convert(proto);
+    }
+
+    private ItemFeature convert(VideoFeatureProto proto) {
+        if (proto == null) {
+            return null;
+        }
+        ItemFeature feature = new ItemFeature();
+
+        feature.setPlayLength(proto.getPlayLength());
+        feature.setTags(proto.getTags());
+        feature.setTotalTime(proto.getTotalTime());
+        feature.setUpId(proto.getUpId());
+        feature.setVideoId(proto.getVideoId());
+        feature.setDaysSinceUpload(proto.getDaysSinceUpload());
+
+        if (proto.hasVideoDay1CntFeature()) {
+            feature.setItem_day1_cnt_features(convert(proto.getVideoDay1CntFeature()));
+        }
+        if (proto.hasVideoDay3CntFeature()) {
+            feature.setItem_day3_cnt_features(convert(proto.getVideoDay3CntFeature()));
+        }
+        if (proto.hasVideoDay7CntFeature()) {
+            feature.setItem_day7_cnt_features(convert(proto.getVideoDay7CntFeature()));
+        }
+        if (proto.hasVideoMonth3CntFeature()) {
+            feature.setItem_month3_cnt_features(convert(proto.getVideoMonth3CntFeature()));
+        }
+
+
+        return feature;
+    }
+
+
+}