Quellcode durchsuchen

pageUrl上报标题封面

wangyunpeng vor 1 Woche
Ursprung
Commit
1c0de17341

+ 85 - 0
long-article-server/src/main/java/com/tzld/piaoquan/longarticle/service/local/VideoMultiService.java

@@ -0,0 +1,85 @@
+package com.tzld.piaoquan.longarticle.service.local;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.tzld.piaoquan.longarticle.service.remote.ManagerApiService;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+
+import java.net.URLEncoder;
+import java.util.Objects;
+
+@Slf4j
+@Service
+public class VideoMultiService {
+
+    @Autowired
+    private ManagerApiService managerApiService;
+
+    public String setVideoMultiTitleCoverPagePath(Long videoId, String pageUrl, String title, String coverUrl) {
+        JSONArray multiTitleList = managerApiService.videoMultiTitleListV2(videoId);
+        JSONArray multiCoverList = managerApiService.videoMultiCoverListV2(videoId);
+        if (!CollectionUtils.isEmpty(multiTitleList)) {
+            Integer titleId = null;
+            for (int i = 0; i < multiTitleList.size(); i++) {
+                JSONObject item = multiTitleList.getJSONObject(i);
+                if (item.getInteger("source") == 0) {
+                    titleId = item.getInteger("id");
+                    break;
+                }
+            }
+            if (Objects.isNull(titleId)) {
+                for (int i = 0; i < multiTitleList.size(); i++) {
+                    JSONObject item = multiTitleList.getJSONObject(i);
+                    if (title.equals(item.getString("title"))) {
+                        titleId = item.getInteger("id");
+                        break;
+                    }
+                }
+            }
+            try {
+                if (Objects.nonNull(titleId) && !pageUrl.contains("shareTitleId")) {
+                    pageUrl += URLEncoder.encode("&shareTitleId=" + titleId, "UTF-8");
+                }
+                if (Objects.nonNull(title) && !pageUrl.contains("shareTitle")) {
+                    pageUrl += URLEncoder.encode("&shareTitle=" + title, "UTF-8");
+                }
+            } catch (Exception e) {
+                log.error("ThirdPartyPushMessageStrategyV1 insertSmallData setCustomerCoverTitleId Error,data:", e);
+            }
+        }
+        if (!CollectionUtils.isEmpty(multiCoverList)) {
+            Integer coverId = null;
+            for (int i = 0; i < multiCoverList.size(); i++) {
+                JSONObject item = multiCoverList.getJSONObject(i);
+                if (item.getInteger("source") == 0) {
+                    coverId = item.getInteger("id");
+                    break;
+                }
+            }
+            if (Objects.isNull(coverId)) {
+                for (int i = 0; i < multiCoverList.size(); i++) {
+                    JSONObject item = multiCoverList.getJSONObject(i);
+                    if (coverUrl.equals(item.getString("coverUrl"))) {
+                        coverId = item.getInteger("id");
+                        break;
+                    }
+                }
+            }
+            try {
+                if (Objects.nonNull(coverId) && !pageUrl.contains("shareImageId")) {
+                    pageUrl += URLEncoder.encode("&shareImageId=" + coverId, "UTF-8");
+                }
+                if (StringUtils.isNotEmpty(coverUrl) && !pageUrl.contains("shareImageUrl")) {
+                    pageUrl += URLEncoder.encode("&shareImageUrl=" + URLEncoder.encode(coverUrl, "UTF-8"), "UTF-8");
+                }
+            } catch (Exception e) {
+                log.error("ThirdPartyPushMessageStrategyV1 insertSmallData setCustomerCoverTitleId Error,data:", e);
+            }
+        }
+        return pageUrl;
+    }
+}

+ 20 - 21
long-article-server/src/main/java/com/tzld/piaoquan/longarticle/service/local/impl/CardServiceImpl.java

@@ -3,13 +3,12 @@ package com.tzld.piaoquan.longarticle.service.local.impl;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
-import com.tzld.piaoquan.longarticle.common.enums.ContentStatusEnum;
 import com.tzld.piaoquan.longarticle.common.enums.MatchResultStatusEnum;
-import com.tzld.piaoquan.longarticle.dao.mapper.longarticle.NewVideoCoverMapper;
 import com.tzld.piaoquan.longarticle.model.bo.VideoDetail;
 import com.tzld.piaoquan.longarticle.model.po.longarticle.*;
 import com.tzld.piaoquan.longarticle.model.vo.MatchMiniprogramStatusParam;
 import com.tzld.piaoquan.longarticle.service.local.CardService;
+import com.tzld.piaoquan.longarticle.service.local.VideoMultiService;
 import com.tzld.piaoquan.longarticle.service.remote.AigcService;
 import com.tzld.piaoquan.longarticle.service.remote.MatchService;
 import com.tzld.piaoquan.longarticle.service.remote.VideoService;
@@ -45,6 +44,10 @@ public class CardServiceImpl implements CardService {
 
     @ApolloJsonValue("${useShareImgPathList:[]}")
     private List<String> useShareImgPathList;
+    @ApolloJsonValue("${useSmallPlayImgPathList:[]}")
+    private List<String> useSmallPlayImgPathList;
+    @ApolloJsonValue("${crawlerImgPathList:[]}")
+    private List<String> crawlerImgPathList;
 
     @Autowired
     AigcService aigcService;
@@ -55,23 +58,16 @@ public class CardServiceImpl implements CardService {
     @Autowired
     private MatchService matchService;
 
-    private static final List<String> crawlerImgPathList = new ArrayList<String>() {{
-        add("20250208065525959973866");
-        add("20250208111811026884434");
-        add("20250212125646224172850");
-        add("20250213023808593788754");
-        add("20250213091337867990118");
-        add("20250214091843879629665");
-        add("20250214122110960857913");
-        add("20250217080347557694800");
-        add("20250217120153840400833");
-        add("20250304073234245880032");
-    }};
-
-    private static final List<String> useSmallPlayImgPathList = new ArrayList<String>();
+    @Autowired
+    private VideoMultiService videoMultiService;
 
 
-    public JSONObject createGzhPath(String videoId, String sharedUid, String ghId, Integer miniProgramType, Integer index) throws UnsupportedEncodingException {
+    public JSONObject createGzhPath(String videoId,
+                                    String sharedUid,
+                                    String ghId,
+                                    Integer miniProgramType,
+                                    Integer index,
+                                    PublishMiniprogram publishMiniprogram) throws UnsupportedEncodingException {
         String rootShareId = UUID.randomUUID().toString();
         String rootSourceId;
         switch (miniProgramType) {
@@ -111,6 +107,8 @@ public class CardServiceImpl implements CardService {
         String url = String.format("pages/user-videos?id=%s&su=%s&fromGzh=1&rootShareId=%s&shareId=%s&rootSourceId=%s",
                 videoId, sharedUid, rootShareId, rootShareId, rootSourceId);
         String productionPath = String.format("pages/category?jumpPage=%s", URLEncoder.encode(url, StandardCharsets.UTF_8.toString()));
+        productionPath = videoMultiService.setVideoMultiTitleCoverPagePath(Long.valueOf(videoId), productionPath,
+                publishMiniprogram.getVideoTitle(), publishMiniprogram.getVideoCover());
         JSONObject jsonObject = new JSONObject();
         jsonObject.put("rootShareId", rootShareId);
         jsonObject.put("rootSourceId", rootSourceId);
@@ -150,7 +148,6 @@ public class CardServiceImpl implements CardService {
 
         String videoId = videoDetail.getVideoId();
         String uid = videoDetail.getUid();
-        JSONObject jsonObject = createGzhPath(videoId, uid, planAccount.getGhId(), planAccount.getMiniprogramUseType(), index);
 
         PublishMiniprogram publishMiniprogram = new PublishMiniprogram();
         publishMiniprogram.setContentId(publishContent.getId());
@@ -178,14 +175,16 @@ public class CardServiceImpl implements CardService {
             publishMiniprogram.setVideoCover(videoDetail.getCoverImgPath());
         }
         publishMiniprogram.setVideoPath(videoDetail.getVideoPath());
-        publishMiniprogram.setProductionPath(jsonObject.getString("productionPath"));
-        publishMiniprogram.setRootSourceId(jsonObject.getString("rootSourceId"));
-        publishMiniprogram.setRootShareId(jsonObject.getString("rootShareId"));
         publishMiniprogram.setIndex(index);
         publishMiniprogram.setTraceId(videoDetail.getTraceId());
         publishMiniprogram.setCrawlerVideoId(videoDetail.getCrawlerVideoId());
         publishMiniprogram.setVideoOssPath(videoDetail.getVideoOss());
         publishMiniprogram.setUserId(videoDetail.getUid());
+
+        JSONObject jsonObject = createGzhPath(videoId, uid, planAccount.getGhId(), planAccount.getMiniprogramUseType(), index, publishMiniprogram);
+        publishMiniprogram.setProductionPath(jsonObject.getString("productionPath"));
+        publishMiniprogram.setRootSourceId(jsonObject.getString("rootSourceId"));
+        publishMiniprogram.setRootShareId(jsonObject.getString("rootShareId"));
         return publishMiniprogram;
     }
 

+ 18 - 0
long-article-server/src/main/java/com/tzld/piaoquan/longarticle/service/remote/ManagerApiService.java

@@ -0,0 +1,18 @@
+package com.tzld.piaoquan.longarticle.service.remote;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import org.springframework.stereotype.Component;
+
+@Component
+public interface ManagerApiService {
+
+    public JSONObject videoMultiTitleSave(Long videoId, String title);
+
+    public JSONObject videoMultiCoverSave(Long videoId, String coverUrl);
+
+    public JSONArray videoMultiCoverListV2(Long videoId);
+
+    public JSONArray videoMultiTitleListV2(Long videoId);
+
+}

+ 123 - 0
long-article-server/src/main/java/com/tzld/piaoquan/longarticle/service/remote/impl/ManagerApiServiceImpl.java

@@ -0,0 +1,123 @@
+package com.tzld.piaoquan.longarticle.service.remote.impl;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.tzld.piaoquan.longarticle.service.remote.ManagerApiService;
+import com.tzld.piaoquan.longarticle.utils.HttpClientUtil;
+import com.tzld.piaoquan.longarticle.utils.HttpPoolClientUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+import java.util.Objects;
+
+@Slf4j
+@Component
+public class ManagerApiServiceImpl implements ManagerApiService {
+
+    private static final HttpPoolClientUtil HTTP_POOL_CLIENT_UTIL_DEFAULT = HttpClientUtil.create(
+            5000, 10000, 20, 100, 3, 3000);
+
+    @Value("${manager.api.host:https://testadmin.piaoquantv.com/manager}")
+    private String managerApiHost;
+
+    public JSONObject videoMultiTitleSave(Long videoId, String title) {
+        String url = managerApiHost + "/video/multiTitleV2/saveNoAuth";
+        JSONObject res = null;
+        try {
+            JSONObject param = new JSONObject();
+            param.put("videoId", videoId);
+            param.put("title", title);
+            param.put("source", 1);
+            String post = HTTP_POOL_CLIENT_UTIL_DEFAULT.post(url, param.toJSONString());
+            res = JSONObject.parseObject(post);
+        } catch (Exception e) {
+            log.error("ManagerApiService videoMultiTitleSave error, videoId={} title={}",
+                    videoId, title, e);
+        }
+        if (Objects.isNull(res)) {
+            return null;
+        }
+        if (res.getInteger("code") != 0) {
+            log.error("ManagerApiService videoMultiTitleSave error, videoId={} title={} res={}",
+                    videoId, title, res);
+            return null;
+        }
+        return res.getJSONObject("content");
+    }
+
+    public JSONObject videoMultiCoverSave(Long videoId, String coverUrl) {
+        String url = managerApiHost + "/video/multiCover/saveNoAuth";
+        JSONObject res = null;
+        try {
+            JSONObject param = new JSONObject();
+            param.put("videoId", videoId);
+            param.put("coverUrl", coverUrl);
+            param.put("source", 1);
+            String post = HTTP_POOL_CLIENT_UTIL_DEFAULT.post(url, param.toJSONString());
+            res = JSONObject.parseObject(post);
+        } catch (Exception e) {
+            log.error("ManagerApiService videoMultiCoverSave error, videoId={} coverUrl={}",
+                    videoId, coverUrl, e);
+        }
+        if (Objects.isNull(res)) {
+            return null;
+        }
+        if (res.getInteger("code") != 0) {
+            log.error("ManagerApiService videoMultiCoverSave error, videoId={} coverUrl={} res={}",
+                    videoId, coverUrl, res);
+            return null;
+        }
+        return res.getJSONObject("content");
+    }
+
+    public JSONArray videoMultiCoverListV2(Long videoId) {
+        String url = managerApiHost + "/video/multiCover/listV2";
+        JSONObject res = null;
+        try {
+            JSONObject param = new JSONObject();
+            param.put("videoId", videoId);
+            param.put("range", "2h");
+            String post = HTTP_POOL_CLIENT_UTIL_DEFAULT.post(url, param.toJSONString());
+            res = JSONObject.parseObject(post);
+        } catch (Exception e) {
+            log.error("ManagerApiService videoMultiCoverListV2 error, videoId={} range={}",
+                    videoId, "2h", e);
+        }
+        if (Objects.isNull(res)) {
+            return null;
+        }
+        if (res.getInteger("code") != 0) {
+            log.error("ManagerApiService videoMultiCoverListV2 error, videoId={} range={} res={}",
+                    videoId, "2h", res);
+            return null;
+        }
+        return res.getJSONArray("content");
+    }
+
+    public JSONArray videoMultiTitleListV2(Long videoId) {
+        String url = managerApiHost + "/video/multiTitleV2/listV2";
+        JSONObject res = null;
+        try {
+            JSONObject param = new JSONObject();
+            param.put("videoId", videoId);
+            param.put("range", "4h");
+            String post = HTTP_POOL_CLIENT_UTIL_DEFAULT.post(url, param.toJSONString());
+            res = JSONObject.parseObject(post);
+        } catch (Exception e) {
+            log.error("ManagerApiService videoMultiCoverListV2 error, videoId={} range={}",
+                    videoId, "4h", e);
+        }
+        if (Objects.isNull(res)) {
+            return null;
+        }
+        if (res.getInteger("code") != 0) {
+            log.error("ManagerApiService videoMultiCoverListV2 error, videoId={} range={} res={}",
+                    videoId, "4h", res);
+            return null;
+        }
+        return res.getJSONArray("content");
+    }
+
+
+}