增加获取uuid的方法,为压测环境的同一token购物车重复问题处理

This commit is contained in:
Chopper 2022-01-12 11:20:27 +08:00
parent 62804941c2
commit 65e7f9750a
4 changed files with 18 additions and 6 deletions

View File

@ -52,9 +52,6 @@ public class UploadController {
@Autowired @Autowired
private Cache cache; private Cache cache;
@Autowired
private SystemSettingProperties systemSettingProperties;
@ApiOperation(value = "文件上传") @ApiOperation(value = "文件上传")
@PostMapping(value = "/file") @PostMapping(value = "/file")
public ResultMessage<Object> upload(MultipartFile file, public ResultMessage<Object> upload(MultipartFile file,

View File

@ -37,6 +37,20 @@ public class UserContext {
return null; return null;
} }
/**
* 根据request获取用户信息
*
* @return 授权用户
*/
public static String getUuid() {
if (RequestContextHolder.getRequestAttributes() != null) {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
String uuid = request.getHeader(SecurityEnum.UUID.getValue());
return uuid;
}
return null;
}
/** /**
* 根据jwt获取token重的用户信息 * 根据jwt获取token重的用户信息

View File

@ -10,7 +10,7 @@ public enum SecurityEnum {
/** /**
* 存在与header中的token参数头 * 存在与header中的token参数头
*/ */
HEADER_TOKEN("accessToken"), USER_CONTEXT("userContext"), JWT_SECRET("secret"); HEADER_TOKEN("accessToken"), USER_CONTEXT("userContext"), JWT_SECRET("secret"), UUID("uuid");
String value; String value;

View File

@ -229,8 +229,9 @@ public class CartServiceImpl implements CartService {
//缓存key默认使用购物车 //缓存key默认使用购物车
if (cartTypeEnum != null) { if (cartTypeEnum != null) {
AuthUser currentUser = UserContext.getCurrentUser(); // AuthUser currentUser = UserContext.getCurrentUser();
return cartTypeEnum.getPrefix() + currentUser.getId(); // return cartTypeEnum.getPrefix() + currentUser.getId();
return cartTypeEnum.getPrefix() + UserContext.getUuid();
} }
throw new ServiceException(ResultCode.ERROR); throw new ServiceException(ResultCode.ERROR);
} }