Ver Fonte

修改回去文章和发送短信息

fangzhen há 7 meses atrás
pai
commit
4ffca80f98

+ 1 - 1
ruoyi-generator/src/main/java/com/ruoyi/generator/domain/Community/CommunityArticle.java

@@ -60,7 +60,7 @@ public class CommunityArticle implements Serializable {
      * 圈子id
      */
     @ApiModelProperty("圈子id")
-    private Long circle_id;
+    private Long circleId;
 
     /**
      * 文章内容

+ 1 - 1
ruoyi-generator/src/main/java/com/ruoyi/generator/domain/Community/CommunityArticleImages.java

@@ -39,7 +39,7 @@ public class CommunityArticleImages implements Serializable {
      * 图片地址
      */
     @ApiModelProperty("图片地址")
-    @TableField("images_url")
+    @TableField("image_url")
     private String imageUrl;
 
 

+ 168 - 80
ruoyi-generator/src/main/java/com/ruoyi/generator/service/CommunityArticleServiceImpl.java

@@ -19,8 +19,10 @@ import java.net.HttpURLConnection;
 import java.net.URL;
 import java.text.ParseException;
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Objects;
+import java.util.stream.Collectors;
 
 /**
  * 业务 服务层实现
@@ -87,96 +89,171 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
         //找出板块下的分类
         Long classId = communityArticle.getClassId();
         Long userId = SecurityUtils.getUserId();
-        List<CommunityClassCircle> classCircles = communityClassCircleMapper.selectList(new QueryWrapper<CommunityClassCircle>().eq("class_id", classId));
-        List<Long> circleIds = new ArrayList<>();
-        for (CommunityClassCircle classCircle : classCircles) {
-            circleIds.add(classCircle.getCircleId());
+        List<Long> circleIds = null;
+        if (!Objects.isNull(classId)) {
+            List<CommunityClassCircle> classCircles = communityClassCircleMapper.selectList(new QueryWrapper<CommunityClassCircle>().eq("class_id", classId));
+            circleIds = new ArrayList<>();
+            for (CommunityClassCircle classCircle : classCircles) {
+                circleIds.add(classCircle.getCircleId());
+            }
         }
-        List<CommunityArticleVo> communityArticleVos = new ArrayList<>();
-        if (!classCircles.isEmpty()) {
-            int offset = (pageNum - 1) * pageSize;
-            communityArticleVos = communityArticleMapper.selectCommunityArticleList(communityArticle, circleIds, offset, pageSize);
-            for (CommunityArticleVo articleVo : communityArticleVos) {
-                List<CommunityArticleImages> imageList = articleVo.getImageList();
-                List<CommunityArticleImages> videoList = new ArrayList<>();
-                CommunityArticleImages videos = null;
-                for (CommunityArticleImages image : imageList) {
-                    videos = new CommunityArticleImages();
-                    String imageUrl = image.getImageUrl();
-                    //判断是否是视频
-                    boolean isVideo = isVideoFile(imageUrl);
-                    if (isVideo) {
-                        imageList.remove(image);
-                        BeanUtils.copyProperties(image, videos);
-                        videoList.add(videos);
-                    }
-                }
-                articleVo.setVideoList(videoList);
-
-                //设置文章的点赞数量
-                articleVo.setLikeCount(communityLikeMapper
-                        .selectList(new QueryWrapper<CommunityLike>()
-                                .eq("article_id", articleVo.getId()))
-                        .size());
 
-                articleVo.setCollectCount(communityCollectMapper
-                        .selectList(new QueryWrapper<CommunityArticleCollect>()
-                                .eq("article_id", articleVo.getId()))
-                        .size());
-
-                //文章下的评论
-                List<CommunityArticleCommentVo> comments = articleVo.getComments();
-                for (CommunityArticleCommentVo communityArticleCommentVo : comments) {
-                    //获取评论的用户信息
-                    SysUser sysUser = sysUserMapper.selectUserById(communityArticleCommentVo.getUserId());
-                    communityArticleCommentVo.setUsername(sysUser.getUserName());
-                    communityArticleCommentVo.setAvatar(sysUser.getAvatar());
-                    //当前登录用户是否已点赞
-                    List<CommunityCommentLike> commentLikes = communityCommentLikeMapper
-                            .selectList(new QueryWrapper<CommunityCommentLike>()
-                                    .eq("comment_id", communityArticleCommentVo.getId()).eq("user_id", userId));
-                    communityArticleCommentVo.setCommentLike(!commentLikes.isEmpty());
-
-                    //该评论的点赞数量
-                    communityArticleCommentVo.setCommentLikeCount(communityCommentLikeMapper
-                            .selectList(new QueryWrapper<CommunityCommentLike>()
-                                    .eq("comment_id", communityArticleCommentVo.getId()))
-                            .size());
-                }
-
-                //判断是否已收藏
-                CommunityArticleCollect collect = communityCollectMapper
-                        .selectOne(new QueryWrapper<CommunityArticleCollect>()
-                                .eq("user_id", userId)
-                                .eq("article_id", articleVo.getId()));
-                articleVo.setCollect(!Objects.isNull(collect));
-
-                //判断是否已点赞
-                CommunityLike like = communityLikeMapper
-                        .selectOne(new QueryWrapper<CommunityLike>()
-                                .eq("user_id", userId)
-                                .eq("article_id", articleVo.getId()));
-                articleVo.setLike(!Objects.isNull(like));
-
-                //获取文章标签
-                List<CommunityArticleTag> articleTags = communityArticleTagMapper
-                        .selectList(new QueryWrapper<CommunityArticleTag>()
-                                .eq("article_id", articleVo.getId()));
-                List<Long> tagIds = new ArrayList<>();
-                for (CommunityArticleTag articleTag : articleTags) {
-                    tagIds.add(articleTag.getTagId());
+        //根据分类查找文章
+        int offset = (pageNum - 1) * pageSize;
+        List<CommunityArticleVo> communityArticleVos = communityArticleMapper.selectCommunityArticleList(communityArticle, circleIds, offset, pageSize);
+        for (CommunityArticleVo articleVo : communityArticleVos) {
+            List<CommunityArticleImages> imageList = articleVo.getImageList();
+            List<CommunityArticleImages> videoList = new ArrayList<>();
+            CommunityArticleImages videos = null;
+            for (CommunityArticleImages image : imageList) {
+                videos = new CommunityArticleImages();
+                String imageUrl = image.getImageUrl();
+                //判断是否是视频
+                boolean isVideo = isVideoFile(imageUrl);
+                if (isVideo) {
+                    imageList.remove(image);
+                    BeanUtils.copyProperties(image, videos);
+                    videoList.add(videos);
                 }
+            }
+            articleVo.setVideoList(videoList);
+
+            //设置文章的点赞数量
+            articleVo.setLikeCount(communityLikeMapper
+                    .selectList(new QueryWrapper<CommunityLike>()
+                            .eq("article_id", articleVo.getId()))
+                    .size());
+
+            articleVo.setCollectCount(communityCollectMapper
+                    .selectList(new QueryWrapper<CommunityArticleCollect>()
+                            .eq("article_id", articleVo.getId()))
+                    .size());
+
+            //文章下的评论
+            List<CommunityArticleCommentVo> comments = articleVo.getComments();
+            for (CommunityArticleCommentVo communityArticleCommentVo : comments) {
+                //获取评论的用户信息
+                SysUser sysUser = sysUserMapper.selectUserById(communityArticleCommentVo.getUserId());
+                communityArticleCommentVo.setUsername(sysUser.getUserName());
+                communityArticleCommentVo.setAvatar(sysUser.getAvatar());
+                //当前登录用户是否已点赞
+                List<CommunityCommentLike> commentLikes = communityCommentLikeMapper
+                        .selectList(new QueryWrapper<CommunityCommentLike>()
+                                .eq("comment_id", communityArticleCommentVo.getId()).eq("user_id", userId));
+                communityArticleCommentVo.setCommentLike(!commentLikes.isEmpty());
+
+                //该评论的点赞数量
+                communityArticleCommentVo.setCommentLikeCount(communityCommentLikeMapper
+                        .selectList(new QueryWrapper<CommunityCommentLike>()
+                                .eq("comment_id", communityArticleCommentVo.getId()))
+                        .size());
+            }
 
-                if (!tagIds.isEmpty()) {
-                    List<CommunityTag> communityTags = communityTagMapper.selectBatchIds(tagIds);
-                    articleVo.setTags(communityTags);
-                }
+            //判断是否已收藏
+            CommunityArticleCollect collect = communityCollectMapper
+                    .selectOne(new QueryWrapper<CommunityArticleCollect>()
+                            .eq("user_id", userId)
+                            .eq("article_id", articleVo.getId()));
+            articleVo.setCollect(!Objects.isNull(collect));
+
+            //判断是否已点赞
+            CommunityLike like = communityLikeMapper
+                    .selectOne(new QueryWrapper<CommunityLike>()
+                            .eq("user_id", userId)
+                            .eq("article_id", articleVo.getId()));
+            articleVo.setLike(!Objects.isNull(like));
+
+            //获取文章标签
+            List<CommunityArticleTag> articleTags = communityArticleTagMapper
+                    .selectList(new QueryWrapper<CommunityArticleTag>()
+                            .eq("article_id", articleVo.getId()));
+            List<Long> tagIds = new ArrayList<>();
+            for (CommunityArticleTag articleTag : articleTags) {
+                tagIds.add(articleTag.getTagId());
+            }
 
+            if (!tagIds.isEmpty()) {
+                List<CommunityTag> communityTags = communityTagMapper.selectBatchIds(tagIds);
+                articleVo.setTags(communityTags);
             }
         }
         return communityArticleVos;
     }
 
+//    @Override
+//    public List<CommunityArticleVo> selectCommunityArticleList1(CommunityArticle communityArticle, int pageNum, int pageSize) {
+//        Long classId = communityArticle.getClassId();
+//        Long userId = SecurityUtils.getUserId();
+//        List<Long> circleIds = null;
+//
+//        // 获取分类圈子ID
+//        if (classId != null) {
+//            circleIds = communityClassCircleMapper.getCircleIdsByClassId(classId);
+//        }
+//
+//        // 使用分页和偏移量查询文章
+//        int offset = (pageNum - 1) * pageSize;
+//        List<CommunityArticleVo> communityArticleVos = communityArticleMapper.selectCommunityArticleList(communityArticle, circleIds, offset, pageSize);
+//
+//        // 批量获取文章ID列表
+//        List<Long> articleIds = communityArticleVos.stream().map(CommunityArticleVo::getId).collect(Collectors.toList());
+//
+//        if (!articleIds.isEmpty()) {
+//            // 批量查询点赞、收藏、评论等相关信息,减少单次查询
+//            Map<Long, Integer> likeCounts = communityLikeMapper.getLikeCountsByArticleIds(articleIds);
+//            Map<Long, Integer> collectCounts = communityCollectMapper.getCollectCountsByArticleIds(articleIds);
+//            Map<Long, List<CommunityArticleImages>> imagesMap = communityArticleImagesMapper.getImagesByArticleIds(articleIds);
+//            Map<Long, List<CommunityArticleCommentVo>> commentsMap = communityArticleCommentMapper.getCommentsByArticleIds(articleIds);
+//
+//            // 批量获取用户是否点赞/收藏信息
+//            Map<Long, Boolean> userLikes = communityLikeMapper.getUserLikesByArticleIds(userId, articleIds);
+//            Map<Long, Boolean> userCollects = communityCollectMapper.getUserCollectsByArticleIds(userId, articleIds);
+//
+//            for (CommunityArticleVo articleVo : communityArticleVos) {
+//                Long articleId = articleVo.getId();
+//
+//                // 设置文章的点赞和收藏数量
+//                articleVo.setLikeCount(likeCounts.getOrDefault(articleId, 0));
+//                articleVo.setCollectCount(collectCounts.getOrDefault(articleId, 0));
+//
+//                // 设置用户点赞/收藏状态
+//                articleVo.setLike(userLikes.getOrDefault(articleId, false));
+//                articleVo.setCollect(userCollects.getOrDefault(articleId, false));
+//
+//                // 设置图片和视频
+//                List<CommunityArticleImages> imageList = imagesMap.get(articleId);
+//                List<CommunityArticleImages> videoList = new ArrayList<>();
+//                if (imageList != null) {
+//                    for (Iterator<CommunityArticleImages> iterator = imageList.iterator(); iterator.hasNext(); ) {
+//                        CommunityArticleImages image = iterator.next();
+//                        if (isVideoFile(image.getImageUrl())) {
+//                            videoList.add(image);
+//                            iterator.remove();
+//                        }
+//                    }
+//                }
+//                articleVo.setImageList(imageList);
+//                articleVo.setVideoList(videoList);
+//
+//                // 设置评论信息
+//                List<CommunityArticleCommentVo> comments = commentsMap.get(articleId);
+//                if (comments != null) {
+//                    for (CommunityArticleCommentVo comment : comments) {
+//                        // 设置评论的用户信息及点赞状态
+//                        SysUser sysUser = sysUserMapper.selectUserById(comment.getUserId());
+//                        comment.setUsername(sysUser.getUserName());
+//                        comment.setAvatar(sysUser.getAvatar());
+//                        comment.setCommentLike(communityCommentLikeMapper.isUserLikedComment(comment.getId(), userId));
+//                        comment.setCommentLikeCount(communityCommentLikeMapper.getCommentLikeCount(comment.getId()));
+//                    }
+//                    articleVo.setComments(comments);
+//                }
+//            }
+//        }
+//        return communityArticleVos;
+//    }
+
+
 
     /**
      * 发布文章
@@ -412,6 +489,17 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
                 .selectList(new QueryWrapper<CommunityUserLike>()
                         .eq("like_user_id", userId)).size());
         communityUserInfoVo.setCompanionCount(0);
+
+        //设置是否被当前登录的用户关注
+        communityUserInfoVo.setLike(false);
+        Long loginUserId = SecurityUtils.getLoginUser().getUserId();
+        if (!Objects.equals(userId, loginUserId)) {
+            CommunityUserLike communityUserLike = communityUserLikeMapper.selectOne(new QueryWrapper<CommunityUserLike>().eq("user_id", loginUserId).eq("like_user_id", userId));
+            if (!Objects.isNull(communityUserLike) && !Objects.isNull(communityUserLike.getId())) {
+                communityUserInfoVo.setLike(true);
+            }
+        }
+
         return communityUserInfoVo;
     }
 

+ 1 - 1
ruoyi-generator/src/main/java/com/ruoyi/generator/service/ICommunityArticleService.java

@@ -23,7 +23,7 @@ public interface ICommunityArticleService extends IService<CommunityArticle> {
      * @return 文章信息集合
      */
     List<CommunityArticleVo> selectCommunityArticleList(CommunityArticle communityArticle, int pageNum, int pageSize);
-
+    //List<CommunityArticleVo> selectCommunityArticleList1(CommunityArticle communityArticle, int pageNum, int pageSize);
     /**
      * 发布文章
      *

+ 7 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/vo/CommunityUserInfoVo.java

@@ -1,5 +1,6 @@
 package com.ruoyi.generator.vo;
 
+import com.fasterxml.jackson.annotation.JsonFormat;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
@@ -52,6 +53,10 @@ public class CommunityUserInfoVo implements Serializable {
      * 陪伴数量
      */
     private int companionCount;
+    /**
+     * 是否被关注
+     */
+    private boolean isLike;
     /**
     * 创建人
     */
@@ -61,6 +66,7 @@ public class CommunityUserInfoVo implements Serializable {
     * 创建时间
     */
     @ApiModelProperty("创建时间")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private Date createTime;
     /**
     * 更新人
@@ -71,5 +77,6 @@ public class CommunityUserInfoVo implements Serializable {
     * 更新时间
     */
     @ApiModelProperty("更新时间")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private Date updateTime;
 }

+ 24 - 15
ruoyi-generator/src/main/resources/mapper/community/ArticleMapper.xml

@@ -108,25 +108,33 @@
         a.create_time as article_create_time,
         a.update_by as article_update_by,
         a.update_time as article_update_time,
-        b.id as image_id,
-        b.article_id as images_article_id,
-        b.image_url as image_url,
-        b.create_by as images_create_by,
-        b.create_time as images_create_time,
-        b.update_by as images_update_by,
-        b.update_time as images_update_time,
+        JSON_ARRAYAGG(
+        JSON_OBJECT(
+        'image_id', b.id,
+        'images_article_id',b.article_id,
+        'image_url',b.image_url,
+        'images_create_by',b.create_by,
+        'images_create_time',b.create_time,
+        'images_update_by',b.update_by,
+        'images_update_time',b.update_time
+        )
+        ) as images,
         c.user_name as user_name,
         c.nick_name as nick_name,
         c.email as email,
         c.avatar as avatar,
-        d.id as comment_id,
-        d.article_id as comment_article_id,
-        d.user_id as comment_user_id,
-        d.content as comment_content,
-        d.create_by as comment_create_by,
-        d.create_time as comment_create_time,
-        d.update_by as comment_update_by,
-        d.update_time as comment_update_time
+        JSON_ARRAYAGG(
+        JSON_OBJECT(
+        'comment_id',d.id,
+        'comment_article_id',d.article_id,
+        'comment_user_id',d.user_id,
+        'comment_content',d.content,
+        'comment_create_by',d.create_by,
+        'comment_create_time',d.create_time,
+        'comment_update_by',d.update_by,
+        'comment_update_time',d.update_time
+        )
+        ) as comments
         from
         community_article a
         left join community_article_images b on a.id = b.article_id
@@ -149,6 +157,7 @@
                 AND a.user_id = #{communityArticle.userId}
             </if>
         </where>
+        group by a.id
         limit #{offset},#{limit}
     </select>