From 96dad0ce7610603d446a2c82f6ddaa0ee8c80c7e Mon Sep 17 00:00:00 2001 From: ublue Date: Sat, 12 Sep 2020 21:25:54 +0800 Subject: [PATCH] gzq --- .../parent/{Exercise.java => Excercise.java} | 2 +- .../codesdream/ase/model/parent/Parent.java | 1 + ...pository.java => ExcerciseRepository.java} | 6 +- .../repository/parent/ParentRepository.java | 4 +- .../repository/student/StudentRepository.java | 5 +- .../codesdream/ase/service/ParentService.java | 76 +++++++++++++++++++ .../ase/service/StaticsService.java | 8 +- .../ase/service/StudentService.java | 3 + 8 files changed, 92 insertions(+), 13 deletions(-) rename src/main/java/com/codesdream/ase/model/parent/{Exercise.java => Excercise.java} (93%) rename src/main/java/com/codesdream/ase/repository/parent/{ExerciseRepository.java => ExcerciseRepository.java} (51%) create mode 100644 src/main/java/com/codesdream/ase/service/ParentService.java diff --git a/src/main/java/com/codesdream/ase/model/parent/Exercise.java b/src/main/java/com/codesdream/ase/model/parent/Excercise.java similarity index 93% rename from src/main/java/com/codesdream/ase/model/parent/Exercise.java rename to src/main/java/com/codesdream/ase/model/parent/Excercise.java index 065f2e3..7b6fd3f 100644 --- a/src/main/java/com/codesdream/ase/model/parent/Exercise.java +++ b/src/main/java/com/codesdream/ase/model/parent/Excercise.java @@ -9,7 +9,7 @@ import java.util.Date; @Entity @Table @Data -public class Exercise { +public class Excercise { @Id @GeneratedValue(strategy = GenerationType.AUTO) 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 7fb7617..8db5148 100644 --- a/src/main/java/com/codesdream/ase/model/parent/Parent.java +++ b/src/main/java/com/codesdream/ase/model/parent/Parent.java @@ -15,4 +15,5 @@ import java.util.List; @EqualsAndHashCode(callSuper = false) public class Parent extends User { + private int studentId; } diff --git a/src/main/java/com/codesdream/ase/repository/parent/ExerciseRepository.java b/src/main/java/com/codesdream/ase/repository/parent/ExcerciseRepository.java similarity index 51% rename from src/main/java/com/codesdream/ase/repository/parent/ExerciseRepository.java rename to src/main/java/com/codesdream/ase/repository/parent/ExcerciseRepository.java index bd1ef7f..c9d3e2c 100644 --- a/src/main/java/com/codesdream/ase/repository/parent/ExerciseRepository.java +++ b/src/main/java/com/codesdream/ase/repository/parent/ExcerciseRepository.java @@ -1,12 +1,12 @@ package com.codesdream.ase.repository.parent; -import com.codesdream.ase.model.parent.Exercise; +import com.codesdream.ase.model.parent.Excercise; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import java.util.List; @Repository -public interface ExerciseRepository extends JpaRepository { - List findByStudentId(int studentId); +public interface ExcerciseRepository extends JpaRepository { + List findByStudentId(int studentId); } diff --git a/src/main/java/com/codesdream/ase/repository/parent/ParentRepository.java b/src/main/java/com/codesdream/ase/repository/parent/ParentRepository.java index 4560a04..efa86ae 100644 --- a/src/main/java/com/codesdream/ase/repository/parent/ParentRepository.java +++ b/src/main/java/com/codesdream/ase/repository/parent/ParentRepository.java @@ -11,7 +11,7 @@ import java.util.Optional; @Repository public interface ParentRepository extends JpaRepository { - List findByStudentId(String studentId); - List findByStudentId(String studentId, Sort sort); + List findByStudentId(int studentId); + List findByStudentId(int studentId, Sort sort); } 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 bcc9863..6709b07 100644 --- a/src/main/java/com/codesdream/ase/repository/student/StudentRepository.java +++ b/src/main/java/com/codesdream/ase/repository/student/StudentRepository.java @@ -12,7 +12,6 @@ import java.util.Optional; @Repository public interface StudentRepository extends JpaRepository { - Student findByParentId(String parentId); - Student findByParentId(String parentId, Sort sort); - + Student findByParentId(int parentId); + Student findByStudentId(int studentId); } diff --git a/src/main/java/com/codesdream/ase/service/ParentService.java b/src/main/java/com/codesdream/ase/service/ParentService.java new file mode 100644 index 0000000..4184f34 --- /dev/null +++ b/src/main/java/com/codesdream/ase/service/ParentService.java @@ -0,0 +1,76 @@ +package com.codesdream.ase.service; + +import com.codesdream.ase.model.message.Notification; +import com.codesdream.ase.model.parent.Parent; +import com.codesdream.ase.model.student.Student; +import com.codesdream.ase.repository.message.MessageRepository; +import com.codesdream.ase.repository.parent.ParentRepository; +import com.codesdream.ase.repository.student.StudentRepository; +import org.springframework.stereotype.Repository; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +@Service +public class ParentService { + + @Resource + ParentRepository parentRepository; + + @Resource + StudentRepository studentRepository; + + @Resource + MessageRepository messageRepository; + + /** + * 用于创建一个家长账号 + * @param studentId 学生ID + * @param parentId 家长id,一般为家长的电话 + * @param parentName 家长姓名 + * @return 创建的家长实体 + */ + public Parent createParent(int studentId, int parentId, String parentName){ + + Parent parent=new Parent(); + parent.setUsername(parentName); + parent.setId(parentId); + parent.setStudentId(studentId); + return parent; + } + + /** + * 获取某个家长的孩子 + * @param parentId 家长ID + * @param + * @return 这个家长的孩子 + */ + public Student getStudent(int parentId){ + + return studentRepository.findByParentId(parentId); + } + /** + * (用于绑定家长与学生账号)家长输入学生学号与姓名,若都正确,返回真。 + * @param studentId 学生ID + * @param studentName 姓名 + * @return 学号与姓名是否一致 + */ + public boolean startIdentify(int studentId, String studentName){ + Student s0=studentRepository.findByStudentId(studentId); + if(s0!=null){ + if(s0.getUsername().equals(studentName)) + return true; + else return false; + } + else return false; + } + + + + + +} diff --git a/src/main/java/com/codesdream/ase/service/StaticsService.java b/src/main/java/com/codesdream/ase/service/StaticsService.java index d36d56c..1b7ddbd 100644 --- a/src/main/java/com/codesdream/ase/service/StaticsService.java +++ b/src/main/java/com/codesdream/ase/service/StaticsService.java @@ -3,14 +3,14 @@ package com.codesdream.ase.service; import com.codesdream.ase.component.student.SubjectScore; import com.codesdream.ase.exception.notfound.NotFoundException; import com.codesdream.ase.model.message.Notification; -import com.codesdream.ase.model.parent.Exercise; +import com.codesdream.ase.model.parent.Excercise; import com.codesdream.ase.model.permission.User; import com.codesdream.ase.model.permission.UserDetail; import com.codesdream.ase.model.student.Course; import com.codesdream.ase.model.student.Honor; import com.codesdream.ase.model.student.Student; import com.codesdream.ase.model.student.StudentCourse; -import com.codesdream.ase.repository.parent.ExerciseRepository; +import com.codesdream.ase.repository.parent.ExcerciseRepository; import com.codesdream.ase.repository.permission.UserRepository; import com.codesdream.ase.repository.student.*; import org.springframework.data.domain.Sort; @@ -43,7 +43,7 @@ public class StaticsService { NotificationRepository notificationRepository; @Resource - ExerciseRepository exerciseRepository; + ExcerciseRepository exerciseRepository; /** @@ -124,7 +124,7 @@ public class StaticsService { * @param studentId 学生id * @return 锻炼情况列表 */ - public List displayExercise(int studentId){ + public List displayExercise(int studentId){ if(!checkStudentExistence(studentId)){ throw new NotFoundException("No such student."); } diff --git a/src/main/java/com/codesdream/ase/service/StudentService.java b/src/main/java/com/codesdream/ase/service/StudentService.java index bf380bb..b440c6d 100644 --- a/src/main/java/com/codesdream/ase/service/StudentService.java +++ b/src/main/java/com/codesdream/ase/service/StudentService.java @@ -10,6 +10,7 @@ import com.codesdream.ase.model.permission.UserDetail; 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.repository.parent.ExcerciseRepository; import com.codesdream.ase.repository.student.HonorRepository; import com.codesdream.ase.repository.student.NotificationRepository; import com.codesdream.ase.repository.student.StudentRepository; @@ -37,6 +38,8 @@ public class StudentService { @Resource HonorRepository honorRepository; + @Resource + ExcerciseRepository excerciseRepository; /** * 用于创建一个公告 * @see Notification