|
@@ -0,0 +1,228 @@
|
|
|
+package com.tzld.longarticle.recommend.server.service.video.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
|
|
|
+import com.tzld.longarticle.recommend.server.common.enums.MinigramEnum;
|
|
|
+import com.tzld.longarticle.recommend.server.common.enums.longArticle.ConstantStatusEnum;
|
|
|
+import com.tzld.longarticle.recommend.server.common.response.CommonResponse;
|
|
|
+import com.tzld.longarticle.recommend.server.model.bo.CardData;
|
|
|
+import com.tzld.longarticle.recommend.server.model.entity.longArticle.*;
|
|
|
+import com.tzld.longarticle.recommend.server.model.param.ChooseMinigramParam;
|
|
|
+import com.tzld.longarticle.recommend.server.model.param.GetOffVideosParam;
|
|
|
+import com.tzld.longarticle.recommend.server.model.param.RecallVideosParam;
|
|
|
+import com.tzld.longarticle.recommend.server.model.param.SearchVideoParam;
|
|
|
+import com.tzld.longarticle.recommend.server.model.vo.ChooseMinigramResponse;
|
|
|
+import com.tzld.longarticle.recommend.server.model.vo.SearchVideoResponse;
|
|
|
+import com.tzld.longarticle.recommend.server.repository.longArticle.*;
|
|
|
+import com.tzld.longarticle.recommend.server.service.video.CardGeneratorService;
|
|
|
+import com.tzld.longarticle.recommend.server.service.video.MatchVideoService;
|
|
|
+import com.tzld.longarticle.recommend.server.util.http.HttpClientUtils;
|
|
|
+import com.tzld.longarticle.recommend.server.util.http.HttpResponseContent;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.checkerframework.checker.units.qual.A;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class MatchVideoServiceImpl implements MatchVideoService {
|
|
|
+
|
|
|
+ @ApolloJsonValue("${ghIdInPqVideo:[\"gh_2ad5072e7a76\",\"gh_57c9e8babea7\",\"gh_a61d7ae2e594\",\"gh_2fe4c2f7d571\",\"gh_d8c215687f02\",\"gh_749271f1ccd5\",\"gh_617684416aec\",\"gh_a221d1a952aa\",\"gh_ec42d1027ba5\",\"gh_e3a8e14013cd\",\"gh_9ee8fc75c07f\",\"gh_0e4fd9e88386\",\"gh_2e8ae0384787\",\"gh_7c66e0dbd2cf\",\"gh_755225d8ede5\",\"gh_92da3c574f82\",\"gh_31e523f45168\",\"gh_df59c5e42954\",\"gh_6d3aa9d13402\",\"gh_810a439f320a\",\"gh_2e0c4609839f\",\"gh_f1122b34f1f3\",\"gh_da44c409ec0f\",\"gh_2e615fa75ffb\",\"gh_d32fe439b098\",\"gh_d7fa1998b4e1\",\"gh_abc6794e6996\",\"gh_c43c01198e6a\",\"gh_a447c30961b7\",\"gh_dc2da0611278\",\"gh_156c66ac3e37\",\"gh_ddf6ec0104d0\",\"gh_39218d3a3ec1\",\"gh_98ec0ffe69b3\",\"gh_243829b5ff02\",\"gh_03d32e83122f\",\"gh_a1c2771f8020\",\"gh_4f6bfd731ac8\",\"gh_9360765baf6a\",\"gh_1686250f15b6\",\"gh_6e977e8cd40d\",\"gh_dfa7599c181f\"]}")
|
|
|
+ private List<String> ghIdInPqVideo;
|
|
|
+
|
|
|
+ private static final Set<String> EXPERIMENT_27_GH_ID_SET = new HashSet<String>() {{
|
|
|
+ add("gh_970460d9ccec");
|
|
|
+ add("gh_bfea052b5baa");
|
|
|
+ add("gh_5d18ac6e3118");
|
|
|
+ add("gh_660afe87b6fd");
|
|
|
+ add("gh_7c66e0dbd2cf");
|
|
|
+ add("gh_57c9e8babea7");
|
|
|
+ add("gh_749271f1ccd5");
|
|
|
+ add("gh_2e615fa75ffb");
|
|
|
+ add("gh_486568379bf8");
|
|
|
+ add("gh_c9b664360ce6");
|
|
|
+ add("gh_98ec0ffe69b3");
|
|
|
+ add("gh_03d45c260115");
|
|
|
+ add("gh_6d3aa9d13402");
|
|
|
+ add("gh_1686250f15b6");
|
|
|
+ }};
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private LongArticlesMatchVideoRepository longArticlesMatchVideoRepository;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private GetOffVideoArticleRepository getOffVideoArticleRepository;
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private LongArticlesTextRepository longArticlesTextRepository;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CrawlerProduceIdMapRepository crawlerProduceIdMapRepository;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private LongArticlesPublishedTraceIdRepository longArticlesPublishedTraceIdRepository;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CardGeneratorService cardGeneratorService;
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public CommonResponse<SearchVideoResponse> searchVideo(SearchVideoParam searchVideoParam) {
|
|
|
+ if (StringUtils.isEmpty(searchVideoParam.getContent())
|
|
|
+ || StringUtils.isEmpty(searchVideoParam.getArticleId())
|
|
|
+ || StringUtils.isEmpty(searchVideoParam.getGhId())
|
|
|
+ || StringUtils.isEmpty(searchVideoParam.getAccountName())
|
|
|
+ || StringUtils.isEmpty(searchVideoParam.getTitle())) {
|
|
|
+ SearchVideoResponse searchVideoResponse = new SearchVideoResponse();
|
|
|
+ searchVideoResponse.setCode(1);
|
|
|
+ searchVideoResponse.setStatus("fail");
|
|
|
+ searchVideoResponse.setInfo("params check error");
|
|
|
+ return CommonResponse.success(searchVideoResponse);
|
|
|
+ }
|
|
|
+ String traceId = String.format("search-%s-%s", UUID.randomUUID(), System.currentTimeMillis() / 1000);
|
|
|
+ LongArticlesMatchVideo longArticlesMatchVideo = new LongArticlesMatchVideo();
|
|
|
+ longArticlesMatchVideo.setTraceId(traceId);
|
|
|
+ longArticlesMatchVideo.setContentId(searchVideoParam.getArticleId());
|
|
|
+ longArticlesMatchVideo.setFlowPoolLevel(searchVideoParam.getFlowPoolLevelTag());
|
|
|
+ longArticlesMatchVideo.setGhId(searchVideoParam.getGhId());
|
|
|
+ longArticlesMatchVideo.setAccountName(searchVideoParam.getAccountName());
|
|
|
+ longArticlesMatchVideo.setRequestTimestamp(System.currentTimeMillis() / 1000);
|
|
|
+ if (searchVideoParam.getPublishFlag() == null) {
|
|
|
+ longArticlesMatchVideo.setPublishFlag(1);
|
|
|
+ } else {
|
|
|
+ longArticlesMatchVideo.setPublishFlag(searchVideoParam.getPublishFlag());
|
|
|
+ }
|
|
|
+ longArticlesMatchVideoRepository.save(longArticlesMatchVideo);
|
|
|
+
|
|
|
+
|
|
|
+ LongArticlesText longArticlesText = new LongArticlesText();
|
|
|
+ longArticlesText.setContentId(searchVideoParam.getArticleId());
|
|
|
+ longArticlesText.setArticleTitle(searchVideoParam.getTitle());
|
|
|
+ longArticlesText.setArticleTitle(searchVideoParam.getContent());
|
|
|
+ longArticlesTextRepository.save(longArticlesText);
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(searchVideoParam.getChannelContentId())) {
|
|
|
+ CrawlerProduceIdMap crawlerProduceIdMap = new CrawlerProduceIdMap();
|
|
|
+ crawlerProduceIdMap.setChannelContentId(searchVideoParam.getChannelContentId());
|
|
|
+ crawlerProduceIdMap.setContentId(searchVideoParam.getArticleId());
|
|
|
+ crawlerProduceIdMapRepository.save(crawlerProduceIdMap);
|
|
|
+ }
|
|
|
+ SearchVideoResponse searchVideoResponse = new SearchVideoResponse();
|
|
|
+ searchVideoResponse.setCode(0);
|
|
|
+ searchVideoResponse.setStatus("success input to article queue");
|
|
|
+ searchVideoResponse.setTraceId(traceId);
|
|
|
+ return CommonResponse.success(searchVideoResponse);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CommonResponse<ChooseMinigramResponse> chooseMinigram(ChooseMinigramParam chooseMinigramParam) {
|
|
|
+ String ghId = chooseMinigramParam.getGhId();
|
|
|
+ ChooseMinigramResponse chooseMinigramResponse = new ChooseMinigramResponse();
|
|
|
+ if (ghId != null && EXPERIMENT_27_GH_ID_SET.contains(ghId)) {
|
|
|
+ chooseMinigramResponse.setProgramAvatar(MinigramEnum.XYMHFQDD_27.getAvatar());
|
|
|
+ chooseMinigramResponse.setProgramId(MinigramEnum.XYMHFQDD_27.getId());
|
|
|
+ chooseMinigramResponse.setProgramName(MinigramEnum.XYMHFQDD_27.getName());
|
|
|
+ chooseMinigramResponse.setTrace_id(chooseMinigramParam.getTraceId());
|
|
|
+ } else if (ghId != null && ghIdInPqVideo.contains(ghId)) {
|
|
|
+ chooseMinigramResponse.setProgramAvatar(MinigramEnum.PQSP4.getAvatar());
|
|
|
+ chooseMinigramResponse.setProgramId(MinigramEnum.PQSP4.getId());
|
|
|
+ chooseMinigramResponse.setProgramName(MinigramEnum.PQSP4.getName());
|
|
|
+ chooseMinigramResponse.setTrace_id(chooseMinigramParam.getTraceId());
|
|
|
+ } else {
|
|
|
+ chooseMinigramResponse.setProgramAvatar(MinigramEnum.VLOG0.getAvatar());
|
|
|
+ chooseMinigramResponse.setProgramId(MinigramEnum.VLOG0.getId());
|
|
|
+ chooseMinigramResponse.setProgramName(MinigramEnum.VLOG0.getName());
|
|
|
+ chooseMinigramResponse.setTrace_id(chooseMinigramParam.getTraceId());
|
|
|
+ }
|
|
|
+ return CommonResponse.success(chooseMinigramResponse);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getOffVideos(GetOffVideosParam getOffVideosParam) {
|
|
|
+ JSONObject res = new JSONObject();
|
|
|
+ if (StringUtils.isEmpty(getOffVideosParam.getPushType()) || StringUtils.isEmpty(getOffVideosParam.getTraceId())) {
|
|
|
+ res.put("error", "params error");
|
|
|
+ return res.toJSONString();
|
|
|
+ }
|
|
|
+ if (!getOffVideosParam.getTraceId().startsWith("search")) {
|
|
|
+ res.put("msg", "do not process trace id");
|
|
|
+ return res.toJSONString();
|
|
|
+ }
|
|
|
+ String traceId = getOffVideosParam.getTraceId();
|
|
|
+ LongArticlesMatchVideo matchVideo = longArticlesMatchVideoRepository.getByTraceId(traceId);
|
|
|
+ if (matchVideo == null) {
|
|
|
+ String url = "http://192.168.205.85:8111/get_off_videos";
|
|
|
+ JSONObject param = new JSONObject();
|
|
|
+ param.put("traceId", getOffVideosParam.getTraceId());
|
|
|
+ HttpResponseContent httpResponseContent = HttpClientUtils.postData(url, param.toJSONString(),
|
|
|
+ HttpClientUtils.contentTypeJson);
|
|
|
+ return httpResponseContent.getBodyContent();
|
|
|
+ }
|
|
|
+ String ghId = matchVideo.getGhId();
|
|
|
+ String response = matchVideo.getResponse();
|
|
|
+ List<Long> videoIds = JSONArray.parseArray(response, Long.class);
|
|
|
+ if (CollectionUtils.isNotEmpty(videoIds)) {
|
|
|
+ List<GetOffVideoArticle> addList = new ArrayList<>();
|
|
|
+ for (Long videoId : videoIds) {
|
|
|
+ GetOffVideoArticle getOffVideoArticle = new GetOffVideoArticle();
|
|
|
+ getOffVideoArticle.setTraceId(getOffVideosParam.getTraceId());
|
|
|
+ getOffVideoArticle.setVideoId(videoId);
|
|
|
+ getOffVideoArticle.setVideoStatus(1);
|
|
|
+ getOffVideoArticle.setPublishTime(System.currentTimeMillis() / 1000);
|
|
|
+ addList.add(getOffVideoArticle);
|
|
|
+ }
|
|
|
+ getOffVideoArticleRepository.saveAll(addList);
|
|
|
+ }
|
|
|
+ LongArticlesPublishedTraceId longArticlesPublishedTraceId = new LongArticlesPublishedTraceId();
|
|
|
+ longArticlesPublishedTraceId.setGhId(ghId);
|
|
|
+ longArticlesPublishedTraceId.setTraceId(traceId);
|
|
|
+ longArticlesPublishedTraceId.setPushType(getOffVideosParam.getPushType());
|
|
|
+ longArticlesPublishedTraceId.setCreateTimestamp(System.currentTimeMillis() / 1000);
|
|
|
+ longArticlesPublishedTraceIdRepository.save(longArticlesPublishedTraceId);
|
|
|
+
|
|
|
+ res.put("status", "success");
|
|
|
+ res.put("traceId", traceId);
|
|
|
+ return res.toJSONString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String recallVideos(RecallVideosParam recallVideosParam) throws UnsupportedEncodingException {
|
|
|
+ JSONObject res = new JSONObject();
|
|
|
+ String traceId = recallVideosParam.getTraceId();
|
|
|
+ Integer miniprogramUseType = recallVideosParam.getMiniprogramUseType();
|
|
|
+ LongArticlesMatchVideo matchVideo = longArticlesMatchVideoRepository.getByTraceId(traceId);
|
|
|
+ if (matchVideo == null) {
|
|
|
+ String url = "http://192.168.205.85:8111/recall_videos";
|
|
|
+ JSONObject param = new JSONObject();
|
|
|
+ param.put("traceId", traceId);
|
|
|
+ param.put("miniprogramUseType", miniprogramUseType);
|
|
|
+ HttpResponseContent httpResponseContent = HttpClientUtils.postData(url, param.toJSONString(),
|
|
|
+ HttpClientUtils.contentTypeJson);
|
|
|
+ return httpResponseContent.getBodyContent();
|
|
|
+ }
|
|
|
+ LongArticlesMatchVideo longArticlesMatchVideo = longArticlesMatchVideoRepository.getByTraceId(traceId);
|
|
|
+ if (Objects.equals(longArticlesMatchVideo.getContentStatus(), ConstantStatusEnum.TASK_PUBLISHED_CODE.getCode())) {
|
|
|
+ CardData cardData = cardGeneratorService.generateCards(longArticlesMatchVideo.getGhId(),
|
|
|
+ longArticlesMatchVideo.getResponse(), miniprogramUseType);
|
|
|
+ List<JSONObject> cardList = cardData.getCardList();
|
|
|
+ res.put("traceId", traceId);
|
|
|
+ res.put("miniprogramList", cardList);
|
|
|
+ longArticlesMatchVideo.setResponse(cardData.getNewItemList().toJSONString());
|
|
|
+ longArticlesMatchVideo.setSuccessStatus(1);
|
|
|
+ longArticlesMatchVideoRepository.save(longArticlesMatchVideo);
|
|
|
+ return res.toJSONString();
|
|
|
+ }
|
|
|
+
|
|
|
+ res.put("traceId", traceId);
|
|
|
+ res.put("code", longArticlesMatchVideo.getContentStatus());
|
|
|
+ return res.toJSONString();
|
|
|
+ }
|
|
|
+}
|