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; + } + }