bugfix: 补卡,评论区分页

This commit is contained in:
Cauchy
2023-10-22 18:00:14 +08:00
parent f9b852d637
commit 739adb011d
3 changed files with 42 additions and 6 deletions

View File

@@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
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;
@@ -63,9 +64,12 @@ public class BookClockForumController {
* @param entryId
* @return
*/
@RequestMapping(path = "/getChatList", method = RequestMethod.GET)
@RequestMapping(path = "/getChatList", method = RequestMethod.POST)
public R getChatList(@RequestParam("entryId") Integer entryId,
@RequestParam(value = "userId", required = false) Integer userId) {
@RequestParam(value = "userId", required = false) Integer userId,
@RequestParam(value = "pageSize") Integer pageSize,
@RequestParam("currentPage") Integer currentPage,
@RequestBody Map<Integer, Integer> subPage) {
QueryWrapper<BookClockEntryChatEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("entry_id", entryId);
queryWrapper.eq("fid", 0);
@@ -88,6 +92,7 @@ public class BookClockForumController {
subQueryWrapper.eq("fid", entity.getId());
List<BookClockEntryChatEntity> subClockInChatList = bookClockEntryChatService.list(subQueryWrapper);
List<ClockInCommentVo> subCommentList = new ArrayList<>();
List<PageUtils> subCommentPages = new ArrayList<>();
for (BookClockEntryChatEntity subChat : subClockInChatList) {
ClockInCommentVo subVo = new ClockInCommentVo();
BeanUtil.copyProperties(subChat, subVo);
@@ -98,12 +103,16 @@ public class BookClockForumController {
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(subCommentList);
vo.setSubCommentList(subCommentPages);
resultList.add(vo);
}
PageUtils page = new PageUtils(resultList, resultList.size(), 5, currentPage);
Map<String, Object> result = new HashMap<>();
result.put("chatList", resultList);
result.put("chatList", page);
return R.ok(result);
}

View File

@@ -25,7 +25,7 @@ import java.util.*;
@Slf4j
@RestController
@RequestMapping("/book/userClockIn")
public class UserBookClockController {
public class UserBookClockInController {
@Autowired
UserBookClockService userBookClockService;
@@ -108,4 +108,30 @@ public class UserBookClockController {
userBookClockService.updateById(userBookClock);
return R.ok("打卡成功");
}
/**
* 用户补卡接口
*
* @param bookId book ID
* @param userId user ID
* @param day 补卡 day
* @return R
*/
@RequestMapping(value = "/correctClockIn", method = RequestMethod.GET)
public R correctClockIn(@RequestParam("bookId") Integer bookId,
@RequestParam("userId") Integer userId,
@RequestParam("day") Integer day) {
QueryWrapper<UserBookClockEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("book_id", bookId);
queryWrapper.eq("user_id", userId);
UserBookClockEntity userBookClock = userBookClockService.getOne(queryWrapper);
String clocksStr = userBookClock.getClocks();
List<Integer> clockInDaysList = JSON.parseObject(clocksStr, new TypeReference<List<Integer>>() {
});
clockInDaysList.add(day);
String clockInDaysListStr = JSON.toJSON(clockInDaysList).toString();
userBookClock.setClocks(clockInDaysListStr);
userBookClockService.updateById(userBookClock);
return R.ok("补卡成功");
}
}

View File

@@ -1,5 +1,6 @@
package com.peanut.modules.book.vo;
import com.peanut.common.utils.PageUtils;
import lombok.Data;
import java.util.Date;
@@ -42,6 +43,6 @@ public class ClockInCommentVo {
private String puserAvatar;
private List<ClockInCommentVo> subCommentList;
private List<PageUtils> subCommentList;
}