Эх сурвалжийг харах

优化代码(用户合集增加分页)

fangqing 5 сар өмнө
parent
commit
215566b75d

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

@@ -757,7 +757,9 @@ public class CommunityArticleController extends BaseController {
         if (Objects.isNull(userId)) {
             return AjaxResult.error("参数异常!");
         }
-
+        int pageNum = Convert.toInt(ServletUtils.getParameter("pageNum"), 1);
+        int pageSize = Convert.toInt(ServletUtils.getParameter("pageSize"), 10);
+        int searchType = Convert.toInt(ServletUtils.getParameter("searchType"), 0);
 //        List<CommunityCollection> collections = communityCollectionService.list(new QueryWrapper<CommunityCollection>()
 //                .eq("user_id", userId)
 //                .ne("is_delete", true)
@@ -766,7 +768,7 @@ public class CommunityArticleController extends BaseController {
 
         List<CommunityCollectionVo> communityCollectionVos = null;
         try {
-            communityCollectionVos = communityCollectionService.selectUserCollection(userId, articleId);
+            communityCollectionVos = communityCollectionService.selectUserCollection(userId, articleId,pageNum,pageSize,searchType);
         } catch (Exception e) {
             System.out.println(e.getMessage());
             throw new ProjectException();
@@ -1033,8 +1035,6 @@ public class CommunityArticleController extends BaseController {
     @ApiOperation("获取个人中心信息")
     @GetMapping("/userPrompt")
     public AjaxResult userPrompt(Long userId) {
-
-
         List<CommunityUserPromptVo> communityUserPromptVo = null;
         try {
             communityUserPromptVo = communityArticleService.selectCommunityUserPrompt(userId);
@@ -1051,13 +1051,9 @@ public class CommunityArticleController extends BaseController {
         int pageNum = Convert.toInt(ServletUtils.getParameter("pageNum"), 1);
         int pageSize = Convert.toInt(ServletUtils.getParameter("pageSize"), 10);
         int searchType = Convert.toInt(ServletUtils.getParameter("searchType"), 0);
-
-        TableDataInfo rspData = null;
-        CommunityArticle communityArticle  = new CommunityArticle();
         List<CommunityArticleVo> communityArticleVos = null;
         try {
             communityArticleVos = communityArticleService.selectUserLike(pageNum, pageSize, searchType);
-
         } catch (Exception e) {
             System.out.println(e.getMessage());
             throw new ProjectException();
@@ -1072,8 +1068,6 @@ public class CommunityArticleController extends BaseController {
         int pageSize = Convert.toInt(ServletUtils.getParameter("pageSize"), 10);
         int searchType = Convert.toInt(ServletUtils.getParameter("searchType"), 0);
 
-        TableDataInfo rspData = null;
-        CommunityArticle communityArticle  = new CommunityArticle();
         List<CommunityArticleVo> communityArticleVos = null;
         try {
             communityArticleVos = communityArticleService.selectUserCollect(pageNum, pageSize, searchType);

+ 5 - 1
ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/community/CommunityCollectionMapper.java

@@ -16,7 +16,11 @@ public interface CommunityCollectionMapper extends BaseMapper<CommunityCollectio
      * @param userId 用户id
      * @return 用户合集信息
      */
-    List<CommunityCollectionVo> selectUserCollection(@Param("userId") Long userId, @Param("articleId") Long articleId);
+    List<CommunityCollectionVo> selectUserCollection(@Param("userId") Long userId,
+                                                     @Param("articleId") Long articleId,
+                                                     @Param("offset") int offset,
+                                                     @Param("limit") int limit,
+                                                     @Param("searchType") int searchType);
 
     /**
      * 获取文章对应的合集信息

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

@@ -258,8 +258,9 @@ public class CommunityCollectionServiceImpl extends ServiceImpl<CommunityCollect
     }
 
     @Override
-    public List<CommunityCollectionVo> selectUserCollection(Long userId, Long articleId) {
-        List<CommunityCollectionVo> communityCollectionVos = communityCollectionMapper.selectUserCollection(userId, articleId);
+    public List<CommunityCollectionVo> selectUserCollection(Long userId, Long articleId, int pageNum, int pageSize, int searchType) {
+        int offset = (pageNum - 1) * pageSize;
+        List<CommunityCollectionVo> communityCollectionVos = communityCollectionMapper.selectUserCollection(userId, articleId, offset, pageSize, searchType);
         for (CommunityCollectionVo communityCollectionVo : communityCollectionVos) {
             JSONArray objects = selectArticleInfoInCollection(communityCollectionVo.getId(), 1L);
             Long articleNumber =  0L;

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

@@ -42,5 +42,5 @@ public interface ICommunityCollectionService extends IService<CommunityCollectio
      * @param userId 用户id
      * @return 用户合集信息
      */
-    List<CommunityCollectionVo> selectUserCollection(Long userId,Long articleId);
+    List<CommunityCollectionVo> selectUserCollection(Long userId,Long articleId, int pageNum, int pageSize, int searchType);
 }

+ 9 - 1
ruoyi-generator/src/main/resources/mapper/community/CommunityCollectionMapper.xml

@@ -4,6 +4,7 @@
         "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.ruoyi.generator.mapper.community.CommunityCollectionMapper">
     <select id="selectUserCollection" resultType="com.ruoyi.generator.vo.CommunityCollectionVo">
+        select id,user_id,collection_name,collection_profile,images,is_delete,articleCount,pageViews,create_by,update_by,create_time,update_time,isFollow  from (
         SELECT a.id,
         a.user_id,
         a.collection_name,
@@ -70,8 +71,15 @@
         a.update_by,
         a.create_time,
         a.update_time
+        ) A
+        <if test="searchType == 1">
+            order by a.create_time desc
+        </if>
 
-
+        <if test="searchType == 2">
+            order by a.page_views desc
+        </if>
+        limit #{offset},#{limit}
     </select>