瀏覽代碼

Merge branch 'wyp/1204-accountCategory' of Server/long-article-recommend into master

wangyunpeng 7 月之前
父節點
當前提交
c7a2609bf3

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

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

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

@@ -59,9 +59,12 @@ public class ScoreService implements ApplicationContextAware {
                 try {
                     List<Score> result = strategy.score(param);
                     return result;
+                } catch (Exception e) {
+                    log.error("scoreService error:{}", e.getMessage(), e);
                 } finally {
                     cdl.countDown();
                 }
+                return new ArrayList<>();
             });
             futures.add(future);
         }

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

@@ -42,8 +42,14 @@ public class CategoryStrategy implements ScoreStrategy {
         if (CollectionUtils.isEmpty(param.getContents())) {
             return scores;
         }
-        AccountCategory accountCategory = accountCategoryRepository.getByGhIdAndStatus(param.getGhId(), StatusEnum.ONE.getCode());
-        if (Objects.isNull(accountCategory) || !StringUtils.hasText(accountCategory.getCategoryMap())) {
+        List<AccountCategory> accountCategoryList = accountCategoryRepository.getByGhIdAndStatus(param.getGhId(), StatusEnum.ONE.getCode());
+        if (CollectionUtils.isEmpty(accountCategoryList)) {
+            return scores;
+        }
+        AccountCategory accountCategory = accountCategoryList.stream()
+                .sorted(Comparator.comparing(AccountCategory::getDt, Comparator.reverseOrder()))
+                .findFirst().get();
+        if (!StringUtils.hasText(accountCategory.getCategoryMap())) {
             return scores;
         }
         JSONObject categoryWeightMap = JSONObject.parseObject(accountCategory.getCategoryMap());