Commit 057956f1 authored by 王亚雷's avatar 王亚雷

Merge remote-tracking branch 'origin/v2.2.7'

parents ece385a0 a20c600c
...@@ -10,6 +10,8 @@ import javax.validation.constraints.NotNull; ...@@ -10,6 +10,8 @@ import javax.validation.constraints.NotNull;
@Data @Data
public class ThemeListReq { public class ThemeListReq {
@ApiModelProperty(value = "用户Id")
private String userId;
@NotNull(message = "主题类型不能为空") @NotNull(message = "主题类型不能为空")
@ApiModelProperty(value = "类型,1:推荐 2:关注 3:话题-热门 4:话题-最新") @ApiModelProperty(value = "类型,1:推荐 2:关注 3:话题-热门 4:话题-最新")
......
...@@ -2,6 +2,14 @@ package com.tanpu.community.api.constants; ...@@ -2,6 +2,14 @@ package com.tanpu.community.api.constants;
public class RedisKeyConstant { public class RedisKeyConstant {
public static final String ENV = "env";
// token app 小程序用
public static final String TAMP_TOKEN = "tampToken";
// H5 cookie
public static final String SESSION_COOKIE_NAME = "qimsession";
// redis token 前缀
public static final String REDIS_PREFIX_TOKEN = "s:sid:";
//点赞量 //点赞量
public static final String THEME_LIKE_COUNT ="THEME_LIKE_COUNT_"; public static final String THEME_LIKE_COUNT ="THEME_LIKE_COUNT_";
//收藏量 //收藏量
......
...@@ -42,12 +42,11 @@ public class CommentController { ...@@ -42,12 +42,11 @@ public class CommentController {
} }
@ApiOperation("评论列表") @ApiOperation("评论列表")
@AuthLogin
@PostMapping(value = "/queryComment") @PostMapping(value = "/queryComment")
@ResponseBody @ResponseBody
public CommonResp<Page<CommentQo>> queryComment(@Validated @RequestBody QueryCommentReq req) { public CommonResp<Page<CommentQo>> queryComment(@Validated @RequestBody QueryCommentReq req) {
String userId = userHolder.getUserId(); String selfUserId = userHolder.getUserId();
List<CommentQo> result = commentManager.queryComments(req.getThemeId(), userId); List<CommentQo> result = commentManager.queryComments(req.getThemeId(), selfUserId);
return CommonResp.success(PageUtils.page(req.getPage(), result)); return CommonResp.success(PageUtils.page(req.getPage(), result));
} }
......
...@@ -15,14 +15,19 @@ import com.tanpu.community.api.beans.vo.feign.fatools.UserInfoNewChief; ...@@ -15,14 +15,19 @@ import com.tanpu.community.api.beans.vo.feign.fatools.UserInfoNewChief;
import com.tanpu.community.api.beans.vo.feign.fatools.UserInfoResp; import com.tanpu.community.api.beans.vo.feign.fatools.UserInfoResp;
import com.tanpu.community.manager.HomePageManager; import com.tanpu.community.manager.HomePageManager;
import com.tanpu.community.manager.ThemeManager; import com.tanpu.community.manager.ThemeManager;
import io.swagger.annotations.ApiImplicitParam; import com.tanpu.community.util.HttpServletHelper;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
...@@ -41,13 +46,13 @@ public class HomePageController { ...@@ -41,13 +46,13 @@ public class HomePageController {
@Resource @Resource
private UserHolder userHolder; private UserHolder userHolder;
// 用户信息查询 (供圈子服务调用) // 用户信息查询 (供圈子服务调用)
@ApiOperation(value = "个人中心 查询") @ApiOperation(value = "个人中心 查询")
@GetMapping(value = "/queryUserInfoNew") @GetMapping(value = "/queryUserInfoNew")
@AuthLogin public CommonResp<UserInfoResp> queryUsersListNew(@RequestParam(value = "userId") String userId) {
public CommonResp<UserInfoResp> queryUsersListNew(@RequestParam(value = "userId", required = false) String userId) { String selfUserId = userHolder.getUserId();
String userIdMyself = userHolder.getUserId(); return CommonResp.success(homePageManager.queryUsersInfo(selfUserId, userId));
return CommonResp.success(homePageManager.queryUsersInfo(userIdMyself, userId));
} }
// 理财师客户列表查询 (供圈子服务调用) // 理财师客户列表查询 (供圈子服务调用)
...@@ -69,10 +74,9 @@ public class HomePageController { ...@@ -69,10 +74,9 @@ public class HomePageController {
@PostMapping(value = "/followList") @PostMapping(value = "/followList")
@ApiOperation("查询关注/粉丝列表") @ApiOperation("查询关注/粉丝列表")
@ResponseBody @ResponseBody
@AuthLogin
public CommonResp<Page<FollowQo>> queryFollowList(@RequestBody QueryFollowReq req) { public CommonResp<Page<FollowQo>> queryFollowList(@RequestBody QueryFollowReq req) {
String userId = userHolder.getUserId(); String selfUserId = userHolder.getUserId();
return CommonResp.success(homePageManager.queryFollow(req, userId)); return CommonResp.success(homePageManager.queryFollow(req, selfUserId));
} }
@PostMapping(value = "/addIdol") @PostMapping(value = "/addIdol")
...@@ -88,10 +92,9 @@ public class HomePageController { ...@@ -88,10 +92,9 @@ public class HomePageController {
@PostMapping(value = "/themeList") @PostMapping(value = "/themeList")
@ApiOperation("用户的帖子列表") @ApiOperation("用户的帖子列表")
@ResponseBody @ResponseBody
@AuthLogin
public CommonResp<List<ThemeQo>> likeList(@Validated @RequestBody QueryRecordThemeReq req) { public CommonResp<List<ThemeQo>> likeList(@Validated @RequestBody QueryRecordThemeReq req) {
String userId = userHolder.getUserId(); String selfUserId = userHolder.getUserId();
return CommonResp.success(themeManager.queryThemesByUser(req, userId)); return CommonResp.success(themeManager.queryThemesByUser(req, selfUserId));
} }
} }
...@@ -36,22 +36,19 @@ public class ThemeController { ...@@ -36,22 +36,19 @@ public class ThemeController {
return themeManager.publishTheme(req, userId); return themeManager.publishTheme(req, userId);
} }
@AuthLogin
@ApiOperation("主题列表-推荐/关注/热门/最新") @ApiOperation("主题列表-推荐/关注/热门/最新")
@PostMapping(value = "/list") @PostMapping(value = "/list")
@ResponseBody @ResponseBody
public CommonResp<ThemeListResp> selectInterestList(@Validated @RequestBody ThemeListReq req) { public CommonResp<ThemeListResp> selectInterestList(@Validated @RequestBody ThemeListReq req) {
String userId = userHolder.getUserId(); ThemeListResp result = themeManager.queryList(req, req.getUserId());
ThemeListResp result = themeManager.queryList(req, userId);
return CommonResp.success(result); return CommonResp.success(result);
} }
@AuthLogin
@ApiOperation("主题正文") @ApiOperation("主题正文")
@GetMapping(value = "/detail") @GetMapping(value = "/detail")
@ResponseBody @ResponseBody
public CommonResp<ThemeQo> getDetail(@RequestParam(value = "themeId") String themeId) { public CommonResp<ThemeQo> getDetail(@RequestParam(value = "themeId") String themeId,
String userId = userHolder.getUserId(); @RequestParam(value = "userId", required = false) String userId) {
return themeManager.getThemeDetail(themeId, userId); return themeManager.getThemeDetail(themeId, userId);
} }
......
...@@ -35,7 +35,6 @@ public class TopicController { ...@@ -35,7 +35,6 @@ public class TopicController {
return CommonResp.success(topicManager.getAllTopicBriefInfo(req)); return CommonResp.success(topicManager.getAllTopicBriefInfo(req));
} }
@AuthLogin
@GetMapping(value = "/detailPage") @GetMapping(value = "/detailPage")
@ApiOperation("话题详情页顶部") @ApiOperation("话题详情页顶部")
@ResponseBody @ResponseBody
......
...@@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.RequestParam; ...@@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import java.util.List; import java.util.List;
@FeignClient(value = "service-jifen", contextId = "jifen", fallbackFactory = FeignBackClientForActivity.class, url = "http://tp-jifen-svc", path = "/jifen") @FeignClient(value = "service-jifen", contextId = "jifen", fallbackFactory = FeignBackClientForActivity.class, url = "${tanpu.jifen.svc:http://tp-jifen-svc}", path = "/jifen")
// @FeignClient(value = "service-jifen", contextId = "jifen", fallbackFactory = FeignBackClientForActivity.class, url = "http://127.0.0.1:8202/community") // @FeignClient(value = "service-jifen", contextId = "jifen", fallbackFactory = FeignBackClientForActivity.class, url = "http://127.0.0.1:8202/community")
public interface FeignClientForActivity { public interface FeignClientForActivity {
......
...@@ -2,27 +2,24 @@ package com.tanpu.community.feign.fatools; ...@@ -2,27 +2,24 @@ package com.tanpu.community.feign.fatools;
import com.tanpu.common.api.CommonResp; import com.tanpu.common.api.CommonResp;
import com.tanpu.community.api.beans.req.page.Page; import com.tanpu.community.api.beans.req.page.Page;
import com.tanpu.community.api.beans.req.page.Pageable;
import com.tanpu.community.api.beans.vo.feign.course.ShortVideoBaseInfoResp; import com.tanpu.community.api.beans.vo.feign.course.ShortVideoBaseInfoResp;
import com.tanpu.community.api.beans.vo.feign.fatools.UserInfoNewChief; import com.tanpu.community.api.beans.vo.feign.fatools.UserInfoNewChief;
import com.tanpu.community.api.beans.vo.feign.fatools.UserInfoOrg; import com.tanpu.community.api.beans.vo.feign.fatools.UserInfoOrg;
import com.tanpu.community.api.beans.vo.feign.fatools.UserInfoResp; import com.tanpu.community.api.beans.vo.feign.fatools.UserInfoResp;
import com.tanpu.community.api.beans.vo.feign.user.FileQueryResp; import com.tanpu.community.api.beans.vo.feign.user.FileQueryResp;
import com.tanpu.community.api.beans.vo.feign.user.UserInfoVo; import com.tanpu.community.api.beans.vo.feign.user.UserInfoVo;
import com.tanpu.community.config.FeignConfiguration;
import com.tanpu.community.feign.diagnose.FeignBackClientForDiagnose;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@FeignClient(value = "fatools", contextId = "fatools", fallbackFactory = FeignbackForFatools.class, url = "http://tp-fatools-svc", path = "/fatools") @FeignClient(value = "fatools", contextId = "fatools", fallbackFactory = FeignbackForFatools.class, url = "${tanpu.fatools.svc:http://tp-fatools-svc}", path = "/fatools")
//@FeignClient(value = "fatools", contextId = "fatoolsUser", fallbackFactory = FeignbackForFatools.class, path = "/fatools") //@FeignClient(value = "fatools", contextId = "fatoolsUser", fallbackFactory = FeignbackForFatools.class, path = "/fatools")
public interface FeignClientForFatools { public interface FeignClientForFatools {
...@@ -44,7 +41,7 @@ public interface FeignClientForFatools { ...@@ -44,7 +41,7 @@ public interface FeignClientForFatools {
// 用户信息查询 (供圈子服务调用) // 用户信息查询 (供圈子服务调用)
@ApiOperation(value = "查询用户信息") @ApiOperation(value = "查询用户信息")
@GetMapping(value = "/queryUserInfoNew") @GetMapping(value = "/queryUserInfoNew", produces = {MediaType.APPLICATION_JSON_VALUE})
CommonResp<UserInfoResp> queryUserInfoNew(@RequestParam("userId") String userId); CommonResp<UserInfoResp> queryUserInfoNew(@RequestParam("userId") String userId);
@ApiOperation(value = "批量查询查询基本信息") @ApiOperation(value = "批量查询查询基本信息")
......
package com.tanpu.community.manager; package com.tanpu.community.manager;
import com.google.common.collect.Sets;
import com.tanpu.biz.common.enums.community.CollectionTypeEnum; import com.tanpu.biz.common.enums.community.CollectionTypeEnum;
import com.tanpu.biz.common.enums.community.CommentTypeEnum; import com.tanpu.biz.common.enums.community.CommentTypeEnum;
import com.tanpu.biz.common.enums.community.ReportTypeEnum; import com.tanpu.biz.common.enums.community.ReportTypeEnum;
...@@ -116,7 +117,12 @@ public class CommentManager { ...@@ -116,7 +117,12 @@ public class CommentManager {
List<CommentEntity> commentEntities = commentService.selectByThemeId(themeId); List<CommentEntity> commentEntities = commentService.selectByThemeId(themeId);
List<CommentQo> commentQos = ConvertUtil.commentEntity2Qos(commentEntities); List<CommentQo> commentQos = ConvertUtil.commentEntity2Qos(commentEntities);
Set<String> likeCommentList = collectionService.getSetByUser(userId, CollectionTypeEnum.LIKE_COMMENT); Set<String> likeCommentList;
if (StringUtils.isNotEmpty(userId)) {
likeCommentList = collectionService.getSetByUser(userId, CollectionTypeEnum.LIKE_COMMENT);
} else {
likeCommentList = Sets.newHashSetWithExpectedSize(0);
}
for (CommentQo commentQo : commentQos) { for (CommentQo commentQo : commentQos) {
// 封装用户信息 // 封装用户信息
......
package com.tanpu.community.manager; package com.tanpu.community.manager;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.google.common.collect.Lists;
import com.tanpu.biz.common.enums.user.UserLevelEnum; import com.tanpu.biz.common.enums.user.UserLevelEnum;
import com.tanpu.biz.common.enums.user.UserTypeEnum; import com.tanpu.biz.common.enums.user.UserTypeEnum;
import com.tanpu.common.api.CommonResp; import com.tanpu.common.api.CommonResp;
...@@ -46,6 +47,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -46,6 +47,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.Date; import java.util.Date;
...@@ -88,23 +90,22 @@ public class HomePageManager { ...@@ -88,23 +90,22 @@ public class HomePageManager {
//查询 个人中心 相关信息 //查询 个人中心 相关信息
public UserInfoResp queryUsersInfo(String userIdMyself, String userId) { public UserInfoResp queryUsersInfo(String userIdMyself, String userId) {
CommonResp<UserInfoResp> queryUsersListNew = feignClientForFatools.queryUserInfoNew(StringUtils.isNotBlank(userId) ? userId : userIdMyself); CommonResp<UserInfoResp> queryUsersListNew = feignClientForFatools.queryUserInfoNew(userId);
if (queryUsersListNew.isNotSuccess() || !ObjectUtils.anyNotNull(queryUsersListNew.getData())) if (queryUsersListNew.isNotSuccess() || !ObjectUtils.anyNotNull(queryUsersListNew.getData()))
throw new BizException("内部接口调用失败"); throw new BizException("内部接口调用失败");
UserInfoResp userInfoNew = queryUsersListNew.getData(); UserInfoResp userInfoNew = queryUsersListNew.getData();
if (StringUtils.isNotBlank(userId) && !StringUtils.equals(userIdMyself, userId)) { //查询别人的个人主页 userInfoNew.setShowFollowStatus(ShowFollowStatusEnum.NOT_FOLLOWED.getCode());
// 关注 按钮的显示逻辑 if (StringUtils.isNotBlank(userIdMyself)) {
FollowRelEntity followRelEntity = followRelService.queryRecord(userId, userIdMyself); if (!StringUtils.equals(userIdMyself, userId)) {
if (ObjectUtils.allNotNull(followRelEntity) && BizStatus.DeleteTag.tag_init == followRelEntity.getDeleteTag()) { // 查询别人的个人主页
userInfoNew.setShowFollowStatus(ShowFollowStatusEnum.FOLLOWED.getCode()); // 已关注 // 关注 按钮的显示逻辑
} else { FollowRelEntity followRelEntity = followRelService.queryRecord(userId, userIdMyself);
userInfoNew.setShowFollowStatus(ShowFollowStatusEnum.NOT_FOLLOWED.getCode()); // 未关注 if (ObjectUtils.allNotNull(followRelEntity) && BizStatus.DeleteTag.tag_init == followRelEntity.getDeleteTag()) {
userInfoNew.setShowFollowStatus(ShowFollowStatusEnum.FOLLOWED.getCode()); // 已关注
}
if (userInfoNew.getWorkshopStatus() == 2) userInfoNew.setWorkshopStatus(1); //别人的主页不需要展示 工作室
} }
if (userInfoNew.getWorkshopStatus() == 2) userInfoNew.setWorkshopStatus(1); //别人的主页不需要展示 工作室
} else {
// 查询自己的主页
userId = userIdMyself;
} }
//获取粉丝数 关注数 //获取粉丝数 关注数
getFansNUmAndFollowNum(userInfoNew); getFansNUmAndFollowNum(userInfoNew);
...@@ -257,26 +258,26 @@ public class HomePageManager { ...@@ -257,26 +258,26 @@ public class HomePageManager {
Page<String> userIdsPage = QueryFollowTypeEnum.QUERY_FANS.getCode().equals(req.getQueryType()) ? Page<String> userIdsPage = QueryFollowTypeEnum.QUERY_FANS.getCode().equals(req.getQueryType()) ?
followRelService.queryFansByIdolId(req.userId, pageNumber, pageSize) followRelService.queryFansByIdolId(req.userId, pageNumber, pageSize)
: followRelService.queryIdolsByFansId(req.userId, pageNumber, pageSize); : followRelService.queryIdolsByFansId(req.userId, pageNumber, pageSize);
List<FollowQo> followQos = new ArrayList<>(); if (CollectionUtils.isEmpty(userIdsPage.getContent())) {
if (!CollectionUtils.isEmpty(userIdsPage.getContent())) { return PageUtils.page(userIdsPage, Lists.newArrayListWithCapacity(0));
List<UserInfoResp> userInfoNews = feignClientForFatools.queryUserListNew(userIdsPage.getContent()); }
List<FollowQo> collect = userInfoNews.stream().map(ConvertUtil::userInfoNew2FollowQo).collect(Collectors.toList()); List<UserInfoResp> userInfoNews = feignClientForFatools.queryUserListNew(userIdsPage.getContent());
followQos = judgeFollowed(collect, userId); List<FollowQo> followQos = userInfoNews.stream().map(ConvertUtil::userInfoNew2FollowQo).collect(Collectors.toList());
if (StringUtils.isNotEmpty(userId)) {
judgeFollowed(followQos, userId);
} }
return PageUtils.page(userIdsPage, followQos); return PageUtils.page(userIdsPage, followQos);
} }
//判断返回列表中的用户是否被当前用户关注 //判断返回列表中的用户是否被当前用户关注
public List<FollowQo> judgeFollowed(List<FollowQo> followQos, String followerId) { public void judgeFollowed(List<FollowQo> followQos, @NotEmpty String followerId) {
Set<String> idolSet = new HashSet<>(followRelService.queryIdolsByFansId(followerId)); Set<String> idolSet = new HashSet<>(followRelService.queryIdolsByFansId(followerId));
return followQos.stream().map(o -> { followQos.stream().peek(o -> {
if (idolSet.contains(o.getUserId())) { if (idolSet.contains(o.getUserId())) {
o.setFollowed(true); o.setFollowed(true);
} }
return o; });
}).collect(Collectors.toList());
} }
public void addFollowRel(FollowRelReq req, String followerId) { public void addFollowRel(FollowRelReq req, String followerId) {
......
...@@ -2,11 +2,13 @@ package com.tanpu.community.manager; ...@@ -2,11 +2,13 @@ package com.tanpu.community.manager;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.tanpu.biz.common.enums.RelTypeEnum; import com.tanpu.biz.common.enums.RelTypeEnum;
import com.tanpu.biz.common.enums.community.CollectionTypeEnum; import com.tanpu.biz.common.enums.community.CollectionTypeEnum;
import com.tanpu.biz.common.enums.community.ReportTypeEnum; import com.tanpu.biz.common.enums.community.ReportTypeEnum;
import com.tanpu.common.api.CommonResp; import com.tanpu.common.api.CommonResp;
import com.tanpu.common.api.ResultCode;
import com.tanpu.common.constant.ErrorCodeConstant; import com.tanpu.common.constant.ErrorCodeConstant;
import com.tanpu.common.enums.fund.ProductTypeEnum; import com.tanpu.common.enums.fund.ProductTypeEnum;
import com.tanpu.common.exception.BizException; import com.tanpu.common.exception.BizException;
...@@ -464,7 +466,7 @@ public class ThemeManager { ...@@ -464,7 +466,7 @@ public class ThemeManager {
* 查询主题列表:推荐/关注/热门/最新 * 查询主题列表:推荐/关注/热门/最新
*/ */
// 查询主题列表:推荐/关注/热门/最新 // 查询主题列表:推荐/关注/热门/最新
public ThemeListResp queryList(ThemeListReq req, String userId) { public ThemeListResp queryList(ThemeListReq req, String userId111) {
List<String> excludeIds = new ArrayList<>(); List<String> excludeIds = new ArrayList<>();
LocalDateTime firstThemeTime = LocalDateTime.now(); LocalDateTime firstThemeTime = LocalDateTime.now();
if (req.page.pageNumber > 1) { if (req.page.pageNumber > 1) {
...@@ -486,14 +488,14 @@ public class ThemeManager { ...@@ -486,14 +488,14 @@ public class ThemeManager {
if (ThemeListTypeEnum.RECOMMEND.getCode().equals(req.getType())) { if (ThemeListTypeEnum.RECOMMEND.getCode().equals(req.getType())) {
// 需要筛掉用户访问过详情的 & 最近出现在列表页过的. // 需要筛掉用户访问过详情的 & 最近出现在列表页过的.
List<String> visitedIds = visitLogService.queryUserRecentVisited(userId); List<String> visitedIds = StringUtils.isEmpty(req.getUserId()) ? Lists.newArrayListWithCapacity(0) : visitLogService.queryUserRecentVisited(req.getUserId());
List<String> excludes = ListUtils.union(excludeIds, visitedIds); List<String> excludes = ListUtils.union(excludeIds, visitedIds);
List<String> recmdIds = recommendService.getRecommendThemes(pageStart, pageSize, userId, excludes, firstThemeTime); List<String> recmdIds = recommendService.getRecommendThemes(pageStart, pageSize, req.getUserId(), excludes, firstThemeTime);
// 加载第一页时,为防止首页显示空列表,从推荐池中再捞出已看过帖子 // 加载第一页时,为防止首页显示空列表,从推荐池中再捞出已看过帖子
if (req.page.pageNumber <= 3 && recmdIds.size() < pageSize) { if (req.page.pageNumber <= 3 && recmdIds.size() < pageSize) {
List<String> reSearchIds = ListUtils.union(excludeIds, recmdIds); List<String> reSearchIds = ListUtils.union(excludeIds, recmdIds);
recmdIds.addAll(recommendService.getRecommendThemes(pageStart, pageSize, userId, reSearchIds, firstThemeTime)); recmdIds.addAll(recommendService.getRecommendThemes(pageStart, pageSize, req.getUserId(), reSearchIds, firstThemeTime));
} }
themes = themeService.queryByThemeIds(recmdIds); themes = themeService.queryByThemeIds(recmdIds);
...@@ -502,17 +504,21 @@ public class ThemeManager { ...@@ -502,17 +504,21 @@ public class ThemeManager {
} else if (ThemeListTypeEnum.FOLLOW.getCode().equals(req.getType())) { } else if (ThemeListTypeEnum.FOLLOW.getCode().equals(req.getType())) {
// 根据关注列表查询,按时间倒序 if (StringUtils.isEmpty(req.getUserId())) {
List<String> fansList = followRelService.queryIdolsByFansId(userId); // 未登录情况下返回空数组
themes = themeService.queryByUserIdsCreateDesc(fansList, pageStart, pageSize); themes = Lists.newArrayListWithCapacity(0);
} else {
if (CollectionUtils.isEmpty(excludeIds) && !themes.isEmpty()) { // 根据关注列表查询,按时间倒序
// 说明是从头开始刷,则直接把最新的lastId放到redis中,保留一个月 List<String> fansList = followRelService.queryIdolsByFansId(req.getUserId());
Long lastId = themes.stream().map(ThemeEntity::getId).max(Long::compareTo).get(); themes = themeService.queryByUserIdsCreateDesc(fansList, pageStart, pageSize);
redisCache.put(CACHE_IDOL_THEME_LAST_ID + userId, lastId, 60 * 60 * 24 * 7 * 4);
if (CollectionUtils.isEmpty(excludeIds) && !themes.isEmpty()) {
// 说明是从头开始刷,则直接把最新的lastId放到redis中,保留一个月
Long lastId = themes.stream().map(ThemeEntity::getId).max(Long::compareTo).get();
redisCache.put(CACHE_IDOL_THEME_LAST_ID + req.getUserId(), lastId, 60 * 60 * 24 * 7 * 4);
// visitLogService.addPageView(userId, userId, VisitTypeEnum.FOLLOW_THEME_VIEW); // visitLogService.addPageView(userId, userId, VisitTypeEnum.FOLLOW_THEME_VIEW);
}
} }
} 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())) {
...@@ -534,7 +540,7 @@ public class ThemeManager { ...@@ -534,7 +540,7 @@ public class ThemeManager {
} }
ThemeListResp resp = new ThemeListResp(); ThemeListResp resp = new ThemeListResp();
resp.themes = convertEntityToQo(themes, userId); resp.themes = convertEntityToQo(themes, req.getUserId());
excludeIds.addAll(resp.themes.stream().map(ThemeQo::getThemeId).collect(Collectors.toList())); excludeIds.addAll(resp.themes.stream().map(ThemeQo::getThemeId).collect(Collectors.toList()));
redisCache.put("queryThemes_" + req.ident, excludeIds, 60 * 60 * 6); redisCache.put("queryThemes_" + req.ident, excludeIds, 60 * 60 * 6);
...@@ -556,8 +562,9 @@ public class ThemeManager { ...@@ -556,8 +562,9 @@ public class ThemeManager {
} }
// 和用户相关信息 // 和用户相关信息
buildThemeExtraInfoByUser(userId, themeQos); if (StringUtils.isNotEmpty(userId)) {
buildThemeExtraInfoByUser(userId, themeQos);
}
return themeQos; return themeQos;
} }
...@@ -647,7 +654,7 @@ public class ThemeManager { ...@@ -647,7 +654,7 @@ public class ThemeManager {
} }
List<ThemeQo> themeQos = convertEntityToQo(themeEntities, userId); List<ThemeQo> themeQos = convertEntityToQo(themeEntities, userId);
if (userId.equals(req.getUserId())) { if (StringUtils.equals(userId, req.getUserId())) {
//如果用户是查询自己的帖子,需要实时查询用户自己的个人信息,防止数据不一致(非收藏类型) //如果用户是查询自己的帖子,需要实时查询用户自己的个人信息,防止数据不一致(非收藏类型)
CommonResp<UserInfoResp> userInfoNewCommonResp = feignClientForFatools.queryUserInfoNew(userId); CommonResp<UserInfoResp> userInfoNewCommonResp = feignClientForFatools.queryUserInfoNew(userId);
if (userInfoNewCommonResp.isNotSuccess()) { if (userInfoNewCommonResp.isNotSuccess()) {
...@@ -684,7 +691,9 @@ public class ThemeManager { ...@@ -684,7 +691,9 @@ public class ThemeManager {
buildThemeQoExtraInfo(themeQo); buildThemeQoExtraInfo(themeQo);
// 添加用户相关信息 // 添加用户相关信息
buildThemeExtraInfoByUser(userId, themeQo); if (StringUtils.isNotEmpty(userId)) {
buildThemeExtraInfoByUser(userId, themeQo);
}
return CommonResp.success(themeQo); return CommonResp.success(themeQo);
} }
...@@ -905,7 +914,8 @@ public class ThemeManager { ...@@ -905,7 +914,8 @@ public class ThemeManager {
.content(Collections.singletonList(commentContent)) .content(Collections.singletonList(commentContent))
.commentId(commentEntity.getCommentId()) .commentId(commentEntity.getCommentId())
.themeType(ThemeTypeEnum.RES_COMMENT.getCode()) .themeType(ThemeTypeEnum.RES_COMMENT.getCode())
.follow(followRelService.checkFollow(userId, userId)) // 回复列表不需要关注按钮
// .follow(followRelService.checkFollow(userInfo.getUserId(), userId))
.upToNowTime(TimeUtils.calUpToNowTime(commentEntity.getCreateTime())) .upToNowTime(TimeUtils.calUpToNowTime(commentEntity.getCreateTime()))
.build(); .build();
......
package com.tanpu.community.service; package com.tanpu.community.service;
import com.google.common.collect.Lists;
import com.tanpu.common.util.JsonUtil; import com.tanpu.common.util.JsonUtil;
import com.tanpu.community.api.beans.qo.ThemeAnalysDO; import com.tanpu.community.api.beans.qo.ThemeAnalysDO;
import com.tanpu.community.api.beans.resp.PythonResponse; import com.tanpu.community.api.beans.resp.PythonResponse;
...@@ -8,6 +9,7 @@ import com.tanpu.community.util.BizUtils; ...@@ -8,6 +9,7 @@ import com.tanpu.community.util.BizUtils;
import com.tanpu.community.util.ConvertUtil; import com.tanpu.community.util.ConvertUtil;
import com.tanpu.community.util.TimeUtils; import com.tanpu.community.util.TimeUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -72,11 +74,16 @@ public class RecommendService { ...@@ -72,11 +74,16 @@ public class RecommendService {
newThemeIds = BizUtils.subList(newThemeIds, 0, pageSize); newThemeIds = BizUtils.subList(newThemeIds, 0, pageSize);
//推荐话题 //推荐话题
List<String> recThemeIds = getPythonRecommendList(userId).stream() List<String> recThemeIds;
.filter(id -> { if (StringUtils.isNotEmpty(userId)) {
return !excludeIds.contains(id); recThemeIds = getPythonRecommendList(userId).stream()
}).collect(Collectors.toList()); .filter(id -> {
recThemeIds = BizUtils.subList(recThemeIds, pageStart, pageSize); return !excludeIds.contains(id);
}).collect(Collectors.toList());
recThemeIds = BizUtils.subList(recThemeIds, pageStart, pageSize);
} else {
recThemeIds = Lists.newArrayListWithCapacity(0);
}
// merge // merge
return mergeRecommend(hotThemeIds, newThemeIds, recThemeIds); return mergeRecommend(hotThemeIds, newThemeIds, recThemeIds);
......
package com.tanpu.community.util;
import com.tanpu.common.redis.RedisHelper;
import com.tanpu.community.api.constants.RedisKeyConstant;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpCookie;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.Optional;
/**
* @Description TODO
* @Author wangyalei
* @Date 2021/9/23 下午8:31
**/
@Slf4j
@Service
public class HttpServletHelper {
@Resource
private RedisHelper redisHelper;
public String getCurrentUserId() {
String userId = null;
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
String clientEnv = request.getHeader(RedisKeyConstant.ENV);
if (isAndroid(clientEnv) || isIOS(clientEnv) || isPc(clientEnv) || isMiniProgram(clientEnv)) {
// android,ios,pc,小程序用token
String token = request.getHeader(RedisKeyConstant.TAMP_TOKEN);
// redis获取的value,都带有 "",这里去掉
userId = StringUtils.remove(redisHelper.get(RedisKeyConstant.REDIS_PREFIX_TOKEN + token), "\"");
} else {
// 用cookie
Cookie[] cookies = request.getCookies();
if (cookies != null) {
Optional<Cookie> first = Arrays.stream(request.getCookies())
.filter(cookie -> StringUtils.equalsIgnoreCase(RedisKeyConstant.SESSION_COOKIE_NAME, cookie.getName()))
.findFirst();
if (first.isPresent()) {
userId = first.get().getValue();
}
}
}
log.debug("当前登录用户Id: {}", userId);
return userId;
}
public static boolean isAndroid(String clientEnv) {
return "android".equalsIgnoreCase(clientEnv);
}
public static boolean isIOS(String clientEnv) {
return "ios".equalsIgnoreCase(clientEnv);
}
public static boolean isPc(String clientEnv) {
return "pc".equalsIgnoreCase(clientEnv);
}
public static boolean isMiniProgram(String clientEnv) {
return "xcx".equalsIgnoreCase(clientEnv);
}
}
...@@ -96,4 +96,14 @@ recommend: ...@@ -96,4 +96,14 @@ recommend:
python: 1 python: 1
python: python:
enable: false enable: false
url: http://172.168.0.164:9000/api/get_recommend?user_id=2431614397151511 url: http://172.168.0.164:9000/api/get_recommend?user_id=2431614397151511
\ No newline at end of file
tmpfile:
dir: /data/tmp
tanpu:
fatools:
svc: https://testtamper.tanpuyun.com
jifen:
svc: https://testtamper.tanpuyun.com
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