From e400fa6ebaa5ea1dc7070ce51e6e70b6132d151a Mon Sep 17 00:00:00 2001 From: Cauchy Date: Mon, 23 Oct 2023 13:26:43 +0800 Subject: [PATCH] chat sub list --- .../controller/BookClockForumController.java | 74 ++++++++++--------- .../book/dao/BookClockEntryChatDao.java | 4 +- ...hatEntity.java => BookClockEntryChat.java} | 2 +- .../service/BookClockEntryChatService.java | 4 +- .../service/impl/BookClockEntryChatImpl.java | 4 +- src/main/resources/application.yml | 2 +- 6 files changed, 49 insertions(+), 41 deletions(-) rename src/main/java/com/peanut/modules/book/entity/{BookClockEntryChatEntity.java => BookClockEntryChat.java} (93%) diff --git a/src/main/java/com/peanut/modules/book/controller/BookClockForumController.java b/src/main/java/com/peanut/modules/book/controller/BookClockForumController.java index 9d85e637..bf54e428 100644 --- a/src/main/java/com/peanut/modules/book/controller/BookClockForumController.java +++ b/src/main/java/com/peanut/modules/book/controller/BookClockForumController.java @@ -7,7 +7,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.peanut.common.utils.PageUtils; import com.peanut.common.utils.R; import com.peanut.modules.book.entity.BookClockEntryEntity; -import com.peanut.modules.book.entity.BookClockEntryChatEntity; +import com.peanut.modules.book.entity.BookClockEntryChat; import com.peanut.modules.book.entity.MyUserEntity; import com.peanut.modules.book.service.BookClockEntryChatService; import com.peanut.modules.book.service.BookClockEntryService; @@ -64,13 +64,12 @@ public class BookClockForumController { * @param entryId * @return */ - @RequestMapping(path = "/getChatList", method = RequestMethod.POST) + @RequestMapping(path = "/getChatList", method = RequestMethod.GET) public R getChatList(@RequestParam("entryId") Integer entryId, @RequestParam(value = "userId", required = false) Integer userId, - @RequestParam(value = "pageSize") Integer pageSize, - @RequestParam("currentPage") Integer currentPage, - @RequestBody Map subPage) { - QueryWrapper queryWrapper = new QueryWrapper<>(); + @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize, + @RequestParam(value = "currentPage", defaultValue = "1") Integer currentPage) { + QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("entry_id", entryId); queryWrapper.eq("fid", 0); if (userId != null) { @@ -78,8 +77,8 @@ public class BookClockForumController { } queryWrapper.orderByAsc("fid", "create_time"); List resultList = new ArrayList<>(); - List chatEntityList = bookClockEntryChatService.list(queryWrapper); - for (BookClockEntryChatEntity entity : chatEntityList) { + List chatEntityList = bookClockEntryChatService.list(queryWrapper); + for (BookClockEntryChat entity : chatEntityList) { List imageList = JSON.parseObject(entity.getImages(), new TypeReference>() { }); entity.setImageList(imageList); @@ -88,32 +87,41 @@ public class BookClockForumController { MyUserEntity user = userService.getById(entity.getUserId()); vo.setNickName(user.getNickname()); vo.setAvatar(user.getAvatar()); - QueryWrapper subQueryWrapper = new QueryWrapper<>(); - subQueryWrapper.eq("fid", entity.getId()); - List subClockInChatList = bookClockEntryChatService.list(subQueryWrapper); - List subCommentList = new ArrayList<>(); - List subCommentPages = new ArrayList<>(); - for (BookClockEntryChatEntity subChat : subClockInChatList) { - ClockInCommentVo subVo = new ClockInCommentVo(); - BeanUtil.copyProperties(subChat, subVo); - MyUserEntity subChatUser = userService.getById(subChat.getUserId()); - MyUserEntity pUser = userService.getById(subChat.getPuserId()); - subVo.setPuserNickName(pUser.getNickname()); - subVo.setPuserAvatar(pUser.getAvatar()); - subVo.setAvatar(subChatUser.getAvatar()); - subVo.setNickName(subChatUser.getNickname()); - subCommentList.add(subVo); - Integer currentCommentId = subPage.get(entity.getId()); - PageUtils subCommentPage = new PageUtils(subCommentList, subCommentList.size(), 5, subPage.get(currentCommentId)); - subCommentPages.add(subCommentPage); - } - vo.setSubCommentList(subCommentPages); resultList.add(vo); } - PageUtils page = new PageUtils(resultList, resultList.size(), 5, currentPage); - Map result = new HashMap<>(); - result.put("chatList", page); - return R.ok(result); + PageUtils page = new PageUtils(resultList, resultList.size(), pageSize, currentPage); + return R.ok().put("result", page); + } + + /** + * 获取子评论 + * + * @param fid 父评论 ID + * @param pageSize 页大小 + * @param currentPage 当前页 + * @return R + */ + @RequestMapping(path = "/getSubChatList", method = RequestMethod.GET) + public R getSubChatList(@RequestParam("fid") Integer fid, + @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize, + @RequestParam(value = "currentPage", defaultValue = "1") Integer currentPage) { + QueryWrapper subQueryWrapper = new QueryWrapper<>(); + subQueryWrapper.eq("fid", fid); + List subClockInChatList = bookClockEntryChatService.list(subQueryWrapper); + List subCommentList = new ArrayList<>(); + for (BookClockEntryChat subChat : subClockInChatList) { + ClockInCommentVo subVo = new ClockInCommentVo(); + BeanUtil.copyProperties(subChat, subVo); + MyUserEntity subChatUser = userService.getById(subChat.getUserId()); + MyUserEntity pUser = userService.getById(subChat.getPuserId()); + subVo.setPuserNickName(pUser.getNickname()); + subVo.setPuserAvatar(pUser.getAvatar()); + subVo.setAvatar(subChatUser.getAvatar()); + subVo.setNickName(subChatUser.getNickname()); + subCommentList.add(subVo); + } + PageUtils subChatPage = new PageUtils(subCommentList, subCommentList.size(), pageSize, currentPage); + return R.ok().put("result", subChatPage); } /** @@ -123,7 +131,7 @@ public class BookClockForumController { * @return */ @RequestMapping(path = "/addChat", method = RequestMethod.POST) - public R addChat(@RequestBody BookClockEntryChatEntity chat) { + public R addChat(@RequestBody BookClockEntryChat chat) { List imageList = chat.getImageList(); if (imageList != null) { String images = JSON.toJSON(imageList).toString(); diff --git a/src/main/java/com/peanut/modules/book/dao/BookClockEntryChatDao.java b/src/main/java/com/peanut/modules/book/dao/BookClockEntryChatDao.java index 43c572b9..a21c2818 100644 --- a/src/main/java/com/peanut/modules/book/dao/BookClockEntryChatDao.java +++ b/src/main/java/com/peanut/modules/book/dao/BookClockEntryChatDao.java @@ -1,9 +1,9 @@ package com.peanut.modules.book.dao; import com.github.yulichang.base.MPJBaseMapper; -import com.peanut.modules.book.entity.BookClockEntryChatEntity; +import com.peanut.modules.book.entity.BookClockEntryChat; import org.apache.ibatis.annotations.Mapper; @Mapper -public interface BookClockEntryChatDao extends MPJBaseMapper { +public interface BookClockEntryChatDao extends MPJBaseMapper { } diff --git a/src/main/java/com/peanut/modules/book/entity/BookClockEntryChatEntity.java b/src/main/java/com/peanut/modules/book/entity/BookClockEntryChat.java similarity index 93% rename from src/main/java/com/peanut/modules/book/entity/BookClockEntryChatEntity.java rename to src/main/java/com/peanut/modules/book/entity/BookClockEntryChat.java index f000c4e7..ebc42cdc 100644 --- a/src/main/java/com/peanut/modules/book/entity/BookClockEntryChatEntity.java +++ b/src/main/java/com/peanut/modules/book/entity/BookClockEntryChat.java @@ -12,7 +12,7 @@ import java.util.List; @Data @TableName("book_clock_entry_chat") -public class BookClockEntryChatEntity implements Serializable { +public class BookClockEntryChat implements Serializable { private static final long serialVersionUID = 1L; @TableId diff --git a/src/main/java/com/peanut/modules/book/service/BookClockEntryChatService.java b/src/main/java/com/peanut/modules/book/service/BookClockEntryChatService.java index c91fa49e..0befd052 100644 --- a/src/main/java/com/peanut/modules/book/service/BookClockEntryChatService.java +++ b/src/main/java/com/peanut/modules/book/service/BookClockEntryChatService.java @@ -1,7 +1,7 @@ package com.peanut.modules.book.service; import com.baomidou.mybatisplus.extension.service.IService; -import com.peanut.modules.book.entity.BookClockEntryChatEntity; +import com.peanut.modules.book.entity.BookClockEntryChat; -public interface BookClockEntryChatService extends IService { +public interface BookClockEntryChatService extends IService { } diff --git a/src/main/java/com/peanut/modules/book/service/impl/BookClockEntryChatImpl.java b/src/main/java/com/peanut/modules/book/service/impl/BookClockEntryChatImpl.java index 8ffdac07..adadc50e 100644 --- a/src/main/java/com/peanut/modules/book/service/impl/BookClockEntryChatImpl.java +++ b/src/main/java/com/peanut/modules/book/service/impl/BookClockEntryChatImpl.java @@ -2,10 +2,10 @@ package com.peanut.modules.book.service.impl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.peanut.modules.book.dao.BookClockEntryChatDao; -import com.peanut.modules.book.entity.BookClockEntryChatEntity; +import com.peanut.modules.book.entity.BookClockEntryChat; import com.peanut.modules.book.service.BookClockEntryChatService; import org.springframework.stereotype.Service; @Service("bookClockEntryChatService") -public class BookClockEntryChatImpl extends ServiceImpl implements BookClockEntryChatService { +public class BookClockEntryChatImpl extends ServiceImpl implements BookClockEntryChatService { } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index ad28466c..dfbe12f6 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -11,7 +11,7 @@ connection-timeout: 6000000ms spring: # 环境 dev|test|prod profiles: - active: prod + active: dev-wcl # jackson时间格式化 jackson: time-zone: GMT+8