123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- package com.tzld.longarticle.recommend.server;
- import com.alibaba.fastjson.JSONObject;
- import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
- import com.tzld.longarticle.recommend.server.mapper.aigc.AigcBaseMapper;
- import com.tzld.longarticle.recommend.server.mapper.longArticle.LongArticleBaseMapper;
- import com.tzld.longarticle.recommend.server.model.dto.CrawlerContent;
- import com.tzld.longarticle.recommend.server.model.dto.ProduceContentDTO;
- import com.tzld.longarticle.recommend.server.model.dto.PublishAccountTypeDTO;
- import com.tzld.longarticle.recommend.server.model.entity.aigc.ProducePlanExeRecord;
- import com.tzld.longarticle.recommend.server.model.entity.longArticle.ArticleCategory;
- import com.tzld.longarticle.recommend.server.model.entity.longArticle.ArticlePoolPromotionSource;
- import com.tzld.longarticle.recommend.server.model.vo.ProduceContentCrawlerVO;
- import com.tzld.longarticle.recommend.server.repository.longArticle.ArticleCategoryRepository;
- import com.tzld.longarticle.recommend.server.repository.longArticle.ArticlePoolPromotionSourceRepository;
- import com.tzld.longarticle.recommend.server.service.recommend.ArticleService;
- import com.tzld.longarticle.recommend.server.util.Md5Util;
- import org.junit.jupiter.api.Test;
- import org.springframework.boot.test.context.SpringBootTest;
- import javax.annotation.Resource;
- import java.util.*;
- import java.util.function.Function;
- import java.util.stream.Collectors;
- @SpringBootTest(classes = Application.class)
- public class XxlJobTest {
- @Resource
- private ArticleService articleService;
- @Resource
- private AigcBaseMapper aigcBaseMapper;
- @Resource
- private LongArticleBaseMapper longArticleBaseMapper;
- @Resource
- private ArticlePoolPromotionSourceRepository articlePoolPromotionSourceRepository;
- @Resource
- private ArticleCategoryRepository articleCategoryRepository;
- @ApolloJsonValue("${cold.pool.produce.planId:[\"20240802021606053813696\", \"20240802080355355308981\",\n" +
- "\"20240805154433785506170\", \"20240805154359027876170\", \"20241024100016206421084\", " +
- "\"20241030070010871546586\"]}")
- private static List<String> producePlanIds;
- @Test
- public void test() {
- List<String> planIds = Arrays.asList("20240804003153130851174", "20240802171417146947657", "20240802143345289374071");
- List<String> levels = Arrays.asList("autoArticlePoolLevel3", "autoArticlePoolLevel1", "autoArticlePoolLevel1");
- List<ArticlePoolPromotionSource> dis = articlePoolPromotionSourceRepository.findAll();
- List<String> channelContentIds = dis.stream().map(ArticlePoolPromotionSource::getChannelContentId).collect(Collectors.toList());
- for (int i = 0; i < planIds.size(); i++) {
- List<ProduceContentDTO> list = aigcBaseMapper.getProduceContentByPlanId(planIds.get(i));
- list = list.stream().filter(item -> !channelContentIds.contains(item.getContentId())).collect(Collectors.toList());
- List<ArticlePoolPromotionSource> saveList = new ArrayList<>();
- for (ProduceContentDTO produceContentDTO : list) {
- ArticlePoolPromotionSource item = new ArticlePoolPromotionSource();
- item.setChannelContentId(produceContentDTO.getContentId());
- item.setTitle(produceContentDTO.getTitle());
- item.setTitleMd5(Md5Util.encoderByMd5(produceContentDTO.getTitle()));
- item.setLevel(levels.get(i));
- item.setCreateTimestamp(System.currentTimeMillis());
- saveList.add(item);
- }
- articlePoolPromotionSourceRepository.saveAll(saveList);
- }
- }
- @Test
- public void articleCategoryTest() {
- List<ProducePlanExeRecord> produceContentList = aigcBaseMapper.getAllByProducePlanId(producePlanIds);
- List<String> channelContentIds = produceContentList.stream().map(ProducePlanExeRecord::getChannelContentId).distinct().collect(Collectors.toList());
- List<ArticleCategory> articleCategoryList = articleCategoryRepository.getAllByChannelContentIdIn(channelContentIds);
- List<String> articleCategoryIds = articleCategoryList.stream().map(ArticleCategory::getChannelContentId).collect(Collectors.toList());
- List<ProduceContentCrawlerVO> list = produceContentList.stream().filter(o -> !articleCategoryIds.contains(o.getChannelContentId())).map(o -> {
- ProduceContentCrawlerVO item = new ProduceContentCrawlerVO();
- item.setChannelContentId(o.getChannelContentId());
- item.setProduceContentId(o.getPlanExeId());
- return item;
- }).collect(Collectors.toList());
- channelContentIds = channelContentIds.stream().filter(o -> !articleCategoryIds.contains(o)).collect(Collectors.toList());
- List<CrawlerContent> crawlerContentList = aigcBaseMapper.getCrawlerContentByChannelContentIdIn(channelContentIds);
- Map<String, CrawlerContent> map = crawlerContentList.stream().collect(Collectors.toMap(CrawlerContent::getChannelContentId, Function.identity()));
- long now = System.currentTimeMillis();
- List<ArticleCategory> saveList = new ArrayList<>();
- for (ProduceContentCrawlerVO vo : list) {
- ArticleCategory item = new ArticleCategory();
- item.setChannelContentId(vo.getChannelContentId());
- item.setProduceContentId(vo.getProduceContentId());
- CrawlerContent crawlerContent = map.get(vo.getChannelContentId());
- if (Objects.nonNull(crawlerContent)) {
- String title = crawlerContent.getTitle();
- item.setCrawlerPlanId(crawlerContent.getCrawlerPlanId());
- item.setTitle(title);
- item.setTitleMd5(Md5Util.encoderByMd5(title));
- item.setCreateTimestamp(now);
- saveList.add(item);
- }
- }
- longArticleBaseMapper.batchInsertArticleCategory(saveList);
- }
- @Test
- public void getAccountTypeListTest() {
- List<PublishAccountTypeDTO> accountTypeList = aigcBaseMapper.getAccountTypeList();
- System.out.println(JSONObject.toJSONString(accountTypeList));
- }
- }
|