refactor(mcwl): 调整

master
yang 2025-04-14 15:31:37 +08:00
parent 1f85f77ca3
commit 67d1f6cc19
1 changed files with 0 additions and 53 deletions

View File

@ -40,60 +40,7 @@ public class PublishCommentLikeServiceImpl extends ServiceImpl<PublishCommentLik
@Transactional(rollbackFor = Exception.class)
public void like(PublishCommentLikeRes publishCommentLikeRes) {
PublishComment publishComment = publishCommentMapper.selectByIdAndTenantIdAndCommunityIdAndOperatorId(
publishCommentLikeRes.getTenantId(), publishCommentLikeRes.getCommunityId(), publishCommentLikeRes.getCommentId()
);
if (Objects.isNull(publishComment)) {
throw new ServiceException("该评论不存在", HttpStatus.SHOW_ERROR_MSG);
}
PublishCommentLike publishCommentLike = baseMapper.selectLike(publishCommentLikeRes, SecurityUtils.getUserId());
if (Objects.isNull(publishCommentLike)) {
publishCommentLike = new PublishCommentLike();
publishCommentLike.setTenantId(publishCommentLikeRes.getTenantId());
publishCommentLike.setCommunityId(publishCommentLikeRes.getCommunityId());
publishCommentLike.setPublishId(publishCommentLikeRes.getPublishId());
publishCommentLike.setPublishCommentId(publishCommentLikeRes.getCommentId());
publishCommentLike.setUserId(SecurityUtils.getUserId());
baseMapper.insert(publishCommentLike);
publishComment.setLikeNum(publishComment.getLikeNum() + 1);
publishCommentMapper.updateById(publishComment);
this.addLikeAdvice();
return;
}
if (Objects.equals(publishCommentLike.getDelFlag(), "0")) {
publishCommentLike.setDelFlag("2");
int likeNum = publishComment.getLikeNum() - 1;
likeNum = Math.max(likeNum, 0);
publishComment.setLikeNum(likeNum);
} else {
publishCommentLike.setDelFlag("0");
publishComment.setLikeNum(publishComment.getLikeNum() + 1);
this.addLikeAdvice();
}
baseMapper.updateDelFlagById(publishCommentLike);
publishCommentMapper.updateById(publishComment);
}
private void addLikeAdvice(PublishCommentLike publishCommentLike) {
CommunityAdvice communityAdvice = new CommunityAdvice();
communityAdvice.setTenantId(publishCommentLike.getTenantId());
communityAdvice.setCommunityId(publishCommentLike.getCommunityId());
communityAdvice.setSendUserId(SecurityUtils.getUserId());
communityAdvice.setAdviceType(AdviceConstant.COMMUNITY_NOTICE);
communityAdvice.setUserId(publishCommentLike);
communityAdvice.setTitle(StringUtils.format("{}回复{}",
SecurityUtils.getLoginUser().getUser().getNickName(),
question.getContent()));
communityAdvice.setContent(questionCommentRes.getContent());
communityAdviceMapper.insert(communityAdvice);
}