Commit 914d0c9f authored by 王亚雷's avatar 王亚雷

Merge remote-tracking branch 'origin/bugfix-20211015'

parents 5cf99e31 0bae3870
...@@ -78,7 +78,7 @@ public class HomePageController { ...@@ -78,7 +78,7 @@ public class HomePageController {
@ApiOperation("查询关注/粉丝列表") @ApiOperation("查询关注/粉丝列表")
@ResponseBody @ResponseBody
public CommonResp<Page<FollowQo>> queryFollowList(@RequestBody QueryFollowReq req) { public CommonResp<Page<FollowQo>> queryFollowList(@RequestBody QueryFollowReq req) {
String selfUserId = httpServletHelper.getCurrentUserId(); String selfUserId = userHolder.getUserId();
// 为空查询当前用户自己的粉丝/关注列表 // 为空查询当前用户自己的粉丝/关注列表
if (StringUtils.isEmpty(req.getUserId()) && StringUtils.isNotEmpty(selfUserId)) { if (StringUtils.isEmpty(req.getUserId()) && StringUtils.isNotEmpty(selfUserId)) {
req.setUserId(selfUserId); req.setUserId(selfUserId);
......
...@@ -264,20 +264,21 @@ public class HomePageManager { ...@@ -264,20 +264,21 @@ public class HomePageManager {
List<UserInfoResp> userInfoNews = feignClientForFatools.queryUserListNew(userIdsPage.getContent()); List<UserInfoResp> userInfoNews = feignClientForFatools.queryUserListNew(userIdsPage.getContent());
List<FollowQo> followQos = userInfoNews.stream().map(ConvertUtil::userInfoNew2FollowQo).collect(Collectors.toList()); List<FollowQo> followQos = userInfoNews.stream().map(ConvertUtil::userInfoNew2FollowQo).collect(Collectors.toList());
if (StringUtils.isNotEmpty(userId)) { if (StringUtils.isNotEmpty(userId)) {
judgeFollowed(followQos, userId); followQos = judgeFollowed(followQos, userId);
} }
return PageUtils.page(userIdsPage, followQos); return PageUtils.page(userIdsPage, followQos);
} }
//判断返回列表中的用户是否被当前用户关注 //判断返回列表中的用户是否被当前用户关注
public void judgeFollowed(List<FollowQo> followQos, @NotEmpty String followerId) { public List<FollowQo> judgeFollowed(List<FollowQo> followQos, @NotEmpty String followerId) {
Set<String> idolSet = new HashSet<>(followRelService.queryIdolsByFansId(followerId)); Set<String> idolSet = new HashSet<>(followRelService.queryIdolsByFansId(followerId));
followQos.stream().peek(o -> { return followQos.stream().map(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) {
......
package com.tanpu.community.util; package com.tanpu.community.util;
import com.tanpu.common.auth.UserHolder;
import com.tanpu.common.redis.RedisHelper; import com.tanpu.common.redis.RedisHelper;
import com.tanpu.community.api.constants.RedisKeyConstant; import com.tanpu.community.api.constants.RedisKeyConstant;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -26,28 +27,31 @@ import java.util.Optional; ...@@ -26,28 +27,31 @@ import java.util.Optional;
public class HttpServletHelper { public class HttpServletHelper {
@Resource @Resource
private RedisHelper redisHelper; private RedisHelper redisHelper;
@Resource
private UserHolder userHolder;
public String getCurrentUserId() { public String getCurrentUserId() {
String userId = null; // String userId = null;
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest(); // HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
String clientEnv = request.getHeader(RedisKeyConstant.ENV); // String clientEnv = request.getHeader(RedisKeyConstant.ENV);
if (isAndroid(clientEnv) || isIOS(clientEnv) || isPc(clientEnv) || isMiniProgram(clientEnv)) { // if (isAndroid(clientEnv) || isIOS(clientEnv) || isPc(clientEnv) || isMiniProgram(clientEnv)) {
// android,ios,pc,小程序用token // // android,ios,pc,小程序用token
String token = request.getHeader(RedisKeyConstant.TAMP_TOKEN); // String token = request.getHeader(RedisKeyConstant.TAMP_TOKEN);
// redis获取的value,都带有 "",这里去掉 // // redis获取的value,都带有 "",这里去掉
userId = StringUtils.remove(redisHelper.get(RedisKeyConstant.REDIS_PREFIX_TOKEN + token), "\""); // userId = StringUtils.remove(redisHelper.get(RedisKeyConstant.REDIS_PREFIX_TOKEN + token), "\"");
} else { // } else {
// 用cookie // // 用cookie
Cookie[] cookies = request.getCookies(); // Cookie[] cookies = request.getCookies();
if (cookies != null) { // if (cookies != null) {
Optional<Cookie> first = Arrays.stream(request.getCookies()) // Optional<Cookie> first = Arrays.stream(request.getCookies())
.filter(cookie -> StringUtils.equalsIgnoreCase(RedisKeyConstant.SESSION_COOKIE_NAME, cookie.getName())) // .filter(cookie -> StringUtils.equalsIgnoreCase(RedisKeyConstant.SESSION_COOKIE_NAME, cookie.getName()))
.findFirst(); // .findFirst();
if (first.isPresent()) { // if (first.isPresent()) {
userId = first.get().getValue(); // userId = first.get().getValue();
} // }
} // }
} // }
String userId = userHolder.getUserId();
log.debug("当前登录用户Id: {}", userId); log.debug("当前登录用户Id: {}", userId);
return userId; return userId;
} }
......
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