瀏覽代碼

代码优化

fangzhen 4 月之前
父節點
當前提交
07fce0fef2

+ 3 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysProfileController.java

@@ -31,6 +31,7 @@ import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.util.Objects;
+import java.util.concurrent.TimeUnit;
 
 /**
  * 个人信息 业务处理
@@ -233,6 +234,8 @@ public class SysProfileController extends BaseController {
         CommunityUserBlock communityTagBlock = null;
         try {
             communityTagBlock = communityUserBlockService.blockUser(communityUserBlock);
+//            redisCache.setCacheList(CacheConstants.COMMUNITY_USER_BLOCK, communityUserBlockService.list(new QueryWrapper<CommunityUserBlock>()));
+//            redisCache.expire(CacheConstants.COMMUNITY_USER_BLOCK,24, TimeUnit.HOURS);
         } catch (Exception e) {
             throw new ProjectException();
         }

+ 50 - 0
ruoyi-common/src/main/java/com/ruoyi/common/constant/CacheConstants.java

@@ -67,4 +67,54 @@ public class CacheConstants
      * wx的ticket缓存
      */
     public static final String WX_TICKET = "wx_ticket:";
+
+    /**
+     * 用户拉黑数据
+     */
+    public static final String COMMUNITY_USER_BLOCK = "community:user:block";
+
+    /**
+     * 关注数据
+     */
+    public static final String COMMUNITY_USER_LIKE = "community:user:like";
+
+    /**
+     * 文章板块数据
+     */
+    public static final String COMMUNITY_ARTICLE_CLASS = "community:article:class";
+
+    /**
+     * 文章点赞数据
+     */
+    public static final String COMMUNITY_LIKE = "community:like";
+
+    /**
+     * 文章收藏数据
+     */
+    public static final String COMMUNITY_COLLECT = "community:collect";
+
+    /**
+     * 文章推荐数据
+     */
+    public static final String COMMUNITY_ARTICLE_RECOMMEND = "community:article:recommend";
+
+    /**
+     * 中奖信息数据
+     */
+    public static final String COMMUNITY_COMMENT_RAFFLE = "community:comment:raffle";
+
+    /**
+     * 文章标签数据
+     */
+    public static final String COMMUNITY_ARTICLE_TAG = "community:article:tag";
+
+    /**
+     * 文章标签数据
+     */
+    public static final String COMMUNITY_TAG_BLOCK = "community:tag:block";
+
+    /**
+     * 文章标签
+     */
+    public static final String COMMUNITY_TAG = "community:tag";
 }

+ 34 - 4
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/CommunityArticleController.java

@@ -10,6 +10,7 @@ import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.common.core.page.TableDataInfo;
+import com.ruoyi.common.core.redis.RedisCache;
 import com.ruoyi.common.core.text.Convert;
 import com.ruoyi.common.exception.user.ProjectException;
 import com.ruoyi.common.utils.*;
@@ -91,7 +92,6 @@ public class CommunityArticleController extends BaseController {
     @Autowired
     private CommunityCircleExpandMapper communityCircleExpandMapper;
 
-
     @Autowired
     private CommunityUserBlockMapper communityUserBlockMapper;
 
@@ -104,8 +104,24 @@ public class CommunityArticleController extends BaseController {
     @Autowired
     private ISysUserService userService;
 
+    @Autowired
+    private ICommunityArticleTagService communityArticleTagService;
+
+    @Autowired
+    private RedisCache redisCache;
+
     private static final String CACHE_PREFIX = "article:list:"; // 缓存前缀
     private static final long CACHE_EXPIRE_TIME = 30; // 缓存过期时间(分钟)
+    @Autowired
+    private CommunityUserLikeMapper communityUserLikeMapper;
+    @Autowired
+    private CommunityLikeMapper communityLikeMapper;
+    @Autowired
+    private CommunityArticleCollectMapper communityArticleCollectMapper;
+    @Autowired
+    private CommunityArticleRecommendMapper communityArticleRecommendMapper;
+    @Autowired
+    private CommunityArticleTagMapper communityArticleTagMapper;
 
     /**
      * 生成唯一的缓存键(基于请求参数)
@@ -208,7 +224,7 @@ public class CommunityArticleController extends BaseController {
             communityArticleService.editCommunityArticle(communityArticle);
 
         } catch (Exception e) {
-           // e.printStackTrace();
+            // e.printStackTrace();
             System.out.println(e.getMessage());
             throw new ProjectException();
         }
@@ -216,7 +232,7 @@ public class CommunityArticleController extends BaseController {
     }
 
     /**
-     * 发布文章
+     * 删除文章
      */
     @ApiOperation("删除文章")
     @DeleteMapping("/article")
@@ -235,7 +251,10 @@ public class CommunityArticleController extends BaseController {
             int result2 = communityCollectionArticleMapper.update(null, new UpdateWrapper<CommunityCollectionArticle>()
                     .eq("article_id", id)
                     .set("is_delete", true));
-
+            //文章关联的标签删除
+            communityArticleTagService.update(new UpdateWrapper<CommunityArticleTag>()
+                    .set("is_delete", true)
+                    .eq("article_id", id));
             if (result1 && result2 >= 0) {
                 return success("删除成功!");
             }
@@ -395,6 +414,9 @@ public class CommunityArticleController extends BaseController {
                 message = "操作失败!";
                 return AjaxResult.error(message);
             }
+
+//            redisCache.setCacheList(CacheConstants.COMMUNITY_LIKE, communityLikeMapper.selectList(new QueryWrapper<CommunityLike>()));
+//            redisCache.expire(CacheConstants.COMMUNITY_LIKE, 24, TimeUnit.HOURS);
         } catch (Exception e) {
             System.out.println(e.getMessage());
             throw new ProjectException();
@@ -446,6 +468,9 @@ public class CommunityArticleController extends BaseController {
                 message = "操作失败!";
                 return AjaxResult.error(message);
             }
+
+//            redisCache.setCacheList(CacheConstants.COMMUNITY_ARTICLE_RECOMMEND, communityArticleRecommendMapper.selectList(new QueryWrapper<CommunityArticleRecommend>().eq("is_delete", false)));
+//            redisCache.expire(CacheConstants.COMMUNITY_ARTICLE_RECOMMEND, 24, TimeUnit.HOURS);
         } catch (Exception e) {
             System.out.println(e.getMessage());
             throw new ProjectException();
@@ -485,6 +510,9 @@ public class CommunityArticleController extends BaseController {
                 message = "操作失败!";
                 return AjaxResult.error(message);
             }
+
+//            redisCache.setCacheList(CacheConstants.COMMUNITY_COLLECT, communityArticleCollectMapper.selectList(new QueryWrapper<CommunityArticleCollect>()));
+//            redisCache.expire(CacheConstants.COMMUNITY_COLLECT, 24, TimeUnit.HOURS);
         } catch (Exception e) {
             System.out.println(e.getMessage());
             throw new ProjectException();
@@ -684,6 +712,8 @@ public class CommunityArticleController extends BaseController {
             } else {
                 msg = "已关注";
             }
+//            redisCache.setCacheList(CacheConstants.COMMUNITY_USER_LIKE, communityUserLikeMapper.selectList(new QueryWrapper<CommunityUserLike>()));
+//            redisCache.expire(CacheConstants.COMMUNITY_USER_LIKE, 24, TimeUnit.HOURS);
         } catch (Exception e) {
             System.out.println(e.getMessage());
             throw new ProjectException();

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

@@ -4,9 +4,11 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ruoyi.common.annotation.Anonymous;
+import com.ruoyi.common.constant.CacheConstants;
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.domain.entity.SysUser;
+import com.ruoyi.common.core.redis.RedisCache;
 import com.ruoyi.common.core.text.Convert;
 import com.ruoyi.common.exception.user.ProjectException;
 import com.ruoyi.common.utils.*;
@@ -33,6 +35,7 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Objects;
 import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
 /**
@@ -96,6 +99,11 @@ public class CommunityCommentController extends BaseController {
     @Autowired
     private CommunityUserLikeMapper communityUserLikeMapper;
 
+    @Autowired
+    private RedisCache redisCache;
+    @Autowired
+    private CommunityCommentRaffleMapper communityCommentRaffleMapper;
+
     /**
      * 获取文章评论
      */
@@ -383,7 +391,8 @@ public class CommunityCommentController extends BaseController {
         CommunityCommentRaffleVo communityCommentRaffleVos = null;
         try {
             communityCommentRaffleVos = communityArticleService.selectCommentRaffle(articleId);
-
+//            redisCache.setCacheList(CacheConstants.COMMUNITY_COMMENT_RAFFLE, communityCommentRaffleMapper.selectList(new QueryWrapper<CommunityCommentRaffle>().eq("is_delete", false)));
+//            redisCache.expire(CacheConstants.COMMUNITY_COMMENT_RAFFLE, 24, TimeUnit.HOURS);
         } catch (Exception e) {
             System.out.println(e.getMessage());
             throw new ProjectException();

+ 12 - 2
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/CommunityTagController.java

@@ -2,13 +2,14 @@ package com.ruoyi.generator.controller;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.ruoyi.common.constant.CacheConstants;
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.core.redis.RedisCache;
 import com.ruoyi.common.exception.user.ProjectException;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.StringUtils;
-import com.ruoyi.generator.domain.Community.CommunityArticleRecommend;
 import com.ruoyi.generator.domain.Community.CommunityTag;
 import com.ruoyi.generator.domain.Community.CommunityTagBlock;
 import com.ruoyi.generator.mapper.community.CommunityTagBlockMapper;
@@ -25,6 +26,7 @@ import org.springframework.web.bind.annotation.*;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Objects;
+import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
 /**
@@ -46,6 +48,9 @@ public class CommunityTagController extends BaseController {
     @Autowired
     private CommunityTagMapper communityTagMapper;
 
+    @Autowired
+    private RedisCache redisCache;
+
     /**
      * 获取标签信息
      */
@@ -164,6 +169,10 @@ public class CommunityTagController extends BaseController {
                 return AjaxResult.error("标签名称重复");
             }
             communityTagService.save(communityTag);
+//            redisCache.setCacheList(CacheConstants.COMMUNITY_TAG, communityTagMapper
+//                    .selectList(new QueryWrapper<CommunityTag>()
+//                    .eq("is_delete", false)));
+//            redisCache.expire(CacheConstants.COMMUNITY_TAG, 24, TimeUnit.HOURS);
         } catch (Exception e) {
             System.out.println(e.getMessage());
             throw new ProjectException();
@@ -191,7 +200,8 @@ public class CommunityTagController extends BaseController {
             System.out.println(e.getMessage());
             throw new ProjectException();
         }
-
+//        redisCache.setCacheList(CacheConstants.COMMUNITY_TAG_BLOCK, communityTagBlockMapper.selectList(new QueryWrapper<CommunityTagBlock>()));
+//        redisCache.expire(CacheConstants.COMMUNITY_TAG_BLOCK, 24, TimeUnit.HOURS);
         return AjaxResult.success(communityTagBlock);
     }
 }

+ 279 - 5
ruoyi-generator/src/main/java/com/ruoyi/generator/service/CommunityArticleServiceImpl.java

@@ -5,8 +5,10 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.common.constant.CacheConstants;
 import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.common.core.page.TableDataInfo;
+import com.ruoyi.common.core.redis.RedisCache;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.bean.BeanUtils;
@@ -14,11 +16,11 @@ import com.ruoyi.common.utils.ip.AddressUtils;
 import com.ruoyi.generator.domain.Community.*;
 import com.ruoyi.generator.mapper.community.*;
 import com.ruoyi.generator.vo.*;
-import com.ruoyi.system.domain.CommunityChatMsg;
 import com.ruoyi.system.mapper.SysUserMapper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 
 import java.net.HttpURLConnection;
@@ -29,6 +31,7 @@ import java.time.ZoneId;
 import java.time.temporal.ChronoUnit;
 import java.util.*;
 import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
 import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 
@@ -123,6 +126,10 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
 
     @Autowired
     private CommunityArticleCircleMapper communityArticleCircleMapper;
+    @Autowired
+    private RedisCache redisCache;
+    @Autowired
+    private RedisTemplate<Object, Object> redisTemplate;
 
     /**
      * 查询文章列表
@@ -355,6 +362,273 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
         return communityArticleVos;
     }
 
+    /**
+     * 查询文章列表
+     *
+     * @param communityArticle 文章信息
+     * @return 文章信息集合
+     */
+    @Override
+    public List<CommunityArticleVo> selectCommunityArticleList1(Long userId, TableDataInfo rspData, CommunityArticle communityArticle, int pageNum, int pageSize, int searchType) {
+
+        List<CommunityArticleVo> communityArticleVos = null;
+        //找出板块下的分类
+        List<Long> classIds = communityArticle.getClassIds();
+        Long id = communityArticle.getId();
+        List<Long> articleIds = communityArticle.getArticleIds();
+        Integer pageTagType = communityArticle.getPageTagType();
+        Integer noCollection = communityArticle.getNoCollection();
+        if (pageTagType != null && pageTagType == 1) {
+            List<CommunityUserLikeVo> communityUserLikeVos = selectCommunityUserLikeList(SecurityUtils.getUserId(), null, 1, 999999, 1);
+            if (communityUserLikeVos.isEmpty()) {
+                return null;
+            }
+            List<Long> likeUserIds = communityUserLikeVos.stream().map(CommunityUserLikeVo::getLikeUserId).collect(Collectors.toList());
+            communityArticle.setUserIds(likeUserIds);
+        }
+
+        if (Objects.nonNull(id)) {
+            //获取指定文章详细内容,文章浏览量+1
+            CommunityArticle article = communityArticleMapper.selectById(id);
+            article.setPageViews(article.getPageViews() + 1);
+            communityArticleMapper.updateById(article);
+        }
+
+        if (articleIds != null && !articleIds.isEmpty()) {
+            for (Long articleId : articleIds) {
+                //获取指定文章详细内容,文章浏览量+1
+                CommunityArticle article = communityArticleMapper.selectById(articleId);
+                article.setPageViews(article.getPageViews() + 1);
+                communityArticleMapper.updateById(article);
+            }
+        }
+
+        //根据分类查找文章
+        int offset = (pageNum - 1) * pageSize;
+        communityArticleVos = communityArticleMapper.selectCommunityArticleList(communityArticle, classIds, offset, pageSize, searchType, userId);
+
+        List<CommunityArticleVo> articleVos_copy = new ArrayList<>(communityArticleVos);
+        if (noCollection != null) {
+            if (noCollection == 1) {
+                //剔除是否有合集文章
+                List<Long> ids = communityArticleVos.stream().map(CommunityArticleVo::getId).collect(Collectors.toList());
+                if (!ids.isEmpty()) {
+                    List<CommunityCollectionArticle> collections = communityCollectionArticleMapper.selectList(new QueryWrapper<CommunityCollectionArticle>()
+                            .in("article_id", ids)
+                            .and((wrapper) -> {
+                                wrapper.ne("is_delete", true).or().isNull("is_delete");
+                            }));
+
+                    for (CommunityArticleVo communityArticleVo : articleVos_copy) {
+                        for (CommunityCollectionArticle collection : collections) {
+                            if (collection.getArticleId().equals(communityArticleVo.getId())) {
+                                communityArticleVos.remove(communityArticleVo);
+                            }
+                        }
+                    }
+                }
+            }
+        }
+
+        //数据拉取区域
+        //判断当前文章是否被用户拉黑
+        //用户拉黑数据
+        List<CommunityUserBlock> communityUserBlocks = redisCache.getCacheList(CacheConstants.COMMUNITY_USER_BLOCK);
+        if (communityUserBlocks.isEmpty()) {
+            communityUserBlocks = communityUserBlockMapper.selectList(new QueryWrapper<CommunityUserBlock>());
+            redisCache.setCacheList(CacheConstants.COMMUNITY_USER_BLOCK, communityUserBlocks);
+            redisCache.expire(CacheConstants.COMMUNITY_USER_BLOCK, 24, TimeUnit.HOURS);
+        }
+
+        //关注数据
+        List<CommunityUserLike> communityUserLikes = redisCache.getCacheList(CacheConstants.COMMUNITY_USER_LIKE);
+        if (communityUserLikes.isEmpty()) {
+            communityUserLikes = communityUserLikeMapper.selectList(new QueryWrapper<CommunityUserLike>());
+            redisCache.setCacheList(CacheConstants.COMMUNITY_USER_LIKE, communityUserLikes);
+            redisCache.expire(CacheConstants.COMMUNITY_USER_LIKE, 24, TimeUnit.HOURS);
+        }
+
+        //文章板块数据
+        List<CommunityArticleClass> communityArticleClasses = redisCache.getCacheList(CacheConstants.COMMUNITY_ARTICLE_CLASS);
+        if (communityArticleClasses.isEmpty()) {
+            communityArticleClasses = communityArticleCircleMapper.selectList(new QueryWrapper<CommunityArticleClass>().eq("is_delete", false));
+            redisCache.setCacheList(CacheConstants.COMMUNITY_ARTICLE_CLASS, communityArticleClasses);
+            redisCache.expire(CacheConstants.COMMUNITY_ARTICLE_CLASS, 24, TimeUnit.HOURS);
+        }
+
+        //文章点赞数据
+        List<CommunityLike> communityLikes = redisCache.getCacheList(CacheConstants.COMMUNITY_LIKE);
+        if (communityLikes.isEmpty()) {
+            communityLikes = communityLikeMapper.selectList(new QueryWrapper<CommunityLike>());
+            redisCache.setCacheList(CacheConstants.COMMUNITY_LIKE, communityLikes);
+            redisCache.expire(CacheConstants.COMMUNITY_LIKE, 24, TimeUnit.HOURS);
+        }
+
+        //文章收藏数据
+        List<CommunityArticleCollect> communityArticleCollects = redisCache.getCacheList(CacheConstants.COMMUNITY_COLLECT);
+        if (communityArticleCollects.isEmpty()) {
+            communityArticleCollects = communityCollectMapper.selectList(new QueryWrapper<CommunityArticleCollect>());
+            redisCache.setCacheList(CacheConstants.COMMUNITY_COLLECT, communityArticleCollects);
+            redisCache.expire(CacheConstants.COMMUNITY_COLLECT, 24, TimeUnit.HOURS);
+        }
+
+        //文章推荐数据
+        List<CommunityArticleRecommend> communityArticleRecommends = redisCache.getCacheList(CacheConstants.COMMUNITY_ARTICLE_RECOMMEND);
+        if (communityArticleRecommends.isEmpty()) {
+            communityArticleRecommends = recommendMapper.selectList(new QueryWrapper<CommunityArticleRecommend>().eq("is_delete", false));
+            redisCache.setCacheList(CacheConstants.COMMUNITY_ARTICLE_RECOMMEND, communityArticleRecommends);
+            redisCache.expire(CacheConstants.COMMUNITY_ARTICLE_RECOMMEND, 24, TimeUnit.HOURS);
+        }
+
+        //中奖信息数据
+        List<CommunityCommentRaffle> communityCommentRaffles = redisCache.getCacheList(CacheConstants.COMMUNITY_COMMENT_RAFFLE);
+        if (communityCommentRaffles.isEmpty()) {
+            communityCommentRaffles = communityCommentRaffleMapper.selectList(new QueryWrapper<CommunityCommentRaffle>().eq("is_delete", false));
+            redisCache.setCacheList(CacheConstants.COMMUNITY_COMMENT_RAFFLE, communityCommentRaffles);
+            redisCache.expire(CacheConstants.COMMUNITY_COMMENT_RAFFLE, 24, TimeUnit.HOURS);
+        }
+
+        //文章标签数据
+        List<CommunityArticleTag> communityArticleTags = redisCache.getCacheList(CacheConstants.COMMUNITY_ARTICLE_TAG);
+        if (communityArticleTags.isEmpty()) {
+            communityArticleTags = communityArticleTagMapper.selectList(new QueryWrapper<CommunityArticleTag>().eq("is_delete", false));
+            redisCache.setCacheList(CacheConstants.COMMUNITY_ARTICLE_TAG, communityArticleTags);
+            redisCache.expire(CacheConstants.COMMUNITY_ARTICLE_TAG, 24, TimeUnit.HOURS);
+        }
+
+        //文章标签拉黑数据
+        List<CommunityTagBlock> communityTagBlocks = redisCache.getCacheList(CacheConstants.COMMUNITY_TAG_BLOCK);
+        if (communityTagBlocks.isEmpty()) {
+            communityTagBlocks = communityTagBlockMapper.selectList(new QueryWrapper<CommunityTagBlock>());
+            redisCache.setCacheList(CacheConstants.COMMUNITY_TAG_BLOCK, communityTagBlocks);
+            redisCache.expire(CacheConstants.COMMUNITY_TAG_BLOCK, 24, TimeUnit.HOURS);
+        }
+
+        //文章标签
+        List<CommunityTag> communityTags = redisCache.getCacheList(CacheConstants.COMMUNITY_TAG);
+        if (communityTags.isEmpty()) {
+            communityTags = communityTagMapper.selectList(new QueryWrapper<CommunityTag>().eq("is_delete", false));
+            redisCache.setCacheList(CacheConstants.COMMUNITY_TAG, communityTags);
+            redisCache.expire(CacheConstants.COMMUNITY_TAG, 24, TimeUnit.HOURS);
+        }
+
+        rspData.setTotal(communityArticleVos.size());
+        List<CommunityArticleVo> communityArticleVos_copy = new ArrayList<>(communityArticleVos);
+        List<CommunityArticleImages> videoList = new ArrayList<>();
+        for (CommunityArticleVo articleVo : communityArticleVos_copy) {
+            //判断当前文章是否被用户拉黑
+            communityUserBlocks
+                    .stream()
+                    .filter(item -> item.getUserId().equals(userId) && item.getPeerId().equals(articleVo.getUserId()))
+                    .findFirst()
+                    .ifPresent(communityUserBlock -> articleVo.setBlock(communityUserBlock.isBlock()));
+
+            //获取文章是否被关注
+            communityUserLikes
+                    .stream()
+                    .filter(item -> item.getUserId().equals(userId) && item.getLikeUserId().equals(articleVo.getUserId()))
+                    .findFirst()
+                    .ifPresent(communityUserLike -> articleVo.setCare(communityUserLike.getUserId() != null));
+
+            //设置文章的板块 提取 classId,并转换成 List<Long>
+            List<CommunityArticleClass> communityArticleClassList = communityArticleClasses
+                    .stream()
+                    .filter(item ->
+                            item.getArticleId().equals(articleVo.getId()) && !item.getIsDelete()).collect(Collectors.toList());
+            classIds = communityArticleClassList
+                    .stream()
+                    .map(CommunityArticleClass::getClassId)
+                    .collect(Collectors.toList());
+            articleVo.setClassIds(classIds);
+
+            List<Map<String, Object>> imageList = articleVo.getImageList();
+            List<Map<String, Object>> imageList_copy = new ArrayList<>(imageList);
+            CommunityArticleImages videos = null;
+            for (Map<String, Object> image : imageList_copy) {
+                String imageUrl = image.get("imageUrl").toString();
+                //判断是否是视频
+                boolean isVideo = isVideoFile(imageUrl);
+                if (isVideo) {
+                    imageList.remove(image);
+                    videos = JSONObject.parseObject(JSONObject.toJSONString(image), CommunityArticleImages.class);
+                    //BeanUtils.copyProperties(image, videos);
+                    videoList.add(videos);
+                }
+            }
+            articleVo.setVideoList(videoList);
+
+            //设置评论回复数量
+            articleVo.setCommentCount(communityArticleCommentMapper.queryCommentCount(articleVo.getId()));
+            //设置文章的点赞数量
+            articleVo.setLikeCount((int) communityLikes.stream().filter(item -> item.getArticleId().equals(articleVo.getId())).count());
+            //设置文章的收藏数量
+            articleVo.setCollectCount((int) communityArticleCollects.stream().filter(item -> item.getArticleId().equals(articleVo.getId())).count());
+            //设置文章推荐数量
+            articleVo.setRecommendCount((int) communityArticleRecommends.stream().filter(item -> item.getArticleId().equals(articleVo.getId()) && !item.isDelete()).count());
+            //设置文章所属合集
+            articleVo.setCollectionVo(communityCollectionMapper.selectCollectById(userId, articleVo.getId()));
+
+            //设置中奖信息
+            CommunityCommentRaffleVo communityCommentRaffleVo = new CommunityCommentRaffleVo();
+            communityCommentRaffles
+                    .stream()
+                    .filter(item -> item.getArticleId().equals(articleVo.getId()) && !item.isDelete())
+                    .findFirst()
+                    .ifPresent(communityCommentRaffle -> {
+                        BeanUtils.copyProperties(communityCommentRaffle, communityCommentRaffleVo);
+                        CommunityUserInfoVo communityUserInfoVo = communityArticleService.selectCommunityUserInfoById(communityCommentRaffle.getUserId());
+                        communityCommentRaffleVo.setUserName(communityUserInfoVo.getNickName());
+                        communityCommentRaffleVo.setUserAvatar(communityUserInfoVo.getAvatar());
+                        articleVo.setCommentRaffleVo(communityCommentRaffleVo);
+                    });
+
+            //判断是否已收藏
+            List<CommunityArticleCollect> collects = communityArticleCollects.stream().filter(item -> item.getUserId().equals(userId) && item.getArticleId().equals(articleVo.getId())).collect(Collectors.toList());
+            articleVo.setCollect(!collects.isEmpty());
+
+            //判断是否已点赞
+            List<CommunityLike> likes = communityLikes.stream().filter(item -> item.getUserId().equals(userId) && item.getArticleId().equals(articleVo.getId())).collect(Collectors.toList());
+            articleVo.setLike(!likes.isEmpty());
+
+            //判断是否已推荐
+            List<CommunityArticleRecommend> recommends = communityArticleRecommends.stream().filter(item -> item.getUserId().equals(userId) && item.getArticleId().equals(articleVo.getId()) && !item.isDelete()).collect(Collectors.toList());
+            articleVo.setRecommend(!recommends.isEmpty());
+
+            //获取文章标签
+            List<CommunityArticleTag> articleTags = communityArticleTags.stream().filter(item -> item.getArticleId().equals(articleVo.getId()) && !item.getIsDelete()).collect(Collectors.toList());
+            List<Long> tagList = articleTags.stream().map(CommunityArticleTag::getTagId).collect(Collectors.toList());
+            List<Long> tagIds = new ArrayList<>();
+
+            if (!tagList.isEmpty()) {
+                //判断当前标签是否被当前登录用户拉黑
+                List<CommunityTagBlock> communityTagBlockList = communityTagBlocks
+                        .stream()
+                        .filter(item -> tagList.contains(item.getTagId()) && item.getUserId().equals(userId))
+                        .collect(Collectors.toList());
+                for (CommunityTagBlock tagBlock : communityTagBlockList) {
+                    if (tagBlock.isBlock()) {
+                        communityArticleVos.remove(articleVo);
+                        break;
+                    }
+                    tagIds.add(tagBlock.getTagId());
+                }
+
+                if (communityTagBlockList.isEmpty()) {
+                    tagIds.addAll(tagList);
+                }
+
+                if (!tagIds.isEmpty()) {
+                    List<CommunityTag> communityTagList = communityTags
+                            .stream()
+                            .filter(item -> tagIds.contains(item.getId()))
+                            .collect(Collectors.toList());
+                    articleVo.setTags(communityTagList);
+                }
+            }
+        }
+        return communityArticleVos;
+    }
+
     /**
      * 发布文章
      *
@@ -531,7 +805,7 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
                             wrapper.ne("is_delete", true).or().isNull("is_delete");
                         })));
                 //不为空就不操作
-                if (communityArticleTag  == null ){
+                if (communityArticleTag == null) {
                     tagLog = new CommunityArticleTag();
                     tagLog.setArticleId(communityArticle.getId());
                     tagLog.setTagId(Long.parseLong(tag));
@@ -615,7 +889,7 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
                     null,
                     new UpdateWrapper<CommunityCollectionArticle>()
                             .eq("article_id", communityArticle.getId())
-                            .eq("create_by",userId)
+                            .eq("create_by", userId)
                             .set("is_delete", true)
                             .and((wrapper) -> {
                                 wrapper.ne("is_delete", 1).or().isNull("is_delete");
@@ -1254,7 +1528,7 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
     }
 
     @Override
-    public List<CommunityArticleVo> selectUserLike(Long userId,int pageNum, int pageSize, int searchType) {
+    public List<CommunityArticleVo> selectUserLike(Long userId, int pageNum, int pageSize, int searchType) {
         // 查询自己的通知列表
         List<CommunityLike> communityUserLike
                 = communityLikeMapper
@@ -1273,7 +1547,7 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
     }
 
     @Override
-    public List<CommunityArticleVo> selectUserCollect(Long userId,int pageNum, int pageSize, int searchType) {
+    public List<CommunityArticleVo> selectUserCollect(Long userId, int pageNum, int pageSize, int searchType) {
         // 查询自己的通知列表
         List<CommunityArticleCollect> communityArticleCollects
                 = communityArticleCollectMapper

+ 10 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/service/CommunityArticleTagImpl.java

@@ -0,0 +1,10 @@
+package com.ruoyi.generator.service;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.generator.domain.Community.CommunityArticleTag;
+import com.ruoyi.generator.mapper.community.CommunityArticleTagMapper;
+import org.springframework.stereotype.Service;
+
+@Service
+public class CommunityArticleTagImpl extends ServiceImpl<CommunityArticleTagMapper, CommunityArticleTag> implements ICommunityArticleTagService {
+}

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

@@ -23,6 +23,14 @@ public interface ICommunityArticleService extends IService<CommunityArticle> {
      */
     List<CommunityArticleVo> selectCommunityArticleList(Long userId,TableDataInfo rspData,CommunityArticle communityArticle, int pageNum, int pageSize, int searchType);
 
+    /**
+     * 查询文章列表
+     *
+     * @param communityArticle 文章信息
+     * @return 文章信息集合
+     */
+    List<CommunityArticleVo> selectCommunityArticleList1(Long userId,TableDataInfo rspData,CommunityArticle communityArticle, int pageNum, int pageSize, int searchType);
+
     /**
      * 发布文章
      *

+ 7 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/service/ICommunityArticleTagService.java

@@ -0,0 +1,7 @@
+package com.ruoyi.generator.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.ruoyi.generator.domain.Community.CommunityArticleTag;
+
+public interface ICommunityArticleTagService extends IService<CommunityArticleTag> {
+}

+ 3 - 2
ruoyi-generator/src/main/resources/mapper/community/CommunityArticleCommentMapper.xml

@@ -6,11 +6,12 @@
     <select id="queryCommentCount" resultType="java.lang.Integer">
         select d.commentCount + d.replyCount
         from (select c.article_id,
-                     count(1)                            as commentCount,
+                     count(1)                 as commentCount,
                      (select count(1) as replyCount
                       from community_article_comment a
                                left join community_comment_reply b on a.id = b.comment_id
-                      where a.article_id = #{articleId} and  b.is_delete != 1) as replyCount
+                      where a.article_id = #{articleId}
+                        and b.is_delete != 1) as replyCount
               from community_article_comment c
               where c.article_id = #{articleId}) as d
     </select>