XxlJobTest.java 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package com.tzld.longarticle.recommend.server;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
  4. import com.tzld.longarticle.recommend.server.mapper.aigc.AigcBaseMapper;
  5. import com.tzld.longarticle.recommend.server.mapper.longArticle.LongArticleBaseMapper;
  6. import com.tzld.longarticle.recommend.server.model.dto.CrawlerContent;
  7. import com.tzld.longarticle.recommend.server.model.dto.ProduceContentDTO;
  8. import com.tzld.longarticle.recommend.server.model.dto.PublishAccountTypeDTO;
  9. import com.tzld.longarticle.recommend.server.model.entity.aigc.ProducePlanExeRecord;
  10. import com.tzld.longarticle.recommend.server.model.entity.longArticle.ArticleCategory;
  11. import com.tzld.longarticle.recommend.server.model.entity.longArticle.ArticlePoolPromotionSource;
  12. import com.tzld.longarticle.recommend.server.model.vo.ProduceContentCrawlerVO;
  13. import com.tzld.longarticle.recommend.server.repository.longArticle.ArticleCategoryRepository;
  14. import com.tzld.longarticle.recommend.server.repository.longArticle.ArticlePoolPromotionSourceRepository;
  15. import com.tzld.longarticle.recommend.server.service.recommend.ArticleService;
  16. import com.tzld.longarticle.recommend.server.util.Md5Util;
  17. import org.junit.jupiter.api.Test;
  18. import org.springframework.boot.test.context.SpringBootTest;
  19. import javax.annotation.Resource;
  20. import java.util.*;
  21. import java.util.function.Function;
  22. import java.util.stream.Collectors;
  23. @SpringBootTest(classes = Application.class)
  24. public class XxlJobTest {
  25. @Resource
  26. private ArticleService articleService;
  27. @Resource
  28. private AigcBaseMapper aigcBaseMapper;
  29. @Resource
  30. private LongArticleBaseMapper longArticleBaseMapper;
  31. @Resource
  32. private ArticlePoolPromotionSourceRepository articlePoolPromotionSourceRepository;
  33. @Resource
  34. private ArticleCategoryRepository articleCategoryRepository;
  35. @ApolloJsonValue("${cold.pool.produce.planId:[\"20240802021606053813696\", \"20240802080355355308981\",\n" +
  36. "\"20240805154433785506170\", \"20240805154359027876170\", \"20241024100016206421084\", " +
  37. "\"20241030070010871546586\"]}")
  38. private static List<String> producePlanIds;
  39. @Test
  40. public void test() {
  41. List<String> planIds = Arrays.asList("20240804003153130851174", "20240802171417146947657", "20240802143345289374071");
  42. List<String> levels = Arrays.asList("autoArticlePoolLevel3", "autoArticlePoolLevel1", "autoArticlePoolLevel1");
  43. List<ArticlePoolPromotionSource> dis = articlePoolPromotionSourceRepository.findAll();
  44. List<String> channelContentIds = dis.stream().map(ArticlePoolPromotionSource::getChannelContentId).collect(Collectors.toList());
  45. for (int i = 0; i < planIds.size(); i++) {
  46. List<ProduceContentDTO> list = aigcBaseMapper.getProduceContentByPlanId(planIds.get(i));
  47. list = list.stream().filter(item -> !channelContentIds.contains(item.getContentId())).collect(Collectors.toList());
  48. List<ArticlePoolPromotionSource> saveList = new ArrayList<>();
  49. for (ProduceContentDTO produceContentDTO : list) {
  50. ArticlePoolPromotionSource item = new ArticlePoolPromotionSource();
  51. item.setChannelContentId(produceContentDTO.getContentId());
  52. item.setTitle(produceContentDTO.getTitle());
  53. item.setTitleMd5(Md5Util.encoderByMd5(produceContentDTO.getTitle()));
  54. item.setLevel(levels.get(i));
  55. item.setCreateTimestamp(System.currentTimeMillis());
  56. saveList.add(item);
  57. }
  58. articlePoolPromotionSourceRepository.saveAll(saveList);
  59. }
  60. }
  61. @Test
  62. public void articleCategoryTest() {
  63. List<ProducePlanExeRecord> produceContentList = aigcBaseMapper.getAllByProducePlanId(producePlanIds);
  64. List<String> channelContentIds = produceContentList.stream().map(ProducePlanExeRecord::getChannelContentId).distinct().collect(Collectors.toList());
  65. List<ArticleCategory> articleCategoryList = articleCategoryRepository.getAllByChannelContentIdIn(channelContentIds);
  66. List<String> articleCategoryIds = articleCategoryList.stream().map(ArticleCategory::getChannelContentId).collect(Collectors.toList());
  67. List<ProduceContentCrawlerVO> list = produceContentList.stream().filter(o -> !articleCategoryIds.contains(o.getChannelContentId())).map(o -> {
  68. ProduceContentCrawlerVO item = new ProduceContentCrawlerVO();
  69. item.setChannelContentId(o.getChannelContentId());
  70. item.setProduceContentId(o.getPlanExeId());
  71. return item;
  72. }).collect(Collectors.toList());
  73. channelContentIds = channelContentIds.stream().filter(o -> !articleCategoryIds.contains(o)).collect(Collectors.toList());
  74. List<CrawlerContent> crawlerContentList = aigcBaseMapper.getCrawlerContentByChannelContentIdIn(channelContentIds);
  75. Map<String, CrawlerContent> map = crawlerContentList.stream().collect(Collectors.toMap(CrawlerContent::getChannelContentId, Function.identity()));
  76. long now = System.currentTimeMillis();
  77. List<ArticleCategory> saveList = new ArrayList<>();
  78. for (ProduceContentCrawlerVO vo : list) {
  79. ArticleCategory item = new ArticleCategory();
  80. item.setChannelContentId(vo.getChannelContentId());
  81. item.setProduceContentId(vo.getProduceContentId());
  82. CrawlerContent crawlerContent = map.get(vo.getChannelContentId());
  83. if (Objects.nonNull(crawlerContent)) {
  84. String title = crawlerContent.getTitle();
  85. item.setCrawlerPlanId(crawlerContent.getCrawlerPlanId());
  86. item.setTitle(title);
  87. item.setTitleMd5(Md5Util.encoderByMd5(title));
  88. item.setCreateTimestamp(now);
  89. saveList.add(item);
  90. }
  91. }
  92. longArticleBaseMapper.batchInsertArticleCategory(saveList);
  93. }
  94. @Test
  95. public void getAccountTypeListTest() {
  96. List<PublishAccountTypeDTO> accountTypeList = aigcBaseMapper.getAccountTypeList();
  97. System.out.println(JSONObject.toJSONString(accountTypeList));
  98. }
  99. }