فهرست منبع

优化个人喜欢和收藏接口

fangqing 2 ماه پیش
والد
کامیت
43f5b447de

+ 41 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/CommunityArticleController.java

@@ -125,6 +125,10 @@ public class CommunityArticleController extends BaseController {
     @Autowired
     private CommunityArticleAtMapper communityArticleAtMapper;
 
+    @Autowired
+    private CommunityArticleRecommendMapper recommendMapper;
+
+
     /**
      * 生成唯一的缓存键(基于请求参数)
      */
@@ -1306,6 +1310,24 @@ public class CommunityArticleController extends BaseController {
         }
         try {
             communityArticleVos = communityArticleService.selectUserLike(userId, pageNum, pageSize, searchType);
+
+            for (CommunityArticleVo communityArticleVo : communityArticleVos) {
+                //判断当前查询用户有没有喜欢该文章
+                CommunityLike like = communityLikeMapper.selectOne(
+                        new QueryWrapper<CommunityLike>()
+                                .eq("user_id", SecurityUtils.getUserId())
+                                .eq("article_id", communityArticleVo.getId()));
+
+                communityArticleVo.setLike(!Objects.isNull(like));
+
+                //判断是否已推荐
+                CommunityArticleRecommend recommend = recommendMapper.selectOne(new QueryWrapper<CommunityArticleRecommend>()
+                        .eq("user_id", SecurityUtils.getUserId())
+                        .eq("article_id", communityArticleVo.getId()).and((wrapper) -> {
+                            wrapper.ne("is_delete", true).or().isNull("is_delete");
+                        }));
+                communityArticleVo.setRecommend(!Objects.isNull(recommend));
+            }
         } catch (Exception e) {
             System.out.println(e.getMessage());
             throw new ProjectException();
@@ -1327,6 +1349,25 @@ public class CommunityArticleController extends BaseController {
                 userId = SecurityUtils.getUserId();
             }
             communityArticleVos = communityArticleService.selectUserCollect(userId, pageNum, pageSize, searchType);
+
+
+            for (CommunityArticleVo communityArticleVo : communityArticleVos) {
+                //判断当前查询用户有没有喜欢该文章
+                CommunityLike like = communityLikeMapper.selectOne(
+                        new QueryWrapper<CommunityLike>()
+                                .eq("user_id", SecurityUtils.getUserId())
+                                .eq("article_id", communityArticleVo.getId()));
+
+                communityArticleVo.setLike(!Objects.isNull(like));
+
+                //判断是否已推荐
+                CommunityArticleRecommend recommend = recommendMapper.selectOne(new QueryWrapper<CommunityArticleRecommend>()
+                        .eq("user_id", SecurityUtils.getUserId())
+                        .eq("article_id", communityArticleVo.getId()).and((wrapper) -> {
+                            wrapper.ne("is_delete", true).or().isNull("is_delete");
+                        }));
+                communityArticleVo.setRecommend(!Objects.isNull(recommend));
+            }
         } catch (Exception e) {
             System.out.println(e.getMessage());
             throw new ProjectException();

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

@@ -1605,7 +1605,7 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
 
     @Override
     public List<CommunityArticleVo> selectUserLike(Long userId, int pageNum, int pageSize, int searchType) {
-        // 查询自己的通知列表
+        // 查询的喜欢列表
         List<CommunityLike> communityUserLike
                 = communityLikeMapper
                 .selectList(new QueryWrapper<CommunityLike>().eq("user_id", userId));
@@ -1624,7 +1624,7 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
 
     @Override
     public List<CommunityArticleVo> selectUserCollect(Long userId, int pageNum, int pageSize, int searchType) {
-        // 查询自己的通知列表
+        // 查询收藏的列表
         List<CommunityArticleCollect> communityArticleCollects
                 = communityArticleCollectMapper
                 .selectList(new QueryWrapper<CommunityArticleCollect>().eq("user_id", userId));