|
@@ -43,17 +43,18 @@ public class ExamCourseApi {
|
|
|
@GetMapping
|
|
|
public Page<ExamCourseDTO> findCourse(@RequestParam("exam_id") Long examId,
|
|
|
@RequestParam(value = "course_code", required = false) String courseCode,
|
|
|
+ @RequestParam(value = "course_level", required = false) String courseLevel,
|
|
|
@RequestParam("cur_page") Integer curPage,
|
|
|
@RequestParam("page_size") Integer pageSize) {
|
|
|
|
|
|
|
|
|
List<ExamStudent> examStudents;
|
|
|
- if (StringUtils.isEmpty(courseCode)) {
|
|
|
- examStudents = examStudentRepo.findDistinctCourseCode(examId);
|
|
|
- } else {
|
|
|
+ if (!StringUtils.isEmpty(courseCode)) {
|
|
|
examStudents = examStudentRepo.findDistinctCourseCode(examId, courseCode);
|
|
|
+ } else {
|
|
|
+ examStudents = examStudentRepo.findDistinctCourseCode(examId);
|
|
|
}
|
|
|
- Map<String, Boolean> courseMap = getCourseEnableMap(examId);
|
|
|
+ Map<String, Course> courseMap = getCourseMap(examId);
|
|
|
|
|
|
List<ExamCourseDTO> examCourseDTOs = examStudents.stream().map(examStudent -> {
|
|
|
ExamCourseDTO examCourseDTO = new ExamCourseDTO();
|
|
@@ -65,8 +66,15 @@ public class ExamCourseApi {
|
|
|
examCourseDTO.setOrgId(examStudent.getRootOrgId());
|
|
|
return examCourseDTO;
|
|
|
}).filter(examCourseDTO -> {
|
|
|
- Boolean enable = courseMap.get(examCourseDTO.getCourseCode());
|
|
|
- return enable != null ? enable : false;
|
|
|
+ Course course = courseMap.get(examCourseDTO.getCourseCode());
|
|
|
+ return course.getEnable() != null ? course.getEnable() : false;
|
|
|
+ }).filter(examCourseDTO -> {
|
|
|
+ if(!StringUtils.isEmpty(courseLevel)){
|
|
|
+ Course course = courseMap.get(examCourseDTO.getCourseCode());
|
|
|
+ return courseLevel.equals(course.getLevel().name());
|
|
|
+ }else{
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}).collect(Collectors.toList());
|
|
|
int total = examCourseDTOs.size();
|
|
|
examCourseDTOs = examCourseDTOs.stream().skip(curPage * pageSize).limit(pageSize).collect(Collectors.toList());
|
|
@@ -79,7 +87,7 @@ public class ExamCourseApi {
|
|
|
|
|
|
List<ExamStudent> examStudents = examStudentRepo.findDistinctCourseCode(examId);
|
|
|
|
|
|
- Map<String, Boolean> courseMap = getCourseEnableMap(examId);
|
|
|
+ Map<String, Course> courseMap = getCourseMap(examId);
|
|
|
|
|
|
List<ExamCourseDTO> examCourseDTOs = examStudents.stream().map(examStudent -> {
|
|
|
ExamCourseDTO examCourseDTO = new ExamCourseDTO();
|
|
@@ -91,20 +99,20 @@ public class ExamCourseApi {
|
|
|
examCourseDTO.setOrgId(examStudent.getRootOrgId());
|
|
|
return examCourseDTO;
|
|
|
}).filter(examCourseDTO -> {
|
|
|
- Boolean enable = courseMap.get(examCourseDTO.getCourseCode());
|
|
|
- return enable != null ? enable : false;
|
|
|
+ Course course = courseMap.get(examCourseDTO.getCourseCode());
|
|
|
+ return course.getEnable() != null ? course.getEnable() : false;
|
|
|
}).collect(Collectors.toList());
|
|
|
return examCourseDTOs;
|
|
|
|
|
|
}
|
|
|
|
|
|
- private Map<String, Boolean> getCourseEnableMap(Long examId) {
|
|
|
- Map<String, Boolean> courseMap = new HashMap<>();
|
|
|
+ private Map<String, Course> getCourseMap(Long examId) {
|
|
|
+ Map<String, Course> courseMap = new HashMap<>();
|
|
|
Exam exam = examRepo.findOne(examId);
|
|
|
List<Course> courses = courseService.findByOrgId(exam.getRootOrgId());
|
|
|
if(courses != null && courses.size() > 0){
|
|
|
for(Course course:courses){
|
|
|
- courseMap.put(course.getCode(),course.getEnable());
|
|
|
+ courseMap.put(course.getCode(),course);
|
|
|
}
|
|
|
}
|
|
|
return courseMap;
|