Преглед изворни кода

内部投流公众号 增加实验id

wangyunpeng пре 17 часа
родитељ
комит
13ea82867e

+ 30 - 8
api-module/src/main/java/com/tzld/piaoquan/api/service/strategy/impl/BuckStrategyV1.java

@@ -10,9 +10,11 @@ import com.tzld.piaoquan.api.model.bo.*;
 import com.tzld.piaoquan.api.model.po.AlgGhAutoreplyVideoRankData;
 import com.tzld.piaoquan.api.model.po.AlgGhAutoreplyVideoRankDataExample;
 import com.tzld.piaoquan.api.model.po.GhDetailExt;
+import com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformGzhPlanVideo;
 import com.tzld.piaoquan.api.model.vo.VideoCharacteristicVO;
 import com.tzld.piaoquan.api.service.GhDetailService;
 import com.tzld.piaoquan.api.service.VideoMultiService;
+import com.tzld.piaoquan.api.service.contentplatform.ContentPlatformPlanService;
 import com.tzld.piaoquan.api.service.strategy.ReplyStrategyService;
 import com.tzld.piaoquan.growth.common.common.enums.GhTypeEnum;
 import com.tzld.piaoquan.growth.common.common.enums.StrategyStatusEnum;
@@ -85,6 +87,8 @@ public class BuckStrategyV1 implements ReplyStrategyService {
     private VideoMultiService videoMultiService;
     @Autowired
     private GhDetailService ghDetailService;
+    @Autowired
+    private ContentPlatformPlanService contentPlatformPlanService;
 
     @Autowired
     private RedisUtils redisUtils;
@@ -105,9 +109,10 @@ public class BuckStrategyV1 implements ReplyStrategyService {
             // 1 处理文章--算法引擎--排序文章数据
 //            getWenzhangData();
             // 2 处理小程序--读取离线数据表--获取策略排序小程序数据
-            List<CgiReplyBucketData> smallDataCgiReplyList = readStrategyOrderSmallData(keyedSet, bucketDataParam);
+            Map<Long, String> videoTestIdMap = new HashMap<>();
+            List<CgiReplyBucketData> smallDataCgiReplyList = readStrategyOrderSmallData(keyedSet, bucketDataParam, videoTestIdMap);
             // 2.1 获取小程序落地页地址 http调用
-            smallDataCgiReplyList = setSmallPageUrl(smallDataCgiReplyList);
+            smallDataCgiReplyList = setSmallPageUrl(smallDataCgiReplyList, videoTestIdMap);
             log.info(JSON.toJSONString(smallDataCgiReplyList));
             // 3 入库读表
             insertSmallData(smallDataCgiReplyList, keyedSet, bucketDataParam);
@@ -351,7 +356,8 @@ public class BuckStrategyV1 implements ReplyStrategyService {
         }
     }
 
-    private List<CgiReplyBucketData> setSmallPageUrl(List<CgiReplyBucketData> smallDataCgiReplyList) {
+    private List<CgiReplyBucketData> setSmallPageUrl(List<CgiReplyBucketData> smallDataCgiReplyList,
+                                                     Map<Long, String> videoTestIdMap) {
         if (CollectionUtils.isEmpty(smallDataCgiReplyList)) {
             return smallDataCgiReplyList;
         }
@@ -393,7 +399,7 @@ public class BuckStrategyV1 implements ReplyStrategyService {
             if (CollectionUtils.isEmpty(cgiReplyBucketData)) {
                 // 库里不存在,调用新生成
                 String response = touLiuHttpClient.sendAdFlowAddRequest(GET_SMALL_PAGE_URL, videoId, putScene, channel,
-                        "自动", "公众号", "自动回复小程序", "位置" + sort, ghId, null);
+                        "自动", "公众号", "自动回复小程序", "位置" + sort, ghId, videoTestIdMap.get(Long.valueOf(videoId)));
                 JSONObject jsonObject = JSON.parseObject(response);
                 if (jsonObject.getInteger("code").equals(0)) {
                     smallPageUrlDetail = jsonObject.getObject("data", SmallPageUrlDetail.class);
@@ -426,11 +432,12 @@ public class BuckStrategyV1 implements ReplyStrategyService {
     }
 
 
-    private List<CgiReplyBucketData> readStrategyOrderSmallData(Set<String> keyedSet, BucketDataParam bucketDataParam) {
+    private List<CgiReplyBucketData> readStrategyOrderSmallData(Set<String> keyedSet, BucketDataParam bucketDataParam,
+                                                                Map<Long, String> videoTestIdMap) {
         List<CgiReplyBucketData> result = new ArrayList<>();
         if (Objects.equals(StrategyStatusEnum.DEFAULT.status, bucketDataParam.getStrategyStatus())) {
             for (String key : keyedSet) {
-                List<CgiReplyBucketData> defaultData = getDefaultData(bucketDataParam, key);
+                List<CgiReplyBucketData> defaultData = getDefaultData(bucketDataParam, key, videoTestIdMap);
                 if (!CollectionUtils.isEmpty(defaultData)) {
                     result.addAll(defaultData);
                 }
@@ -448,7 +455,7 @@ public class BuckStrategyV1 implements ReplyStrategyService {
         } else if (Objects.equals(StrategyStatusEnum.MIXED_STRATEGY.status, bucketDataParam.getStrategyStatus())) {
             for (String key : keyedSet) {
                 if (key.equals(MANUAL)) {
-                    List<CgiReplyBucketData> defaultData = getDefaultData(bucketDataParam, key);
+                    List<CgiReplyBucketData> defaultData = getDefaultData(bucketDataParam, key, videoTestIdMap);
                     if (!CollectionUtils.isEmpty(defaultData)) {
                         result.addAll(defaultData);
                     }
@@ -467,7 +474,8 @@ public class BuckStrategyV1 implements ReplyStrategyService {
     }
 
 
-    private List<CgiReplyBucketData> getDefaultData(BucketDataParam bucketDataParam, String key) {
+    private List<CgiReplyBucketData> getDefaultData(BucketDataParam bucketDataParam, String key,
+                                                    Map<Long, String> videoTestIdMap) {
         List<CgiReplyBucketData> result = new ArrayList<>();
         if (CollectionUtils.isEmpty(bucketDataParam.getVideos()) && CollectionUtils.isEmpty(bucketDataParam.getMiniPageDatas())) {
             return result;
@@ -500,6 +508,9 @@ public class BuckStrategyV1 implements ReplyStrategyService {
             String batchId1 = UUID.randomUUID().toString();
             int totalSize1 = bucketDataParam.getMiniPageDatas().size();
             Map<Long, VideoDetail> videoDetailMap = touLiuHttpClient.getVideoDetailRequest(bucketDataParam.getVideos());
+            List<ContentPlatformGzhPlanVideo> gzhPlanVideoList = contentPlatformPlanService.getGzhPlanVideoListByCooperateAccountId(bucketDataParam.getGhId());
+            Map<Long, ContentPlatformGzhPlanVideo> gzhPlanVideoMap = gzhPlanVideoList.stream()
+                    .collect(Collectors.toMap(ContentPlatformGzhPlanVideo::getVideoId, x -> x, (a, b) -> b));
             for (int i = 0; i < bucketDataParam.getMiniPageDatas().size(); i++) {
                 int sort = i + 1;
                 Long videoId = bucketDataParam.getVideos().get(i);
@@ -525,6 +536,10 @@ public class BuckStrategyV1 implements ReplyStrategyService {
                                 "?x-oss-process=image/resize,m_fill,w_600,h_480,limit_0/format,jpg/watermark,image_eXNoL3BpYy93YXRlcm1hcmtlci9pY29uX3BsYXlfd2hpdGUucG5nP3gtb3NzLXByb2Nlc3M9aW1hZ2UvcmVzaXplLHdfMTQ0,g_center");
                     }
                 }
+                ContentPlatformGzhPlanVideo gzhPlanVideo = gzhPlanVideoMap.get(videoId);
+                if (Objects.nonNull(gzhPlanVideo) && Objects.nonNull(videoDetail)) {
+                    videoTestIdMap.put(gzhPlanVideo.getVideoId(), gzhPlanVideo.getExperimentId());
+                }
                 cgiReplyBucketData.setTitle(miniPageData.getTitle());
                 cgiReplyBucketData.setMiniPagePath(miniPageData.getPage());
                 cgiReplyBucketData.setMiniAppId(SMALL_APP_Id);
@@ -553,6 +568,9 @@ public class BuckStrategyV1 implements ReplyStrategyService {
             String batchId2 = UUID.randomUUID().toString();
             int totalSize2 = bucketDataParam.getVideos().size();
             Map<Long, VideoDetail> videoDetailMap = touLiuHttpClient.getVideoDetailRequest(bucketDataParam.getVideos());
+            List<ContentPlatformGzhPlanVideo> gzhPlanVideoList = contentPlatformPlanService.getGzhPlanVideoListByCooperateAccountId(bucketDataParam.getGhId());
+            Map<Long, ContentPlatformGzhPlanVideo> gzhPlanVideoMap = gzhPlanVideoList.stream()
+                    .collect(Collectors.toMap(ContentPlatformGzhPlanVideo::getVideoId, x -> x, (a, b) -> b));
             for (int i = 0; i < bucketDataParam.getVideos().size(); i++) {
                 int sort = i + 1;
                 Long videoId = bucketDataParam.getVideos().get(i);
@@ -564,6 +582,10 @@ public class BuckStrategyV1 implements ReplyStrategyService {
                 cgiReplyBucketData.setGhId(bucketDataParam.getGhId());
                 cgiReplyBucketData.setMsgType(1);
                 VideoDetail videoDetail = videoDetailMap.get(videoId);
+                ContentPlatformGzhPlanVideo gzhPlanVideo = gzhPlanVideoMap.get(videoId);
+                if (Objects.nonNull(gzhPlanVideo) && Objects.nonNull(videoDetail)) {
+                    videoTestIdMap.put(gzhPlanVideo.getVideoId(), gzhPlanVideo.getExperimentId());
+                }
                 if (videoDetail != null && StringUtils.isNotEmpty(videoDetail.getCover())) {
                     cgiReplyBucketData.setCoverUrl(videoDetail.getCover());
                 }