Browse Source

Merge branch 'wyp/1203-sortLog' of Server/long-article-recommend into master

wangyunpeng 7 months ago
parent
commit
d87afa52fe

+ 0 - 30
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/model/entity/crawler/PublishContentSortLog.java

@@ -1,30 +0,0 @@
-package com.tzld.longarticle.recommend.server.model.entity.crawler;
-
-import lombok.AllArgsConstructor;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
-import javax.persistence.*;
-
-@Data
-@AllArgsConstructor
-@NoArgsConstructor
-@Entity
-@Table(name = "publish_content_sort_log")
-public class PublishContentSortLog {
-
-    @Id
-    @GeneratedValue(strategy = GenerationType.IDENTITY)
-    private Long id;
-    @Column(name = "gh_id")
-    private String ghId;
-    @Column(name = "account_name")
-    private String accountName;
-    @Column(name = "strategy")
-    private String strategy;
-    @Column(name = "publish_content_id")
-    private String publishContentId;
-    @Column(name = "create_timestamp")
-    private Long createTimestamp;
-
-}

+ 4 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/model/entity/crawler/PublishSortLog.java

@@ -22,8 +22,12 @@ public class PublishSortLog {
     private String ghId;
     @Column(name = "account_name")
     private String accountName;
+    @Column(name = "publish_content_id")
+    private String publishContentId;
     @Column(name = "crawler_channel_content_id")
     private String crawlerChannelContentId;
+    @Column(name = "source_id")
+    private String sourceId;
     @Column(name = "title")
     private String title;
     @Column(name = "`index`")

+ 9 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/model/entity/longArticle/DatastatScore.java

@@ -74,4 +74,13 @@ public class DatastatScore {
     @Column(name = "first_pub_interval")
     private Integer firstPubInterval;
 
+    @Column(name = "publish_content_id")
+    private String publishContentId;
+
+    @Column(name = "crawler_channel_content_id")
+    private String crawlerChannelContentId;
+
+    @Column(name = "source_id")
+    private String sourceId;
+
 }

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

@@ -1,10 +0,0 @@
-package com.tzld.longarticle.recommend.server.repository.crawler;
-
-import com.tzld.longarticle.recommend.server.model.entity.crawler.PublishContentSortLog;
-import org.springframework.data.jpa.repository.JpaRepository;
-import org.springframework.stereotype.Repository;
-
-@Repository
-public interface PublishContentSortLogRepository extends JpaRepository<PublishContentSortLog, Long> {
-
-}

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

@@ -1513,6 +1513,7 @@ public class DataDashboardService {
                                 Collectors.toMap(AccountAvgInfo::getPosition, o -> o))));
 
         String title = "";
+        List<DatastatScore> saveList = new ArrayList<>();
         for (PublishSortLog publishSortLog : sortLogList) {
             Map<String, Map<Integer, Article>> dateArticleMap = articleMap.get(publishSortLog.getGhId());
             if (Objects.isNull(dateArticleMap)) {
@@ -1578,40 +1579,44 @@ public class DataDashboardService {
                 item.setFirstExplorationIntervalAvg(explorationInterval);
             }
             result.add(item);
+            saveList.add(buildDatastatScore(publishSortLog, item));
         }
-        saveDatastatScore(dateStrList, result);
+        saveDatastatScore(dateStrList, saveList);
         result = result.stream().filter(o -> o.getIndex() == 1).collect(Collectors.toList());
         result.sort(Comparator.comparing(FirstContentScoreExport::getDateStr).reversed()
                 .thenComparing(FirstContentScoreExport::getGhId));
         return result;
     }
 
-    private void saveDatastatScore(List<String> dateStrList, List<FirstContentScoreExport> result) {
-        if (CollectionUtils.isNotEmpty(result)) {
+    private DatastatScore buildDatastatScore(PublishSortLog publishSortLog, FirstContentScoreExport value) {
+        DatastatScore item = new DatastatScore();
+        item.setDt(value.getDateStr());
+        item.setGhId(value.getGhId());
+        item.setAccountName(value.getAccountName());
+        item.setIndex(value.getIndex());
+        item.setTitle(value.getTitle());
+        item.setCategory(value.getCategory());
+        item.setStrategy(value.getStrategy());
+        item.setScore(value.getScore());
+        item.setHisFissionAvgReadRateRate(value.getHisFissionAvgReadRateRateStrategy());
+        item.setHisFissionAvgReadSumRate(value.getHisFissionAvgReadSumRateStrategy());
+        item.setSimilarity(value.getSimilarityStrategy());
+        item.setCategoryScore(value.getCategoryStrategy());
+        item.setViewCountRate(value.getViewCountRateStrategy());
+        item.setHisFissionDeWeightAvgReadSumRate(value.getHisFissionDeWeightAvgReadSumRateStrategy());
+        item.setReadCount(value.getReadCount());
+        item.setReadAvg(value.getReadAvg());
+        item.setReadAvgRate(value.getReadAvgRate());
+        item.setFirstPubInterval(value.getFirstExplorationIntervalAvg());
+        item.setPublishContentId(publishSortLog.getPublishContentId());
+        item.setCrawlerChannelContentId(publishSortLog.getCrawlerChannelContentId());
+        item.setSourceId(publishSortLog.getSourceId());
+        return item;
+    }
+
+    private void saveDatastatScore(List<String> dateStrList, List<DatastatScore> saveList) {
+        if (CollectionUtils.isNotEmpty(saveList)) {
             longArticleBaseMapper.deleteDatastatScoreByDtIn(dateStrList);
-            List<DatastatScore> saveList = new ArrayList<>();
-            for (FirstContentScoreExport value : result) {
-                DatastatScore item = new DatastatScore();
-                item.setDt(value.getDateStr());
-                item.setGhId(value.getGhId());
-                item.setAccountName(value.getAccountName());
-                item.setIndex(value.getIndex());
-                item.setTitle(value.getTitle());
-                item.setCategory(value.getCategory());
-                item.setStrategy(value.getStrategy());
-                item.setScore(value.getScore());
-                item.setHisFissionAvgReadRateRate(value.getHisFissionAvgReadRateRateStrategy());
-                item.setHisFissionAvgReadSumRate(value.getHisFissionAvgReadSumRateStrategy());
-                item.setSimilarity(value.getSimilarityStrategy());
-                item.setCategoryScore(value.getCategoryStrategy());
-                item.setViewCountRate(value.getViewCountRateStrategy());
-                item.setHisFissionDeWeightAvgReadSumRate(value.getHisFissionDeWeightAvgReadSumRateStrategy());
-                item.setReadCount(value.getReadCount());
-                item.setReadAvg(value.getReadAvg());
-                item.setReadAvgRate(value.getReadAvgRate());
-                item.setFirstPubInterval(value.getFirstExplorationIntervalAvg());
-                saveList.add(item);
-            }
             for (List<DatastatScore> saveListPartition : Lists.partition(saveList, 1000)) {
                 longArticleBaseMapper.batchInsertDatastatScore(saveListPartition);
             }

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

@@ -3,14 +3,13 @@ package com.tzld.longarticle.recommend.server.service.recommend;
 import com.alibaba.fastjson.JSONObject;
 import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
 import com.tzld.longarticle.recommend.server.common.CostMonitor;
-import com.tzld.longarticle.recommend.server.common.enums.recommend.ArticleTypeEnum;
+import com.tzld.longarticle.recommend.server.common.constant.SceneConstants;
 import com.tzld.longarticle.recommend.server.common.enums.aigc.PushTypeEnum;
+import com.tzld.longarticle.recommend.server.common.enums.recommend.ArticleTypeEnum;
 import com.tzld.longarticle.recommend.server.common.enums.recommend.RankStrategyEnum;
-import com.tzld.longarticle.recommend.server.mapper.aigc.AigcBaseMapper;
 import com.tzld.longarticle.recommend.server.mapper.crawler.ArticleUserGroupMapper;
 import com.tzld.longarticle.recommend.server.model.dto.Content;
 import com.tzld.longarticle.recommend.server.model.entity.crawler.AccountAvgInfo;
-import com.tzld.longarticle.recommend.server.model.entity.crawler.PublishContentSortLog;
 import com.tzld.longarticle.recommend.server.model.entity.crawler.PublishSortLog;
 import com.tzld.longarticle.recommend.server.model.param.RecommendParam;
 import com.tzld.longarticle.recommend.server.model.param.RecommendRequest;
@@ -20,9 +19,7 @@ import com.tzld.longarticle.recommend.server.model.vo.RecommendResponse;
 import com.tzld.longarticle.recommend.server.model.vo.RecommendWithUserGroupResponse;
 import com.tzld.longarticle.recommend.server.repository.crawler.AccountAvgInfoRepository;
 import com.tzld.longarticle.recommend.server.repository.crawler.ArticleRepository;
-import com.tzld.longarticle.recommend.server.repository.crawler.PublishContentSortLogRepository;
 import com.tzld.longarticle.recommend.server.repository.crawler.PublishSortLogRepository;
-import com.tzld.longarticle.recommend.server.common.constant.SceneConstants;
 import com.tzld.longarticle.recommend.server.service.recommend.config.AccountIndexAvgViewCountService;
 import com.tzld.longarticle.recommend.server.service.recommend.rank.RankParam;
 import com.tzld.longarticle.recommend.server.service.recommend.rank.RankResult;
@@ -62,8 +59,6 @@ public class RecommendService {
     @Autowired
     private RankService rankService;
     @Autowired
-    private PublishContentSortLogRepository publishContentSortLogRepository;
-    @Autowired
     private PublishSortLogRepository publishSortLogRepository;
     @Autowired
     AccountIndexAvgViewCountService accountIndexAvgViewCountService;
@@ -72,8 +67,6 @@ public class RecommendService {
     @Autowired
     private ArticleUserGroupMapper articleUserGroupMapper;
     @Autowired
-    private AigcBaseMapper aigcBaseMapper;
-    @Autowired
     private ArticleRepository articleRepository;
 
     @ApolloJsonValue("${accountStrategyConfig:{}}")
@@ -282,21 +275,6 @@ public class RecommendService {
         if (!ArticleTypeEnum.QUNFA.getVal().equals(param.getType())) {
             return;
         }
-        switch (param.getScene()) {
-            case FWH_COLD_START:
-                break;
-            default:
-                PublishContentSortLog log = new PublishContentSortLog();
-                log.setGhId(param.getGhId());
-                log.setAccountName(param.getAccountName());
-                log.setStrategy(param.getStrategy());
-                List<String> publishContentIds = rankResult.getContents().stream().map(Content::getId).collect(Collectors.toList());
-                log.setPublishContentId(JSONObject.toJSONString(publishContentIds));
-                log.setCreateTimestamp(System.currentTimeMillis());
-                publishContentSortLogRepository.save(log);
-                break;
-
-        }
         String dateStr = DateUtils.getCurrentDateStr("yyyyMMdd");
         List<PublishSortLog> publishSortLogSaveList = new ArrayList<>();
         List<AccountAvgInfo> avgInfoList = accountAvgInfoRepository.getAllByGhIdEqualsAndStatusEquals(param.getGhId(), 1);
@@ -313,7 +291,9 @@ public class RecommendService {
             sortLog.setDateStr(dateStr);
             sortLog.setGhId(param.getGhId());
             sortLog.setAccountName(param.getAccountName());
+            sortLog.setPublishContentId(content.getId());
             sortLog.setCrawlerChannelContentId(content.getCrawlerChannelContentId());
+            sortLog.setSourceId(content.getSourceId());
             sortLog.setTitle(content.getTitle());
             sortLog.setIndex(i);
             sortLog.setIndexAvgCount(accountIndexAvgViewCountService.getAvgReadCountByDB(avgInfoList, param.getGhId(), i));

+ 6 - 4
long-article-recommend-service/src/main/resources/mapper/longArticle/LongArticleBaseMapper.xml

@@ -72,14 +72,16 @@
     <insert id="batchInsertDatastatScore">
         INSERT INTO datastat_score
         (dt, gh_id, account_name, `index`, title, strategy, score, similarity, view_count_rate,
-         his_fission_avg_read_rate_rate, his_fission_avg_read_sum_rate, his_fission_de_weight_avg_read_sum_rate,
-        read_count, read_avg, read_avg_rate, category, category_score, first_pub_interval)
+        his_fission_avg_read_rate_rate, his_fission_avg_read_sum_rate, his_fission_de_weight_avg_read_sum_rate,
+        read_count, read_avg, read_avg_rate, category, category_score, first_pub_interval, publish_content_id,
+        crawler_channel_content_id, source_id)
         VALUES
         <foreach collection="list" item="item" separator=",">
             (#{item.dt}, #{item.ghId}, #{item.accountName}, #{item.index}, #{item.title}, #{item.strategy},
-             #{item.score}, #{item.similarity}, #{item.viewCountRate}, #{item.hisFissionAvgReadRateRate},
+            #{item.score}, #{item.similarity}, #{item.viewCountRate}, #{item.hisFissionAvgReadRateRate},
             #{item.hisFissionAvgReadSumRate}, #{item.hisFissionDeWeightAvgReadSumRate}, #{item.readCount},
-             #{item.readAvg}, #{item.readAvgRate}, #{item.category}, #{item.categoryScore}, #{item.firstPubInterval})
+            #{item.readAvg}, #{item.readAvgRate}, #{item.category}, #{item.categoryScore}, #{item.firstPubInterval},
+            #{item.publishContentId}, #{item.crawlerChannelContentId}, #{item.sourceId})
         </foreach>
     </insert>