| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- package nju.seec.helper.service.impl;
- import lombok.extern.slf4j.Slf4j;
- import nju.seec.helper.dao.CommentDAO;
- import nju.seec.helper.dao.ReplyDAO;
- import nju.seec.helper.dao.SlideDAO;
- import nju.seec.helper.dto.LoginUser;
- import nju.seec.helper.dto.ReplyDTO;
- import nju.seec.helper.entity.Comment;
- import nju.seec.helper.entity.Reply;
- import nju.seec.helper.entity.Slide;
- import nju.seec.helper.service.MessageService;
- import nju.seec.helper.service.ReplyService;
- import nju.seec.helper.service.util.AuthUtils;
- import nju.seec.helper.util.enums.ExceptionType;
- import nju.seec.helper.util.enums.MessageType;
- import nju.seec.helper.util.exception.HelperException;
- import nju.seec.helper.vo.ReplyVO;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import java.util.Collections;
- /**
- * @author cst
- */
- @Slf4j
- @Service
- public class ReplyServiceImpl implements ReplyService {
- private final SlideDAO slideDAO;
- private final CommentDAO commentDAO;
- private final ReplyDAO replyDAO;
- private final MessageService messageService;
- public ReplyServiceImpl(SlideDAO slideDAO, CommentDAO commentDAO, ReplyDAO replyDAO, MessageService messageService) {
- this.slideDAO = slideDAO;
- this.commentDAO = commentDAO;
- this.replyDAO = replyDAO;
- this.messageService = messageService;
- }
- @Transactional(rollbackFor = Exception.class)
- @Override
- public ReplyVO createReply(LoginUser user, ReplyDTO replyDTO) {
- Comment comment = commentDAO.findCommentById(replyDTO.getCommentId());
- AuthUtils.checkDataAuth(user.getId(), slideDAO.findSlideById(comment.getSlideId()).getTeacherId(), "您无权回复该评论");
- if (comment.getReply() != null) {
- throw HelperException.of(ExceptionType.CONFLICT, "您已回复该评论");
- }
- Reply reply = new Reply()
- .setComment(comment)
- .setTeacherId(user.getId())
- .setContent(replyDTO.getContent());
- reply.setComment(comment);
- reply = replyDAO.save(reply);
- // 增加通知
- if (!user.getId().equals(comment.getUserId())) {
- Slide slide = slideDAO.findSlideById(comment.getSlideId());
- messageService.createMessage(Collections.singleton(comment.getUserId()), MessageType.COMMENT_REPLY, String.format("您在课件「%s」发表的题为「%s」的讨论帖已收到回复", comment.getTitle(), slide.getName()), slide.getId());
- }
- return new ReplyVO(reply);
- }
- @Transactional(rollbackFor = Exception.class)
- @Override
- public void removeReply(LoginUser user, Integer replyId) {
- Reply reply = replyDAO.findReplyById(replyId);
- AuthUtils.checkDataAuth(user.getId(), reply.getTeacherId(), "您无权回复该评论");
- Comment comment = reply.getComment();
- comment.setReply(null);
- replyDAO.delete(reply);
- }
- }
|