use of top.hcode.hoj.pojo.entity.discussion.Comment in project HOJ by HimitZH.
the class CommentManager method getAllReply.
public List<ReplyVo> getAllReply(Integer commentId, Long cid) throws StatusForbiddenException, StatusFailException, AccessException {
// 如果有登录,则获取当前登录的用户
Session session = SecurityUtils.getSubject().getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
boolean isRoot = SecurityUtils.getSubject().hasRole("root");
if (cid == null) {
Comment comment = commentEntityService.getById(commentId);
QueryWrapper<Discussion> discussionQueryWrapper = new QueryWrapper<>();
discussionQueryWrapper.select("id", "gid").eq("id", comment.getDid());
Discussion discussion = discussionEntityService.getOne(discussionQueryWrapper);
Long gid = discussion.getGid();
if (gid != null) {
accessValidator.validateAccess(HOJAccessEnum.GROUP_DISCUSSION);
if (!isRoot && !groupValidator.isGroupMember(userRolesVo.getUid(), gid)) {
throw new StatusForbiddenException("对不起,您无权限操作!");
}
} else {
accessValidator.validateAccess(HOJAccessEnum.PUBLIC_DISCUSSION);
}
} else {
accessValidator.validateAccess(HOJAccessEnum.CONTEST_COMMENT);
Contest contest = contestEntityService.getById(cid);
contestValidator.validateContestAuth(contest, userRolesVo, isRoot);
}
return replyEntityService.getAllReplyByCommentId(cid, userRolesVo != null ? userRolesVo.getUid() : null, isRoot, commentId);
}
use of top.hcode.hoj.pojo.entity.discussion.Comment in project HOJ by HimitZH.
the class CommentManager method addCommentLike.
@Transactional(rollbackFor = Exception.class)
public void addCommentLike(Integer cid, Boolean toLike, Integer sourceId, String sourceType) throws StatusFailException {
// 获取当前登录的用户
Session session = SecurityUtils.getSubject().getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
QueryWrapper<CommentLike> commentLikeQueryWrapper = new QueryWrapper<>();
commentLikeQueryWrapper.eq("cid", cid).eq("uid", userRolesVo.getUid());
CommentLike commentLike = commentLikeEntityService.getOne(commentLikeQueryWrapper, false);
if (toLike) {
// 添加点赞
if (commentLike == null) {
// 如果不存在就添加
boolean isSave = commentLikeEntityService.saveOrUpdate(new CommentLike().setUid(userRolesVo.getUid()).setCid(cid));
if (!isSave) {
throw new StatusFailException("点赞失败,请重试尝试!");
}
}
// 点赞+1
Comment comment = commentEntityService.getById(cid);
if (comment != null) {
comment.setLikeNum(comment.getLikeNum() + 1);
commentEntityService.updateById(comment);
// 当前的评论要不是点赞者的 才发送点赞消息
if (!userRolesVo.getUsername().equals(comment.getFromName())) {
commentEntityService.updateCommentLikeMsg(comment.getFromUid(), userRolesVo.getUid(), sourceId, sourceType);
}
}
} else {
// 取消点赞
if (commentLike != null) {
// 如果存在就删除
boolean isDelete = commentLikeEntityService.removeById(commentLike.getId());
if (!isDelete) {
throw new StatusFailException("取消点赞失败,请重试尝试!");
}
}
// 点赞-1
UpdateWrapper<Comment> commentUpdateWrapper = new UpdateWrapper<>();
commentUpdateWrapper.setSql("like_num=like_num-1").eq("id", cid);
commentEntityService.update(commentUpdateWrapper);
}
}
use of top.hcode.hoj.pojo.entity.discussion.Comment in project HOJ by HimitZH.
the class MsgRemindServiceImpl method getUserReplyMsgList.
public IPage<UserMsgVo> getUserReplyMsgList(IPage<UserMsgVo> userMsgList) {
for (UserMsgVo userMsgVo : userMsgList.getRecords()) {
if ("Discussion".equals(userMsgVo.getSourceType())) {
Discussion discussion = discussionMapper.selectById(userMsgVo.getSourceId());
if (discussion != null) {
userMsgVo.setSourceTitle(discussion.getTitle());
} else {
userMsgVo.setSourceTitle("原讨论帖已被删除!【The original discussion post has been deleted!】");
}
} else if ("Contest".equals(userMsgVo.getSourceType())) {
Contest contest = contestService.getById(userMsgVo.getSourceId());
if (contest != null) {
userMsgVo.setSourceTitle(contest.getTitle());
} else {
userMsgVo.setSourceTitle("原比赛已被删除!【The original contest has been deleted!】");
}
}
if ("Comment".equals(userMsgVo.getQuoteType())) {
Comment comment = commentMapper.selectById(userMsgVo.getQuoteId());
if (comment != null) {
String content;
if (comment.getContent().length() < 100) {
content = comment.getFromName() + " : " + comment.getContent();
} else {
content = comment.getFromName() + " : " + comment.getContent().substring(0, 100) + "...";
}
userMsgVo.setQuoteContent(content);
} else {
userMsgVo.setQuoteContent("您的原评论信息已被删除!【Your original comments have been deleted!】");
}
} else if ("Reply".equals(userMsgVo.getQuoteType())) {
Reply reply = replyMapper.selectById(userMsgVo.getQuoteId());
if (reply != null) {
String content;
if (reply.getContent().length() < 100) {
content = reply.getFromName() + " : @" + reply.getToName() + ":" + reply.getContent();
} else {
content = reply.getFromName() + " : @" + reply.getToName() + ":" + reply.getContent().substring(0, 100) + "...";
}
userMsgVo.setQuoteContent(content);
} else {
userMsgVo.setQuoteContent("您的原回复信息已被删除!【Your original reply has been deleted!】");
}
}
}
applicationContext.getBean(MsgRemindServiceImpl.class).updateUserMsgRead(userMsgList);
return userMsgList;
}
use of top.hcode.hoj.pojo.entity.discussion.Comment in project HOJ by HimitZH.
the class CommentController method addDiscussionLike.
@GetMapping("/comment-like")
@RequiresAuthentication
@Transactional
public CommonResult addDiscussionLike(@RequestParam("cid") Integer cid, @RequestParam("toLike") Boolean toLike, @RequestParam("sourceId") Integer sourceId, @RequestParam("sourceType") String sourceType, HttpServletRequest request) {
// 获取当前登录的用户
HttpSession session = request.getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
QueryWrapper<CommentLike> commentLikeQueryWrapper = new QueryWrapper<>();
commentLikeQueryWrapper.eq("cid", cid).eq("uid", userRolesVo.getUid());
CommentLike commentLike = commentLikeService.getOne(commentLikeQueryWrapper, false);
if (toLike) {
// 添加点赞
if (commentLike == null) {
// 如果不存在就添加
boolean isSave = commentLikeService.saveOrUpdate(new CommentLike().setUid(userRolesVo.getUid()).setCid(cid));
if (!isSave) {
return CommonResult.errorResponse("点赞失败,请重试尝试!");
}
}
// 点赞+1
Comment comment = commentService.getById(cid);
if (comment != null) {
comment.setLikeNum(comment.getLikeNum() + 1);
commentService.updateById(comment);
commentService.updateCommentLikeMsg(comment.getFromUid(), userRolesVo.getUid(), sourceId, sourceType);
}
return CommonResult.successResponse(null, "点赞成功");
} else {
// 取消点赞
if (commentLike != null) {
// 如果存在就删除
boolean isDelete = commentLikeService.removeById(commentLike.getId());
if (!isDelete) {
return CommonResult.errorResponse("取消点赞失败,请重试尝试!");
}
}
// 点赞-1
UpdateWrapper<Comment> commentUpdateWrapper = new UpdateWrapper<>();
commentUpdateWrapper.setSql("like_num=like_num-1").eq("id", cid);
commentService.update(commentUpdateWrapper);
return CommonResult.successResponse(null, "取消成功");
}
}
use of top.hcode.hoj.pojo.entity.discussion.Comment in project HOJ by HimitZH.
the class UserMessageManager method getUserReplyMsgList.
private IPage<UserMsgVo> getUserReplyMsgList(IPage<UserMsgVo> userMsgList) {
for (UserMsgVo userMsgVo : userMsgList.getRecords()) {
if ("Discussion".equals(userMsgVo.getSourceType())) {
Discussion discussion = discussionEntityService.getById(userMsgVo.getSourceId());
if (discussion != null) {
userMsgVo.setSourceTitle(discussion.getTitle());
} else {
userMsgVo.setSourceTitle("原讨论帖已被删除!【The original discussion post has been deleted!】");
}
} else if ("Contest".equals(userMsgVo.getSourceType())) {
Contest contest = contestEntityService.getById(userMsgVo.getSourceId());
if (contest != null) {
userMsgVo.setSourceTitle(contest.getTitle());
} else {
userMsgVo.setSourceTitle("原比赛已被删除!【The original contest has been deleted!】");
}
}
if ("Comment".equals(userMsgVo.getQuoteType())) {
Comment comment = commentEntityService.getById(userMsgVo.getQuoteId());
if (comment != null) {
String content;
if (comment.getContent().length() < 100) {
content = comment.getFromName() + " : " + comment.getContent();
} else {
content = comment.getFromName() + " : " + comment.getContent().substring(0, 100) + "...";
}
userMsgVo.setQuoteContent(content);
} else {
userMsgVo.setQuoteContent("您的原评论信息已被删除!【Your original comments have been deleted!】");
}
} else if ("Reply".equals(userMsgVo.getQuoteType())) {
Reply reply = replyEntityService.getById(userMsgVo.getQuoteId());
if (reply != null) {
String content;
if (reply.getContent().length() < 100) {
content = reply.getFromName() + " : @" + reply.getToName() + ":" + reply.getContent();
} else {
content = reply.getFromName() + " : @" + reply.getToName() + ":" + reply.getContent().substring(0, 100) + "...";
}
userMsgVo.setQuoteContent(content);
} else {
userMsgVo.setQuoteContent("您的原回复信息已被删除!【Your original reply has been deleted!】");
}
}
}
applicationContext.getBean(UserMessageManager.class).updateUserMsgRead(userMsgList);
return userMsgList;
}
Aggregations