wangyunpeng 1 месяц назад
Родитель
Сommit
c6879e5429

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

@@ -42,4 +42,6 @@ public interface ArticleRepository extends JpaRepository<Article, String> {
     List<Article> getByTitleMd5(String titleMd5);
 
     List<Article> getByPublishTimestampGreaterThan(Long publishTimestamp);
+
+    List<Article> getByRootSourceIdListLike(String rootSourceId);
 }

+ 5 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/ArticleService.java

@@ -370,4 +370,9 @@ public class ArticleService {
         }
         return null;
     }
+
+    public Article getArticleByRootSourceId(String rootSourceId) {
+        List<Article> articles = articleRepository.getByRootSourceIdListLike("%" + rootSourceId + "%");
+        return CollectionUtils.isEmpty(articles) ? null : articles.get(0);
+    }
 }

+ 7 - 4
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/web/recommend/ArticleController.java

@@ -1,14 +1,12 @@
 package com.tzld.longarticle.recommend.server.web.recommend;
 
 import com.tzld.longarticle.recommend.server.common.response.CommonResponse;
+import com.tzld.longarticle.recommend.server.model.entity.crawler.Article;
 import com.tzld.longarticle.recommend.server.model.param.ArticleFindSourceParam;
 import com.tzld.longarticle.recommend.server.service.recommend.ArticleService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 @RestController
 @RequestMapping("/article")
@@ -24,4 +22,9 @@ public class ArticleController {
         return CommonResponse.success();
     }
 
+    @GetMapping("/getArticleByRootSourceId")
+    public CommonResponse<Article> getArticleByRootSourceId(@RequestParam String rootSourceId) {
+        return CommonResponse.success(service.getArticleByRootSourceId(rootSourceId));
+    }
+
 }