wangyunpeng 10 miesięcy temu
rodzic
commit
196a3a5f32

+ 4 - 1
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/model/NewSortStrategyExport.java

@@ -6,6 +6,7 @@ import lombok.Data;
 public class NewSortStrategyExport {
 
     private String dateStr;
+    private String publishTime;
     private String accountMode;
     private String accountSource;
     private String accountType;
@@ -22,11 +23,13 @@ public class NewSortStrategyExport {
     private Double readRate = 0.0;
     private Double readFansRate = 0.0;
     private Double firstReadRate = 0.0;
-    private Double fission0ReadAvgRate = 0.0;
+    private Double fission0FirstRate = 0.0;
     private Double fission1Fission0Rate = 0.0;
+    private Double fission0ReadAvgRate = 0.0;
     private Integer position;
     private String ghId;
     private String title;
     private String link;
+    private String wxSn;
 
 }

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

@@ -5,10 +5,9 @@ import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.stereotype.Repository;
 
 import java.util.List;
-import java.util.Set;
 
 @Repository
 public interface ArticleDetailInfoRepository extends JpaRepository<ArticleDetailInfo, ArticleDetailInfo.PK> {
 
-    List<ArticleDetailInfo> getAllByWxSnIn(Set<String> wxSnList);
+    List<ArticleDetailInfo> getAllByWxSnIn(List<String> wxSnList);
 }

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

@@ -12,7 +12,7 @@ public interface ArticleRepository extends JpaRepository<Article, String> {
 
     List<Article> getByAccountNameAndItemIndexInAndTypeEquals(String accountName, List<Integer> indexList, String type);
 
-    List<Article> getByTitleIn(Set<String> titleList);
+    List<Article> getByTitleIn(List<String> titleList);
 
     List<Article> getByGhIdInAndAppMsgIdInAndItemIndex(Set<String> ghIds, Set<String> appMsgIds, Integer itemIndex);
 

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

@@ -28,7 +28,6 @@ import org.springframework.util.StringUtils;
 import org.springframework.web.client.RestTemplate;
 
 import java.lang.reflect.Field;
-import java.text.SimpleDateFormat;
 import java.time.LocalDate;
 import java.time.format.DateTimeFormatter;
 import java.util.*;
@@ -88,7 +87,7 @@ public class DataDashboardService {
 
     private void exportFeishuNewSortStrategy(List<String> dateStrList, String sheetToken, String sheetId) {
         String minDate = dateStrList.stream().min(String::compareTo).orElse("");
-        List<NewSortStrategyExport> newContentsYesData = newSortStrageData(minDate);
+        List<NewSortStrategyExport> newContentsYesData = newSortStrategyData(minDate);
         if (CollectionUtil.isEmpty(newContentsYesData)) {
             return;
         }
@@ -114,24 +113,25 @@ public class DataDashboardService {
 
         List<Pair<String, String>> styles = Arrays
                 .asList(
-                        Pair.of("O", "0.00%"),
                         Pair.of("P", "0.00%"),
                         Pair.of("Q", "0.00%"),
                         Pair.of("R", "0.00%"),
-                        Pair.of("S", "0.00%")
+                        Pair.of("S", "0.00%"),
+                        Pair.of("T", "0.00%"),
+                        Pair.of("U", "0.00%")
                 );
 
         doSendFeishuSheet(dateStrList, sheetToken, sheetId, rowNum, rows, 2, styles);
     }
 
-    private List<NewSortStrategyExport> newSortStrageData(String dateStr) {
+    private List<NewSortStrategyExport> newSortStrategyData(String dateStr) {
         long timestamp = DateUtils.dateStrToTimestamp(dateStr, "yyyyMMdd");
         List<AccountAvgInfo> accountAvgInfoList = accountAvgInfoRepository.getAllByStatusEquals(1);
         Set<String> ghIds = accountAvgInfoList.stream().map(AccountAvgInfo::getGhId).collect(Collectors.toSet());
         List<Article> articleList = articleRepository.getByGhIdInAndUpdateTimeGreaterThan(ghIds, timestamp);
 
         Set<String> snList = articleList.stream().map(Article::getWxSn).collect(Collectors.toSet());
-        List<ArticleDetailInfo> articleDetailInfoList = articleDetailInfoRepository.getAllByWxSnIn(snList);
+        List<ArticleDetailInfo> articleDetailInfoList = articleDetailInfoRepository.getAllByWxSnIn(new ArrayList<>(snList));
         Map<String, List<ArticleDetailInfo>> articleDetailInfoMap = articleDetailInfoList.stream()
                 .collect(Collectors.groupingBy(ArticleDetailInfo::getWxSn));
         List<PublishSortLog> sortLogList = publishSortLogRepository.findByGhIdInAndDateStrGreaterThanEqual(ghIds, dateStr);
@@ -163,8 +163,7 @@ public class DataDashboardService {
             }
             Map<String, AccountAvgInfo> accountAvgInfoMap = accountAvgInfoIndexMap.get(article.getGhId());
             AccountAvgInfo avgInfo = accountAvgInfoMap.get(article.getItemIndex().toString());
-            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
-            String date = sdf.format(new Date(article.getUpdateTime() * 1000));
+            String date = DateUtils.timestampToYMDStr(article.getUpdateTime(), "yyyyMMdd");
             NewSortStrategyExport obj = new NewSortStrategyExport();
             obj.setGhId(article.getGhId());
             obj.setAccountName(article.getAccountName());
@@ -173,7 +172,15 @@ public class DataDashboardService {
             obj.setPosition(article.getItemIndex());
             obj.setViewCount(article.getShowViewCount());
             obj.setDateStr(date);
-            obj.setStrategy(dateStrategy.get(date));
+            obj.setPublishTime(DateUtils.timestampToYMDStr(article.getUpdateTime(), "HH:mm:ss"));
+            obj.setFirstLevel(sumfirstLevel);
+            obj.setFission0(sumFission0);
+            obj.setFission1(sumFission1);
+            obj.setFission2(sumFission2);
+            obj.setWxSn(article.getWxSn());
+            if (Objects.nonNull(dateStrategy)) {
+                obj.setStrategy(dateStrategy.get(date));
+            }
             if (Objects.nonNull(avgInfo)) {
                 obj.setAccountMode(avgInfo.getAccountMode());
                 obj.setAccountSource(avgInfo.getAccountSource());
@@ -183,17 +190,14 @@ public class DataDashboardService {
                 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());
                 }
             }
-            obj.setFirstLevel(sumfirstLevel);
-            obj.setFission0(sumFission0);
-            obj.setFission1(sumFission1);
-            obj.setFission2(sumFission2);
             if (sumfirstLevel > 0) {
-                obj.setFission0ReadAvgRate((sumFission0 * 1.0) / sumfirstLevel);
+                obj.setFission0FirstRate((sumFission0 * 1.0) / sumfirstLevel);
             }
             if (article.getShowViewCount() > 0) {
                 obj.setFirstReadRate((sumfirstLevel * 1.0) / article.getShowViewCount());
@@ -261,7 +265,7 @@ public class DataDashboardService {
                 delNum = Math.min(delNum + 4000, count);
             } while (delNum < count);
         }
-        List<List<List<Object>>> partitions = Lists.partition(rows, 4000);
+        List<List<List<Object>>> partitions = Lists.partition(rows, 1000);
         int startRow = startRowIndex;
         for (List<List<Object>> partition : partitions) {
             // 插入数据
@@ -269,7 +273,7 @@ public class DataDashboardService {
                     .builder()
                     .put("valueRange", MapBuilder
                             .builder()
-                            .put("range", String.format("%s!A" + startRow + ":W", sheetId) + (partition.size() + startRow - 1))
+                            .put("range", String.format("%s!A" + startRow + ":Z", sheetId) + (partition.size() + startRow - 1))
                             .put("values", partition)
                             .build())
                     .build(), httpHeaders);

+ 11 - 2
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recall/RecallService.java

@@ -1,5 +1,6 @@
 package com.tzld.longarticle.recommend.server.service.recall;
 
+import com.google.common.collect.Lists;
 import com.tzld.longarticle.recommend.server.common.ThreadPoolFactory;
 import com.tzld.longarticle.recommend.server.model.Content;
 import com.tzld.longarticle.recommend.server.model.ContentHisPublishArticle;
@@ -191,11 +192,19 @@ public class RecallService implements ApplicationContextAware {
         Set<String> crawlerTitleList = contentList.stream().map(Content::getCrawlerTitle).collect(Collectors.toSet());
         titleList.addAll(crawlerTitleList);
         // 获取历史已发布文章
-        List<Article> hisArticleList = articleRepository.getByTitleIn(titleList);
+        List<Article> hisArticleList = new ArrayList<>();
+        List<List<String>> titlePartition = Lists.partition(new ArrayList<>(titleList), 1000);
+        for (List<String> titles : titlePartition) {
+            hisArticleList.addAll(articleRepository.getByTitleIn(titles));
+        }
         Map<String, Map<Integer, List<Article>>> map = hisArticleList.stream()
                 .collect(Collectors.groupingBy(Article::getTitle, Collectors.groupingBy(Article::getItemIndex)));
         Set<String> snList = hisArticleList.stream().map(Article::getWxSn).collect(Collectors.toSet());
-        List<ArticleDetailInfo> articleDetailInfoList = articleDetailInfoRepository.getAllByWxSnIn(snList);
+        List<ArticleDetailInfo> articleDetailInfoList = new ArrayList<>();
+        List<List<String>> snPartition = Lists.partition(new ArrayList<>(snList), 1000);
+        for (List<String> sns : snPartition) {
+            articleDetailInfoList.addAll(articleDetailInfoRepository.getAllByWxSnIn(sns));
+        }
         Map<String, List<ArticleDetailInfo>> articleDetailInfoMap = articleDetailInfoList.stream()
                 .collect(Collectors.groupingBy(ArticleDetailInfo::getWxSn));
         // 获取历史已发布文章所属头条内容

+ 2 - 1
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/score/ScoreService.java

@@ -44,6 +44,7 @@ public class ScoreService implements ApplicationContextAware {
     }
 
     public ScoreResult score(ScoreParam param) {
+        long start = System.currentTimeMillis();
         List<ScoreStrategy> strategies = getScoreStrategy(param);
         log.info("ScoreStrategy {}", JSONUtils.toJson(CommonCollectionUtils.toList(strategies,
                 s -> s.getClass().getSimpleName())));
@@ -77,7 +78,7 @@ public class ScoreService implements ApplicationContextAware {
                 log.error("future get error ", e);
             }
         }
-
+        log.info("score耗时:{}", System.currentTimeMillis() - start);
         return new ScoreResult(scoreMap);
     }
 

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

@@ -1,6 +1,7 @@
 package com.tzld.longarticle.recommend.server.util;
 
 import java.text.SimpleDateFormat;
+import java.time.Instant;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.ZoneId;
@@ -72,6 +73,21 @@ public final class DateUtils {
         return dateTime.toEpochSecond(zone.getRules().getOffset(dateTime));
     }
 
+    public static String timestampToYMDStr(Long timestamp, String format) {
+
+        // 定义北京时区
+        ZoneId zone = ZoneId.of("Asia/Shanghai");
+
+        // 将时间戳转换为LocalDateTime
+        LocalDateTime dateTime = LocalDateTime.ofInstant(Instant.ofEpochSecond(timestamp), zone);
+
+        // 定义日期格式为"yyyyMMddHHmmss"
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
+
+        // 将LocalDateTime格式化为字符串
+        return dateTime.format(formatter);
+    }
+
 
     public static void main(String[] args) {
         Calendar calendar = Calendar.getInstance();