夏文涛 2 年之前
父節點
當前提交
e497731f40

+ 27 - 1
mhotel/src/com/happy/action/articleTweetAction.java

@@ -348,7 +348,7 @@ public class articleTweetAction extends BaseController implements ModelDriven<Ar
             result.setIsLike(0);
         }
 
-        result.setLikes(likes == null ? new ArrayList<>() : likes.stream().map(LikeListVo::getImage).collect(Collectors.toList()));
+        result.setLikes(likes == null ? new ArrayList<>() : likes.stream().map(LikeListVo::getImage).limit(10).collect(Collectors.toList()));
         result.setLikeNum(likes == null ? 0 : likes.size());
 
         List<ArticleCommentVo> comments = articleTweetService.queryArticleComment(articleTweetDto.getId());
@@ -366,6 +366,32 @@ public class articleTweetAction extends BaseController implements ModelDriven<Ar
         return null;
     }
 
+    /**
+     * 点赞集合列表
+     * @return
+     */
+    public String queryLikes(){
+
+        JSONObject jsonObject = new JSONObject();
+
+        if (articleTweetDto.getId() == null) {
+            jsonObject.put("code", 500);
+            jsonObject.put("message", "推文ID不能为空");
+            jsonObject.put("data", null);
+            ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
+            return null;
+        }
+
+        IPage<LikeListVo> result = articleTweetService.queryLikesPage(articleTweetDto.getId(), page, rows);
+
+        jsonObject.put("code", ResultStatusCode.OK.getStatus());
+        jsonObject.put("message", "请求成功");
+        jsonObject.put("data", result);
+        ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
+
+        return null;
+    }
+
 
     /**
      * 获取推文详情中民宿分页列表

+ 10 - 0
mhotel/src/com/happy/dao/ArticleTweetDao.java

@@ -255,4 +255,14 @@ public interface ArticleTweetDao {
      * @return
      */
     int updateDescript(Integer authorId, String descript);
+
+    /**
+     * 点赞分页列表数据
+     */
+    List<LikeListVo> queryLikesPage(Integer articleId, int page, int rows);
+
+    /**
+     * 点赞总数据条数
+     */
+    int queryLikesTotal(Integer articleId);
 }

+ 36 - 1
mhotel/src/com/happy/dao/impl/ArticleTweetImplDao.java

@@ -226,10 +226,44 @@ public class ArticleTweetImplDao implements ArticleTweetDao {
 
 
     @Override
+    public List<LikeListVo> queryLikesPage(Integer articleId, int page, int rows) {
+        int start = (page - 1) * rows;// 每页的起始下标
+        String sql = "select (select IFNULL(count(*),0) from article_tweet where user_id = al.like_id) as article_number,(select IFNULL(count(*),0) from user_collect where is_lose = 0 and parent_userid = al.like_id) as fans_number,al.like_id as id,al.like_image as image,al.like_name as name " +
+                "from article_likes al\n" +
+                "where al.is_lose = 0 and al.article_id = :articleId order by al.create_date desc limit :start,:rows";
+        MapSqlParameterSource sps = new MapSqlParameterSource();
+        sps.addValue("start", start);
+        sps.addValue("rows", rows);
+        sps.addValue("articleId", articleId);
+        List<LikeListVo> list = null;
+        try {
+            list = namedParameterJdbcTemplate.query(sql, sps, new BeanPropertyRowMapper<>(LikeListVo.class));
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        if (list != null && list.size() > 0) {
+            return list;
+        }
+        return null;
+    }
+
+
+    @Override
+    public int queryLikesTotal(Integer articleId) {
+        String sql ="select count(*) from article_likes " +
+                "where is_lose = 0 and article_id = :articleId order by create_date desc";
+        MapSqlParameterSource sps = new MapSqlParameterSource();
+        sps.addValue("articleId", articleId);
+
+        return namedParameterJdbcTemplate.queryForInt(sql, sps);
+    }
+
+
+    @Override
     public List<LikeListVo> queryArticleLikes(Integer articleId) {
         String sql = "select (select IFNULL(count(*),0) from article_tweet where user_id = al.like_id) as article_number,(select IFNULL(count(*),0) from user_collect where is_lose = 0 and parent_userid = al.like_id) as fans_number,al.like_id as id,al.like_image as image,al.like_name as name " +
                 "from article_likes al\n" +
-                "where al.is_lose = 0 and al.article_id = :articleId order by al.create_date desc limit 0,10";
+                "where al.is_lose = 0 and al.article_id = :articleId order by al.create_date desc";
         MapSqlParameterSource sps = new MapSqlParameterSource();
         sps.addValue("articleId", articleId);
         List<LikeListVo> list = null;
@@ -244,6 +278,7 @@ public class ArticleTweetImplDao implements ArticleTweetDao {
         return null;
     }
 
+
     @Override
     public List<ArticleCommentVo> queryArticleComment(Integer articleId) {
         String sql = "select id,comment_parent_id as parent_id,comment_id as user_id,comment_name as user_name,comment_image as image,content,create_date as date " +

+ 10 - 0
mhotel/src/com/happy/service/ArticleTweetService.java

@@ -225,4 +225,14 @@ public interface ArticleTweetService {
      * @return
      */
     int updateDescript(Integer authorId, String descript);
+
+
+    /**
+     * 点赞分页列表数据
+     * @param articleId
+     * @param page
+     * @param rows
+     * @return
+     */
+    IPage<LikeListVo> queryLikesPage(Integer articleId, int page, int rows);
 }

+ 15 - 0
mhotel/src/com/happy/service/impl/ArticleTweetImplService.java

@@ -243,4 +243,19 @@ public class ArticleTweetImplService implements ArticleTweetService {
         int num = articleTweetDao.updateDescript(authorId, descript);
         return num;
     }
+
+
+    @Override
+    public IPage<LikeListVo> queryLikesPage(Integer articleId, int page, int rows) {
+        IPage<LikeListVo> iPage = new IPage();
+        List<LikeListVo> commentList = articleTweetDao.queryLikesPage(articleId, page, rows);
+        int total = articleTweetDao.queryLikesTotal(articleId);
+        iPage.setPageList(commentList == null ? new ArrayList<>() : commentList);
+        iPage.setPage(page);
+        iPage.setTotalPage((int) Math.ceil((double) total / rows));
+        iPage.setRows(rows);
+        iPage.setTotal(total);
+        return iPage;
+    }
+
 }