From 5e3ba60707d26cf90519de8dd8bf3b8aa0efbbc5 Mon Sep 17 00:00:00 2001 From: ublue Date: Tue, 22 Sep 2020 15:34:15 +0800 Subject: [PATCH] gzq --- .../ase/component/student/SubjectScore.java | 6 + .../ase/model/student/StudentCourse.java | 3 + .../student/StudentCourseRepository.java | 3 + .../repository/student/StudentRepository.java | 1 + .../codesdream/ase/service/JudgeService.java | 153 ++++++++++++++++++ .../ase/service/StaticsService.java | 1 + .../ase/service/StudentService.java | 2 + 7 files changed, 169 insertions(+) create mode 100644 src/main/java/com/codesdream/ase/service/JudgeService.java diff --git a/src/main/java/com/codesdream/ase/component/student/SubjectScore.java b/src/main/java/com/codesdream/ase/component/student/SubjectScore.java index 10e80e7..20e3c7a 100644 --- a/src/main/java/com/codesdream/ase/component/student/SubjectScore.java +++ b/src/main/java/com/codesdream/ase/component/student/SubjectScore.java @@ -17,4 +17,10 @@ public class SubjectScore { private Date finishedDate; + private boolean isFailed; + + public boolean getIsFailed(){ + return this.isFailed; + } + } diff --git a/src/main/java/com/codesdream/ase/model/student/StudentCourse.java b/src/main/java/com/codesdream/ase/model/student/StudentCourse.java index 826a017..a65e0fe 100644 --- a/src/main/java/com/codesdream/ase/model/student/StudentCourse.java +++ b/src/main/java/com/codesdream/ase/model/student/StudentCourse.java @@ -26,4 +26,7 @@ public class StudentCourse { Date finishedDate; + public boolean getIsFailed() { + return this.isFailed; + } } diff --git a/src/main/java/com/codesdream/ase/repository/student/StudentCourseRepository.java b/src/main/java/com/codesdream/ase/repository/student/StudentCourseRepository.java index ad804f8..3103b77 100644 --- a/src/main/java/com/codesdream/ase/repository/student/StudentCourseRepository.java +++ b/src/main/java/com/codesdream/ase/repository/student/StudentCourseRepository.java @@ -11,4 +11,7 @@ import java.util.List; public interface StudentCourseRepository extends JpaRepository { List findByStudentId(int studentId); List findByStudentId(int studentId, Sort sort); + List findByStudentIdAndTerm(int studentId,int term); + List findByStudentIdAndTerm(int studentId,int term,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 706d13b..9c80e48 100644 --- a/src/main/java/com/codesdream/ase/repository/student/StudentRepository.java +++ b/src/main/java/com/codesdream/ase/repository/student/StudentRepository.java @@ -5,6 +5,7 @@ import org.springframework.data.domain.Sort; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.List; import java.util.Optional; @Repository diff --git a/src/main/java/com/codesdream/ase/service/JudgeService.java b/src/main/java/com/codesdream/ase/service/JudgeService.java new file mode 100644 index 0000000..fbf03cc --- /dev/null +++ b/src/main/java/com/codesdream/ase/service/JudgeService.java @@ -0,0 +1,153 @@ +package com.codesdream.ase.service; +import com.codesdream.ase.component.student.SubjectScore; +import com.codesdream.ase.model.student.Course; +import com.codesdream.ase.model.student.Student; +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.apache.xmlbeans.impl.xb.xsdschema.Public; +import org.springframework.data.domain.Sort; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; + +@Service +public class JudgeService { + + @Resource + StudentCourseRepository scRepo; + + @Resource + CourseRepository courseRepository; + + @Resource + StudentRepository students; + + /** + * 根据给定排序方式查询某学生的成绩情况 + * @see SubjectScore + * @see StudentCourse + * @param studentId 学生id + * @param term 学期 + * @param flag 指定排序方式,0表示按学期排序,1表示按分数排序,2表示按照学分排序,否则表示不排序 + * @return + */ + public List displayScore (int studentId, int term, int flag){ + + Sort sort; + switch (flag){ + case 0:{ + sort = Sort.by(Sort.Direction.ASC, "term"); + break; + } + case 1:{ + sort = Sort.by(Sort.Direction.ASC, "score"); + break; + } + case 2:{ + sort = Sort.by(Sort.Direction.ASC, "credit"); + break; + } + default: + sort = null; + } + List studentCourseList = new ArrayList<>(); + if(sort == null){ + studentCourseList = scRepo.findByStudentIdAndTerm(studentId,term); + }else{ + studentCourseList = scRepo.findByStudentIdAndTerm(studentId,term,sort); + } + if(studentCourseList.isEmpty()){ + return null; + } + List subjectScores = new ArrayList<>(); + for(StudentCourse studentCourse : studentCourseList){ + + Course course = courseRepository.findById(studentCourse.getCourseId()).get(); + SubjectScore sc = new SubjectScore(); + + sc.setCredit(course.getCredit()); + sc.setFinishedDate(studentCourse.getFinishedDate()); + sc.setScore(studentCourse.getScore()); + sc.setStudentId(studentCourse.getStudentId()); + + subjectScores.add(sc); + } + return subjectScores; + } + + /** + * 判断某学生某学期是否有学业警告 + * @param studentId 学生id + * @param term 学期 + * @return 是否警告 + */ + public boolean judgeWarning(int studentId,int term){ + List scores= displayScore(studentId,term,1); + double sum=0; + for(SubjectScore ss:scores){ + if(ss.getScore()>=60.0||ss.getIsFailed()==false){ + sum+=ss.getCredit(); + } + } + if(sum<15.0){ + return true; + } + else return false; + } + /** + * 判断某学生某学期选课学分是否低于20分 + * @param studentId 学生id + * @param term 学期 + * @return 是否低于20学分 + */ + + public boolean judgeLowCredit(int studentId,int term){ + List scores= displayScore(studentId,term,1); + double sum=0; + for(SubjectScore ss:scores){ + sum+=ss.getCredit(); + } + if(sum<20.0){ + return true; + } + else return false; + } + +// /** +// * 获取某个学期,所有有学业预警的学生 +// * @param term 学期 +// * @return 学生列表 +// */ +// public List getWarning(int term){ +// +// List result= new ArrayList<>(); +// for (Student s:students){ +// if(judgeWarning(s.getId(),term)){ +// result.add(s); +// } +// } +// return result; +// } +// /** +// * 获取某个学期,所有选课低于20分的学生 +// * @param term 学期 +// * @return 学生列表 +// */ +// public List getLowCredit(int term){ +// +// List result= new ArrayList<>(); +// for (Student s:students){ +// if(judgeLowCredit(s.getId(),term)){ +// result.add(s); +// } +// } +// return result; +// } + + + +} diff --git a/src/main/java/com/codesdream/ase/service/StaticsService.java b/src/main/java/com/codesdream/ase/service/StaticsService.java index 4545d81..6acdda6 100644 --- a/src/main/java/com/codesdream/ase/service/StaticsService.java +++ b/src/main/java/com/codesdream/ase/service/StaticsService.java @@ -94,6 +94,7 @@ public class StaticsService { sc.setFinishedDate(studentCourse.getFinishedDate()); sc.setScore(studentCourse.getScore()); sc.setStudentId(studentCourse.getStudentId()); + sc.setFailed(studentCourse.getIsFailed()); subjectScores.add(sc); } diff --git a/src/main/java/com/codesdream/ase/service/StudentService.java b/src/main/java/com/codesdream/ase/service/StudentService.java index 34f6e8f..2247275 100644 --- a/src/main/java/com/codesdream/ase/service/StudentService.java +++ b/src/main/java/com/codesdream/ase/service/StudentService.java @@ -149,4 +149,6 @@ public class StudentService { return studentRepository.save(student); } + + }