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

@ -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);