|
@@ -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;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|