Browse Source

内容管理

chenhongzhou1 4 years ago
parent
commit
1226b9f95c

+ 1 - 4
mpwechatApp/src/main/java/com/liangjian11/wx/mp/controller/content/ArticleController.java

@@ -54,10 +54,7 @@ public class ArticleController {
             filterString = filtersData.getFilterString();
         }
         List<Article> articleList = articleService.listArticlePage(filterString, pageIndex, pageSize);
-        int count = 0;
-        if (articleList!=null) {
-            count = articleList.size();
-        }
+        int count = articleService.countArticle(filterString);
         return ResultUtil.createSuccess(200, "查询文章成功", articleList, count);
     }
 

+ 2 - 0
mpwechatApp/src/main/java/com/liangjian11/wx/mp/mapperUE/ArticleMapper.java

@@ -24,6 +24,8 @@ public interface ArticleMapper extends BaseMapper<Article> {
 
     List<Article> selectArticlePage(@Param("filterSql")String filterSql, @Param("start") int start, @Param("pageSize") int pageSize);
 
+    Integer selectCountArticle(@Param("filterSql")String filterSql);
+
     Integer insertArticle(Article article);
 
     Integer updateArticle(Article article);

+ 2 - 0
mpwechatApp/src/main/java/com/liangjian11/wx/mp/service/content/ArticleService.java

@@ -20,6 +20,8 @@ public interface ArticleService extends IService<Article> {
 
     List<Article> listArticlePage(String filterSql, int start, int pageSize);
 
+    Integer countArticle(String filterSql);
+
     Integer saveArticle(Article article) throws RuntimeException;
 
     Integer updateArticle(Article article) throws RuntimeException;

+ 23 - 2
mpwechatApp/src/main/java/com/liangjian11/wx/mp/service/content/impl/ArticleServiceImpl.java

@@ -36,9 +36,22 @@ public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article> impl
 
 
     @Override
-    @Transactional(readOnly = true)
+    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = RuntimeException.class)
     public Article getByArticleId(Integer articleId) {
-        return articleMapper.selectArticleByArticleId(articleId);
+        Article article = articleMapper.selectArticleByArticleId(articleId);
+        if(article!=null ){
+            Article newArticle = new Article();
+            newArticle.setArticleId(article.getArticleId());
+            if(article.getArticleRealpageviews() !=null){
+                newArticle.setArticleRealpageviews(article.getArticleRealpageviews()+1);
+            }else{
+                newArticle.setArticleRealpageviews(1);
+            }
+            if(articleMapper.updateById(newArticle)==0){
+                throw new RuntimeException("更新文章真实阅读量发生错误");
+            }
+        }
+        return article;
     }
 
     @Override
@@ -47,6 +60,14 @@ public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article> impl
         return articleMapper.selectArticlePage(filterSql, start, pageSize);
     }
 
+    @Override
+    @Transactional(readOnly = true)
+    public Integer countArticle(String filterSql) {
+        return articleMapper.selectCountArticle(filterSql);
+    }
+
+
+
     @Override
     @Transactional(propagation = Propagation.REQUIRED, rollbackFor = RuntimeException.class)
     public Integer saveArticle(Article article) throws RuntimeException {

+ 1 - 1
mpwechatApp/src/main/resources/application-pgdev.properties

@@ -5,7 +5,7 @@ project.weburl = http://192.168.50.32:13001/mpwechat
 material.Locations = D:\\public\\material
 material.href= /public/material
 #\u670D\u52A1\u540D
-spring.application.name = mpwechatT1
+spring.application.name = mpwechatContentTest
 
 #spring cloud eureka
 eureka.client.service-url.defaultZone = http://liangjian:360lj.comOauth2passwd@192.168.50.32:11002/eureka/

+ 9 - 4
mpwechatApp/src/main/resources/mapperUE/ArticleMapper.xml

@@ -48,15 +48,20 @@
         where article_id = #{articleId}
     </select>
 
-
     <select id="selectArticlePage" resultType="com.liangjian11.wx.mp.modle.content.Article">
-        select * from (select a.article_id, article_column_id,article_title ,article_author_id,article_createt_date,
-        article_realpageviews, article_status,article_typographic_type,
-        array_to_string(ARRAY[array_agg(ad.department_id)], ',') from content_article_department ad where ad.article_id = a.article_id) as department_id
+         select * from
+        (select a.article_id, article_column_id,article_classification_id,article_title ,
+        article_author_id,article_createt_date, article_realpageviews, article_status,article_typographic_type,
+        ( select  array_to_string(ARRAY[array_agg(ad.department_id)], ',')  from content_article_department ad where ad.article_id = a.article_id) as department_id
         from content_article a) src
         ${filterSql}  ORDER BY src.article_createt_date DESC LIMIT #{pageSize} offset #{start}
     </select>
 
+    <select id="selectCountArticle" >
+        select count(*) from content_article
+        ${filterSql}
+    </select>
+
     <insert id="insertArticle" useGeneratedKeys="true" keyProperty="articleId">
         insert into content_article(article_classification_id,article_column_id,article_title,article_status,
         article_author_id,article_summary,article_createt_date,article_link_address, article_photoaddress,