use of top.hcode.hoj.pojo.entity.discussion.Reply in project HOJ by HimitZH.
the class CommentController method addReply.
@PostMapping("/reply")
@RequiresPermissions("reply_add")
@RequiresAuthentication
public CommonResult addReply(@RequestBody ReplyDto replyDto, HttpServletRequest request) {
if (StringUtils.isEmpty(replyDto.getReply().getContent().trim())) {
return CommonResult.errorResponse("回复内容不能为空!");
}
// 获取当前登录的用户
HttpSession session = request.getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
Reply reply = replyDto.getReply();
reply.setFromAvatar(userRolesVo.getAvatar()).setFromName(userRolesVo.getUsername()).setFromUid(userRolesVo.getUid());
if (SecurityUtils.getSubject().hasRole("root")) {
reply.setFromRole("root");
} else if (SecurityUtils.getSubject().hasRole("admin") || SecurityUtils.getSubject().hasRole("problem_admin")) {
reply.setFromRole("admin");
} else {
reply.setFromRole("user");
}
// 带有表情的字符串转换为编码
reply.setContent(EmojiUtil.toHtml(reply.getContent()));
boolean isOk = replyService.saveOrUpdate(reply);
if (isOk) {
// 如果是讨论区的回复,发布成功需要增加统计该讨论的回复数
if (replyDto.getDid() != null) {
UpdateWrapper<Discussion> discussionUpdateWrapper = new UpdateWrapper<>();
discussionUpdateWrapper.eq("id", replyDto.getDid()).setSql("comment_num=comment_num+1");
discussionService.update(discussionUpdateWrapper);
// 更新消息
replyService.updateReplyMsg(replyDto.getDid(), "Discussion", reply.getContent(), replyDto.getQuoteId(), replyDto.getQuoteType(), reply.getToUid(), reply.getFromUid());
}
return CommonResult.successResponse(reply, "回复成功");
} else {
return CommonResult.errorResponse("回复失败,请重新尝试!");
}
}
use of top.hcode.hoj.pojo.entity.discussion.Reply in project HOJ by HimitZH.
the class CommentController method getAllReply.
@GetMapping("/reply")
public CommonResult getAllReply(@RequestParam("commentId") Integer commentId, @RequestParam(value = "cid", required = false) Long cid, HttpServletRequest request) {
// 如果有登录,则获取当前登录的用户
HttpSession session = request.getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
boolean isRoot = SecurityUtils.getSubject().hasRole("root");
List<Reply> replyList = commentService.getAllReplyByCommentId(cid, userRolesVo != null ? userRolesVo.getUid() : null, isRoot, commentId);
return CommonResult.successResponse(replyList, "获取全部回复列表成功");
}
use of top.hcode.hoj.pojo.entity.discussion.Reply in project HOJ by HimitZH.
the class CommentController method deleteReply.
@DeleteMapping("/reply")
@RequiresAuthentication
public CommonResult deleteReply(@RequestBody ReplyDto replyDto, HttpServletRequest request) {
// 获取当前登录的用户
HttpSession session = request.getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
Reply reply = replyDto.getReply();
// 如果不是评论本人 或者不是管理员 无权限删除该评论
if (reply.getFromUid().equals(userRolesVo.getUid()) || SecurityUtils.getSubject().hasRole("root") || SecurityUtils.getSubject().hasRole("admin") || SecurityUtils.getSubject().hasRole("problem_admin")) {
// 删除该数据
boolean isOk = replyService.removeById(reply.getId());
if (isOk) {
// 如果是讨论区的回复,删除成功需要减少统计该讨论的回复数
if (replyDto.getDid() != null) {
UpdateWrapper<Discussion> discussionUpdateWrapper = new UpdateWrapper<>();
discussionUpdateWrapper.eq("id", replyDto.getDid()).setSql("comment_num=comment_num-1");
discussionService.update(discussionUpdateWrapper);
}
return CommonResult.successResponse(null, "删除成功");
} else {
return CommonResult.errorResponse("删除失败,请重新尝试");
}
} else {
return CommonResult.errorResponse("无权删除该回复", CommonResult.STATUS_FORBIDDEN);
}
}
use of top.hcode.hoj.pojo.entity.discussion.Reply in project HOJ by HimitZH.
the class CommentServiceImpl method getAllReplyByCommentId.
@Override
public List<Reply> getAllReplyByCommentId(Long cid, String uid, Boolean isRoot, Integer commentId) {
QueryWrapper<Reply> replyQueryWrapper = new QueryWrapper<>();
replyQueryWrapper.eq("comment_id", commentId);
if (cid != null) {
Contest contest = contestService.getById(cid);
boolean onlyMineAndAdmin = contest.getStatus().equals(Constants.Contest.STATUS_RUNNING.getCode()) && !isRoot && !contest.getUid().equals(uid);
if (onlyMineAndAdmin) {
// 自己和比赛管理者评论可看
List<UserInfo> superAdminList = contestRecordService.getSuperAdminList();
List<String> myAndAdminUidList = superAdminList.stream().map(UserInfo::getUuid).collect(Collectors.toList());
myAndAdminUidList.add(uid);
myAndAdminUidList.add(contest.getUid());
replyQueryWrapper.in("from_uid", myAndAdminUidList);
}
}
replyQueryWrapper.orderByDesc("gmt_create");
return replyService.list(replyQueryWrapper);
}
use of top.hcode.hoj.pojo.entity.discussion.Reply 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;
}
Aggregations