Browse Source

社区功能开发

夏文涛 2 years atrás
parent
commit
d4d2e1bb32

+ 7 - 0
mhotel/src/com/happy/Model/ArticleTweet.java

@@ -78,4 +78,11 @@ public class ArticleTweet {
      * 文章收藏数
      */
     private Integer collectNum;
+
+    /**
+     * 是否收藏
+     * 未收藏:0
+     * 已收藏:1
+     */
+    private Integer isCollect;
 }

+ 1 - 1
mhotel/src/com/happy/action/WorkflowAction.java

@@ -160,7 +160,7 @@ public class WorkflowAction  extends ActionSupport implements ServletRequestAwar
                 //region
                 //2023-10-11 A-jax添加推文的审批操作
                 case 3: {
-                    ArticleTweet articleTweet = articleTweetService.queryArticleById(workflow1.getLinkId());
+                    ArticleTweet articleTweet = articleTweetService.queryArticleById(workflow1.getLinkId(), null);
                     workflow1.setStatus(workflow.getStatus());
                     articleTweet.setApprove(workflow.getStatus());
                     int n = articleTweetService.updateArticleApprove(articleTweet);

+ 56 - 15
mhotel/src/com/happy/action/articleTweetAction.java

@@ -205,7 +205,7 @@ public class articleTweetAction extends BaseController implements ModelDriven<Ar
         }
 
         //查询推文数据
-        ArticleTweet data = articleTweetService.queryArticleById(String.valueOf(articleTweetDto.getId()));
+        ArticleTweet data = articleTweetService.queryArticleById(String.valueOf(articleTweetDto.getId()), articleTweetDto.getUserId());
         if (data == null) {
             jsonObject.put("code", 500);
             jsonObject.put("message", "推文数据已失效,查看详情失败");
@@ -244,8 +244,8 @@ public class articleTweetAction extends BaseController implements ModelDriven<Ar
 
         //region 民宿列表
         //根据乡镇ID获取
-        List<String> hotelIds = Arrays.asList(user.getCollect_hotel().split(","));
-        String sql = "id in = (" + data.getHotelId() + ")";
+        List<String> hotelIds = user.getCollect_hotel() == null ? new ArrayList<>() : Arrays.asList(user.getCollect_hotel().split(","));
+        String sql = "id in (" + data.getHotelId() + ")";
         List<HotelVo> hotels = articleTweetService.queryHotels(sql);
         List<HotelListVo> hotelDatas = new ArrayList<>();
 
@@ -316,10 +316,11 @@ public class articleTweetAction extends BaseController implements ModelDriven<Ar
             }
             hotelDatas.add(hotelData);
         }
+        result.setHotels(hotelDatas);
         //endregion
 
         List<LikeListVo> likes = articleTweetService.queryArticleLikes(articleTweetDto.getId());
-        result.setLikes(likes.stream().map(LikeListVo::getImage).collect(Collectors.toList()));
+        result.setLikes(likes == null ? new ArrayList<>() : likes.stream().map(LikeListVo::getImage).collect(Collectors.toList()));
         result.setLikeNum(likes == null ? 0 : likes.size());
 
         List<ArticleCommentVo> comments = articleTweetService.queryArticleComment(articleTweetDto.getId());
@@ -362,7 +363,7 @@ public class articleTweetAction extends BaseController implements ModelDriven<Ar
         }
 
         //查询推文数据
-        ArticleTweet data = articleTweetService.queryArticleById(String.valueOf(articleTweetDto.getId()));
+        ArticleTweet data = articleTweetService.queryArticleById(String.valueOf(articleTweetDto.getId()), articleTweetDto.getUserId());
         if (data == null) {
             jsonObject.put("code", 500);
             jsonObject.put("message", "推文数据已失效,查看详情失败");
@@ -373,8 +374,8 @@ public class articleTweetAction extends BaseController implements ModelDriven<Ar
 
         //region 民宿列表
         //根据乡镇ID获取
-        List<String> hotelIds = Arrays.asList(user.getCollect_hotel().split(","));
-        String sql = "id in = (" + data.getHotelId() + ")";
+        List<String> hotelIds = user.getCollect_hotel() == null ? new ArrayList<>() : Arrays.asList(user.getCollect_hotel().split(","));
+        String sql = "id in (" + data.getHotelId() + ")";
         IPage<HotelVo> hotels = articleTweetService.queryHotelPageByHotleId(sql, page, rows);
         List<HotelListVo> hotelDatas = new ArrayList<>();
 
@@ -569,9 +570,9 @@ public class articleTweetAction extends BaseController implements ModelDriven<Ar
 
         String sqlWhere = "";//全部推文
         if (articleTweetDto.getType().intValue() == 1) {
-            sqlWhere = "at.approve = 1 ";//审核中
+            sqlWhere = "and at.approve = 1 ";//审核中
         } else if (articleTweetDto.getType().intValue() == 2) {
-            sqlWhere = "at.approve = 3 ";//驳回
+            sqlWhere = "and at.approve = 3 ";//驳回
         }
         IPage<OwnerArticleVo> result = articleTweetService.queryOwnerArticlePage(articleTweetDto.getUserId(), sqlWhere, page, rows);
 
@@ -580,11 +581,11 @@ public class articleTweetAction extends BaseController implements ModelDriven<Ar
             List<FileInfo> fileInfos = articleTweetService.queryList("and link_id in (" + articleIds + ")");
 
             for (OwnerArticleVo data : result.getPageList()) {
-                List<FileInfo> fileInfoList = fileInfos.stream().filter(e -> e.getLinkId().equals(data.getId())).collect(Collectors.toList());
+                List<FileInfo> fileInfoList = fileInfos.stream().filter(e -> e.getLinkId().equals(data.getId().toString())).collect(Collectors.toList());
                 if (fileInfoList != null) {
                     if (fileInfoList.size() > 1) {
                         data.setImages(fileInfoList.stream().map(FileInfo::getUrl).collect(Collectors.toList()));
-                    } else {
+                    } else if(fileInfoList.size() == 1){
                         data.setVideo(fileInfoList.get(0).getUrl());
                     }
                 }
@@ -622,23 +623,62 @@ public class articleTweetAction extends BaseController implements ModelDriven<Ar
             return null;
         }
 
-        IPage<ArticleListVo> result = articleTweetService.queryArticlesPage(articleTweetDto.getTownId(), articleTweetDto.getUserId(), articleTweetDto.getType(), page, rows);
+        IPage<ArticleListVo> result = articleTweetService.queryArticlesPage(articleTweetDto.getTownId().equals("") ? null : articleTweetDto.getTownId(), articleTweetDto.getUserId(), articleTweetDto.getType(), page, rows);
         if (result.getPageList().size() > 0) {
             String articleIds = StringUtils.join(result.getPageList().stream().map(ArticleListVo::getId).collect(Collectors.toList()), ",");
             List<FileInfo> fileInfos = articleTweetService.queryList("and link_id in (" + articleIds + ")");
 
             for (ArticleListVo data : result.getPageList()) {
-                List<FileInfo> fileInfoList = fileInfos.stream().filter(e -> e.getLinkId().equals(data.getId())).collect(Collectors.toList());
+                List<FileInfo> fileInfoList = fileInfos.stream().filter(e -> e.getLinkId().equals(data.getId().toString())).collect(Collectors.toList());
                 if (fileInfoList != null) {
                     if (fileInfoList.size() > 1) {
                         data.setImage(fileInfoList.get(0).getUrl());
-                    } else {
+                    } else if(fileInfoList.size() == 1){
                         data.setVideo(fileInfoList.get(0).getUrl());
                     }
                 }
             }
         }
 
+        jsonObject.put("code", ResultStatusCode.OK.getStatus());
+        jsonObject.put("message", "请求成功");
+        jsonObject.put("data", result);
+        ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
+
+        return null;
+    }
+
+
+    /**
+     * 相关推文
+     */
+    public String relatedTweets(){
+        JSONObject jsonObject = new JSONObject();
+
+        if (articleTweetDto.getId() == null || articleTweetDto.getTownId() == null || articleTweetDto.getUserId() == null) {
+            jsonObject.put("code", 500);
+            jsonObject.put("message", "乡镇ID或推文ID或用户ID不能为空");
+            jsonObject.put("data", null);
+            ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
+            return null;
+        }
+
+        IPage<ArticleListVo> result = articleTweetService.relatedTweetPage(articleTweetDto.getUserId(), articleTweetDto.getTownId(), articleTweetDto.getId(), page, rows);
+        if (result.getPageList().size() > 0) {
+            String articleIds = StringUtils.join(result.getPageList().stream().map(ArticleListVo::getId).collect(Collectors.toList()), ",");
+            List<FileInfo> fileInfos = articleTweetService.queryList("and link_id in (" + articleIds + ")");
+
+            for (ArticleListVo data : result.getPageList()) {
+                List<FileInfo> fileInfoList = fileInfos.stream().filter(e -> e.getLinkId().equals(data.getId().toString())).collect(Collectors.toList());
+                if (fileInfoList != null) {
+                    if (fileInfoList.size() > 1) {
+                        data.setImage(fileInfoList.get(0).getUrl());
+                    } else if(fileInfoList.size() == 1){
+                        data.setVideo(fileInfoList.get(0).getUrl());
+                    }
+                }
+            }
+        }
 
         jsonObject.put("code", ResultStatusCode.OK.getStatus());
         jsonObject.put("message", "请求成功");
@@ -647,6 +687,7 @@ public class articleTweetAction extends BaseController implements ModelDriven<Ar
 
         return null;
     }
+    //select * from article_tweet where location_id = '' and user_id != 1 and approve = 2
 
 
     /**
@@ -758,7 +799,7 @@ public class articleTweetAction extends BaseController implements ModelDriven<Ar
 
         ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
             put("message", "评论成功");
-            put("code", 500);
+            put("code", 200);
         }}.toString());
 
         return null;

+ 19 - 1
mhotel/src/com/happy/dao/ArticleTweetDao.java

@@ -12,7 +12,7 @@ public interface ArticleTweetDao {
      * @param id
      * @return
      */
-    ArticleTweet queryArticleById(String id);
+    ArticleTweet queryArticleById(String id, Integer userId);
 
     /**
      * 新增推文数据
@@ -179,6 +179,24 @@ public interface ArticleTweetDao {
     int queryArticlesTotal(String townId, Integer userId, Integer type);
 
     /**
+     * 相关推文列表分页数据
+     * @param townId
+     * @param articleId
+     * @param page
+     * @param rows
+     * @return
+     */
+    List<ArticleListVo> relatedTweetPage(Integer userId, String townId, Integer articleId, int page, int rows);
+
+    /**
+     * 相关推文总数据条数
+     * @param townId
+     * @param articleId
+     * @return
+     */
+    int relatedTweetTotal(String townId, Integer articleId);
+
+    /**
      * 查询文章收藏数据
      * @param articleId
      * @param userId

+ 105 - 43
mhotel/src/com/happy/dao/impl/ArticleTweetImplDao.java

@@ -32,10 +32,15 @@ public class ArticleTweetImplDao implements ArticleTweetDao {
     }
 
     @Override
-    public ArticleTweet queryArticleById(String id) {
-        String sql = "SELECT (select IFNULL(count(*),0) from article_collect where article_id = :id and is_lose = 0) as collect_num,hd.name as location_name,u.user_name,at.* FROM article_tweet at" +
+    public ArticleTweet queryArticleById(String id, Integer userId) {
+        String caseSql = userId == null ? "" : "case ac.id when null then 0 else 1 end is_collect,";
+        String leftSql = userId == null ? "" : "left join article_collect ac on ac.is_lose = 0 and ac.article_id = at.id and ac.user_id = " + userId + " ";
+
+        String sql = "SELECT " + caseSql + "(select IFNULL(count(*),0) from article_collect where article_id = :id and is_lose = 0) as collect_num,hd.name as location_name,u.user_name,at.* " +
+                "FROM article_tweet at " +
                 "inner join users u on u.id = at.user_id " +
-                "left join hotel_dict hd on hd.code = 10 and hd.id = at.location_id" +
+                "left join hotel_dict hd on hd.code = 10 and hd.id = at.location_id " +
+                leftSql +
                 "WHERE at.id = :id ";
         MapSqlParameterSource sps = new MapSqlParameterSource();
         sps.addValue("id", id);
@@ -56,7 +61,7 @@ public class ArticleTweetImplDao implements ArticleTweetDao {
     @Override
     public int insert(ArticleTweet articleTweet) {
         KeyHolder key = new GeneratedKeyHolder();
-        String sql = "insert into `article_tweet`(user_id,title,content,location_id,hotel_id,create_id,create_date,status,approve)" +
+        String sql = "insert into `article_tweet` (user_id,title,content,location_id,hotel_id,create_id,create_date,status,approve) " +
                 "values(:userId,:title,:content,:locationId,:hotelId,:createId,:createDate,:status,:approve) ";
         MapSqlParameterSource sps = new MapSqlParameterSource();
         sps.addValue("userId", articleTweet.getUserId());
@@ -108,7 +113,8 @@ public class ArticleTweetImplDao implements ArticleTweetDao {
     public List<HotelVo> queryHotelPage(String sqlx, int page, int rows) {
         SqlUtil.filterKeyword(sqlx);
         int start = (page - 1) * rows;// 每页的起始下标
-        String sql = "select h.id,h.hname as name,h.cover_img,h.score_hotel as score,am.type from admin_manager am\n" +
+        String sql = "select h.id,h.hname as name,h.cover_img,h.score_hotel as score,am.type " +
+                "from admin_manager am\n" +
                 "inner join hotel h on h.status = 1 and h.manager_id = am.id\n" +
                 "where am.status = 1 and am." + sqlx + " ORDER BY name asc limit :start,:rows ";
         MapSqlParameterSource sps = new MapSqlParameterSource();
@@ -135,7 +141,8 @@ public class ArticleTweetImplDao implements ArticleTweetDao {
     @Override
     public List<HotelVo> queryHotels(String sqlx) {
         SqlUtil.filterKeyword(sqlx);
-        String sql = "select h.manager_id,(select IFNULL(count(*),0) from booking_comment where status = 1 and hotel_id = h.id) as comment,h.id,h.hname as name,h.cover_img,h.score_hotel as score,am.type from hotel h\n" +
+        String sql = "select h.manager_id,(select IFNULL(count(*),0) from booking_comment where status = 1 and hotel_id = h.id) as comment,h.id,h.hname as name,h.cover_img,h.score_hotel as score,am.type " +
+                "from hotel h\n" +
                 "left join admin_manager am on am.status = 1 and h.manager_id = am.id\n" +
                 "where h.status = 1 and h." + sqlx + " ORDER BY name asc limit 0,2";
         MapSqlParameterSource sps = new MapSqlParameterSource();
@@ -152,7 +159,8 @@ public class ArticleTweetImplDao implements ArticleTweetDao {
         SqlUtil.filterKeyword(sqlx);
         int start = (page - 1) * rows;// 每页的起始下标
         String sql =
-                "select h.manager_id,(select IFNULL(count(*),0) from booking_comment where status = 1 and hotel_id = h.id) as comment,h.id,h.hname as name,h.cover_img,h.score_hotel as score,am.type from hotel h\n" +
+                "select h.manager_id,(select IFNULL(count(*),0) from booking_comment where status = 1 and hotel_id = h.id) as comment,h.id,h.hname as name,h.cover_img,h.score_hotel as score,am.type " +
+                        "from hotel h\n" +
                         "left join admin_manager am on am.status = 1 and h.manager_id = am.id\n" +
                         "where h.status = 1 and h." + sqlx + " ORDER BY name asc limit :start,:rows ";
         MapSqlParameterSource sps = new MapSqlParameterSource();
@@ -169,8 +177,7 @@ public class ArticleTweetImplDao implements ArticleTweetDao {
     @Override
     public int queryHotelTotalByHotleId(String sqlx) {
         SqlUtil.filterKeyword(sqlx);
-        String sql = "select h.manager_id,(select IFNULL(count(*),0) from booking_comment where status = 1 and hotel_id = h.id) as comment,h.id,h.hname as name,h.cover_img,h.score_hotel as score,am.type from hotel h\n" +
-                "left join admin_manager am on am.status = 1 and h.manager_id = am.id\n" +
+        String sql = "select count(*) from hotel h\n" +
                 "where h.status = 1 and h." + sqlx;
         MapSqlParameterSource sps = new MapSqlParameterSource();
         return namedParameterJdbcTemplate.queryForInt(sql, sps);
@@ -179,21 +186,25 @@ public class ArticleTweetImplDao implements ArticleTweetDao {
     @Override
     public List<FileInfo> queryList(String sqlx) {
         SqlUtil.filterKeyword(sqlx);
-        String sql = "SELECT id,link_id,url,name FROM `article_file_info` WHERE type=1 " + sqlx;
+        String sql = "SELECT id,link_id,url,name " +
+                "FROM `article_file_info` WHERE type=1 " + sqlx;
         List<FileInfo> list = null;
         try {
             list = namedParameterJdbcTemplate.query(sql, new BeanPropertyRowMapper<>(FileInfo.class));
         } catch (Exception e) {
             e.printStackTrace();
         }
-        if (list != null && list.size() > 0) return list;
+        if (list != null && list.size() > 0) {
+            return list;
+        }
         return null;
     }
 
 
     @Override
     public UserCollect queryUserCollect(Integer parentId, Integer userId) {
-        String sql = "SELECT * FROM user_collect WHERE is_lose=0 and parent_userid = :parentId and user_id = :userId";
+        String sql = "SELECT * FROM user_collect " +
+                "WHERE is_lose=0 and parent_userid = :parentId and user_id = :userId";
         MapSqlParameterSource sps = new MapSqlParameterSource();
         sps.addValue("parentId", parentId);
         sps.addValue("userId", userId);
@@ -213,7 +224,8 @@ public class ArticleTweetImplDao implements ArticleTweetDao {
 
     @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" +
+        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";
         MapSqlParameterSource sps = new MapSqlParameterSource();
         sps.addValue("articleId", articleId);
@@ -231,8 +243,9 @@ public class ArticleTweetImplDao implements ArticleTweetDao {
 
     @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 from article_comment " +
-                "where article_id = :articleId and comment_parent_id = 0" +
+        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 " +
+                "from article_comment " +
+                "where article_id = :articleId and comment_parent_id = 0 " +
                 "ORDER BY create_date desc limit 0,3";
         MapSqlParameterSource sps = new MapSqlParameterSource();
         sps.addValue("articleId", articleId);
@@ -263,8 +276,9 @@ public class ArticleTweetImplDao implements ArticleTweetDao {
     @Override
     public List<ArticleCommentVo> queryCommentPageByArticle(Integer articleId, int page, int rows) {
         int start = (page - 1) * rows;// 每页的起始下标
-        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 from article_comment " +
-                "where article_id = :articleId and comment_parent_id = 0" +
+        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 " +
+                "from article_comment " +
+                "where article_id = :articleId and comment_parent_id = 0 " +
                 "ORDER BY create_date desc limit :start,:rows";
         MapSqlParameterSource sps = new MapSqlParameterSource();
         sps.addValue("start", start);
@@ -280,7 +294,7 @@ public class ArticleTweetImplDao implements ArticleTweetDao {
 
     @Override
     public int queryCommentTotalByArticle(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 from article_comment " +
+        String sql = "select count(*) from article_comment " +
                 "where article_id = :articleId and comment_parent_id = 0";
         MapSqlParameterSource sps = new MapSqlParameterSource();
         sps.addValue("articleId", articleId);
@@ -290,8 +304,9 @@ public class ArticleTweetImplDao implements ArticleTweetDao {
 
     @Override
     public List<ArticleCommentVo> queryCommentsByArticle(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 from article_comment " +
-                "where article_id = :articleId and comment_parent_id > 0" +
+        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 " +
+                "from article_comment " +
+                "where article_id = :articleId and comment_parent_id > 0 " +
                 "order BY create_date desc";
         MapSqlParameterSource sps = new MapSqlParameterSource();
         sps.addValue("articleId", articleId);
@@ -351,8 +366,8 @@ public class ArticleTweetImplDao implements ArticleTweetDao {
 
     @Override
     public int queryOwnerArticleTotal(Integer userId, String sqlWhere) {
-        String sql = "select count(*) from article_tweet \n" +
-                "where user_id = :userId " + sqlWhere;
+        String sql = "select count(*) from article_tweet at \n" +
+                "where at.user_id = :userId " + sqlWhere;
 
         MapSqlParameterSource sps = new MapSqlParameterSource();
         sps.addValue("userId", userId);
@@ -379,16 +394,17 @@ public class ArticleTweetImplDao implements ArticleTweetDao {
             innSql = "inner join article_collect acc on acc.is_lose = 0 and acc.article_id = at.id and acc.user_id = :userId\n";//收藏
         }
 
-        String sqlWhere = townId == null ? "" : "at.location_id = '" + townId + "'";
+        String sqlWhere = townId == null ? "" : "and at.location_id = '" + townId + "'";
 
         String sql = "select at.id,at.location_id as town_id,hd.name as town_name,at.title,at.user_id,u.user_name,\n" + caseSql +
                 "(select count(*) from article_collect where is_lose = 0 and article_id = at.id) as collect_num\n" +
                 "from article_tweet at\n" +
-                "left join hotel_dict hd on dh.id = at.location_id\n" +
+                "left join hotel_dict hd on hd.id = at.location_id\n" +
                 "left join users u on u.id = at.user_id\n" +
                 leftSql +
                 innSql +
-                "where at.approve = 2 " + sqlWhere;
+                "where at.approve = 2 " + sqlWhere +
+                "order by at.create_date desc ";
 
         MapSqlParameterSource sps = new MapSqlParameterSource();
         sps.addValue("start", start);
@@ -412,9 +428,9 @@ public class ArticleTweetImplDao implements ArticleTweetDao {
             innSql = "inner join article_collect acc on acc.is_lose = 0 and acc.article_id = at.id and acc.user_id = :userId\n";//收藏
         }
 
-        String sqlWhere = townId == null ? "" : "at.location_id = '" + townId + "'";
+        String sqlWhere = townId == null ? "" : "and at.location_id = '" + townId + "'";
 
-        String sql = "select count(at.*) from article_tweet at\n" +
+        String sql = "select count(*) from article_tweet at\n" +
                 innSql +
                 "where at.approve = 2 " + sqlWhere;
 
@@ -426,9 +442,49 @@ public class ArticleTweetImplDao implements ArticleTweetDao {
 
 
     @Override
+    public List<ArticleListVo> relatedTweetPage(Integer userId, String townId, Integer articleId, int page, int rows) {
+        int start = (page - 1) * rows;// 每页的起始下标
+
+        String sql = "select at.id,at.location_id as town_id,hd.name as town_name,at.title,at.user_id,u.user_name,case ac.id when null then 0 else 1 end is_collect,\n" +
+                "(select count(*) from article_collect where is_lose = 0 and article_id = at.id) as collect_num\n" +
+                "from article_tweet at\n" +
+                "left join hotel_dict hd on hd.id = at.location_id\n" +
+                "left join users u on u.id = at.user_id\n" +
+                "left join article_collect ac on ac.is_lose = 0 and ac.article_id = at.id and ac.user_id = :userId\n" +
+                "where at.approve = 2 and at.location_id = :townId and at.id != :articleId\n" +
+                "order by at.create_date desc ";
+
+        MapSqlParameterSource sps = new MapSqlParameterSource();
+        sps.addValue("start", start);
+        sps.addValue("rows", rows);
+        sps.addValue("userId", userId);
+        sps.addValue("townId", townId);
+        sps.addValue("articleId", articleId);
+        List<ArticleListVo> list = namedParameterJdbcTemplate.query(sql, sps,
+                new BeanPropertyRowMapper<>(ArticleListVo.class));
+        if (list != null && list.size() > 0) {
+            return list;
+        }
+        return null;
+    }
+
+    @Override
+    public int relatedTweetTotal(String townId, Integer articleId) {
+
+        String sql = "select count(*) from article_tweet at\n" +
+                "where at.approve = 2 and at.location_id = :townId and at.id != :articleId";
+
+        MapSqlParameterSource sps = new MapSqlParameterSource();
+        sps.addValue("townId", townId);
+        sps.addValue("articleId", articleId);
+        return namedParameterJdbcTemplate.queryForInt(sql, sps);
+    }
+
+
+    @Override
     public ArticleCollect queryArticleCollect(Integer articleId, Integer userId) {
         String sql = "select * from article_collect\n" +
-                     "where article_id = :articleId and user_id = :userId ";
+                "where article_id = :articleId and user_id = :userId ";
         MapSqlParameterSource sps = new MapSqlParameterSource();
         sps.addValue("articleId", articleId);
         sps.addValue("userId", userId);
@@ -448,10 +504,10 @@ public class ArticleTweetImplDao implements ArticleTweetDao {
 
     @Override
     public int updateArticleCollect(ArticleCollect articleCollect) {
-        String sql ="";
+        String sql = "";
         MapSqlParameterSource sps = new MapSqlParameterSource();
-        if(articleCollect.getId() == null){
-            sql = "insert into article_collect (article_id,user_id,is_lose,create_id,create_date,status)" +
+        if (articleCollect.getId() == null) {
+            sql = "insert into article_collect (article_id,user_id,is_lose,create_id,create_date,status) " +
                     "values(:articleId,:userId,:isLose,:createId,:createDate,:status) ";
 
             sps.addValue("articleId", articleCollect.getArticleId());
@@ -460,7 +516,7 @@ public class ArticleTweetImplDao implements ArticleTweetDao {
             sps.addValue("createId", articleCollect.getCreateId());
             sps.addValue("createDate", articleCollect.getCreateDate());
             sps.addValue("status", articleCollect.getStatus());
-        }else{
+        } else {
             sql = "update article_collect set is_lose = :isLose where id = :id";
             sps.addValue("isLose", articleCollect.getIsLose());
             sps.addValue("id", articleCollect.getId());
@@ -478,7 +534,7 @@ public class ArticleTweetImplDao implements ArticleTweetDao {
     @Override
     public int insertArticleComment(ArticleComment articleComment) {
         MapSqlParameterSource sps = new MapSqlParameterSource();
-        String sql = "insert into article_comment (article_id,comment_parent_id,comment_id,comment_name,comment_image,content,create_id,create_date,status)" +
+        String sql = "insert into article_comment (article_id,comment_parent_id,comment_id,comment_name,comment_image,content,create_id,create_date,status) " +
                 "values(:articleId,:commentParentId,:commentId,:commentName,:commentImage,:content,:createId,:createDate,:status) ";
 
         sps.addValue("articleId", articleComment.getArticleId());
@@ -504,7 +560,7 @@ public class ArticleTweetImplDao implements ArticleTweetDao {
     @Override
     public UserCollect queryUserCollectNoLose(Integer authorId, Integer userId) {
         String sql = "select * from user_collect\n" +
-                     "where parent_userid = :authorId and user_id = :userId ";
+                "where parent_userid = :authorId and user_id = :userId ";
         MapSqlParameterSource sps = new MapSqlParameterSource();
         sps.addValue("authorId", authorId);
         sps.addValue("userId", userId);
@@ -524,10 +580,10 @@ public class ArticleTweetImplDao implements ArticleTweetDao {
 
     @Override
     public int updateUserCollect(UserCollect userCollect) {
-        String sql ="";
+        String sql = "";
         MapSqlParameterSource sps = new MapSqlParameterSource();
-        if(userCollect.getId() == null){
-            sql = "insert into user_collect (parent_userid,user_id,is_lose,create_id,create_date,status)" +
+        if (userCollect.getId() == null) {
+            sql = "insert into user_collect (parent_userid,user_id,is_lose,create_id,create_date,status) " +
                     "values(:parentUserid,:userId,:isLose,:createId,:createDate,:status) ";
 
             sps.addValue("parentUserid", userCollect.getParentUserid());
@@ -536,7 +592,7 @@ public class ArticleTweetImplDao implements ArticleTweetDao {
             sps.addValue("createId", userCollect.getCreateId());
             sps.addValue("createDate", userCollect.getCreateDate());
             sps.addValue("status", userCollect.getStatus());
-        }else{
+        } else {
             sql = "update user_collect set is_lose = :isLose where id = :id";
             sps.addValue("isLose", userCollect.getIsLose());
             sps.addValue("id", userCollect.getId());
@@ -574,10 +630,10 @@ public class ArticleTweetImplDao implements ArticleTweetDao {
 
     @Override
     public int updateArticleLike(ArticleLikes articleLikes) {
-        String sql ="";
+        String sql = "";
         MapSqlParameterSource sps = new MapSqlParameterSource();
-        if(articleLikes.getId() == null){
-            sql = "insert into article_collect (article_id,like_id,like_name,like_image,is_lose,create_id,create_date,status)" +
+        if (articleLikes.getId() == null) {
+            sql = "insert into article_likes (article_id,like_id,like_name,like_image,is_lose,create_id,create_date,status) " +
                     "values(:articleId,:likeId,:likeName,:likeImage,:isLose,:createId,:createDate,:status) ";
 
             sps.addValue("articleId", articleLikes.getArticleId());
@@ -588,8 +644,8 @@ public class ArticleTweetImplDao implements ArticleTweetDao {
             sps.addValue("createId", articleLikes.getCreateId());
             sps.addValue("createDate", articleLikes.getCreateDate());
             sps.addValue("status", articleLikes.getStatus());
-        }else{
-            sql = "update article_collect set is_lose = :isLose where id = :id";
+        } else {
+            sql = "update article_likes set is_lose = :isLose where id = :id";
             sps.addValue("isLose", articleLikes.getIsLose());
             sps.addValue("id", articleLikes.getId());
         }
@@ -603,4 +659,10 @@ public class ArticleTweetImplDao implements ArticleTweetDao {
         return num;
     }
 
+
+    /**
+     * 相关推文
+     */
+
+    //select * from article_tweet where location_id = '' and user_id != 1 and approve = 2
 }

+ 0 - 5
mhotel/src/com/happy/dto/ArticleTweetDto.java

@@ -30,11 +30,6 @@ public class ArticleTweetDto extends ArticleTweet {
     public String townId;
 
     /**
-     * 用户ID
-     */
-    public Integer userId;
-
-    /**
      * 推文中用户主页下的推文列表状态查询
      * 全部推文:0
      * 审核中:1

+ 12 - 1
mhotel/src/com/happy/service/ArticleTweetService.java

@@ -13,7 +13,7 @@ public interface ArticleTweetService {
      * @param id
      * @return
      */
-    ArticleTweet queryArticleById(String id);
+    ArticleTweet queryArticleById(String id, Integer userId);
 
     /**
      * 新增推文数据
@@ -155,6 +155,17 @@ public interface ArticleTweetService {
     IPage<ArticleListVo> queryArticlesPage(String townId, Integer userId, Integer type, int page, int rows);
 
     /**
+     * 相关推文分页数据
+     * @param userId
+     * @param townId
+     * @param articleId
+     * @param page
+     * @param rows
+     * @return
+     */
+    IPage<ArticleListVo> relatedTweetPage(Integer userId, String townId, Integer articleId, int page, int rows);
+
+    /**
      * 获取文章收藏数据
      * @param articleId
      * @param userId

+ 34 - 14
mhotel/src/com/happy/service/impl/ArticleTweetImplService.java

@@ -8,6 +8,7 @@ import com.happy.vo.*;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.util.ArrayList;
 import java.util.List;
 
 @Service("ArticleTweetService")
@@ -17,8 +18,8 @@ public class ArticleTweetImplService implements ArticleTweetService {
     public ArticleTweetDao articleTweetDao;
 
     @Override
-    public ArticleTweet queryArticleById(String id) {
-        ArticleTweet num = articleTweetDao.queryArticleById(id);
+    public ArticleTweet queryArticleById(String id, Integer userId) {
+        ArticleTweet num = articleTweetDao.queryArticleById(id, userId);
         return num;
     }
 
@@ -45,7 +46,7 @@ public class ArticleTweetImplService implements ArticleTweetService {
         IPage<HotelVo> iPage = new IPage();
         List<HotelVo> hotelList = articleTweetDao.queryHotelPage(sqlx, page, rows);
         int total = articleTweetDao.queryHotelTotal(sqlx);
-        iPage.setPageList(hotelList);
+        iPage.setPageList(hotelList == null ? new ArrayList<>() : hotelList);
         iPage.setPage(page);
         iPage.setTotalPage((int) Math.ceil((double) total / rows));
         iPage.setRows(rows);
@@ -64,7 +65,7 @@ public class ArticleTweetImplService implements ArticleTweetService {
         IPage<HotelVo> iPage = new IPage();
         List<HotelVo> hotelList = articleTweetDao.queryHotelPageByHotleId(sqlx, page, rows);
         int total = articleTweetDao.queryHotelTotalByHotleId(sqlx);
-        iPage.setPageList(hotelList);
+        iPage.setPageList(hotelList == null ? new ArrayList<>() : hotelList);
         iPage.setPage(page);
         iPage.setTotalPage((int) Math.ceil((double) total / rows));
         iPage.setRows(rows);
@@ -107,7 +108,7 @@ public class ArticleTweetImplService implements ArticleTweetService {
         IPage<ArticleCommentVo> iPage = new IPage();
         List<ArticleCommentVo> commentList = articleTweetDao.queryCommentPageByArticle(articleId, page, rows);
         int total = articleTweetDao.queryCommentTotalByArticle(articleId);
-        iPage.setPageList(commentList);
+        iPage.setPageList(commentList == null ? new ArrayList<>() : commentList);
         iPage.setPage(page);
         iPage.setTotalPage((int) Math.ceil((double) total / rows));
         iPage.setRows(rows);
@@ -132,7 +133,7 @@ public class ArticleTweetImplService implements ArticleTweetService {
         IPage<OwnerArticleVo> iPage = new IPage();
         List<OwnerArticleVo> commentList = articleTweetDao.queryOwnerArticlePage(userId, sqlWhere, page, rows);
         int total = articleTweetDao.queryOwnerArticleTotal(userId, sqlWhere);
-        iPage.setPageList(commentList);
+        iPage.setPageList(commentList == null ? new ArrayList<>() : commentList);
         iPage.setPage(page);
         iPage.setTotalPage((int) Math.ceil((double) total / rows));
         iPage.setRows(rows);
@@ -145,7 +146,20 @@ public class ArticleTweetImplService implements ArticleTweetService {
         IPage<ArticleListVo> iPage = new IPage();
         List<ArticleListVo> commentList = articleTweetDao.queryArticlesPage(townId, userId, type, page, rows);
         int total = articleTweetDao.queryArticlesTotal(townId, userId, type);
-        iPage.setPageList(commentList);
+        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;
+    }
+
+    @Override
+    public IPage<ArticleListVo> relatedTweetPage(Integer userId, String townId, Integer articleId, int page, int rows) {
+        IPage<ArticleListVo> iPage = new IPage();
+        List<ArticleListVo> commentList = articleTweetDao.relatedTweetPage(userId, townId, articleId, page, rows);
+        int total = articleTweetDao.relatedTweetTotal(townId, articleId);
+        iPage.setPageList(commentList == null ? new ArrayList<>() : commentList);
         iPage.setPage(page);
         iPage.setTotalPage((int) Math.ceil((double) total / rows));
         iPage.setRows(rows);
@@ -160,55 +174,61 @@ public class ArticleTweetImplService implements ArticleTweetService {
     }
 
     @Override
-    public int updateArticleCollect(ArticleCollect articleCollect){
+    public int updateArticleCollect(ArticleCollect articleCollect) {
         int result = articleTweetDao.updateArticleCollect(articleCollect);
         return result;
-    };
+    }
+
+    ;
 
     @Override
-    public int insertArticleComment(ArticleComment articleComment){
+    public int insertArticleComment(ArticleComment articleComment) {
         int result = articleTweetDao.insertArticleComment(articleComment);
         return result;
     }
 
     /**
      * 查询用户关注记录数据
+     *
      * @param authorId
      * @param userId
      * @return
      */
-    public UserCollect queryUserCollectNoLose(Integer authorId, Integer userId){
+    public UserCollect queryUserCollectNoLose(Integer authorId, Integer userId) {
         UserCollect result = articleTweetDao.queryUserCollectNoLose(authorId, userId);
         return result;
     }
 
     /**
      * 关注或取消关注操作
+     *
      * @param userCollect
      * @return
      */
-    public int updateUserCollect(UserCollect userCollect){
+    public int updateUserCollect(UserCollect userCollect) {
         int result = articleTweetDao.updateUserCollect(userCollect);
         return result;
     }
 
     /**
      * 查询用户点赞记录数据
+     *
      * @param articleId
      * @param userId
      * @return
      */
-    public ArticleLikes queryArticleLike(Integer articleId, Integer userId){
+    public ArticleLikes queryArticleLike(Integer articleId, Integer userId) {
         ArticleLikes result = articleTweetDao.queryArticleLike(articleId, userId);
         return result;
     }
 
     /**
      * 点赞文章
+     *
      * @param articleLikes
      * @return
      */
-    public int updateArticleLike(ArticleLikes articleLikes){
+    public int updateArticleLike(ArticleLikes articleLikes) {
         int num = articleTweetDao.updateArticleLike(articleLikes);
         return num;
     }

+ 1 - 1
mhotel/src/com/happy/service/impl/WorkflowImplService.java

@@ -51,7 +51,7 @@ public class WorkflowImplService implements WorkflowService {
                     fileInfoList = fileDao.queryList("and link_id = '"+workflow.getLinkId()+"'");
                 }
                 //region
-                //2023-10-11 A-jax????????????
+                //2023-10-11 A-jax添加推文流程数据获取逻辑
                 else if(workflow.getType() == 3){
                     fileInfoList = articleTweetDao.queryList("and link_id = '"+workflow.getLinkId()+"'");
                 }