Преглед на файлове

article_category add version

wangyunpeng преди 3 месеца
родител
ревизия
b8afe8192e
променени са 10 файла, в които са добавени 55 реда и са изтрити 18 реда
  1. 3 0
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/model/entity/longArticle/AccountCategory.java
  2. 3 3
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/remote/DeepSeekApiService.java
  3. 2 2
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/repository/longArticle/AccountCategoryRepository.java
  4. 2 0
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/repository/longArticle/ArticleCategoryRepository.java
  5. 2 0
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/repository/longArticle/DatastatScoreRepository.java
  6. 12 9
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/ArticleCategoryService.java
  7. 1 1
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/recall/RecallService.java
  8. 6 1
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/score/strategy/CategoryStrategy.java
  9. 2 2
      long-article-recommend-service/src/main/resources/mapper/longArticle/ArticleCategoryMapper.xml
  10. 22 0
      long-article-recommend-service/src/test/java/com/tzld/longarticle/recommend/server/DataDashboardTest.java

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

@@ -26,6 +26,9 @@ public class AccountCategory {
     @Column(name = "status")
     @Column(name = "status")
     private Integer status;
     private Integer status;
 
 
+    @Column(name = "version")
+    private Integer version;
+
     @Column(name = "create_timestamp")
     @Column(name = "create_timestamp")
     private Long createTimestamp;
     private Long createTimestamp;
 
 

+ 3 - 3
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/remote/DeepSeekApiService.java

@@ -25,9 +25,9 @@ public class DeepSeekApiService {
     @PostConstruct
     @PostConstruct
     public void init() {
     public void init() {
         client = new OkHttpClient().newBuilder()
         client = new OkHttpClient().newBuilder()
-                .connectTimeout(15, TimeUnit.MINUTES)
-                .readTimeout(15, TimeUnit.MINUTES)
-                .writeTimeout(15, TimeUnit.MINUTES)
+                .connectTimeout(5, TimeUnit.MINUTES)
+                .readTimeout(5, TimeUnit.MINUTES)
+                .writeTimeout(5, TimeUnit.MINUTES)
                 .build();
                 .build();
     }
     }
 
 

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

@@ -9,8 +9,8 @@ import java.util.List;
 @Repository
 @Repository
 public interface AccountCategoryRepository extends JpaRepository<AccountCategory, AccountCategory.PK> {
 public interface AccountCategoryRepository extends JpaRepository<AccountCategory, AccountCategory.PK> {
 
 
-    List<AccountCategory> getByGhIdAndStatus(String ghId, Integer status);
+    List<AccountCategory> getByGhIdAndStatusAndVersion(String ghId, Integer status, Integer version);
 
 
-    List<AccountCategory> getByStatus(Integer status);
+    List<AccountCategory> getByStatusAndVersion(Integer status, Integer version);
 
 
 }
 }

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

@@ -13,6 +13,8 @@ public interface ArticleCategoryRepository extends JpaRepository<ArticleCategory
 
 
     List<ArticleCategory> getByProduceContentIdInAndVersion(List<String> produceContentIds, Integer version);
     List<ArticleCategory> getByProduceContentIdInAndVersion(List<String> produceContentIds, Integer version);
 
 
+    ArticleCategory getByProduceContentIdAndVersion(String produceContentId, Integer version);
+
     List<ArticleCategory> getByStatusAndVersion(Integer status, Integer version);
     List<ArticleCategory> getByStatusAndVersion(Integer status, Integer version);
 
 
     Page<ArticleCategory> getByStatusAndVersion(Integer status, Integer version, PageRequest pageRequest);
     Page<ArticleCategory> getByStatusAndVersion(Integer status, Integer version, PageRequest pageRequest);

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

@@ -9,4 +9,6 @@ import java.util.List;
 @Repository
 @Repository
 public interface DatastatScoreRepository extends JpaRepository<DatastatScore, Long> {
 public interface DatastatScoreRepository extends JpaRepository<DatastatScore, Long> {
     void deleteByDtIn(List<String> dateStrList);
     void deleteByDtIn(List<String> dateStrList);
+
+    List<DatastatScore> getBySourceIdIsNotNull();
 }
 }

+ 12 - 9
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/ArticleCategoryService.java

@@ -66,7 +66,7 @@ public class ArticleCategoryService {
             "\"20241030070010871546586\"]}")
             "\"20241030070010871546586\"]}")
     private static List<String> producePlanIds;
     private static List<String> producePlanIds;
     @Value("${kimiCategoryPrompt:}")
     @Value("${kimiCategoryPrompt:}")
-    private String kimiCategoryPrompt;
+    private String categoryPrompt;
 
 
     @Value("${category.active.version:1}")
     @Value("${category.active.version:1}")
     private Integer activeVersion;
     private Integer activeVersion;
@@ -99,7 +99,7 @@ public class ArticleCategoryService {
         addPromotionArticleCategoryByProducePlan();
         addPromotionArticleCategoryByProducePlan();
         // 视频内容池 添加品类处理任务
         // 视频内容池 添加品类处理任务
         addVideoPoolArticleCategory();
         addVideoPoolArticleCategory();
-        // 调用kimi进行内容分类
+        // 调用大模型进行内容分类
         dealArticleCategory();
         dealArticleCategory();
     }
     }
 
 
@@ -108,7 +108,7 @@ public class ArticleCategoryService {
         List<List<ArticleCategory>> partitionList = Lists.partition(dealList, 20);
         List<List<ArticleCategory>> partitionList = Lists.partition(dealList, 20);
         for (List<ArticleCategory> partition : partitionList) {
         for (List<ArticleCategory> partition : partitionList) {
             List<String> partitionTitles = partition.stream().map(ArticleCategory::getTitle).distinct().collect(Collectors.toList());
             List<String> partitionTitles = partition.stream().map(ArticleCategory::getTitle).distinct().collect(Collectors.toList());
-            String prompt = buildKimiPrompt(partitionTitles);
+            String prompt = buildCategoryPrompt(partitionTitles);
             KimiResult kimiResult = deepSeekApiService.requestOfficialApi(prompt, null, null, true);
             KimiResult kimiResult = deepSeekApiService.requestOfficialApi(prompt, null, null, true);
             long now = System.currentTimeMillis();
             long now = System.currentTimeMillis();
             JSONObject obj = null;
             JSONObject obj = null;
@@ -120,7 +120,7 @@ public class ArticleCategoryService {
                 }
                 }
             }
             }
             for (ArticleCategory articleCategory : partition) {
             for (ArticleCategory articleCategory : partition) {
-                articleCategory.setKimiResult(kimiResult.getResponseStr());
+                articleCategory.setKimiResult(kimiResult.getResponseStr().trim());
                 articleCategory.setUpdateTimestamp(now);
                 articleCategory.setUpdateTimestamp(now);
                 if (kimiResult.isSuccess() && Objects.nonNull(obj) && obj.containsKey(articleCategory.getTitle())) {
                 if (kimiResult.isSuccess() && Objects.nonNull(obj) && obj.containsKey(articleCategory.getTitle())) {
                     articleCategory.setCategory(obj.getString(articleCategory.getTitle()));
                     articleCategory.setCategory(obj.getString(articleCategory.getTitle()));
@@ -164,6 +164,7 @@ public class ArticleCategoryService {
                 item.setTitle(vo.getTitle());
                 item.setTitle(vo.getTitle());
                 item.setTitleMd5(Md5Util.encoderByMd5(vo.getTitle()));
                 item.setTitleMd5(Md5Util.encoderByMd5(vo.getTitle()));
                 item.setCreateTimestamp(now);
                 item.setCreateTimestamp(now);
+                item.setVersion(activeVersion);
                 saveList.add(item);
                 saveList.add(item);
             }
             }
             if (CollectionUtils.isNotEmpty(saveList)) {
             if (CollectionUtils.isNotEmpty(saveList)) {
@@ -231,7 +232,7 @@ public class ArticleCategoryService {
                 }
                 }
                 if (Objects.nonNull(category) && StringUtils.hasText(category.getCategory())) {
                 if (Objects.nonNull(category) && StringUtils.hasText(category.getCategory())) {
                     articleCategory.setCategory(category.getCategory());
                     articleCategory.setCategory(category.getCategory());
-                    articleCategory.setKimiResult(category.getKimiResult());
+                    articleCategory.setKimiResult(category.getKimiResult().trim());
                     articleCategory.setStatus(ArticleCategoryStatusEnum.SUCCESS.getCode());
                     articleCategory.setStatus(ArticleCategoryStatusEnum.SUCCESS.getCode());
                 }
                 }
             }
             }
@@ -253,6 +254,7 @@ public class ArticleCategoryService {
             item.setTitle(videoSource.getArticleTitle());
             item.setTitle(videoSource.getArticleTitle());
             item.setTitleMd5(Md5Util.encoderByMd5(videoSource.getArticleTitle()));
             item.setTitleMd5(Md5Util.encoderByMd5(videoSource.getArticleTitle()));
             item.setCreateTimestamp(now);
             item.setCreateTimestamp(now);
+            item.setVersion(activeVersion);
             saveList.add(item);
             saveList.add(item);
         }
         }
         articleCategoryMapper.batchInsertArticleCategory(saveList);
         articleCategoryMapper.batchInsertArticleCategory(saveList);
@@ -291,14 +293,15 @@ public class ArticleCategoryService {
                 item.setTitle(title);
                 item.setTitle(title);
                 item.setTitleMd5(Md5Util.encoderByMd5(title));
                 item.setTitleMd5(Md5Util.encoderByMd5(title));
                 item.setCreateTimestamp(now);
                 item.setCreateTimestamp(now);
+                item.setVersion(activeVersion);
                 saveList.add(item);
                 saveList.add(item);
             }
             }
         }
         }
         return saveList;
         return saveList;
     }
     }
 
 
-    private String buildKimiPrompt(List<String> titleList) {
-        StringBuilder prompt = new StringBuilder(kimiCategoryPrompt);
+    private String buildCategoryPrompt(List<String> titleList) {
+        StringBuilder prompt = new StringBuilder(categoryPrompt);
         prompt.append("\n");
         prompt.append("\n");
         for (String title : titleList) {
         for (String title : titleList) {
             prompt.append(title).append("\n");
             prompt.append(title).append("\n");
@@ -310,7 +313,7 @@ public class ArticleCategoryService {
         List<ArticleCategory> dealList = articleCategoryRepository.getByStatusAndRetryTimesLessThanAndVersion(ArticleCategoryStatusEnum.FAIL.getCode(), 3, activeVersion);
         List<ArticleCategory> dealList = articleCategoryRepository.getByStatusAndRetryTimesLessThanAndVersion(ArticleCategoryStatusEnum.FAIL.getCode(), 3, activeVersion);
         for (ArticleCategory articleCategory : dealList) {
         for (ArticleCategory articleCategory : dealList) {
             List<String> partitionTitles = Collections.singletonList(articleCategory.getTitle());
             List<String> partitionTitles = Collections.singletonList(articleCategory.getTitle());
-            String prompt = buildKimiPrompt(partitionTitles);
+            String prompt = buildCategoryPrompt(partitionTitles);
             KimiResult kimiResult = deepSeekApiService.requestOfficialApi(prompt, null, null, true);
             KimiResult kimiResult = deepSeekApiService.requestOfficialApi(prompt, null, null, true);
             long now = System.currentTimeMillis();
             long now = System.currentTimeMillis();
             JSONObject obj = null;
             JSONObject obj = null;
@@ -321,7 +324,7 @@ public class ArticleCategoryService {
                     log.error(kimiResult.getResponse().getChoices().get(0).getMessage().getContent());
                     log.error(kimiResult.getResponse().getChoices().get(0).getMessage().getContent());
                 }
                 }
             }
             }
-            articleCategory.setKimiResult(kimiResult.getResponseStr());
+            articleCategory.setKimiResult(kimiResult.getResponseStr().trim());
             articleCategory.setUpdateTimestamp(now);
             articleCategory.setUpdateTimestamp(now);
             articleCategory.setRetryTimes(articleCategory.getRetryTimes() + 1);
             articleCategory.setRetryTimes(articleCategory.getRetryTimes() + 1);
             if (kimiResult.isSuccess() && Objects.nonNull(obj)) {
             if (kimiResult.isSuccess() && Objects.nonNull(obj)) {

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

@@ -486,7 +486,7 @@ public class RecallService implements ApplicationContextAware {
                 .filter(o -> "1".equals(o.getPosition()))
                 .filter(o -> "1".equals(o.getPosition()))
                 .filter(o -> Objects.nonNull(o.getReadAvg()) && o.getReadAvg() > 0 && o.getFans() > 1000)
                 .filter(o -> Objects.nonNull(o.getReadAvg()) && o.getReadAvg() > 0 && o.getFans() > 1000)
                 .collect(Collectors.groupingBy(AccountAvgInfo::getGhId, Collectors.toMap(AccountAvgInfo::getUpdateTime, o -> o)));
                 .collect(Collectors.groupingBy(AccountAvgInfo::getGhId, Collectors.toMap(AccountAvgInfo::getUpdateTime, o -> o)));
-        List<AccountCategory> accountCategoryList = accountCategoryRepository.getByStatus(StatusEnum.ONE.getCode());
+        List<AccountCategory> accountCategoryList = accountCategoryRepository.getByStatusAndVersion(StatusEnum.ONE.getCode(), activeVersion);
         Map<String, JSONObject> accountCategoryMap = accountCategoryList.stream().filter(o -> StringUtils.hasText(o.getCategoryMap()))
         Map<String, JSONObject> accountCategoryMap = accountCategoryList.stream().filter(o -> StringUtils.hasText(o.getCategoryMap()))
                 .collect(Collectors.toMap(AccountCategory::getGhId, o -> JSONObject.parseObject(o.getCategoryMap())));
                 .collect(Collectors.toMap(AccountCategory::getGhId, o -> JSONObject.parseObject(o.getCategoryMap())));
 
 

+ 6 - 1
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/score/strategy/CategoryStrategy.java

@@ -14,6 +14,7 @@ import com.tzld.longarticle.recommend.server.service.recommend.score.ScoreParam;
 import com.tzld.longarticle.recommend.server.service.recommend.score.ScoreStrategy;
 import com.tzld.longarticle.recommend.server.service.recommend.score.ScoreStrategy;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
 import org.springframework.stereotype.Component;
 import org.springframework.util.CollectionUtils;
 import org.springframework.util.CollectionUtils;
 import org.springframework.util.StringUtils;
 import org.springframework.util.StringUtils;
@@ -34,6 +35,9 @@ public class CategoryStrategy implements ScoreStrategy {
     @ApolloJsonValue("${accountCategoryWeightConfig:{}}")
     @ApolloJsonValue("${accountCategoryWeightConfig:{}}")
     private Map<String, AccountCategoryWeightConfig[]> accountCategoryWeightConfigMap;
     private Map<String, AccountCategoryWeightConfig[]> accountCategoryWeightConfigMap;
 
 
+    @Value("${category.active.version:1}")
+    private Integer activeVersion;
+
 
 
     @Override
     @Override
     public List<Score> score(ScoreParam param) {
     public List<Score> score(ScoreParam param) {
@@ -42,7 +46,8 @@ public class CategoryStrategy implements ScoreStrategy {
         if (CollectionUtils.isEmpty(param.getContents())) {
         if (CollectionUtils.isEmpty(param.getContents())) {
             return scores;
             return scores;
         }
         }
-        List<AccountCategory> accountCategoryList = accountCategoryRepository.getByGhIdAndStatus(param.getGhId(), StatusEnum.ONE.getCode());
+        List<AccountCategory> accountCategoryList = accountCategoryRepository.getByGhIdAndStatusAndVersion(
+                param.getGhId(), StatusEnum.ONE.getCode(), activeVersion);
         if (CollectionUtils.isEmpty(accountCategoryList)) {
         if (CollectionUtils.isEmpty(accountCategoryList)) {
             return scores;
             return scores;
         }
         }

+ 2 - 2
long-article-recommend-service/src/main/resources/mapper/longArticle/ArticleCategoryMapper.xml

@@ -5,11 +5,11 @@
     <insert id="batchInsertArticleCategory">
     <insert id="batchInsertArticleCategory">
         INSERT INTO article_category
         INSERT INTO article_category
         (produce_content_id, channel_content_id, crawler_plan_id, title, title_md5, category,
         (produce_content_id, channel_content_id, crawler_plan_id, title, title_md5, category,
-        kimi_result, status, create_timestamp)
+        kimi_result, status, create_timestamp, version)
         VALUES
         VALUES
         <foreach collection="list" item="item" separator=",">
         <foreach collection="list" item="item" separator=",">
             (#{item.produceContentId}, #{item.channelContentId}, #{item.crawlerPlanId}, #{item.title}, #{item.titleMd5},
             (#{item.produceContentId}, #{item.channelContentId}, #{item.crawlerPlanId}, #{item.title}, #{item.titleMd5},
-            #{item.category}, #{item.kimiResult}, #{item.status}, #{item.createTimestamp})
+            #{item.category}, #{item.kimiResult}, #{item.status}, #{item.createTimestamp}, #{item.version})
         </foreach>
         </foreach>
     </insert>
     </insert>
 
 

+ 22 - 0
long-article-recommend-service/src/test/java/com/tzld/longarticle/recommend/server/DataDashboardTest.java

@@ -1,8 +1,12 @@
 package com.tzld.longarticle.recommend.server;
 package com.tzld.longarticle.recommend.server;
 
 
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONObject;
+import com.tzld.longarticle.recommend.server.model.entity.longArticle.ArticleCategory;
+import com.tzld.longarticle.recommend.server.model.entity.longArticle.DatastatScore;
 import com.tzld.longarticle.recommend.server.model.vo.IntermediateIndicatorsExport;
 import com.tzld.longarticle.recommend.server.model.vo.IntermediateIndicatorsExport;
 import com.tzld.longarticle.recommend.server.model.vo.NewSortStrategyExport;
 import com.tzld.longarticle.recommend.server.model.vo.NewSortStrategyExport;
+import com.tzld.longarticle.recommend.server.repository.longArticle.ArticleCategoryRepository;
+import com.tzld.longarticle.recommend.server.repository.longArticle.DatastatScoreRepository;
 import com.tzld.longarticle.recommend.server.service.recommend.DataDashboardService;
 import com.tzld.longarticle.recommend.server.service.recommend.DataDashboardService;
 import com.tzld.longarticle.recommend.server.util.DateUtils;
 import com.tzld.longarticle.recommend.server.util.DateUtils;
 import com.tzld.longarticle.recommend.server.util.feishu.FeiShu;
 import com.tzld.longarticle.recommend.server.util.feishu.FeiShu;
@@ -14,6 +18,7 @@ import org.springframework.http.HttpHeaders;
 
 
 import javax.annotation.Resource;
 import javax.annotation.Resource;
 import java.util.List;
 import java.util.List;
+import java.util.Objects;
 
 
 @SpringBootTest(classes = Application.class)
 @SpringBootTest(classes = Application.class)
 @Slf4j
 @Slf4j
@@ -21,6 +26,10 @@ public class DataDashboardTest {
 
 
     @Resource
     @Resource
     DataDashboardService dataDashboardService;
     DataDashboardService dataDashboardService;
+    @Resource
+    DatastatScoreRepository datastatScoreRepository;
+    @Resource
+    ArticleCategoryRepository articleCategoryRepository;
 
 
     @Test
     @Test
     public void test() {
     public void test() {
@@ -63,4 +72,17 @@ public class DataDashboardTest {
         dataDashboardService.contentGroupFunnelExport(dateStrList);
         dataDashboardService.contentGroupFunnelExport(dateStrList);
     }
     }
 
 
+    @Test
+    public void datastatScore() {
+        List<DatastatScore> scoreList = datastatScoreRepository.getBySourceIdIsNotNull();
+        for (DatastatScore score : scoreList) {
+            ArticleCategory category = articleCategoryRepository.getByProduceContentIdAndVersion(score.getSourceId(), 2);
+            if (Objects.isNull(category)) {
+                continue;
+            }
+            score.setCategory(category.getCategory());
+            datastatScoreRepository.save(score);
+        }
+    }
+
 }
 }