|
|
@@ -0,0 +1,74 @@
|
|
|
+package nju.seec.helper.service.impl;
|
|
|
+
|
|
|
+import nju.seec.helper.dao.ChooseDAO;
|
|
|
+import nju.seec.helper.dao.CourseDAO;
|
|
|
+import nju.seec.helper.dao.NoticeDAO;
|
|
|
+import nju.seec.helper.dto.LoginUser;
|
|
|
+import nju.seec.helper.dto.NoticeDTO;
|
|
|
+import nju.seec.helper.entity.Course;
|
|
|
+import nju.seec.helper.entity.Notice;
|
|
|
+import nju.seec.helper.service.MessageService;
|
|
|
+import nju.seec.helper.service.NoticeService;
|
|
|
+import nju.seec.helper.service.util.AuthUtils;
|
|
|
+import nju.seec.helper.util.enums.MessageType;
|
|
|
+import nju.seec.helper.vo.NoticeVO;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author cst
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class NoticeServiceImpl implements NoticeService {
|
|
|
+ private final CourseDAO courseDAO;
|
|
|
+ private final ChooseDAO chooseDAO;
|
|
|
+ private final NoticeDAO noticeDAO;
|
|
|
+
|
|
|
+ private final MessageService messageService;
|
|
|
+
|
|
|
+ public NoticeServiceImpl(CourseDAO courseDAO, ChooseDAO chooseDAO, NoticeDAO noticeDAO, MessageService messageService) {
|
|
|
+ this.courseDAO = courseDAO;
|
|
|
+ this.chooseDAO = chooseDAO;
|
|
|
+ this.noticeDAO = noticeDAO;
|
|
|
+ this.messageService = messageService;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public NoticeVO create(LoginUser user, NoticeDTO noticeDTO) {
|
|
|
+ Course course = courseDAO.findCourseById(noticeDTO.getCourseId());
|
|
|
+ AuthUtils.checkDataAuth(user.getId(), course.getTeacherId(), "您无权创建该课程的公告");
|
|
|
+ Notice notice = new Notice()
|
|
|
+ .setCourseId(noticeDTO.getCourseId())
|
|
|
+ .setTeacherId(user.getId())
|
|
|
+ .setTitle(noticeDTO.getTitle())
|
|
|
+ .setContent(noticeDTO.getContent());
|
|
|
+
|
|
|
+ Set<Long> studentIds = chooseDAO.findStudentIdsByCourseId(noticeDTO.getCourseId());
|
|
|
+ messageService.createMessage(studentIds, MessageType.NOTICE_NEW, String.format("课程 [%s] 发布了标题为 [%s] 的公告", course.getName(), notice.getTitle()), null);
|
|
|
+ return new NoticeVO(noticeDAO.save(notice));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public NoticeVO modify(LoginUser user, NoticeDTO noticeDTO) {
|
|
|
+ Notice notice = noticeDAO.findNoticeById(noticeDTO.getId());
|
|
|
+ AuthUtils.checkDataAuth(user.getId(), notice.getTeacherId(), "您无权修改该公告");
|
|
|
+ notice.setTitle(noticeDTO.getTitle())
|
|
|
+ .setContent(noticeDTO.getContent());
|
|
|
+ return new NoticeVO(noticeDAO.save(notice));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<NoticeVO> getNoticesByCourse(LoginUser user, Long courseId, String key, Pageable pageable) {
|
|
|
+ return noticeDAO.findByCourseIdAndKey(courseId, key, pageable).map(NoticeVO::new);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void deleteNotice(LoginUser user, Long noticeId) {
|
|
|
+ Notice notice = noticeDAO.findNoticeById(noticeId);
|
|
|
+ AuthUtils.checkDataAuth(user.getId(), notice.getTeacherId(), "您无权删除该公告");
|
|
|
+ noticeDAO.deleteById(noticeId);
|
|
|
+ }
|
|
|
+}
|