Search in sources :

Example 1 with Reply

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("回复失败,请重新尝试!");
    }
}
Also used : UpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper) HttpSession(javax.servlet.http.HttpSession) UserRolesVo(top.hcode.hoj.pojo.vo.UserRolesVo) Reply(top.hcode.hoj.pojo.entity.discussion.Reply) Discussion(top.hcode.hoj.pojo.entity.discussion.Discussion) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication)

Example 2 with Reply

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, "获取全部回复列表成功");
}
Also used : HttpSession(javax.servlet.http.HttpSession) UserRolesVo(top.hcode.hoj.pojo.vo.UserRolesVo) Reply(top.hcode.hoj.pojo.entity.discussion.Reply)

Example 3 with Reply

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);
    }
}
Also used : UpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper) HttpSession(javax.servlet.http.HttpSession) UserRolesVo(top.hcode.hoj.pojo.vo.UserRolesVo) Reply(top.hcode.hoj.pojo.entity.discussion.Reply) Discussion(top.hcode.hoj.pojo.entity.discussion.Discussion) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication)

Example 4 with Reply

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);
}
Also used : QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) Reply(top.hcode.hoj.pojo.entity.discussion.Reply) UserInfo(top.hcode.hoj.pojo.entity.user.UserInfo) Contest(top.hcode.hoj.pojo.entity.contest.Contest)

Example 5 with Reply

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;
}
Also used : Comment(top.hcode.hoj.pojo.entity.discussion.Comment) Reply(top.hcode.hoj.pojo.entity.discussion.Reply) Contest(top.hcode.hoj.pojo.entity.contest.Contest) Discussion(top.hcode.hoj.pojo.entity.discussion.Discussion) UserMsgVo(top.hcode.hoj.pojo.vo.UserMsgVo)

Aggregations

Reply (top.hcode.hoj.pojo.entity.discussion.Reply)8 Discussion (top.hcode.hoj.pojo.entity.discussion.Discussion)6 Contest (top.hcode.hoj.pojo.entity.contest.Contest)5 UpdateWrapper (com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper)4 Comment (top.hcode.hoj.pojo.entity.discussion.Comment)4 HttpSession (javax.servlet.http.HttpSession)3 UserRolesVo (top.hcode.hoj.pojo.vo.UserRolesVo)3 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)2 RequiresAuthentication (org.apache.shiro.authz.annotation.RequiresAuthentication)2 Session (org.apache.shiro.session.Session)2 StatusFailException (top.hcode.hoj.common.exception.StatusFailException)2 StatusForbiddenException (top.hcode.hoj.common.exception.StatusForbiddenException)2 UserMsgVo (top.hcode.hoj.pojo.vo.UserMsgVo)2 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)1 UserAcproblem (top.hcode.hoj.pojo.entity.user.UserAcproblem)1 UserInfo (top.hcode.hoj.pojo.entity.user.UserInfo)1