|  | @@ -1,10 +1,22 @@
 | 
											
												
													
														|  |  package com.tzld.longarticle.recommend.server.service;
 |  |  package com.tzld.longarticle.recommend.server.service;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  import cn.hutool.core.collection.CollectionUtil;
 |  |  import cn.hutool.core.collection.CollectionUtil;
 | 
											
												
													
														|  | 
 |  | +import com.alibaba.fastjson.JSONArray;
 | 
											
												
													
														|  |  import com.alibaba.fastjson.JSONObject;
 |  |  import com.alibaba.fastjson.JSONObject;
 | 
											
												
													
														|  |  import com.tzld.longarticle.recommend.server.mapper.aigc.AigcBaseMapper;
 |  |  import com.tzld.longarticle.recommend.server.mapper.aigc.AigcBaseMapper;
 | 
											
												
													
														|  | 
 |  | +import com.tzld.longarticle.recommend.server.mapper.crawler.CrawlerBaseMapper;
 | 
											
												
													
														|  |  import com.tzld.longarticle.recommend.server.model.dto.NotPublishPlan;
 |  |  import com.tzld.longarticle.recommend.server.model.dto.NotPublishPlan;
 | 
											
												
													
														|  |  import com.tzld.longarticle.recommend.server.model.entity.aigc.PublishAccount;
 |  |  import com.tzld.longarticle.recommend.server.model.entity.aigc.PublishAccount;
 | 
											
												
													
														|  | 
 |  | +import com.tzld.longarticle.recommend.server.model.entity.crawler.GetOffVideoCrawler;
 | 
											
												
													
														|  | 
 |  | +import com.tzld.longarticle.recommend.server.model.entity.crawler.LongArticlesRootSourceId;
 | 
											
												
													
														|  | 
 |  | +import com.tzld.longarticle.recommend.server.model.entity.crawler.LongArticlesVideo;
 | 
											
												
													
														|  | 
 |  | +import com.tzld.longarticle.recommend.server.model.entity.longArticle.GetOffVideoArticle;
 | 
											
												
													
														|  | 
 |  | +import com.tzld.longarticle.recommend.server.model.entity.longArticle.LongArticlesMatchVideo;
 | 
											
												
													
														|  | 
 |  | +import com.tzld.longarticle.recommend.server.repository.crawler.GetOffVideoCrawlerRepository;
 | 
											
												
													
														|  | 
 |  | +import com.tzld.longarticle.recommend.server.repository.crawler.LongArticlesRootSourceIdRepository;
 | 
											
												
													
														|  | 
 |  | +import com.tzld.longarticle.recommend.server.repository.crawler.LongArticlesVideoRepository;
 | 
											
												
													
														|  | 
 |  | +import com.tzld.longarticle.recommend.server.repository.longArticle.GetOffVideoArticleRepository;
 | 
											
												
													
														|  | 
 |  | +import com.tzld.longarticle.recommend.server.repository.longArticle.LongArticlesMatchVideoRepository;
 | 
											
												
													
														|  |  import com.tzld.longarticle.recommend.server.util.DateUtils;
 |  |  import com.tzld.longarticle.recommend.server.util.DateUtils;
 | 
											
												
													
														|  |  import com.tzld.longarticle.recommend.server.util.feishu.FeishuMessageSender;
 |  |  import com.tzld.longarticle.recommend.server.util.feishu.FeishuMessageSender;
 | 
											
												
													
														|  |  import com.xxl.job.core.biz.model.ReturnT;
 |  |  import com.xxl.job.core.biz.model.ReturnT;
 | 
											
										
											
												
													
														|  | @@ -25,6 +37,18 @@ public class XxlJobService {
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      @Autowired
 |  |      @Autowired
 | 
											
												
													
														|  |      private AigcBaseMapper aigcBaseMapper;
 |  |      private AigcBaseMapper aigcBaseMapper;
 | 
											
												
													
														|  | 
 |  | +    @Autowired
 | 
											
												
													
														|  | 
 |  | +    private CrawlerBaseMapper crawlerBaseMapper;
 | 
											
												
													
														|  | 
 |  | +    @Autowired
 | 
											
												
													
														|  | 
 |  | +    private GetOffVideoCrawlerRepository getOffVideoCrawlerRepository;
 | 
											
												
													
														|  | 
 |  | +    @Autowired
 | 
											
												
													
														|  | 
 |  | +    private LongArticlesVideoRepository longArticlesVideoRepository;
 | 
											
												
													
														|  | 
 |  | +    @Autowired
 | 
											
												
													
														|  | 
 |  | +    private GetOffVideoArticleRepository getOffVideoArticleRepository;
 | 
											
												
													
														|  | 
 |  | +    @Autowired
 | 
											
												
													
														|  | 
 |  | +    private LongArticlesMatchVideoRepository longArticlesMatchVideoRepository;
 | 
											
												
													
														|  | 
 |  | +    @Autowired
 | 
											
												
													
														|  | 
 |  | +    private LongArticlesRootSourceIdRepository longArticlesRootSourceIdRepository;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      @XxlJob("checkPublishPlan")
 |  |      @XxlJob("checkPublishPlan")
 | 
											
												
													
														|  |      public ReturnT<String> checkPublishPlan(String param) {
 |  |      public ReturnT<String> checkPublishPlan(String param) {
 | 
											
										
											
												
													
														|  | @@ -68,4 +92,108 @@ public class XxlJobService {
 | 
											
												
													
														|  |                          + "<at user_id=\"all\">所有人</at> ");
 |  |                          + "<at user_id=\"all\">所有人</at> ");
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +    @XxlJob("migrateCrawlerRootSourceId")
 | 
											
												
													
														|  | 
 |  | +    public ReturnT<String> migrateCrawlerRootSourceId(String param) {
 | 
											
												
													
														|  | 
 |  | +        try {
 | 
											
												
													
														|  | 
 |  | +            long timeStamp = DateUtils.getBeforeDayStart(1);
 | 
											
												
													
														|  | 
 |  | +            if (StringUtils.hasText(param)) {
 | 
											
												
													
														|  | 
 |  | +                timeStamp = DateUtils.getStartOfDay(param, "yyyyMMdd");
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +            List<GetOffVideoCrawler> getOffVideoCrawlerList = getOffVideoCrawlerRepository.getByPublishTimeBetween(timeStamp, timeStamp + 86400);
 | 
											
												
													
														|  | 
 |  | +            List<String> traceIds = getOffVideoCrawlerList.stream().map(GetOffVideoCrawler::getTraceId).distinct().collect(Collectors.toList());
 | 
											
												
													
														|  | 
 |  | +            List<LongArticlesVideo> longArticlesVideoList = longArticlesVideoRepository.getByTraceIdIn(traceIds);
 | 
											
												
													
														|  | 
 |  | +            for (LongArticlesVideo longArticlesVideo : longArticlesVideoList) {
 | 
											
												
													
														|  | 
 |  | +                processCrawlerEachData(longArticlesVideo);
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +        } catch (Exception e) {
 | 
											
												
													
														|  | 
 |  | +            log.error("migrateCrawlerRootSourceId exception: {}", e.getMessage(), e);
 | 
											
												
													
														|  | 
 |  | +            return ReturnT.FAIL;
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +        return ReturnT.SUCCESS;
 | 
											
												
													
														|  | 
 |  | +    }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +    /**
 | 
											
												
													
														|  | 
 |  | +     * Processes each data tuple and updates the rootSourceId.
 | 
											
												
													
														|  | 
 |  | +     */
 | 
											
												
													
														|  | 
 |  | +    public void processCrawlerEachData(LongArticlesVideo longArticlesVideo) {
 | 
											
												
													
														|  | 
 |  | +        try {
 | 
											
												
													
														|  | 
 |  | +            String[] results = {longArticlesVideo.getResult1(), longArticlesVideo.getResult2(), longArticlesVideo.getResult3()};
 | 
											
												
													
														|  | 
 |  | +            List<LongArticlesRootSourceId> saveList = new ArrayList<>();
 | 
											
												
													
														|  | 
 |  | +            for (String result : results) {
 | 
											
												
													
														|  | 
 |  | +                if (result != null && !result.isEmpty()) {
 | 
											
												
													
														|  | 
 |  | +                    try {
 | 
											
												
													
														|  | 
 |  | +                        JSONObject jsonNode = JSONObject.parseObject(result);
 | 
											
												
													
														|  | 
 |  | +                        String productionPath = jsonNode.getString("productionPath");
 | 
											
												
													
														|  | 
 |  | +                        String rootSourceId = productionPath.split("rootSourceId%3D")[1];
 | 
											
												
													
														|  | 
 |  | +                        String videoId = productionPath.split("videos%3Fid%3D")[1].split("%26su%")[0];
 | 
											
												
													
														|  | 
 |  | +                        LongArticlesRootSourceId saveItem = new LongArticlesRootSourceId();
 | 
											
												
													
														|  | 
 |  | +                        saveItem.setRootSourceId(rootSourceId);
 | 
											
												
													
														|  | 
 |  | +                        saveItem.setAccountName(longArticlesVideo.getAccountName());
 | 
											
												
													
														|  | 
 |  | +                        saveItem.setGhId(longArticlesVideo.getGhId());
 | 
											
												
													
														|  | 
 |  | +                        saveItem.setArticleTitle(jsonNode.getString("productionName"));
 | 
											
												
													
														|  | 
 |  | +                        saveItem.setRequestTime(longArticlesVideo.getRequestTimeStamp());
 | 
											
												
													
														|  | 
 |  | +                        saveItem.setTraceId(longArticlesVideo.getTraceId());
 | 
											
												
													
														|  | 
 |  | +                        saveItem.setPushType(2);
 | 
											
												
													
														|  | 
 |  | +                        saveItem.setVideoId(Long.valueOf(videoId));
 | 
											
												
													
														|  | 
 |  | +                        saveList.add(saveItem);
 | 
											
												
													
														|  | 
 |  | +                    } catch (Exception e) {
 | 
											
												
													
														|  | 
 |  | +                        log.error("processCrawlerEachData LongArticlesRootSourceId saveError: {}", result, e);
 | 
											
												
													
														|  | 
 |  | +                    }
 | 
											
												
													
														|  | 
 |  | +                }
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +            if (CollectionUtil.isNotEmpty(saveList)) {
 | 
											
												
													
														|  | 
 |  | +                crawlerBaseMapper.batchInsertLongArticlesRootSourceId(saveList);
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +        } catch (Exception e) {
 | 
											
												
													
														|  | 
 |  | +            log.error("Error processCrawlerEachData: {}", JSONObject.toJSONString(longArticlesVideo), e);
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +    }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +    @XxlJob("migrateArticleRootSourceId")
 | 
											
												
													
														|  | 
 |  | +    public ReturnT<String> migrateArticleRootSourceId(String param) {
 | 
											
												
													
														|  | 
 |  | +        try {
 | 
											
												
													
														|  | 
 |  | +            long timeStamp = DateUtils.getBeforeDayStart(1);
 | 
											
												
													
														|  | 
 |  | +            if (StringUtils.hasText(param)) {
 | 
											
												
													
														|  | 
 |  | +                timeStamp = DateUtils.getStartOfDay(param, "yyyyMMdd");
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +            List<GetOffVideoArticle> getOffVideoArticleList = getOffVideoArticleRepository.getByPublishTimeBetween(timeStamp, timeStamp + 86400);
 | 
											
												
													
														|  | 
 |  | +            List<String> traceIds = getOffVideoArticleList.stream().map(GetOffVideoArticle::getTraceId).distinct().collect(Collectors.toList());
 | 
											
												
													
														|  | 
 |  | +            List<LongArticlesMatchVideo> longArticlesMatchVideoList = longArticlesMatchVideoRepository.getByTraceIdIn(traceIds);
 | 
											
												
													
														|  | 
 |  | +            for (LongArticlesMatchVideo longArticlesMatchVideo : longArticlesMatchVideoList) {
 | 
											
												
													
														|  | 
 |  | +                processArticleEachData(longArticlesMatchVideo);
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +        } catch (Exception e) {
 | 
											
												
													
														|  | 
 |  | +            log.error("migrateArticleRootSourceId exception: {}", e.getMessage(), e);
 | 
											
												
													
														|  | 
 |  | +            return ReturnT.FAIL;
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +        return ReturnT.SUCCESS;
 | 
											
												
													
														|  | 
 |  | +    }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +    /**
 | 
											
												
													
														|  | 
 |  | +     * Processes each data tuple and updates the rootSourceId.
 | 
											
												
													
														|  | 
 |  | +     */
 | 
											
												
													
														|  | 
 |  | +    public void processArticleEachData(LongArticlesMatchVideo longArticlesMatchVideo) {
 | 
											
												
													
														|  | 
 |  | +        try {
 | 
											
												
													
														|  | 
 |  | +            List<String> results = JSONArray.parseArray(longArticlesMatchVideo.getResponse(), String.class);
 | 
											
												
													
														|  | 
 |  | +            List<LongArticlesRootSourceId> saveList = new ArrayList<>();
 | 
											
												
													
														|  | 
 |  | +            for (String result : results) {
 | 
											
												
													
														|  | 
 |  | +                JSONObject jsonNode = JSONObject.parseObject(result);
 | 
											
												
													
														|  | 
 |  | +                LongArticlesRootSourceId saveItem = new LongArticlesRootSourceId();
 | 
											
												
													
														|  | 
 |  | +                saveItem.setRootSourceId(jsonNode.getString("rootSourceId"));
 | 
											
												
													
														|  | 
 |  | +                saveItem.setAccountName(longArticlesMatchVideo.getAccountName());
 | 
											
												
													
														|  | 
 |  | +                saveItem.setGhId(longArticlesMatchVideo.getGhId());
 | 
											
												
													
														|  | 
 |  | +                saveItem.setRequestTime(longArticlesMatchVideo.getRequestTimestamp());
 | 
											
												
													
														|  | 
 |  | +                saveItem.setTraceId(longArticlesMatchVideo.getTraceId());
 | 
											
												
													
														|  | 
 |  | +                saveItem.setPushType(2);
 | 
											
												
													
														|  | 
 |  | +                saveItem.setVideoId(jsonNode.getLong("videoId"));
 | 
											
												
													
														|  | 
 |  | +                saveList.add(saveItem);
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +            if (CollectionUtil.isNotEmpty(saveList)) {
 | 
											
												
													
														|  | 
 |  | +                crawlerBaseMapper.batchInsertLongArticlesRootSourceId(saveList);
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +        } catch (Exception e) {
 | 
											
												
													
														|  | 
 |  | +            log.error("Error processArticleEachData: {}", JSONObject.toJSONString(longArticlesMatchVideo), e);
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +    }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  |  }
 |  |  }
 |