Forráskód Böngészése

获取聊天记录接口增加分页

fangqing 3 hónapja
szülő
commit
310919e87f

+ 9 - 2
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/CommunityChatMsgController.java

@@ -5,9 +5,11 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 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.text.Convert;
 import com.ruoyi.common.exception.user.ProjectException;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.common.utils.ServletUtils;
 import com.ruoyi.common.utils.bean.BeanUtils;
 import com.ruoyi.generator.domain.Community.CommunityReturnRecord;
 import com.ruoyi.generator.domain.Community.CommunityUserBlock;
@@ -63,6 +65,11 @@ public class CommunityChatMsgController extends BaseController {
     public AjaxResult chatRecord(Long otherUserId, String type) {
         Long userId = SecurityUtils.getUserId();
         List<CommunityChatMsgVo> chatMsgVos = new ArrayList<>();
+        int pageNum = Convert.toInt(ServletUtils.getParameter("pageNum"), 1);
+        int pageSize = Convert.toInt(ServletUtils.getParameter("pageSize"), 10);
+        int offset = (pageNum - 1) * pageSize;
+
+
         try {
             List<CommunityUserBlock> communityUserBlocks = communityUserBlockMapper.selectList(new QueryWrapper<CommunityUserBlock>()
                     .eq("user_id", userId)
@@ -85,7 +92,7 @@ public class CommunityChatMsgController extends BaseController {
                     })
                     .orderByDesc("create_time")
             );*/
-            List<CommunityChatMsg> chatMsgList = communitychatMsgMapper.getChatMsgRecord(userId, otherUserId, type);
+            List<CommunityChatMsg> chatMsgList = communitychatMsgMapper.getChatMsgRecord(userId, otherUserId, type,offset,pageSize);
 
             //更新该消息标记为已读
             List<Long> msgId = chatMsgList.stream()
@@ -219,7 +226,7 @@ public class CommunityChatMsgController extends BaseController {
         String type = updateAnonName.getType();
         try {
             if ("anonymous".equals(type)) {
-                List<CommunityChatMsg> chatMsgList = communitychatMsgMapper.getChatMsgRecord(userId, otherUserId, type);
+                List<CommunityChatMsg> chatMsgList = communitychatMsgMapper.getChatMsgRecord(userId, otherUserId, type,1,100000);
                 for (CommunityChatMsg chatMsg : chatMsgList) {
                     if (chatMsg.getSenderId().equals(otherUserId)) {
                         chatMsg.setSenderAnonName(newAnonName);

+ 3 - 1
ruoyi-system/src/main/java/com/ruoyi/system/mapper/CommunityChatMsgMapper.java

@@ -40,5 +40,7 @@ public interface CommunityChatMsgMapper extends BaseMapper<CommunityChatMsg> {
      */
     List<CommunityChatMsg> getChatMsgRecord(@Param("userId") Long userId,
                                             @Param("otherUserId") Long otherUserId,
-                                            @Param("type") String type);
+                                            @Param("type") String type,
+                                            @Param("offset") int offset,
+                                            @Param("limit") int limit);
 }

+ 1 - 0
ruoyi-system/src/main/resources/mapper/system/CommunityChatMsgMapper.xml

@@ -195,5 +195,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
                 )
             )
         ORDER BY create_time DESC
+        limit #{offset},#{limit}
     </select>
 </mapper>