Browse Source

增加用户展示页面-获取全部友情链接接口,用户展示页面-根据菜单id获取新闻接口

xusonglin 5 năm trước cách đây
mục cha
commit
aa46beda81

+ 3 - 0
src/main/java/com/jkcredit/sysnews/mapper/LinksMapper.java

@@ -7,6 +7,8 @@ import com.jkcredit.sysnews.model.dto.links.LinksDto;
 import com.jkcredit.sysnews.model.po.links.LinksPo;
 import org.apache.ibatis.annotations.Param;
 
+import java.util.List;
+
 /**
  * @description:
  * @author: xusonglin
@@ -16,4 +18,5 @@ import org.apache.ibatis.annotations.Param;
 public interface LinksMapper extends BaseMapper<LinksPo> {
     IPage<LinksPo> getLinksPage(Page page, @Param("query")LinksDto linksDto);
     LinksPo getLinkById(Long id);
+    List<LinksPo> getLinksWithoutPage();
 }

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

@@ -7,6 +7,8 @@ import com.jkcredit.sysnews.model.dto.newsArticle.NewsArticleDto;
 import com.jkcredit.sysnews.model.po.newsArticle.NewsArticlePo;
 import org.apache.ibatis.annotations.Param;
 
+import java.util.List;
+
 /**
  * @description:
  * @author: xusonglin
@@ -17,4 +19,6 @@ public interface NewsArticleMapper extends BaseMapper<NewsArticlePo> {
     IPage<NewsArticlePo> getNewsArticles(Page page, @Param("query")NewsArticleDto newsArticleDto);
 
     NewsArticlePo getNewsArticleById(Long id);
+
+    List<NewsArticlePo> getNewsArticleByNavigationBarId(Long id);
 }

+ 39 - 0
src/main/java/com/jkcredit/sysnews/resource/biz/links/LinksBizResource.java

@@ -0,0 +1,39 @@
+package com.jkcredit.sysnews.resource.biz.links;
+
+import com.jkcredit.sysnews.model.vo.links.LinksVo;
+import com.jkcredit.sysnews.resource.base.BizResource;
+import com.jkcredit.sysnews.service.links.LinksService;
+import com.jkcredit.sysnews.spi.lang.exception.ServiceException;
+import com.jkcredit.sysnews.spi.web.data.ResponseData;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/3/16 15:26
+ * @version: V1.0
+ **/
+@Slf4j
+@RestController
+public class LinksBizResource extends BizResource {
+    @Autowired
+    LinksService linksService;
+
+    @GetMapping("/links")
+    @ApiOperation("用户展示页面-获取全部友情链接")
+    public ResponseData getLinks() {
+        try {
+            List<LinksVo> linksVoList = linksService.getLinksWithoutPage();
+            return ResponseData.success(linksVoList);
+        } catch (ServiceException e) {
+            log.error(e.getMessage());
+            return ResponseData.failed("获取友情链接失败");
+        }
+    }
+}

+ 40 - 0
src/main/java/com/jkcredit/sysnews/resource/biz/newsArticle/NewsArticleBizResource.java

@@ -0,0 +1,40 @@
+package com.jkcredit.sysnews.resource.biz.newsArticle;
+
+import com.jkcredit.sysnews.model.vo.newsArticle.NewsArticleVo;
+import com.jkcredit.sysnews.resource.base.BizResource;
+import com.jkcredit.sysnews.service.newsArticle.NewsArticleService;
+import com.jkcredit.sysnews.spi.lang.exception.ServiceException;
+import com.jkcredit.sysnews.spi.web.data.ResponseData;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/3/16 15:20
+ * @version: V1.0
+ **/
+@Slf4j
+@RestController
+public class NewsArticleBizResource extends BizResource {
+    @Autowired
+    NewsArticleService newsArticleService;
+
+    @GetMapping("/newsArticles/{id}")
+    @ApiOperation("用户展示页面-根据模块id获取新闻")
+    public ResponseData getNewsArticlesByNavigationBarId(@PathVariable Long id) {
+        try {
+            List<NewsArticleVo> newsArticleVoList = newsArticleService.getNewsArticleByNavigationBarId(id);
+            return ResponseData.success(newsArticleVoList);
+        } catch (ServiceException e) {
+            log.error(e.getMessage());
+            return ResponseData.failed("获取新闻失败");
+        }
+    }
+}

+ 4 - 0
src/main/java/com/jkcredit/sysnews/service/links/LinksService.java

@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.jkcredit.sysnews.model.dto.links.LinksDto;
 import com.jkcredit.sysnews.model.vo.links.LinksVo;
 
+import java.util.List;
+
 /**
  * @description:
  * @author: xusonglin
@@ -21,4 +23,6 @@ public interface LinksService {
     IPage<LinksVo> getLinksPage(Page page, LinksDto linksDto);
 
     LinksVo getLinkById(Long id);
+
+    List<LinksVo> getLinksWithoutPage();
 }

+ 23 - 0
src/main/java/com/jkcredit/sysnews/service/links/LinksServiceImpl.java

@@ -26,7 +26,9 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
+import java.util.ArrayList;
 import java.util.Date;
+import java.util.List;
 
 /**
  * @description:
@@ -151,4 +153,25 @@ public class LinksServiceImpl extends BaseService implements LinksService {
         }
         return linksVo;
     }
+
+    @Override
+    public List<LinksVo> getLinksWithoutPage() {
+        try {
+            List<LinksPo> linksPoList = linksMapper.getLinksWithoutPage();
+            List<LinksVo> linksVoList = new ArrayList<>();
+            for (LinksPo po : linksPoList) {
+                LinksVo linksVo = new LinksVo();
+                BeanUtil.copyProperties(linksVo, po);
+                if (po.getPhotoUrl() != null) {
+                    String url = accessPath + accessResource + po.getPhotoUrl().replace("/","");
+                    linksVo.setPhotoUrl(url);
+                }
+                linksVoList.add(linksVo);
+            }
+            return linksVoList;
+        } catch (Exception e) {
+            log.error("获取友情链接失败,失败原因:{}", e.getMessage());
+            throw new ServiceException("获取友情链接失败");
+        }
+    }
 }

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

@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.jkcredit.sysnews.model.dto.newsArticle.NewsArticleDto;
 import com.jkcredit.sysnews.model.vo.newsArticle.NewsArticleVo;
 
+import java.util.List;
+
 /**
  * @description:
  * @author: xusonglin
@@ -21,4 +23,6 @@ public interface NewsArticleService {
     void editNewsArticle(NewsArticleDto newsArticleDto);
 
     void deleteNewsArticle(Long id);
+
+    List<NewsArticleVo> getNewsArticleByNavigationBarId(Long id);
 }

+ 23 - 0
src/main/java/com/jkcredit/sysnews/service/newsArticle/NewsArticleServiceImpl.java

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

+ 14 - 0
src/main/resources/mapper/LinsMapper.xml

@@ -53,4 +53,18 @@
             links.activated = 1
             and links.id = #{id}
     </select>
+
+    <select id="getLinksWithoutPage" resultMap="baseResultMap">
+        select
+            links.*,
+            photo.url as photoUrl
+        from
+            links
+        left join
+            photo
+        on
+            links.photo_id = photo.id
+        where
+            links.activated = 1
+    </select>
 </mapper>

+ 10 - 0
src/main/resources/mapper/NewsArticleMapper.xml

@@ -46,4 +46,14 @@
         left join photo on newsArticle.photo_id = photo.id
         where newsArticle.id = #{id}
     </select>
+
+    <select id="getNewsArticleByNavigationBarId" resultMap="baseResultMap">
+        select
+        newsArticle.*, photo.url as photoUrl
+        from
+        news_article as newsArticle
+        left join photo on newsArticle.photo_id = photo.id
+        left join news_article_navigation_bar as newsArticleNavigationBar on newsArticle.id = newsArticleNavigationBar.news_article_id
+        where newsArticle.activated = 1 and newsArticleNavigationBar.activated = 1 and newsArticleNavigationBar.navigation_bar_id = #{id}
+    </select>
 </mapper>