Browse Source

修改自动回复

xueyiming 1 week ago
parent
commit
86966507b6

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

@@ -25,6 +25,8 @@ public class BucketDataParam {
 
     private List<Long> videos;
 
+    private List<MiniPageData> miniPageDatas;
+
     private String rate;
 
     private String contentDetail;

+ 15 - 0
api-module/src/main/java/com/tzld/piaoquan/api/model/bo/MiniPageData.java

@@ -0,0 +1,15 @@
+package com.tzld.piaoquan.api.model.bo;
+
+import lombok.Data;
+import lombok.ToString;
+
+@Data
+@ToString
+public class MiniPageData {
+
+    private String page;
+
+    private String title;
+
+    private String cover;
+}

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

@@ -277,16 +277,25 @@ public class BuckStrategyV1 implements ReplyStrategyService {
         if (CollectionUtils.isEmpty(smallDataCgiReplyList)) {
             return smallDataCgiReplyList;
         }
+        boolean hasPage = true;
+        for (CgiReplyBucketData cgiReplyBucketData : smallDataCgiReplyList) {
+            if (StringUtils.isEmpty(cgiReplyBucketData.getMiniPagePath())) {
+                hasPage = false;
+            }
+        }
+        if (hasPage) {
+            return smallDataCgiReplyList;
+        }
         String putScene = "touliu";
         String channel = "tencentgzh";
         String ghId1 = smallDataCgiReplyList.get(0).getGhId();
         JSONObject rootSourceConfigs = JSON.parseObject(rootSourceConfig);
         JSONObject jsonObject1 = rootSourceConfigs.getJSONObject(ghId1);
-        if(jsonObject1 != null){
-            if(StringUtils.isNotEmpty(jsonObject1.getString("putScene"))){
+        if (jsonObject1 != null) {
+            if (StringUtils.isNotEmpty(jsonObject1.getString("putScene"))) {
                 putScene = jsonObject1.getString("putScene");
             }
-            if(StringUtils.isNotEmpty(jsonObject1.getString("channel"))){
+            if (StringUtils.isNotEmpty(jsonObject1.getString("channel"))) {
                 channel = jsonObject1.getString("channel");
             }
         }
@@ -381,7 +390,7 @@ public class BuckStrategyV1 implements ReplyStrategyService {
 
     private List<CgiReplyBucketData> getDefaultData(BucketDataParam bucketDataParam, String key) {
         List<CgiReplyBucketData> result = new ArrayList<>();
-        if (CollectionUtils.isEmpty(bucketDataParam.getVideos())) {
+        if (CollectionUtils.isEmpty(bucketDataParam.getVideos()) && CollectionUtils.isEmpty(bucketDataParam.getMiniPageDatas())) {
             return result;
         }
 
@@ -389,58 +398,95 @@ public class BuckStrategyV1 implements ReplyStrategyService {
         countExample.createCriteria().andIsDeleteEqualTo(0).andStrategyEqualTo(key)
                 .andGhIdEqualTo(bucketDataParam.getGhId());
         long allCount = cgiReplyBucketDataMapper.countByExample(countExample);
-        if (allCount == bucketDataParam.getVideos().size()) {
-            int existNum = 0;
+        if (!CollectionUtils.isEmpty(bucketDataParam.getVideos())) {
+            if (allCount == bucketDataParam.getVideos().size()) {
+                int existNum = 0;
+                for (int i = 0; i < bucketDataParam.getVideos().size(); i++) {
+                    int sort = i + 1;
+                    Long videoId = bucketDataParam.getVideos().get(i);
+                    CgiReplyBucketDataExample cgiReplyBucketDataExample = new CgiReplyBucketDataExample();
+                    cgiReplyBucketDataExample.createCriteria().andIsDeleteEqualTo(0).andStrategyEqualTo(key)
+                            .andGhIdEqualTo(bucketDataParam.getGhId()).andMiniVideoIdEqualTo(videoId).andSortEqualTo(sort);
+                    long count = cgiReplyBucketDataMapper.countByExample(cgiReplyBucketDataExample);
+                    if (count > 0) {
+                        existNum++;
+                    }
+                }
+                if (existNum == bucketDataParam.getVideos().size()) {
+                    return null;
+                }
+            }
             for (int i = 0; i < bucketDataParam.getVideos().size(); i++) {
                 int sort = i + 1;
                 Long videoId = bucketDataParam.getVideos().get(i);
-                CgiReplyBucketDataExample cgiReplyBucketDataExample = new CgiReplyBucketDataExample();
-                cgiReplyBucketDataExample.createCriteria().andIsDeleteEqualTo(0).andStrategyEqualTo(key)
-                        .andGhIdEqualTo(bucketDataParam.getGhId()).andMiniVideoIdEqualTo(videoId).andSortEqualTo(sort);
-                long count = cgiReplyBucketDataMapper.countByExample(cgiReplyBucketDataExample);
-                if (count > 0) {
-                    existNum++;
+                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));
+                CgiReplyBucketData cgiReplyBucketData = new CgiReplyBucketData();
+                cgiReplyBucketData.setStrategy(key);
+                cgiReplyBucketData.setSort(sort);
+                cgiReplyBucketData.setGhId(bucketDataParam.getGhId());
+                cgiReplyBucketData.setMsgType(1);
+                VideoDetail videoDetail = videoDetailMap.get(videoId);
+                ContentPlatformGzhPlanVideo gzhPlanVideo = gzhPlanVideoMap.get(videoId);
+                // 内容合作平台视频标题和封面
+                if (Objects.nonNull(gzhPlanVideo) && Objects.nonNull(videoDetail)) {
+                    cgiReplyBucketData.setTitle(ContentPlatformPlanService.getVideoTitle(gzhPlanVideo));
+                    String cover = ContentPlatformPlanService.getVideoCover(gzhPlanVideo);
+                    if (StringUtils.isNotEmpty(cover)) {
+                        String coverSuffix = videoDetail.getCover().substring(videoDetail.getCover().indexOf("?"));
+                        if (cover.contains("?") && cover.contains("image/resize")) {
+                            coverSuffix = videoDetail.getCover().substring(videoDetail.getCover().indexOf("/watermark"));
+                        }
+                        cgiReplyBucketData.setCoverUrl(cover + coverSuffix);
+                    }
+                } else {
+                    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);
             }
-            if (existNum == bucketDataParam.getVideos().size()) {
-                return null;
-            }
-        }
-        for (int i = 0; i < bucketDataParam.getVideos().size(); i++) {
-            int sort = i + 1;
-            Long videoId = bucketDataParam.getVideos().get(i);
-            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));
-            CgiReplyBucketData cgiReplyBucketData = new CgiReplyBucketData();
-            cgiReplyBucketData.setStrategy(key);
-            cgiReplyBucketData.setSort(sort);
-            cgiReplyBucketData.setGhId(bucketDataParam.getGhId());
-            cgiReplyBucketData.setMsgType(1);
-            VideoDetail videoDetail = videoDetailMap.get(videoId);
-            ContentPlatformGzhPlanVideo gzhPlanVideo = gzhPlanVideoMap.get(videoId);
-            // 内容合作平台视频标题和封面
-            if (Objects.nonNull(gzhPlanVideo) && Objects.nonNull(videoDetail)) {
-                cgiReplyBucketData.setTitle(ContentPlatformPlanService.getVideoTitle(gzhPlanVideo));
-                String cover = ContentPlatformPlanService.getVideoCover(gzhPlanVideo);
-                if (StringUtils.isNotEmpty(cover)) {
-                    String coverSuffix = videoDetail.getCover().substring(videoDetail.getCover().indexOf("?"));
-                    if (cover.contains("?") && cover.contains("image/resize")) {
-                        coverSuffix = videoDetail.getCover().substring(videoDetail.getCover().indexOf("/watermark"));
+        } else if (!CollectionUtils.isEmpty(bucketDataParam.getMiniPageDatas())) {
+            if (allCount == bucketDataParam.getVideos().size()) {
+                int existNum = 0;
+                for (int i = 0; i < bucketDataParam.getMiniPageDatas().size(); i++) {
+                    int sort = i + 1;
+                    MiniPageData miniPageData = bucketDataParam.getMiniPageDatas().get(i);
+                    CgiReplyBucketDataExample cgiReplyBucketDataExample = new CgiReplyBucketDataExample();
+                    cgiReplyBucketDataExample.createCriteria().andIsDeleteEqualTo(0).andStrategyEqualTo(key)
+                            .andGhIdEqualTo(bucketDataParam.getGhId()).andMiniPagePathEqualTo(miniPageData.getPage()).andSortEqualTo(sort);
+                    long count = cgiReplyBucketDataMapper.countByExample(cgiReplyBucketDataExample);
+                    if (count > 0) {
+                        existNum++;
                     }
-                    cgiReplyBucketData.setCoverUrl(cover + coverSuffix);
-                }
-            } else {
-                if (videoDetail != null && StringUtils.isNotEmpty(videoDetail.getCover())) {
-                    cgiReplyBucketData.setCoverUrl(videoDetail.getCover());
                 }
-                if (videoDetail != null && StringUtils.isNotEmpty(videoDetail.getTitle())) {
-                    cgiReplyBucketData.setTitle(videoDetail.getTitle());
+                if (existNum == bucketDataParam.getMiniPageDatas().size()) {
+                    return null;
                 }
             }
-            cgiReplyBucketData.setMiniAppId(SMALL_APP_Id);
-            cgiReplyBucketData.setMiniVideoId(videoId);
-            result.add(cgiReplyBucketData);
+
+            for (int i = 0; i < bucketDataParam.getMiniPageDatas().size(); i++) {
+                int sort = i + 1;
+                MiniPageData miniPageData = bucketDataParam.getMiniPageDatas().get(i);
+                CgiReplyBucketData cgiReplyBucketData = new CgiReplyBucketData();
+                cgiReplyBucketData.setStrategy(key);
+                cgiReplyBucketData.setSort(sort);
+                cgiReplyBucketData.setGhId(bucketDataParam.getGhId());
+                cgiReplyBucketData.setMsgType(1);
+                cgiReplyBucketData.setCoverUrl(miniPageData.getCover());
+                cgiReplyBucketData.setTitle(miniPageData.getTitle());
+                cgiReplyBucketData.setMiniPagePath(miniPageData.getPage());
+                cgiReplyBucketData.setMiniAppId(SMALL_APP_Id);
+                result.add(cgiReplyBucketData);
+            }
+        } else {
+            return null;
         }
         return result;
     }

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

@@ -182,6 +182,15 @@ public class ThirdPartyPushMessageStrategyV1 implements ReplyStrategyService {
         if (CollectionUtils.isEmpty(smallDataCgiReplyList)) {
             return smallDataCgiReplyList;
         }
+        boolean hasPage = true;
+        for (CgiReplyBucketData cgiReplyBucketData : smallDataCgiReplyList) {
+            if (StringUtils.isEmpty(cgiReplyBucketData.getMiniPagePath())) {
+                hasPage = false;
+            }
+        }
+        if (hasPage) {
+            return smallDataCgiReplyList;
+        }
         Set<String> keys = smallDataCgiReplyList.stream().map(x -> x.getGhId() + "&" + x.getMiniVideoId() + "&" + x.getSort()).collect(Collectors.toSet());
         Map<String, SmallPageUrlDetail> keyPageUrl = new HashMap<>();
         // gh-id + videoId + sort 复用同一page_url及落地页id
@@ -237,69 +246,106 @@ public class ThirdPartyPushMessageStrategyV1 implements ReplyStrategyService {
                 continue;
             }
             if (Objects.equals(StrategyStatusEnum.DEFAULT.status, bucketDataParam.getStrategyStatus())) {
-                if (CollectionUtils.isEmpty(bucketDataParam.getVideos())) {
+                if (CollectionUtils.isEmpty(bucketDataParam.getVideos()) && CollectionUtils.isEmpty(bucketDataParam.getMiniPageDatas())) {
                     return null;
                 }
                 CgiReplyBucketDataExample countExample = new CgiReplyBucketDataExample();
                 countExample.createCriteria().andIsDeleteEqualTo(0).andStrategyEqualTo(key)
                         .andGhIdEqualTo(bucketDataParam.getGhId());
                 long allCount = cgiReplyBucketDataMapper.countByExample(countExample);
-                if (allCount == bucketDataParam.getVideos().size()) {
-                    int existNum = 0;
+                if (!CollectionUtils.isEmpty(bucketDataParam.getVideos())) {
+                    if (allCount == bucketDataParam.getVideos().size()) {
+                        int existNum = 0;
+                        for (int i = 0; i < bucketDataParam.getVideos().size(); i++) {
+                            int sort = i + 1;
+                            Long videoId = bucketDataParam.getVideos().get(i);
+                            CgiReplyBucketDataExample cgiReplyBucketDataExample = new CgiReplyBucketDataExample();
+                            cgiReplyBucketDataExample.createCriteria().andIsDeleteEqualTo(0).andStrategyEqualTo(key)
+                                    .andGhIdEqualTo(bucketDataParam.getGhId()).andMiniVideoIdEqualTo(videoId).andSortEqualTo(sort);
+                            long count = cgiReplyBucketDataMapper.countByExample(cgiReplyBucketDataExample);
+                            if (count > 0) {
+                                existNum++;
+                            }
+                        }
+                        if (existNum == bucketDataParam.getVideos().size()) {
+                            continue;
+                        }
+                    }
+                    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);
-                        CgiReplyBucketDataExample cgiReplyBucketDataExample = new CgiReplyBucketDataExample();
-                        cgiReplyBucketDataExample.createCriteria().andIsDeleteEqualTo(0).andStrategyEqualTo(key)
-                                .andGhIdEqualTo(bucketDataParam.getGhId()).andMiniVideoIdEqualTo(videoId).andSortEqualTo(sort);
-                        long count = cgiReplyBucketDataMapper.countByExample(cgiReplyBucketDataExample);
-                        if (count > 0) {
-                            existNum++;
-                        }
-                    }
-                    if (existNum == bucketDataParam.getVideos().size()) {
-                        continue;
-                    }
-                }
-                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);
-                    CgiReplyBucketData cgiReplyBucketData = new CgiReplyBucketData();
-                    cgiReplyBucketData.setStrategy(key);
-                    cgiReplyBucketData.setSort(sort);
-                    cgiReplyBucketData.setGhId(bucketDataParam.getGhId());
-                    cgiReplyBucketData.setMsgType(1);
-                    VideoDetail videoDetail = videoDetailMap.get(videoId);
-                    ContentPlatformGzhPlanVideo gzhPlanVideo = gzhPlanVideoMap.get(videoId);
-                    // 内容合作平台视频标题和封面
-                    if (Objects.nonNull(gzhPlanVideo) && Objects.nonNull(videoDetail)) {
-                        cgiReplyBucketData.setTitle(ContentPlatformPlanService.getVideoTitle(gzhPlanVideo));
-                        String cover = ContentPlatformPlanService.getVideoCover(gzhPlanVideo);
-                        if (StringUtils.isNotEmpty(cover)) {
-                            String coverSuffix = videoDetail.getCover().substring(videoDetail.getCover().indexOf("?"));
-                            if (cover.contains("?") && cover.contains("image/resize")) {
-                                coverSuffix = videoDetail.getCover().substring(videoDetail.getCover().indexOf("/watermark"));
+                        CgiReplyBucketData cgiReplyBucketData = new CgiReplyBucketData();
+                        cgiReplyBucketData.setStrategy(key);
+                        cgiReplyBucketData.setSort(sort);
+                        cgiReplyBucketData.setGhId(bucketDataParam.getGhId());
+                        cgiReplyBucketData.setMsgType(1);
+                        VideoDetail videoDetail = videoDetailMap.get(videoId);
+                        ContentPlatformGzhPlanVideo gzhPlanVideo = gzhPlanVideoMap.get(videoId);
+                        // 内容合作平台视频标题和封面
+                        if (Objects.nonNull(gzhPlanVideo) && Objects.nonNull(videoDetail)) {
+                            cgiReplyBucketData.setTitle(ContentPlatformPlanService.getVideoTitle(gzhPlanVideo));
+                            String cover = ContentPlatformPlanService.getVideoCover(gzhPlanVideo);
+                            if (StringUtils.isNotEmpty(cover)) {
+                                String coverSuffix = videoDetail.getCover().substring(videoDetail.getCover().indexOf("?"));
+                                if (cover.contains("?") && cover.contains("image/resize")) {
+                                    coverSuffix = videoDetail.getCover().substring(videoDetail.getCover().indexOf("/watermark"));
+                                }
+                                if (!cover.contains("yishihui")) {
+                                    coverSuffix = "?x-oss-process=image/resize,m_fill,w_600,h_480,limit_0/format,jpg";
+                                }
+                                cgiReplyBucketData.setCoverUrl(cover + coverSuffix);
+                            }
+                        } else {
+                            if (videoDetail != null && StringUtils.isNotEmpty(videoDetail.getCover())) {
+                                cgiReplyBucketData.setCoverUrl(videoDetail.getCover());
                             }
-                            if (!cover.contains("yishihui")) {
-                                coverSuffix = "?x-oss-process=image/resize,m_fill,w_600,h_480,limit_0/format,jpg";
+                            if (videoDetail != null && StringUtils.isNotEmpty(videoDetail.getTitle())) {
+                                cgiReplyBucketData.setTitle(videoDetail.getTitle());
                             }
-                            cgiReplyBucketData.setCoverUrl(cover + coverSuffix);
                         }
-                    } else {
-                        if (videoDetail != null && StringUtils.isNotEmpty(videoDetail.getCover())) {
-                            cgiReplyBucketData.setCoverUrl(videoDetail.getCover());
+                        cgiReplyBucketData.setMiniAppId(SMALL_APP_Id);
+                        cgiReplyBucketData.setMiniVideoId(videoId);
+                        result.add(cgiReplyBucketData);
+                    }
+
+                } else if (!CollectionUtils.isEmpty(bucketDataParam.getMiniPageDatas())) {
+                    if (allCount == bucketDataParam.getVideos().size()) {
+                        int existNum = 0;
+                        for (int i = 0; i < bucketDataParam.getMiniPageDatas().size(); i++) {
+                            int sort = i + 1;
+                            MiniPageData miniPageData = bucketDataParam.getMiniPageDatas().get(i);
+                            CgiReplyBucketDataExample cgiReplyBucketDataExample = new CgiReplyBucketDataExample();
+                            cgiReplyBucketDataExample.createCriteria().andIsDeleteEqualTo(0).andStrategyEqualTo(key)
+                                    .andGhIdEqualTo(bucketDataParam.getGhId()).andMiniPagePathEqualTo(miniPageData.getPage()).andSortEqualTo(sort);
+                            long count = cgiReplyBucketDataMapper.countByExample(cgiReplyBucketDataExample);
+                            if (count > 0) {
+                                existNum++;
+                            }
                         }
-                        if (videoDetail != null && StringUtils.isNotEmpty(videoDetail.getTitle())) {
-                            cgiReplyBucketData.setTitle(videoDetail.getTitle());
+                        if (existNum == bucketDataParam.getMiniPageDatas().size()) {
+                            return null;
                         }
                     }
-                    cgiReplyBucketData.setMiniAppId(SMALL_APP_Id);
-                    cgiReplyBucketData.setMiniVideoId(videoId);
-                    result.add(cgiReplyBucketData);
+                    for (int i = 0; i < bucketDataParam.getMiniPageDatas().size(); i++) {
+                        int sort = i + 1;
+                        MiniPageData miniPageData = bucketDataParam.getMiniPageDatas().get(i);
+                        CgiReplyBucketData cgiReplyBucketData = new CgiReplyBucketData();
+                        cgiReplyBucketData.setStrategy(key);
+                        cgiReplyBucketData.setSort(sort);
+                        cgiReplyBucketData.setGhId(bucketDataParam.getGhId());
+                        cgiReplyBucketData.setMsgType(1);
+                        cgiReplyBucketData.setCoverUrl(miniPageData.getCover());
+                        cgiReplyBucketData.setTitle(miniPageData.getTitle());
+                        cgiReplyBucketData.setMiniPagePath(miniPageData.getPage());
+                        cgiReplyBucketData.setMiniAppId(SMALL_APP_Id);
+                        result.add(cgiReplyBucketData);
+                    }
+                } else {
+                    return null;
                 }
             } else {
                 // 获取最新dt的策略