|
@@ -0,0 +1,247 @@
|
|
|
+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.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 JSONObject searchVideo(SearchVideoParam searchVideoParam) {
|
|
|
+ JSONObject res = new JSONObject();
|
|
|
+ if (StringUtils.isEmpty(searchVideoParam.getContent())
|
|
|
+ || StringUtils.isEmpty(searchVideoParam.getArticleId())
|
|
|
+ || StringUtils.isEmpty(searchVideoParam.getGhId())
|
|
|
+ || StringUtils.isEmpty(searchVideoParam.getAccountName())
|
|
|
+ || StringUtils.isEmpty(searchVideoParam.getTitle())) {
|
|
|
+ res.put("code", 1);
|
|
|
+ res.put("status", "fail");
|
|
|
+ res.put("info", "params check error");
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ 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.setUpdateTime(new Date());
|
|
|
+ longArticlesMatchVideo.setRequestTimestamp(System.currentTimeMillis() / 1000);
|
|
|
+ if (searchVideoParam.getPublishFlag() == null) {
|
|
|
+ longArticlesMatchVideo.setPublishFlag(1);
|
|
|
+ } else {
|
|
|
+ longArticlesMatchVideo.setPublishFlag(searchVideoParam.getPublishFlag());
|
|
|
+ }
|
|
|
+ longArticlesMatchVideo.setVideoPoolTraceId(searchVideoParam.getVideoPoolTraceId());
|
|
|
+ longArticlesMatchVideoRepository.save(longArticlesMatchVideo);
|
|
|
+
|
|
|
+
|
|
|
+ LongArticlesText longArticlesText = new LongArticlesText();
|
|
|
+ longArticlesText.setContentId(searchVideoParam.getArticleId());
|
|
|
+ longArticlesText.setArticleTitle(searchVideoParam.getTitle());
|
|
|
+ longArticlesText.setArticleText(searchVideoParam.getContent());
|
|
|
+ longArticlesText.setKimiStatus(0);
|
|
|
+ longArticlesText.setSimilarityStatus(0);
|
|
|
+ longArticlesTextRepository.save(longArticlesText);
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(searchVideoParam.getChannelContentId())) {
|
|
|
+ CrawlerProduceIdMap crawlerProduceIdMap = new CrawlerProduceIdMap();
|
|
|
+ crawlerProduceIdMap.setChannelContentId(searchVideoParam.getChannelContentId());
|
|
|
+ crawlerProduceIdMap.setContentId(searchVideoParam.getArticleId());
|
|
|
+ crawlerProduceIdMapRepository.save(crawlerProduceIdMap);
|
|
|
+ }
|
|
|
+
|
|
|
+ res.put("code", 0);
|
|
|
+ res.put("status", "success input to article queue");
|
|
|
+ res.put("traceId", traceId);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public JSONObject chooseMinigram(ChooseMinigramParam chooseMinigramParam) {
|
|
|
+ JSONObject res = new JSONObject();
|
|
|
+ if (StringUtils.isEmpty(chooseMinigramParam.getTraceId())
|
|
|
+ || StringUtils.isEmpty(chooseMinigramParam.getBusinessType())
|
|
|
+ || StringUtils.isEmpty(chooseMinigramParam.getMiniCode())) {
|
|
|
+ res.put("status", "fail");
|
|
|
+ res.put("code", 1);
|
|
|
+ res.put("info", "params check error");
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ String ghId = chooseMinigramParam.getGhId();
|
|
|
+ if (ghId != null && ghIdInPqVideo.contains(ghId)) {
|
|
|
+ res.put("programAvatar", MinigramEnum.PQSP4.getAvatar());
|
|
|
+ res.put("programId", MinigramEnum.PQSP4.getId());
|
|
|
+ res.put("programName", MinigramEnum.PQSP4.getName());
|
|
|
+ res.put("trace_id", chooseMinigramParam.getTraceId());
|
|
|
+ } else {
|
|
|
+ res.put("programAvatar", MinigramEnum.VLOG0.getAvatar());
|
|
|
+ res.put("programId", MinigramEnum.VLOG0.getId());
|
|
|
+ res.put("programName", MinigramEnum.VLOG0.getName());
|
|
|
+ res.put("trace_id", chooseMinigramParam.getTraceId());
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public JSONObject getOffVideos(GetOffVideosParam getOffVideosParam) {
|
|
|
+ JSONObject res = new JSONObject();
|
|
|
+ if (StringUtils.isEmpty(getOffVideosParam.getPushType()) || StringUtils.isEmpty(getOffVideosParam.getTraceId())) {
|
|
|
+ res.put("error", "params error");
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ if (!getOffVideosParam.getTraceId().startsWith("search")) {
|
|
|
+ res.put("msg", "do not process trace id");
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ String traceId = getOffVideosParam.getTraceId();
|
|
|
+ LongArticlesMatchVideo matchVideo = longArticlesMatchVideoRepository.getByTraceId(traceId);
|
|
|
+ if (matchVideo == null) {
|
|
|
+ try {
|
|
|
+ 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 JSONObject.parseObject(httpResponseContent.getBodyContent());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("old get_off_videos error", e);
|
|
|
+ }
|
|
|
+ res.put("error", "old get_off_videos error");
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ String ghId = matchVideo.getGhId();
|
|
|
+ String response = matchVideo.getResponse();
|
|
|
+ JSONArray jsonArray = JSONArray.parseArray(response);
|
|
|
+
|
|
|
+ if (CollectionUtils.isNotEmpty(jsonArray)) {
|
|
|
+ List<GetOffVideoArticle> addList = new ArrayList<>();
|
|
|
+ for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
+ JSONObject jsonObject = jsonArray.getJSONObject(i);
|
|
|
+ GetOffVideoArticle getOffVideoArticle = new GetOffVideoArticle();
|
|
|
+ getOffVideoArticle.setTraceId(getOffVideosParam.getTraceId());
|
|
|
+ getOffVideoArticle.setVideoId(jsonObject.getLong("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;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public JSONObject recallVideos(RecallVideosParam recallVideosParam) {
|
|
|
+ JSONObject res = new JSONObject();
|
|
|
+ String traceId = recallVideosParam.getTraceId();
|
|
|
+ Integer miniprogramUseType = recallVideosParam.getMiniprogramUseType();
|
|
|
+ LongArticlesMatchVideo matchVideo = longArticlesMatchVideoRepository.getByTraceId(traceId);
|
|
|
+ if (matchVideo == null) {
|
|
|
+ try {
|
|
|
+ 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 JSONObject.parseObject(httpResponseContent.getBodyContent());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("old recall_videos error", e);
|
|
|
+ }
|
|
|
+ res.put("error", "old recall_videos error");
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ res.put("traceId", traceId);
|
|
|
+ res.put("code", longArticlesMatchVideo.getContentStatus());
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+}
|