Ver código fonte

中间指标导出

wangyunpeng 10 meses atrás
pai
commit
43e5d72de3

+ 179 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/model/IntermediateIndicatorsExport.java

@@ -0,0 +1,179 @@
+package com.tzld.longarticle.recommend.server.model;
+import lombok.Data;
+
+@Data
+public class IntermediateIndicatorsExport {
+    // 日期
+    private String dateStr = "";
+    // 探索-利用类型
+    private String type = "";
+    // 文章发布槽位
+    private Integer articleReleaseSlot = 0;
+    // 文章实际发布数
+    private Integer actualArticleReleaseCount = 0;
+    // 文章发布篇数(去重)
+    private Integer distinctArticleReleaseCount = 0;
+    // 文章发布篇数(去重)/文章实际发布数
+    private Double distinctArticleReleaseRatio = 0.0;
+    // 文章实际发布数-L1(3-8)
+    private Integer actualReleaseCountL1 = 0;
+    // 文章实际发布数-L2(次条)
+    private Integer actualReleaseCountL2 = 0;
+    // 文章实际发布数-L3(小号头条)
+    private Integer actualReleaseCountL3 = 0;
+    // 文章实际发布数-L4(大号头条)
+    private Integer actualReleaseCountL4 = 0;
+    // 文章发布篇数(去重)-L1(3-8)
+    private Integer distinctReleaseCountL1 = 0;
+    // 文章发布篇数(去重)-L2(次条)
+    private Integer distinctReleaseCountL2 = 0;
+    // 文章发布篇数(去重)-L3(小号头条)
+    private Integer distinctReleaseCountL3 = 0;
+    // 文章发布篇数(去重)-L4(大号头条)
+    private Integer distinctReleaseCountL4 = 0;
+    // 文章发布篇数(去重)/文章实际发布数-L1(3-8)
+    private Double distinctToActualRatioL1 = 0.0;
+    // 文章发布篇数(去重)/文章实际发布数-L2(次条)
+    private Double distinctToActualRatioL2 = 0.0;
+    // 文章发布篇数(去重)/文章实际发布数-L3(小号头条)
+    private Double distinctToActualRatioL3 = 0.0;
+    // 文章发布篇数(去重)/文章实际发布数-L4(大号头条)
+    private Double distinctToActualRatioL4 = 0.0;
+    // 阅读量
+    private Integer viewCount = 0;
+    // 首层UV
+    private Integer firstLayerUV = 0;
+    // T+0裂变UV
+    private Integer t0FissionUV = 0;
+    // 账号-文章相关性均值
+    private Double accountArticleRelevanceAvg = 0.0;
+    // 阅读量/Base
+    private Double viewToBaseRatio = 0.0;
+    // 小程序打开率
+    private Double miniAppOpenRate = 0.0;
+    // T+0裂变率
+    private Double t0FissionRate = 0.0;
+    // 首层当日带回裂变人/阅读Base
+    private Double firstLayerFissionToViewBaseRatio = 0.0;
+    // 阅读Base
+    private Double viewBase = 0.0;
+    // T+0裂变数
+    private Integer t0FissionCount = 0;
+    // T+1裂变数
+    private Integer t1FissionCount = 0;
+    // T+2裂变数
+    private Integer t2FissionCount = 0;
+    // T+0裂变率
+    private Double t0FissionRateAgain = 0.0;
+    // T+1累积裂变率
+    private Double t1CumulativeFissionRate = 0.0;
+    // T+2累积裂变率
+    private Double t2CumulativeFissionRate = 0.0;
+    // 首次探索时间间隔天数均值
+    private Double firstExplorationIntervalAvg = 0.0;
+    // 文章发布总次数(非无限流)
+    private Integer totalArticleReleaseCountNonInfinite = 0;
+    // 阅读量 (重复定义,保留以防需要)
+    private Integer redundantViewCount = 0;
+    // 首层UV (重复定义,保留以防需要)
+    private Integer redundantFirstLayerUV = 0;
+    // T+0裂变UV (重复定义,保留以防需要)
+    private Integer redundantT0FissionUV = 0;
+    // 账号-文章相关性均值 (重复定义,保留以防需要)
+    private Double redundantAccountArticleRelevanceAvg = 0.0;
+    // 均值(阅读量/Base)
+    private Double averageViewToBaseRatio = 0.0;
+    // 均值(小程序打开率)
+    private Double averageMiniAppOpenRate = 0.0;
+    // 均值(T+0裂变率)
+    private Double averageT0FissionRate = 0.0;
+    // 均值(首层当日带回裂变人/阅读Base)
+    private Double averageFirstLayerFissionToViewBaseRatio = 0.0;
+    // 阅读Base (重复定义,保留以防需要)
+    private Double redundantViewBase = 0.0;
+
+    // 晋级篇数-L2
+    private Integer promotionCountL2 = 0;
+    // 晋级篇数-L3
+    private Integer promotionCountL3 = 0;
+    // 晋级篇数-L4
+    private Integer promotionCountL4 = 0;
+    // 晋级率-L2
+    private Double promotionRateL2 = 0.0;
+    // 晋级率-L3
+    private Double promotionRateL3 = 0.0;
+    // 晋级率-L4
+    private Double promotionRateL4 = 0.0;
+    // T+1日阅读量
+    private Integer t1DayViewCount = 0;
+    // T+1日首层UV
+    private Integer t1DayFirstLayerUV = 0;
+    // T+1日T+0裂变UV
+    private Integer t1DayT0FissionUV = 0;
+    // T+1日账号-文章相关性均值
+    private Double t1DayAccountArticleRelevanceAvg = 0.0;
+    // T+1日均值(阅读量/Base)
+    private Double t1DayAverageViewToBaseRatio = 0.0;
+    // T+1日均值(小程序打开率)
+    private Double t1DayAverageMiniAppOpenRate = 0.0;
+    // T+1日均值(T+0裂变率)
+    private Double t1DayAverageT0FissionRate = 0.0;
+    // T+1日均值(首层当日带回裂变人/阅读Base)
+    private Double t1DayAverageFirstLayerFissionToViewBaseRatio = 0.0;
+    // T+1日阅读Base
+    private Integer t1DayViewBase = 0;
+    // T+2日阅读量
+    private Integer t2DayViewCount = 0;
+    // T+2日首层UV
+    private Integer t2DayFirstLayerUV = 0;
+    // T+2日T+0裂变UV
+    private Integer t2DayT0FissionUV = 0;
+    // T+2日账号-文章相关性均值
+    private Double t2DayAccountArticleRelevanceAvg = 0.0;
+    // T+2日均值(阅读量/Base)
+    private Double t2DayAverageViewToBaseRatio = 0.0;
+    // T+2日均值(小程序打开率)
+    private Double t2DayAverageMiniAppOpenRate = 0.0;
+    // T+2日均值(T+0裂变率)
+    private Double t2DayAverageT0FissionRate = 0.0;
+    // T+2日均值(首层当日带回裂变人/阅读Base)
+    private Double t2DayAverageFirstLayerFissionToViewBaseRatio = 0.0;
+    // T+2日阅读Base
+    private Integer t2DayViewBase = 0;
+    // T+3日阅读量
+    private Integer t3DayViewCount = 0;
+    // T+3日首层UV
+    private Integer t3DayFirstLayerUV = 0;
+    // T+3日T+0裂变UV
+    private Integer t3DayT0FissionUV = 0;
+    // T+3日账号-文章相关性均值
+    private Double t3DayAccountArticleRelevanceAvg = 0.0;
+    // T+3日均值(阅读量/Base)
+    private Double t3DayAverageViewToBaseRatio = 0.0;
+    // T+3日均值(小程序打开率)
+    private Double t3DayAverageMiniAppOpenRate = 0.0;
+    // T+3日均值(T+0裂变率)
+    private Double t3DayAverageT0FissionRate = 0.0;
+    // T+3日均值(首层当日带回裂变人/阅读Base)
+    private Double t3DayAverageFirstLayerFissionToViewBaseRatio = 0.0;
+    // T+3日阅读Base
+    private Integer t3DayViewBase = 0;
+    // T+3+日阅读量
+    private Integer t3PlusDayViewCount = 0;
+    // T+3+日首层UV
+    private Integer t3PlusDayFirstLayerUV = 0;
+    // T+3+日T+0裂变UV
+    private Integer t3PlusDayT0FissionUV = 0;
+    // T+3+日账号-文章相关性均值
+    private Double t3PlusDayAccountArticleRelevanceAvg = 0.0;
+    // T+3+日均值(阅读量/Base)
+    private Double t3PlusDayAverageViewToBaseRatio = 0.0;
+    // T+3+日均值(小程序打开率)
+    private Double t3PlusDayAverageMiniAppOpenRate = 0.0;
+    // T+3+日均值(T+0裂变率)
+    private Double t3PlusDayAverageT0FissionRate = 0.0;
+    // T+3+日均值(首层当日带回裂变人/阅读Base)
+    private Double t3PlusDayAverageFirstLayerFissionToViewBaseRatio = 0.0;
+    // T+3+日阅读Base
+    private Integer t3PlusDayViewBase = 0;
+}

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

@@ -19,4 +19,6 @@ public interface AccountAvgInfoRepository extends JpaRepository<AccountAvgInfo,
     List<AccountAvgInfo> getAllByStatusEquals(Integer status);
 
     List<AccountAvgInfo> getAllByUpdateTimeGreaterThanEqual(String updateTime);
+
+    List<AccountAvgInfo> getAllByUpdateTimeLessThanEqual(String updateTime);
 }

+ 4 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/repository/crawler/ArticleRepository.java

@@ -20,4 +20,8 @@ public interface ArticleRepository extends JpaRepository<Article, String> {
 
     List<Article> getByGhIdInAndUpdateTimeGreaterThanAndTypeEquals(Set<String> ghIds, Long updateTime, String type);
 
+    List<Article> getByGhIdInAndUpdateTimeLessThanAndTypeEquals(List<String> ghIds, Long updateTIme, String type);
+
+    List<Article> getByUpdateTimeGreaterThanAndTypeEquals(Long updateTIme, String type);
+
 }

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

@@ -3,13 +3,11 @@ package com.tzld.longarticle.recommend.server.service;
 import cn.hutool.core.collection.CollectionUtil;
 import com.alibaba.fastjson.JSON;
 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.AccountBusinessTypeEnum;
-import com.tzld.longarticle.recommend.server.model.MiniprogramTaskParam;
-import com.tzld.longarticle.recommend.server.model.NewSortStrategyExport;
-import com.tzld.longarticle.recommend.server.model.ProduceAuditLayoutContentObjVO;
-import com.tzld.longarticle.recommend.server.model.PublishContentParam;
+import com.tzld.longarticle.recommend.server.model.*;
 import com.tzld.longarticle.recommend.server.repository.aigc.*;
 import com.tzld.longarticle.recommend.server.repository.crawler.AccountAvgInfoRepository;
 import com.tzld.longarticle.recommend.server.repository.crawler.ArticleDetailInfoRepository;
@@ -445,7 +443,7 @@ public class DataDashboardService {
         HttpEntity<Object> queryEntity = new HttpEntity<>(httpHeaders);
         ResponseEntity<String> queryResponseEntity = restTemplate.exchange(
                 String.format("https://open.feishu.cn/open-apis/sheets/v2/spreadsheets/%s/values/%s!A"
-                                + startRowIndex + ":A" + (startRowIndex + (rowNum * 2)), sheetToken, sheetId),
+                        + startRowIndex + ":A" + (startRowIndex + (rowNum * 2)), sheetToken, sheetId),
                 HttpMethod.GET, queryEntity, String.class);
         JSONArray values = JSON.parseObject(queryResponseEntity.getBody())
                 .getJSONObject("data")
@@ -493,11 +491,11 @@ public class DataDashboardService {
                     .builder()
                     .put("valueRange", MapBuilder
                             .builder()
-                            .put("range", String.format("%s!A" + startRow + ":AZ", sheetId) + (partition.size() + startRow - 1))
+                            .put("range", String.format("%s!A" + startRow + ":CH", sheetId) + (partition.size() + startRow - 1))
                             .put("values", partition)
                             .build())
                     .build(), httpHeaders);
-            restTemplate.exchange(String.format("https://open.feishu.cn/open-apis/sheets/v2/spreadsheets/%s/values_prepend",
+            ResponseEntity<String> response = restTemplate.exchange(String.format("https://open.feishu.cn/open-apis/sheets/v2/spreadsheets/%s/values_prepend",
                             sheetToken),
                     HttpMethod.POST, postEntity, String.class);
             startRow += partition.size();
@@ -553,4 +551,447 @@ public class DataDashboardService {
         }
     }
 
+    @Scheduled(cron = "0 0 4 * * ?")
+    public void scheduleIntermediateIndicatorsExport() {
+        List<String> dateStrList = DateUtils.getBeforeDays(null, 3);
+        for (String date : dateStrList) {
+            exportFeishuIntermediateIndicators(date, sheetToken, "OuaLWV");
+        }
+    }
+
+    public void intermediateIndicatorsExport(String dateStr) {
+        List<String> dateStrList = DateUtils.getBeforeDays(dateStr, 3);
+        for (String date : dateStrList) {
+            exportFeishuIntermediateIndicators(date, sheetToken, "OuaLWV");
+        }
+    }
+
+    private void exportFeishuIntermediateIndicators(String dateStr, String sheetToken, String sheetId) {
+        List<IntermediateIndicatorsExport> newContentsYesData = intermediateIndicatorsData(dateStr);
+        if (CollectionUtil.isEmpty(newContentsYesData)) {
+            return;
+        }
+
+        int rowNum = newContentsYesData.size();
+        List<List<Object>> rows = new ArrayList<>();
+        Field[] fields = IntermediateIndicatorsExport.class.getDeclaredFields();
+        for (IntermediateIndicatorsExport datum : newContentsYesData) {
+            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("F", "0.00%"),
+                        Pair.of("O", "0.00%"),
+                        Pair.of("P", "0.00%"),
+                        Pair.of("Q", "0.00%"),
+                        Pair.of("R", "0.00%"),
+                        Pair.of("W", "0.00%"),
+                        Pair.of("X", "0.00%"),
+                        Pair.of("Y", "0.00%"),
+                        Pair.of("Z", "0.00%"),
+                        Pair.of("AE", "0.00%"),
+                        Pair.of("AF", "0.00%"),
+                        Pair.of("AG", "0.00%"),
+                        Pair.of("AN", "0.00%"),
+                        Pair.of("AO", "0.00%"),
+                        Pair.of("AP", "0.00%"),
+                        Pair.of("AQ", "0.00%")
+                );
+
+        doSendFeishuSheet(Collections.singletonList(dateStr), sheetToken, sheetId, rowNum, rows, 3, styles);
+    }
+
+    private List<IntermediateIndicatorsExport> intermediateIndicatorsData(String dateStr) {
+        List<IntermediateIndicatorsExport> result = buildIntermediateIndicatorsData(dateStr);
+        Map<String, IntermediateIndicatorsExport> resultMap = result.stream().collect(Collectors.toMap(
+                IntermediateIndicatorsExport::getType, o -> o));
+        List<String> small = Arrays.asList("gh_084a485e859a", "gh_183d80deffb8", "gh_1b27dd1beeca", "gh_29074b51f2b7",
+                "gh_4568b5a7e2fe", "gh_5ff48e9fb9ef", "gh_6d9f36e3a7be", "gh_72bace6b3059", "gh_7b4a5f86d68c",
+                "gh_9f8dc5b0c74e", "gh_b676b7ad9b74", "gh_ee78360d06f5", "gh_f25b5fb01977", "gh_f902cea89e48");
+        Long dateStart = DateUtils.getStartOfDay(dateStr, "yyyyMMdd");
+        Long dateEnd = DateUtils.getEndOfDay(dateStr, "yyyyMMdd");
+        long timestamp = DateUtils.dateStrToTimestamp(dateStr, "yyyyMMdd");
+        String dateStrS = DateUtils.timestampToYMDStr(timestamp, "yyyy-MM-dd");
+        List<AccountAvgInfo> accountAvgInfoList = accountAvgInfoRepository.getAllByUpdateTimeLessThanEqual(dateStrS);
+        Map<String, Map<String, Map<String, AccountAvgInfo>>> accountAvgInfoIndexMap = accountAvgInfoList.stream()
+                .filter(o -> Objects.nonNull(o.getReadAvg()) && o.getReadAvg() > 0 && o.getFans() > 1000)
+                .collect(Collectors.groupingBy(AccountAvgInfo::getGhId, Collectors.groupingBy(AccountAvgInfo::getUpdateTime,
+                        Collectors.toMap(AccountAvgInfo::getPosition, o -> o))));
+        List<String> ghIds = accountAvgInfoList.stream().map(AccountAvgInfo::getGhId).distinct().collect(Collectors.toList());
+        List<Article> articleList = articleRepository.getByGhIdInAndUpdateTimeLessThanAndTypeEquals(ghIds, dateEnd, "9");
+        List<Article> todayPublish = articleList.stream().filter(o -> o.getUpdateTime() > dateStart).collect(Collectors.toList());
+        Map<String, List<Article>> hisPublishMap = articleList.stream().collect(Collectors.groupingBy(Article::getTitle));
+        List<String> wxSnList = articleList.stream().map(Article::getWxSn).distinct().collect(Collectors.toList());
+        List<ArticleDetailInfo> articleDetailInfoList = new ArrayList<>();
+        for (List<String> partitions : Lists.partition(wxSnList, 1000)) {
+            articleDetailInfoList.addAll(articleDetailInfoRepository.getAllByWxSnIn(partitions));
+        }
+        Map<String, List<ArticleDetailInfo>> articleDetailInfoMap = articleDetailInfoList.stream()
+                .collect(Collectors.groupingBy(ArticleDetailInfo::getWxSn));
+        List<PublishSortLog> publishSortLogList = publishSortLogRepository.findByDateStr(dateStr);
+        Map<String, Map<Integer, PublishSortLog>> publishSortLogMap = publishSortLogList.stream()
+                .collect(Collectors.groupingBy(PublishSortLog::getGhId, Collectors.toMap(
+                        PublishSortLog::getIndex, o -> o, (existing, replacement) -> replacement
+                )));
+        List<NewSortStrategyExport> newSortStrategyExportList = getNewSortStrategyExportList(todayPublish,
+                articleDetailInfoMap, accountAvgInfoIndexMap);
+
+        List<Article> futurePublishList = articleRepository.getByUpdateTimeGreaterThanAndTypeEquals(dateEnd, "9");
+        Map<String, List<Article>> futurePublishMap = futurePublishList.stream().collect(Collectors.groupingBy(Article::getTitle));
+
+        Map<String, List<String>> titleTypeMap = new HashMap<>();
+        Map<String, Map<Integer, List<String>>> titleTypePoolMap = new HashMap<>();
+        for (NewSortStrategyExport data : newSortStrategyExportList) {
+            String type = getArticleType(data, small);
+            IntermediateIndicatorsExport item = resultMap.get(type);
+            List<Article> list = hisPublishMap.get(data.getTitle());
+            Integer poolLevel = getArticlePoolLevel(data, list, small);
+            // 发布情况
+            setPublishSituation(item, type, titleTypeMap, titleTypePoolMap, poolLevel, data);
+            // 发布表现
+            setPublishPerformance(item, data, publishSortLogMap);
+            // 发布依赖表现
+            setPublishSourcePerformance(item, data, accountAvgInfoIndexMap, articleDetailInfoMap, hisPublishMap, small);
+            // 发布未来表现 todo
+            setPublishFuturePerformance(item, data, poolLevel, futurePublishMap, small);
+
+            List<String> titles = titleTypeMap.computeIfAbsent(type, k -> new ArrayList<>());
+            titles.add(data.getTitle());
+            Map<Integer, List<String>> titlePoolMap = titleTypePoolMap.computeIfAbsent(type, k -> new HashMap<>());
+            List<String> poolTitles = titlePoolMap.computeIfAbsent(poolLevel, k -> new ArrayList<>());
+            poolTitles.add(data.getTitle());
+        }
+
+        return result;
+    }
+
+    private void setPublishFuturePerformance(IntermediateIndicatorsExport item, NewSortStrategyExport data, Integer poolLevel,
+                                             Map<String, List<Article>> futurePublishMap, List<String> small) {
+        List<Article> futurePublishList = futurePublishMap.get(data.getTitle());
+//        Integer futurePoolLevel = getArticlePoolLevel(data, futurePublishList, small);
+//        if (futurePoolLevel > poolLevel) {
+//
+//        }
+        item.setPromotionCountL2(item.getPromotionCountL2());
+        item.setPromotionCountL3(item.getPromotionCountL3());
+        item.setPromotionCountL4(item.getPromotionCountL4());
+        item.setPromotionRateL2(item.getPromotionRateL2());
+        item.setPromotionRateL3(item.getPromotionRateL3());
+        item.setPromotionRateL4(item.getPromotionRateL4());
+        item.setT1DayViewCount(item.getT1DayViewCount());
+        item.setT1DayFirstLayerUV(item.getT1DayFirstLayerUV());
+        item.setT1DayT0FissionUV(item.getT1DayT0FissionUV());
+        item.setT1DayAccountArticleRelevanceAvg(item.getT1DayAccountArticleRelevanceAvg());
+        item.setT1DayAverageViewToBaseRatio(item.getT1DayAverageViewToBaseRatio());
+        item.setT1DayAverageMiniAppOpenRate(item.getT1DayAverageMiniAppOpenRate());
+        item.setT1DayAverageT0FissionRate(item.getT1DayAverageT0FissionRate());
+        item.setT1DayAverageFirstLayerFissionToViewBaseRatio(item.getT1DayAverageFirstLayerFissionToViewBaseRatio());
+        item.setT1DayViewBase(item.getT1DayViewBase());
+        item.setT2DayViewCount(item.getT2DayViewCount());
+        item.setT2DayFirstLayerUV(item.getT2DayFirstLayerUV());
+        item.setT2DayT0FissionUV(item.getT2DayT0FissionUV());
+        item.setT2DayAccountArticleRelevanceAvg(item.getT2DayAccountArticleRelevanceAvg());
+        item.setT2DayAverageViewToBaseRatio(item.getT2DayAverageViewToBaseRatio());
+        item.setT2DayAverageMiniAppOpenRate(item.getT2DayAverageMiniAppOpenRate());
+        item.setT2DayAverageT0FissionRate(item.getT2DayAverageT0FissionRate());
+        item.setT2DayAverageFirstLayerFissionToViewBaseRatio(item.getT2DayAverageFirstLayerFissionToViewBaseRatio());
+        item.setT2DayViewBase(item.getT2DayViewBase());
+        item.setT3DayViewCount(item.getT3DayViewCount());
+        item.setT3DayFirstLayerUV(item.getT3DayFirstLayerUV());
+        item.setT3DayT0FissionUV(item.getT3DayT0FissionUV());
+        item.setT3DayAccountArticleRelevanceAvg(item.getT3DayAccountArticleRelevanceAvg());
+        item.setT3DayAverageViewToBaseRatio(item.getT3DayAverageViewToBaseRatio());
+        item.setT3DayAverageMiniAppOpenRate(item.getT3DayAverageMiniAppOpenRate());
+        item.setT3DayAverageT0FissionRate(item.getT3DayAverageT0FissionRate());
+        item.setT3DayAverageFirstLayerFissionToViewBaseRatio(item.getT3DayAverageFirstLayerFissionToViewBaseRatio());
+        item.setT3DayViewBase(item.getT3DayViewBase());
+        item.setT3PlusDayViewCount(item.getT3PlusDayViewCount());
+        item.setT3PlusDayFirstLayerUV(item.getT3PlusDayFirstLayerUV());
+        item.setT3PlusDayT0FissionUV(item.getT3PlusDayT0FissionUV());
+        item.setT3PlusDayAccountArticleRelevanceAvg(item.getT3PlusDayAccountArticleRelevanceAvg());
+        item.setT3PlusDayAverageViewToBaseRatio(item.getT3PlusDayAverageViewToBaseRatio());
+        item.setT3PlusDayAverageMiniAppOpenRate(item.getT3PlusDayAverageMiniAppOpenRate());
+        item.setT3PlusDayAverageT0FissionRate(item.getT3PlusDayAverageT0FissionRate());
+        item.setT3PlusDayAverageFirstLayerFissionToViewBaseRatio(item.getT3PlusDayAverageFirstLayerFissionToViewBaseRatio());
+        item.setT3PlusDayViewBase(item.getT3PlusDayViewBase());
+    }
+
+    private List<NewSortStrategyExport> getNewSortStrategyExportList(List<Article> todayPublish,
+                                                                     Map<String, List<ArticleDetailInfo>> articleDetailInfoMap,
+                                                                     Map<String, Map<String, Map<String, AccountAvgInfo>>> accountAvgInfoIndexMap) {
+        List<NewSortStrategyExport> result = new ArrayList<>();
+        for (Article article : todayPublish) {
+            List<ArticleDetailInfo> articleDetailInfos = articleDetailInfoMap.get(article.getWxSn());
+            if (CollectionUtils.isEmpty(articleDetailInfos)) {
+                continue;
+            }
+            Date minDate = articleDetailInfos.stream().map(ArticleDetailInfo::getRecallDt).min(Date::compareTo).orElse(new Date());
+            int sumFirstLevel = 0;
+            int sumFission0 = 0;
+            int sumFission1 = 0;
+            int sumFission2 = 0;
+            for (ArticleDetailInfo articleDetailInfo : articleDetailInfos) {
+                if (articleDetailInfo.getRecallDt().equals(minDate)) {
+                    sumFirstLevel += Optional.ofNullable(articleDetailInfo.getFirstLevel()).orElse(0);
+                    sumFission0 += Optional.ofNullable(articleDetailInfo.getFission0()).orElse(0);
+                    sumFission1 += Optional.ofNullable(articleDetailInfo.getFission1()).orElse(0);
+                    sumFission2 += Optional.ofNullable(articleDetailInfo.getFission2()).orElse(0);
+                }
+            }
+            Map<String, Map<String, AccountAvgInfo>> dateAvgMap = accountAvgInfoIndexMap.get(article.getGhId());
+            String hisPublishDate = DateUtils.timestampToYMDStr(article.getUpdateTime(), "yyyy-MM-dd");
+            AccountAvgInfo avgInfo = null;
+            if (Objects.nonNull(dateAvgMap)) {
+                List<String> avgMapDateList = new ArrayList<>(dateAvgMap.keySet());
+                hisPublishDate = DateUtils.findNearestDate(avgMapDateList, hisPublishDate, "yyyy-MM-dd");
+                Map<String, AccountAvgInfo> accountAvgInfoMap = dateAvgMap.get(hisPublishDate);
+                if (Objects.nonNull(accountAvgInfoMap)) {
+                    avgInfo = accountAvgInfoMap.get(article.getItemIndex().toString());
+                }
+            }
+            String date = DateUtils.timestampToYMDStr(article.getUpdateTime(), "yyyyMMdd");
+            NewSortStrategyExport obj = new NewSortStrategyExport();
+            obj.setGhId(article.getGhId());
+            obj.setAccountName(article.getAccountName());
+            obj.setTitle(article.getTitle());
+            obj.setLink(article.getContentUrl());
+            obj.setPosition(article.getItemIndex());
+            obj.setViewCount(article.getShowViewCount());
+            obj.setDateStr(date);
+            obj.setFirstLevel(sumFirstLevel);
+            obj.setFission0(sumFission0);
+            obj.setFission1(sumFission1);
+            obj.setFission2(sumFission2);
+            obj.setWxSn(article.getWxSn());
+            if (Objects.nonNull(avgInfo)) {
+                obj.setAccountMode(avgInfo.getAccountMode());
+                obj.setAccountSource(avgInfo.getAccountSource());
+                obj.setAccountType(avgInfo.getAccountType());
+                obj.setAccountStatus(avgInfo.getAccountStatus());
+                obj.setBusinessType(AccountBusinessTypeEnum.from(avgInfo.getBusinessType()).getDescription());
+                obj.setFans(avgInfo.getFans());
+                obj.setAvgViewCount(avgInfo.getReadAvg());
+                if (avgInfo.getReadAvg() > 0) {
+                    obj.setReadRate((article.getShowViewCount() * 1.0) / avgInfo.getReadAvg());
+                    obj.setFission0ReadAvgRate((sumFission0 * 1.0) / avgInfo.getReadAvg());
+                }
+                if (avgInfo.getFans() > 0) {
+                    obj.setReadFansRate((article.getShowViewCount() * 1.0) / avgInfo.getFans());
+                }
+            }
+            if (sumFirstLevel > 0) {
+                obj.setFission0FirstRate((sumFission0 * 1.0) / sumFirstLevel);
+            }
+            if (article.getShowViewCount() > 0) {
+                obj.setFirstReadRate((sumFirstLevel * 1.0) / article.getShowViewCount());
+            }
+            if (sumFission0 > 0) {
+                obj.setFission1Fission0Rate((sumFission1 * 1.0) / sumFission0);
+            }
+            result.add(obj);
+        }
+        return result;
+    }
+
+    private void setPublishSourcePerformance(IntermediateIndicatorsExport item, NewSortStrategyExport data,
+                                             Map<String, Map<String, Map<String, AccountAvgInfo>>> accountAvgInfoIndexMap,
+                                             Map<String, List<ArticleDetailInfo>> articleDetailInfoMap,
+                                             Map<String, List<Article>> hisPublishMap, List<String> small) {
+        List<Article> hisPublish = hisPublishMap.get(data.getTitle());
+        for (Article publish : hisPublish) {
+            Map<String, Map<String, AccountAvgInfo>> dateAvgMap = accountAvgInfoIndexMap.get(publish.getGhId());
+            String hisPublishDate = DateUtils.timestampToYMDStr(publish.getUpdateTime(), "yyyy-MM-dd");
+            AccountAvgInfo avgInfo = null;
+            if (Objects.nonNull(dateAvgMap)) {
+                List<String> avgMapDateList = new ArrayList<>(dateAvgMap.keySet());
+                hisPublishDate = DateUtils.findNearestDate(avgMapDateList, hisPublishDate, "yyyy-MM-dd");
+                Map<String, AccountAvgInfo> accountAvgInfoMap = dateAvgMap.get(hisPublishDate);
+                if (Objects.nonNull(accountAvgInfoMap)) {
+                    avgInfo = accountAvgInfoMap.get(publish.getItemIndex().toString());
+                }
+            }
+            if (!(publish.getItemIndex() == 1 && !small.contains(publish.getGhId()))) {
+                item.setTotalArticleReleaseCountNonInfinite(item.getTotalArticleReleaseCountNonInfinite() + 1);
+            }
+            item.setRedundantViewCount(item.getRedundantViewCount() + publish.getShowViewCount());
+            if (Objects.nonNull(avgInfo)) {
+                item.setRedundantViewBase(item.getRedundantViewBase() + avgInfo.getReadAvg());
+            }
+            if (item.getRedundantViewBase() > 0 && item.getRedundantViewCount() > 0) {
+                item.setAverageViewToBaseRatio(item.getRedundantViewCount() / (double) item.getRedundantViewBase());
+            }
+            List<ArticleDetailInfo> articleDetailInfos = articleDetailInfoMap.get(publish.getWxSn());
+            if (CollectionUtils.isEmpty(articleDetailInfos)) {
+                continue;
+            }
+            int sumFirstLevel = 0;
+            int sumFission0 = 0;
+            Date minDate = articleDetailInfos.stream().map(ArticleDetailInfo::getRecallDt).min(Date::compareTo).orElse(new Date());
+            for (ArticleDetailInfo articleDetailInfo : articleDetailInfos) {
+                if (articleDetailInfo.getRecallDt().equals(minDate)) {
+                    sumFirstLevel += Optional.ofNullable(articleDetailInfo.getFirstLevel()).orElse(0);
+                    sumFission0 += Optional.ofNullable(articleDetailInfo.getFission0()).orElse(0);
+                }
+            }
+            item.setRedundantFirstLayerUV(item.getRedundantFirstLayerUV() + sumFirstLevel);
+            item.setRedundantT0FissionUV(item.getRedundantT0FissionUV() + sumFission0);
+            if (item.getRedundantFirstLayerUV() > 0 && item.getRedundantViewCount() > 0) {
+                item.setAverageMiniAppOpenRate(item.getRedundantFirstLayerUV() / (double) item.getRedundantViewCount());
+            }
+            if (item.getRedundantFirstLayerUV() > 0 && item.getRedundantT0FissionUV() > 0) {
+                item.setAverageT0FissionRate(item.getRedundantT0FissionUV() / (double) item.getRedundantFirstLayerUV());
+            }
+            if (item.getRedundantViewBase() > 0 && item.getRedundantT0FissionUV() > 0) {
+                item.setAverageFirstLayerFissionToViewBaseRatio(item.getRedundantT0FissionUV() / (double) item.getRedundantViewBase());
+            }
+            // todo
+            item.setFirstExplorationIntervalAvg(item.getFirstExplorationIntervalAvg());
+            item.setRedundantAccountArticleRelevanceAvg(item.getRedundantAccountArticleRelevanceAvg());
+        }
+    }
+
+    private void setPublishPerformance(IntermediateIndicatorsExport item, NewSortStrategyExport data,
+                                       Map<String, Map<Integer, PublishSortLog>> publishSortLogMap) {
+        item.setViewCount(item.getViewCount() + data.getViewCount());
+        item.setFirstLayerUV(item.getFirstLayerUV() + data.getFirstLevel());
+        item.setT0FissionUV(item.getT0FissionUV() + data.getFission0());
+        item.setViewBase(item.getViewBase() + data.getAvgViewCount());
+        if (item.getViewBase() > 0 && item.getViewCount() > 0) {
+            item.setViewToBaseRatio(item.getViewCount() / (double) item.getViewBase());
+        }
+        if (item.getFirstLayerUV() > 0 && item.getViewCount() > 0) {
+            item.setMiniAppOpenRate(item.getFirstLayerUV() / (double) item.getViewCount());
+        }
+        if (item.getFirstLayerUV() > 0 && item.getT0FissionUV() > 0) {
+            item.setT0FissionRate(item.getT0FissionUV() / (double) item.getFirstLayerUV());
+            item.setT0FissionRateAgain(item.getT0FissionUV() / (double) item.getFirstLayerUV());
+        }
+        item.setT0FissionCount(item.getT0FissionCount() + data.getFission0());
+        item.setT1FissionCount(item.getT1FissionCount() + data.getFission1());
+        item.setT2FissionCount(item.getT2FissionCount() + data.getFission2());
+        if (item.getT0FissionCount() > 0 && item.getViewBase() > 0) {
+            item.setFirstLayerFissionToViewBaseRatio(item.getT0FissionCount() / (double) item.getViewBase());
+        }
+        if (item.getT0FissionCount() + item.getT1FissionCount() > 0 && item.getFirstLayerUV() > 0) {
+            item.setT1CumulativeFissionRate((item.getT0FissionCount() + item.getT1FissionCount()) / (double) item.getFirstLayerUV());
+        }
+        if (item.getT0FissionCount() + item.getT1FissionCount() + item.getT2FissionCount() > 0 && item.getViewBase() > 0) {
+            item.setT2CumulativeFissionRate((item.getT0FissionCount() + item.getT1FissionCount() + item.getT2FissionCount()) / (double) item.getFirstLayerUV());
+        }
+        Map<Integer, PublishSortLog> indexMap = publishSortLogMap.get(data.getGhId());
+        if (Objects.nonNull(indexMap)) {
+            PublishSortLog log = indexMap.get(data.getPosition());
+            double scoreAvg = item.getAccountArticleRelevanceAvg();
+            double score = 0.0;
+            if (Objects.nonNull(log) && Objects.nonNull(log.getScore())) {
+                JSONObject scoreMap = JSONObject.parseObject(log.getScoreMap());
+                if (scoreMap.containsKey("SimilarityStrategy")) {
+                    score = scoreMap.getDoubleValue("SimilarityStrategy");
+                }
+            }
+            scoreAvg = (scoreAvg * (item.getActualArticleReleaseCount() - 1) + score) / item.getActualArticleReleaseCount();
+            item.setAccountArticleRelevanceAvg(scoreAvg);
+        }
+    }
+
+    private void setPublishSituation(IntermediateIndicatorsExport item, String type, Map<String, List<String>> titleTypeMap,
+                                     Map<String, Map<Integer, List<String>>> titleTypePoolMap, Integer poolLevel,
+                                     NewSortStrategyExport data) {
+        item.setArticleReleaseSlot(item.getArticleReleaseSlot() + 1);
+        item.setActualArticleReleaseCount(item.getActualArticleReleaseCount() + 1);
+        if (titleTypeMap.containsKey(type) && !titleTypeMap.get(type).contains(data.getTitle())) {
+            item.setDistinctArticleReleaseCount(item.getDistinctArticleReleaseCount() + 1);
+        }
+        item.setDistinctArticleReleaseRatio(item.getDistinctArticleReleaseCount() / (double) item.getActualArticleReleaseCount());
+
+        if (4 == poolLevel) {
+            item.setActualReleaseCountL4(item.getActualReleaseCountL4() + 1);
+        } else if (3 == poolLevel) {
+            item.setActualReleaseCountL3(item.getActualReleaseCountL3() + 1);
+        } else if (2 == poolLevel) {
+            item.setActualReleaseCountL2(item.getActualReleaseCountL2() + 1);
+        } else {
+            item.setActualReleaseCountL1(item.getActualReleaseCountL1() + 1);
+        }
+        if (titleTypePoolMap.containsKey(type)
+                && titleTypePoolMap.get(type).containsKey(poolLevel)
+                && !titleTypePoolMap.get(type).get(poolLevel).contains(data.getTitle())) {
+            if (4 == poolLevel) {
+                item.setDistinctReleaseCountL4(item.getDistinctReleaseCountL4() + 1);
+            } else if (3 == poolLevel) {
+                item.setDistinctReleaseCountL3(item.getDistinctReleaseCountL3() + 1);
+            } else if (2 == poolLevel) {
+                item.setDistinctReleaseCountL2(item.getDistinctReleaseCountL2() + 1);
+            } else {
+                item.setDistinctReleaseCountL1(item.getDistinctReleaseCountL1() + 1);
+            }
+        }
+        if (item.getActualReleaseCountL1() > 0 && item.getDistinctReleaseCountL1() > 0) {
+            item.setDistinctToActualRatioL1(item.getDistinctReleaseCountL1() / (double) item.getActualReleaseCountL1());
+        }
+        if (item.getActualReleaseCountL2() > 0 && item.getDistinctReleaseCountL2() > 0) {
+            item.setDistinctToActualRatioL2(item.getDistinctReleaseCountL2() / (double) item.getActualReleaseCountL2());
+        }
+        if (item.getActualReleaseCountL3() > 0 && item.getDistinctReleaseCountL3() > 0) {
+            item.setDistinctToActualRatioL3(item.getDistinctReleaseCountL3() / (double) item.getActualReleaseCountL3());
+        }
+        if (item.getActualReleaseCountL4() > 0 && item.getDistinctReleaseCountL4() > 0) {
+            item.setDistinctToActualRatioL4(item.getDistinctReleaseCountL4() / (double) item.getActualReleaseCountL4());
+        }
+    }
+
+    private Integer getArticlePoolLevel(NewSortStrategyExport data, List<Article> list, List<String> small) {
+        int minPosition = list.stream().mapToInt(Article::getItemIndex).min().orElse(8);
+        if (minPosition == 1) {
+            if (small.contains(data.getGhId())) {
+                return 3;
+            } else {
+                return 4;
+            }
+        } else if (data.getPosition() == 2) {
+            return 2;
+        } else {
+            return 1;
+        }
+    }
+
+    private String getArticleType(NewSortStrategyExport data, List<String> small) {
+        if (data.getPosition() == 1) {
+            if (small.contains(data.getGhId())) {
+                return "L1-订阅号冷启1";
+            } else {
+                return "L1-订阅号无限流";
+            }
+        } else if (data.getPosition() == 2) {
+            return "L2-订阅号冷启2";
+        } else {
+            return "L3-订阅号利用";
+        }
+    }
+
+    private List<IntermediateIndicatorsExport> buildIntermediateIndicatorsData(String dateStr) {
+        List<IntermediateIndicatorsExport> result = new ArrayList<>();
+        List<String> typeList = Arrays.asList("L3-订阅号利用", "L2-订阅号冷启2", "L1-订阅号冷启1", "L1-订阅号无限流");
+        for (String type : typeList) {
+            IntermediateIndicatorsExport item = new IntermediateIndicatorsExport();
+            item.setDateStr(dateStr);
+            item.setType(type);
+            result.add(item);
+        }
+        return result;
+    }
+
 }

+ 40 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/util/DateUtils.java

@@ -140,6 +140,46 @@ public final class DateUtils {
         return datesList;
     }
 
+    // 获取每日最小秒数 (当天零点)
+    public static Long getStartOfDay(String dateStr, String formatter) {
+        try {
+            SimpleDateFormat sdf = new SimpleDateFormat(formatter);
+            Date date = sdf.parse(dateStr);
+
+            Calendar calendar = Calendar.getInstance();
+            calendar.setTime(date);
+            calendar.set(Calendar.HOUR_OF_DAY, 0);
+            calendar.set(Calendar.MINUTE, 0);
+            calendar.set(Calendar.SECOND, 0);
+            calendar.set(Calendar.MILLISECOND, 0);
+
+            return calendar.getTimeInMillis() / 1000;
+        } catch (Exception e) {
+            Date date = new Date();
+            return date.getTime() / 1000;
+        }
+    }
+
+    // 获取每日最大秒数 (当天的23:59:59)
+    public static Long getEndOfDay(String dateStr, String formatter) {
+        try {
+            SimpleDateFormat sdf = new SimpleDateFormat(formatter);
+            Date date = sdf.parse(dateStr);
+
+            Calendar calendar = Calendar.getInstance();
+            calendar.setTime(date);
+            calendar.set(Calendar.HOUR_OF_DAY, 23);
+            calendar.set(Calendar.MINUTE, 59);
+            calendar.set(Calendar.SECOND, 59);
+            calendar.set(Calendar.MILLISECOND, 999);
+
+            return calendar.getTimeInMillis() / 1000;
+        } catch (Exception e) {
+            Date date = new Date();
+            return date.getTime() / 1000;
+        }
+    }
+
 
     public static void main(String[] args) {
         Calendar calendar = Calendar.getInstance();

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

@@ -21,5 +21,11 @@ public class DataDashboardController {
             service.export(dateStr);
         }).start();
     }
+    @GetMapping("/export/intermediateIndicators")
+    public void intermediateIndicatorsExport(String dateStr) {
+        new Thread(() -> {
+            service.intermediateIndicatorsExport(dateStr);
+        }).start();
+    }
 
 }