Jelajahi Sumber

[feat]
添加分页

limeng 3 bulan lalu
induk
melakukan
0e31be8b80

+ 13 - 5
application-webadmin/src/main/java/com/tourism/webadmin/app/website/controller/TravelNotesCommentController.java

@@ -1,15 +1,18 @@
 package com.tourism.webadmin.app.website.controller;
 
+import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
 import com.tourism.common.additional.config.ApplicationConfig;
 import com.tourism.common.additional.utils.UrlConvertUtils;
 import com.tourism.common.core.annotation.MyRequestBody;
 import com.tourism.common.core.constant.ErrorCodeEnum;
 import com.tourism.common.core.object.MyOrderParam;
+import com.tourism.common.core.object.MyPageData;
 import com.tourism.common.core.object.ResponseResult;
 import com.tourism.common.core.object.TokenData;
 import com.tourism.common.core.util.MyCommonUtil;
 import com.tourism.common.core.util.MyModelUtil;
+import com.tourism.common.core.util.MyPageUtil;
 import com.tourism.common.log.annotation.OperationLog;
 import com.tourism.common.log.model.constant.SysOperationLogType;
 import com.tourism.webadmin.app.website.dto.TravelNotesCommentToWebDto;
@@ -17,6 +20,7 @@ import com.tourism.webadmin.back.dto.TourTravelNotesCommentDto;
 import com.tourism.webadmin.back.model.TourTravelNotesComment;
 import com.tourism.webadmin.back.service.TourTravelNotesCommentService;
 import com.tourism.webadmin.back.vo.TourTravelNotesCommentVo;
+import com.tourism.webadmin.back.vo.TourismProjectTravelNotesWriteVo;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -132,18 +136,22 @@ public class TravelNotesCommentController {
      */
 //    @SaIgnore
     @GetMapping("/my-comments")
-    public ResponseResult<List<TourTravelNotesCommentVo>> myComments(TravelNotesCommentToWebDto dto) {
+    public ResponseResult<MyPageData<TourTravelNotesCommentVo>> myComments(TravelNotesCommentToWebDto dto) {
         if(dto.getCommentType() == null){
             return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
         }
 
-        List<TourTravelNotesComment> myTravelNoteComments = tourTravelNotesCommentService.getMyTravelNoteComments(dto.getCommentType());
-        myTravelNoteComments.forEach(e->{
+        List<TourTravelNotesComment> list = tourTravelNotesCommentService.getMyTravelNoteComments(dto);
+        list.forEach(e->{
             Map<String, Object> travelNoteDictMap = e.getTravelNoteDictMap();
-            String url = (String)travelNoteDictMap.get(e.getTravelNoteId());
+            String url = null;
+            if(travelNoteDictMap != null){
+                url = (String)travelNoteDictMap.get(e.getTravelNoteId());
+            }
             e.setTravelNoteUrl(UrlConvertUtils.urlConvertSingle(applicationConfig.getHostIpPort(), url));
         });
-        return ResponseResult.success(MyModelUtil.copyCollectionTo(myTravelNoteComments, TourTravelNotesCommentVo.class));
+        MyPageData<TourTravelNotesCommentVo> tourTravelNotesCommentVoMyPageData = MyPageUtil.makeResponseData(list, TourTravelNotesCommentVo.class);
+        return ResponseResult.success(tourTravelNotesCommentVoMyPageData);
     }
 
     private ResponseResult<Void> doDelete(Long id) {

+ 4 - 3
application-webadmin/src/main/java/com/tourism/webadmin/back/service/TourTravelNotesCommentService.java

@@ -1,5 +1,7 @@
 package com.tourism.webadmin.back.service;
 
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.tourism.webadmin.app.website.dto.TravelNotesCommentToWebDto;
 import com.tourism.webadmin.back.model.*;
 import com.tourism.common.core.base.service.IBaseService;
 
@@ -92,9 +94,8 @@ public interface TourTravelNotesCommentService extends IBaseService<TourTravelNo
 
     /**
      * 我的评论列表
-     * @param userId
-     * @param commentType
+     * @param dto
      * @return
      */
-    List<TourTravelNotesComment> getMyTravelNoteComments(Integer commentType);
+    List<TourTravelNotesComment> getMyTravelNoteComments(TravelNotesCommentToWebDto dto);
 }

+ 15 - 7
application-webadmin/src/main/java/com/tourism/webadmin/back/service/impl/TourTravelNotesCommentServiceImpl.java

@@ -3,7 +3,8 @@ package com.tourism.webadmin.back.service.impl;
 import cn.hutool.core.collection.CollUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
-import com.github.pagehelper.Page;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.tourism.common.core.base.dao.BaseDaoMapper;
 import com.tourism.common.core.base.service.BaseService;
 import com.tourism.common.core.constant.GlobalDeletedFlag;
@@ -12,6 +13,7 @@ import com.tourism.common.core.object.TokenData;
 import com.tourism.common.core.util.MyCommonUtil;
 import com.tourism.common.core.util.MyModelUtil;
 import com.tourism.common.sequence.wrapper.IdGeneratorWrapper;
+import com.tourism.webadmin.app.website.dto.TravelNotesCommentToWebDto;
 import com.tourism.webadmin.back.dao.TourTravelNotesCommentMapper;
 import com.tourism.webadmin.back.model.TourTravelNotesComment;
 import com.tourism.webadmin.back.model.constant.TravelNotesCommentType;
@@ -146,7 +148,12 @@ public class TourTravelNotesCommentServiceImpl extends BaseService<TourTravelNot
     }
 
     @Override
-    public List<TourTravelNotesComment> getMyTravelNoteComments(Integer commentType) {
+    public List<TourTravelNotesComment> getMyTravelNoteComments(TravelNotesCommentToWebDto dto) {
+        // 构建IPage分页参数
+//        IPage<TourTravelNotesComment> page = new IPage<TourTravelNotesComment>(dto.getPageNum(), dto.getPageSize());
+//
+//        Page<TourTravelNotesComment> page = new Page<>(dto.getPageNum(), dto.getPageSize());
+
         // 获取当前登录用户id
         TokenData tokenData = TokenData.takeFromRequest();
         Long userId = tokenData.getUserId();
@@ -154,7 +161,6 @@ public class TourTravelNotesCommentServiceImpl extends BaseService<TourTravelNot
         List<Long> myTravelNoteIds = tourismProjectTravelNotesWriteService.getMyTravelNoteIds(userId);
 
         LambdaQueryWrapper<TourTravelNotesComment> queryWrapper = new LambdaQueryWrapper<>();
-//        queryWrapper.eq(TourTravelNotesComment::getDataState, GlobalDeletedFlag.NORMAL);
         Long[] noteIds = myTravelNoteIds.toArray(new Long[myTravelNoteIds.size()]);
         // 如果没有写过游记,随便给个值应付一下,因为这里如果到表达式里去处理太麻烦了,且不易懂
         if(noteIds == null || noteIds.length == 0) {
@@ -163,16 +169,16 @@ public class TourTravelNotesCommentServiceImpl extends BaseService<TourTravelNot
         Long[] finalNoteIds = noteIds;
         // 查询收到的评论,我的游记评论和直接回复我的评论
         // 查询发出的评论,create_user = userId
-        if(commentType == TravelNotesCommentType.ALL_COMMENTS){
+        if(dto.getCommentType() == TravelNotesCommentType.ALL_COMMENTS){
             queryWrapper.and(
                     i->i
                             .or(j->j.in(TourTravelNotesComment::getTravelNoteId, finalNoteIds))
                             .or(j->j.eq(TourTravelNotesComment::getReplyUserId, userId))
                             .or(j->j.eq(TourTravelNotesComment::getCreateUserId, userId))
             );
-        }else if(commentType == TravelNotesCommentType.COMMENTS_POSTED){
+        }else if(dto.getCommentType() == TravelNotesCommentType.COMMENTS_POSTED){
             queryWrapper.eq(TourTravelNotesComment::getCreateUserId, userId);
-        }else if(commentType == TravelNotesCommentType.RECEIVED_COMMENTS){
+        }else if(dto.getCommentType() == TravelNotesCommentType.RECEIVED_COMMENTS){
             queryWrapper.and(
                     i->i
                             .or(j->j.in(TourTravelNotesComment::getTravelNoteId, finalNoteIds))
@@ -181,7 +187,9 @@ public class TourTravelNotesCommentServiceImpl extends BaseService<TourTravelNot
             queryWrapper.ne(TourTravelNotesComment::getCreateUserId, userId);
         }
         queryWrapper.orderByDesc(TourTravelNotesComment::getUpdateTime);
-        List<TourTravelNotesComment> resultList = tourTravelNotesCommentMapper.selectList(queryWrapper);
+//        IPage<TourTravelNotesComment> pageData = tourTravelNotesCommentMapper.selectPage(new Page<>(dto.getPageNum(), dto.getPageSize()), queryWrapper);
+
+        List<TourTravelNotesComment> resultList = tourTravelNotesCommentMapper.selectList(new Page<>(dto.getPageNum(), dto.getPageSize()), queryWrapper);
         int batchSize = resultList instanceof Page ? 0 : 1000;
         this.buildRelationForDataList(resultList, MyRelationParam.normal(), batchSize);
         return resultList;