Browse Source

Merge branch 'dev-xym-update-strategy' of Server/long-article-recommend into master

xueyiming 4 months ago
parent
commit
eddefe1c14

+ 13 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/model/bo/VideoDetail.java

@@ -0,0 +1,13 @@
+package com.tzld.longarticle.recommend.server.model.bo;
+
+import lombok.Data;
+
+@Data
+public class VideoDetail {
+
+    private String id;
+
+    private String cover;
+
+    private String title;
+}

+ 4 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/model/cgi/BucketDataParam.java

@@ -21,4 +21,8 @@ public class BucketDataParam {
 
     private String channel;
 
+    private Integer strategyStatus;
+
+    private List<Long> videos;
+
 }

+ 8 - 3
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/cgi/TouLiuHttpClientService.java

@@ -3,6 +3,7 @@ package com.tzld.longarticle.recommend.server.service.cgi;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.tzld.longarticle.recommend.server.model.bo.VideoDetail;
 import com.tzld.longarticle.recommend.server.model.cgi.GroupData;
 import org.springframework.http.MediaType;
 import org.springframework.stereotype.Service;
@@ -80,8 +81,8 @@ public class TouLiuHttpClientService {
         return JSON.parseArray(block, GroupData.class);
     }
 
-    public static Map<Long, String> getVideoDetailRequest(List<Long> videoIds) {
-        Map<Long, String> map = new HashMap<>();
+    public static Map<Long, VideoDetail> getVideoDetailRequest(List<Long> videoIds) {
+        Map<Long, VideoDetail> map = new HashMap<>();
         JSONObject params = new JSONObject();
         params.put("videoIdList", videoIds);
         WebClient webClient = WebClient.builder()
@@ -102,7 +103,11 @@ public class TouLiuHttpClientService {
             JSONObject jsonObject = data.getJSONObject(i);
             Long videoId = jsonObject.getLong("id");
             String shareImgPath = jsonObject.getString("shareImgPath");
-            map.put(videoId, shareImgPath);
+            String title = jsonObject.getString("title");
+            VideoDetail videoDetail = new VideoDetail();
+            videoDetail.setCover(shareImgPath);
+            videoDetail.setTitle(title);
+            map.put(videoId, videoDetail);
         }
         return map;
     }

+ 6 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/cgi/impl/CgiReplyServiceImpl.java

@@ -1,6 +1,7 @@
 package com.tzld.longarticle.recommend.server.service.cgi.impl;
 
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
 import com.tzld.longarticle.recommend.server.common.enums.GhTypeEnum;
 import com.tzld.longarticle.recommend.server.common.enums.cgi.ReplyStrategyServiceEnum;
 import com.tzld.longarticle.recommend.server.mapper.growth.GhDetailMapper;
@@ -12,6 +13,7 @@ import com.tzld.longarticle.recommend.server.repository.model.GhDetailExample;
 import com.tzld.longarticle.recommend.server.service.cgi.CgiReplyService;
 import com.tzld.longarticle.recommend.server.service.strategy.reply.ReplyStrategyService;
 import com.tzld.longarticle.recommend.server.util.LarkRobotUtil;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.ApplicationContext;
 import org.springframework.stereotype.Service;
@@ -52,6 +54,10 @@ public class CgiReplyServiceImpl implements CgiReplyService {
         GhDetail ghDetail = ghDetails.get(0);
         if (Objects.equals(ghDetail.getType(), GhTypeEnum.THIRD_PARTY_GH.type)) {
             bucketDataParam.setChannel(ghDetail.getChannel());
+            bucketDataParam.setStrategyStatus(ghDetail.getStrategyStatus());
+            if (StringUtils.isNotEmpty(ghDetail.getVideoIds())) {
+                bucketDataParam.setVideos(JSONArray.parseArray(ghDetail.getVideoIds(), Long.class));
+            }
             return getPushMessageData(bucketDataParam);
         }
         return getRgiBucketData(bucketDataParam);

+ 5 - 4
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/strategy/reply/impl/BuckStrategyV1.java

@@ -7,6 +7,7 @@ import com.tzld.longarticle.recommend.server.common.enums.cgi.ReplyStrategyServi
 import com.tzld.longarticle.recommend.server.mapper.growth.AlgGhAutoreplyVideoRankDataMapper;
 import com.tzld.longarticle.recommend.server.mapper.growth.CgiReplyBucketDataMapper;
 import com.tzld.longarticle.recommend.server.mapper.growth.GhDetailMapper;
+import com.tzld.longarticle.recommend.server.model.bo.VideoDetail;
 import com.tzld.longarticle.recommend.server.model.cgi.*;
 import com.tzld.longarticle.recommend.server.repository.model.*;
 import com.tzld.longarticle.recommend.server.service.cgi.TouLiuHttpClientService;
@@ -270,7 +271,7 @@ public class BuckStrategyV1 implements ReplyStrategyService {
             // 获取最新dt数据
             List<AlgGhAutoreplyVideoRankData> dtVersionStrategyData = getDtVersionStrategyData(key, dtVersion);
             List<Long> videoIds = dtVersionStrategyData.stream().map(AlgGhAutoreplyVideoRankData::getVideoId).collect(Collectors.toList());
-            Map<Long, String> videoDetailMap = TouLiuHttpClientService.getVideoDetailRequest(videoIds);
+            Map<Long, VideoDetail> videoDetailMap = TouLiuHttpClientService.getVideoDetailRequest(videoIds);
             result.addAll(dtVersionStrategyData.stream().map(x -> {
                 CgiReplyBucketData cgiReplyBucketData = new CgiReplyBucketData();
                 cgiReplyBucketData.setStrategy(key);
@@ -279,9 +280,9 @@ public class BuckStrategyV1 implements ReplyStrategyService {
                 cgiReplyBucketData.setGhId(x.getGhId());
                 cgiReplyBucketData.setMsgType(1);
                 cgiReplyBucketData.setTitle(x.getTitle());
-                String cover = videoDetailMap.get(x.getVideoId());
-                if (StringUtils.isNotEmpty(cover)) {
-                    cgiReplyBucketData.setCoverUrl(cover);
+                VideoDetail videoDetail = videoDetailMap.get(x.getVideoId());
+                if (videoDetail !=null && StringUtils.isNotEmpty(videoDetail.getCover())) {
+                    cgiReplyBucketData.setCoverUrl(videoDetail.getCover());
                 } else {
                     cgiReplyBucketData.setCoverUrl(CDN_URL + x.getCoverUrl());
                 }

+ 68 - 31
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/strategy/reply/impl/PushMessageStrategyV1.java

@@ -2,9 +2,11 @@ package com.tzld.longarticle.recommend.server.service.strategy.reply.impl;
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+import com.tzld.longarticle.recommend.server.common.enums.StrategyStatusEnum;
 import com.tzld.longarticle.recommend.server.common.enums.cgi.ReplyStrategyServiceEnum;
 import com.tzld.longarticle.recommend.server.mapper.growth.AlgGhAutoreplyVideoRankDataMapper;
 import com.tzld.longarticle.recommend.server.mapper.growth.CgiReplyBucketDataMapper;
+import com.tzld.longarticle.recommend.server.model.bo.VideoDetail;
 import com.tzld.longarticle.recommend.server.model.cgi.*;
 import com.tzld.longarticle.recommend.server.repository.model.AlgGhAutoreplyVideoRankData;
 import com.tzld.longarticle.recommend.server.repository.model.AlgGhAutoreplyVideoRankDataExample;
@@ -12,6 +14,7 @@ import com.tzld.longarticle.recommend.server.repository.model.CgiReplyBucketData
 import com.tzld.longarticle.recommend.server.repository.model.CgiReplyBucketDataExample;
 import com.tzld.longarticle.recommend.server.service.cgi.TouLiuHttpClientService;
 import com.tzld.longarticle.recommend.server.service.strategy.reply.ReplyStrategyService;
+import com.tzld.longarticle.recommend.server.util.DateUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.BeanUtils;
@@ -207,38 +210,72 @@ public class PushMessageStrategyV1 implements ReplyStrategyService {
                 // base作为人工控制
                 continue;
             }
-            // 获取最新dt的策略
-            String dtVersion = algGhAutoreplyVideoRankDataMapper.selectLatestDtVersionByStrategyKeyAndGhId(key, bucketDataParam.getGhId());
-            // 判断当前的dtVersion是否已经处理过了
-            CgiReplyBucketDataExample cgiReplyBucketDataExample = new CgiReplyBucketDataExample();
-            cgiReplyBucketDataExample.createCriteria().andIsDeleteEqualTo(0).andStrategyDtEqualTo(dtVersion).andStrategyEqualTo(key).andGhIdEqualTo(bucketDataParam.getGhId());
-            long count = cgiReplyBucketDataMapper.countByExample(cgiReplyBucketDataExample);
-            if (count != 0) {
-                // 说明已处理过该dtVersion数据
-                continue;
-            }
-            // 获取最新dt数据
-            List<AlgGhAutoreplyVideoRankData> dtVersionStrategyData = getDtVersionStrategyData(key, dtVersion, bucketDataParam.getGhId());
-            List<Long> videoIds = dtVersionStrategyData.stream().map(AlgGhAutoreplyVideoRankData::getVideoId).collect(Collectors.toList());
-            Map<Long, String> videoDetailMap = TouLiuHttpClientService.getVideoDetailRequest(videoIds);
-            result.addAll(dtVersionStrategyData.stream().map(x -> {
-                CgiReplyBucketData cgiReplyBucketData = new CgiReplyBucketData();
-                cgiReplyBucketData.setStrategy(key);
-                cgiReplyBucketData.setSort(x.getSort());
-                cgiReplyBucketData.setStrategyDt(x.getDtVersion());
-                cgiReplyBucketData.setGhId(x.getGhId());
-                cgiReplyBucketData.setMsgType(1);
-                cgiReplyBucketData.setTitle(x.getTitle());
-                String cover = videoDetailMap.get(x.getVideoId());
-                if (StringUtils.isNotEmpty(cover)) {
-                    cgiReplyBucketData.setCoverUrl(cover);
-                } else {
-                    cgiReplyBucketData.setCoverUrl(CDN_URL + x.getCoverUrl());
+            if (Objects.equals(StrategyStatusEnum.DEFAULT.status, bucketDataParam.getStrategyStatus())) {
+                if (CollectionUtils.isEmpty(bucketDataParam.getVideos())) {
+                    return null;
+                }
+                Map<Long, VideoDetail> videoDetailMap = TouLiuHttpClientService.getVideoDetailRequest(bucketDataParam.getVideos());
+                int sort = 1;
+                for (Long videoId : bucketDataParam.getVideos()) {
+                    CgiReplyBucketDataExample cgiReplyBucketDataExample = new CgiReplyBucketDataExample();
+                    cgiReplyBucketDataExample.createCriteria().andIsDeleteEqualTo(0).andStrategyEqualTo(key)
+                            .andGhIdEqualTo(bucketDataParam.getGhId()).andMiniVideoIdIn(bucketDataParam.getVideos());
+                    long count = cgiReplyBucketDataMapper.countByExample(cgiReplyBucketDataExample);
+                    if (count == bucketDataParam.getVideos().size()) {
+                        // 已经存在就不处理
+                        continue;
+                    }
+                    CgiReplyBucketData cgiReplyBucketData = new CgiReplyBucketData();
+                    cgiReplyBucketData.setStrategy(key);
+                    cgiReplyBucketData.setSort(sort);
+                    cgiReplyBucketData.setGhId(bucketDataParam.getGhId());
+                    cgiReplyBucketData.setMsgType(1);
+                    VideoDetail videoDetail = videoDetailMap.get(videoId);
+                    if (videoDetail != null && StringUtils.isNotEmpty(videoDetail.getCover())) {
+                        cgiReplyBucketData.setCoverUrl(videoDetail.getCover());
+                    }
+                    if (videoDetail != null && StringUtils.isNotEmpty(videoDetail.getTitle())) {
+                        cgiReplyBucketData.setTitle(videoDetail.getTitle());
+                    }
+                    cgiReplyBucketData.setMiniAppId(SMALL_APP_Id);
+                    cgiReplyBucketData.setMiniVideoId(videoId);
+                    result.add(cgiReplyBucketData);
+                    sort++;
+                }
+            } else {
+                // 获取最新dt的策略
+                String dtVersion = algGhAutoreplyVideoRankDataMapper.selectLatestDtVersionByStrategyKeyAndGhId(key, bucketDataParam.getGhId());
+                // 判断当前的dtVersion是否已经处理过了
+                CgiReplyBucketDataExample cgiReplyBucketDataExample = new CgiReplyBucketDataExample();
+                cgiReplyBucketDataExample.createCriteria().andIsDeleteEqualTo(0).andStrategyDtEqualTo(dtVersion).andStrategyEqualTo(key).andGhIdEqualTo(bucketDataParam.getGhId());
+                long count = cgiReplyBucketDataMapper.countByExample(cgiReplyBucketDataExample);
+                if (count != 0) {
+                    // 说明已处理过该dtVersion数据
+                    continue;
                 }
-                cgiReplyBucketData.setMiniAppId(SMALL_APP_Id);
-                cgiReplyBucketData.setMiniVideoId(x.getVideoId());
-                return cgiReplyBucketData;
-            }).collect(Collectors.toList()));
+                // 获取最新dt数据
+                List<AlgGhAutoreplyVideoRankData> dtVersionStrategyData = getDtVersionStrategyData(key, dtVersion, bucketDataParam.getGhId());
+                List<Long> videoIds = dtVersionStrategyData.stream().map(AlgGhAutoreplyVideoRankData::getVideoId).collect(Collectors.toList());
+                Map<Long, VideoDetail> videoDetailMap = TouLiuHttpClientService.getVideoDetailRequest(videoIds);
+                result.addAll(dtVersionStrategyData.stream().map(x -> {
+                    CgiReplyBucketData cgiReplyBucketData = new CgiReplyBucketData();
+                    cgiReplyBucketData.setStrategy(key);
+                    cgiReplyBucketData.setSort(x.getSort());
+                    cgiReplyBucketData.setStrategyDt(x.getDtVersion());
+                    cgiReplyBucketData.setGhId(x.getGhId());
+                    cgiReplyBucketData.setMsgType(1);
+                    cgiReplyBucketData.setTitle(x.getTitle());
+                    VideoDetail videoDetail = videoDetailMap.get(x.getVideoId());
+                    if (videoDetail != null && StringUtils.isNotEmpty(videoDetail.getCover())) {
+                        cgiReplyBucketData.setCoverUrl(videoDetail.getCover());
+                    } else {
+                        cgiReplyBucketData.setCoverUrl(CDN_URL + x.getCoverUrl());
+                    }
+                    cgiReplyBucketData.setMiniAppId(SMALL_APP_Id);
+                    cgiReplyBucketData.setMiniVideoId(x.getVideoId());
+                    return cgiReplyBucketData;
+                }).collect(Collectors.toList()));
+            }
         }
         // 获取最新数据版本
         return CollectionUtils.isEmpty(result) ? null : result;

+ 5 - 4
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/strategy/reply/impl/WeComPushMessageStrategyV1.java

@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.tzld.longarticle.recommend.server.common.enums.cgi.ReplyStrategyServiceEnum;
 import com.tzld.longarticle.recommend.server.mapper.growth.AlgGhAutoreplyVideoRankDataMapper;
 import com.tzld.longarticle.recommend.server.mapper.growth.CgiReplyBucketDataMapper;
+import com.tzld.longarticle.recommend.server.model.bo.VideoDetail;
 import com.tzld.longarticle.recommend.server.model.cgi.*;
 import com.tzld.longarticle.recommend.server.repository.model.AlgGhAutoreplyVideoRankData;
 import com.tzld.longarticle.recommend.server.repository.model.AlgGhAutoreplyVideoRankDataExample;
@@ -220,7 +221,7 @@ public class WeComPushMessageStrategyV1 implements ReplyStrategyService {
             // 获取最新dt数据
             List<AlgGhAutoreplyVideoRankData> dtVersionStrategyData = getDtVersionStrategyData(key, dtVersion, bucketDataParam.getGhId());
             List<Long> videoIds = dtVersionStrategyData.stream().map(AlgGhAutoreplyVideoRankData::getVideoId).collect(Collectors.toList());
-            Map<Long, String> videoDetailMap = TouLiuHttpClientService.getVideoDetailRequest(videoIds);
+            Map<Long, VideoDetail> videoDetailMap = TouLiuHttpClientService.getVideoDetailRequest(videoIds);
             result.addAll(dtVersionStrategyData.stream().map(x -> {
                 CgiReplyBucketData cgiReplyBucketData = new CgiReplyBucketData();
                 cgiReplyBucketData.setStrategy(key);
@@ -229,9 +230,9 @@ public class WeComPushMessageStrategyV1 implements ReplyStrategyService {
                 cgiReplyBucketData.setGhId(x.getGhId());
                 cgiReplyBucketData.setMsgType(1);
                 cgiReplyBucketData.setTitle(x.getTitle());
-                String cover = videoDetailMap.get(x.getVideoId());
-                if (StringUtils.isNotEmpty(cover)) {
-                    cgiReplyBucketData.setCoverUrl(cover);
+                VideoDetail videoDetail = videoDetailMap.get(x.getVideoId());
+                if (videoDetail != null && StringUtils.isNotEmpty(videoDetail.getCover())) {
+                    cgiReplyBucketData.setCoverUrl(videoDetail.getCover());
                 } else {
                     cgiReplyBucketData.setCoverUrl(CDN_URL + x.getCoverUrl());
                 }