|
@@ -1,10 +1,114 @@
|
|
|
package com.tzld.piaoquan.offline.job;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import com.tzld.piaoquan.growth.common.common.enums.GhTypeEnum;
|
|
|
+import com.tzld.piaoquan.growth.common.common.enums.StrategyStatusEnum;
|
|
|
+import com.tzld.piaoquan.growth.common.component.HttpPoolClient;
|
|
|
+import com.tzld.piaoquan.growth.common.dao.mapper.CgiReplyBucketDataMapper;
|
|
|
+import com.tzld.piaoquan.growth.common.dao.mapper.GhDetailMapper;
|
|
|
+import com.tzld.piaoquan.growth.common.model.po.CgiReplyBucketData;
|
|
|
+import com.tzld.piaoquan.growth.common.model.po.CgiReplyBucketDataExample;
|
|
|
+import com.tzld.piaoquan.growth.common.model.po.GhDetail;
|
|
|
+import com.tzld.piaoquan.growth.common.model.po.GhDetailExample;
|
|
|
+import com.tzld.piaoquan.growth.common.utils.LarkRobotUtil;
|
|
|
+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.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Slf4j
|
|
|
@Component
|
|
|
public class AutoReplyVideoDataJob {
|
|
|
|
|
|
+ private static final String VIDEO_DETAIL_URL = "https://longvideoapi.piaoquantv.com/longvideoapi/openapi/video/batchSelectVideoInfo";
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CgiReplyBucketDataMapper cgiReplyBucketDataMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private HttpPoolClient httpPoolClient;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private GhDetailMapper ghDetailMapper;
|
|
|
+
|
|
|
+
|
|
|
+ @XxlJob("validateAutoReplyVideoAuditStatusJob")
|
|
|
+ public ReturnT<String> validateAutoReplyVideoAuditStatus(String param) throws IOException {
|
|
|
+ List<Long> videoIds = cgiReplyBucketDataMapper.selectVideoId();
|
|
|
+ if (CollectionUtils.isEmpty(videoIds)) {
|
|
|
+ return ReturnT.SUCCESS;
|
|
|
+ }
|
|
|
+ List<Long> auditFailedVideoIds = new ArrayList<>();
|
|
|
+ List<List<Long>> partition = Lists.partition(videoIds, 20);
|
|
|
+ for (List<Long> videoIdList : partition) {
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("videoIdList", videoIdList);
|
|
|
+ String res = httpPoolClient.post(VIDEO_DETAIL_URL, jsonObject.toJSONString());
|
|
|
+ if (StringUtils.isEmpty(res)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ JSONObject result = JSONObject.parseObject(res);
|
|
|
+ Integer code = result.getInteger("code");
|
|
|
+ if (code != 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ JSONArray jsonArray = result.getJSONArray("data");
|
|
|
+ for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
+ JSONObject videoDetail = jsonArray.getJSONObject(i);
|
|
|
+ Integer auditStatus = videoDetail.getInteger("auditStatus");
|
|
|
+ Integer appAuditStatus = videoDetail.getInteger("appAuditStatus");
|
|
|
+ if (auditStatus != 5 || appAuditStatus != 5) {
|
|
|
+ auditFailedVideoIds.add(videoDetail.getLong("id"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isEmpty(auditFailedVideoIds)) {
|
|
|
+ return ReturnT.SUCCESS;
|
|
|
+ }
|
|
|
+ String videoMsg = String.format("审核不通过的视频列表:%s", auditFailedVideoIds);
|
|
|
+ System.out.println(videoMsg);
|
|
|
+ LarkRobotUtil.sendAutoReplyVideoMessage(videoMsg);
|
|
|
+
|
|
|
+ for (Long videoId : auditFailedVideoIds) {
|
|
|
+ CgiReplyBucketDataExample example = new CgiReplyBucketDataExample();
|
|
|
+ example.createCriteria().andMiniVideoIdEqualTo(videoId).andIsDeleteEqualTo(0);
|
|
|
+ List<CgiReplyBucketData> cgiReplyBucketDataList = cgiReplyBucketDataMapper.selectByExample(example);
|
|
|
+ List<String> ghIds = cgiReplyBucketDataList.stream().map(CgiReplyBucketData::getGhId).collect(Collectors.toList());
|
|
|
+ List<String> manualGhIds = new ArrayList<>();
|
|
|
+ for (CgiReplyBucketData cgiReplyBucketData : cgiReplyBucketDataList) {
|
|
|
+ if (Objects.equals(cgiReplyBucketData.getStrategy(), "manual")) {
|
|
|
+ String ghId = cgiReplyBucketData.getGhId();
|
|
|
+ GhDetailExample ghDetailExample = new GhDetailExample();
|
|
|
+ ghDetailExample.createCriteria().andGhIdEqualTo(ghId).andTypeEqualTo(GhTypeEnum.THIRD_PARTY_GH.type);
|
|
|
+ List<GhDetail> ghDetails = ghDetailMapper.selectByExample(ghDetailExample);
|
|
|
+ if (!CollectionUtils.isEmpty(ghDetails)) {
|
|
|
+ for (GhDetail ghDetail : ghDetails) {
|
|
|
+ ghDetail.setStrategyStatus(StrategyStatusEnum.STRATEGY.status);
|
|
|
+ ghDetailMapper.updateByPrimaryKeySelective(ghDetail);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ manualGhIds.add(cgiReplyBucketData.getGhId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String msg = String.format("审核不通过的视频id:%s \n 配置了该视频的ghId列表:%s \n 保底视频更新为策略视频的ghId列表:%s",
|
|
|
+ videoId, ghIds, manualGhIds);
|
|
|
+ System.out.println(msg);
|
|
|
+ LarkRobotUtil.sendAutoReplyVideoMessage(msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ return ReturnT.SUCCESS;
|
|
|
+ }
|
|
|
+
|
|
|
}
|