Commit 40d76196 authored by 刘基明's avatar 刘基明

粉丝列表分页查询

parent 44b86aed
......@@ -10,11 +10,11 @@ import lombok.Data;
public class QueryFollowReq {
@ApiModelProperty(value = "用户Id")
private String userId;
public String userId;
@ApiModelProperty(value = "查询类型,1:粉丝 2:关注")
private Integer queryType;
public Integer queryType;
@ApiModelProperty(value = "分页")
private Pageable page;
public Pageable page;
}
......@@ -58,7 +58,8 @@ public class HomePageManager {
//查询 个人中心 相关信息
public UserInfoResp queryUsersInfo(String userIdMyself, String userId) {
CommonResp<UserInfoResp> queryUsersListNew = feignClientForFatools.queryUsersListNew(StringUtils.isNotBlank(userId) ? userId : userIdMyself);
if (queryUsersListNew.isNotSuccess() || !ObjectUtils.anyNotNull(queryUsersListNew.getData())) throw new BizException("内部接口调用失败");
if (queryUsersListNew.isNotSuccess() || !ObjectUtils.anyNotNull(queryUsersListNew.getData()))
throw new BizException("内部接口调用失败");
UserInfoResp userInfoNew = queryUsersListNew.getData();
if (StringUtils.isNotBlank(userId) && !StringUtils.equals(userIdMyself, userId)) { //查询别人的个人主页
......@@ -94,7 +95,7 @@ public class HomePageManager {
}
// 查询首席投顾数量
CommonResp<Page<UserInfoNewChief>> pageCommonResp = feignClientForFatools.queryChiefFinancialAdviserList(1, 1);
if (pageCommonResp.isSuccess()){
if (pageCommonResp.isSuccess()) {
userInfoNew.getUserInfoNewChief().setChiefCount(pageCommonResp.getData().getTotalSize());
} else {
userInfoNew.getUserInfoNewChief().setChiefCount(0L);
......@@ -180,28 +181,32 @@ public class HomePageManager {
/**
* 用户关注列表
*
* @param req 目标用户
* @param userId 当前用户
* @return
*/
public Page<FollowQo> queryFollow(QueryFollowReq req, String userId) {
//TODO 数据库分页
List<String> userIds = QueryFollowTypeEnum.QUERY_FANS.getCode().equals(req.getQueryType()) ?
followRelService.queryFansByIdolId(req.getUserId()) : followRelService.queryIdolsByFollowerId(req.getUserId());
//数据库分页
Integer pageSize = req.page.pageSize;
Integer pageNumber = req.page.pageNumber;
Page<String> userIdsPage = QueryFollowTypeEnum.QUERY_FANS.getCode().equals(req.getQueryType()) ?
followRelService.queryFansByIdolId(req.userId, pageNumber, pageSize)
: followRelService.queryIdolsByFansId(req.userId, pageNumber, pageSize);
List<FollowQo> followQos = new ArrayList<>();
if (!CollectionUtils.isEmpty(userIds)) {
List<UserInfoResp> userInfoNews = feignClientForFatools.queryUserListNew(userIds);
if (!CollectionUtils.isEmpty(userIdsPage.getContent())) {
List<UserInfoResp> userInfoNews = feignClientForFatools.queryUserListNew(userIdsPage.getContent());
List<FollowQo> collect = userInfoNews.stream().map(ConvertUtil::userInfoNew2FollowQo).collect(Collectors.toList());
followQos = judgeFollowed(collect, userId);
}
//分页
return PageUtils.page(req.getPage(), followQos);
return PageUtils.page(userIdsPage,followQos);
}
//判断返回列表中的用户是否被当前用户关注
public List<FollowQo> judgeFollowed(List<FollowQo> followQos, String followerId) {
Set<String> idolSet = new HashSet<>(followRelService.queryIdolsByFollowerId(followerId));
Set<String> idolSet = new HashSet<>(followRelService.queryIdolsByFansId(followerId));
return followQos.stream().map(o -> {
if (idolSet.contains(o.getUserId())) {
o.setFollowed(true);
......
......@@ -9,7 +9,6 @@ import com.tanpu.common.api.CommonResp;
import com.tanpu.common.constant.ErrorCodeConstant;
import com.tanpu.common.exception.BizException;
import com.tanpu.common.util.JsonUtil;
import com.tanpu.community.api.CommunityConstant;
import com.tanpu.community.api.beans.qo.ESThemeQo;
import com.tanpu.community.api.beans.qo.FormerThemeQo;
import com.tanpu.community.api.beans.qo.ThemeContentQo;
......@@ -25,7 +24,6 @@ import com.tanpu.community.api.beans.req.theme.ThemeListReq;
import com.tanpu.community.api.beans.resp.CreateThemeResp;
import com.tanpu.community.api.beans.resp.ThemeFullSearchResp;
import com.tanpu.community.api.beans.resp.ThemeListResp;
import com.tanpu.community.api.beans.vo.ImagesDTO;
import com.tanpu.community.api.beans.vo.feign.fatools.UserInfoResp;
import com.tanpu.community.api.enums.BlockTypeEnum;
import com.tanpu.community.api.enums.OperationTypeEnum;
......@@ -281,7 +279,7 @@ public class ThemeManager {
} else if (ThemeListTypeEnum.FOLLOW.getCode().equals(req.getType())) {
// 根据关注列表查询,按时间倒序
List<String> fansList = followRelService.queryIdolsByFollowerId(userId);
List<String> fansList = followRelService.queryIdolsByFansId(userId);
themes = themeService.queryByUserIdsCreateDesc(fansList, pageStart, pageSize);
if (CollectionUtils.isEmpty(excludeIds) && !themes.isEmpty()) {
......@@ -346,15 +344,7 @@ public class ThemeManager {
FormerThemeQo former = redisCache.getObject(StringUtils.joinWith("_", CACHE_FORMER_THEME_ID, themeId), 60,
() -> this.getFormerTheme(themeQo.getFormerThemeId()), FormerThemeQo.class);
themeQo.setFormerTheme(former);
//压缩图片
themeQo.getContent().stream().forEach(o -> {
if (o.getImgList() != null) {
for (ImagesDTO imagesDTO : o.getImgList()) {
if (StringUtils.isNotBlank(imagesDTO.getRemark()))
imagesDTO.setResizeUrl(imagesDTO.getRemark() + CommunityConstant.OSS_RESIZE_RATIO);
}
}
});
// 点赞,收藏,转发
......@@ -390,7 +380,7 @@ public class ThemeManager {
private void buildThemeExtraInfoByUser(String userId, List<ThemeQo> themeQos) {
// 批量查询
List<String> themeIds = themeQos.stream().map(ThemeQo::getThemeId).collect(Collectors.toList());
Set<String> idolSet = new HashSet<>(followRelService.queryIdolsByFollowerId(userId));
Set<String> idolSet = new HashSet<>(followRelService.queryIdolsByFansId(userId));
Set<String> likeSet = collectionService.getTargets(themeIds, userId, CollectionTypeEnum.LIKE_THEME);
Set<String> bookSet = collectionService.getTargets(themeIds, userId, CollectionTypeEnum.COLLECT_THEME);
Set<String> forwardUsers = themeService.getForwardUsers(themeIds);
......@@ -512,7 +502,7 @@ public class ThemeManager {
public Integer getFollowUpdateCount(String userId) {
String lastIdStr = redisCache.get(CACHE_IDOL_THEME_LAST_ID + userId);
Long lastId = StringUtils.isBlank(lastIdStr) ? 0L : Long.parseLong(lastIdStr);
List<String> fansList = followRelService.queryIdolsByFollowerId(userId);
List<String> fansList = followRelService.queryIdolsByFansId(userId);
return themeService.queryCountFromLastId(fansList, lastId);
}
......
......@@ -7,6 +7,7 @@ import com.tanpu.biz.common.enums.user.UserLevelEnum;
import com.tanpu.common.api.CommonResp;
import com.tanpu.common.enums.fund.ProductTypeEnum;
import com.tanpu.common.util.JsonUtil;
import com.tanpu.community.api.CommunityConstant;
import com.tanpu.community.api.beans.qo.AttachmentDetailVo;
import com.tanpu.community.api.beans.qo.ThemeContentQo;
import com.tanpu.community.api.beans.qo.ThemeQo;
......@@ -258,10 +259,10 @@ public class BatchFeignCallService {
Set<String> ifaFundIds,
Set<String> notNetFundIds,
Map<String, FundInfoBaseResp> fundMap) {
Map<String, FundInfoBaseResp> tampFundMap = null;
Map<String, FundInfoBaseResp> privateFundMap = null;
Map<String, FundInfoBaseResp> publicFundMap = null;
Map<String, FundInfoBaseResp> ifaFundMap = null;
Map<String, FundInfoBaseResp> tampFundMap;
Map<String, FundInfoBaseResp> privateFundMap;
Map<String, FundInfoBaseResp> publicFundMap;
Map<String, FundInfoBaseResp> ifaFundMap;
Map<String, FundInfoBaseResp> notNetFundMap = null;
if (!CollectionUtils.isEmpty(tanpuFundIds)) {
// ProductListReq productListReq = ProductListReq.builder()
......@@ -276,7 +277,7 @@ public class BatchFeignCallService {
}).collect(Collectors.toList());
tampFundMap = fundInfoBaseRespList.stream().collect(Collectors.toMap(FundInfoBaseResp::getFundId, item -> item));
if (tampFundMap != null && tampFundMap.size() > 0) {
if (tampFundMap.size() > 0) {
fundMap.putAll(tampFundMap);
}
}
......@@ -291,7 +292,7 @@ public class BatchFeignCallService {
}).collect(Collectors.toList());
privateFundMap = fundInfoBaseRespList.stream().collect(Collectors.toMap(FundInfoBaseResp::getFundId, item -> item));
if (privateFundMap != null && privateFundMap.size() > 0) {
if (privateFundMap.size() > 0) {
fundMap.putAll(privateFundMap);
}
}
......@@ -307,7 +308,7 @@ public class BatchFeignCallService {
ifaFundMap = fundInfoBaseRespList.stream().collect(Collectors.toMap(FundInfoBaseResp::getFundId, item -> item));
if (ifaFundMap != null && ifaFundMap.size() > 0) {
if (ifaFundMap.size() > 0) {
fundMap.putAll(ifaFundMap);
}
}
......@@ -322,7 +323,7 @@ public class BatchFeignCallService {
}).collect(Collectors.toList());
publicFundMap = fundInfoBaseRespList.stream().collect(Collectors.toMap(FundInfoBaseResp::getFundId, item -> item));
if (publicFundMap != null && publicFundMap.size() > 0) {
if (publicFundMap.size() > 0) {
fundMap.putAll(publicFundMap);
}
}
......@@ -427,19 +428,20 @@ public class BatchFeignCallService {
//单图封装到imglist列表中
if (imgUrlMap.containsKey(themeContent.getValue())) {
FileRecordEntity imgEntity = imgUrlMap.get(themeContent.getValue());
String extInfo = imgEntity.getExtInfo();
if (!StringUtils.isEmpty(extInfo)) {
Map<String, Object> extMap = JsonUtil.toMap(extInfo);
if (imgEntity!=null && !StringUtils.isEmpty(imgEntity.getExtInfo())) {
Map<String, Object> extMap = JsonUtil.toMap(imgEntity.getExtInfo());
ImagesDTO imagesDTO = ImagesDTO.builder().imgHeight((Integer) extMap.get("height"))
.imgWidth((Integer) extMap.get("width"))
.remark(imgEntity.getUrl())
.relId(imgEntity.getFileId())
//压缩图片
.resizeUrl(imgEntity.getUrl() + CommunityConstant.OSS_RESIZE_RATIO)
.build();
themeContent.setImgList(Collections.singletonList(imagesDTO));
}
}
} else if (themeContent.getType().equals(RelTypeEnum.MULTIPLE_IMAGE.type)) {
//多图写入图片宽高
//多图写入图片宽高,压缩图片url
List<ImagesDTO> imgList = themeContent.getImgList();
for (ImagesDTO imagesDTO : imgList) {
if (imgUrlMap.containsKey(imagesDTO.getRelId())) {
......@@ -450,6 +452,8 @@ public class BatchFeignCallService {
imagesDTO.setImgHeight((Integer) extMap.get("height"));
imagesDTO.setImgWidth((Integer) extMap.get("width"));
}
//压缩图片地址
imagesDTO.setResizeUrl(imgEntity.getUrl() + CommunityConstant.OSS_RESIZE_RATIO);
}
}
......
package com.tanpu.community.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tanpu.common.constant.BizStatus;
import com.tanpu.common.exception.BizException;
import com.tanpu.community.api.beans.req.page.Page;
import com.tanpu.community.api.enums.DeleteTagEnum;
import com.tanpu.community.dao.entity.community.FollowRelEntity;
import com.tanpu.community.dao.mapper.community.FollowRelMapper;
......@@ -21,7 +23,7 @@ public class FollowRelService {
@Resource
private FollowRelMapper followRelMapper;
public List<String> queryIdolsByFollowerId(String followerId) {
public List<String> queryIdolsByFansId(String followerId) {
return followRelMapper.selectList(new LambdaQueryWrapper<FollowRelEntity>()
.eq(FollowRelEntity::getFansId, followerId)
.eq(FollowRelEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()))
......@@ -29,19 +31,55 @@ public class FollowRelService {
.collect(Collectors.toList());
}
// @Cacheable(value = "tempCache", keyGenerator = "communityKeyGenerator")
public List<String> queryFansByIdolId(String idolId) {
public Page<String> queryIdolsByFansId(String fansId, Integer pageNum, Integer pageSize) {
Integer pageStart = (pageNum - 1) * pageSize;
List<FollowRelEntity> idols = followRelMapper.selectList(new LambdaQueryWrapper<FollowRelEntity>()
.eq(FollowRelEntity::getFansId, fansId)
.last("limit " + pageStart + ", " + pageSize)
.eq(FollowRelEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()));
List<String> list = idols.stream().map(FollowRelEntity::getIdolId)
.collect(Collectors.toList());
Integer totalSize = followRelMapper.selectCount(new LambdaQueryWrapper<FollowRelEntity>().eq(FollowRelEntity::getFansId,fansId)
.eq(FollowRelEntity::getDeleteTag, BizStatus.DeleteTag.tag_init));
Page<String> tPage = new Page<>(pageNum, pageSize, (long) totalSize, 0, list);
int totalPage = list.size() / pageSize;
if (list.size() % pageSize == 0) {
tPage.setTotalPages(totalPage);
} else {
tPage.setTotalPages(totalPage + 1);
}
return tPage;
}
public Page<String> queryFansByIdolId(String idolId, Integer pageNum, Integer pageSize) {
Integer pageStart = (pageNum - 1) * pageSize;
LambdaQueryWrapper<FollowRelEntity> queryWrapper = new LambdaQueryWrapper<FollowRelEntity>()
.eq(FollowRelEntity::getIdolId, idolId)
.last("limit " + pageStart + ", " + pageSize)
.eq(FollowRelEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode());
return followRelMapper.selectList(queryWrapper)
List<String> list = followRelMapper.selectList(queryWrapper)
.stream().map(FollowRelEntity::getFansId).collect(Collectors.toList());
// 分页
Integer totalSize = followRelMapper.selectCount(new LambdaQueryWrapper<FollowRelEntity>().eq(FollowRelEntity::getIdolId, idolId)
.eq(FollowRelEntity::getDeleteTag, BizStatus.DeleteTag.tag_init));
Page<String> tPage = new Page<>(pageNum, pageSize, (long) totalSize, 0, list);
int totalPage = list.size() / pageSize;
if (list.size() % pageSize == 0) {
tPage.setTotalPages(totalPage);
} else {
tPage.setTotalPages(totalPage + 1);
}
return tPage;
}
@Transactional
public void addFollowRel(String idolId, String followerId) {
FollowRelEntity searchResult = queryRecord(idolId, followerId);
if (searchResult==null){
if (searchResult == null) {
FollowRelEntity entity = FollowRelEntity.builder()
.idolId(idolId)
.fansId(followerId)
......@@ -49,7 +87,7 @@ public class FollowRelService {
.build();
followRelMapper.insert(entity);
}else {
} else {
searchResult.setFollowTime(LocalDateTime.now());
searchResult.setDeleteTag(DeleteTagEnum.NOT_DELETED.getCode());
followRelMapper.updateById(searchResult);
......@@ -59,13 +97,14 @@ public class FollowRelService {
/**
* 逻辑删除关注关系
*
* @param idolId
* @param followerId
*/
@Transactional
public void deleteFollowRel(String idolId, String followerId) {
FollowRelEntity searchResult = queryRecord(idolId, followerId);
if (searchResult==null){
if (searchResult == null) {
throw new BizException("未找到关注关系");
}
searchResult.setUnfollowTime(LocalDateTime.now());
......@@ -73,18 +112,18 @@ public class FollowRelService {
followRelMapper.updateById(searchResult);
}
public FollowRelEntity queryRecord(String idolId, String followerId){
public FollowRelEntity queryRecord(String idolId, String followerId) {
return followRelMapper.selectOne(new LambdaQueryWrapper<FollowRelEntity>()
.eq(FollowRelEntity::getIdolId,idolId)
.eq(FollowRelEntity::getFansId,followerId));
.eq(FollowRelEntity::getIdolId, idolId)
.eq(FollowRelEntity::getFansId, followerId));
}
public boolean checkFollow(String idolId,String followerId){
public boolean checkFollow(String idolId, String followerId) {
return followRelMapper.selectCount(new LambdaQueryWrapper<FollowRelEntity>()
.eq(FollowRelEntity::getIdolId,idolId)
.eq(FollowRelEntity::getFansId,followerId)
.eq(FollowRelEntity::getDeleteTag,DeleteTagEnum.NOT_DELETED.getCode()))
>0;
.eq(FollowRelEntity::getIdolId, idolId)
.eq(FollowRelEntity::getFansId, followerId)
.eq(FollowRelEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()))
> 0;
}
......
......@@ -12,12 +12,14 @@ import java.util.List;
* @email: zhoupeng@wealthgrow.cn
*/
public class PageUtils {
public static <T> Page<T> page(Pageable pageable, List<T> 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<T>(pageable, 0L, new ArrayList<>());
} else {
if(pageable==null){
return new Page<T>(1,list.size(), (long)list.size(),1, list);
......@@ -64,4 +66,8 @@ public class PageUtils {
}
}
}
public static <T> Page<T> page(Page<String> o, List<T> list) {
return new Page<>(o.getPageNum(),o.getPageSize(),o.getTotalSize(),o.getTotalPages(),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