|
@@ -0,0 +1,375 @@
|
|
|
+package com.tzld.longarticle.recommend.server.service;
|
|
|
+
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
|
|
+import com.tzld.longarticle.recommend.server.common.CommonThreadPoolExecutor;
|
|
|
+import com.tzld.longarticle.recommend.server.common.ThreadPoolFactory;
|
|
|
+import com.tzld.longarticle.recommend.server.mapper.crawler.CrawlerBaseMapper;
|
|
|
+import com.tzld.longarticle.recommend.server.mapper.longArticle.LongArticleBaseMapper;
|
|
|
+import com.tzld.longarticle.recommend.server.model.dto.*;
|
|
|
+import com.tzld.longarticle.recommend.server.model.entity.longArticle.LongArticlesRootSourceId;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+
|
|
|
+import java.net.URLDecoder;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class DataFlushService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private LongArticleBaseMapper longArticleBaseMapper;
|
|
|
+ @Autowired
|
|
|
+ private CrawlerBaseMapper crawlerBaseMapper;
|
|
|
+
|
|
|
+ private final ExecutorService pool = ThreadPoolFactory.deDuplicatePool();
|
|
|
+
|
|
|
+
|
|
|
+ public void flushGetOffVideos(Integer pageNum) {
|
|
|
+ int pageSize = 1000;
|
|
|
+ if (pageNum == null) {
|
|
|
+ pageNum = 1;
|
|
|
+ }
|
|
|
+ int count = crawlerBaseMapper.countGetOffVideos();
|
|
|
+ int totalPage = count / pageSize + 1;
|
|
|
+ int flushNum = 0;
|
|
|
+ while (pageNum <= totalPage) {
|
|
|
+ int offset = (pageNum - 1) * pageSize;
|
|
|
+ List<GetOffVideos> list = crawlerBaseMapper.pageGetOffVideos(offset, pageSize);
|
|
|
+ List<Long> videoIds = list.stream().map(GetOffVideos::getVideoId)
|
|
|
+ .distinct().collect(Collectors.toList());
|
|
|
+ List<GetOffVideos> existsList = longArticleBaseMapper.getGetOffVideos(videoIds);
|
|
|
+ Set<Long> existsIds = existsList.stream().map(GetOffVideos::getVideoId).collect(Collectors.toSet());
|
|
|
+ list = list.stream().filter(o -> !existsIds.contains(o.getVideoId())).collect(Collectors.toList());
|
|
|
+ if (CollectionUtil.isNotEmpty(list)) {
|
|
|
+ longArticleBaseMapper.batchInsertGetOffVideos(list);
|
|
|
+ }
|
|
|
+ log.info("flushGetOffVideos pageNum:{} totalPage:{} flushNum:{}", pageNum, totalPage, list.size());
|
|
|
+ flushNum += list.size();
|
|
|
+ pageNum++;
|
|
|
+ }
|
|
|
+ log.info("flushGetOffVideos flushNum:{}", flushNum);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void flushLongArticlesRootSourceId(Integer pageNum) {
|
|
|
+ int pageSize = 1000;
|
|
|
+ if (pageNum == null) {
|
|
|
+ pageNum = 1;
|
|
|
+ }
|
|
|
+ int count = crawlerBaseMapper.countLongArticlesRootSourceId();
|
|
|
+ int totalPage = count / pageSize + 1;
|
|
|
+ while (pageNum <= totalPage) {
|
|
|
+ int offset = (pageNum - 1) * pageSize;
|
|
|
+ List<LongArticlesRootSourceId> list = crawlerBaseMapper.pageLongArticlesRootSourceId(offset, pageSize);
|
|
|
+ List<String> rootSourceIdList = list.stream().map(LongArticlesRootSourceId::getRootSourceId)
|
|
|
+ .distinct().collect(Collectors.toList());
|
|
|
+ List<LongArticlesRootSourceId> existsList = longArticleBaseMapper.getLongArticlesRootSourceId(rootSourceIdList);
|
|
|
+ Set<String> existsIds = existsList.stream().map(LongArticlesRootSourceId::getRootSourceId).collect(Collectors.toSet());
|
|
|
+ list = list.stream().filter(o -> !existsIds.contains(o.getRootSourceId())).collect(Collectors.toList());
|
|
|
+ if (CollectionUtil.isNotEmpty(list)) {
|
|
|
+ longArticleBaseMapper.batchInsertLongArticlesRootSourceId(list);
|
|
|
+ }
|
|
|
+ log.info("flushLongArticlesRootSourceId pageNum:{} totalPage:{} existsSize: {}", pageNum, totalPage, existsList.size());
|
|
|
+ pageNum++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void flushLongArticlesCrawlerVideos(Integer pageNum) {
|
|
|
+ List<ArticleMatchVideos> list = crawlerBaseMapper.pageArticleMatchVideos();
|
|
|
+ list = list.stream().filter(o -> StringUtils.hasText(o.getVideoPath())).collect(Collectors.toList());
|
|
|
+ Map<String, List<ArticleMatchVideos>> map = list.stream().collect(Collectors.groupingBy(ArticleMatchVideos::getContentId));
|
|
|
+ List<LongArticlesCrawlerVideos> batchSaveList = new ArrayList<>();
|
|
|
+ for (ArticleMatchVideos articleMatchVideos : list) {
|
|
|
+ List<ArticleMatchVideos> mapList = map.get(articleMatchVideos.getContentId());
|
|
|
+ List<Date> orderDate = mapList.stream().map(ArticleMatchVideos::getUpdateTime)
|
|
|
+ .sorted().collect(Collectors.toList());
|
|
|
+ double score = 0.2;
|
|
|
+ for (int i = 0; i < orderDate.size(); i++) {
|
|
|
+ if (orderDate.get(i).equals(articleMatchVideos.getUpdateTime())) {
|
|
|
+ if (i == 0) {
|
|
|
+ score = 1;
|
|
|
+ } else if (i == 1) {
|
|
|
+ score = 0.5;
|
|
|
+ } else {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ LongArticlesCrawlerVideos saveItem = new LongArticlesCrawlerVideos();
|
|
|
+ saveItem.setContentId(articleMatchVideos.getContentId());
|
|
|
+ saveItem.setPlatform(articleMatchVideos.getPlatform());
|
|
|
+ saveItem.setVideoTitle(articleMatchVideos.getVideoTitle());
|
|
|
+ saveItem.setCrawlerTime(articleMatchVideos.getUpdateTime());
|
|
|
+ saveItem.setVideoOssPath(articleMatchVideos.getVideoPath());
|
|
|
+ saveItem.setCoverOssPath(articleMatchVideos.getCoverPath());
|
|
|
+ saveItem.setUserId(articleMatchVideos.getUid());
|
|
|
+ saveItem.setTraceId(articleMatchVideos.getTraceId());
|
|
|
+ saveItem.setDownloadStatus(2);
|
|
|
+ saveItem.setScore(score / 1000);
|
|
|
+ batchSaveList.add(saveItem);
|
|
|
+ }
|
|
|
+ int flushNum = 0;
|
|
|
+ if (!CollectionUtils.isEmpty(batchSaveList)) {
|
|
|
+ for (List<LongArticlesCrawlerVideos> partition : Lists.partition(batchSaveList, 1000)) {
|
|
|
+ List<String> contentIds = partition.stream().map(LongArticlesCrawlerVideos::getContentId).collect(Collectors.toList());
|
|
|
+ List<LongArticlesCrawlerVideos> existsList = longArticleBaseMapper.getLongArticlesCrawlerVideos(contentIds);
|
|
|
+ Map<String, List<LongArticlesCrawlerVideos>> existsMap = existsList.stream()
|
|
|
+ .collect(Collectors.groupingBy(LongArticlesCrawlerVideos::getContentId));
|
|
|
+ partition = partition.stream().filter(o -> {
|
|
|
+ List<LongArticlesCrawlerVideos> itemList = existsMap.get(o.getContentId());
|
|
|
+ return CollectionUtil.isEmpty(itemList) || itemList.size() < 3;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ if (CollectionUtil.isNotEmpty(partition)) {
|
|
|
+ longArticleBaseMapper.batchInsertLongArticlesCrawlerVideos(partition);
|
|
|
+ flushNum += partition.size();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.info("flushLongArticlesCrawlerVideos flushNum:{}", flushNum);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void flushLongArticlesVideos(Integer pageNum, Long id) {
|
|
|
+ int pageSize = 1000;
|
|
|
+ List<LongArticlesText> kimiTitleList = crawlerBaseMapper.getLongArticlesText();
|
|
|
+ Map<String, LongArticlesText> kimiTitleMap = kimiTitleList.stream().collect(
|
|
|
+ Collectors.toMap(LongArticlesText::getContentId, o -> o, (existing, replacement) -> replacement));
|
|
|
+ int count = crawlerBaseMapper.countLongArticlesVideos();
|
|
|
+ int totalPage = count / pageSize + 1;
|
|
|
+ int longArticlesTextFlushNum = 0;
|
|
|
+ int longArticlesMatchVideosFlushNum = 0;
|
|
|
+ while (true) {
|
|
|
+ List<LongArticlesVideoDTO> list = crawlerBaseMapper.pageLongArticlesVideos(id, pageSize);
|
|
|
+ if (CollectionUtils.isEmpty(list)) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ id = list.stream().mapToLong(LongArticlesVideoDTO::getId).max().getAsLong();
|
|
|
+ List<LongArticlesText> batchSaveLongArticlesTextList = new ArrayList<>();
|
|
|
+ List<LongArticlesMatchVideos> batchSaveLongArticlesMatchVideosList = new ArrayList<>();
|
|
|
+ Set<String> existsIdSet = new HashSet<>();
|
|
|
+ for (LongArticlesVideoDTO longArticlesVideoDTO : list) {
|
|
|
+ if (longArticlesVideoDTO.getContentId().endsWith("lehuo")) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (!existsIdSet.contains(longArticlesVideoDTO.getContentId())) {
|
|
|
+ LongArticlesText longArticlesText = new LongArticlesText();
|
|
|
+ longArticlesText.setContentId(longArticlesVideoDTO.getContentId());
|
|
|
+ longArticlesText.setArticleTitle(longArticlesVideoDTO.getArticleTitle());
|
|
|
+ longArticlesText.setArticleText(longArticlesVideoDTO.getArticleText());
|
|
|
+ if (StringUtils.hasText(longArticlesVideoDTO.getArticleText())) {
|
|
|
+ longArticlesText.setKimiTitle(longArticlesVideoDTO.getKimiTitle().replace("\"", ""));
|
|
|
+ }
|
|
|
+ if (StringUtils.hasText(longArticlesVideoDTO.getKimiSummary())) {
|
|
|
+ longArticlesText.setKimiSummary(longArticlesVideoDTO.getKimiSummary());
|
|
|
+ longArticlesText.setKimiKeys(longArticlesVideoDTO.getKimiKeys());
|
|
|
+ } else {
|
|
|
+ LongArticlesText text = kimiTitleMap.get(longArticlesVideoDTO.getContentId());
|
|
|
+ longArticlesText.setKimiSummary(text.getKimiSummary());
|
|
|
+ longArticlesText.setKimiKeys(text.getKimiKeys());
|
|
|
+ }
|
|
|
+ longArticlesText.setKimiStatus(1);
|
|
|
+ batchSaveLongArticlesTextList.add(longArticlesText);
|
|
|
+ existsIdSet.add(longArticlesVideoDTO.getContentId());
|
|
|
+ }
|
|
|
+ if (Objects.isNull(longArticlesVideoDTO.getRequestTimeStamp())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ LongArticlesMatchVideos longArticlesMatchVideos = new LongArticlesMatchVideos();
|
|
|
+ longArticlesMatchVideos.setContentId(longArticlesVideoDTO.getContentId());
|
|
|
+ longArticlesMatchVideos.setTraceId(longArticlesVideoDTO.getTraceId());
|
|
|
+ longArticlesMatchVideos.setGhId(longArticlesVideoDTO.getGhId());
|
|
|
+ longArticlesMatchVideos.setAccountName(longArticlesVideoDTO.getAccountName());
|
|
|
+ longArticlesMatchVideos.setContentStatus(4);
|
|
|
+ longArticlesMatchVideos.setSuccessStatus(longArticlesVideoDTO.getSuccess());
|
|
|
+ longArticlesMatchVideos.setRequestTimestamp(longArticlesVideoDTO.getRequestTimeStamp());
|
|
|
+ longArticlesMatchVideos.setUpdateTime(longArticlesVideoDTO.getUpdateTime());
|
|
|
+ longArticlesMatchVideos.setProcessTimes(longArticlesVideoDTO.getProcessTimes());
|
|
|
+ longArticlesMatchVideos.setResponse(getLongArticleVideoResponse(longArticlesVideoDTO));
|
|
|
+ batchSaveLongArticlesMatchVideosList.add(longArticlesMatchVideos);
|
|
|
+ }
|
|
|
+ if (CollectionUtil.isNotEmpty(batchSaveLongArticlesTextList)) {
|
|
|
+ List<String> contentIds = batchSaveLongArticlesTextList.stream()
|
|
|
+ .map(LongArticlesText::getContentId).distinct().collect(Collectors.toList());
|
|
|
+ List<String> existsContentIds = longArticleBaseMapper.getLongArticlesTextByContentIds(contentIds);
|
|
|
+ if (CollectionUtil.isNotEmpty(existsContentIds)) {
|
|
|
+ batchSaveLongArticlesTextList = batchSaveLongArticlesTextList.stream()
|
|
|
+ .filter(o -> !existsContentIds.contains(o.getContentId())).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ if (CollectionUtil.isNotEmpty(batchSaveLongArticlesTextList)) {
|
|
|
+ longArticleBaseMapper.batchInsertLongArticlesText(batchSaveLongArticlesTextList);
|
|
|
+ longArticlesTextFlushNum += batchSaveLongArticlesTextList.size();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (CollectionUtil.isNotEmpty(batchSaveLongArticlesMatchVideosList)) {
|
|
|
+ List<String> traceIds = batchSaveLongArticlesMatchVideosList.stream().map(LongArticlesMatchVideos::getTraceId)
|
|
|
+ .distinct().collect(Collectors.toList());
|
|
|
+ List<LongArticlesMatchVideos> existsList = longArticleBaseMapper.getLongArticlesMatchVideos(traceIds);
|
|
|
+ Set<String> existsIds = existsList.stream().map(LongArticlesMatchVideos::getTraceId).collect(Collectors.toSet());
|
|
|
+ batchSaveLongArticlesMatchVideosList = batchSaveLongArticlesMatchVideosList.stream()
|
|
|
+ .filter(o -> !existsIds.contains(o.getTraceId())).collect(Collectors.toList());
|
|
|
+ if (CollectionUtil.isNotEmpty(batchSaveLongArticlesMatchVideosList)) {
|
|
|
+ longArticleBaseMapper.batchInsertLongArticlesMatchVideos(batchSaveLongArticlesMatchVideosList);
|
|
|
+ longArticlesMatchVideosFlushNum += batchSaveLongArticlesMatchVideosList.size();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.info("flushLongArticlesVideos pageNum:{} totalPage:{} id:{} longArticlesMatchVideosFlushNum:{}",
|
|
|
+ pageNum, totalPage, id, longArticlesMatchVideosFlushNum);
|
|
|
+ pageNum++;
|
|
|
+ }
|
|
|
+ log.info("flushLongArticlesVideos longArticlesTextFlushNum:{} longArticlesMatchVideosFlushNum:{}",
|
|
|
+ longArticlesTextFlushNum, longArticlesMatchVideosFlushNum);
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getLongArticleVideoResponse(LongArticlesVideoDTO longArticlesVideoDTO) {
|
|
|
+ JSONArray jsonArray = new JSONArray();
|
|
|
+ if (StringUtils.hasText(longArticlesVideoDTO.getResult1())) {
|
|
|
+ if (StringUtils.hasText(longArticlesVideoDTO.getKimiTitle()) && longArticlesVideoDTO.getKimiTitle().contains("\"")) {
|
|
|
+ longArticlesVideoDTO.setResult1(longArticlesVideoDTO.getResult1().replace(longArticlesVideoDTO.getKimiTitle(),
|
|
|
+ longArticlesVideoDTO.getKimiTitle().replace("\"", "")));
|
|
|
+ }
|
|
|
+ jsonArray.add(resultToResponse(longArticlesVideoDTO.getResult1()));
|
|
|
+ }
|
|
|
+ if (StringUtils.hasText(longArticlesVideoDTO.getResult2())) {
|
|
|
+ if (StringUtils.hasText(longArticlesVideoDTO.getKimiTitle()) && longArticlesVideoDTO.getKimiTitle().contains("\"")) {
|
|
|
+ longArticlesVideoDTO.setResult2(longArticlesVideoDTO.getResult2().replace(longArticlesVideoDTO.getKimiTitle(),
|
|
|
+ longArticlesVideoDTO.getKimiTitle().replace("\"", "")));
|
|
|
+ }
|
|
|
+ jsonArray.add(resultToResponse(longArticlesVideoDTO.getResult2()));
|
|
|
+ }
|
|
|
+ if (StringUtils.hasText(longArticlesVideoDTO.getResult3())) {
|
|
|
+ if (StringUtils.hasText(longArticlesVideoDTO.getKimiTitle()) && longArticlesVideoDTO.getKimiTitle().contains("\"")) {
|
|
|
+ longArticlesVideoDTO.setResult3(longArticlesVideoDTO.getResult3().replace(longArticlesVideoDTO.getKimiTitle(),
|
|
|
+ longArticlesVideoDTO.getKimiTitle().replace("\"", "")));
|
|
|
+ }
|
|
|
+ jsonArray.add(resultToResponse(longArticlesVideoDTO.getResult3()));
|
|
|
+ }
|
|
|
+ return JSONObject.toJSONString(jsonArray);
|
|
|
+ }
|
|
|
+
|
|
|
+ private JSONObject resultToResponse(String result) {
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ JSONObject fromJSON = JSONObject.parseObject(result);
|
|
|
+ jsonObject.put("kimiTitle", fromJSON.getString("productionName"));
|
|
|
+ jsonObject.put("videoCover", fromJSON.getString("productionCover"));
|
|
|
+ jsonObject.put("videoPath", fromJSON.getString("videoUrl"));
|
|
|
+ jsonObject.put("source", fromJSON.getString("source"));
|
|
|
+ String productionPath = fromJSON.getString("productionPath");
|
|
|
+ String uid = getParamFromPath(productionPath, "su");
|
|
|
+ String videoId = getParamFromPath(productionPath, "id");
|
|
|
+ String rootSourceId = getParamFromPath(productionPath, "rootSourceId");
|
|
|
+ jsonObject.put("uid", uid);
|
|
|
+ if (StringUtils.hasText(videoId)) {
|
|
|
+ jsonObject.put("videoId", Long.valueOf(videoId));
|
|
|
+ }
|
|
|
+ if (StringUtils.hasText(rootSourceId)) {
|
|
|
+ jsonObject.put("rootSourceId", rootSourceId);
|
|
|
+ }
|
|
|
+ return jsonObject;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getParamFromPath(String productionPath, String param) {
|
|
|
+ String decode = URLDecoder.decode(productionPath);
|
|
|
+ String[] sss = decode.split("\\?");
|
|
|
+ for (String ss : sss) {
|
|
|
+ String[] split = ss.split("&");
|
|
|
+ for (String s : split) {
|
|
|
+ if (s.startsWith(param)) {
|
|
|
+ String[] uid = s.split("=");
|
|
|
+ return uid[1];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void flushLongArticlesText() {
|
|
|
+ List<LongArticlesText> kimiTitleList = crawlerBaseMapper.getLongArticlesText();
|
|
|
+ Map<String, LongArticlesText> kimiTitleMap = kimiTitleList.stream().collect(
|
|
|
+ Collectors.toMap(LongArticlesText::getContentId, o -> o, (existing, replacement) -> replacement));
|
|
|
+ List<LongArticlesText> updateList = longArticleBaseMapper.getNeedUpdateRecords();
|
|
|
+ int updateNum = 0;
|
|
|
+ for (LongArticlesText update : updateList) {
|
|
|
+ LongArticlesText kimi = kimiTitleMap.get(update.getContentId());
|
|
|
+ if (Objects.nonNull(kimi)) {
|
|
|
+ pool.submit(() -> {
|
|
|
+ update.setKimiTitle(kimi.getKimiTitle());
|
|
|
+ update.setKimiSummary(kimi.getKimiSummary());
|
|
|
+ update.setKimiKeys(kimi.getKimiKeys());
|
|
|
+ longArticleBaseMapper.updateLongArticlesText(update);
|
|
|
+ });
|
|
|
+ updateNum++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.info("flushLongArticlesText updateNum:{}", updateNum);
|
|
|
+ }
|
|
|
+
|
|
|
+ private final static ExecutorService batchPool = new CommonThreadPoolExecutor(
|
|
|
+ 5,
|
|
|
+ 5,
|
|
|
+ 0L, TimeUnit.SECONDS,
|
|
|
+ new LinkedBlockingQueue<>(10000),
|
|
|
+ new ThreadFactoryBuilder().setNameFormat("batch-%d").build(),
|
|
|
+ new ThreadPoolExecutor.AbortPolicy());
|
|
|
+
|
|
|
+ public void updateLongArticleMatchVideosResponse(Long id) {
|
|
|
+ int pageSize = 1000;
|
|
|
+ if (Objects.isNull(id)) {
|
|
|
+ id = 0L;
|
|
|
+ }
|
|
|
+ int count = longArticleBaseMapper.countNeedMatchVideos(id);
|
|
|
+ CountDownLatch cdl = new CountDownLatch((count / 1000) + 1);
|
|
|
+ while (true) {
|
|
|
+ List<LongArticlesMatchVideos> matchVideosList = longArticleBaseMapper.getNeedMatchVideos(id, pageSize);
|
|
|
+ if (CollectionUtil.isEmpty(matchVideosList)) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ id = matchVideosList.stream().mapToLong(LongArticlesMatchVideos::getId).max().getAsLong();
|
|
|
+ Long finalId = id;
|
|
|
+ batchPool.submit(() -> {
|
|
|
+ try {
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
+ List<String> traceIds = matchVideosList.stream().map(LongArticlesMatchVideos::getTraceId)
|
|
|
+ .distinct().collect(Collectors.toList());
|
|
|
+ List<LongArticlesVideoDTO> longArticlesVideoDTOList = crawlerBaseMapper.getLongArticlesVideo(traceIds);
|
|
|
+ Map<String, LongArticlesVideoDTO> longArticlesVideoMap = longArticlesVideoDTOList.stream().collect(
|
|
|
+ Collectors.toMap(LongArticlesVideoDTO::getTraceId, o -> o, (existing, replacement) -> replacement));
|
|
|
+ CountDownLatch countDownLatch = new CountDownLatch(matchVideosList.size());
|
|
|
+ for (LongArticlesMatchVideos longArticlesMatchVideos : matchVideosList) {
|
|
|
+ pool.submit(() -> {
|
|
|
+ try {
|
|
|
+ LongArticlesVideoDTO longArticlesVideoDTO = longArticlesVideoMap.get(longArticlesMatchVideos.getTraceId());
|
|
|
+ if (Objects.nonNull(longArticlesVideoDTO)) {
|
|
|
+ longArticlesMatchVideos.setResponse(getLongArticleVideoResponse(longArticlesVideoDTO));
|
|
|
+ longArticleBaseMapper.updateLongArticleMatchVideosResponse(longArticlesMatchVideos);
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ countDownLatch.countDown();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ countDownLatch.await();
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ log.error("updateLongArticleMatchVideosResponse InterruptedException", e);
|
|
|
+ }
|
|
|
+ log.info("updateLongArticleMatchVideosResponse end id:{}, cost:{}", finalId, System.currentTimeMillis() - start);
|
|
|
+ } finally {
|
|
|
+ cdl.countDown();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ cdl.await();
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ log.error("updateLongArticleMatchVideosResponse InterruptedException", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|