Quellcode durchsuchen

增加保底视频设置

xueyiming vor 4 Monaten
Ursprung
Commit
b0dbcf8634

+ 9 - 3
api-module/src/main/java/com/tzld/piaoquan/api/component/TouLiuHttpClient.java

@@ -2,6 +2,7 @@ package com.tzld.piaoquan.api.component;
 
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.tzld.piaoquan.api.model.bo.VideoDetail;
 import com.tzld.piaoquan.growth.common.component.HttpPoolClient;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -53,8 +54,8 @@ public class TouLiuHttpClient {
     }
 
 
-    public Map<Long, String> getVideoDetailRequest(List<Long> videoIds) {
-        Map<Long, String> map = new HashMap<>();
+    public Map<Long, VideoDetail> getVideoDetailRequest(List<Long> videoIds) {
+        Map<Long, VideoDetail> map = new HashMap<>();
         try {
             String url = "https://longvideoapi.piaoquantv.com/longvideoapi/openapi/video/batchSelectVideoInfo";
             JSONObject params = new JSONObject();
@@ -66,7 +67,12 @@ public class TouLiuHttpClient {
                 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.setId(videoId);
+                videoDetail.setCover(shareImgPath);
+                videoDetail.setTitle(title);
+                map.put(videoId, videoDetail);
             }
         } catch (Exception e) {
             log.error("getVideoDetailRequest error", e);

+ 4 - 0
api-module/src/main/java/com/tzld/piaoquan/api/model/bo/BucketDataParam.java

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

+ 13 - 0
api-module/src/main/java/com/tzld/piaoquan/api/model/bo/VideoDetail.java

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

+ 11 - 5
api-module/src/main/java/com/tzld/piaoquan/api/service/impl/ThirdPartyServiceImpl.java

@@ -1,6 +1,7 @@
 package com.tzld.piaoquan.api.service.impl;
 
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
 import com.aliyun.odps.data.Record;
 import com.tzld.piaoquan.api.common.enums.GhTypeEnum;
 import com.tzld.piaoquan.api.common.enums.ReplyStrategyServiceEnum;
@@ -84,7 +85,8 @@ public class ThirdPartyServiceImpl implements ThirdPartyService {
         if (CollectionUtils.isEmpty(ghDetails)) {
             return CommonResponse.create(404, "ghId不存在,请联系管理员配置");
         }
-        String channel = ghDetails.get(0).getChannel();
+        GhDetail ghDetail = ghDetails.get(0);
+        String channel = ghDetail.getChannel();
         if (channel == null) {
             LarkRobotUtil.sendMessage("channel不存在,请查看详情 ghId=", param.getGhId());
             return CommonResponse.create(404, "ghId异常,请联系管理员检查");
@@ -95,7 +97,7 @@ public class ThirdPartyServiceImpl implements ThirdPartyService {
             return CommonResponse.create(404, "ghId异常,请联系管理员检查");
         }
         List<PushMessageVo> pushMessageVoList = new ArrayList<>();
-        ReplyBucketData replyBucketData = getPushMessageData(param, channel);
+        ReplyBucketData replyBucketData = getPushMessageData(ghDetail);
         log.info("replyBucketData={}", JSON.toJSONString(replyBucketData));
         if (replyBucketData == null) {
             log.error("获取推送策略数据失败");
@@ -169,15 +171,19 @@ public class ThirdPartyServiceImpl implements ThirdPartyService {
         return CommonResponse.success(res);
     }
 
-    private ReplyBucketData getPushMessageData(PushMessageParam param, String channel) {
+    private ReplyBucketData getPushMessageData(GhDetail ghDetail) {
         log.info("strategyServiceMap={}", JSON.toJSONString(strategyServiceMap));
         for (Map.Entry<String, ReplyStrategyService> stringReplyStrategyServiceEntry : strategyServiceMap.entrySet()) {
             ReplyStrategyService replyStrategyService = stringReplyStrategyServiceEntry.getValue();
             // 使用策略层
             if (replyStrategyService.support(ReplyStrategyServiceEnum.THIRD_PARTY_PUSH_MESSAGE_STRATEGY_V1)) {
                 BucketDataParam bucketDataParam = new BucketDataParam();
-                bucketDataParam.setGhId(param.getGhId());
-                bucketDataParam.setChannel(channel);
+                bucketDataParam.setGhId(ghDetail.getGhId());
+                bucketDataParam.setChannel(ghDetail.getChannel());
+                bucketDataParam.setStrategyStatus(ghDetail.getStrategyStatus());
+                if (StringUtils.isNotEmpty(ghDetail.getVideoIds())) {
+                    bucketDataParam.setVideos(JSONArray.parseArray(ghDetail.getVideoIds(), Long.class));
+                }
                 return replyStrategyService.getResult(bucketDataParam);
             }
         }

+ 77 - 37
api-module/src/main/java/com/tzld/piaoquan/api/service/strategy/impl/ThirdPartyPushMessageStrategyV1.java

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 
 import com.tzld.piaoquan.api.common.enums.ReplyStrategyServiceEnum;
+import com.tzld.piaoquan.api.common.enums.StrategyStatusEnum;
 import com.tzld.piaoquan.api.component.TouLiuHttpClient;
 import com.tzld.piaoquan.api.dao.mapper.AlgGhAutoreplyVideoRankDataMapper;
 import com.tzld.piaoquan.api.dao.mapper.CgiReplyBucketDataMapper;
@@ -40,6 +41,9 @@ public class ThirdPartyPushMessageStrategyV1 implements ReplyStrategyService {
      */
     private static final String bucketStrategyConfig = "{\"3rd-party-base\":[0,1,2,3,4,5,6],\"3rd-party-explore1\":[7],\"3rd-party-explore2\":[8,9]}";
 
+
+    private static final String manualConfig = "{\"manual\":[0,1,2,3,4,5,6,7,8,9]}";
+
     /**
      * 自动回复使用小程序Id
      */
@@ -61,8 +65,13 @@ public class ThirdPartyPushMessageStrategyV1 implements ReplyStrategyService {
     public ReplyBucketData getResult(BucketDataParam bucketDataParam) {
         log.info("ThirdPartyPushMessageStrategyV1 start");
         // 0 获取策略key
-        JSONObject bucketStrategyConfigJsonObject = JSON.parseObject(bucketStrategyConfig);
-        Set<String> keyedSet = bucketStrategyConfigJsonObject.keySet();
+        JSONObject configJsonObject;
+        if (Objects.equals(StrategyStatusEnum.DEFAULT.status, bucketDataParam.getStrategyStatus())) {
+            configJsonObject = JSON.parseObject(manualConfig);
+        } else {
+            configJsonObject = JSON.parseObject(bucketStrategyConfig);
+        }
+        Set<String> keyedSet = configJsonObject.keySet();
         // 1 处理文章--算法引擎--排序文章数据
 //        getWenzhangData();
         // 2 处理小程序--读取离线数据表--获取策略排序小程序数据
@@ -73,7 +82,7 @@ public class ThirdPartyPushMessageStrategyV1 implements ReplyStrategyService {
         // 3 入库读表
         insertSmallData(smallDataCgiReplyList, keyedSet, bucketDataParam);
         // 4 组装分桶数据
-        return getReplyBucketData(bucketStrategyConfigJsonObject, keyedSet, bucketDataParam.getGhId());
+        return getReplyBucketData(configJsonObject, keyedSet, bucketDataParam.getGhId());
     }
 
     private ReplyBucketData getReplyBucketData(JSONObject bucketStrategyConfigJsonObject, Set<String> keyedSet, String ghId) {
@@ -208,41 +217,72 @@ public class ThirdPartyPushMessageStrategyV1 implements ReplyStrategyService {
                 // base作为人工控制
                 continue;
             }
-            // 获取最新dt的策略
-            String dtVersion = algGhAutoreplyVideoRankDataMapper.selectLatestDtVersionByStrategyKeyAndGhId(key, bucketDataParam.getGhId());
-            if (StringUtils.isEmpty(dtVersion)) {
-                continue;
-            }
-            // 判断当前的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 = touLiuHttpClient.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;
                 }
-                cgiReplyBucketData.setMiniAppId(SMALL_APP_Id);
-                cgiReplyBucketData.setMiniVideoId(x.getVideoId());
-                return cgiReplyBucketData;
-            }).collect(Collectors.toList()));
+                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;
+                }
+                Map<Long, VideoDetail> videoDetailMap = touLiuHttpClient.getVideoDetailRequest(bucketDataParam.getVideos());
+                int sort = 1;
+                for (Long videoId : bucketDataParam.getVideos()) {
+                    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;
+                }
+                // 获取最新dt数据
+                List<AlgGhAutoreplyVideoRankData> dtVersionStrategyData = getDtVersionStrategyData(key, dtVersion, bucketDataParam.getGhId());
+                List<Long> videoIds = dtVersionStrategyData.stream().map(AlgGhAutoreplyVideoRankData::getVideoId).collect(Collectors.toList());
+                Map<Long, VideoDetail> videoDetailMap = touLiuHttpClient.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;

+ 4 - 4
api-module/src/main/java/com/tzld/piaoquan/api/service/strategy/impl/WeComPushMessageStrategyV1.java

@@ -223,7 +223,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 = touLiuHttpClient.getVideoDetailRequest(videoIds);
+            Map<Long, VideoDetail> videoDetailMap = touLiuHttpClient.getVideoDetailRequest(videoIds);
             result.addAll(dtVersionStrategyData.stream().map(x -> {
                 CgiReplyBucketData cgiReplyBucketData = new CgiReplyBucketData();
                 cgiReplyBucketData.setStrategy(key);
@@ -232,9 +232,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());
                 }