Commit 656e98ec authored by 刘基明's avatar 刘基明

关注列表

parent 80f73371
package com.tanpu.community.api.beans.req.page; package com.tanpu.community.api.beans.req.page;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;
...@@ -9,7 +8,6 @@ import java.util.List; ...@@ -9,7 +8,6 @@ import java.util.List;
@Data @Data
@Builder @Builder
@AllArgsConstructor
public class Page<T> { public class Page<T> {
private Integer pageNum; private Integer pageNum;
...@@ -94,6 +92,13 @@ public class Page<T> { ...@@ -94,6 +92,13 @@ public class Page<T> {
} }
} }
public Page(Integer pageNum, Integer pageSize, Long totalSize, Integer totalPages, List<T> content) {
this.pageNum = pageNum;
this.pageSize = pageSize;
this.totalSize = totalSize;
this.totalPages = totalPages;
this.content = content;
}
public Page() { public Page() {
} }
......
...@@ -11,12 +11,11 @@ import com.tanpu.community.service.FollowRelService; ...@@ -11,12 +11,11 @@ import com.tanpu.community.service.FollowRelService;
import com.tanpu.community.service.UserInfoService; import com.tanpu.community.service.UserInfoService;
import com.tanpu.community.util.ConvertUtil; import com.tanpu.community.util.ConvertUtil;
import com.tanpu.community.util.PageUtils; import com.tanpu.community.util.PageUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.HashSet; import java.util.*;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Service @Service
...@@ -34,15 +33,18 @@ public class HomePageManager { ...@@ -34,15 +33,18 @@ public class HomePageManager {
public Page<FollowQo> queryFollow(QueryFollowReq req, String userId) { public Page<FollowQo> queryFollow(QueryFollowReq req, String userId) {
List<String> userIds = QueryFollowTypeEnum.QUERY_FANS.getCode().equals(req.getQueryType()) ? List<String> userIds = QueryFollowTypeEnum.QUERY_FANS.getCode().equals(req.getQueryType()) ?
followRelService.queryFansByIdolId(req.getUserId()) : followRelService.queryFansByFollowerId(req.getUserId()); followRelService.queryFansByIdolId(req.getUserId()) : followRelService.queryFansByFollowerId(req.getUserId());
List<FollowQo> followQos = new ArrayList<>();
if (!CollectionUtils.isEmpty(userIds)) {
List<UserInfoEntity> userInfos = userInfoService.queryUserByIds(userIds); List<UserInfoEntity> userInfos = userInfoService.queryUserByIds(userIds);
List<FollowQo> collect = userInfos.stream().map(ConvertUtil::homePageEntity2FollowQo).collect(Collectors.toList()); List<FollowQo> collect = userInfos.stream().map(ConvertUtil::homePageEntity2FollowQo).collect(Collectors.toList());
List<FollowQo> followQos = judgeFollowed(collect, userId); followQos = judgeFollowed(collect, userId);
}
//分页 //分页
return PageUtils.page(req.getPage(), followQos); return PageUtils.page(req.getPage(), followQos);
} }
//判断返回列表中的用户是否被当前用户关注 //判断返回列表中的用户是否被当前用户关注
public List<FollowQo> judgeFollowed(List<FollowQo> followQos, String followerId) { public List<FollowQo> judgeFollowed(List<FollowQo> followQos, String followerId) {
Set<String> idolSet = new HashSet<>(followRelService.queryFansByFollowerId(followerId)); Set<String> idolSet = new HashSet<>(followRelService.queryFansByFollowerId(followerId));
......
...@@ -14,11 +14,13 @@ import java.util.List; ...@@ -14,11 +14,13 @@ import java.util.List;
public class PageUtils { public class PageUtils {
public static <T> Page<T> page(Pageable pageable, List<T> list) { public static <T> Page<T> page(Pageable pageable, List<T> list) {
if (CollectionUtils.isEmpty(list)) { if (CollectionUtils.isEmpty(list)) {
if(pageable==null){
return new Page<T>(1,0, (long)list.size(),1, list);
}
return new Page<>(pageable, 0L, new ArrayList<>()); return new Page<>(pageable, 0L, new ArrayList<>());
} else { } else {
if(pageable==null){ if(pageable==null){
Pageable p = new Pageable(1, list.size()); return new Page<T>(1,list.size(), (long)list.size(),1, list);
return new Page<T>(p, (long)list.size(), list);
} }
// 记录总数 // 记录总数
......
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