Переглянути джерело

增加用户展示页面-根据模块id获取新闻列表,增加分页

xusonglin 5 роки тому
батько
коміт
e5bc4f32d1

+ 1 - 1
src/main/java/com/jkcredit/sysnews/mapper/NewsArticleMapper.java

@@ -20,5 +20,5 @@ public interface NewsArticleMapper extends BaseMapper<NewsArticlePo> {
 
     NewsArticlePo getNewsArticleById(Long id);
 
-    List<NewsArticlePo> getNewsArticleByNavigationBarId(Long id);
+    IPage<NewsArticlePo> getNewsArticleByNavigationBarId(Page page, Long id);
 }

+ 4 - 2
src/main/java/com/jkcredit/sysnews/resource/biz/newsArticle/NewsArticleBizResource.java

@@ -1,5 +1,7 @@
 package com.jkcredit.sysnews.resource.biz.newsArticle;
 
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.jkcredit.sysnews.model.vo.newsArticle.NewsArticleBizVo;
 import com.jkcredit.sysnews.model.vo.newsArticle.NewsArticleVo;
 import com.jkcredit.sysnews.resource.base.BizResource;
@@ -29,9 +31,9 @@ public class NewsArticleBizResource extends BizResource {
 
     @GetMapping("/newsArticles/{id}")
     @ApiOperation("用户展示页面-根据模块id获取新闻")
-    public ResponseData getNewsArticlesByNavigationBarId(@PathVariable Long id) {
+    public ResponseData getNewsArticlesByNavigationBarId(Page page, @PathVariable Long id) {
         try {
-            List<NewsArticleBizVo> newsArticleVoList = newsArticleService.getNewsArticleByNavigationBarId(id);
+            IPage<NewsArticleBizVo> newsArticleVoList = newsArticleService.getNewsArticleByNavigationBarId(page, id);
             return ResponseData.success(newsArticleVoList);
         } catch (ServiceException e) {
             log.error(e.getMessage());

+ 1 - 1
src/main/java/com/jkcredit/sysnews/service/newsArticle/NewsArticleService.java

@@ -25,5 +25,5 @@ public interface NewsArticleService {
 
     void deleteNewsArticle(Long id);
 
-    List<NewsArticleBizVo> getNewsArticleByNavigationBarId(Long id);
+    IPage<NewsArticleBizVo> getNewsArticleByNavigationBarId(Page page, Long id);
 }

+ 12 - 13
src/main/java/com/jkcredit/sysnews/service/newsArticle/NewsArticleServiceImpl.java

@@ -344,25 +344,24 @@ public class NewsArticleServiceImpl extends BaseService implements NewsArticleSe
     }
 
     @Override
-    public List<NewsArticleBizVo> getNewsArticleByNavigationBarId(Long id) {
+    public IPage<NewsArticleBizVo> getNewsArticleByNavigationBarId(Page page, Long id) {
         AssertUtils.assertNotNull(id, "id不能为空");
         try {
-            List<NewsArticlePo> newsArticlePoList = mapper.getNewsArticleByNavigationBarId(id);
-            List<NewsArticleBizVo> newsArticleVoList = new ArrayList<>();
-            for (NewsArticlePo po : newsArticlePoList) {
-                NewsArticleBizVo newsArticleVo = new NewsArticleBizVo();
-                BeanUtil.copyProperties(newsArticleVo, po);
-                if (po.getPhotoUrl() != null) {
-                    String url = accessPath + accessResource + po.getPhotoUrl().replace("/","");
-                    newsArticleVo.setPhotoUrl(url);
-                }
-                newsArticleVoList.add(newsArticleVo);
-            }
-            return newsArticleVoList;
+            IPage<NewsArticlePo> newsArticlePoList = mapper.getNewsArticleByNavigationBarId(page, id);
+            return newsArticlePoList.convert(this::convertNewsArticleBizVo);
         } catch (Exception e) {
             log.error("获取新闻数据失败,失败原因:{}", e.getMessage());
             throw new ServiceException("获取新闻数据失败");
         }
 
     }
+    private NewsArticleBizVo convertNewsArticleBizVo(NewsArticlePo po) {
+        NewsArticleBizVo vo = new NewsArticleBizVo();
+        BeanUtils.copyProperties(po, vo);
+        if (po.getPhotoUrl() != null) {
+            String url = accessPath + accessResource + po.getPhotoUrl().replace("/","");
+            vo.setPhotoUrl(url);
+        }
+        return vo;
+    }
 }