Ver código fonte

票圈视频审核

wangyunpeng 7 meses atrás
pai
commit
0808df8465

+ 32 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/common/enums/cgi/PQVideoAuditResultENum.java

@@ -0,0 +1,32 @@
+package com.tzld.longarticle.recommend.server.common.enums.cgi;
+
+import lombok.Getter;
+
+import java.util.Objects;
+
+@Getter
+public enum PQVideoAuditResultENum {
+    WAITING(0, "审核中"),
+    PASS(1, "审核通过"),
+    REJECT(2, "审核不通过"),
+
+    other(999, "其他"),
+    ;
+
+    private final Integer status;
+    private final String description;
+
+    PQVideoAuditResultENum(Integer status, String description) {
+        this.status = status;
+        this.description = description;
+    }
+
+    public static PQVideoAuditResultENum from(Integer status) {
+        for (PQVideoAuditResultENum statusEnum : PQVideoAuditResultENum.values()) {
+            if (Objects.equals(statusEnum.status, status)) {
+                return statusEnum;
+            }
+        }
+        return other;
+    }
+}

+ 10 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/model/cgi/PQVideoAuditResult.java

@@ -0,0 +1,10 @@
+package com.tzld.longarticle.recommend.server.model.cgi;
+
+import lombok.Data;
+
+@Data
+public class PQVideoAuditResult {
+    private Long taskId;
+    private Integer auditResult;
+    private String reason;
+}

+ 81 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/remote/pq/PQVideoAuditResultService.java

@@ -0,0 +1,81 @@
+package com.tzld.longarticle.recommend.server.remote.pq;
+
+import com.alibaba.fastjson.JSONObject;
+import com.tzld.longarticle.recommend.server.common.HttpPoolFactory;
+import com.tzld.longarticle.recommend.server.model.cgi.PQVideoAuditResult;
+import com.tzld.longarticle.recommend.server.model.param.PQResponse;
+import com.tzld.longarticle.recommend.server.repository.crawler.ArticleRepository;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.http.HttpEntity;
+import org.apache.http.StatusLine;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.util.EntityUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
+@Service
+@Slf4j
+public class PQVideoAuditResultService {
+
+    @Autowired
+    ArticleRepository articleRepository;
+
+    @Value("${pq.host")
+    private String host;
+
+    private final CloseableHttpClient client = HttpPoolFactory.aigcPool();
+    private static final String url = "/longvideoapi/openai/audit/queryTaskResult";
+
+    public List<PQVideoAuditResult> getResult(List<Long> taskIds) {
+        int retryTimes = 3;
+        while (retryTimes > 0) {
+            List<PQVideoAuditResult> result = post(taskIds);
+            if (CollectionUtils.isNotEmpty(result)) {
+                return result;
+            }
+            retryTimes--;
+        }
+        return new ArrayList<>();
+    }
+
+    public List<PQVideoAuditResult> post(List<Long> taskIds) {
+        JSONObject params = new JSONObject();
+        params.put("taskIds", taskIds);
+        try {
+            HttpPost httpPost = new HttpPost(host + url);
+            StringEntity stringEntity = new StringEntity(params.toJSONString(), StandardCharsets.UTF_8);
+            httpPost.setHeader("Content-Type", "application/json;charset=UTF-8");
+            httpPost.setEntity(stringEntity);
+            CloseableHttpResponse response = client.execute(httpPost);
+            StatusLine statusLine = response.getStatusLine();
+            if (statusLine.getStatusCode() == 200) {
+                HttpEntity responseEntity = response.getEntity();
+                if (Objects.nonNull(responseEntity)) {
+                    String responseBody = EntityUtils.toString(responseEntity, "UTF-8");
+                    PQResponse<List<PQVideoAuditResult>> pqResponse = JSONObject.parseObject(responseBody, PQResponse.class);
+                    if (pqResponse.getCode() == 0) {
+                        return pqResponse.getData();
+                    } else {
+                        return null;
+                    }
+                }
+            }
+        } catch (IOException e) {
+            log.error("articleGetProducePlanDetail error", e);
+        }
+        return null;
+    }
+
+
+}

+ 19 - 4
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/remote/pq/PQVideoAuditStartProcessService.java

@@ -12,6 +12,7 @@ import org.apache.http.entity.StringEntity;
 import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.util.EntityUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
 import java.io.IOException;
@@ -25,14 +26,29 @@ public class PQVideoAuditStartProcessService {
     @Autowired
     ArticleRepository articleRepository;
 
+    @Value("${pq.host")
+    private String host;
+
     private final CloseableHttpClient client = HttpPoolFactory.aigcPool();
-    private static final String url = "https://longvideoapi.piaoquantv.com/longvideoapi/openai/audit/startProcess";
+    private static final String url = "/longvideoapi/openai/audit/startProcess";
 
     public Long startProcess(Long videoId) {
+        int retryTimes = 3;
+        while (retryTimes > 0) {
+            Long taskId = post(videoId);
+            if (Objects.nonNull(taskId)) {
+                return taskId;
+            }
+            retryTimes--;
+        }
+        return null;
+    }
+
+    public Long post(Long videoId) {
         JSONObject params = new JSONObject();
         params.put("videoId", videoId);
         try {
-            HttpPost httpPost = new HttpPost(url);
+            HttpPost httpPost = new HttpPost(host + url);
             StringEntity stringEntity = new StringEntity(params.toJSONString(), StandardCharsets.UTF_8);
             httpPost.setHeader("Content-Type", "application/json;charset=UTF-8");
             httpPost.setEntity(stringEntity);
@@ -49,14 +65,13 @@ public class PQVideoAuditStartProcessService {
                             return data.getLong("taskId");
                         }
                     } else {
-                        // todo 任务处理失败
+                        return null;
                     }
                 }
             }
         } catch (IOException e) {
             log.error("articleGetProducePlanDetail error", e);
         }
-        // todo 失败增加重试
         return null;
     }
 

+ 2 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/repository/longArticle/LongArticleVideoAuditRepository.java

@@ -11,4 +11,6 @@ public interface LongArticleVideoAuditRepository extends JpaRepository<LongArtic
     LongArticleVideoAudit getByVideoId(Long videoId);
 
     List<LongArticleVideoAudit> getByVideoIdIn(List<Long> videoIds);
+
+    List<LongArticleVideoAudit> getByStatusAndTaskIdIsNotNull(Integer status);
 }

+ 30 - 13
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/ArticleAuditService.java

@@ -6,8 +6,10 @@ import com.google.common.collect.Lists;
 import com.tzld.longarticle.recommend.server.common.enums.StatusEnum;
 import com.tzld.longarticle.recommend.server.common.enums.aigc.PushTypeEnum;
 import com.tzld.longarticle.recommend.server.common.enums.recommend.ArticleDeleteStatusEnum;
+import com.tzld.longarticle.recommend.server.common.enums.cgi.PQVideoAuditResultENum;
 import com.tzld.longarticle.recommend.server.common.enums.recommend.FeishuRobotIdEnum;
 import com.tzld.longarticle.recommend.server.mapper.aigc.AigcBaseMapper;
+import com.tzld.longarticle.recommend.server.model.cgi.PQVideoAuditResult;
 import com.tzld.longarticle.recommend.server.model.dto.*;
 import com.tzld.longarticle.recommend.server.model.entity.aigc.PublishAccount;
 import com.tzld.longarticle.recommend.server.model.entity.crawler.Article;
@@ -17,6 +19,7 @@ import com.tzld.longarticle.recommend.server.model.param.ArticleVideoAuditResult
 import com.tzld.longarticle.recommend.server.model.param.PublishContentParam;
 import com.tzld.longarticle.recommend.server.remote.WxAccessTokenRemoteService;
 import com.tzld.longarticle.recommend.server.remote.WxArticleDeleteService;
+import com.tzld.longarticle.recommend.server.remote.pq.PQVideoAuditResultService;
 import com.tzld.longarticle.recommend.server.remote.pq.PQVideoAuditStartProcessService;
 import com.tzld.longarticle.recommend.server.repository.aigc.PublishAccountRepository;
 import com.tzld.longarticle.recommend.server.repository.crawler.ArticleRepository;
@@ -64,6 +67,8 @@ public class ArticleAuditService {
     private ArticleUnsafeTitleRepository articleUnsafeTitleRepository;
     @Autowired
     private PQVideoAuditStartProcessService pqVideoAuditStartProcessService;
+    @Autowired
+    private PQVideoAuditResultService pqVideoAuditResultService;
 
 
     @XxlJob("articleVideoAudit")
@@ -102,10 +107,14 @@ public class ArticleAuditService {
                 // 调用PQ 审核视频
                 try {
                     Long taskId = pqVideoAuditStartProcessService.startProcess(response.getVideoID());
-                    videoAudit.setTaskId(taskId);
-                    longArticleVideoAuditRepository.save(videoAudit);
+                    if (Objects.nonNull(taskId)) {
+                        videoAudit.setTaskId(taskId);
+                        longArticleVideoAuditRepository.save(videoAudit);
+                    } else {
+                        log.error("PQVideoAuditStartProcess start process error videoId:{} ", response.getVideoID());
+                    }
                 } catch (Exception e) {
-                    log.error("PQVideoAuditStartProcess start process error:{}", e.getMessage());
+                    log.error("PQVideoAuditStartProcess start process videoId:{} error:{}", response.getVideoID(), e.getMessage());
                 }
             }
         }
@@ -113,20 +122,28 @@ public class ArticleAuditService {
         return ReturnT.SUCCESS;
     }
 
-    /**
-     * 视频审核结果处理
-     */
-    public void articleVideoAuditResult(ArticleVideoAuditResultParam param) {
-        LongArticleVideoAudit longArticleVideoAudit = longArticleVideoAuditRepository.getByVideoId(param.getVideoId());
-        if (param.getResult() == 1) {
+    @XxlJob("articleVideoAuditResult")
+    public ReturnT<String> articleVideoAuditResult(String param) {
+        List<LongArticleVideoAudit> list = longArticleVideoAuditRepository.getByStatusAndTaskIdIsNotNull(StatusEnum.ZERO.getCode());
+        for (List<LongArticleVideoAudit> partition : Lists.partition(list, 10)) {
+            List<Long> taskIds = partition.stream().map(LongArticleVideoAudit::getTaskId).collect(Collectors.toList());
+            Map<Long, LongArticleVideoAudit> map = partition.stream().collect(Collectors.toMap(LongArticleVideoAudit::getTaskId, Function.identity()));
+            List<PQVideoAuditResult> resultList = pqVideoAuditResultService.getResult(taskIds);
+            resultList.forEach(result -> saveVideoAuditResult(map.get(result.getTaskId()), result.getAuditResult()));
+        }
+        return ReturnT.SUCCESS;
+    }
+
+
+    public void saveVideoAuditResult(LongArticleVideoAudit longArticleVideoAudit, Integer auditResult) {
+        if (Objects.equals(auditResult, PQVideoAuditResultENum.PASS.getStatus())) {
             // 审核通过,更新文章状态
-            longArticleVideoAudit.setStatus(ArticleDeleteStatusEnum.SUCCESS.getCode());
+            longArticleVideoAudit.setStatus(PQVideoAuditResultENum.PASS.getStatus());
             longArticleVideoAudit.setFinishTimestamp(System.currentTimeMillis());
             longArticleVideoAuditRepository.save(longArticleVideoAudit);
-        } else {
+        } else if (Objects.equals(auditResult, PQVideoAuditResultENum.REJECT.getStatus())) {
             // 审核不通过,删除文章
-            longArticleVideoAudit.setStatus(ArticleDeleteStatusEnum.FAIL.getCode());
-            longArticleVideoAudit.setFailReason(param.getFailReason());
+            longArticleVideoAudit.setStatus(PQVideoAuditResultENum.REJECT.getStatus());
             longArticleVideoAudit.setFinishTimestamp(System.currentTimeMillis());
             longArticleVideoAuditRepository.save(longArticleVideoAudit);
             // 构建删除文章记录 并保存

+ 2 - 3
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/web/recommend/ArticleAuditController.java

@@ -2,7 +2,6 @@ package com.tzld.longarticle.recommend.server.web.recommend;
 
 import com.tzld.longarticle.recommend.server.common.response.CommonResponse;
 import com.tzld.longarticle.recommend.server.model.param.ArticleDangerFindDeleteParam;
-import com.tzld.longarticle.recommend.server.model.param.ArticleVideoAuditResultParam;
 import com.tzld.longarticle.recommend.server.service.recommend.ArticleAuditService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -22,8 +21,8 @@ public class ArticleAuditController {
         service.articleVideoAudit(dateStr);
     }
 
-    @PostMapping("/articleVideoAuditResult")
-    public CommonResponse<Void> articleVideoAuditResult(@RequestBody ArticleVideoAuditResultParam param) {
+    @GetMapping("/articleVideoAuditResult")
+    public CommonResponse<Void> articleVideoAuditResult(String param) {
         service.articleVideoAuditResult(param);
         return CommonResponse.success();
     }

+ 4 - 1
long-article-recommend-service/src/main/resources/application-dev.yml

@@ -131,4 +131,7 @@ pushMessage:
     groupId: GID_3RD_PARTY_PUSH_MESSAGE_CALLBACK_DEV
     tag: mini
 
-small_page_url: https://testapi.piaoquantv.com
+small_page_url: https://testapi.piaoquantv.com
+
+pq:
+  host: https://videotest.yishihui.com

+ 4 - 1
long-article-recommend-service/src/main/resources/application-pre.yml

@@ -163,4 +163,7 @@ aliyun:
         project: wqsd-video
         store: video_blacklist_security_filter_log
 
-small_page_url: https://testapi.piaoquantv.com
+small_page_url: https://testapi.piaoquantv.com
+
+pq:
+  host: https://videopre.piaoquantv.com

+ 4 - 1
long-article-recommend-service/src/main/resources/application-prod.yml

@@ -121,4 +121,7 @@ pushMessage:
     groupId: GID_3RD_PARTY_PUSH_MESSAGE_CALLBACK_PROD
     tag: mini
 
-small_page_url: https://api.piaoquantv.com
+small_page_url: https://api.piaoquantv.com
+
+pq:
+  host: https://longvideoapi.piaoquantv.com

+ 4 - 1
long-article-recommend-service/src/main/resources/application-test.yml

@@ -153,4 +153,7 @@ aliyun:
         project: wqsd-video-test
         store: video_blacklist_security_filter_log
 
-small_page_url: https://testapi.piaoquantv.com
+small_page_url: https://testapi.piaoquantv.com
+
+pq:
+  host: https://videotest.yishihui.com