chao 4 rokov pred
rodič
commit
b6e42b2c17

+ 9 - 0
src/main/java/com/caimei/www/controller/unlimited/ArticleController.java

@@ -154,4 +154,13 @@ public class ArticleController extends BaseController {
         return articleService.articleLike(id, serverWebExchange);
     }
 
+    /**
+     * 文章浏览量增加
+     */
+    @GetMapping("/article/pv")
+    @ResponseBody
+    public JsonModel articlePv(Integer id) {
+        return articleService.articlePv(id);
+    }
+
 }

+ 6 - 0
src/main/java/com/caimei/www/mapper/ArticleDao.java

@@ -91,4 +91,10 @@ public interface ArticleDao {
      * @return
      */
     List<Integer> findLabelIdsByName(@Param("labelTexts") String[] labelTexts);
+
+    /**
+     * 文章浏览量增加
+     * @param infoId
+     */
+    void articlePv(Integer infoId);
 }

+ 7 - 0
src/main/java/com/caimei/www/service/page/ArticleService.java

@@ -65,4 +65,11 @@ public interface ArticleService {
      * @return
      */
     JsonModel articleLike(Integer id, ServerWebExchange serverWebExchange);
+
+    /**
+     * 文章浏览量增加
+     * @param id
+     * @return
+     */
+    JsonModel articlePv(Integer id);
 }

+ 12 - 0
src/main/java/com/caimei/www/service/page/impl/ArticleServiceImpl.java

@@ -164,6 +164,18 @@ public class ArticleServiceImpl implements ArticleService {
         }
     }
 
+    /**
+     * 文章浏览量增加
+     *
+     * @param id
+     * @return
+     */
+    @Override
+    public JsonModel articlePv(Integer id) {
+        articleDao.articlePv(id);
+        return JsonModel.success();
+    }
+
     private String getIp(ServerWebExchange serverWebExchange){
        ServerHttpRequest request = serverWebExchange.getRequest();
         return Objects.requireNonNull(request.getRemoteAddress()).getAddress().toString();

+ 6 - 2
src/main/resources/mapper/ArticleMapper.xml

@@ -89,8 +89,13 @@
 		SET num = num+1
 		WHERE infoId = #{infoId}
 	</update>
+	<update id="articlePv">
+		UPDATE info_praise
+		SET pv = pv+1
+		WHERE infoId = #{infoId}
+	</update>
 
-    <select id="getArticleInfo" resultType="com.caimei.www.pojo.page.Article">
+	<select id="getArticleInfo" resultType="com.caimei.www.pojo.page.Article">
 		SELECT
 		  a.id AS id,
 		  a.title AS title,
@@ -130,5 +135,4 @@
 		order by clickRate desc
 	</select>
 
-
 </mapper>

+ 9 - 0
src/main/resources/static/js/article/detail.js

@@ -55,5 +55,14 @@ var articleRelated = new Vue({
             "color": "#3a3",
             "text": thisUri
         });
+        // 文章浏览量+1
+        $.get("/article/pv", {id: this.infoId}, function(res){
+            if(res.code === 0){
+                // 更新文章索引
+                $.post(spiServer + "/search/manage/update/article", {aid: _self.infoId}, function(res){
+                    console.log(res.msg);
+                });
+            }
+        });
     }
 });