AutoReplyVideoDataJob.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. package com.tzld.piaoquan.offline.job;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONArray;
  4. import com.alibaba.fastjson.JSONObject;
  5. import com.google.common.collect.Lists;
  6. import com.tzld.piaoquan.growth.common.common.enums.FieshuTableColumnDataTypeEnum;
  7. import com.tzld.piaoquan.growth.common.common.enums.GhTypeEnum;
  8. import com.tzld.piaoquan.growth.common.common.enums.StrategyStatusEnum;
  9. import com.tzld.piaoquan.growth.common.component.HttpPoolClient;
  10. import com.tzld.piaoquan.growth.common.dao.mapper.CgiReplyBucketDataMapper;
  11. import com.tzld.piaoquan.growth.common.dao.mapper.GhDetailMapper;
  12. import com.tzld.piaoquan.growth.common.model.bo.FeishuTableDTO;
  13. import com.tzld.piaoquan.growth.common.model.po.CgiReplyBucketData;
  14. import com.tzld.piaoquan.growth.common.model.po.CgiReplyBucketDataExample;
  15. import com.tzld.piaoquan.growth.common.model.po.GhDetail;
  16. import com.tzld.piaoquan.growth.common.model.po.GhDetailExample;
  17. import com.tzld.piaoquan.growth.common.utils.DateUtil;
  18. import com.tzld.piaoquan.growth.common.utils.LarkRobotUtil;
  19. import com.tzld.piaoquan.growth.common.utils.MessageUtil;
  20. import com.tzld.piaoquan.growth.common.utils.page.Page;
  21. import com.xxl.job.core.biz.model.ReturnT;
  22. import com.xxl.job.core.handler.annotation.XxlJob;
  23. import lombok.extern.slf4j.Slf4j;
  24. import org.apache.commons.lang3.StringUtils;
  25. import org.springframework.beans.factory.annotation.Autowired;
  26. import org.springframework.stereotype.Component;
  27. import org.springframework.util.CollectionUtils;
  28. import java.io.IOException;
  29. import java.util.*;
  30. import java.util.stream.Collectors;
  31. @Slf4j
  32. @Component
  33. public class AutoReplyVideoDataJob {
  34. private static final List<String> auditGhIds = new ArrayList<String>() {{
  35. add("gh_b63b9dde3f4b");
  36. add("gh_330ef0db846d");
  37. add("gh_330ef0db846d");
  38. add("gh_e2318164f869");
  39. add("gh_620af8e24fb9");
  40. add("gh_620af8e24fb9");
  41. add("gh_133c36b99b14");
  42. add("gh_133c36b99b14");
  43. add("gh_5ac72e2b9130");
  44. add("gh_ef8ade0fad92");
  45. add("gh_1e03b6de22bf");
  46. add("gh_5538fe297e59");
  47. add("gh_8c6fffcbaac1");
  48. add("gh_8c6fffcbaac1");
  49. add("gh_d0e830b7547e");
  50. add("gh_fb234f4e32a5");
  51. add("gh_84c5d01a61e7");
  52. add("gh_87c4b8ae885e");
  53. add("gh_29d8a63d5e5e");
  54. add("gh_b144210318e5");
  55. add("gh_b144210318e5");
  56. add("gh_1f9bf4cfa788");
  57. add("gh_4f47d12bbe04");
  58. add("gh_8c6af276df98");
  59. add("gh_1f16bc6ac60d");
  60. add("gh_4920bc4c5720");
  61. add("gh_5177a8c57917");
  62. add("gh_5177a8c57917");
  63. add("gh_5e3e6cd5e35c");
  64. add("gh_5e3e6cd5e35c");
  65. add("gh_d2c72bcc05c9");
  66. add("gh_d2c72bcc05c9");
  67. add("gh_5f2400da935c");
  68. add("gh_5f2400da935c");
  69. add("gh_669555ebea28");
  70. add("gh_28ce883486c3");
  71. add("gh_28ce883486c3");
  72. add("gh_7057ef30222b");
  73. add("gh_7057ef30222b");
  74. add("gh_b0048adc0b46");
  75. add("gh_6e61a2d5db85");
  76. add("gh_01cd19465b39");
  77. add("gh_01cd19465b39");
  78. add("gh_126c99b39cea");
  79. add("gh_4a1174e36ceb");
  80. add("gh_f81c27eb8c48");
  81. add("gh_f81c27eb8c48");
  82. add("gh_3170dc15e246");
  83. add("gh_1ccfb5620605");
  84. add("gh_315be76a746d");
  85. add("gh_4f47d12bbe04");
  86. add("gh_4f47d12bbe04");
  87. add("gh_4f47d12bbe04");
  88. }};
  89. private static final String VIDEO_DETAIL_URL = "https://longvideoapi.piaoquantv.com/longvideoapi/openapi/video/batchSelectVideoInfo";
  90. private static final String REFRESH_GZH_URL = "http://aigc-api.cybertogether.net/aigc/publish/api/refreshGzhAutoReplyMsgData";
  91. @Autowired
  92. private CgiReplyBucketDataMapper cgiReplyBucketDataMapper;
  93. @Autowired
  94. private HttpPoolClient httpPoolClient;
  95. @Autowired
  96. private GhDetailMapper ghDetailMapper;
  97. @XxlJob("validateAutoReplyVideoAuditStatusJob")
  98. public ReturnT<String> validateAutoReplyVideoAuditStatus(String param) throws IOException {
  99. Long beforeDayStart = DateUtil.getBeforeDayStart(7);
  100. List<Long> videoIds = cgiReplyBucketDataMapper.selectVideoId(new Date(beforeDayStart));
  101. if (CollectionUtils.isEmpty(videoIds)) {
  102. return ReturnT.SUCCESS;
  103. }
  104. List<Long> auditFailedVideoIds = new ArrayList<>();
  105. List<List<Long>> partition = Lists.partition(videoIds, 20);
  106. for (List<Long> videoIdList : partition) {
  107. JSONObject jsonObject = new JSONObject();
  108. jsonObject.put("videoIdList", videoIdList);
  109. String res = httpPoolClient.post(VIDEO_DETAIL_URL, jsonObject.toJSONString());
  110. if (StringUtils.isEmpty(res)) {
  111. continue;
  112. }
  113. JSONObject result = JSONObject.parseObject(res);
  114. Integer code = result.getInteger("code");
  115. if (code != 0) {
  116. continue;
  117. }
  118. JSONArray jsonArray = result.getJSONArray("data");
  119. for (int i = 0; i < jsonArray.size(); i++) {
  120. JSONObject videoDetail = jsonArray.getJSONObject(i);
  121. Integer auditStatus = videoDetail.getInteger("auditStatus");
  122. Integer appAuditStatus = videoDetail.getInteger("appAuditStatus");
  123. if (auditStatus != 5 || appAuditStatus != 5) {
  124. auditFailedVideoIds.add(videoDetail.getLong("id"));
  125. }
  126. }
  127. }
  128. if (CollectionUtils.isEmpty(auditFailedVideoIds)) {
  129. return ReturnT.SUCCESS;
  130. }
  131. List<FeishuTableDTO.Column> columns = buildCheckPublishPlanAccountColumns();
  132. List<JSONObject> rows = new ArrayList<>();
  133. for (Long videoId : auditFailedVideoIds) {
  134. CgiReplyBucketDataExample example = new CgiReplyBucketDataExample();
  135. example.createCriteria().andMiniVideoIdEqualTo(videoId).andIsDeleteEqualTo(0)
  136. .andCreateTimeGreaterThan(new Date(beforeDayStart));
  137. List<CgiReplyBucketData> cgiReplyBucketDataList = cgiReplyBucketDataMapper.selectByExample(example);
  138. // List<String> ghIds = new ArrayList<>();
  139. // List<String> manualGhIds = new ArrayList<>();
  140. for (CgiReplyBucketData cgiReplyBucketData : cgiReplyBucketDataList) {
  141. String ghId = cgiReplyBucketData.getGhId();
  142. GhDetailExample ghDetailExample = new GhDetailExample();
  143. ghDetailExample.createCriteria().andGhIdEqualTo(ghId);
  144. List<GhDetail> ghDetails = ghDetailMapper.selectByExample(ghDetailExample);
  145. if (CollectionUtils.isEmpty(ghDetails)) {
  146. continue;
  147. }
  148. GhDetail ghDetail = ghDetails.get(0);
  149. // if (Objects.equals(cgiReplyBucketData.getStrategy(), "manual")) {
  150. // ghDetail1.setStrategyStatus(StrategyStatusEnum.STRATEGY.status);
  151. // ghDetailMapper.updateByPrimaryKeySelective(ghDetail1);
  152. // manualGhIds.add(cgiReplyBucketData.getGhId());
  153. // }
  154. // ghIds.add(cgiReplyBucketData.getGhId());
  155. JSONObject row = new JSONObject();
  156. row.put("name", ghDetail.getGhName());
  157. row.put("channel", ghDetail.getChannel());
  158. row.put("video", videoId);
  159. row.put("ghId", ghDetail.getGhId());
  160. rows.add(row);
  161. try {
  162. if (auditGhIds.contains(ghId)) {
  163. String url = REFRESH_GZH_URL + "?ghId=" + cgiReplyBucketData.getGhId();
  164. String res = httpPoolClient.get(url);
  165. log.info("refresh ghId={}, res={}", cgiReplyBucketData.getGhId(), res);
  166. }
  167. } catch (Exception e) {
  168. log.error("refresh error", e);
  169. }
  170. }
  171. }
  172. Map<String, JSONObject> collect = rows.stream()
  173. .collect(Collectors.toMap(
  174. row -> row.getString("ghId") + "-" + row.getString("video"),
  175. row -> row,
  176. (existing, replacement) -> existing
  177. ));
  178. rows = new ArrayList<>(collect.values());
  179. FeishuTableDTO tableDTO = FeishuTableDTO.createTable("自动回复视频审核失败报警", columns, rows, false);
  180. JSONObject content = JSONObject.parseObject(JSONObject.toJSONString(tableDTO));
  181. JSONObject bodyParam = new JSONObject();
  182. bodyParam.put("msg_type", "interactive");
  183. bodyParam.put("card", content);
  184. LarkRobotUtil.sendAutoReplyVideoMessage(bodyParam);
  185. return ReturnT.SUCCESS;
  186. }
  187. private List<FeishuTableDTO.Column> buildCheckPublishPlanAccountColumns() {
  188. List<FeishuTableDTO.Column> columns = new ArrayList<>();
  189. FeishuTableDTO.Column nameColumn = FeishuTableDTO.createFeishuColumns(
  190. FieshuTableColumnDataTypeEnum.TEXT.getType(), "name", "账号名称", null);
  191. columns.add(nameColumn);
  192. FeishuTableDTO.Column channelColumn = FeishuTableDTO.createFeishuColumns(
  193. FieshuTableColumnDataTypeEnum.TEXT.getType(), "channel", "渠道id", null);
  194. columns.add(channelColumn);
  195. FeishuTableDTO.Column videoColumn = FeishuTableDTO.createFeishuColumns(
  196. FieshuTableColumnDataTypeEnum.TEXT.getType(), "video", "审核不通过的视频id", null);
  197. columns.add(videoColumn);
  198. FeishuTableDTO.Column ghIdColumn = FeishuTableDTO.createFeishuColumns(
  199. FieshuTableColumnDataTypeEnum.TEXT.getType(), "ghId", "ghId", null);
  200. columns.add(ghIdColumn);
  201. return columns;
  202. }
  203. @XxlJob("updateRootSourceIdJob")
  204. public ReturnT<String> updateRootSourceId(String param) {
  205. CgiReplyBucketDataExample example = new CgiReplyBucketDataExample();
  206. example.createCriteria().andRootSourceIdIsNull();
  207. List<CgiReplyBucketData> cgiReplyBucketData = cgiReplyBucketDataMapper.selectByExample(example);
  208. if (!CollectionUtils.isEmpty(cgiReplyBucketData)) {
  209. for (CgiReplyBucketData replyBucketData : cgiReplyBucketData) {
  210. String rootSourceId = MessageUtil.getRootSourceId(replyBucketData.getMiniPagePath());
  211. if(StringUtils.isEmpty(rootSourceId)){
  212. continue;
  213. }
  214. CgiReplyBucketData updateReplyBucketData = new CgiReplyBucketData();
  215. updateReplyBucketData.setId(replyBucketData.getId());
  216. updateReplyBucketData.setRootSourceId(rootSourceId);
  217. cgiReplyBucketDataMapper.updateByPrimaryKeySelective(updateReplyBucketData);
  218. }
  219. }
  220. return ReturnT.SUCCESS;
  221. }
  222. }