Jelajahi Sumber

Merge branch 'wyp/1218-exportDetail' of Server/long-article-recommend into master

wangyunpeng 7 bulan lalu
induk
melakukan
6b8a04d885

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

@@ -45,6 +45,7 @@ import com.xxl.job.core.biz.model.ReturnT;
 import com.xxl.job.core.handler.annotation.XxlJob;
 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.data.util.Pair;
 import org.springframework.http.*;
@@ -339,7 +340,7 @@ public class DataDashboardService {
             setObjArticleDetailInfo(article, obj, articleDetailInfos);
             Article firstArticle = articleMap.get(article.getGhId()).get(article.getAppMsgId()).get(1);
             Map<String, Map<String, PublishSortLog>> dateStrategy = sortStrategyMap.get(article.getGhId());
-            AccountAvgInfo avgInfo = getAccountAvgInfo(accountAvgInfoIndexMap, article.getGhId(),
+            Map<String, AccountAvgInfo> indexAvgInfoMap = getDateAccountAvgInfo(accountAvgInfoIndexMap, article.getGhId(),
                     article.getPublishTimestamp(), article.getItemIndex());
             AccountAvgInfo firstAvgInfo = getAccountAvgInfo(accountAvgInfoIndexMap, article.getGhId(),
                     article.getPublishTimestamp(), 1);
@@ -377,7 +378,7 @@ public class DataDashboardService {
                     Objects.equals(articleType, ArticleTypeEnum.WUXIANLIU.getVal())) {
                 obj.setStrategy(RankStrategyEnum.INFINITE_STRATEGY.getStrategy());
             }
-            setObjAvgInfo(article, obj, avgInfo);
+            setObjAvgInfo(article, obj, indexAvgInfoMap);
             setObjHisRateInfo(article, obj, hisArticleMap, accountAvgInfoIndexMap, hisArticleDetailInfoMap);
             // aigc 数据
             setObjAigcInfo(article, obj, date, publishAccountMap, publishContentMap, publishContentLayoutMap,
@@ -601,14 +602,24 @@ public class DataDashboardService {
         }
     }
 
-    private void setObjAvgInfo(Article article, DatastatSortStrategy obj, AccountAvgInfo avgInfo) {
+    private void setObjAvgInfo(Article article, DatastatSortStrategy obj, Map<String, AccountAvgInfo> indexAvgInfoMap) {
+        if (MapUtils.isNotEmpty(indexAvgInfoMap)) {
+            AccountAvgInfo info = null;
+            for (String index : indexAvgInfoMap.keySet()) {
+                info = indexAvgInfoMap.get(index);
+                break;
+            }
+            if (Objects.nonNull(info)) {
+                obj.setAccountMode(info.getAccountMode());
+                obj.setAccountSource(info.getAccountSource());
+                obj.setAccountType(info.getAccountType());
+                obj.setAccountStatus(info.getAccountStatus());
+                obj.setBusinessType(AccountBusinessTypeEnum.from(info.getBusinessType()).getDescription());
+                obj.setFans(info.getFans());
+            }
+        }
+        AccountAvgInfo avgInfo = indexAvgInfoMap.get(article.getItemIndex().toString());
         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());
@@ -1066,6 +1077,21 @@ public class DataDashboardService {
         return avgInfo;
     }
 
+    private Map<String, AccountAvgInfo> getDateAccountAvgInfo(Map<String, Map<String, Map<String, AccountAvgInfo>>> accountAvgInfoIndexMap,
+                                                              String ghId, Long updateTime, Integer itemIndex) {
+        Map<String, Map<String, AccountAvgInfo>> dateAvgMap = accountAvgInfoIndexMap.get(ghId);
+        String hisPublishDate = DateUtils.timestampToYMDStr(updateTime, "yyyy-MM-dd");
+        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)) {
+                return accountAvgInfoMap;
+            }
+        }
+        return new HashMap<>();
+    }
+
     private void setPublishFuturePerformance(IntermediateIndicatorsExport item, DatastatSortStrategy data, Integer poolLevel,
                                              Map<String, ArticlePoolPromotionSource> promotionSourceMap,
                                              Map<String, List<Article>> futurePublishMap,
@@ -1205,11 +1231,11 @@ public class DataDashboardService {
             DatastatSortStrategy obj = new DatastatSortStrategy();
             List<ArticleDetailInfo> articleDetailInfos = articleDetailInfoMap.get(article.getWxSn());
             setObjArticleDetailInfo(article, obj, articleDetailInfos);
-            AccountAvgInfo avgInfo = getAccountAvgInfo(accountAvgInfoIndexMap, article.getGhId(),
+            Map<String, AccountAvgInfo> indexAvgInfoMap = getDateAccountAvgInfo(accountAvgInfoIndexMap, article.getGhId(),
                     article.getPublishTimestamp(), article.getItemIndex());
             String date = DateUtils.timestampToYMDStr(article.getPublishTimestamp(), "yyyyMMdd");
             setObjBaseInfo(article, obj, date);
-            setObjAvgInfo(article, obj, avgInfo);
+            setObjAvgInfo(article, obj, indexAvgInfoMap);
             result.add(obj);
         }
         return result;