From dc08efbaba26b83426940cd4d998699f4fd5b10f Mon Sep 17 00:00:00 2001 From: chuyan <1047381936@qq.com> Date: Fri, 11 Sep 2020 20:44:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B6=88=E6=81=AF=E6=8E=A8=E9=80=81=E6=9C=BA?= =?UTF-8?q?=E5=88=B6=E6=9E=B6=E6=9E=84=E6=90=AD=E5=BB=BA=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ase/service/CalculationService.java | 2 + .../ase/service/MessageService.java | 49 +++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/src/main/java/com/codesdream/ase/service/CalculationService.java b/src/main/java/com/codesdream/ase/service/CalculationService.java index 72c0ed1..d4228d9 100644 --- a/src/main/java/com/codesdream/ase/service/CalculationService.java +++ b/src/main/java/com/codesdream/ase/service/CalculationService.java @@ -7,11 +7,13 @@ import com.codesdream.ase.model.student.StudentCourse; import com.codesdream.ase.repository.student.CourseRepository; import com.codesdream.ase.repository.student.StudentCourseRepository; import com.codesdream.ase.repository.student.StudentRepository; +import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.List; import java.util.Optional; +@Service public class CalculationService { @Resource StudentRepository studentRepository; diff --git a/src/main/java/com/codesdream/ase/service/MessageService.java b/src/main/java/com/codesdream/ase/service/MessageService.java index 7c82a70..6d606a3 100644 --- a/src/main/java/com/codesdream/ase/service/MessageService.java +++ b/src/main/java/com/codesdream/ase/service/MessageService.java @@ -1,5 +1,6 @@ package com.codesdream.ase.service; +import com.codesdream.ase.exception.notfound.NotFoundException; import com.codesdream.ase.model.message.Message; import com.codesdream.ase.model.permission.User; import com.codesdream.ase.repository.message.MessageRepository; @@ -7,6 +8,7 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.List; +import java.util.Optional; @Service public class MessageService { @@ -56,4 +58,51 @@ public class MessageService { return true; } + /** + * 删除信息 + * @exception NotFoundException 如果messageId无效 + * @param messageId 信息id + * @return 是否删成功 + */ + public boolean deleteMessage(int messageId){ + Optional optionalMessage = messageRepository.findById(messageId); + try{ + if(!checkMessageExistence(messageId)){ + throw new NotFoundException("No such message."); + } + }catch (Exception e){ + return false; + } + Message message = optionalMessage.get(); + messageRepository.delete(message); + return true; + } + + public Message searchMessageById(int messageId){ + if(!checkMessageExistence(messageId)){ + throw new NotFoundException("No such message."); + } + return messageRepository.findById(messageId).get(); + } + + public List searchMessageByTitle(String messageTitle){ + return messageRepository.findByTitle(messageTitle); + } + + public boolean sendMessageToGroup(int messageId, List users){ + if(!checkMessageExistence(messageId)){ + throw new NotFoundException("No such message."); + } + Message message = messageRepository.findById(messageId).get(); + return sendMessage(message, users); + } + + private boolean checkMessageExistence(int messageId){ + Optional optionalMessage = messageRepository.findById(messageId); + if(!optionalMessage.isPresent()){ + return false; + } + return true; + } + }