diff --git a/src/main/java/com/codesdream/ase/component/auth/ASEJSONTokenAuthenticationFilter.java b/src/main/java/com/codesdream/ase/component/auth/ASEJSONTokenAuthenticationFilter.java index f7f54f2..b736e66 100644 --- a/src/main/java/com/codesdream/ase/component/auth/ASEJSONTokenAuthenticationFilter.java +++ b/src/main/java/com/codesdream/ase/component/auth/ASEJSONTokenAuthenticationFilter.java @@ -51,7 +51,7 @@ public class ASEJSONTokenAuthenticationFilter extends OncePerRequestFilter { // 服务端API测试豁免签名 if(signed != null && signed.equals("6d4923fca4dcb51f67b85e54a23a8d763d9e02af")){ //执行授权 - doAuthentication("u_id_88883b9e023c8824310760d8bb8b6542e5a3f16a0d67253214e01ee7ab0e96a1", request); + doAuthentication("u_id_c70233fd7cb1f8a770c440975a0d13ad4013d3631b6f93c0037c7294bbc42140", request); } // 正常认证 else if (signed != null && username != null && timestamp != null) { diff --git a/src/main/java/com/codesdream/ase/controller/RegisterController.java b/src/main/java/com/codesdream/ase/controller/RegisterController.java index 0908a34..9051636 100644 --- a/src/main/java/com/codesdream/ase/controller/RegisterController.java +++ b/src/main/java/com/codesdream/ase/controller/RegisterController.java @@ -18,6 +18,7 @@ import javax.servlet.http.HttpServletRequest; import java.util.Optional; @Controller +@RequestMapping("register") public class RegisterController { @Resource private UserService userService; @@ -31,13 +32,22 @@ public class RegisterController { @Resource private QuickJSONRespond quickJSONRespond; - @RequestMapping(value = "/register") + @RequestMapping(value = "") String registerView(Model model){ return "register"; } + @PostMapping(value="baseinfo") + @ResponseBody + String addBaseInfo(){ + BaseStudentInfo bsi = baseInformationService.constructStudentInfo("2018303209", "14011809", "Jack", + "男","软件学院","软件工程","汉族","群众","未知"); + baseInformationService.save(bsi); + + return "OK"; + } // 处理注册表单 - @PostMapping(value = "/register/do_register") + @PostMapping(value = "user") @ResponseBody String doRegister(HttpServletRequest request){ diff --git a/src/main/java/com/codesdream/ase/controller/TestController.java b/src/main/java/com/codesdream/ase/controller/TestController.java index de39213..df9ddd8 100644 --- a/src/main/java/com/codesdream/ase/controller/TestController.java +++ b/src/main/java/com/codesdream/ase/controller/TestController.java @@ -4,24 +4,23 @@ import com.codesdream.ase.model.student.Comment; import com.codesdream.ase.repository.student.CommentRepository; import org.springframework.data.domain.Sort; import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseStatus; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.List; -@RestController("test") +@RestController +@RequestMapping("test") public class TestController { @Resource - CommentRepository commentRepository; + private CommentRepository commentRepository; - @RequestMapping + @GetMapping("") @ResponseStatus(HttpStatus.OK) public boolean test() throws InterruptedException { - int userId = 1; + String userId = "1"; for (int i = 0;i < 10; i++){ Comment comment = new Comment(); comment.setUserId(userId); @@ -30,8 +29,11 @@ public class TestController { Thread.sleep(20); } Thread.sleep(1000); - List comments = commentRepository.findByUserId(new Integer(userId).toString(), - Sort.by(Sort.Direction.ASC, "date")); + List comments = commentRepository.findByUserId(userId, + Sort.by(Sort.Direction.DESC, "date")); + if(!comments.isEmpty()){ + System.out.println(comments.toString()); + } return true; } } diff --git a/src/main/java/com/codesdream/ase/exception/innerservererror/DataInvalidFormatException.java b/src/main/java/com/codesdream/ase/exception/innerservererror/DataInvalidFormatException.java index 99f6dd9..f18d536 100644 --- a/src/main/java/com/codesdream/ase/exception/innerservererror/DataInvalidFormatException.java +++ b/src/main/java/com/codesdream/ase/exception/innerservererror/DataInvalidFormatException.java @@ -16,4 +16,8 @@ public class DataInvalidFormatException extends FormatException { public DataInvalidFormatException(){ super(); } + + public DataInvalidFormatException(String s) { + information = s; + } } diff --git a/src/main/java/com/codesdream/ase/exception/innerservererror/InvalidDataException.java b/src/main/java/com/codesdream/ase/exception/innerservererror/InvalidDataException.java new file mode 100644 index 0000000..101edd9 --- /dev/null +++ b/src/main/java/com/codesdream/ase/exception/innerservererror/InvalidDataException.java @@ -0,0 +1,16 @@ +package com.codesdream.ase.exception.innerservererror; + +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@EqualsAndHashCode(callSuper = false) +public class InvalidDataException extends FormatException{ + private String message; + public InvalidDataException(String message){ + super(message); + this.message = message; + } +} diff --git a/src/main/java/com/codesdream/ase/model/activity/Activity.java b/src/main/java/com/codesdream/ase/model/activity/Activity.java index 654ff8b..09a628a 100644 --- a/src/main/java/com/codesdream/ase/model/activity/Activity.java +++ b/src/main/java/com/codesdream/ase/model/activity/Activity.java @@ -20,10 +20,10 @@ public class Activity { String title; @ManyToOne - User Creator; + User creator; - @ManyToOne - User Manager; + @ManyToMany + List manager; @ElementCollection List participantIds = new ArrayList<>(); diff --git a/src/main/java/com/codesdream/ase/model/parent/Message.java b/src/main/java/com/codesdream/ase/model/parent/Message.java index 266d92b..a0e9501 100644 --- a/src/main/java/com/codesdream/ase/model/parent/Message.java +++ b/src/main/java/com/codesdream/ase/model/parent/Message.java @@ -25,6 +25,6 @@ public class Message { int type; @OneToMany - User Receiver; + List Receiver; } \ No newline at end of file diff --git a/src/main/java/com/codesdream/ase/model/parent/Parent.java b/src/main/java/com/codesdream/ase/model/parent/Parent.java index 950ea50..7fb7617 100644 --- a/src/main/java/com/codesdream/ase/model/parent/Parent.java +++ b/src/main/java/com/codesdream/ase/model/parent/Parent.java @@ -14,10 +14,5 @@ import java.util.List; @Data @EqualsAndHashCode(callSuper = false) public class Parent extends User { - @Column(nullable = false) - String parentId; - - @Column(nullable = false) - String name; } diff --git a/src/main/java/com/codesdream/ase/model/permission/User.java b/src/main/java/com/codesdream/ase/model/permission/User.java index 5c43149..b58ef0a 100644 --- a/src/main/java/com/codesdream/ase/model/permission/User.java +++ b/src/main/java/com/codesdream/ase/model/permission/User.java @@ -1,5 +1,6 @@ package com.codesdream.ase.model.permission; +import com.codesdream.ase.model.file.Image; import com.codesdream.ase.model.mark.Tag; import lombok.Data; import org.springframework.security.core.GrantedAuthority; diff --git a/src/main/java/com/codesdream/ase/model/permission/UserDetail.java b/src/main/java/com/codesdream/ase/model/permission/UserDetail.java index 42cf013..976f6f9 100644 --- a/src/main/java/com/codesdream/ase/model/permission/UserDetail.java +++ b/src/main/java/com/codesdream/ase/model/permission/UserDetail.java @@ -1,5 +1,6 @@ package com.codesdream.ase.model.permission; +import com.codesdream.ase.model.file.Image; import com.codesdream.ase.model.information.*; import lombok.Data; @@ -47,4 +48,13 @@ public class UserDetail { // 在校认证状态 private boolean atSchool = false; + + // 电话 + private String telNum; + + // 邮箱 + private String email; + + @OneToOne + private Image profilePic; } diff --git a/src/main/java/com/codesdream/ase/model/robot/Faq.java b/src/main/java/com/codesdream/ase/model/robot/Faq.java index ee28efb..0bea192 100644 --- a/src/main/java/com/codesdream/ase/model/robot/Faq.java +++ b/src/main/java/com/codesdream/ase/model/robot/Faq.java @@ -13,8 +13,13 @@ import java.util.List; @Table @Data public class Faq { + @Id + int id; + String answer; String question; + + @ElementCollection List tag; } diff --git a/src/main/java/com/codesdream/ase/model/student/Comment.java b/src/main/java/com/codesdream/ase/model/student/Comment.java index ee0bfc3..61fa9a4 100644 --- a/src/main/java/com/codesdream/ase/model/student/Comment.java +++ b/src/main/java/com/codesdream/ase/model/student/Comment.java @@ -14,7 +14,7 @@ public class Comment { int id; // 发出此评论的用户 - int userId; + String userId; // 评论内容 String context; diff --git a/src/main/java/com/codesdream/ase/model/student/Honor.java b/src/main/java/com/codesdream/ase/model/student/Honor.java index fbf1fd5..8c9efe6 100644 --- a/src/main/java/com/codesdream/ase/model/student/Honor.java +++ b/src/main/java/com/codesdream/ase/model/student/Honor.java @@ -15,7 +15,7 @@ public class Honor { @GeneratedValue(strategy = GenerationType.AUTO) int id; - String studentId; + int studentId; // 荣誉描述 String description; diff --git a/src/main/java/com/codesdream/ase/model/student/Notification.java b/src/main/java/com/codesdream/ase/model/student/Notification.java index d88cc79..f1fba39 100644 --- a/src/main/java/com/codesdream/ase/model/student/Notification.java +++ b/src/main/java/com/codesdream/ase/model/student/Notification.java @@ -1,10 +1,13 @@ package com.codesdream.ase.model.student; +import com.codesdream.ase.model.file.File; import lombok.Data; import javax.persistence.Entity; import javax.persistence.Id; +import javax.persistence.ManyToMany; import javax.persistence.Table; +import java.util.List; @Entity @Table @@ -17,5 +20,7 @@ public class Notification { String title; + @ManyToMany + List files; } diff --git a/src/main/java/com/codesdream/ase/model/student/Student.java b/src/main/java/com/codesdream/ase/model/student/Student.java index 962bf46..67f724c 100644 --- a/src/main/java/com/codesdream/ase/model/student/Student.java +++ b/src/main/java/com/codesdream/ase/model/student/Student.java @@ -6,21 +6,24 @@ import lombok.Data; import lombok.EqualsAndHashCode; import javax.persistence.*; +import java.util.HashMap; +import java.util.Map; @Entity @Data @EqualsAndHashCode(callSuper = false) public class Student extends User { - @Column(nullable = false) - String studentId; - - @Column(nullable = false) - String name; String profilePicture; - @Column(nullable = false) - Boolean is_showgrade; + Boolean isShowGrade = true; + @ElementCollection + Map privacy = new HashMap(){{ + put("score", true); + put("attendance", true); + put("step", true); + put("honor", true); + }}; } diff --git a/src/main/java/com/codesdream/ase/repository/student/StudentRepository.java b/src/main/java/com/codesdream/ase/repository/student/StudentRepository.java index 9d7d568..69d1b69 100644 --- a/src/main/java/com/codesdream/ase/repository/student/StudentRepository.java +++ b/src/main/java/com/codesdream/ase/repository/student/StudentRepository.java @@ -10,9 +10,5 @@ import java.util.Optional; @Repository public interface StudentRepository extends JpaRepository { - Optional findByStudentId(String studentId); - List findByName(String name, Sort sort); - - List findByName(String name); } diff --git a/src/main/java/com/codesdream/ase/service/activity/ActivityService.java b/src/main/java/com/codesdream/ase/service/activity/ActivityService.java new file mode 100644 index 0000000..b6407e7 --- /dev/null +++ b/src/main/java/com/codesdream/ase/service/activity/ActivityService.java @@ -0,0 +1,41 @@ +package com.codesdream.ase.service.activity; + +import com.codesdream.ase.model.activity.Activity; +import com.codesdream.ase.model.permission.User; +import com.codesdream.ase.repository.activity.ActivityRepository; +import com.codesdream.ase.repository.permission.UserRepository; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.Optional; + +@Service +public class ActivityService { + + @Resource + ActivityRepository activityRepository; + + @Resource + UserRepository userRepository; + + public Activity addMember(int activityId, int memberId, boolean type){ + + Optional optionalActivity = activityRepository.findById(activityId); + Optional optionalUser = userRepository.findById(memberId); + if(!optionalActivity.isPresent() || !optionalUser.isPresent()){ + return null; + } + Activity activity = optionalActivity.get(); + User user = optionalUser.get(); + if(!type){ + activity.getManager().add(user); + } + else{ + activity.getParticipantIds().add(user.getId()); + } + return activityRepository.save(activity); + } + + + +} diff --git a/src/main/java/com/codesdream/ase/service/student/StudentService.java b/src/main/java/com/codesdream/ase/service/student/StudentService.java new file mode 100644 index 0000000..827b172 --- /dev/null +++ b/src/main/java/com/codesdream/ase/service/student/StudentService.java @@ -0,0 +1,135 @@ +package com.codesdream.ase.service.student; + +import com.codesdream.ase.exception.innerservererror.DataInvalidFormatException; +import com.codesdream.ase.exception.innerservererror.InvalidDataException; +import com.codesdream.ase.exception.notfound.NotFoundException; +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.permission.UserDetail; +import com.codesdream.ase.model.student.Honor; +import com.codesdream.ase.model.student.Notification; +import com.codesdream.ase.model.student.Student; +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.service.activity.ActivityService; +import com.codesdream.ase.validator.GeneralValidator; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +@Service +public class StudentService { + + @Resource + StudentRepository studentRepository; + + @Resource + NotificationRepository notificationRepository; + + @Resource + ActivityService activityService; + + @Resource + HonorRepository honorRepository; + + public Notification createNotification(String title, String description, List files){ + Notification notification = new Notification(); + + notification.setTitle(title); + notification.setContext(description); + notification.setFiles(files); + + return notificationRepository.save(notification); + } + + public boolean cancelNotification(int notificationId){ + Optional notification = notificationRepository.findById(notificationId); + if(notification.isPresent()){ + notificationRepository.delete(notification.get()); + return true; + } + else{ + throw new NotFoundException("No such notification."); + } + } + + public Activity attendActivity(int studentId, int activityId){ + return activityService.addMember(activityId, studentId, true); + } + + public Honor createHonor(int studentId, String description, List images){ + + Honor honor = new Honor(); + honor.setDescription(description); + honor.setImages(images); + honor.setLastModification(honor.getCreationDate()); + honor.setStudentId(studentId); + + return honorRepository.save(honor); + } + + public Honor updateHonor(int honorId, String description, List images){ + + Optional optionalHonor = honorRepository.findById(honorId); + if(!optionalHonor.isPresent()){ + throw new NotFoundException("No such honor."); + } + Honor honor = optionalHonor.get(); + if(!description.isEmpty()){ + honor.setDescription(description); + } + if(!images.isEmpty()){ + honor.setImages(images); + } + return honorRepository.save(honor); + } + + public boolean updatePrivacy(int studentId, List privacyList){ + + Optional optionalStudent = studentRepository.findById(studentId); + if(optionalStudent.isPresent()){ + Student student = optionalStudent.get(); + if(student.getPrivacy().keySet().containsAll(privacyList)){ + Map privacyMap = student.getPrivacy(); + for(String privacy : privacyList){ + privacyMap.put(privacy, true); + } + return true; + } + else { + throw new DataInvalidFormatException("Invalid privacy with illegal phrases."); + } + } + else { + throw new NotFoundException("No such privacy."); + } + } + + public Student editProfile(int studentId, String telNum, Image profilePic, String email){ + Optional optionalStudent = studentRepository.findById(studentId); + if(!optionalStudent.isPresent()){ + throw new NotFoundException("No such student."); + } + if(!GeneralValidator.isTelNumber(telNum) && !telNum.equals("0")){ + throw new InvalidDataException("Invalid telephone number."); + } + Student student = optionalStudent.get(); + UserDetail userDetail = student.getUserDetail(); + if(!telNum.equals("0")){ + userDetail.setTelNum(telNum); + } + if(profilePic!=null){ + userDetail.setProfilePic(profilePic); + } + if(!email.isEmpty()){ + userDetail.setEmail(email); + } + return studentRepository.save(student); + } + +} diff --git a/src/main/java/com/codesdream/ase/validator/GeneralValidator.java b/src/main/java/com/codesdream/ase/validator/GeneralValidator.java new file mode 100644 index 0000000..e2702fd --- /dev/null +++ b/src/main/java/com/codesdream/ase/validator/GeneralValidator.java @@ -0,0 +1,18 @@ +package com.codesdream.ase.validator; + +import org.springframework.stereotype.Component; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +@Component +public class GeneralValidator { + + public static boolean isTelNumber (String telNum){ + String reg = "^[1](([3][0-9])|([4][5,7,9])|([5][^4,6,9])|([6][6])" + + "|([7][3,5,6,7,8])|([8][0-9])|([9][8,9]))[0-9]{8}$"; + Pattern p = Pattern.compile(reg); + Matcher m = p.matcher(telNum); + return m.find(); + } +} diff --git a/src/test/java/com/codesdream/ase/test/JpaTest.java b/src/test/java/com/codesdream/ase/test/JpaTest.java index aeb6edd..26a63ef 100644 --- a/src/test/java/com/codesdream/ase/test/JpaTest.java +++ b/src/test/java/com/codesdream/ase/test/JpaTest.java @@ -19,8 +19,8 @@ public class JpaTest { @Test public void test() throws InterruptedException { - CommentRepository commentRepository = aseSpringUtil.getBean(CommentRepository.class); - int userId = 1; + /*CommentRepository commentRepository = aseSpringUtil.getBean(CommentRepository.class); + String userId = "1"; for (int i = 0;i < 10; i++){ Comment comment = new Comment(); comment.setUserId(userId); @@ -30,6 +30,6 @@ public class JpaTest { } Thread.sleep(1000); List comments = commentRepository.findByUserId(new Integer(userId).toString(), - Sort.by(Sort.Direction.ASC, "date")); + Sort.by(Sort.Direction.ASC, "date"));*/ } }