消息推送机制架构搭建完成

This commit is contained in:
chuyan 2020-09-11 20:44:50 +08:00
parent 17aace8fa6
commit dc08efbaba
2 changed files with 51 additions and 0 deletions

View File

@ -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;

View File

@ -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<Message> 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<Message> searchMessageByTitle(String messageTitle){
return messageRepository.findByTitle(messageTitle);
}
public boolean sendMessageToGroup(int messageId, List<User> 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<Message> optionalMessage = messageRepository.findById(messageId);
if(!optionalMessage.isPresent()){
return false;
}
return true;
}
}