Browse Source

修改代码结构

fangzhen 9 months ago
parent
commit
c0bb237bb4

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

@@ -34,7 +34,7 @@ public class CommunityArticleController extends BaseController
      */
      */
     @ApiOperation("获取文章列表")
     @ApiOperation("获取文章列表")
     @GetMapping("/list")
     @GetMapping("/list")
-    @Anonymous
+    //@Anonymous
     public TableDataInfo genList(CommunityArticle communityArticle)
     public TableDataInfo genList(CommunityArticle communityArticle)
     {
     {
         startPage();
         startPage();

+ 5 - 3
ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/community/CommunityArticleMapper.java

@@ -5,6 +5,7 @@ import com.ruoyi.generator.domain.Community.CommunityArticleCollect;
 import com.ruoyi.generator.domain.Community.CommunityLike;
 import com.ruoyi.generator.domain.Community.CommunityLike;
 import com.ruoyi.generator.vo.CommunityArticleVo;
 import com.ruoyi.generator.vo.CommunityArticleVo;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
 
 
 import java.util.List;
 import java.util.List;
 
 
@@ -31,15 +32,16 @@ public interface CommunityArticleMapper {
      * @param articleId 文章id
      * @param articleId 文章id
      * @return 文章收藏信息
      * @return 文章收藏信息
      */
      */
-    CommunityArticleCollect selectCommunityArticleCollectById(Long userId, Long articleId);
+    CommunityArticleCollect selectCommunityArticleCollectById(@Param("userId") Long userId, @Param("articleId") Long articleId);
 
 
     /**
     /**
      * 获取该用户是否已点赞该文章
      * 获取该用户是否已点赞该文章
-     * @param userId 用户id
+     *
+     * @param userId    用户id
      * @param articleId 文章id
      * @param articleId 文章id
      * @return 文章点赞信息
      * @return 文章点赞信息
      */
      */
-    CommunityLike selectCommunityArticleLikeById(Long userId, Long articleId);
+    CommunityLike selectCommunityArticleLikeById(@Param("userId") Long userId, @Param("articleId") Long articleId);
 }
 }
 
 
 
 

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

@@ -42,6 +42,7 @@ public class CommunityArticleServiceImpl implements ICommunityArticleService {
     public List<CommunityArticleVo> selectCommunityArticleList(CommunityArticle communityArticle) {
     public List<CommunityArticleVo> selectCommunityArticleList(CommunityArticle communityArticle) {
         List<CommunityArticleVo> communityArticleVos = communityArticleMapper.selectCommunityArticleList(communityArticle);
         List<CommunityArticleVo> communityArticleVos = communityArticleMapper.selectCommunityArticleList(communityArticle);
         CommunityArticleVo communityArticleVo = null;
         CommunityArticleVo communityArticleVo = null;
+        Long userId = SecurityUtils.getUserId();
         for (int i = 0; i < communityArticleVos.size(); i++) {
         for (int i = 0; i < communityArticleVos.size(); i++) {
             communityArticleVo = communityArticleVos.get(i);
             communityArticleVo = communityArticleVos.get(i);
             //文章下的评论
             //文章下的评论
@@ -53,11 +54,11 @@ public class CommunityArticleServiceImpl implements ICommunityArticleService {
                 communityArticleCommentVo.setAvatar(sysUser.getAvatar());
                 communityArticleCommentVo.setAvatar(sysUser.getAvatar());
 
 
                 //判断是否已收藏
                 //判断是否已收藏
-                CommunityArticleCollect collect = communityArticleMapper.selectCommunityArticleCollectById(SecurityUtils.getUserId(), communityArticleCommentVo.getArticleId());
+                CommunityArticleCollect collect = communityArticleMapper.selectCommunityArticleCollectById(userId, communityArticleCommentVo.getArticleId());
                 communityArticleVo.setCollect(!Objects.isNull(collect));
                 communityArticleVo.setCollect(!Objects.isNull(collect));
 
 
                 //判断是否已点赞
                 //判断是否已点赞
-                CommunityLike like = communityArticleMapper.selectCommunityArticleLikeById(SecurityUtils.getUserId(), communityArticleCommentVo.getArticleId());
+                CommunityLike like = communityArticleMapper.selectCommunityArticleLikeById(userId, communityArticleCommentVo.getArticleId());
                 communityArticleVo.setLike(!Objects.isNull(like));
                 communityArticleVo.setLike(!Objects.isNull(like));
             }
             }
         }
         }

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

@@ -141,10 +141,10 @@
         select collect_id, article_id, user_id, create_by, create_time, update_by, update_time from
         select collect_id, article_id, user_id, create_by, create_time, update_by, update_time from
         community_article_collect
         community_article_collect
         <where>
         <where>
-            <if test="user_id != null and user_id != '">
+            <if test="userId != null and userId != ''">
                 user_id = #{userId}
                 user_id = #{userId}
             </if>
             </if>
-            <if test="article_id != null and article_id != '">
+            <if test="articleId != null and articleId != ''">
                 and article_id = #{articleId}
                 and article_id = #{articleId}
             </if>
             </if>
         </where>
         </where>
@@ -154,10 +154,10 @@
         select like_id, article_id, user_id, create_by, create_time, update_by, update_time from
         select like_id, article_id, user_id, create_by, create_time, update_by, update_time from
         community_like
         community_like
         <where>
         <where>
-            <if test="user_id != null and user_id != '">
+            <if test="userId != null and userId != ''">
                 user_id = #{userId}
                 user_id = #{userId}
             </if>
             </if>
-            <if test="article_id != null and article_id != '">
+            <if test="articleId != null and articleId != ''">
                 and article_id = #{articleId}
                 and article_id = #{articleId}
             </if>
             </if>
         </where>
         </where>