refactor(resource): 调整用户身份获取方法

master
yang 2025-02-20 14:47:33 +08:00
parent 7597e9d74d
commit 477d1c0dea
9 changed files with 41 additions and 48 deletions

View File

@ -48,9 +48,9 @@ public class ModelCommentController {
@RepeatSubmit @RepeatSubmit
@GetMapping("/modelLike") @GetMapping("/modelLike")
public R<Object> like(@Valid public R<Object> like(@Valid
@NotNull(message = "模型id不能为空") @NotNull(message = "模型id不能为空")
@ApiParam(value = "模型id", required = true) @ApiParam(value = "模型id", required = true)
Long modelId) { Long modelId) {
modelLikeService.like(modelId); modelLikeService.like(modelId);
return R.ok(); return R.ok();
} }
@ -73,9 +73,9 @@ public class ModelCommentController {
@RepeatSubmit @RepeatSubmit
@GetMapping("/commentLike") @GetMapping("/commentLike")
public R<Object> commentLike(@Valid public R<Object> commentLike(@Valid
@NotNull(message = "评论id不能为空") @NotNull(message = "评论id不能为空")
@ApiParam(value = "评论id", required = true) @ApiParam(value = "评论id", required = true)
Long commentId) { Long commentId) {
modelCommentLikeService.like(commentId); modelCommentLikeService.like(commentId);
return R.ok(); return R.ok();
} }
@ -88,13 +88,13 @@ public class ModelCommentController {
@GetMapping("/comment") @GetMapping("/comment")
@Valid @Valid
public R<List<ModelCommentVo>> getComment(@Valid public R<List<ModelCommentVo>> getComment(@Valid
@NotNull(message = "模型id不能为空") @NotNull(message = "模型id不能为空")
@ApiParam(value = "模型id", required = true) @ApiParam(value = "模型id", required = true)
Long modelId, Long modelId,
@Valid @Valid
@NotNull(message = "排序方式不能为空") @NotNull(message = "排序方式不能为空")
@ApiParam(value = "排序方式 0最热 1最新", required = true) @ApiParam(value = "排序方式 0最热 1最新", required = true)
Integer sortType) { Integer sortType) {
List<ModelCommentVo> modelCommentList = modelCommentService.getComment(modelId, sortType); List<ModelCommentVo> modelCommentList = modelCommentService.getComment(modelId, sortType);
return R.ok(modelCommentList); return R.ok(modelCommentList);
} }
@ -106,9 +106,9 @@ public class ModelCommentController {
@ApiOperation(value = "删除模型评论") @ApiOperation(value = "删除模型评论")
@GetMapping("/commentDelete") @GetMapping("/commentDelete")
public R<Object> commentDelete(@Valid public R<Object> commentDelete(@Valid
@NotNull(message = "评论id不能为空") @NotNull(message = "评论id不能为空")
@ApiParam(value = "评论id", required = true) @ApiParam(value = "评论id", required = true)
Long commentId) { Long commentId) {
modelCommentService.removeById(commentId); modelCommentService.removeById(commentId);
return R.ok(); return R.ok();
} }

View File

@ -51,9 +51,9 @@ public class ModelImageCommentController {
@RepeatSubmit(interval = 1000) @RepeatSubmit(interval = 1000)
@GetMapping("/commentLike") @GetMapping("/commentLike")
public R<Object> commentLike(@Valid public R<Object> commentLike(@Valid
@NotNull(message = "评论id不能为空") @NotNull(message = "评论id不能为空")
@ApiParam(value = "评论id", required = true) @ApiParam(value = "评论id", required = true)
Long commentId) { Long commentId) {
modelImageCommentLikeService.like(commentId); modelImageCommentLikeService.like(commentId);
return R.ok(); return R.ok();
} }
@ -64,8 +64,8 @@ public class ModelImageCommentController {
@ApiOperation(value = "删除图片评论") @ApiOperation(value = "删除图片评论")
@GetMapping("/commentDelete") @GetMapping("/commentDelete")
public R<Object> commentDelete(@Valid public R<Object> commentDelete(@Valid
@NotNull(message = "评论id不能为空") @NotNull(message = "评论id不能为空")
@ApiParam(value = "评论id", required = true) Long commentId) { @ApiParam(value = "评论id", required = true) Long commentId) {
modelImageCommentService.removeById(commentId); modelImageCommentService.removeById(commentId);
return R.ok(); return R.ok();
} }
@ -77,13 +77,13 @@ public class ModelImageCommentController {
@GetMapping("/comment") @GetMapping("/comment")
@Valid @Valid
public R<List<ModelImageCommentVo>> getComment(@Valid public R<List<ModelImageCommentVo>> getComment(@Valid
@NotNull(message = "图片id不能为空") @NotNull(message = "图片id不能为空")
@ApiParam(value = "评论id", required = true) @ApiParam(value = "评论id", required = true)
Long imageId, Long imageId,
@Valid @Valid
@NotNull(message = "排序方式不能为空") @NotNull(message = "排序方式不能为空")
@ApiParam(value = "排序方式 0最热 1最新", required = true) @ApiParam(value = "排序方式 0最热 1最新", required = true)
Integer sortType) { Integer sortType) {
List<ModelImageCommentVo> modelImageCommentVoList = modelImageCommentService.getComment(imageId, sortType); List<ModelImageCommentVo> modelImageCommentVoList = modelImageCommentService.getComment(imageId, sortType);
return R.ok(modelImageCommentVoList); return R.ok(modelImageCommentVoList);
} }

View File

@ -42,14 +42,11 @@ public class SecurityUtils
public static Long getUserIdMax(){ public static Long getUserIdMax(){
Long userId = null; Long userId;
try { try {
userId = SecurityUtils.getUserId(); userId = SecurityUtils.getUserId();
if (userId == null){
userId = 0L;
}
}catch (Exception e){ }catch (Exception e){
log.error(e.getMessage()); userId = 0L;
} }
return userId; return userId;

View File

@ -146,8 +146,8 @@ public class ModelCommentServiceImpl extends ServiceImpl<ModelCommentMapper, Mod
List<Long> allCommentIds = collectAllCommentIds(parentComments, childComments); List<Long> allCommentIds = collectAllCommentIds(parentComments, childComments);
// 5. 批量查询点赞状态(仅当用户已登录) // 5. 批量查询点赞状态(仅当用户已登录)
Map<Long, Integer> likeStatusMap = SecurityUtils.getUserId() != null ? Map<Long, Integer> likeStatusMap = SecurityUtils.getUserIdMax() != null ?
batchGetLikeStatus(allCommentIds, SecurityUtils.getUserId()) : batchGetLikeStatus(allCommentIds, SecurityUtils.getUserIdMax()) :
new HashMap<>(); new HashMap<>();
// 6. 构建评论树结构(传递点赞状态) // 6. 构建评论树结构(传递点赞状态)

View File

@ -131,8 +131,8 @@ public class ModelImageCommentServiceImpl extends ServiceImpl<ModelImageCommentM
List<Long> allCommentIds = collectAllCommentIds(parentComments, childComments); List<Long> allCommentIds = collectAllCommentIds(parentComments, childComments);
// 5. 批量查询点赞状态(仅当用户已登录) // 5. 批量查询点赞状态(仅当用户已登录)
Map<Long, Integer> likeStatusMap = SecurityUtils.getUserId() != null ? Map<Long, Integer> likeStatusMap = SecurityUtils.getUserIdMax() != 0 ?
batchGetLikeStatus(allCommentIds, SecurityUtils.getUserId()) : batchGetLikeStatus(allCommentIds, SecurityUtils.getUserIdMax()) :
new HashMap<>(); new HashMap<>();
// 6. 构建评论树结构(传递点赞状态) // 6. 构建评论树结构(传递点赞状态)

View File

@ -236,7 +236,7 @@ public class ModelImageServiceImpl extends ServiceImpl<ModelImageMapper, ModelIm
BeanUtil.copyProperties(modelImage, modelImageVo); BeanUtil.copyProperties(modelImage, modelImageVo);
ModelImageLike modelImageLike = modelImageLikeService.lambdaQuery() ModelImageLike modelImageLike = modelImageLikeService.lambdaQuery()
.eq(ModelImageLike::getUserId, SecurityUtils.getUserId()) .eq(ModelImageLike::getUserId, SecurityUtils.getUserIdMax())
.eq(ModelImageLike::getModelImageId, imageId) .eq(ModelImageLike::getModelImageId, imageId)
.one(); .one();
@ -255,8 +255,8 @@ public class ModelImageServiceImpl extends ServiceImpl<ModelImageMapper, ModelIm
modelImageVo.setTags(tagList); modelImageVo.setTags(tagList);
SysUser sysUser = sysUserService.selectUserById(modelImage.getUserId()); SysUser sysUser = sysUserService.selectUserById(modelImage.getUserId());
modelImageVo.setUserId(SecurityUtils.getUserId()); modelImageVo.setUserId(sysUser.getUserId());
modelImageVo.setUserName(SecurityUtils.getUsername()); modelImageVo.setUserName(sysUser.getUserName());
modelImageVo.setUserAvatar(sysUser.getAvatar()); modelImageVo.setUserAvatar(sysUser.getAvatar());
return modelImageVo; return modelImageVo;
} }

View File

@ -492,12 +492,12 @@ public class ModelServiceImpl extends ServiceImpl<ModelMapper,ModelProduct> impl
} }
modelProduct.setIsAttention(1); modelProduct.setIsAttention(1);
SysUserAttention sysUserAttention = sysUserAttentionMapper.selectAttention(SecurityUtils.getUserId(), modelProduct.getUserId()); SysUserAttention sysUserAttention = sysUserAttentionMapper.selectAttention(SecurityUtils.getUserIdMax(), modelProduct.getUserId());
if (sysUserAttention == null){ if (sysUserAttention == null){
modelProduct.setIsAttention(0); modelProduct.setIsAttention(0);
} }
WorkFlowLike workFlowLike = modelLikeMapper.selectModelLikeById(SecurityUtils.getUserId(),modelProduct.getId()); WorkFlowLike workFlowLike = modelLikeMapper.selectModelLikeById(SecurityUtils.getUserIdMax(),modelProduct.getId());
modelProduct.setIsLike(1); modelProduct.setIsLike(1);
if (workFlowLike == null){ if (workFlowLike == null){
modelProduct.setIsLike(0); modelProduct.setIsLike(0);

View File

@ -88,13 +88,9 @@ public class SysUserAttentionServiceImpl extends ServiceImpl<SysUserAttentionMap
@Override @Override
public Boolean selectAttention(Long userId) { public Boolean selectAttention(Long userId) {
SysUserAttention sysUserAttention = sysUserAttentionMapper.selectAttention(SecurityUtils.getUserId(), userId); SysUserAttention sysUserAttention = sysUserAttentionMapper.selectAttention(SecurityUtils.getUserIdMax(), userId);
if (sysUserAttention == null) { return sysUserAttention != null;
return false;
}
return true;
} }
@Override @Override

View File

@ -391,12 +391,12 @@ public class WorkFlowServiceImpl extends ServiceImpl<WorkFlowMapper, WorkFlow> i
workFlow.setTypeList(strings); workFlow.setTypeList(strings);
} }
workFlow.setIsAttention(1); workFlow.setIsAttention(1);
SysUserAttention sysUserAttention = sysUserAttentionMapper.selectAttention(SecurityUtils.getUserId(), workFlow.getUserId()); SysUserAttention sysUserAttention = sysUserAttentionMapper.selectAttention(SecurityUtils.getUserIdMax(), workFlow.getUserId());
if (sysUserAttention == null){ if (sysUserAttention == null){
workFlow.setIsAttention(0); workFlow.setIsAttention(0);
} }
WorkFlowLike workFlowLike = workFlowLikeService.selectWorkFlowLikeById(SecurityUtils.getUserId(),workFlow.getId()); WorkFlowLike workFlowLike = workFlowLikeService.selectWorkFlowLikeById(SecurityUtils.getUserIdMax(),workFlow.getId());
workFlow.setIsLike(1); workFlow.setIsLike(1);
if (workFlowLike == null){ if (workFlowLike == null){
workFlow.setIsLike(0); workFlow.setIsLike(0);