|
|
@@ -8,14 +8,19 @@ 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.service.util.AuthUtils;
|
|
|
+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
|
|
|
*/
|
|
|
@@ -26,10 +31,13 @@ public class ReplyServiceImpl implements ReplyService {
|
|
|
private final CommentDAO commentDAO;
|
|
|
private final ReplyDAO replyDAO;
|
|
|
|
|
|
- public ReplyServiceImpl(SlideDAO slideDAO, CommentDAO commentDAO, 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)
|
|
|
@@ -39,7 +47,7 @@ public class ReplyServiceImpl implements ReplyService {
|
|
|
AuthUtils.checkDataAuth(user.getId(), slideDAO.findSlideById(comment.getSlideId()).getTeacherId(), "您无权回复该评论");
|
|
|
|
|
|
if (comment.getReply() != null) {
|
|
|
- throw HelperException.of(ExceptionType.FORBIDDEN, "您已回复该评论");
|
|
|
+ throw HelperException.of(ExceptionType.CONFLICT, "您已回复该评论");
|
|
|
}
|
|
|
Reply reply = new Reply()
|
|
|
.setComment(comment)
|
|
|
@@ -47,6 +55,13 @@ public class ReplyServiceImpl implements ReplyService {
|
|
|
.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】的评论被回复了,请及时查看", slide.getCourseName(), slide.getName()), slide.getId());
|
|
|
+ }
|
|
|
+
|
|
|
return new ReplyVO(reply);
|
|
|
}
|
|
|
|