Commit df7fa9e4 authored by 张辰's avatar 张辰

pageable

parent 4e912b47
package com.tanpu.community.api.beans.req.theme; package com.tanpu.community.api.beans.req.theme;
import com.tanpu.community.api.beans.req.page.Pageable;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
...@@ -21,13 +22,7 @@ public class ThemeListReq { ...@@ -21,13 +22,7 @@ public class ThemeListReq {
@ApiModelProperty(value = "当前浏览的最后一个themeId,可以为空") @ApiModelProperty(value = "当前浏览的最后一个themeId,可以为空")
public String lastId=""; public String lastId="";
@NotNull(message = "pageNumber不能为空") public Pageable page;
@ApiModelProperty(value = "页面起始")
public Integer pageNumber;
@NotNull(message = "PageSize不能为空")
@ApiModelProperty(value = "页面大小")
public Integer pageSize;
public List<String> excludeIds; public List<String> excludeIds;
} }
...@@ -184,8 +184,8 @@ public class ThemeManager { ...@@ -184,8 +184,8 @@ public class ThemeManager {
*/ */
// 查询主题列表:推荐/关注/热门/最新 // 查询主题列表:推荐/关注/热门/最新
public ThemeListResp queryThemes(ThemeListReq req, String userId) { public ThemeListResp queryThemes(ThemeListReq req, String userId) {
Integer pageStart = (req.pageNumber - 1) * req.pageSize; Integer pageStart = (req.page.pageNumber - 1) * req.page.pageSize;
Integer realSize = req.pageSize * 2; Integer realSize = req.page.pageSize * 2;
List<ThemeEntity> themes = new ArrayList<>(); List<ThemeEntity> themes = new ArrayList<>();
if (ThemeListTypeEnum.RECOMMEND.getCode().equals(req.getType())) { if (ThemeListTypeEnum.RECOMMEND.getCode().equals(req.getType())) {
...@@ -199,7 +199,7 @@ public class ThemeManager { ...@@ -199,7 +199,7 @@ public class ThemeManager {
} else if (ThemeListTypeEnum.FOLLOW.getCode().equals(req.getType())) { } else if (ThemeListTypeEnum.FOLLOW.getCode().equals(req.getType())) {
//根据关注列表查询 //根据关注列表查询
List<String> fansList = followRelService.queryFansByFollowerId(userId); List<String> fansList = followRelService.queryFansByFollowerId(userId);
themes = themeService.queryByUserIds(fansList, req.getLastId(), req.getPageSize()); themes = themeService.queryByUserIds(fansList, req.getLastId(), req.page.getPageSize());
} else if (ThemeListTypeEnum.TOPIC_HOT.getCode().equals(req.getType())) { } else if (ThemeListTypeEnum.TOPIC_HOT.getCode().equals(req.getType())) {
//根据话题查询热门 //根据话题查询热门
if (StringUtils.isEmpty(req.getTopicId())) { if (StringUtils.isEmpty(req.getTopicId())) {
...@@ -216,13 +216,13 @@ public class ThemeManager { ...@@ -216,13 +216,13 @@ public class ThemeManager {
throw new BizException("TopicId为空"); throw new BizException("TopicId为空");
} }
themes = themeService.queryNewestByTopic(req.topicId, req.pageNumber, realSize); themes = themeService.queryNewestByTopic(req.topicId, req.page.pageNumber, realSize);
} }
// filter用户自己的 // filter用户自己的
themes = themes.stream().filter(t -> { themes = themes.stream().filter(t -> {
return !userId.equals(t.getAuthorId()) && !req.excludeIds.contains(t.getThemeId()); return !userId.equals(t.getAuthorId()) && !req.excludeIds.contains(t.getThemeId());
}).collect(Collectors.toList()).subList(0, req.pageSize); }).collect(Collectors.toList()).subList(0, req.page.pageSize);
ThemeListResp resp = new ThemeListResp(); ThemeListResp resp = new ThemeListResp();
resp.excludeIds = req.excludeIds; resp.excludeIds = req.excludeIds;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment