This commit is contained in:
ublue 2020-09-12 21:41:22 +08:00
commit 8375983b27
19 changed files with 180 additions and 90 deletions

View File

@ -1,11 +1,9 @@
package com.codesdream.ase.controller.student; package com.codesdream.ase.controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@RestController @RestController
@RequestMapping("student") @RequestMapping("file")
public class StudentController { public class FileController {
//public
} }

View File

@ -0,0 +1,28 @@
package com.codesdream.ase.controller;
import com.codesdream.ase.model.message.Notification;
import com.codesdream.ase.model.permission.User;
import com.codesdream.ase.service.MessageService;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
@RestController
@RequestMapping("message")
public class MessageController {
@Resource
MessageService messageService;
@PostMapping("notification/create")
@ResponseStatus(HttpStatus.CREATED)
public Notification createNotification (@RequestBody String title, @RequestBody String context,
@RequestBody List<Integer> files, Authentication authentication){
User user = (User)authentication.getPrincipal();
return null;//messageService.createNotification(title,context,);
}
}

View File

@ -0,0 +1,15 @@
package com.codesdream.ase.controller;
import com.codesdream.ase.model.message.Notification;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("student")
public class StudentController {
}

View File

@ -1,4 +1,4 @@
package com.codesdream.ase.controller.permission; package com.codesdream.ase.controller;
import com.codesdream.ase.component.datamanager.JSONParameter; import com.codesdream.ase.component.datamanager.JSONParameter;
import com.codesdream.ase.component.json.model.JsonableUser; import com.codesdream.ase.component.json.model.JsonableUser;

View File

@ -1,13 +1,11 @@
package com.codesdream.ase.model.message; package com.codesdream.ase.model.message;
import com.codesdream.ase.model.permission.User;
import lombok.Data; import lombok.Data;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table; import javax.persistence.Table;
import java.util.List; import java.util.Date;
@Entity @Entity
@Table @Table
@ -20,12 +18,9 @@ public class Message {
String text; String text;
boolean isRead = false; Date creationDate = new Date();;
// 重要性 值为0-1 // 重要性 值为0-1
int type; int type;
@OneToMany
List<User> Receiver;
} }

View File

@ -0,0 +1,23 @@
package com.codesdream.ase.model.message;
import lombok.Data;
import javax.persistence.*;
@Entity
@Table
@Data
public class MessageDelivery {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
int id;
boolean isRead = false;
int messageId;
int senderId;
int receiverId;
}

View File

@ -2,26 +2,17 @@ package com.codesdream.ase.model.message;
import com.codesdream.ase.model.file.File; import com.codesdream.ase.model.file.File;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToMany; import javax.persistence.ManyToMany;
import javax.persistence.Table;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@EqualsAndHashCode(callSuper = true)
@Entity @Entity
@Table
@Data @Data
public class Notification { public class Notification extends Message{
@Id
int id;
String context;
String title;
Date creationDate = new Date();
Date announcementDate; Date announcementDate;

View File

@ -9,7 +9,7 @@ import java.util.Date;
@Entity @Entity
@Table @Table
@Data @Data
public class Excercise { public class Exercise {
@Id @Id
@GeneratedValue(strategy = GenerationType.AUTO) @GeneratedValue(strategy = GenerationType.AUTO)

View File

@ -1,19 +1,17 @@
package com.codesdream.ase.model.parent; package com.codesdream.ase.model.parent;
import com.codesdream.ase.model.mark.Tag;
import com.codesdream.ase.model.permission.User; import com.codesdream.ase.model.permission.User;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import javax.annotation.Generated; import javax.persistence.Entity;
import javax.persistence.*;
import java.util.List;
@Entity @Entity
@Table
@Data @Data
@EqualsAndHashCode(callSuper = false) @EqualsAndHashCode(callSuper = false)
public class Parent extends User { public class Parent extends User {
private int studentId;
int studentId;
} }

View File

@ -13,6 +13,7 @@ import java.util.Map;
@Data @Data
@EqualsAndHashCode(callSuper = false) @EqualsAndHashCode(callSuper = false)
public class Student extends User { public class Student extends User {
int parentId;
String profilePicture; String profilePicture;

View File

@ -0,0 +1,16 @@
package com.codesdream.ase.repository.message;
import com.codesdream.ase.model.message.MessageDelivery;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface MessageDeliveryRepository extends JpaRepository<MessageDelivery, Integer> {
List<MessageDelivery> findByReceiverId(int id);
List<MessageDelivery> findBySenderId(int id);
List<MessageDelivery> findBySenderIdAndIsReadTrue(int id);
}

View File

@ -1,4 +1,4 @@
package com.codesdream.ase.repository.student; package com.codesdream.ase.repository.message;
import com.codesdream.ase.model.message.Notification; import com.codesdream.ase.model.message.Notification;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;

View File

@ -1,12 +1,12 @@
package com.codesdream.ase.repository.parent; package com.codesdream.ase.repository.parent;
import com.codesdream.ase.model.parent.Excercise; import com.codesdream.ase.model.parent.Exercise;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
@Repository @Repository
public interface ExcerciseRepository extends JpaRepository<Excercise, Integer> { public interface ExerciseRepository extends JpaRepository<Exercise, Integer> {
List<Excercise> findByStudentId(int studentId); List<Exercise> findByStudentId(int studentId);
} }

View File

@ -1,13 +1,11 @@
package com.codesdream.ase.repository.parent; package com.codesdream.ase.repository.parent;
import com.codesdream.ase.model.parent.Parent; import com.codesdream.ase.model.parent.Parent;
import com.codesdream.ase.model.student.Student;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
import java.util.Optional;
@Repository @Repository
public interface ParentRepository extends JpaRepository<Parent,Integer> { public interface ParentRepository extends JpaRepository<Parent,Integer> {

View File

@ -1,17 +1,18 @@
package com.codesdream.ase.repository.student; package com.codesdream.ase.repository.student;
import com.codesdream.ase.model.student.Student; import com.codesdream.ase.model.student.Student;
import com.codesdream.ase.model.student.StudentCourse;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Optional;
@Repository @Repository
public interface StudentRepository extends JpaRepository<Student, Integer> { public interface StudentRepository extends JpaRepository<Student, Integer> {
Student findByParentId(int parentId); Student findByParentId(int parentId);
Student findByStudentId(int studentId); Student findByStudentId(int studentId);
Student findByParentId(int parentId, Sort sort);
} }

View File

@ -119,7 +119,7 @@ public class ActivityService {
Message message = messageService.createMessage( Message message = messageService.createMessage(
String.format("活动%s即将开始", activity.getTitle()), String.format("活动%s即将开始", activity.getTitle()),
formatter.format(activity.getRealBeginDate()) formatter.format(activity.getRealBeginDate()), -1
); );

View File

@ -1,9 +1,12 @@
package com.codesdream.ase.service; package com.codesdream.ase.service;
import com.codesdream.ase.exception.notfound.NotFoundException; import com.codesdream.ase.exception.notfound.NotFoundException;
import com.codesdream.ase.model.file.File;
import com.codesdream.ase.model.message.Message; import com.codesdream.ase.model.message.Message;
import com.codesdream.ase.model.message.Notification;
import com.codesdream.ase.model.permission.User; import com.codesdream.ase.model.permission.User;
import com.codesdream.ase.repository.message.MessageRepository; import com.codesdream.ase.repository.message.MessageRepository;
import com.codesdream.ase.repository.message.NotificationRepository;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -16,6 +19,10 @@ public class MessageService {
@Resource @Resource
MessageRepository messageRepository; MessageRepository messageRepository;
@Resource
NotificationRepository notificationRepository;
/** /**
* 创建新消息 * 创建新消息
* @see Message * @see Message
@ -23,7 +30,7 @@ public class MessageService {
* @param text 消息内容 * @param text 消息内容
* @return 持久化的消息 * @return 持久化的消息
*/ */
public Message createMessage(String title, String text){ public Message createMessage(String title, String text, int userId){
Message message = new Message(); Message message = new Message();
message.setText(text); message.setText(text);
@ -40,8 +47,8 @@ public class MessageService {
* @param type 消息类型紧急程度 * @param type 消息类型紧急程度
* @return 持久化的消息 * @return 持久化的消息
*/ */
public Message createMessage(String title, String text, int type){ public Message createMessage(String title, String text, int userId, int type){
Message message = createMessage(title, text); Message message = createMessage(title, text, userId);
message.setType(type); message.setType(type);
return messageRepository.save(message); return messageRepository.save(message);
} }
@ -78,6 +85,12 @@ public class MessageService {
return true; return true;
} }
/**
* 根据message的id寻找对应的message若不存在则抛出{@code NotFoundException}异常
* @exception NotFoundException 若id无效
* @param messageId 消息id
* @return 寻找到的message
*/
public Message searchMessageById(int messageId){ public Message searchMessageById(int messageId){
if(!checkMessageExistence(messageId)){ if(!checkMessageExistence(messageId)){
throw new NotFoundException("No such message."); throw new NotFoundException("No such message.");
@ -85,10 +98,22 @@ public class MessageService {
return messageRepository.findById(messageId).get(); return messageRepository.findById(messageId).get();
} }
/**
* 根据消息标题寻找消息若无此标题返回空列表
* @param messageTitle 消息标题
* @return 消息列表
*/
public List<Message> searchMessageByTitle(String messageTitle){ public List<Message> searchMessageByTitle(String messageTitle){
return messageRepository.findByTitle(messageTitle); return messageRepository.findByTitle(messageTitle);
} }
/**
* 把消息发送给指定用户若消息id不存在则抛出{@code NotFoundException}异常
* @exception NotFoundException 若消息id不存在
* @param messageId 消息id
* @param users 用户列表
* @return 是否发送成功
*/
public boolean sendMessageToGroup(int messageId, List<User> users){ public boolean sendMessageToGroup(int messageId, List<User> users){
if(!checkMessageExistence(messageId)){ if(!checkMessageExistence(messageId)){
throw new NotFoundException("No such message."); throw new NotFoundException("No such message.");
@ -97,6 +122,45 @@ public class MessageService {
return sendMessage(message, users); return sendMessage(message, users);
} }
/**
* 用于创建一个公告
* @see Notification
* @param title 公告标题
* @param description 公告内容
* @param files 公告所需附件
* @return 已经持久化的公告
*/
public Notification createNotification(String title, String description, List<File> files){
Notification notification = new Notification();
notification.setTitle(title);
notification.setText(description);
notification.setFiles(files);
return notificationRepository.save(notification);
}
/**
* 在数据库中删除指定公告
* @param notificationId 需要删除的公告id如果此id不存在则会抛出异常删除失败
* @return 是否删除成功
*/
public boolean cancelNotification(int notificationId){
Optional<Notification> notification = notificationRepository.findById(notificationId);
if(notification.isPresent()){
notificationRepository.delete(notification.get());
return true;
}
else{
throw new NotFoundException("No such notification.");
}
}
/**
* 私有方法用于判断消息id是否存在
* @param messageId 消息id
* @return id存在与否
*/
private boolean checkMessageExistence(int messageId){ private boolean checkMessageExistence(int messageId){
Optional<Message> optionalMessage = messageRepository.findById(messageId); Optional<Message> optionalMessage = messageRepository.findById(messageId);
if(!optionalMessage.isPresent()){ if(!optionalMessage.isPresent()){

View File

@ -3,14 +3,16 @@ package com.codesdream.ase.service;
import com.codesdream.ase.component.student.SubjectScore; import com.codesdream.ase.component.student.SubjectScore;
import com.codesdream.ase.exception.notfound.NotFoundException; import com.codesdream.ase.exception.notfound.NotFoundException;
import com.codesdream.ase.model.message.Notification; import com.codesdream.ase.model.message.Notification;
import com.codesdream.ase.model.parent.Excercise; import com.codesdream.ase.model.parent.Exercise;
import com.codesdream.ase.model.permission.User; import com.codesdream.ase.model.permission.User;
import com.codesdream.ase.model.permission.UserDetail; import com.codesdream.ase.model.permission.UserDetail;
import com.codesdream.ase.model.student.Course; import com.codesdream.ase.model.student.Course;
import com.codesdream.ase.model.student.Honor; import com.codesdream.ase.model.student.Honor;
import com.codesdream.ase.model.student.Student; import com.codesdream.ase.model.student.Student;
import com.codesdream.ase.model.student.StudentCourse; import com.codesdream.ase.model.student.StudentCourse;
import com.codesdream.ase.repository.parent.ExcerciseRepository;
import com.codesdream.ase.repository.message.NotificationRepository;
import com.codesdream.ase.repository.parent.ExerciseRepository;
import com.codesdream.ase.repository.permission.UserRepository; import com.codesdream.ase.repository.permission.UserRepository;
import com.codesdream.ase.repository.student.*; import com.codesdream.ase.repository.student.*;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
@ -43,7 +45,7 @@ public class StaticsService {
NotificationRepository notificationRepository; NotificationRepository notificationRepository;
@Resource @Resource
ExcerciseRepository exerciseRepository; ExerciseRepository exerciseRepository;
/** /**
@ -124,7 +126,7 @@ public class StaticsService {
* @param studentId 学生id * @param studentId 学生id
* @return 锻炼情况列表 * @return 锻炼情况列表
*/ */
public List<Excercise> displayExercise(int studentId){ public List<Exercise> displayExercise(int studentId){
if(!checkStudentExistence(studentId)){ if(!checkStudentExistence(studentId)){
throw new NotFoundException("No such student."); throw new NotFoundException("No such student.");
} }

View File

@ -4,15 +4,11 @@ import com.codesdream.ase.exception.innerservererror.DataInvalidFormatException;
import com.codesdream.ase.exception.innerservererror.InvalidDataException; import com.codesdream.ase.exception.innerservererror.InvalidDataException;
import com.codesdream.ase.exception.notfound.NotFoundException; import com.codesdream.ase.exception.notfound.NotFoundException;
import com.codesdream.ase.model.activity.Activity; import com.codesdream.ase.model.activity.Activity;
import com.codesdream.ase.model.file.File;
import com.codesdream.ase.model.file.Image; import com.codesdream.ase.model.file.Image;
import com.codesdream.ase.model.permission.UserDetail; import com.codesdream.ase.model.permission.UserDetail;
import com.codesdream.ase.model.student.Honor; import com.codesdream.ase.model.student.Honor;
import com.codesdream.ase.model.message.Notification;
import com.codesdream.ase.model.student.Student; import com.codesdream.ase.model.student.Student;
import com.codesdream.ase.repository.parent.ExcerciseRepository;
import com.codesdream.ase.repository.student.HonorRepository; import com.codesdream.ase.repository.student.HonorRepository;
import com.codesdream.ase.repository.student.NotificationRepository;
import com.codesdream.ase.repository.student.StudentRepository; import com.codesdream.ase.repository.student.StudentRepository;
import com.codesdream.ase.validator.GeneralValidator; import com.codesdream.ase.validator.GeneralValidator;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -29,50 +25,14 @@ public class StudentService {
@Resource @Resource
StudentRepository studentRepository; StudentRepository studentRepository;
@Resource
NotificationRepository notificationRepository;
@Resource @Resource
ActivityService activityService; ActivityService activityService;
@Resource @Resource
HonorRepository honorRepository; HonorRepository honorRepository;
@Resource
ExcerciseRepository excerciseRepository;
/**
* 用于创建一个公告
* @see Notification
* @param title 公告标题
* @param description 公告内容
* @param files 公告所需附件
* @return 已经持久化的公告
*/
public Notification createNotification(String title, String description, List<File> files){
Notification notification = new Notification();
notification.setTitle(title);
notification.setContext(description);
notification.setFiles(files);
return notificationRepository.save(notification);
}
/**
* 在数据库中删除指定公告
* @param notificationId 需要删除的公告id如果此id不存在则会抛出异常删除失败
* @return 是否删除成功
*/
public boolean cancelNotification(int notificationId){
Optional<Notification> notification = notificationRepository.findById(notificationId);
if(notification.isPresent()){
notificationRepository.delete(notification.get());
return true;
}
else{
throw new NotFoundException("No such notification.");
}
}
/** /**
* 指定学生加入指定活动 * 指定学生加入指定活动