Bladeren bron

品类数据导出

wangyunpeng 1 week geleden
bovenliggende
commit
e8df521960

+ 40 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/common/enums/ContentPositionEnum.java

@@ -0,0 +1,40 @@
+package com.tzld.longarticle.recommend.server.common.enums;
+
+import java.util.Objects;
+
+public enum ContentPositionEnum {
+
+    One(1, "头条"),
+    Two(2, "次条"),
+    Three(3, "3-8"),
+    Four(4, "3-8"),
+    Five(5, "3-8"),
+    Six(6, "3-8"),
+    Seven(7, "3-8"),
+    Eight(8, "3-8"),
+    ;
+
+    ContentPositionEnum(Integer position, String name) {
+        this.position = position;
+        this.name = name;
+    }
+
+    public final Integer position;
+
+    public final String name;
+
+
+    public static String from(Integer position) {
+        if (position == null) {
+            return null;
+        }
+        for (ContentPositionEnum positionEnum : ContentPositionEnum.values()) {
+            if (Objects.equals(positionEnum.position, position)) {
+                return positionEnum.name;
+            }
+        }
+        return null;
+    }
+
+
+}

+ 14 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/model/vo/CategoryGroupDataExport.java

@@ -0,0 +1,14 @@
+package com.tzld.longarticle.recommend.server.model.vo;
+
+import lombok.Data;
+
+@Data
+public class CategoryGroupDataExport {
+    private String dateStr;
+    private String position;
+    private String category;
+    private Long fansCount = 0L;
+    private Integer viewCount = 0;
+    private Integer firstLevel = 0;
+    private Double openRate;
+}

+ 2 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/repository/longArticle/DatastatSortStrategyRepository.java

@@ -13,4 +13,6 @@ public interface DatastatSortStrategyRepository extends JpaRepository<DatastatSo
                                                                                                       Double readRate,
                                                                                                       List<Integer> positionList);
     List<DatastatSortStrategy> getByWxSnIn(List<String> wxSnList);
+
+    List<DatastatSortStrategy> getByDateStr(String dateStr);
 }

+ 107 - 4
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/DataDashboardService.java

@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
 import com.google.common.collect.Lists;
+import com.tzld.longarticle.recommend.server.common.enums.ContentPositionEnum;
 import com.tzld.longarticle.recommend.server.common.enums.StatusEnum;
 import com.tzld.longarticle.recommend.server.common.enums.aigc.ChannelEnum;
 import com.tzld.longarticle.recommend.server.common.enums.aigc.ProduceContentAuditStatusEnum;
@@ -13,10 +14,7 @@ import com.tzld.longarticle.recommend.server.common.enums.aigc.PublishPlanInputS
 import com.tzld.longarticle.recommend.server.common.enums.longArticle.ArticleVideoAuditStatusEnum;
 import com.tzld.longarticle.recommend.server.common.enums.longArticle.ArticleVideoBadStatusEnum;
 import com.tzld.longarticle.recommend.server.common.enums.longArticle.VideoPoolPlatformEnum;
-import com.tzld.longarticle.recommend.server.common.enums.recommend.AccountBusinessTypeEnum;
-import com.tzld.longarticle.recommend.server.common.enums.recommend.ArticleTypeEnum;
-import com.tzld.longarticle.recommend.server.common.enums.recommend.ContentPoolEnum;
-import com.tzld.longarticle.recommend.server.common.enums.recommend.RankStrategyEnum;
+import com.tzld.longarticle.recommend.server.common.enums.recommend.*;
 import com.tzld.longarticle.recommend.server.mapper.aigc.AigcBaseMapper;
 import com.tzld.longarticle.recommend.server.mapper.aigc.PublishContentMapper;
 import com.tzld.longarticle.recommend.server.mapper.crawler.CrawlerBaseMapper;
@@ -46,6 +44,7 @@ import com.tzld.longarticle.recommend.server.repository.longArticle.*;
 import com.tzld.longarticle.recommend.server.service.recommend.score.ScoreStrategy;
 import com.tzld.longarticle.recommend.server.util.DateUtils;
 import com.tzld.longarticle.recommend.server.util.MapBuilder;
+import com.tzld.longarticle.recommend.server.util.Md5Util;
 import com.tzld.longarticle.recommend.server.util.feishu.FeiShu;
 import com.xxl.job.core.biz.model.ReturnT;
 import com.xxl.job.core.handler.annotation.XxlJob;
@@ -53,6 +52,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.collections4.MapUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.data.util.Pair;
 import org.springframework.http.*;
 import org.springframework.stereotype.Service;
@@ -123,6 +123,9 @@ public class DataDashboardService {
     private static List<String> ghIdList;
     @ApolloJsonValue("${audit.producePlan.list:[]}")
     private static List<String> auditProducePlanList;
+
+    @Value("${category.active.version:1}")
+    private Integer activeVersion;
     private static final String dailyDetailSheetToken = "M0pLs3uF6hfL0htn2dMcB9eFn8e";
     private static final String dailySafeSheetToken = "Xoass3ZGYhi9BVtZDoMclGFpnYe";
 
@@ -3578,5 +3581,105 @@ public class DataDashboardService {
         return result;
     }
 
+    @XxlJob("categoryGroupDataExport")
+    public ReturnT<String> categoryGroupDataJob(String param) {
+        List<String> dateStrList = DateUtils.getBeforeDays(null, null, 1);
+        contentEffectGroupBySource(dateStrList);
+        return ReturnT.SUCCESS;
+    }
+
+    public void categoryGroupData(String dateStr) {
+        if (!StringUtils.hasText(dateStr)) {
+            dateStr = DateUtils.getBeforeDaysDateStr("yyyyMMdd", 1);
+        }
+        categoryGroupData(Collections.singletonList(dateStr));
+    }
+
+    public void categoryGroupData(List<String> dateStrList) {
+        List<CategoryGroupDataExport> exportList = new ArrayList<>();
+        dateStrList = Lists.reverse(dateStrList);
+        for (String dateStr : dateStrList) {
+            exportList.addAll(buildCategoryGroupDataExport(dateStr));
+        }
+        if (CollectionUtil.isEmpty(exportList)) {
+            return;
+        }
+        int rowNum = exportList.size();
+        List<List<Object>> rows = new ArrayList<>();
+        Field[] fields = CategoryGroupDataExport.class.getDeclaredFields();
+        for (CategoryGroupDataExport datum : exportList) {
+            List<Object> rowDatas = new ArrayList<>();
+            rows.add(rowDatas);
+
+            for (Field field : fields) {
+                field.setAccessible(true);
+                try {
+                    rowDatas.add(field.get(datum));
+                } catch (IllegalAccessException e) {
+                    log.error("获取值出错:{}", field.getName());
+                } catch (Exception e) {
+                    throw new RuntimeException(e.getMessage());
+                }
+            }
+        }
+
+        List<Pair<String, String>> styles = Arrays
+                .asList(
+                        Pair.of("G", "0.00%")
+                );
+        doSendFeishuSheet(dateStrList, dailyDetailSheetToken, "bl1eL2", rowNum, rows,
+                2, styles, null, null);
+    }
+
+    private List<CategoryGroupDataExport> buildCategoryGroupDataExport(String dateStr) {
+        List<DatastatSortStrategy> list = datastatSortStrategyRepository.getByDateStr(dateStr);
+        List<ArticleCategory> articleCategoryList = articleCategoryRepository.getByStatusAndVersion(
+                ArticleCategoryStatusEnum.SUCCESS.getCode(), activeVersion);
+        Map<String, ArticleCategory> categoryMap = articleCategoryList.stream()
+                .collect(Collectors.toMap(ArticleCategory::getProduceContentId, Function.identity()));
+        Map<String, ArticleCategory> titleCategoryMap = articleCategoryList.stream()
+                .collect(Collectors.toMap(ArticleCategory::getTitleMd5, Function.identity(), (a, b) -> a));
+        Map<String, Map<String, CategoryGroupDataExport>> resultMap = new HashMap<>();
+        for (DatastatSortStrategy item : list) {
+            if (Objects.isNull(item.getViewCount()) || Objects.isNull(item.getFirstLevel()) || Objects.isNull(item.getFans())) {
+                continue;
+            }
+            Map<String, CategoryGroupDataExport> positionMap = resultMap.get(ContentPositionEnum.from(item.getPosition()));
+            if (MapUtils.isEmpty(positionMap)) {
+                positionMap = new HashMap<>();
+                resultMap.put(ContentPositionEnum.from(item.getPosition()), positionMap);
+            }
+            ArticleCategory articleCategory = categoryMap.get(item.getSourceId());
+            if (Objects.isNull(articleCategory)) {
+                String titleMd5 = Md5Util.encoderByMd5(item.getTitle());
+                articleCategory = titleCategoryMap.get(titleMd5);
+            }
+            if (Objects.isNull(articleCategory)) {
+                continue;
+            }
+            CategoryGroupDataExport export = positionMap.get(articleCategory.getCategory());
+            if (Objects.isNull(export)) {
+                export = new CategoryGroupDataExport();
+                export.setDateStr(dateStr);
+                export.setPosition(ContentPositionEnum.from(item.getPosition()));
+                export.setCategory(articleCategory.getCategory());
+            }
+            export.setViewCount(export.getViewCount() + item.getViewCount());
+            export.setFirstLevel(export.getFirstLevel() + item.getFirstLevel());
+            export.setFansCount(export.getFansCount() + item.getFans());
+        }
+        List<CategoryGroupDataExport> result = new ArrayList<>();
+        for (Map.Entry<String, Map<String, CategoryGroupDataExport>> entry : resultMap.entrySet()) {
+            for (Map.Entry<String, CategoryGroupDataExport> item : entry.getValue().entrySet()) {
+                CategoryGroupDataExport export = item.getValue();
+                if (export.getFansCount()!= null && export.getFansCount()!= 0) {
+                    export.setOpenRate((double) export.getFirstLevel() / export.getFansCount());
+                }
+                result.add(export);
+            }
+        }
+        return result;
+    }
+
 
 }

+ 7 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/web/recommend/DataDashboardController.java

@@ -92,4 +92,11 @@ public class DataDashboardController {
         }).start();
     }
 
+    @GetMapping("/export/categoryGroupData")
+    public void categoryGroupData(String dateStr) {
+        new Thread(() -> {
+            service.categoryGroupData(dateStr);
+        }).start();
+    }
+
 }