Ver código fonte

Merge branch 'wyp/0219-avgVideoAudit' of Server/long-article-recommend into master

wangyunpeng 4 meses atrás
pai
commit
2cebae84bd

+ 4 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/mapper/longArticle/ArticleAuditMapper.java

@@ -18,6 +18,10 @@ public interface ArticleAuditMapper {
                                                         List<String> producePlanIds,
                                                         int offset, Integer pageSize, String poolLevelDesc);
 
+    ArticleVideoAuditListVO articleVideoAuditNext(List<String> contentId, List<Integer> status,
+                                                  List<String> title, List<String> auditAccount,
+                                                  List<String> producePlanIds, String poolLevel);
+
     void updateCrawlerVideoIsIllegal(List<Integer> illegalVideoIds, Integer isIllegal);
 
     List<String> searchFilterValueByItemName(String itemName, String searchKeyword);

+ 4 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/mapper/longArticle/VideoPoolAuditMapper.java

@@ -18,6 +18,10 @@ public interface VideoPoolAuditMapper {
                                                          List<Integer> flowPoolLevels,
                                                          int offset, Integer pageSize, String poolLevelDesc);
 
+    PublishSingleVideoSource articleVideoAuditNext(List<String> contentId, List<Integer> status,
+                                                         List<String> title, List<String> auditAccount,
+                                                         Integer flowPoolLevel);
+
     List<String> searchFilterValueByItemName(String itemName, String searchKeyword);
 
     void updateArticleTitle(ArticleTitleUpdateParam param, Long updateTime);

+ 73 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/ArticleVideoAuditService.java

@@ -1,6 +1,7 @@
 package com.tzld.longarticle.recommend.server.service.recommend;
 
 import com.alibaba.fastjson.JSONArray;
+import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
 import com.tzld.longarticle.recommend.server.common.enums.aigc.PublishContentStatusEnum;
 import com.tzld.longarticle.recommend.server.common.enums.longArticle.ArticleVideoAuditStatusEnum;
 import com.tzld.longarticle.recommend.server.common.enums.recommend.ContentPoolEnum;
@@ -14,17 +15,21 @@ import com.tzld.longarticle.recommend.server.model.param.videoAudit.*;
 import com.tzld.longarticle.recommend.server.model.vo.ArticleVideoAuditListVO;
 import com.tzld.longarticle.recommend.server.repository.aigc.ProducePlanExeRecordRepository;
 import com.tzld.longarticle.recommend.server.repository.longArticle.*;
+import com.tzld.longarticle.recommend.server.util.DateUtils;
 import com.tzld.longarticle.recommend.server.util.page.Page;
 import com.xxl.job.core.biz.model.ReturnT;
 import com.xxl.job.core.handler.annotation.XxlJob;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.collections4.MapUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 import org.springframework.util.StringUtils;
 
 import java.util.*;
+import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
 @Service
@@ -52,12 +57,18 @@ public class ArticleVideoAuditService {
     @Autowired
     private ArticlePoolPromotionSourceRepository articlePoolPromotionSourceRepository;
 
+    @Autowired
+    private RedisTemplate<String, String> redisTemplate;
+
     @Value("${cdnUrl:https://rescdn.piaoquantv.com/}")
     private String cdnUrl;
 
     @Value("${videoAudit.poolLevel.sort:}")
     private String poolLevelDesc;
 
+    @ApolloJsonValue("${daily.article.audit.pool.count.config:{}}")
+    private Map<String, Integer> dailyAuditPoolCount;
+
     public Page<ArticleVideoAuditListVO> list(ArticleVideoAuditListParam param) {
         int offset = (param.getPageNum() - 1) * param.getPageSize();
         int count = articleAuditMapper.articleVideoAuditListCount(param.getContentId(), param.getStatus(),
@@ -107,6 +118,60 @@ public class ArticleVideoAuditService {
         }
     }
 
+    public Page<ArticleVideoAuditListVO> next(ArticleVideoAuditListParam param) {
+        if (Objects.nonNull(param.getSourceProducePlan())) {
+            param.setPageSize(1);
+            return list(param);
+        }
+        Page<ArticleVideoAuditListVO> result = new Page<>();
+        // 根据配置判断当日是否审核完成 并 选择内容池返回
+        ArticleVideoAuditListVO item = null;
+        List<String> excludePoolLevel = new ArrayList<>();
+        String poolLevel = getAuditPoolLevel(excludePoolLevel);
+        if (Objects.isNull(poolLevel)) {
+            item = articleAuditMapper.articleVideoAuditNext(param.getContentId(),
+                    param.getStatus(), param.getTitle(), param.getAuditAccount(), param.getSourceProducePlan(), poolLevel);
+        } else {
+            do {
+                item = articleAuditMapper.articleVideoAuditNext(param.getContentId(),
+                        param.getStatus(), param.getTitle(), param.getAuditAccount(), param.getSourceProducePlan(), poolLevel);
+                if (Objects.nonNull(item)) {
+                    break;
+                }
+                excludePoolLevel.add(poolLevel);
+                poolLevel = getAuditPoolLevel(excludePoolLevel);
+            } while (Objects.nonNull(poolLevel));
+        }
+        if (Objects.isNull(item)) {
+            return result;
+        }
+        List<ArticleVideoAuditListVO> list = Collections.singletonList(item);
+        buildArticleVideoAuditListVO(list);
+        result.setObjs(list);
+        return result;
+    }
+
+    private String getAuditPoolLevel(List<String> excludePoolLevel) {
+        if (MapUtils.isEmpty(dailyAuditPoolCount)) {
+            return null;
+        }
+        String dateStr = DateUtils.getCurrentDateStr("yyyyMMdd");
+        Set<String> keySet = dailyAuditPoolCount.keySet();
+        keySet = keySet.stream().sorted().collect(Collectors.toCollection(LinkedHashSet::new));
+        for (String poolLevel : keySet) {
+            if (excludePoolLevel.contains(poolLevel)) {
+                continue;
+            }
+            int target = dailyAuditPoolCount.get(poolLevel);
+            String key = "article_audit_count_" + dateStr + "_" + poolLevel;
+            int totalCount = Integer.parseInt(Optional.ofNullable(redisTemplate.opsForValue().get(key)).orElse("0"));
+            if (target > totalCount) {
+                return poolLevel;
+            }
+        }
+        return null;
+    }
+
     public void auditArticle(ArticleAuditParam param) {
         LongArticleTitleAudit titleAudit = titleAuditRepository.getByContentId(param.getContentId());
         Long now = System.currentTimeMillis();
@@ -121,7 +186,15 @@ public class ArticleVideoAuditService {
             // 审核通过
             auditArticlePass(titleAudit);
         }
+        // 当日审核数+1
+        addAuditCount(titleAudit.getFlowPoolLevel());
+    }
 
+    private void addAuditCount(String poolLevel) {
+        String dateStr = DateUtils.getCurrentDateStr("yyyyMMdd");
+        String key = "article_audit_count_" + dateStr + "_" + poolLevel;
+        int totalCount = Integer.parseInt(Optional.ofNullable(redisTemplate.opsForValue().get(key)).orElse("0"));
+        redisTemplate.opsForValue().set(key, String.valueOf(totalCount + 1), 24, TimeUnit.HOURS);
     }
 
     private void auditArticlePass(LongArticleTitleAudit titleAudit) {

+ 75 - 5
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/VideoPoolAuditService.java

@@ -1,5 +1,6 @@
 package com.tzld.longarticle.recommend.server.service.recommend;
 
+import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
 import com.tzld.longarticle.recommend.server.common.enums.aigc.PublishContentStatusEnum;
 import com.tzld.longarticle.recommend.server.common.enums.longArticle.ArticleVideoAuditStatusEnum;
 import com.tzld.longarticle.recommend.server.common.enums.longArticle.ArticleVideoBadStatusEnum;
@@ -10,19 +11,20 @@ import com.tzld.longarticle.recommend.server.model.entity.longArticle.PublishSin
 import com.tzld.longarticle.recommend.server.model.param.videoAudit.*;
 import com.tzld.longarticle.recommend.server.model.vo.VideoPoolAuditListVO;
 import com.tzld.longarticle.recommend.server.repository.longArticle.PublishSingleVideoSourceRepository;
+import com.tzld.longarticle.recommend.server.util.DateUtils;
 import com.tzld.longarticle.recommend.server.util.page.Page;
 import com.xxl.job.core.biz.model.ReturnT;
 import com.xxl.job.core.handler.annotation.XxlJob;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.collections4.MapUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Objects;
+import java.util.*;
+import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
 @Service
@@ -36,12 +38,18 @@ public class VideoPoolAuditService {
     @Autowired
     private PublishSingleVideoSourceRepository videoSourceRepository;
 
+    @Autowired
+    private RedisTemplate<String, String> redisTemplate;
+
     @Value("${cdnUrl:https://rescdn.piaoquantv.com/}")
     private String cdnUrl;
 
     @Value("${videoAudit.poolLevel.sort:}")
     private String poolLevelDesc;
 
+    @ApolloJsonValue("${daily.video.audit.pool.count.config:{}}")
+    private Map<String, Integer> dailyAuditPoolCount;
+
     public Page<VideoPoolAuditListVO> list(VideoPoolAuditListParam param) {
         int offset = (param.getPageNum() - 1) * param.getPageSize();
         int count = videoPoolAuditMapper.articleVideoAuditListCount(param.getContentId(), param.getStatus(),
@@ -84,6 +92,60 @@ public class VideoPoolAuditService {
         return result;
     }
 
+    public Page<VideoPoolAuditListVO> next(VideoPoolAuditListParam param) {
+        if (Objects.nonNull(param.getFlowPoolLevel())) {
+            param.setPageSize(1);
+            return list(param);
+        }
+        Page<VideoPoolAuditListVO> result = new Page<>();
+        // 根据配置判断当日是否审核完成 并 选择内容池返回
+        PublishSingleVideoSource obj = null;
+        List<String> excludePoolLevel = new ArrayList<>();
+        Integer poolLevel = getAuditPoolLevel(excludePoolLevel);
+        if (Objects.isNull(poolLevel)) {
+            obj = videoPoolAuditMapper.articleVideoAuditNext(param.getContentId(),
+                    param.getStatus(), param.getTitle(), param.getAuditAccount(), poolLevel);
+        } else {
+            do {
+                obj = videoPoolAuditMapper.articleVideoAuditNext(param.getContentId(),
+                        param.getStatus(), param.getTitle(), param.getAuditAccount(), poolLevel);
+                if (Objects.nonNull(obj)) {
+                    break;
+                }
+                excludePoolLevel.add(ContentPoolEnum.from(poolLevel).getContentPool());
+                poolLevel = getAuditPoolLevel(excludePoolLevel);
+            } while (Objects.nonNull(poolLevel));
+        }
+        if (Objects.isNull(obj)) {
+            return result;
+        }
+        List<VideoPoolAuditListVO> list = buildVideoPoolAuditListVO(Collections.singletonList(obj));
+        result.setObjs(list);
+        return result;
+    }
+
+    private Integer getAuditPoolLevel(List<String> excludePoolLevel) {
+        if (MapUtils.isEmpty(dailyAuditPoolCount)) {
+            return null;
+        }
+        String dateStr = DateUtils.getCurrentDateStr("yyyyMMdd");
+        Set<String> keySet = dailyAuditPoolCount.keySet();
+        keySet = keySet.stream().sorted().collect(Collectors.toCollection(LinkedHashSet::new));
+        for (String poolLevel : keySet) {
+            if (excludePoolLevel.contains(poolLevel)) {
+                continue;
+            }
+            int target = dailyAuditPoolCount.get(poolLevel);
+            String key = "video_audit_count_" + dateStr + "_" + poolLevel;
+            int totalCount = Integer.parseInt(Optional.ofNullable(redisTemplate.opsForValue().get(key)).orElse("0"));
+            if (target > totalCount) {
+                ContentPoolEnum poolEnum = ContentPoolEnum.from(poolLevel);
+                return poolEnum.getValue();
+            }
+        }
+        return null;
+    }
+
     public void auditArticle(ArticleAuditParam param) {
         PublishSingleVideoSource videoAudit = videoSourceRepository.getByContentTraceId(param.getContentId());
         Long now = System.currentTimeMillis();
@@ -103,7 +165,15 @@ public class VideoPoolAuditService {
             // 审核通过
             auditArticlePass(videoAudit);
         }
+        // 当日审核数+1
+        addAuditCount(ContentPoolEnum.from(videoAudit.getFlowPoolLevel()).getContentPool());
+    }
 
+    private void addAuditCount(String poolLevel) {
+        String dateStr = DateUtils.getCurrentDateStr("yyyyMMdd");
+        String key = "video_audit_count_" + dateStr + "_" + poolLevel;
+        int totalCount = Integer.parseInt(Optional.ofNullable(redisTemplate.opsForValue().get(key)).orElse("0"));
+        redisTemplate.opsForValue().set(key, String.valueOf(totalCount + 1), 24, TimeUnit.HOURS);
     }
 
     private void auditArticlePass(PublishSingleVideoSource videoAudit) {
@@ -142,7 +212,7 @@ public class VideoPoolAuditService {
 
     @XxlJob("shuffleVideoPoolAuditGroup")
     public ReturnT<String> shuffleVideoPoolAuditGroup(String param) {
-        List<String> auditUser = Arrays.asList("a","b","c","d","e","f","g","h","i","j");
+        List<String> auditUser = Arrays.asList("a", "b", "c", "d", "e", "f", "g", "h", "i", "j");
         List<PublishSingleVideoSource> contentIds = videoSourceRepository.getByVideoPoolAuditStatus(ArticleVideoAuditStatusEnum.WAITING.getCode());
         for (int i = 0; i < contentIds.size(); i++) {
             int per = i % auditUser.size();

+ 5 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/web/recommend/ArticleVideoAuditController.java

@@ -24,6 +24,11 @@ public class ArticleVideoAuditController {
         return CommonResponse.success(service.list(param));
     }
 
+    @PostMapping("/next")
+    public CommonResponse<Page<ArticleVideoAuditListVO>> articleVideoAuditNext(@RequestBody ArticleVideoAuditListParam param) {
+        return CommonResponse.success(service.next(param));
+    }
+
     @PostMapping("/auditArticle")
     public CommonResponse<Void> auditArticle(@RequestBody ArticleAuditParam param) {
         service.auditArticle(param);

+ 5 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/web/recommend/VideoPoolAuditController.java

@@ -24,6 +24,11 @@ public class VideoPoolAuditController {
         return CommonResponse.success(service.list(param));
     }
 
+    @PostMapping("/next")
+    public CommonResponse<Page<VideoPoolAuditListVO>> articleVideoAuditNext(@RequestBody VideoPoolAuditListParam param) {
+        return CommonResponse.success(service.next(param));
+    }
+
     @PostMapping("/auditArticle")
     public CommonResponse<Void> auditArticle(@RequestBody ArticleAuditParam param) {
         service.auditArticle(param);

+ 45 - 0
long-article-recommend-service/src/main/resources/mapper/longArticle/ArticleAuditMapper.xml

@@ -141,6 +141,51 @@
         </choose>
     </select>
 
+    <select id="articleVideoAuditNext"
+            resultType="com.tzld.longarticle.recommend.server.model.vo.ArticleVideoAuditListVO">
+        select lata.content_id, lata.status, lat.article_title as title, lat.kimi_title,
+        lata.audit_account, lata.audit_timestamp, lata.flow_pool_level
+        from long_articles_title_audit lata
+        left join long_articles_text lat on lata.content_id = lat.content_id
+        <where>
+            <if test="status!= null and status.size() > 0">
+                and lata.status in
+                <foreach collection="status" item="item" separator="," open="(" close=")">
+                    #{item}
+                </foreach>
+            </if>
+            <if test="contentId!= null and contentId.size() > 0">
+                and lata.content_id in
+                <foreach collection="contentId" item="item" separator="," open="(" close=")">
+                    #{item}
+                </foreach>
+            </if>
+            <if test="title!= null and title.size() > 0">
+                and lat.article_title in
+                <foreach collection="title" item="item" separator="," open="(" close=")">
+                    #{item}
+                </foreach>
+            </if>
+            <if test="auditAccount!= null and auditAccount.size() > 0">
+                and lata.audit_account in
+                <foreach collection="auditAccount" item="item" separator="," open="(" close=")">
+                    #{item}
+                </foreach>
+            </if>
+            <if test="producePlanIds!= null and producePlanIds.size() > 0">
+                and lata.produce_plan_id in
+                <foreach collection="producePlanIds" item="item" separator="," open="(" close=")">
+                    #{item}
+                </foreach>
+            </if>
+            <if test="poolLevel!= null and poolLevel !=''">
+                and lata.flow_pool_level = #{poolLevel}
+            </if>
+        </where>
+        order by lata.content_id desc
+        limit 1
+    </select>
+
     <update id="updateArticleTitle">
         update long_articles_text
         set old_article_title = article_title,

+ 36 - 0
long-article-recommend-service/src/main/resources/mapper/longArticle/VideoPoolAuditMapper.xml

@@ -84,6 +84,42 @@
         limit #{offset}, #{pageSize}
     </select>
 
+    <select id="articleVideoAuditNext"
+            resultType="com.tzld.longarticle.recommend.server.model.entity.longArticle.PublishSingleVideoSource">
+        select *
+        from publish_single_video_source
+        where bad_status = 0 and audit_status = 1
+        <if test="status!= null and status.size() > 0">
+            and `video_pool_audit_status` in
+            <foreach collection="status" item="item" separator="," open="(" close=")">
+                #{item}
+            </foreach>
+        </if>
+        <if test="contentId!= null and contentId.size() > 0">
+            and content_trace_id in
+            <foreach collection="contentId" item="item" separator="," open="(" close=")">
+                #{item}
+            </foreach>
+        </if>
+        <if test="title!= null and title.size() > 0">
+            and article_title in
+            <foreach collection="title" item="item" separator="," open="(" close=")">
+                #{item}
+            </foreach>
+        </if>
+        <if test="auditAccount!= null and auditAccount.size() > 0">
+            and video_pool_audit_account in
+            <foreach collection="auditAccount" item="item" separator="," open="(" close=")">
+                #{item}
+            </foreach>
+        </if>
+        <if test="flowPoolLevel != null">
+            and flow_pool_level = #{flowPoolLevel}
+        </if>
+        order by content_trace_id desc
+        limit 1
+    </select>
+
     <select id="searchFilterValueByItemName" resultType="java.lang.String">
         <choose>
             <when test="itemName == 'contentId'">