浏览代码

优化获取文章回复时间排序
新增文章删除功能

fangzhen 6 月之前
父节点
当前提交
ab9181a8dc

+ 23 - 2
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/CommunityArticleController.java

@@ -1,6 +1,7 @@
 package com.ruoyi.generator.controller;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.page.TableDataInfo;
@@ -106,6 +107,27 @@ public class CommunityArticleController extends BaseController {
         return AjaxResult.success("文章发布成功!");
     }
 
+    /**
+     * 发布文章
+     */
+    @ApiOperation("删除文章")
+    @DeleteMapping("/article")
+    @Transactional
+    //@Anonymous
+    public AjaxResult article(String id) {
+        if (Strings.isEmpty(id)) {
+            return AjaxResult.error("参数异常!");
+        }
+
+        CommunityArticle communityArticle = new CommunityArticle();
+        communityArticle.setIsDelete(true);
+        boolean result = communityArticleService.update(communityArticle, new UpdateWrapper<CommunityArticle>().eq("id", id));
+        if (result) {
+            return success("删除成功!");
+        }
+        return error("删除失败!");
+    }
+
 
     @GetMapping("/class")
     @ApiOperation("获取文章分类列表")
@@ -632,7 +654,7 @@ public class CommunityArticleController extends BaseController {
     /**
      * 获取通知权限
      *
-     * @param userId  用户ID
+     * @param userId 用户ID
      * @return
      */
     @ApiOperation("获取通知权限")
@@ -643,5 +665,4 @@ public class CommunityArticleController extends BaseController {
     }
 
 
-
 }

+ 1 - 1
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/CommunityCommentController.java

@@ -135,7 +135,7 @@ public class CommunityCommentController extends BaseController {
         Page<CommunityCommentReply> page = new Page<>(currentPage, limit);
         List<CommunityCommentReply> replies = communityCommentReplyService.page(page, new QueryWrapper<CommunityCommentReply>().eq("comment_id", commentId).and((wrapper) -> {
             wrapper.ne("is_delete", true).or().isNull("is_delete");
-        }).orderByDesc("create_time")).getRecords();
+        }).orderByAsc("create_time")).getRecords();
         CommunityCommentReplyVo replyVo = null;
         List<CommunityCommentReplyVo> replyVos = new ArrayList<>();
         for (final CommunityCommentReply reply : replies) {

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

@@ -114,6 +114,12 @@ public class CommunityArticle implements Serializable {
     @ApiModelProperty("浏览量")
     private long pageViews;
 
+    /**
+     * 是否已删除
+     */
+    @ApiModelProperty("是否已删除")
+    private Boolean isDelete;
+
     /**
      * 创建者
      */

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

@@ -93,165 +93,6 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
     @Autowired
     private CommunityUserNotificationMapper communityUserNotificationMapper;
 
-//    @Override
-//    public List<CommunityArticleVo> selectCommunityArticleList(CommunityArticle communityArticle, int pageNum, int pageSize, int searchType) {
-//        Long userId = SecurityUtils.getUserId();
-//
-//        // 处理文章浏览量
-//        updateArticlePageViews(communityArticle.getId());
-//
-//        // 获取圈子IDs
-//        List<Long> circleIds = getCircleIds(communityArticle.getClassId(), communityArticle.getCircleId());
-//        if (circleIds.isEmpty()) {
-//            return new ArrayList<>();
-//        }
-//
-//        // 查询文章列表
-//        int offset = (pageNum - 1) * pageSize;
-//        List<CommunityArticleVo> articleVos = communityArticleMapper.selectCommunityArticleList(
-//                communityArticle, circleIds, offset, pageSize, searchType);
-//
-//        // 批量处理文章数据
-//        return processArticleVos(articleVos, circleIds, userId);
-//    }
-
-    private void updateArticlePageViews(Long articleId) {
-        if (Objects.nonNull(articleId)) {
-            CommunityArticle article = communityArticleMapper.selectById(articleId);
-            article.setPageViews(article.getPageViews() + 1);
-            communityArticleMapper.updateById(article);
-        }
-    }
-
-    private List<Long> getCircleIds(Long classId, Long circleId) {
-        if (Objects.nonNull(circleId)) {
-            return Collections.singletonList(circleId);
-        }
-
-        if (Objects.nonNull(classId)) {
-            return communityClassCircleMapper.selectList(
-                            new QueryWrapper<CommunityClassCircle>().eq("class_id", classId))
-                    .stream()
-                    .map(CommunityClassCircle::getCircleId)
-                    .collect(Collectors.toList());
-        }
-
-        return new ArrayList<>();
-    }
-
-    private List<CommunityArticleVo> processArticleVos(List<CommunityArticleVo> articleVos, List<Long> circleIds, Long userId) {
-        List<CommunityArticleVo> result = new ArrayList<>(articleVos);
-
-        for (CommunityArticleVo articleVo : result) {
-            articleVo.setCircleIds(circleIds);
-
-            // 处理图片和视频
-            processMediaList(articleVo);
-
-            // 设置计数
-            setArticleCounts(articleVo);
-
-            // 设置用户交互状态
-            setUserInteractionStatus(articleVo, userId);
-
-            // 处理文章标签
-            if (!processArticleTags(articleVo, userId)) {
-                result.remove(articleVo);
-            }
-        }
-
-        return result;
-    }
-
-    private void processMediaList(CommunityArticleVo articleVo) {
-        List<Map<String, Object>> imageList = articleVo.getImageList();
-        List<CommunityArticleImages> videoList = new ArrayList<>();
-
-        Iterator<Map<String, Object>> iterator = imageList.iterator();
-        while (iterator.hasNext()) {
-            Map<String, Object> image = iterator.next();
-            String imageUrl = image.get("imageUrl").toString();
-
-            if (isVideoFile(imageUrl)) {
-                iterator.remove();
-                CommunityArticleImages video = new CommunityArticleImages();
-                BeanUtils.copyProperties(image, video);
-                videoList.add(video);
-            }
-        }
-
-        articleVo.setVideoList(videoList);
-    }
-
-    private void setArticleCounts(CommunityArticleVo articleVo) {
-        Long articleId = articleVo.getId();
-
-        // 使用单个查询获取所有计数
-        articleVo.setLikeCount(communityLikeMapper.selectCount(
-                new QueryWrapper<CommunityLike>().eq("article_id", articleId)).intValue());
-
-        articleVo.setCollectCount(communityCollectMapper.selectCount(
-                new QueryWrapper<CommunityArticleCollect>().eq("article_id", articleId)).intValue());
-
-        articleVo.setRecommendCount(recommendMapper.selectCount(
-                new QueryWrapper<CommunityArticleRecommend>()
-                        .eq("article_id", articleId)
-                        .and(wrapper -> wrapper.ne("is_delete", true).or().isNull("is_delete"))).intValue());
-    }
-
-    private void setUserInteractionStatus(CommunityArticleVo articleVo, Long userId) {
-        Long articleId = articleVo.getId();
-
-        articleVo.setCollect(communityCollectMapper.exists(
-                new QueryWrapper<CommunityArticleCollect>()
-                        .eq("user_id", userId)
-                        .eq("article_id", articleId)));
-
-        articleVo.setLike(communityLikeMapper.exists(
-                new QueryWrapper<CommunityLike>()
-                        .eq("user_id", userId)
-                        .eq("article_id", articleId)));
-
-        articleVo.setRecommend(recommendMapper.exists(
-                new QueryWrapper<CommunityArticleRecommend>()
-                        .eq("user_id", userId)
-                        .eq("article_id", articleId)
-                        .and(wrapper -> wrapper.ne("is_delete", true).or().isNull("is_delete"))));
-    }
-
-    private boolean processArticleTags(CommunityArticleVo articleVo, Long userId) {
-        List<CommunityArticleTag> articleTags = communityArticleTagMapper.selectList(
-                new QueryWrapper<CommunityArticleTag>().eq("article_id", articleVo.getId()));
-
-        List<Long> tagIds = articleTags.stream()
-                .map(CommunityArticleTag::getTagId)
-                .collect(Collectors.toList());
-
-        if (tagIds.isEmpty()) {
-            return true;
-        }
-
-        // 检查标签是否被拉黑
-        List<CommunityTagBlock> tagBlocks = communityTagBlockMapper.selectList(
-                new QueryWrapper<CommunityTagBlock>()
-                        .in("tag_id", tagIds)
-                        .eq("user_id", userId));
-
-        if (tagBlocks.stream().anyMatch(CommunityTagBlock::isBlock)) {
-            return false;
-        }
-
-        List<Long> validTagIds = tagBlocks.isEmpty() ? tagIds :
-                tagBlocks.stream().map(CommunityTagBlock::getTagId).collect(Collectors.toList());
-
-        if (!validTagIds.isEmpty()) {
-            List<CommunityTag> communityTags = communityTagMapper.selectBatchIds(validTagIds);
-            articleVo.setTags(communityTags);
-        }
-
-        return true;
-    }
-
     /**
      * 查询文章列表
      *
@@ -406,6 +247,7 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
         communityArticle.setUserId(userId);
         communityArticle.setCreateBy(userId);
         communityArticle.setUpdateBy(userId);
+        communityArticle.setIsDelete(false);
         communityArticle.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
         communityArticle.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
         communityArticleMapper.insert(communityArticle);

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

@@ -134,29 +134,29 @@
         c.nick_name as nick_name,
         c.email as email,
         c.avatar as avatar
-#         COALESCE((
-#         SELECT
-#         JSON_ARRAYAGG(
-#         CASE
-#         WHEN d.id IS NOT NULL THEN
-#         JSON_OBJECT(
-#         'id', IFNULL(d.id,''),
-#         'articleId', IFNULL(d.article_id,''),
-#         'userId', IFNULL(d.user_id,''),
-#         'content', IFNULL(d.content,''),
-#         'createBy', IFNULL(d.create_by,''),
-#         'createTime', IFNULL(DATE_FORMAT(d.create_time,'%Y-%m-%d %H:%i:%s'),''),
-#         'updateBy', IFNULL(d.update_by,''),
-#         'updateTime', IFNULL(DATE_FORMAT(d.update_time,'%Y-%m-%d %H:%i:%s'),'')
-#         )
-#         ELSE NULL
-#         END
-#         )
-#         FROM
-#         community_article_comment d
-#         WHERE
-#         d.article_id = a.id and d.is_delete != 1 order by d.create_time desc
-#         ), '[]') AS comments
+        # COALESCE((
+        # SELECT
+        # JSON_ARRAYAGG(
+        # CASE
+        # WHEN d.id IS NOT NULL THEN
+        # JSON_OBJECT(
+        # 'id', IFNULL(d.id,''),
+        # 'articleId', IFNULL(d.article_id,''),
+        # 'userId', IFNULL(d.user_id,''),
+        # 'content', IFNULL(d.content,''),
+        # 'createBy', IFNULL(d.create_by,''),
+        # 'createTime', IFNULL(DATE_FORMAT(d.create_time,'%Y-%m-%d %H:%i:%s'),''),
+        # 'updateBy', IFNULL(d.update_by,''),
+        # 'updateTime', IFNULL(DATE_FORMAT(d.update_time,'%Y-%m-%d %H:%i:%s'),'')
+        # )
+        # ELSE NULL
+        # END
+        # )
+        # FROM
+        # community_article_comment d
+        # WHERE
+        # d.article_id = a.id and d.is_delete != 1 order by d.create_time desc
+        # ), '[]') AS comments
         from
         community_article a
         left join sys_user c on a.user_id = c.user_id
@@ -178,6 +178,7 @@
             <if test="communityArticle.userId != null and communityArticle.userId != ''">
                 AND a.user_id = #{communityArticle.userId}
             </if>
+            and (is_delete != 1 or is_delete is null)
         </where>
         group by a.id,a.create_time
         <if test="searchType == 1">