package com.tzld.longarticle.recommend.server; import com.alibaba.fastjson.JSONObject; import com.tzld.longarticle.recommend.server.common.enums.recommend.ArticleCategoryStatusEnum; import com.tzld.longarticle.recommend.server.mapper.longArticle.ArticleCategoryMapper; import com.tzld.longarticle.recommend.server.model.entity.longArticle.ArticleCategory; import com.tzld.longarticle.recommend.server.model.entity.longArticle.DatastatScore; import com.tzld.longarticle.recommend.server.model.vo.IntermediateIndicatorsExport; import com.tzld.longarticle.recommend.server.model.vo.NewSortStrategyExport; import com.tzld.longarticle.recommend.server.repository.longArticle.ArticleCategoryRepository; import com.tzld.longarticle.recommend.server.repository.longArticle.DatastatScoreRepository; import com.tzld.longarticle.recommend.server.service.recommend.DataDashboardService; import com.tzld.longarticle.recommend.server.util.DateUtils; import com.tzld.longarticle.recommend.server.util.feishu.FeiShu; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.util.Pair; import org.springframework.http.HttpHeaders; import javax.annotation.Resource; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.stream.Collectors; @SpringBootTest(classes = Application.class) @Slf4j public class DataDashboardTest { @Resource DataDashboardService dataDashboardService; @Resource DatastatScoreRepository datastatScoreRepository; @Resource ArticleCategoryRepository articleCategoryRepository; @Resource ArticleCategoryMapper articleCategoryMapper; @Test public void test() { List result = dataDashboardService.intermediateIndicatorsData("20241225"); log.info(JSONObject.toJSONString(result)); } @Test public void newSortStrategyData() { List result = dataDashboardService.newSortStrategyData("20241222", "20241223", "9", 0); log.info(JSONObject.toJSONString(result)); } @Test public void producePlanAuditExport() { List dateStrList = DateUtils.getBeforeDays(null, null, 86); dataDashboardService.producePlanAuditExport(dateStrList); } @Test public void delFeishuSheet() { List delDateStrList = DateUtils.getBeforeDays(null, null, 14); Pair token = FeiShu.requestAccessToken(); HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.add("Authorization", "Bearer " + token.getFirst()); dataDashboardService.delFeishuSheet(httpHeaders, "7d4e12", 2, delDateStrList); } @Test public void contentFunnelExport() { List dateStrList = DateUtils.getBeforeDays(null, null, 15); dataDashboardService.contentFunnelExport(dateStrList); } @Test public void contentGroupFunnelExport() { List dateStrList = DateUtils.getBeforeDays(null, null, 7); dataDashboardService.contentGroupFunnelExport(dateStrList); } @Test public void datastatScore() { List scoreList = datastatScoreRepository.getBySourceIdIsNotNull(); List categoryList = articleCategoryRepository.getByStatusAndVersion(ArticleCategoryStatusEnum.SUCCESS.getCode(), 2); Map categoryMap = categoryList.stream().collect(Collectors.toMap(ArticleCategory::getProduceContentId, category -> category)); Map titleMap = categoryList.stream().collect(Collectors.toMap(ArticleCategory::getTitle, category -> category, (a, b) -> a)); Map> scoreMap = scoreList.stream().collect(Collectors.groupingBy(DatastatScore::getTitle)); for (Map.Entry> entry : scoreMap.entrySet()) { String title = entry.getKey(); List list = entry.getValue(); ArticleCategory category = null; for (DatastatScore score : list) { category = categoryMap.get(score.getSourceId()); if (Objects.nonNull(category)) { category = titleMap.get(score.getTitle()); break; } } if (Objects.isNull(category)) { category = titleMap.get(title); } if (Objects.isNull(category)) { log.error("category not exists"); continue; } articleCategoryMapper.updateArticleCategory(title, category.getCategory()); } } }