refactor(resource): 调整用户身份获取方法
parent
7597e9d74d
commit
477d1c0dea
|
@ -48,9 +48,9 @@ public class ModelCommentController {
|
|||
@RepeatSubmit
|
||||
@GetMapping("/modelLike")
|
||||
public R<Object> like(@Valid
|
||||
@NotNull(message = "模型id不能为空")
|
||||
@ApiParam(value = "模型id", required = true)
|
||||
Long modelId) {
|
||||
@NotNull(message = "模型id不能为空")
|
||||
@ApiParam(value = "模型id", required = true)
|
||||
Long modelId) {
|
||||
modelLikeService.like(modelId);
|
||||
return R.ok();
|
||||
}
|
||||
|
@ -73,9 +73,9 @@ public class ModelCommentController {
|
|||
@RepeatSubmit
|
||||
@GetMapping("/commentLike")
|
||||
public R<Object> commentLike(@Valid
|
||||
@NotNull(message = "评论id不能为空")
|
||||
@ApiParam(value = "评论id", required = true)
|
||||
Long commentId) {
|
||||
@NotNull(message = "评论id不能为空")
|
||||
@ApiParam(value = "评论id", required = true)
|
||||
Long commentId) {
|
||||
modelCommentLikeService.like(commentId);
|
||||
return R.ok();
|
||||
}
|
||||
|
@ -88,13 +88,13 @@ public class ModelCommentController {
|
|||
@GetMapping("/comment")
|
||||
@Valid
|
||||
public R<List<ModelCommentVo>> getComment(@Valid
|
||||
@NotNull(message = "模型id不能为空")
|
||||
@ApiParam(value = "模型id", required = true)
|
||||
Long modelId,
|
||||
@NotNull(message = "模型id不能为空")
|
||||
@ApiParam(value = "模型id", required = true)
|
||||
Long modelId,
|
||||
@Valid
|
||||
@NotNull(message = "排序方式不能为空")
|
||||
@ApiParam(value = "排序方式 0最热 1最新", required = true)
|
||||
Integer sortType) {
|
||||
@NotNull(message = "排序方式不能为空")
|
||||
@ApiParam(value = "排序方式 0最热 1最新", required = true)
|
||||
Integer sortType) {
|
||||
List<ModelCommentVo> modelCommentList = modelCommentService.getComment(modelId, sortType);
|
||||
return R.ok(modelCommentList);
|
||||
}
|
||||
|
@ -106,9 +106,9 @@ public class ModelCommentController {
|
|||
@ApiOperation(value = "删除模型评论")
|
||||
@GetMapping("/commentDelete")
|
||||
public R<Object> commentDelete(@Valid
|
||||
@NotNull(message = "评论id不能为空")
|
||||
@ApiParam(value = "评论id", required = true)
|
||||
Long commentId) {
|
||||
@NotNull(message = "评论id不能为空")
|
||||
@ApiParam(value = "评论id", required = true)
|
||||
Long commentId) {
|
||||
modelCommentService.removeById(commentId);
|
||||
return R.ok();
|
||||
}
|
||||
|
|
|
@ -51,9 +51,9 @@ public class ModelImageCommentController {
|
|||
@RepeatSubmit(interval = 1000)
|
||||
@GetMapping("/commentLike")
|
||||
public R<Object> commentLike(@Valid
|
||||
@NotNull(message = "评论id不能为空")
|
||||
@ApiParam(value = "评论id", required = true)
|
||||
Long commentId) {
|
||||
@NotNull(message = "评论id不能为空")
|
||||
@ApiParam(value = "评论id", required = true)
|
||||
Long commentId) {
|
||||
modelImageCommentLikeService.like(commentId);
|
||||
return R.ok();
|
||||
}
|
||||
|
@ -64,8 +64,8 @@ public class ModelImageCommentController {
|
|||
@ApiOperation(value = "删除图片评论")
|
||||
@GetMapping("/commentDelete")
|
||||
public R<Object> commentDelete(@Valid
|
||||
@NotNull(message = "评论id不能为空")
|
||||
@ApiParam(value = "评论id", required = true) Long commentId) {
|
||||
@NotNull(message = "评论id不能为空")
|
||||
@ApiParam(value = "评论id", required = true) Long commentId) {
|
||||
modelImageCommentService.removeById(commentId);
|
||||
return R.ok();
|
||||
}
|
||||
|
@ -77,13 +77,13 @@ public class ModelImageCommentController {
|
|||
@GetMapping("/comment")
|
||||
@Valid
|
||||
public R<List<ModelImageCommentVo>> getComment(@Valid
|
||||
@NotNull(message = "图片id不能为空")
|
||||
@ApiParam(value = "评论id", required = true)
|
||||
Long imageId,
|
||||
@NotNull(message = "图片id不能为空")
|
||||
@ApiParam(value = "评论id", required = true)
|
||||
Long imageId,
|
||||
@Valid
|
||||
@NotNull(message = "排序方式不能为空")
|
||||
@ApiParam(value = "排序方式 0最热 1最新", required = true)
|
||||
Integer sortType) {
|
||||
@NotNull(message = "排序方式不能为空")
|
||||
@ApiParam(value = "排序方式 0最热 1最新", required = true)
|
||||
Integer sortType) {
|
||||
List<ModelImageCommentVo> modelImageCommentVoList = modelImageCommentService.getComment(imageId, sortType);
|
||||
return R.ok(modelImageCommentVoList);
|
||||
}
|
||||
|
|
|
@ -42,14 +42,11 @@ public class SecurityUtils
|
|||
|
||||
public static Long getUserIdMax(){
|
||||
|
||||
Long userId = null;
|
||||
Long userId;
|
||||
try {
|
||||
userId = SecurityUtils.getUserId();
|
||||
if (userId == null){
|
||||
userId = 0L;
|
||||
}
|
||||
}catch (Exception e){
|
||||
log.error(e.getMessage());
|
||||
userId = 0L;
|
||||
}
|
||||
|
||||
return userId;
|
||||
|
|
|
@ -146,8 +146,8 @@ public class ModelCommentServiceImpl extends ServiceImpl<ModelCommentMapper, Mod
|
|||
List<Long> allCommentIds = collectAllCommentIds(parentComments, childComments);
|
||||
|
||||
// 5. 批量查询点赞状态(仅当用户已登录)
|
||||
Map<Long, Integer> likeStatusMap = SecurityUtils.getUserId() != null ?
|
||||
batchGetLikeStatus(allCommentIds, SecurityUtils.getUserId()) :
|
||||
Map<Long, Integer> likeStatusMap = SecurityUtils.getUserIdMax() != null ?
|
||||
batchGetLikeStatus(allCommentIds, SecurityUtils.getUserIdMax()) :
|
||||
new HashMap<>();
|
||||
|
||||
// 6. 构建评论树结构(传递点赞状态)
|
||||
|
|
|
@ -131,8 +131,8 @@ public class ModelImageCommentServiceImpl extends ServiceImpl<ModelImageCommentM
|
|||
List<Long> allCommentIds = collectAllCommentIds(parentComments, childComments);
|
||||
|
||||
// 5. 批量查询点赞状态(仅当用户已登录)
|
||||
Map<Long, Integer> likeStatusMap = SecurityUtils.getUserId() != null ?
|
||||
batchGetLikeStatus(allCommentIds, SecurityUtils.getUserId()) :
|
||||
Map<Long, Integer> likeStatusMap = SecurityUtils.getUserIdMax() != 0 ?
|
||||
batchGetLikeStatus(allCommentIds, SecurityUtils.getUserIdMax()) :
|
||||
new HashMap<>();
|
||||
|
||||
// 6. 构建评论树结构(传递点赞状态)
|
||||
|
|
|
@ -236,7 +236,7 @@ public class ModelImageServiceImpl extends ServiceImpl<ModelImageMapper, ModelIm
|
|||
BeanUtil.copyProperties(modelImage, modelImageVo);
|
||||
|
||||
ModelImageLike modelImageLike = modelImageLikeService.lambdaQuery()
|
||||
.eq(ModelImageLike::getUserId, SecurityUtils.getUserId())
|
||||
.eq(ModelImageLike::getUserId, SecurityUtils.getUserIdMax())
|
||||
.eq(ModelImageLike::getModelImageId, imageId)
|
||||
.one();
|
||||
|
||||
|
@ -255,8 +255,8 @@ public class ModelImageServiceImpl extends ServiceImpl<ModelImageMapper, ModelIm
|
|||
modelImageVo.setTags(tagList);
|
||||
|
||||
SysUser sysUser = sysUserService.selectUserById(modelImage.getUserId());
|
||||
modelImageVo.setUserId(SecurityUtils.getUserId());
|
||||
modelImageVo.setUserName(SecurityUtils.getUsername());
|
||||
modelImageVo.setUserId(sysUser.getUserId());
|
||||
modelImageVo.setUserName(sysUser.getUserName());
|
||||
modelImageVo.setUserAvatar(sysUser.getAvatar());
|
||||
return modelImageVo;
|
||||
}
|
||||
|
|
|
@ -492,12 +492,12 @@ public class ModelServiceImpl extends ServiceImpl<ModelMapper,ModelProduct> impl
|
|||
}
|
||||
|
||||
modelProduct.setIsAttention(1);
|
||||
SysUserAttention sysUserAttention = sysUserAttentionMapper.selectAttention(SecurityUtils.getUserId(), modelProduct.getUserId());
|
||||
SysUserAttention sysUserAttention = sysUserAttentionMapper.selectAttention(SecurityUtils.getUserIdMax(), modelProduct.getUserId());
|
||||
if (sysUserAttention == null){
|
||||
modelProduct.setIsAttention(0);
|
||||
}
|
||||
|
||||
WorkFlowLike workFlowLike = modelLikeMapper.selectModelLikeById(SecurityUtils.getUserId(),modelProduct.getId());
|
||||
WorkFlowLike workFlowLike = modelLikeMapper.selectModelLikeById(SecurityUtils.getUserIdMax(),modelProduct.getId());
|
||||
modelProduct.setIsLike(1);
|
||||
if (workFlowLike == null){
|
||||
modelProduct.setIsLike(0);
|
||||
|
|
|
@ -88,13 +88,9 @@ public class SysUserAttentionServiceImpl extends ServiceImpl<SysUserAttentionMap
|
|||
@Override
|
||||
public Boolean selectAttention(Long userId) {
|
||||
|
||||
SysUserAttention sysUserAttention = sysUserAttentionMapper.selectAttention(SecurityUtils.getUserId(), userId);
|
||||
SysUserAttention sysUserAttention = sysUserAttentionMapper.selectAttention(SecurityUtils.getUserIdMax(), userId);
|
||||
|
||||
if (sysUserAttention == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return sysUserAttention != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -391,12 +391,12 @@ public class WorkFlowServiceImpl extends ServiceImpl<WorkFlowMapper, WorkFlow> i
|
|||
workFlow.setTypeList(strings);
|
||||
}
|
||||
workFlow.setIsAttention(1);
|
||||
SysUserAttention sysUserAttention = sysUserAttentionMapper.selectAttention(SecurityUtils.getUserId(), workFlow.getUserId());
|
||||
SysUserAttention sysUserAttention = sysUserAttentionMapper.selectAttention(SecurityUtils.getUserIdMax(), workFlow.getUserId());
|
||||
if (sysUserAttention == null){
|
||||
workFlow.setIsAttention(0);
|
||||
}
|
||||
|
||||
WorkFlowLike workFlowLike = workFlowLikeService.selectWorkFlowLikeById(SecurityUtils.getUserId(),workFlow.getId());
|
||||
WorkFlowLike workFlowLike = workFlowLikeService.selectWorkFlowLikeById(SecurityUtils.getUserIdMax(),workFlow.getId());
|
||||
workFlow.setIsLike(1);
|
||||
if (workFlowLike == null){
|
||||
workFlow.setIsLike(0);
|
||||
|
|
Loading…
Reference in New Issue