Browse Source

点赞最多

夏文涛 2 năm trước cách đây
mục cha
commit
c7bbf4ab00

+ 36 - 3
mhotel/src/com/happy/action/articleTweetAction.java

@@ -94,7 +94,7 @@ public class articleTweetAction extends BaseController implements ModelDriven<Ar
         }
         }
 
 
         //推文发布参数
         //推文发布参数
-        System.out.println("推文发布参数:"+ JSON.toJSON(articleTweetDto));
+        System.out.println("推文发布参数:" + JSON.toJSON(articleTweetDto));
 
 
         //查询当前用户
         //查询当前用户
         Users user = userService.queryByUserId(String.valueOf(articleTweetDto.getCreateId()));
         Users user = userService.queryByUserId(String.valueOf(articleTweetDto.getCreateId()));
@@ -180,7 +180,7 @@ public class articleTweetAction extends BaseController implements ModelDriven<Ar
                 return null;
                 return null;
             }
             }
         } catch (Exception e) {
         } catch (Exception e) {
-            System.out.println("推文发布异常:"+e.getMessage());
+            System.out.println("推文发布异常:" + e.getMessage());
             ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
             ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
                 put("message", "推文发布异常");
                 put("message", "推文发布异常");
                 put("code", 500);
                 put("code", 500);
@@ -381,9 +381,10 @@ public class articleTweetAction extends BaseController implements ModelDriven<Ar
 
 
     /**
     /**
      * 点赞集合列表
      * 点赞集合列表
+     *
      * @return
      * @return
      */
      */
-    public String queryLikes(){
+    public String queryLikes() {
 
 
         JSONObject jsonObject = new JSONObject();
         JSONObject jsonObject = new JSONObject();
 
 
@@ -745,6 +746,36 @@ public class articleTweetAction extends BaseController implements ModelDriven<Ar
 
 
 
 
     /**
     /**
+     * 点赞数最高的推文
+     */
+    public String queryMaxArticleLike() {
+        JSONObject jsonObject = new JSONObject();
+        ArticleLikeMaxVo result = articleTweetService.queryMaxArticleLike();
+        if (result != null) {
+            List<FileInfo> fileInfos = articleTweetService.queryList("and link_id = " + result.getId() + "");
+            if (fileInfos != null) {
+                if (fileInfos.size() > 1) {
+                    result.setImage(fileInfos.get(0).getUrl());
+                } else if (fileInfos.size() == 1) {
+                    String url = fileInfos.get(0).getUrl();
+                    if (!url.endsWith("jpg") && !url.endsWith("png")) {
+                        result.setVideo(fileInfos.get(0).getUrl());
+                    } else {
+                        result.setImage(url);
+                    }
+                }
+            }
+        }
+
+        jsonObject.put("code", ResultStatusCode.OK.getStatus());
+        jsonObject.put("message", "请求成功");
+        jsonObject.put("data", result);
+        ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
+        return null;
+    }
+
+
+    /**
      * 相关推文
      * 相关推文
      */
      */
     public String relatedTweets() {
     public String relatedTweets() {
@@ -1103,4 +1134,6 @@ public class articleTweetAction extends BaseController implements ModelDriven<Ar
         ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
         ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
         return null;
         return null;
     }
     }
+
+
 }
 }

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

@@ -265,4 +265,9 @@ public interface ArticleTweetDao {
      * 点赞总数据条数
      * 点赞总数据条数
      */
      */
     int queryLikesTotal(Integer articleId);
     int queryLikesTotal(Integer articleId);
+
+    /**
+     * 获取点赞数最多的最新推文数据
+     */
+    ArticleLikeMaxVo queryMaxArticleLike();
 }
 }

+ 27 - 0
mhotel/src/com/happy/dao/impl/ArticleTweetImplDao.java

@@ -713,4 +713,31 @@ public class ArticleTweetImplDao implements ArticleTweetDao {
         return num;
         return num;
     }
     }
 
 
+
+    /**
+     * 获取点赞数最多的最新推文数据
+     */
+    @Override
+    public ArticleLikeMaxVo queryMaxArticleLike() {
+        String sql = "select t.id,t.townId,t.townName,t.title,t.content from (select at.id,at.location_id as townId,hd.name as townName,at.title,at.content,(select Count(*) from article_likes where is_lose = 0 and article_id = at.id) as like_num,at.create_date\n" +
+                     "from article_tweet at\n" +
+                     "left join hotel_dict hd on hd.id = at.location_id\n" +
+                     "where at.approve = 2) t\n" +
+                     "order by t.like_num desc,t.create_date desc LIMIT 1";
+        MapSqlParameterSource sps = new MapSqlParameterSource();
+        List<ArticleLikeMaxVo> list = null;
+        try {
+            list = namedParameterJdbcTemplate.query(sql, sps,
+                    new BeanPropertyRowMapper<>(ArticleLikeMaxVo.class));
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        if (list != null && list.size() > 0) {
+            return list.get(0);
+        }
+        return null;
+
+    }
+
+
 }
 }

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

@@ -235,4 +235,10 @@ public interface ArticleTweetService {
      * @return
      * @return
      */
      */
     IPage<LikeListVo> queryLikesPage(Integer articleId, int page, int rows);
     IPage<LikeListVo> queryLikesPage(Integer articleId, int page, int rows);
+
+
+    /**
+     * 获取点赞数最多的最新推文数据
+     */
+    ArticleLikeMaxVo queryMaxArticleLike();
 }
 }

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

@@ -258,4 +258,10 @@ public class ArticleTweetImplService implements ArticleTweetService {
         return iPage;
         return iPage;
     }
     }
 
 
+
+    @Override
+    public ArticleLikeMaxVo queryMaxArticleLike(){
+        ArticleLikeMaxVo result = articleTweetDao.queryMaxArticleLike();
+        return result;
+    }
 }
 }

+ 48 - 0
mhotel/src/com/happy/vo/ArticleLikeMaxVo.java

@@ -0,0 +1,48 @@
+package com.happy.vo;
+
+import lombok.Data;
+
+/**
+ * @Author: binguo
+ * @Date: 2023/10/12 星期四 10:45
+ * @Description: com.happy.vo
+ * @Version: 1.0
+ */
+@Data
+public class ArticleLikeMaxVo {
+    /**
+     * 数据ID
+     */
+    private Integer id;
+
+    /**
+     * 图片
+     */
+    private String image;
+
+    /**
+     * 视频
+     */
+    private String video;
+
+    /**
+     * 乡镇ID
+     */
+    private Integer townId;
+
+    /**
+     * 乡镇名称
+     */
+    private String townName;
+
+    /**
+     * 标题
+     */
+    private String title;
+
+    /**
+     * 内容
+     */
+    private String content;
+
+}