Commit 6b638eac authored by 王亚雷's avatar 王亚雷

游客权限

parent 0efc6dbf
...@@ -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_";
//收藏量 //收藏量
......
...@@ -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,15 @@ public class HomePageController { ...@@ -41,13 +46,15 @@ public class HomePageController {
@Resource @Resource
private UserHolder userHolder; private UserHolder userHolder;
@Resource
HttpServletHelper httpServletHelper;
// 用户信息查询 (供圈子服务调用) // 用户信息查询 (供圈子服务调用)
@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 = httpServletHelper.getCurrentUserId();
String userIdMyself = userHolder.getUserId(); return CommonResp.success(homePageManager.queryUsersInfo(selfUserId, userId));
return CommonResp.success(homePageManager.queryUsersInfo(userIdMyself, userId));
} }
// 理财师客户列表查询 (供圈子服务调用) // 理财师客户列表查询 (供圈子服务调用)
......
...@@ -44,12 +44,11 @@ public class ThemeController { ...@@ -44,12 +44,11 @@ public class ThemeController {
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);
} }
......
...@@ -88,12 +88,14 @@ public class HomePageManager { ...@@ -88,12 +88,14 @@ 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)) { //查询别人的个人主页 if (StringUtils.isNotBlank(userIdMyself)) {
if (!StringUtils.equals(userIdMyself, userId)) {
// 查询别人的个人主页
// 关注 按钮的显示逻辑 // 关注 按钮的显示逻辑
FollowRelEntity followRelEntity = followRelService.queryRecord(userId, userIdMyself); FollowRelEntity followRelEntity = followRelService.queryRecord(userId, userIdMyself);
if (ObjectUtils.allNotNull(followRelEntity) && BizStatus.DeleteTag.tag_init == followRelEntity.getDeleteTag()) { if (ObjectUtils.allNotNull(followRelEntity) && BizStatus.DeleteTag.tag_init == followRelEntity.getDeleteTag()) {
...@@ -102,9 +104,7 @@ public class HomePageManager { ...@@ -102,9 +104,7 @@ public class HomePageManager {
userInfoNew.setShowFollowStatus(ShowFollowStatusEnum.NOT_FOLLOWED.getCode()); // 未关注 userInfoNew.setShowFollowStatus(ShowFollowStatusEnum.NOT_FOLLOWED.getCode()); // 未关注
} }
if (userInfoNew.getWorkshopStatus() == 2) userInfoNew.setWorkshopStatus(1); //别人的主页不需要展示 工作室 if (userInfoNew.getWorkshopStatus() == 2) userInfoNew.setWorkshopStatus(1); //别人的主页不需要展示 工作室
} else { }
// 查询自己的主页
userId = userIdMyself;
} }
//获取粉丝数 关注数 //获取粉丝数 关注数
getFansNUmAndFollowNum(userInfoNew); getFansNUmAndFollowNum(userInfoNew);
......
...@@ -690,7 +690,9 @@ public class ThemeManager { ...@@ -690,7 +690,9 @@ public class ThemeManager {
buildThemeQoExtraInfo(themeQo); buildThemeQoExtraInfo(themeQo);
// 添加用户相关信息 // 添加用户相关信息
if (StringUtils.isNotEmpty(userId)) {
buildThemeExtraInfoByUser(userId, themeQo); buildThemeExtraInfoByUser(userId, themeQo);
}
return CommonResp.success(themeQo); return CommonResp.success(themeQo);
} }
......
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);
userId = 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();
}
}
}
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);
}
}
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