xueyiming 7 ماه پیش
والد
کامیت
325e5dd21f

+ 32 - 58
long-article-server/src/main/java/com/tzld/piaoquan/longarticle/service/local/impl/ContentServiceImpl.java

@@ -32,10 +32,7 @@ public class ContentServiceImpl implements ContentService {
     private CrawlerVideoMapper crawlerVideoMapper;
 
     @Autowired
-    private PublishMiniprogramMapper publishMiniprogramMapper;
-
-    @Autowired
-    private PublishContentMapper publishContentMapper;
+    private PublicContentServiceImpl publicContentService;
 
 
     public MatchVideo getContent(String contentId, String ghId, Integer publishFlag) {
@@ -49,16 +46,6 @@ public class ContentServiceImpl implements ContentService {
         return matchVideos.get(0);
     }
 
-    public List<PublishMiniprogram> getPublishMiniprograms(PublishArticleData publishArticleData) {
-        PublishMiniprogramExample publishMiniprogramExample = new PublishMiniprogramExample();
-        publishMiniprogramExample.createCriteria().andPublishContentIdEqualTo(publishArticleData.getId());
-        List<PublishMiniprogram> publishMiniprograms = publishMiniprogramMapper.selectByExample(publishMiniprogramExample);
-        if (CollectionUtils.isEmpty(publishMiniprograms)) {
-            return new ArrayList<>();
-        }
-        return publishMiniprograms;
-    }
-
     public void updateMatchContent(PublishContent publishContent, String ghId, JSONArray jsonArray) {
         try {
             MatchVideoExample matchVideoExample = new MatchVideoExample();
@@ -77,60 +64,47 @@ public class ContentServiceImpl implements ContentService {
             updateMatchVideo.setPublishFlag(2);
             updateMatchVideo.setResponse(jsonArray.toJSONString());
             matchVideoMapper.updateByPrimaryKeySelective(updateMatchVideo);
-            updatePublishContentTraceId(traceId, publishContent.getId());
+            publicContentService.updatePublishContentTraceId(traceId, publishContent.getId());
         } catch (Exception e) {
             log.error("updateMatchContent error", e);
         }
     }
 
-    public void updatePublishContentTraceId(String traceId, Long publishContentId) {
-        if (StringUtils.isEmpty(traceId)) {
-            return;
-        }
-        PublishContent publishContent = new PublishContent();
-        publishContent.setTraceId(traceId);
-        publishContent.setId(publishContentId);
-        publishContentMapper.updateByPrimaryKeySelective(publishContent);
-    }
-
-    public void updatePublishContentStatus(Integer status, Long publishContentId, String reason) {
-        PublishContent publishContent = new PublishContent();
-        publishContent.setStatus(status);
-        publishContent.setId(publishContentId);
-        publishContent.setReason(reason);
-        publishContentMapper.updateByPrimaryKeySelective(publishContent);
-    }
-
 
     public List<CrawlerVideo> getContentMiniVideo(PublishArticleData publishArticleData, PlanAccount planAccount) {
-        CrawlerVideoExample example = new CrawlerVideoExample();
-        example.setOrderByClause("score desc");
-        example.createCriteria().andDownloadStatusEqualTo(2).andContentIdEqualTo(publishArticleData.getSourceId());
-        List<CrawlerVideo> crawlerVideoList = crawlerVideoMapper.selectByExample(example);
-        List<CrawlerVideo> videoList;
-        switch (publishArticleData.getContentPoolType()) {
-            case "autoArticlePoolLevel4":
-                // 冷启层,全量做
-                videoList = shuffleList(crawlerVideoList).subList(0, Math.min(crawlerVideoList.size(), 3));
-                break;
-            case "autoArticlePoolLevel3":
-                //次条,只针对具体账号做
-                if (ghIdMap.containsKey(planAccount.getGhId())) {
+        try {
+            CrawlerVideoExample example = new CrawlerVideoExample();
+            example.setOrderByClause("score desc");
+            example.createCriteria().andDownloadStatusEqualTo(2).andContentIdEqualTo(publishArticleData.getSourceId());
+            List<CrawlerVideo> crawlerVideoList = crawlerVideoMapper.selectByExample(example);
+            List<CrawlerVideo> videoList;
+            switch (publishArticleData.getContentPoolType()) {
+                case "autoArticlePoolLevel4":
+                    // 冷启层,全量做
                     videoList = shuffleList(crawlerVideoList).subList(0, Math.min(crawlerVideoList.size(), 3));
-                } else {
+                    break;
+                case "autoArticlePoolLevel3":
+                    //次条,只针对具体账号做
+                    if (ghIdMap.containsKey(planAccount.getGhId())) {
+                        videoList = shuffleList(crawlerVideoList).subList(0, Math.min(crawlerVideoList.size(), 3));
+                    } else {
+                        videoList = crawlerVideoList.subList(0, Math.min(crawlerVideoList.size(), 3));
+                    }
+                    break;
+                case "autoArticlePoolLevel1":
+                    // 头条,先不做
+                    videoList = crawlerVideoList.subList(0, Math.min(crawlerVideoList.size(), 3));
+                    break;
+                default:
                     videoList = crawlerVideoList.subList(0, Math.min(crawlerVideoList.size(), 3));
-                }
-                break;
-            case "autoArticlePoolLevel1":
-                // 头条,先不做
-                videoList = crawlerVideoList.subList(0, Math.min(crawlerVideoList.size(), 3));
-                break;
-            default:
-                videoList = crawlerVideoList.subList(0, Math.min(crawlerVideoList.size(), 3));
-                break;
+                    break;
+            }
+            log.info("getContentMiniVideo videoList={}", videoList);
+            return videoList;
+        } catch (Exception e) {
+            log.error("getContentMiniVideo error", e);
         }
-
-        return videoList;
+        return new ArrayList<>();
     }
 
     private <T> List<T> shuffleList(List<T> oriList) {

+ 26 - 42
long-article-server/src/main/java/com/tzld/piaoquan/longarticle/service/local/impl/CoreServiceImpl.java

@@ -396,6 +396,7 @@ public class CoreServiceImpl implements CoreService {
             waitingSortParam.setPageNum(1);
             waitingSortParam.setPageSize(planAccount.getPublishPreNum());
             LongArticleSystemContentVO longArticleSystemContentVO = aigcService.listWaitingSortContents(waitingSortParam);
+            log.info("aigcService.listWaitingSortContents={}", longArticleSystemContentVO);
             if (longArticleSystemContentVO == null
                     || longArticleSystemContentVO.getTotalCount() < planAccount.getPublishPreMinNum()
                     || CollectionUtils.isEmpty(longArticleSystemContentVO.getContentItemList())
@@ -469,45 +470,38 @@ public class CoreServiceImpl implements CoreService {
                 }
                 sendIds.add(publishContent.getId());
                 //获取小程序
-                List<PublishMiniprogram> publishMiniprogramList = contentService.getPublishMiniprograms(publishArticleData);
+                List<PublishMiniprogram> publishMiniprogramList = publicContentService.getPublishMiniprograms(publishArticleData);
 
                 //不存在则重新生成
                 if (CollectionUtils.isEmpty(publishMiniprogramList)) {
                     List<CrawlerVideo> contentVideos =
                             contentService.getContentMiniVideo(publishArticleData, planAccount);
                     List<VideoDetail> videoDetails = new ArrayList<>();
-                    //发布小程序
-                    for (CrawlerVideo crawlerVideo : contentVideos) {
-                        Integer crawlerVideoId = crawlerVideo.getId();
-                        String videoOssPath = crawlerVideo.getVideoOssPath();
-                        String platform = crawlerVideo.getPlatform();
-                        String userId = crawlerVideo.getUserId();
-                        String traceId = crawlerVideo.getTraceId();
-                        String kimiTitle;
-                        LongArticlesText kimiText = kimiService.getKimiText(crawlerVideo.getContentId());
-                        if (kimiText != null && StringUtils.isNotEmpty(kimiText.getKimiTitle())) {
-                            kimiTitle = kimiText.getKimiTitle();
-                        } else {
-                            kimiTitle = crawlerVideo.getVideoTitle();
-                        }
-                        VideoDetail publish = videoService.publish(crawlerVideoId, videoOssPath, userId, kimiTitle, platform, traceId);
-                        if (publish == null) {
-                            continue;
+                    if (!CollectionUtils.isEmpty(contentVideos)) {
+                        //发布小程序
+                        for (CrawlerVideo crawlerVideo : contentVideos) {
+                            Integer crawlerVideoId = crawlerVideo.getId();
+                            String videoOssPath = crawlerVideo.getVideoOssPath();
+                            String platform = crawlerVideo.getPlatform();
+                            String userId = crawlerVideo.getUserId();
+                            String traceId = crawlerVideo.getTraceId();
+                            String kimiTitle;
+                            LongArticlesText kimiText = kimiService.getKimiText(crawlerVideo.getContentId());
+                            if (kimiText != null && StringUtils.isNotEmpty(kimiText.getKimiTitle())) {
+                                kimiTitle = kimiText.getKimiTitle();
+                            } else {
+                                kimiTitle = crawlerVideo.getVideoTitle();
+                            }
+                            VideoDetail publish = videoService.publish(crawlerVideoId, videoOssPath, userId, kimiTitle, platform, traceId);
+                            if (publish == null) {
+                                continue;
+                            }
+                            videoDetails.add(publish);
                         }
-                        videoDetails.add(publish);
                     }
+                    log.info("videoDetails={}", videoDetails);
                     if (videoDetails.size() < 2) {
-                        MatchMiniprogramStatusParam statusParam = new MatchMiniprogramStatusParam();
-                        statusParam.setStatus(3);
-                        statusParam.setPublishContentId(publishContent.getPublishContentId());
-                        statusParam.setErrorMsg("小程序视频数量不足");
-                        aigcService.updateMatchMiniprogramStatus(statusParam);
-
-                        PublishContent update = new PublishContent();
-                        update.setId(publishContent.getId());
-                        update.setStatus(3);
-                        update.setReason("小程序数量不足");
-                        publishContentMapper.updateByPrimaryKeySelective(update);
+                        publicContentService.delPublishContent(publishContent);
                         continue;
                     }
                     String ghId = planAccount.getGhId();
@@ -586,17 +580,7 @@ public class CoreServiceImpl implements CoreService {
                     publishCardList.add(param);
                 }
                 if (publishCardList.size() < 2) {
-                    MatchMiniprogramStatusParam statusParam = new MatchMiniprogramStatusParam();
-                    statusParam.setStatus(3);
-                    statusParam.setPublishContentId(publishContent.getPublishContentId());
-                    statusParam.setErrorMsg("小程序视频数量不足");
-                    aigcService.updateMatchMiniprogramStatus(statusParam);
-
-                    PublishContent update = new PublishContent();
-                    update.setId(publishContent.getId());
-                    update.setStatus(3);
-                    update.setReason("小程序数量不足");
-                    publishContentMapper.updateByPrimaryKeySelective(update);
+                    publicContentService.delPublishContent(publishContent);
                     continue;
                 }
                 contentParam.setPublishContentId(publishContent.getPublishContentId());
@@ -688,7 +672,7 @@ public class CoreServiceImpl implements CoreService {
             PlanAccount planAccount = planAccountService.getPlanAccountById(planAccountId);
             if (updateStatus == 2) {
                 for (PublishContent publishContent : entry.getValue()) {
-                    contentService.updatePublishContentStatus(updateStatus, publishContent.getId(), pushStatusVO.getErrorMsg());
+                    publicContentService.updatePublishContentStatus(updateStatus, publishContent.getId(), pushStatusVO.getErrorMsg());
                     if (StringUtils.isNotEmpty(publishContent.getTraceId())) {
                         videoService.miniProgramVideoOff(publishContent.getTraceId());
                     } else {

+ 53 - 3
long-article-server/src/main/java/com/tzld/piaoquan/longarticle/service/local/impl/PublicContentServiceImpl.java

@@ -1,25 +1,35 @@
 package com.tzld.piaoquan.longarticle.service.local.impl;
 
 import com.tzld.piaoquan.longarticle.dao.mapper.PublishContentMapper;
+import com.tzld.piaoquan.longarticle.dao.mapper.PublishMiniprogramMapper;
 import com.tzld.piaoquan.longarticle.model.dto.PublishArticleData;
-import com.tzld.piaoquan.longarticle.model.po.PlanAccount;
-import com.tzld.piaoquan.longarticle.model.po.PublishContent;
-import com.tzld.piaoquan.longarticle.model.po.PublishContentExample;
+import com.tzld.piaoquan.longarticle.model.po.*;
+import com.tzld.piaoquan.longarticle.model.vo.MatchMiniprogramStatusParam;
+import com.tzld.piaoquan.longarticle.service.remote.AigcService;
 import com.tzld.piaoquan.longarticle.utils.DateUtil;
+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.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
+@Slf4j
 @Service
 public class PublicContentServiceImpl {
 
     @Autowired
     private PublishContentMapper publishContentMapper;
 
+    @Autowired
+    private PublishMiniprogramMapper publishMiniprogramMapper;
+
+    @Autowired
+    private AigcService aigcService;
+
     public int getSendCount(Long planAccountId) {
         PublishContentExample example = new PublishContentExample();
         example.createCriteria().andStatusIn(Arrays.asList(1, 2))
@@ -53,4 +63,44 @@ public class PublicContentServiceImpl {
         publishContentMapper.insertSelective(publishContent);
         return publishContent;
     }
+
+    public List<PublishMiniprogram> getPublishMiniprograms(PublishArticleData publishArticleData) {
+        PublishMiniprogramExample publishMiniprogramExample = new PublishMiniprogramExample();
+        publishMiniprogramExample.createCriteria().andPublishContentIdEqualTo(publishArticleData.getId());
+        List<PublishMiniprogram> publishMiniprograms = publishMiniprogramMapper.selectByExample(publishMiniprogramExample);
+        if (CollectionUtils.isEmpty(publishMiniprograms)) {
+            return new ArrayList<>();
+        }
+        return publishMiniprograms;
+    }
+
+    public void updatePublishContentTraceId(String traceId, Long publishContentId) {
+        if (StringUtils.isEmpty(traceId)) {
+            return;
+        }
+        PublishContent publishContent = new PublishContent();
+        publishContent.setTraceId(traceId);
+        publishContent.setId(publishContentId);
+        publishContentMapper.updateByPrimaryKeySelective(publishContent);
+    }
+
+    public void delPublishContent(PublishContent publishContent) {
+        log.info("delPublishContent publishContent={}", publishContent);
+        MatchMiniprogramStatusParam statusParam = new MatchMiniprogramStatusParam();
+        statusParam.setStatus(3);
+        statusParam.setPublishContentId(publishContent.getPublishContentId());
+        statusParam.setErrorMsg("小程序视频数量不足");
+        aigcService.updateMatchMiniprogramStatus(statusParam);
+        //更新为失败
+        updatePublishContentStatus(3, publishContent.getId(), "小程序数量不足");
+    }
+
+    public void updatePublishContentStatus(Integer status, Long publishContentId, String reason) {
+        PublishContent publishContent = new PublishContent();
+        publishContent.setStatus(status);
+        publishContent.setId(publishContentId);
+        publishContent.setReason(reason);
+        publishContentMapper.updateByPrimaryKeySelective(publishContent);
+    }
+
 }